LCOV - code coverage report
Current view: top level - src/ap - ap_drv_ops.c (source / functions) Hit Total Coverage
Test: hostapd hwsim test run 1388338050 Lines: 216 368 58.7 %
Date: 2013-12-29 Functions: 33 45 73.3 %
Branches: 102 275 37.1 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * hostapd - Driver operations
       3                 :            :  * Copyright (c) 2009-2010, 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 "utils/includes.h"
      10                 :            : 
      11                 :            : #include "utils/common.h"
      12                 :            : #include "common/ieee802_11_defs.h"
      13                 :            : #include "wps/wps.h"
      14                 :            : #include "p2p/p2p.h"
      15                 :            : #include "hostapd.h"
      16                 :            : #include "ieee802_11.h"
      17                 :            : #include "sta_info.h"
      18                 :            : #include "ap_config.h"
      19                 :            : #include "p2p_hostapd.h"
      20                 :            : #include "hs20.h"
      21                 :            : #include "ap_drv_ops.h"
      22                 :            : 
      23                 :            : 
      24                 :       2265 : u32 hostapd_sta_flags_to_drv(u32 flags)
      25                 :            : {
      26                 :       2265 :         int res = 0;
      27         [ +  + ]:       2265 :         if (flags & WLAN_STA_AUTHORIZED)
      28                 :        565 :                 res |= WPA_STA_AUTHORIZED;
      29         [ +  - ]:       2265 :         if (flags & WLAN_STA_WMM)
      30                 :       2265 :                 res |= WPA_STA_WMM;
      31         [ +  - ]:       2265 :         if (flags & WLAN_STA_SHORT_PREAMBLE)
      32                 :       2265 :                 res |= WPA_STA_SHORT_PREAMBLE;
      33         [ +  + ]:       2265 :         if (flags & WLAN_STA_MFP)
      34                 :         95 :                 res |= WPA_STA_MFP;
      35                 :       2265 :         return res;
      36                 :            : }
      37                 :            : 
      38                 :            : 
      39                 :        658 : int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
      40                 :            :                                struct wpabuf **beacon_ret,
      41                 :            :                                struct wpabuf **proberesp_ret,
      42                 :            :                                struct wpabuf **assocresp_ret)
      43                 :            : {
      44                 :        658 :         struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
      45                 :            :         u8 buf[200], *pos;
      46                 :            : 
      47                 :        658 :         *beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
      48                 :            : 
      49                 :        658 :         pos = buf;
      50                 :        658 :         pos = hostapd_eid_time_adv(hapd, pos);
      51         [ +  + ]:        658 :         if (pos != buf) {
      52         [ -  + ]:         10 :                 if (wpabuf_resize(&beacon, pos - buf) != 0)
      53                 :          0 :                         goto fail;
      54                 :         10 :                 wpabuf_put_data(beacon, buf, pos - buf);
      55                 :            :         }
      56                 :        658 :         pos = hostapd_eid_time_zone(hapd, pos);
      57         [ +  + ]:        658 :         if (pos != buf) {
      58         [ -  + ]:         10 :                 if (wpabuf_resize(&proberesp, pos - buf) != 0)
      59                 :          0 :                         goto fail;
      60                 :         10 :                 wpabuf_put_data(proberesp, buf, pos - buf);
      61                 :            :         }
      62                 :            : 
      63                 :        658 :         pos = buf;
      64                 :        658 :         pos = hostapd_eid_ext_capab(hapd, pos);
      65         [ +  - ]:        658 :         if (pos != buf) {
      66         [ -  + ]:        658 :                 if (wpabuf_resize(&assocresp, pos - buf) != 0)
      67                 :          0 :                         goto fail;
      68                 :        658 :                 wpabuf_put_data(assocresp, buf, pos - buf);
      69                 :            :         }
      70                 :        658 :         pos = hostapd_eid_interworking(hapd, pos);
      71                 :        658 :         pos = hostapd_eid_adv_proto(hapd, pos);
      72                 :        658 :         pos = hostapd_eid_roaming_consortium(hapd, pos);
      73         [ +  - ]:        658 :         if (pos != buf) {
      74         [ -  + ]:        658 :                 if (wpabuf_resize(&beacon, pos - buf) != 0)
      75                 :          0 :                         goto fail;
      76                 :        658 :                 wpabuf_put_data(beacon, buf, pos - buf);
      77                 :            : 
      78         [ -  + ]:        658 :                 if (wpabuf_resize(&proberesp, pos - buf) != 0)
      79                 :          0 :                         goto fail;
      80                 :        658 :                 wpabuf_put_data(proberesp, buf, pos - buf);
      81                 :            :         }
      82                 :            : 
      83         [ +  + ]:        658 :         if (hapd->wps_beacon_ie) {
      84         [ -  + ]:        206 :                 if (wpabuf_resize(&beacon, wpabuf_len(hapd->wps_beacon_ie)) <
      85                 :            :                     0)
      86                 :          0 :                         goto fail;
      87                 :        206 :                 wpabuf_put_buf(beacon, hapd->wps_beacon_ie);
      88                 :            :         }
      89                 :            : 
      90         [ +  + ]:        658 :         if (hapd->wps_probe_resp_ie) {
      91         [ -  + ]:        206 :                 if (wpabuf_resize(&proberesp,
      92                 :        206 :                                   wpabuf_len(hapd->wps_probe_resp_ie)) < 0)
      93                 :          0 :                         goto fail;
      94                 :        206 :                 wpabuf_put_buf(proberesp, hapd->wps_probe_resp_ie);
      95                 :            :         }
      96                 :            : 
      97                 :            : #ifdef CONFIG_P2P
      98                 :            :         if (hapd->p2p_beacon_ie) {
      99                 :            :                 if (wpabuf_resize(&beacon, wpabuf_len(hapd->p2p_beacon_ie)) <
     100                 :            :                     0)
     101                 :            :                         goto fail;
     102                 :            :                 wpabuf_put_buf(beacon, hapd->p2p_beacon_ie);
     103                 :            :         }
     104                 :            : 
     105                 :            :         if (hapd->p2p_probe_resp_ie) {
     106                 :            :                 if (wpabuf_resize(&proberesp,
     107                 :            :                                   wpabuf_len(hapd->p2p_probe_resp_ie)) < 0)
     108                 :            :                         goto fail;
     109                 :            :                 wpabuf_put_buf(proberesp, hapd->p2p_probe_resp_ie);
     110                 :            :         }
     111                 :            : #endif /* CONFIG_P2P */
     112                 :            : 
     113                 :            : #ifdef CONFIG_P2P_MANAGER
     114         [ -  + ]:        658 :         if (hapd->conf->p2p & P2P_MANAGE) {
     115         [ #  # ]:          0 :                 if (wpabuf_resize(&beacon, 100) == 0) {
     116                 :            :                         u8 *start, *p;
     117                 :          0 :                         start = wpabuf_put(beacon, 0);
     118                 :          0 :                         p = hostapd_eid_p2p_manage(hapd, start);
     119                 :          0 :                         wpabuf_put(beacon, p - start);
     120                 :            :                 }
     121                 :            : 
     122         [ #  # ]:          0 :                 if (wpabuf_resize(&proberesp, 100) == 0) {
     123                 :            :                         u8 *start, *p;
     124                 :          0 :                         start = wpabuf_put(proberesp, 0);
     125                 :          0 :                         p = hostapd_eid_p2p_manage(hapd, start);
     126                 :          0 :                         wpabuf_put(proberesp, p - start);
     127                 :            :                 }
     128                 :            :         }
     129                 :            : #endif /* CONFIG_P2P_MANAGER */
     130                 :            : 
     131                 :            : #ifdef CONFIG_WPS2
     132         [ +  + ]:        658 :         if (hapd->conf->wps_state) {
     133                 :        206 :                 struct wpabuf *a = wps_build_assoc_resp_ie();
     134 [ +  - ][ +  - ]:        206 :                 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
     135                 :        206 :                         wpabuf_put_buf(assocresp, a);
     136                 :        206 :                 wpabuf_free(a);
     137                 :            :         }
     138                 :            : #endif /* CONFIG_WPS2 */
     139                 :            : 
     140                 :            : #ifdef CONFIG_P2P_MANAGER
     141         [ -  + ]:        658 :         if (hapd->conf->p2p & P2P_MANAGE) {
     142         [ #  # ]:          0 :                 if (wpabuf_resize(&assocresp, 100) == 0) {
     143                 :            :                         u8 *start, *p;
     144                 :          0 :                         start = wpabuf_put(assocresp, 0);
     145                 :          0 :                         p = hostapd_eid_p2p_manage(hapd, start);
     146                 :          0 :                         wpabuf_put(assocresp, p - start);
     147                 :            :                 }
     148                 :            :         }
     149                 :            : #endif /* CONFIG_P2P_MANAGER */
     150                 :            : 
     151                 :            : #ifdef CONFIG_WIFI_DISPLAY
     152                 :            :         if (hapd->p2p_group) {
     153                 :            :                 struct wpabuf *a;
     154                 :            :                 a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
     155                 :            :                 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
     156                 :            :                         wpabuf_put_buf(assocresp, a);
     157                 :            :                 wpabuf_free(a);
     158                 :            :         }
     159                 :            : #endif /* CONFIG_WIFI_DISPLAY */
     160                 :            : 
     161                 :            : #ifdef CONFIG_HS20
     162                 :        658 :         pos = buf;
     163                 :        658 :         pos = hostapd_eid_hs20_indication(hapd, pos);
     164         [ +  + ]:        658 :         if (pos != buf) {
     165         [ -  + ]:        107 :                 if (wpabuf_resize(&beacon, pos - buf) != 0)
     166                 :          0 :                         goto fail;
     167                 :        107 :                 wpabuf_put_data(beacon, buf, pos - buf);
     168                 :            : 
     169         [ -  + ]:        107 :                 if (wpabuf_resize(&proberesp, pos - buf) != 0)
     170                 :          0 :                         goto fail;
     171                 :        107 :                 wpabuf_put_data(proberesp, buf, pos - buf);
     172                 :            :         }
     173                 :            : #endif /* CONFIG_HS20 */
     174                 :            : 
     175         [ -  + ]:        658 :         if (hapd->conf->vendor_elements) {
     176                 :          0 :                 size_t add = wpabuf_len(hapd->conf->vendor_elements);
     177         [ #  # ]:          0 :                 if (wpabuf_resize(&beacon, add) == 0)
     178                 :          0 :                         wpabuf_put_buf(beacon, hapd->conf->vendor_elements);
     179         [ #  # ]:          0 :                 if (wpabuf_resize(&proberesp, add) == 0)
     180                 :          0 :                         wpabuf_put_buf(proberesp, hapd->conf->vendor_elements);
     181                 :            :         }
     182                 :            : 
     183                 :        658 :         *beacon_ret = beacon;
     184                 :        658 :         *proberesp_ret = proberesp;
     185                 :        658 :         *assocresp_ret = assocresp;
     186                 :            : 
     187                 :        658 :         return 0;
     188                 :            : 
     189                 :            : fail:
     190                 :          0 :         wpabuf_free(beacon);
     191                 :          0 :         wpabuf_free(proberesp);
     192                 :          0 :         wpabuf_free(assocresp);
     193                 :        658 :         return -1;
     194                 :            : }
     195                 :            : 
     196                 :            : 
     197                 :        658 : void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
     198                 :            :                                struct wpabuf *beacon,
     199                 :            :                                struct wpabuf *proberesp,
     200                 :            :                                struct wpabuf *assocresp)
     201                 :            : {
     202                 :        658 :         wpabuf_free(beacon);
     203                 :        658 :         wpabuf_free(proberesp);
     204                 :        658 :         wpabuf_free(assocresp);
     205                 :        658 : }
     206                 :            : 
     207                 :            : 
     208                 :        311 : int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
     209                 :            : {
     210                 :            :         struct wpabuf *beacon, *proberesp, *assocresp;
     211                 :            :         int ret;
     212                 :            : 
     213 [ +  - ][ +  - ]:        311 :         if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
     214                 :        311 :                 return 0;
     215                 :            : 
     216         [ #  # ]:          0 :         if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
     217                 :            :             0)
     218                 :          0 :                 return -1;
     219                 :            : 
     220                 :          0 :         ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
     221                 :            :                                           assocresp);
     222                 :            : 
     223                 :          0 :         hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
     224                 :            : 
     225                 :        311 :         return ret;
     226                 :            : }
     227                 :            : 
     228                 :            : 
     229                 :        520 : int hostapd_set_authorized(struct hostapd_data *hapd,
     230                 :            :                            struct sta_info *sta, int authorized)
     231                 :            : {
     232         [ +  + ]:        520 :         if (authorized) {
     233                 :        187 :                 return hostapd_sta_set_flags(hapd, sta->addr,
     234                 :        187 :                                              hostapd_sta_flags_to_drv(
     235                 :            :                                                      sta->flags),
     236                 :            :                                              WPA_STA_AUTHORIZED, ~0);
     237                 :            :         }
     238                 :            : 
     239                 :        520 :         return hostapd_sta_set_flags(hapd, sta->addr,
     240                 :        333 :                                      hostapd_sta_flags_to_drv(sta->flags),
     241                 :            :                                      0, ~WPA_STA_AUTHORIZED);
     242                 :            : }
     243                 :            : 
     244                 :            : 
     245                 :        291 : int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
     246                 :            : {
     247                 :            :         int set_flags, total_flags, flags_and, flags_or;
     248                 :        291 :         total_flags = hostapd_sta_flags_to_drv(sta->flags);
     249                 :        291 :         set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
     250 [ +  + ][ +  + ]:        291 :         if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
                 [ +  + ]
     251         [ +  - ]:         95 :              sta->auth_alg == WLAN_AUTH_FT) &&
     252                 :         95 :             sta->flags & WLAN_STA_AUTHORIZED)
     253                 :         95 :                 set_flags |= WPA_STA_AUTHORIZED;
     254                 :        291 :         flags_or = total_flags & set_flags;
     255                 :        291 :         flags_and = total_flags | ~set_flags;
     256                 :        291 :         return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
     257                 :            :                                      flags_or, flags_and);
     258                 :            : }
     259                 :            : 
     260                 :            : 
     261                 :        314 : int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
     262                 :            :                               int enabled)
     263                 :            : {
     264                 :            :         struct wpa_bss_params params;
     265                 :        314 :         os_memset(&params, 0, sizeof(params));
     266                 :        314 :         params.ifname = ifname;
     267                 :        314 :         params.enabled = enabled;
     268         [ +  + ]:        314 :         if (enabled) {
     269                 :        158 :                 params.wpa = hapd->conf->wpa;
     270                 :        158 :                 params.ieee802_1x = hapd->conf->ieee802_1x;
     271                 :        158 :                 params.wpa_group = hapd->conf->wpa_group;
     272                 :        158 :                 params.wpa_pairwise = hapd->conf->wpa_pairwise;
     273                 :        158 :                 params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
     274                 :        158 :                 params.rsn_preauth = hapd->conf->rsn_preauth;
     275                 :            : #ifdef CONFIG_IEEE80211W
     276                 :        158 :                 params.ieee80211w = hapd->conf->ieee80211w;
     277                 :            : #endif /* CONFIG_IEEE80211W */
     278                 :            :         }
     279                 :        314 :         return hostapd_set_ieee8021x(hapd, &params);
     280                 :            : }
     281                 :            : 
     282                 :            : 
     283                 :          0 : int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
     284                 :            : {
     285                 :            :         char force_ifname[IFNAMSIZ];
     286                 :            :         u8 if_addr[ETH_ALEN];
     287                 :          0 :         return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
     288                 :            :                               NULL, NULL, force_ifname, if_addr, NULL, 0);
     289                 :            : }
     290                 :            : 
     291                 :            : 
     292                 :          0 : int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
     293                 :            : {
     294                 :          0 :         return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
     295                 :            : }
     296                 :            : 
     297                 :            : 
     298                 :          0 : int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
     299                 :            :                         const u8 *addr, int aid, int val)
     300                 :            : {
     301                 :          0 :         const char *bridge = NULL;
     302                 :            : 
     303 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
     304                 :          0 :                 return -1;
     305         [ #  # ]:          0 :         if (hapd->conf->wds_bridge[0])
     306                 :          0 :                 bridge = hapd->conf->wds_bridge;
     307         [ #  # ]:          0 :         else if (hapd->conf->bridge[0])
     308                 :          0 :                 bridge = hapd->conf->bridge;
     309                 :          0 :         return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
     310                 :            :                                          bridge, ifname_wds);
     311                 :            : }
     312                 :            : 
     313                 :            : 
     314                 :          6 : int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
     315                 :            :                          u16 auth_alg)
     316                 :            : {
     317 [ +  - ][ +  - ]:          6 :         if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
     318                 :          6 :                 return 0;
     319                 :          6 :         return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
     320                 :            : }
     321                 :            : 
     322                 :            : 
     323                 :          0 : int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
     324                 :            :                      u16 seq, u16 status, const u8 *ie, size_t len)
     325                 :            : {
     326 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
     327                 :          0 :                 return 0;
     328                 :          0 :         return hapd->driver->sta_auth(hapd->drv_priv, hapd->own_addr, addr,
     329                 :            :                                       seq, status, ie, len);
     330                 :            : }
     331                 :            : 
     332                 :            : 
     333                 :          0 : int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
     334                 :            :                       int reassoc, u16 status, const u8 *ie, size_t len)
     335                 :            : {
     336 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
     337                 :          0 :                 return 0;
     338                 :          0 :         return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
     339                 :            :                                        reassoc, status, ie, len);
     340                 :            : }
     341                 :            : 
     342                 :            : 
     343                 :        291 : int hostapd_sta_add(struct hostapd_data *hapd,
     344                 :            :                     const u8 *addr, u16 aid, u16 capability,
     345                 :            :                     const u8 *supp_rates, size_t supp_rates_len,
     346                 :            :                     u16 listen_interval,
     347                 :            :                     const struct ieee80211_ht_capabilities *ht_capab,
     348                 :            :                     const struct ieee80211_vht_capabilities *vht_capab,
     349                 :            :                     u32 flags, u8 qosinfo)
     350                 :            : {
     351                 :            :         struct hostapd_sta_add_params params;
     352                 :            : 
     353         [ -  + ]:        291 :         if (hapd->driver == NULL)
     354                 :          0 :                 return 0;
     355         [ -  + ]:        291 :         if (hapd->driver->sta_add == NULL)
     356                 :          0 :                 return 0;
     357                 :            : 
     358                 :        291 :         os_memset(&params, 0, sizeof(params));
     359                 :        291 :         params.addr = addr;
     360                 :        291 :         params.aid = aid;
     361                 :        291 :         params.capability = capability;
     362                 :        291 :         params.supp_rates = supp_rates;
     363                 :        291 :         params.supp_rates_len = supp_rates_len;
     364                 :        291 :         params.listen_interval = listen_interval;
     365                 :        291 :         params.ht_capabilities = ht_capab;
     366                 :        291 :         params.vht_capabilities = vht_capab;
     367                 :        291 :         params.flags = hostapd_sta_flags_to_drv(flags);
     368                 :        291 :         params.qosinfo = qosinfo;
     369                 :        291 :         return hapd->driver->sta_add(hapd->drv_priv, &params);
     370                 :            : }
     371                 :            : 
     372                 :            : 
     373                 :          0 : int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
     374                 :            :                       u8 *tspec_ie, size_t tspec_ielen)
     375                 :            : {
     376 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
     377                 :          0 :                 return 0;
     378                 :          0 :         return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
     379                 :            :                                        tspec_ielen);
     380                 :            : }
     381                 :            : 
     382                 :            : 
     383                 :        720 : int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
     384                 :            : {
     385 [ +  - ][ +  - ]:        720 :         if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
     386                 :        720 :                 return 0;
     387                 :        720 :         return hapd->driver->set_privacy(hapd->drv_priv, enabled);
     388                 :            : }
     389                 :            : 
     390                 :            : 
     391                 :        314 : int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
     392                 :            :                              size_t elem_len)
     393                 :            : {
     394 [ +  - ][ +  - ]:        314 :         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
     395                 :        314 :                 return 0;
     396                 :        314 :         return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
     397                 :            : }
     398                 :            : 
     399                 :            : 
     400                 :        200 : int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
     401                 :            : {
     402 [ +  - ][ +  - ]:        200 :         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
     403                 :        200 :                 return 0;
     404                 :        200 :         return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
     405                 :            : }
     406                 :            : 
     407                 :            : 
     408                 :        214 : int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
     409                 :            : {
     410 [ +  - ][ +  - ]:        214 :         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
     411                 :        214 :                 return 0;
     412                 :        214 :         return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
     413                 :            : }
     414                 :            : 
     415                 :            : 
     416                 :         17 : int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
     417                 :            :                    const char *ifname, const u8 *addr, void *bss_ctx,
     418                 :            :                    void **drv_priv, char *force_ifname, u8 *if_addr,
     419                 :            :                    const char *bridge, int use_existing)
     420                 :            : {
     421 [ +  - ][ -  + ]:         17 :         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
     422                 :          0 :                 return -1;
     423                 :         17 :         return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
     424                 :            :                                     bss_ctx, drv_priv, force_ifname, if_addr,
     425                 :            :                                     bridge, use_existing);
     426                 :            : }
     427                 :            : 
     428                 :            : 
     429                 :         17 : int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
     430                 :            :                       const char *ifname)
     431                 :            : {
     432 [ +  - ][ +  - ]:         17 :         if (hapd->driver == NULL || hapd->drv_priv == NULL ||
                 [ -  + ]
     433                 :         17 :             hapd->driver->if_remove == NULL)
     434                 :          0 :                 return -1;
     435                 :         17 :         return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
     436                 :            : }
     437                 :            : 
     438                 :            : 
     439                 :        314 : int hostapd_set_ieee8021x(struct hostapd_data *hapd,
     440                 :            :                           struct wpa_bss_params *params)
     441                 :            : {
     442 [ +  - ][ +  - ]:        314 :         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
     443                 :        314 :                 return 0;
     444                 :        314 :         return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
     445                 :            : }
     446                 :            : 
     447                 :            : 
     448                 :        229 : int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
     449                 :            :                        const u8 *addr, int idx, u8 *seq)
     450                 :            : {
     451 [ +  - ][ -  + ]:        229 :         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
     452                 :          0 :                 return 0;
     453                 :        229 :         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
     454                 :            :                                         seq);
     455                 :            : }
     456                 :            : 
     457                 :            : 
     458                 :        421 : int hostapd_flush(struct hostapd_data *hapd)
     459                 :            : {
     460 [ +  - ][ -  + ]:        421 :         if (hapd->driver == NULL || hapd->driver->flush == NULL)
     461                 :          0 :                 return 0;
     462                 :        421 :         return hapd->driver->flush(hapd->drv_priv);
     463                 :            : }
     464                 :            : 
     465                 :            : 
     466                 :        183 : int hostapd_set_freq_params(struct hostapd_freq_params *data, int mode,
     467                 :            :                             int freq, int channel, int ht_enabled,
     468                 :            :                             int vht_enabled, int sec_channel_offset,
     469                 :            :                             int vht_oper_chwidth, int center_segment0,
     470                 :            :                             int center_segment1, u32 vht_caps)
     471                 :            : {
     472                 :            :         int tmp;
     473                 :            : 
     474                 :        183 :         os_memset(data, 0, sizeof(*data));
     475                 :        183 :         data->mode = mode;
     476                 :        183 :         data->freq = freq;
     477                 :        183 :         data->channel = channel;
     478                 :        183 :         data->ht_enabled = ht_enabled;
     479                 :        183 :         data->vht_enabled = vht_enabled;
     480                 :        183 :         data->sec_channel_offset = sec_channel_offset;
     481                 :        183 :         data->center_freq1 = freq + sec_channel_offset * 10;
     482                 :        183 :         data->center_freq2 = 0;
     483         [ +  + ]:        183 :         data->bandwidth = sec_channel_offset ? 40 : 20;
     484                 :            : 
     485                 :            :         /*
     486                 :            :          * This validation code is probably misplaced, maybe it should be
     487                 :            :          * in src/ap/hw_features.c and check the hardware support as well.
     488                 :            :          */
     489 [ -  + ][ #  #  :        183 :         if (data->vht_enabled) switch (vht_oper_chwidth) {
                #  #  # ]
     490                 :            :         case VHT_CHANWIDTH_USE_HT:
     491         [ #  # ]:          0 :                 if (center_segment1)
     492                 :          0 :                         return -1;
     493 [ #  # ][ #  # ]:          0 :                 if (5000 + center_segment0 * 5 != data->center_freq1 &&
     494                 :          0 :                     2407 + center_segment0 * 5 != data->center_freq1)
     495                 :          0 :                         return -1;
     496                 :          0 :                 break;
     497                 :            :         case VHT_CHANWIDTH_80P80MHZ:
     498         [ #  # ]:          0 :                 if (!(vht_caps & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) {
     499                 :          0 :                         wpa_printf(MSG_ERROR,
     500                 :            :                                    "80+80 channel width is not supported!");
     501                 :          0 :                         return -1;
     502                 :            :                 }
     503 [ #  # ][ #  # ]:          0 :                 if (center_segment1 == center_segment0 + 4 ||
     504                 :          0 :                     center_segment1 == center_segment0 - 4)
     505                 :          0 :                         return -1;
     506                 :          0 :                 data->center_freq2 = 5000 + center_segment1 * 5;
     507                 :            :                 /* fall through */
     508                 :            :         case VHT_CHANWIDTH_80MHZ:
     509                 :          0 :                 data->bandwidth = 80;
     510 [ #  # ][ #  # ]:          0 :                 if (vht_oper_chwidth == 1 && center_segment1)
     511                 :          0 :                         return -1;
     512 [ #  # ][ #  # ]:          0 :                 if (vht_oper_chwidth == 3 && !center_segment1)
     513                 :          0 :                         return -1;
     514         [ #  # ]:          0 :                 if (!sec_channel_offset)
     515                 :          0 :                         return -1;
     516                 :            :                 /* primary 40 part must match the HT configuration */
     517                 :          0 :                 tmp = (30 + freq - 5000 - center_segment0 * 5)/20;
     518                 :          0 :                 tmp /= 2;
     519         [ #  # ]:          0 :                 if (data->center_freq1 != 5000 +
     520                 :          0 :                                          center_segment0 * 5 - 20 + 40 * tmp)
     521                 :          0 :                         return -1;
     522                 :          0 :                 data->center_freq1 = 5000 + center_segment0 * 5;
     523                 :          0 :                 break;
     524                 :            :         case VHT_CHANWIDTH_160MHZ:
     525                 :          0 :                 data->bandwidth = 160;
     526         [ #  # ]:          0 :                 if (!(vht_caps & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
     527                 :            :                                   VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) {
     528                 :          0 :                         wpa_printf(MSG_ERROR,
     529                 :            :                                    "160MHZ channel width is not supported!");
     530                 :          0 :                         return -1;
     531                 :            :                 }
     532         [ #  # ]:          0 :                 if (center_segment1)
     533                 :          0 :                         return -1;
     534         [ #  # ]:          0 :                 if (!sec_channel_offset)
     535                 :          0 :                         return -1;
     536                 :            :                 /* primary 40 part must match the HT configuration */
     537                 :          0 :                 tmp = (70 + freq - 5000 - center_segment0 * 5)/20;
     538                 :          0 :                 tmp /= 2;
     539         [ #  # ]:          0 :                 if (data->center_freq1 != 5000 +
     540                 :          0 :                                          center_segment0 * 5 - 60 + 40 * tmp)
     541                 :          0 :                         return -1;
     542                 :          0 :                 data->center_freq1 = 5000 + center_segment0 * 5;
     543                 :          0 :                 break;
     544                 :            :         }
     545                 :            : 
     546                 :        183 :         return 0;
     547                 :            : }
     548                 :            : 
     549                 :            : 
     550                 :        183 : int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq,
     551                 :            :                      int channel, int ht_enabled, int vht_enabled,
     552                 :            :                      int sec_channel_offset, int vht_oper_chwidth,
     553                 :            :                      int center_segment0, int center_segment1)
     554                 :            : {
     555                 :            :         struct hostapd_freq_params data;
     556                 :            : 
     557         [ -  + ]:        183 :         if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
     558                 :            :                                     vht_enabled, sec_channel_offset,
     559                 :            :                                     vht_oper_chwidth,
     560                 :            :                                     center_segment0, center_segment1,
     561                 :        183 :                                     hapd->iface->current_mode->vht_capab))
     562                 :          0 :                 return -1;
     563                 :            : 
     564         [ -  + ]:        183 :         if (hapd->driver == NULL)
     565                 :          0 :                 return 0;
     566         [ -  + ]:        183 :         if (hapd->driver->set_freq == NULL)
     567                 :          0 :                 return 0;
     568                 :        183 :         return hapd->driver->set_freq(hapd->drv_priv, &data);
     569                 :            : }
     570                 :            : 
     571                 :          0 : int hostapd_set_rts(struct hostapd_data *hapd, int rts)
     572                 :            : {
     573 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
     574                 :          0 :                 return 0;
     575                 :          0 :         return hapd->driver->set_rts(hapd->drv_priv, rts);
     576                 :            : }
     577                 :            : 
     578                 :            : 
     579                 :          0 : int hostapd_set_frag(struct hostapd_data *hapd, int frag)
     580                 :            : {
     581 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
     582                 :          0 :                 return 0;
     583                 :          0 :         return hapd->driver->set_frag(hapd->drv_priv, frag);
     584                 :            : }
     585                 :            : 
     586                 :            : 
     587                 :        811 : int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
     588                 :            :                           int total_flags, int flags_or, int flags_and)
     589                 :            : {
     590 [ +  - ][ -  + ]:        811 :         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
     591                 :          0 :                 return 0;
     592                 :        811 :         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
     593                 :            :                                            flags_or, flags_and);
     594                 :            : }
     595                 :            : 
     596                 :            : 
     597                 :          0 : int hostapd_set_country(struct hostapd_data *hapd, const char *country)
     598                 :            : {
     599 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL ||
     600                 :          0 :             hapd->driver->set_country == NULL)
     601                 :          0 :                 return 0;
     602                 :          0 :         return hapd->driver->set_country(hapd->drv_priv, country);
     603                 :            : }
     604                 :            : 
     605                 :            : 
     606                 :        732 : int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
     607                 :            :                                 int cw_min, int cw_max, int burst_time)
     608                 :            : {
     609 [ +  - ][ -  + ]:        732 :         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
     610                 :          0 :                 return 0;
     611                 :        732 :         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
     612                 :            :                                                  cw_min, cw_max, burst_time);
     613                 :            : }
     614                 :            : 
     615                 :            : 
     616                 :            : struct hostapd_hw_modes *
     617                 :        190 : hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
     618                 :            :                             u16 *flags)
     619                 :            : {
     620 [ +  - ][ -  + ]:        190 :         if (hapd->driver == NULL ||
     621                 :        190 :             hapd->driver->get_hw_feature_data == NULL)
     622                 :          0 :                 return NULL;
     623                 :        190 :         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
     624                 :            :                                                  flags);
     625                 :            : }
     626                 :            : 
     627                 :            : 
     628                 :        183 : int hostapd_driver_commit(struct hostapd_data *hapd)
     629                 :            : {
     630 [ +  - ][ +  - ]:        183 :         if (hapd->driver == NULL || hapd->driver->commit == NULL)
     631                 :        183 :                 return 0;
     632                 :        183 :         return hapd->driver->commit(hapd->drv_priv);
     633                 :            : }
     634                 :            : 
     635                 :            : 
     636                 :       1358 : int hostapd_drv_none(struct hostapd_data *hapd)
     637                 :            : {
     638 [ +  - ][ -  + ]:       1358 :         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
     639                 :            : }
     640                 :            : 
     641                 :            : 
     642                 :         24 : int hostapd_driver_scan(struct hostapd_data *hapd,
     643                 :            :                         struct wpa_driver_scan_params *params)
     644                 :            : {
     645 [ +  - ][ +  - ]:         24 :         if (hapd->driver && hapd->driver->scan2)
     646                 :         24 :                 return hapd->driver->scan2(hapd->drv_priv, params);
     647                 :         24 :         return -1;
     648                 :            : }
     649                 :            : 
     650                 :            : 
     651                 :          4 : struct wpa_scan_results * hostapd_driver_get_scan_results(
     652                 :            :         struct hostapd_data *hapd)
     653                 :            : {
     654 [ +  - ][ +  - ]:          4 :         if (hapd->driver && hapd->driver->get_scan_results2)
     655                 :          4 :                 return hapd->driver->get_scan_results2(hapd->drv_priv);
     656                 :          4 :         return NULL;
     657                 :            : }
     658                 :            : 
     659                 :            : 
     660                 :          0 : int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
     661                 :            :                            int duration)
     662                 :            : {
     663 [ #  # ][ #  # ]:          0 :         if (hapd->driver && hapd->driver->set_noa)
     664                 :          0 :                 return hapd->driver->set_noa(hapd->drv_priv, count, start,
     665                 :            :                                              duration);
     666                 :          0 :         return -1;
     667                 :            : }
     668                 :            : 
     669                 :            : 
     670                 :       3481 : int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
     671                 :            :                         enum wpa_alg alg, const u8 *addr,
     672                 :            :                         int key_idx, int set_tx,
     673                 :            :                         const u8 *seq, size_t seq_len,
     674                 :            :                         const u8 *key, size_t key_len)
     675                 :            : {
     676 [ +  - ][ -  + ]:       3481 :         if (hapd->driver == NULL || hapd->driver->set_key == NULL)
     677                 :          0 :                 return 0;
     678                 :       3481 :         return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
     679                 :            :                                      key_idx, set_tx, seq, seq_len, key,
     680                 :            :                                      key_len);
     681                 :            : }
     682                 :            : 
     683                 :            : 
     684                 :       1302 : int hostapd_drv_send_mlme(struct hostapd_data *hapd,
     685                 :            :                           const void *msg, size_t len, int noack)
     686                 :            : {
     687 [ +  - ][ -  + ]:       1302 :         if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
     688                 :          0 :                 return 0;
     689                 :       1302 :         return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack);
     690                 :            : }
     691                 :            : 
     692                 :            : 
     693                 :        460 : int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
     694                 :            :                            const u8 *addr, int reason)
     695                 :            : {
     696 [ +  - ][ -  + ]:        460 :         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
     697                 :          0 :                 return 0;
     698                 :        460 :         return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
     699                 :            :                                         reason);
     700                 :            : }
     701                 :            : 
     702                 :            : 
     703                 :          0 : int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
     704                 :            :                              const u8 *addr, int reason)
     705                 :            : {
     706 [ #  # ][ #  # ]:          0 :         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
     707                 :          0 :                 return 0;
     708                 :          0 :         return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
     709                 :            :                                           reason);
     710                 :            : }
     711                 :            : 
     712                 :            : 
     713                 :         15 : int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
     714                 :            :                          const u8 *peer, u8 *buf, u16 *buf_len)
     715                 :            : {
     716 [ +  - ][ +  - ]:         15 :         if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
     717                 :         15 :                 return -1;
     718                 :         15 :         return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
     719                 :            :                                       buf_len);
     720                 :            : }
     721                 :            : 
     722                 :            : 
     723                 :         76 : int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
     724                 :            :                             unsigned int wait, const u8 *dst, const u8 *data,
     725                 :            :                             size_t len)
     726                 :            : {
     727 [ +  - ][ -  + ]:         76 :         if (hapd->driver == NULL || hapd->driver->send_action == NULL)
     728                 :          0 :                 return 0;
     729                 :         76 :         return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
     730                 :         76 :                                          hapd->own_addr, hapd->own_addr, data,
     731                 :            :                                          len, 0);
     732                 :            : }
     733                 :            : 
     734                 :            : 
     735                 :          0 : int hostapd_start_dfs_cac(struct hostapd_iface *iface, int mode, int freq,
     736                 :            :                           int channel, int ht_enabled, int vht_enabled,
     737                 :            :                           int sec_channel_offset, int vht_oper_chwidth,
     738                 :            :                           int center_segment0, int center_segment1)
     739                 :            : {
     740                 :          0 :         struct hostapd_data *hapd = iface->bss[0];
     741                 :            :         struct hostapd_freq_params data;
     742                 :            :         int res;
     743                 :            : 
     744 [ #  # ][ #  # ]:          0 :         if (!hapd->driver || !hapd->driver->start_dfs_cac)
     745                 :          0 :                 return 0;
     746                 :            : 
     747         [ #  # ]:          0 :         if (!iface->conf->ieee80211h) {
     748                 :          0 :                 wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
     749                 :            :                            "is not enabled");
     750                 :          0 :                 return -1;
     751                 :            :         }
     752                 :            : 
     753         [ #  # ]:          0 :         if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
     754                 :            :                                     vht_enabled, sec_channel_offset,
     755                 :            :                                     vht_oper_chwidth, center_segment0,
     756                 :            :                                     center_segment1,
     757                 :          0 :                                     iface->current_mode->vht_capab))
     758                 :          0 :                 return -1;
     759                 :            : 
     760                 :          0 :         res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
     761         [ #  # ]:          0 :         if (!res)
     762                 :          0 :                 iface->cac_started = 1;
     763                 :            : 
     764                 :          0 :         return res;
     765                 :            : }
     766                 :            : 
     767                 :            : 
     768                 :          2 : int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
     769                 :            :                             const u8 *qos_map_set, u8 qos_map_set_len)
     770                 :            : {
     771 [ +  - ][ -  + ]:          2 :         if (hapd->driver == NULL || hapd->driver->set_qos_map == NULL)
     772                 :          0 :                 return 0;
     773                 :          2 :         return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
     774                 :            :                                          qos_map_set_len);
     775                 :            : }

Generated by: LCOV version 1.9