LCOV - code coverage report
Current view: top level - src/ap - wnm_ap.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 214 260 82.3 %
Date: 2014-03-02 Functions: 10 10 100.0 %
Branches: 49 88 55.7 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * hostapd - WNM
       3                 :            :  * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
       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 "utils/eloop.h"
      13                 :            : #include "common/ieee802_11_defs.h"
      14                 :            : #include "ap/hostapd.h"
      15                 :            : #include "ap/sta_info.h"
      16                 :            : #include "ap/ap_config.h"
      17                 :            : #include "ap/ap_drv_ops.h"
      18                 :            : #include "ap/wpa_auth.h"
      19                 :            : #include "wnm_ap.h"
      20                 :            : 
      21                 :            : #define MAX_TFS_IE_LEN  1024
      22                 :            : 
      23                 :            : 
      24                 :            : /* get the TFS IE from driver */
      25                 :          6 : static int ieee80211_11_get_tfs_ie(struct hostapd_data *hapd, const u8 *addr,
      26                 :            :                                    u8 *buf, u16 *buf_len, enum wnm_oper oper)
      27                 :            : {
      28                 :          6 :         wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
      29                 :            : 
      30                 :          6 :         return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
      31                 :            : }
      32                 :            : 
      33                 :            : 
      34                 :            : /* set the TFS IE to driver */
      35                 :          3 : static int ieee80211_11_set_tfs_ie(struct hostapd_data *hapd, const u8 *addr,
      36                 :            :                                    u8 *buf, u16 *buf_len, enum wnm_oper oper)
      37                 :            : {
      38                 :          3 :         wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
      39                 :            : 
      40                 :          3 :         return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
      41                 :            : }
      42                 :            : 
      43                 :            : 
      44                 :            : /* MLME-SLEEPMODE.response */
      45                 :          6 : static int ieee802_11_send_wnmsleep_resp(struct hostapd_data *hapd,
      46                 :            :                                          const u8 *addr, u8 dialog_token,
      47                 :            :                                          u8 action_type, u16 intval)
      48                 :            : {
      49                 :            :         struct ieee80211_mgmt *mgmt;
      50                 :            :         int res;
      51                 :            :         size_t len;
      52                 :          6 :         size_t gtk_elem_len = 0;
      53                 :          6 :         size_t igtk_elem_len = 0;
      54                 :            :         struct wnm_sleep_element wnmsleep_ie;
      55                 :            :         u8 *wnmtfs_ie;
      56                 :            :         u8 wnmsleep_ie_len;
      57                 :            :         u16 wnmtfs_ie_len;
      58                 :            :         u8 *pos;
      59                 :            :         struct sta_info *sta;
      60         [ +  + ]:          6 :         enum wnm_oper tfs_oper = action_type == WNM_SLEEP_MODE_ENTER ?
      61                 :            :                 WNM_SLEEP_TFS_RESP_IE_ADD : WNM_SLEEP_TFS_RESP_IE_NONE;
      62                 :            : 
      63                 :          6 :         sta = ap_get_sta(hapd, addr);
      64         [ -  + ]:          6 :         if (sta == NULL) {
      65                 :          0 :                 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
      66                 :          0 :                 return -EINVAL;
      67                 :            :         }
      68                 :            : 
      69                 :            :         /* WNM-Sleep Mode IE */
      70                 :          6 :         os_memset(&wnmsleep_ie, 0, sizeof(struct wnm_sleep_element));
      71                 :          6 :         wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
      72                 :          6 :         wnmsleep_ie.eid = WLAN_EID_WNMSLEEP;
      73                 :          6 :         wnmsleep_ie.len = wnmsleep_ie_len - 2;
      74                 :          6 :         wnmsleep_ie.action_type = action_type;
      75                 :          6 :         wnmsleep_ie.status = WNM_STATUS_SLEEP_ACCEPT;
      76                 :          6 :         wnmsleep_ie.intval = host_to_le16(intval);
      77                 :            : 
      78                 :            :         /* TFS IE(s) */
      79                 :          6 :         wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
      80         [ -  + ]:          6 :         if (wnmtfs_ie == NULL)
      81                 :          0 :                 return -1;
      82         [ +  - ]:          6 :         if (ieee80211_11_get_tfs_ie(hapd, addr, wnmtfs_ie, &wnmtfs_ie_len,
      83                 :            :                                     tfs_oper)) {
      84                 :          6 :                 wnmtfs_ie_len = 0;
      85                 :          6 :                 os_free(wnmtfs_ie);
      86                 :          6 :                 wnmtfs_ie = NULL;
      87                 :            :         }
      88                 :            : 
      89                 :            : #define MAX_GTK_SUBELEM_LEN 45
      90                 :            : #define MAX_IGTK_SUBELEM_LEN 26
      91                 :          6 :         mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len +
      92                 :            :                          MAX_GTK_SUBELEM_LEN + MAX_IGTK_SUBELEM_LEN);
      93         [ -  + ]:          6 :         if (mgmt == NULL) {
      94                 :          0 :                 wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
      95                 :            :                            "WNM-Sleep Response action frame");
      96                 :          0 :                 return -1;
      97                 :            :         }
      98                 :          6 :         os_memcpy(mgmt->da, addr, ETH_ALEN);
      99                 :          6 :         os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
     100                 :          6 :         os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
     101                 :          6 :         mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     102                 :            :                                            WLAN_FC_STYPE_ACTION);
     103                 :          6 :         mgmt->u.action.category = WLAN_ACTION_WNM;
     104                 :          6 :         mgmt->u.action.u.wnm_sleep_resp.action = WNM_SLEEP_MODE_RESP;
     105                 :          6 :         mgmt->u.action.u.wnm_sleep_resp.dialogtoken = dialog_token;
     106                 :          6 :         pos = (u8 *)mgmt->u.action.u.wnm_sleep_resp.variable;
     107                 :            :         /* add key data if MFP is enabled */
     108 [ +  + ][ +  + ]:          6 :         if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
     109                 :            :             action_type != WNM_SLEEP_MODE_EXIT) {
     110                 :          5 :                 mgmt->u.action.u.wnm_sleep_resp.keydata_len = 0;
     111                 :            :         } else {
     112                 :          1 :                 gtk_elem_len = wpa_wnmsleep_gtk_subelem(sta->wpa_sm, pos);
     113                 :          1 :                 pos += gtk_elem_len;
     114                 :          1 :                 wpa_printf(MSG_DEBUG, "Pass 4, gtk_len = %d",
     115                 :            :                            (int) gtk_elem_len);
     116                 :            : #ifdef CONFIG_IEEE80211W
     117                 :          1 :                 res = wpa_wnmsleep_igtk_subelem(sta->wpa_sm, pos);
     118         [ -  + ]:          1 :                 if (res < 0) {
     119                 :          0 :                         os_free(wnmtfs_ie);
     120                 :          0 :                         os_free(mgmt);
     121                 :          0 :                         return -1;
     122                 :            :                 }
     123                 :          1 :                 igtk_elem_len = res;
     124                 :          1 :                 pos += igtk_elem_len;
     125                 :          1 :                 wpa_printf(MSG_DEBUG, "Pass 4 igtk_len = %d",
     126                 :            :                            (int) igtk_elem_len);
     127                 :            : #endif /* CONFIG_IEEE80211W */
     128                 :            : 
     129                 :          1 :                 WPA_PUT_LE16((u8 *)
     130                 :          1 :                              &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
     131                 :            :                              gtk_elem_len + igtk_elem_len);
     132                 :            :         }
     133                 :          6 :         os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
     134                 :            :         /* copy TFS IE here */
     135                 :          6 :         pos += wnmsleep_ie_len;
     136         [ -  + ]:          6 :         if (wnmtfs_ie)
     137                 :          0 :                 os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
     138                 :            : 
     139                 :         12 :         len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
     140                 :          6 :                 igtk_elem_len + wnmsleep_ie_len + wnmtfs_ie_len;
     141                 :            : 
     142                 :            :         /* In driver, response frame should be forced to sent when STA is in
     143                 :            :          * PS mode */
     144                 :          6 :         res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
     145                 :          6 :                                       mgmt->da, &mgmt->u.action.category, len);
     146                 :            : 
     147         [ +  - ]:          6 :         if (!res) {
     148                 :          6 :                 wpa_printf(MSG_DEBUG, "Successfully send WNM-Sleep Response "
     149                 :            :                            "frame");
     150                 :            : 
     151                 :            :                 /* when entering wnmsleep
     152                 :            :                  * 1. pause the node in driver
     153                 :            :                  * 2. mark the node so that AP won't update GTK/IGTK during
     154                 :            :                  * WNM Sleep
     155                 :            :                  */
     156 [ +  + ][ +  - ]:          6 :                 if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
     157                 :          6 :                     wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
     158                 :          3 :                         sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
     159                 :          3 :                         hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
     160                 :            :                                              addr, NULL, NULL);
     161                 :          3 :                         wpa_set_wnmsleep(sta->wpa_sm, 1);
     162                 :            :                 }
     163                 :            :                 /* when exiting wnmsleep
     164                 :            :                  * 1. unmark the node
     165                 :            :                  * 2. start GTK/IGTK update if MFP is not used
     166                 :            :                  * 3. unpause the node in driver
     167                 :            :                  */
     168 [ -  + ][ #  # ]:          6 :                 if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
     169                 :          0 :                      wnmsleep_ie.status ==
     170         [ +  + ]:          6 :                      WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
     171                 :          6 :                     wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
     172                 :          3 :                         sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
     173                 :          3 :                         wpa_set_wnmsleep(sta->wpa_sm, 0);
     174                 :          3 :                         hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
     175                 :            :                                              addr, NULL, NULL);
     176         [ +  + ]:          3 :                         if (!wpa_auth_uses_mfp(sta->wpa_sm))
     177                 :          2 :                                 wpa_wnmsleep_rekey_gtk(sta->wpa_sm);
     178                 :            :                 }
     179                 :            :         } else
     180                 :          0 :                 wpa_printf(MSG_DEBUG, "Fail to send WNM-Sleep Response frame");
     181                 :            : 
     182                 :            : #undef MAX_GTK_SUBELEM_LEN
     183                 :            : #undef MAX_IGTK_SUBELEM_LEN
     184                 :          6 :         os_free(wnmtfs_ie);
     185                 :          6 :         os_free(mgmt);
     186                 :          6 :         return res;
     187                 :            : }
     188                 :            : 
     189                 :            : 
     190                 :          6 : static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
     191                 :            :                                        const u8 *addr, const u8 *frm, int len)
     192                 :            : {
     193                 :            :         /* Dialog Token [1] | WNM-Sleep Mode IE | TFS Response IE */
     194                 :          6 :         const u8 *pos = frm;
     195                 :            :         u8 dialog_token;
     196                 :          6 :         struct wnm_sleep_element *wnmsleep_ie = NULL;
     197                 :            :         /* multiple TFS Req IE (assuming consecutive) */
     198                 :          6 :         u8 *tfsreq_ie_start = NULL;
     199                 :          6 :         u8 *tfsreq_ie_end = NULL;
     200                 :          6 :         u16 tfsreq_ie_len = 0;
     201                 :            : 
     202                 :          6 :         dialog_token = *pos++;
     203         [ +  + ]:         12 :         while (pos + 1 < frm + len) {
     204                 :          6 :                 u8 ie_len = pos[1];
     205         [ -  + ]:          6 :                 if (pos + 2 + ie_len > frm + len)
     206                 :          0 :                         break;
     207         [ +  - ]:          6 :                 if (*pos == WLAN_EID_WNMSLEEP)
     208                 :          6 :                         wnmsleep_ie = (struct wnm_sleep_element *) pos;
     209         [ #  # ]:          0 :                 else if (*pos == WLAN_EID_TFS_REQ) {
     210         [ #  # ]:          0 :                         if (!tfsreq_ie_start)
     211                 :          0 :                                 tfsreq_ie_start = (u8 *) pos;
     212                 :          0 :                         tfsreq_ie_end = (u8 *) pos;
     213                 :            :                 } else
     214                 :          0 :                         wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
     215                 :          0 :                                    *pos);
     216                 :          6 :                 pos += ie_len + 2;
     217                 :            :         }
     218                 :            : 
     219         [ -  + ]:          6 :         if (!wnmsleep_ie) {
     220                 :          0 :                 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
     221                 :          6 :                 return;
     222                 :            :         }
     223                 :            : 
     224 [ +  + ][ -  + ]:          6 :         if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
     225 [ #  # ][ #  # ]:          0 :             tfsreq_ie_start && tfsreq_ie_end &&
     226                 :          0 :             tfsreq_ie_end - tfsreq_ie_start >= 0) {
     227                 :          0 :                 tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
     228                 :            :                         tfsreq_ie_start;
     229                 :          0 :                 wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
     230                 :            :                 /* pass the TFS Req IE(s) to driver for processing */
     231         [ #  # ]:          0 :                 if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
     232                 :            :                                             &tfsreq_ie_len,
     233                 :            :                                             WNM_SLEEP_TFS_REQ_IE_SET))
     234                 :          0 :                         wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
     235                 :            :         }
     236                 :            : 
     237                 :          6 :         ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
     238                 :          6 :                                       wnmsleep_ie->action_type,
     239                 :          6 :                                       le_to_host16(wnmsleep_ie->intval));
     240                 :            : 
     241         [ +  + ]:          6 :         if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
     242                 :            :                 /* clear the tfs after sending the resp frame */
     243                 :          3 :                 ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
     244                 :            :                                         &tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
     245                 :            :         }
     246                 :            : }
     247                 :            : 
     248                 :            : 
     249                 :          1 : static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
     250                 :            :                                                   const u8 *addr,
     251                 :            :                                                   u8 dialog_token,
     252                 :            :                                                   const char *url)
     253                 :            : {
     254                 :            :         struct ieee80211_mgmt *mgmt;
     255                 :            :         size_t url_len, len;
     256                 :            :         u8 *pos;
     257                 :            :         int res;
     258                 :            : 
     259         [ -  + ]:          1 :         if (url)
     260                 :          0 :                 url_len = os_strlen(url);
     261                 :            :         else
     262                 :          1 :                 url_len = 0;
     263                 :            : 
     264         [ -  + ]:          1 :         mgmt = os_zalloc(sizeof(*mgmt) + (url_len ? 1 + url_len : 0));
     265         [ -  + ]:          1 :         if (mgmt == NULL)
     266                 :          0 :                 return -1;
     267                 :          1 :         os_memcpy(mgmt->da, addr, ETH_ALEN);
     268                 :          1 :         os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
     269                 :          1 :         os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
     270                 :          1 :         mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     271                 :            :                                            WLAN_FC_STYPE_ACTION);
     272                 :          1 :         mgmt->u.action.category = WLAN_ACTION_WNM;
     273                 :          1 :         mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
     274                 :          1 :         mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
     275                 :          1 :         mgmt->u.action.u.bss_tm_req.req_mode = 0;
     276                 :          1 :         mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
     277                 :          1 :         mgmt->u.action.u.bss_tm_req.validity_interval = 1;
     278                 :          1 :         pos = mgmt->u.action.u.bss_tm_req.variable;
     279         [ -  + ]:          1 :         if (url) {
     280                 :          0 :                 *pos++ += url_len;
     281                 :          0 :                 os_memcpy(pos, url, url_len);
     282                 :          0 :                 pos += url_len;
     283                 :            :         }
     284                 :            : 
     285                 :          1 :         wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
     286                 :            :                    MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
     287                 :            :                    "validity_interval=%u",
     288                 :          6 :                    MAC2STR(addr), dialog_token,
     289                 :          1 :                    mgmt->u.action.u.bss_tm_req.req_mode,
     290                 :          1 :                    le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
     291                 :          1 :                    mgmt->u.action.u.bss_tm_req.validity_interval);
     292                 :            : 
     293                 :          1 :         len = pos - &mgmt->u.action.category;
     294                 :          1 :         res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
     295                 :          1 :                                       mgmt->da, &mgmt->u.action.category, len);
     296                 :          1 :         os_free(mgmt);
     297                 :          1 :         return res;
     298                 :            : }
     299                 :            : 
     300                 :            : 
     301                 :          1 : static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
     302                 :            :                                                const u8 *addr, const u8 *frm,
     303                 :            :                                                size_t len)
     304                 :            : {
     305                 :            :         u8 dialog_token, reason;
     306                 :            :         const u8 *pos, *end;
     307                 :            : 
     308         [ -  + ]:          1 :         if (len < 2) {
     309                 :          0 :                 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
     310                 :          0 :                            MACSTR, MAC2STR(addr));
     311                 :          1 :                 return;
     312                 :            :         }
     313                 :            : 
     314                 :          1 :         pos = frm;
     315                 :          1 :         end = pos + len;
     316                 :          1 :         dialog_token = *pos++;
     317                 :          1 :         reason = *pos++;
     318                 :            : 
     319                 :          1 :         wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
     320                 :            :                    MACSTR " dialog_token=%u reason=%u",
     321                 :          6 :                    MAC2STR(addr), dialog_token, reason);
     322                 :            : 
     323                 :          1 :         wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
     324                 :          1 :                     pos, end - pos);
     325                 :            : 
     326                 :          1 :         ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token, NULL);
     327                 :            : }
     328                 :            : 
     329                 :            : 
     330                 :          4 : static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
     331                 :            :                                               const u8 *addr, const u8 *frm,
     332                 :            :                                               size_t len)
     333                 :            : {
     334                 :            :         u8 dialog_token, status_code, bss_termination_delay;
     335                 :            :         const u8 *pos, *end;
     336                 :            : 
     337         [ -  + ]:          4 :         if (len < 3) {
     338                 :          0 :                 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
     339                 :          0 :                            MACSTR, MAC2STR(addr));
     340                 :          0 :                 return;
     341                 :            :         }
     342                 :            : 
     343                 :          4 :         pos = frm;
     344                 :          4 :         end = pos + len;
     345                 :          4 :         dialog_token = *pos++;
     346                 :          4 :         status_code = *pos++;
     347                 :          4 :         bss_termination_delay = *pos++;
     348                 :            : 
     349                 :          4 :         wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
     350                 :            :                    MACSTR " dialog_token=%u status_code=%u "
     351                 :         24 :                    "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
     352                 :            :                    status_code, bss_termination_delay);
     353                 :            : 
     354         [ +  + ]:          4 :         if (status_code == WNM_BSS_TM_ACCEPT) {
     355         [ -  + ]:          2 :                 if (end - pos < ETH_ALEN) {
     356                 :          0 :                         wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
     357                 :          0 :                         return;
     358                 :            :                 }
     359                 :          2 :                 wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
     360                 :         12 :                            MAC2STR(pos));
     361                 :          2 :                 pos += ETH_ALEN;
     362                 :            :         }
     363                 :            : 
     364                 :          4 :         wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
     365                 :          4 :                     pos, end - pos);
     366                 :            : }
     367                 :            : 
     368                 :            : 
     369                 :         11 : int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
     370                 :            :                                 const struct ieee80211_mgmt *mgmt, size_t len)
     371                 :            : {
     372                 :            :         u8 action;
     373                 :            :         const u8 *payload;
     374                 :            :         size_t plen;
     375                 :            : 
     376         [ -  + ]:         11 :         if (len < IEEE80211_HDRLEN + 2)
     377                 :          0 :                 return -1;
     378                 :            : 
     379                 :         11 :         payload = &mgmt->u.action.category;
     380                 :         11 :         payload++;
     381                 :         11 :         action = *payload++;
     382                 :         11 :         plen = (((const u8 *) mgmt) + len) - payload;
     383                 :            : 
     384   [ +  +  +  - ]:         11 :         switch (action) {
     385                 :            :         case WNM_BSS_TRANS_MGMT_QUERY:
     386                 :          1 :                 ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
     387                 :            :                                                    plen);
     388                 :          1 :                 return 0;
     389                 :            :         case WNM_BSS_TRANS_MGMT_RESP:
     390                 :          4 :                 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
     391                 :            :                                                   plen);
     392                 :          4 :                 return 0;
     393                 :            :         case WNM_SLEEP_MODE_REQ:
     394                 :          6 :                 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
     395                 :          6 :                 return 0;
     396                 :            :         }
     397                 :            : 
     398                 :          0 :         wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
     399                 :          0 :                    action, MAC2STR(mgmt->sa));
     400                 :         11 :         return -1;
     401                 :            : }
     402                 :            : 
     403                 :            : 
     404                 :          1 : int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
     405                 :            :                                struct sta_info *sta, int disassoc_timer)
     406                 :            : {
     407                 :            :         u8 buf[1000], *pos;
     408                 :            :         struct ieee80211_mgmt *mgmt;
     409                 :            : 
     410                 :          1 :         os_memset(buf, 0, sizeof(buf));
     411                 :          1 :         mgmt = (struct ieee80211_mgmt *) buf;
     412                 :          1 :         mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     413                 :            :                                            WLAN_FC_STYPE_ACTION);
     414                 :          1 :         os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
     415                 :          1 :         os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
     416                 :          1 :         os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
     417                 :          1 :         mgmt->u.action.category = WLAN_ACTION_WNM;
     418                 :          1 :         mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
     419                 :          1 :         mgmt->u.action.u.bss_tm_req.dialog_token = 1;
     420                 :          1 :         mgmt->u.action.u.bss_tm_req.req_mode =
     421                 :            :                 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
     422                 :          1 :         mgmt->u.action.u.bss_tm_req.disassoc_timer =
     423                 :          1 :                 host_to_le16(disassoc_timer);
     424                 :          1 :         mgmt->u.action.u.bss_tm_req.validity_interval = 0;
     425                 :            : 
     426                 :          1 :         pos = mgmt->u.action.u.bss_tm_req.variable;
     427                 :            : 
     428                 :          1 :         wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
     429                 :          6 :                    MACSTR, disassoc_timer, MAC2STR(sta->addr));
     430         [ -  + ]:          1 :         if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
     431                 :          0 :                 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
     432                 :            :                            "Management Request frame");
     433                 :          0 :                 return -1;
     434                 :            :         }
     435                 :            : 
     436                 :          1 :         return 0;
     437                 :            : }
     438                 :            : 
     439                 :            : 
     440                 :          2 : int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
     441                 :            :                                    struct sta_info *sta, const char *url,
     442                 :            :                                    int disassoc_timer)
     443                 :            : {
     444                 :            :         u8 buf[1000], *pos;
     445                 :            :         struct ieee80211_mgmt *mgmt;
     446                 :            :         size_t url_len;
     447                 :            : 
     448                 :          2 :         os_memset(buf, 0, sizeof(buf));
     449                 :          2 :         mgmt = (struct ieee80211_mgmt *) buf;
     450                 :          2 :         mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     451                 :            :                                            WLAN_FC_STYPE_ACTION);
     452                 :          2 :         os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
     453                 :          2 :         os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
     454                 :          2 :         os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
     455                 :          2 :         mgmt->u.action.category = WLAN_ACTION_WNM;
     456                 :          2 :         mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
     457                 :          2 :         mgmt->u.action.u.bss_tm_req.dialog_token = 1;
     458                 :          2 :         mgmt->u.action.u.bss_tm_req.req_mode =
     459                 :            :                 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
     460                 :            :                 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
     461                 :          2 :         mgmt->u.action.u.bss_tm_req.disassoc_timer =
     462                 :          2 :                 host_to_le16(disassoc_timer);
     463                 :          2 :         mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
     464                 :            : 
     465                 :          2 :         pos = mgmt->u.action.u.bss_tm_req.variable;
     466                 :            : 
     467                 :            :         /* Session Information URL */
     468                 :          2 :         url_len = os_strlen(url);
     469         [ -  + ]:          2 :         if (url_len > 255)
     470                 :          0 :                 return -1;
     471                 :          2 :         *pos++ = url_len;
     472                 :          2 :         os_memcpy(pos, url, url_len);
     473                 :          2 :         pos += url_len;
     474                 :            : 
     475         [ -  + ]:          2 :         if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
     476                 :          0 :                 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
     477                 :            :                            "Management Request frame");
     478                 :          0 :                 return -1;
     479                 :            :         }
     480                 :            : 
     481                 :            :         /* send disassociation frame after time-out */
     482         [ +  - ]:          2 :         if (disassoc_timer) {
     483                 :            :                 int timeout, beacon_int;
     484                 :            : 
     485                 :            :                 /*
     486                 :            :                  * Prevent STA from reconnecting using cached PMKSA to force
     487                 :            :                  * full authentication with the authentication server (which may
     488                 :            :                  * decide to reject the connection),
     489                 :            :                  */
     490                 :          2 :                 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
     491                 :            : 
     492                 :          2 :                 beacon_int = hapd->iconf->beacon_int;
     493         [ -  + ]:          2 :                 if (beacon_int < 1)
     494                 :          0 :                         beacon_int = 100; /* best guess */
     495                 :            :                 /* Calculate timeout in ms based on beacon_int in TU */
     496                 :          2 :                 timeout = disassoc_timer * beacon_int * 128 / 125;
     497                 :          2 :                 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
     498                 :         12 :                            " set to %d ms", MAC2STR(sta->addr), timeout);
     499                 :            : 
     500                 :          2 :                 sta->timeout_next = STA_DISASSOC_FROM_CLI;
     501                 :          2 :                 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
     502                 :          2 :                 eloop_register_timeout(timeout / 1000,
     503                 :          2 :                                        timeout % 1000 * 1000,
     504                 :            :                                        ap_handle_timer, hapd, sta);
     505                 :            :         }
     506                 :            : 
     507                 :          2 :         return 0;
     508                 :            : }

Generated by: LCOV version 1.9