]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Convert WPS IE concat routine to a generic helper
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 11 Sep 2009 13:36:59 +0000 (16:36 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 11 Sep 2009 13:36:59 +0000 (16:36 +0300)
This may also be needed in wpa_supplicant and potentially for other
IE types, too.

hostapd/wps_hostapd.c
src/common/ieee802_11_common.c
src/common/ieee802_11_common.h

index 5ecf3a44428afd1eb64ad646c07990a3ff3b6f61..42568cd307af2a4cb3fd888554c545a8bc8ae84e 100644 (file)
@@ -20,6 +20,7 @@
 #include "uuid.h"
 #include "wpa_ctrl.h"
 #include "ieee802_11_defs.h"
+#include "ieee802_11_common.h"
 #include "sta_info.h"
 #include "eapol_sm.h"
 #include "wps/wps.h"
@@ -793,44 +794,14 @@ static void hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
 {
        struct hostapd_data *hapd = ctx;
        struct wpabuf *wps_ie;
-       const u8 *end, *pos, *wps;
 
        if (hapd->wps == NULL)
                return;
 
-       pos = ie;
-       end = ie + ie_len;
-       wps = NULL;
-
-       while (pos + 1 < end) {
-               if (pos + 2 + pos[1] > end)
-                       return;
-               if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
-                   WPA_GET_BE32(&pos[2]) == WPS_DEV_OUI_WFA) {
-                       wps = pos;
-                       break;
-               }
-               pos += 2 + pos[1];
-       }
-
-       if (wps == NULL)
-               return; /* No WPS IE in Probe Request */
-
-       wps_ie = wpabuf_alloc(ie_len);
+       wps_ie = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
        if (wps_ie == NULL)
                return;
 
-       /* There may be multiple WPS IEs in the message, so need to concatenate
-        * their WPS Data fields */
-       while (pos + 1 < end) {
-               if (pos + 2 + pos[1] > end)
-                       break;
-               if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
-                   WPA_GET_BE32(&pos[2]) == WPS_DEV_OUI_WFA)
-                       wpabuf_put_data(wps_ie, pos + 6, pos[1] - 4);
-               pos += 2 + pos[1];
-       }
-
        if (wpabuf_len(wps_ie) > 0) {
                wps_registrar_probe_req_rx(hapd->wps->registrar, addr, wps_ie);
 #ifdef CONFIG_WPS_UPNP
index 6910b4e63d8711b79d49925032d85e0ea4694d27..79a9325ed8cd79027a3a6cf05d5540239ac61640 100644 (file)
@@ -279,3 +279,48 @@ int ieee802_11_ie_count(const u8 *ies, size_t ies_len)
 
        return count;
 }
+
+
+struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
+                                           u32 oui_type)
+{
+       struct wpabuf *buf;
+       const u8 *end, *pos, *ie;
+
+       pos = ies;
+       end = ies + ies_len;
+       ie = NULL;
+
+       while (pos + 1 < end) {
+               if (pos + 2 + pos[1] > end)
+                       return NULL;
+               if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+                   WPA_GET_BE32(&pos[2]) == oui_type) {
+                       ie = pos;
+                       break;
+               }
+               pos += 2 + pos[1];
+       }
+
+       if (ie == NULL)
+               return NULL; /* No specified vendor IE found */
+
+       buf = wpabuf_alloc(ies_len);
+       if (buf == NULL)
+               return NULL;
+
+       /*
+        * There may be multiple vendor IEs in the message, so need to
+        * concatenate their data fields.
+        */
+       while (pos + 1 < end) {
+               if (pos + 2 + pos[1] > end)
+                       break;
+               if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
+                   WPA_GET_BE32(&pos[2]) == oui_type)
+                       wpabuf_put_data(buf, pos + 6, pos[1] - 4);
+               pos += 2 + pos[1];
+       }
+
+       return buf;
+}
index 14599cb4fc41bc47bd88a1a3cb54648135226568..4a48046ff37abd6382de7a8b7bfc21b62565b104 100644 (file)
@@ -71,5 +71,7 @@ ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
                                struct ieee802_11_elems *elems,
                                int show_errors);
 int ieee802_11_ie_count(const u8 *ies, size_t ies_len);
+struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
+                                           u32 oui_type);
 
 #endif /* IEEE802_11_COMMON_H */