1e28a4053SRui Paulo /*
2e28a4053SRui Paulo * Wi-Fi Protected Setup - UPnP AP functionality
3e28a4053SRui Paulo * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo *
5f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo * See README for more details.
7e28a4053SRui Paulo */
8e28a4053SRui Paulo
9e28a4053SRui Paulo #include "includes.h"
10e28a4053SRui Paulo
11e28a4053SRui Paulo #include "common.h"
12e28a4053SRui Paulo #include "eloop.h"
13e28a4053SRui Paulo #include "uuid.h"
14e28a4053SRui Paulo #include "wps_i.h"
15e28a4053SRui Paulo #include "wps_upnp.h"
16e28a4053SRui Paulo #include "wps_upnp_i.h"
17e28a4053SRui Paulo
18e28a4053SRui Paulo
upnp_er_set_selected_timeout(void * eloop_ctx,void * timeout_ctx)19e28a4053SRui Paulo static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
20e28a4053SRui Paulo {
21e28a4053SRui Paulo struct subscription *s = eloop_ctx;
22f05cddf9SRui Paulo struct wps_registrar *reg = timeout_ctx;
23e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
24e28a4053SRui Paulo s->selected_registrar = 0;
255b9c547cSRui Paulo wps_registrar_selected_registrar_changed(reg, 0);
26e28a4053SRui Paulo }
27e28a4053SRui Paulo
28e28a4053SRui Paulo
upnp_er_set_selected_registrar(struct wps_registrar * reg,struct subscription * s,const struct wpabuf * msg)29e28a4053SRui Paulo int upnp_er_set_selected_registrar(struct wps_registrar *reg,
30e28a4053SRui Paulo struct subscription *s,
31e28a4053SRui Paulo const struct wpabuf *msg)
32e28a4053SRui Paulo {
33e28a4053SRui Paulo struct wps_parse_attr attr;
34e28a4053SRui Paulo
35e28a4053SRui Paulo wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
36e28a4053SRui Paulo msg);
37325151a3SRui Paulo if (wps_validate_upnp_set_selected_registrar(msg) < 0 ||
38325151a3SRui Paulo wps_parse_msg(msg, &attr) < 0)
39e28a4053SRui Paulo return -1;
40e28a4053SRui Paulo
41e28a4053SRui Paulo s->reg = reg;
42f05cddf9SRui Paulo eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
43e28a4053SRui Paulo
44f05cddf9SRui Paulo os_memset(s->authorized_macs, 0, sizeof(s->authorized_macs));
45e28a4053SRui Paulo if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
46e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
47e28a4053SRui Paulo "Selected Registrar");
48e28a4053SRui Paulo s->selected_registrar = 0;
49e28a4053SRui Paulo } else {
50e28a4053SRui Paulo s->selected_registrar = 1;
51e28a4053SRui Paulo s->dev_password_id = attr.dev_password_id ?
52e28a4053SRui Paulo WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
53e28a4053SRui Paulo s->config_methods = attr.sel_reg_config_methods ?
54e28a4053SRui Paulo WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
55f05cddf9SRui Paulo if (attr.authorized_macs) {
56f05cddf9SRui Paulo int count = attr.authorized_macs_len / ETH_ALEN;
57f05cddf9SRui Paulo if (count > WPS_MAX_AUTHORIZED_MACS)
58f05cddf9SRui Paulo count = WPS_MAX_AUTHORIZED_MACS;
59f05cddf9SRui Paulo os_memcpy(s->authorized_macs, attr.authorized_macs,
60f05cddf9SRui Paulo count * ETH_ALEN);
61f05cddf9SRui Paulo } else if (!attr.version2) {
62f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "WPS: Add broadcast "
63f05cddf9SRui Paulo "AuthorizedMACs for WPS 1.0 ER");
64f05cddf9SRui Paulo os_memset(s->authorized_macs, 0xff, ETH_ALEN);
65f05cddf9SRui Paulo }
66e28a4053SRui Paulo eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
67f05cddf9SRui Paulo upnp_er_set_selected_timeout, s, reg);
68e28a4053SRui Paulo }
69e28a4053SRui Paulo
705b9c547cSRui Paulo wps_registrar_selected_registrar_changed(reg, 0);
71e28a4053SRui Paulo
72e28a4053SRui Paulo return 0;
73e28a4053SRui Paulo }
74e28a4053SRui Paulo
75e28a4053SRui Paulo
upnp_er_remove_notification(struct wps_registrar * reg,struct subscription * s)76f05cddf9SRui Paulo void upnp_er_remove_notification(struct wps_registrar *reg,
77f05cddf9SRui Paulo struct subscription *s)
78e28a4053SRui Paulo {
79*c1d255d3SCy Schubert bool was_sel_reg = s->selected_registrar;
80*c1d255d3SCy Schubert
81e28a4053SRui Paulo s->selected_registrar = 0;
82f05cddf9SRui Paulo eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
83*c1d255d3SCy Schubert if (reg && was_sel_reg)
845b9c547cSRui Paulo wps_registrar_selected_registrar_changed(reg, 0);
85e28a4053SRui Paulo }
86