From 41462572ab536c44ee1b1d67d2ad25d88931975a Mon Sep 17 00:00:00 2001 From: Artur Tynecki <77382963+ATmobica@users.noreply.github.com> Date: Mon, 22 Nov 2021 16:39:00 +0100 Subject: [PATCH] [Mbed] Fix WiFi provisioning (#11982) * Increase session establishment timeout to 40s * Update mbed-os-posix-socket lib Improve get default network interface * Fix condition in GetPrimaryWiFiMACAddress --- src/controller/CHIPDeviceController.cpp | 2 +- .../mbed/ConfigurationManagerImpl.cpp | 39 +++++++++---------- src/platform/mbed/ConnectivityManagerImpl.cpp | 4 +- third_party/mbed-os-posix-socket/repo | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 3b84465be3e11e..985f1f27de2049 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -105,7 +105,7 @@ using namespace chip::Encoding; using namespace chip::Protocols::UserDirectedCommissioning; #endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY -constexpr uint32_t kSessionEstablishmentTimeout = 30 * kMillisecondsPerSecond; +constexpr uint32_t kSessionEstablishmentTimeout = 40 * kMillisecondsPerSecond; DeviceController::DeviceController() : mOpenPairingSuccessCallback(OnOpenPairingWindowSuccessResponse, this), diff --git a/src/platform/mbed/ConfigurationManagerImpl.cpp b/src/platform/mbed/ConfigurationManagerImpl.cpp index f169f9885f2659..94f79c80ef8a4e 100644 --- a/src/platform/mbed/ConfigurationManagerImpl.cpp +++ b/src/platform/mbed/ConfigurationManagerImpl.cpp @@ -36,6 +36,7 @@ // mbed-os headers #include "platform/mbed_power_mgmt.h" +#include namespace chip { namespace DeviceLayer { @@ -55,35 +56,33 @@ CHIP_ERROR ConfigurationManagerImpl::Init() CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { - auto interface = WiFiInterface::get_default_instance(); - if (interface) + auto net_if = get_mbed_net_if(); + if (net_if == nullptr || net_if->wifiInterface() == nullptr) { - auto * mac_address = interface->get_mac_address(); - if (mac_address) + ChipLogError(DeviceLayer, "Failed to extract the MAC address: WiFi interface not available"); + return CHIP_ERROR_INTERNAL; + } + + auto * mac_address = net_if->wifiInterface()->get_mac_address(); + if (mac_address) + { + int last = -1; + int rc = + sscanf(mac_address, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx%n", buf + 5, buf + 4, buf + 3, buf + 2, buf + 1, buf + 0, &last); + if (rc != NSAPI_MAC_BYTES || last != (NSAPI_MAC_SIZE - 1)) { - int last = -1; - int rc = - sscanf(mac_address, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx%n", buf + 5, buf + 4, buf + 3, buf + 2, buf + 1, buf + 0, &last); - if (rc != NSAPI_MAC_BYTES || last != (NSAPI_MAC_SIZE - 1)) - { - ChipLogError(DeviceLayer, "Failed to extract the MAC address: %s, rc = %d, last = %d", mac_address, rc, last); - return CHIP_ERROR_INTERNAL; - } - else - { - ChipLogError(DeviceLayer, "Extract the MAC address: %s", mac_address); - return CHIP_NO_ERROR; - } + ChipLogError(DeviceLayer, "Failed to extract the MAC address: %s, rc = %d, last = %d", mac_address, rc, last); + return CHIP_ERROR_INTERNAL; } else { - ChipLogError(DeviceLayer, "Failed to extract the MAC address: nothing returned by the interface"); - return CHIP_ERROR_INTERNAL; + ChipLogError(DeviceLayer, "Extract the MAC address: %s", mac_address); + return CHIP_NO_ERROR; } } else { - ChipLogError(DeviceLayer, "Failed to extract the MAC address: interface not available"); + ChipLogError(DeviceLayer, "Failed to extract the MAC address: nothing returned by the interface"); return CHIP_ERROR_INTERNAL; } } diff --git a/src/platform/mbed/ConnectivityManagerImpl.cpp b/src/platform/mbed/ConnectivityManagerImpl.cpp index 1a3ac24fa599d4..dcb2055c392742 100644 --- a/src/platform/mbed/ConnectivityManagerImpl.cpp +++ b/src/platform/mbed/ConnectivityManagerImpl.cpp @@ -18,7 +18,7 @@ */ /* this file behaves like a config.h, comes first */ -#include "netsocket/WiFiInterface.h" +#include #include #include @@ -123,7 +123,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init() mWiFiAPIdleTimeout = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT); mSecurityType = NSAPI_SECURITY_WPA_WPA2; - ::NetworkInterface * net_if = ::NetworkInterface::get_default_instance(); + auto net_if = get_mbed_net_if(); if (net_if == nullptr) { ChipLogError(DeviceLayer, "No network interface available"); diff --git a/third_party/mbed-os-posix-socket/repo b/third_party/mbed-os-posix-socket/repo index fd30baf86e7d9c..8797ebb01d5b3f 160000 --- a/third_party/mbed-os-posix-socket/repo +++ b/third_party/mbed-os-posix-socket/repo @@ -1 +1 @@ -Subproject commit fd30baf86e7d9cfbfbe91600ba5f76a7c9783f42 +Subproject commit 8797ebb01d5b3f96b59616eba65ee9b0d67e17c8