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

Generated by: LCOV version 1.10