From patchwork Wed Apr 10 19:12:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 235449 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) by ozlabs.org (Postfix) with ESMTP id B9A2C2C00A1 for ; Thu, 11 Apr 2013 05:13:02 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 736D99D21B; Wed, 10 Apr 2013 15:13:00 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N6LBmWzYZ7AZ; Wed, 10 Apr 2013 15:13:00 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 30ED19D21C; Wed, 10 Apr 2013 15:12:56 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 21FF79D21B for ; Wed, 10 Apr 2013 15:12:55 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Vk5foYZmsk5p for ; Wed, 10 Apr 2013 15:12:51 -0400 (EDT) Received: from sipsolutions.net (he.sipsolutions.net [78.46.109.217]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id B9D7A9C143 for ; Wed, 10 Apr 2013 15:12:50 -0400 (EDT) Received: by sipsolutions.net with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1UQ0Rs-000742-3x; Wed, 10 Apr 2013 21:12:48 +0200 From: Johannes Berg To: hostap@lists.shmoo.com Subject: [PATCH v2] hostapd: add some testing options Date: Wed, 10 Apr 2013 21:12:44 +0200 Message-Id: <1365621164-18268-1-git-send-email-johannes@sipsolutions.net> X-Mailer: git-send-email 1.8.0 Cc: Johannes Berg X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Johannes Berg 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 Signed-off-by: Johannes Berg --- hostapd/Makefile | 4 ++++ hostapd/config_file.c | 19 +++++++++++++++++++ hostapd/defconfig | 8 ++++++++ hostapd/hostapd.conf | 20 ++++++++++++++++++++ src/ap/ap_config.c | 7 +++++++ src/ap/ap_config.h | 7 +++++++ src/ap/beacon.c | 10 ++++++++++ src/ap/ieee802_11.c | 30 ++++++++++++++++++++++++++++++ 8 files changed, 105 insertions(+) diff --git a/hostapd/Makefile b/hostapd/Makefile index 8404e0c..26cc2b5 100644 --- a/hostapd/Makefile +++ b/hostapd/Makefile @@ -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) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index 12d627a..0999f0d 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -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 } else if (os_strcmp(buf, "vendor_elements") == 0) { struct wpabuf *elems; size_t len = os_strlen(pos); diff --git a/hostapd/defconfig b/hostapd/defconfig index b5ddca3..317fe74 100644 --- a/hostapd/defconfig +++ b/hostapd/defconfig @@ -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 diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf index 17bb7ed..5f48acb 100644 --- a/hostapd/hostapd.conf +++ b/hostapd/hostapd.conf @@ -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 @@ -1554,3 +1573,4 @@ own_ip_addr=127.0.0.1 #bss=wlan0_1 #bssid=00:13:10:95:fe:0b # ... + diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c index 922f564..640773b 100644 --- a/src/ap/ap_config.c +++ b/src/ap/ap_config.c @@ -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 + return conf; } diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h index d9ef984..37d6c98 100644 --- a/src/ap/ap_config.h +++ b/src/ap/ap_config.h @@ -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 }; diff --git a/src/ap/beacon.c b/src/ap/beacon.c index 4c47c75..845e66c 100644 --- a/src/ap/beacon.c +++ b/src/ap/beacon.c @@ -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 + resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL, &resp_len); if (resp == NULL) diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c index 8baa15e..0d9b0c1 100644 --- a/src/ap/ieee802_11.c +++ b/src/ap/ieee802_11.c @@ -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 + 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 + if (reassoc) { capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info); listen_interval = le_to_host16(