From 4c29cae9320ccc6675b59f41dddf652b997fdc71 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 23 Jan 2009 21:08:55 +0200 Subject: [PATCH] Added ap_settings option for overriding WPS AP Settings in M7 This optional configuration parameter can be used to override AP Settings attributes in M7 similarly to extra_cred option for Credential attribute(s) in M8. --- hostapd/config.c | 11 +++++++++++ hostapd/config.h | 2 ++ hostapd/hostapd.conf | 7 +++++++ hostapd/wps_hostapd.c | 3 +++ src/wps/wps.h | 13 +++++++++++++ src/wps/wps_enrollee.c | 28 ++++++++++++++++++++-------- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/hostapd/config.c b/hostapd/config.c index a35aaa3bd..5097f4d06 100644 --- a/hostapd/config.c +++ b/hostapd/config.c @@ -2229,6 +2229,16 @@ struct hostapd_config * hostapd_config_read(const char *fname) } } else if (os_strcmp(buf, "wps_cred_processing") == 0) { bss->wps_cred_processing = atoi(pos); + } else if (os_strcmp(buf, "ap_settings") == 0) { + os_free(bss->ap_settings); + bss->ap_settings = + (u8 *) os_readfile(pos, &bss->ap_settings_len); + if (bss->ap_settings == NULL) { + wpa_printf(MSG_ERROR, "Line %d: could not " + "read AP Settings from '%s'", + line, pos); + errors++; + } #endif /* CONFIG_WPS */ } else { wpa_printf(MSG_ERROR, "Line %d: unknown configuration " @@ -2435,6 +2445,7 @@ static void hostapd_config_free_bss(struct hostapd_bss_config *conf) os_free(conf->config_methods); os_free(conf->ap_pin); os_free(conf->extra_cred); + os_free(conf->ap_settings); #endif /* CONFIG_WPS */ } diff --git a/hostapd/config.h b/hostapd/config.h index f799d9c44..87be50624 100644 --- a/hostapd/config.h +++ b/hostapd/config.h @@ -304,6 +304,8 @@ struct hostapd_bss_config { u8 *extra_cred; size_t extra_cred_len; int wps_cred_processing; + u8 *ap_settings; + size_t ap_settings_len; #endif /* CONFIG_WPS */ }; diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf index b423be564..24709eeb2 100644 --- a/hostapd/hostapd.conf +++ b/hostapd/hostapd.conf @@ -958,6 +958,13 @@ own_ip_addr=127.0.0.1 # extra_cred be used to provide the Credential data for Enrollees. #wps_cred_processing=0 +# AP Settings Attributes for M7 +# By default, hostapd generates the AP Settings Attributes for M7 based on the +# current configuration. It is possible to override this by providing a file +# with pre-configured attributes. This is similar to extra_cred file format, +# but the AP Settings attributes are not encapsulated in a Credential +# attribute. +#ap_settings=hostapd.ap_settings ##### Multiple BSSID support ################################################## # diff --git a/hostapd/wps_hostapd.c b/hostapd/wps_hostapd.c index 902682c9d..077e40017 100644 --- a/hostapd/wps_hostapd.c +++ b/hostapd/wps_hostapd.c @@ -545,6 +545,9 @@ int hostapd_init_wps(struct hostapd_data *hapd, wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP; } + wps->ap_settings = conf->ap_settings; + wps->ap_settings_len = conf->ap_settings_len; + cfg.new_psk_cb = hostapd_wps_new_psk_cb; cfg.set_ie_cb = hostapd_wps_set_ie_cb; cfg.pin_needed_cb = hostapd_wps_pin_needed_cb; diff --git a/src/wps/wps.h b/src/wps/wps.h index 484733287..7524acbf1 100644 --- a/src/wps/wps.h +++ b/src/wps/wps.h @@ -396,6 +396,19 @@ struct wps_context { */ size_t network_key_len; + /** + * ap_settings - AP Settings override for M7 (only used at AP) + * + * If %NULL, AP Settings attributes will be generated based on the + * current network configuration. + */ + u8 *ap_settings; + + /** + * ap_settings_len - Length of ap_settings in octets + */ + size_t ap_settings_len; + /** * cred_cb - Callback to notify that new Credentials were received * @ctx: Higher layer context data (cb_ctx) diff --git a/src/wps/wps_enrollee.c b/src/wps/wps_enrollee.c index 59f3b192d..dda8fc6ac 100644 --- a/src/wps/wps_enrollee.c +++ b/src/wps/wps_enrollee.c @@ -268,17 +268,34 @@ static int wps_build_cred_mac_addr(struct wps_data *wps, struct wpabuf *msg) } +static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *plain) +{ + if (wps->wps->ap_settings) { + wpa_printf(MSG_DEBUG, "WPS: * AP Settings (pre-configured)"); + wpabuf_put_data(plain, wps->wps->ap_settings, + wps->wps->ap_settings_len); + return 0; + } + + return wps_build_cred_ssid(wps, plain) || + wps_build_cred_mac_addr(wps, plain) || + wps_build_cred_auth_type(wps, plain) || + wps_build_cred_encr_type(wps, plain) || + wps_build_cred_network_key(wps, plain); +} + + static struct wpabuf * wps_build_m7(struct wps_data *wps) { struct wpabuf *msg, *plain; wpa_printf(MSG_DEBUG, "WPS: Building Message M7"); - plain = wpabuf_alloc(500); + plain = wpabuf_alloc(500 + wps->wps->ap_settings_len); if (plain == NULL) return NULL; - msg = wpabuf_alloc(1000); + msg = wpabuf_alloc(1000 + wps->wps->ap_settings_len); if (msg == NULL) { wpabuf_free(plain); return NULL; @@ -288,12 +305,7 @@ static struct wpabuf * wps_build_m7(struct wps_data *wps) wps_build_msg_type(msg, WPS_M7) || wps_build_registrar_nonce(wps, msg) || wps_build_e_snonce2(wps, plain) || - (wps->wps->ap && - (wps_build_cred_ssid(wps, plain) || - wps_build_cred_mac_addr(wps, plain) || - wps_build_cred_auth_type(wps, plain) || - wps_build_cred_encr_type(wps, plain) || - wps_build_cred_network_key(wps, plain))) || + (wps->wps->ap && wps_build_ap_settings(wps, plain)) || wps_build_key_wrap_auth(wps, plain) || wps_build_encr_settings(wps, msg, plain) || wps_build_authenticator(wps, msg)) {