LCOV - code coverage report
Current view: top level - src/wps - wps_upnp_ap.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 40 40 100.0 %
Date: 2015-09-27 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.10