Skip to content

Commit

Permalink
[Mbed] Fix WiFi provisioning (#11982)
Browse files Browse the repository at this point in the history
* Increase session establishment timeout to 40s

* Update mbed-os-posix-socket lib
Improve get default network interface

* Fix condition in GetPrimaryWiFiMACAddress
  • Loading branch information
ATmobica authored and pull[bot] committed Aug 30, 2023
1 parent 06d85d6 commit 4146257
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
39 changes: 19 additions & 20 deletions src/platform/mbed/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

// mbed-os headers
#include "platform/mbed_power_mgmt.h"
#include <net_common.h>

namespace chip {
namespace DeviceLayer {
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/mbed/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
/* this file behaves like a config.h, comes first */

#include "netsocket/WiFiInterface.h"
#include <net_common.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <platform/ConnectivityManager.h>
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 4146257

Please sign in to comment.