LCOV - code coverage report
Current view: top level - src/ap - wpa_auth_glue.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1401264779 Lines: 287 334 85.9 %
Date: 2014-05-28 Functions: 22 23 95.7 %

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

Generated by: LCOV version 1.10