WPS: Set currently used RF band in RF Bands attribute
authorDavid Spinadel <david.spinadel@intel.com>
Sun, 25 Aug 2013 07:55:53 +0000 (10:55 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 25 Aug 2013 07:55:53 +0000 (10:55 +0300)
According to WSC specification (Ver 2.0.2, section 8.3), RF Bands
attribute should be set to the specific RF band used for the current
message. Add an option to set wanted band in wps_build_rf_bands() and
add a callback to get the current band from wpa_supplicant and hostapd.

Signed-hostap: David Spinadel <david.spinadel@intel.com>

src/ap/wps_hostapd.c
src/wps/wps.c
src/wps/wps.h
src/wps/wps_dev_attr.c
src/wps/wps_dev_attr.h
src/wps/wps_enrollee.c
src/wps/wps_registrar.c
wpa_supplicant/wps_supplicant.c

index a33168c..3304c06 100644 (file)
@@ -857,6 +857,15 @@ static void hostapd_wps_event_cb(void *ctx, enum wps_event event,
 }
 
 
+static int hostapd_wps_rf_band_cb(void *ctx)
+{
+       struct hostapd_data *hapd = ctx;
+
+       return hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211A ?
+               WPS_RF_50GHZ : WPS_RF_24GHZ; /* FIX: dualband AP */
+}
+
+
 static void hostapd_wps_clear_ies(struct hostapd_data *hapd)
 {
        wpabuf_free(hapd->wps_beacon_ie);
@@ -964,6 +973,7 @@ int hostapd_init_wps(struct hostapd_data *hapd,
 
        wps->cred_cb = hostapd_wps_cred_cb;
        wps->event_cb = hostapd_wps_event_cb;
+       wps->rf_band_cb = hostapd_wps_rf_band_cb;
        wps->cb_ctx = hapd;
 
        os_memset(&cfg, 0, sizeof(cfg));
index dd55566..22d7eea 100644 (file)
@@ -497,7 +497,7 @@ struct wpabuf * wps_build_probe_req_ie(u16 pw_id, struct wps_device_data *dev,
            wps_build_config_methods(ie, dev->config_methods) ||
            wps_build_uuid_e(ie, uuid) ||
            wps_build_primary_dev_type(dev, ie) ||
-           wps_build_rf_bands(dev, ie) ||
+           wps_build_rf_bands(dev, ie, 0) ||
            wps_build_assoc_state(NULL, ie) ||
            wps_build_config_error(ie, WPS_CFG_NO_ERROR) ||
            wps_build_dev_password_id(ie, pw_id) ||
index 57d7ca0..dc82c44 100644 (file)
@@ -746,6 +746,13 @@ struct wps_context {
                         union wps_event_data *data);
 
        /**
+        * rf_band_cb - Fetch currently used RF band
+        * @ctx: Higher layer context data (cb_ctx)
+        * Return: Current used RF band or 0 if not known
+        */
+       int (*rf_band_cb)(void *ctx);
+
+       /**
         * cb_ctx: Higher layer context data for callbacks
         */
        void *cb_ctx;
index 7a7c099..1b12b5a 100644 (file)
@@ -217,12 +217,13 @@ int wps_build_vendor_ext_m1(struct wps_device_data *dev, struct wpabuf *msg)
 }
 
 
-int wps_build_rf_bands(struct wps_device_data *dev, struct wpabuf *msg)
+int wps_build_rf_bands(struct wps_device_data *dev, struct wpabuf *msg,
+                      u8 rf_band)
 {
        wpa_printf(MSG_DEBUG, "WPS:  * RF Bands (%x)", dev->rf_bands);
        wpabuf_put_be16(msg, ATTR_RF_BANDS);
        wpabuf_put_be16(msg, 1);
-       wpabuf_put_u8(msg, dev->rf_bands);
+       wpabuf_put_u8(msg, rf_band ? rf_band : dev->rf_bands);
        return 0;
 }
 
index 200c9c4..0158cdc 100644 (file)
@@ -18,7 +18,8 @@ int wps_build_dev_name(struct wps_device_data *dev, struct wpabuf *msg);
 int wps_build_device_attrs(struct wps_device_data *dev, struct wpabuf *msg);
 int wps_build_os_version(struct wps_device_data *dev, struct wpabuf *msg);
 int wps_build_vendor_ext_m1(struct wps_device_data *dev, struct wpabuf *msg);
-int wps_build_rf_bands(struct wps_device_data *dev, struct wpabuf *msg);
+int wps_build_rf_bands(struct wps_device_data *dev, struct wpabuf *msg,
+                      u8 rf_band);
 int wps_build_primary_dev_type(struct wps_device_data *dev,
                               struct wpabuf *msg);
 int wps_build_secondary_dev_type(struct wps_device_data *dev,
index 67ef01e..d02ba30 100644 (file)
@@ -148,7 +148,8 @@ static struct wpabuf * wps_build_m1(struct wps_data *wps)
            wps_build_config_methods(msg, config_methods) ||
            wps_build_wps_state(wps, msg) ||
            wps_build_device_attrs(&wps->wps->dev, msg) ||
-           wps_build_rf_bands(&wps->wps->dev, msg) ||
+           wps_build_rf_bands(&wps->wps->dev, msg,
+                              wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
            wps_build_assoc_state(wps, msg) ||
            wps_build_dev_password_id(msg, wps->dev_pw_id) ||
            wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
index b3a8c0a..318445f 100644 (file)
@@ -1265,7 +1265,7 @@ static int wps_set_ie(struct wps_registrar *reg)
            wps_build_sel_reg_dev_password_id(reg, beacon) ||
            wps_build_sel_reg_config_methods(reg, beacon) ||
            wps_build_sel_pbc_reg_uuid_e(reg, beacon) ||
-           (reg->dualband && wps_build_rf_bands(&reg->wps->dev, beacon)) ||
+           (reg->dualband && wps_build_rf_bands(&reg->wps->dev, beacon, 0)) ||
            wps_build_wfa_ext(beacon, 0, auth_macs, count) ||
            wps_build_vendor_ext(&reg->wps->dev, beacon)) {
                wpabuf_free(beacon);
@@ -1295,7 +1295,7 @@ static int wps_set_ie(struct wps_registrar *reg)
            wps_build_uuid_e(probe, reg->wps->uuid) ||
            wps_build_device_attrs(&reg->wps->dev, probe) ||
            wps_build_probe_config_methods(reg, probe) ||
-           (reg->dualband && wps_build_rf_bands(&reg->wps->dev, probe)) ||
+           (reg->dualband && wps_build_rf_bands(&reg->wps->dev, probe, 0)) ||
            wps_build_wfa_ext(probe, 0, auth_macs, count) ||
            wps_build_vendor_ext(&reg->wps->dev, probe)) {
                wpabuf_free(beacon);
@@ -1790,7 +1790,8 @@ static struct wpabuf * wps_build_m2(struct wps_data *wps)
            wps_build_conn_type_flags(wps, msg) ||
            wps_build_config_methods_r(wps->wps->registrar, msg) ||
            wps_build_device_attrs(&wps->wps->dev, msg) ||
-           wps_build_rf_bands(&wps->wps->dev, msg) ||
+           wps_build_rf_bands(&wps->wps->dev, msg,
+                              wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
            wps_build_assoc_state(wps, msg) ||
            wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
            wps_build_dev_password_id(msg, wps->dev_pw_id) ||
@@ -1831,7 +1832,8 @@ static struct wpabuf * wps_build_m2d(struct wps_data *wps)
            wps_build_conn_type_flags(wps, msg) ||
            wps_build_config_methods_r(wps->wps->registrar, msg) ||
            wps_build_device_attrs(&wps->wps->dev, msg) ||
-           wps_build_rf_bands(&wps->wps->dev, msg) ||
+           wps_build_rf_bands(&wps->wps->dev, msg,
+                              wps->wps->rf_band_cb(wps->wps->cb_ctx)) ||
            wps_build_assoc_state(wps, msg) ||
            wps_build_config_error(msg, err) ||
            wps_build_os_version(&wps->wps->dev, msg) ||
index ef50878..b855dbd 100644 (file)
@@ -856,6 +856,17 @@ static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
 }
 
 
+static int wpa_supplicant_wps_rf_band(void *ctx)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+
+       if (!wpa_s->current_ssid || !wpa_s->assoc_freq)
+               return 0;
+
+       return (wpa_s->assoc_freq > 2484) ? WPS_RF_50GHZ : WPS_RF_24GHZ;
+}
+
+
 enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
 {
        if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
@@ -1327,6 +1338,7 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
 
        wps->cred_cb = wpa_supplicant_wps_cred;
        wps->event_cb = wpa_supplicant_wps_event;
+       wps->rf_band_cb = wpa_supplicant_wps_rf_band;
        wps->cb_ctx = wpa_s;
 
        wps->dev.device_name = wpa_s->conf->device_name;