2 * Wi-Fi Protected Setup - UPnP AP functionality
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
22 #include "wps_upnp_i.h"
25 static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
27 struct subscription *s = eloop_ctx;
28 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
29 s->selected_registrar = 0;
30 wps_registrar_selected_registrar_changed(s->reg);
34 int upnp_er_set_selected_registrar(struct wps_registrar *reg,
35 struct subscription *s,
36 const struct wpabuf *msg)
38 struct wps_parse_attr attr;
40 wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
42 if (wps_validate_upnp_set_selected_registrar(msg) < 0)
45 if (wps_parse_msg(msg, &attr) < 0)
49 eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
51 os_memset(s->authorized_macs, 0, sizeof(s->authorized_macs));
52 if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
53 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
54 "Selected Registrar");
55 s->selected_registrar = 0;
57 s->selected_registrar = 1;
58 s->dev_password_id = attr.dev_password_id ?
59 WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
60 s->config_methods = attr.sel_reg_config_methods ?
61 WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
62 if (attr.authorized_macs) {
63 int count = attr.authorized_macs_len / ETH_ALEN;
64 if (count > WPS_MAX_AUTHORIZED_MACS)
65 count = WPS_MAX_AUTHORIZED_MACS;
66 os_memcpy(s->authorized_macs, attr.authorized_macs,
68 } else if (!attr.version2) {
70 wpa_printf(MSG_DEBUG, "WPS: Add broadcast "
71 "AuthorizedMACs for WPS 1.0 ER");
72 os_memset(s->authorized_macs, 0xff, ETH_ALEN);
73 #endif /* CONFIG_WPS2 */
75 eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
76 upnp_er_set_selected_timeout, s, NULL);
79 wps_registrar_selected_registrar_changed(reg);
85 void upnp_er_remove_notification(struct subscription *s)
87 s->selected_registrar = 0;
88 eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
90 wps_registrar_selected_registrar_changed(s->reg);