2008-11-23 18:34:26 +01:00
|
|
|
/*
|
|
|
|
* hostapd / WPS integration
|
2012-06-27 19:54:56 +02:00
|
|
|
* Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
|
2008-11-23 18:34:26 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-11-23 18:34:26 +01:00
|
|
|
*/
|
|
|
|
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "utils/includes.h"
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
|
|
|
#include "utils/uuid.h"
|
2009-11-29 16:51:55 +01:00
|
|
|
#include "common/wpa_ctrl.h"
|
|
|
|
#include "common/ieee802_11_defs.h"
|
|
|
|
#include "common/ieee802_11_common.h"
|
2009-11-29 19:03:28 +01:00
|
|
|
#include "eapol_auth/eapol_auth_sm.h"
|
2009-11-29 22:16:04 +01:00
|
|
|
#include "eapol_auth/eapol_auth_sm_i.h"
|
2008-11-23 18:34:26 +01:00
|
|
|
#include "wps/wps.h"
|
|
|
|
#include "wps/wps_defs.h"
|
|
|
|
#include "wps/wps_dev_attr.h"
|
2012-06-27 19:54:56 +02:00
|
|
|
#include "wps/wps_attr_parse.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "hostapd.h"
|
|
|
|
#include "ap_config.h"
|
2010-11-24 15:50:06 +01:00
|
|
|
#include "ap_drv_ops.h"
|
2010-04-06 17:04:30 +02:00
|
|
|
#include "beacon.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "sta_info.h"
|
2008-11-23 18:34:26 +01:00
|
|
|
#include "wps_hostapd.h"
|
|
|
|
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
#include "wps/wps_upnp.h"
|
|
|
|
static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
|
|
|
|
struct wps_context *wps);
|
|
|
|
static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd);
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2011-07-15 19:25:53 +02:00
|
|
|
static int hostapd_wps_probe_req_rx(void *ctx, const u8 *addr, const u8 *da,
|
|
|
|
const u8 *bssid,
|
2012-04-01 17:48:12 +02:00
|
|
|
const u8 *ie, size_t ie_len,
|
|
|
|
int ssi_signal);
|
2010-08-24 15:35:37 +02:00
|
|
|
static void hostapd_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
|
2014-03-20 16:01:37 +01:00
|
|
|
static void hostapd_wps_nfc_clear(struct wps_context *wps);
|
2009-06-12 17:13:40 +02:00
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
|
2010-10-08 16:15:16 +02:00
|
|
|
struct wps_for_each_data {
|
|
|
|
int (*func)(struct hostapd_data *h, void *ctx);
|
|
|
|
void *ctx;
|
2013-03-31 10:48:52 +02:00
|
|
|
struct hostapd_data *calling_hapd;
|
2010-10-08 16:15:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_for_each(struct hostapd_iface *iface, void *ctx)
|
|
|
|
{
|
|
|
|
struct wps_for_each_data *data = ctx;
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
if (iface == NULL)
|
|
|
|
return 0;
|
|
|
|
for (j = 0; j < iface->num_bss; j++) {
|
|
|
|
struct hostapd_data *hapd = iface->bss[j];
|
2013-03-31 10:48:52 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (hapd != data->calling_hapd &&
|
|
|
|
(hapd->conf->wps_independent ||
|
|
|
|
data->calling_hapd->conf->wps_independent))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = data->func(hapd, data->ctx);
|
2010-10-08 16:15:16 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hostapd_wps_for_each(struct hostapd_data *hapd,
|
|
|
|
int (*func)(struct hostapd_data *h, void *ctx),
|
|
|
|
void *ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_iface *iface = hapd->iface;
|
|
|
|
struct wps_for_each_data data;
|
|
|
|
data.func = func;
|
|
|
|
data.ctx = ctx;
|
2013-03-31 10:48:52 +02:00
|
|
|
data.calling_hapd = hapd;
|
2012-08-25 11:43:27 +02:00
|
|
|
if (iface->interfaces == NULL ||
|
|
|
|
iface->interfaces->for_each_interface == NULL)
|
2010-10-10 16:43:42 +02:00
|
|
|
return wps_for_each(iface, &data);
|
2012-08-25 11:43:27 +02:00
|
|
|
return iface->interfaces->for_each_interface(iface->interfaces,
|
|
|
|
wps_for_each, &data);
|
2010-10-08 16:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-01 09:47:34 +02:00
|
|
|
static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr,
|
|
|
|
const u8 *p2p_dev_addr, const u8 *psk,
|
2008-11-23 18:34:26 +01:00
|
|
|
size_t psk_len)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
struct hostapd_wpa_psk *p;
|
|
|
|
struct hostapd_ssid *ssid = &hapd->conf->ssid;
|
|
|
|
|
2013-09-01 09:47:34 +02:00
|
|
|
if (is_zero_ether_addr(p2p_dev_addr)) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"Received new WPA/WPA2-PSK from WPS for STA " MACSTR,
|
|
|
|
MAC2STR(mac_addr));
|
|
|
|
} else {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"Received new WPA/WPA2-PSK from WPS for STA " MACSTR
|
|
|
|
" P2P Device Addr " MACSTR,
|
|
|
|
MAC2STR(mac_addr), MAC2STR(p2p_dev_addr));
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
|
|
|
|
|
|
|
|
if (psk_len != PMK_LEN) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Unexpected PSK length %lu",
|
|
|
|
(unsigned long) psk_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the new PSK to runtime PSK list */
|
|
|
|
p = os_zalloc(sizeof(*p));
|
|
|
|
if (p == NULL)
|
|
|
|
return -1;
|
|
|
|
os_memcpy(p->addr, mac_addr, ETH_ALEN);
|
2013-09-01 09:47:34 +02:00
|
|
|
os_memcpy(p->p2p_dev_addr, p2p_dev_addr, ETH_ALEN);
|
2008-11-23 18:34:26 +01:00
|
|
|
os_memcpy(p->psk, psk, PMK_LEN);
|
|
|
|
|
2013-09-01 12:40:33 +02:00
|
|
|
if (hapd->new_psk_cb) {
|
|
|
|
hapd->new_psk_cb(hapd->new_psk_cb_ctx, mac_addr, p2p_dev_addr,
|
|
|
|
psk, psk_len);
|
|
|
|
}
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
p->next = ssid->wpa_psk;
|
|
|
|
ssid->wpa_psk = p;
|
|
|
|
|
|
|
|
if (ssid->wpa_psk_file) {
|
|
|
|
FILE *f;
|
|
|
|
char hex[PMK_LEN * 2 + 1];
|
|
|
|
/* Add the new PSK to PSK list file */
|
|
|
|
f = fopen(ssid->wpa_psk_file, "a");
|
|
|
|
if (f == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Failed to add the PSK to "
|
|
|
|
"'%s'", ssid->wpa_psk_file);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_snprintf_hex(hex, sizeof(hex), psk, psk_len);
|
|
|
|
fprintf(f, MACSTR " %s\n", MAC2STR(mac_addr), hex);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-24 18:46:06 +01:00
|
|
|
static int hostapd_wps_set_ie_cb(void *ctx, struct wpabuf *beacon_ie,
|
|
|
|
struct wpabuf *probe_resp_ie)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
2009-12-24 18:46:06 +01:00
|
|
|
wpabuf_free(hapd->wps_beacon_ie);
|
|
|
|
hapd->wps_beacon_ie = beacon_ie;
|
|
|
|
wpabuf_free(hapd->wps_probe_resp_ie);
|
|
|
|
hapd->wps_probe_resp_ie = probe_resp_ie;
|
2011-08-09 13:40:06 +02:00
|
|
|
if (hapd->beacon_set_done)
|
|
|
|
ieee802_11_set_beacon(hapd);
|
2010-11-24 15:50:06 +01:00
|
|
|
return hostapd_set_ap_wps_ie(hapd);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
|
|
|
|
const struct wps_device_data *dev)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
char uuid[40], txt[400];
|
|
|
|
int len;
|
2009-11-26 10:39:29 +01:00
|
|
|
char devtype[WPS_DEV_TYPE_BUFSIZE];
|
2008-11-23 18:34:26 +01:00
|
|
|
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
|
|
|
|
return;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: PIN needed for E-UUID %s", uuid);
|
|
|
|
len = os_snprintf(txt, sizeof(txt), WPS_EVENT_PIN_NEEDED
|
2009-11-26 10:39:29 +01:00
|
|
|
"%s " MACSTR " [%s|%s|%s|%s|%s|%s]",
|
2008-11-23 18:34:26 +01:00
|
|
|
uuid, MAC2STR(dev->mac_addr), dev->device_name,
|
|
|
|
dev->manufacturer, dev->model_name,
|
|
|
|
dev->model_number, dev->serial_number,
|
2009-11-26 10:39:29 +01:00
|
|
|
wps_dev_type_bin2str(dev->pri_dev_type, devtype,
|
|
|
|
sizeof(devtype)));
|
2014-12-07 11:15:34 +01:00
|
|
|
if (!os_snprintf_error(sizeof(txt), len))
|
2009-09-29 20:25:14 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, "%s", txt);
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
if (hapd->conf->wps_pin_requests) {
|
|
|
|
FILE *f;
|
|
|
|
struct os_time t;
|
|
|
|
f = fopen(hapd->conf->wps_pin_requests, "a");
|
|
|
|
if (f == NULL)
|
|
|
|
return;
|
|
|
|
os_get_time(&t);
|
|
|
|
fprintf(f, "%ld\t%s\t" MACSTR "\t%s\t%s\t%s\t%s\t%s"
|
2009-11-26 10:39:29 +01:00
|
|
|
"\t%s\n",
|
2008-11-23 18:34:26 +01:00
|
|
|
t.sec, uuid, MAC2STR(dev->mac_addr), dev->device_name,
|
|
|
|
dev->manufacturer, dev->model_name, dev->model_number,
|
|
|
|
dev->serial_number,
|
2009-11-26 10:39:29 +01:00
|
|
|
wps_dev_type_bin2str(dev->pri_dev_type, devtype,
|
|
|
|
sizeof(devtype)));
|
2008-11-23 18:34:26 +01:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-30 15:48:14 +01:00
|
|
|
struct wps_stop_reg_data {
|
|
|
|
struct hostapd_data *current_hapd;
|
|
|
|
const u8 *uuid_e;
|
2012-02-29 19:42:48 +01:00
|
|
|
const u8 *dev_pw;
|
|
|
|
size_t dev_pw_len;
|
2011-11-30 15:48:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static int wps_stop_registrar(struct hostapd_data *hapd, void *ctx)
|
|
|
|
{
|
|
|
|
struct wps_stop_reg_data *data = ctx;
|
|
|
|
if (hapd != data->current_hapd && hapd->wps != NULL)
|
2012-02-29 19:42:48 +01:00
|
|
|
wps_registrar_complete(hapd->wps->registrar, data->uuid_e,
|
|
|
|
data->dev_pw, data->dev_pw_len);
|
2011-11-30 15:48:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-21 12:48:10 +01:00
|
|
|
static void hostapd_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
|
2012-02-29 19:42:48 +01:00
|
|
|
const u8 *uuid_e, const u8 *dev_pw,
|
|
|
|
size_t dev_pw_len)
|
2009-01-21 12:48:10 +01:00
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
char uuid[40];
|
2011-11-30 15:48:14 +01:00
|
|
|
struct wps_stop_reg_data data;
|
2009-01-21 12:48:10 +01:00
|
|
|
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
|
|
|
|
return;
|
2009-09-29 20:25:14 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_REG_SUCCESS MACSTR " %s",
|
2009-01-21 12:48:10 +01:00
|
|
|
MAC2STR(mac_addr), uuid);
|
2010-04-11 19:21:08 +02:00
|
|
|
if (hapd->wps_reg_success_cb)
|
|
|
|
hapd->wps_reg_success_cb(hapd->wps_reg_success_cb_ctx,
|
|
|
|
mac_addr, uuid_e);
|
2011-11-30 15:48:14 +01:00
|
|
|
data.current_hapd = hapd;
|
|
|
|
data.uuid_e = uuid_e;
|
2012-02-29 19:42:48 +01:00
|
|
|
data.dev_pw = dev_pw;
|
|
|
|
data.dev_pw_len = dev_pw_len;
|
2011-11-30 15:48:14 +01:00
|
|
|
hostapd_wps_for_each(hapd, wps_stop_registrar, &data);
|
2009-01-21 12:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-28 15:24:04 +01:00
|
|
|
static void hostapd_wps_enrollee_seen_cb(void *ctx, const u8 *addr,
|
|
|
|
const u8 *uuid_e,
|
|
|
|
const u8 *pri_dev_type,
|
|
|
|
u16 config_methods,
|
|
|
|
u16 dev_password_id, u8 request_type,
|
|
|
|
const char *dev_name)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
char uuid[40];
|
|
|
|
char devtype[WPS_DEV_TYPE_BUFSIZE];
|
|
|
|
if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
|
|
|
|
return;
|
|
|
|
if (dev_name == NULL)
|
|
|
|
dev_name = "";
|
|
|
|
wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, WPS_EVENT_ENROLLEE_SEEN MACSTR
|
|
|
|
" %s %s 0x%x %u %u [%s]",
|
|
|
|
MAC2STR(addr), uuid,
|
|
|
|
wps_dev_type_bin2str(pri_dev_type, devtype,
|
|
|
|
sizeof(devtype)),
|
|
|
|
config_methods, dev_password_id, request_type, dev_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
static int str_starts(const char *str, const char *start)
|
|
|
|
{
|
|
|
|
return os_strncmp(str, start, os_strlen(start)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wps_reload_config(void *eloop_data, void *user_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_iface *iface = eloop_data;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Reload configuration data");
|
2012-08-25 11:43:27 +02:00
|
|
|
if (iface->interfaces == NULL ||
|
|
|
|
iface->interfaces->reload_config(iface) < 0) {
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_WARNING, "WPS: Failed to reload the updated "
|
|
|
|
"configuration");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-29 15:52:44 +01:00
|
|
|
void hostapd_wps_eap_completed(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Reduce race condition of the station trying to reconnect immediately
|
|
|
|
* after AP reconfiguration through WPS by rescheduling the reload
|
|
|
|
* timeout to happen after EAP completion rather than the originally
|
|
|
|
* scheduled 100 ms after new configuration became known.
|
|
|
|
*/
|
2014-01-05 08:59:38 +01:00
|
|
|
if (eloop_deplete_timeout(0, 0, wps_reload_config, hapd->iface, NULL) ==
|
|
|
|
1)
|
2013-11-29 15:52:44 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Reschedule immediate configuration reload");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-30 21:26:37 +02:00
|
|
|
static void hapd_new_ap_event(struct hostapd_data *hapd, const u8 *attr,
|
|
|
|
size_t attr_len)
|
|
|
|
{
|
|
|
|
size_t blen = attr_len * 2 + 1;
|
|
|
|
char *buf = os_malloc(blen);
|
|
|
|
if (buf) {
|
|
|
|
wpa_snprintf_hex(buf, blen, attr, attr_len);
|
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO,
|
|
|
|
WPS_EVENT_NEW_AP_SETTINGS "%s", buf);
|
|
|
|
os_free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-31 10:26:29 +02:00
|
|
|
static int hapd_wps_reconfig_in_memory(struct hostapd_data *hapd,
|
|
|
|
const struct wps_credential *cred)
|
|
|
|
{
|
|
|
|
struct hostapd_bss_config *bss = hapd->conf;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Updating in-memory configuration");
|
|
|
|
|
|
|
|
bss->wps_state = 2;
|
2015-04-07 11:41:20 +02:00
|
|
|
if (cred->ssid_len <= SSID_MAX_LEN) {
|
2013-03-31 10:26:29 +02:00
|
|
|
os_memcpy(bss->ssid.ssid, cred->ssid, cred->ssid_len);
|
|
|
|
bss->ssid.ssid_len = cred->ssid_len;
|
|
|
|
bss->ssid.ssid_set = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cred->auth_type & (WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK)) &&
|
|
|
|
(cred->auth_type & (WPS_AUTH_WPA | WPS_AUTH_WPAPSK)))
|
|
|
|
bss->wpa = 3;
|
|
|
|
else if (cred->auth_type & (WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK))
|
|
|
|
bss->wpa = 2;
|
|
|
|
else if (cred->auth_type & (WPS_AUTH_WPA | WPS_AUTH_WPAPSK))
|
|
|
|
bss->wpa = 1;
|
|
|
|
else
|
|
|
|
bss->wpa = 0;
|
|
|
|
|
|
|
|
if (bss->wpa) {
|
|
|
|
if (cred->auth_type & (WPS_AUTH_WPA2 | WPS_AUTH_WPA))
|
|
|
|
bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X;
|
|
|
|
if (cred->auth_type & (WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK))
|
|
|
|
bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
|
|
|
|
|
|
|
|
bss->wpa_pairwise = 0;
|
2015-04-27 19:42:08 +02:00
|
|
|
if (cred->encr_type & WPS_ENCR_AES) {
|
|
|
|
if (hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
|
|
|
|
bss->wpa_pairwise |= WPA_CIPHER_GCMP;
|
|
|
|
else
|
|
|
|
bss->wpa_pairwise |= WPA_CIPHER_CCMP;
|
|
|
|
}
|
2013-03-31 10:26:29 +02:00
|
|
|
if (cred->encr_type & WPS_ENCR_TKIP)
|
|
|
|
bss->wpa_pairwise |= WPA_CIPHER_TKIP;
|
|
|
|
bss->rsn_pairwise = bss->wpa_pairwise;
|
|
|
|
bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
|
|
|
|
bss->wpa_pairwise,
|
|
|
|
bss->rsn_pairwise);
|
|
|
|
|
|
|
|
if (cred->key_len >= 8 && cred->key_len < 64) {
|
|
|
|
os_free(bss->ssid.wpa_passphrase);
|
|
|
|
bss->ssid.wpa_passphrase = os_zalloc(cred->key_len + 1);
|
|
|
|
if (bss->ssid.wpa_passphrase)
|
|
|
|
os_memcpy(bss->ssid.wpa_passphrase, cred->key,
|
|
|
|
cred->key_len);
|
2015-01-19 23:57:41 +01:00
|
|
|
hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
|
2013-03-31 10:26:29 +02:00
|
|
|
} else if (cred->key_len == 64) {
|
2015-01-19 23:57:41 +01:00
|
|
|
hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk);
|
2013-03-31 10:26:29 +02:00
|
|
|
bss->ssid.wpa_psk =
|
|
|
|
os_zalloc(sizeof(struct hostapd_wpa_psk));
|
|
|
|
if (bss->ssid.wpa_psk &&
|
|
|
|
hexstr2bin((const char *) cred->key,
|
|
|
|
bss->ssid.wpa_psk->psk, PMK_LEN) == 0) {
|
|
|
|
bss->ssid.wpa_psk->group = 1;
|
|
|
|
os_free(bss->ssid.wpa_passphrase);
|
|
|
|
bss->ssid.wpa_passphrase = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bss->auth_algs = 1;
|
|
|
|
} else {
|
2014-03-22 18:22:10 +01:00
|
|
|
/*
|
|
|
|
* WPS 2.0 does not allow WEP to be configured, so no need to
|
|
|
|
* process that option here either.
|
|
|
|
*/
|
|
|
|
bss->auth_algs = 1;
|
2013-03-31 10:26:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Schedule configuration reload after short period of time to allow
|
|
|
|
* EAP-WSC to be finished.
|
|
|
|
*/
|
|
|
|
eloop_register_timeout(0, 100000, wps_reload_config, hapd->iface,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 16:32:10 +02:00
|
|
|
static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2010-10-08 16:32:10 +02:00
|
|
|
const struct wps_credential *cred = ctx;
|
2008-11-23 18:34:26 +01:00
|
|
|
FILE *oconf, *nconf;
|
|
|
|
size_t len, i;
|
|
|
|
char *tmp_fname;
|
|
|
|
char buf[1024];
|
|
|
|
int multi_bss;
|
|
|
|
int wpa;
|
|
|
|
|
2010-10-08 16:32:10 +02:00
|
|
|
if (hapd->wps == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2009-01-17 21:17:12 +01:00
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
|
|
|
|
cred->cred_attr, cred->cred_attr_len);
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received new AP Settings");
|
|
|
|
wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
|
|
|
|
cred->auth_type);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
|
|
|
|
wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
|
|
|
|
cred->key, cred->key_len);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
|
|
|
|
MAC2STR(cred->mac_addr));
|
|
|
|
|
2009-01-21 10:54:12 +01:00
|
|
|
if ((hapd->conf->wps_cred_processing == 1 ||
|
|
|
|
hapd->conf->wps_cred_processing == 2) && cred->cred_attr) {
|
2011-09-30 21:26:37 +02:00
|
|
|
hapd_new_ap_event(hapd, cred->cred_attr, cred->cred_attr_len);
|
|
|
|
} else if (hapd->conf->wps_cred_processing == 1 ||
|
|
|
|
hapd->conf->wps_cred_processing == 2) {
|
|
|
|
struct wpabuf *attr;
|
|
|
|
attr = wpabuf_alloc(200);
|
|
|
|
if (attr && wps_build_credential_wrap(attr, cred) == 0)
|
|
|
|
hapd_new_ap_event(hapd, wpabuf_head_u8(attr),
|
|
|
|
wpabuf_len(attr));
|
|
|
|
wpabuf_free(attr);
|
2009-01-21 10:54:12 +01:00
|
|
|
} else
|
2009-09-29 20:25:14 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_NEW_AP_SETTINGS);
|
2009-01-21 10:54:12 +01:00
|
|
|
|
|
|
|
if (hapd->conf->wps_cred_processing == 1)
|
|
|
|
return 0;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-03-30 17:48:41 +02:00
|
|
|
os_memcpy(hapd->wps->ssid, cred->ssid, cred->ssid_len);
|
|
|
|
hapd->wps->ssid_len = cred->ssid_len;
|
|
|
|
hapd->wps->encr_types = cred->encr_type;
|
|
|
|
hapd->wps->auth_types = cred->auth_type;
|
2014-01-16 16:35:45 +01:00
|
|
|
hapd->wps->ap_encr_type = cred->encr_type;
|
|
|
|
hapd->wps->ap_auth_type = cred->auth_type;
|
2009-11-10 16:01:26 +01:00
|
|
|
if (cred->key_len == 0) {
|
2009-03-30 17:48:41 +02:00
|
|
|
os_free(hapd->wps->network_key);
|
|
|
|
hapd->wps->network_key = NULL;
|
|
|
|
hapd->wps->network_key_len = 0;
|
|
|
|
} else {
|
|
|
|
if (hapd->wps->network_key == NULL ||
|
|
|
|
hapd->wps->network_key_len < cred->key_len) {
|
|
|
|
hapd->wps->network_key_len = 0;
|
|
|
|
os_free(hapd->wps->network_key);
|
|
|
|
hapd->wps->network_key = os_malloc(cred->key_len);
|
|
|
|
if (hapd->wps->network_key == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
hapd->wps->network_key_len = cred->key_len;
|
|
|
|
os_memcpy(hapd->wps->network_key, cred->key, cred->key_len);
|
|
|
|
}
|
|
|
|
hapd->wps->wps_state = WPS_STATE_CONFIGURED;
|
|
|
|
|
2012-06-18 17:11:54 +02:00
|
|
|
if (hapd->iface->config_fname == NULL)
|
2013-03-31 10:26:29 +02:00
|
|
|
return hapd_wps_reconfig_in_memory(hapd, cred);
|
2008-11-23 18:34:26 +01:00
|
|
|
len = os_strlen(hapd->iface->config_fname) + 5;
|
|
|
|
tmp_fname = os_malloc(len);
|
|
|
|
if (tmp_fname == NULL)
|
|
|
|
return -1;
|
|
|
|
os_snprintf(tmp_fname, len, "%s-new", hapd->iface->config_fname);
|
|
|
|
|
|
|
|
oconf = fopen(hapd->iface->config_fname, "r");
|
|
|
|
if (oconf == NULL) {
|
|
|
|
wpa_printf(MSG_WARNING, "WPS: Could not open current "
|
|
|
|
"configuration file");
|
|
|
|
os_free(tmp_fname);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nconf = fopen(tmp_fname, "w");
|
|
|
|
if (nconf == NULL) {
|
|
|
|
wpa_printf(MSG_WARNING, "WPS: Could not write updated "
|
|
|
|
"configuration file");
|
|
|
|
os_free(tmp_fname);
|
|
|
|
fclose(oconf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(nconf, "# WPS configuration - START\n");
|
|
|
|
|
|
|
|
fprintf(nconf, "wps_state=2\n");
|
|
|
|
|
2012-08-07 15:27:40 +02:00
|
|
|
if (is_hex(cred->ssid, cred->ssid_len)) {
|
|
|
|
fprintf(nconf, "ssid2=");
|
|
|
|
for (i = 0; i < cred->ssid_len; i++)
|
|
|
|
fprintf(nconf, "%02x", cred->ssid[i]);
|
|
|
|
fprintf(nconf, "\n");
|
|
|
|
} else {
|
|
|
|
fprintf(nconf, "ssid=");
|
|
|
|
for (i = 0; i < cred->ssid_len; i++)
|
|
|
|
fputc(cred->ssid[i], nconf);
|
|
|
|
fprintf(nconf, "\n");
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
if ((cred->auth_type & (WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK)) &&
|
|
|
|
(cred->auth_type & (WPS_AUTH_WPA | WPS_AUTH_WPAPSK)))
|
|
|
|
wpa = 3;
|
|
|
|
else if (cred->auth_type & (WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK))
|
|
|
|
wpa = 2;
|
|
|
|
else if (cred->auth_type & (WPS_AUTH_WPA | WPS_AUTH_WPAPSK))
|
|
|
|
wpa = 1;
|
|
|
|
else
|
|
|
|
wpa = 0;
|
|
|
|
|
|
|
|
if (wpa) {
|
|
|
|
char *prefix;
|
|
|
|
fprintf(nconf, "wpa=%d\n", wpa);
|
|
|
|
|
|
|
|
fprintf(nconf, "wpa_key_mgmt=");
|
|
|
|
prefix = "";
|
|
|
|
if (cred->auth_type & (WPS_AUTH_WPA2 | WPS_AUTH_WPA)) {
|
|
|
|
fprintf(nconf, "WPA-EAP");
|
|
|
|
prefix = " ";
|
|
|
|
}
|
|
|
|
if (cred->auth_type & (WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK))
|
|
|
|
fprintf(nconf, "%sWPA-PSK", prefix);
|
|
|
|
fprintf(nconf, "\n");
|
|
|
|
|
|
|
|
fprintf(nconf, "wpa_pairwise=");
|
|
|
|
prefix = "";
|
|
|
|
if (cred->encr_type & WPS_ENCR_AES) {
|
2015-04-27 19:42:08 +02:00
|
|
|
if (hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
|
|
|
|
fprintf(nconf, "GCMP");
|
|
|
|
else
|
|
|
|
fprintf(nconf, "CCMP");
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
prefix = " ";
|
|
|
|
}
|
|
|
|
if (cred->encr_type & WPS_ENCR_TKIP) {
|
|
|
|
fprintf(nconf, "%sTKIP", prefix);
|
|
|
|
}
|
|
|
|
fprintf(nconf, "\n");
|
|
|
|
|
|
|
|
if (cred->key_len >= 8 && cred->key_len < 64) {
|
|
|
|
fprintf(nconf, "wpa_passphrase=");
|
|
|
|
for (i = 0; i < cred->key_len; i++)
|
|
|
|
fputc(cred->key[i], nconf);
|
|
|
|
fprintf(nconf, "\n");
|
|
|
|
} else if (cred->key_len == 64) {
|
|
|
|
fprintf(nconf, "wpa_psk=");
|
|
|
|
for (i = 0; i < cred->key_len; i++)
|
|
|
|
fputc(cred->key[i], nconf);
|
|
|
|
fprintf(nconf, "\n");
|
|
|
|
} else {
|
|
|
|
wpa_printf(MSG_WARNING, "WPS: Invalid key length %lu "
|
|
|
|
"for WPA/WPA2",
|
|
|
|
(unsigned long) cred->key_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(nconf, "auth_algs=1\n");
|
|
|
|
} else {
|
2014-03-22 22:31:39 +01:00
|
|
|
/*
|
|
|
|
* WPS 2.0 does not allow WEP to be configured, so no need to
|
|
|
|
* process that option here either.
|
|
|
|
*/
|
|
|
|
fprintf(nconf, "auth_algs=1\n");
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(nconf, "# WPS configuration - END\n");
|
|
|
|
|
|
|
|
multi_bss = 0;
|
|
|
|
while (fgets(buf, sizeof(buf), oconf)) {
|
|
|
|
if (os_strncmp(buf, "bss=", 4) == 0)
|
|
|
|
multi_bss = 1;
|
|
|
|
if (!multi_bss &&
|
|
|
|
(str_starts(buf, "ssid=") ||
|
2012-08-07 15:27:40 +02:00
|
|
|
str_starts(buf, "ssid2=") ||
|
2008-11-23 18:34:26 +01:00
|
|
|
str_starts(buf, "auth_algs=") ||
|
2010-11-04 16:02:16 +01:00
|
|
|
str_starts(buf, "wep_default_key=") ||
|
|
|
|
str_starts(buf, "wep_key") ||
|
2008-11-23 18:34:26 +01:00
|
|
|
str_starts(buf, "wps_state=") ||
|
|
|
|
str_starts(buf, "wpa=") ||
|
|
|
|
str_starts(buf, "wpa_psk=") ||
|
|
|
|
str_starts(buf, "wpa_pairwise=") ||
|
|
|
|
str_starts(buf, "rsn_pairwise=") ||
|
|
|
|
str_starts(buf, "wpa_key_mgmt=") ||
|
|
|
|
str_starts(buf, "wpa_passphrase="))) {
|
|
|
|
fprintf(nconf, "#WPS# %s", buf);
|
|
|
|
} else
|
|
|
|
fprintf(nconf, "%s", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(nconf);
|
|
|
|
fclose(oconf);
|
|
|
|
|
|
|
|
if (rename(tmp_fname, hapd->iface->config_fname) < 0) {
|
|
|
|
wpa_printf(MSG_WARNING, "WPS: Failed to rename the updated "
|
|
|
|
"configuration file: %s", strerror(errno));
|
|
|
|
os_free(tmp_fname);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_free(tmp_fname);
|
|
|
|
|
|
|
|
/* Schedule configuration reload after short period of time to allow
|
|
|
|
* EAP-WSC to be finished.
|
|
|
|
*/
|
|
|
|
eloop_register_timeout(0, 100000, wps_reload_config, hapd->iface,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: AP configuration updated");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 16:32:10 +02:00
|
|
|
static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
return hostapd_wps_for_each(hapd, hapd_wps_cred_cb, (void *) cred);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-24 14:24:05 +02:00
|
|
|
static void hostapd_wps_reenable_ap_pin(void *eloop_data, void *user_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_data;
|
|
|
|
|
|
|
|
if (hapd->conf->ap_setup_locked)
|
|
|
|
return;
|
2012-01-30 16:31:06 +01:00
|
|
|
if (hapd->ap_pin_failures_consecutive >= 10)
|
|
|
|
return;
|
2010-08-24 14:24:05 +02:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Re-enable AP PIN");
|
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_UNLOCKED);
|
|
|
|
hapd->wps->ap_setup_locked = 0;
|
|
|
|
wps_registrar_update_ie(hapd->wps->registrar);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 16:24:58 +02:00
|
|
|
static int wps_pwd_auth_fail(struct hostapd_data *hapd, void *ctx)
|
2009-01-23 20:57:43 +01:00
|
|
|
{
|
2010-10-08 16:24:58 +02:00
|
|
|
struct wps_event_pwd_auth_fail *data = ctx;
|
|
|
|
|
|
|
|
if (!data->enrollee || hapd->conf->ap_pin == NULL || hapd->wps == NULL)
|
|
|
|
return 0;
|
2009-01-23 20:57:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Registrar failed to prove its knowledge of the AP PIN. Lock AP setup
|
2010-08-24 14:24:05 +02:00
|
|
|
* for some time if this happens multiple times to slow down brute
|
|
|
|
* force attacks.
|
2009-01-23 20:57:43 +01:00
|
|
|
*/
|
|
|
|
hapd->ap_pin_failures++;
|
2012-01-30 16:31:06 +01:00
|
|
|
hapd->ap_pin_failures_consecutive++;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u "
|
|
|
|
"(%u consecutive)",
|
|
|
|
hapd->ap_pin_failures, hapd->ap_pin_failures_consecutive);
|
2010-08-24 14:24:05 +02:00
|
|
|
if (hapd->ap_pin_failures < 3)
|
2010-10-08 16:24:58 +02:00
|
|
|
return 0;
|
2009-01-23 20:57:43 +01:00
|
|
|
|
2009-09-29 20:25:14 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_LOCKED);
|
2009-01-23 20:57:43 +01:00
|
|
|
hapd->wps->ap_setup_locked = 1;
|
|
|
|
|
|
|
|
wps_registrar_update_ie(hapd->wps->registrar);
|
|
|
|
|
2012-01-30 16:31:06 +01:00
|
|
|
if (!hapd->conf->ap_setup_locked &&
|
|
|
|
hapd->ap_pin_failures_consecutive >= 10) {
|
|
|
|
/*
|
|
|
|
* In indefinite lockdown - disable automatic AP PIN
|
|
|
|
* reenablement.
|
|
|
|
*/
|
|
|
|
eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: AP PIN disabled indefinitely");
|
|
|
|
} else if (!hapd->conf->ap_setup_locked) {
|
2010-08-24 14:24:05 +02:00
|
|
|
if (hapd->ap_pin_lockout_time == 0)
|
|
|
|
hapd->ap_pin_lockout_time = 60;
|
|
|
|
else if (hapd->ap_pin_lockout_time < 365 * 24 * 60 * 60 &&
|
|
|
|
(hapd->ap_pin_failures % 3) == 0)
|
|
|
|
hapd->ap_pin_lockout_time *= 2;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN for %u seconds",
|
|
|
|
hapd->ap_pin_lockout_time);
|
|
|
|
eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
|
|
|
|
eloop_register_timeout(hapd->ap_pin_lockout_time, 0,
|
|
|
|
hostapd_wps_reenable_ap_pin, hapd,
|
|
|
|
NULL);
|
2009-01-23 20:57:43 +01:00
|
|
|
}
|
|
|
|
|
2010-10-08 16:24:58 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_pwd_auth_fail(struct hostapd_data *hapd,
|
|
|
|
struct wps_event_pwd_auth_fail *data)
|
|
|
|
{
|
2013-08-23 15:38:16 +02:00
|
|
|
/* Update WPS Status - Authentication Failure */
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Authentication failure update");
|
|
|
|
hapd->wps_stats.status = WPS_STATUS_FAILURE;
|
|
|
|
hapd->wps_stats.failure_reason = WPS_EI_AUTH_FAILURE;
|
2013-08-23 15:01:55 +02:00
|
|
|
os_memcpy(hapd->wps_stats.peer_addr, data->peer_macaddr, ETH_ALEN);
|
2013-08-23 15:38:16 +02:00
|
|
|
|
2010-10-08 16:24:58 +02:00
|
|
|
hostapd_wps_for_each(hapd, wps_pwd_auth_fail, data);
|
2009-01-23 20:57:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-30 16:31:06 +01:00
|
|
|
static int wps_ap_pin_success(struct hostapd_data *hapd, void *ctx)
|
|
|
|
{
|
|
|
|
if (hapd->conf->ap_pin == NULL || hapd->wps == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (hapd->ap_pin_failures_consecutive == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Clear consecutive AP PIN failure counter "
|
|
|
|
"- total validation failures %u (%u consecutive)",
|
|
|
|
hapd->ap_pin_failures, hapd->ap_pin_failures_consecutive);
|
|
|
|
hapd->ap_pin_failures_consecutive = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_ap_pin_success(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
hostapd_wps_for_each(hapd, wps_ap_pin_success, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-23 15:51:27 +02:00
|
|
|
static void hostapd_wps_event_pbc_overlap(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
/* Update WPS Status - PBC Overlap */
|
|
|
|
hapd->wps_stats.pbc_status = WPS_PBC_STATUS_OVERLAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_event_pbc_timeout(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
/* Update WPS PBC Status:PBC Timeout */
|
|
|
|
hapd->wps_stats.pbc_status = WPS_PBC_STATUS_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_event_pbc_active(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
/* Update WPS PBC status - Active */
|
|
|
|
hapd->wps_stats.pbc_status = WPS_PBC_STATUS_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_event_pbc_disable(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
/* Update WPS PBC status - Active */
|
|
|
|
hapd->wps_stats.pbc_status = WPS_PBC_STATUS_DISABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-23 15:01:55 +02:00
|
|
|
static void hostapd_wps_event_success(struct hostapd_data *hapd,
|
|
|
|
struct wps_event_success *success)
|
2013-08-23 15:38:16 +02:00
|
|
|
{
|
|
|
|
/* Update WPS status - Success */
|
2013-08-23 15:51:27 +02:00
|
|
|
hapd->wps_stats.pbc_status = WPS_PBC_STATUS_DISABLE;
|
2013-08-23 15:38:16 +02:00
|
|
|
hapd->wps_stats.status = WPS_STATUS_SUCCESS;
|
2013-08-23 15:01:55 +02:00
|
|
|
os_memcpy(hapd->wps_stats.peer_addr, success->peer_macaddr, ETH_ALEN);
|
2013-08-23 15:38:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-14 19:50:46 +02:00
|
|
|
static void hostapd_wps_event_fail(struct hostapd_data *hapd,
|
|
|
|
struct wps_event_fail *fail)
|
|
|
|
{
|
2013-08-23 15:38:16 +02:00
|
|
|
/* Update WPS status - Failure */
|
|
|
|
hapd->wps_stats.status = WPS_STATUS_FAILURE;
|
2013-08-23 15:01:55 +02:00
|
|
|
os_memcpy(hapd->wps_stats.peer_addr, fail->peer_macaddr, ETH_ALEN);
|
|
|
|
|
2013-08-23 15:38:16 +02:00
|
|
|
hapd->wps_stats.failure_reason = fail->error_indication;
|
|
|
|
|
2011-01-13 16:50:59 +01:00
|
|
|
if (fail->error_indication > 0 &&
|
|
|
|
fail->error_indication < NUM_WPS_EI_VALUES) {
|
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO,
|
|
|
|
WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)",
|
|
|
|
fail->msg, fail->config_error, fail->error_indication,
|
2013-07-31 16:30:45 +02:00
|
|
|
wps_ei_str(fail->error_indication));
|
2011-01-13 16:50:59 +01:00
|
|
|
} else {
|
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO,
|
|
|
|
WPS_EVENT_FAIL "msg=%d config_error=%d",
|
|
|
|
fail->msg, fail->config_error);
|
|
|
|
}
|
2010-10-14 19:50:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-23 20:57:43 +01:00
|
|
|
static void hostapd_wps_event_cb(void *ctx, enum wps_event event,
|
|
|
|
union wps_event_data *data)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
|
2010-10-14 19:50:46 +02:00
|
|
|
switch (event) {
|
|
|
|
case WPS_EV_M2D:
|
2011-08-04 15:56:41 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_M2D);
|
2010-10-14 19:50:46 +02:00
|
|
|
break;
|
|
|
|
case WPS_EV_FAIL:
|
|
|
|
hostapd_wps_event_fail(hapd, &data->fail);
|
|
|
|
break;
|
|
|
|
case WPS_EV_SUCCESS:
|
2013-08-23 15:01:55 +02:00
|
|
|
hostapd_wps_event_success(hapd, &data->success);
|
2011-08-04 15:56:41 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_SUCCESS);
|
2010-10-14 19:50:46 +02:00
|
|
|
break;
|
|
|
|
case WPS_EV_PWD_AUTH_FAIL:
|
2009-01-23 20:57:43 +01:00
|
|
|
hostapd_pwd_auth_fail(hapd, &data->pwd_auth_fail);
|
2010-10-14 19:50:46 +02:00
|
|
|
break;
|
|
|
|
case WPS_EV_PBC_OVERLAP:
|
2013-08-23 15:51:27 +02:00
|
|
|
hostapd_wps_event_pbc_overlap(hapd);
|
2011-08-04 15:56:41 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_OVERLAP);
|
2010-10-14 19:50:46 +02:00
|
|
|
break;
|
|
|
|
case WPS_EV_PBC_TIMEOUT:
|
2013-08-23 15:51:27 +02:00
|
|
|
hostapd_wps_event_pbc_timeout(hapd);
|
2011-08-04 15:56:41 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_TIMEOUT);
|
2010-10-14 19:50:46 +02:00
|
|
|
break;
|
2013-08-23 15:01:30 +02:00
|
|
|
case WPS_EV_PBC_ACTIVE:
|
2013-08-23 15:51:27 +02:00
|
|
|
hostapd_wps_event_pbc_active(hapd);
|
2013-08-23 15:01:30 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_ACTIVE);
|
|
|
|
break;
|
|
|
|
case WPS_EV_PBC_DISABLE:
|
2013-08-23 15:51:27 +02:00
|
|
|
hostapd_wps_event_pbc_disable(hapd);
|
2013-08-23 15:01:30 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_DISABLE);
|
|
|
|
break;
|
2010-10-14 19:50:46 +02:00
|
|
|
case WPS_EV_ER_AP_ADD:
|
|
|
|
break;
|
|
|
|
case WPS_EV_ER_AP_REMOVE:
|
|
|
|
break;
|
|
|
|
case WPS_EV_ER_ENROLLEE_ADD:
|
|
|
|
break;
|
|
|
|
case WPS_EV_ER_ENROLLEE_REMOVE:
|
|
|
|
break;
|
|
|
|
case WPS_EV_ER_AP_SETTINGS:
|
|
|
|
break;
|
2010-10-25 20:29:22 +02:00
|
|
|
case WPS_EV_ER_SET_SELECTED_REGISTRAR:
|
|
|
|
break;
|
2012-01-30 16:31:06 +01:00
|
|
|
case WPS_EV_AP_PIN_SUCCESS:
|
|
|
|
hostapd_wps_ap_pin_success(hapd);
|
|
|
|
break;
|
2010-10-14 19:50:46 +02:00
|
|
|
}
|
2010-10-14 19:57:00 +02:00
|
|
|
if (hapd->wps_event_cb)
|
|
|
|
hapd->wps_event_cb(hapd->wps_event_cb_ctx, event, data);
|
2009-01-23 20:57:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-25 09:55:53 +02:00
|
|
|
static int hostapd_wps_rf_band_cb(void *ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
|
|
|
|
return hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211A ?
|
2015-04-27 19:42:08 +02:00
|
|
|
WPS_RF_50GHZ :
|
|
|
|
hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD ?
|
|
|
|
WPS_RF_60GHZ : WPS_RF_24GHZ; /* FIX: dualband AP */
|
2013-08-25 09:55:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-20 16:01:37 +01:00
|
|
|
static void hostapd_wps_clear_ies(struct hostapd_data *hapd, int deinit_only)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2009-12-24 18:46:06 +01:00
|
|
|
wpabuf_free(hapd->wps_beacon_ie);
|
2008-11-23 18:34:26 +01:00
|
|
|
hapd->wps_beacon_ie = NULL;
|
|
|
|
|
2009-12-24 18:46:06 +01:00
|
|
|
wpabuf_free(hapd->wps_probe_resp_ie);
|
2008-11-23 18:34:26 +01:00
|
|
|
hapd->wps_probe_resp_ie = NULL;
|
2009-12-24 15:15:22 +01:00
|
|
|
|
2015-03-24 14:05:43 +01:00
|
|
|
if (deinit_only) {
|
|
|
|
hostapd_reset_ap_wps_ie(hapd);
|
2014-03-20 16:01:37 +01:00
|
|
|
return;
|
2015-03-24 14:05:43 +01:00
|
|
|
}
|
2014-03-20 16:01:37 +01:00
|
|
|
|
2010-11-24 15:50:06 +01:00
|
|
|
hostapd_set_ap_wps_ie(hapd);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-20 23:28:43 +02:00
|
|
|
static int get_uuid_cb(struct hostapd_iface *iface, void *ctx)
|
|
|
|
{
|
|
|
|
const u8 **uuid = ctx;
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
if (iface == NULL)
|
|
|
|
return 0;
|
|
|
|
for (j = 0; j < iface->num_bss; j++) {
|
|
|
|
struct hostapd_data *hapd = iface->bss[j];
|
2013-03-31 10:48:52 +02:00
|
|
|
if (hapd->wps && !hapd->conf->wps_independent &&
|
|
|
|
!is_nil_uuid(hapd->wps->uuid)) {
|
2010-09-20 23:28:43 +02:00
|
|
|
*uuid = hapd->wps->uuid;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const u8 * get_own_uuid(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
const u8 *uuid;
|
2012-08-25 11:43:27 +02:00
|
|
|
if (iface->interfaces == NULL ||
|
|
|
|
iface->interfaces->for_each_interface == NULL)
|
2010-09-20 23:28:43 +02:00
|
|
|
return NULL;
|
|
|
|
uuid = NULL;
|
2012-08-25 11:43:27 +02:00
|
|
|
iface->interfaces->for_each_interface(iface->interfaces, get_uuid_cb,
|
|
|
|
&uuid);
|
2010-09-20 23:28:43 +02:00
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-21 00:32:29 +02:00
|
|
|
static int count_interface_cb(struct hostapd_iface *iface, void *ctx)
|
|
|
|
{
|
|
|
|
int *count= ctx;
|
|
|
|
(*count)++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int interface_count(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
int count = 0;
|
2012-08-25 11:43:27 +02:00
|
|
|
if (iface->interfaces == NULL ||
|
|
|
|
iface->interfaces->for_each_interface == NULL)
|
2010-10-06 15:46:43 +02:00
|
|
|
return 0;
|
2012-08-25 11:43:27 +02:00
|
|
|
iface->interfaces->for_each_interface(iface->interfaces,
|
|
|
|
count_interface_cb, &count);
|
2010-09-21 00:32:29 +02:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-19 10:44:42 +01:00
|
|
|
static int hostapd_wps_set_vendor_ext(struct hostapd_data *hapd,
|
|
|
|
struct wps_context *wps)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++) {
|
|
|
|
wpabuf_free(wps->dev.vendor_ext[i]);
|
|
|
|
wps->dev.vendor_ext[i] = NULL;
|
|
|
|
|
|
|
|
if (hapd->conf->wps_vendor_ext[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wps->dev.vendor_ext[i] =
|
|
|
|
wpabuf_dup(hapd->conf->wps_vendor_ext[i]);
|
|
|
|
if (wps->dev.vendor_ext[i] == NULL) {
|
|
|
|
while (--i >= 0)
|
|
|
|
wpabuf_free(wps->dev.vendor_ext[i]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-20 16:01:37 +01:00
|
|
|
static void hostapd_free_wps(struct wps_context *wps)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
|
|
|
|
wpabuf_free(wps->dev.vendor_ext[i]);
|
|
|
|
wps_device_data_free(&wps->dev);
|
|
|
|
os_free(wps->network_key);
|
|
|
|
hostapd_wps_nfc_clear(wps);
|
|
|
|
wpabuf_free(wps->dh_pubkey);
|
|
|
|
wpabuf_free(wps->dh_privkey);
|
|
|
|
os_free(wps);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
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) {
|
2014-03-20 16:01:37 +01:00
|
|
|
hostapd_wps_clear_ies(hapd, 0);
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wps = os_zalloc(sizeof(*wps));
|
|
|
|
if (wps == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
wps->cred_cb = hostapd_wps_cred_cb;
|
2009-01-23 20:57:43 +01:00
|
|
|
wps->event_cb = hostapd_wps_event_cb;
|
2013-08-25 09:55:53 +02:00
|
|
|
wps->rf_band_cb = hostapd_wps_rf_band_cb;
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->cb_ctx = hapd;
|
|
|
|
|
|
|
|
os_memset(&cfg, 0, sizeof(cfg));
|
|
|
|
wps->wps_state = hapd->conf->wps_state;
|
|
|
|
wps->ap_setup_locked = hapd->conf->ap_setup_locked;
|
2009-01-01 21:56:52 +01:00
|
|
|
if (is_nil_uuid(hapd->conf->uuid)) {
|
2010-09-20 23:28:43 +02:00
|
|
|
const u8 *uuid;
|
|
|
|
uuid = get_own_uuid(hapd->iface);
|
2013-03-31 10:48:52 +02:00
|
|
|
if (uuid && !conf->wps_independent) {
|
2010-09-20 23:28:43 +02:00
|
|
|
os_memcpy(wps->uuid, uuid, UUID_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Clone UUID from another "
|
|
|
|
"interface", wps->uuid, UUID_LEN);
|
|
|
|
} else {
|
|
|
|
uuid_gen_mac_addr(hapd->own_addr, wps->uuid);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC "
|
|
|
|
"address", wps->uuid, UUID_LEN);
|
|
|
|
}
|
|
|
|
} else {
|
2009-01-01 21:56:52 +01:00
|
|
|
os_memcpy(wps->uuid, hapd->conf->uuid, UUID_LEN);
|
2010-09-20 23:28:43 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Use configured UUID",
|
|
|
|
wps->uuid, UUID_LEN);
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
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);
|
2009-01-22 20:26:14 +01:00
|
|
|
wps->dev.device_name = hapd->conf->device_name ?
|
|
|
|
os_strdup(hapd->conf->device_name) : NULL;
|
|
|
|
wps->dev.manufacturer = hapd->conf->manufacturer ?
|
|
|
|
os_strdup(hapd->conf->manufacturer) : NULL;
|
|
|
|
wps->dev.model_name = hapd->conf->model_name ?
|
|
|
|
os_strdup(hapd->conf->model_name) : NULL;
|
|
|
|
wps->dev.model_number = hapd->conf->model_number ?
|
|
|
|
os_strdup(hapd->conf->model_number) : NULL;
|
|
|
|
wps->dev.serial_number = hapd->conf->serial_number ?
|
|
|
|
os_strdup(hapd->conf->serial_number) : NULL;
|
2009-12-21 14:59:25 +01:00
|
|
|
wps->config_methods =
|
|
|
|
wps_config_methods_str2bin(hapd->conf->config_methods);
|
2010-09-23 02:45:43 +02:00
|
|
|
if ((wps->config_methods &
|
|
|
|
(WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY |
|
|
|
|
WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) {
|
|
|
|
wpa_printf(MSG_INFO, "WPS: Converting display to "
|
|
|
|
"virtual_display for WPS 2.0 compliance");
|
|
|
|
wps->config_methods |= WPS_CONFIG_VIRT_DISPLAY;
|
|
|
|
}
|
|
|
|
if ((wps->config_methods &
|
|
|
|
(WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
|
|
|
|
WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) {
|
|
|
|
wpa_printf(MSG_INFO, "WPS: Converting push_button to "
|
|
|
|
"virtual_push_button for WPS 2.0 compliance");
|
|
|
|
wps->config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
|
|
|
|
}
|
2011-03-17 17:50:22 +01:00
|
|
|
os_memcpy(wps->dev.pri_dev_type, hapd->conf->device_type,
|
|
|
|
WPS_DEV_TYPE_LEN);
|
|
|
|
|
2014-03-20 16:01:37 +01:00
|
|
|
if (hostapd_wps_set_vendor_ext(hapd, wps) < 0)
|
|
|
|
goto fail;
|
2011-03-19 10:44:42 +01:00
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->dev.os_version = WPA_GET_BE32(hapd->conf->os_version);
|
2011-11-30 16:44:43 +01:00
|
|
|
|
|
|
|
if (conf->wps_rf_bands) {
|
|
|
|
wps->dev.rf_bands = conf->wps_rf_bands;
|
|
|
|
} else {
|
|
|
|
wps->dev.rf_bands =
|
|
|
|
hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211A ?
|
2015-04-27 19:42:08 +02:00
|
|
|
WPS_RF_50GHZ :
|
|
|
|
hapd->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD ?
|
|
|
|
WPS_RF_60GHZ : WPS_RF_24GHZ; /* FIX: dualband AP */
|
2011-11-30 16:44:43 +01:00
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
if (conf->wpa & WPA_PROTO_RSN) {
|
|
|
|
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
|
|
|
|
wps->auth_types |= WPS_AUTH_WPA2PSK;
|
|
|
|
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
|
|
|
|
wps->auth_types |= WPS_AUTH_WPA2;
|
|
|
|
|
2014-10-26 13:04:29 +01:00
|
|
|
if (conf->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP))
|
2008-11-23 18:34:26 +01:00
|
|
|
wps->encr_types |= WPS_ENCR_AES;
|
|
|
|
if (conf->rsn_pairwise & WPA_CIPHER_TKIP)
|
|
|
|
wps->encr_types |= WPS_ENCR_TKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->wpa & WPA_PROTO_WPA) {
|
|
|
|
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
|
|
|
|
wps->auth_types |= WPS_AUTH_WPAPSK;
|
|
|
|
if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
|
|
|
|
wps->auth_types |= WPS_AUTH_WPA;
|
|
|
|
|
|
|
|
if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
|
|
|
|
wps->encr_types |= WPS_ENCR_AES;
|
|
|
|
if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
|
|
|
|
wps->encr_types |= WPS_ENCR_TKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->ssid.security_policy == SECURITY_PLAINTEXT) {
|
|
|
|
wps->encr_types |= WPS_ENCR_NONE;
|
|
|
|
wps->auth_types |= WPS_AUTH_OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
wps->network_key = os_malloc(2 * PMK_LEN + 1);
|
2014-03-20 16:01:37 +01:00
|
|
|
if (wps->network_key == NULL)
|
|
|
|
goto fail;
|
2008-11-23 18:34:26 +01:00
|
|
|
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]) {
|
|
|
|
wps->network_key = os_malloc(conf->ssid.wep.len[0]);
|
2014-03-20 16:01:37 +01:00
|
|
|
if (wps->network_key == NULL)
|
|
|
|
goto fail;
|
2008-11-23 18:34:26 +01:00
|
|
|
os_memcpy(wps->network_key, conf->ssid.wep.key[0],
|
|
|
|
conf->ssid.wep.len[0]);
|
|
|
|
wps->network_key_len = conf->ssid.wep.len[0];
|
|
|
|
}
|
|
|
|
|
2009-12-21 11:46:19 +01:00
|
|
|
if (conf->ssid.wpa_psk) {
|
|
|
|
os_memcpy(wps->psk, conf->ssid.wpa_psk->psk, PMK_LEN);
|
|
|
|
wps->psk_set = 1;
|
|
|
|
}
|
|
|
|
|
2014-01-16 16:35:45 +01:00
|
|
|
wps->ap_auth_type = wps->auth_types;
|
|
|
|
wps->ap_encr_type = wps->encr_types;
|
2008-11-23 18:34:26 +01:00
|
|
|
if (conf->wps_state == WPS_STATE_NOT_CONFIGURED) {
|
|
|
|
/* Override parameters to enable security by default */
|
|
|
|
wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
|
|
|
|
wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
|
|
|
|
}
|
|
|
|
|
2009-01-23 20:08:55 +01:00
|
|
|
wps->ap_settings = conf->ap_settings;
|
|
|
|
wps->ap_settings_len = conf->ap_settings_len;
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
cfg.new_psk_cb = hostapd_wps_new_psk_cb;
|
|
|
|
cfg.set_ie_cb = hostapd_wps_set_ie_cb;
|
|
|
|
cfg.pin_needed_cb = hostapd_wps_pin_needed_cb;
|
2009-01-21 12:48:10 +01:00
|
|
|
cfg.reg_success_cb = hostapd_wps_reg_success_cb;
|
2009-12-28 15:24:04 +01:00
|
|
|
cfg.enrollee_seen_cb = hostapd_wps_enrollee_seen_cb;
|
2008-11-23 18:34:26 +01:00
|
|
|
cfg.cb_ctx = hapd;
|
2009-01-16 21:50:41 +01:00
|
|
|
cfg.skip_cred_build = conf->skip_cred_build;
|
|
|
|
cfg.extra_cred = conf->extra_cred;
|
|
|
|
cfg.extra_cred_len = conf->extra_cred_len;
|
2009-01-21 12:48:10 +01:00
|
|
|
cfg.disable_auto_conf = (hapd->conf->wps_cred_processing == 1) &&
|
|
|
|
conf->skip_cred_build;
|
2009-03-08 18:36:02 +01:00
|
|
|
if (conf->ssid.security_policy == SECURITY_STATIC_WEP)
|
|
|
|
cfg.static_wep_only = 1;
|
2010-09-21 00:32:29 +02:00
|
|
|
cfg.dualband = interface_count(hapd->iface) > 1;
|
2012-12-17 15:06:10 +01:00
|
|
|
if ((wps->dev.rf_bands & (WPS_RF_50GHZ | WPS_RF_24GHZ)) ==
|
|
|
|
(WPS_RF_50GHZ | WPS_RF_24GHZ))
|
|
|
|
cfg.dualband = 1;
|
2010-09-21 00:32:29 +02:00
|
|
|
if (cfg.dualband)
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Dualband AP");
|
2013-09-01 09:08:30 +02:00
|
|
|
cfg.force_per_enrollee_psk = conf->force_per_enrollee_psk;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wps->registrar = wps_registrar_init(wps, &cfg);
|
|
|
|
if (wps->registrar == NULL) {
|
2010-09-21 00:32:29 +02:00
|
|
|
wpa_printf(MSG_ERROR, "Failed to initialize WPS Registrar");
|
2014-03-20 16:01:37 +01:00
|
|
|
goto fail;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
wps->friendly_name = hapd->conf->friendly_name;
|
|
|
|
wps->manufacturer_url = hapd->conf->manufacturer_url;
|
|
|
|
wps->model_description = hapd->conf->model_description;
|
|
|
|
wps->model_url = hapd->conf->model_url;
|
|
|
|
wps->upc = hapd->conf->upc;
|
2011-05-19 11:55:47 +02:00
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
|
|
|
hostapd_register_probereq_cb(hapd, hostapd_wps_probe_req_rx, hapd);
|
|
|
|
|
|
|
|
hapd->wps = wps;
|
2009-01-29 17:47:02 +01:00
|
|
|
|
2011-05-19 11:55:47 +02:00
|
|
|
return 0;
|
2014-03-20 16:01:37 +01:00
|
|
|
|
|
|
|
fail:
|
|
|
|
hostapd_free_wps(wps);
|
|
|
|
return -1;
|
2011-05-19 11:55:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_init_wps_complete(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
struct wps_context *wps = hapd->wps;
|
|
|
|
|
2011-05-31 19:11:25 +02:00
|
|
|
if (wps == NULL)
|
2011-05-19 11:55:47 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
#ifdef CONFIG_WPS_UPNP
|
2009-01-29 17:47:02 +01:00
|
|
|
if (hostapd_wps_upnp_init(hapd, wps) < 0) {
|
|
|
|
wpa_printf(MSG_ERROR, "Failed to initialize WPS UPnP");
|
|
|
|
wps_registrar_deinit(wps->registrar);
|
2014-03-20 16:01:37 +01:00
|
|
|
hostapd_free_wps(wps);
|
2011-05-19 11:55:47 +02:00
|
|
|
hapd->wps = NULL;
|
2009-01-29 17:47:02 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-28 18:43:29 +02:00
|
|
|
static void hostapd_wps_nfc_clear(struct wps_context *wps)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_WPS_NFC
|
2013-09-08 17:09:38 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Clear NFC Tag context %p", wps);
|
2012-06-28 18:43:29 +02:00
|
|
|
wps->ap_nfc_dev_pw_id = 0;
|
|
|
|
wpabuf_free(wps->ap_nfc_dh_pubkey);
|
|
|
|
wps->ap_nfc_dh_pubkey = NULL;
|
|
|
|
wpabuf_free(wps->ap_nfc_dh_privkey);
|
|
|
|
wps->ap_nfc_dh_privkey = NULL;
|
|
|
|
wpabuf_free(wps->ap_nfc_dev_pw);
|
|
|
|
wps->ap_nfc_dev_pw = NULL;
|
|
|
|
#endif /* CONFIG_WPS_NFC */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
void hostapd_deinit_wps(struct hostapd_data *hapd)
|
|
|
|
{
|
2010-08-24 14:24:05 +02:00
|
|
|
eloop_cancel_timeout(hostapd_wps_reenable_ap_pin, hapd, NULL);
|
2010-08-24 15:35:37 +02:00
|
|
|
eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
|
2013-12-28 18:18:47 +01:00
|
|
|
eloop_cancel_timeout(wps_reload_config, hapd->iface, NULL);
|
2014-03-20 16:01:37 +01:00
|
|
|
if (hapd->wps == NULL) {
|
|
|
|
hostapd_wps_clear_ies(hapd, 1);
|
2008-11-23 18:34:26 +01:00
|
|
|
return;
|
2014-03-20 16:01:37 +01:00
|
|
|
}
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
hostapd_wps_upnp_deinit(hapd);
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
2008-11-23 18:34:26 +01:00
|
|
|
wps_registrar_deinit(hapd->wps->registrar);
|
2009-02-06 20:39:32 +01:00
|
|
|
wps_free_pending_msgs(hapd->wps->upnp_msgs);
|
2014-03-20 16:01:37 +01:00
|
|
|
hostapd_free_wps(hapd->wps);
|
2008-11-23 18:34:26 +01:00
|
|
|
hapd->wps = NULL;
|
2014-03-20 16:01:37 +01:00
|
|
|
hostapd_wps_clear_ies(hapd, 1);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-02 10:21:19 +02:00
|
|
|
void hostapd_update_wps(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
if (hapd->wps == NULL)
|
|
|
|
return;
|
2010-09-23 04:34:32 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
hapd->wps->friendly_name = hapd->conf->friendly_name;
|
|
|
|
hapd->wps->manufacturer_url = hapd->conf->manufacturer_url;
|
|
|
|
hapd->wps->model_description = hapd->conf->model_description;
|
|
|
|
hapd->wps->model_url = hapd->conf->model_url;
|
|
|
|
hapd->wps->upc = hapd->conf->upc;
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
|
2011-03-19 10:44:42 +01:00
|
|
|
hostapd_wps_set_vendor_ext(hapd, hapd->wps);
|
|
|
|
|
2010-05-02 10:21:19 +02:00
|
|
|
if (hapd->conf->wps_state)
|
|
|
|
wps_registrar_update_ie(hapd->wps->registrar);
|
|
|
|
else
|
|
|
|
hostapd_deinit_wps(hapd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 16:15:16 +02:00
|
|
|
struct wps_add_pin_data {
|
|
|
|
const u8 *addr;
|
|
|
|
const u8 *uuid;
|
|
|
|
const u8 *pin;
|
|
|
|
size_t pin_len;
|
|
|
|
int timeout;
|
|
|
|
int added;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_add_pin(struct hostapd_data *hapd, void *ctx)
|
|
|
|
{
|
|
|
|
struct wps_add_pin_data *data = ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (hapd->wps == NULL)
|
|
|
|
return 0;
|
|
|
|
ret = wps_registrar_add_pin(hapd->wps->registrar, data->addr,
|
|
|
|
data->uuid, data->pin, data->pin_len,
|
|
|
|
data->timeout);
|
|
|
|
if (ret == 0)
|
|
|
|
data->added++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-12 15:40:10 +01:00
|
|
|
int hostapd_wps_add_pin(struct hostapd_data *hapd, const u8 *addr,
|
|
|
|
const char *uuid, const char *pin, int timeout)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
|
|
|
u8 u[UUID_LEN];
|
2010-10-08 16:15:16 +02:00
|
|
|
struct wps_add_pin_data data;
|
|
|
|
|
|
|
|
data.addr = addr;
|
|
|
|
data.uuid = u;
|
|
|
|
data.pin = (const u8 *) pin;
|
|
|
|
data.pin_len = os_strlen(pin);
|
|
|
|
data.timeout = timeout;
|
|
|
|
data.added = 0;
|
2008-11-30 19:32:03 +01:00
|
|
|
|
|
|
|
if (os_strcmp(uuid, "any") == 0)
|
2010-10-08 16:15:16 +02:00
|
|
|
data.uuid = NULL;
|
|
|
|
else {
|
|
|
|
if (uuid_str2bin(uuid, u))
|
|
|
|
return -1;
|
|
|
|
data.uuid = u;
|
|
|
|
}
|
|
|
|
if (hostapd_wps_for_each(hapd, wps_add_pin, &data) < 0)
|
2008-11-23 18:34:26 +01:00
|
|
|
return -1;
|
2010-10-08 16:15:16 +02:00
|
|
|
return data.added ? 0 : -1;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 16:15:16 +02:00
|
|
|
static int wps_button_pushed(struct hostapd_data *hapd, void *ctx)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2011-02-07 17:28:36 +01:00
|
|
|
const u8 *p2p_dev_addr = ctx;
|
2008-11-23 18:34:26 +01:00
|
|
|
if (hapd->wps == NULL)
|
2014-05-14 15:51:04 +02:00
|
|
|
return -1;
|
2011-02-07 17:28:36 +01:00
|
|
|
return wps_registrar_button_pushed(hapd->wps->registrar, p2p_dev_addr);
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-07 17:28:36 +01:00
|
|
|
int hostapd_wps_button_pushed(struct hostapd_data *hapd,
|
|
|
|
const u8 *p2p_dev_addr)
|
2010-10-08 16:15:16 +02:00
|
|
|
{
|
2011-02-07 17:28:36 +01:00
|
|
|
return hostapd_wps_for_each(hapd, wps_button_pushed,
|
|
|
|
(void *) p2p_dev_addr);
|
2010-10-08 16:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-19 07:23:31 +01:00
|
|
|
static int wps_cancel(struct hostapd_data *hapd, void *ctx)
|
|
|
|
{
|
|
|
|
if (hapd->wps == NULL)
|
2014-05-14 15:51:04 +02:00
|
|
|
return -1;
|
2012-03-19 07:23:31 +01:00
|
|
|
|
|
|
|
wps_registrar_wps_cancel(hapd->wps->registrar);
|
|
|
|
ap_for_each_sta(hapd, ap_sta_wps_cancel, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_wps_cancel(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
return hostapd_wps_for_each(hapd, wps_cancel, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-15 19:25:53 +02:00
|
|
|
static int hostapd_wps_probe_req_rx(void *ctx, const u8 *addr, const u8 *da,
|
|
|
|
const u8 *bssid,
|
2012-04-01 17:48:12 +02:00
|
|
|
const u8 *ie, size_t ie_len,
|
|
|
|
int ssi_signal)
|
2008-11-23 18:34:26 +01:00
|
|
|
{
|
2009-06-12 17:13:40 +02:00
|
|
|
struct hostapd_data *hapd = ctx;
|
2008-11-23 18:34:26 +01:00
|
|
|
struct wpabuf *wps_ie;
|
2010-06-11 07:36:34 +02:00
|
|
|
struct ieee802_11_elems elems;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
if (hapd->wps == NULL)
|
2009-12-28 12:14:58 +01:00
|
|
|
return 0;
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2010-06-11 07:36:34 +02:00
|
|
|
if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Could not parse ProbeReq from "
|
|
|
|
MACSTR, MAC2STR(addr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elems.ssid && elems.ssid_len > 0 &&
|
|
|
|
(elems.ssid_len != hapd->conf->ssid.ssid_len ||
|
|
|
|
os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) !=
|
|
|
|
0))
|
|
|
|
return 0; /* Not for us */
|
|
|
|
|
2009-09-11 15:36:59 +02:00
|
|
|
wps_ie = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
|
2008-11-23 18:34:26 +01:00
|
|
|
if (wps_ie == NULL)
|
2009-12-28 12:14:58 +01:00
|
|
|
return 0;
|
2010-09-22 19:07:20 +02:00
|
|
|
if (wps_validate_probe_req(wps_ie, addr) < 0) {
|
2010-05-26 16:16:14 +02:00
|
|
|
wpabuf_free(wps_ie);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
2009-01-29 17:47:02 +01:00
|
|
|
if (wpabuf_len(wps_ie) > 0) {
|
2010-07-18 23:30:24 +02:00
|
|
|
int p2p_wildcard = 0;
|
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (elems.ssid && elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
|
|
|
|
os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
|
|
|
|
P2P_WILDCARD_SSID_LEN) == 0)
|
|
|
|
p2p_wildcard = 1;
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
wps_registrar_probe_req_rx(hapd->wps->registrar, addr, wps_ie,
|
|
|
|
p2p_wildcard);
|
2009-01-29 17:47:02 +01:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
/* FIX: what exactly should be included in the WLANEvent?
|
|
|
|
* WPS attributes? Full ProbeReq frame? */
|
2010-07-18 23:30:24 +02:00
|
|
|
if (!p2p_wildcard)
|
|
|
|
upnp_wps_device_send_wlan_event(
|
|
|
|
hapd->wps_upnp, addr,
|
|
|
|
UPNP_WPS_WLANEVENT_TYPE_PROBE, wps_ie);
|
2009-01-29 17:47:02 +01:00
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
|
|
|
}
|
2008-11-23 18:34:26 +01:00
|
|
|
|
|
|
|
wpabuf_free(wps_ie);
|
2009-12-28 12:14:58 +01:00
|
|
|
|
|
|
|
return 0;
|
2008-11-23 18:34:26 +01:00
|
|
|
}
|
2009-01-29 17:47:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_WPS_UPNP
|
|
|
|
|
2009-02-06 20:44:19 +01:00
|
|
|
static int hostapd_rx_req_put_wlan_response(
|
2009-01-29 17:47:02 +01:00
|
|
|
void *priv, enum upnp_wps_wlanevent_type ev_type,
|
2009-02-06 20:39:32 +01:00
|
|
|
const u8 *mac_addr, const struct wpabuf *msg,
|
|
|
|
enum wps_msg_type msg_type)
|
2009-01-29 17:47:02 +01:00
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = priv;
|
|
|
|
struct sta_info *sta;
|
2009-02-06 20:39:32 +01:00
|
|
|
struct upnp_pending_message *p;
|
2009-01-29 17:47:02 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS UPnP: PutWLANResponse ev_type=%d mac_addr="
|
|
|
|
MACSTR, ev_type, MAC2STR(mac_addr));
|
2009-11-15 17:28:59 +01:00
|
|
|
wpa_hexdump(MSG_MSGDUMP, "WPS UPnP: PutWLANResponse NewMessage",
|
|
|
|
wpabuf_head(msg), wpabuf_len(msg));
|
2009-01-29 17:47:02 +01:00
|
|
|
if (ev_type != UPNP_WPS_WLANEVENT_TYPE_EAP) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS UPnP: Ignored unexpected "
|
|
|
|
"PutWLANResponse WLANEventType %d", ev_type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EAP response to ongoing to WPS Registration. Send it to EAP-WSC
|
|
|
|
* server implementation for delivery to the peer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, mac_addr);
|
2010-05-26 10:16:54 +02:00
|
|
|
#ifndef CONFIG_WPS_STRICT
|
2009-02-06 15:39:49 +01:00
|
|
|
if (!sta) {
|
|
|
|
/*
|
|
|
|
* Workaround - Intel wsccmd uses bogus NewWLANEventMAC:
|
|
|
|
* Pick STA that is in an ongoing WPS registration without
|
|
|
|
* checking the MAC address.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS UPnP: No matching STA found based "
|
|
|
|
"on NewWLANEventMAC; try wildcard match");
|
|
|
|
for (sta = hapd->sta_list; sta; sta = sta->next) {
|
2009-02-06 20:39:32 +01:00
|
|
|
if (sta->eapol_sm && (sta->flags & WLAN_STA_WPS))
|
2009-02-06 15:39:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-26 10:16:54 +02:00
|
|
|
#endif /* CONFIG_WPS_STRICT */
|
2009-01-29 17:47:02 +01:00
|
|
|
|
2011-08-12 10:58:32 +02:00
|
|
|
if (!sta || !(sta->flags & WLAN_STA_WPS)) {
|
2009-02-06 20:39:32 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS UPnP: No matching STA found");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-02-06 15:39:49 +01:00
|
|
|
|
2014-02-19 22:51:55 +01:00
|
|
|
if (!sta->eapol_sm) {
|
|
|
|
/*
|
|
|
|
* This can happen, e.g., if an ER sends an extra message after
|
|
|
|
* the station has disassociated (but not fully
|
|
|
|
* deauthenticated).
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS UPnP: Matching STA did not have EAPOL state machine initialized");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-06 20:39:32 +01:00
|
|
|
p = os_zalloc(sizeof(*p));
|
|
|
|
if (p == NULL)
|
|
|
|
return -1;
|
|
|
|
os_memcpy(p->addr, sta->addr, ETH_ALEN);
|
|
|
|
p->msg = wpabuf_dup(msg);
|
|
|
|
p->type = msg_type;
|
|
|
|
p->next = hapd->wps->upnp_msgs;
|
|
|
|
hapd->wps->upnp_msgs = p;
|
|
|
|
|
|
|
|
return eapol_auth_eap_pending_cb(sta->eapol_sm, sta->eapol_sm->eap);
|
2009-01-29 17:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
|
|
|
|
struct wps_context *wps)
|
|
|
|
{
|
|
|
|
struct upnp_wps_device_ctx *ctx;
|
|
|
|
|
|
|
|
if (!hapd->conf->upnp_iface)
|
|
|
|
return 0;
|
|
|
|
ctx = os_zalloc(sizeof(*ctx));
|
|
|
|
if (ctx == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2009-02-06 20:44:19 +01:00
|
|
|
ctx->rx_req_put_wlan_response = hostapd_rx_req_put_wlan_response;
|
2009-12-12 15:47:39 +01:00
|
|
|
if (hapd->conf->ap_pin)
|
|
|
|
ctx->ap_pin = os_strdup(hapd->conf->ap_pin);
|
2009-01-29 17:47:02 +01:00
|
|
|
|
2010-11-11 13:50:13 +01:00
|
|
|
hapd->wps_upnp = upnp_wps_device_init(ctx, wps, hapd,
|
|
|
|
hapd->conf->upnp_iface);
|
|
|
|
if (hapd->wps_upnp == NULL)
|
2009-01-29 17:47:02 +01:00
|
|
|
return -1;
|
|
|
|
wps->wps_upnp = hapd->wps_upnp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd)
|
|
|
|
{
|
2010-11-11 13:50:13 +01:00
|
|
|
upnp_wps_device_deinit(hapd->wps_upnp, hapd);
|
2009-01-29 17:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
2009-09-07 21:09:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
int hostapd_wps_get_mib_sta(struct hostapd_data *hapd, const u8 *addr,
|
|
|
|
char *buf, size_t buflen)
|
|
|
|
{
|
2010-03-29 18:59:16 +02:00
|
|
|
if (hapd->wps == NULL)
|
|
|
|
return 0;
|
2009-09-07 21:09:13 +02:00
|
|
|
return wps_registrar_get_info(hapd->wps->registrar, addr, buf, buflen);
|
|
|
|
}
|
2010-08-24 15:35:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_data;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
|
|
|
|
hostapd_wps_ap_pin_disable(hapd);
|
2011-08-04 15:56:41 +02:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_PIN_DISABLED);
|
2010-08-24 15:35:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_wps_ap_pin_enable(struct hostapd_data *hapd, int timeout)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
|
|
|
|
hapd->ap_pin_failures = 0;
|
2012-01-30 16:31:06 +01:00
|
|
|
hapd->ap_pin_failures_consecutive = 0;
|
2010-08-24 15:35:37 +02:00
|
|
|
hapd->conf->ap_setup_locked = 0;
|
|
|
|
if (hapd->wps->ap_setup_locked) {
|
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, WPS_EVENT_AP_SETUP_UNLOCKED);
|
|
|
|
hapd->wps->ap_setup_locked = 0;
|
|
|
|
wps_registrar_update_ie(hapd->wps->registrar);
|
|
|
|
}
|
|
|
|
eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
|
|
|
|
if (timeout > 0)
|
|
|
|
eloop_register_timeout(timeout, 0,
|
|
|
|
hostapd_wps_ap_pin_timeout, hapd, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 16:15:16 +02:00
|
|
|
static int wps_ap_pin_disable(struct hostapd_data *hapd, void *ctx)
|
2010-08-24 15:35:37 +02:00
|
|
|
{
|
|
|
|
os_free(hapd->conf->ap_pin);
|
|
|
|
hapd->conf->ap_pin = NULL;
|
2010-09-05 11:34:04 +02:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
2010-08-24 15:35:37 +02:00
|
|
|
upnp_wps_set_ap_pin(hapd->wps_upnp, NULL);
|
2010-09-05 11:34:04 +02:00
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
2010-08-24 15:35:37 +02:00
|
|
|
eloop_cancel_timeout(hostapd_wps_ap_pin_timeout, hapd, NULL);
|
2010-10-08 16:15:16 +02:00
|
|
|
return 0;
|
2010-08-24 15:35:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-08 16:15:16 +02:00
|
|
|
void hostapd_wps_ap_pin_disable(struct hostapd_data *hapd)
|
2010-08-24 15:35:37 +02:00
|
|
|
{
|
2010-10-08 16:15:16 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
|
|
|
|
hostapd_wps_for_each(hapd, wps_ap_pin_disable, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wps_ap_pin_data {
|
2010-08-24 15:35:37 +02:00
|
|
|
char pin_txt[9];
|
2010-10-08 16:15:16 +02:00
|
|
|
int timeout;
|
|
|
|
};
|
2010-08-24 15:35:37 +02:00
|
|
|
|
2010-10-08 16:15:16 +02:00
|
|
|
|
|
|
|
static int wps_ap_pin_set(struct hostapd_data *hapd, void *ctx)
|
|
|
|
{
|
|
|
|
struct wps_ap_pin_data *data = ctx;
|
2010-08-24 15:35:37 +02:00
|
|
|
os_free(hapd->conf->ap_pin);
|
2010-10-08 16:15:16 +02:00
|
|
|
hapd->conf->ap_pin = os_strdup(data->pin_txt);
|
2010-09-05 11:34:04 +02:00
|
|
|
#ifdef CONFIG_WPS_UPNP
|
2010-10-08 16:15:16 +02:00
|
|
|
upnp_wps_set_ap_pin(hapd->wps_upnp, data->pin_txt);
|
2010-09-05 11:34:04 +02:00
|
|
|
#endif /* CONFIG_WPS_UPNP */
|
2010-10-08 16:15:16 +02:00
|
|
|
hostapd_wps_ap_pin_enable(hapd, data->timeout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char * hostapd_wps_ap_pin_random(struct hostapd_data *hapd, int timeout)
|
|
|
|
{
|
|
|
|
unsigned int pin;
|
|
|
|
struct wps_ap_pin_data data;
|
|
|
|
|
|
|
|
pin = wps_generate_pin();
|
2011-12-02 22:04:39 +01:00
|
|
|
os_snprintf(data.pin_txt, sizeof(data.pin_txt), "%08u", pin);
|
2010-10-08 16:15:16 +02:00
|
|
|
data.timeout = timeout;
|
|
|
|
hostapd_wps_for_each(hapd, wps_ap_pin_set, &data);
|
2010-08-24 15:35:37 +02:00
|
|
|
return hapd->conf->ap_pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char * hostapd_wps_ap_pin_get(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
return hapd->conf->ap_pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_wps_ap_pin_set(struct hostapd_data *hapd, const char *pin,
|
|
|
|
int timeout)
|
|
|
|
{
|
2010-10-08 16:15:16 +02:00
|
|
|
struct wps_ap_pin_data data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = os_snprintf(data.pin_txt, sizeof(data.pin_txt), "%s", pin);
|
Check os_snprintf() result more consistently - automatic 1
This converts os_snprintf() result validation cases to use
os_snprintf_error() where the exact rule used in os_snprintf_error() was
used. These changes were done automatically with spatch using the
following semantic patch:
@@
identifier E1;
expression E2,E3,E4,E5,E6;
statement S1;
@@
(
E1 = os_snprintf(E2, E3, ...);
|
int E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else
E1 = os_snprintf(E2, E3, ...);
|
if (E5)
E1 = os_snprintf(E2, E3, ...);
else if (E6)
E1 = os_snprintf(E2, E3, ...);
else
E1 = 0;
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else if (E6) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
return -1;
}
|
if (E5) {
...
E1 = os_snprintf(E2, E3, ...);
} else {
...
E1 = os_snprintf(E2, E3, ...);
}
)
? os_free(E4);
- if (E1 < 0 || \( E1 >= E3 \| (size_t) E1 >= E3 \| (unsigned int) E1 >= E3 \| E1 >= (int) E3 \))
+ if (os_snprintf_error(E3, E1))
(
S1
|
{ ... }
)
Signed-off-by: Jouni Malinen <j@w1.fi>
2014-12-08 10:15:51 +01:00
|
|
|
if (os_snprintf_error(sizeof(data.pin_txt), ret))
|
2010-08-24 15:35:37 +02:00
|
|
|
return -1;
|
2010-10-08 16:15:16 +02:00
|
|
|
data.timeout = timeout;
|
|
|
|
return hostapd_wps_for_each(hapd, wps_ap_pin_set, &data);
|
2010-08-24 15:35:37 +02:00
|
|
|
}
|
2010-10-19 18:57:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
static int wps_update_ie(struct hostapd_data *hapd, void *ctx)
|
|
|
|
{
|
|
|
|
if (hapd->wps)
|
|
|
|
wps_registrar_update_ie(hapd->wps->registrar);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void hostapd_wps_update_ie(struct hostapd_data *hapd)
|
|
|
|
{
|
2010-10-20 12:35:55 +02:00
|
|
|
hostapd_wps_for_each(hapd, wps_update_ie, NULL);
|
2010-10-19 18:57:01 +02:00
|
|
|
}
|
2010-10-21 15:49:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
int hostapd_wps_config_ap(struct hostapd_data *hapd, const char *ssid,
|
|
|
|
const char *auth, const char *encr, const char *key)
|
|
|
|
{
|
|
|
|
struct wps_credential cred;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
os_memset(&cred, 0, sizeof(cred));
|
|
|
|
|
|
|
|
len = os_strlen(ssid);
|
|
|
|
if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
|
|
|
|
hexstr2bin(ssid, cred.ssid, len / 2))
|
|
|
|
return -1;
|
|
|
|
cred.ssid_len = len / 2;
|
|
|
|
|
|
|
|
if (os_strncmp(auth, "OPEN", 4) == 0)
|
|
|
|
cred.auth_type = WPS_AUTH_OPEN;
|
|
|
|
else if (os_strncmp(auth, "WPAPSK", 6) == 0)
|
|
|
|
cred.auth_type = WPS_AUTH_WPAPSK;
|
|
|
|
else if (os_strncmp(auth, "WPA2PSK", 7) == 0)
|
|
|
|
cred.auth_type = WPS_AUTH_WPA2PSK;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (encr) {
|
|
|
|
if (os_strncmp(encr, "NONE", 4) == 0)
|
|
|
|
cred.encr_type = WPS_ENCR_NONE;
|
|
|
|
else if (os_strncmp(encr, "TKIP", 4) == 0)
|
|
|
|
cred.encr_type = WPS_ENCR_TKIP;
|
|
|
|
else if (os_strncmp(encr, "CCMP", 4) == 0)
|
|
|
|
cred.encr_type = WPS_ENCR_AES;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
cred.encr_type = WPS_ENCR_NONE;
|
|
|
|
|
|
|
|
if (key) {
|
|
|
|
len = os_strlen(key);
|
|
|
|
if ((len & 1) || len > 2 * sizeof(cred.key) ||
|
|
|
|
hexstr2bin(key, cred.key, len / 2))
|
|
|
|
return -1;
|
|
|
|
cred.key_len = len / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wps_registrar_config_ap(hapd->wps->registrar, &cred);
|
|
|
|
}
|
2012-06-27 19:54:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_WPS_NFC
|
|
|
|
|
|
|
|
struct wps_nfc_password_token_data {
|
|
|
|
const u8 *oob_dev_pw;
|
|
|
|
size_t oob_dev_pw_len;
|
|
|
|
int added;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int wps_add_nfc_password_token(struct hostapd_data *hapd, void *ctx)
|
|
|
|
{
|
|
|
|
struct wps_nfc_password_token_data *data = ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (hapd->wps == NULL)
|
|
|
|
return 0;
|
|
|
|
ret = wps_registrar_add_nfc_password_token(hapd->wps->registrar,
|
|
|
|
data->oob_dev_pw,
|
|
|
|
data->oob_dev_pw_len);
|
|
|
|
if (ret == 0)
|
|
|
|
data->added++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hostapd_wps_add_nfc_password_token(struct hostapd_data *hapd,
|
|
|
|
struct wps_parse_attr *attr)
|
|
|
|
{
|
|
|
|
struct wps_nfc_password_token_data data;
|
|
|
|
|
|
|
|
data.oob_dev_pw = attr->oob_dev_password;
|
|
|
|
data.oob_dev_pw_len = attr->oob_dev_password_len;
|
|
|
|
data.added = 0;
|
|
|
|
if (hostapd_wps_for_each(hapd, wps_add_nfc_password_token, &data) < 0)
|
|
|
|
return -1;
|
|
|
|
return data.added ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hostapd_wps_nfc_tag_process(struct hostapd_data *hapd,
|
|
|
|
const struct wpabuf *wps)
|
|
|
|
{
|
|
|
|
struct wps_parse_attr attr;
|
|
|
|
|
|
|
|
wpa_hexdump_buf(MSG_DEBUG, "WPS: Received NFC tag payload", wps);
|
|
|
|
|
|
|
|
if (wps_parse_msg(wps, &attr)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Ignore invalid data from NFC tag");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.oob_dev_password)
|
|
|
|
return hostapd_wps_add_nfc_password_token(hapd, &attr);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Ignore unrecognized NFC tag");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_wps_nfc_tag_read(struct hostapd_data *hapd,
|
|
|
|
const struct wpabuf *data)
|
|
|
|
{
|
|
|
|
const struct wpabuf *wps = data;
|
|
|
|
struct wpabuf *tmp = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (wpabuf_len(data) < 4)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (*wpabuf_head_u8(data) != 0x10) {
|
|
|
|
/* Assume this contains full NDEF record */
|
|
|
|
tmp = ndef_parse_wifi(data);
|
|
|
|
if (tmp == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Could not parse NDEF");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wps = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = hostapd_wps_nfc_tag_process(hapd, wps);
|
|
|
|
wpabuf_free(tmp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-28 12:25:48 +02:00
|
|
|
|
|
|
|
struct wpabuf * hostapd_wps_nfc_config_token(struct hostapd_data *hapd,
|
|
|
|
int ndef)
|
|
|
|
{
|
|
|
|
struct wpabuf *ret;
|
|
|
|
|
|
|
|
if (hapd->wps == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2013-11-28 11:31:32 +01:00
|
|
|
ret = wps_get_oob_cred(hapd->wps, hostapd_wps_rf_band_cb(hapd),
|
|
|
|
hapd->iconf->channel);
|
2012-06-28 12:25:48 +02:00
|
|
|
if (ndef && ret) {
|
|
|
|
struct wpabuf *tmp;
|
|
|
|
tmp = ndef_build_wifi(ret);
|
|
|
|
wpabuf_free(ret);
|
|
|
|
if (tmp == NULL)
|
|
|
|
return NULL;
|
|
|
|
ret = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-28 18:43:29 +02:00
|
|
|
|
2013-02-10 16:12:55 +01:00
|
|
|
struct wpabuf * hostapd_wps_nfc_hs_cr(struct hostapd_data *hapd, int ndef)
|
|
|
|
{
|
2013-04-27 15:58:56 +02:00
|
|
|
struct wpabuf *ret;
|
|
|
|
|
|
|
|
if (hapd->wps == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (hapd->conf->wps_nfc_dh_pubkey == NULL) {
|
|
|
|
struct wps_context *wps = hapd->wps;
|
|
|
|
if (wps_nfc_gen_dh(&hapd->conf->wps_nfc_dh_pubkey,
|
|
|
|
&hapd->conf->wps_nfc_dh_privkey) < 0)
|
|
|
|
return NULL;
|
|
|
|
hostapd_wps_nfc_clear(wps);
|
|
|
|
wps->ap_nfc_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER;
|
|
|
|
wps->ap_nfc_dh_pubkey =
|
|
|
|
wpabuf_dup(hapd->conf->wps_nfc_dh_pubkey);
|
|
|
|
wps->ap_nfc_dh_privkey =
|
|
|
|
wpabuf_dup(hapd->conf->wps_nfc_dh_privkey);
|
|
|
|
if (!wps->ap_nfc_dh_pubkey || !wps->ap_nfc_dh_privkey) {
|
|
|
|
hostapd_wps_nfc_clear(wps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wps_build_nfc_handover_sel(hapd->wps,
|
2013-04-27 19:31:28 +02:00
|
|
|
hapd->conf->wps_nfc_dh_pubkey,
|
|
|
|
hapd->own_addr, hapd->iface->freq);
|
2013-04-27 15:58:56 +02:00
|
|
|
|
|
|
|
if (ndef && ret) {
|
|
|
|
struct wpabuf *tmp;
|
|
|
|
tmp = ndef_build_wifi(ret);
|
|
|
|
wpabuf_free(ret);
|
|
|
|
if (tmp == NULL)
|
|
|
|
return NULL;
|
|
|
|
ret = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-02-10 16:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 17:30:58 +02:00
|
|
|
int hostapd_wps_nfc_report_handover(struct hostapd_data *hapd,
|
|
|
|
const struct wpabuf *req,
|
|
|
|
const struct wpabuf *sel)
|
|
|
|
{
|
|
|
|
struct wpabuf *wps;
|
|
|
|
int ret = -1;
|
|
|
|
u16 wsc_len;
|
|
|
|
const u8 *pos;
|
|
|
|
struct wpabuf msg;
|
|
|
|
struct wps_parse_attr attr;
|
|
|
|
u16 dev_pw_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enrollee/station is always initiator of the NFC connection handover,
|
|
|
|
* so use the request message here to find Enrollee public key hash.
|
|
|
|
*/
|
|
|
|
wps = ndef_parse_wifi(req);
|
|
|
|
if (wps == NULL)
|
|
|
|
return -1;
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc "
|
|
|
|
"payload from NFC connection handover");
|
|
|
|
wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps);
|
|
|
|
if (wpabuf_len(wps) < 2) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Request "
|
|
|
|
"Message");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
pos = wpabuf_head(wps);
|
|
|
|
wsc_len = WPA_GET_BE16(pos);
|
|
|
|
if (wsc_len > wpabuf_len(wps) - 2) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) "
|
|
|
|
"in rt Wi-Fi Handover Request Message", wsc_len);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
pos += 2;
|
|
|
|
|
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"WPS: WSC attributes in Wi-Fi Handover Request Message",
|
|
|
|
pos, wsc_len);
|
|
|
|
if (wsc_len < wpabuf_len(wps) - 2) {
|
|
|
|
wpa_hexdump(MSG_DEBUG,
|
|
|
|
"WPS: Ignore extra data after WSC attributes",
|
|
|
|
pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
wpabuf_set(&msg, pos, wsc_len);
|
|
|
|
ret = wps_parse_msg(&msg, &attr);
|
|
|
|
if (ret < 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in "
|
|
|
|
"Wi-Fi Handover Request Message");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.oob_dev_password == NULL ||
|
|
|
|
attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password "
|
|
|
|
"included in Wi-Fi Handover Request Message");
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.uuid_e == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: No UUID-E included in Wi-Fi "
|
|
|
|
"Handover Request Message");
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", attr.uuid_e, WPS_UUID_LEN);
|
|
|
|
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password",
|
|
|
|
attr.oob_dev_password, attr.oob_dev_password_len);
|
|
|
|
dev_pw_id = WPA_GET_BE16(attr.oob_dev_password +
|
|
|
|
WPS_OOB_PUBKEY_HASH_LEN);
|
|
|
|
if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID "
|
|
|
|
"%u in Wi-Fi Handover Request Message", dev_pw_id);
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Public Key hash",
|
|
|
|
attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN);
|
|
|
|
|
|
|
|
ret = wps_registrar_add_nfc_pw_token(hapd->wps->registrar,
|
|
|
|
attr.oob_dev_password,
|
|
|
|
DEV_PW_NFC_CONNECTION_HANDOVER,
|
|
|
|
NULL, 0, 1);
|
|
|
|
|
|
|
|
out:
|
|
|
|
wpabuf_free(wps);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-28 18:43:29 +02:00
|
|
|
struct wpabuf * hostapd_wps_nfc_token_gen(struct hostapd_data *hapd, int ndef)
|
|
|
|
{
|
2013-02-15 10:24:29 +01:00
|
|
|
if (hapd->conf->wps_nfc_pw_from_config) {
|
|
|
|
return wps_nfc_token_build(ndef,
|
|
|
|
hapd->conf->wps_nfc_dev_pw_id,
|
|
|
|
hapd->conf->wps_nfc_dh_pubkey,
|
|
|
|
hapd->conf->wps_nfc_dev_pw);
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:54:53 +02:00
|
|
|
return wps_nfc_token_gen(ndef, &hapd->conf->wps_nfc_dev_pw_id,
|
|
|
|
&hapd->conf->wps_nfc_dh_pubkey,
|
|
|
|
&hapd->conf->wps_nfc_dh_privkey,
|
|
|
|
&hapd->conf->wps_nfc_dev_pw);
|
2012-06-28 18:43:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_wps_nfc_token_enable(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
struct wps_context *wps = hapd->wps;
|
2013-02-24 09:57:49 +01:00
|
|
|
struct wpabuf *pw;
|
2012-06-28 18:43:29 +02:00
|
|
|
|
|
|
|
if (wps == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!hapd->conf->wps_nfc_dh_pubkey ||
|
|
|
|
!hapd->conf->wps_nfc_dh_privkey ||
|
|
|
|
!hapd->conf->wps_nfc_dev_pw ||
|
|
|
|
!hapd->conf->wps_nfc_dev_pw_id)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
hostapd_wps_nfc_clear(wps);
|
2013-09-08 17:09:38 +02:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"WPS: Enable NFC Tag (Dev Pw Id %u) for AP interface %s (context %p)",
|
|
|
|
hapd->conf->wps_nfc_dev_pw_id, hapd->conf->iface, wps);
|
2012-06-28 18:43:29 +02:00
|
|
|
wps->ap_nfc_dev_pw_id = hapd->conf->wps_nfc_dev_pw_id;
|
|
|
|
wps->ap_nfc_dh_pubkey = wpabuf_dup(hapd->conf->wps_nfc_dh_pubkey);
|
|
|
|
wps->ap_nfc_dh_privkey = wpabuf_dup(hapd->conf->wps_nfc_dh_privkey);
|
2013-02-24 09:57:49 +01:00
|
|
|
pw = hapd->conf->wps_nfc_dev_pw;
|
|
|
|
wps->ap_nfc_dev_pw = wpabuf_alloc(
|
|
|
|
wpabuf_len(pw) * 2 + 1);
|
|
|
|
if (wps->ap_nfc_dev_pw) {
|
|
|
|
wpa_snprintf_hex_uppercase(
|
|
|
|
(char *) wpabuf_put(wps->ap_nfc_dev_pw,
|
|
|
|
wpabuf_len(pw) * 2),
|
|
|
|
wpabuf_len(pw) * 2 + 1,
|
|
|
|
wpabuf_head(pw), wpabuf_len(pw));
|
|
|
|
}
|
2012-06-28 18:43:29 +02:00
|
|
|
|
|
|
|
if (!wps->ap_nfc_dh_pubkey || !wps->ap_nfc_dh_privkey ||
|
|
|
|
!wps->ap_nfc_dev_pw) {
|
|
|
|
hostapd_wps_nfc_clear(wps);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void hostapd_wps_nfc_token_disable(struct hostapd_data *hapd)
|
|
|
|
{
|
2013-09-08 17:09:38 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Disable NFC token for AP interface %s",
|
|
|
|
hapd->conf->iface);
|
2012-06-28 18:43:29 +02:00
|
|
|
hostapd_wps_nfc_clear(hapd->wps);
|
|
|
|
}
|
|
|
|
|
2012-06-27 19:54:56 +02:00
|
|
|
#endif /* CONFIG_WPS_NFC */
|