Skip to content

Commit 83812f2

Browse files
nxf58150aescolar
authored andcommitted
modules: hostap: add 11k/v/r roaming support
Added new ops and events in glue layer to support roaming. Added new flag WIFI_NM_WPA_SUPPLICANT_ROAMING to control roaming feature. Signed-off-by: Hui Bai <[email protected]>
1 parent 91ec46e commit 83812f2

File tree

11 files changed

+396
-0
lines changed

11 files changed

+396
-0
lines changed

include/zephyr/net/wifi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ enum wifi_security_type {
7878
WIFI_SECURITY_TYPE_EAP_PEAP_TLS,
7979
/** EAP TLS SHA256 security - Enterprise. */
8080
WIFI_SECURITY_TYPE_EAP_TLS_SHA256,
81+
/** FT-PSK security */
82+
WIFI_SECURITY_TYPE_FT_PSK,
83+
/** FT-SAE security */
84+
WIFI_SECURITY_TYPE_FT_SAE,
85+
/** FT-EAP security */
86+
WIFI_SECURITY_TYPE_FT_EAP,
87+
/** FT-EAP-SHA384 security */
88+
WIFI_SECURITY_TYPE_FT_EAP_SHA384,
8189

8290
/** @cond INTERNAL_HIDDEN */
8391
__WIFI_SECURITY_TYPE_AFTER_LAST,

include/zephyr/net/wifi_mgmt.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ enum net_request_wifi_cmd {
117117
/** Connect to APs stored using wifi_credentials library. */
118118
NET_REQUEST_WIFI_CMD_CONNECT_STORED,
119119
#endif
120+
/** Start roaming */
121+
NET_REQUEST_WIFI_CMD_START_ROAMING,
122+
/** Neighbor report complete */
123+
NET_REQUEST_WIFI_CMD_NEIGHBOR_REP_COMPLETE,
124+
/** Specific scan */
125+
NET_REQUEST_WIFI_CMD_CANDIDATE_SCAN,
120126
/** @cond INTERNAL_HIDDEN */
121127
NET_REQUEST_WIFI_CMD_MAX
122128
/** @endcond */
@@ -282,6 +288,16 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG);
282288
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CONNECT_STORED);
283289
#endif
284290

291+
#define NET_REQUEST_WIFI_START_ROAMING \
292+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_START_ROAMING)
293+
294+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_START_ROAMING);
295+
296+
#define NET_REQUEST_WIFI_NEIGHBOR_REP_COMPLETE \
297+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_NEIGHBOR_REP_COMPLETE)
298+
299+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_NEIGHBOR_REP_COMPLETE);
300+
285301
/** @brief Wi-Fi management events */
286302
enum net_event_wifi_cmd {
287303
/** Scan results available */
@@ -304,6 +320,12 @@ enum net_event_wifi_cmd {
304320
NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT,
305321
/** Disconnect complete */
306322
NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE,
323+
/** Signal change event */
324+
NET_EVENT_WIFI_CMD_SIGNAL_CHANGE,
325+
/** Neighbor Report */
326+
NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED,
327+
/** Neighbor Report complete */
328+
NET_EVENT_WIFI_CMD_NEIGHBOR_REP_COMPLETE,
307329
/** AP mode enable result */
308330
NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT,
309331
/** AP mode disable result */
@@ -352,6 +374,14 @@ enum net_event_wifi_cmd {
352374
#define NET_EVENT_WIFI_DISCONNECT_COMPLETE \
353375
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE)
354376

377+
/** Event signal change of connected AP */
378+
#define NET_EVENT_WIFI_SIGNAL_CHANGE \
379+
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_SIGNAL_CHANGE)
380+
381+
/** Event Neighbor Report Completed */
382+
#define NET_EVENT_WIFI_NEIGHBOR_REP_COMP \
383+
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_NEIGHBOR_REP_COMPLETE)
384+
355385
/** Event emitted for Wi-Fi access point enable result */
356386
#define NET_EVENT_WIFI_AP_ENABLE_RESULT \
357387
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT)
@@ -1417,6 +1447,21 @@ struct wifi_mgmt_ops {
14171447
* @return 0 if ok, < 0 if error
14181448
*/
14191449
int (*wps_config)(const struct device *dev, struct wifi_wps_config_params *params);
1450+
/** Trigger candidate scan
1451+
*
1452+
* @param dev Pointer to the device structure for the driver instance
1453+
* @param params Scan parameters
1454+
*
1455+
* @return 0 if ok, < 0 if error
1456+
*/
1457+
int (*candidate_scan)(const struct device *dev, struct wifi_scan_params *params);
1458+
/** Start 11r roaming
1459+
*
1460+
* @param dev Pointer to the device structure for the driver instance
1461+
*
1462+
* @return 0 if ok, < 0 if error
1463+
*/
1464+
int (*start_11r_roaming)(const struct device *dev);
14201465
};
14211466

14221467
/** Wi-Fi management offload API */
@@ -1508,6 +1553,17 @@ void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface,
15081553
*/
15091554
void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, int status);
15101555

1556+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
1557+
/** Wi-Fi management neighbor reports event
1558+
*
1559+
* @param iface Network interface
1560+
* @param inbuf Input buffer of neighbor reports
1561+
* @param buf_len Lenghth of input buffer
1562+
*/
1563+
void wifi_mgmt_raise_neighbor_rep_recv_event(struct net_if *iface,
1564+
char *inbuf, size_t buf_len);
1565+
#endif
1566+
15111567
/** Wi-Fi management AP mode enable result event
15121568
*
15131569
* @param iface Network interface

modules/hostap/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,23 @@ if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
303303
default 16384
304304
endif
305305

306+
config WIFI_NM_WPA_SUPPLICANT_ROAMING
307+
bool "Roaming support"
308+
imply IEEE80211R
309+
help
310+
Enable roaming support with wpa_supplicant. When current BSS RSSI drops,
311+
STA will try to find an AP with better RSSI. If found, STA will reassociate
312+
to the new AP automatically without losing connection.
313+
314+
config WIFI_NM_WPA_SUPPLICANT_SKIP_DHCP_ON_ROAMING
315+
bool "Skip DHCP after roaming to new AP"
316+
help
317+
For L2 roaming, the original AP and new AP are in the same subnet, client
318+
can use same IP address and skip DHCP. Enable this to skip DHCP.
319+
For L3 roaming, the original AP and new AP are in different subnet, client
320+
needs to get new IP address after roaming to new AP. Disable this to keep
321+
DHCP after roaming.
322+
306323
# Create hidden config options that are used in hostap. This way we do not need
307324
# to mark them as allowed for CI checks, and also someone else cannot use the
308325
# same name options.

modules/hostap/src/supp_api.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ static inline enum wifi_security_type wpas_key_mgmt_to_zephyr(int key_mgmt, int
380380
return WIFI_SECURITY_TYPE_SAE;
381381
case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK:
382382
return WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL;
383+
case WPA_KEY_MGMT_FT_PSK:
384+
return WIFI_SECURITY_TYPE_FT_PSK;
385+
case WPA_KEY_MGMT_FT_SAE:
386+
return WIFI_SECURITY_TYPE_FT_SAE;
387+
case WPA_KEY_MGMT_FT_IEEE8021X:
388+
return WIFI_SECURITY_TYPE_FT_EAP;
389+
case WPA_KEY_MGMT_FT_IEEE8021X_SHA384:
390+
return WIFI_SECURITY_TYPE_FT_EAP_SHA384;
383391
default:
384392
return WIFI_SECURITY_TYPE_UNKNOWN;
385393
}
@@ -1435,6 +1443,71 @@ int supplicant_11k_neighbor_request(const struct device *dev, struct wifi_11k_pa
14351443
return 0;
14361444
}
14371445

1446+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
1447+
#define SUPPLICANT_CANDIDATE_SCAN_CMD_BUF_SIZE 100
1448+
int supplicant_candidate_scan(const struct device *dev, struct wifi_scan_params *params)
1449+
{
1450+
int i = 0;
1451+
char cmd[SUPPLICANT_CANDIDATE_SCAN_CMD_BUF_SIZE] = {0};
1452+
char *pos = cmd;
1453+
char *end = pos + SUPPLICANT_CANDIDATE_SCAN_CMD_BUF_SIZE;
1454+
int freq = 0;
1455+
1456+
strcpy(pos, "freq=");
1457+
pos += 5;
1458+
while (params->band_chan[i].channel) {
1459+
if (i > 0) {
1460+
pos += snprintf(pos, end - pos, ",");
1461+
}
1462+
freq = chan_to_freq(params->band_chan[i].channel);
1463+
pos += snprintf(pos, end - pos, "%d", freq);
1464+
i++;
1465+
}
1466+
1467+
if (!wpa_cli_cmd_v("scan %s", cmd)) {
1468+
wpa_printf(MSG_ERROR,
1469+
"%s: cli cmd <scan %s> fail",
1470+
__func__, cmd);
1471+
return -1;
1472+
}
1473+
1474+
return 0;
1475+
}
1476+
1477+
int supplicant_11r_roaming(const struct device *dev)
1478+
{
1479+
struct wpa_supplicant *wpa_s;
1480+
int ret = 0;
1481+
1482+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
1483+
1484+
wpa_s = get_wpa_s_handle(dev);
1485+
if (!wpa_s) {
1486+
wpa_printf(MSG_ERROR, "Device %s not found", dev->name);
1487+
ret = -1;
1488+
goto out;
1489+
}
1490+
1491+
if (wpa_s->reassociate || (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1492+
wpa_s->wpa_state < WPA_COMPLETED)) {
1493+
wpa_printf(MSG_INFO, "Reassociation is in progress, skip");
1494+
ret = 0;
1495+
goto out;
1496+
}
1497+
1498+
if (!wpa_cli_cmd_v("reassociate")) {
1499+
wpa_printf(MSG_ERROR, "%s: cli cmd <reassociate> fail",
1500+
__func__);
1501+
ret = -1;
1502+
goto out;
1503+
}
1504+
1505+
out:
1506+
k_mutex_unlock(&wpa_supplicant_mutex);
1507+
return ret;
1508+
}
1509+
#endif
1510+
14381511
int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *params)
14391512
{
14401513
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);

modules/hostap/src/supp_api.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ int supplicant_11k_cfg(const struct device *dev, struct wifi_11k_params *params)
118118
*/
119119
int supplicant_11k_neighbor_request(const struct device *dev, struct wifi_11k_params *params);
120120

121+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
122+
/** Send candidate scan request
123+
*
124+
* @param dev Pointer to the device structure for the driver instance.
125+
* @param params Scan parameters
126+
*
127+
* @return 0 if ok, < 0 if error
128+
*/
129+
int supplicant_candidate_scan(const struct device *dev, struct wifi_scan_params *params);
130+
131+
/** Send 11r roaming request
132+
*
133+
* @param dev Pointer to the device structure for the driver instance.
134+
*
135+
* @return 0 if ok, < 0 if error
136+
*/
137+
int supplicant_11r_roaming(const struct device *dev);
138+
#endif
139+
121140
/**
122141
* @brief Set Wi-Fi power save configuration
123142
*

modules/hostap/src/supp_events.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,21 @@ int supplicant_send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd
368368
iface,
369369
*(int *)supplicant_status);
370370
break;
371+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
372+
case NET_EVENT_WIFI_CMD_SIGNAL_CHANGE:
373+
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_SIGNAL_CHANGE,
374+
iface, NULL, 0);
375+
break;
376+
case NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED:
377+
wifi_mgmt_raise_neighbor_rep_recv_event(
378+
iface,
379+
(char *)supplicant_status, len);
380+
break;
381+
case NET_EVENT_WIFI_CMD_NEIGHBOR_REP_COMPLETE:
382+
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_NEIGHBOR_REP_COMP,
383+
iface, NULL, 0);
384+
break;
385+
#endif
371386
#ifdef CONFIG_AP
372387
case NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT:
373388
wifi_mgmt_raise_ap_enable_result_event(iface,

modules/hostap/src/supp_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ static const struct wifi_mgmt_ops mgmt_ops = {
6464
#endif
6565
.cfg_11k = supplicant_11k_cfg,
6666
.send_11k_neighbor_request = supplicant_11k_neighbor_request,
67+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
68+
.candidate_scan = supplicant_candidate_scan,
69+
.start_11r_roaming = supplicant_11r_roaming,
70+
#endif
6771
.set_power_save = supplicant_set_power_save,
6872
.set_twt = supplicant_set_twt,
6973
.get_power_save_config = supplicant_get_power_save_config,

samples/net/wifi/boards/frdm_rw612.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
8888
CONFIG_SAE_PWE_EARLY_EXIT=y
8989
CONFIG_WIFI_NM_HOSTAPD_AP=y
9090
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
91+
CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING=y
92+
CONFIG_WIFI_NM_WPA_SUPPLICANT_SKIP_DHCP_ON_ROAMING=y
9193

9294
# Enable mbedtls
9395
CONFIG_MBEDTLS=y

samples/net/wifi/boards/rd_rw612_bga.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
8787
CONFIG_SAE_PWE_EARLY_EXIT=y
8888
CONFIG_WIFI_NM_HOSTAPD_AP=y
8989
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
90+
CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING=y
91+
CONFIG_WIFI_NM_WPA_SUPPLICANT_SKIP_DHCP_ON_ROAMING=y
9092

9193
# Enable mbedtls
9294
CONFIG_MBEDTLS=y

0 commit comments

Comments
 (0)