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 1401264779 Lines: 223 260 85.8 %
Date: 2014-05-28 Functions: 10 10 100.0 %

          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          10 : 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          10 :         wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
      29             : 
      30          10 :         return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
      31             : }
      32             : 
      33             : 
      34             : /* set the TFS IE to driver */
      35           6 : 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           6 :         wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
      39             : 
      40           6 :         return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
      41             : }
      42             : 
      43             : 
      44             : /* MLME-SLEEPMODE.response */
      45          10 : 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          10 :         size_t gtk_elem_len = 0;
      53          10 :         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          10 :         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          10 :         sta = ap_get_sta(hapd, addr);
      64          10 :         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          10 :         os_memset(&wnmsleep_ie, 0, sizeof(struct wnm_sleep_element));
      71          10 :         wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
      72          10 :         wnmsleep_ie.eid = WLAN_EID_WNMSLEEP;
      73          10 :         wnmsleep_ie.len = wnmsleep_ie_len - 2;
      74          10 :         wnmsleep_ie.action_type = action_type;
      75          10 :         wnmsleep_ie.status = WNM_STATUS_SLEEP_ACCEPT;
      76          10 :         wnmsleep_ie.intval = host_to_le16(intval);
      77             : 
      78             :         /* TFS IE(s) */
      79          10 :         wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
      80          10 :         if (wnmtfs_ie == NULL)
      81           0 :                 return -1;
      82          10 :         if (ieee80211_11_get_tfs_ie(hapd, addr, wnmtfs_ie, &wnmtfs_ie_len,
      83             :                                     tfs_oper)) {
      84          10 :                 wnmtfs_ie_len = 0;
      85          10 :                 os_free(wnmtfs_ie);
      86          10 :                 wnmtfs_ie = NULL;
      87             :         }
      88             : 
      89             : #define MAX_GTK_SUBELEM_LEN 45
      90             : #define MAX_IGTK_SUBELEM_LEN 26
      91          10 :         mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len +
      92             :                          MAX_GTK_SUBELEM_LEN + MAX_IGTK_SUBELEM_LEN);
      93          10 :         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          10 :         os_memcpy(mgmt->da, addr, ETH_ALEN);
      99          10 :         os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
     100          10 :         os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
     101          10 :         mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     102             :                                            WLAN_FC_STYPE_ACTION);
     103          10 :         mgmt->u.action.category = WLAN_ACTION_WNM;
     104          10 :         mgmt->u.action.u.wnm_sleep_resp.action = WNM_SLEEP_MODE_RESP;
     105          10 :         mgmt->u.action.u.wnm_sleep_resp.dialogtoken = dialog_token;
     106          10 :         pos = (u8 *)mgmt->u.action.u.wnm_sleep_resp.variable;
     107             :         /* add key data if MFP is enabled */
     108          10 :         if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
     109             :             action_type != WNM_SLEEP_MODE_EXIT) {
     110           9 :                 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           2 :                 WPA_PUT_LE16((u8 *)
     130           1 :                              &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
     131             :                              gtk_elem_len + igtk_elem_len);
     132             :         }
     133          10 :         os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
     134             :         /* copy TFS IE here */
     135          10 :         pos += wnmsleep_ie_len;
     136          10 :         if (wnmtfs_ie)
     137           0 :                 os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
     138             : 
     139          20 :         len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
     140          10 :                 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          10 :         res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
     145          10 :                                       mgmt->da, &mgmt->u.action.category, len);
     146             : 
     147          10 :         if (!res) {
     148          10 :                 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          20 :                 if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
     157          10 :                     wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
     158           5 :                         sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
     159           5 :                         hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
     160             :                                              addr, NULL, NULL);
     161           5 :                         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          10 :                 if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
     169           0 :                      wnmsleep_ie.status ==
     170          10 :                      WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
     171          10 :                     wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
     172           5 :                         sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
     173           5 :                         wpa_set_wnmsleep(sta->wpa_sm, 0);
     174           5 :                         hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
     175             :                                              addr, NULL, NULL);
     176           5 :                         if (!wpa_auth_uses_mfp(sta->wpa_sm))
     177           4 :                                 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          10 :         os_free(wnmtfs_ie);
     185          10 :         os_free(mgmt);
     186          10 :         return res;
     187             : }
     188             : 
     189             : 
     190          10 : 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          10 :         const u8 *pos = frm;
     195             :         u8 dialog_token;
     196          10 :         struct wnm_sleep_element *wnmsleep_ie = NULL;
     197             :         /* multiple TFS Req IE (assuming consecutive) */
     198          10 :         u8 *tfsreq_ie_start = NULL;
     199          10 :         u8 *tfsreq_ie_end = NULL;
     200          10 :         u16 tfsreq_ie_len = 0;
     201             : 
     202          10 :         dialog_token = *pos++;
     203          31 :         while (pos + 1 < frm + len) {
     204          11 :                 u8 ie_len = pos[1];
     205          11 :                 if (pos + 2 + ie_len > frm + len)
     206           0 :                         break;
     207          11 :                 if (*pos == WLAN_EID_WNMSLEEP)
     208          10 :                         wnmsleep_ie = (struct wnm_sleep_element *) pos;
     209           1 :                 else if (*pos == WLAN_EID_TFS_REQ) {
     210           1 :                         if (!tfsreq_ie_start)
     211           1 :                                 tfsreq_ie_start = (u8 *) pos;
     212           1 :                         tfsreq_ie_end = (u8 *) pos;
     213             :                 } else
     214           0 :                         wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
     215           0 :                                    *pos);
     216          11 :                 pos += ie_len + 2;
     217             :         }
     218             : 
     219          10 :         if (!wnmsleep_ie) {
     220           0 :                 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
     221          10 :                 return;
     222             :         }
     223             : 
     224          10 :         if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
     225           2 :             tfsreq_ie_start && tfsreq_ie_end &&
     226           1 :             tfsreq_ie_end - tfsreq_ie_start >= 0) {
     227           1 :                 tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
     228             :                         tfsreq_ie_start;
     229           1 :                 wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
     230             :                 /* pass the TFS Req IE(s) to driver for processing */
     231           1 :                 if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
     232             :                                             &tfsreq_ie_len,
     233             :                                             WNM_SLEEP_TFS_REQ_IE_SET))
     234           1 :                         wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
     235             :         }
     236             : 
     237          20 :         ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
     238          10 :                                       wnmsleep_ie->action_type,
     239          10 :                                       le_to_host16(wnmsleep_ie->intval));
     240             : 
     241          10 :         if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
     242             :                 /* clear the tfs after sending the resp frame */
     243           5 :                 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           9 :         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           7 :         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           7 : 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           7 :         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           7 :         pos = frm;
     344           7 :         end = pos + len;
     345           7 :         dialog_token = *pos++;
     346           7 :         status_code = *pos++;
     347           7 :         bss_termination_delay = *pos++;
     348             : 
     349          49 :         wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
     350             :                    MACSTR " dialog_token=%u status_code=%u "
     351          42 :                    "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
     352             :                    status_code, bss_termination_delay);
     353             : 
     354           7 :         if (status_code == WNM_BSS_TM_ACCEPT) {
     355           4 :                 if (end - pos < ETH_ALEN) {
     356           0 :                         wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
     357           0 :                         return;
     358             :                 }
     359          24 :                 wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
     360          24 :                            MAC2STR(pos));
     361           4 :                 pos += ETH_ALEN;
     362             :         }
     363             : 
     364           7 :         wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
     365           7 :                     pos, end - pos);
     366             : }
     367             : 
     368             : 
     369          18 : 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          18 :         if (len < IEEE80211_HDRLEN + 2)
     377           0 :                 return -1;
     378             : 
     379          18 :         payload = &mgmt->u.action.category;
     380          18 :         payload++;
     381          18 :         action = *payload++;
     382          18 :         plen = (((const u8 *) mgmt) + len) - payload;
     383             : 
     384          18 :         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           7 :                 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
     391             :                                                   plen);
     392           7 :                 return 0;
     393             :         case WNM_SLEEP_MODE_REQ:
     394          10 :                 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
     395          10 :                 return 0;
     396             :         }
     397             : 
     398           0 :         wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
     399           0 :                    action, MAC2STR(mgmt->sa));
     400           0 :         return -1;
     401             : }
     402             : 
     403             : 
     404           2 : 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           2 :         os_memset(buf, 0, sizeof(buf));
     411           2 :         mgmt = (struct ieee80211_mgmt *) buf;
     412           2 :         mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     413             :                                            WLAN_FC_STYPE_ACTION);
     414           2 :         os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
     415           2 :         os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
     416           2 :         os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
     417           2 :         mgmt->u.action.category = WLAN_ACTION_WNM;
     418           2 :         mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
     419           2 :         mgmt->u.action.u.bss_tm_req.dialog_token = 1;
     420           2 :         mgmt->u.action.u.bss_tm_req.req_mode =
     421             :                 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
     422           2 :         mgmt->u.action.u.bss_tm_req.disassoc_timer =
     423           2 :                 host_to_le16(disassoc_timer);
     424           2 :         mgmt->u.action.u.bss_tm_req.validity_interval = 0;
     425             : 
     426           2 :         pos = mgmt->u.action.u.bss_tm_req.variable;
     427             : 
     428          12 :         wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
     429          12 :                    MACSTR, disassoc_timer, MAC2STR(sta->addr));
     430           2 :         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           2 :         return 0;
     437             : }
     438             : 
     439             : 
     440           4 : 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           4 :         os_memset(buf, 0, sizeof(buf));
     449           4 :         mgmt = (struct ieee80211_mgmt *) buf;
     450           4 :         mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     451             :                                            WLAN_FC_STYPE_ACTION);
     452           4 :         os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
     453           4 :         os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
     454           4 :         os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
     455           4 :         mgmt->u.action.category = WLAN_ACTION_WNM;
     456           4 :         mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
     457           4 :         mgmt->u.action.u.bss_tm_req.dialog_token = 1;
     458           4 :         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           4 :         mgmt->u.action.u.bss_tm_req.disassoc_timer =
     462           4 :                 host_to_le16(disassoc_timer);
     463           4 :         mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
     464             : 
     465           4 :         pos = mgmt->u.action.u.bss_tm_req.variable;
     466             : 
     467             :         /* Session Information URL */
     468           4 :         url_len = os_strlen(url);
     469           4 :         if (url_len > 255)
     470           0 :                 return -1;
     471           4 :         *pos++ = url_len;
     472           4 :         os_memcpy(pos, url, url_len);
     473           4 :         pos += url_len;
     474             : 
     475           4 :         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           4 :         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           4 :                 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
     491             : 
     492           4 :                 beacon_int = hapd->iconf->beacon_int;
     493           4 :                 if (beacon_int < 1)
     494           0 :                         beacon_int = 100; /* best guess */
     495             :                 /* Calculate timeout in ms based on beacon_int in TU */
     496           4 :                 timeout = disassoc_timer * beacon_int * 128 / 125;
     497          24 :                 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
     498          24 :                            " set to %d ms", MAC2STR(sta->addr), timeout);
     499             : 
     500           4 :                 sta->timeout_next = STA_DISASSOC_FROM_CLI;
     501           4 :                 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
     502           4 :                 eloop_register_timeout(timeout / 1000,
     503           4 :                                        timeout % 1000 * 1000,
     504             :                                        ap_handle_timer, hapd, sta);
     505             :         }
     506             : 
     507           4 :         return 0;
     508             : }

Generated by: LCOV version 1.10