LCOV - code coverage report
Current view: top level - src/common - ieee802_11_common.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 533 610 87.4 %
Date: 2015-09-27 Functions: 21 21 100.0 %

          Line data    Source code
       1             : /*
       2             :  * IEEE 802.11 Common routines
       3             :  * Copyright (c) 2002-2015, 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 "includes.h"
      10             : 
      11             : #include "common.h"
      12             : #include "defs.h"
      13             : #include "wpa_common.h"
      14             : #include "qca-vendor.h"
      15             : #include "ieee802_11_defs.h"
      16             : #include "ieee802_11_common.h"
      17             : 
      18             : 
      19       65709 : static int ieee802_11_parse_vendor_specific(const u8 *pos, size_t elen,
      20             :                                             struct ieee802_11_elems *elems,
      21             :                                             int show_errors)
      22             : {
      23             :         unsigned int oui;
      24             : 
      25             :         /* first 3 bytes in vendor specific information element are the IEEE
      26             :          * OUI of the vendor. The following byte is used a vendor specific
      27             :          * sub-type. */
      28       65709 :         if (elen < 4) {
      29           3 :                 if (show_errors) {
      30           1 :                         wpa_printf(MSG_MSGDUMP, "short vendor specific "
      31             :                                    "information element ignored (len=%lu)",
      32             :                                    (unsigned long) elen);
      33             :                 }
      34           3 :                 return -1;
      35             :         }
      36             : 
      37       65706 :         oui = WPA_GET_BE24(pos);
      38       65706 :         switch (oui) {
      39             :         case OUI_MICROSOFT:
      40             :                 /* Microsoft/Wi-Fi information elements are further typed and
      41             :                  * subtyped */
      42       48839 :                 switch (pos[3]) {
      43             :                 case 1:
      44             :                         /* Microsoft OUI (00:50:F2) with OUI Type 1:
      45             :                          * real WPA information element */
      46         347 :                         elems->wpa_ie = pos;
      47         347 :                         elems->wpa_ie_len = elen;
      48         347 :                         break;
      49             :                 case WMM_OUI_TYPE:
      50             :                         /* WMM information element */
      51       31077 :                         if (elen < 5) {
      52           1 :                                 wpa_printf(MSG_MSGDUMP, "short WMM "
      53             :                                            "information element ignored "
      54             :                                            "(len=%lu)",
      55             :                                            (unsigned long) elen);
      56           1 :                                 return -1;
      57             :                         }
      58       31076 :                         switch (pos[4]) {
      59             :                         case WMM_OUI_SUBTYPE_INFORMATION_ELEMENT:
      60             :                         case WMM_OUI_SUBTYPE_PARAMETER_ELEMENT:
      61             :                                 /*
      62             :                                  * Share same pointer since only one of these
      63             :                                  * is used and they start with same data.
      64             :                                  * Length field can be used to distinguish the
      65             :                                  * IEs.
      66             :                                  */
      67       31055 :                                 elems->wmm = pos;
      68       31055 :                                 elems->wmm_len = elen;
      69       31055 :                                 break;
      70             :                         case WMM_OUI_SUBTYPE_TSPEC_ELEMENT:
      71          20 :                                 elems->wmm_tspec = pos;
      72          20 :                                 elems->wmm_tspec_len = elen;
      73          20 :                                 break;
      74             :                         default:
      75           1 :                                 wpa_printf(MSG_EXCESSIVE, "unknown WMM "
      76             :                                            "information element ignored "
      77             :                                            "(subtype=%d len=%lu)",
      78           1 :                                            pos[4], (unsigned long) elen);
      79           1 :                                 return -1;
      80             :                         }
      81       31075 :                         break;
      82             :                 case 4:
      83             :                         /* Wi-Fi Protected Setup (WPS) IE */
      84       17414 :                         elems->wps_ie = pos;
      85       17414 :                         elems->wps_ie_len = elen;
      86       17414 :                         break;
      87             :                 default:
      88           1 :                         wpa_printf(MSG_EXCESSIVE, "Unknown Microsoft "
      89             :                                    "information element ignored "
      90             :                                    "(type=%d len=%lu)",
      91           1 :                                    pos[3], (unsigned long) elen);
      92           1 :                         return -1;
      93             :                 }
      94       48836 :                 break;
      95             : 
      96             :         case OUI_WFA:
      97       16790 :                 switch (pos[3]) {
      98             :                 case P2P_OUI_TYPE:
      99             :                         /* Wi-Fi Alliance - P2P IE */
     100       14577 :                         elems->p2p = pos;
     101       14577 :                         elems->p2p_len = elen;
     102       14577 :                         break;
     103             :                 case WFD_OUI_TYPE:
     104             :                         /* Wi-Fi Alliance - WFD IE */
     105         309 :                         elems->wfd = pos;
     106         309 :                         elems->wfd_len = elen;
     107         309 :                         break;
     108             :                 case HS20_INDICATION_OUI_TYPE:
     109             :                         /* Hotspot 2.0 */
     110        1888 :                         elems->hs20 = pos;
     111        1888 :                         elems->hs20_len = elen;
     112        1888 :                         break;
     113             :                 case HS20_OSEN_OUI_TYPE:
     114             :                         /* Hotspot 2.0 OSEN */
     115          15 :                         elems->osen = pos;
     116          15 :                         elems->osen_len = elen;
     117          15 :                         break;
     118             :                 default:
     119           1 :                         wpa_printf(MSG_MSGDUMP, "Unknown WFA "
     120             :                                    "information element ignored "
     121             :                                    "(type=%d len=%lu)",
     122           1 :                                    pos[3], (unsigned long) elen);
     123           1 :                         return -1;
     124             :                 }
     125       16789 :                 break;
     126             : 
     127             :         case OUI_BROADCOM:
     128          13 :                 switch (pos[3]) {
     129             :                 case VENDOR_HT_CAPAB_OUI_TYPE:
     130           2 :                         elems->vendor_ht_cap = pos;
     131           2 :                         elems->vendor_ht_cap_len = elen;
     132           2 :                         break;
     133             :                 case VENDOR_VHT_TYPE:
     134          19 :                         if (elen > 4 &&
     135          12 :                             (pos[4] == VENDOR_VHT_SUBTYPE ||
     136           3 :                              pos[4] == VENDOR_VHT_SUBTYPE2)) {
     137           9 :                                 elems->vendor_vht = pos;
     138           9 :                                 elems->vendor_vht_len = elen;
     139             :                         } else
     140           1 :                                 return -1;
     141           9 :                         break;
     142             :                 default:
     143           1 :                         wpa_printf(MSG_EXCESSIVE, "Unknown Broadcom "
     144             :                                    "information element ignored "
     145             :                                    "(type=%d len=%lu)",
     146           1 :                                    pos[3], (unsigned long) elen);
     147           1 :                         return -1;
     148             :                 }
     149          11 :                 break;
     150             : 
     151             :         case OUI_QCA:
     152           0 :                 switch (pos[3]) {
     153             :                 case QCA_VENDOR_ELEM_P2P_PREF_CHAN_LIST:
     154           0 :                         elems->pref_freq_list = pos;
     155           0 :                         elems->pref_freq_list_len = elen;
     156           0 :                         break;
     157             :                 default:
     158           0 :                         wpa_printf(MSG_EXCESSIVE,
     159             :                                    "Unknown QCA information element ignored (type=%d len=%lu)",
     160           0 :                                    pos[3], (unsigned long) elen);
     161           0 :                         return -1;
     162             :                 }
     163           0 :                 break;
     164             : 
     165             :         default:
     166         192 :                 wpa_printf(MSG_EXCESSIVE, "unknown vendor specific "
     167             :                            "information element ignored (vendor OUI "
     168             :                            "%02x:%02x:%02x len=%lu)",
     169         192 :                            pos[0], pos[1], pos[2], (unsigned long) elen);
     170          64 :                 return -1;
     171             :         }
     172             : 
     173       65636 :         return 0;
     174             : }
     175             : 
     176             : 
     177             : /**
     178             :  * ieee802_11_parse_elems - Parse information elements in management frames
     179             :  * @start: Pointer to the start of IEs
     180             :  * @len: Length of IE buffer in octets
     181             :  * @elems: Data structure for parsed elements
     182             :  * @show_errors: Whether to show parsing errors in debug log
     183             :  * Returns: Parsing result
     184             :  */
     185       45691 : ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
     186             :                                 struct ieee802_11_elems *elems,
     187             :                                 int show_errors)
     188             : {
     189       45691 :         size_t left = len;
     190       45691 :         const u8 *pos = start;
     191       45691 :         int unknown = 0;
     192             : 
     193       45691 :         os_memset(elems, 0, sizeof(*elems));
     194             : 
     195      456900 :         while (left >= 2) {
     196             :                 u8 id, elen;
     197             : 
     198      365521 :                 id = *pos++;
     199      365521 :                 elen = *pos++;
     200      365521 :                 left -= 2;
     201             : 
     202      365521 :                 if (elen > left) {
     203           3 :                         if (show_errors) {
     204           2 :                                 wpa_printf(MSG_DEBUG, "IEEE 802.11 element "
     205             :                                            "parse failed (id=%d elen=%d "
     206             :                                            "left=%lu)",
     207             :                                            id, elen, (unsigned long) left);
     208           2 :                                 wpa_hexdump(MSG_MSGDUMP, "IEs", start, len);
     209             :                         }
     210           3 :                         return ParseFailed;
     211             :                 }
     212             : 
     213      365518 :                 switch (id) {
     214             :                 case WLAN_EID_SSID:
     215       28548 :                         if (elen > SSID_MAX_LEN) {
     216           2 :                                 wpa_printf(MSG_DEBUG,
     217             :                                            "Ignored too long SSID element (elen=%u)",
     218             :                                            elen);
     219           2 :                                 break;
     220             :                         }
     221       28546 :                         elems->ssid = pos;
     222       28546 :                         elems->ssid_len = elen;
     223       28546 :                         break;
     224             :                 case WLAN_EID_SUPP_RATES:
     225       41572 :                         elems->supp_rates = pos;
     226       41572 :                         elems->supp_rates_len = elen;
     227       41572 :                         break;
     228             :                 case WLAN_EID_DS_PARAMS:
     229       24207 :                         if (elen < 1)
     230           1 :                                 break;
     231       24206 :                         elems->ds_params = pos;
     232       24206 :                         break;
     233             :                 case WLAN_EID_CF_PARAMS:
     234             :                 case WLAN_EID_TIM:
     235        8763 :                         break;
     236             :                 case WLAN_EID_CHALLENGE:
     237           1 :                         elems->challenge = pos;
     238           1 :                         elems->challenge_len = elen;
     239           1 :                         break;
     240             :                 case WLAN_EID_ERP_INFO:
     241       13916 :                         if (elen < 1)
     242           1 :                                 break;
     243       13915 :                         elems->erp_info = pos;
     244       13915 :                         break;
     245             :                 case WLAN_EID_EXT_SUPP_RATES:
     246       31776 :                         elems->ext_supp_rates = pos;
     247       31776 :                         elems->ext_supp_rates_len = elen;
     248       31776 :                         break;
     249             :                 case WLAN_EID_VENDOR_SPECIFIC:
     250       65709 :                         if (ieee802_11_parse_vendor_specific(pos, elen,
     251             :                                                              elems,
     252             :                                                              show_errors))
     253          73 :                                 unknown++;
     254       65709 :                         break;
     255             :                 case WLAN_EID_RSN:
     256       14235 :                         elems->rsn_ie = pos;
     257       14235 :                         elems->rsn_ie_len = elen;
     258       14235 :                         break;
     259             :                 case WLAN_EID_PWR_CAPABILITY:
     260           2 :                         break;
     261             :                 case WLAN_EID_SUPPORTED_CHANNELS:
     262           1 :                         elems->supp_channels = pos;
     263           1 :                         elems->supp_channels_len = elen;
     264           1 :                         break;
     265             :                 case WLAN_EID_MOBILITY_DOMAIN:
     266        2688 :                         if (elen < sizeof(struct rsn_mdie))
     267           1 :                                 break;
     268        2687 :                         elems->mdie = pos;
     269        2687 :                         elems->mdie_len = elen;
     270        2687 :                         break;
     271             :                 case WLAN_EID_FAST_BSS_TRANSITION:
     272        1529 :                         if (elen < sizeof(struct rsn_ftie))
     273           1 :                                 break;
     274        1528 :                         elems->ftie = pos;
     275        1528 :                         elems->ftie_len = elen;
     276        1528 :                         break;
     277             :                 case WLAN_EID_TIMEOUT_INTERVAL:
     278           2 :                         if (elen != 5)
     279           2 :                                 break;
     280           0 :                         elems->timeout_int = pos;
     281           0 :                         break;
     282             :                 case WLAN_EID_HT_CAP:
     283       40288 :                         if (elen < sizeof(struct ieee80211_ht_capabilities))
     284           1 :                                 break;
     285       40287 :                         elems->ht_capabilities = pos;
     286       40287 :                         break;
     287             :                 case WLAN_EID_HT_OPERATION:
     288       27200 :                         if (elen < sizeof(struct ieee80211_ht_operation))
     289           1 :                                 break;
     290       27199 :                         elems->ht_operation = pos;
     291       27199 :                         break;
     292             :                 case WLAN_EID_MESH_CONFIG:
     293         142 :                         elems->mesh_config = pos;
     294         142 :                         elems->mesh_config_len = elen;
     295         142 :                         break;
     296             :                 case WLAN_EID_MESH_ID:
     297        6043 :                         elems->mesh_id = pos;
     298        6043 :                         elems->mesh_id_len = elen;
     299        6043 :                         break;
     300             :                 case WLAN_EID_PEER_MGMT:
     301         110 :                         elems->peer_mgmt = pos;
     302         110 :                         elems->peer_mgmt_len = elen;
     303         110 :                         break;
     304             :                 case WLAN_EID_VHT_CAP:
     305         367 :                         if (elen < sizeof(struct ieee80211_vht_capabilities))
     306           1 :                                 break;
     307         366 :                         elems->vht_capabilities = pos;
     308         366 :                         break;
     309             :                 case WLAN_EID_VHT_OPERATION:
     310          92 :                         if (elen < sizeof(struct ieee80211_vht_operation))
     311           1 :                                 break;
     312          91 :                         elems->vht_operation = pos;
     313          91 :                         break;
     314             :                 case WLAN_EID_VHT_OPERATING_MODE_NOTIFICATION:
     315           2 :                         if (elen != 1)
     316           1 :                                 break;
     317           1 :                         elems->vht_opmode_notif = pos;
     318           1 :                         break;
     319             :                 case WLAN_EID_LINK_ID:
     320           2 :                         if (elen < 18)
     321           1 :                                 break;
     322           1 :                         elems->link_id = pos;
     323           1 :                         break;
     324             :                 case WLAN_EID_INTERWORKING:
     325        1706 :                         elems->interworking = pos;
     326        1706 :                         elems->interworking_len = elen;
     327        1706 :                         break;
     328             :                 case WLAN_EID_QOS_MAP_SET:
     329           5 :                         if (elen < 16)
     330           1 :                                 break;
     331           4 :                         elems->qos_map_set = pos;
     332           4 :                         elems->qos_map_set_len = elen;
     333           4 :                         break;
     334             :                 case WLAN_EID_EXT_CAPAB:
     335       39598 :                         elems->ext_capab = pos;
     336       39598 :                         elems->ext_capab_len = elen;
     337       39598 :                         break;
     338             :                 case WLAN_EID_BSS_MAX_IDLE_PERIOD:
     339       12944 :                         if (elen < 3)
     340           1 :                                 break;
     341       12943 :                         elems->bss_max_idle_period = pos;
     342       12943 :                         break;
     343             :                 case WLAN_EID_SSID_LIST:
     344           1 :                         elems->ssid_list = pos;
     345           1 :                         elems->ssid_list_len = elen;
     346           1 :                         break;
     347             :                 case WLAN_EID_AMPE:
     348           1 :                         elems->ampe = pos;
     349           1 :                         elems->ampe_len = elen;
     350           1 :                         break;
     351             :                 case WLAN_EID_MIC:
     352          25 :                         elems->mic = pos;
     353          25 :                         elems->mic_len = elen;
     354             :                         /* after mic everything is encrypted, so stop. */
     355          25 :                         left = elen;
     356          25 :                         break;
     357             :                 case WLAN_EID_MULTI_BAND:
     358        2579 :                         if (elems->mb_ies.nof_ies >= MAX_NOF_MB_IES_SUPPORTED) {
     359           0 :                                 wpa_printf(MSG_MSGDUMP,
     360             :                                            "IEEE 802.11 element parse ignored MB IE (id=%d elen=%d)",
     361             :                                            id, elen);
     362           0 :                                 break;
     363             :                         }
     364             : 
     365        2579 :                         elems->mb_ies.ies[elems->mb_ies.nof_ies].ie = pos;
     366        2579 :                         elems->mb_ies.ies[elems->mb_ies.nof_ies].ie_len = elen;
     367        2579 :                         elems->mb_ies.nof_ies++;
     368        2579 :                         break;
     369             :                 default:
     370        1464 :                         unknown++;
     371        1464 :                         if (!show_errors)
     372        1450 :                                 break;
     373          14 :                         wpa_printf(MSG_MSGDUMP, "IEEE 802.11 element parse "
     374             :                                    "ignored unknown element (id=%d elen=%d)",
     375             :                                    id, elen);
     376          14 :                         break;
     377             :                 }
     378             : 
     379      365518 :                 left -= elen;
     380      365518 :                 pos += elen;
     381             :         }
     382             : 
     383       45688 :         if (left)
     384           3 :                 return ParseFailed;
     385             : 
     386       45685 :         return unknown ? ParseUnknown : ParseOK;
     387             : }
     388             : 
     389             : 
     390         252 : int ieee802_11_ie_count(const u8 *ies, size_t ies_len)
     391             : {
     392         252 :         int count = 0;
     393             :         const u8 *pos, *end;
     394             : 
     395         252 :         if (ies == NULL)
     396         226 :                 return 0;
     397             : 
     398          26 :         pos = ies;
     399          26 :         end = ies + ies_len;
     400             : 
     401          85 :         while (pos + 2 <= end) {
     402          34 :                 if (pos + 2 + pos[1] > end)
     403           1 :                         break;
     404          33 :                 count++;
     405          33 :                 pos += 2 + pos[1];
     406             :         }
     407             : 
     408          26 :         return count;
     409             : }
     410             : 
     411             : 
     412       20424 : struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
     413             :                                             u32 oui_type)
     414             : {
     415             :         struct wpabuf *buf;
     416             :         const u8 *end, *pos, *ie;
     417             : 
     418       20424 :         pos = ies;
     419       20424 :         end = ies + ies_len;
     420       20424 :         ie = NULL;
     421             : 
     422      174048 :         while (pos + 1 < end) {
     423      147204 :                 if (pos + 2 + pos[1] > end)
     424           1 :                         return NULL;
     425      180975 :                 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
     426       33772 :                     WPA_GET_BE32(&pos[2]) == oui_type) {
     427       14003 :                         ie = pos;
     428       14003 :                         break;
     429             :                 }
     430      133200 :                 pos += 2 + pos[1];
     431             :         }
     432             : 
     433       20423 :         if (ie == NULL)
     434        6420 :                 return NULL; /* No specified vendor IE found */
     435             : 
     436       14003 :         buf = wpabuf_alloc(ies_len);
     437       14003 :         if (buf == NULL)
     438           0 :                 return NULL;
     439             : 
     440             :         /*
     441             :          * There may be multiple vendor IEs in the message, so need to
     442             :          * concatenate their data fields.
     443             :          */
     444       51525 :         while (pos + 1 < end) {
     445       23519 :                 if (pos + 2 + pos[1] > end)
     446           0 :                         break;
     447       44321 :                 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
     448       20802 :                     WPA_GET_BE32(&pos[2]) == oui_type)
     449       14078 :                         wpabuf_put_data(buf, pos + 6, pos[1] - 4);
     450       23519 :                 pos += 2 + pos[1];
     451             :         }
     452             : 
     453       14003 :         return buf;
     454             : }
     455             : 
     456             : 
     457       28764 : const u8 * get_hdr_bssid(const struct ieee80211_hdr *hdr, size_t len)
     458             : {
     459             :         u16 fc, type, stype;
     460             : 
     461             :         /*
     462             :          * PS-Poll frames are 16 bytes. All other frames are
     463             :          * 24 bytes or longer.
     464             :          */
     465       28764 :         if (len < 16)
     466           0 :                 return NULL;
     467             : 
     468       28764 :         fc = le_to_host16(hdr->frame_control);
     469       28764 :         type = WLAN_FC_GET_TYPE(fc);
     470       28764 :         stype = WLAN_FC_GET_STYPE(fc);
     471             : 
     472       28764 :         switch (type) {
     473             :         case WLAN_FC_TYPE_DATA:
     474           1 :                 if (len < 24)
     475           0 :                         return NULL;
     476           1 :                 switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
     477             :                 case WLAN_FC_FROMDS | WLAN_FC_TODS:
     478             :                 case WLAN_FC_TODS:
     479           1 :                         return hdr->addr1;
     480             :                 case WLAN_FC_FROMDS:
     481           0 :                         return hdr->addr2;
     482             :                 default:
     483           0 :                         return NULL;
     484             :                 }
     485             :         case WLAN_FC_TYPE_CTRL:
     486           0 :                 if (stype != WLAN_FC_STYPE_PSPOLL)
     487           0 :                         return NULL;
     488           0 :                 return hdr->addr1;
     489             :         case WLAN_FC_TYPE_MGMT:
     490       28763 :                 return hdr->addr3;
     491             :         default:
     492           0 :                 return NULL;
     493             :         }
     494             : }
     495             : 
     496             : 
     497          42 : int hostapd_config_wmm_ac(struct hostapd_wmm_ac_params wmm_ac_params[],
     498             :                           const char *name, const char *val)
     499             : {
     500             :         int num, v;
     501             :         const char *pos;
     502             :         struct hostapd_wmm_ac_params *ac;
     503             : 
     504             :         /* skip 'wme_ac_' or 'wmm_ac_' prefix */
     505          42 :         pos = name + 7;
     506          42 :         if (os_strncmp(pos, "be_", 3) == 0) {
     507           6 :                 num = 0;
     508           6 :                 pos += 3;
     509          36 :         } else if (os_strncmp(pos, "bk_", 3) == 0) {
     510          13 :                 num = 1;
     511          13 :                 pos += 3;
     512          23 :         } else if (os_strncmp(pos, "vi_", 3) == 0) {
     513          11 :                 num = 2;
     514          11 :                 pos += 3;
     515          12 :         } else if (os_strncmp(pos, "vo_", 3) == 0) {
     516          11 :                 num = 3;
     517          11 :                 pos += 3;
     518             :         } else {
     519           1 :                 wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
     520           1 :                 return -1;
     521             :         }
     522             : 
     523          41 :         ac = &wmm_ac_params[num];
     524             : 
     525          41 :         if (os_strcmp(pos, "aifs") == 0) {
     526           6 :                 v = atoi(val);
     527           6 :                 if (v < 1 || v > 255) {
     528           2 :                         wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
     529           2 :                         return -1;
     530             :                 }
     531           4 :                 ac->aifs = v;
     532          35 :         } else if (os_strcmp(pos, "cwmin") == 0) {
     533           6 :                 v = atoi(val);
     534           6 :                 if (v < 0 || v > 15) {
     535           2 :                         wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
     536           2 :                         return -1;
     537             :                 }
     538           4 :                 ac->cwmin = v;
     539          29 :         } else if (os_strcmp(pos, "cwmax") == 0) {
     540           6 :                 v = atoi(val);
     541           6 :                 if (v < 0 || v > 15) {
     542           2 :                         wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
     543           2 :                         return -1;
     544             :                 }
     545           4 :                 ac->cwmax = v;
     546          23 :         } else if (os_strcmp(pos, "txop_limit") == 0) {
     547           6 :                 v = atoi(val);
     548           6 :                 if (v < 0 || v > 0xffff) {
     549           2 :                         wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
     550           2 :                         return -1;
     551             :                 }
     552           4 :                 ac->txop_limit = v;
     553          17 :         } else if (os_strcmp(pos, "acm") == 0) {
     554          16 :                 v = atoi(val);
     555          16 :                 if (v < 0 || v > 1) {
     556           2 :                         wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
     557           2 :                         return -1;
     558             :                 }
     559          14 :                 ac->admission_control_mandatory = v;
     560             :         } else {
     561           1 :                 wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
     562           1 :                 return -1;
     563             :         }
     564             : 
     565          30 :         return 0;
     566             : }
     567             : 
     568             : 
     569      505868 : enum hostapd_hw_mode ieee80211_freq_to_chan(int freq, u8 *channel)
     570             : {
     571             :         u8 op_class;
     572             : 
     573      505868 :         return ieee80211_freq_to_channel_ext(freq, 0, 0, &op_class, channel);
     574             : }
     575             : 
     576             : 
     577             : /**
     578             :  * ieee80211_freq_to_channel_ext - Convert frequency into channel info
     579             :  * for HT40 and VHT. DFS channels are not covered.
     580             :  * @freq: Frequency (MHz) to convert
     581             :  * @sec_channel: 0 = non-HT40, 1 = sec. channel above, -1 = sec. channel below
     582             :  * @vht: 0 - non-VHT, 1 - 80 MHz
     583             :  * @op_class: Buffer for returning operating class
     584             :  * @channel: Buffer for returning channel number
     585             :  * Returns: hw_mode on success, NUM_HOSTAPD_MODES on failure
     586             :  */
     587      516298 : enum hostapd_hw_mode ieee80211_freq_to_channel_ext(unsigned int freq,
     588             :                                                    int sec_channel, int vht,
     589             :                                                    u8 *op_class, u8 *channel)
     590             : {
     591             :         /* TODO: more operating classes */
     592             : 
     593      516298 :         if (sec_channel > 1 || sec_channel < -1)
     594           0 :                 return NUM_HOSTAPD_MODES;
     595             : 
     596      516298 :         if (freq >= 2412 && freq <= 2472) {
     597      183526 :                 if ((freq - 2407) % 5)
     598           0 :                         return NUM_HOSTAPD_MODES;
     599             : 
     600      183526 :                 if (vht)
     601           0 :                         return NUM_HOSTAPD_MODES;
     602             : 
     603             :                 /* 2.407 GHz, channels 1..13 */
     604      183526 :                 if (sec_channel == 1)
     605           0 :                         *op_class = 83;
     606      183526 :                 else if (sec_channel == -1)
     607           0 :                         *op_class = 84;
     608             :                 else
     609      183526 :                         *op_class = 81;
     610             : 
     611      183526 :                 *channel = (freq - 2407) / 5;
     612             : 
     613      183526 :                 return HOSTAPD_MODE_IEEE80211G;
     614             :         }
     615             : 
     616      332772 :         if (freq == 2484) {
     617       13233 :                 if (sec_channel || vht)
     618           0 :                         return NUM_HOSTAPD_MODES;
     619             : 
     620       13233 :                 *op_class = 82; /* channel 14 */
     621       13233 :                 *channel = 14;
     622             : 
     623       13233 :                 return HOSTAPD_MODE_IEEE80211B;
     624             :         }
     625             : 
     626      319539 :         if (freq >= 4900 && freq < 5000) {
     627           0 :                 if ((freq - 4000) % 5)
     628           0 :                         return NUM_HOSTAPD_MODES;
     629           0 :                 *channel = (freq - 4000) / 5;
     630           0 :                 *op_class = 0; /* TODO */
     631           0 :                 return HOSTAPD_MODE_IEEE80211A;
     632             :         }
     633             : 
     634             :         /* 5 GHz, channels 36..48 */
     635      319539 :         if (freq >= 5180 && freq <= 5240) {
     636       53990 :                 if ((freq - 5000) % 5)
     637           0 :                         return NUM_HOSTAPD_MODES;
     638             : 
     639       53990 :                 if (sec_channel == 1)
     640           0 :                         *op_class = 116;
     641       53990 :                 else if (sec_channel == -1)
     642           0 :                         *op_class = 117;
     643       53990 :                 else if (vht)
     644           0 :                         *op_class = 128;
     645             :                 else
     646       53990 :                         *op_class = 115;
     647             : 
     648       53990 :                 *channel = (freq - 5000) / 5;
     649             : 
     650       53990 :                 return HOSTAPD_MODE_IEEE80211A;
     651             :         }
     652             : 
     653             :         /* 5 GHz, channels 149..161 */
     654      265549 :         if (freq >= 5745 && freq <= 5805) {
     655       52941 :                 if ((freq - 5000) % 5)
     656           0 :                         return NUM_HOSTAPD_MODES;
     657             : 
     658       52941 :                 if (sec_channel == 1)
     659           0 :                         *op_class = 126;
     660       52941 :                 else if (sec_channel == -1)
     661           0 :                         *op_class = 127;
     662       52941 :                 else if (vht)
     663           0 :                         *op_class = 128;
     664             :                 else
     665       52941 :                         *op_class = 124;
     666             : 
     667       52941 :                 *channel = (freq - 5000) / 5;
     668             : 
     669       52941 :                 return HOSTAPD_MODE_IEEE80211A;
     670             :         }
     671             : 
     672             :         /* 5 GHz, channels 149..169 */
     673      212608 :         if (freq >= 5745 && freq <= 5845) {
     674       13237 :                 if ((freq - 5000) % 5)
     675           0 :                         return NUM_HOSTAPD_MODES;
     676             : 
     677       13237 :                 *op_class = 125;
     678             : 
     679       13237 :                 *channel = (freq - 5000) / 5;
     680             : 
     681       13237 :                 return HOSTAPD_MODE_IEEE80211A;
     682             :         }
     683             : 
     684      199371 :         if (freq >= 5000 && freq < 5900) {
     685      198490 :                 if ((freq - 5000) % 5)
     686           0 :                         return NUM_HOSTAPD_MODES;
     687      198490 :                 *channel = (freq - 5000) / 5;
     688      198490 :                 *op_class = 0; /* TODO */
     689      198490 :                 return HOSTAPD_MODE_IEEE80211A;
     690             :         }
     691             : 
     692             :         /* 56.16 GHz, channel 1..4 */
     693         881 :         if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 4) {
     694         880 :                 if (sec_channel || vht)
     695           0 :                         return NUM_HOSTAPD_MODES;
     696             : 
     697         880 :                 *channel = (freq - 56160) / 2160;
     698         880 :                 *op_class = 180;
     699             : 
     700         880 :                 return HOSTAPD_MODE_IEEE80211AD;
     701             :         }
     702             : 
     703           1 :         return NUM_HOSTAPD_MODES;
     704             : }
     705             : 
     706             : 
     707             : static const char *const us_op_class_cc[] = {
     708             :         "US", "CA", NULL
     709             : };
     710             : 
     711             : static const char *const eu_op_class_cc[] = {
     712             :         "AL", "AM", "AT", "AZ", "BA", "BE", "BG", "BY", "CH", "CY", "CZ", "DE",
     713             :         "DK", "EE", "EL", "ES", "FI", "FR", "GE", "HR", "HU", "IE", "IS", "IT",
     714             :         "LI", "LT", "LU", "LV", "MD", "ME", "MK", "MT", "NL", "NO", "PL", "PT",
     715             :         "RO", "RS", "RU", "SE", "SI", "SK", "TR", "UA", "UK", NULL
     716             : };
     717             : 
     718             : static const char *const jp_op_class_cc[] = {
     719             :         "JP", NULL
     720             : };
     721             : 
     722             : static const char *const cn_op_class_cc[] = {
     723             :         "CN", NULL
     724             : };
     725             : 
     726             : 
     727      388617 : static int country_match(const char *const cc[], const char *const country)
     728             : {
     729             :         int i;
     730             : 
     731      388617 :         if (country == NULL)
     732      388264 :                 return 0;
     733        4105 :         for (i = 0; cc[i]; i++) {
     734        3819 :                 if (cc[i][0] == country[0] && cc[i][1] == country[1])
     735          67 :                         return 1;
     736             :         }
     737             : 
     738         286 :         return 0;
     739             : }
     740             : 
     741             : 
     742          19 : static int ieee80211_chan_to_freq_us(u8 op_class, u8 chan)
     743             : {
     744          19 :         switch (op_class) {
     745             :         case 12: /* channels 1..11 */
     746             :         case 32: /* channels 1..7; 40 MHz */
     747             :         case 33: /* channels 5..11; 40 MHz */
     748           3 :                 if (chan < 1 || chan > 11)
     749           2 :                         return -1;
     750           1 :                 return 2407 + 5 * chan;
     751             :         case 1: /* channels 36,40,44,48 */
     752             :         case 2: /* channels 52,56,60,64; dfs */
     753             :         case 22: /* channels 36,44; 40 MHz */
     754             :         case 23: /* channels 52,60; 40 MHz */
     755             :         case 27: /* channels 40,48; 40 MHz */
     756             :         case 28: /* channels 56,64; 40 MHz */
     757           3 :                 if (chan < 36 || chan > 64)
     758           2 :                         return -1;
     759           1 :                 return 5000 + 5 * chan;
     760             :         case 4: /* channels 100-144 */
     761             :         case 24: /* channels 100-140; 40 MHz */
     762           3 :                 if (chan < 100 || chan > 144)
     763           2 :                         return -1;
     764           1 :                 return 5000 + 5 * chan;
     765             :         case 3: /* channels 149,153,157,161 */
     766             :         case 25: /* channels 149,157; 40 MHz */
     767             :         case 26: /* channels 149,157; 40 MHz */
     768             :         case 30: /* channels 153,161; 40 MHz */
     769             :         case 31: /* channels 153,161; 40 MHz */
     770           3 :                 if (chan < 149 || chan > 161)
     771           2 :                         return -1;
     772           1 :                 return 5000 + 5 * chan;
     773             :         case 5: /* channels 149,153,157,161,165 */
     774           3 :                 if (chan < 149 || chan > 165)
     775           2 :                         return -1;
     776           1 :                 return 5000 + 5 * chan;
     777             :         case 34: /* 60 GHz band, channels 1..3 */
     778           3 :                 if (chan < 1 || chan > 3)
     779           2 :                         return -1;
     780           1 :                 return 56160 + 2160 * chan;
     781             :         }
     782           1 :         return -1;
     783             : }
     784             : 
     785             : 
     786          22 : static int ieee80211_chan_to_freq_eu(u8 op_class, u8 chan)
     787             : {
     788          22 :         switch (op_class) {
     789             :         case 4: /* channels 1..13 */
     790             :         case 11: /* channels 1..9; 40 MHz */
     791             :         case 12: /* channels 5..13; 40 MHz */
     792           3 :                 if (chan < 1 || chan > 13)
     793           2 :                         return -1;
     794           1 :                 return 2407 + 5 * chan;
     795             :         case 1: /* channels 36,40,44,48 */
     796             :         case 2: /* channels 52,56,60,64; dfs */
     797             :         case 5: /* channels 36,44; 40 MHz */
     798             :         case 6: /* channels 52,60; 40 MHz */
     799             :         case 8: /* channels 40,48; 40 MHz */
     800             :         case 9: /* channels 56,64; 40 MHz */
     801           4 :                 if (chan < 36 || chan > 64)
     802           2 :                         return -1;
     803           2 :                 return 5000 + 5 * chan;
     804             :         case 3: /* channels 100-140 */
     805             :         case 7: /* channels 100-132; 40 MHz */
     806             :         case 10: /* channels 104-136; 40 MHz */
     807             :         case 16: /* channels 100-140 */
     808           3 :                 if (chan < 100 || chan > 140)
     809           2 :                         return -1;
     810           1 :                 return 5000 + 5 * chan;
     811             :         case 17: /* channels 149,153,157,161,165,169 */
     812           3 :                 if (chan < 149 || chan > 169)
     813           2 :                         return -1;
     814           1 :                 return 5000 + 5 * chan;
     815             :         case 18: /* 60 GHz band, channels 1..4 */
     816           3 :                 if (chan < 1 || chan > 4)
     817           2 :                         return -1;
     818           1 :                 return 56160 + 2160 * chan;
     819             :         }
     820           6 :         return -1;
     821             : }
     822             : 
     823             : 
     824          15 : static int ieee80211_chan_to_freq_jp(u8 op_class, u8 chan)
     825             : {
     826          15 :         switch (op_class) {
     827             :         case 30: /* channels 1..13 */
     828             :         case 56: /* channels 1..9; 40 MHz */
     829             :         case 57: /* channels 5..13; 40 MHz */
     830           3 :                 if (chan < 1 || chan > 13)
     831           2 :                         return -1;
     832           1 :                 return 2407 + 5 * chan;
     833             :         case 31: /* channel 14 */
     834           2 :                 if (chan != 14)
     835           1 :                         return -1;
     836           1 :                 return 2414 + 5 * chan;
     837             :         case 1: /* channels 34,38,42,46(old) or 36,40,44,48 */
     838             :         case 32: /* channels 52,56,60,64 */
     839             :         case 33: /* channels 52,56,60,64 */
     840             :         case 36: /* channels 36,44; 40 MHz */
     841             :         case 37: /* channels 52,60; 40 MHz */
     842             :         case 38: /* channels 52,60; 40 MHz */
     843             :         case 41: /* channels 40,48; 40 MHz */
     844             :         case 42: /* channels 56,64; 40 MHz */
     845             :         case 43: /* channels 56,64; 40 MHz */
     846           3 :                 if (chan < 34 || chan > 64)
     847           2 :                         return -1;
     848           1 :                 return 5000 + 5 * chan;
     849             :         case 34: /* channels 100-140 */
     850             :         case 35: /* channels 100-140 */
     851             :         case 39: /* channels 100-132; 40 MHz */
     852             :         case 40: /* channels 100-132; 40 MHz */
     853             :         case 44: /* channels 104-136; 40 MHz */
     854             :         case 45: /* channels 104-136; 40 MHz */
     855             :         case 58: /* channels 100-140 */
     856           3 :                 if (chan < 100 || chan > 140)
     857           2 :                         return -1;
     858           1 :                 return 5000 + 5 * chan;
     859             :         case 59: /* 60 GHz band, channels 1..4 */
     860           3 :                 if (chan < 1 || chan > 3)
     861           2 :                         return -1;
     862           1 :                 return 56160 + 2160 * chan;
     863             :         }
     864           1 :         return -1;
     865             : }
     866             : 
     867             : 
     868          11 : static int ieee80211_chan_to_freq_cn(u8 op_class, u8 chan)
     869             : {
     870          11 :         switch (op_class) {
     871             :         case 7: /* channels 1..13 */
     872             :         case 8: /* channels 1..9; 40 MHz */
     873             :         case 9: /* channels 5..13; 40 MHz */
     874           3 :                 if (chan < 1 || chan > 13)
     875           2 :                         return -1;
     876           1 :                 return 2407 + 5 * chan;
     877             :         case 1: /* channels 36,40,44,48 */
     878             :         case 2: /* channels 52,56,60,64; dfs */
     879             :         case 4: /* channels 36,44; 40 MHz */
     880             :         case 5: /* channels 52,60; 40 MHz */
     881           3 :                 if (chan < 36 || chan > 64)
     882           2 :                         return -1;
     883           1 :                 return 5000 + 5 * chan;
     884             :         case 3: /* channels 149,153,157,161,165 */
     885             :         case 6: /* channels 149,157; 40 MHz */
     886           4 :                 if (chan < 149 || chan > 165)
     887           2 :                         return -1;
     888           2 :                 return 5000 + 5 * chan;
     889             :         }
     890           1 :         return -1;
     891             : }
     892             : 
     893             : 
     894       97142 : static int ieee80211_chan_to_freq_global(u8 op_class, u8 chan)
     895             : {
     896             :         /* Table E-4 in IEEE Std 802.11-2012 - Global operating classes */
     897       97142 :         switch (op_class) {
     898             :         case 81:
     899             :                 /* channels 1..13 */
     900       96377 :                 if (chan < 1 || chan > 13)
     901           3 :                         return -1;
     902       96374 :                 return 2407 + 5 * chan;
     903             :         case 82:
     904             :                 /* channel 14 */
     905           2 :                 if (chan != 14)
     906           1 :                         return -1;
     907           1 :                 return 2414 + 5 * chan;
     908             :         case 83: /* channels 1..9; 40 MHz */
     909             :         case 84: /* channels 5..13; 40 MHz */
     910           3 :                 if (chan < 1 || chan > 13)
     911           2 :                         return -1;
     912           1 :                 return 2407 + 5 * chan;
     913             :         case 115: /* channels 36,40,44,48; indoor only */
     914             :         case 116: /* channels 36,44; 40 MHz; indoor only */
     915             :         case 117: /* channels 40,48; 40 MHz; indoor only */
     916             :         case 118: /* channels 52,56,60,64; dfs */
     917             :         case 119: /* channels 52,60; 40 MHz; dfs */
     918             :         case 120: /* channels 56,64; 40 MHz; dfs */
     919         211 :                 if (chan < 36 || chan > 64)
     920           3 :                         return -1;
     921         208 :                 return 5000 + 5 * chan;
     922             :         case 121: /* channels 100-140 */
     923             :         case 122: /* channels 100-142; 40 MHz */
     924             :         case 123: /* channels 104-136; 40 MHz */
     925           3 :                 if (chan < 100 || chan > 140)
     926           2 :                         return -1;
     927           1 :                 return 5000 + 5 * chan;
     928             :         case 124: /* channels 149,153,157,161 */
     929             :         case 126: /* channels 149,157; 40 MHz */
     930             :         case 127: /* channels 153,161; 40 MHz */
     931         242 :                 if (chan < 149 || chan > 161)
     932           2 :                         return -1;
     933         240 :                 return 5000 + 5 * chan;
     934             :         case 125: /* channels 149,153,157,161,165,169 */
     935         148 :                 if (chan < 149 || chan > 169)
     936           2 :                         return -1;
     937         146 :                 return 5000 + 5 * chan;
     938             :         case 128: /* center freqs 42, 58, 106, 122, 138, 155; 80 MHz */
     939             :         case 130: /* center freqs 42, 58, 106, 122, 138, 155; 80 MHz */
     940         107 :                 if (chan < 36 || chan > 161)
     941           2 :                         return -1;
     942         105 :                 return 5000 + 5 * chan;
     943             :         case 129: /* center freqs 50, 114; 160 MHz */
     944           3 :                 if (chan < 50 || chan > 114)
     945           2 :                         return -1;
     946           1 :                 return 5000 + 5 * chan;
     947             :         case 180: /* 60 GHz band, channels 1..4 */
     948           3 :                 if (chan < 1 || chan > 4)
     949           2 :                         return -1;
     950           1 :                 return 56160 + 2160 * chan;
     951             :         }
     952          43 :         return -1;
     953             : }
     954             : 
     955             : /**
     956             :  * ieee80211_chan_to_freq - Convert channel info to frequency
     957             :  * @country: Country code, if known; otherwise, global operating class is used
     958             :  * @op_class: Operating class
     959             :  * @chan: Channel number
     960             :  * Returns: Frequency in MHz or -1 if the specified channel is unknown
     961             :  */
     962       97163 : int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan)
     963             : {
     964             :         int freq;
     965             : 
     966       97163 :         if (country_match(us_op_class_cc, country)) {
     967          19 :                 freq = ieee80211_chan_to_freq_us(op_class, chan);
     968          19 :                 if (freq > 0)
     969           6 :                         return freq;
     970             :         }
     971             : 
     972       97157 :         if (country_match(eu_op_class_cc, country)) {
     973          22 :                 freq = ieee80211_chan_to_freq_eu(op_class, chan);
     974          22 :                 if (freq > 0)
     975           6 :                         return freq;
     976             :         }
     977             : 
     978       97151 :         if (country_match(jp_op_class_cc, country)) {
     979          15 :                 freq = ieee80211_chan_to_freq_jp(op_class, chan);
     980          15 :                 if (freq > 0)
     981           5 :                         return freq;
     982             :         }
     983             : 
     984       97146 :         if (country_match(cn_op_class_cc, country)) {
     985          11 :                 freq = ieee80211_chan_to_freq_cn(op_class, chan);
     986          11 :                 if (freq > 0)
     987           4 :                         return freq;
     988             :         }
     989             : 
     990       97142 :         return ieee80211_chan_to_freq_global(op_class, chan);
     991             : }
     992             : 
     993             : 
     994         698 : int ieee80211_is_dfs(int freq)
     995             : {
     996             :         /* TODO: this could be more accurate to better cover all domains */
     997         698 :         return (freq >= 5260 && freq <= 5320) || (freq >= 5500 && freq <= 5700);
     998             : }
     999             : 
    1000             : 
    1001       10824 : static int is_11b(u8 rate)
    1002             : {
    1003       10824 :         return rate == 0x02 || rate == 0x04 || rate == 0x0b || rate == 0x16;
    1004             : }
    1005             : 
    1006             : 
    1007        1334 : int supp_rates_11b_only(struct ieee802_11_elems *elems)
    1008             : {
    1009        1334 :         int num_11b = 0, num_others = 0;
    1010             :         int i;
    1011             : 
    1012        1334 :         if (elems->supp_rates == NULL && elems->ext_supp_rates == NULL)
    1013           0 :                 return 0;
    1014             : 
    1015       12006 :         for (i = 0; elems->supp_rates && i < elems->supp_rates_len; i++) {
    1016       10672 :                 if (is_11b(elems->supp_rates[i]))
    1017         152 :                         num_11b++;
    1018             :                 else
    1019       10520 :                         num_others++;
    1020             :         }
    1021             : 
    1022        2820 :         for (i = 0; elems->ext_supp_rates && i < elems->ext_supp_rates_len;
    1023         152 :              i++) {
    1024         152 :                 if (is_11b(elems->ext_supp_rates[i]))
    1025           0 :                         num_11b++;
    1026             :                 else
    1027         152 :                         num_others++;
    1028             :         }
    1029             : 
    1030        1334 :         return num_11b > 0 && num_others == 0;
    1031             : }
    1032             : 
    1033             : 
    1034       80709 : const char * fc2str(u16 fc)
    1035             : {
    1036       80709 :         u16 stype = WLAN_FC_GET_STYPE(fc);
    1037             : #define C2S(x) case x: return #x;
    1038             : 
    1039       80709 :         switch (WLAN_FC_GET_TYPE(fc)) {
    1040             :         case WLAN_FC_TYPE_MGMT:
    1041       80709 :                 switch (stype) {
    1042        5143 :                 C2S(WLAN_FC_STYPE_ASSOC_REQ)
    1043        3035 :                 C2S(WLAN_FC_STYPE_ASSOC_RESP)
    1044        2424 :                 C2S(WLAN_FC_STYPE_REASSOC_REQ)
    1045         311 :                 C2S(WLAN_FC_STYPE_REASSOC_RESP)
    1046        8539 :                 C2S(WLAN_FC_STYPE_PROBE_REQ)
    1047        4795 :                 C2S(WLAN_FC_STYPE_PROBE_RESP)
    1048           0 :                 C2S(WLAN_FC_STYPE_BEACON)
    1049           0 :                 C2S(WLAN_FC_STYPE_ATIM)
    1050        2120 :                 C2S(WLAN_FC_STYPE_DISASSOC)
    1051        9513 :                 C2S(WLAN_FC_STYPE_AUTH)
    1052        9065 :                 C2S(WLAN_FC_STYPE_DEAUTH)
    1053       35764 :                 C2S(WLAN_FC_STYPE_ACTION)
    1054             :                 }
    1055           0 :                 break;
    1056             :         case WLAN_FC_TYPE_CTRL:
    1057           0 :                 switch (stype) {
    1058           0 :                 C2S(WLAN_FC_STYPE_PSPOLL)
    1059           0 :                 C2S(WLAN_FC_STYPE_RTS)
    1060           0 :                 C2S(WLAN_FC_STYPE_CTS)
    1061           0 :                 C2S(WLAN_FC_STYPE_ACK)
    1062           0 :                 C2S(WLAN_FC_STYPE_CFEND)
    1063           0 :                 C2S(WLAN_FC_STYPE_CFENDACK)
    1064             :                 }
    1065           0 :                 break;
    1066             :         case WLAN_FC_TYPE_DATA:
    1067           0 :                 switch (stype) {
    1068           0 :                 C2S(WLAN_FC_STYPE_DATA)
    1069           0 :                 C2S(WLAN_FC_STYPE_DATA_CFACK)
    1070           0 :                 C2S(WLAN_FC_STYPE_DATA_CFPOLL)
    1071           0 :                 C2S(WLAN_FC_STYPE_DATA_CFACKPOLL)
    1072           0 :                 C2S(WLAN_FC_STYPE_NULLFUNC)
    1073           0 :                 C2S(WLAN_FC_STYPE_CFACK)
    1074           0 :                 C2S(WLAN_FC_STYPE_CFPOLL)
    1075           0 :                 C2S(WLAN_FC_STYPE_CFACKPOLL)
    1076           0 :                 C2S(WLAN_FC_STYPE_QOS_DATA)
    1077           0 :                 C2S(WLAN_FC_STYPE_QOS_DATA_CFACK)
    1078           0 :                 C2S(WLAN_FC_STYPE_QOS_DATA_CFPOLL)
    1079           0 :                 C2S(WLAN_FC_STYPE_QOS_DATA_CFACKPOLL)
    1080           0 :                 C2S(WLAN_FC_STYPE_QOS_NULL)
    1081           0 :                 C2S(WLAN_FC_STYPE_QOS_CFPOLL)
    1082           0 :                 C2S(WLAN_FC_STYPE_QOS_CFACKPOLL)
    1083             :                 }
    1084           0 :                 break;
    1085             :         }
    1086           0 :         return "WLAN_FC_TYPE_UNKNOWN";
    1087             : #undef C2S
    1088             : }
    1089             : 
    1090             : 
    1091         570 : int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf,
    1092             :                        size_t ies_len)
    1093             : {
    1094         570 :         os_memset(info, 0, sizeof(*info));
    1095             : 
    1096        5536 :         while (ies_buf && ies_len >= 2 &&
    1097        2198 :                info->nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
    1098        2198 :                 size_t len = 2 + ies_buf[1];
    1099             : 
    1100        2198 :                 if (len > ies_len) {
    1101           0 :                         wpa_hexdump(MSG_DEBUG, "Truncated IEs",
    1102             :                                     ies_buf, ies_len);
    1103           0 :                         return -1;
    1104             :                 }
    1105             : 
    1106        2198 :                 if (ies_buf[0] == WLAN_EID_MULTI_BAND) {
    1107         562 :                         wpa_printf(MSG_DEBUG, "MB IE of %zu bytes found", len);
    1108         562 :                         info->ies[info->nof_ies].ie = ies_buf + 2;
    1109         562 :                         info->ies[info->nof_ies].ie_len = ies_buf[1];
    1110         562 :                         info->nof_ies++;
    1111             :                 }
    1112             : 
    1113        2198 :                 ies_len -= len;
    1114        2198 :                 ies_buf += len;
    1115             :         }
    1116             : 
    1117         570 :         return 0;
    1118             : }
    1119             : 
    1120             : 
    1121         817 : struct wpabuf * mb_ies_by_info(struct mb_ies_info *info)
    1122             : {
    1123         817 :         struct wpabuf *mb_ies = NULL;
    1124             : 
    1125             :         WPA_ASSERT(info != NULL);
    1126             : 
    1127         817 :         if (info->nof_ies) {
    1128             :                 u8 i;
    1129         805 :                 size_t mb_ies_size = 0;
    1130             : 
    1131        1736 :                 for (i = 0; i < info->nof_ies; i++)
    1132         931 :                         mb_ies_size += 2 + info->ies[i].ie_len;
    1133             : 
    1134         805 :                 mb_ies = wpabuf_alloc(mb_ies_size);
    1135         805 :                 if (mb_ies) {
    1136        1734 :                         for (i = 0; i < info->nof_ies; i++) {
    1137         930 :                                 wpabuf_put_u8(mb_ies, WLAN_EID_MULTI_BAND);
    1138         930 :                                 wpabuf_put_u8(mb_ies, info->ies[i].ie_len);
    1139        1860 :                                 wpabuf_put_data(mb_ies,
    1140         930 :                                                 info->ies[i].ie,
    1141         930 :                                                 info->ies[i].ie_len);
    1142             :                         }
    1143             :                 }
    1144             :         }
    1145             : 
    1146         817 :         return mb_ies;
    1147             : }

Generated by: LCOV version 1.10