Moved WPS Registrar initialization from EAP peer to wps_supplicant.c

This matches the style used in hostapd, i.e., Registrar is initialized
only once and callbacks are now processed in wps_supplicant.c.
This commit is contained in:
Jouni Malinen 2009-01-03 20:18:35 +02:00
parent 41c00105f2
commit c5adf528a2
2 changed files with 49 additions and 57 deletions

View file

@ -65,38 +65,6 @@ static void eap_wsc_state(struct eap_wsc_data *data, int state)
} }
static int eap_wsc_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
size_t psk_len)
{
wpa_printf(MSG_DEBUG, "EAP-WSC: Received new WPA/WPA2-PSK from WPS for"
" STA " MACSTR, MAC2STR(mac_addr));
wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
/* TODO */
return 0;
}
static void eap_wsc_pin_needed_cb(void *ctx, const u8 *uuid_e,
const struct wps_device_data *dev)
{
char uuid[40], txt[400];
int len;
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
return;
wpa_printf(MSG_DEBUG, "EAP-WSC: PIN needed for E-UUID %s", uuid);
len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED "
"%s " MACSTR " [%s|%s|%s|%s|%s|%d-%08X-%d]",
uuid, MAC2STR(dev->mac_addr), dev->device_name,
dev->manufacturer, dev->model_name,
dev->model_number, dev->serial_number,
dev->categ, dev->oui, dev->sub_categ);
if (len > 0 && len < (int) sizeof(txt))
wpa_printf(MSG_INFO, "%s", txt);
}
static void * eap_wsc_init(struct eap_sm *sm) static void * eap_wsc_init(struct eap_sm *sm)
{ {
struct eap_wsc_data *data; struct eap_wsc_data *data;
@ -135,29 +103,6 @@ static void * eap_wsc_init(struct eap_sm *sm)
data->registrar = registrar; data->registrar = registrar;
data->wps_ctx = wps; data->wps_ctx = wps;
if (registrar) {
struct wps_registrar_config rcfg;
wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
os_memset(&rcfg, 0, sizeof(rcfg));
rcfg.new_psk_cb = eap_wsc_new_psk_cb;
rcfg.pin_needed_cb = eap_wsc_pin_needed_cb;
rcfg.cb_ctx = data;
wps->registrar = wps_registrar_init(wps, &rcfg);
if (wps->registrar == NULL) {
wpa_printf(MSG_DEBUG, "EAP-WSC: Failed to initialize "
"WPS Registrar");
os_free(wps->network_key);
os_free(wps);
os_free(data);
return NULL;
}
}
os_memset(&cfg, 0, sizeof(cfg)); os_memset(&cfg, 0, sizeof(cfg));
cfg.wps = wps; cfg.wps = wps;
cfg.registrar = registrar; cfg.registrar = registrar;
@ -212,8 +157,6 @@ static void eap_wsc_deinit(struct eap_sm *sm, void *priv)
wpabuf_free(data->in_buf); wpabuf_free(data->in_buf);
wpabuf_free(data->out_buf); wpabuf_free(data->out_buf);
wps_deinit(data->wps); wps_deinit(data->wps);
wps_registrar_deinit(data->wps_ctx->registrar);
data->wps_ctx->registrar = NULL;
os_free(data->wps_ctx->network_key); os_free(data->wps_ctx->network_key);
data->wps_ctx->network_key = NULL; data->wps_ctx->network_key = NULL;
os_free(data); os_free(data);

View file

@ -394,9 +394,42 @@ int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
} }
static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
size_t psk_len)
{
wpa_printf(MSG_DEBUG, "WPS: Received new WPA/WPA2-PSK from WPS for "
"STA " MACSTR, MAC2STR(mac_addr));
wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
/* TODO */
return 0;
}
static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
const struct wps_device_data *dev)
{
char uuid[40], txt[400];
int len;
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
return;
wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
" [%s|%s|%s|%s|%s|%d-%08X-%d]",
uuid, MAC2STR(dev->mac_addr), dev->device_name,
dev->manufacturer, dev->model_name,
dev->model_number, dev->serial_number,
dev->categ, dev->oui, dev->sub_categ);
if (len > 0 && len < (int) sizeof(txt))
wpa_printf(MSG_INFO, "%s", txt);
}
int wpas_wps_init(struct wpa_supplicant *wpa_s) int wpas_wps_init(struct wpa_supplicant *wpa_s)
{ {
struct wps_context *wps; struct wps_context *wps;
struct wps_registrar_config rcfg;
wps = os_zalloc(sizeof(*wps)); wps = os_zalloc(sizeof(*wps));
if (wps == NULL) if (wps == NULL)
@ -448,6 +481,21 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
} else } else
os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN); os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
os_memset(&rcfg, 0, sizeof(rcfg));
rcfg.new_psk_cb = wpas_wps_new_psk_cb;
rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
rcfg.cb_ctx = wpa_s;
wps->registrar = wps_registrar_init(wps, &rcfg);
if (wps->registrar == NULL) {
wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
os_free(wps);
return -1;
}
wpa_s->wps = wps; wpa_s->wps = wps;
return 0; return 0;
@ -461,6 +509,7 @@ void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
if (wpa_s->wps == NULL) if (wpa_s->wps == NULL)
return; return;
wps_registrar_deinit(wpa_s->wps->registrar);
os_free(wpa_s->wps->network_key); os_free(wpa_s->wps->network_key);
os_free(wpa_s->wps); os_free(wpa_s->wps);
wpa_s->wps = NULL; wpa_s->wps = NULL;