LCOV - code coverage report
Current view: top level - src/ap - ieee802_11_shared.c (source / functions) Hit Total Coverage
Test: hostapd/hlr_auc_gw (AS) hwsim test run 1388338050 Lines: 55 272 20.2 %
Date: 2013-12-29 Functions: 7 14 50.0 %
Branches: 29 142 20.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * hostapd / IEEE 802.11 Management
       3                 :            :  * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
       4                 :            :  *
       5                 :            :  * This software may be distributed under the terms of the BSD license.
       6                 :            :  * See README for more details.
       7                 :            :  */
       8                 :            : 
       9                 :            : #include "utils/includes.h"
      10                 :            : 
      11                 :            : #include "utils/common.h"
      12                 :            : #include "common/ieee802_11_defs.h"
      13                 :            : #include "hostapd.h"
      14                 :            : #include "sta_info.h"
      15                 :            : #include "ap_config.h"
      16                 :            : #include "ap_drv_ops.h"
      17                 :            : #include "ieee802_11.h"
      18                 :            : 
      19                 :            : 
      20                 :            : #ifdef CONFIG_IEEE80211W
      21                 :            : 
      22                 :          0 : u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
      23                 :            :                                      struct sta_info *sta, u8 *eid)
      24                 :            : {
      25                 :          0 :         u8 *pos = eid;
      26                 :            :         u32 timeout, tu;
      27                 :            :         struct os_reltime now, passed;
      28                 :            : 
      29                 :          0 :         *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
      30                 :          0 :         *pos++ = 5;
      31                 :          0 :         *pos++ = WLAN_TIMEOUT_ASSOC_COMEBACK;
      32                 :          0 :         os_get_reltime(&now);
      33                 :          0 :         os_reltime_sub(&now, &sta->sa_query_start, &passed);
      34                 :          0 :         tu = (passed.sec * 1000000 + passed.usec) / 1024;
      35         [ #  # ]:          0 :         if (hapd->conf->assoc_sa_query_max_timeout > tu)
      36                 :          0 :                 timeout = hapd->conf->assoc_sa_query_max_timeout - tu;
      37                 :            :         else
      38                 :          0 :                 timeout = 0;
      39         [ #  # ]:          0 :         if (timeout < hapd->conf->assoc_sa_query_max_timeout)
      40                 :          0 :                 timeout++; /* add some extra time for local timers */
      41                 :          0 :         WPA_PUT_LE32(pos, timeout);
      42                 :          0 :         pos += 4;
      43                 :            : 
      44                 :          0 :         return pos;
      45                 :            : }
      46                 :            : 
      47                 :            : 
      48                 :            : /* MLME-SAQuery.request */
      49                 :          0 : void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
      50                 :            :                                   const u8 *addr, const u8 *trans_id)
      51                 :            : {
      52                 :            :         struct ieee80211_mgmt mgmt;
      53                 :            :         u8 *end;
      54                 :            : 
      55                 :          0 :         wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Request to "
      56                 :          0 :                    MACSTR, MAC2STR(addr));
      57                 :          0 :         wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
      58                 :            :                     trans_id, WLAN_SA_QUERY_TR_ID_LEN);
      59                 :            : 
      60                 :          0 :         os_memset(&mgmt, 0, sizeof(mgmt));
      61                 :          0 :         mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
      62                 :            :                                           WLAN_FC_STYPE_ACTION);
      63                 :          0 :         os_memcpy(mgmt.da, addr, ETH_ALEN);
      64                 :          0 :         os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
      65                 :          0 :         os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
      66                 :          0 :         mgmt.u.action.category = WLAN_ACTION_SA_QUERY;
      67                 :          0 :         mgmt.u.action.u.sa_query_req.action = WLAN_SA_QUERY_REQUEST;
      68                 :          0 :         os_memcpy(mgmt.u.action.u.sa_query_req.trans_id, trans_id,
      69                 :            :                   WLAN_SA_QUERY_TR_ID_LEN);
      70                 :          0 :         end = mgmt.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
      71         [ #  # ]:          0 :         if (hostapd_drv_send_mlme(hapd, &mgmt, end - (u8 *) &mgmt, 0) < 0)
      72                 :          0 :                 wpa_printf(MSG_INFO, "ieee802_11_send_sa_query_req: send failed");
      73                 :          0 : }
      74                 :            : 
      75                 :            : 
      76                 :          0 : static void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
      77                 :            :                                           const u8 *sa, const u8 *trans_id)
      78                 :            : {
      79                 :            :         struct sta_info *sta;
      80                 :            :         struct ieee80211_mgmt resp;
      81                 :            :         u8 *end;
      82                 :            : 
      83                 :          0 :         wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Request from "
      84                 :          0 :                    MACSTR, MAC2STR(sa));
      85                 :          0 :         wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
      86                 :            :                     trans_id, WLAN_SA_QUERY_TR_ID_LEN);
      87                 :            : 
      88                 :          0 :         sta = ap_get_sta(hapd, sa);
      89 [ #  # ][ #  # ]:          0 :         if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
      90                 :          0 :                 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignore SA Query Request "
      91                 :          0 :                            "from unassociated STA " MACSTR, MAC2STR(sa));
      92                 :          0 :                 return;
      93                 :            :         }
      94                 :            : 
      95                 :          0 :         wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Response to "
      96                 :          0 :                    MACSTR, MAC2STR(sa));
      97                 :            : 
      98                 :          0 :         os_memset(&resp, 0, sizeof(resp));
      99                 :          0 :         resp.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
     100                 :            :                                           WLAN_FC_STYPE_ACTION);
     101                 :          0 :         os_memcpy(resp.da, sa, ETH_ALEN);
     102                 :          0 :         os_memcpy(resp.sa, hapd->own_addr, ETH_ALEN);
     103                 :          0 :         os_memcpy(resp.bssid, hapd->own_addr, ETH_ALEN);
     104                 :          0 :         resp.u.action.category = WLAN_ACTION_SA_QUERY;
     105                 :          0 :         resp.u.action.u.sa_query_req.action = WLAN_SA_QUERY_RESPONSE;
     106                 :          0 :         os_memcpy(resp.u.action.u.sa_query_req.trans_id, trans_id,
     107                 :            :                   WLAN_SA_QUERY_TR_ID_LEN);
     108                 :          0 :         end = resp.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
     109         [ #  # ]:          0 :         if (hostapd_drv_send_mlme(hapd, &resp, end - (u8 *) &resp, 0) < 0)
     110                 :          0 :                 wpa_printf(MSG_INFO, "ieee80211_mgmt_sa_query_request: send failed");
     111                 :            : }
     112                 :            : 
     113                 :            : 
     114                 :          0 : void ieee802_11_sa_query_action(struct hostapd_data *hapd, const u8 *sa,
     115                 :            :                                 const u8 action_type, const u8 *trans_id)
     116                 :            : {
     117                 :            :         struct sta_info *sta;
     118                 :            :         int i;
     119                 :            : 
     120         [ #  # ]:          0 :         if (action_type == WLAN_SA_QUERY_REQUEST) {
     121                 :          0 :                 ieee802_11_send_sa_query_resp(hapd, sa, trans_id);
     122                 :          0 :                 return;
     123                 :            :         }
     124                 :            : 
     125         [ #  # ]:          0 :         if (action_type != WLAN_SA_QUERY_RESPONSE) {
     126                 :          0 :                 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected SA Query "
     127                 :            :                            "Action %d", action_type);
     128                 :          0 :                 return;
     129                 :            :         }
     130                 :            : 
     131                 :          0 :         wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Response from "
     132                 :          0 :                    MACSTR, MAC2STR(sa));
     133                 :          0 :         wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
     134                 :            :                     trans_id, WLAN_SA_QUERY_TR_ID_LEN);
     135                 :            : 
     136                 :            :         /* MLME-SAQuery.confirm */
     137                 :            : 
     138                 :          0 :         sta = ap_get_sta(hapd, sa);
     139 [ #  # ][ #  # ]:          0 :         if (sta == NULL || sta->sa_query_trans_id == NULL) {
     140                 :          0 :                 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
     141                 :            :                            "pending SA Query request found");
     142                 :          0 :                 return;
     143                 :            :         }
     144                 :            : 
     145         [ #  # ]:          0 :         for (i = 0; i < sta->sa_query_count; i++) {
     146         [ #  # ]:          0 :                 if (os_memcmp(sta->sa_query_trans_id +
     147                 :            :                               i * WLAN_SA_QUERY_TR_ID_LEN,
     148                 :            :                               trans_id, WLAN_SA_QUERY_TR_ID_LEN) == 0)
     149                 :          0 :                         break;
     150                 :            :         }
     151                 :            : 
     152         [ #  # ]:          0 :         if (i >= sta->sa_query_count) {
     153                 :          0 :                 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching SA Query "
     154                 :            :                            "transaction identifier found");
     155                 :          0 :                 return;
     156                 :            :         }
     157                 :            : 
     158                 :          0 :         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
     159                 :            :                        HOSTAPD_LEVEL_DEBUG,
     160                 :            :                        "Reply to pending SA Query received");
     161                 :          0 :         ap_sta_stop_sa_query(hapd, sta);
     162                 :            : }
     163                 :            : 
     164                 :            : #endif /* CONFIG_IEEE80211W */
     165                 :            : 
     166                 :            : 
     167                 :          8 : static void hostapd_ext_capab_byte(struct hostapd_data *hapd, u8 *pos, int idx)
     168                 :            : {
     169                 :          8 :         *pos = 0x00;
     170                 :            : 
     171   [ +  +  +  +  :          8 :         switch (idx) {
             -  -  -  - ]
     172                 :            :         case 0: /* Bits 0-7 */
     173                 :          2 :                 break;
     174                 :            :         case 1: /* Bits 8-15 */
     175                 :          2 :                 break;
     176                 :            :         case 2: /* Bits 16-23 */
     177         [ -  + ]:          2 :                 if (hapd->conf->wnm_sleep_mode)
     178                 :          0 :                         *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
     179         [ -  + ]:          2 :                 if (hapd->conf->bss_transition)
     180                 :          0 :                         *pos |= 0x08; /* Bit 19 - BSS Transition */
     181                 :          2 :                 break;
     182                 :            :         case 3: /* Bits 24-31 */
     183                 :            : #ifdef CONFIG_WNM
     184                 :          2 :                 *pos |= 0x02; /* Bit 25 - SSID List */
     185                 :            : #endif /* CONFIG_WNM */
     186         [ -  + ]:          2 :                 if (hapd->conf->time_advertisement == 2)
     187                 :          0 :                         *pos |= 0x08; /* Bit 27 - UTC TSF Offset */
     188         [ -  + ]:          2 :                 if (hapd->conf->interworking)
     189                 :          0 :                         *pos |= 0x80; /* Bit 31 - Interworking */
     190                 :          2 :                 break;
     191                 :            :         case 4: /* Bits 32-39 */
     192         [ #  # ]:          0 :                 if (hapd->conf->qos_map_set_len)
     193                 :          0 :                         *pos |= 0x01; /* Bit 32 - QoS Map */
     194         [ #  # ]:          0 :                 if (hapd->conf->tdls & TDLS_PROHIBIT)
     195                 :          0 :                         *pos |= 0x40; /* Bit 38 - TDLS Prohibited */
     196         [ #  # ]:          0 :                 if (hapd->conf->tdls & TDLS_PROHIBIT_CHAN_SWITCH) {
     197                 :            :                         /* Bit 39 - TDLS Channel Switching Prohibited */
     198                 :          0 :                         *pos |= 0x80;
     199                 :            :                 }
     200                 :          0 :                 break;
     201                 :            :         case 5: /* Bits 40-47 */
     202                 :          0 :                 break;
     203                 :            :         case 6: /* Bits 48-55 */
     204         [ #  # ]:          0 :                 if (hapd->conf->ssid.utf8_ssid)
     205                 :          0 :                         *pos |= 0x01; /* Bit 48 - UTF-8 SSID */
     206                 :          0 :                 break;
     207                 :            :         }
     208                 :          8 : }
     209                 :            : 
     210                 :            : 
     211                 :          2 : u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
     212                 :            : {
     213                 :          2 :         u8 *pos = eid;
     214                 :          2 :         u8 len = 0, i;
     215                 :            : 
     216         [ -  + ]:          2 :         if (hapd->conf->tdls & (TDLS_PROHIBIT | TDLS_PROHIBIT_CHAN_SWITCH))
     217                 :          0 :                 len = 5;
     218 [ +  - ][ -  + ]:          2 :         if (len < 4 && hapd->conf->interworking)
     219                 :          0 :                 len = 4;
     220 [ +  - ][ -  + ]:          2 :         if (len < 3 && hapd->conf->wnm_sleep_mode)
     221                 :          0 :                 len = 3;
     222 [ +  - ][ -  + ]:          2 :         if (len < 7 && hapd->conf->ssid.utf8_ssid)
     223                 :          0 :                 len = 7;
     224                 :            : #ifdef CONFIG_WNM
     225         [ +  - ]:          2 :         if (len < 4)
     226                 :          2 :                 len = 4;
     227                 :            : #endif /* CONFIG_WNM */
     228         [ -  + ]:          2 :         if (len < hapd->iface->extended_capa_len)
     229                 :          0 :                 len = hapd->iface->extended_capa_len;
     230         [ -  + ]:          2 :         if (len == 0)
     231                 :          0 :                 return eid;
     232                 :            : 
     233                 :          2 :         *pos++ = WLAN_EID_EXT_CAPAB;
     234                 :          2 :         *pos++ = len;
     235         [ +  + ]:         10 :         for (i = 0; i < len; i++, pos++) {
     236                 :          8 :                 hostapd_ext_capab_byte(hapd, pos, i);
     237                 :            : 
     238         [ -  + ]:          8 :                 if (i < hapd->iface->extended_capa_len) {
     239                 :          0 :                         *pos &= ~hapd->iface->extended_capa_mask[i];
     240                 :          0 :                         *pos |= hapd->iface->extended_capa[i];
     241                 :            :                 }
     242                 :            :         }
     243                 :            : 
     244 [ +  - ][ -  + ]:          2 :         while (len > 0 && eid[1 + len] == 0) {
     245                 :          0 :                 len--;
     246                 :          0 :                 eid[1] = len;
     247                 :            :         }
     248         [ -  + ]:          2 :         if (len == 0)
     249                 :          0 :                 return eid;
     250                 :            : 
     251                 :          2 :         return eid + 2 + len;
     252                 :            : }
     253                 :            : 
     254                 :            : 
     255                 :          0 : u8 * hostapd_eid_qos_map_set(struct hostapd_data *hapd, u8 *eid)
     256                 :            : {
     257                 :          0 :         u8 *pos = eid;
     258                 :          0 :         u8 len = hapd->conf->qos_map_set_len;
     259                 :            : 
     260         [ #  # ]:          0 :         if (!len)
     261                 :          0 :                 return eid;
     262                 :            : 
     263                 :          0 :         *pos++ = WLAN_EID_QOS_MAP_SET;
     264                 :          0 :         *pos++ = len;
     265                 :          0 :         os_memcpy(pos, hapd->conf->qos_map_set, len);
     266                 :          0 :         pos += len;
     267                 :            : 
     268                 :          0 :         return pos;
     269                 :            : }
     270                 :            : 
     271                 :            : 
     272                 :          2 : u8 * hostapd_eid_interworking(struct hostapd_data *hapd, u8 *eid)
     273                 :            : {
     274                 :          2 :         u8 *pos = eid;
     275                 :            : #ifdef CONFIG_INTERWORKING
     276                 :            :         u8 *len;
     277                 :            : 
     278         [ +  - ]:          2 :         if (!hapd->conf->interworking)
     279                 :          2 :                 return eid;
     280                 :            : 
     281                 :          0 :         *pos++ = WLAN_EID_INTERWORKING;
     282                 :          0 :         len = pos++;
     283                 :            : 
     284                 :          0 :         *pos = hapd->conf->access_network_type;
     285         [ #  # ]:          0 :         if (hapd->conf->internet)
     286                 :          0 :                 *pos |= INTERWORKING_ANO_INTERNET;
     287         [ #  # ]:          0 :         if (hapd->conf->asra)
     288                 :          0 :                 *pos |= INTERWORKING_ANO_ASRA;
     289         [ #  # ]:          0 :         if (hapd->conf->esr)
     290                 :          0 :                 *pos |= INTERWORKING_ANO_ESR;
     291         [ #  # ]:          0 :         if (hapd->conf->uesa)
     292                 :          0 :                 *pos |= INTERWORKING_ANO_UESA;
     293                 :          0 :         pos++;
     294                 :            : 
     295         [ #  # ]:          0 :         if (hapd->conf->venue_info_set) {
     296                 :          0 :                 *pos++ = hapd->conf->venue_group;
     297                 :          0 :                 *pos++ = hapd->conf->venue_type;
     298                 :            :         }
     299                 :            : 
     300         [ #  # ]:          0 :         if (!is_zero_ether_addr(hapd->conf->hessid)) {
     301                 :          0 :                 os_memcpy(pos, hapd->conf->hessid, ETH_ALEN);
     302                 :          0 :                 pos += ETH_ALEN;
     303                 :            :         }
     304                 :            : 
     305                 :          0 :         *len = pos - len - 1;
     306                 :            : #endif /* CONFIG_INTERWORKING */
     307                 :            : 
     308                 :          2 :         return pos;
     309                 :            : }
     310                 :            : 
     311                 :            : 
     312                 :          2 : u8 * hostapd_eid_adv_proto(struct hostapd_data *hapd, u8 *eid)
     313                 :            : {
     314                 :          2 :         u8 *pos = eid;
     315                 :            : #ifdef CONFIG_INTERWORKING
     316                 :            : 
     317                 :            :         /* TODO: Separate configuration for ANQP? */
     318         [ +  - ]:          2 :         if (!hapd->conf->interworking)
     319                 :          2 :                 return eid;
     320                 :            : 
     321                 :          0 :         *pos++ = WLAN_EID_ADV_PROTO;
     322                 :          0 :         *pos++ = 2;
     323                 :          0 :         *pos++ = 0x7F; /* Query Response Length Limit | PAME-BI */
     324                 :          0 :         *pos++ = ACCESS_NETWORK_QUERY_PROTOCOL;
     325                 :            : #endif /* CONFIG_INTERWORKING */
     326                 :            : 
     327                 :          2 :         return pos;
     328                 :            : }
     329                 :            : 
     330                 :            : 
     331                 :          2 : u8 * hostapd_eid_roaming_consortium(struct hostapd_data *hapd, u8 *eid)
     332                 :            : {
     333                 :          2 :         u8 *pos = eid;
     334                 :            : #ifdef CONFIG_INTERWORKING
     335                 :            :         u8 *len;
     336                 :            :         unsigned int i, count;
     337                 :            : 
     338 [ -  + ][ #  # ]:          2 :         if (!hapd->conf->interworking ||
     339         [ #  # ]:          0 :             hapd->conf->roaming_consortium == NULL ||
     340                 :          0 :             hapd->conf->roaming_consortium_count == 0)
     341                 :          2 :                 return eid;
     342                 :            : 
     343                 :          0 :         *pos++ = WLAN_EID_ROAMING_CONSORTIUM;
     344                 :          0 :         len = pos++;
     345                 :            : 
     346                 :            :         /* Number of ANQP OIs (in addition to the max 3 listed here) */
     347         [ #  # ]:          0 :         if (hapd->conf->roaming_consortium_count > 3 + 255)
     348                 :          0 :                 *pos++ = 255;
     349         [ #  # ]:          0 :         else if (hapd->conf->roaming_consortium_count > 3)
     350                 :          0 :                 *pos++ = hapd->conf->roaming_consortium_count - 3;
     351                 :            :         else
     352                 :          0 :                 *pos++ = 0;
     353                 :            : 
     354                 :            :         /* OU #1 and #2 Lengths */
     355                 :          0 :         *pos = hapd->conf->roaming_consortium[0].len;
     356         [ #  # ]:          0 :         if (hapd->conf->roaming_consortium_count > 1)
     357                 :          0 :                 *pos |= hapd->conf->roaming_consortium[1].len << 4;
     358                 :          0 :         pos++;
     359                 :            : 
     360         [ #  # ]:          0 :         if (hapd->conf->roaming_consortium_count > 3)
     361                 :          0 :                 count = 3;
     362                 :            :         else
     363                 :          0 :                 count = hapd->conf->roaming_consortium_count;
     364                 :            : 
     365         [ #  # ]:          0 :         for (i = 0; i < count; i++) {
     366                 :          0 :                 os_memcpy(pos, hapd->conf->roaming_consortium[i].oi,
     367                 :            :                           hapd->conf->roaming_consortium[i].len);
     368                 :          0 :                 pos += hapd->conf->roaming_consortium[i].len;
     369                 :            :         }
     370                 :            : 
     371                 :          0 :         *len = pos - len - 1;
     372                 :            : #endif /* CONFIG_INTERWORKING */
     373                 :            : 
     374                 :          2 :         return pos;
     375                 :            : }
     376                 :            : 
     377                 :            : 
     378                 :          2 : u8 * hostapd_eid_time_adv(struct hostapd_data *hapd, u8 *eid)
     379                 :            : {
     380         [ +  - ]:          2 :         if (hapd->conf->time_advertisement != 2)
     381                 :          2 :                 return eid;
     382                 :            : 
     383   [ #  #  #  # ]:          0 :         if (hapd->time_adv == NULL &&
     384                 :          0 :             hostapd_update_time_adv(hapd) < 0)
     385                 :          0 :                 return eid;
     386                 :            : 
     387         [ #  # ]:          0 :         if (hapd->time_adv == NULL)
     388                 :          0 :                 return eid;
     389                 :            : 
     390                 :          0 :         os_memcpy(eid, wpabuf_head(hapd->time_adv),
     391                 :            :                   wpabuf_len(hapd->time_adv));
     392                 :          0 :         eid += wpabuf_len(hapd->time_adv);
     393                 :            : 
     394                 :          2 :         return eid;
     395                 :            : }
     396                 :            : 
     397                 :            : 
     398                 :          1 : u8 * hostapd_eid_time_zone(struct hostapd_data *hapd, u8 *eid)
     399                 :            : {
     400                 :            :         size_t len;
     401                 :            : 
     402         [ +  - ]:          1 :         if (hapd->conf->time_advertisement != 2)
     403                 :          1 :                 return eid;
     404                 :            : 
     405                 :          0 :         len = os_strlen(hapd->conf->time_zone);
     406                 :            : 
     407                 :          0 :         *eid++ = WLAN_EID_TIME_ZONE;
     408                 :          0 :         *eid++ = len;
     409                 :          0 :         os_memcpy(eid, hapd->conf->time_zone, len);
     410                 :          0 :         eid += len;
     411                 :            : 
     412                 :          1 :         return eid;
     413                 :            : }
     414                 :            : 
     415                 :            : 
     416                 :          0 : int hostapd_update_time_adv(struct hostapd_data *hapd)
     417                 :            : {
     418                 :          0 :         const int elen = 2 + 1 + 10 + 5 + 1;
     419                 :            :         struct os_time t;
     420                 :            :         struct os_tm tm;
     421                 :            :         u8 *pos;
     422                 :            : 
     423         [ #  # ]:          0 :         if (hapd->conf->time_advertisement != 2)
     424                 :          0 :                 return 0;
     425                 :            : 
     426 [ #  # ][ #  # ]:          0 :         if (os_get_time(&t) < 0 || os_gmtime(t.sec, &tm) < 0)
     427                 :          0 :                 return -1;
     428                 :            : 
     429         [ #  # ]:          0 :         if (!hapd->time_adv) {
     430                 :          0 :                 hapd->time_adv = wpabuf_alloc(elen);
     431         [ #  # ]:          0 :                 if (hapd->time_adv == NULL)
     432                 :          0 :                         return -1;
     433                 :          0 :                 pos = wpabuf_put(hapd->time_adv, elen);
     434                 :            :         } else
     435                 :          0 :                 pos = wpabuf_mhead_u8(hapd->time_adv);
     436                 :            : 
     437                 :          0 :         *pos++ = WLAN_EID_TIME_ADVERTISEMENT;
     438                 :          0 :         *pos++ = 1 + 10 + 5 + 1;
     439                 :            : 
     440                 :          0 :         *pos++ = 2; /* UTC time at which the TSF timer is 0 */
     441                 :            : 
     442                 :            :         /* Time Value at TSF 0 */
     443                 :            :         /* FIX: need to calculate this based on the current TSF value */
     444                 :          0 :         WPA_PUT_LE16(pos, tm.year); /* Year */
     445                 :          0 :         pos += 2;
     446                 :          0 :         *pos++ = tm.month; /* Month */
     447                 :          0 :         *pos++ = tm.day; /* Day of month */
     448                 :          0 :         *pos++ = tm.hour; /* Hours */
     449                 :          0 :         *pos++ = tm.min; /* Minutes */
     450                 :          0 :         *pos++ = tm.sec; /* Seconds */
     451                 :          0 :         WPA_PUT_LE16(pos, 0); /* Milliseconds (not used) */
     452                 :          0 :         pos += 2;
     453                 :          0 :         *pos++ = 0; /* Reserved */
     454                 :            : 
     455                 :            :         /* Time Error */
     456                 :            :         /* TODO: fill in an estimate on the error */
     457                 :          0 :         *pos++ = 0;
     458                 :          0 :         *pos++ = 0;
     459                 :          0 :         *pos++ = 0;
     460                 :          0 :         *pos++ = 0;
     461                 :          0 :         *pos++ = 0;
     462                 :            : 
     463                 :          0 :         *pos++ = hapd->time_update_counter++;
     464                 :            : 
     465                 :          0 :         return 0;
     466                 :            : }
     467                 :            : 
     468                 :            : 
     469                 :          0 : u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid)
     470                 :            : {
     471                 :          0 :         u8 *pos = eid;
     472                 :            : 
     473                 :            : #ifdef CONFIG_WNM
     474         [ #  # ]:          0 :         if (hapd->conf->ap_max_inactivity > 0) {
     475                 :            :                 unsigned int val;
     476                 :          0 :                 *pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
     477                 :          0 :                 *pos++ = 3;
     478                 :          0 :                 val = hapd->conf->ap_max_inactivity;
     479         [ #  # ]:          0 :                 if (val > 68000)
     480                 :          0 :                         val = 68000;
     481                 :          0 :                 val *= 1000;
     482                 :          0 :                 val /= 1024;
     483         [ #  # ]:          0 :                 if (val == 0)
     484                 :          0 :                         val = 1;
     485         [ #  # ]:          0 :                 if (val > 65535)
     486                 :          0 :                         val = 65535;
     487                 :          0 :                 WPA_PUT_LE16(pos, val);
     488                 :          0 :                 pos += 2;
     489                 :          0 :                 *pos++ = 0x00; /* TODO: Protected Keep-Alive Required */
     490                 :            :         }
     491                 :            : #endif /* CONFIG_WNM */
     492                 :            : 
     493                 :          0 :         return pos;
     494                 :            : }

Generated by: LCOV version 1.9