]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Add secondary device types into Probe Request frames
authorJean-Michel Bachot <jean-michelx.bachot@linux.intel.com>
Thu, 17 Mar 2011 09:09:49 +0000 (11:09 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 17 Mar 2011 09:09:49 +0000 (11:09 +0200)
The secondary device type list is an optional attribute in the WSC IE.

Signed-off-by: Jean-Michel Bachot <jean-michelx.bachot@linux.intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
src/wps/wps.c
src/wps/wps.h
src/wps/wps_dev_attr.c
src/wps/wps_dev_attr.h
wpa_supplicant/wps_supplicant.c

index a9d41d039e8336a352b174e1a4d9f70f0da61ea5..72f603b33de33ca66767b0404f3c4e90005efaf2 100644 (file)
@@ -486,10 +486,9 @@ struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
            wps_build_model_name(dev, ie) ||
            wps_build_model_number(dev, ie) ||
            wps_build_dev_name(dev, ie) ||
-           wps_build_wfa_ext(ie, req_type == WPS_REQ_ENROLLEE, NULL, 0)
-#else /* CONFIG_WPS2 */
-           0
+           wps_build_wfa_ext(ie, req_type == WPS_REQ_ENROLLEE, NULL, 0) ||
 #endif /* CONFIG_WPS2 */
+           wps_build_secondary_dev_type(dev, ie)
                ) {
                wpabuf_free(ie);
                return NULL;
index 47b3e760e94ead43976dd3033f1ae760f07ef125..d2fca3f2e9af009e4b6ef8b1bc5177693984d568 100644 (file)
@@ -73,6 +73,8 @@ struct wps_credential {
  * @model_number: Model Number (0..32 octets encoded in UTF-8)
  * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
  * @pri_dev_type: Primary Device Type
+ * @sec_dev_type: Array of secondary device types
+ * @num_sec_dev_type: Number of secondary device types
  * @os_version: OS Version
  * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
  * @p2p: Whether the device is a P2P device
@@ -85,6 +87,9 @@ struct wps_device_data {
        char *model_number;
        char *serial_number;
        u8 pri_dev_type[WPS_DEV_TYPE_LEN];
+#define WPS_SEC_DEVICE_TYPES 5
+       u8 sec_dev_type[WPS_SEC_DEVICE_TYPES][WPS_DEV_TYPE_LEN];
+       u8 num_sec_dev_types;
        u32 os_version;
        u8 rf_bands;
 
index 823c7ef5115477b0881a7fcc52af6f1d9dd4ce54..2304bc4e26c4f12d648c5b9d76ab0ba5749c0cea 100644 (file)
@@ -126,6 +126,22 @@ 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,
+                                 struct wpabuf *msg)
+{
+       if (!dev->num_sec_dev_types)
+               return 0;
+
+       wpa_printf(MSG_DEBUG, "WPS:  * Secondary Device Type");
+       wpabuf_put_be16(msg, ATTR_SECONDARY_DEV_TYPE_LIST);
+       wpabuf_put_be16(msg, WPS_DEV_TYPE_LEN * dev->num_sec_dev_types);
+       wpabuf_put_data(msg, dev->sec_dev_type,
+                       WPS_DEV_TYPE_LEN * dev->num_sec_dev_types);
+
+       return 0;
+}
+
+
 int wps_build_dev_name(struct wps_device_data *dev, struct wpabuf *msg)
 {
        size_t len;
index e3cdf0db21f70d125f3a3906b5fdc371569eb059..84a2cd288585272eea97cd7f2d9108bc96eb89a5 100644 (file)
@@ -26,6 +26,8 @@ int wps_build_os_version(struct wps_device_data *dev, struct wpabuf *msg);
 int wps_build_rf_bands(struct wps_device_data *dev, struct wpabuf *msg);
 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,
+                                struct wpabuf *msg);
 int wps_build_dev_name(struct wps_device_data *dev, struct wpabuf *msg);
 int wps_process_device_attrs(struct wps_device_data *dev,
                             struct wps_parse_attr *attr);
index 1ed403ccec9313e49e8303559c5b455b6aa92dcf..1dac496ef30d22cd7534570528a25350062e2a4c 100644 (file)
@@ -1067,6 +1067,7 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
 {
        struct wps_context *wps;
        struct wps_registrar_config rcfg;
+       int i;
 
        wps = os_zalloc(sizeof(*wps));
        if (wps == NULL)
@@ -1098,6 +1099,22 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
                os_free(wps);
                return -1;
        }
+
+       for (i = 0; i < MAX_SEC_DEVICE_TYPES; i++) {
+               if (wpa_s->conf->sec_device_type[i] == NULL)
+                       continue;
+               if (wps_dev_type_str2bin(
+                           wpa_s->conf->sec_device_type[i],
+                           wps->dev.sec_dev_type[wps->dev.num_sec_dev_types])
+                   < 0) {
+                       wpa_printf(MSG_ERROR, "WPS: Invalid sec_device_type");
+                       return -1;
+               }
+               wps->dev.num_sec_dev_types++;
+               if (wps->dev.num_sec_dev_types == WPS_SEC_DEVICE_TYPES)
+                       break;
+       }
+
        wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
        wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
        os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
@@ -1644,6 +1661,28 @@ void wpas_wps_update_config(struct wpa_supplicant *wpa_s)
                        wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
        }
 
+       if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) {
+               int i;
+
+               wps->dev.num_sec_dev_types = 0;
+
+               for (i = 0; i < MAX_SEC_DEVICE_TYPES; i++) {
+                       if (wpa_s->conf->sec_device_type[i] == NULL)
+                               continue;
+                       if (wps_dev_type_str2bin(
+                                   wpa_s->conf->sec_device_type[i],
+                                   wps->dev.sec_dev_type[
+                                           wps->dev.num_sec_dev_types]) < 0) {
+                               wpa_printf(MSG_ERROR,
+                                          "WPS: Invalid sec_device_type");
+                               continue;
+                       }
+                       wps->dev.num_sec_dev_types++;
+                       if (wps->dev.num_sec_dev_types == WPS_SEC_DEVICE_TYPES)
+                               break;
+               }
+       }
+
        if (wpa_s->conf->changed_parameters & CFG_CHANGED_OS_VERSION)
                wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);