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