LCOV - code coverage report
Current view: top level - src/ap - wpa_auth_glue.c (source / functions) Hit Total Coverage
Test: hostapd hwsim test run 1388338050 Lines: 258 319 80.9 %
Date: 2013-12-29 Functions: 21 23 91.3 %
Branches: 81 151 53.6 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * hostapd / WPA authenticator glue code
       3                 :            :  * Copyright (c) 2002-2012, 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 "common/sae.h"
      14                 :            : #include "eapol_auth/eapol_auth_sm.h"
      15                 :            : #include "eapol_auth/eapol_auth_sm_i.h"
      16                 :            : #include "eap_server/eap.h"
      17                 :            : #include "l2_packet/l2_packet.h"
      18                 :            : #include "hostapd.h"
      19                 :            : #include "ieee802_1x.h"
      20                 :            : #include "preauth_auth.h"
      21                 :            : #include "sta_info.h"
      22                 :            : #include "tkip_countermeasures.h"
      23                 :            : #include "ap_drv_ops.h"
      24                 :            : #include "ap_config.h"
      25                 :            : #include "wpa_auth.h"
      26                 :            : #include "wpa_auth_glue.h"
      27                 :            : 
      28                 :            : 
      29                 :        158 : static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
      30                 :            :                                   struct hostapd_config *iconf,
      31                 :            :                                   struct wpa_auth_config *wconf)
      32                 :            : {
      33                 :        158 :         os_memset(wconf, 0, sizeof(*wconf));
      34                 :        158 :         wconf->wpa = conf->wpa;
      35                 :        158 :         wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
      36                 :        158 :         wconf->wpa_pairwise = conf->wpa_pairwise;
      37                 :        158 :         wconf->wpa_group = conf->wpa_group;
      38                 :        158 :         wconf->wpa_group_rekey = conf->wpa_group_rekey;
      39                 :        158 :         wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
      40                 :        158 :         wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
      41                 :        158 :         wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
      42                 :        158 :         wconf->rsn_pairwise = conf->rsn_pairwise;
      43                 :        158 :         wconf->rsn_preauth = conf->rsn_preauth;
      44                 :        158 :         wconf->eapol_version = conf->eapol_version;
      45                 :        158 :         wconf->peerkey = conf->peerkey;
      46                 :        158 :         wconf->wmm_enabled = conf->wmm_enabled;
      47                 :        158 :         wconf->wmm_uapsd = conf->wmm_uapsd;
      48                 :        158 :         wconf->disable_pmksa_caching = conf->disable_pmksa_caching;
      49                 :        158 :         wconf->okc = conf->okc;
      50                 :            : #ifdef CONFIG_IEEE80211W
      51                 :        158 :         wconf->ieee80211w = conf->ieee80211w;
      52                 :            : #endif /* CONFIG_IEEE80211W */
      53                 :            : #ifdef CONFIG_IEEE80211R
      54                 :        158 :         wconf->ssid_len = conf->ssid.ssid_len;
      55         [ -  + ]:        158 :         if (wconf->ssid_len > SSID_LEN)
      56                 :          0 :                 wconf->ssid_len = SSID_LEN;
      57                 :        158 :         os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
      58                 :        158 :         os_memcpy(wconf->mobility_domain, conf->mobility_domain,
      59                 :            :                   MOBILITY_DOMAIN_ID_LEN);
      60 [ +  + ][ +  - ]:        158 :         if (conf->nas_identifier &&
      61                 :         46 :             os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
      62                 :         46 :                 wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
      63                 :         46 :                 os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
      64                 :            :                           wconf->r0_key_holder_len);
      65                 :            :         }
      66                 :        158 :         os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
      67                 :        158 :         wconf->r0_key_lifetime = conf->r0_key_lifetime;
      68                 :        158 :         wconf->reassociation_deadline = conf->reassociation_deadline;
      69                 :        158 :         wconf->r0kh_list = conf->r0kh_list;
      70                 :        158 :         wconf->r1kh_list = conf->r1kh_list;
      71                 :        158 :         wconf->pmk_r1_push = conf->pmk_r1_push;
      72                 :        158 :         wconf->ft_over_ds = conf->ft_over_ds;
      73                 :            : #endif /* CONFIG_IEEE80211R */
      74                 :            : #ifdef CONFIG_HS20
      75                 :        158 :         wconf->disable_gtk = conf->disable_dgaf;
      76                 :            : #endif /* CONFIG_HS20 */
      77                 :            : #ifdef CONFIG_TESTING_OPTIONS
      78                 :        158 :         wconf->corrupt_gtk_rekey_mic_probability =
      79                 :        158 :                 iconf->corrupt_gtk_rekey_mic_probability;
      80                 :            : #endif /* CONFIG_TESTING_OPTIONS */
      81                 :        158 : }
      82                 :            : 
      83                 :            : 
      84                 :       1540 : static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
      85                 :            :                                     logger_level level, const char *txt)
      86                 :            : {
      87                 :            : #ifndef CONFIG_NO_HOSTAPD_LOGGER
      88                 :       1540 :         struct hostapd_data *hapd = ctx;
      89                 :            :         int hlevel;
      90                 :            : 
      91      [ -  +  + ]:       1540 :         switch (level) {
      92                 :            :         case LOGGER_WARNING:
      93                 :          0 :                 hlevel = HOSTAPD_LEVEL_WARNING;
      94                 :          0 :                 break;
      95                 :            :         case LOGGER_INFO:
      96                 :        195 :                 hlevel = HOSTAPD_LEVEL_INFO;
      97                 :        195 :                 break;
      98                 :            :         case LOGGER_DEBUG:
      99                 :            :         default:
     100                 :       1345 :                 hlevel = HOSTAPD_LEVEL_DEBUG;
     101                 :       1345 :                 break;
     102                 :            :         }
     103                 :            : 
     104                 :       1540 :         hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
     105                 :            : #endif /* CONFIG_NO_HOSTAPD_LOGGER */
     106                 :       1540 : }
     107                 :            : 
     108                 :            : 
     109                 :          1 : static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
     110                 :            :                                         u16 reason)
     111                 :            : {
     112                 :          1 :         struct hostapd_data *hapd = ctx;
     113                 :          1 :         wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
     114                 :            :                    "STA " MACSTR " reason %d",
     115                 :          6 :                    __func__, MAC2STR(addr), reason);
     116                 :          1 :         ap_sta_disconnect(hapd, NULL, addr, reason);
     117                 :          1 : }
     118                 :            : 
     119                 :            : 
     120                 :          0 : static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
     121                 :            : {
     122                 :          0 :         struct hostapd_data *hapd = ctx;
     123                 :          0 :         return michael_mic_failure(hapd, addr, 0);
     124                 :            : }
     125                 :            : 
     126                 :            : 
     127                 :       2312 : static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
     128                 :            :                                        wpa_eapol_variable var, int value)
     129                 :            : {
     130                 :       2312 :         struct hostapd_data *hapd = ctx;
     131                 :       2312 :         struct sta_info *sta = ap_get_sta(hapd, addr);
     132         [ -  + ]:       2312 :         if (sta == NULL)
     133                 :       2312 :                 return;
     134   [ +  +  +  +  :       2312 :         switch (var) {
             +  +  +  +  
                      - ]
     135                 :            :         case WPA_EAPOL_portEnabled:
     136                 :        489 :                 ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
     137                 :        489 :                 break;
     138                 :            :         case WPA_EAPOL_portValid:
     139                 :        512 :                 ieee802_1x_notify_port_valid(sta->eapol_sm, value);
     140                 :        512 :                 break;
     141                 :            :         case WPA_EAPOL_authorized:
     142                 :        297 :                 ieee802_1x_set_sta_authorized(hapd, sta, value);
     143                 :        297 :                 break;
     144                 :            :         case WPA_EAPOL_portControl_Auto:
     145         [ +  + ]:        164 :                 if (sta->eapol_sm)
     146                 :         65 :                         sta->eapol_sm->portControl = Auto;
     147                 :        164 :                 break;
     148                 :            :         case WPA_EAPOL_keyRun:
     149         [ +  - ]:         87 :                 if (sta->eapol_sm)
     150                 :         87 :                         sta->eapol_sm->keyRun = value ? TRUE : FALSE;
     151                 :         87 :                 break;
     152                 :            :         case WPA_EAPOL_keyAvailable:
     153         [ +  + ]:        187 :                 if (sta->eapol_sm)
     154                 :         87 :                         sta->eapol_sm->eap_if->eapKeyAvailable =
     155                 :         87 :                                 value ? TRUE : FALSE;
     156                 :        187 :                 break;
     157                 :            :         case WPA_EAPOL_keyDone:
     158         [ +  + ]:        187 :                 if (sta->eapol_sm)
     159                 :         87 :                         sta->eapol_sm->keyDone = value ? TRUE : FALSE;
     160                 :        187 :                 break;
     161                 :            :         case WPA_EAPOL_inc_EapolFramesTx:
     162         [ +  + ]:        389 :                 if (sta->eapol_sm)
     163                 :        176 :                         sta->eapol_sm->dot1xAuthEapolFramesTx++;
     164                 :        389 :                 break;
     165                 :            :         }
     166                 :            : }
     167                 :            : 
     168                 :            : 
     169                 :       1393 : static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
     170                 :            :                                       wpa_eapol_variable var)
     171                 :            : {
     172                 :       1393 :         struct hostapd_data *hapd = ctx;
     173                 :       1393 :         struct sta_info *sta = ap_get_sta(hapd, addr);
     174 [ +  - ][ -  + ]:       1393 :         if (sta == NULL || sta->eapol_sm == NULL)
     175                 :          0 :                 return -1;
     176      [ +  +  - ]:       1393 :         switch (var) {
     177                 :            :         case WPA_EAPOL_keyRun:
     178                 :       1306 :                 return sta->eapol_sm->keyRun;
     179                 :            :         case WPA_EAPOL_keyAvailable:
     180                 :         87 :                 return sta->eapol_sm->eap_if->eapKeyAvailable;
     181                 :            :         default:
     182                 :       1393 :                 return -1;
     183                 :            :         }
     184                 :            : }
     185                 :            : 
     186                 :            : 
     187                 :        310 : static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
     188                 :            :                                            const u8 *p2p_dev_addr,
     189                 :            :                                            const u8 *prev_psk)
     190                 :            : {
     191                 :        310 :         struct hostapd_data *hapd = ctx;
     192                 :        310 :         struct sta_info *sta = ap_get_sta(hapd, addr);
     193                 :            :         const u8 *psk;
     194                 :            : 
     195                 :            : #ifdef CONFIG_SAE
     196 [ +  - ][ +  + ]:        310 :         if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
     197 [ +  - ][ -  + ]:         48 :                 if (!sta->sae || prev_psk)
     198                 :          0 :                         return NULL;
     199                 :         48 :                 return sta->sae->pmk;
     200                 :            :         }
     201                 :            : #endif /* CONFIG_SAE */
     202                 :            : 
     203                 :        262 :         psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk);
     204                 :            :         /*
     205                 :            :          * This is about to iterate over all psks, prev_psk gives the last
     206                 :            :          * returned psk which should not be returned again.
     207                 :            :          * logic list (all hostapd_get_psk; all sta->psk)
     208                 :            :          */
     209 [ +  - ][ -  + ]:        262 :         if (sta && sta->psk && !psk) {
                 [ #  # ]
     210                 :            :                 struct hostapd_sta_wpa_psk_short *pos;
     211                 :          0 :                 psk = sta->psk->psk;
     212         [ #  # ]:          0 :                 for (pos = sta->psk; pos; pos = pos->next) {
     213         [ #  # ]:          0 :                         if (pos->psk == prev_psk) {
     214         [ #  # ]:          0 :                                 psk = pos->next ? pos->next->psk : NULL;
     215                 :          0 :                                 break;
     216                 :            :                         }
     217                 :            :                 }
     218                 :            :         }
     219                 :        310 :         return psk;
     220                 :            : }
     221                 :            : 
     222                 :            : 
     223                 :         82 : static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
     224                 :            :                                     size_t *len)
     225                 :            : {
     226                 :         82 :         struct hostapd_data *hapd = ctx;
     227                 :            :         const u8 *key;
     228                 :            :         size_t keylen;
     229                 :            :         struct sta_info *sta;
     230                 :            : 
     231                 :         82 :         sta = ap_get_sta(hapd, addr);
     232         [ -  + ]:         82 :         if (sta == NULL)
     233                 :          0 :                 return -1;
     234                 :            : 
     235                 :         82 :         key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
     236         [ -  + ]:         82 :         if (key == NULL)
     237                 :          0 :                 return -1;
     238                 :            : 
     239         [ -  + ]:         82 :         if (keylen > *len)
     240                 :          0 :                 keylen = *len;
     241                 :         82 :         os_memcpy(msk, key, keylen);
     242                 :         82 :         *len = keylen;
     243                 :            : 
     244                 :         82 :         return 0;
     245                 :            : }
     246                 :            : 
     247                 :            : 
     248                 :       1592 : static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
     249                 :            :                                     const u8 *addr, int idx, u8 *key,
     250                 :            :                                     size_t key_len)
     251                 :            : {
     252                 :       1592 :         struct hostapd_data *hapd = ctx;
     253                 :       1592 :         const char *ifname = hapd->conf->iface;
     254                 :            : 
     255         [ -  + ]:       1592 :         if (vlan_id > 0) {
     256                 :          0 :                 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
     257         [ #  # ]:          0 :                 if (ifname == NULL)
     258                 :          0 :                         return -1;
     259                 :            :         }
     260                 :            : 
     261                 :       1592 :         return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
     262                 :            :                                    key, key_len);
     263                 :            : }
     264                 :            : 
     265                 :            : 
     266                 :        229 : static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
     267                 :            :                                        u8 *seq)
     268                 :            : {
     269                 :        229 :         struct hostapd_data *hapd = ctx;
     270                 :        229 :         return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);
     271                 :            : }
     272                 :            : 
     273                 :            : 
     274                 :        389 : static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
     275                 :            :                                        const u8 *data, size_t data_len,
     276                 :            :                                        int encrypt)
     277                 :            : {
     278                 :        389 :         struct hostapd_data *hapd = ctx;
     279                 :            :         struct sta_info *sta;
     280                 :        389 :         u32 flags = 0;
     281                 :            : 
     282                 :        389 :         sta = ap_get_sta(hapd, addr);
     283         [ +  - ]:        389 :         if (sta)
     284                 :        389 :                 flags = hostapd_sta_flags_to_drv(sta->flags);
     285                 :            : 
     286                 :        389 :         return hostapd_drv_hapd_send_eapol(hapd, addr, data, data_len,
     287                 :            :                                            encrypt, flags);
     288                 :            : }
     289                 :            : 
     290                 :            : 
     291                 :         28 : static int hostapd_wpa_auth_for_each_sta(
     292                 :            :         void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
     293                 :            :         void *cb_ctx)
     294                 :            : {
     295                 :         28 :         struct hostapd_data *hapd = ctx;
     296                 :            :         struct sta_info *sta;
     297                 :            : 
     298         [ +  + ]:         55 :         for (sta = hapd->sta_list; sta; sta = sta->next) {
     299 [ +  - ][ +  + ]:         29 :                 if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
     300                 :          2 :                         return 1;
     301                 :            :         }
     302                 :         28 :         return 0;
     303                 :            : }
     304                 :            : 
     305                 :            : 
     306                 :            : struct wpa_auth_iface_iter_data {
     307                 :            :         int (*cb)(struct wpa_authenticator *sm, void *ctx);
     308                 :            :         void *cb_ctx;
     309                 :            : };
     310                 :            : 
     311                 :          1 : static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx)
     312                 :            : {
     313                 :          1 :         struct wpa_auth_iface_iter_data *data = ctx;
     314                 :            :         size_t i;
     315         [ +  - ]:          1 :         for (i = 0; i < iface->num_bss; i++) {
     316   [ +  -  +  - ]:          2 :                 if (iface->bss[i]->wpa_auth &&
     317                 :          1 :                     data->cb(iface->bss[i]->wpa_auth, data->cb_ctx))
     318                 :          1 :                         return 1;
     319                 :            :         }
     320                 :          1 :         return 0;
     321                 :            : }
     322                 :            : 
     323                 :            : 
     324                 :          1 : static int hostapd_wpa_auth_for_each_auth(
     325                 :            :         void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
     326                 :            :         void *cb_ctx)
     327                 :            : {
     328                 :          1 :         struct hostapd_data *hapd = ctx;
     329                 :            :         struct wpa_auth_iface_iter_data data;
     330 [ +  - ][ -  + ]:          1 :         if (hapd->iface->interfaces == NULL ||
     331                 :          1 :             hapd->iface->interfaces->for_each_interface == NULL)
     332                 :          0 :                 return -1;
     333                 :          1 :         data.cb = cb;
     334                 :          1 :         data.cb_ctx = cb_ctx;
     335                 :          1 :         return hapd->iface->interfaces->for_each_interface(
     336                 :          1 :                 hapd->iface->interfaces, wpa_auth_iface_iter, &data);
     337                 :            : }
     338                 :            : 
     339                 :            : 
     340                 :            : #ifdef CONFIG_IEEE80211R
     341                 :            : 
     342                 :            : struct wpa_auth_ft_iface_iter_data {
     343                 :            :         struct hostapd_data *src_hapd;
     344                 :            :         const u8 *dst;
     345                 :            :         const u8 *data;
     346                 :            :         size_t data_len;
     347                 :            : };
     348                 :            : 
     349                 :            : 
     350                 :         34 : static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
     351                 :            : {
     352                 :         34 :         struct wpa_auth_ft_iface_iter_data *idata = ctx;
     353                 :            :         struct hostapd_data *hapd;
     354                 :            :         size_t j;
     355                 :            : 
     356         [ +  + ]:         48 :         for (j = 0; j < iface->num_bss; j++) {
     357                 :         34 :                 hapd = iface->bss[j];
     358         [ +  + ]:         34 :                 if (hapd == idata->src_hapd)
     359                 :         14 :                         continue;
     360         [ +  - ]:         20 :                 if (os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) == 0) {
     361                 :         20 :                         wpa_printf(MSG_DEBUG, "FT: Send RRB data directly to "
     362                 :            :                                    "locally managed BSS " MACSTR "@%s -> "
     363                 :            :                                    MACSTR "@%s",
     364                 :        120 :                                    MAC2STR(idata->src_hapd->own_addr),
     365                 :         20 :                                    idata->src_hapd->conf->iface,
     366                 :        120 :                                    MAC2STR(hapd->own_addr), hapd->conf->iface);
     367                 :         20 :                         wpa_ft_rrb_rx(hapd->wpa_auth,
     368                 :         20 :                                       idata->src_hapd->own_addr,
     369                 :            :                                       idata->data, idata->data_len);
     370                 :         20 :                         return 1;
     371                 :            :                 }
     372                 :            :         }
     373                 :            : 
     374                 :         34 :         return 0;
     375                 :            : }
     376                 :            : 
     377                 :            : #endif /* CONFIG_IEEE80211R */
     378                 :            : 
     379                 :            : 
     380                 :         20 : static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
     381                 :            :                                        const u8 *data, size_t data_len)
     382                 :            : {
     383                 :         20 :         struct hostapd_data *hapd = ctx;
     384                 :            :         struct l2_ethhdr *buf;
     385                 :            :         int ret;
     386                 :            : 
     387                 :            : #ifdef CONFIG_IEEE80211R
     388 [ +  - ][ +  - ]:         20 :         if (proto == ETH_P_RRB && hapd->iface->interfaces &&
                 [ +  - ]
     389                 :         20 :             hapd->iface->interfaces->for_each_interface) {
     390                 :            :                 int res;
     391                 :            :                 struct wpa_auth_ft_iface_iter_data idata;
     392                 :         20 :                 idata.src_hapd = hapd;
     393                 :         20 :                 idata.dst = dst;
     394                 :         20 :                 idata.data = data;
     395                 :         20 :                 idata.data_len = data_len;
     396                 :         20 :                 res = hapd->iface->interfaces->for_each_interface(
     397                 :         20 :                         hapd->iface->interfaces, hostapd_wpa_auth_ft_iter,
     398                 :            :                         &idata);
     399         [ +  - ]:         20 :                 if (res == 1)
     400                 :         20 :                         return data_len;
     401                 :            :         }
     402                 :            : #endif /* CONFIG_IEEE80211R */
     403                 :            : 
     404 [ #  # ][ #  # ]:          0 :         if (hapd->driver && hapd->driver->send_ether)
     405                 :          0 :                 return hapd->driver->send_ether(hapd->drv_priv, dst,
     406                 :          0 :                                                 hapd->own_addr, proto,
     407                 :            :                                                 data, data_len);
     408         [ #  # ]:          0 :         if (hapd->l2 == NULL)
     409                 :          0 :                 return -1;
     410                 :            : 
     411                 :          0 :         buf = os_malloc(sizeof(*buf) + data_len);
     412         [ #  # ]:          0 :         if (buf == NULL)
     413                 :          0 :                 return -1;
     414                 :          0 :         os_memcpy(buf->h_dest, dst, ETH_ALEN);
     415                 :          0 :         os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN);
     416                 :          0 :         buf->h_proto = host_to_be16(proto);
     417                 :          0 :         os_memcpy(buf + 1, data, data_len);
     418                 :          0 :         ret = l2_packet_send(hapd->l2, dst, proto, (u8 *) buf,
     419                 :            :                              sizeof(*buf) + data_len);
     420                 :          0 :         os_free(buf);
     421                 :         20 :         return ret;
     422                 :            : }
     423                 :            : 
     424                 :            : 
     425                 :            : #ifdef CONFIG_IEEE80211R
     426                 :            : 
     427                 :          6 : static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
     428                 :            :                                            const u8 *data, size_t data_len)
     429                 :            : {
     430                 :          6 :         struct hostapd_data *hapd = ctx;
     431                 :            :         int res;
     432                 :            :         struct ieee80211_mgmt *m;
     433                 :            :         size_t mlen;
     434                 :            :         struct sta_info *sta;
     435                 :            : 
     436                 :          6 :         sta = ap_get_sta(hapd, dst);
     437 [ +  - ][ -  + ]:          6 :         if (sta == NULL || sta->wpa_sm == NULL)
     438                 :          0 :                 return -1;
     439                 :            : 
     440                 :          6 :         m = os_zalloc(sizeof(*m) + data_len);
     441         [ -  + ]:          6 :         if (m == NULL)
     442                 :          0 :                 return -1;
     443                 :          6 :         mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
     444                 :          6 :         m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     445                 :            :                                         WLAN_FC_STYPE_ACTION);
     446                 :          6 :         os_memcpy(m->da, dst, ETH_ALEN);
     447                 :          6 :         os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
     448                 :          6 :         os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
     449                 :          6 :         os_memcpy(&m->u, data, data_len);
     450                 :            : 
     451                 :          6 :         res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen, 0);
     452                 :          6 :         os_free(m);
     453                 :          6 :         return res;
     454                 :            : }
     455                 :            : 
     456                 :            : 
     457                 :            : static struct wpa_state_machine *
     458                 :          6 : hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
     459                 :            : {
     460                 :          6 :         struct hostapd_data *hapd = ctx;
     461                 :            :         struct sta_info *sta;
     462                 :            : 
     463         [ -  + ]:          6 :         if (hostapd_add_sta_node(hapd, sta_addr, WLAN_AUTH_FT) < 0)
     464                 :          0 :                 return NULL;
     465                 :            : 
     466                 :          6 :         sta = ap_sta_add(hapd, sta_addr);
     467         [ -  + ]:          6 :         if (sta == NULL)
     468                 :          0 :                 return NULL;
     469         [ +  + ]:          6 :         if (sta->wpa_sm) {
     470                 :          3 :                 sta->auth_alg = WLAN_AUTH_FT;
     471                 :          3 :                 return sta->wpa_sm;
     472                 :            :         }
     473                 :            : 
     474                 :          3 :         sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, NULL);
     475         [ -  + ]:          3 :         if (sta->wpa_sm == NULL) {
     476                 :          0 :                 ap_free_sta(hapd, sta);
     477                 :          0 :                 return NULL;
     478                 :            :         }
     479                 :          3 :         sta->auth_alg = WLAN_AUTH_FT;
     480                 :            : 
     481                 :          6 :         return sta->wpa_sm;
     482                 :            : }
     483                 :            : 
     484                 :            : 
     485                 :          7 : static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
     486                 :            :                                 size_t len)
     487                 :            : {
     488                 :          7 :         struct hostapd_data *hapd = ctx;
     489                 :            :         struct l2_ethhdr *ethhdr;
     490         [ -  + ]:          7 :         if (len < sizeof(*ethhdr))
     491                 :          7 :                 return;
     492                 :          7 :         ethhdr = (struct l2_ethhdr *) buf;
     493                 :          7 :         wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
     494                 :         84 :                    MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest));
     495                 :          7 :         wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr),
     496                 :            :                       len - sizeof(*ethhdr));
     497                 :            : }
     498                 :            : 
     499                 :            : 
     500                 :          0 : static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
     501                 :            :                                       u8 *tspec_ie, size_t tspec_ielen)
     502                 :            : {
     503                 :          0 :         struct hostapd_data *hapd = ctx;
     504                 :          0 :         return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen);
     505                 :            : }
     506                 :            : 
     507                 :            : #endif /* CONFIG_IEEE80211R */
     508                 :            : 
     509                 :            : 
     510                 :        156 : int hostapd_setup_wpa(struct hostapd_data *hapd)
     511                 :            : {
     512                 :            :         struct wpa_auth_config _conf;
     513                 :            :         struct wpa_auth_callbacks cb;
     514                 :            :         const u8 *wpa_ie;
     515                 :            :         size_t wpa_ie_len;
     516                 :            : 
     517                 :        156 :         hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &_conf);
     518         [ +  - ]:        156 :         if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EAPOL_TX_STATUS)
     519                 :        156 :                 _conf.tx_status = 1;
     520         [ +  - ]:        156 :         if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME)
     521                 :        156 :                 _conf.ap_mlme = 1;
     522                 :        156 :         os_memset(&cb, 0, sizeof(cb));
     523                 :        156 :         cb.ctx = hapd;
     524                 :        156 :         cb.logger = hostapd_wpa_auth_logger;
     525                 :        156 :         cb.disconnect = hostapd_wpa_auth_disconnect;
     526                 :        156 :         cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
     527                 :        156 :         cb.set_eapol = hostapd_wpa_auth_set_eapol;
     528                 :        156 :         cb.get_eapol = hostapd_wpa_auth_get_eapol;
     529                 :        156 :         cb.get_psk = hostapd_wpa_auth_get_psk;
     530                 :        156 :         cb.get_msk = hostapd_wpa_auth_get_msk;
     531                 :        156 :         cb.set_key = hostapd_wpa_auth_set_key;
     532                 :        156 :         cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
     533                 :        156 :         cb.send_eapol = hostapd_wpa_auth_send_eapol;
     534                 :        156 :         cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
     535                 :        156 :         cb.for_each_auth = hostapd_wpa_auth_for_each_auth;
     536                 :        156 :         cb.send_ether = hostapd_wpa_auth_send_ether;
     537                 :            : #ifdef CONFIG_IEEE80211R
     538                 :        156 :         cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
     539                 :        156 :         cb.add_sta = hostapd_wpa_auth_add_sta;
     540                 :        156 :         cb.add_tspec = hostapd_wpa_auth_add_tspec;
     541                 :            : #endif /* CONFIG_IEEE80211R */
     542                 :        156 :         hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
     543         [ -  + ]:        156 :         if (hapd->wpa_auth == NULL) {
     544                 :          0 :                 wpa_printf(MSG_ERROR, "WPA initialization failed.");
     545                 :          0 :                 return -1;
     546                 :            :         }
     547                 :            : 
     548         [ -  + ]:        156 :         if (hostapd_set_privacy(hapd, 1)) {
     549                 :          0 :                 wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
     550                 :          0 :                            "for interface %s", hapd->conf->iface);
     551                 :          0 :                 return -1;
     552                 :            :         }
     553                 :            : 
     554                 :        156 :         wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
     555         [ -  + ]:        156 :         if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
     556                 :          0 :                 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
     557                 :            :                            "the kernel driver.");
     558                 :          0 :                 return -1;
     559                 :            :         }
     560                 :            : 
     561         [ -  + ]:        156 :         if (rsn_preauth_iface_init(hapd)) {
     562                 :          0 :                 wpa_printf(MSG_ERROR, "Initialization of RSN "
     563                 :            :                            "pre-authentication failed.");
     564                 :          0 :                 return -1;
     565                 :            :         }
     566                 :            : 
     567                 :            : #ifdef CONFIG_IEEE80211R
     568         [ +  - ]:        156 :         if (!hostapd_drv_none(hapd)) {
     569         [ -  + ]:        156 :                 hapd->l2 = l2_packet_init(hapd->conf->bridge[0] ?
     570                 :          0 :                                           hapd->conf->bridge :
     571                 :        156 :                                           hapd->conf->iface, NULL, ETH_P_RRB,
     572                 :            :                                           hostapd_rrb_receive, hapd, 1);
     573 [ -  + ][ #  # ]:        156 :                 if (hapd->l2 == NULL &&
     574         [ #  # ]:          0 :                     (hapd->driver == NULL ||
     575                 :          0 :                      hapd->driver->send_ether == NULL)) {
     576                 :          0 :                         wpa_printf(MSG_ERROR, "Failed to open l2_packet "
     577                 :            :                                    "interface");
     578                 :          0 :                         return -1;
     579                 :            :                 }
     580                 :            :         }
     581                 :            : #endif /* CONFIG_IEEE80211R */
     582                 :            : 
     583                 :        156 :         return 0;
     584                 :            : 
     585                 :            : }
     586                 :            : 
     587                 :            : 
     588                 :          2 : void hostapd_reconfig_wpa(struct hostapd_data *hapd)
     589                 :            : {
     590                 :            :         struct wpa_auth_config wpa_auth_conf;
     591                 :          2 :         hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &wpa_auth_conf);
     592                 :          2 :         wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
     593                 :          2 : }
     594                 :            : 
     595                 :            : 
     596                 :        200 : void hostapd_deinit_wpa(struct hostapd_data *hapd)
     597                 :            : {
     598                 :        200 :         ieee80211_tkip_countermeasures_deinit(hapd);
     599                 :        200 :         rsn_preauth_iface_deinit(hapd);
     600         [ +  + ]:        200 :         if (hapd->wpa_auth) {
     601                 :        156 :                 wpa_deinit(hapd->wpa_auth);
     602                 :        156 :                 hapd->wpa_auth = NULL;
     603                 :            : 
     604         [ -  + ]:        156 :                 if (hostapd_set_privacy(hapd, 0)) {
     605                 :          0 :                         wpa_printf(MSG_DEBUG, "Could not disable "
     606                 :            :                                    "PrivacyInvoked for interface %s",
     607                 :          0 :                                    hapd->conf->iface);
     608                 :            :                 }
     609                 :            : 
     610         [ -  + ]:        156 :                 if (hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
     611                 :          0 :                         wpa_printf(MSG_DEBUG, "Could not remove generic "
     612                 :            :                                    "information element from interface %s",
     613                 :          0 :                                    hapd->conf->iface);
     614                 :            :                 }
     615                 :            :         }
     616                 :        200 :         ieee802_1x_deinit(hapd);
     617                 :            : 
     618                 :            : #ifdef CONFIG_IEEE80211R
     619                 :        200 :         l2_packet_deinit(hapd->l2);
     620                 :        200 :         hapd->l2 = NULL;
     621                 :            : #endif /* CONFIG_IEEE80211R */
     622                 :        200 : }

Generated by: LCOV version 1.9