LCOV - code coverage report
Current view: top level - src/ap - beacon.c (source / functions) Hit Total Coverage
Test: hostapd hwsim test run 1388338050 Lines: 295 437 67.5 %
Date: 2013-12-29 Functions: 17 19 89.5 %
Branches: 122 260 46.9 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
       3                 :            :  * Copyright (c) 2002-2004, Instant802 Networks, Inc.
       4                 :            :  * Copyright (c) 2005-2006, Devicescape Software, Inc.
       5                 :            :  * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
       6                 :            :  *
       7                 :            :  * This software may be distributed under the terms of the BSD license.
       8                 :            :  * See README for more details.
       9                 :            :  */
      10                 :            : 
      11                 :            : #include "utils/includes.h"
      12                 :            : 
      13                 :            : #ifndef CONFIG_NATIVE_WINDOWS
      14                 :            : 
      15                 :            : #include "utils/common.h"
      16                 :            : #include "common/ieee802_11_defs.h"
      17                 :            : #include "common/ieee802_11_common.h"
      18                 :            : #include "wps/wps_defs.h"
      19                 :            : #include "p2p/p2p.h"
      20                 :            : #include "hostapd.h"
      21                 :            : #include "ieee802_11.h"
      22                 :            : #include "wpa_auth.h"
      23                 :            : #include "wmm.h"
      24                 :            : #include "ap_config.h"
      25                 :            : #include "sta_info.h"
      26                 :            : #include "p2p_hostapd.h"
      27                 :            : #include "ap_drv_ops.h"
      28                 :            : #include "beacon.h"
      29                 :            : #include "hs20.h"
      30                 :            : 
      31                 :            : 
      32                 :            : #ifdef NEED_AP_MLME
      33                 :            : 
      34                 :       1338 : static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
      35                 :            : {
      36                 :            : #ifdef CONFIG_TESTING_OPTIONS
      37         [ -  + ]:       1338 :         if (hapd->conf->bss_load_test_set) {
      38         [ #  # ]:          0 :                 if (2 + 5 > len)
      39                 :          0 :                         return eid;
      40                 :          0 :                 *eid++ = WLAN_EID_BSS_LOAD;
      41                 :          0 :                 *eid++ = 5;
      42                 :          0 :                 os_memcpy(eid, hapd->conf->bss_load_test, 5);
      43                 :          0 :                 eid += 5;
      44                 :            :         }
      45                 :            : #endif /* CONFIG_TESTING_OPTIONS */
      46                 :       1338 :         return eid;
      47                 :            : }
      48                 :            : 
      49                 :            : 
      50                 :       1996 : static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
      51                 :            : {
      52                 :       1996 :         u8 erp = 0;
      53                 :            : 
      54 [ +  - ][ -  + ]:       1996 :         if (hapd->iface->current_mode == NULL ||
      55                 :       1996 :             hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
      56                 :          0 :                 return 0;
      57                 :            : 
      58         [ -  + ]:       1996 :         if (hapd->iface->olbc)
      59                 :          0 :                 erp |= ERP_INFO_USE_PROTECTION;
      60         [ -  + ]:       1996 :         if (hapd->iface->num_sta_non_erp > 0) {
      61                 :          0 :                 erp |= ERP_INFO_NON_ERP_PRESENT |
      62                 :            :                         ERP_INFO_USE_PROTECTION;
      63                 :            :         }
      64 [ +  - ][ +  - ]:       1996 :         if (hapd->iface->num_sta_no_short_preamble > 0 ||
      65                 :       1996 :             hapd->iconf->preamble == LONG_PREAMBLE)
      66                 :       1996 :                 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
      67                 :            : 
      68                 :       1996 :         return erp;
      69                 :            : }
      70                 :            : 
      71                 :            : 
      72                 :       1338 : static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
      73                 :            : {
      74                 :       1338 :         *eid++ = WLAN_EID_DS_PARAMS;
      75                 :       1338 :         *eid++ = 1;
      76                 :       1338 :         *eid++ = hapd->iconf->channel;
      77                 :       1338 :         return eid;
      78                 :            : }
      79                 :            : 
      80                 :            : 
      81                 :       1338 : static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
      82                 :            : {
      83 [ +  - ][ -  + ]:       1338 :         if (hapd->iface->current_mode == NULL ||
      84                 :       1338 :             hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
      85                 :          0 :                 return eid;
      86                 :            : 
      87                 :            :         /* Set NonERP_present and use_protection bits if there
      88                 :            :          * are any associated NonERP stations. */
      89                 :            :         /* TODO: use_protection bit can be set to zero even if
      90                 :            :          * there are NonERP stations present. This optimization
      91                 :            :          * might be useful if NonERP stations are "quiet".
      92                 :            :          * See 802.11g/D6 E-1 for recommended practice.
      93                 :            :          * In addition, Non ERP present might be set, if AP detects Non ERP
      94                 :            :          * operation on other APs. */
      95                 :            : 
      96                 :            :         /* Add ERP Information element */
      97                 :       1338 :         *eid++ = WLAN_EID_ERP_INFO;
      98                 :       1338 :         *eid++ = 1;
      99                 :       1338 :         *eid++ = ieee802_11_erp_info(hapd);
     100                 :            : 
     101                 :       1338 :         return eid;
     102                 :            : }
     103                 :            : 
     104                 :            : 
     105                 :          0 : static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
     106                 :            :                                     struct hostapd_channel_data *start,
     107                 :            :                                     struct hostapd_channel_data *prev)
     108                 :            : {
     109         [ #  # ]:          0 :         if (end - pos < 3)
     110                 :          0 :                 return pos;
     111                 :            : 
     112                 :            :         /* first channel number */
     113                 :          0 :         *pos++ = start->chan;
     114                 :            :         /* number of channels */
     115                 :          0 :         *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
     116                 :            :         /* maximum transmit power level */
     117                 :          0 :         *pos++ = start->max_tx_power;
     118                 :            : 
     119                 :          0 :         return pos;
     120                 :            : }
     121                 :            : 
     122                 :            : 
     123                 :       1338 : static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
     124                 :            :                                 int max_len)
     125                 :            : {
     126                 :       1338 :         u8 *pos = eid;
     127                 :       1338 :         u8 *end = eid + max_len;
     128                 :            :         int i;
     129                 :            :         struct hostapd_hw_modes *mode;
     130                 :            :         struct hostapd_channel_data *start, *prev;
     131                 :       1338 :         int chan_spacing = 1;
     132                 :            : 
     133 [ -  + ][ #  # ]:       1338 :         if (!hapd->iconf->ieee80211d || max_len < 6 ||
                 [ #  # ]
     134                 :          0 :             hapd->iface->current_mode == NULL)
     135                 :       1338 :                 return eid;
     136                 :            : 
     137                 :          0 :         *pos++ = WLAN_EID_COUNTRY;
     138                 :          0 :         pos++; /* length will be set later */
     139                 :          0 :         os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
     140                 :          0 :         pos += 3;
     141                 :            : 
     142                 :          0 :         mode = hapd->iface->current_mode;
     143         [ #  # ]:          0 :         if (mode->mode == HOSTAPD_MODE_IEEE80211A)
     144                 :          0 :                 chan_spacing = 4;
     145                 :            : 
     146                 :          0 :         start = prev = NULL;
     147         [ #  # ]:          0 :         for (i = 0; i < mode->num_channels; i++) {
     148                 :          0 :                 struct hostapd_channel_data *chan = &mode->channels[i];
     149         [ #  # ]:          0 :                 if (chan->flag & HOSTAPD_CHAN_DISABLED)
     150                 :          0 :                         continue;
     151 [ #  # ][ #  # ]:          0 :                 if (start && prev &&
                 [ #  # ]
     152         [ #  # ]:          0 :                     prev->chan + chan_spacing == chan->chan &&
     153                 :          0 :                     start->max_tx_power == chan->max_tx_power) {
     154                 :          0 :                         prev = chan;
     155                 :          0 :                         continue; /* can use same entry */
     156                 :            :                 }
     157                 :            : 
     158         [ #  # ]:          0 :                 if (start) {
     159                 :          0 :                         pos = hostapd_eid_country_add(pos, end, chan_spacing,
     160                 :            :                                                       start, prev);
     161                 :          0 :                         start = NULL;
     162                 :            :                 }
     163                 :            : 
     164                 :            :                 /* Start new group */
     165                 :          0 :                 start = prev = chan;
     166                 :            :         }
     167                 :            : 
     168         [ #  # ]:          0 :         if (start) {
     169                 :          0 :                 pos = hostapd_eid_country_add(pos, end, chan_spacing,
     170                 :            :                                               start, prev);
     171                 :            :         }
     172                 :            : 
     173         [ #  # ]:          0 :         if ((pos - eid) & 1) {
     174         [ #  # ]:          0 :                 if (end - pos < 1)
     175                 :          0 :                         return eid;
     176                 :          0 :                 *pos++ = 0; /* pad for 16-bit alignment */
     177                 :            :         }
     178                 :            : 
     179                 :          0 :         eid[1] = (pos - eid) - 2;
     180                 :            : 
     181                 :       1338 :         return pos;
     182                 :            : }
     183                 :            : 
     184                 :            : 
     185                 :       1338 : static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
     186                 :            : {
     187                 :            :         const u8 *ie;
     188                 :            :         size_t ielen;
     189                 :            : 
     190                 :       1338 :         ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
     191 [ +  + ][ -  + ]:       1338 :         if (ie == NULL || ielen > len)
     192                 :        488 :                 return eid;
     193                 :            : 
     194                 :        850 :         os_memcpy(eid, ie, ielen);
     195                 :       1338 :         return eid + ielen;
     196                 :            : }
     197                 :            : 
     198                 :            : 
     199                 :       1338 : static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
     200                 :            : {
     201                 :            :         u8 chan;
     202                 :            : 
     203         [ +  - ]:       1338 :         if (!hapd->iface->cs_freq_params.freq)
     204                 :       1338 :                 return eid;
     205                 :            : 
     206         [ #  # ]:          0 :         if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) ==
     207                 :            :             NUM_HOSTAPD_MODES)
     208                 :          0 :                 return eid;
     209                 :            : 
     210                 :          0 :         *eid++ = WLAN_EID_CHANNEL_SWITCH;
     211                 :          0 :         *eid++ = 3;
     212                 :          0 :         *eid++ = hapd->iface->cs_block_tx;
     213                 :          0 :         *eid++ = chan;
     214                 :          0 :         *eid++ = hapd->iface->cs_count;
     215                 :            : 
     216                 :       1338 :         return eid;
     217                 :            : }
     218                 :            : 
     219                 :            : 
     220                 :          0 : static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
     221                 :            : {
     222                 :            :         u8 sec_ch;
     223                 :            : 
     224         [ #  # ]:          0 :         if (!hapd->iface->cs_freq_params.sec_channel_offset)
     225                 :          0 :                 return eid;
     226                 :            : 
     227         [ #  # ]:          0 :         if (hapd->iface->cs_freq_params.sec_channel_offset == -1)
     228                 :          0 :                 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
     229         [ #  # ]:          0 :         else if (hapd->iface->cs_freq_params.sec_channel_offset == 1)
     230                 :          0 :                 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
     231                 :            :         else
     232                 :          0 :                 return eid;
     233                 :            : 
     234                 :          0 :         *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
     235                 :          0 :         *eid++ = 1;
     236                 :          0 :         *eid++ = sec_ch;
     237                 :            : 
     238                 :          0 :         return eid;
     239                 :            : }
     240                 :            : 
     241                 :            : 
     242                 :       1338 : static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
     243                 :            :                                   u8 *start, unsigned int *csa_counter_off)
     244                 :            : {
     245                 :       1338 :         u8 *old_pos = pos;
     246                 :            : 
     247         [ -  + ]:       1338 :         if (!csa_counter_off)
     248                 :          0 :                 return pos;
     249                 :            : 
     250                 :       1338 :         *csa_counter_off = 0;
     251                 :       1338 :         pos = hostapd_eid_csa(hapd, pos);
     252                 :            : 
     253         [ -  + ]:       1338 :         if (pos != old_pos) {
     254                 :            :                 /* save an offset to the counter - should be last byte */
     255                 :          0 :                 *csa_counter_off = pos - start - 1;
     256                 :          0 :                 pos = hostapd_eid_secondary_channel(hapd, pos);
     257                 :            :         }
     258                 :            : 
     259                 :       1338 :         return pos;
     260                 :            : }
     261                 :            : 
     262                 :            : 
     263                 :        680 : static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
     264                 :            :                                    struct sta_info *sta,
     265                 :            :                                    const struct ieee80211_mgmt *req,
     266                 :            :                                    int is_p2p, size_t *resp_len)
     267                 :            : {
     268                 :            :         struct ieee80211_mgmt *resp;
     269                 :            :         u8 *pos, *epos;
     270                 :            :         size_t buflen;
     271                 :            : 
     272                 :            : #define MAX_PROBERESP_LEN 768
     273                 :        680 :         buflen = MAX_PROBERESP_LEN;
     274                 :            : #ifdef CONFIG_WPS
     275         [ +  + ]:        680 :         if (hapd->wps_probe_resp_ie)
     276                 :         89 :                 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
     277                 :            : #endif /* CONFIG_WPS */
     278                 :            : #ifdef CONFIG_P2P
     279                 :            :         if (hapd->p2p_probe_resp_ie)
     280                 :            :                 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
     281                 :            : #endif /* CONFIG_P2P */
     282         [ -  + ]:        680 :         if (hapd->conf->vendor_elements)
     283                 :          0 :                 buflen += wpabuf_len(hapd->conf->vendor_elements);
     284                 :        680 :         resp = os_zalloc(buflen);
     285         [ -  + ]:        680 :         if (resp == NULL)
     286                 :          0 :                 return NULL;
     287                 :            : 
     288                 :        680 :         epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
     289                 :            : 
     290                 :        680 :         resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     291                 :            :                                            WLAN_FC_STYPE_PROBE_RESP);
     292         [ +  - ]:        680 :         if (req)
     293                 :        680 :                 os_memcpy(resp->da, req->sa, ETH_ALEN);
     294                 :        680 :         os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
     295                 :            : 
     296                 :        680 :         os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
     297                 :        680 :         resp->u.probe_resp.beacon_int =
     298                 :        680 :                 host_to_le16(hapd->iconf->beacon_int);
     299                 :            : 
     300                 :            :         /* hardware or low-level driver will setup seq_ctrl and timestamp */
     301                 :        680 :         resp->u.probe_resp.capab_info =
     302                 :        680 :                 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
     303                 :            : 
     304                 :        680 :         pos = resp->u.probe_resp.variable;
     305                 :        680 :         *pos++ = WLAN_EID_SSID;
     306                 :        680 :         *pos++ = hapd->conf->ssid.ssid_len;
     307                 :        680 :         os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
     308                 :        680 :         pos += hapd->conf->ssid.ssid_len;
     309                 :            : 
     310                 :            :         /* Supported rates */
     311                 :        680 :         pos = hostapd_eid_supp_rates(hapd, pos);
     312                 :            : 
     313                 :            :         /* DS Params */
     314                 :        680 :         pos = hostapd_eid_ds_params(hapd, pos);
     315                 :            : 
     316                 :        680 :         pos = hostapd_eid_country(hapd, pos, epos - pos);
     317                 :            : 
     318                 :            :         /* ERP Information element */
     319                 :        680 :         pos = hostapd_eid_erp_info(hapd, pos);
     320                 :            : 
     321                 :            :         /* Extended supported rates */
     322                 :        680 :         pos = hostapd_eid_ext_supp_rates(hapd, pos);
     323                 :            : 
     324                 :            :         /* RSN, MDIE, WPA */
     325                 :        680 :         pos = hostapd_eid_wpa(hapd, pos, epos - pos);
     326                 :            : 
     327                 :        680 :         pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
     328                 :            : 
     329                 :            : #ifdef CONFIG_IEEE80211N
     330                 :        680 :         pos = hostapd_eid_ht_capabilities(hapd, pos);
     331                 :        680 :         pos = hostapd_eid_ht_operation(hapd, pos);
     332                 :            : #endif /* CONFIG_IEEE80211N */
     333                 :            : 
     334                 :        680 :         pos = hostapd_eid_ext_capab(hapd, pos);
     335                 :            : 
     336                 :        680 :         pos = hostapd_eid_time_adv(hapd, pos);
     337                 :        680 :         pos = hostapd_eid_time_zone(hapd, pos);
     338                 :            : 
     339                 :        680 :         pos = hostapd_eid_interworking(hapd, pos);
     340                 :        680 :         pos = hostapd_eid_adv_proto(hapd, pos);
     341                 :        680 :         pos = hostapd_eid_roaming_consortium(hapd, pos);
     342                 :            : 
     343                 :        680 :         pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
     344                 :        680 :                                     &hapd->iface->cs_c_off_proberesp);
     345                 :            : #ifdef CONFIG_IEEE80211AC
     346                 :        680 :         pos = hostapd_eid_vht_capabilities(hapd, pos);
     347                 :        680 :         pos = hostapd_eid_vht_operation(hapd, pos);
     348                 :            : #endif /* CONFIG_IEEE80211AC */
     349                 :            : 
     350                 :            :         /* Wi-Fi Alliance WMM */
     351                 :        680 :         pos = hostapd_eid_wmm(hapd, pos);
     352                 :            : 
     353                 :            : #ifdef CONFIG_WPS
     354 [ +  + ][ +  - ]:        680 :         if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
     355                 :         89 :                 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
     356                 :            :                           wpabuf_len(hapd->wps_probe_resp_ie));
     357                 :         89 :                 pos += wpabuf_len(hapd->wps_probe_resp_ie);
     358                 :            :         }
     359                 :            : #endif /* CONFIG_WPS */
     360                 :            : 
     361                 :            : #ifdef CONFIG_P2P
     362                 :            :         if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
     363                 :            :             hapd->p2p_probe_resp_ie) {
     364                 :            :                 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
     365                 :            :                           wpabuf_len(hapd->p2p_probe_resp_ie));
     366                 :            :                 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
     367                 :            :         }
     368                 :            : #endif /* CONFIG_P2P */
     369                 :            : #ifdef CONFIG_P2P_MANAGER
     370         [ -  + ]:        680 :         if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
     371                 :            :             P2P_MANAGE)
     372                 :          0 :                 pos = hostapd_eid_p2p_manage(hapd, pos);
     373                 :            : #endif /* CONFIG_P2P_MANAGER */
     374                 :            : 
     375                 :            : #ifdef CONFIG_HS20
     376                 :        680 :         pos = hostapd_eid_hs20_indication(hapd, pos);
     377                 :            : #endif /* CONFIG_HS20 */
     378                 :            : 
     379         [ -  + ]:        680 :         if (hapd->conf->vendor_elements) {
     380                 :          0 :                 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
     381                 :            :                           wpabuf_len(hapd->conf->vendor_elements));
     382                 :          0 :                 pos += wpabuf_len(hapd->conf->vendor_elements);
     383                 :            :         }
     384                 :            : 
     385                 :        680 :         *resp_len = pos - (u8 *) resp;
     386                 :        680 :         return (u8 *) resp;
     387                 :            : }
     388                 :            : 
     389                 :            : 
     390                 :            : enum ssid_match_result {
     391                 :            :         NO_SSID_MATCH,
     392                 :            :         EXACT_SSID_MATCH,
     393                 :            :         WILDCARD_SSID_MATCH
     394                 :            : };
     395                 :            : 
     396                 :        757 : static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
     397                 :            :                                          const u8 *ssid, size_t ssid_len,
     398                 :            :                                          const u8 *ssid_list,
     399                 :            :                                          size_t ssid_list_len)
     400                 :            : {
     401                 :            :         const u8 *pos, *end;
     402                 :        757 :         int wildcard = 0;
     403                 :            : 
     404         [ +  + ]:        757 :         if (ssid_len == 0)
     405                 :        667 :                 wildcard = 1;
     406 [ +  + ][ +  + ]:        757 :         if (ssid_len == hapd->conf->ssid.ssid_len &&
     407                 :         30 :             os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
     408                 :         21 :                 return EXACT_SSID_MATCH;
     409                 :            : 
     410         [ +  - ]:        736 :         if (ssid_list == NULL)
     411         [ +  + ]:        736 :                 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
     412                 :            : 
     413                 :          0 :         pos = ssid_list;
     414                 :          0 :         end = ssid_list + ssid_list_len;
     415         [ #  # ]:          0 :         while (pos + 1 <= end) {
     416         [ #  # ]:          0 :                 if (pos + 2 + pos[1] > end)
     417                 :          0 :                         break;
     418         [ #  # ]:          0 :                 if (pos[1] == 0)
     419                 :          0 :                         wildcard = 1;
     420 [ #  # ][ #  # ]:          0 :                 if (pos[1] == hapd->conf->ssid.ssid_len &&
     421                 :          0 :                     os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
     422                 :          0 :                         return EXACT_SSID_MATCH;
     423                 :          0 :                 pos += 2 + pos[1];
     424                 :            :         }
     425                 :            : 
     426         [ #  # ]:        757 :         return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
     427                 :            : }
     428                 :            : 
     429                 :            : 
     430                 :        757 : void handle_probe_req(struct hostapd_data *hapd,
     431                 :            :                       const struct ieee80211_mgmt *mgmt, size_t len,
     432                 :            :                       int ssi_signal)
     433                 :            : {
     434                 :            :         u8 *resp;
     435                 :            :         struct ieee802_11_elems elems;
     436                 :            :         const u8 *ie;
     437                 :            :         size_t ie_len;
     438                 :        757 :         struct sta_info *sta = NULL;
     439                 :            :         size_t i, resp_len;
     440                 :            :         int noack;
     441                 :            :         enum ssid_match_result res;
     442                 :            : 
     443                 :        757 :         ie = mgmt->u.probe_req.variable;
     444         [ -  + ]:        757 :         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
     445                 :          0 :                 return;
     446                 :        757 :         ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
     447                 :            : 
     448 [ +  + ][ +  + ]:        846 :         for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
     449         [ -  + ]:         89 :                 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
     450                 :         89 :                                             mgmt->sa, mgmt->da, mgmt->bssid,
     451                 :            :                                             ie, ie_len, ssi_signal) > 0)
     452                 :          0 :                         return;
     453                 :            : 
     454         [ -  + ]:        757 :         if (!hapd->iconf->send_probe_response)
     455                 :          0 :                 return;
     456                 :            : 
     457         [ -  + ]:        757 :         if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
     458                 :          0 :                 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
     459                 :          0 :                            MAC2STR(mgmt->sa));
     460                 :          0 :                 return;
     461                 :            :         }
     462                 :            : 
     463 [ +  - ][ -  + ]:        757 :         if ((!elems.ssid || !elems.supp_rates)) {
     464                 :          0 :                 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
     465                 :            :                            "without SSID or supported rates element",
     466                 :          0 :                            MAC2STR(mgmt->sa));
     467                 :          0 :                 return;
     468                 :            :         }
     469                 :            : 
     470                 :            : #ifdef CONFIG_P2P
     471                 :            :         if (hapd->p2p && elems.wps_ie) {
     472                 :            :                 struct wpabuf *wps;
     473                 :            :                 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
     474                 :            :                 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
     475                 :            :                         wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
     476                 :            :                                    "due to mismatch with Requested Device "
     477                 :            :                                    "Type");
     478                 :            :                         wpabuf_free(wps);
     479                 :            :                         return;
     480                 :            :                 }
     481                 :            :                 wpabuf_free(wps);
     482                 :            :         }
     483                 :            : 
     484                 :            :         if (hapd->p2p && elems.p2p) {
     485                 :            :                 struct wpabuf *p2p;
     486                 :            :                 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
     487                 :            :                 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
     488                 :            :                         wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
     489                 :            :                                    "due to mismatch with Device ID");
     490                 :            :                         wpabuf_free(p2p);
     491                 :            :                         return;
     492                 :            :                 }
     493                 :            :                 wpabuf_free(p2p);
     494                 :            :         }
     495                 :            : #endif /* CONFIG_P2P */
     496                 :            : 
     497 [ -  + ][ #  # ]:        757 :         if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
                 [ #  # ]
     498                 :          0 :             elems.ssid_list_len == 0) {
     499                 :          0 :                 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
     500                 :          0 :                            "broadcast SSID ignored", MAC2STR(mgmt->sa));
     501                 :          0 :                 return;
     502                 :            :         }
     503                 :            : 
     504                 :        757 :         sta = ap_get_sta(hapd, mgmt->sa);
     505                 :            : 
     506                 :            : #ifdef CONFIG_P2P
     507                 :            :         if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
     508                 :            :             elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
     509                 :            :             os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
     510                 :            :                       P2P_WILDCARD_SSID_LEN) == 0) {
     511                 :            :                 /* Process P2P Wildcard SSID like Wildcard SSID */
     512                 :            :                 elems.ssid_len = 0;
     513                 :            :         }
     514                 :            : #endif /* CONFIG_P2P */
     515                 :            : 
     516                 :        757 :         res = ssid_match(hapd, elems.ssid, elems.ssid_len,
     517                 :        757 :                          elems.ssid_list, elems.ssid_list_len);
     518         [ +  + ]:        757 :         if (res != NO_SSID_MATCH) {
     519         [ +  + ]:        688 :                 if (sta)
     520                 :         39 :                         sta->ssid_probe = &hapd->conf->ssid;
     521                 :            :         } else {
     522         [ -  + ]:         69 :                 if (!(mgmt->da[0] & 0x01)) {
     523                 :            :                         char ssid_txt[33];
     524                 :          0 :                         ieee802_11_print_ssid(ssid_txt, elems.ssid,
     525                 :          0 :                                               elems.ssid_len);
     526         [ #  # ]:          0 :                         wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
     527                 :            :                                    " for foreign SSID '%s' (DA " MACSTR ")%s",
     528                 :          0 :                                    MAC2STR(mgmt->sa), ssid_txt,
     529                 :          0 :                                    MAC2STR(mgmt->da),
     530                 :          0 :                                    elems.ssid_list ? " (SSID list)" : "");
     531                 :            :                 }
     532                 :         69 :                 return;
     533                 :            :         }
     534                 :            : 
     535                 :            : #ifdef CONFIG_INTERWORKING
     536 [ +  + ][ +  - ]:        688 :         if (elems.interworking && elems.interworking_len >= 1) {
     537                 :         96 :                 u8 ant = elems.interworking[0] & 0x0f;
     538 [ +  + ][ +  + ]:         96 :                 if (ant != INTERWORKING_ANT_WILDCARD &&
     539                 :         10 :                     ant != hapd->conf->access_network_type) {
     540                 :          5 :                         wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
     541                 :            :                                    " for mismatching ANT %u ignored",
     542                 :         30 :                                    MAC2STR(mgmt->sa), ant);
     543                 :          5 :                         return;
     544                 :            :                 }
     545                 :            :         }
     546                 :            : 
     547 [ +  + ][ +  + ]:        683 :         if (elems.interworking &&
     548         [ -  + ]:         86 :             (elems.interworking_len == 7 || elems.interworking_len == 9)) {
     549                 :            :                 const u8 *hessid;
     550         [ +  - ]:          5 :                 if (elems.interworking_len == 7)
     551                 :          5 :                         hessid = elems.interworking + 1;
     552                 :            :                 else
     553                 :          0 :                         hessid = elems.interworking + 1 + 2;
     554 [ +  - ][ +  + ]:          5 :                 if (!is_broadcast_ether_addr(hessid) &&
     555                 :          5 :                     os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
     556                 :          3 :                         wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
     557                 :            :                                    " for mismatching HESSID " MACSTR
     558                 :            :                                    " ignored",
     559                 :         36 :                                    MAC2STR(mgmt->sa), MAC2STR(hessid));
     560                 :          3 :                         return;
     561                 :            :                 }
     562                 :            :         }
     563                 :            : #endif /* CONFIG_INTERWORKING */
     564                 :            : 
     565                 :            : #ifdef CONFIG_P2P
     566                 :            :         if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
     567                 :            :             supp_rates_11b_only(&elems)) {
     568                 :            :                 /* Indicates support for 11b rates only */
     569                 :            :                 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
     570                 :            :                            MACSTR " with only 802.11b rates",
     571                 :            :                            MAC2STR(mgmt->sa));
     572                 :            :                 return;
     573                 :            :         }
     574                 :            : #endif /* CONFIG_P2P */
     575                 :            : 
     576                 :            :         /* TODO: verify that supp_rates contains at least one matching rate
     577                 :            :          * with AP configuration */
     578                 :            : 
     579                 :            : #ifdef CONFIG_TESTING_OPTIONS
     580   [ -  +  #  # ]:        680 :         if (hapd->iconf->ignore_probe_probability > 0.0d &&
     581                 :          0 :             drand48() < hapd->iconf->ignore_probe_probability) {
     582                 :          0 :                 wpa_printf(MSG_INFO,
     583                 :            :                            "TESTING: ignoring probe request from " MACSTR,
     584                 :          0 :                            MAC2STR(mgmt->sa));
     585                 :          0 :                 return;
     586                 :            :         }
     587                 :            : #endif /* CONFIG_TESTING_OPTIONS */
     588                 :            : 
     589                 :        680 :         resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
     590                 :            :                                       &resp_len);
     591         [ -  + ]:        680 :         if (resp == NULL)
     592                 :          0 :                 return;
     593                 :            : 
     594                 :            :         /*
     595                 :            :          * If this is a broadcast probe request, apply no ack policy to avoid
     596                 :            :          * excessive retries.
     597                 :            :          */
     598   [ +  +  +  - ]:       1339 :         noack = !!(res == WILDCARD_SSID_MATCH &&
     599                 :        659 :                    is_broadcast_ether_addr(mgmt->da));
     600                 :            : 
     601         [ +  + ]:        680 :         if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
     602                 :          3 :                 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
     603                 :            : 
     604                 :        680 :         os_free(resp);
     605                 :            : 
     606         [ +  + ]:        757 :         wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
     607                 :       4080 :                    "SSID", MAC2STR(mgmt->sa),
     608                 :        680 :                    elems.ssid_len == 0 ? "broadcast" : "our");
     609                 :            : }
     610                 :            : 
     611                 :            : 
     612                 :        658 : static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
     613                 :            :                                         size_t *resp_len)
     614                 :            : {
     615                 :            :         /* check probe response offloading caps and print warnings */
     616         [ +  - ]:        658 :         if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
     617                 :        658 :                 return NULL;
     618                 :            : 
     619                 :            : #ifdef CONFIG_WPS
     620 [ #  # ][ #  # ]:          0 :         if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
                 [ #  # ]
     621                 :          0 :             (!(hapd->iface->probe_resp_offloads &
     622                 :            :                (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
     623                 :            :                 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
     624                 :          0 :                 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
     625                 :            :                            "Probe Response while not supporting this");
     626                 :            : #endif /* CONFIG_WPS */
     627                 :            : 
     628                 :            : #ifdef CONFIG_P2P
     629                 :            :         if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
     630                 :            :             !(hapd->iface->probe_resp_offloads &
     631                 :            :               WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
     632                 :            :                 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
     633                 :            :                            "Probe Response while not supporting this");
     634                 :            : #endif  /* CONFIG_P2P */
     635                 :            : 
     636 [ #  # ][ #  # ]:          0 :         if (hapd->conf->interworking &&
     637                 :          0 :             !(hapd->iface->probe_resp_offloads &
     638                 :            :               WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
     639                 :          0 :                 wpa_printf(MSG_WARNING, "Device is trying to offload "
     640                 :            :                            "Interworking Probe Response while not supporting "
     641                 :            :                            "this");
     642                 :            : 
     643                 :            :         /* Generate a Probe Response template for the non-P2P case */
     644                 :        658 :         return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
     645                 :            : }
     646                 :            : 
     647                 :            : #endif /* NEED_AP_MLME */
     648                 :            : 
     649                 :            : 
     650                 :        658 : int ieee802_11_build_ap_params(struct hostapd_data *hapd,
     651                 :            :                                struct wpa_driver_ap_params *params)
     652                 :            : {
     653                 :        658 :         struct ieee80211_mgmt *head = NULL;
     654                 :        658 :         u8 *tail = NULL;
     655                 :        658 :         size_t head_len = 0, tail_len = 0;
     656                 :        658 :         u8 *resp = NULL;
     657                 :        658 :         size_t resp_len = 0;
     658                 :            : #ifdef NEED_AP_MLME
     659                 :            :         u16 capab_info;
     660                 :            :         u8 *pos, *tailpos;
     661                 :            : 
     662                 :            : #define BEACON_HEAD_BUF_SIZE 256
     663                 :            : #define BEACON_TAIL_BUF_SIZE 512
     664                 :        658 :         head = os_zalloc(BEACON_HEAD_BUF_SIZE);
     665                 :        658 :         tail_len = BEACON_TAIL_BUF_SIZE;
     666                 :            : #ifdef CONFIG_WPS
     667 [ +  + ][ +  - ]:        658 :         if (hapd->conf->wps_state && hapd->wps_beacon_ie)
     668                 :        206 :                 tail_len += wpabuf_len(hapd->wps_beacon_ie);
     669                 :            : #endif /* CONFIG_WPS */
     670                 :            : #ifdef CONFIG_P2P
     671                 :            :         if (hapd->p2p_beacon_ie)
     672                 :            :                 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
     673                 :            : #endif /* CONFIG_P2P */
     674         [ -  + ]:        658 :         if (hapd->conf->vendor_elements)
     675                 :          0 :                 tail_len += wpabuf_len(hapd->conf->vendor_elements);
     676                 :        658 :         tailpos = tail = os_malloc(tail_len);
     677 [ +  - ][ -  + ]:        658 :         if (head == NULL || tail == NULL) {
     678                 :          0 :                 wpa_printf(MSG_ERROR, "Failed to set beacon data");
     679                 :          0 :                 os_free(head);
     680                 :          0 :                 os_free(tail);
     681                 :          0 :                 return -1;
     682                 :            :         }
     683                 :            : 
     684                 :        658 :         head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     685                 :            :                                            WLAN_FC_STYPE_BEACON);
     686                 :        658 :         head->duration = host_to_le16(0);
     687                 :        658 :         os_memset(head->da, 0xff, ETH_ALEN);
     688                 :            : 
     689                 :        658 :         os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
     690                 :        658 :         os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
     691                 :        658 :         head->u.beacon.beacon_int =
     692                 :        658 :                 host_to_le16(hapd->iconf->beacon_int);
     693                 :            : 
     694                 :            :         /* hardware or low-level driver will setup seq_ctrl and timestamp */
     695                 :        658 :         capab_info = hostapd_own_capab_info(hapd, NULL, 0);
     696                 :        658 :         head->u.beacon.capab_info = host_to_le16(capab_info);
     697                 :        658 :         pos = &head->u.beacon.variable[0];
     698                 :            : 
     699                 :            :         /* SSID */
     700                 :        658 :         *pos++ = WLAN_EID_SSID;
     701         [ -  + ]:        658 :         if (hapd->conf->ignore_broadcast_ssid == 2) {
     702                 :            :                 /* clear the data, but keep the correct length of the SSID */
     703                 :          0 :                 *pos++ = hapd->conf->ssid.ssid_len;
     704                 :          0 :                 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
     705                 :          0 :                 pos += hapd->conf->ssid.ssid_len;
     706         [ -  + ]:        658 :         } else if (hapd->conf->ignore_broadcast_ssid) {
     707                 :          0 :                 *pos++ = 0; /* empty SSID */
     708                 :            :         } else {
     709                 :        658 :                 *pos++ = hapd->conf->ssid.ssid_len;
     710                 :        658 :                 os_memcpy(pos, hapd->conf->ssid.ssid,
     711                 :            :                           hapd->conf->ssid.ssid_len);
     712                 :        658 :                 pos += hapd->conf->ssid.ssid_len;
     713                 :            :         }
     714                 :            : 
     715                 :            :         /* Supported rates */
     716                 :        658 :         pos = hostapd_eid_supp_rates(hapd, pos);
     717                 :            : 
     718                 :            :         /* DS Params */
     719                 :        658 :         pos = hostapd_eid_ds_params(hapd, pos);
     720                 :            : 
     721                 :        658 :         head_len = pos - (u8 *) head;
     722                 :            : 
     723                 :        658 :         tailpos = hostapd_eid_country(hapd, tailpos,
     724                 :        658 :                                       tail + BEACON_TAIL_BUF_SIZE - tailpos);
     725                 :            : 
     726                 :            :         /* ERP Information element */
     727                 :        658 :         tailpos = hostapd_eid_erp_info(hapd, tailpos);
     728                 :            : 
     729                 :            :         /* Extended supported rates */
     730                 :        658 :         tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
     731                 :            : 
     732                 :            :         /* RSN, MDIE, WPA */
     733                 :        658 :         tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
     734                 :            :                                   tailpos);
     735                 :            : 
     736                 :        658 :         tailpos = hostapd_eid_bss_load(hapd, tailpos,
     737                 :        658 :                                        tail + BEACON_TAIL_BUF_SIZE - tailpos);
     738                 :            : 
     739                 :            : #ifdef CONFIG_IEEE80211N
     740                 :        658 :         tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
     741                 :        658 :         tailpos = hostapd_eid_ht_operation(hapd, tailpos);
     742                 :            : #endif /* CONFIG_IEEE80211N */
     743                 :            : 
     744                 :        658 :         tailpos = hostapd_eid_ext_capab(hapd, tailpos);
     745                 :            : 
     746                 :            :         /*
     747                 :            :          * TODO: Time Advertisement element should only be included in some
     748                 :            :          * DTIM Beacon frames.
     749                 :            :          */
     750                 :        658 :         tailpos = hostapd_eid_time_adv(hapd, tailpos);
     751                 :            : 
     752                 :        658 :         tailpos = hostapd_eid_interworking(hapd, tailpos);
     753                 :        658 :         tailpos = hostapd_eid_adv_proto(hapd, tailpos);
     754                 :        658 :         tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
     755                 :        658 :         tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
     756                 :        658 :                                         &hapd->iface->cs_c_off_beacon);
     757                 :            : #ifdef CONFIG_IEEE80211AC
     758                 :        658 :         tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
     759                 :        658 :         tailpos = hostapd_eid_vht_operation(hapd, tailpos);
     760                 :            : #endif /* CONFIG_IEEE80211AC */
     761                 :            : 
     762                 :            :         /* Wi-Fi Alliance WMM */
     763                 :        658 :         tailpos = hostapd_eid_wmm(hapd, tailpos);
     764                 :            : 
     765                 :            : #ifdef CONFIG_WPS
     766 [ +  + ][ +  - ]:        658 :         if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
     767                 :        206 :                 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
     768                 :            :                           wpabuf_len(hapd->wps_beacon_ie));
     769                 :        206 :                 tailpos += wpabuf_len(hapd->wps_beacon_ie);
     770                 :            :         }
     771                 :            : #endif /* CONFIG_WPS */
     772                 :            : 
     773                 :            : #ifdef CONFIG_P2P
     774                 :            :         if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
     775                 :            :                 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
     776                 :            :                           wpabuf_len(hapd->p2p_beacon_ie));
     777                 :            :                 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
     778                 :            :         }
     779                 :            : #endif /* CONFIG_P2P */
     780                 :            : #ifdef CONFIG_P2P_MANAGER
     781         [ -  + ]:        658 :         if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
     782                 :            :             P2P_MANAGE)
     783                 :          0 :                 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
     784                 :            : #endif /* CONFIG_P2P_MANAGER */
     785                 :            : 
     786                 :            : #ifdef CONFIG_HS20
     787                 :        658 :         tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
     788                 :            : #endif /* CONFIG_HS20 */
     789                 :            : 
     790         [ -  + ]:        658 :         if (hapd->conf->vendor_elements) {
     791                 :          0 :                 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
     792                 :            :                           wpabuf_len(hapd->conf->vendor_elements));
     793                 :          0 :                 tailpos += wpabuf_len(hapd->conf->vendor_elements);
     794                 :            :         }
     795                 :            : 
     796         [ +  - ]:        658 :         tail_len = tailpos > tail ? tailpos - tail : 0;
     797                 :            : 
     798                 :        658 :         resp = hostapd_probe_resp_offloads(hapd, &resp_len);
     799                 :            : #endif /* NEED_AP_MLME */
     800                 :            : 
     801                 :        658 :         os_memset(params, 0, sizeof(*params));
     802                 :        658 :         params->head = (u8 *) head;
     803                 :        658 :         params->head_len = head_len;
     804                 :        658 :         params->tail = tail;
     805                 :        658 :         params->tail_len = tail_len;
     806                 :        658 :         params->proberesp = resp;
     807                 :        658 :         params->proberesp_len = resp_len;
     808                 :        658 :         params->dtim_period = hapd->conf->dtim_period;
     809                 :        658 :         params->beacon_int = hapd->iconf->beacon_int;
     810                 :        658 :         params->basic_rates = hapd->iface->basic_rates;
     811                 :        658 :         params->ssid = hapd->conf->ssid.ssid;
     812                 :        658 :         params->ssid_len = hapd->conf->ssid.ssid_len;
     813         [ +  - ]:        658 :         params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
     814                 :        658 :                 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
     815                 :        658 :         params->group_cipher = hapd->conf->wpa_group;
     816                 :        658 :         params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
     817                 :        658 :         params->auth_algs = hapd->conf->auth_algs;
     818                 :        658 :         params->wpa_version = hapd->conf->wpa;
     819 [ +  + ][ +  + ]:        658 :         params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
                 [ -  + ]
     820         [ #  # ]:          0 :                 (hapd->conf->ieee802_1x &&
     821         [ #  # ]:          0 :                  (hapd->conf->default_wep_key_len ||
     822                 :          0 :                   hapd->conf->individual_wep_key_len));
     823   [ +  -  -  - ]:        658 :         switch (hapd->conf->ignore_broadcast_ssid) {
     824                 :            :         case 0:
     825                 :        658 :                 params->hide_ssid = NO_SSID_HIDING;
     826                 :        658 :                 break;
     827                 :            :         case 1:
     828                 :          0 :                 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
     829                 :          0 :                 break;
     830                 :            :         case 2:
     831                 :          0 :                 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
     832                 :          0 :                 break;
     833                 :            :         }
     834                 :        658 :         params->isolate = hapd->conf->isolate;
     835                 :            : #ifdef NEED_AP_MLME
     836                 :        658 :         params->cts_protect = !!(ieee802_11_erp_info(hapd) &
     837                 :            :                                 ERP_INFO_USE_PROTECTION);
     838 [ +  - ][ -  + ]:        658 :         params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
     839                 :        658 :                 hapd->iconf->preamble == SHORT_PREAMBLE;
     840 [ +  - ][ +  - ]:        658 :         if (hapd->iface->current_mode &&
     841                 :        658 :             hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
     842                 :        658 :                 params->short_slot_time =
     843                 :        658 :                         hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
     844                 :            :         else
     845                 :          0 :                 params->short_slot_time = -1;
     846 [ +  - ][ +  + ]:        658 :         if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
     847                 :        552 :                 params->ht_opmode = -1;
     848                 :            :         else
     849                 :        106 :                 params->ht_opmode = hapd->iface->ht_op_mode;
     850                 :            : #endif /* NEED_AP_MLME */
     851                 :        658 :         params->interworking = hapd->conf->interworking;
     852   [ +  +  +  + ]:        765 :         if (hapd->conf->interworking &&
     853                 :        107 :             !is_zero_ether_addr(hapd->conf->hessid))
     854                 :         67 :                 params->hessid = hapd->conf->hessid;
     855                 :        658 :         params->access_network_type = hapd->conf->access_network_type;
     856                 :        658 :         params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
     857                 :            : #ifdef CONFIG_HS20
     858                 :        658 :         params->disable_dgaf = hapd->conf->disable_dgaf;
     859                 :            : #endif /* CONFIG_HS20 */
     860                 :        658 :         return 0;
     861                 :            : }
     862                 :            : 
     863                 :            : 
     864                 :        658 : void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
     865                 :            : {
     866                 :        658 :         os_free(params->tail);
     867                 :        658 :         params->tail = NULL;
     868                 :        658 :         os_free(params->head);
     869                 :        658 :         params->head = NULL;
     870                 :        658 :         os_free(params->proberesp);
     871                 :        658 :         params->proberesp = NULL;
     872                 :        658 : }
     873                 :            : 
     874                 :            : 
     875                 :        658 : int ieee802_11_set_beacon(struct hostapd_data *hapd)
     876                 :            : {
     877                 :            :         struct wpa_driver_ap_params params;
     878                 :            :         struct wpabuf *beacon, *proberesp, *assocresp;
     879                 :        658 :         int res, ret = -1;
     880                 :            : 
     881         [ -  + ]:        658 :         if (hapd->iface->csa_in_progress) {
     882                 :          0 :                 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
     883                 :          0 :                 return -1;
     884                 :            :         }
     885                 :            : 
     886                 :        658 :         hapd->beacon_set_done = 1;
     887                 :            : 
     888         [ -  + ]:        658 :         if (ieee802_11_build_ap_params(hapd, &params) < 0)
     889                 :          0 :                 return -1;
     890                 :            : 
     891         [ -  + ]:        658 :         if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
     892                 :            :             0)
     893                 :          0 :                 goto fail;
     894                 :            : 
     895                 :        658 :         params.beacon_ies = beacon;
     896                 :        658 :         params.proberesp_ies = proberesp;
     897                 :        658 :         params.assocresp_ies = assocresp;
     898                 :            : 
     899                 :        658 :         res = hostapd_drv_set_ap(hapd, &params);
     900                 :        658 :         hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
     901         [ -  + ]:        658 :         if (res)
     902                 :          0 :                 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
     903                 :            :         else
     904                 :        658 :                 ret = 0;
     905                 :            : fail:
     906                 :        658 :         ieee802_11_free_ap_params(&params);
     907                 :        658 :         return ret;
     908                 :            : }
     909                 :            : 
     910                 :            : 
     911                 :        328 : int ieee802_11_set_beacons(struct hostapd_iface *iface)
     912                 :            : {
     913                 :            :         size_t i;
     914                 :        328 :         int ret = 0;
     915                 :            : 
     916         [ +  + ]:        660 :         for (i = 0; i < iface->num_bss; i++) {
     917   [ +  -  -  + ]:        664 :                 if (iface->bss[i]->started &&
     918                 :        332 :                     ieee802_11_set_beacon(iface->bss[i]) < 0)
     919                 :          0 :                         ret = -1;
     920                 :            :         }
     921                 :            : 
     922                 :        328 :         return ret;
     923                 :            : }
     924                 :            : 
     925                 :            : 
     926                 :            : /* only update beacons if started */
     927                 :         34 : int ieee802_11_update_beacons(struct hostapd_iface *iface)
     928                 :            : {
     929                 :            :         size_t i;
     930                 :         34 :         int ret = 0;
     931                 :            : 
     932         [ +  + ]:         68 :         for (i = 0; i < iface->num_bss; i++) {
     933         [ +  - ]:         68 :                 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
           [ +  -  -  + ]
     934                 :         34 :                     ieee802_11_set_beacon(iface->bss[i]) < 0)
     935                 :          0 :                         ret = -1;
     936                 :            :         }
     937                 :            : 
     938                 :         34 :         return ret;
     939                 :            : }
     940                 :            : 
     941                 :            : #endif /* CONFIG_NATIVE_WINDOWS */

Generated by: LCOV version 1.9