2 * IEEE 802.11 Common routines
3 * Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #ifndef IEEE802_11_COMMON_H
10 #define IEEE802_11_COMMON_H
13 #include "ieee802_11_defs.h"
21 struct hostapd_hw_modes;
23 #define MAX_NOF_MB_IES_SUPPORTED 5
29 } ies[MAX_NOF_MB_IES_SUPPORTED];
33 /* Parsed Information Elements */
34 struct ieee802_11_elems {
40 const u8 *ext_supp_rates;
43 const u8 *wmm; /* WMM Information or Parameter Element */
46 const u8 *supp_channels;
49 const u8 *timeout_int;
50 const u8 *ht_capabilities;
51 const u8 *ht_operation;
52 const u8 *mesh_config;
55 const u8 *vht_capabilities;
56 const u8 *vht_operation;
57 const u8 *vht_opmode_notif;
58 const u8 *vendor_ht_cap;
63 const u8 *interworking;
64 const u8 *qos_map_set;
67 const u8 *bss_max_idle_period;
73 const u8 *pref_freq_list;
74 const u8 *supp_op_classes;
75 const u8 *rrm_enabled;
80 const u8 *assoc_delay_info;
81 const u8 *fils_req_params;
82 const u8 *fils_key_confirm;
83 const u8 *fils_session;
85 const u8 *fils_ip_addr_assign;
86 const u8 *key_delivery;
87 const u8 *fils_wrapped_data;
91 const u8 *power_capab;
92 const u8 *roaming_cons_sel;
93 const u8 *password_id;
96 const u8 *he_capabilities;
101 u8 ext_supp_rates_len;
104 u8 wmm_len; /* 7 = WMM Information; 24 = WMM Parameter */
107 u8 supp_channels_len;
113 u8 vendor_ht_cap_len;
126 u8 pref_freq_list_len;
127 u8 supp_op_classes_len;
132 u8 fils_req_params_len;
133 u8 fils_key_confirm_len;
135 u8 fils_ip_addr_assign_len;
137 u8 fils_wrapped_data_len;
141 u8 roaming_cons_sel_len;
145 u8 he_capabilities_len;
147 struct mb_ies_info mb_ies;
150 typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
152 ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
153 struct ieee802_11_elems *elems,
155 int ieee802_11_ie_count(const u8 *ies, size_t ies_len);
156 struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
158 struct ieee80211_hdr;
159 const u8 * get_hdr_bssid(const struct ieee80211_hdr *hdr, size_t len);
161 struct hostapd_wmm_ac_params {
165 int txop_limit; /* in units of 32us */
166 int admission_control_mandatory;
169 int hostapd_config_wmm_ac(struct hostapd_wmm_ac_params wmm_ac_params[],
170 const char *name, const char *val);
171 enum hostapd_hw_mode ieee80211_freq_to_chan(int freq, u8 *channel);
172 int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan);
173 enum hostapd_hw_mode ieee80211_freq_to_channel_ext(unsigned int freq,
174 int sec_channel, int vht,
175 u8 *op_class, u8 *channel);
176 int ieee80211_chaninfo_to_channel(unsigned int freq, enum chan_width chanwidth,
177 int sec_channel, u8 *op_class, u8 *channel);
178 int ieee80211_is_dfs(int freq, const struct hostapd_hw_modes *modes,
180 enum phy_type ieee80211_get_phy_type(int freq, int ht, int vht);
182 int supp_rates_11b_only(struct ieee802_11_elems *elems);
183 int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf,
185 struct wpabuf * mb_ies_by_info(struct mb_ies_info *info);
187 const char * fc2str(u16 fc);
189 struct oper_class_map {
190 enum hostapd_hw_mode mode;
195 enum { BW20, BW40PLUS, BW40MINUS, BW80, BW2160, BW160, BW80P80 } bw;
196 enum { P2P_SUPP, NO_P2P_SUPP } p2p;
199 extern const struct oper_class_map global_op_class[];
200 extern size_t global_op_class_size;
202 const u8 * get_ie(const u8 *ies, size_t len, u8 eid);
203 const u8 * get_ie_ext(const u8 *ies, size_t len, u8 ext);
204 const u8 * get_vendor_ie(const u8 *ies, size_t len, u32 vendor_type);
206 size_t mbo_add_ie(u8 *buf, size_t len, const u8 *attr, size_t attr_len);
208 size_t add_multi_ap_ie(u8 *buf, size_t len, u8 value);
210 struct country_op_class {
215 u8 country_to_global_op_class(const char *country, u8 op_class);
217 const struct oper_class_map * get_oper_class(const char *country, u8 op_class);
218 int oper_class_bw_to_int(const struct oper_class_map *map);
220 int ieee802_11_parse_candidate_list(const char *pos, u8 *nei_rep,
223 int ieee802_11_ext_capab(const u8 *ie, unsigned int capab);
225 /* element iteration helpers */
226 #define for_each_element(_elem, _data, _datalen) \
227 for (_elem = (const struct element *) (_data); \
228 (const u8 *) (_data) + (_datalen) - (const u8 *) _elem >= \
229 (int) sizeof(*_elem) && \
230 (const u8 *) (_data) + (_datalen) - (const u8 *) _elem >= \
231 (int) sizeof(*_elem) + _elem->datalen; \
232 _elem = (const struct element *) (_elem->data + _elem->datalen))
234 #define for_each_element_id(element, _id, data, datalen) \
235 for_each_element(element, data, datalen) \
236 if (element->id == (_id))
238 #define for_each_element_extid(element, extid, _data, _datalen) \
239 for_each_element(element, _data, _datalen) \
240 if (element->id == WLAN_EID_EXTENSION && \
241 element->datalen > 0 && \
242 element->data[0] == (extid))
244 #define for_each_subelement(sub, element) \
245 for_each_element(sub, (element)->data, (element)->datalen)
247 #define for_each_subelement_id(sub, id, element) \
248 for_each_element_id(sub, id, (element)->data, (element)->datalen)
250 #define for_each_subelement_extid(sub, extid, element) \
251 for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
254 * for_each_element_completed - Determine if element parsing consumed all data
255 * @element: Element pointer after for_each_element() or friends
256 * @data: Same data pointer as passed to for_each_element() or friends
257 * @datalen: Same data length as passed to for_each_element() or friends
259 * This function returns 1 if all the data was parsed or considered
260 * while walking the elements. Only use this if your for_each_element()
261 * loop cannot be broken out of, otherwise it always returns 0.
263 * If some data was malformed, this returns %false since the last parsed
264 * element will not fill the whole remaining data.
266 static inline int for_each_element_completed(const struct element *element,
267 const void *data, size_t datalen)
269 return (const u8 *) element == (const u8 *) data + datalen;
272 #endif /* IEEE802_11_COMMON_H */