Skip to content

Commit

Permalink
Adds support for using the stored setting for AP/STA mode. (#436)
Browse files Browse the repository at this point in the history
Adds WlanRole::DEFAULT as an argument to the start() method that allows
to use the AP/STA setting from the NWP stored configuration instead of
from the application.

Adds wlan_set_role to override such configuration.

Fixes a bug where the IP address handed out via DHCP was incorrectly
saved in the AP's own IP address variable. This caused the "is local
connection" check in SocketClient to misbehave in AP mode.
  • Loading branch information
balazsracz committed Sep 26, 2020
1 parent fcf9b13 commit 4e3f14b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/freertos_drivers/common/WifiDefs.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ enum class WlanState : uint8_t
*/
enum class WlanRole : uint8_t
{
UNKNOWN = 0, /**< Wi-Fi station mode */
STA, /**< Wi-Fi station mode */
AP /**< Wi-Fi access point mode */
UNKNOWN = 0, /**< Default mode (from stored configuration) */
DEFAULT = UNKNOWN, /**< Default mode (from stored configuration) */
STA, /**< Wi-Fi station mode */
AP /**< Wi-Fi access point mode */
};

enum class CountryCode : uint8_t
Expand Down
25 changes: 22 additions & 3 deletions src/freertos_drivers/net_cc32xx/CC32xxWiFi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,10 @@ void CC32xxWiFi::set_default_state()
}

SlCheckError(result);
if (wlanRole == WlanRole::AP)
if (wlanRole == WlanRole::AP ||
(wlanRole == WlanRole::UNKNOWN && result == ROLE_AP))
{
wlanRole = WlanRole::AP;
if (result != ROLE_AP)
{
sl_WlanSetMode(ROLE_AP);
Expand All @@ -821,6 +823,7 @@ void CC32xxWiFi::set_default_state()
}
else
{
wlanRole = WlanRole::STA;
if (wlan_profile_test_none())
{
/* no profiles saved, add the default profile */
Expand All @@ -845,6 +848,24 @@ void CC32xxWiFi::set_default_state()
started = true;
}

/*
* CC32xxWiFi::wlan_set_role()
*/
void CC32xxWiFi::wlan_set_role(WlanRole new_role)
{
switch (new_role)
{
case WlanRole::STA:
sl_WlanSetMode(ROLE_STA);
break;
case WlanRole::AP:
sl_WlanSetMode(ROLE_AP);
break;
default:
DIE("Unsupported wlan role");
}
}

/*
* CC32xxWiFi::wlan_task()
*/
Expand Down Expand Up @@ -1192,8 +1213,6 @@ void CC32xxWiFi::net_app_event_handler(NetAppEvent *event)
// event_data = &event->EventData.ipLeased;
//

SlIpLeasedAsync_t *ip_leased = &event->Data.IpLeased;
ipAddress = ip_leased->IpAddress;
break;
}
case SL_NETAPP_EVENT_IP_COLLISION:
Expand Down
7 changes: 7 additions & 0 deletions src/freertos_drivers/net_cc32xx/CC32xxWiFi.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ public:
return wlanRole;
}

/** Change the default Wlan Role. This will be used in the next start(...)
* if the UNKNOWN role is specified. The new setting takes effect when the
* device is restarted (either via reboot or stop + start).
* @param role new role. Must not be UNKNOWN
*/
void wlan_set_role(WlanRole new_role);

/** @return 0 if !wlan_ready, else a debugging status code. */
WlanState wlan_startup_state()
{
Expand Down

0 comments on commit 4e3f14b

Please sign in to comment.