Home | History | Annotate | Download | only in common
      1 /*
      2  * IEEE 802.11 Common routines
      3  * Copyright (c) 2002-2012, Jouni Malinen <j (at) 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 #ifndef IEEE802_11_COMMON_H
     10 #define IEEE802_11_COMMON_H
     11 
     12 #include "defs.h"
     13 
     14 #define MAX_NOF_MB_IES_SUPPORTED 5
     15 
     16 struct mb_ies_info {
     17 	struct {
     18 		const u8 *ie;
     19 		u8 ie_len;
     20 	} ies[MAX_NOF_MB_IES_SUPPORTED];
     21 	u8 nof_ies;
     22 };
     23 
     24 /* Parsed Information Elements */
     25 struct ieee802_11_elems {
     26 	const u8 *ssid;
     27 	const u8 *supp_rates;
     28 	const u8 *ds_params;
     29 	const u8 *challenge;
     30 	const u8 *erp_info;
     31 	const u8 *ext_supp_rates;
     32 	const u8 *wpa_ie;
     33 	const u8 *rsn_ie;
     34 	const u8 *wmm; /* WMM Information or Parameter Element */
     35 	const u8 *wmm_tspec;
     36 	const u8 *wps_ie;
     37 	const u8 *supp_channels;
     38 	const u8 *mdie;
     39 	const u8 *ftie;
     40 	const u8 *timeout_int;
     41 	const u8 *ht_capabilities;
     42 	const u8 *ht_operation;
     43 	const u8 *mesh_config;
     44 	const u8 *mesh_id;
     45 	const u8 *peer_mgmt;
     46 	const u8 *vht_capabilities;
     47 	const u8 *vht_operation;
     48 	const u8 *vht_opmode_notif;
     49 	const u8 *vendor_ht_cap;
     50 	const u8 *vendor_vht;
     51 	const u8 *p2p;
     52 	const u8 *wfd;
     53 	const u8 *link_id;
     54 	const u8 *interworking;
     55 	const u8 *qos_map_set;
     56 	const u8 *hs20;
     57 	const u8 *ext_capab;
     58 	const u8 *bss_max_idle_period;
     59 	const u8 *ssid_list;
     60 	const u8 *osen;
     61 	const u8 *mbo;
     62 	const u8 *ampe;
     63 	const u8 *mic;
     64 	const u8 *pref_freq_list;
     65 	const u8 *supp_op_classes;
     66 	const u8 *rrm_enabled;
     67 	const u8 *cag_number;
     68 	const u8 *ap_csn;
     69 	const u8 *fils_indic;
     70 	const u8 *dils;
     71 	const u8 *assoc_delay_info;
     72 	const u8 *fils_req_params;
     73 	const u8 *fils_key_confirm;
     74 	const u8 *fils_session;
     75 	const u8 *fils_hlp;
     76 	const u8 *fils_ip_addr_assign;
     77 	const u8 *key_delivery;
     78 	const u8 *fils_wrapped_data;
     79 	const u8 *fils_pk;
     80 	const u8 *fils_nonce;
     81 	const u8 *owe_dh;
     82 
     83 	u8 ssid_len;
     84 	u8 supp_rates_len;
     85 	u8 challenge_len;
     86 	u8 ext_supp_rates_len;
     87 	u8 wpa_ie_len;
     88 	u8 rsn_ie_len;
     89 	u8 wmm_len; /* 7 = WMM Information; 24 = WMM Parameter */
     90 	u8 wmm_tspec_len;
     91 	u8 wps_ie_len;
     92 	u8 supp_channels_len;
     93 	u8 mdie_len;
     94 	u8 ftie_len;
     95 	u8 mesh_config_len;
     96 	u8 mesh_id_len;
     97 	u8 peer_mgmt_len;
     98 	u8 vendor_ht_cap_len;
     99 	u8 vendor_vht_len;
    100 	u8 p2p_len;
    101 	u8 wfd_len;
    102 	u8 interworking_len;
    103 	u8 qos_map_set_len;
    104 	u8 hs20_len;
    105 	u8 ext_capab_len;
    106 	u8 ssid_list_len;
    107 	u8 osen_len;
    108 	u8 mbo_len;
    109 	u8 ampe_len;
    110 	u8 mic_len;
    111 	u8 pref_freq_list_len;
    112 	u8 supp_op_classes_len;
    113 	u8 rrm_enabled_len;
    114 	u8 cag_number_len;
    115 	u8 fils_indic_len;
    116 	u8 dils_len;
    117 	u8 fils_req_params_len;
    118 	u8 fils_key_confirm_len;
    119 	u8 fils_hlp_len;
    120 	u8 fils_ip_addr_assign_len;
    121 	u8 key_delivery_len;
    122 	u8 fils_wrapped_data_len;
    123 	u8 fils_pk_len;
    124 	u8 owe_dh_len;
    125 
    126 	struct mb_ies_info mb_ies;
    127 };
    128 
    129 typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
    130 
    131 ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
    132 				struct ieee802_11_elems *elems,
    133 				int show_errors);
    134 int ieee802_11_ie_count(const u8 *ies, size_t ies_len);
    135 struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
    136 					    u32 oui_type);
    137 struct ieee80211_hdr;
    138 const u8 * get_hdr_bssid(const struct ieee80211_hdr *hdr, size_t len);
    139 
    140 struct hostapd_wmm_ac_params {
    141 	int cwmin;
    142 	int cwmax;
    143 	int aifs;
    144 	int txop_limit; /* in units of 32us */
    145 	int admission_control_mandatory;
    146 };
    147 
    148 int hostapd_config_wmm_ac(struct hostapd_wmm_ac_params wmm_ac_params[],
    149 			  const char *name, const char *val);
    150 enum hostapd_hw_mode ieee80211_freq_to_chan(int freq, u8 *channel);
    151 int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan);
    152 enum hostapd_hw_mode ieee80211_freq_to_channel_ext(unsigned int freq,
    153 						   int sec_channel, int vht,
    154 						   u8 *op_class, u8 *channel);
    155 int ieee80211_is_dfs(int freq);
    156 enum phy_type ieee80211_get_phy_type(int freq, int ht, int vht);
    157 
    158 int supp_rates_11b_only(struct ieee802_11_elems *elems);
    159 int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf,
    160 		       size_t ies_len);
    161 struct wpabuf * mb_ies_by_info(struct mb_ies_info *info);
    162 
    163 const char * fc2str(u16 fc);
    164 
    165 struct oper_class_map {
    166 	enum hostapd_hw_mode mode;
    167 	u8 op_class;
    168 	u8 min_chan;
    169 	u8 max_chan;
    170 	u8 inc;
    171 	enum { BW20, BW40PLUS, BW40MINUS, BW80, BW2160, BW160, BW80P80 } bw;
    172 	enum { P2P_SUPP, NO_P2P_SUPP } p2p;
    173 };
    174 
    175 extern const struct oper_class_map global_op_class[];
    176 extern size_t global_op_class_size;
    177 
    178 const u8 * get_ie(const u8 *ies, size_t len, u8 eid);
    179 const u8 * get_ie_ext(const u8 *ies, size_t len, u8 ext);
    180 
    181 size_t mbo_add_ie(u8 *buf, size_t len, const u8 *attr, size_t attr_len);
    182 
    183 struct country_op_class {
    184 	u8 country_op_class;
    185 	u8 global_op_class;
    186 };
    187 
    188 u8 country_to_global_op_class(const char *country, u8 op_class);
    189 
    190 const struct oper_class_map * get_oper_class(const char *country, u8 op_class);
    191 
    192 int ieee802_11_parse_candidate_list(const char *pos, u8 *nei_rep,
    193 				    size_t nei_rep_len);
    194 
    195 #endif /* IEEE802_11_COMMON_H */
    196