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_EXCESSIVE, "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_EXCESSIVE, "Unknown Microsoft "
92 "information element ignored "
94 pos[3], (unsigned long) elen);
102 /* Wi-Fi Alliance - P2P IE */
104 elems->p2p_len = elen;
107 wpa_printf(MSG_MSGDUMP, "Unknown WFA "
108 "information element ignored "
109 "(type=%d len=%lu)\n",
110 pos[3], (unsigned long) elen);
117 case VENDOR_HT_CAPAB_OUI_TYPE:
118 elems->vendor_ht_cap = pos;
119 elems->vendor_ht_cap_len = elen;
122 wpa_printf(MSG_EXCESSIVE, "Unknown Broadcom "
123 "information element ignored "
125 pos[3], (unsigned long) elen);
131 wpa_printf(MSG_EXCESSIVE, "unknown vendor specific "
132 "information element ignored (vendor OUI "
133 "%02x:%02x:%02x len=%lu)",
134 pos[0], pos[1], pos[2], (unsigned long) elen);
143 * ieee802_11_parse_elems - Parse information elements in management frames
144 * @start: Pointer to the start of IEs
145 * @len: Length of IE buffer in octets
146 * @elems: Data structure for parsed elements
147 * @show_errors: Whether to show parsing errors in debug log
148 * Returns: Parsing result
150 ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
151 struct ieee802_11_elems *elems,
155 const u8 *pos = start;
158 os_memset(elems, 0, sizeof(*elems));
169 wpa_printf(MSG_DEBUG, "IEEE 802.11 element "
170 "parse failed (id=%d elen=%d "
172 id, elen, (unsigned long) left);
173 wpa_hexdump(MSG_MSGDUMP, "IEs", start, len);
181 elems->ssid_len = elen;
183 case WLAN_EID_SUPP_RATES:
184 elems->supp_rates = pos;
185 elems->supp_rates_len = elen;
187 case WLAN_EID_FH_PARAMS:
188 elems->fh_params = pos;
189 elems->fh_params_len = elen;
191 case WLAN_EID_DS_PARAMS:
192 elems->ds_params = pos;
193 elems->ds_params_len = elen;
195 case WLAN_EID_CF_PARAMS:
196 elems->cf_params = pos;
197 elems->cf_params_len = elen;
201 elems->tim_len = elen;
203 case WLAN_EID_IBSS_PARAMS:
204 elems->ibss_params = pos;
205 elems->ibss_params_len = elen;
207 case WLAN_EID_CHALLENGE:
208 elems->challenge = pos;
209 elems->challenge_len = elen;
211 case WLAN_EID_ERP_INFO:
212 elems->erp_info = pos;
213 elems->erp_info_len = elen;
215 case WLAN_EID_EXT_SUPP_RATES:
216 elems->ext_supp_rates = pos;
217 elems->ext_supp_rates_len = elen;
219 case WLAN_EID_VENDOR_SPECIFIC:
220 if (ieee802_11_parse_vendor_specific(pos, elen,
227 elems->rsn_ie_len = elen;
229 case WLAN_EID_PWR_CAPABILITY:
230 elems->power_cap = pos;
231 elems->power_cap_len = elen;
233 case WLAN_EID_SUPPORTED_CHANNELS:
234 elems->supp_channels = pos;
235 elems->supp_channels_len = elen;
237 case WLAN_EID_MOBILITY_DOMAIN:
239 elems->mdie_len = elen;
241 case WLAN_EID_FAST_BSS_TRANSITION:
243 elems->ftie_len = elen;
245 case WLAN_EID_TIMEOUT_INTERVAL:
246 elems->timeout_int = pos;
247 elems->timeout_int_len = elen;
249 case WLAN_EID_HT_CAP:
250 elems->ht_capabilities = pos;
251 elems->ht_capabilities_len = elen;
253 case WLAN_EID_HT_OPERATION:
254 elems->ht_operation = pos;
255 elems->ht_operation_len = elen;
261 wpa_printf(MSG_MSGDUMP, "IEEE 802.11 element parse "
262 "ignored unknown element (id=%d elen=%d)",
274 return unknown ? ParseUnknown : ParseOK;
278 int ieee802_11_ie_count(const u8 *ies, size_t ies_len)
289 while (pos + 2 <= end) {
290 if (pos + 2 + pos[1] > end)
300 struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
304 const u8 *end, *pos, *ie;
310 while (pos + 1 < end) {
311 if (pos + 2 + pos[1] > end)
313 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
314 WPA_GET_BE32(&pos[2]) == oui_type) {
322 return NULL; /* No specified vendor IE found */
324 buf = wpabuf_alloc(ies_len);
329 * There may be multiple vendor IEs in the message, so need to
330 * concatenate their data fields.
332 while (pos + 1 < end) {
333 if (pos + 2 + pos[1] > end)
335 if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
336 WPA_GET_BE32(&pos[2]) == oui_type)
337 wpabuf_put_data(buf, pos + 6, pos[1] - 4);