aboutsummaryrefslogtreecommitdiffstats
path: root/src/wps/wps_registrar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wps/wps_registrar.c')
-rw-r--r--src/wps/wps_registrar.c98
1 files changed, 92 insertions, 6 deletions
diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c
index 30b78b3..c2104ad 100644
--- a/src/wps/wps_registrar.c
+++ b/src/wps/wps_registrar.c
@@ -19,6 +19,34 @@
#include "wps_i.h"
+struct wps_uuid_pin {
+ struct wps_uuid_pin *next;
+ u8 uuid[WPS_UUID_LEN];
+ u8 *pin;
+ size_t pin_len;
+};
+
+
+static void wps_free_pin(struct wps_uuid_pin *pin)
+{
+ os_free(pin->pin);
+ os_free(pin);
+}
+
+
+static void wps_free_pins(struct wps_uuid_pin *pins)
+{
+ struct wps_uuid_pin *pin, *prev;
+
+ pin = pins;
+ while (pin) {
+ prev = pin;
+ pin = pin->next;
+ wps_free_pin(prev);
+ }
+}
+
+
struct wps_registrar {
int wps_state;
u8 uuid[WPS_UUID_LEN];
@@ -32,6 +60,8 @@ struct wps_registrar {
int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
size_t psk_len);
void *cb_ctx;
+
+ struct wps_uuid_pin *pins;
};
@@ -78,10 +108,57 @@ void wps_registrar_deinit(struct wps_registrar *reg)
if (reg == NULL)
return;
os_free(reg->network_key);
+ wps_free_pins(reg->pins);
os_free(reg);
}
+int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
+ const u8 *pin, size_t pin_len)
+{
+ struct wps_uuid_pin *p;
+
+ p = os_zalloc(sizeof(*p));
+ if (p == NULL)
+ return -1;
+ os_memcpy(p->uuid, uuid, WPS_UUID_LEN);
+ p->pin = os_malloc(pin_len);
+ if (p->pin == NULL) {
+ os_free(p);
+ return -1;
+ }
+ os_memcpy(p->pin, pin, pin_len);
+ p->pin_len = pin_len;
+
+ p->next = reg->pins;
+ reg->pins = p;
+
+ wpa_printf(MSG_DEBUG, "WPS: A new PIN configured");
+ wpa_hexdump(MSG_DEBUG, "WPS: UUID", uuid, WPS_UUID_LEN);
+ wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
+
+ return 0;
+}
+
+
+static const u8 * wps_registrar_get_pin(struct wps_registrar *reg,
+ const u8 *uuid, size_t *pin_len)
+{
+ struct wps_uuid_pin *pin;
+
+ pin = reg->pins;
+ while (pin) {
+ if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
+ *pin_len = pin->pin_len;
+ return pin->pin;
+ }
+ pin = pin->next;
+ }
+
+ return NULL;
+}
+
+
static int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
const u8 *psk, size_t psk_len)
{
@@ -94,17 +171,26 @@ static int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
static int wps_get_dev_password(struct wps_data *wps)
{
+ const u8 *pin;
+ size_t pin_len;
+
os_free(wps->dev_password);
wps->dev_password = NULL;
- /* TODO: callback to request Device Password */
- if (1) {
- wps->dev_password = (u8 *) os_strdup("12345670");
- wps->dev_password_len = 8;
- return 0;
+ pin = wps_registrar_get_pin(wps->registrar, wps->uuid_e, &pin_len);
+ if (pin == NULL) {
+ wpa_printf(MSG_DEBUG, "WPS: No Device Password available for "
+ "the Enrollee");
+ return -1;
}
- return -1;
+ wps->dev_password = os_malloc(pin_len);
+ if (wps->dev_password == NULL)
+ return -1;
+ os_memcpy(wps->dev_password, pin, pin_len);
+ wps->dev_password_len = pin_len;
+
+ return 0;
}