Added ap_settings option for overriding WPS AP Settings in M7
authorJouni Malinen <j@w1.fi>
Fri, 23 Jan 2009 19:08:55 +0000 (21:08 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 23 Jan 2009 19:08:55 +0000 (21:08 +0200)
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
hostapd/config.h
hostapd/hostapd.conf
hostapd/wps_hostapd.c
src/wps/wps.h
src/wps/wps_enrollee.c

index a35aaa3..5097f4d 100644 (file)
@@ -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 */
 }
 
index f799d9c..87be506 100644 (file)
@@ -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 */
 };
 
index b423be5..24709ee 100644 (file)
@@ -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 ##################################################
 #
index 902682c..077e400 100644 (file)
@@ -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;
index 4847332..7524acb 100644 (file)
@@ -397,6 +397,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)
         * @cred: The received Credential
index 59f3b19..dda8fc6 100644 (file)
@@ -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)) {