LCOV - code coverage report
Current view: top level - src/ap - hs20.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 57 89 64.0 %
Date: 2014-03-02 Functions: 3 4 75.0 %
Branches: 8 22 36.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Hotspot 2.0 AP ANQP processing
       3                 :            :  * Copyright (c) 2009, Atheros Communications, Inc.
       4                 :            :  * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
       5                 :            :  *
       6                 :            :  * This software may be distributed under the terms of the BSD license.
       7                 :            :  * See README for more details.
       8                 :            :  */
       9                 :            : 
      10                 :            : #include "includes.h"
      11                 :            : 
      12                 :            : #include "common.h"
      13                 :            : #include "common/ieee802_11_defs.h"
      14                 :            : #include "hostapd.h"
      15                 :            : #include "ap_config.h"
      16                 :            : #include "ap_drv_ops.h"
      17                 :            : #include "hs20.h"
      18                 :            : 
      19                 :            : 
      20                 :       3402 : u8 * hostapd_eid_hs20_indication(struct hostapd_data *hapd, u8 *eid)
      21                 :            : {
      22                 :            :         u8 conf;
      23         [ +  + ]:       3402 :         if (!hapd->conf->hs20)
      24                 :       3040 :                 return eid;
      25                 :        362 :         *eid++ = WLAN_EID_VENDOR_SPECIFIC;
      26                 :        362 :         *eid++ = 7;
      27                 :        362 :         WPA_PUT_BE24(eid, OUI_WFA);
      28                 :        362 :         eid += 3;
      29                 :        362 :         *eid++ = HS20_INDICATION_OUI_TYPE;
      30                 :        362 :         conf = HS20_VERSION; /* Release Number */
      31                 :        362 :         conf |= HS20_ANQP_DOMAIN_ID_PRESENT;
      32         [ -  + ]:        362 :         if (hapd->conf->disable_dgaf)
      33                 :          0 :                 conf |= HS20_DGAF_DISABLED;
      34                 :        362 :         *eid++ = conf;
      35                 :        362 :         WPA_PUT_LE16(eid, hapd->conf->anqp_domain_id);
      36                 :        362 :         eid += 2;
      37                 :            : 
      38                 :       3402 :         return eid;
      39                 :            : }
      40                 :            : 
      41                 :            : 
      42                 :       3402 : u8 * hostapd_eid_osen(struct hostapd_data *hapd, u8 *eid)
      43                 :            : {
      44                 :            :         u8 *len;
      45                 :            :         u16 capab;
      46                 :            : 
      47         [ +  + ]:       3402 :         if (!hapd->conf->osen)
      48                 :       3399 :                 return eid;
      49                 :            : 
      50                 :          3 :         *eid++ = WLAN_EID_VENDOR_SPECIFIC;
      51                 :          3 :         len = eid++; /* to be filled */
      52                 :          3 :         WPA_PUT_BE24(eid, OUI_WFA);
      53                 :          3 :         eid += 3;
      54                 :          3 :         *eid++ = HS20_OSEN_OUI_TYPE;
      55                 :            : 
      56                 :            :         /* Group Data Cipher Suite */
      57                 :          3 :         RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
      58                 :          3 :         eid += RSN_SELECTOR_LEN;
      59                 :            : 
      60                 :            :         /* Pairwise Cipher Suite Count and List */
      61                 :          3 :         WPA_PUT_LE16(eid, 1);
      62                 :          3 :         eid += 2;
      63                 :          3 :         RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_CCMP);
      64                 :          3 :         eid += RSN_SELECTOR_LEN;
      65                 :            : 
      66                 :            :         /* AKM Suite Count and List */
      67                 :          3 :         WPA_PUT_LE16(eid, 1);
      68                 :          3 :         eid += 2;
      69                 :          3 :         RSN_SELECTOR_PUT(eid, RSN_AUTH_KEY_MGMT_OSEN);
      70                 :          3 :         eid += RSN_SELECTOR_LEN;
      71                 :            : 
      72                 :            :         /* RSN Capabilities */
      73                 :          3 :         capab = 0;
      74         [ +  - ]:          3 :         if (hapd->conf->wmm_enabled) {
      75                 :            :                 /* 4 PTKSA replay counters when using WMM */
      76                 :          3 :                 capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2);
      77                 :            :         }
      78                 :            : #ifdef CONFIG_IEEE80211W
      79         [ -  + ]:          3 :         if (hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
      80                 :          0 :                 capab |= WPA_CAPABILITY_MFPC;
      81         [ #  # ]:          0 :                 if (hapd->conf->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
      82                 :          0 :                         capab |= WPA_CAPABILITY_MFPR;
      83                 :            :         }
      84                 :            : #endif /* CONFIG_IEEE80211W */
      85                 :          3 :         WPA_PUT_LE16(eid, capab);
      86                 :          3 :         eid += 2;
      87                 :            : 
      88                 :          3 :         *len = eid - len - 1;
      89                 :            : 
      90                 :       3402 :         return eid;
      91                 :            : }
      92                 :            : 
      93                 :            : 
      94                 :          0 : int hs20_send_wnm_notification(struct hostapd_data *hapd, const u8 *addr,
      95                 :            :                                u8 osu_method, const char *url)
      96                 :            : {
      97                 :            :         struct wpabuf *buf;
      98                 :          0 :         size_t len = 0;
      99                 :            :         int ret;
     100                 :            : 
     101                 :            :         /* TODO: should refuse to send notification if the STA is not associated
     102                 :            :          * or if the STA did not indicate support for WNM-Notification */
     103                 :            : 
     104         [ #  # ]:          0 :         if (url) {
     105                 :          0 :                 len = 1 + os_strlen(url);
     106         [ #  # ]:          0 :                 if (5 + len > 255) {
     107                 :          0 :                         wpa_printf(MSG_INFO, "HS 2.0: Too long URL for "
     108                 :            :                                    "WNM-Notification: '%s'", url);
     109                 :          0 :                         return -1;
     110                 :            :                 }
     111                 :            :         }
     112                 :            : 
     113                 :          0 :         buf = wpabuf_alloc(4 + 7 + len);
     114         [ #  # ]:          0 :         if (buf == NULL)
     115                 :          0 :                 return -1;
     116                 :            : 
     117                 :          0 :         wpabuf_put_u8(buf, WLAN_ACTION_WNM);
     118                 :          0 :         wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
     119                 :          0 :         wpabuf_put_u8(buf, 1); /* Dialog token */
     120                 :          0 :         wpabuf_put_u8(buf, 1); /* Type - 1 reserved for WFA */
     121                 :            : 
     122                 :            :         /* Subscription Remediation subelement */
     123                 :          0 :         wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
     124                 :          0 :         wpabuf_put_u8(buf, 5 + len);
     125                 :          0 :         wpabuf_put_be24(buf, OUI_WFA);
     126                 :          0 :         wpabuf_put_u8(buf, HS20_WNM_SUB_REM_NEEDED);
     127         [ #  # ]:          0 :         if (url) {
     128                 :          0 :                 wpabuf_put_u8(buf, len - 1);
     129                 :          0 :                 wpabuf_put_data(buf, url, len - 1);
     130                 :          0 :                 wpabuf_put_u8(buf, osu_method);
     131                 :            :         } else {
     132                 :            :                 /* Server URL and Server Method fields not included */
     133                 :          0 :                 wpabuf_put_u8(buf, 0);
     134                 :            :         }
     135                 :            : 
     136                 :          0 :         ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
     137                 :          0 :                                       wpabuf_head(buf), wpabuf_len(buf));
     138                 :            : 
     139                 :          0 :         wpabuf_free(buf);
     140                 :            : 
     141                 :          0 :         return ret;
     142                 :            : }
     143                 :            : 
     144                 :            : 
     145                 :          2 : int hs20_send_wnm_notification_deauth_req(struct hostapd_data *hapd,
     146                 :            :                                           const u8 *addr,
     147                 :            :                                           const struct wpabuf *payload)
     148                 :            : {
     149                 :            :         struct wpabuf *buf;
     150                 :            :         int ret;
     151                 :            : 
     152                 :            :         /* TODO: should refuse to send notification if the STA is not associated
     153                 :            :          * or if the STA did not indicate support for WNM-Notification */
     154                 :            : 
     155                 :          2 :         buf = wpabuf_alloc(4 + 6 + wpabuf_len(payload));
     156         [ -  + ]:          2 :         if (buf == NULL)
     157                 :          0 :                 return -1;
     158                 :            : 
     159                 :          2 :         wpabuf_put_u8(buf, WLAN_ACTION_WNM);
     160                 :          2 :         wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
     161                 :          2 :         wpabuf_put_u8(buf, 1); /* Dialog token */
     162                 :          2 :         wpabuf_put_u8(buf, 1); /* Type - 1 reserved for WFA */
     163                 :            : 
     164                 :            :         /* Deauthentication Imminent Notice subelement */
     165                 :          2 :         wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
     166                 :          2 :         wpabuf_put_u8(buf, 4 + wpabuf_len(payload));
     167                 :          2 :         wpabuf_put_be24(buf, OUI_WFA);
     168                 :          2 :         wpabuf_put_u8(buf, HS20_WNM_DEAUTH_IMMINENT_NOTICE);
     169                 :          2 :         wpabuf_put_buf(buf, payload);
     170                 :            : 
     171                 :          4 :         ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
     172                 :          2 :                                       wpabuf_head(buf), wpabuf_len(buf));
     173                 :            : 
     174                 :          2 :         wpabuf_free(buf);
     175                 :            : 
     176                 :          2 :         return ret;
     177                 :            : }

Generated by: LCOV version 1.9