Skip to content

Commit 60a2888

Browse files
ndrs-pstkartben
authored andcommitted
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 e1faa19 commit 60a2888

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
@@ -354,10 +354,35 @@ static void esp_wifi_handle_ap_connect_event(void *event_data)
354354

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

357+
wifi_sta_list_t sta_list;
357358
struct wifi_ap_sta_info sta_info;
358359

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

363388
if (!(esp32_data.ap_connection_cnt++)) {
@@ -377,6 +402,8 @@ static void esp_wifi_handle_ap_disconnect_event(void *event_data)
377402
LOG_DBG("station " MACSTR " leave, AID=%d", MAC2STR(event->mac), event->aid);
378403
struct wifi_ap_sta_info sta_info;
379404

405+
sta_info.link_mode = WIFI_LINK_MODE_UNKNOWN;
406+
sta_info.twt_capable = false; /* Only support in 802.11ax */
380407
sta_info.mac_length = WIFI_MAC_ADDR_LEN;
381408
memcpy(sta_info.mac, event->mac, WIFI_MAC_ADDR_LEN);
382409
wifi_mgmt_raise_ap_sta_disconnected_event(iface, &sta_info);

0 commit comments

Comments
 (0)