]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add MGMT_RX_PROCESS test command for hostapd
authorJouni Malinen <jouni@qca.qualcomm.com>
Tue, 29 Nov 2016 13:57:22 +0000 (15:57 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 29 Nov 2016 14:26:00 +0000 (16:26 +0200)
This makes it easier to write hwsim test cases to verify management
frame processing sequences with dropped or modified frames. When
ext_mgmt_frame_handling is used, this new command can be used to request
hostapd to process a received a management frame, e.g., based on
information reported in the MGMT-RX events.

This is more or less identical to the earlier wpa_supplicant commit
4de70e2330c54c32f42a5fc93517d65c0a2c3be9 ('Add MGMT_RX_PROCESS test
command for wpa_supplicant'), but for hostapd.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
hostapd/ctrl_iface.c

index 4acc06443c7de1db192d4e3e7c99bf37ad95b57d..b9d9411e96e33e3032875812dc1f756ec2373158 100644 (file)
@@ -1562,6 +1562,76 @@ static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data *hapd, char *cmd)
 }
 
 
+static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data *hapd,
+                                             char *cmd)
+{
+       char *pos, *param;
+       size_t len;
+       u8 *buf;
+       int freq = 0, datarate = 0, ssi_signal = 0;
+       union wpa_event_data event;
+
+       if (!hapd->ext_mgmt_frame_handling)
+               return -1;
+
+       /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
+
+       wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
+
+       pos = cmd;
+       param = os_strstr(pos, "freq=");
+       if (param) {
+               param += 5;
+               freq = atoi(param);
+       }
+
+       param = os_strstr(pos, " datarate=");
+       if (param) {
+               param += 10;
+               datarate = atoi(param);
+       }
+
+       param = os_strstr(pos, " ssi_signal=");
+       if (param) {
+               param += 12;
+               ssi_signal = atoi(param);
+       }
+
+       param = os_strstr(pos, " frame=");
+       if (param == NULL)
+               return -1;
+       param += 7;
+
+       len = os_strlen(param);
+       if (len & 1)
+               return -1;
+       len /= 2;
+
+       buf = os_malloc(len);
+       if (buf == NULL)
+               return -1;
+
+       if (hexstr2bin(param, buf, len) < 0) {
+               os_free(buf);
+               return -1;
+       }
+
+       os_memset(&event, 0, sizeof(event));
+       event.rx_mgmt.freq = freq;
+       event.rx_mgmt.frame = buf;
+       event.rx_mgmt.frame_len = len;
+       event.rx_mgmt.ssi_signal = ssi_signal;
+       event.rx_mgmt.datarate = datarate;
+       hapd->ext_mgmt_frame_handling = 0;
+       wpa_supplicant_event(hapd, EVENT_RX_MGMT, &event);
+       hapd->ext_mgmt_frame_handling = 1;
+
+       os_free(buf);
+
+       return 0;
+}
+
+
 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data *hapd, char *cmd)
 {
        char *pos;
@@ -2517,6 +2587,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
        } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
                if (hostapd_ctrl_iface_mgmt_tx(hapd, buf + 8))
                        reply_len = -1;
+       } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
+               if (hostapd_ctrl_iface_mgmt_rx_process(hapd, buf + 16) < 0)
+                       reply_len = -1;
        } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
                if (hostapd_ctrl_iface_eapol_rx(hapd, buf + 9) < 0)
                        reply_len = -1;