hostapd: Add testing option to override own WPA/RSN IE(s)
authorJouni Malinen <j@w1.fi>
Sat, 8 Aug 2015 15:18:03 +0000 (18:18 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 8 Aug 2015 15:18:03 +0000 (18:18 +0300)
This allows the new own_ie_override=<hexdump> configuration parameter to
be used to replace the normally generated WPA/RSN IE(s) for testing
purposes in CONFIG_TESTING_OPTIONS=y builds.

Signed-off-by: Jouni Malinen <j@w1.fi>
hostapd/config_file.c
src/ap/ap_config.c
src/ap/ap_config.h
src/ap/wpa_auth.h
src/ap/wpa_auth_glue.c
src/ap/wpa_auth_ie.c

index 0edf6af..f8ca6da 100644 (file)
@@ -3268,6 +3268,24 @@ static int hostapd_config_fill(struct hostapd_config *conf,
                bss->bss_load_test_set = 1;
        } else if (os_strcmp(buf, "radio_measurements") == 0) {
                bss->radio_measurements = atoi(pos);
+       } else if (os_strcmp(buf, "own_ie_override") == 0) {
+               struct wpabuf *tmp;
+               size_t len = os_strlen(pos) / 2;
+
+               tmp = wpabuf_alloc(len);
+               if (!tmp)
+                       return 1;
+
+               if (hexstr2bin(pos, wpabuf_put(tmp, len), len)) {
+                       wpabuf_free(tmp);
+                       wpa_printf(MSG_ERROR,
+                                  "Line %d: Invalid own_ie_override '%s'",
+                                  line, pos);
+                       return 1;
+               }
+
+               wpabuf_free(bss->own_ie_override);
+               bss->own_ie_override = tmp;
 #endif /* CONFIG_TESTING_OPTIONS */
        } else if (os_strcmp(buf, "vendor_elements") == 0) {
                struct wpabuf *elems;
index 455013a..8727375 100644 (file)
@@ -561,6 +561,10 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
 
        os_free(conf->server_id);
 
+#ifdef CONFIG_TESTING_OPTIONS
+       wpabuf_free(conf->own_ie_override);
+#endif /* CONFIG_TESTING_OPTIONS */
+
        os_free(conf);
 }
 
index b319587..07550bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * hostapd / Configuration definitions and helpers functions
- * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -544,6 +544,7 @@ struct hostapd_bss_config {
 #ifdef CONFIG_TESTING_OPTIONS
        u8 bss_load_test[5];
        u8 bss_load_test_set;
+       struct wpabuf *own_ie_override;
 #endif /* CONFIG_TESTING_OPTIONS */
 
 #define MESH_ENABLED BIT(0)
index e747806..7c76700 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * hostapd - IEEE 802.11i-2004 / WPA Authenticator
- * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -14,6 +14,8 @@
 #include "common/wpa_common.h"
 #include "common/ieee802_11_defs.h"
 
+#define MAX_OWN_IE_OVERRIDE 256
+
 #ifdef _MSC_VER
 #pragma pack(push, 1)
 #endif /* _MSC_VER */
@@ -164,6 +166,8 @@ struct wpa_auth_config {
        int ap_mlme;
 #ifdef CONFIG_TESTING_OPTIONS
        double corrupt_gtk_rekey_mic_probability;
+       u8 own_ie_override[MAX_OWN_IE_OVERRIDE];
+       size_t own_ie_override_len;
 #endif /* CONFIG_TESTING_OPTIONS */
 #ifdef CONFIG_P2P
        u8 ip_addr_go[4];
index d65dc63..f98cc50 100644 (file)
@@ -92,6 +92,13 @@ static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
 #ifdef CONFIG_TESTING_OPTIONS
        wconf->corrupt_gtk_rekey_mic_probability =
                iconf->corrupt_gtk_rekey_mic_probability;
+       if (conf->own_ie_override &&
+           wpabuf_len(conf->own_ie_override) <= MAX_OWN_IE_OVERRIDE) {
+               wconf->own_ie_override_len = wpabuf_len(conf->own_ie_override);
+               os_memcpy(wconf->own_ie_override,
+                         wpabuf_head(conf->own_ie_override),
+                         wconf->own_ie_override_len);
+       }
 #endif /* CONFIG_TESTING_OPTIONS */
 #ifdef CONFIG_P2P
        os_memcpy(wconf->ip_addr_go, conf->ip_addr_go, 4);
index cf2a712..eafb828 100644 (file)
@@ -378,6 +378,23 @@ int wpa_auth_gen_wpa_ie(struct wpa_authenticator *wpa_auth)
        u8 *pos, buf[128];
        int res;
 
+#ifdef CONFIG_TESTING_OPTIONS
+       if (wpa_auth->conf.own_ie_override_len) {
+               wpa_hexdump(MSG_DEBUG, "WPA: Forced own IE(s) for testing",
+                           wpa_auth->conf.own_ie_override,
+                           wpa_auth->conf.own_ie_override_len);
+               os_free(wpa_auth->wpa_ie);
+               wpa_auth->wpa_ie =
+                       os_malloc(wpa_auth->conf.own_ie_override_len);
+               if (wpa_auth->wpa_ie == NULL)
+                       return -1;
+               os_memcpy(wpa_auth->wpa_ie, wpa_auth->conf.own_ie_override,
+                         wpa_auth->conf.own_ie_override_len);
+               wpa_auth->wpa_ie_len = wpa_auth->conf.own_ie_override_len;
+               return 0;
+       }
+#endif /* CONFIG_TESTING_OPTIONS */
+
        pos = buf;
 
        if (wpa_auth->conf.wpa == WPA_PROTO_OSEN) {