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 1393793999 Lines: 31 41 75.6 %
Date: 2014-03-02 Functions: 2 3 66.7 %
Branches: 12 20 60.0 %

           Branch data     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                 :          0 : static void upnp_er_set_selected_timeout(void *eloop_ctx, void *timeout_ctx)
      20                 :            : {
      21                 :          0 :         struct subscription *s = eloop_ctx;
      22                 :          0 :         struct wps_registrar *reg = timeout_ctx;
      23                 :          0 :         wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar from ER timed out");
      24                 :          0 :         s->selected_registrar = 0;
      25                 :          0 :         wps_registrar_selected_registrar_changed(reg, 0);
      26                 :          0 : }
      27                 :            : 
      28                 :            : 
      29                 :         18 : 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                 :         18 :         wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
      36                 :            :                         msg);
      37         [ -  + ]:         18 :         if (wps_validate_upnp_set_selected_registrar(msg) < 0)
      38                 :          0 :                 return -1;
      39                 :            : 
      40         [ -  + ]:         18 :         if (wps_parse_msg(msg, &attr) < 0)
      41                 :          0 :                 return -1;
      42                 :            : 
      43                 :         18 :         s->reg = reg;
      44                 :         18 :         eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
      45                 :            : 
      46                 :         18 :         os_memset(s->authorized_macs, 0, sizeof(s->authorized_macs));
      47 [ +  + ][ +  - ]:         18 :         if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
      48                 :          6 :                 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
      49                 :            :                            "Selected Registrar");
      50                 :          6 :                 s->selected_registrar = 0;
      51                 :            :         } else {
      52                 :         12 :                 s->selected_registrar = 1;
      53         [ +  - ]:         12 :                 s->dev_password_id = attr.dev_password_id ?
      54                 :         12 :                         WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
      55         [ +  - ]:         12 :                 s->config_methods = attr.sel_reg_config_methods ?
      56                 :         12 :                         WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
      57         [ +  + ]:         12 :                 if (attr.authorized_macs) {
      58                 :         10 :                         int count = attr.authorized_macs_len / ETH_ALEN;
      59         [ -  + ]:         10 :                         if (count > WPS_MAX_AUTHORIZED_MACS)
      60                 :          0 :                                 count = WPS_MAX_AUTHORIZED_MACS;
      61                 :         10 :                         os_memcpy(s->authorized_macs, attr.authorized_macs,
      62                 :            :                                   count * ETH_ALEN);
      63         [ +  - ]:          2 :                 } else if (!attr.version2) {
      64                 :            : #ifdef CONFIG_WPS2
      65                 :          2 :                         wpa_printf(MSG_DEBUG, "WPS: Add broadcast "
      66                 :            :                                    "AuthorizedMACs for WPS 1.0 ER");
      67                 :          2 :                         os_memset(s->authorized_macs, 0xff, ETH_ALEN);
      68                 :            : #endif /* CONFIG_WPS2 */
      69                 :            :                 }
      70                 :         12 :                 eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
      71                 :            :                                        upnp_er_set_selected_timeout, s, reg);
      72                 :            :         }
      73                 :            : 
      74                 :         18 :         wps_registrar_selected_registrar_changed(reg, 0);
      75                 :            : 
      76                 :         18 :         return 0;
      77                 :            : }
      78                 :            : 
      79                 :            : 
      80                 :         11 : void upnp_er_remove_notification(struct wps_registrar *reg,
      81                 :            :                                  struct subscription *s)
      82                 :            : {
      83                 :         11 :         s->selected_registrar = 0;
      84                 :         11 :         eloop_cancel_timeout(upnp_er_set_selected_timeout, s, reg);
      85         [ +  - ]:         11 :         if (reg)
      86                 :         11 :                 wps_registrar_selected_registrar_changed(reg, 0);
      87                 :         11 : }

Generated by: LCOV version 1.9