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 1422976643 Lines: 257 308 83.4 %
Date: 2015-02-03 Functions: 12 12 100.0 %

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

Generated by: LCOV version 1.10