2 * Wi-Fi Protected Setup - UPnP AP functionality
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
16 #include "wps_upnp_i.h"
19 static void upnp_er_set_selected_timeout(void *eloop_ctx
, void *timeout_ctx
)
21 struct subscription
*s
= eloop_ctx
;
22 struct wps_registrar
*reg
= timeout_ctx
;
23 wpa_printf(MSG_DEBUG
, "WPS: SetSelectedRegistrar from ER timed out");
24 s
->selected_registrar
= 0;
25 wps_registrar_selected_registrar_changed(reg
);
29 int upnp_er_set_selected_registrar(struct wps_registrar
*reg
,
30 struct subscription
*s
,
31 const struct wpabuf
*msg
)
33 struct wps_parse_attr attr
;
35 wpa_hexdump_buf(MSG_MSGDUMP
, "WPS: SetSelectedRegistrar attributes",
37 if (wps_validate_upnp_set_selected_registrar(msg
) < 0)
40 if (wps_parse_msg(msg
, &attr
) < 0)
44 eloop_cancel_timeout(upnp_er_set_selected_timeout
, s
, reg
);
46 os_memset(s
->authorized_macs
, 0, sizeof(s
->authorized_macs
));
47 if (attr
.selected_registrar
== NULL
|| *attr
.selected_registrar
== 0) {
48 wpa_printf(MSG_DEBUG
, "WPS: SetSelectedRegistrar: Disable "
49 "Selected Registrar");
50 s
->selected_registrar
= 0;
52 s
->selected_registrar
= 1;
53 s
->dev_password_id
= attr
.dev_password_id
?
54 WPA_GET_BE16(attr
.dev_password_id
) : DEV_PW_DEFAULT
;
55 s
->config_methods
= attr
.sel_reg_config_methods
?
56 WPA_GET_BE16(attr
.sel_reg_config_methods
) : -1;
57 if (attr
.authorized_macs
) {
58 int count
= attr
.authorized_macs_len
/ ETH_ALEN
;
59 if (count
> WPS_MAX_AUTHORIZED_MACS
)
60 count
= WPS_MAX_AUTHORIZED_MACS
;
61 os_memcpy(s
->authorized_macs
, attr
.authorized_macs
,
63 } else if (!attr
.version2
) {
65 wpa_printf(MSG_DEBUG
, "WPS: Add broadcast "
66 "AuthorizedMACs for WPS 1.0 ER");
67 os_memset(s
->authorized_macs
, 0xff, ETH_ALEN
);
68 #endif /* CONFIG_WPS2 */
70 eloop_register_timeout(WPS_PBC_WALK_TIME
, 0,
71 upnp_er_set_selected_timeout
, s
, reg
);
74 wps_registrar_selected_registrar_changed(reg
);
80 void upnp_er_remove_notification(struct wps_registrar
*reg
,
81 struct subscription
*s
)
83 s
->selected_registrar
= 0;
84 eloop_cancel_timeout(upnp_er_set_selected_timeout
, s
, reg
);
86 wps_registrar_selected_registrar_changed(reg
);