WPS: Moved wps_context initialization into wps_supplicant.c

The wps_context data is now managed at wpa_supplicant, not EAP-WSC. This
makes wpa_supplicant design for WPS match with hostapd one and also
makes it easier configure whatever parameters and callbacks are needed
for WPS.
This commit is contained in:
Jouni Malinen 2008-11-28 20:32:13 +02:00
parent bcbbc7af45
commit 116654ce24
11 changed files with 81 additions and 63 deletions

View file

@ -1182,6 +1182,7 @@ struct eap_sm * eap_peer_sm_init(void *eapol_ctx,
os_memcpy(sm->mac_addr, conf->mac_addr, ETH_ALEN);
if (conf->uuid)
os_memcpy(sm->uuid, conf->uuid, 16);
sm->wps = conf->wps;
os_memset(&tlsconf, 0, sizeof(tlsconf));
tlsconf.opensc_engine_path = conf->opensc_engine_path;

View file

@ -22,7 +22,6 @@
struct eap_sm;
struct wpa_config_blob;
struct wpabuf;
struct wps_credential;
struct eap_method_type {
int vendor;
@ -214,17 +213,6 @@ struct eapol_callbacks {
*/
void (*notify_pending)(void *ctx);
/**
* wps_cred - Notify that new credential was received from WPS
* @ctx: eapol_ctx from eap_peer_sm_init() call
* Returns: 0 on success (credential stored), -1 on failure
*
* This callback is only needed when using WPS Enrollee to configure
* new credentials. This can be left %NULL if no WPS functionality is
* enabled.
*/
int (*wps_cred)(void *ctx, const struct wps_credential *cred);
/**
* eap_param_needed - Notify that EAP parameter is needed
* @ctx: eapol_ctx from eap_peer_sm_init() call
@ -269,6 +257,12 @@ struct eap_config {
* This is only used by EAP-WSC and can be left %NULL if not available.
*/
const u8 *uuid;
/**
* wps - WPS context data
*
* This is only used by EAP-WSC and can be left %NULL if not available.
*/
struct wps_context *wps;
};
struct eap_sm * eap_peer_sm_init(void *eapol_ctx,

View file

@ -335,6 +335,7 @@ struct eap_sm {
u8 mac_addr[ETH_ALEN];
u8 uuid[16];
struct wps_context *wps;
};
const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len);

View file

@ -106,7 +106,13 @@ static void * eap_wsc_init(struct eap_sm *sm)
struct wps_config cfg;
const char *pos;
const char *phase1;
struct wps_context *wps = NULL;
struct wps_context *wps;
wps = sm->wps;
if (wps == NULL) {
wpa_printf(MSG_ERROR, "EAP-WSC: WPS context not available");
return NULL;
}
identity = eap_get_config_identity(sm, &identity_len);
@ -127,27 +133,7 @@ static void * eap_wsc_init(struct eap_sm *sm)
return NULL;
data->state = registrar ? MSG : WAIT_START;
data->registrar = registrar;
wps = os_zalloc(sizeof(*wps));
if (wps == NULL) {
os_free(data);
return NULL;
}
data->wps_ctx = wps;
wps->cb_ctx = sm->eapol_ctx;
wps->cred_cb = sm->eapol_cb->wps_cred;
/* TODO: store wps_context at higher layer and make the device data
* configurable */
wps->dev.device_name = "dev name";
wps->dev.manufacturer = "manuf";
wps->dev.model_name = "model name";
wps->dev.model_number = "model number";
wps->dev.serial_number = "12345";
wps->dev.categ = WPS_DEV_COMPUTER;
wps->dev.oui = WPS_DEV_OUI_WFA;
wps->dev.sub_categ = WPS_DEV_COMPUTER_PC;
if (registrar) {
struct wps_registrar_config rcfg;
@ -175,7 +161,7 @@ static void * eap_wsc_init(struct eap_sm *sm)
os_memset(&cfg, 0, sizeof(cfg));
cfg.authenticator = 0;
cfg.wps = wps;
cfg.registrar = data->wps_ctx ? data->wps_ctx->registrar : NULL;
cfg.registrar = registrar ? data->wps_ctx->registrar : NULL;
cfg.enrollee_mac_addr = sm->mac_addr;
phase1 = eap_get_config_phase1(sm);
@ -238,11 +224,9 @@ static void eap_wsc_deinit(struct eap_sm *sm, void *priv)
wpabuf_free(data->in_buf);
wpabuf_free(data->out_buf);
wps_deinit(data->wps);
if (data->wps_ctx) {
wps_registrar_deinit(data->wps_ctx->registrar);
os_free(data->wps_ctx->network_key);
os_free(data->wps_ctx);
}
wps_registrar_deinit(data->wps_ctx->registrar);
os_free(data->wps_ctx->network_key);
data->wps_ctx->network_key = NULL;
os_free(data);
}

View file

@ -1742,20 +1742,6 @@ static void eapol_sm_notify_pending(void *ctx)
}
#ifdef CONFIG_WPS
static int eapol_sm_wps_cred(void *ctx, const struct wps_credential *cred)
{
struct eapol_sm *sm = ctx;
wpa_printf(MSG_DEBUG, "EAPOL: received new WPS credential");
if (sm->ctx->wps_cred)
return sm->ctx->wps_cred(sm->ctx->ctx, cred);
return 0;
}
#else /* CONFIG_WPS */
#define eapol_sm_wps_cred NULL
#endif /* CONFIG_WPS */
#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
static void eapol_sm_eap_param_needed(void *ctx, const char *field,
const char *txt)
@ -1781,7 +1767,6 @@ static struct eapol_callbacks eapol_cb =
eapol_sm_set_config_blob,
eapol_sm_get_config_blob,
eapol_sm_notify_pending,
eapol_sm_wps_cred,
eapol_sm_eap_param_needed
};
@ -1821,6 +1806,7 @@ struct eapol_sm *eapol_sm_init(struct eapol_ctx *ctx)
#endif /* EAP_TLS_OPENSSL */
conf.mac_addr = ctx->mac_addr;
conf.uuid = ctx->uuid;
conf.wps = ctx->wps;
sm->eap = eap_peer_sm_init(sm, &eapol_cb, sm->ctx->msg_ctx, &conf);
if (sm->eap == NULL) {

View file

@ -63,7 +63,6 @@ struct eapol_config {
struct eapol_sm;
struct wpa_config_blob;
struct wps_credential;
/**
* struct eapol_ctx - Global (for all networks) EAPOL state machine context
@ -215,15 +214,11 @@ struct eapol_ctx {
const u8 *uuid;
/**
* wps_cred - Notify that new credential was received from WPS
* @ctx: Callback context (ctx)
* Returns: 0 on success (credential stored), -1 on failure
* wps - WPS context data
*
* This callback is only needed when using WPS Enrollee to configure
* new credentials. This can be left %NULL if no WPS functionality is
* enabled.
* This is only used by EAP-WSC and can be left %NULL if not available.
*/
int (*wps_cred)(void *ctx, const struct wps_credential *cred);
struct wps_context *wps;
/**
* eap_param_needed - Notify that EAP parameter is needed

View file

@ -39,6 +39,7 @@
#include "blacklist.h"
#include "wpas_glue.h"
#include "wps/wps.h"
#include "wps_supplicant.h"
const char *wpa_supplicant_version =
"wpa_supplicant v" VERSION_STR "\n"
@ -386,6 +387,8 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
wpa_supplicant_cancel_auth_timeout(wpa_s);
ieee80211_sta_deinit(wpa_s);
wpas_wps_deinit(wpa_s);
}
@ -1789,6 +1792,9 @@ static int wpa_supplicant_init_iface2(struct wpa_supplicant *wpa_s)
wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
if (wpas_wps_init(wpa_s))
return -1;
if (wpa_supplicant_init_eapol(wpa_s) < 0)
return -1;
wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);

View file

@ -338,6 +338,8 @@ struct wpa_supplicant {
int pending_mic_error_report;
int pending_mic_error_pairwise;
int mic_errors_seen; /* Michael MIC errors with the current PTK */
struct wps_context *wps;
};

View file

@ -560,7 +560,7 @@ int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
#endif /* EAP_TLS_OPENSSL */
ctx->mac_addr = wpa_s->own_addr;
ctx->uuid = wpa_s->conf->uuid;
ctx->wps_cred = wpas_wps_get_cred_cb();
ctx->wps = wpa_s->wps;
ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
ctx->cb = wpa_supplicant_eapol_cb;
ctx->cb_ctx = wpa_s;

View file

@ -175,3 +175,41 @@ void * wpas_wps_get_cred_cb(void)
{
return wpa_supplicant_wps_cred;
}
int wpas_wps_init(struct wpa_supplicant *wpa_s)
{
struct wps_context *wps;
wps = os_zalloc(sizeof(*wps));
if (wps == NULL)
return -1;
wps->cred_cb = wpa_supplicant_wps_cred;
wps->cb_ctx = wpa_s;
/* TODO: make the device data configurable */
wps->dev.device_name = "dev name";
wps->dev.manufacturer = "manuf";
wps->dev.model_name = "model name";
wps->dev.model_number = "model number";
wps->dev.serial_number = "12345";
wps->dev.categ = WPS_DEV_COMPUTER;
wps->dev.oui = WPS_DEV_OUI_WFA;
wps->dev.sub_categ = WPS_DEV_COMPUTER_PC;
wpa_s->wps = wps;
return 0;
}
void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
{
if (wpa_s->wps == NULL)
return;
os_free(wpa_s->wps->network_key);
os_free(wpa_s->wps);
wpa_s->wps = NULL;
}

View file

@ -17,11 +17,22 @@
#ifdef CONFIG_WPS
int wpas_wps_init(struct wpa_supplicant *wpa_s);
void wpas_wps_deinit(struct wpa_supplicant *wpa_s);
int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s);
void * wpas_wps_get_cred_cb(void);
#else /* CONFIG_WPS */
static inline int wpas_wps_init(struct wpa_supplicant *wpa_s)
{
return 0;
}
static inline void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
{
}
static inline int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
{
return 0;