Parcourir la source

WPS: Moved WPS IE building for ProbeReq/AssocReq into wps.c

These functions fit in better with the category of functions included in
wps.c. wps_common.c is now used for generic helper functions (currently,
only crypto code).
Jouni Malinen il y a 16 ans
Parent
commit
b8a8c299c8
3 fichiers modifiés avec 88 ajouts et 90 suppressions
  1. 71 0
      src/wps/wps.c
  2. 17 19
      src/wps/wps.h
  3. 0 71
      src/wps/wps_common.c

+ 71 - 0
src/wps/wps.c

@@ -17,6 +17,7 @@
 #include "common.h"
 #include "wps_i.h"
 #include "wps_dev_attr.h"
+#include "ieee802_11_defs.h"
 
 
 struct wps_data * wps_init(const struct wps_config *cfg)
@@ -171,3 +172,73 @@ const u8 * wps_get_uuid_e(const u8 *buf, size_t len)
 		return NULL;
 	return attr.uuid_e;
 }
+
+
+struct wpabuf * wps_build_assoc_req_ie(void)
+{
+	struct wpabuf *ie;
+	u8 *len;
+
+	wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
+		   "Request");
+	ie = wpabuf_alloc(100);
+	if (ie == NULL)
+		return NULL;
+
+	wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
+	len = wpabuf_put(ie, 1);
+	wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
+
+	if (wps_build_version(ie) ||
+	    wps_build_req_type(ie, WPS_REQ_ENROLLEE)) {
+		wpabuf_free(ie);
+		return NULL;
+	}
+
+	*len = wpabuf_len(ie) - 2;
+
+	return ie;
+}
+
+
+struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
+				       const u8 *uuid)
+{
+	struct wpabuf *ie;
+	u8 *len;
+	u16 methods;
+
+	wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for Probe Request");
+
+	ie = wpabuf_alloc(200);
+	if (ie == NULL)
+		return NULL;
+
+	wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
+	len = wpabuf_put(ie, 1);
+	wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
+
+	if (pbc)
+		methods = WPS_CONFIG_PUSHBUTTON;
+	else
+		methods = WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY |
+			WPS_CONFIG_KEYPAD;
+
+	if (wps_build_version(ie) ||
+	    wps_build_req_type(ie, WPS_REQ_ENROLLEE) ||
+	    wps_build_config_methods(ie, methods) ||
+	    wps_build_uuid_e(ie, uuid) ||
+	    wps_build_primary_dev_type(dev, ie) ||
+	    wps_build_rf_bands(dev, ie) ||
+	    wps_build_assoc_state(NULL, ie) ||
+	    wps_build_config_error(ie, WPS_CFG_NO_ERROR) ||
+	    wps_build_dev_password_id(ie, pbc ? DEV_PW_PUSHBUTTON :
+				      DEV_PW_DEFAULT)) {
+		wpabuf_free(ie);
+		return NULL;
+	}
+
+	*len = wpabuf_len(ie) - 2;
+
+	return ie;
+}

+ 17 - 19
src/wps/wps.h

@@ -37,6 +37,20 @@ struct wps_credential {
 	u8 mac_addr[ETH_ALEN];
 };
 
+struct wps_device_data {
+	u8 mac_addr[ETH_ALEN];
+	char *device_name;
+	char *manufacturer;
+	char *model_name;
+	char *model_number;
+	char *serial_number;
+	u16 categ;
+	u32 oui;
+	u16 sub_categ;
+	u32 os_version;
+	u8 rf_bands; /* WPS_RF_* */
+};
+
 struct wps_config {
 	int authenticator;
 	struct wps_context *wps;
@@ -65,21 +79,9 @@ struct wpabuf * wps_get_msg(struct wps_data *wps, u8 *op_code);
 int wps_is_selected_pbc_registrar(const u8 *buf, size_t len);
 int wps_is_selected_pin_registrar(const u8 *buf, size_t len);
 const u8 * wps_get_uuid_e(const u8 *buf, size_t len);
-
-
-struct wps_device_data {
-	u8 mac_addr[ETH_ALEN];
-	char *device_name;
-	char *manufacturer;
-	char *model_name;
-	char *model_number;
-	char *serial_number;
-	u16 categ;
-	u32 oui;
-	u16 sub_categ;
-	u32 os_version;
-	u8 rf_bands; /* WPS_RF_* */
-};
+struct wpabuf * wps_build_assoc_req_ie(void);
+struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
+				       const u8 *uuid);
 
 
 struct wps_registrar_config {
@@ -131,8 +133,4 @@ int wps_registrar_button_pushed(struct wps_registrar *reg);
 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
 				const struct wpabuf *wps_data);
 
-struct wpabuf * wps_build_assoc_req_ie(void);
-struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
-				       const u8 *uuid);
-
 #endif /* WPS_H */

+ 0 - 71
src/wps/wps_common.c

@@ -19,7 +19,6 @@
 #include "sha256.h"
 #include "aes_wrap.h"
 #include "crypto.h"
-#include "ieee802_11_defs.h"
 #include "wps_i.h"
 #include "wps_dev_attr.h"
 
@@ -62,76 +61,6 @@ void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
 }
 
 
-struct wpabuf * wps_build_assoc_req_ie(void)
-{
-	struct wpabuf *ie;
-	u8 *len;
-
-	wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
-		   "Request");
-	ie = wpabuf_alloc(100);
-	if (ie == NULL)
-		return NULL;
-
-	wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
-	len = wpabuf_put(ie, 1);
-	wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
-
-	if (wps_build_version(ie) ||
-	    wps_build_req_type(ie, WPS_REQ_ENROLLEE)) {
-		wpabuf_free(ie);
-		return NULL;
-	}
-
-	*len = wpabuf_len(ie) - 2;
-
-	return ie;
-}
-
-
-struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
-				       const u8 *uuid)
-{
-	struct wpabuf *ie;
-	u8 *len;
-	u16 methods;
-
-	wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for Probe Request");
-
-	ie = wpabuf_alloc(200);
-	if (ie == NULL)
-		return NULL;
-
-	wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
-	len = wpabuf_put(ie, 1);
-	wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
-
-	if (pbc)
-		methods = WPS_CONFIG_PUSHBUTTON;
-	else
-		methods = WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY |
-			WPS_CONFIG_KEYPAD;
-
-	if (wps_build_version(ie) ||
-	    wps_build_req_type(ie, WPS_REQ_ENROLLEE) ||
-	    wps_build_config_methods(ie, methods) ||
-	    wps_build_uuid_e(ie, uuid) ||
-	    wps_build_primary_dev_type(dev, ie) ||
-	    wps_build_rf_bands(dev, ie) ||
-	    wps_build_assoc_state(NULL, ie) ||
-	    wps_build_config_error(ie, WPS_CFG_NO_ERROR) ||
-	    wps_build_dev_password_id(ie, pbc ? DEV_PW_PUSHBUTTON :
-				      DEV_PW_DEFAULT)) {
-		wpabuf_free(ie);
-		return NULL;
-	}
-
-	*len = wpabuf_len(ie) - 2;
-
-	return ie;
-}
-
-
 int wps_derive_keys(struct wps_data *wps)
 {
 	struct wpabuf *pubkey, *dh_shared;