Skip to content

Commit 0e59cf4

Browse files
GaofengZhangNXPkartben
authored andcommitted
hostap: support legacy roaming
There are currently four types of roaming, 11r roaming, 11v roaming, 11k roaming and legacy roaming, The priority of the roaming mode is 11r-->11v-->11k-->legacy roaming. If the ap does not support 11r/11v/11k roaming, we will use legacy roaming. legecy roaming needs to do full channel scan, which is the same as the general scan connection process, so the legacy roaming time will be longer. Signed-off-by: Gaofeng Zhang <[email protected]>
1 parent 63904f3 commit 0e59cf4

File tree

5 files changed

+98
-7
lines changed

5 files changed

+98
-7
lines changed

include/zephyr/net/wifi_mgmt.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,15 @@ enum wifi_sap_iface_state {
12611261
WIFI_SAP_IFACE_ENABLED
12621262
};
12631263

1264+
/* Extended Capabilities */
1265+
enum wifi_ext_capab {
1266+
WIFI_EXT_CAPAB_20_40_COEX = 0,
1267+
WIFI_EXT_CAPAB_GLK = 1,
1268+
WIFI_EXT_CAPAB_EXT_CHAN_SWITCH = 2,
1269+
WIFI_EXT_CAPAB_TIM_BROADCAST = 18,
1270+
WIFI_EXT_CAPAB_BSS_TRANSITION = 19,
1271+
};
1272+
12641273
#include <zephyr/net/net_if.h>
12651274

12661275
/** Scan result callback
@@ -1454,6 +1463,23 @@ struct wifi_mgmt_ops {
14541463
*/
14551464
int (*btm_query)(const struct device *dev, uint8_t reason);
14561465
#endif
1466+
/** Judge ap whether support the capability
1467+
*
1468+
* @param dev Pointer to the device structure for the driver instance.
1469+
* @param capab is the capability to judge
1470+
*
1471+
* @return 1 if support, 0 if not support
1472+
*/
1473+
int (*bss_ext_capab)(const struct device *dev, int capab);
1474+
1475+
/** Send legacy scan
1476+
*
1477+
* @param dev Pointer to the device structure for the driver instance.
1478+
*
1479+
* @return 0 if ok, < 0 if error
1480+
*/
1481+
int (*legacy_roam)(const struct device *dev);
1482+
14571483
/** Get Version of WiFi driver and Firmware
14581484
*
14591485
* The driver that implements the get_version function must not use stack to allocate the

modules/hostap/src/supp_api.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "includes.h"
1414
#include "common.h"
1515
#include "common/defs.h"
16+
#include "common/ieee802_11_defs.h"
17+
#include "common/ieee802_11_common.h"
1618
#include "wpa_supplicant/config.h"
1719
#include "wpa_supplicant_i.h"
1820
#include "driver_i.h"
@@ -26,6 +28,7 @@
2628
#include "ap_drv_ops.h"
2729
#endif
2830
#include "supp_events.h"
31+
#include "wpa_supplicant/bss.h"
2932

3033
extern struct k_sem wpa_supplicant_ready_sem;
3134
extern struct wpa_global *global;
@@ -1944,6 +1947,41 @@ int supplicant_get_rts_threshold(const struct device *dev, unsigned int *rts_thr
19441947
return wifi_mgmt_api->get_rts_threshold(dev, rts_threshold);
19451948
}
19461949

1950+
int supplicant_bss_ext_capab(const struct device *dev, int capab)
1951+
{
1952+
struct wpa_supplicant *wpa_s;
1953+
int is_support = 0;
1954+
1955+
wpa_s = get_wpa_s_handle(dev);
1956+
if (!wpa_s) {
1957+
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
1958+
return 0;
1959+
}
1960+
1961+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
1962+
is_support = wpa_bss_ext_capab(wpa_s->current_bss, capab);
1963+
k_mutex_unlock(&wpa_supplicant_mutex);
1964+
1965+
return is_support;
1966+
}
1967+
1968+
int supplicant_legacy_roam(const struct device *dev)
1969+
{
1970+
int ret = -1;
1971+
1972+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
1973+
if (!wpa_cli_cmd_v("scan")) {
1974+
goto out;
1975+
}
1976+
1977+
ret = 0;
1978+
1979+
out:
1980+
k_mutex_unlock(&wpa_supplicant_mutex);
1981+
1982+
return ret;
1983+
}
1984+
19471985
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
19481986
int supplicant_btm_query(const struct device *dev, uint8_t reason)
19491987
{

modules/hostap/src/supp_api.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,23 @@ int supplicant_get_rts_threshold(const struct device *dev, unsigned int *rts_thr
252252
int supplicant_btm_query(const struct device *dev, uint8_t reason);
253253
#endif
254254

255+
/** Send legacy roam
256+
*
257+
* @param dev Pointer to the device structure for the driver instance.
258+
*
259+
* @return 0 if ok, < 0 if error
260+
*/
261+
int supplicant_legacy_roam(const struct device *dev);
262+
263+
/** Judge ap whether support the capability
264+
*
265+
* @param dev Pointer to the device structure for the driver instance.
266+
* @param capab is the capability to judge
267+
*
268+
* @return 1 if support, 0 if not support
269+
*/
270+
int supplicant_bss_ext_capab(const struct device *dev, int capab);
271+
255272
/** Get Wi-Fi connection parameters recently used
256273
*
257274
* @param dev Pointer to the device structure for the driver instance

modules/hostap/src/supp_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ static const struct wifi_mgmt_ops mgmt_ops = {
7777
.channel = supplicant_channel,
7878
.set_rts_threshold = supplicant_set_rts_threshold,
7979
.get_rts_threshold = supplicant_get_rts_threshold,
80+
.bss_ext_capab = supplicant_bss_ext_capab,
81+
.legacy_roam = supplicant_legacy_roam,
8082
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
8183
.btm_query = supplicant_btm_query,
8284
#endif

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,26 +477,34 @@ static int wifi_start_roaming(uint32_t mgmt_request, struct net_if *iface,
477477
const struct device *dev = net_if_get_device(iface);
478478
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
479479

480+
if (wifi_mgmt_api == NULL) {
481+
return -ENOTSUP;
482+
}
480483
if (roaming_params.is_11r_used) {
481-
if (wifi_mgmt_api == NULL ||
482-
wifi_mgmt_api->start_11r_roaming == NULL) {
484+
if (wifi_mgmt_api->start_11r_roaming == NULL) {
483485
return -ENOTSUP;
484486
}
485487

486488
return wifi_mgmt_api->start_11r_roaming(dev);
487489
} else if (roaming_params.is_11k_enabled) {
488490
memset(&roaming_params.neighbor_rep, 0x0, sizeof(roaming_params.neighbor_rep));
489-
if (wifi_mgmt_api == NULL
490-
|| wifi_mgmt_api->send_11k_neighbor_request == NULL) {
491+
if (wifi_mgmt_api->send_11k_neighbor_request == NULL) {
491492
return -ENOTSUP;
492493
}
493494

494495
return wifi_mgmt_api->send_11k_neighbor_request(dev, NULL);
495-
} else if (wifi_mgmt_api == NULL || wifi_mgmt_api->btm_query == NULL) {
496+
} else if (wifi_mgmt_api->bss_ext_capab &&
497+
wifi_mgmt_api->bss_ext_capab(dev, WIFI_EXT_CAPAB_BSS_TRANSITION)) {
498+
if (wifi_mgmt_api->btm_query) {
499+
return wifi_mgmt_api->btm_query(dev, 0x10);
500+
} else {
501+
return -ENOTSUP;
502+
}
503+
} else if (wifi_mgmt_api->legacy_roam) {
504+
return wifi_mgmt_api->legacy_roam(dev);
505+
} else {
496506
return -ENOTSUP;
497507
}
498-
499-
return wifi_mgmt_api->btm_query(dev, 0x10);
500508
}
501509

502510
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_START_ROAMING, wifi_start_roaming);

0 commit comments

Comments
 (0)