aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2008-01-14 03:38:41 (GMT)
committerJouni Malinen <j@w1.fi>2008-01-14 03:38:41 (GMT)
commitbf843af5cd4adabdecaab0f67e229fc6af794770 (patch)
treee1caf65187d6b8082097fe629fa35f93e8eb32a3 /hostapd
parent2e6a91c459ab1f3bb210d05eec2f141c1dbb4473 (diff)
downloadhostap-history-bf843af5cd4adabdecaab0f67e229fc6af794770.zip
hostap-history-bf843af5cd4adabdecaab0f67e229fc6af794770.tar.gz
hostap-history-bf843af5cd4adabdecaab0f67e229fc6af794770.tar.bz2
WPS: Move device-specific data from Registrar to generic WPS context
This adds a new struct wps_context for device-specific data that fits better for number of variables than struct wps_registrar. This allows AP configuration to be provided to Enrollee code so that M7 can be built with current AP configuration for external Registrar registration. In addition, Network Key is now hex encoded in wps_hostapd.c if needed to use correct fixed-PSK/passphrase setting. It should be noted that the option of using per-device PSK works only when the supplicant is acting as an Enrollee. If the supplicant is acting as a Registrar, generating a new per-device PSK would likely not work since the external Registrar could provision that PSK to other devices.
Diffstat (limited to 'hostapd')
-rw-r--r--hostapd/eapol_sm.c4
-rw-r--r--hostapd/eapol_sm.h2
-rw-r--r--hostapd/hostapd.c2
-rw-r--r--hostapd/hostapd.h2
-rw-r--r--hostapd/ieee802_1x.c2
-rw-r--r--hostapd/wps_hostapd.c146
6 files changed, 98 insertions, 60 deletions
diff --git a/hostapd/eapol_sm.c b/hostapd/eapol_sm.c
index c489909..1b277d6 100644
--- a/hostapd/eapol_sm.c
+++ b/hostapd/eapol_sm.c
@@ -806,7 +806,7 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
eap_conf.pac_opaque_encr_key = eapol->conf.pac_opaque_encr_key;
eap_conf.eap_fast_a_id = eapol->conf.eap_fast_a_id;
eap_conf.eap_sim_aka_result_ind = eapol->conf.eap_sim_aka_result_ind;
- eap_conf.wps_registrar = eapol->conf.wps_registrar;
+ eap_conf.wps = eapol->conf.wps;
sm->eap = eap_server_sm_init(sm, &eapol_cb, &eap_conf);
if (sm->eap == NULL) {
eapol_auth_free(sm);
@@ -1233,7 +1233,7 @@ static int eapol_auth_conf_clone(struct eapol_auth_config *dst,
else
dst->eap_fast_a_id = NULL;
dst->eap_sim_aka_result_ind = src->eap_sim_aka_result_ind;
- dst->wps_registrar = src->wps_registrar;
+ dst->wps = src->wps;
return 0;
}
diff --git a/hostapd/eapol_sm.h b/hostapd/eapol_sm.h
index 9a561f8..a200882 100644
--- a/hostapd/eapol_sm.h
+++ b/hostapd/eapol_sm.h
@@ -50,7 +50,7 @@ struct eapol_auth_config {
u8 *pac_opaque_encr_key;
char *eap_fast_a_id;
int eap_sim_aka_result_ind;
- struct wps_registrar *wps_registrar;
+ struct wps_context *wps;
/*
* Pointer to hostapd data. This is a temporary workaround for
diff --git a/hostapd/hostapd.c b/hostapd/hostapd.c
index cce6047..3381e36 100644
--- a/hostapd/hostapd.c
+++ b/hostapd/hostapd.c
@@ -1144,7 +1144,7 @@ static int hostapd_setup_radius_srv(struct hostapd_data *hapd,
srv.pac_opaque_encr_key = conf->pac_opaque_encr_key;
srv.eap_fast_a_id = conf->eap_fast_a_id;
srv.eap_sim_aka_result_ind = conf->eap_sim_aka_result_ind;
- srv.wps_registrar = hapd->wps_registrar;
+ srv.wps = hapd->wps;
srv.ipv6 = conf->radius_server_ipv6;
srv.get_eap_user = hostapd_radius_get_eap_user;
diff --git a/hostapd/hostapd.h b/hostapd/hostapd.h
index a203177..03dbc94 100644
--- a/hostapd/hostapd.h
+++ b/hostapd/hostapd.h
@@ -168,7 +168,7 @@ struct hostapd_data {
#endif /* CONFIG_FULL_DYNAMIC_VLAN */
struct l2_packet_data *l2;
- struct wps_registrar *wps_registrar;
+ struct wps_context *wps;
#ifdef CONFIG_WPS
u8 *wps_beacon_ie;
diff --git a/hostapd/ieee802_1x.c b/hostapd/ieee802_1x.c
index 2688a92..038da8a 100644
--- a/hostapd/ieee802_1x.c
+++ b/hostapd/ieee802_1x.c
@@ -1644,7 +1644,7 @@ int ieee802_1x_init(struct hostapd_data *hapd)
conf.pac_opaque_encr_key = hapd->conf->pac_opaque_encr_key;
conf.eap_fast_a_id = hapd->conf->eap_fast_a_id;
conf.eap_sim_aka_result_ind = hapd->conf->eap_sim_aka_result_ind;
- conf.wps_registrar = hapd->wps_registrar;
+ conf.wps = hapd->wps;
os_memset(&cb, 0, sizeof(cb));
cb.eapol_send = ieee802_1x_eapol_send;
diff --git a/hostapd/wps_hostapd.c b/hostapd/wps_hostapd.c
index 3404158..1b3028a 100644
--- a/hostapd/wps_hostapd.c
+++ b/hostapd/wps_hostapd.c
@@ -22,6 +22,7 @@
#include "ieee802_11_defs.h"
#include "wps/wps.h"
#include "wps/wps_defs.h"
+#include "wps/wps_dev_attr.h"
#include "wps_hostapd.h"
@@ -125,10 +126,10 @@ static void hostapd_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
return;
wpa_printf(MSG_DEBUG, "WPS: PIN needed for E-UUID %s", uuid);
len = os_snprintf(txt, sizeof(txt), WPS_EVENT_PIN_NEEDED
- "%s [%s|%s|%s|%s|%s|%d-%08X-%d]",
- uuid, dev->device_name, dev->manufacturer,
- dev->model_name, dev->model_number,
- dev->serial_number,
+ "%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))
hostapd_ctrl_iface_send(hapd, MSG_INFO, txt, len);
@@ -140,9 +141,10 @@ static void hostapd_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
if (f == NULL)
return;
os_get_time(&t);
- fprintf(f, "%ld\t%s\t%s\t%s\t%s\t%s\t%s\t%d-%08X-%d\n",
- t.sec, uuid, dev->device_name, dev->manufacturer,
- dev->model_name, dev->model_number,
+ fprintf(f, "%ld\t%s\t" MACSTR "\t%s\t%s\t%s\t%s\t%s"
+ "\t%d-%08X-%d\n",
+ t.sec, 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);
fclose(f);
@@ -167,6 +169,7 @@ static void hostapd_wps_clear_ies(struct hostapd_data *hapd)
int hostapd_init_wps(struct hostapd_data *hapd,
struct hostapd_bss_config *conf)
{
+ struct wps_context *wps;
struct wps_registrar_config cfg;
if (conf->wps_state == 0) {
@@ -174,104 +177,127 @@ int hostapd_init_wps(struct hostapd_data *hapd,
return 0;
}
+ wps = os_zalloc(sizeof(*wps));
+ if (wps == NULL)
+ return -1;
+
os_memset(&cfg, 0, sizeof(cfg));
- cfg.wps_state = hapd->conf->wps_state;
- cfg.ap_setup_locked = hapd->conf->ap_setup_locked;
- cfg.uuid = hapd->conf->uuid;
- cfg.ssid = (const u8 *) hapd->conf->ssid.ssid;
- cfg.ssid_len = hapd->conf->ssid.ssid_len;
- cfg.ap = 1;
- cfg.dev.device_name = hapd->conf->device_name;
- cfg.dev.manufacturer = hapd->conf->manufacturer;
- cfg.dev.model_name = hapd->conf->model_name;
- cfg.dev.model_number = hapd->conf->model_number;
- cfg.dev.serial_number = hapd->conf->serial_number;
+ 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);
+ wps->ssid_len = hapd->conf->ssid.ssid_len;
+ os_memcpy(wps->ssid, hapd->conf->ssid.ssid, wps->ssid_len);
+ wps->ap = 1;
+ os_memcpy(wps->dev.mac_addr, hapd->own_addr, ETH_ALEN);
+ wps->dev.device_name = hapd->conf->device_name;
+ wps->dev.manufacturer = hapd->conf->manufacturer;
+ wps->dev.model_name = hapd->conf->model_name;
+ wps->dev.model_number = hapd->conf->model_number;
+ wps->dev.serial_number = hapd->conf->serial_number;
if (hapd->conf->config_methods) {
char *m = hapd->conf->config_methods;
if (os_strstr(m, "label"))
- cfg.config_methods |= WPS_CONFIG_LABEL;
+ wps->config_methods |= WPS_CONFIG_LABEL;
if (os_strstr(m, "display"))
- cfg.config_methods |= WPS_CONFIG_DISPLAY;
+ wps->config_methods |= WPS_CONFIG_DISPLAY;
if (os_strstr(m, "push_button"))
- cfg.config_methods |= WPS_CONFIG_PUSHBUTTON;
+ wps->config_methods |= WPS_CONFIG_PUSHBUTTON;
if (os_strstr(m, "keypad"))
- cfg.config_methods |= WPS_CONFIG_KEYPAD;
+ wps->config_methods |= WPS_CONFIG_KEYPAD;
}
if (hapd->conf->device_type) {
char *pos;
u8 oui[4];
/* <categ>-<OUI>-<subcateg> */
- cfg.dev.categ = atoi(hapd->conf->device_type);
+ wps->dev.categ = atoi(hapd->conf->device_type);
pos = os_strchr(hapd->conf->device_type, '-');
if (pos == NULL) {
wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
+ os_free(wps);
return -1;
}
pos++;
if (hexstr2bin(pos, oui, 4)) {
wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
+ os_free(wps);
return -1;
}
- cfg.dev.oui = WPA_GET_BE32(oui);
+ wps->dev.oui = WPA_GET_BE32(oui);
pos = os_strchr(pos, '-');
if (pos == NULL) {
wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
+ os_free(wps);
return -1;
}
pos++;
- cfg.dev.sub_categ = atoi(pos);
+ wps->dev.sub_categ = atoi(pos);
}
- cfg.dev.os_version = WPA_GET_BE32(hapd->conf->os_version);
+ wps->dev.os_version = WPA_GET_BE32(hapd->conf->os_version);
if (conf->wpa & WPA_PROTO_RSN) {
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
- cfg.auth_types |= WPS_AUTH_WPA2PSK;
+ wps->auth_types |= WPS_AUTH_WPA2PSK;
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
- cfg.auth_types |= WPS_AUTH_WPA2;
+ wps->auth_types |= WPS_AUTH_WPA2;
if (conf->rsn_pairwise & WPA_CIPHER_CCMP)
- cfg.encr_types |= WPS_ENCR_AES;
+ wps->encr_types |= WPS_ENCR_AES;
if (conf->rsn_pairwise & WPA_CIPHER_TKIP)
- cfg.encr_types |= WPS_ENCR_TKIP;
+ wps->encr_types |= WPS_ENCR_TKIP;
}
if (conf->wpa & WPA_PROTO_WPA) {
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
- cfg.auth_types |= WPS_AUTH_WPAPSK;
+ wps->auth_types |= WPS_AUTH_WPAPSK;
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
- cfg.auth_types |= WPS_AUTH_WPA;
+ wps->auth_types |= WPS_AUTH_WPA;
if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
- cfg.encr_types |= WPS_ENCR_AES;
+ wps->encr_types |= WPS_ENCR_AES;
if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
- cfg.encr_types |= WPS_ENCR_TKIP;
+ wps->encr_types |= WPS_ENCR_TKIP;
}
if (conf->ssid.security_policy == SECURITY_PLAINTEXT) {
- cfg.encr_types |= WPS_ENCR_NONE;
- cfg.auth_types |= WPS_AUTH_OPEN;
+ wps->encr_types |= WPS_ENCR_NONE;
+ wps->auth_types |= WPS_AUTH_OPEN;
} else if (conf->ssid.security_policy == SECURITY_STATIC_WEP) {
- cfg.encr_types |= WPS_ENCR_WEP;
+ wps->encr_types |= WPS_ENCR_WEP;
if (conf->auth_algs & WPA_AUTH_ALG_OPEN)
- cfg.auth_types |= WPS_AUTH_OPEN;
+ wps->auth_types |= WPS_AUTH_OPEN;
if (conf->auth_algs & WPA_AUTH_ALG_SHARED)
- cfg.auth_types |= WPS_AUTH_SHARED;
+ wps->auth_types |= WPS_AUTH_SHARED;
} else if (conf->ssid.security_policy == SECURITY_IEEE_802_1X) {
- cfg.auth_types |= WPS_AUTH_OPEN;
+ wps->auth_types |= WPS_AUTH_OPEN;
if (conf->default_wep_key_len)
- cfg.encr_types |= WPS_ENCR_WEP;
+ wps->encr_types |= WPS_ENCR_WEP;
else
- cfg.encr_types |= WPS_ENCR_NONE;
+ wps->encr_types |= WPS_ENCR_NONE;
}
if (conf->ssid.wpa_psk_file) {
/* Use per-device PSKs */
+ } else if (conf->ssid.wpa_passphrase) {
+ wps->network_key = (u8 *) os_strdup(conf->ssid.wpa_passphrase);
+ wps->network_key_len = os_strlen(conf->ssid.wpa_passphrase);
} else if (conf->ssid.wpa_psk) {
- cfg.network_key = conf->ssid.wpa_psk->psk;
- cfg.network_key_len = PMK_LEN;
+ wps->network_key = os_malloc(2 * PMK_LEN + 1);
+ if (wps->network_key == NULL) {
+ os_free(wps);
+ return -1;
+ }
+ wpa_snprintf_hex((char *) wps->network_key, 2 * PMK_LEN + 1,
+ conf->ssid.wpa_psk->psk, PMK_LEN);
+ wps->network_key_len = 2 * PMK_LEN;
} else if (conf->ssid.wep.keys_set && conf->ssid.wep.key[0]) {
- cfg.network_key = conf->ssid.wep.key[0];
- cfg.network_key_len = conf->ssid.wep.len[0];
+ wps->network_key = os_malloc(conf->ssid.wep.len[0]);
+ if (wps->network_key == NULL) {
+ os_free(wps);
+ return -1;
+ }
+ os_memcpy(wps->network_key, conf->ssid.wep.key[0],
+ conf->ssid.wep.len[0]);
+ wps->network_key_len = conf->ssid.wep.len[0];
}
cfg.new_psk_cb = hostapd_wps_new_psk_cb;
@@ -279,19 +305,29 @@ int hostapd_init_wps(struct hostapd_data *hapd,
cfg.pin_needed_cb = hostapd_wps_pin_needed_cb;
cfg.cb_ctx = hapd;
- hapd->wps_registrar = wps_registrar_init(&cfg);
- if (hapd->wps_registrar == NULL) {
+ wps->registrar = wps_registrar_init(wps, &cfg);
+ if (wps->registrar == NULL) {
printf("Failed to initialize WPS Registrar\n");
+ os_free(wps->network_key);
+ os_free(wps);
return -1;
}
+ hapd->wps = wps;
+
return 0;
}
void hostapd_deinit_wps(struct hostapd_data *hapd)
{
- wps_registrar_deinit(hapd->wps_registrar);
+ if (hapd->wps == NULL)
+ return;
+ wps_registrar_deinit(hapd->wps->registrar);
+ wps_device_data_free(&hapd->wps->dev);
+ os_free(hapd->wps->network_key);
+ os_free(hapd->wps);
+ hapd->wps = NULL;
hostapd_wps_clear_ies(hapd);
}
@@ -300,16 +336,18 @@ int hostapd_wps_add_pin(struct hostapd_data *hapd, const char *uuid,
const char *pin)
{
u8 u[UUID_LEN];
- if (uuid_str2bin(uuid, u))
+ if (hapd->wps == NULL || uuid_str2bin(uuid, u))
return -1;
- return wps_registrar_add_pin(hapd->wps_registrar, u,
+ return wps_registrar_add_pin(hapd->wps->registrar, u,
(const u8 *) pin, os_strlen(pin));
}
int hostapd_wps_button_pushed(struct hostapd_data *hapd)
{
- return wps_registrar_button_pushed(hapd->wps_registrar);
+ if (hapd->wps == NULL)
+ return -1;
+ return wps_registrar_button_pushed(hapd->wps->registrar);
}
@@ -319,7 +357,7 @@ void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
struct wpabuf *wps_ie;
const u8 *end, *pos, *wps;
- if (hapd->wps_registrar == NULL)
+ if (hapd->wps == NULL)
return;
pos = ie;
@@ -356,7 +394,7 @@ void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
}
if (wpabuf_len(wps_ie) > 0)
- wps_registrar_probe_req_rx(hapd->wps_registrar, addr, wps_ie);
+ wps_registrar_probe_req_rx(hapd->wps->registrar, addr, wps_ie);
wpabuf_free(wps_ie);
}