Skip to content

Commit d62ccb0

Browse files
committed
wifi: esp32: enhance handling of AP connect events
This commit aims to improve the integration of `esp_wifi_drv` by providing the link mode information to `wifi_mgmt` when a station device is connected to the AP. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent 5b15751 commit d62ccb0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

drivers/wifi/esp32/src/esp_wifi_drv.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,35 @@ static void esp_wifi_handle_ap_connect_event(void *event_data)
350350

351351
LOG_DBG("Station " MACSTR " join, AID=%d", MAC2STR(event->mac), event->aid);
352352

353+
wifi_sta_list_t sta_list;
353354
struct wifi_ap_sta_info sta_info;
354355

356+
sta_info.link_mode = WIFI_LINK_MODE_UNKNOWN;
357+
sta_info.twt_capable = false; /* Only support in 802.11ax */
355358
sta_info.mac_length = WIFI_MAC_ADDR_LEN;
356359
memcpy(sta_info.mac, event->mac, WIFI_MAC_ADDR_LEN);
360+
361+
/* Expect the return value to always be ESP_OK,
362+
* since it is called in esp_wifi_event_handler()
363+
*/
364+
(void)esp_wifi_ap_get_sta_list(&sta_list);
365+
for (int i = 0; i < sta_list.num; i++) {
366+
wifi_sta_info_t *sta = &sta_list.sta[i];
367+
368+
if (memcmp(event->mac, sta->mac, 6) == 0) {
369+
if (sta->phy_11n) {
370+
sta_info.link_mode = WIFI_4;
371+
} else if (sta->phy_11g) {
372+
sta_info.link_mode = WIFI_3;
373+
} else if (sta->phy_11b) {
374+
sta_info.link_mode = WIFI_1;
375+
} else {
376+
sta_info.link_mode = WIFI_LINK_MODE_UNKNOWN;
377+
}
378+
break;
379+
}
380+
}
381+
357382
wifi_mgmt_raise_ap_sta_connected_event(iface, &sta_info);
358383

359384
if (!(esp32_data.ap_connection_cnt++)) {
@@ -373,6 +398,8 @@ static void esp_wifi_handle_ap_disconnect_event(void *event_data)
373398
LOG_DBG("station " MACSTR " leave, AID=%d", MAC2STR(event->mac), event->aid);
374399
struct wifi_ap_sta_info sta_info;
375400

401+
sta_info.link_mode = WIFI_LINK_MODE_UNKNOWN;
402+
sta_info.twt_capable = false; /* Only support in 802.11ax */
376403
sta_info.mac_length = WIFI_MAC_ADDR_LEN;
377404
memcpy(sta_info.mac, event->mac, WIFI_MAC_ADDR_LEN);
378405
wifi_mgmt_raise_ap_sta_disconnected_event(iface, &sta_info);

0 commit comments

Comments
 (0)