]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
hostapd: Add some testing options
authorJohannes Berg <johannes.berg@intel.com>
Tue, 23 Apr 2013 14:51:28 +0000 (17:51 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 23 Apr 2013 14:51:28 +0000 (17:51 +0300)
In order to test clients in scenarios where APs may (randomly)
drop certain management frames, introduce some testing options
into the hostapd configuration that can make it ignore certain
frames. For now, these are probe requests, authentication and
(re)association frames.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>

hostapd/Makefile
hostapd/config_file.c
hostapd/defconfig
hostapd/hostapd.conf
src/ap/ap_config.c
src/ap/ap_config.h
src/ap/beacon.c
src/ap/ieee802_11.c

index 8404e0cb10a3dfe45e73d167c97841697ce9f62b..26cc2b513fae6d62c11cccaa6bcc182da1c1adc8 100644 (file)
@@ -824,6 +824,10 @@ LIBS += -lsqlite3
 LIBS_h += -lsqlite3
 endif
 
+ifdef CONFIG_TESTING_OPTIONS
+CFLAGS += -DCONFIG_TESTING_OPTIONS
+endif
+
 ALL=hostapd hostapd_cli
 
 all: verify_config $(ALL)
index 12d627a8aaa66831ed30a728661ad8f209015dbc..cd68e3ef97c78e52185c5ffd4c00981102be0b90 100644 (file)
@@ -2876,6 +2876,25 @@ static int hostapd_config_fill(struct hostapd_config *conf,
                        bss->hs20_operating_class = oper_class;
                        bss->hs20_operating_class_len = oper_class_len;
 #endif /* CONFIG_HS20 */
+#ifdef CONFIG_TESTING_OPTIONS
+#define PARSE_TEST_PROBABILITY(_val)                                   \
+               } else if (os_strcmp(buf, #_val) == 0) {                \
+                       char *end;                                      \
+                                                                       \
+                       conf->_val = strtod(pos, &end);                 \
+                       if (*end || conf->_val < 0.0d ||                \
+                           conf->_val > 1.0d) {                        \
+                               wpa_printf(MSG_ERROR,                   \
+                                          "Line %d: Invalid value '%s'", \
+                                          line, pos);                  \
+                               errors++;                               \
+                               return errors;                          \
+                       }
+               PARSE_TEST_PROBABILITY(ignore_probe_probability)
+               PARSE_TEST_PROBABILITY(ignore_auth_probability)
+               PARSE_TEST_PROBABILITY(ignore_assoc_probability)
+               PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
+#endif /* CONFIG_TESTING_OPTIONS */
                } else if (os_strcmp(buf, "vendor_elements") == 0) {
                        struct wpabuf *elems;
                        size_t len = os_strlen(pos);
index b5ddca34c09d019a68cfcaf6f112343b5825e5f2..317fe740e218584dd5cc65090d540d354c0991ad 100644 (file)
@@ -267,3 +267,11 @@ CONFIG_IPV6=y
 
 # Enable SQLite database support in hlr_auc_gw, EAP-SIM DB, and eap_user_file
 #CONFIG_SQLITE=y
+
+# Testing options
+# This can be used to enable some testing options (see also the example
+# configuration file) that are really useful only for testing clients that
+# connect to this hostapd. These options allow, for example, to drop a
+# certain percentage of probe requests or auth/(re)assoc frames.
+#
+#CONFIG_TESTING_OPTIONS=y
index 17bb7ed785620b3d6fd060c611e8b01b0f1f96ae..d4425866b79286cb20c82a6559c247cf6509ede3 100644 (file)
@@ -1521,6 +1521,25 @@ own_ip_addr=127.0.0.1
 # channels 36-48):
 #hs20_operating_class=5173
 
+##### TESTING OPTIONS #########################################################
+#
+# The options in this section are only available when the build configuration
+# option CONFIG_TESTING_OPTIONS is set while compiling hostapd. They allow
+# testing some scenarios that are otherwise difficult to reproduce.
+#
+# Ignore probe requests sent to hostapd with the given probability, must be a
+# floating point number in the range [0, 1).
+#ignore_probe_probability=0.0
+#
+# Ignore authentication frames with the given probability
+#ignore_auth_probability=0.0
+#
+# Ignore association requests with the given probability
+#ignore_assoc_probability=0.0
+#
+# Ignore reassociation requests with the given probability
+#ignore_reassoc_probability=0.0
+
 ##### Multiple BSSID support ##################################################
 #
 # Above configuration is using the default interface (wlan#, or multi-SSID VLAN
index 922f56469da8f58294616045f8bdf01bd1f926f6..70b26a6eec1de639ce2838fe80717ff241030eb5 100644 (file)
@@ -163,6 +163,13 @@ struct hostapd_config * hostapd_config_defaults(void)
        conf->ap_table_max_size = 255;
        conf->ap_table_expiration_time = 60;
 
+#ifdef CONFIG_TESTING_OPTIONS
+       conf->ignore_probe_probability = 0.0d;
+       conf->ignore_auth_probability = 0.0d;
+       conf->ignore_assoc_probability = 0.0d;
+       conf->ignore_reassoc_probability = 0.0d;
+#endif /* CONFIG_TESTING_OPTIONS */
+
        return conf;
 }
 
index d9ef984df62ff17d9ed5b399a8c6cf39c271b928..f9629a2cdba4d665617cb8d1f5d281e12eba9684 100644 (file)
@@ -520,6 +520,13 @@ struct hostapd_config {
        u8 vht_oper_chwidth;
        u8 vht_oper_centr_freq_seg0_idx;
        u8 vht_oper_centr_freq_seg1_idx;
+
+#ifdef CONFIG_TESTING_OPTIONS
+       double ignore_probe_probability;
+       double ignore_auth_probability;
+       double ignore_assoc_probability;
+       double ignore_reassoc_probability;
+#endif /* CONFIG_TESTING_OPTIONS */
 };
 
 
index 4c47c75841c51b49a668ca0b34f7074e6723ee5a..0ef307d34c6db450d2765c41437ade07719c1da9 100644 (file)
@@ -488,6 +488,16 @@ void handle_probe_req(struct hostapd_data *hapd,
        /* TODO: verify that supp_rates contains at least one matching rate
         * with AP configuration */
 
+#ifdef CONFIG_TESTING_OPTIONS
+       if (hapd->iconf->ignore_probe_probability > 0.0d &&
+           drand48() < hapd->iconf->ignore_probe_probability) {
+               wpa_printf(MSG_INFO,
+                          "TESTING: ignoring probe request from " MACSTR,
+                          MAC2STR(mgmt->sa));
+               return;
+       }
+#endif /* CONFIG_TESTING_OPTIONS */
+
        resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
                                      &resp_len);
        if (resp == NULL)
index 8baa15e70af9329683d4a5404cd43fb018032ea6..7bef55fa5fe86f2098bd559f21be1d3eacea8eae 100644 (file)
@@ -557,6 +557,16 @@ static void handle_auth(struct hostapd_data *hapd,
                return;
        }
 
+#ifdef CONFIG_TESTING_OPTIONS
+       if (hapd->iconf->ignore_auth_probability > 0.0d &&
+           drand48() < hapd->iconf->ignore_auth_probability) {
+               wpa_printf(MSG_INFO,
+                          "TESTING: ignoring auth frame from " MACSTR,
+                          MAC2STR(mgmt->sa));
+               return;
+       }
+#endif /* CONFIG_TESTING_OPTIONS */
+
        auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
        auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
        status_code = le_to_host16(mgmt->u.auth.status_code);
@@ -1226,6 +1236,26 @@ static void handle_assoc(struct hostapd_data *hapd,
                return;
        }
 
+#ifdef CONFIG_TESTING_OPTIONS
+       if (reassoc) {
+               if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
+                   drand48() < hapd->iconf->ignore_reassoc_probability) {
+                       wpa_printf(MSG_INFO,
+                                  "TESTING: ignoring reassoc request from "
+                                  MACSTR, MAC2STR(mgmt->sa));
+                       return;
+               }
+       } else {
+               if (hapd->iconf->ignore_assoc_probability > 0.0d &&
+                   drand48() < hapd->iconf->ignore_assoc_probability) {
+                       wpa_printf(MSG_INFO,
+                                  "TESTING: ignoring assoc request from "
+                                  MACSTR, MAC2STR(mgmt->sa));
+                       return;
+               }
+       }
+#endif /* CONFIG_TESTING_OPTIONS */
+
        if (reassoc) {
                capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
                listen_interval = le_to_host16(