Added WirelessManager, a port of wpa_supplicant.
[AROS.git] / workbench / network / WirelessManager / src / wps / wps_upnp_ap.c
blob93746dae1c566c08267b4e6561da0b9f8e7ac85d
1 /*
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
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
17 #include "common.h"
18 #include "eloop.h"
19 #include "uuid.h"
20 #include "wps_i.h"
21 #include "wps_upnp.h"
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",
41 msg);
43 if (wps_parse_msg(msg, &attr) < 0)
44 return -1;
45 if (!wps_version_supported(attr.version)) {
46 wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
47 "version 0x%x", attr.version ? *attr.version : 0);
48 return -1;
51 s->reg = reg;
52 eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
54 if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
55 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
56 "Selected Registrar");
57 s->selected_registrar = 0;
58 } else {
59 s->selected_registrar = 1;
60 s->dev_password_id = attr.dev_password_id ?
61 WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
62 s->config_methods = attr.sel_reg_config_methods ?
63 WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
64 eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
65 upnp_er_set_selected_timeout, s, NULL);
68 wps_registrar_selected_registrar_changed(reg);
70 return 0;
74 void upnp_er_remove_notification(struct subscription *s)
76 s->selected_registrar = 0;
77 eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
78 if (s->reg)
79 wps_registrar_selected_registrar_changed(s->reg);