xref: /linux/drivers/net/wireless/intel/ipw2x00/libipw.h (revision 9410645520e9b820069761f3450ef6661418e279)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Merged with mainline ieee80211.h in Aug 2004.  Original ieee802_11
4  * remains copyright by the original authors
5  *
6  * Portions of the merged code are based on Host AP (software wireless
7  * LAN access point) driver for Intersil Prism2/2.5/3.
8  *
9  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
10  * <j@w1.fi>
11  * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
12  *
13  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
14  * <jketreno@linux.intel.com>
15  * Copyright (c) 2004-2005, Intel Corporation
16  *
17  * API Version History
18  * 1.0.x -- Initial version
19  * 1.1.x -- Added radiotap, QoS, TIM, libipw_geo APIs,
20  *          various structure changes, and crypto API init method
21  */
22 #ifndef LIBIPW_H
23 #define LIBIPW_H
24 #include <linux/if_ether.h>	/* ETH_ALEN */
25 #include <linux/kernel.h>	/* ARRAY_SIZE */
26 #include <linux/wireless.h>
27 #include <linux/ieee80211.h>
28 
29 #include <net/lib80211.h>
30 #include <net/cfg80211.h>
31 
32 #define LIBIPW_VERSION "git-1.1.13"
33 
34 #define LIBIPW_DATA_LEN		2304
35 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
36    6.2.1.1.2.
37 
38    The figure in section 7.1.2 suggests a body size of up to 2312
39    bytes is allowed, which is a bit confusing, I suspect this
40    represents the 2304 bytes of real data, plus a possible 8 bytes of
41    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
42 
43 #define LIBIPW_1ADDR_LEN 10
44 #define LIBIPW_2ADDR_LEN 16
45 #define LIBIPW_3ADDR_LEN 24
46 #define LIBIPW_4ADDR_LEN 30
47 #define LIBIPW_FCS_LEN    4
48 #define LIBIPW_HLEN			(LIBIPW_4ADDR_LEN)
49 #define LIBIPW_FRAME_LEN		(LIBIPW_DATA_LEN + LIBIPW_HLEN)
50 
51 #define MIN_FRAG_THRESHOLD     256U
52 #define	MAX_FRAG_THRESHOLD     2346U
53 
54 /* QOS control */
55 #define LIBIPW_QCTL_TID		0x000F
56 
57 /* debug macros */
58 
59 #ifdef CONFIG_LIBIPW_DEBUG
60 extern u32 libipw_debug_level;
61 #define LIBIPW_DEBUG(level, fmt, args...) \
62 do { if (libipw_debug_level & (level)) \
63   printk(KERN_DEBUG "libipw: %s " fmt, __func__ , ## args); } while (0)
64 #else
65 #define LIBIPW_DEBUG(level, fmt, args...) do {} while (0)
66 #endif				/* CONFIG_LIBIPW_DEBUG */
67 
68 /*
69  * To use the debug system:
70  *
71  * If you are defining a new debug classification, simply add it to the #define
72  * list here in the form of:
73  *
74  * #define LIBIPW_DL_xxxx VALUE
75  *
76  * shifting value to the left one bit from the previous entry.  xxxx should be
77  * the name of the classification (for example, WEP)
78  *
79  * You then need to either add a LIBIPW_xxxx_DEBUG() macro definition for your
80  * classification, or use LIBIPW_DEBUG(LIBIPW_DL_xxxx, ...) whenever you want
81  * to send output to that classification.
82  *
83  * To add your debug level to the list of levels seen when you perform
84  *
85  * % cat /proc/net/ieee80211/debug_level
86  *
87  * you simply need to add your entry to the libipw_debug_level array.
88  *
89  * If you do not see debug_level in /proc/net/ieee80211 then you do not have
90  * CONFIG_LIBIPW_DEBUG defined in your kernel configuration
91  *
92  */
93 
94 #define LIBIPW_DL_INFO          (1<<0)
95 #define LIBIPW_DL_WX            (1<<1)
96 #define LIBIPW_DL_SCAN          (1<<2)
97 #define LIBIPW_DL_STATE         (1<<3)
98 #define LIBIPW_DL_MGMT          (1<<4)
99 #define LIBIPW_DL_FRAG          (1<<5)
100 #define LIBIPW_DL_DROP          (1<<7)
101 
102 #define LIBIPW_DL_TX            (1<<8)
103 #define LIBIPW_DL_RX            (1<<9)
104 #define LIBIPW_DL_QOS           (1<<31)
105 
106 #define LIBIPW_ERROR(f, a...) printk(KERN_ERR "libipw: " f, ## a)
107 #define LIBIPW_WARNING(f, a...) printk(KERN_WARNING "libipw: " f, ## a)
108 #define LIBIPW_DEBUG_INFO(f, a...)   LIBIPW_DEBUG(LIBIPW_DL_INFO, f, ## a)
109 
110 #define LIBIPW_DEBUG_WX(f, a...)     LIBIPW_DEBUG(LIBIPW_DL_WX, f, ## a)
111 #define LIBIPW_DEBUG_SCAN(f, a...)   LIBIPW_DEBUG(LIBIPW_DL_SCAN, f, ## a)
112 #define LIBIPW_DEBUG_STATE(f, a...)  LIBIPW_DEBUG(LIBIPW_DL_STATE, f, ## a)
113 #define LIBIPW_DEBUG_MGMT(f, a...)  LIBIPW_DEBUG(LIBIPW_DL_MGMT, f, ## a)
114 #define LIBIPW_DEBUG_FRAG(f, a...)  LIBIPW_DEBUG(LIBIPW_DL_FRAG, f, ## a)
115 #define LIBIPW_DEBUG_DROP(f, a...)  LIBIPW_DEBUG(LIBIPW_DL_DROP, f, ## a)
116 #define LIBIPW_DEBUG_TX(f, a...)  LIBIPW_DEBUG(LIBIPW_DL_TX, f, ## a)
117 #define LIBIPW_DEBUG_RX(f, a...)  LIBIPW_DEBUG(LIBIPW_DL_RX, f, ## a)
118 #define LIBIPW_DEBUG_QOS(f, a...)  LIBIPW_DEBUG(LIBIPW_DL_QOS, f, ## a)
119 #include <linux/netdevice.h>
120 #include <linux/if_arp.h>	/* ARPHRD_ETHER */
121 
122 #ifndef WIRELESS_SPY
123 #define WIRELESS_SPY		/* enable iwspy support */
124 #endif
125 #include <net/iw_handler.h>	/* new driver API */
126 
127 #define ETH_P_PREAUTH 0x88C7	/* IEEE 802.11i pre-authentication */
128 
129 #ifndef ETH_P_80211_RAW
130 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
131 #endif
132 
133 /* IEEE 802.11 defines */
134 
135 #define P80211_OUI_LEN 3
136 
137 struct libipw_snap_hdr {
138 
139 	u8 dsap;		/* always 0xAA */
140 	u8 ssap;		/* always 0xAA */
141 	u8 ctrl;		/* always 0x03 */
142 	u8 oui[P80211_OUI_LEN];	/* organizational universal id */
143 
144 } __packed;
145 
146 #define SNAP_SIZE sizeof(struct libipw_snap_hdr)
147 
148 #define WLAN_FC_GET_VERS(fc) ((fc) & IEEE80211_FCTL_VERS)
149 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
150 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
151 
152 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
153 #define WLAN_GET_SEQ_SEQ(seq)  (((seq) & IEEE80211_SCTL_SEQ) >> 4)
154 
155 #define LIBIPW_STATMASK_SIGNAL (1<<0)
156 #define LIBIPW_STATMASK_RSSI (1<<1)
157 #define LIBIPW_STATMASK_NOISE (1<<2)
158 #define LIBIPW_STATMASK_RATE (1<<3)
159 #define LIBIPW_STATMASK_WEMASK 0x7
160 
161 #define LIBIPW_CCK_MODULATION    (1<<0)
162 #define LIBIPW_OFDM_MODULATION   (1<<1)
163 
164 #define LIBIPW_24GHZ_BAND     (1<<0)
165 #define LIBIPW_52GHZ_BAND     (1<<1)
166 
167 #define LIBIPW_CCK_RATE_1MB		        0x02
168 #define LIBIPW_CCK_RATE_2MB		        0x04
169 #define LIBIPW_CCK_RATE_5MB		        0x0B
170 #define LIBIPW_CCK_RATE_11MB		        0x16
171 #define LIBIPW_OFDM_RATE_6MB		        0x0C
172 #define LIBIPW_OFDM_RATE_9MB		        0x12
173 #define LIBIPW_OFDM_RATE_12MB		0x18
174 #define LIBIPW_OFDM_RATE_18MB		0x24
175 #define LIBIPW_OFDM_RATE_24MB		0x30
176 #define LIBIPW_OFDM_RATE_36MB		0x48
177 #define LIBIPW_OFDM_RATE_48MB		0x60
178 #define LIBIPW_OFDM_RATE_54MB		0x6C
179 #define LIBIPW_BASIC_RATE_MASK		0x80
180 
181 #define LIBIPW_CCK_RATE_1MB_MASK		(1<<0)
182 #define LIBIPW_CCK_RATE_2MB_MASK		(1<<1)
183 #define LIBIPW_CCK_RATE_5MB_MASK		(1<<2)
184 #define LIBIPW_CCK_RATE_11MB_MASK		(1<<3)
185 #define LIBIPW_OFDM_RATE_6MB_MASK		(1<<4)
186 #define LIBIPW_OFDM_RATE_9MB_MASK		(1<<5)
187 #define LIBIPW_OFDM_RATE_12MB_MASK		(1<<6)
188 #define LIBIPW_OFDM_RATE_18MB_MASK		(1<<7)
189 #define LIBIPW_OFDM_RATE_24MB_MASK		(1<<8)
190 #define LIBIPW_OFDM_RATE_36MB_MASK		(1<<9)
191 #define LIBIPW_OFDM_RATE_48MB_MASK		(1<<10)
192 #define LIBIPW_OFDM_RATE_54MB_MASK		(1<<11)
193 
194 #define LIBIPW_CCK_RATES_MASK	        0x0000000F
195 #define LIBIPW_CCK_BASIC_RATES_MASK	(LIBIPW_CCK_RATE_1MB_MASK | \
196 	LIBIPW_CCK_RATE_2MB_MASK)
197 #define LIBIPW_CCK_DEFAULT_RATES_MASK	(LIBIPW_CCK_BASIC_RATES_MASK | \
198         LIBIPW_CCK_RATE_5MB_MASK | \
199         LIBIPW_CCK_RATE_11MB_MASK)
200 
201 #define LIBIPW_OFDM_RATES_MASK		0x00000FF0
202 #define LIBIPW_OFDM_BASIC_RATES_MASK	(LIBIPW_OFDM_RATE_6MB_MASK | \
203 	LIBIPW_OFDM_RATE_12MB_MASK | \
204 	LIBIPW_OFDM_RATE_24MB_MASK)
205 #define LIBIPW_OFDM_DEFAULT_RATES_MASK	(LIBIPW_OFDM_BASIC_RATES_MASK | \
206 	LIBIPW_OFDM_RATE_9MB_MASK  | \
207 	LIBIPW_OFDM_RATE_18MB_MASK | \
208 	LIBIPW_OFDM_RATE_36MB_MASK | \
209 	LIBIPW_OFDM_RATE_48MB_MASK | \
210 	LIBIPW_OFDM_RATE_54MB_MASK)
211 #define LIBIPW_DEFAULT_RATES_MASK (LIBIPW_OFDM_DEFAULT_RATES_MASK | \
212                                 LIBIPW_CCK_DEFAULT_RATES_MASK)
213 
214 #define LIBIPW_NUM_OFDM_RATES	    8
215 #define LIBIPW_NUM_CCK_RATES	            4
216 #define LIBIPW_OFDM_SHIFT_MASK_A         4
217 
218 /* NOTE: This data is for statistical purposes; not all hardware provides this
219  *       information for frames received.
220  *       For libipw_rx_mgt, you need to set at least the 'len' parameter.
221  */
222 struct libipw_rx_stats {
223 	u32 mac_time;
224 	s8 rssi;
225 	u8 signal;
226 	u8 noise;
227 	u16 rate;		/* in 100 kbps */
228 	u8 received_channel;
229 	u8 control;
230 	u8 mask;
231 	u8 freq;
232 	u16 len;
233 	u64 tsf;
234 	u32 beacon_time;
235 };
236 
237 /* IEEE 802.11 requires that STA supports concurrent reception of at least
238  * three fragmented frames. This define can be increased to support more
239  * concurrent frames, but it should be noted that each entry can consume about
240  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
241 #define LIBIPW_FRAG_CACHE_LEN 4
242 
243 struct libipw_frag_entry {
244 	unsigned long first_frag_time;
245 	unsigned int seq;
246 	unsigned int last_frag;
247 	struct sk_buff *skb;
248 	u8 src_addr[ETH_ALEN];
249 	u8 dst_addr[ETH_ALEN];
250 };
251 
252 struct libipw_stats {
253 	unsigned int tx_unicast_frames;
254 	unsigned int tx_multicast_frames;
255 	unsigned int tx_fragments;
256 	unsigned int tx_unicast_octets;
257 	unsigned int tx_multicast_octets;
258 	unsigned int tx_deferred_transmissions;
259 	unsigned int tx_single_retry_frames;
260 	unsigned int tx_multiple_retry_frames;
261 	unsigned int tx_retry_limit_exceeded;
262 	unsigned int tx_discards;
263 	unsigned int rx_unicast_frames;
264 	unsigned int rx_multicast_frames;
265 	unsigned int rx_fragments;
266 	unsigned int rx_unicast_octets;
267 	unsigned int rx_multicast_octets;
268 	unsigned int rx_fcs_errors;
269 	unsigned int rx_discards_no_buffer;
270 	unsigned int tx_discards_wrong_sa;
271 	unsigned int rx_discards_undecryptable;
272 	unsigned int rx_message_in_msg_fragments;
273 	unsigned int rx_message_in_bad_msg_fragments;
274 };
275 
276 struct libipw_device;
277 
278 #define SEC_KEY_1		(1<<0)
279 #define SEC_KEY_2		(1<<1)
280 #define SEC_KEY_3		(1<<2)
281 #define SEC_KEY_4		(1<<3)
282 #define SEC_ACTIVE_KEY		(1<<4)
283 #define SEC_AUTH_MODE		(1<<5)
284 #define SEC_UNICAST_GROUP	(1<<6)
285 #define SEC_LEVEL		(1<<7)
286 #define SEC_ENABLED		(1<<8)
287 #define SEC_ENCRYPT		(1<<9)
288 
289 #define SEC_LEVEL_0		0	/* None */
290 #define SEC_LEVEL_1		1	/* WEP 40 and 104 bit */
291 #define SEC_LEVEL_2		2	/* Level 1 + TKIP */
292 #define SEC_LEVEL_2_CKIP	3	/* Level 1 + CKIP */
293 #define SEC_LEVEL_3		4	/* Level 2 + CCMP */
294 
295 #define SEC_ALG_NONE		0
296 #define SEC_ALG_WEP		1
297 #define SEC_ALG_TKIP		2
298 #define SEC_ALG_CCMP		3
299 
300 #define WEP_KEYS		4
301 #define WEP_KEY_LEN		13
302 #define SCM_KEY_LEN		32
303 #define SCM_TEMPORAL_KEY_LENGTH	16
304 
305 struct libipw_security {
306 	u16 active_key:2, enabled:1, unicast_uses_group:1, encrypt:1;
307 	u8 auth_mode;
308 	u8 encode_alg[WEP_KEYS];
309 	u8 key_sizes[WEP_KEYS];
310 	u8 keys[WEP_KEYS][SCM_KEY_LEN];
311 	u8 level;
312 	u16 flags;
313 } __packed;
314 
315 /*
316 
317  802.11 data frame from AP
318 
319       ,-------------------------------------------------------------------.
320 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
321       |------|------|---------|---------|---------|------|---------|------|
322 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
323       |      | tion | (BSSID) |         |         | ence |  data   |      |
324       `-------------------------------------------------------------------'
325 
326 Total: 28-2340 bytes
327 
328 */
329 
330 #define BEACON_PROBE_SSID_ID_POSITION 12
331 
332 struct libipw_hdr_1addr {
333 	__le16 frame_ctl;
334 	__le16 duration_id;
335 	u8 addr1[ETH_ALEN];
336 	u8 payload[];
337 } __packed;
338 
339 struct libipw_hdr_2addr {
340 	__le16 frame_ctl;
341 	__le16 duration_id;
342 	u8 addr1[ETH_ALEN];
343 	u8 addr2[ETH_ALEN];
344 	u8 payload[];
345 } __packed;
346 
347 struct libipw_hdr_3addr {
348 	/* New members MUST be added within the __struct_group() macro below. */
349 	__struct_group(libipw_hdr_3addr_hdr, hdr, __packed,
350 		__le16 frame_ctl;
351 		__le16 duration_id;
352 		u8 addr1[ETH_ALEN];
353 		u8 addr2[ETH_ALEN];
354 		u8 addr3[ETH_ALEN];
355 		__le16 seq_ctl;
356 	);
357 	u8 payload[];
358 } __packed;
359 static_assert(offsetof(struct libipw_hdr_3addr, payload) == sizeof(struct libipw_hdr_3addr_hdr),
360 	      "struct member likely outside of __struct_group()");
361 
362 struct libipw_hdr_4addr {
363 	__le16 frame_ctl;
364 	__le16 duration_id;
365 	u8 addr1[ETH_ALEN];
366 	u8 addr2[ETH_ALEN];
367 	u8 addr3[ETH_ALEN];
368 	__le16 seq_ctl;
369 	u8 addr4[ETH_ALEN];
370 	u8 payload[];
371 } __packed;
372 
373 struct libipw_hdr_3addrqos {
374 	__le16 frame_ctl;
375 	__le16 duration_id;
376 	u8 addr1[ETH_ALEN];
377 	u8 addr2[ETH_ALEN];
378 	u8 addr3[ETH_ALEN];
379 	__le16 seq_ctl;
380 	u8 payload[0];
381 	__le16 qos_ctl;
382 } __packed;
383 
384 struct libipw_info_element {
385 	u8 id;
386 	u8 len;
387 	u8 data[];
388 } __packed;
389 
390 /*
391  * These are the data types that can make up management packets
392  *
393 	u16 auth_algorithm;
394 	u16 auth_sequence;
395 	u16 beacon_interval;
396 	u16 capability;
397 	u8 current_ap[ETH_ALEN];
398 	u16 listen_interval;
399 	struct {
400 		u16 association_id:14, reserved:2;
401 	} __packed;
402 	u32 time_stamp[2];
403 	u16 reason;
404 	u16 status;
405 */
406 
407 struct libipw_auth {
408 	struct libipw_hdr_3addr_hdr header;
409 	__le16 algorithm;
410 	__le16 transaction;
411 	__le16 status;
412 	/* challenge */
413 	u8 variable[];
414 } __packed;
415 
416 struct libipw_channel_switch {
417 	u8 id;
418 	u8 len;
419 	u8 mode;
420 	u8 channel;
421 	u8 count;
422 } __packed;
423 
424 struct libipw_action {
425 	struct libipw_hdr_3addr_hdr header;
426 	u8 category;
427 	u8 action;
428 	union {
429 		struct libipw_action_exchange {
430 			u8 token;
431 		} exchange;
432 		struct libipw_channel_switch channel_switch;
433 
434 	} format;
435 } __packed;
436 
437 struct libipw_disassoc {
438 	struct libipw_hdr_3addr_hdr header;
439 	__le16 reason;
440 } __packed;
441 
442 /* Alias deauth for disassoc */
443 #define libipw_deauth libipw_disassoc
444 
445 struct libipw_probe_request {
446 	struct libipw_hdr_3addr_hdr header;
447 	/* SSID, supported rates */
448 	u8 variable[];
449 } __packed;
450 
451 struct libipw_probe_response {
452 	struct libipw_hdr_3addr_hdr header;
453 	__le32 time_stamp[2];
454 	__le16 beacon_interval;
455 	__le16 capability;
456 	/* SSID, supported rates, FH params, DS params,
457 	 * CF params, IBSS params, TIM (if beacon), RSN */
458 	u8 variable[];
459 } __packed;
460 
461 /* Alias beacon for probe_response */
462 #define libipw_beacon libipw_probe_response
463 
464 struct libipw_reassoc_request {
465 	struct libipw_hdr_3addr_hdr header;
466 	__le16 capability;
467 	__le16 listen_interval;
468 	u8 current_ap[ETH_ALEN];
469 	u8 variable[];
470 } __packed;
471 
472 struct libipw_assoc_response {
473 	struct libipw_hdr_3addr_hdr header;
474 	__le16 capability;
475 	__le16 status;
476 	__le16 aid;
477 	/* supported rates */
478 	u8 variable[];
479 } __packed;
480 
481 struct libipw_txb {
482 	u8 nr_frags;
483 	u8 encrypted;
484 	u8 rts_included;
485 	u8 reserved;
486 	u16 frag_size;
487 	u16 payload_size;
488 	struct sk_buff *fragments[] __counted_by(nr_frags);
489 };
490 
491 /* SWEEP TABLE ENTRIES NUMBER */
492 #define MAX_SWEEP_TAB_ENTRIES		  42
493 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
494 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
495  * only use 8, and then use extended rates for the remaining supported
496  * rates.  Other APs, however, stick all of their supported rates on the
497  * main rates information element... */
498 #define MAX_RATES_LENGTH                  ((u8)12)
499 #define MAX_RATES_EX_LENGTH               ((u8)16)
500 #define MAX_NETWORK_COUNT                  128
501 
502 #define CRC_LENGTH                 4U
503 
504 #define MAX_WPA_IE_LEN 64
505 
506 #define NETWORK_HAS_OFDM       (1<<1)
507 #define NETWORK_HAS_CCK        (1<<2)
508 
509 /* QoS structure */
510 #define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
511 #define NETWORK_HAS_QOS_INFORMATION     (1<<4)
512 #define NETWORK_HAS_QOS_MASK            (NETWORK_HAS_QOS_PARAMETERS | \
513 					 NETWORK_HAS_QOS_INFORMATION)
514 
515 /* 802.11h */
516 #define NETWORK_HAS_POWER_CONSTRAINT    (1<<5)
517 #define NETWORK_HAS_CSA                 (1<<6)
518 #define NETWORK_HAS_QUIET               (1<<7)
519 #define NETWORK_HAS_IBSS_DFS            (1<<8)
520 #define NETWORK_HAS_TPC_REPORT          (1<<9)
521 
522 #define NETWORK_HAS_ERP_VALUE           (1<<10)
523 
524 #define QOS_QUEUE_NUM                   4
525 #define QOS_OUI_LEN                     3
526 #define QOS_OUI_TYPE                    2
527 #define QOS_ELEMENT_ID                  221
528 #define QOS_OUI_INFO_SUB_TYPE           0
529 #define QOS_OUI_PARAM_SUB_TYPE          1
530 #define QOS_VERSION_1                   1
531 #define QOS_AIFSN_MIN_VALUE             2
532 
533 struct libipw_qos_information_element {
534 	u8 elementID;
535 	u8 length;
536 	u8 qui[QOS_OUI_LEN];
537 	u8 qui_type;
538 	u8 qui_subtype;
539 	u8 version;
540 	u8 ac_info;
541 } __packed;
542 
543 struct libipw_qos_ac_parameter {
544 	u8 aci_aifsn;
545 	u8 ecw_min_max;
546 	__le16 tx_op_limit;
547 } __packed;
548 
549 struct libipw_qos_parameter_info {
550 	struct libipw_qos_information_element info_element;
551 	u8 reserved;
552 	struct libipw_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
553 } __packed;
554 
555 struct libipw_qos_parameters {
556 	__le16 cw_min[QOS_QUEUE_NUM];
557 	__le16 cw_max[QOS_QUEUE_NUM];
558 	u8 aifs[QOS_QUEUE_NUM];
559 	u8 flag[QOS_QUEUE_NUM];
560 	__le16 tx_op_limit[QOS_QUEUE_NUM];
561 } __packed;
562 
563 struct libipw_qos_data {
564 	struct libipw_qos_parameters parameters;
565 	int active;
566 	int supported;
567 	u8 param_count;
568 	u8 old_param_count;
569 };
570 
571 struct libipw_tim_parameters {
572 	u8 tim_count;
573 	u8 tim_period;
574 } __packed;
575 
576 /*******************************************************/
577 
578 struct libipw_tpc_report {
579 	u8 transmit_power;
580 	u8 link_margin;
581 } __packed;
582 
583 struct libipw_channel_map {
584 	u8 channel;
585 	u8 map;
586 } __packed;
587 
588 struct libipw_csa {
589 	u8 mode;
590 	u8 channel;
591 	u8 count;
592 } __packed;
593 
594 struct libipw_quiet {
595 	u8 count;
596 	u8 period;
597 	u8 duration;
598 	u8 offset;
599 } __packed;
600 
601 struct libipw_network {
602 	/* These entries are used to identify a unique network */
603 	u8 bssid[ETH_ALEN];
604 	u8 channel;
605 	/* Ensure null-terminated for any debug msgs */
606 	u8 ssid[IW_ESSID_MAX_SIZE + 1];
607 	u8 ssid_len;
608 
609 	struct libipw_qos_data qos_data;
610 
611 	/* These are network statistics */
612 	struct libipw_rx_stats stats;
613 	u16 capability;
614 	u8 rates[MAX_RATES_LENGTH];
615 	u8 rates_len;
616 	u8 rates_ex[MAX_RATES_EX_LENGTH];
617 	u8 rates_ex_len;
618 	unsigned long last_scanned;
619 	u8 mode;
620 	u32 flags;
621 	u32 last_associate;
622 	u32 time_stamp[2];
623 	u16 beacon_interval;
624 	u16 listen_interval;
625 	u16 atim_window;
626 	u8 erp_value;
627 	u8 wpa_ie[MAX_WPA_IE_LEN];
628 	size_t wpa_ie_len;
629 	u8 rsn_ie[MAX_WPA_IE_LEN];
630 	size_t rsn_ie_len;
631 	struct libipw_tim_parameters tim;
632 
633 	/* 802.11h info */
634 
635 	/* Power Constraint - mandatory if spctrm mgmt required */
636 	u8 power_constraint;
637 
638 	/* TPC Report - mandatory if spctrm mgmt required */
639 	struct libipw_tpc_report tpc_report;
640 
641 	/* Channel Switch Announcement - optional if spctrm mgmt required */
642 	struct libipw_csa csa;
643 
644 	/* Quiet - optional if spctrm mgmt required */
645 	struct libipw_quiet quiet;
646 
647 	struct list_head list;
648 };
649 
650 enum libipw_state {
651 	LIBIPW_UNINITIALIZED = 0,
652 	LIBIPW_INITIALIZED,
653 	LIBIPW_ASSOCIATING,
654 	LIBIPW_ASSOCIATED,
655 	LIBIPW_AUTHENTICATING,
656 	LIBIPW_AUTHENTICATED,
657 	LIBIPW_SHUTDOWN
658 };
659 
660 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
661 #define DEFAULT_FTS 2346
662 
663 #define CFG_LIBIPW_RESERVE_FCS (1<<0)
664 #define CFG_LIBIPW_COMPUTE_FCS (1<<1)
665 #define CFG_LIBIPW_RTS (1<<2)
666 
667 #define LIBIPW_24GHZ_MIN_CHANNEL 1
668 #define LIBIPW_24GHZ_MAX_CHANNEL 14
669 #define LIBIPW_24GHZ_CHANNELS (LIBIPW_24GHZ_MAX_CHANNEL - \
670 				  LIBIPW_24GHZ_MIN_CHANNEL + 1)
671 
672 #define LIBIPW_52GHZ_MIN_CHANNEL 34
673 #define LIBIPW_52GHZ_MAX_CHANNEL 165
674 #define LIBIPW_52GHZ_CHANNELS (LIBIPW_52GHZ_MAX_CHANNEL - \
675 				  LIBIPW_52GHZ_MIN_CHANNEL + 1)
676 
677 enum {
678 	LIBIPW_CH_PASSIVE_ONLY = (1 << 0),
679 	LIBIPW_CH_80211H_RULES = (1 << 1),
680 	LIBIPW_CH_B_ONLY = (1 << 2),
681 	LIBIPW_CH_NO_IBSS = (1 << 3),
682 	LIBIPW_CH_UNIFORM_SPREADING = (1 << 4),
683 	LIBIPW_CH_RADAR_DETECT = (1 << 5),
684 	LIBIPW_CH_INVALID = (1 << 6),
685 };
686 
687 struct libipw_channel {
688 	u32 freq;	/* in MHz */
689 	u8 channel;
690 	u8 flags;
691 	u8 max_power;	/* in dBm */
692 };
693 
694 struct libipw_geo {
695 	u8 name[4];
696 	u8 bg_channels;
697 	u8 a_channels;
698 	struct libipw_channel bg[LIBIPW_24GHZ_CHANNELS];
699 	struct libipw_channel a[LIBIPW_52GHZ_CHANNELS];
700 };
701 
702 struct libipw_device {
703 	struct net_device *dev;
704 	struct wireless_dev wdev;
705 	struct libipw_security sec;
706 
707 	/* Bookkeeping structures */
708 	struct libipw_stats ieee_stats;
709 
710 	struct libipw_geo geo;
711 	struct ieee80211_supported_band bg_band;
712 	struct ieee80211_supported_band a_band;
713 
714 	/* Probe / Beacon management */
715 	struct list_head network_free_list;
716 	struct list_head network_list;
717 	struct libipw_network *networks[MAX_NETWORK_COUNT];
718 	int scans;
719 	int scan_age;
720 
721 	int iw_mode;		/* operating mode (IW_MODE_*) */
722 	struct iw_spy_data spy_data;	/* iwspy support */
723 
724 	spinlock_t lock;
725 
726 	int tx_headroom;	/* Set to size of any additional room needed at front
727 				 * of allocated Tx SKBs */
728 	u32 config;
729 
730 	/* WEP and other encryption related settings at the device level */
731 	int open_wep;		/* Set to 1 to allow unencrypted frames */
732 
733 	/* If the host performs {en,de}cryption, then set to 1 */
734 	int host_encrypt;
735 	int host_encrypt_msdu;
736 	int host_decrypt;
737 	/* host performs multicast decryption */
738 	int host_mc_decrypt;
739 
740 	/* host should strip IV and ICV from protected frames */
741 	/* meaningful only when hardware decryption is being used */
742 	int host_strip_iv_icv;
743 
744 	int host_open_frag;
745 	int ieee802_1x;		/* is IEEE 802.1X used */
746 
747 	/* WPA data */
748 	int wpa_enabled;
749 	int drop_unencrypted;
750 	int privacy_invoked;
751 	size_t wpa_ie_len;
752 	u8 *wpa_ie;
753 
754 	struct lib80211_crypt_info crypt_info;
755 
756 	int bcrx_sta_key;	/* use individual keys to override default keys even
757 				 * with RX of broad/multicast frames */
758 
759 	/* Fragmentation structures */
760 	struct libipw_frag_entry frag_cache[LIBIPW_FRAG_CACHE_LEN];
761 	unsigned int frag_next_idx;
762 	u16 fts;		/* Fragmentation Threshold */
763 	u16 rts;		/* RTS threshold */
764 
765 	/* Association info */
766 	u8 bssid[ETH_ALEN];
767 
768 	enum libipw_state state;
769 
770 	int mode;		/* A, B, G */
771 	int modulation;		/* CCK, OFDM */
772 	int freq_band;		/* 2.4Ghz, 5.2Ghz, Mixed */
773 	int abg_true;		/* ABG flag              */
774 
775 	int perfect_rssi;
776 	int worst_rssi;
777 
778 	u16 prev_seq_ctl;	/* used to drop duplicate frames */
779 
780 	/* Callback functions */
781 	void (*set_security) (struct net_device * dev,
782 			      struct libipw_security * sec);
783 	netdev_tx_t (*hard_start_xmit) (struct libipw_txb * txb,
784 					struct net_device * dev, int pri);
785 	int (*is_queue_full) (struct net_device * dev, int pri);
786 
787 	int (*handle_management) (struct net_device * dev,
788 				  struct libipw_network * network, u16 type);
789 	int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb);
790 
791 	/* Typical STA methods */
792 	int (*handle_auth) (struct net_device * dev,
793 			    struct libipw_auth * auth);
794 	int (*handle_deauth) (struct net_device * dev,
795 			      struct libipw_deauth * auth);
796 	int (*handle_action) (struct net_device * dev,
797 			      struct libipw_action * action,
798 			      struct libipw_rx_stats * stats);
799 	int (*handle_disassoc) (struct net_device * dev,
800 				struct libipw_disassoc * assoc);
801 	int (*handle_beacon) (struct net_device * dev,
802 			      struct libipw_beacon * beacon,
803 			      struct libipw_network * network);
804 	int (*handle_probe_response) (struct net_device * dev,
805 				      struct libipw_probe_response * resp,
806 				      struct libipw_network * network);
807 	int (*handle_probe_request) (struct net_device * dev,
808 				     struct libipw_probe_request * req,
809 				     struct libipw_rx_stats * stats);
810 	int (*handle_assoc_response) (struct net_device * dev,
811 				      struct libipw_assoc_response * resp,
812 				      struct libipw_network * network);
813 
814 	/* Typical AP methods */
815 	int (*handle_assoc_request) (struct net_device * dev);
816 	int (*handle_reassoc_request) (struct net_device * dev,
817 				       struct libipw_reassoc_request * req);
818 
819 	/* This must be the last item so that it points to the data
820 	 * allocated beyond this structure by alloc_libipw */
821 	u8 priv[];
822 };
823 
824 #define IEEE_A            (1<<0)
825 #define IEEE_B            (1<<1)
826 #define IEEE_G            (1<<2)
827 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
828 
libipw_priv(struct net_device * dev)829 static inline void *libipw_priv(struct net_device *dev)
830 {
831 	return ((struct libipw_device *)netdev_priv(dev))->priv;
832 }
833 
libipw_is_valid_mode(struct libipw_device * ieee,int mode)834 static inline int libipw_is_valid_mode(struct libipw_device *ieee,
835 					  int mode)
836 {
837 	/*
838 	 * It is possible for both access points and our device to support
839 	 * combinations of modes, so as long as there is one valid combination
840 	 * of ap/device supported modes, then return success
841 	 *
842 	 */
843 	if ((mode & IEEE_A) &&
844 	    (ieee->modulation & LIBIPW_OFDM_MODULATION) &&
845 	    (ieee->freq_band & LIBIPW_52GHZ_BAND))
846 		return 1;
847 
848 	if ((mode & IEEE_G) &&
849 	    (ieee->modulation & LIBIPW_OFDM_MODULATION) &&
850 	    (ieee->freq_band & LIBIPW_24GHZ_BAND))
851 		return 1;
852 
853 	if ((mode & IEEE_B) &&
854 	    (ieee->modulation & LIBIPW_CCK_MODULATION) &&
855 	    (ieee->freq_band & LIBIPW_24GHZ_BAND))
856 		return 1;
857 
858 	return 0;
859 }
860 
libipw_get_hdrlen(u16 fc)861 static inline int libipw_get_hdrlen(u16 fc)
862 {
863 	int hdrlen = LIBIPW_3ADDR_LEN;
864 	u16 stype = WLAN_FC_GET_STYPE(fc);
865 
866 	switch (WLAN_FC_GET_TYPE(fc)) {
867 	case IEEE80211_FTYPE_DATA:
868 		if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
869 			hdrlen = LIBIPW_4ADDR_LEN;
870 		if (stype & IEEE80211_STYPE_QOS_DATA)
871 			hdrlen += 2;
872 		break;
873 	case IEEE80211_FTYPE_CTL:
874 		switch (WLAN_FC_GET_STYPE(fc)) {
875 		case IEEE80211_STYPE_CTS:
876 		case IEEE80211_STYPE_ACK:
877 			hdrlen = LIBIPW_1ADDR_LEN;
878 			break;
879 		default:
880 			hdrlen = LIBIPW_2ADDR_LEN;
881 			break;
882 		}
883 		break;
884 	}
885 
886 	return hdrlen;
887 }
888 
libipw_get_payload(struct ieee80211_hdr * hdr)889 static inline u8 *libipw_get_payload(struct ieee80211_hdr *hdr)
890 {
891 	switch (libipw_get_hdrlen(le16_to_cpu(hdr->frame_control))) {
892 	case LIBIPW_1ADDR_LEN:
893 		return ((struct libipw_hdr_1addr *)hdr)->payload;
894 	case LIBIPW_2ADDR_LEN:
895 		return ((struct libipw_hdr_2addr *)hdr)->payload;
896 	case LIBIPW_3ADDR_LEN:
897 		return ((struct libipw_hdr_3addr *)hdr)->payload;
898 	case LIBIPW_4ADDR_LEN:
899 		return ((struct libipw_hdr_4addr *)hdr)->payload;
900 	}
901 	return NULL;
902 }
903 
libipw_is_ofdm_rate(u8 rate)904 static inline int libipw_is_ofdm_rate(u8 rate)
905 {
906 	switch (rate & ~LIBIPW_BASIC_RATE_MASK) {
907 	case LIBIPW_OFDM_RATE_6MB:
908 	case LIBIPW_OFDM_RATE_9MB:
909 	case LIBIPW_OFDM_RATE_12MB:
910 	case LIBIPW_OFDM_RATE_18MB:
911 	case LIBIPW_OFDM_RATE_24MB:
912 	case LIBIPW_OFDM_RATE_36MB:
913 	case LIBIPW_OFDM_RATE_48MB:
914 	case LIBIPW_OFDM_RATE_54MB:
915 		return 1;
916 	}
917 	return 0;
918 }
919 
libipw_is_cck_rate(u8 rate)920 static inline int libipw_is_cck_rate(u8 rate)
921 {
922 	switch (rate & ~LIBIPW_BASIC_RATE_MASK) {
923 	case LIBIPW_CCK_RATE_1MB:
924 	case LIBIPW_CCK_RATE_2MB:
925 	case LIBIPW_CCK_RATE_5MB:
926 	case LIBIPW_CCK_RATE_11MB:
927 		return 1;
928 	}
929 	return 0;
930 }
931 
932 /* libipw.c */
933 void free_libipw(struct net_device *dev, int monitor);
934 struct net_device *alloc_libipw(int sizeof_priv, int monitor);
935 
936 void libipw_networks_age(struct libipw_device *ieee, unsigned long age_secs);
937 
938 int libipw_set_encryption(struct libipw_device *ieee);
939 
940 /* libipw_tx.c */
941 netdev_tx_t libipw_xmit(struct sk_buff *skb, struct net_device *dev);
942 void libipw_txb_free(struct libipw_txb *);
943 
944 /* libipw_rx.c */
945 void libipw_rx_any(struct libipw_device *ieee, struct sk_buff *skb,
946 		   struct libipw_rx_stats *stats);
947 int libipw_rx(struct libipw_device *ieee, struct sk_buff *skb,
948 	      struct libipw_rx_stats *rx_stats);
949 /* make sure to set stats->len */
950 void libipw_rx_mgt(struct libipw_device *ieee, struct libipw_hdr_4addr *header,
951 		   struct libipw_rx_stats *stats);
952 
953 /* libipw_geo.c */
954 const struct libipw_geo *libipw_get_geo(struct libipw_device *ieee);
955 void libipw_set_geo(struct libipw_device *ieee, const struct libipw_geo *geo);
956 
957 int libipw_is_valid_channel(struct libipw_device *ieee, u8 channel);
958 int libipw_channel_to_index(struct libipw_device *ieee, u8 channel);
959 u8 libipw_freq_to_channel(struct libipw_device *ieee, u32 freq);
960 u8 libipw_get_channel_flags(struct libipw_device *ieee, u8 channel);
961 const struct libipw_channel *libipw_get_channel(struct libipw_device *ieee,
962 						u8 channel);
963 u32 libipw_channel_to_freq(struct libipw_device *ieee, u8 channel);
964 
965 /* libipw_wx.c */
966 int libipw_wx_get_scan(struct libipw_device *ieee, struct iw_request_info *info,
967 		       union iwreq_data *wrqu, char *key);
968 int libipw_wx_set_encode(struct libipw_device *ieee,
969 			 struct iw_request_info *info, union iwreq_data *wrqu,
970 			 char *key);
971 int libipw_wx_get_encode(struct libipw_device *ieee,
972 			 struct iw_request_info *info, union iwreq_data *wrqu,
973 			 char *key);
974 int libipw_wx_set_encodeext(struct libipw_device *ieee,
975 			    struct iw_request_info *info,
976 			    union iwreq_data *wrqu, char *extra);
977 int libipw_wx_get_encodeext(struct libipw_device *ieee,
978 			    struct iw_request_info *info,
979 			    union iwreq_data *wrqu, char *extra);
980 
libipw_increment_scans(struct libipw_device * ieee)981 static inline void libipw_increment_scans(struct libipw_device *ieee)
982 {
983 	ieee->scans++;
984 }
985 
libipw_get_scans(struct libipw_device * ieee)986 static inline int libipw_get_scans(struct libipw_device *ieee)
987 {
988 	return ieee->scans;
989 }
990 
991 #endif				/* LIBIPW_H */
992