2008-10-29 20:48:14 +01:00
|
|
|
/*
|
|
|
|
* IEEE 802.11 Common routines
|
2019-01-02 16:56:41 +01:00
|
|
|
* Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi>
|
2008-10-29 20:48:14 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-10-29 20:48:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef IEEE802_11_COMMON_H
|
|
|
|
#define IEEE802_11_COMMON_H
|
|
|
|
|
2016-02-15 15:53:32 +01:00
|
|
|
#include "defs.h"
|
2019-01-07 16:26:40 +01:00
|
|
|
#include "ieee802_11_defs.h"
|
2016-02-15 15:53:32 +01:00
|
|
|
|
2019-02-08 17:57:48 +01:00
|
|
|
struct element {
|
|
|
|
u8 id;
|
|
|
|
u8 datalen;
|
|
|
|
u8 data[];
|
|
|
|
} STRUCT_PACKED;
|
|
|
|
|
2018-04-13 11:55:40 +02:00
|
|
|
struct hostapd_hw_modes;
|
|
|
|
|
2015-01-21 14:30:48 +01:00
|
|
|
#define MAX_NOF_MB_IES_SUPPORTED 5
|
2020-02-24 10:14:33 +01:00
|
|
|
#define MAX_NUM_FRAG_IES_SUPPORTED 3
|
2015-01-21 14:30:48 +01:00
|
|
|
|
|
|
|
struct mb_ies_info {
|
|
|
|
struct {
|
|
|
|
const u8 *ie;
|
|
|
|
u8 ie_len;
|
|
|
|
} ies[MAX_NOF_MB_IES_SUPPORTED];
|
|
|
|
u8 nof_ies;
|
|
|
|
};
|
|
|
|
|
2020-02-24 10:14:33 +01:00
|
|
|
struct frag_ies_info {
|
|
|
|
struct {
|
|
|
|
u8 eid;
|
|
|
|
u8 eid_ext;
|
|
|
|
const u8 *ie;
|
|
|
|
u8 ie_len;
|
|
|
|
} frags[MAX_NUM_FRAG_IES_SUPPORTED];
|
|
|
|
|
|
|
|
u8 n_frags;
|
|
|
|
|
|
|
|
/* the last parsed element ID and element extension ID */
|
|
|
|
u8 last_eid;
|
|
|
|
u8 last_eid_ext;
|
|
|
|
};
|
|
|
|
|
2008-10-29 20:48:14 +01:00
|
|
|
/* Parsed Information Elements */
|
|
|
|
struct ieee802_11_elems {
|
2009-12-13 22:11:11 +01:00
|
|
|
const u8 *ssid;
|
|
|
|
const u8 *supp_rates;
|
|
|
|
const u8 *ds_params;
|
|
|
|
const u8 *challenge;
|
|
|
|
const u8 *erp_info;
|
|
|
|
const u8 *ext_supp_rates;
|
|
|
|
const u8 *wpa_ie;
|
|
|
|
const u8 *rsn_ie;
|
2019-10-17 15:53:09 +02:00
|
|
|
const u8 *rsnxe;
|
2009-12-13 22:11:11 +01:00
|
|
|
const u8 *wmm; /* WMM Information or Parameter Element */
|
|
|
|
const u8 *wmm_tspec;
|
|
|
|
const u8 *wps_ie;
|
|
|
|
const u8 *supp_channels;
|
|
|
|
const u8 *mdie;
|
|
|
|
const u8 *ftie;
|
|
|
|
const u8 *timeout_int;
|
|
|
|
const u8 *ht_capabilities;
|
|
|
|
const u8 *ht_operation;
|
2014-09-01 06:23:25 +02:00
|
|
|
const u8 *mesh_config;
|
|
|
|
const u8 *mesh_id;
|
|
|
|
const u8 *peer_mgmt;
|
2012-08-10 18:39:43 +02:00
|
|
|
const u8 *vht_capabilities;
|
|
|
|
const u8 *vht_operation;
|
2014-02-10 13:43:05 +01:00
|
|
|
const u8 *vht_opmode_notif;
|
2009-12-13 22:11:11 +01:00
|
|
|
const u8 *vendor_ht_cap;
|
2014-11-10 16:12:29 +01:00
|
|
|
const u8 *vendor_vht;
|
2010-07-18 23:30:24 +02:00
|
|
|
const u8 *p2p;
|
2012-03-02 16:26:01 +01:00
|
|
|
const u8 *wfd;
|
2010-12-13 10:20:55 +01:00
|
|
|
const u8 *link_id;
|
2011-10-21 11:43:24 +02:00
|
|
|
const u8 *interworking;
|
2013-07-24 12:17:56 +02:00
|
|
|
const u8 *qos_map_set;
|
2011-10-03 17:23:01 +02:00
|
|
|
const u8 *hs20;
|
2012-05-28 02:35:00 +02:00
|
|
|
const u8 *ext_capab;
|
|
|
|
const u8 *bss_max_idle_period;
|
2012-12-16 20:22:24 +01:00
|
|
|
const u8 *ssid_list;
|
2013-07-23 20:23:25 +02:00
|
|
|
const u8 *osen;
|
2016-02-21 19:54:23 +01:00
|
|
|
const u8 *mbo;
|
2014-09-01 06:23:25 +02:00
|
|
|
const u8 *ampe;
|
|
|
|
const u8 *mic;
|
2015-07-24 02:39:45 +02:00
|
|
|
const u8 *pref_freq_list;
|
2016-02-24 11:20:31 +01:00
|
|
|
const u8 *supp_op_classes;
|
2016-04-06 18:42:10 +02:00
|
|
|
const u8 *rrm_enabled;
|
2015-09-01 16:50:04 +02:00
|
|
|
const u8 *cag_number;
|
|
|
|
const u8 *ap_csn;
|
|
|
|
const u8 *fils_indic;
|
|
|
|
const u8 *dils;
|
|
|
|
const u8 *assoc_delay_info;
|
|
|
|
const u8 *fils_req_params;
|
|
|
|
const u8 *fils_key_confirm;
|
|
|
|
const u8 *fils_session;
|
|
|
|
const u8 *fils_hlp;
|
|
|
|
const u8 *fils_ip_addr_assign;
|
|
|
|
const u8 *key_delivery;
|
2020-02-24 10:14:32 +01:00
|
|
|
const u8 *wrapped_data;
|
2015-09-01 16:50:04 +02:00
|
|
|
const u8 *fils_pk;
|
|
|
|
const u8 *fils_nonce;
|
2017-03-11 23:23:36 +01:00
|
|
|
const u8 *owe_dh;
|
2017-10-06 17:03:25 +02:00
|
|
|
const u8 *power_capab;
|
2018-04-17 12:08:31 +02:00
|
|
|
const u8 *roaming_cons_sel;
|
2018-05-19 16:28:01 +02:00
|
|
|
const u8 *password_id;
|
2018-08-06 21:46:28 +02:00
|
|
|
const u8 *oci;
|
2018-12-05 11:23:51 +01:00
|
|
|
const u8 *multi_ap;
|
2019-02-14 21:23:05 +01:00
|
|
|
const u8 *he_capabilities;
|
2019-05-20 09:55:05 +02:00
|
|
|
const u8 *he_operation;
|
2019-06-19 14:49:16 +02:00
|
|
|
const u8 *short_ssid_list;
|
2009-12-13 22:11:11 +01:00
|
|
|
|
2008-10-29 20:48:14 +01:00
|
|
|
u8 ssid_len;
|
|
|
|
u8 supp_rates_len;
|
|
|
|
u8 challenge_len;
|
|
|
|
u8 ext_supp_rates_len;
|
|
|
|
u8 wpa_ie_len;
|
|
|
|
u8 rsn_ie_len;
|
2019-10-17 15:53:09 +02:00
|
|
|
u8 rsnxe_len;
|
2009-03-04 11:33:24 +01:00
|
|
|
u8 wmm_len; /* 7 = WMM Information; 24 = WMM Parameter */
|
|
|
|
u8 wmm_tspec_len;
|
2008-11-23 18:34:26 +01:00
|
|
|
u8 wps_ie_len;
|
2008-10-29 20:48:14 +01:00
|
|
|
u8 supp_channels_len;
|
|
|
|
u8 mdie_len;
|
|
|
|
u8 ftie_len;
|
2014-09-01 06:23:25 +02:00
|
|
|
u8 mesh_config_len;
|
|
|
|
u8 mesh_id_len;
|
|
|
|
u8 peer_mgmt_len;
|
2008-12-04 12:42:33 +01:00
|
|
|
u8 vendor_ht_cap_len;
|
2014-11-10 16:12:29 +01:00
|
|
|
u8 vendor_vht_len;
|
2010-07-18 23:30:24 +02:00
|
|
|
u8 p2p_len;
|
2012-03-02 16:26:01 +01:00
|
|
|
u8 wfd_len;
|
2011-10-21 11:43:24 +02:00
|
|
|
u8 interworking_len;
|
2013-07-24 12:17:56 +02:00
|
|
|
u8 qos_map_set_len;
|
2011-10-03 17:23:01 +02:00
|
|
|
u8 hs20_len;
|
2012-05-28 02:35:00 +02:00
|
|
|
u8 ext_capab_len;
|
2012-12-16 20:22:24 +01:00
|
|
|
u8 ssid_list_len;
|
2013-07-23 20:23:25 +02:00
|
|
|
u8 osen_len;
|
2016-02-21 19:54:23 +01:00
|
|
|
u8 mbo_len;
|
2014-09-01 06:23:25 +02:00
|
|
|
u8 ampe_len;
|
|
|
|
u8 mic_len;
|
2015-07-24 02:39:45 +02:00
|
|
|
u8 pref_freq_list_len;
|
2016-02-24 11:20:31 +01:00
|
|
|
u8 supp_op_classes_len;
|
2016-04-06 18:42:10 +02:00
|
|
|
u8 rrm_enabled_len;
|
2015-09-01 16:50:04 +02:00
|
|
|
u8 cag_number_len;
|
|
|
|
u8 fils_indic_len;
|
|
|
|
u8 dils_len;
|
|
|
|
u8 fils_req_params_len;
|
|
|
|
u8 fils_key_confirm_len;
|
|
|
|
u8 fils_hlp_len;
|
|
|
|
u8 fils_ip_addr_assign_len;
|
|
|
|
u8 key_delivery_len;
|
2020-02-24 10:14:32 +01:00
|
|
|
u8 wrapped_data_len;
|
2015-09-01 16:50:04 +02:00
|
|
|
u8 fils_pk_len;
|
2017-03-11 23:23:36 +01:00
|
|
|
u8 owe_dh_len;
|
2017-10-06 17:03:25 +02:00
|
|
|
u8 power_capab_len;
|
2018-04-17 12:08:31 +02:00
|
|
|
u8 roaming_cons_sel_len;
|
2018-05-19 16:28:01 +02:00
|
|
|
u8 password_id_len;
|
2018-08-06 21:46:28 +02:00
|
|
|
u8 oci_len;
|
2018-12-05 11:23:51 +01:00
|
|
|
u8 multi_ap_len;
|
2019-02-14 21:23:05 +01:00
|
|
|
u8 he_capabilities_len;
|
2019-05-20 09:55:05 +02:00
|
|
|
u8 he_operation_len;
|
2019-06-19 14:49:16 +02:00
|
|
|
u8 short_ssid_list_len;
|
2016-02-24 11:20:31 +01:00
|
|
|
|
2015-01-21 14:30:48 +01:00
|
|
|
struct mb_ies_info mb_ies;
|
2020-02-24 10:14:33 +01:00
|
|
|
struct frag_ies_info frag_ies;
|
2008-10-29 20:48:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
|
|
|
|
|
2009-12-13 22:11:11 +01:00
|
|
|
ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
|
2008-10-29 20:48:14 +01:00
|
|
|
struct ieee802_11_elems *elems,
|
|
|
|
int show_errors);
|
2009-03-09 19:45:17 +01:00
|
|
|
int ieee802_11_ie_count(const u8 *ies, size_t ies_len);
|
2009-09-11 15:36:59 +02:00
|
|
|
struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
|
|
|
|
u32 oui_type);
|
2011-10-20 20:50:23 +02:00
|
|
|
struct ieee80211_hdr;
|
|
|
|
const u8 * get_hdr_bssid(const struct ieee80211_hdr *hdr, size_t len);
|
2008-10-29 20:48:14 +01:00
|
|
|
|
2012-08-12 10:33:00 +02:00
|
|
|
struct hostapd_wmm_ac_params {
|
|
|
|
int cwmin;
|
|
|
|
int cwmax;
|
|
|
|
int aifs;
|
|
|
|
int txop_limit; /* in units of 32us */
|
|
|
|
int admission_control_mandatory;
|
|
|
|
};
|
|
|
|
|
|
|
|
int hostapd_config_wmm_ac(struct hostapd_wmm_ac_params wmm_ac_params[],
|
|
|
|
const char *name, const char *val);
|
2013-04-27 20:27:15 +02:00
|
|
|
enum hostapd_hw_mode ieee80211_freq_to_chan(int freq, u8 *channel);
|
2014-11-22 18:48:08 +01:00
|
|
|
int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan);
|
2015-07-27 21:24:18 +02:00
|
|
|
enum hostapd_hw_mode ieee80211_freq_to_channel_ext(unsigned int freq,
|
|
|
|
int sec_channel, int vht,
|
|
|
|
u8 *op_class, u8 *channel);
|
2018-08-06 21:46:22 +02:00
|
|
|
int ieee80211_chaninfo_to_channel(unsigned int freq, enum chan_width chanwidth,
|
|
|
|
int sec_channel, u8 *op_class, u8 *channel);
|
2018-04-13 11:55:40 +02:00
|
|
|
int ieee80211_is_dfs(int freq, const struct hostapd_hw_modes *modes,
|
|
|
|
u16 num_modes);
|
2016-02-15 15:53:40 +01:00
|
|
|
enum phy_type ieee80211_get_phy_type(int freq, int ht, int vht);
|
2012-08-12 10:33:00 +02:00
|
|
|
|
2013-06-19 18:16:23 +02:00
|
|
|
int supp_rates_11b_only(struct ieee802_11_elems *elems);
|
2015-01-21 14:30:48 +01:00
|
|
|
int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf,
|
|
|
|
size_t ies_len);
|
|
|
|
struct wpabuf * mb_ies_by_info(struct mb_ies_info *info);
|
2013-06-19 18:16:23 +02:00
|
|
|
|
2014-06-03 10:24:53 +02:00
|
|
|
const char * fc2str(u16 fc);
|
2019-04-15 21:20:05 +02:00
|
|
|
const char * reason2str(u16 reason);
|
2019-04-18 20:03:21 +02:00
|
|
|
const char * status2str(u16 status);
|
2016-02-15 15:53:17 +01:00
|
|
|
|
2016-02-15 15:53:32 +01:00
|
|
|
struct oper_class_map {
|
|
|
|
enum hostapd_hw_mode mode;
|
|
|
|
u8 op_class;
|
|
|
|
u8 min_chan;
|
|
|
|
u8 max_chan;
|
|
|
|
u8 inc;
|
2019-12-04 15:40:22 +01:00
|
|
|
enum { BW20, BW40PLUS, BW40MINUS, BW80, BW2160, BW160, BW80P80, BW4320,
|
|
|
|
BW6480, BW8640} bw;
|
2016-02-15 15:53:32 +01:00
|
|
|
enum { P2P_SUPP, NO_P2P_SUPP } p2p;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct oper_class_map global_op_class[];
|
|
|
|
extern size_t global_op_class_size;
|
|
|
|
|
2016-02-15 15:53:17 +01:00
|
|
|
const u8 * get_ie(const u8 *ies, size_t len, u8 eid);
|
2017-10-10 17:26:29 +02:00
|
|
|
const u8 * get_ie_ext(const u8 *ies, size_t len, u8 ext);
|
2017-08-21 18:43:52 +02:00
|
|
|
const u8 * get_vendor_ie(const u8 *ies, size_t len, u32 vendor_type);
|
2016-02-15 15:53:17 +01:00
|
|
|
|
2016-02-15 15:53:24 +01:00
|
|
|
size_t mbo_add_ie(u8 *buf, size_t len, const u8 *attr, size_t attr_len);
|
|
|
|
|
2018-12-05 11:23:51 +01:00
|
|
|
size_t add_multi_ap_ie(u8 *buf, size_t len, u8 value);
|
|
|
|
|
2016-12-28 14:06:42 +01:00
|
|
|
struct country_op_class {
|
|
|
|
u8 country_op_class;
|
|
|
|
u8 global_op_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
u8 country_to_global_op_class(const char *country, u8 op_class);
|
|
|
|
|
2016-12-28 14:06:43 +01:00
|
|
|
const struct oper_class_map * get_oper_class(const char *country, u8 op_class);
|
2018-08-06 21:46:23 +02:00
|
|
|
int oper_class_bw_to_int(const struct oper_class_map *map);
|
2019-06-19 14:49:11 +02:00
|
|
|
int center_idx_to_bw_6ghz(u8 idx);
|
|
|
|
int is_6ghz_freq(int freq);
|
2019-06-19 14:49:13 +02:00
|
|
|
int is_6ghz_op_class(u8 op_class);
|
2019-11-26 06:49:32 +01:00
|
|
|
int is_6ghz_psc_frequency(int freq);
|
2016-12-28 14:06:43 +01:00
|
|
|
|
2017-03-08 13:37:39 +01:00
|
|
|
int ieee802_11_parse_candidate_list(const char *pos, u8 *nei_rep,
|
|
|
|
size_t nei_rep_len);
|
|
|
|
|
2019-01-02 16:56:41 +01:00
|
|
|
int ieee802_11_ext_capab(const u8 *ie, unsigned int capab);
|
2019-12-06 14:47:29 +01:00
|
|
|
int op_class_to_bandwidth(u8 op_class);
|
|
|
|
int op_class_to_ch_width(u8 op_class);
|
2019-01-02 16:56:41 +01:00
|
|
|
|
2019-02-08 17:57:48 +01:00
|
|
|
/* element iteration helpers */
|
|
|
|
#define for_each_element(_elem, _data, _datalen) \
|
|
|
|
for (_elem = (const struct element *) (_data); \
|
|
|
|
(const u8 *) (_data) + (_datalen) - (const u8 *) _elem >= \
|
|
|
|
(int) sizeof(*_elem) && \
|
|
|
|
(const u8 *) (_data) + (_datalen) - (const u8 *) _elem >= \
|
|
|
|
(int) sizeof(*_elem) + _elem->datalen; \
|
|
|
|
_elem = (const struct element *) (_elem->data + _elem->datalen))
|
|
|
|
|
|
|
|
#define for_each_element_id(element, _id, data, datalen) \
|
|
|
|
for_each_element(element, data, datalen) \
|
|
|
|
if (element->id == (_id))
|
|
|
|
|
|
|
|
#define for_each_element_extid(element, extid, _data, _datalen) \
|
|
|
|
for_each_element(element, _data, _datalen) \
|
|
|
|
if (element->id == WLAN_EID_EXTENSION && \
|
|
|
|
element->datalen > 0 && \
|
|
|
|
element->data[0] == (extid))
|
|
|
|
|
|
|
|
#define for_each_subelement(sub, element) \
|
|
|
|
for_each_element(sub, (element)->data, (element)->datalen)
|
|
|
|
|
|
|
|
#define for_each_subelement_id(sub, id, element) \
|
|
|
|
for_each_element_id(sub, id, (element)->data, (element)->datalen)
|
|
|
|
|
|
|
|
#define for_each_subelement_extid(sub, extid, element) \
|
|
|
|
for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* for_each_element_completed - Determine if element parsing consumed all data
|
|
|
|
* @element: Element pointer after for_each_element() or friends
|
|
|
|
* @data: Same data pointer as passed to for_each_element() or friends
|
|
|
|
* @datalen: Same data length as passed to for_each_element() or friends
|
|
|
|
*
|
|
|
|
* This function returns 1 if all the data was parsed or considered
|
|
|
|
* while walking the elements. Only use this if your for_each_element()
|
|
|
|
* loop cannot be broken out of, otherwise it always returns 0.
|
|
|
|
*
|
|
|
|
* If some data was malformed, this returns %false since the last parsed
|
|
|
|
* element will not fill the whole remaining data.
|
|
|
|
*/
|
|
|
|
static inline int for_each_element_completed(const struct element *element,
|
|
|
|
const void *data, size_t datalen)
|
|
|
|
{
|
|
|
|
return (const u8 *) element == (const u8 *) data + datalen;
|
|
|
|
}
|
|
|
|
|
2019-09-11 11:03:07 +02:00
|
|
|
struct ieee80211_edmg_config;
|
|
|
|
|
|
|
|
void hostapd_encode_edmg_chan(int edmg_enable, u8 edmg_channel,
|
|
|
|
int primary_channel,
|
|
|
|
struct ieee80211_edmg_config *edmg);
|
|
|
|
|
|
|
|
int ieee802_edmg_is_allowed(struct ieee80211_edmg_config allowed,
|
|
|
|
struct ieee80211_edmg_config requested);
|
|
|
|
|
2020-02-24 10:14:33 +01:00
|
|
|
struct wpabuf * ieee802_11_defrag_data(struct ieee802_11_elems *elems,
|
|
|
|
u8 eid, u8 eid_ext,
|
|
|
|
const u8 *data, u8 len);
|
|
|
|
struct wpabuf * ieee802_11_defrag(struct ieee802_11_elems *elems,
|
|
|
|
u8 eid, u8 eid_ext);
|
|
|
|
|
2008-10-29 20:48:14 +01:00
|
|
|
#endif /* IEEE802_11_COMMON_H */
|