2009-12-12 15:54:59 +01:00
|
|
|
/*
|
|
|
|
* Wi-Fi Protected Setup - UPnP AP functionality
|
|
|
|
* Copyright (c) 2009, Jouni Malinen <j@w1.fi>
|
|
|
|
*
|
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.
|
2009-12-12 15:54:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "eloop.h"
|
|
|
|
#include "uuid.h"
|
|
|
|
#include "wps_i.h"
|
|
|
|
#include "wps_upnp.h"
|
|
|
|
#include "wps_upnp_i.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct subscription *s = eloop_ctx;
|
2012-02-13 22:02:57 +01:00
|
|
|
struct wps_registrar *reg = timeout_ctx;
|
2009-12-12 15:54:59 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
|
|
|
|
s->selected_registrar = 0;
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2009-12-12 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int upnp_er_set_selected_registrar(struct wps_registrar *reg,
|
|
|
|
struct subscription *s,
|
|
|
|
const struct wpabuf *msg)
|
|
|
|
{
|
|
|
|
struct wps_parse_attr attr;
|
|
|
|
|
|
|
|
wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
|
|
|
|
msg);
|
2015-08-31 11:29:09 +02:00
|
|
|
if (wps_validate_upnp_set_selected_registrar(msg) < 0 ||
|
|
|
|
wps_parse_msg(msg, &attr) < 0)
|
2009-12-12 15:54:59 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
s->reg = reg;
|
2012-02-13 22:02:57 +01:00
|
|
|
eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
|
2009-12-12 15:54:59 +01:00
|
|
|
|
2009-12-12 15:40:10 +01:00
|
|
|
os_memset(s->authorized_macs, 0, sizeof(s->authorized_macs));
|
2009-12-12 15:54:59 +01:00
|
|
|
if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
|
|
|
|
"Selected Registrar");
|
|
|
|
s->selected_registrar = 0;
|
|
|
|
} else {
|
|
|
|
s->selected_registrar = 1;
|
|
|
|
s->dev_password_id = attr.dev_password_id ?
|
|
|
|
WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
|
|
|
|
s->config_methods = attr.sel_reg_config_methods ?
|
|
|
|
WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
|
2009-12-12 15:40:10 +01:00
|
|
|
if (attr.authorized_macs) {
|
|
|
|
int count = attr.authorized_macs_len / ETH_ALEN;
|
|
|
|
if (count > WPS_MAX_AUTHORIZED_MACS)
|
|
|
|
count = WPS_MAX_AUTHORIZED_MACS;
|
|
|
|
os_memcpy(s->authorized_macs, attr.authorized_macs,
|
|
|
|
count * ETH_ALEN);
|
2010-07-18 03:12:00 +02:00
|
|
|
} else if (!attr.version2) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Add broadcast "
|
|
|
|
"AuthorizedMACs for WPS 1.0 ER");
|
|
|
|
os_memset(s->authorized_macs, 0xff, ETH_ALEN);
|
2009-12-12 15:40:10 +01:00
|
|
|
}
|
2009-12-12 15:54:59 +01:00
|
|
|
eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
|
2012-02-13 22:02:57 +01:00
|
|
|
upnp_er_set_selected_timeout, s, reg);
|
2009-12-12 15:54:59 +01:00
|
|
|
}
|
|
|
|
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2009-12-12 15:54:59 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-13 22:02:57 +01:00
|
|
|
void upnp_er_remove_notification(struct wps_registrar *reg,
|
|
|
|
struct subscription *s)
|
2009-12-12 15:54:59 +01:00
|
|
|
{
|
|
|
|
s->selected_registrar = 0;
|
2012-02-13 22:02:57 +01:00
|
|
|
eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
|
|
|
|
if (reg)
|
2013-04-02 17:27:36 +02:00
|
|
|
wps_registrar_selected_registrar_changed(reg, 0);
|
2009-12-12 15:54:59 +01:00
|
|
|
}
|