wps_upnp_ap.c
Go to the documentation of this file.
00001 /*
00002  * Wi-Fi Protected Setup - UPnP AP functionality
00003  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 
00017 #include "common.h"
00018 #include "eloop.h"
00019 #include "uuid.h"
00020 #include "wps_i.h"
00021 #include "wps_upnp.h"
00022 #include "wps_upnp_i.h"
00023 
00024 
00025 static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
00026 {
00027         struct subscription *s = eloop_ctx;
00028         wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
00029         s->selected_registrar = 0;
00030         wps_registrar_selected_registrar_changed(s->reg);
00031 }
00032 
00033 
00034 int upnp_er_set_selected_registrar(struct wps_registrar *reg,
00035                                    struct subscription *s,
00036                                    const struct wpabuf *msg)
00037 {
00038         struct wps_parse_attr attr;
00039 
00040         wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
00041                         msg);
00042 
00043         if (wps_parse_msg(msg, &attr) < 0)
00044                 return -1;
00045         if (!wps_version_supported(attr.version)) {
00046                 wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
00047                            "version 0x%x", attr.version ? *attr.version : 0);
00048                 return -1;
00049         }
00050 
00051         s->reg = reg;
00052         eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
00053 
00054         if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
00055                 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
00056                            "Selected Registrar");
00057                 s->selected_registrar = 0;
00058         } else {
00059                 s->selected_registrar = 1;
00060                 s->dev_password_id = attr.dev_password_id ?
00061                         WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
00062                 s->config_methods = attr.sel_reg_config_methods ?
00063                         WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
00064                 eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
00065                                        upnp_er_set_selected_timeout, s, NULL);
00066         }
00067 
00068         wps_registrar_selected_registrar_changed(reg);
00069 
00070         return 0;
00071 }
00072 
00073 
00074 void upnp_er_remove_notification(struct subscription *s)
00075 {
00076         s->selected_registrar = 0;
00077         eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);
00078         if (s->reg)
00079                 wps_registrar_selected_registrar_changed(s->reg);
00080 }


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:36