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