LCOV - code coverage report
Current view: top level - src/ap - ieee802_11_shared.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 206 276 74.6 %
Date: 2014-03-02 Functions: 12 14 85.7 %
Branches: 99 148 66.9 %

           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                 :          2 : 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                 :          2 :         wpa_printf(MSG_DEBUG, "IEEE 802.11: Sending SA Query Request to "
      56                 :         12 :                    MACSTR, MAC2STR(addr));
      57                 :          2 :         wpa_hexdump(MSG_DEBUG, "IEEE 802.11: SA Query Transaction ID",
      58                 :            :                     trans_id, WLAN_SA_QUERY_TR_ID_LEN);
      59                 :            : 
      60                 :          2 :         os_memset(&mgmt, 0, sizeof(mgmt));
      61                 :          2 :         mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
      62                 :            :                                           WLAN_FC_STYPE_ACTION);
      63                 :          2 :         os_memcpy(mgmt.da, addr, ETH_ALEN);
      64                 :          2 :         os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
      65                 :          2 :         os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
      66                 :          2 :         mgmt.u.action.category = WLAN_ACTION_SA_QUERY;
      67                 :          2 :         mgmt.u.action.u.sa_query_req.action = WLAN_SA_QUERY_REQUEST;
      68                 :          2 :         os_memcpy(mgmt.u.action.u.sa_query_req.trans_id, trans_id,
      69                 :            :                   WLAN_SA_QUERY_TR_ID_LEN);
      70                 :          2 :         end = mgmt.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
      71         [ -  + ]:          2 :         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                 :          2 : }
      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                 :          2 : 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         [ -  + ]:          2 :         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         [ -  + ]:          2 :         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                 :          2 :         wpa_printf(MSG_DEBUG, "IEEE 802.11: Received SA Query Response from "
     132                 :         12 :                    MACSTR, MAC2STR(sa));
     133                 :          2 :         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                 :          2 :         sta = ap_get_sta(hapd, sa);
     139 [ +  - ][ +  - ]:          2 :         if (sta == NULL || sta->sa_query_trans_id == NULL) {
     140                 :          2 :                 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
     141                 :            :                            "pending SA Query request found");
     142                 :          2 :                 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                 :          2 :         ap_sta_stop_sa_query(hapd, sta);
     162                 :            : }
     163                 :            : 
     164                 :            : #endif /* CONFIG_IEEE80211W */
     165                 :            : 
     166                 :            : 
     167                 :      32600 : static void hostapd_ext_capab_byte(struct hostapd_data *hapd, u8 *pos, int idx)
     168                 :            : {
     169                 :      32600 :         *pos = 0x00;
     170                 :            : 
     171   [ +  +  +  +  :      32600 :         switch (idx) {
             +  +  +  + ]
     172                 :            :         case 0: /* Bits 0-7 */
     173                 :       4076 :                 break;
     174                 :            :         case 1: /* Bits 8-15 */
     175                 :       4076 :                 break;
     176                 :            :         case 2: /* Bits 16-23 */
     177         [ +  + ]:       4076 :                 if (hapd->conf->wnm_sleep_mode)
     178                 :         28 :                         *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
     179         [ +  + ]:       4076 :                 if (hapd->conf->bss_transition)
     180                 :         34 :                         *pos |= 0x08; /* Bit 19 - BSS Transition */
     181                 :       4076 :                 break;
     182                 :            :         case 3: /* Bits 24-31 */
     183                 :            : #ifdef CONFIG_WNM
     184                 :       4076 :                 *pos |= 0x02; /* Bit 25 - SSID List */
     185                 :            : #endif /* CONFIG_WNM */
     186         [ +  + ]:       4076 :                 if (hapd->conf->time_advertisement == 2)
     187                 :         28 :                         *pos |= 0x08; /* Bit 27 - UTC TSF Offset */
     188         [ +  + ]:       4076 :                 if (hapd->conf->interworking)
     189                 :        436 :                         *pos |= 0x80; /* Bit 31 - Interworking */
     190                 :       4076 :                 break;
     191                 :            :         case 4: /* Bits 32-39 */
     192         [ +  + ]:       4074 :                 if (hapd->conf->qos_map_set_len)
     193                 :          4 :                         *pos |= 0x01; /* Bit 32 - QoS Map */
     194         [ -  + ]:       4074 :                 if (hapd->conf->tdls & TDLS_PROHIBIT)
     195                 :          0 :                         *pos |= 0x40; /* Bit 38 - TDLS Prohibited */
     196         [ -  + ]:       4074 :                 if (hapd->conf->tdls & TDLS_PROHIBIT_CHAN_SWITCH) {
     197                 :            :                         /* Bit 39 - TDLS Channel Switching Prohibited */
     198                 :          0 :                         *pos |= 0x80;
     199                 :            :                 }
     200                 :       4074 :                 break;
     201                 :            :         case 5: /* Bits 40-47 */
     202                 :            : #ifdef CONFIG_HS20
     203         [ +  + ]:       4074 :                 if (hapd->conf->hs20)
     204                 :        436 :                         *pos |= 0x40; /* Bit 46 - WNM-Notification */
     205                 :            : #endif /* CONFIG_HS20 */
     206                 :       4074 :                 break;
     207                 :            :         case 6: /* Bits 48-55 */
     208         [ +  + ]:       4074 :                 if (hapd->conf->ssid.utf8_ssid)
     209                 :          6 :                         *pos |= 0x01; /* Bit 48 - UTF-8 SSID */
     210                 :       4074 :                 break;
     211                 :            :         }
     212                 :      32600 : }
     213                 :            : 
     214                 :            : 
     215                 :       4076 : u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
     216                 :            : {
     217                 :       4076 :         u8 *pos = eid;
     218                 :       4076 :         u8 len = 0, i;
     219                 :            : 
     220         [ -  + ]:       4076 :         if (hapd->conf->tdls & (TDLS_PROHIBIT | TDLS_PROHIBIT_CHAN_SWITCH))
     221                 :          0 :                 len = 5;
     222 [ +  - ][ +  + ]:       4076 :         if (len < 4 && hapd->conf->interworking)
     223                 :        436 :                 len = 4;
     224 [ +  + ][ +  + ]:       4076 :         if (len < 3 && hapd->conf->wnm_sleep_mode)
     225                 :         28 :                 len = 3;
     226 [ +  - ][ +  + ]:       4076 :         if (len < 7 && hapd->conf->ssid.utf8_ssid)
     227                 :          6 :                 len = 7;
     228                 :            : #ifdef CONFIG_WNM
     229         [ +  + ]:       4076 :         if (len < 4)
     230                 :       3634 :                 len = 4;
     231                 :            : #endif /* CONFIG_WNM */
     232                 :            : #ifdef CONFIG_HS20
     233 [ +  + ][ +  - ]:       4076 :         if (hapd->conf->hs20 && len < 6)
     234                 :        436 :                 len = 6;
     235                 :            : #endif /* CONFIG_HS20 */
     236         [ +  + ]:       4076 :         if (len < hapd->iface->extended_capa_len)
     237                 :       4074 :                 len = hapd->iface->extended_capa_len;
     238         [ -  + ]:       4076 :         if (len == 0)
     239                 :          0 :                 return eid;
     240                 :            : 
     241                 :       4076 :         *pos++ = WLAN_EID_EXT_CAPAB;
     242                 :       4076 :         *pos++ = len;
     243         [ +  + ]:      36676 :         for (i = 0; i < len; i++, pos++) {
     244                 :      32600 :                 hostapd_ext_capab_byte(hapd, pos, i);
     245                 :            : 
     246         [ +  + ]:      32600 :                 if (i < hapd->iface->extended_capa_len) {
     247                 :      32592 :                         *pos &= ~hapd->iface->extended_capa_mask[i];
     248                 :      32592 :                         *pos |= hapd->iface->extended_capa[i];
     249                 :            :                 }
     250                 :            :         }
     251                 :            : 
     252 [ +  - ][ -  + ]:       4076 :         while (len > 0 && eid[1 + len] == 0) {
     253                 :          0 :                 len--;
     254                 :          0 :                 eid[1] = len;
     255                 :            :         }
     256         [ -  + ]:       4076 :         if (len == 0)
     257                 :          0 :                 return eid;
     258                 :            : 
     259                 :       4076 :         return eid + 2 + len;
     260                 :            : }
     261                 :            : 
     262                 :            : 
     263                 :        666 : u8 * hostapd_eid_qos_map_set(struct hostapd_data *hapd, u8 *eid)
     264                 :            : {
     265                 :        666 :         u8 *pos = eid;
     266                 :        666 :         u8 len = hapd->conf->qos_map_set_len;
     267                 :            : 
     268         [ +  + ]:        666 :         if (!len)
     269                 :        665 :                 return eid;
     270                 :            : 
     271                 :          1 :         *pos++ = WLAN_EID_QOS_MAP_SET;
     272                 :          1 :         *pos++ = len;
     273                 :          1 :         os_memcpy(pos, hapd->conf->qos_map_set, len);
     274                 :          1 :         pos += len;
     275                 :            : 
     276                 :        666 :         return pos;
     277                 :            : }
     278                 :            : 
     279                 :            : 
     280                 :       3402 : u8 * hostapd_eid_interworking(struct hostapd_data *hapd, u8 *eid)
     281                 :            : {
     282                 :       3402 :         u8 *pos = eid;
     283                 :            : #ifdef CONFIG_INTERWORKING
     284                 :            :         u8 *len;
     285                 :            : 
     286         [ +  + ]:       3402 :         if (!hapd->conf->interworking)
     287                 :       3040 :                 return eid;
     288                 :            : 
     289                 :        362 :         *pos++ = WLAN_EID_INTERWORKING;
     290                 :        362 :         len = pos++;
     291                 :            : 
     292                 :        362 :         *pos = hapd->conf->access_network_type;
     293         [ +  - ]:        362 :         if (hapd->conf->internet)
     294                 :        362 :                 *pos |= INTERWORKING_ANO_INTERNET;
     295         [ -  + ]:        362 :         if (hapd->conf->asra)
     296                 :          0 :                 *pos |= INTERWORKING_ANO_ASRA;
     297         [ -  + ]:        362 :         if (hapd->conf->esr)
     298                 :          0 :                 *pos |= INTERWORKING_ANO_ESR;
     299         [ -  + ]:        362 :         if (hapd->conf->uesa)
     300                 :          0 :                 *pos |= INTERWORKING_ANO_UESA;
     301                 :        362 :         pos++;
     302                 :            : 
     303         [ +  + ]:        362 :         if (hapd->conf->venue_info_set) {
     304                 :        358 :                 *pos++ = hapd->conf->venue_group;
     305                 :        358 :                 *pos++ = hapd->conf->venue_type;
     306                 :            :         }
     307                 :            : 
     308         [ +  + ]:        362 :         if (!is_zero_ether_addr(hapd->conf->hessid)) {
     309                 :        150 :                 os_memcpy(pos, hapd->conf->hessid, ETH_ALEN);
     310                 :        150 :                 pos += ETH_ALEN;
     311                 :            :         }
     312                 :            : 
     313                 :        362 :         *len = pos - len - 1;
     314                 :            : #endif /* CONFIG_INTERWORKING */
     315                 :            : 
     316                 :       3402 :         return pos;
     317                 :            : }
     318                 :            : 
     319                 :            : 
     320                 :       3402 : u8 * hostapd_eid_adv_proto(struct hostapd_data *hapd, u8 *eid)
     321                 :            : {
     322                 :       3402 :         u8 *pos = eid;
     323                 :            : #ifdef CONFIG_INTERWORKING
     324                 :            : 
     325                 :            :         /* TODO: Separate configuration for ANQP? */
     326         [ +  + ]:       3402 :         if (!hapd->conf->interworking)
     327                 :       3040 :                 return eid;
     328                 :            : 
     329                 :        362 :         *pos++ = WLAN_EID_ADV_PROTO;
     330                 :        362 :         *pos++ = 2;
     331                 :        362 :         *pos++ = 0x7F; /* Query Response Length Limit | PAME-BI */
     332                 :        362 :         *pos++ = ACCESS_NETWORK_QUERY_PROTOCOL;
     333                 :            : #endif /* CONFIG_INTERWORKING */
     334                 :            : 
     335                 :       3402 :         return pos;
     336                 :            : }
     337                 :            : 
     338                 :            : 
     339                 :       3402 : u8 * hostapd_eid_roaming_consortium(struct hostapd_data *hapd, u8 *eid)
     340                 :            : {
     341                 :       3402 :         u8 *pos = eid;
     342                 :            : #ifdef CONFIG_INTERWORKING
     343                 :            :         u8 *len;
     344                 :            :         unsigned int i, count;
     345                 :            : 
     346 [ +  + ][ +  - ]:       3402 :         if (!hapd->conf->interworking ||
     347         [ -  + ]:        362 :             hapd->conf->roaming_consortium == NULL ||
     348                 :        362 :             hapd->conf->roaming_consortium_count == 0)
     349                 :       3040 :                 return eid;
     350                 :            : 
     351                 :        362 :         *pos++ = WLAN_EID_ROAMING_CONSORTIUM;
     352                 :        362 :         len = pos++;
     353                 :            : 
     354                 :            :         /* Number of ANQP OIs (in addition to the max 3 listed here) */
     355         [ -  + ]:        362 :         if (hapd->conf->roaming_consortium_count > 3 + 255)
     356                 :          0 :                 *pos++ = 255;
     357         [ +  + ]:        362 :         else if (hapd->conf->roaming_consortium_count > 3)
     358                 :        346 :                 *pos++ = hapd->conf->roaming_consortium_count - 3;
     359                 :            :         else
     360                 :         16 :                 *pos++ = 0;
     361                 :            : 
     362                 :            :         /* OU #1 and #2 Lengths */
     363                 :        362 :         *pos = hapd->conf->roaming_consortium[0].len;
     364         [ +  + ]:        362 :         if (hapd->conf->roaming_consortium_count > 1)
     365                 :        346 :                 *pos |= hapd->conf->roaming_consortium[1].len << 4;
     366                 :        362 :         pos++;
     367                 :            : 
     368         [ +  + ]:        362 :         if (hapd->conf->roaming_consortium_count > 3)
     369                 :        346 :                 count = 3;
     370                 :            :         else
     371                 :         16 :                 count = hapd->conf->roaming_consortium_count;
     372                 :            : 
     373         [ +  + ]:       1416 :         for (i = 0; i < count; i++) {
     374                 :       1054 :                 os_memcpy(pos, hapd->conf->roaming_consortium[i].oi,
     375                 :            :                           hapd->conf->roaming_consortium[i].len);
     376                 :       1054 :                 pos += hapd->conf->roaming_consortium[i].len;
     377                 :            :         }
     378                 :            : 
     379                 :        362 :         *len = pos - len - 1;
     380                 :            : #endif /* CONFIG_INTERWORKING */
     381                 :            : 
     382                 :       3402 :         return pos;
     383                 :            : }
     384                 :            : 
     385                 :            : 
     386                 :       3402 : u8 * hostapd_eid_time_adv(struct hostapd_data *hapd, u8 *eid)
     387                 :            : {
     388         [ +  + ]:       3402 :         if (hapd->conf->time_advertisement != 2)
     389                 :       3380 :                 return eid;
     390                 :            : 
     391   [ +  +  -  + ]:         28 :         if (hapd->time_adv == NULL &&
     392                 :          6 :             hostapd_update_time_adv(hapd) < 0)
     393                 :          0 :                 return eid;
     394                 :            : 
     395         [ -  + ]:         22 :         if (hapd->time_adv == NULL)
     396                 :          0 :                 return eid;
     397                 :            : 
     398                 :         22 :         os_memcpy(eid, wpabuf_head(hapd->time_adv),
     399                 :            :                   wpabuf_len(hapd->time_adv));
     400                 :         22 :         eid += wpabuf_len(hapd->time_adv);
     401                 :            : 
     402                 :       3402 :         return eid;
     403                 :            : }
     404                 :            : 
     405                 :            : 
     406                 :       2245 : u8 * hostapd_eid_time_zone(struct hostapd_data *hapd, u8 *eid)
     407                 :            : {
     408                 :            :         size_t len;
     409                 :            : 
     410         [ +  + ]:       2245 :         if (hapd->conf->time_advertisement != 2)
     411                 :       2229 :                 return eid;
     412                 :            : 
     413                 :         16 :         len = os_strlen(hapd->conf->time_zone);
     414                 :            : 
     415                 :         16 :         *eid++ = WLAN_EID_TIME_ZONE;
     416                 :         16 :         *eid++ = len;
     417                 :         16 :         os_memcpy(eid, hapd->conf->time_zone, len);
     418                 :         16 :         eid += len;
     419                 :            : 
     420                 :       2245 :         return eid;
     421                 :            : }
     422                 :            : 
     423                 :            : 
     424                 :          6 : int hostapd_update_time_adv(struct hostapd_data *hapd)
     425                 :            : {
     426                 :          6 :         const int elen = 2 + 1 + 10 + 5 + 1;
     427                 :            :         struct os_time t;
     428                 :            :         struct os_tm tm;
     429                 :            :         u8 *pos;
     430                 :            : 
     431         [ -  + ]:          6 :         if (hapd->conf->time_advertisement != 2)
     432                 :          0 :                 return 0;
     433                 :            : 
     434 [ +  - ][ -  + ]:          6 :         if (os_get_time(&t) < 0 || os_gmtime(t.sec, &tm) < 0)
     435                 :          0 :                 return -1;
     436                 :            : 
     437         [ +  - ]:          6 :         if (!hapd->time_adv) {
     438                 :          6 :                 hapd->time_adv = wpabuf_alloc(elen);
     439         [ -  + ]:          6 :                 if (hapd->time_adv == NULL)
     440                 :          0 :                         return -1;
     441                 :          6 :                 pos = wpabuf_put(hapd->time_adv, elen);
     442                 :            :         } else
     443                 :          0 :                 pos = wpabuf_mhead_u8(hapd->time_adv);
     444                 :            : 
     445                 :          6 :         *pos++ = WLAN_EID_TIME_ADVERTISEMENT;
     446                 :          6 :         *pos++ = 1 + 10 + 5 + 1;
     447                 :            : 
     448                 :          6 :         *pos++ = 2; /* UTC time at which the TSF timer is 0 */
     449                 :            : 
     450                 :            :         /* Time Value at TSF 0 */
     451                 :            :         /* FIX: need to calculate this based on the current TSF value */
     452                 :          6 :         WPA_PUT_LE16(pos, tm.year); /* Year */
     453                 :          6 :         pos += 2;
     454                 :          6 :         *pos++ = tm.month; /* Month */
     455                 :          6 :         *pos++ = tm.day; /* Day of month */
     456                 :          6 :         *pos++ = tm.hour; /* Hours */
     457                 :          6 :         *pos++ = tm.min; /* Minutes */
     458                 :          6 :         *pos++ = tm.sec; /* Seconds */
     459                 :          6 :         WPA_PUT_LE16(pos, 0); /* Milliseconds (not used) */
     460                 :          6 :         pos += 2;
     461                 :          6 :         *pos++ = 0; /* Reserved */
     462                 :            : 
     463                 :            :         /* Time Error */
     464                 :            :         /* TODO: fill in an estimate on the error */
     465                 :          6 :         *pos++ = 0;
     466                 :          6 :         *pos++ = 0;
     467                 :          6 :         *pos++ = 0;
     468                 :          6 :         *pos++ = 0;
     469                 :          6 :         *pos++ = 0;
     470                 :            : 
     471                 :          6 :         *pos++ = hapd->time_update_counter++;
     472                 :            : 
     473                 :          6 :         return 0;
     474                 :            : }
     475                 :            : 
     476                 :            : 
     477                 :        674 : u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid)
     478                 :            : {
     479                 :        674 :         u8 *pos = eid;
     480                 :            : 
     481                 :            : #ifdef CONFIG_WNM
     482         [ +  - ]:        674 :         if (hapd->conf->ap_max_inactivity > 0) {
     483                 :            :                 unsigned int val;
     484                 :        674 :                 *pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
     485                 :        674 :                 *pos++ = 3;
     486                 :        674 :                 val = hapd->conf->ap_max_inactivity;
     487         [ -  + ]:        674 :                 if (val > 68000)
     488                 :          0 :                         val = 68000;
     489                 :        674 :                 val *= 1000;
     490                 :        674 :                 val /= 1024;
     491         [ -  + ]:        674 :                 if (val == 0)
     492                 :          0 :                         val = 1;
     493         [ -  + ]:        674 :                 if (val > 65535)
     494                 :          0 :                         val = 65535;
     495                 :        674 :                 WPA_PUT_LE16(pos, val);
     496                 :        674 :                 pos += 2;
     497                 :        674 :                 *pos++ = 0x00; /* TODO: Protected Keep-Alive Required */
     498                 :            :         }
     499                 :            : #endif /* CONFIG_WNM */
     500                 :            : 
     501                 :        674 :         return pos;
     502                 :            : }

Generated by: LCOV version 1.9