aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-01-01 20:56:52 (GMT)
committerJouni Malinen <j@w1.fi>2009-01-01 20:56:52 (GMT)
commit79da74a20c0f61ded4c0fd203f054cf3783f54da (patch)
tree7026e9d131c454f430e4cb10058b0bb8cb65299e
parent84f5b41fc1e7a74c343b42075e1708a19d44a63e (diff)
downloadhostap-06-79da74a20c0f61ded4c0fd203f054cf3783f54da.zip
hostap-06-79da74a20c0f61ded4c0fd203f054cf3783f54da.tar.gz
hostap-06-79da74a20c0f61ded4c0fd203f054cf3783f54da.tar.bz2
WPS: Generate UUID based on MAC address, if not set
Generate a SHA1 hash -based UUID from the local MAC address if the UUID was not configured. This makes it easier to prepare for WPS since there is no need to generate an UUID.
-rw-r--r--hostapd/README-WPS1
-rw-r--r--hostapd/hostapd.conf1
-rw-r--r--hostapd/wps_hostapd.c7
-rw-r--r--src/utils/uuid.c30
-rw-r--r--src/utils/uuid.h1
-rw-r--r--wpa_supplicant/README-WPS3
-rw-r--r--wpa_supplicant/scan.c2
-rw-r--r--wpa_supplicant/wpa_supplicant.conf1
-rw-r--r--wpa_supplicant/wps_supplicant.c8
9 files changed, 50 insertions, 4 deletions
diff --git a/hostapd/README-WPS b/hostapd/README-WPS
index 2786c60..e435a56 100644
--- a/hostapd/README-WPS
+++ b/hostapd/README-WPS
@@ -94,6 +94,7 @@ eap_server=1
# WPS configuration (AP configured, do not allow external WPS Registrars)
wps_state=2
ap_setup_locked=1
+# If UUID is not configured, it will be generated based on local MAC address.
uuid=87654321-9abc-def0-1234-56789abc0000
wps_pin_requests=/var/run/hostapd.pin-req
device_name=Wireless AP
diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
index 9732573..c5d82e6 100644
--- a/hostapd/hostapd.conf
+++ b/hostapd/hostapd.conf
@@ -871,6 +871,7 @@ own_ip_addr=127.0.0.1
# Universally Unique IDentifier (UUID; see RFC 4122) of the device
# This value is used as the UUID for the internal WPS Registrar. If the AP
# is also using UPnP, this value should be set to the device's UPnP UUID.
+# If not configured, UUID will be generated based on the local MAC address.
#uuid=12345678-9abc-def0-1234-56789abcdef0
# Note: If wpa_psk_file is set, WPS is used to generate random, per-device PSKs
diff --git a/hostapd/wps_hostapd.c b/hostapd/wps_hostapd.c
index 4871d9c..14966d9 100644
--- a/hostapd/wps_hostapd.c
+++ b/hostapd/wps_hostapd.c
@@ -383,7 +383,12 @@ int hostapd_init_wps(struct hostapd_data *hapd,
os_memset(&cfg, 0, sizeof(cfg));
wps->wps_state = hapd->conf->wps_state;
wps->ap_setup_locked = hapd->conf->ap_setup_locked;
- os_memcpy(wps->uuid, hapd->conf->uuid, UUID_LEN);
+ if (is_nil_uuid(hapd->conf->uuid)) {
+ uuid_gen_mac_addr(hapd->own_addr, wps->uuid);
+ wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address",
+ wps->uuid, UUID_LEN);
+ } else
+ os_memcpy(wps->uuid, hapd->conf->uuid, UUID_LEN);
wps->ssid_len = hapd->conf->ssid.ssid_len;
os_memcpy(wps->ssid, hapd->conf->ssid.ssid, wps->ssid_len);
wps->ap = 1;
diff --git a/src/utils/uuid.c b/src/utils/uuid.c
index d8cc267..620d3d6 100644
--- a/src/utils/uuid.c
+++ b/src/utils/uuid.c
@@ -15,6 +15,8 @@
#include "includes.h"
#include "common.h"
+#include "crypto.h"
+#include "sha1.h"
#include "uuid.h"
int uuid_str2bin(const char *str, u8 *bin)
@@ -75,3 +77,31 @@ int is_nil_uuid(const u8 *uuid)
return 0;
return 1;
}
+
+
+void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid)
+{
+ const u8 *addr[2];
+ size_t len[2];
+ u8 hash[SHA1_MAC_LEN];
+ u8 nsid[16] = {
+ 0x52, 0x64, 0x80, 0xf8,
+ 0xc9, 0x9b,
+ 0x4b, 0xe5,
+ 0xa6, 0x55,
+ 0x58, 0xed, 0x5f, 0x5d, 0x60, 0x84
+ };
+
+ addr[0] = nsid;
+ len[0] = sizeof(nsid);
+ addr[1] = mac_addr;
+ len[1] = 6;
+ sha1_vector(2, addr, len, hash);
+ os_memcpy(uuid, hash, 16);
+
+ /* Version: 5 = named-based version using SHA-1 */
+ uuid[6] = (5 << 4) | (uuid[6] & 0x0f);
+
+ /* Variant specified in RFC 4122 */
+ uuid[8] = 0x80 | (uuid[8] & 0x3f);
+}
diff --git a/src/utils/uuid.h b/src/utils/uuid.h
index 0759165..9fc2ba0 100644
--- a/src/utils/uuid.h
+++ b/src/utils/uuid.h
@@ -20,5 +20,6 @@
int uuid_str2bin(const char *str, u8 *bin);
int uuid_bin2str(const u8 *bin, char *str, size_t max_len);
int is_nil_uuid(const u8 *uuid);
+void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
#endif /* UUID_H */
diff --git a/wpa_supplicant/README-WPS b/wpa_supplicant/README-WPS
index b1aa0dc..284753f 100644
--- a/wpa_supplicant/README-WPS
+++ b/wpa_supplicant/README-WPS
@@ -67,7 +67,8 @@ CONFIG_WPS=y
WPS needs the Universally Unique IDentifier (UUID; see RFC 4122) for
the device. This is configured in the runtime configuration for
-wpa_supplicant:
+wpa_supplicant (if not set, UUID will be generated based on local MAC
+address):
# example UUID for WPS
uuid=12345678-9abc-def0-1234-56789abcdef0
diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index c7b2dbd..a9f86ea 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -181,7 +181,7 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
#ifdef CONFIG_WPS
if (wps) {
wps_ie = wps_build_probe_req_ie(wps == 2, &wpa_s->wps->dev,
- wpa_s->conf->uuid, req_type);
+ wpa_s->wps->uuid, req_type);
if (wps_ie) {
extra_ie = wpabuf_head(wps_ie);
extra_ie_len = wpabuf_len(wps_ie);
diff --git a/wpa_supplicant/wpa_supplicant.conf b/wpa_supplicant/wpa_supplicant.conf
index b92f43f..cfcea88 100644
--- a/wpa_supplicant/wpa_supplicant.conf
+++ b/wpa_supplicant/wpa_supplicant.conf
@@ -150,6 +150,7 @@ fast_reauth=1
# Wi-Fi Protected Setup (WPS) parameters
# Universally Unique IDentifier (UUID; see RFC 4122) of the device
+# If not configured, UUID will be generated based on the local MAC address.
#uuid=12345678-9abc-def0-1234-56789abcdef0
# Device Name
diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c
index eeee496..a538338 100644
--- a/wpa_supplicant/wps_supplicant.c
+++ b/wpa_supplicant/wps_supplicant.c
@@ -21,6 +21,7 @@
#include "eap_peer/eap.h"
#include "wpa_supplicant_i.h"
#include "eloop.h"
+#include "uuid.h"
#include "wpa_ctrl.h"
#include "eap_common/eap_wsc_common.h"
#include "wps/wps.h"
@@ -442,7 +443,12 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
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);
- os_memcpy(wps->uuid, wpa_s->conf->uuid, 16);
+ if (is_nil_uuid(wpa_s->conf->uuid)) {
+ uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
+ wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address",
+ wps->uuid, WPS_UUID_LEN);
+ } else
+ os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
wpa_s->wps = wps;