From: Marek Puzyniak Date: Wed, 9 Oct 2024 08:15:02 +0000 (+0200) Subject: Introduce DUMP_BEACON command X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df0b6fa900c7deee83fdaeff1723df315ab6be40;p=thirdparty%2Fhostap.git Introduce DUMP_BEACON command Occasionally, external applications require information about AP configurations and capabilities. One potentially useful source for this is the Beacon frame content. To support this need, introduce a new control interface command: DUMP_BEACON. This return a hexdump of the Beacon frame template, i.e., IEEE 802.11 frame header and frame body with the TIM element missing since it is added by the driver and some of the fields like the Timestamp field left to all zeros since they will be filled in by the driver/hardware. This can be fetched with hostapd_cli: hostapd_cli -i wlxxx raw DUMP_BEACON 80000000ffffffffffff... 7f080400000200000040dd180050f2020101010003a4000027a4000042435e0062322f00 Signed-off-by: Marek Puzyniak --- diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index 50704a675..e282faacc 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -3206,6 +3206,7 @@ static int hostapd_ctrl_iface_log_level(struct hostapd_data *hapd, char *cmd, #ifdef NEED_AP_MLME + static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data *hapd, char *buf, size_t buflen) { @@ -3239,6 +3240,35 @@ static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data *hapd, return pos - buf; } + + +static int hostapd_ctrl_iface_dump_beacon(struct hostapd_data *hapd, + char *buf, size_t buflen) +{ + struct beacon_data beacon; + char *pos, *end; + int ret; + + if (hostapd_build_beacon_data(hapd, &beacon) < 0) + return -1; + + if (2 * (beacon.head_len + beacon.tail_len) > buflen) + return -1; + + pos = buf; + end = buf + buflen; + + ret = wpa_snprintf_hex(pos, end - pos, beacon.head, beacon.head_len); + pos += ret; + + ret = wpa_snprintf_hex(pos, end - pos, beacon.tail, beacon.tail_len); + pos += ret; + + free_beacon_data(&beacon); + + return pos - buf; +} + #endif /* NEED_AP_MLME */ @@ -4343,6 +4373,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, } else if (os_strcmp(buf, "TRACK_STA_LIST") == 0) { reply_len = hostapd_ctrl_iface_track_sta_list( hapd, reply, reply_size); + } else if (os_strcmp(buf, "DUMP_BEACON") == 0) { + reply_len = hostapd_ctrl_iface_dump_beacon(hapd, reply, + reply_size); #endif /* NEED_AP_MLME */ } else if (os_strcmp(buf, "PMKSA") == 0) { reply_len = hostapd_ctrl_iface_pmksa_list(hapd, reply, diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index a850eaf2b..06e837afc 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -4227,8 +4227,8 @@ void free_beacon_data(struct beacon_data *beacon) } -static int hostapd_build_beacon_data(struct hostapd_data *hapd, - struct beacon_data *beacon) +int hostapd_build_beacon_data(struct hostapd_data *hapd, + struct beacon_data *beacon) { struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra; struct wpa_driver_ap_params params; diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 8edfc827c..0cb5e14a1 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -862,6 +862,8 @@ int hostapd_mld_remove_link(struct hostapd_data *hapd); u8 hostapd_get_active_links(struct hostapd_data *hapd); struct hostapd_data * hostapd_mld_get_first_bss(struct hostapd_data *hapd); +int hostapd_build_beacon_data(struct hostapd_data *hapd, + struct beacon_data *beacon); void free_beacon_data(struct beacon_data *beacon); int hostapd_fill_cca_settings(struct hostapd_data *hapd, struct cca_settings *settings);