• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/staging/rtl8187se/ieee80211/
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 * <jkmaline@cc.hut.fi>
10 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
11 *
12 * Adaption to a generic IEEE 802.11 stack by James Ketrenos
13 * <jketreno@linux.intel.com>
14 * Copyright (c) 2004, Intel Corporation
15 *
16 * Modified for Realtek's wi-fi cards by Andrea Merello
17 * <andreamrl@tiscali.it>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 2 as
21 * published by the Free Software Foundation. See README and COPYING for
22 * more details.
23 */
24#ifndef IEEE80211_H
25#define IEEE80211_H
26#include <linux/if_ether.h> /* ETH_ALEN */
27#include <linux/kernel.h>   /* ARRAY_SIZE */
28#include <linux/version.h>
29#include <linux/jiffies.h>
30#include <linux/timer.h>
31#include <linux/sched.h>
32#include <linux/semaphore.h>
33#include <linux/wireless.h>
34#include <linux/ieee80211.h>
35
36#define KEY_TYPE_NA		0x0
37#define KEY_TYPE_WEP40 		0x1
38#define KEY_TYPE_TKIP		0x2
39#define KEY_TYPE_CCMP		0x4
40#define KEY_TYPE_WEP104		0x5
41
42#define aSifsTime					10
43
44#define MGMT_QUEUE_NUM 5
45
46
47#define IEEE_CMD_SET_WPA_PARAM			1
48#define	IEEE_CMD_SET_WPA_IE			2
49#define IEEE_CMD_SET_ENCRYPTION			3
50#define IEEE_CMD_MLME				4
51
52#define IEEE_PARAM_WPA_ENABLED			1
53#define IEEE_PARAM_TKIP_COUNTERMEASURES		2
54#define IEEE_PARAM_DROP_UNENCRYPTED		3
55#define IEEE_PARAM_PRIVACY_INVOKED		4
56#define IEEE_PARAM_AUTH_ALGS			5
57#define IEEE_PARAM_IEEE_802_1X			6
58//It should consistent with the driver_XXX.c
59//   David, 2006.9.26
60#define IEEE_PARAM_WPAX_SELECT			7
61//Added for notify the encryption type selection
62//   David, 2006.9.26
63#define IEEE_PROTO_WPA				1
64#define IEEE_PROTO_RSN				2
65//Added for notify the encryption type selection
66//   David, 2006.9.26
67#define IEEE_WPAX_USEGROUP			0
68#define IEEE_WPAX_WEP40				1
69#define IEEE_WPAX_TKIP				2
70#define IEEE_WPAX_WRAP   			3
71#define IEEE_WPAX_CCMP				4
72#define IEEE_WPAX_WEP104			5
73
74#define IEEE_KEY_MGMT_IEEE8021X			1
75#define IEEE_KEY_MGMT_PSK			2
76
77
78
79#define IEEE_MLME_STA_DEAUTH			1
80#define IEEE_MLME_STA_DISASSOC			2
81
82
83#define IEEE_CRYPT_ERR_UNKNOWN_ALG		2
84#define IEEE_CRYPT_ERR_UNKNOWN_ADDR		3
85#define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED		4
86#define IEEE_CRYPT_ERR_KEY_SET_FAILED		5
87#define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED		6
88#define IEEE_CRYPT_ERR_CARD_CONF_FAILED		7
89
90
91#define	IEEE_CRYPT_ALG_NAME_LEN			16
92
93//by amy for ps
94typedef struct ieee_param {
95	u32 cmd;
96	u8 sta_addr[ETH_ALEN];
97        union {
98		struct {
99			u8 name;
100			u32 value;
101		} wpa_param;
102		struct {
103			u32 len;
104			u8 reserved[32];
105			u8 data[0];
106		} wpa_ie;
107	        struct{
108			int command;
109    			int reason_code;
110		} mlme;
111		struct {
112			u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
113			u8 set_tx;
114			u32 err;
115			u8 idx;
116			u8 seq[8]; /* sequence counter (set: RX, get: TX) */
117			u16 key_len;
118			u8 key[0];
119		} crypt;
120
121	} u;
122}ieee_param;
123
124
125#define MSECS(t) msecs_to_jiffies(t)
126#define msleep_interruptible_rtl  msleep_interruptible
127
128#define IEEE80211_DATA_LEN		2304
129/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
130   6.2.1.1.2.
131
132   The figure in section 7.1.2 suggests a body size of up to 2312
133   bytes is allowed, which is a bit confusing, I suspect this
134   represents the 2304 bytes of real data, plus a possible 8 bytes of
135   WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
136
137#define IEEE80211_3ADDR_LEN 24
138#define IEEE80211_4ADDR_LEN 30
139#define IEEE80211_FCS_LEN    4
140#define IEEE80211_HLEN			IEEE80211_4ADDR_LEN
141#define IEEE80211_FRAME_LEN		(IEEE80211_DATA_LEN + IEEE80211_HLEN)
142#define IEEE80211_MGMT_HDR_LEN 24
143#define IEEE80211_DATA_HDR3_LEN 24
144#define IEEE80211_DATA_HDR4_LEN 30
145
146#define MIN_FRAG_THRESHOLD     256U
147#define	MAX_FRAG_THRESHOLD     2346U
148
149/* Frame control field constants */
150#define IEEE80211_FCTL_DSTODS		0x0300 //added by david
151#define IEEE80211_FCTL_WEP		0x4000
152
153/* debug macros */
154
155#ifdef CONFIG_IEEE80211_DEBUG
156extern u32 ieee80211_debug_level;
157#define IEEE80211_DEBUG(level, fmt, args...) \
158do { if (ieee80211_debug_level & (level)) \
159  printk(KERN_DEBUG "ieee80211: %c %s " fmt, \
160         in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
161#else
162#define IEEE80211_DEBUG(level, fmt, args...) do {} while (0)
163#endif	/* CONFIG_IEEE80211_DEBUG */
164
165
166#define IEEE80211_DL_INFO          (1<<0)
167#define IEEE80211_DL_WX            (1<<1)
168#define IEEE80211_DL_SCAN          (1<<2)
169#define IEEE80211_DL_STATE         (1<<3)
170#define IEEE80211_DL_MGMT          (1<<4)
171#define IEEE80211_DL_FRAG          (1<<5)
172#define IEEE80211_DL_EAP           (1<<6)
173#define IEEE80211_DL_DROP          (1<<7)
174
175#define IEEE80211_DL_TX            (1<<8)
176#define IEEE80211_DL_RX            (1<<9)
177
178#define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
179#define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
180#define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
181
182#define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
183#define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
184//#define IEEE_DEBUG_SCAN  IEEE80211_WARNING
185#define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
186#define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
187#define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
188#define IEEE80211_DEBUG_EAP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
189#define IEEE80211_DEBUG_DROP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
190#define IEEE80211_DEBUG_TX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
191#define IEEE80211_DEBUG_RX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
192#include <linux/netdevice.h>
193#include <linux/wireless.h>
194#include <linux/if_arp.h> /* ARPHRD_ETHER */
195
196#ifndef WIRELESS_SPY
197#define WIRELESS_SPY		// enable iwspy support
198#endif
199#include <net/iw_handler.h>	// new driver API
200
201#ifndef ETH_P_PAE
202#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
203#endif /* ETH_P_PAE */
204
205#define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
206
207#ifndef ETH_P_80211_RAW
208#define ETH_P_80211_RAW (ETH_P_ECONET + 1)
209#endif
210
211/* IEEE 802.11 defines */
212
213#define P80211_OUI_LEN 3
214
215struct ieee80211_snap_hdr {
216
217        u8    dsap;   /* always 0xAA */
218        u8    ssap;   /* always 0xAA */
219        u8    ctrl;   /* always 0x03 */
220        u8    oui[P80211_OUI_LEN];    /* organizational universal id */
221
222} __attribute__ ((packed));
223
224#define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
225
226#define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
227#define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
228
229#define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
230#define WLAN_GET_SEQ_SEQ(seq)  ((seq) & IEEE80211_SCTL_SEQ)
231
232#define WLAN_CAPABILITY_BSS (1<<0)
233#define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
234
235#define IEEE80211_STATMASK_SIGNAL (1<<0)
236#define IEEE80211_STATMASK_RSSI (1<<1)
237#define IEEE80211_STATMASK_NOISE (1<<2)
238#define IEEE80211_STATMASK_RATE (1<<3)
239#define IEEE80211_STATMASK_WEMASK 0x7
240
241
242#define IEEE80211_CCK_MODULATION    (1<<0)
243#define IEEE80211_OFDM_MODULATION   (1<<1)
244
245#define IEEE80211_24GHZ_BAND     (1<<0)
246#define IEEE80211_52GHZ_BAND     (1<<1)
247
248#define IEEE80211_CCK_RATE_LEN  		4
249#define IEEE80211_CCK_RATE_1MB		        0x02
250#define IEEE80211_CCK_RATE_2MB		        0x04
251#define IEEE80211_CCK_RATE_5MB		        0x0B
252#define IEEE80211_CCK_RATE_11MB		        0x16
253#define IEEE80211_OFDM_RATE_LEN 		8
254#define IEEE80211_OFDM_RATE_6MB		        0x0C
255#define IEEE80211_OFDM_RATE_9MB		        0x12
256#define IEEE80211_OFDM_RATE_12MB		0x18
257#define IEEE80211_OFDM_RATE_18MB		0x24
258#define IEEE80211_OFDM_RATE_24MB		0x30
259#define IEEE80211_OFDM_RATE_36MB		0x48
260#define IEEE80211_OFDM_RATE_48MB		0x60
261#define IEEE80211_OFDM_RATE_54MB		0x6C
262#define IEEE80211_BASIC_RATE_MASK		0x80
263
264#define IEEE80211_CCK_RATE_1MB_MASK		(1<<0)
265#define IEEE80211_CCK_RATE_2MB_MASK		(1<<1)
266#define IEEE80211_CCK_RATE_5MB_MASK		(1<<2)
267#define IEEE80211_CCK_RATE_11MB_MASK		(1<<3)
268#define IEEE80211_OFDM_RATE_6MB_MASK		(1<<4)
269#define IEEE80211_OFDM_RATE_9MB_MASK		(1<<5)
270#define IEEE80211_OFDM_RATE_12MB_MASK		(1<<6)
271#define IEEE80211_OFDM_RATE_18MB_MASK		(1<<7)
272#define IEEE80211_OFDM_RATE_24MB_MASK		(1<<8)
273#define IEEE80211_OFDM_RATE_36MB_MASK		(1<<9)
274#define IEEE80211_OFDM_RATE_48MB_MASK		(1<<10)
275#define IEEE80211_OFDM_RATE_54MB_MASK		(1<<11)
276
277#define IEEE80211_CCK_RATES_MASK	        0x0000000F
278#define IEEE80211_CCK_BASIC_RATES_MASK	(IEEE80211_CCK_RATE_1MB_MASK | \
279	IEEE80211_CCK_RATE_2MB_MASK)
280#define IEEE80211_CCK_DEFAULT_RATES_MASK	(IEEE80211_CCK_BASIC_RATES_MASK | \
281        IEEE80211_CCK_RATE_5MB_MASK | \
282        IEEE80211_CCK_RATE_11MB_MASK)
283
284#define IEEE80211_OFDM_RATES_MASK		0x00000FF0
285#define IEEE80211_OFDM_BASIC_RATES_MASK	(IEEE80211_OFDM_RATE_6MB_MASK | \
286	IEEE80211_OFDM_RATE_12MB_MASK | \
287	IEEE80211_OFDM_RATE_24MB_MASK)
288#define IEEE80211_OFDM_DEFAULT_RATES_MASK	(IEEE80211_OFDM_BASIC_RATES_MASK | \
289	IEEE80211_OFDM_RATE_9MB_MASK  | \
290	IEEE80211_OFDM_RATE_18MB_MASK | \
291	IEEE80211_OFDM_RATE_36MB_MASK | \
292	IEEE80211_OFDM_RATE_48MB_MASK | \
293	IEEE80211_OFDM_RATE_54MB_MASK)
294#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
295                                IEEE80211_CCK_DEFAULT_RATES_MASK)
296
297#define IEEE80211_NUM_OFDM_RATES	    8
298#define IEEE80211_NUM_CCK_RATES	            4
299#define IEEE80211_OFDM_SHIFT_MASK_A         4
300
301/* this is stolen and modified from the madwifi driver*/
302#define IEEE80211_FC0_TYPE_MASK		0x0c
303#define IEEE80211_FC0_TYPE_DATA		0x08
304#define IEEE80211_FC0_SUBTYPE_MASK	0xB0
305#define IEEE80211_FC0_SUBTYPE_QOS	0x80
306
307#define IEEE80211_QOS_HAS_SEQ(fc) \
308	(((fc) & (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == \
309	 (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
310
311/* this is stolen from ipw2200 driver */
312#define IEEE_IBSS_MAC_HASH_SIZE 31
313struct ieee_ibss_seq {
314	u8 mac[ETH_ALEN];
315	u16 seq_num[17];
316	u16 frag_num[17];
317	unsigned long packet_time[17];
318	struct list_head list;
319};
320
321/* NOTE: This data is for statistical purposes; not all hardware provides this
322 *       information for frames received.  Not setting these will not cause
323 *       any adverse affects. */
324struct ieee80211_rx_stats {
325	u32 mac_time[2];
326	u8 signalstrength;
327	s8 rssi;
328	u8 signal;
329	u8 noise;
330	u16 rate; /* in 100 kbps */
331	u8 received_channel;
332	u8 control;
333	u8 mask;
334	u8 freq;
335	u16 len;
336	u8 nic_type;
337};
338
339/* IEEE 802.11 requires that STA supports concurrent reception of at least
340 * three fragmented frames. This define can be increased to support more
341 * concurrent frames, but it should be noted that each entry can consume about
342 * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
343#define IEEE80211_FRAG_CACHE_LEN 4
344
345struct ieee80211_frag_entry {
346	unsigned long first_frag_time;
347	unsigned int seq;
348	unsigned int last_frag;
349	struct sk_buff *skb;
350	u8 src_addr[ETH_ALEN];
351	u8 dst_addr[ETH_ALEN];
352};
353
354struct ieee80211_stats {
355	unsigned int tx_unicast_frames;
356	unsigned int tx_multicast_frames;
357	unsigned int tx_fragments;
358	unsigned int tx_unicast_octets;
359	unsigned int tx_multicast_octets;
360	unsigned int tx_deferred_transmissions;
361	unsigned int tx_single_retry_frames;
362	unsigned int tx_multiple_retry_frames;
363	unsigned int tx_retry_limit_exceeded;
364	unsigned int tx_discards;
365	unsigned int rx_unicast_frames;
366	unsigned int rx_multicast_frames;
367	unsigned int rx_fragments;
368	unsigned int rx_unicast_octets;
369	unsigned int rx_multicast_octets;
370	unsigned int rx_fcs_errors;
371	unsigned int rx_discards_no_buffer;
372	unsigned int tx_discards_wrong_sa;
373	unsigned int rx_discards_undecryptable;
374	unsigned int rx_message_in_msg_fragments;
375	unsigned int rx_message_in_bad_msg_fragments;
376};
377
378struct ieee80211_device;
379
380#include "ieee80211_crypt.h"
381
382#define SEC_KEY_1         (1<<0)
383#define SEC_KEY_2         (1<<1)
384#define SEC_KEY_3         (1<<2)
385#define SEC_KEY_4         (1<<3)
386#define SEC_ACTIVE_KEY    (1<<4)
387#define SEC_AUTH_MODE     (1<<5)
388#define SEC_UNICAST_GROUP (1<<6)
389#define SEC_LEVEL         (1<<7)
390#define SEC_ENABLED       (1<<8)
391
392#define SEC_LEVEL_0      0 /* None */
393#define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
394#define SEC_LEVEL_2      2 /* Level 1 + TKIP */
395#define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
396#define SEC_LEVEL_3      4 /* Level 2 + CCMP */
397
398#define WEP_KEYS 4
399#define WEP_KEY_LEN 13
400
401#define WEP_KEY_LEN_MODIF 32
402
403struct ieee80211_security {
404	u16 active_key:2,
405            enabled:1,
406	    auth_mode:2,
407            auth_algo:4,
408            unicast_uses_group:1;
409	u8 key_sizes[WEP_KEYS];
410	u8 keys[WEP_KEYS][WEP_KEY_LEN_MODIF];
411	u8 level;
412	u16 flags;
413} __attribute__ ((packed));
414
415
416/*
417
418 802.11 data frame from AP
419
420      ,-------------------------------------------------------------------.
421Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
422      |------|------|---------|---------|---------|------|---------|------|
423Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
424      |      | tion | (BSSID) |         |         | ence |  data   |      |
425      `-------------------------------------------------------------------'
426
427Total: 28-2340 bytes
428
429*/
430
431/* Management Frame Information Element Types */
432enum {
433	MFIE_TYPE_SSID = 0,
434	MFIE_TYPE_RATES = 1,
435	MFIE_TYPE_FH_SET = 2,
436	MFIE_TYPE_DS_SET = 3,
437	MFIE_TYPE_CF_SET = 4,
438	MFIE_TYPE_TIM = 5,
439	MFIE_TYPE_IBSS_SET = 6,
440	MFIE_TYPE_COUNTRY = 7,
441	MFIE_TYPE_CHALLENGE = 16,
442	MFIE_TYPE_ERP = 42,
443	MFIE_TYPE_RSN = 48,
444	MFIE_TYPE_RATES_EX = 50,
445	MFIE_TYPE_GENERIC = 221,
446};
447
448struct ieee80211_header_data {
449	u16 frame_ctl;
450	u16 duration_id;
451	u8 addr1[6];
452	u8 addr2[6];
453	u8 addr3[6];
454	u16 seq_ctrl;
455};
456
457struct ieee80211_hdr_4addr {
458	u16 frame_ctl;
459	u16 duration_id;
460	u8 addr1[ETH_ALEN];
461	u8 addr2[ETH_ALEN];
462	u8 addr3[ETH_ALEN];
463	u16 seq_ctl;
464	u8 addr4[ETH_ALEN];
465} __attribute__ ((packed));
466
467struct ieee80211_hdr_3addrqos {
468	u16 frame_ctl;
469	u16 duration_id;
470	u8 addr1[ETH_ALEN];
471	u8 addr2[ETH_ALEN];
472	u8 addr3[ETH_ALEN];
473	u16 seq_ctl;
474	u16 qos_ctl;
475} __attribute__ ((packed));
476
477struct ieee80211_hdr_4addrqos {
478	u16 frame_ctl;
479	u16 duration_id;
480	u8 addr1[ETH_ALEN];
481	u8 addr2[ETH_ALEN];
482	u8 addr3[ETH_ALEN];
483	u16 seq_ctl;
484	u8 addr4[ETH_ALEN];
485	u16 qos_ctl;
486} __attribute__ ((packed));
487
488struct ieee80211_info_element_hdr {
489	u8 id;
490	u8 len;
491} __attribute__ ((packed));
492
493struct ieee80211_info_element {
494	u8 id;
495	u8 len;
496	u8 data[0];
497} __attribute__ ((packed));
498
499struct ieee80211_authentication {
500	struct ieee80211_header_data header;
501	u16 algorithm;
502	u16 transaction;
503	u16 status;
504	//struct ieee80211_info_element_hdr info_element;
505} __attribute__ ((packed));
506
507struct ieee80211_disassoc_frame {
508	struct ieee80211_hdr_3addr header;
509	u16    reasoncode;
510} __attribute__ ((packed));
511
512struct ieee80211_probe_request {
513	struct ieee80211_header_data header;
514	/* struct ieee80211_info_element info_element; */
515} __attribute__ ((packed));
516
517struct ieee80211_probe_response {
518	struct ieee80211_header_data header;
519	u32 time_stamp[2];
520	u16 beacon_interval;
521	u16 capability;
522	struct ieee80211_info_element info_element;
523} __attribute__ ((packed));
524
525struct ieee80211_assoc_request_frame {
526	struct ieee80211_hdr_3addr header;
527	u16 capability;
528	u16 listen_interval;
529	//u8 current_ap[ETH_ALEN];
530	struct ieee80211_info_element_hdr info_element;
531} __attribute__ ((packed));
532
533struct ieee80211_assoc_response_frame {
534	struct ieee80211_hdr_3addr header;
535	u16 capability;
536	u16 status;
537	u16 aid;
538	struct ieee80211_info_element info_element; /* supported rates */
539} __attribute__ ((packed));
540
541struct ieee80211_txb {
542	u8 nr_frags;
543	u8 encrypted;
544	u16 reserved;
545	u16 frag_size;
546	u16 payload_size;
547	struct sk_buff *fragments[0];
548};
549
550/* SWEEP TABLE ENTRIES NUMBER */
551#define MAX_SWEEP_TAB_ENTRIES			42
552#define MAX_SWEEP_TAB_ENTRIES_PER_PACKET	7
553
554/* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
555 * only use 8, and then use extended rates for the remaining supported
556 * rates.  Other APs, however, stick all of their supported rates on the
557 * main rates information element... */
558#define MAX_RATES_LENGTH			((u8)12)
559#define MAX_RATES_EX_LENGTH			((u8)16)
560
561#define MAX_NETWORK_COUNT			128
562
563#define MAX_CHANNEL_NUMBER			165
564
565#define IEEE80211_SOFTMAC_SCAN_TIME		100 /* (HZ / 2) */
566#define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME	(HZ * 2)
567
568#define CRC_LENGTH	4U
569
570#define MAX_WPA_IE_LEN	64
571
572#define NETWORK_EMPTY_ESSID	(1 << 0)
573#define NETWORK_HAS_OFDM	(1 << 1)
574#define NETWORK_HAS_CCK		(1 << 2)
575
576struct ieee80211_wmm_ac_param {
577	u8 ac_aci_acm_aifsn;
578	u8 ac_ecwmin_ecwmax;
579	u16 ac_txop_limit;
580};
581
582struct ieee80211_wmm_ts_info {
583	u8 ac_dir_tid;
584	u8 ac_up_psb;
585	u8 reserved;
586} __attribute__ ((packed));
587
588struct ieee80211_wmm_tspec_elem {
589	struct ieee80211_wmm_ts_info ts_info;
590	u16 norm_msdu_size;
591	u16 max_msdu_size;
592	u32 min_serv_inter;
593	u32 max_serv_inter;
594	u32 inact_inter;
595	u32 suspen_inter;
596	u32 serv_start_time;
597	u32 min_data_rate;
598	u32 mean_data_rate;
599	u32 peak_data_rate;
600	u32 max_burst_size;
601	u32 delay_bound;
602	u32 min_phy_rate;
603	u16 surp_band_allow;
604	u16 medium_time;
605}__attribute__((packed));
606
607enum eap_type {
608	EAP_PACKET = 0,
609	EAPOL_START,
610	EAPOL_LOGOFF,
611	EAPOL_KEY,
612	EAPOL_ENCAP_ASF_ALERT
613};
614
615static const char *eap_types[] = {
616	[EAP_PACKET]		= "EAP-Packet",
617	[EAPOL_START]		= "EAPOL-Start",
618	[EAPOL_LOGOFF]		= "EAPOL-Logoff",
619	[EAPOL_KEY]		= "EAPOL-Key",
620	[EAPOL_ENCAP_ASF_ALERT]	= "EAPOL-Encap-ASF-Alert"
621};
622
623static inline const char *eap_get_type(int type)
624{
625	return (type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
626}
627
628struct eapol {
629	u8 snap[6];
630	u16 ethertype;
631	u8 version;
632	u8 type;
633	u16 length;
634} __attribute__ ((packed));
635
636struct ieee80211_softmac_stats {
637	unsigned int rx_ass_ok;
638	unsigned int rx_ass_err;
639	unsigned int rx_probe_rq;
640	unsigned int tx_probe_rs;
641	unsigned int tx_beacons;
642	unsigned int rx_auth_rq;
643	unsigned int rx_auth_rs_ok;
644	unsigned int rx_auth_rs_err;
645	unsigned int tx_auth_rq;
646	unsigned int no_auth_rs;
647	unsigned int no_ass_rs;
648	unsigned int tx_ass_rq;
649	unsigned int rx_ass_rq;
650	unsigned int tx_probe_rq;
651	unsigned int reassoc;
652	unsigned int swtxstop;
653	unsigned int swtxawake;
654};
655
656#define BEACON_PROBE_SSID_ID_POSITION 12
657
658/*
659 * These are the data types that can make up management packets
660 *
661	u16 auth_algorithm;
662	u16 auth_sequence;
663	u16 beacon_interval;
664	u16 capability;
665	u8 current_ap[ETH_ALEN];
666	u16 listen_interval;
667	struct {
668		u16 association_id:14, reserved:2;
669	} __attribute__ ((packed));
670	u32 time_stamp[2];
671	u16 reason;
672	u16 status;
673*/
674
675#define IEEE80211_DEFAULT_TX_ESSID "Penguin"
676#define IEEE80211_DEFAULT_BASIC_RATE 10
677
678enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
679#define MAX_SP_Len  (WMM_all_frame << 4)
680#define IEEE80211_QOS_TID 0x0f
681#define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
682
683#define MAX_IE_LEN						0xFF //+YJ,080625
684
685typedef struct _CHANNEL_LIST{
686	u8	Channel[MAX_CHANNEL_NUMBER + 1];
687	u8	Len;
688}CHANNEL_LIST, *PCHANNEL_LIST;
689
690//by amy for ps
691#define IEEE80211_WATCH_DOG_TIME    2000
692//by amy for ps
693//by amy for antenna
694#define ANTENNA_DIVERSITY_TIMER_PERIOD		1000 // 1000 m
695//by amy for antenna
696
697#define IEEE80211_DTIM_MBCAST 4
698#define IEEE80211_DTIM_UCAST 2
699#define IEEE80211_DTIM_VALID 1
700#define IEEE80211_DTIM_INVALID 0
701
702#define IEEE80211_PS_DISABLED 0
703#define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
704#define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
705#define IEEE80211_PS_ENABLE   IEEE80211_DTIM_VALID
706//added by David for QoS 2006/6/30
707//#define WMM_Hang_8187
708#ifdef WMM_Hang_8187
709#undef WMM_Hang_8187
710#endif
711
712#define WME_AC_BE   0x00
713#define WME_AC_BK   0x01
714#define WME_AC_VI   0x02
715#define WME_AC_VO   0x03
716#define WME_ACI_MASK 0x03
717#define WME_AIFSN_MASK 0x03
718#define WME_AC_PRAM_LEN 16
719
720//UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP
721//#define UP2AC(up)	((up<3) ? ((up==0)?1:0) : (up>>1))
722#define UP2AC(up) (		   \
723	((up) < 1) ? WME_AC_BE : \
724	((up) < 3) ? WME_AC_BK : \
725	((up) < 4) ? WME_AC_BE : \
726	((up) < 6) ? WME_AC_VI : \
727	WME_AC_VO)
728//AC Mapping to UP, using in Tx part for selecting the corresponding TX queue
729#define AC2UP(_ac)	(       \
730	((_ac) == WME_AC_VO) ? 6 : \
731	((_ac) == WME_AC_VI) ? 5 : \
732	((_ac) == WME_AC_BK) ? 1 : \
733	0)
734
735#define	ETHER_ADDR_LEN		6	/* length of an Ethernet address */
736struct	ether_header {
737	u8 ether_dhost[ETHER_ADDR_LEN];
738	u8 ether_shost[ETHER_ADDR_LEN];
739	u16 ether_type;
740} __attribute__((packed));
741
742#ifndef ETHERTYPE_PAE
743#define	ETHERTYPE_PAE	0x888e		/* EAPOL PAE/802.1x */
744#endif
745#ifndef ETHERTYPE_IP
746#define	ETHERTYPE_IP	0x0800		/* IP protocol */
747#endif
748
749struct ieee80211_network {
750	/* These entries are used to identify a unique network */
751	u8 bssid[ETH_ALEN];
752	u8 channel;
753	/* Ensure null-terminated for any debug msgs */
754	u8 ssid[IW_ESSID_MAX_SIZE + 1];
755	u8 ssid_len;
756
757	/* These are network statistics */
758	struct ieee80211_rx_stats stats;
759	u16 capability;
760	u8 rates[MAX_RATES_LENGTH];
761	u8 rates_len;
762	u8 rates_ex[MAX_RATES_EX_LENGTH];
763	u8 rates_ex_len;
764	unsigned long last_scanned;
765	u8 mode;
766	u8 flags;
767	u32 last_associate;
768	u32 time_stamp[2];
769	u16 beacon_interval;
770	u16 listen_interval;
771	u16 atim_window;
772	u8 wpa_ie[MAX_WPA_IE_LEN];
773	size_t wpa_ie_len;
774	u8 rsn_ie[MAX_WPA_IE_LEN];
775	size_t rsn_ie_len;
776	u8 dtim_period;
777	u8 dtim_data;
778	u32 last_dtim_sta_time[2];
779	struct list_head list;
780	//appeded for QoS
781	u8 wmm_info;
782	struct ieee80211_wmm_ac_param wmm_param[4];
783	u8 QoS_Enable;
784	u8 SignalStrength;
785//by amy 080312
786	u8 HighestOperaRate;
787//by amy 080312
788	u8 Turbo_Enable;//enable turbo mode, added by thomas
789	u16 CountryIeLen;
790	u8 CountryIeBuf[MAX_IE_LEN];
791};
792
793enum ieee80211_state {
794
795	/* the card is not linked at all */
796	IEEE80211_NOLINK = 0,
797
798	/* IEEE80211_ASSOCIATING* are for BSS client mode
799	 * the driver shall not perform RX filtering unless
800	 * the state is LINKED.
801	 * The driver shall just check for the state LINKED and
802	 * defaults to NOLINK for ALL the other states (including
803	 * LINKED_SCANNING)
804	 */
805
806	/* the association procedure will start (wq scheduling)*/
807	IEEE80211_ASSOCIATING,
808	IEEE80211_ASSOCIATING_RETRY,
809
810	/* the association procedure is sending AUTH request*/
811	IEEE80211_ASSOCIATING_AUTHENTICATING,
812
813	/* the association procedure has successfully authentcated
814	 * and is sending association request
815	 */
816	IEEE80211_ASSOCIATING_AUTHENTICATED,
817
818	/* the link is ok. the card associated to a BSS or linked
819	 * to a ibss cell or acting as an AP and creating the bss
820	 */
821	IEEE80211_LINKED,
822
823	/* same as LINKED, but the driver shall apply RX filter
824	 * rules as we are in NO_LINK mode. As the card is still
825	 * logically linked, but it is doing a syncro site survey
826	 * then it will be back to LINKED state.
827	 */
828	IEEE80211_LINKED_SCANNING,
829
830};
831
832#define DEFAULT_MAX_SCAN_AGE (15 * HZ)
833#define DEFAULT_FTS 2346
834
835#define CFG_IEEE80211_RESERVE_FCS (1<<0)
836#define CFG_IEEE80211_COMPUTE_FCS (1<<1)
837
838typedef struct tx_pending_t{
839	int frag;
840	struct ieee80211_txb *txb;
841}tx_pending_t;
842
843enum {
844	COUNTRY_CODE_FCC = 0,
845	COUNTRY_CODE_IC = 1,
846	COUNTRY_CODE_ETSI = 2,
847	COUNTRY_CODE_SPAIN = 3,
848	COUNTRY_CODE_FRANCE = 4,
849	COUNTRY_CODE_MKK = 5,
850	COUNTRY_CODE_MKK1 = 6,
851	COUNTRY_CODE_ISRAEL = 7,
852	COUNTRY_CODE_TELEC = 8,
853	COUNTRY_CODE_GLOBAL_DOMAIN = 9,
854	COUNTRY_CODE_WORLD_WIDE_13_INDEX = 10
855};
856
857struct ieee80211_device {
858	struct net_device *dev;
859
860	/* Bookkeeping structures */
861	struct net_device_stats stats;
862	struct ieee80211_stats ieee_stats;
863	struct ieee80211_softmac_stats softmac_stats;
864
865	/* Probe / Beacon management */
866	struct list_head network_free_list;
867	struct list_head network_list;
868	struct ieee80211_network *networks;
869	int scans;
870	int scan_age;
871
872	int iw_mode; /* operating mode (IW_MODE_*) */
873
874	spinlock_t lock;
875	spinlock_t wpax_suitlist_lock;
876
877	int tx_headroom; /* Set to size of any additional room needed at front
878			  * of allocated Tx SKBs */
879	u32 config;
880
881	/* WEP and other encryption related settings at the device level */
882	int open_wep; /* Set to 1 to allow unencrypted frames */
883
884	int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
885				 * WEP key changes */
886
887	/* If the host performs {en,de}cryption, then set to 1 */
888	int host_encrypt;
889	int host_decrypt;
890	int ieee802_1x; /* is IEEE 802.1X used */
891
892	/* WPA data */
893	int wpa_enabled;
894	int drop_unencrypted;
895	int tkip_countermeasures;
896	int privacy_invoked;
897	size_t wpa_ie_len;
898	u8 *wpa_ie;
899
900	u8 ap_mac_addr[6];
901	u16 pairwise_key_type;
902	u16 broadcast_key_type;
903
904	struct list_head crypt_deinit_list;
905	struct ieee80211_crypt_data *crypt[WEP_KEYS];
906	int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
907	struct timer_list crypt_deinit_timer;
908
909	int bcrx_sta_key; /* use individual keys to override default keys even
910			   * with RX of broad/multicast frames */
911
912	/* Fragmentation structures */
913	// each streaming contain a entry
914	struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN];
915	unsigned int frag_next_idx[17];
916	u16 fts; /* Fragmentation Threshold */
917
918	/* This stores infos for the current network.
919	 * Either the network we are associated in INFRASTRUCTURE
920	 * or the network that we are creating in MASTER mode.
921	 * ad-hoc is a mixture ;-).
922	 * Note that in infrastructure mode, even when not associated,
923	 * fields bssid and essid may be valid (if wpa_set and essid_set
924	 * are true) as thy carry the value set by the user via iwconfig
925	 */
926	struct ieee80211_network current_network;
927
928
929	enum ieee80211_state state;
930
931	int short_slot;
932	int mode;       /* A, B, G */
933	int modulation; /* CCK, OFDM */
934	int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
935	int abg_true;   /* ABG flag              */
936
937	/* used for forcing the ibss workqueue to terminate
938	 * without wait for the syncro scan to terminate
939	 */
940	short sync_scan_hurryup;
941
942	void * pDot11dInfo;
943	bool bGlobalDomain;
944
945	// For Liteon Ch12~13 passive scan
946	u8	MinPassiveChnlNum;
947	u8	IbssStartChnl;
948
949	int rate;       /* current rate */
950	int basic_rate;
951	short active_scan;
952
953	/* this contains flags for selectively enable softmac support */
954	u16 softmac_features;
955
956	/* if the sequence control field is not filled by HW */
957	u16 seq_ctrl[5];
958
959	/* association procedure transaction sequence number */
960	u16 associate_seq;
961
962	/* AID for RTXed association responses */
963	u16 assoc_id;
964
965	/* power save mode related*/
966	short ps;
967	short sta_sleep;
968	int ps_timeout;
969	struct tasklet_struct ps_task;
970	u32 ps_th;
971	u32 ps_tl;
972
973	short raw_tx;
974	/* used if IEEE_SOFTMAC_TX_QUEUE is set */
975	short queue_stop;
976	short scanning;
977	short proto_started;
978
979	struct semaphore wx_sem;
980	struct semaphore scan_sem;
981
982	spinlock_t mgmt_tx_lock;
983	spinlock_t beacon_lock;
984
985	short beacon_txing;
986
987	short wap_set;
988	short ssid_set;
989
990	u8  wpax_type_set;    //{added by David, 2006.9.28}
991	u32 wpax_type_notify; //{added by David, 2006.9.26}
992
993	/* QoS related flag */
994	char init_wmmparam_flag;
995
996	/* for discarding duplicated packets in IBSS */
997	struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
998
999	/* for discarding duplicated packets in BSS */
1000	u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1001	u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1002	unsigned long last_packet_time[17];
1003
1004	/* for PS mode */
1005	unsigned long last_rx_ps_time;
1006
1007	/* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1008	struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1009	int mgmt_queue_head;
1010	int mgmt_queue_tail;
1011
1012
1013	/* used if IEEE_SOFTMAC_TX_QUEUE is set */
1014	struct  tx_pending_t tx_pending;
1015
1016	/* used if IEEE_SOFTMAC_ASSOCIATE is set */
1017	struct timer_list associate_timer;
1018
1019	/* used if IEEE_SOFTMAC_BEACONS is set */
1020	struct timer_list beacon_timer;
1021
1022	struct work_struct associate_complete_wq;
1023//	struct work_struct associate_retry_wq;
1024	struct work_struct associate_procedure_wq;
1025//	struct work_struct softmac_scan_wq;
1026	struct work_struct wx_sync_scan_wq;
1027	struct work_struct wmm_param_update_wq;
1028	struct work_struct ps_request_tx_ack_wq;//for ps
1029//	struct work_struct hw_wakeup_wq;
1030//	struct work_struct hw_sleep_wq;
1031//	struct work_struct watch_dog_wq;
1032	bool bInactivePs;
1033	bool actscanning;
1034	bool beinretry;
1035	u16 ListenInterval;
1036	unsigned long NumRxDataInPeriod; //YJ,add,080828
1037	unsigned long NumRxBcnInPeriod;  //YJ,add,080828
1038	unsigned long NumRxOkTotal;
1039	unsigned long NumRxUnicast;//YJ,add,080828,for keep alive
1040	bool bHwRadioOff;
1041        struct delayed_work softmac_scan_wq;
1042        struct delayed_work associate_retry_wq;
1043	struct delayed_work hw_wakeup_wq;
1044	struct delayed_work hw_sleep_wq;//+by amy 080324
1045	struct delayed_work watch_dog_wq;
1046	struct delayed_work sw_antenna_wq;
1047	struct delayed_work  start_ibss_wq;
1048//by amy for rate adaptive 080312
1049    struct delayed_work rate_adapter_wq;
1050//by amy for rate adaptive
1051	struct delayed_work hw_dig_wq;
1052	struct delayed_work tx_pw_wq;
1053
1054//Added for RF power on power off by lizhaoming 080512
1055	struct delayed_work GPIOChangeRFWorkItem;
1056
1057	struct workqueue_struct *wq;
1058
1059	/* Callback functions */
1060	void (*set_security)(struct net_device *dev,
1061			     struct ieee80211_security *sec);
1062
1063	/* Used to TX data frame by using txb structs.
1064	 * this is not used if in the softmac_features
1065	 * is set the flag IEEE_SOFTMAC_TX_QUEUE
1066	 */
1067	int (*hard_start_xmit)(struct ieee80211_txb *txb,
1068			       struct net_device *dev);
1069
1070	int (*reset_port)(struct net_device *dev);
1071
1072	/* Softmac-generated frames (mamagement) are TXed via this
1073	 * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1074	 * not set. As some cards may have different HW queues that
1075	 * one might want to use for data and management frames
1076	 * the option to have two callbacks might be useful.
1077	 * This fucntion can't sleep.
1078	 */
1079	int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1080			       struct net_device *dev);
1081
1082	/* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1083	 * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1084	 * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1085	 * then also management frames are sent via this callback.
1086	 * This function can't sleep.
1087	 */
1088	void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1089			       struct net_device *dev,int rate);
1090
1091	/* stops the HW queue for DATA frames. Useful to avoid
1092	 * waste time to TX data frame when we are reassociating
1093	 * This function can sleep.
1094	 */
1095	void (*data_hard_stop)(struct net_device *dev);
1096
1097	/* OK this is complementar to data_poll_hard_stop */
1098	void (*data_hard_resume)(struct net_device *dev);
1099
1100	/* ask to the driver to retune the radio .
1101	 * This function can sleep. the driver should ensure
1102	 * the radio has been swithced before return.
1103	 */
1104	void (*set_chan)(struct net_device *dev,short ch);
1105
1106	/* These are not used if the ieee stack takes care of
1107	 * scanning (IEEE_SOFTMAC_SCAN feature set).
1108	 * In this case only the set_chan is used.
1109	 *
1110	 * The syncro version is similar to the start_scan but
1111	 * does not return until all channels has been scanned.
1112	 * this is called in user context and should sleep,
1113	 * it is called in a work_queue when swithcing to ad-hoc mode
1114	 * or in behalf of iwlist scan when the card is associated
1115	 * and root user ask for a scan.
1116	 * the fucntion stop_scan should stop both the syncro and
1117	 * background scanning and can sleep.
1118	 * The fucntion start_scan should initiate the background
1119	 * scanning and can't sleep.
1120	 */
1121	void (*scan_syncro)(struct net_device *dev);
1122	void (*start_scan)(struct net_device *dev);
1123	void (*stop_scan)(struct net_device *dev);
1124
1125	/* indicate the driver that the link state is changed
1126	 * for example it may indicate the card is associated now.
1127	 * Driver might be interested in this to apply RX filter
1128	 * rules or simply light the LINK led
1129	 */
1130	void (*link_change)(struct net_device *dev);
1131
1132	/* these two function indicates to the HW when to start
1133	 * and stop to send beacons. This is used when the
1134	 * IEEE_SOFTMAC_BEACONS is not set. For now the
1135	 * stop_send_bacons is NOT guaranteed to be called only
1136	 * after start_send_beacons.
1137	 */
1138	void (*start_send_beacons) (struct net_device *dev);
1139	void (*stop_send_beacons) (struct net_device *dev);
1140
1141	/* power save mode related */
1142	void (*sta_wake_up) (struct net_device *dev);
1143	void (*ps_request_tx_ack) (struct net_device *dev);
1144	void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
1145	short (*ps_is_queue_empty) (struct net_device *dev);
1146
1147	/* QoS related */
1148	//void (*wmm_param_update) (struct net_device *dev, u8 *ac_param);
1149	//void (*wmm_param_update) (struct ieee80211_device *ieee);
1150
1151	/* This must be the last item so that it points to the data
1152	 * allocated beyond this structure by alloc_ieee80211 */
1153	u8 priv[0];
1154};
1155
1156#define IEEE_A            (1<<0)
1157#define IEEE_B            (1<<1)
1158#define IEEE_G            (1<<2)
1159#define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
1160
1161/* Generate a 802.11 header */
1162
1163/* Uses the channel change callback directly
1164 * instead of [start/stop] scan callbacks
1165 */
1166#define IEEE_SOFTMAC_SCAN (1<<2)
1167
1168/* Perform authentication and association handshake */
1169#define IEEE_SOFTMAC_ASSOCIATE (1<<3)
1170
1171/* Generate probe requests */
1172#define IEEE_SOFTMAC_PROBERQ (1<<4)
1173
1174/* Generate respones to probe requests */
1175#define IEEE_SOFTMAC_PROBERS (1<<5)
1176
1177/* The ieee802.11 stack will manages the netif queue
1178 * wake/stop for the driver, taking care of 802.11
1179 * fragmentation. See softmac.c for details. */
1180#define IEEE_SOFTMAC_TX_QUEUE (1<<7)
1181
1182/* Uses only the softmac_data_hard_start_xmit
1183 * even for TX management frames.
1184 */
1185#define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
1186
1187/* Generate beacons.  The stack will enqueue beacons
1188 * to the card
1189 */
1190#define IEEE_SOFTMAC_BEACONS (1<<6)
1191
1192
1193
1194static inline void *ieee80211_priv(struct net_device *dev)
1195{
1196	return ((struct ieee80211_device *)netdev_priv(dev))->priv;
1197}
1198
1199extern inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
1200{
1201	/* Single white space is for Linksys APs */
1202	if (essid_len == 1 && essid[0] == ' ')
1203		return 1;
1204
1205	/* Otherwise, if the entire essid is 0, we assume it is hidden */
1206	while (essid_len) {
1207		essid_len--;
1208		if (essid[essid_len] != '\0')
1209			return 0;
1210	}
1211
1212	return 1;
1213}
1214
1215extern inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
1216{
1217	/*
1218	 * It is possible for both access points and our device to support
1219	 * combinations of modes, so as long as there is one valid combination
1220	 * of ap/device supported modes, then return success
1221	 *
1222	 */
1223	if ((mode & IEEE_A) &&
1224	    (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1225	    (ieee->freq_band & IEEE80211_52GHZ_BAND))
1226		return 1;
1227
1228	if ((mode & IEEE_G) &&
1229	    (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1230	    (ieee->freq_band & IEEE80211_24GHZ_BAND))
1231		return 1;
1232
1233	if ((mode & IEEE_B) &&
1234	    (ieee->modulation & IEEE80211_CCK_MODULATION) &&
1235	    (ieee->freq_band & IEEE80211_24GHZ_BAND))
1236		return 1;
1237
1238	return 0;
1239}
1240
1241extern inline int ieee80211_get_hdrlen(u16 fc)
1242{
1243	int hdrlen = 24;
1244
1245	switch (WLAN_FC_GET_TYPE(fc)) {
1246	case IEEE80211_FTYPE_DATA:
1247		if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
1248			hdrlen = 30; /* Addr4 */
1249		if(IEEE80211_QOS_HAS_SEQ(fc))
1250			hdrlen += 2; /* QOS ctrl*/
1251		break;
1252	case IEEE80211_FTYPE_CTL:
1253		switch (WLAN_FC_GET_STYPE(fc)) {
1254		case IEEE80211_STYPE_CTS:
1255		case IEEE80211_STYPE_ACK:
1256			hdrlen = 10;
1257			break;
1258		default:
1259			hdrlen = 16;
1260			break;
1261		}
1262		break;
1263	}
1264
1265	return hdrlen;
1266}
1267
1268
1269
1270/* ieee80211.c */
1271extern void free_ieee80211(struct net_device *dev);
1272extern struct net_device *alloc_ieee80211(int sizeof_priv);
1273
1274extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
1275
1276/* ieee80211_tx.c */
1277
1278extern int ieee80211_encrypt_fragment(
1279	struct ieee80211_device *ieee,
1280	struct sk_buff *frag,
1281	int hdr_len);
1282
1283extern int ieee80211_rtl_xmit(struct sk_buff *skb,
1284			  struct net_device *dev);
1285extern void ieee80211_txb_free(struct ieee80211_txb *);
1286
1287
1288/* ieee80211_rx.c */
1289extern int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1290			struct ieee80211_rx_stats *rx_stats);
1291extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1292			     struct ieee80211_hdr_4addr *header,
1293			     struct ieee80211_rx_stats *stats);
1294
1295/* ieee80211_wx.c */
1296extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
1297				 struct iw_request_info *info,
1298				 union iwreq_data *wrqu, char *key);
1299extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
1300				   struct iw_request_info *info,
1301				   union iwreq_data *wrqu, char *key);
1302extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
1303				   struct iw_request_info *info,
1304				   union iwreq_data *wrqu, char *key);
1305extern int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
1306                            struct iw_request_info *info,
1307                            union iwreq_data* wrqu, char *extra);
1308int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
1309                               struct iw_request_info *info,
1310                               struct iw_param *data, char *extra);
1311int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
1312                               struct iw_request_info *info,
1313                               union iwreq_data *wrqu, char *extra);
1314
1315int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len);
1316/* ieee80211_softmac.c */
1317extern short ieee80211_is_54g(struct ieee80211_network net);
1318extern short ieee80211_is_shortslot(struct ieee80211_network net);
1319extern int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1320			struct ieee80211_rx_stats *rx_stats, u16 type,
1321			u16 stype);
1322extern void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net);
1323
1324extern void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee);
1325extern void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee);
1326extern void ieee80211_start_bss(struct ieee80211_device *ieee);
1327extern void ieee80211_start_master_bss(struct ieee80211_device *ieee);
1328extern void ieee80211_start_ibss(struct ieee80211_device *ieee);
1329extern void ieee80211_softmac_init(struct ieee80211_device *ieee);
1330extern void ieee80211_softmac_free(struct ieee80211_device *ieee);
1331extern void ieee80211_associate_abort(struct ieee80211_device *ieee);
1332extern void ieee80211_disassociate(struct ieee80211_device *ieee);
1333extern void ieee80211_stop_scan(struct ieee80211_device *ieee);
1334extern void ieee80211_start_scan_syncro(struct ieee80211_device *ieee);
1335extern void ieee80211_check_all_nets(struct ieee80211_device *ieee);
1336extern void ieee80211_start_protocol(struct ieee80211_device *ieee);
1337extern void ieee80211_stop_protocol(struct ieee80211_device *ieee);
1338extern void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee);
1339extern void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee);
1340extern void ieee80211_reset_queue(struct ieee80211_device *ieee);
1341extern void ieee80211_rtl_wake_queue(struct ieee80211_device *ieee);
1342extern void ieee80211_rtl_stop_queue(struct ieee80211_device *ieee);
1343extern struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee);
1344extern void ieee80211_start_send_beacons(struct ieee80211_device *ieee);
1345extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
1346extern int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p);
1347extern void notify_wx_assoc_event(struct ieee80211_device *ieee);
1348extern void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success);
1349extern void SendDisassociation(struct ieee80211_device *ieee,u8* asSta,u8 asRsn);
1350extern void ieee80211_rtl_start_scan(struct ieee80211_device *ieee);
1351
1352//Add for RF power on power off by lizhaoming 080512
1353extern void SendDisassociation(struct ieee80211_device *ieee,
1354       			 u8*                     asSta,
1355        		 u8                      asRsn);
1356
1357/* ieee80211_crypt_ccmp&tkip&wep.c */
1358extern void ieee80211_tkip_null(void);
1359extern void ieee80211_wep_null(void);
1360extern void ieee80211_ccmp_null(void);
1361/* ieee80211_softmac_wx.c */
1362
1363extern int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
1364			    struct iw_request_info *info,
1365			    union iwreq_data *wrqu, char *ext);
1366
1367extern int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
1368			 struct iw_request_info *info,
1369			 union iwreq_data *awrq,
1370			 char *extra);
1371
1372extern int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b);
1373
1374extern int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
1375			     struct iw_request_info *info,
1376			     union iwreq_data *wrqu, char *extra);
1377
1378extern int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
1379			     struct iw_request_info *info,
1380			     union iwreq_data *wrqu, char *extra);
1381
1382extern int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1383			     union iwreq_data *wrqu, char *b);
1384
1385extern int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info *a,
1386			     union iwreq_data *wrqu, char *b);
1387
1388extern int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
1389			      struct iw_request_info *a,
1390			      union iwreq_data *wrqu, char *extra);
1391
1392extern int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1393			     union iwreq_data *wrqu, char *b);
1394
1395extern int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1396			     union iwreq_data *wrqu, char *b);
1397
1398extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1399			     union iwreq_data *wrqu, char *b);
1400
1401extern void ieee80211_wx_sync_scan_wq(struct work_struct *work);
1402
1403extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
1404			       struct iw_request_info *info,
1405			       union iwreq_data *wrqu, char *extra);
1406
1407extern int ieee80211_wx_get_name(struct ieee80211_device *ieee,
1408			     struct iw_request_info *info,
1409			     union iwreq_data *wrqu, char *extra);
1410
1411extern int ieee80211_wx_set_power(struct ieee80211_device *ieee,
1412				 struct iw_request_info *info,
1413				 union iwreq_data *wrqu, char *extra);
1414
1415extern int ieee80211_wx_get_power(struct ieee80211_device *ieee,
1416				 struct iw_request_info *info,
1417				 union iwreq_data *wrqu, char *extra);
1418
1419extern void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee);
1420
1421extern void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr);
1422
1423extern const long ieee80211_wlan_frequencies[];
1424
1425extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
1426{
1427	ieee->scans++;
1428}
1429
1430extern inline int ieee80211_get_scans(struct ieee80211_device *ieee)
1431{
1432	return ieee->scans;
1433}
1434
1435static inline const char *escape_essid(const char *essid, u8 essid_len) {
1436	static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
1437	const char *s = essid;
1438	char *d = escaped;
1439
1440	if (ieee80211_is_empty_essid(essid, essid_len)) {
1441		memcpy(escaped, "<hidden>", sizeof("<hidden>"));
1442		return escaped;
1443	}
1444
1445	essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
1446	while (essid_len--) {
1447		if (*s == '\0') {
1448			*d++ = '\\';
1449			*d++ = '0';
1450			s++;
1451		} else {
1452			*d++ = *s++;
1453		}
1454	}
1455	*d = '\0';
1456	return escaped;
1457}
1458#endif /* IEEE80211_H */
1459