2 * IEEE 802.11 Common routines
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "ieee802_11_defs.h"
19 #include "ieee802_11_common.h"
22 static int ieee802_11_parse_vendor_specific(const u8
*pos
, size_t elen
,
23 struct ieee802_11_elems
*elems
,
28 /* first 3 bytes in vendor specific information element are the IEEE
29 * OUI of the vendor. The following byte is used a vendor specific
33 wpa_printf(MSG_MSGDUMP
, "short vendor specific "
34 "information element ignored (len=%lu)",
35 (unsigned long) elen
);
40 oui
= WPA_GET_BE24(pos
);
43 /* Microsoft/Wi-Fi information elements are further typed and
47 /* Microsoft OUI (00:50:F2) with OUI Type 1:
48 * real WPA information element */
50 elems
->wpa_ie_len
= elen
;
53 /* WMM information element */
55 wpa_printf(MSG_MSGDUMP
, "short WMM "
56 "information element ignored "
58 (unsigned long) elen
);
62 case WMM_OUI_SUBTYPE_INFORMATION_ELEMENT
:
63 case WMM_OUI_SUBTYPE_PARAMETER_ELEMENT
:
65 * Share same pointer since only one of these
66 * is used and they start with same data.
67 * Length field can be used to distinguish the
71 elems
->wmm_len
= elen
;
73 case WMM_OUI_SUBTYPE_TSPEC_ELEMENT
:
74 elems
->wmm_tspec
= pos
;
75 elems
->wmm_tspec_len
= elen
;
78 wpa_printf(MSG_MSGDUMP
, "unknown WMM "
79 "information element ignored "
80 "(subtype=%d len=%lu)",
81 pos
[4], (unsigned long) elen
);
86 /* Wi-Fi Protected Setup (WPS) IE */
88 elems
->wps_ie_len
= elen
;
91 wpa_printf(MSG_MSGDUMP
, "Unknown Microsoft "
92 "information element ignored "
93 "(type=%d len=%lu)\n",
94 pos
[3], (unsigned long) elen
);
101 case VENDOR_HT_CAPAB_OUI_TYPE
:
102 elems
->vendor_ht_cap
= pos
;
103 elems
->vendor_ht_cap_len
= elen
;
106 wpa_printf(MSG_MSGDUMP
, "Unknown Broadcom "
107 "information element ignored "
108 "(type=%d len=%lu)\n",
109 pos
[3], (unsigned long) elen
);
115 wpa_printf(MSG_MSGDUMP
, "unknown vendor specific information "
116 "element ignored (vendor OUI %02x:%02x:%02x "
118 pos
[0], pos
[1], pos
[2], (unsigned long) elen
);
127 * ieee802_11_parse_elems - Parse information elements in management frames
128 * @start: Pointer to the start of IEs
129 * @len: Length of IE buffer in octets
130 * @elems: Data structure for parsed elements
131 * @show_errors: Whether to show parsing errors in debug log
132 * Returns: Parsing result
134 ParseRes
ieee802_11_parse_elems(const u8
*start
, size_t len
,
135 struct ieee802_11_elems
*elems
,
139 const u8
*pos
= start
;
142 os_memset(elems
, 0, sizeof(*elems
));
153 wpa_printf(MSG_DEBUG
, "IEEE 802.11 element "
154 "parse failed (id=%d elen=%d "
156 id
, elen
, (unsigned long) left
);
157 wpa_hexdump(MSG_MSGDUMP
, "IEs", start
, len
);
165 elems
->ssid_len
= elen
;
167 case WLAN_EID_SUPP_RATES
:
168 elems
->supp_rates
= pos
;
169 elems
->supp_rates_len
= elen
;
171 case WLAN_EID_FH_PARAMS
:
172 elems
->fh_params
= pos
;
173 elems
->fh_params_len
= elen
;
175 case WLAN_EID_DS_PARAMS
:
176 elems
->ds_params
= pos
;
177 elems
->ds_params_len
= elen
;
179 case WLAN_EID_CF_PARAMS
:
180 elems
->cf_params
= pos
;
181 elems
->cf_params_len
= elen
;
185 elems
->tim_len
= elen
;
187 case WLAN_EID_IBSS_PARAMS
:
188 elems
->ibss_params
= pos
;
189 elems
->ibss_params_len
= elen
;
191 case WLAN_EID_CHALLENGE
:
192 elems
->challenge
= pos
;
193 elems
->challenge_len
= elen
;
195 case WLAN_EID_ERP_INFO
:
196 elems
->erp_info
= pos
;
197 elems
->erp_info_len
= elen
;
199 case WLAN_EID_EXT_SUPP_RATES
:
200 elems
->ext_supp_rates
= pos
;
201 elems
->ext_supp_rates_len
= elen
;
203 case WLAN_EID_VENDOR_SPECIFIC
:
204 if (ieee802_11_parse_vendor_specific(pos
, elen
,
211 elems
->rsn_ie_len
= elen
;
213 case WLAN_EID_PWR_CAPABILITY
:
214 elems
->power_cap
= pos
;
215 elems
->power_cap_len
= elen
;
217 case WLAN_EID_SUPPORTED_CHANNELS
:
218 elems
->supp_channels
= pos
;
219 elems
->supp_channels_len
= elen
;
221 case WLAN_EID_MOBILITY_DOMAIN
:
223 elems
->mdie_len
= elen
;
225 case WLAN_EID_FAST_BSS_TRANSITION
:
227 elems
->ftie_len
= elen
;
229 case WLAN_EID_TIMEOUT_INTERVAL
:
230 elems
->timeout_int
= pos
;
231 elems
->timeout_int_len
= elen
;
233 case WLAN_EID_HT_CAP
:
234 elems
->ht_capabilities
= pos
;
235 elems
->ht_capabilities_len
= elen
;
237 case WLAN_EID_HT_OPERATION
:
238 elems
->ht_operation
= pos
;
239 elems
->ht_operation_len
= elen
;
245 wpa_printf(MSG_MSGDUMP
, "IEEE 802.11 element parse "
246 "ignored unknown element (id=%d elen=%d)",
258 return unknown
? ParseUnknown
: ParseOK
;
262 int ieee802_11_ie_count(const u8
*ies
, size_t ies_len
)
273 while (pos
+ 2 <= end
) {
274 if (pos
+ 2 + pos
[1] > end
)
284 struct wpabuf
* ieee802_11_vendor_ie_concat(const u8
*ies
, size_t ies_len
,
288 const u8
*end
, *pos
, *ie
;
294 while (pos
+ 1 < end
) {
295 if (pos
+ 2 + pos
[1] > end
)
297 if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&& pos
[1] >= 4 &&
298 WPA_GET_BE32(&pos
[2]) == oui_type
) {
306 return NULL
; /* No specified vendor IE found */
308 buf
= wpabuf_alloc(ies_len
);
313 * There may be multiple vendor IEs in the message, so need to
314 * concatenate their data fields.
316 while (pos
+ 1 < end
) {
317 if (pos
+ 2 + pos
[1] > end
)
319 if (pos
[0] == WLAN_EID_VENDOR_SPECIFIC
&& pos
[1] >= 4 &&
320 WPA_GET_BE32(&pos
[2]) == oui_type
)
321 wpabuf_put_data(buf
, pos
+ 6, pos
[1] - 4);