LCOV - code coverage report
Current view: top level - src/rsn_supp - preauth.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 95 206 46.1 %
Date: 2014-03-02 Functions: 9 13 69.2 %
Branches: 37 108 34.3 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * RSN pre-authentication (supplicant)
       3                 :            :  * Copyright (c) 2003-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 "includes.h"
      10                 :            : 
      11                 :            : #include "common.h"
      12                 :            : #include "wpa.h"
      13                 :            : #include "eloop.h"
      14                 :            : #include "l2_packet/l2_packet.h"
      15                 :            : #include "eapol_supp/eapol_supp_sm.h"
      16                 :            : #include "preauth.h"
      17                 :            : #include "pmksa_cache.h"
      18                 :            : #include "wpa_i.h"
      19                 :            : 
      20                 :            : 
      21                 :            : #ifdef IEEE8021X_EAPOL
      22                 :            : 
      23                 :            : #define PMKID_CANDIDATE_PRIO_SCAN 1000
      24                 :            : 
      25                 :            : 
      26                 :            : struct rsn_pmksa_candidate {
      27                 :            :         struct dl_list list;
      28                 :            :         u8 bssid[ETH_ALEN];
      29                 :            :         int priority;
      30                 :            : };
      31                 :            : 
      32                 :            : 
      33                 :            : /**
      34                 :            :  * pmksa_candidate_free - Free all entries in PMKSA candidate list
      35                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
      36                 :            :  */
      37                 :         90 : void pmksa_candidate_free(struct wpa_sm *sm)
      38                 :            : {
      39                 :            :         struct rsn_pmksa_candidate *entry, *n;
      40                 :            : 
      41         [ +  + ]:         90 :         if (sm == NULL)
      42                 :         90 :                 return;
      43                 :            : 
      44         [ -  + ]:         89 :         dl_list_for_each_safe(entry, n, &sm->pmksa_candidates,
      45                 :            :                               struct rsn_pmksa_candidate, list) {
      46                 :          0 :                 dl_list_del(&entry->list);
      47                 :          0 :                 os_free(entry);
      48                 :            :         }
      49                 :            : }
      50                 :            : 
      51                 :            : 
      52                 :          0 : static void rsn_preauth_receive(void *ctx, const u8 *src_addr,
      53                 :            :                                 const u8 *buf, size_t len)
      54                 :            : {
      55                 :          0 :         struct wpa_sm *sm = ctx;
      56                 :            : 
      57                 :          0 :         wpa_printf(MSG_DEBUG, "RX pre-auth from " MACSTR, MAC2STR(src_addr));
      58                 :          0 :         wpa_hexdump(MSG_MSGDUMP, "RX pre-auth", buf, len);
      59                 :            : 
      60   [ #  #  #  # ]:          0 :         if (sm->preauth_eapol == NULL ||
      61         [ #  # ]:          0 :             is_zero_ether_addr(sm->preauth_bssid) ||
      62                 :          0 :             os_memcmp(sm->preauth_bssid, src_addr, ETH_ALEN) != 0) {
      63                 :          0 :                 wpa_printf(MSG_WARNING, "RSN pre-auth frame received from "
      64                 :            :                            "unexpected source " MACSTR " - dropped",
      65                 :          0 :                            MAC2STR(src_addr));
      66                 :          0 :                 return;
      67                 :            :         }
      68                 :            : 
      69                 :          0 :         eapol_sm_rx_eapol(sm->preauth_eapol, src_addr, buf, len);
      70                 :            : }
      71                 :            : 
      72                 :            : 
      73                 :          0 : static void rsn_preauth_eapol_cb(struct eapol_sm *eapol,
      74                 :            :                                  enum eapol_supp_result result,
      75                 :            :                                  void *ctx)
      76                 :            : {
      77                 :          0 :         struct wpa_sm *sm = ctx;
      78                 :            :         u8 pmk[PMK_LEN];
      79                 :            : 
      80         [ #  # ]:          0 :         if (result == EAPOL_SUPP_RESULT_SUCCESS) {
      81                 :            :                 int res, pmk_len;
      82                 :          0 :                 pmk_len = PMK_LEN;
      83                 :          0 :                 res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
      84         [ #  # ]:          0 :                 if (res) {
      85                 :            :                         /*
      86                 :            :                          * EAP-LEAP is an exception from other EAP methods: it
      87                 :            :                          * uses only 16-byte PMK.
      88                 :            :                          */
      89                 :          0 :                         res = eapol_sm_get_key(eapol, pmk, 16);
      90                 :          0 :                         pmk_len = 16;
      91                 :            :                 }
      92         [ #  # ]:          0 :                 if (res == 0) {
      93                 :          0 :                         wpa_hexdump_key(MSG_DEBUG, "RSN: PMK from pre-auth",
      94                 :            :                                         pmk, pmk_len);
      95                 :          0 :                         sm->pmk_len = pmk_len;
      96                 :          0 :                         pmksa_cache_add(sm->pmksa, pmk, pmk_len,
      97                 :          0 :                                         sm->preauth_bssid, sm->own_addr,
      98                 :            :                                         sm->network_ctx,
      99                 :            :                                         WPA_KEY_MGMT_IEEE8021X);
     100                 :            :                 } else {
     101                 :          0 :                         wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
     102                 :            :                                 "RSN: failed to get master session key from "
     103                 :            :                                 "pre-auth EAPOL state machines");
     104                 :          0 :                         result = EAPOL_SUPP_RESULT_FAILURE;
     105                 :            :                 }
     106                 :            :         }
     107                 :            : 
     108         [ #  # ]:          0 :         wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
     109                 :          0 :                 MACSTR " %s", MAC2STR(sm->preauth_bssid),
     110                 :            :                 result == EAPOL_SUPP_RESULT_SUCCESS ? "completed successfully" :
     111                 :            :                 "failed");
     112                 :            : 
     113                 :          0 :         rsn_preauth_deinit(sm);
     114                 :          0 :         rsn_preauth_candidate_process(sm);
     115                 :          0 : }
     116                 :            : 
     117                 :            : 
     118                 :          0 : static void rsn_preauth_timeout(void *eloop_ctx, void *timeout_ctx)
     119                 :            : {
     120                 :          0 :         struct wpa_sm *sm = eloop_ctx;
     121                 :            : 
     122                 :          0 :         wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
     123                 :          0 :                 MACSTR " timed out", MAC2STR(sm->preauth_bssid));
     124                 :          0 :         rsn_preauth_deinit(sm);
     125                 :          0 :         rsn_preauth_candidate_process(sm);
     126                 :          0 : }
     127                 :            : 
     128                 :            : 
     129                 :          3 : static int rsn_preauth_eapol_send(void *ctx, int type, const u8 *buf,
     130                 :            :                                   size_t len)
     131                 :            : {
     132                 :          3 :         struct wpa_sm *sm = ctx;
     133                 :            :         u8 *msg;
     134                 :            :         size_t msglen;
     135                 :            :         int res;
     136                 :            : 
     137                 :            :         /* TODO: could add l2_packet_sendmsg that allows fragments to avoid
     138                 :            :          * extra copy here */
     139                 :            : 
     140         [ -  + ]:          3 :         if (sm->l2_preauth == NULL)
     141                 :          0 :                 return -1;
     142                 :            : 
     143                 :          3 :         msg = wpa_sm_alloc_eapol(sm, type, buf, len, &msglen, NULL);
     144         [ -  + ]:          3 :         if (msg == NULL)
     145                 :          0 :                 return -1;
     146                 :            : 
     147                 :          3 :         wpa_hexdump(MSG_MSGDUMP, "TX EAPOL (preauth)", msg, msglen);
     148                 :          3 :         res = l2_packet_send(sm->l2_preauth, sm->preauth_bssid,
     149                 :            :                              ETH_P_RSN_PREAUTH, msg, msglen);
     150                 :          3 :         os_free(msg);
     151                 :          3 :         return res;
     152                 :            : }
     153                 :            : 
     154                 :            : 
     155                 :            : /**
     156                 :            :  * rsn_preauth_init - Start new RSN pre-authentication
     157                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     158                 :            :  * @dst: Authenticator address (BSSID) with which to preauthenticate
     159                 :            :  * @eap_conf: Current EAP configuration
     160                 :            :  * Returns: 0 on success, -1 on another pre-authentication is in progress,
     161                 :            :  * -2 on layer 2 packet initialization failure, -3 on EAPOL state machine
     162                 :            :  * initialization failure, -4 on memory allocation failure
     163                 :            :  *
     164                 :            :  * This function request an RSN pre-authentication with a given destination
     165                 :            :  * address. This is usually called for PMKSA candidates found from scan results
     166                 :            :  * or from driver reports. In addition, ctrl_iface PREAUTH command can trigger
     167                 :            :  * pre-authentication.
     168                 :            :  */
     169                 :          1 : int rsn_preauth_init(struct wpa_sm *sm, const u8 *dst,
     170                 :            :                      struct eap_peer_config *eap_conf)
     171                 :            : {
     172                 :            :         struct eapol_config eapol_conf;
     173                 :            :         struct eapol_ctx *ctx;
     174                 :            : 
     175         [ -  + ]:          1 :         if (sm->preauth_eapol)
     176                 :          0 :                 return -1;
     177                 :            : 
     178                 :          1 :         wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG,
     179                 :          6 :                 "RSN: starting pre-authentication with " MACSTR, MAC2STR(dst));
     180                 :            : 
     181                 :          1 :         sm->l2_preauth = l2_packet_init(sm->ifname, sm->own_addr,
     182                 :            :                                         ETH_P_RSN_PREAUTH,
     183                 :            :                                         rsn_preauth_receive, sm, 0);
     184         [ -  + ]:          1 :         if (sm->l2_preauth == NULL) {
     185                 :          0 :                 wpa_printf(MSG_WARNING, "RSN: Failed to initialize L2 packet "
     186                 :            :                            "processing for pre-authentication");
     187                 :          0 :                 return -2;
     188                 :            :         }
     189                 :            : 
     190         [ -  + ]:          1 :         if (sm->bridge_ifname) {
     191                 :          0 :                 sm->l2_preauth_br = l2_packet_init(sm->bridge_ifname,
     192                 :          0 :                                                    sm->own_addr,
     193                 :            :                                                    ETH_P_RSN_PREAUTH,
     194                 :            :                                                    rsn_preauth_receive, sm, 0);
     195         [ #  # ]:          0 :                 if (sm->l2_preauth_br == NULL) {
     196                 :          0 :                         wpa_printf(MSG_WARNING, "RSN: Failed to initialize L2 "
     197                 :            :                                    "packet processing (bridge) for "
     198                 :            :                                    "pre-authentication");
     199                 :          0 :                         return -2;
     200                 :            :                 }
     201                 :            :         }
     202                 :            : 
     203                 :          1 :         ctx = os_zalloc(sizeof(*ctx));
     204         [ -  + ]:          1 :         if (ctx == NULL) {
     205                 :          0 :                 wpa_printf(MSG_WARNING, "Failed to allocate EAPOL context.");
     206                 :          0 :                 return -4;
     207                 :            :         }
     208                 :          1 :         ctx->ctx = sm->ctx->ctx;
     209                 :          1 :         ctx->msg_ctx = sm->ctx->ctx;
     210                 :          1 :         ctx->preauth = 1;
     211                 :          1 :         ctx->cb = rsn_preauth_eapol_cb;
     212                 :          1 :         ctx->cb_ctx = sm;
     213                 :          1 :         ctx->scard_ctx = sm->scard_ctx;
     214                 :          1 :         ctx->eapol_send = rsn_preauth_eapol_send;
     215                 :          1 :         ctx->eapol_send_ctx = sm;
     216                 :          1 :         ctx->set_config_blob = sm->ctx->set_config_blob;
     217                 :          1 :         ctx->get_config_blob = sm->ctx->get_config_blob;
     218                 :            : 
     219                 :          1 :         sm->preauth_eapol = eapol_sm_init(ctx);
     220         [ -  + ]:          1 :         if (sm->preauth_eapol == NULL) {
     221                 :          0 :                 os_free(ctx);
     222                 :          0 :                 wpa_printf(MSG_WARNING, "RSN: Failed to initialize EAPOL "
     223                 :            :                            "state machines for pre-authentication");
     224                 :          0 :                 return -3;
     225                 :            :         }
     226                 :          1 :         os_memset(&eapol_conf, 0, sizeof(eapol_conf));
     227                 :          1 :         eapol_conf.accept_802_1x_keys = 0;
     228                 :          1 :         eapol_conf.required_keys = 0;
     229                 :          1 :         eapol_conf.fast_reauth = sm->fast_reauth;
     230                 :          1 :         eapol_conf.workaround = sm->eap_workaround;
     231                 :          1 :         eapol_sm_notify_config(sm->preauth_eapol, eap_conf, &eapol_conf);
     232                 :            :         /*
     233                 :            :          * Use a shorter startPeriod with preauthentication since the first
     234                 :            :          * preauth EAPOL-Start frame may end up being dropped due to race
     235                 :            :          * condition in the AP between the data receive and key configuration
     236                 :            :          * after the 4-Way Handshake.
     237                 :            :          */
     238                 :          1 :         eapol_sm_configure(sm->preauth_eapol, -1, -1, 5, 6);
     239                 :          1 :         os_memcpy(sm->preauth_bssid, dst, ETH_ALEN);
     240                 :            : 
     241                 :          1 :         eapol_sm_notify_portValid(sm->preauth_eapol, TRUE);
     242                 :            :         /* 802.1X::portControl = Auto */
     243                 :          1 :         eapol_sm_notify_portEnabled(sm->preauth_eapol, TRUE);
     244                 :            : 
     245                 :          1 :         eloop_register_timeout(sm->dot11RSNAConfigSATimeout, 0,
     246                 :            :                                rsn_preauth_timeout, sm, NULL);
     247                 :            : 
     248                 :          1 :         return 0;
     249                 :            : }
     250                 :            : 
     251                 :            : 
     252                 :            : /**
     253                 :            :  * rsn_preauth_deinit - Abort RSN pre-authentication
     254                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     255                 :            :  *
     256                 :            :  * This function aborts the current RSN pre-authentication (if one is started)
     257                 :            :  * and frees resources allocated for it.
     258                 :            :  */
     259                 :       1280 : void rsn_preauth_deinit(struct wpa_sm *sm)
     260                 :            : {
     261 [ +  + ][ +  + ]:       1280 :         if (sm == NULL || !sm->preauth_eapol)
     262                 :       1280 :                 return;
     263                 :            : 
     264                 :          1 :         eloop_cancel_timeout(rsn_preauth_timeout, sm, NULL);
     265                 :          1 :         eapol_sm_deinit(sm->preauth_eapol);
     266                 :          1 :         sm->preauth_eapol = NULL;
     267                 :          1 :         os_memset(sm->preauth_bssid, 0, ETH_ALEN);
     268                 :            : 
     269                 :          1 :         l2_packet_deinit(sm->l2_preauth);
     270                 :          1 :         sm->l2_preauth = NULL;
     271         [ -  + ]:          1 :         if (sm->l2_preauth_br) {
     272                 :          0 :                 l2_packet_deinit(sm->l2_preauth_br);
     273                 :          0 :                 sm->l2_preauth_br = NULL;
     274                 :            :         }
     275                 :            : }
     276                 :            : 
     277                 :            : 
     278                 :            : /**
     279                 :            :  * rsn_preauth_candidate_process - Process PMKSA candidates
     280                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     281                 :            :  *
     282                 :            :  * Go through the PMKSA candidates and start pre-authentication if a candidate
     283                 :            :  * without an existing PMKSA cache entry is found. Processed candidates will be
     284                 :            :  * removed from the list.
     285                 :            :  */
     286                 :        405 : void rsn_preauth_candidate_process(struct wpa_sm *sm)
     287                 :            : {
     288                 :            :         struct rsn_pmksa_candidate *candidate, *n;
     289                 :            : 
     290         [ +  - ]:        405 :         if (dl_list_empty(&sm->pmksa_candidates))
     291                 :        405 :                 return;
     292                 :            : 
     293                 :            :         /* TODO: drop priority for old candidate entries */
     294                 :            : 
     295                 :          0 :         wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: processing PMKSA candidate "
     296                 :            :                 "list");
     297 [ #  # ][ #  # ]:          0 :         if (sm->preauth_eapol ||
     298         [ #  # ]:          0 :             sm->proto != WPA_PROTO_RSN ||
     299         [ #  # ]:          0 :             wpa_sm_get_state(sm) != WPA_COMPLETED ||
     300         [ #  # ]:          0 :             (sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X &&
     301                 :          0 :              sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X_SHA256)) {
     302                 :          0 :                 wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: not in suitable "
     303                 :            :                         "state for new pre-authentication");
     304                 :          0 :                 return; /* invalid state for new pre-auth */
     305                 :            :         }
     306                 :            : 
     307         [ #  # ]:          0 :         dl_list_for_each_safe(candidate, n, &sm->pmksa_candidates,
     308                 :            :                               struct rsn_pmksa_candidate, list) {
     309                 :          0 :                 struct rsn_pmksa_cache_entry *p = NULL;
     310                 :          0 :                 p = pmksa_cache_get(sm->pmksa, candidate->bssid, NULL, NULL);
     311 [ #  # ][ #  # ]:          0 :                 if (os_memcmp(sm->bssid, candidate->bssid, ETH_ALEN) != 0 &&
     312         [ #  # ]:          0 :                     (p == NULL || p->opportunistic)) {
     313                 :          0 :                         wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA "
     314                 :            :                                 "candidate " MACSTR
     315                 :            :                                 " selected for pre-authentication",
     316                 :          0 :                                 MAC2STR(candidate->bssid));
     317                 :          0 :                         dl_list_del(&candidate->list);
     318                 :          0 :                         rsn_preauth_init(sm, candidate->bssid,
     319                 :          0 :                                          sm->eap_conf_ctx);
     320                 :          0 :                         os_free(candidate);
     321                 :          0 :                         return;
     322                 :            :                 }
     323                 :          0 :                 wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA candidate "
     324                 :            :                         MACSTR " does not need pre-authentication anymore",
     325                 :          0 :                         MAC2STR(candidate->bssid));
     326                 :            :                 /* Some drivers (e.g., NDIS) expect to get notified about the
     327                 :            :                  * PMKIDs again, so report the existing data now. */
     328         [ #  # ]:          0 :                 if (p) {
     329                 :          0 :                         wpa_sm_add_pmkid(sm, candidate->bssid, p->pmkid);
     330                 :            :                 }
     331                 :            : 
     332                 :          0 :                 dl_list_del(&candidate->list);
     333                 :          0 :                 os_free(candidate);
     334                 :            :         }
     335                 :        405 :         wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: no more pending PMKSA "
     336                 :            :                 "candidates");
     337                 :            : }
     338                 :            : 
     339                 :            : 
     340                 :            : /**
     341                 :            :  * pmksa_candidate_add - Add a new PMKSA candidate
     342                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     343                 :            :  * @bssid: BSSID (authenticator address) of the candidate
     344                 :            :  * @prio: Priority (the smaller number, the higher priority)
     345                 :            :  * @preauth: Whether the candidate AP advertises support for pre-authentication
     346                 :            :  *
     347                 :            :  * This function is used to add PMKSA candidates for RSN pre-authentication. It
     348                 :            :  * is called from scan result processing and from driver events for PMKSA
     349                 :            :  * candidates, i.e., EVENT_PMKID_CANDIDATE events to wpa_supplicant_event().
     350                 :            :  */
     351                 :          3 : void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
     352                 :            :                          int prio, int preauth)
     353                 :            : {
     354                 :            :         struct rsn_pmksa_candidate *cand, *pos;
     355                 :            : 
     356 [ +  - ][ +  + ]:          3 :         if (sm->network_ctx && sm->proactive_key_caching)
     357                 :          2 :                 pmksa_cache_get_opportunistic(sm->pmksa, sm->network_ctx,
     358                 :            :                                               bssid);
     359                 :            : 
     360         [ +  - ]:          3 :         if (!preauth) {
     361                 :          3 :                 wpa_printf(MSG_DEBUG, "RSN: Ignored PMKID candidate without "
     362                 :            :                            "preauth flag");
     363                 :          3 :                 return;
     364                 :            :         }
     365                 :            : 
     366                 :            :         /* If BSSID already on candidate list, update the priority of the old
     367                 :            :          * entry. Do not override priority based on normal scan results. */
     368                 :          0 :         cand = NULL;
     369         [ #  # ]:          0 :         dl_list_for_each(pos, &sm->pmksa_candidates,
     370                 :            :                          struct rsn_pmksa_candidate, list) {
     371         [ #  # ]:          0 :                 if (os_memcmp(pos->bssid, bssid, ETH_ALEN) == 0) {
     372                 :          0 :                         cand = pos;
     373                 :          0 :                         break;
     374                 :            :                 }
     375                 :            :         }
     376                 :            : 
     377         [ #  # ]:          0 :         if (cand) {
     378                 :          0 :                 dl_list_del(&cand->list);
     379         [ #  # ]:          0 :                 if (prio < PMKID_CANDIDATE_PRIO_SCAN)
     380                 :          0 :                         cand->priority = prio;
     381                 :            :         } else {
     382                 :          0 :                 cand = os_zalloc(sizeof(*cand));
     383         [ #  # ]:          0 :                 if (cand == NULL)
     384                 :          0 :                         return;
     385                 :          0 :                 os_memcpy(cand->bssid, bssid, ETH_ALEN);
     386                 :          0 :                 cand->priority = prio;
     387                 :            :         }
     388                 :            : 
     389                 :            :         /* Add candidate to the list; order by increasing priority value. i.e.,
     390                 :            :          * highest priority (smallest value) first. */
     391         [ #  # ]:          0 :         dl_list_for_each(pos, &sm->pmksa_candidates,
     392                 :            :                          struct rsn_pmksa_candidate, list) {
     393         [ #  # ]:          0 :                 if (cand->priority <= pos->priority) {
     394                 :          0 :                         dl_list_add(pos->list.prev, &cand->list);
     395                 :          0 :                         cand = NULL;
     396                 :          0 :                         break;
     397                 :            :                 }
     398                 :            :         }
     399         [ #  # ]:          0 :         if (cand)
     400                 :          0 :                 dl_list_add_tail(&sm->pmksa_candidates, &cand->list);
     401                 :            : 
     402                 :          0 :         wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: added PMKSA cache "
     403                 :          0 :                 "candidate " MACSTR " prio %d", MAC2STR(bssid), prio);
     404                 :          3 :         rsn_preauth_candidate_process(sm);
     405                 :            : }
     406                 :            : 
     407                 :            : 
     408                 :            : /* TODO: schedule periodic scans if current AP supports preauth */
     409                 :            : 
     410                 :            : /**
     411                 :            :  * rsn_preauth_scan_results - Start processing scan results for canditates
     412                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     413                 :            :  * Returns: 0 if ready to process results or -1 to skip processing
     414                 :            :  *
     415                 :            :  * This functions is used to notify RSN code about start of new scan results
     416                 :            :  * processing. The actual scan results will be provided by calling
     417                 :            :  * rsn_preauth_scan_result() for each BSS if this function returned 0.
     418                 :            :  */
     419                 :        438 : int rsn_preauth_scan_results(struct wpa_sm *sm)
     420                 :            : {
     421         [ +  + ]:        438 :         if (sm->ssid_len == 0)
     422                 :        388 :                 return -1;
     423                 :            : 
     424                 :            :         /*
     425                 :            :          * TODO: is it ok to free all candidates? What about the entries
     426                 :            :          * received from EVENT_PMKID_CANDIDATE?
     427                 :            :          */
     428                 :         50 :         pmksa_candidate_free(sm);
     429                 :            : 
     430                 :        438 :         return 0;
     431                 :            : }
     432                 :            : 
     433                 :            : 
     434                 :            : /**
     435                 :            :  * rsn_preauth_scan_result - Processing scan result for PMKSA canditates
     436                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     437                 :            :  *
     438                 :            :  * Add all suitable APs (Authenticators) from scan results into PMKSA
     439                 :            :  * candidate list.
     440                 :            :  */
     441                 :         50 : void rsn_preauth_scan_result(struct wpa_sm *sm, const u8 *bssid,
     442                 :            :                              const u8 *ssid, const u8 *rsn)
     443                 :            : {
     444                 :            :         struct wpa_ie_data ie;
     445                 :            :         struct rsn_pmksa_cache_entry *pmksa;
     446                 :            : 
     447 [ +  + ][ +  + ]:         50 :         if (ssid[1] != sm->ssid_len ||
     448                 :         46 :             os_memcmp(ssid + 2, sm->ssid, sm->ssid_len) != 0)
     449                 :          5 :                 return; /* Not for the current SSID */
     450                 :            : 
     451         [ +  + ]:         45 :         if (os_memcmp(bssid, sm->bssid, ETH_ALEN) == 0)
     452                 :         39 :                 return; /* Ignore current AP */
     453                 :            : 
     454         [ -  + ]:          6 :         if (wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie))
     455                 :          0 :                 return;
     456                 :            : 
     457                 :          6 :         pmksa = pmksa_cache_get(sm->pmksa, bssid, NULL, NULL);
     458 [ +  + ][ -  + ]:          6 :         if (pmksa && (!pmksa->opportunistic ||
                 [ #  # ]
     459                 :          0 :                       !(ie.capabilities & WPA_CAPABILITY_PREAUTH)))
     460                 :          3 :                 return;
     461                 :            : 
     462                 :            :         /* Give less priority to candidates found from normal scan results. */
     463                 :         50 :         pmksa_candidate_add(sm, bssid, PMKID_CANDIDATE_PRIO_SCAN,
     464                 :          3 :                             ie.capabilities & WPA_CAPABILITY_PREAUTH);
     465                 :            : }
     466                 :            : 
     467                 :            : 
     468                 :            : #ifdef CONFIG_CTRL_IFACE
     469                 :            : /**
     470                 :            :  * rsn_preauth_get_status - Get pre-authentication status
     471                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     472                 :            :  * @buf: Buffer for status information
     473                 :            :  * @buflen: Maximum buffer length
     474                 :            :  * @verbose: Whether to include verbose status information
     475                 :            :  * Returns: Number of bytes written to buf.
     476                 :            :  *
     477                 :            :  * Query WPA2 pre-authentication for status information. This function fills in
     478                 :            :  * a text area with current status information. If the buffer (buf) is not
     479                 :            :  * large enough, status information will be truncated to fit the buffer.
     480                 :            :  */
     481                 :        524 : int rsn_preauth_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
     482                 :            :                            int verbose)
     483                 :            : {
     484                 :        524 :         char *pos = buf, *end = buf + buflen;
     485                 :            :         int res, ret;
     486                 :            : 
     487         [ +  + ]:        524 :         if (sm->preauth_eapol) {
     488                 :          1 :                 ret = os_snprintf(pos, end - pos, "Pre-authentication "
     489                 :            :                                   "EAPOL state machines:\n");
     490 [ +  - ][ -  + ]:          1 :                 if (ret < 0 || ret >= end - pos)
     491                 :          0 :                         return pos - buf;
     492                 :          1 :                 pos += ret;
     493                 :          1 :                 res = eapol_sm_get_status(sm->preauth_eapol,
     494                 :          1 :                                           pos, end - pos, verbose);
     495         [ +  - ]:          1 :                 if (res >= 0)
     496                 :          1 :                         pos += res;
     497                 :            :         }
     498                 :            : 
     499                 :        524 :         return pos - buf;
     500                 :            : }
     501                 :            : #endif /* CONFIG_CTRL_IFACE */
     502                 :            : 
     503                 :            : 
     504                 :            : /**
     505                 :            :  * rsn_preauth_in_progress - Verify whether pre-authentication is in progress
     506                 :            :  * @sm: Pointer to WPA state machine data from wpa_sm_init()
     507                 :            :  */
     508                 :          0 : int rsn_preauth_in_progress(struct wpa_sm *sm)
     509                 :            : {
     510                 :          0 :         return sm->preauth_eapol != NULL;
     511                 :            : }
     512                 :            : 
     513                 :            : #endif /* IEEE8021X_EAPOL */

Generated by: LCOV version 1.9