hostapd: Add control interface test commands for radar detection
authorJouni Malinen <j@w1.fi>
Sat, 2 Nov 2013 18:44:58 +0000 (20:44 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 3 Nov 2013 09:31:48 +0000 (11:31 +0200)
If hostapd is build with CONFIG_TESTING_OPTIONS=y, the RADAR control
interface command can be used to test hostapd behavior on arbitrary
driver radar events.

Signed-hostap: Jouni Malinen <j@w1.fi>

hostapd/ctrl_iface.c

index e6758d9..3bc7379 100644 (file)
@@ -1050,6 +1050,67 @@ static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
 }
 
 
+#ifdef CONFIG_TESTING_OPTIONS
+static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
+{
+       union wpa_event_data data;
+       char *pos, *param;
+       enum wpa_event_type event;
+
+       wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
+
+       os_memset(&data, 0, sizeof(data));
+
+       param = os_strchr(cmd, ' ');
+       if (param == NULL)
+               return -1;
+       *param++ = '\0';
+
+       if (os_strcmp(cmd, "DETECTED") == 0)
+               event = EVENT_DFS_RADAR_DETECTED;
+       else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
+               event = EVENT_DFS_CAC_FINISHED;
+       else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
+               event = EVENT_DFS_CAC_ABORTED;
+       else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
+               event = EVENT_DFS_NOP_FINISHED;
+       else {
+               wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
+                          cmd);
+               return -1;
+       }
+
+       pos = os_strstr(param, "freq=");
+       if (pos)
+               data.dfs_event.freq = atoi(pos + 5);
+
+       pos = os_strstr(param, "ht_enabled=1");
+       if (pos)
+               data.dfs_event.ht_enabled = 1;
+
+       pos = os_strstr(param, "chan_offset=");
+       if (pos)
+               data.dfs_event.chan_offset = atoi(pos + 12);
+
+       pos = os_strstr(param, "chan_width=");
+       if (pos)
+               data.dfs_event.chan_width = atoi(pos + 11);
+
+       pos = os_strstr(param, "cf1=");
+       if (pos)
+               data.dfs_event.cf1 = atoi(pos + 4);
+
+       pos = os_strstr(param, "cf2=");
+       if (pos)
+               data.dfs_event.cf2 = atoi(pos + 4);
+
+       wpa_supplicant_event(hapd, event, &data);
+
+       return 0;
+}
+#endif /* CONFIG_TESTING_OPTIONS */
+
+
 static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
                                       void *sock_ctx)
 {
@@ -1228,6 +1289,11 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
        } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
                if (hostapd_ctrl_iface_disable(hapd->iface))
                        reply_len = -1;
+#ifdef CONFIG_TESTING_OPTIONS
+       } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
+               if (hostapd_ctrl_iface_radar(hapd, buf + 6))
+                       reply_len = -1;
+#endif /* CONFIG_TESTING_OPTIONS */
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;