2 * Merged with mainline rtllib.h in Aug 2004. Original ieee802_11
3 * remains copyright by the original authors
5 * Portions of the merged code are based on Host AP (software wireless
6 * LAN access point) driver for Intersil Prism2/2.5/3.
8 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
10 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
12 * Adaption to a generic IEEE 802.11 stack by James Ketrenos
13 * <jketreno@linux.intel.com>
14 * Copyright (c) 2004, Intel Corporation
16 * Modified for Realtek's wi-fi cards by Andrea Merello
17 * <andrea.merello@gmail.com>
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
26 #include <linux/if_ether.h> /* ETH_ALEN */
27 #include <linux/kernel.h> /* ARRAY_SIZE */
28 #include <linux/module.h>
29 #include <linux/interrupt.h>
30 #include <linux/jiffies.h>
31 #include <linux/timer.h>
32 #include <linux/sched.h>
33 #include <linux/semaphore.h>
34 #include <linux/mutex.h>
36 #include <linux/delay.h>
37 #include <linux/wireless.h>
39 #include "rtllib_debug.h"
40 #include "rtl819x_HT.h"
41 #include "rtl819x_BA.h"
42 #include "rtl819x_TS.h"
44 #include <linux/netdevice.h>
45 #include <linux/if_arp.h> /* ARPHRD_ETHER */
46 #include <net/lib80211.h>
48 #define MAX_PRECMD_CNT 16
49 #define MAX_RFDEPENDCMD_CNT 16
50 #define MAX_POSTCMD_CNT 16
55 #include <net/iw_handler.h>
57 #ifndef IW_MODE_MONITOR
58 #define IW_MODE_MONITOR 6
62 #define IWEVCUSTOM 0x8c02
66 /* Max number of char in custom event - use multiple of them if needed */
67 #define IW_CUSTOM_MAX 256 /* In bytes */
70 #define skb_tail_pointer_rsl(skb) skb_tail_pointer(skb)
72 #define queue_delayed_work_rsl(x, y, z) queue_delayed_work(x, y, z)
73 #define INIT_DELAYED_WORK_RSL(x, y, z) INIT_DELAYED_WORK(x, y)
75 #define queue_work_rsl(x, y) queue_work(x, y)
76 #define INIT_WORK_RSL(x, y, z) INIT_WORK(x, y)
78 #define container_of_work_rsl(x, y, z) container_of(x, y, z)
79 #define container_of_dwork_rsl(x, y, z) \
80 container_of(to_delayed_work(x), y, z)
82 #define iwe_stream_add_event_rsl(info, start, stop, iwe, len) \
83 iwe_stream_add_event(info, start, stop, iwe, len)
85 #define iwe_stream_add_point_rsl(info, start, stop, iwe, p) \
86 iwe_stream_add_point(info, start, stop, iwe, p)
88 static inline void *netdev_priv_rsl(struct net_device *dev)
90 return netdev_priv(dev);
93 #define KEY_TYPE_NA 0x0
94 #define KEY_TYPE_WEP40 0x1
95 #define KEY_TYPE_TKIP 0x2
96 #define KEY_TYPE_CCMP 0x4
97 #define KEY_TYPE_WEP104 0x5
98 /* added for rtl819x tx procedure */
99 #define MAX_QUEUE_SIZE 0x10
106 #define TXCMD_QUEUE 5
109 #define BEACON_QUEUE 8
112 #define IW_MODE_MESH 7
115 #define IE_CISCO_FLAG_POSITION 0x08
116 #define SUPPORT_CKIP_MIC 0x08
117 #define SUPPORT_CKIP_PK 0x10
118 #define RT_RF_OFF_LEVL_HALT_NIC BIT3
119 #define RT_IN_PS_LEVEL(pPSC, _PS_FLAG) \
120 ((pPSC->CurPsLevel & _PS_FLAG) ? true : false)
121 #define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG) \
122 (pPSC->CurPsLevel &= (~(_PS_FLAG)))
123 #define RT_SET_PS_LEVEL(pPSC, _PS_FLAG) (pPSC->CurPsLevel |= _PS_FLAG)
125 /* defined for skb cb field */
126 /* At most 28 byte */
128 /* Tx Desc Related flags (8-9) */
134 u8 bTxDisableRateFallBack:1;
135 u8 bTxUseDriverAssingedRate:1;
140 /* Tx Firmware Related flags (10-11)*/
144 u8 bUseShortPreamble:1;
145 u8 bTxEnableFwCalcDur:1;
152 u8 bRTSUseShortPreamble:1;
159 /* Tx Desc related element(12-19) */
170 /* Tx firmware related element(20-27) */
178 u8 bIsSpecialDataFrame;
184 enum sw_chnl_cmd_id {
186 CmdID_SetTxPowerLevel,
188 CmdID_WritePortUlong,
189 CmdID_WritePortUshort,
190 CmdID_WritePortUchar,
195 enum sw_chnl_cmd_id CmdID;
201 /*--------------------------Define -------------------------------------------*/
204 #define MGN_5_5M 0x0b
216 #define MGN_MCS0 0x80
217 #define MGN_MCS1 0x81
218 #define MGN_MCS2 0x82
219 #define MGN_MCS3 0x83
220 #define MGN_MCS4 0x84
221 #define MGN_MCS5 0x85
222 #define MGN_MCS6 0x86
223 #define MGN_MCS7 0x87
224 #define MGN_MCS8 0x88
225 #define MGN_MCS9 0x89
226 #define MGN_MCS10 0x8a
227 #define MGN_MCS11 0x8b
228 #define MGN_MCS12 0x8c
229 #define MGN_MCS13 0x8d
230 #define MGN_MCS14 0x8e
231 #define MGN_MCS15 0x8f
235 HW_VAR_MULTICAST_REG,
239 HW_VAR_SECURITY_CONF,
240 HW_VAR_BEACON_INTERVAL,
242 HW_VAR_LISTEN_INTERVAL,
255 HW_VAR_RATE_FALLBACK_CONTROL,
256 HW_VAR_CONTENTION_WINDOW,
261 HW_VAR_AMPDU_MIN_SPACE,
262 HW_VAR_SHORTGI_DENSITY,
264 HW_VAR_MCS_RATE_AVAILABLE,
267 HW_VAR_DIS_Req_Qsize,
268 HW_VAR_CCX_CHNL_LOAD,
269 HW_VAR_CCX_NOISE_HISTOGRAM,
276 HW_VAR_SET_DEV_POWER,
286 HW_VAR_USER_CONTROL_TURBO_MODE,
292 HW_VAR_AUTOLOAD_STATUS,
293 HW_VAR_RF_2R_DISABLE,
295 HW_VAR_H2C_FW_PWRMODE,
296 HW_VAR_H2C_FW_JOINBSSRPT,
297 HW_VAR_1X1_RECV_COMBINE,
298 HW_VAR_STOP_SEND_BEACON,
303 HW_VAR_H2C_FW_UPDATE_GTK,
306 HW_VAR_WF_IS_MAC_ADDR,
307 HW_VAR_H2C_FW_OFFLOAD,
310 HW_VAR_HANDLE_FW_C2H,
311 HW_VAR_DL_FW_RSVD_PAGE,
313 HW_VAR_HW_SEQ_ENABLE,
318 HW_VAR_SWITCH_EPHY_WoWLAN,
319 HW_VAR_INT_MIGRATION,
326 RT_OP_MODE_INFRASTRUCTURE,
333 (((priv->rtllib->current_network.mode == IEEE_A) \
334 || (priv->rtllib->current_network.mode == IEEE_N_24G) \
335 || (priv->rtllib->current_network.mode == IEEE_N_5G)) ? 16 : 10)
337 #define MGMT_QUEUE_NUM 5
339 #define IEEE_CMD_SET_WPA_PARAM 1
340 #define IEEE_CMD_SET_WPA_IE 2
341 #define IEEE_CMD_SET_ENCRYPTION 3
342 #define IEEE_CMD_MLME 4
344 #define IEEE_PARAM_WPA_ENABLED 1
345 #define IEEE_PARAM_TKIP_COUNTERMEASURES 2
346 #define IEEE_PARAM_DROP_UNENCRYPTED 3
347 #define IEEE_PARAM_PRIVACY_INVOKED 4
348 #define IEEE_PARAM_AUTH_ALGS 5
349 #define IEEE_PARAM_IEEE_802_1X 6
350 #define IEEE_PARAM_WPAX_SELECT 7
352 #define IEEE_MLME_STA_DEAUTH 1
353 #define IEEE_MLME_STA_DISASSOC 2
356 #define IEEE_CRYPT_ERR_UNKNOWN_ALG 2
357 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED 4
358 #define IEEE_CRYPT_ERR_KEY_SET_FAILED 5
359 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED 7
360 #define IEEE_CRYPT_ALG_NAME_LEN 16
362 #define MAX_IE_LEN 0xff
366 u8 sta_addr[ETH_ALEN];
382 u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
386 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
393 #define msleep_interruptible_rsl msleep_interruptible
395 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
398 * The figure in section 7.1.2 suggests a body size of up to 2312
399 * bytes is allowed, which is a bit confusing, I suspect this
400 * represents the 2304 bytes of real data, plus a possible 8 bytes of
401 * WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro)
403 #define RTLLIB_1ADDR_LEN 10
404 #define RTLLIB_2ADDR_LEN 16
405 #define RTLLIB_3ADDR_LEN 24
406 #define RTLLIB_4ADDR_LEN 30
407 #define RTLLIB_FCS_LEN 4
409 #define RTLLIB_SKBBUFFER_SIZE 2500
411 #define MIN_FRAG_THRESHOLD 256U
412 #define MAX_FRAG_THRESHOLD 2346U
414 /* Frame control field constants */
415 #define RTLLIB_FCTL_FTYPE 0x000c
416 #define RTLLIB_FCTL_STYPE 0x00f0
417 #define RTLLIB_FCTL_FRAMETYPE 0x00fc
418 #define RTLLIB_FCTL_TODS 0x0100
419 #define RTLLIB_FCTL_FROMDS 0x0200
420 #define RTLLIB_FCTL_DSTODS 0x0300
421 #define RTLLIB_FCTL_MOREFRAGS 0x0400
422 #define RTLLIB_FCTL_RETRY 0x0800
423 #define RTLLIB_FCTL_PM 0x1000
424 #define RTLLIB_FCTL_MOREDATA 0x2000
425 #define RTLLIB_FCTL_WEP 0x4000
426 #define RTLLIB_FCTL_ORDER 0x8000
428 #define RTLLIB_FTYPE_MGMT 0x0000
429 #define RTLLIB_FTYPE_CTL 0x0004
430 #define RTLLIB_FTYPE_DATA 0x0008
433 #define RTLLIB_STYPE_ASSOC_REQ 0x0000
434 #define RTLLIB_STYPE_ASSOC_RESP 0x0010
435 #define RTLLIB_STYPE_REASSOC_REQ 0x0020
436 #define RTLLIB_STYPE_REASSOC_RESP 0x0030
437 #define RTLLIB_STYPE_PROBE_REQ 0x0040
438 #define RTLLIB_STYPE_PROBE_RESP 0x0050
439 #define RTLLIB_STYPE_BEACON 0x0080
440 #define RTLLIB_STYPE_ATIM 0x0090
441 #define RTLLIB_STYPE_DISASSOC 0x00A0
442 #define RTLLIB_STYPE_AUTH 0x00B0
443 #define RTLLIB_STYPE_DEAUTH 0x00C0
444 #define RTLLIB_STYPE_MANAGE_ACT 0x00D0
447 #define RTLLIB_STYPE_PSPOLL 0x00A0
448 #define RTLLIB_STYPE_RTS 0x00B0
449 #define RTLLIB_STYPE_CTS 0x00C0
450 #define RTLLIB_STYPE_ACK 0x00D0
453 #define RTLLIB_STYPE_DATA 0x0000
454 #define RTLLIB_STYPE_DATA_CFACK 0x0010
455 #define RTLLIB_STYPE_DATA_CFPOLL 0x0020
456 #define RTLLIB_STYPE_DATA_CFACKPOLL 0x0030
457 #define RTLLIB_STYPE_NULLFUNC 0x0040
458 #define RTLLIB_STYPE_QOS_DATA 0x0080
459 #define RTLLIB_STYPE_QOS_NULL 0x00C0
461 #define RTLLIB_SCTL_FRAG 0x000F
462 #define RTLLIB_SCTL_SEQ 0xFFF0
465 #define RTLLIB_QCTL_TID 0x000F
467 #define FC_QOS_BIT BIT7
468 #define IsDataFrame(pdu) (((pdu[0] & 0x0C) == 0x08) ? true : false)
469 #define IsLegacyDataFrame(pdu) (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
470 #define IsQoSDataFrame(pframe) \
471 ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) == \
472 (RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA))
473 #define Frame_Order(pframe) (*(u16 *)pframe&RTLLIB_FCTL_ORDER)
474 #define SN_LESS(a, b) (((a-b)&0x800) != 0)
475 #define SN_EQUAL(a, b) (a == b)
476 #define MAX_DEV_ADDR_SIZE 8
492 enum init_gain_op_type {
499 LED_CTL_POWER_ON = 1,
504 LED_CTL_SITE_SURVEY = 6,
505 LED_CTL_POWER_OFF = 7,
506 LED_CTL_START_TO_LINK = 8,
509 enum rt_rf_type_def {
515 WIRELESS_MODE_UNKNOWN = 0x00,
516 WIRELESS_MODE_A = 0x01,
517 WIRELESS_MODE_B = 0x02,
518 WIRELESS_MODE_G = 0x04,
519 WIRELESS_MODE_AUTO = 0x08,
520 WIRELESS_MODE_N_24G = 0x10,
521 WIRELESS_MODE_N_5G = 0x20
525 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
526 #define ETH_P_IP 0x0800 /* Internet Protocol packet */
527 #define ETH_P_ARP 0x0806 /* Address Resolution packet */
528 #endif /* ETH_P_PAE */
530 #ifndef ETH_P_80211_RAW
531 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
534 /* IEEE 802.11 defines */
536 #define P80211_OUI_LEN 3
538 struct rtllib_snap_hdr {
540 u8 dsap; /* always 0xAA */
541 u8 ssap; /* always 0xAA */
542 u8 ctrl; /* always 0x03 */
543 u8 oui[P80211_OUI_LEN]; /* organizational universal id */
547 enum _REG_PREAMBLE_MODE {
553 #define SNAP_SIZE sizeof(struct rtllib_snap_hdr)
555 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTLLIB_FCTL_FTYPE)
556 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTLLIB_FCTL_STYPE)
557 #define WLAN_FC_MORE_DATA(fc) ((fc) & RTLLIB_FCTL_MOREDATA)
559 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & RTLLIB_FCTL_FRAMETYPE)
560 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTLLIB_SCTL_FRAG)
561 #define WLAN_GET_SEQ_SEQ(seq) (((seq) & RTLLIB_SCTL_SEQ) >> 4)
563 /* Authentication algorithms */
564 #define WLAN_AUTH_OPEN 0
565 #define WLAN_AUTH_SHARED_KEY 1
566 #define WLAN_AUTH_LEAP 128
568 #define WLAN_CAPABILITY_ESS (1<<0)
569 #define WLAN_CAPABILITY_IBSS (1<<1)
570 #define WLAN_CAPABILITY_PRIVACY (1<<4)
571 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
572 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
574 #define RTLLIB_STATMASK_SIGNAL (1<<0)
575 #define RTLLIB_STATMASK_RSSI (1<<1)
576 #define RTLLIB_STATMASK_NOISE (1<<2)
577 #define RTLLIB_STATMASK_WEMASK 0x7
579 #define RTLLIB_CCK_MODULATION (1<<0)
580 #define RTLLIB_OFDM_MODULATION (1<<1)
582 #define RTLLIB_24GHZ_BAND (1<<0)
583 #define RTLLIB_52GHZ_BAND (1<<1)
585 #define RTLLIB_CCK_RATE_LEN 4
586 #define RTLLIB_CCK_RATE_1MB 0x02
587 #define RTLLIB_CCK_RATE_2MB 0x04
588 #define RTLLIB_CCK_RATE_5MB 0x0B
589 #define RTLLIB_CCK_RATE_11MB 0x16
590 #define RTLLIB_OFDM_RATE_LEN 8
591 #define RTLLIB_OFDM_RATE_6MB 0x0C
592 #define RTLLIB_OFDM_RATE_9MB 0x12
593 #define RTLLIB_OFDM_RATE_12MB 0x18
594 #define RTLLIB_OFDM_RATE_18MB 0x24
595 #define RTLLIB_OFDM_RATE_24MB 0x30
596 #define RTLLIB_OFDM_RATE_36MB 0x48
597 #define RTLLIB_OFDM_RATE_48MB 0x60
598 #define RTLLIB_OFDM_RATE_54MB 0x6C
599 #define RTLLIB_BASIC_RATE_MASK 0x80
601 /* this is stolen and modified from the madwifi driver*/
602 #define RTLLIB_FC0_TYPE_MASK 0x0c
603 #define RTLLIB_FC0_TYPE_DATA 0x08
604 #define RTLLIB_FC0_SUBTYPE_MASK 0xB0
605 #define RTLLIB_FC0_SUBTYPE_QOS 0x80
607 #define RTLLIB_QOS_HAS_SEQ(fc) \
608 (((fc) & (RTLLIB_FC0_TYPE_MASK | RTLLIB_FC0_SUBTYPE_MASK)) == \
609 (RTLLIB_FC0_TYPE_DATA | RTLLIB_FC0_SUBTYPE_QOS))
611 /* this is stolen from ipw2200 driver */
612 #define IEEE_IBSS_MAC_HASH_SIZE 31
613 struct ieee_ibss_seq {
617 unsigned long packet_time[17];
618 struct list_head list;
621 /* NOTE: This data is for statistical purposes; not all hardware provides this
622 * information for frames received. Not setting these will not cause
623 * any adverse affects. */
624 struct rtllib_rx_stats {
629 u16 rate; /* in 100 kbps */
646 u16 bShortPreamble:1;
662 bool RxIs40MHzPacket;
664 u8 RxMIMOSignalStrength[4];
665 s8 RxMIMOSignalQuality[2];
666 bool bPacketMatchBSSID;
678 /* IEEE 802.11 requires that STA supports concurrent reception of at least
679 * three fragmented frames. This define can be increased to support more
680 * concurrent frames, but it should be noted that each entry can consume about
681 * 2 kB of RAM and increasing cache size will slow down frame reassembly.
683 #define RTLLIB_FRAG_CACHE_LEN 4
685 struct rtllib_frag_entry {
686 unsigned long first_frag_time;
688 unsigned int last_frag;
690 u8 src_addr[ETH_ALEN];
691 u8 dst_addr[ETH_ALEN];
694 struct rtllib_device;
696 #define SEC_ACTIVE_KEY (1<<4)
697 #define SEC_AUTH_MODE (1<<5)
698 #define SEC_UNICAST_GROUP (1<<6)
699 #define SEC_LEVEL (1<<7)
700 #define SEC_ENABLED (1<<8)
702 #define SEC_LEVEL_0 0 /* None */
703 #define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */
704 #define SEC_LEVEL_2 2 /* Level 1 + TKIP */
705 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
706 #define SEC_LEVEL_3 4 /* Level 2 + CCMP */
708 #define SEC_ALG_NONE 0
709 #define SEC_ALG_WEP 1
710 #define SEC_ALG_TKIP 2
711 #define SEC_ALG_CCMP 4
713 #define WEP_KEY_LEN 13
714 #define SCM_KEY_LEN 32
716 struct rtllib_security {
721 unicast_uses_group:1,
723 u8 key_sizes[NUM_WEP_KEYS];
724 u8 keys[NUM_WEP_KEYS][SCM_KEY_LEN];
730 /* 802.11 data frame from AP
731 * ,-------------------------------------------------------------------.
732 * Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
733 * |------|------|---------|---------|---------|------|---------|------|
734 * Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs |
735 * | | tion | (BSSID) | | | ence | data | |
736 * `-------------------------------------------------------------------'
737 * Total: 28-2340 bytes
740 /* Management Frame Information Element Types */
744 MFIE_TYPE_FH_SET = 2,
745 MFIE_TYPE_DS_SET = 3,
746 MFIE_TYPE_CF_SET = 4,
748 MFIE_TYPE_IBSS_SET = 6,
749 MFIE_TYPE_COUNTRY = 7,
750 MFIE_TYPE_HOP_PARAMS = 8,
751 MFIE_TYPE_HOP_TABLE = 9,
752 MFIE_TYPE_REQUEST = 10,
753 MFIE_TYPE_CHALLENGE = 16,
754 MFIE_TYPE_POWER_CONSTRAINT = 32,
755 MFIE_TYPE_POWER_CAPABILITY = 33,
756 MFIE_TYPE_TPC_REQUEST = 34,
757 MFIE_TYPE_TPC_REPORT = 35,
758 MFIE_TYPE_SUPP_CHANNELS = 36,
760 MFIE_TYPE_MEASURE_REQUEST = 38,
761 MFIE_TYPE_MEASURE_REPORT = 39,
762 MFIE_TYPE_QUIET = 40,
763 MFIE_TYPE_IBSS_DFS = 41,
765 MFIE_TYPE_HT_CAP = 45,
767 MFIE_TYPE_RATES_EX = 50,
768 MFIE_TYPE_HT_INFO = 61,
769 MFIE_TYPE_AIRONET = 133,
770 MFIE_TYPE_GENERIC = 221,
771 MFIE_TYPE_QOS_PARAMETER = 222,
774 /* Minimal header; can be used for passing 802.11 frames with sufficient
775 * information to determine what type of underlying data type is actually
776 * stored in the data.
778 struct rtllib_pspoll_hdr {
791 struct rtllib_hdr_1addr {
798 struct rtllib_hdr_2addr {
806 struct rtllib_hdr_3addr {
816 struct rtllib_hdr_4addr {
827 struct rtllib_hdr_3addrqos {
838 struct rtllib_hdr_4addrqos {
850 struct rtllib_info_element {
856 struct rtllib_authentication {
857 struct rtllib_hdr_3addr header;
862 struct rtllib_info_element info_element[0];
865 struct rtllib_disauth {
866 struct rtllib_hdr_3addr header;
870 struct rtllib_disassoc {
871 struct rtllib_hdr_3addr header;
875 struct rtllib_probe_request {
876 struct rtllib_hdr_3addr header;
877 /* SSID, supported rates */
878 struct rtllib_info_element info_element[0];
881 struct rtllib_probe_response {
882 struct rtllib_hdr_3addr header;
884 __le16 beacon_interval;
886 /* SSID, supported rates, FH params, DS params,
887 * CF params, IBSS params, TIM (if beacon), RSN
889 struct rtllib_info_element info_element[0];
892 /* Alias beacon for probe_response */
893 #define rtllib_beacon rtllib_probe_response
895 struct rtllib_assoc_request_frame {
896 struct rtllib_hdr_3addr header;
898 __le16 listen_interval;
899 /* SSID, supported rates, RSN */
900 struct rtllib_info_element info_element[0];
903 struct rtllib_assoc_response_frame {
904 struct rtllib_hdr_3addr header;
908 struct rtllib_info_element info_element[0]; /* supported rates */
919 struct sk_buff *fragments[0];
922 #define MAX_SUBFRAME_COUNT 64
925 struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
942 /* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs
943 * only use 8, and then use extended rates for the remaining supported
944 * rates. Other APs, however, stick all of their supported rates on the
945 * main rates information element...
947 #define MAX_RATES_LENGTH ((u8)12)
948 #define MAX_RATES_EX_LENGTH ((u8)16)
949 #define MAX_NETWORK_COUNT 96
951 #define MAX_CHANNEL_NUMBER 161
952 #define RTLLIB_SOFTMAC_SCAN_TIME 100
953 #define RTLLIB_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
955 #define MAX_WPA_IE_LEN 64
956 #define MAX_WZC_IE_LEN 256
958 #define NETWORK_EMPTY_ESSID (1<<0)
959 #define NETWORK_HAS_OFDM (1<<1)
960 #define NETWORK_HAS_CCK (1<<2)
963 #define NETWORK_HAS_QOS_PARAMETERS (1<<3)
964 #define NETWORK_HAS_QOS_INFORMATION (1<<4)
965 #define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | \
966 NETWORK_HAS_QOS_INFORMATION)
968 #define NETWORK_HAS_ERP_VALUE (1<<10)
970 #define QOS_QUEUE_NUM 4
971 #define QOS_OUI_LEN 3
972 #define QOS_OUI_TYPE 2
973 #define QOS_ELEMENT_ID 221
974 #define QOS_OUI_INFO_SUB_TYPE 0
975 #define QOS_OUI_PARAM_SUB_TYPE 1
976 #define QOS_VERSION_1 1
978 struct rtllib_qos_information_element {
988 struct rtllib_qos_ac_parameter {
994 struct rtllib_qos_parameter_info {
995 struct rtllib_qos_information_element info_element;
997 struct rtllib_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
1000 struct rtllib_qos_parameters {
1001 __le16 cw_min[QOS_QUEUE_NUM];
1002 __le16 cw_max[QOS_QUEUE_NUM];
1003 u8 aifs[QOS_QUEUE_NUM];
1004 u8 flag[QOS_QUEUE_NUM];
1005 __le16 tx_op_limit[QOS_QUEUE_NUM];
1008 struct rtllib_qos_data {
1009 struct rtllib_qos_parameters parameters;
1010 unsigned int wmm_acm;
1017 struct rtllib_tim_parameters {
1022 struct rtllib_wmm_ac_param {
1023 u8 ac_aci_acm_aifsn;
1024 u8 ac_ecwmin_ecwmax;
1033 EAPOL_ENCAP_ASF_ALERT
1036 static const char * const eap_types[] = {
1037 [EAP_PACKET] = "EAP-Packet",
1038 [EAPOL_START] = "EAPOL-Start",
1039 [EAPOL_LOGOFF] = "EAPOL-Logoff",
1040 [EAPOL_KEY] = "EAPOL-Key",
1041 [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
1044 static inline const char *eap_get_type(int type)
1046 return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" :
1049 static inline u8 Frame_QoSTID(u8 *buf)
1051 struct rtllib_hdr_3addr *hdr;
1054 hdr = (struct rtllib_hdr_3addr *)buf;
1055 fc = le16_to_cpu(hdr->frame_ctl);
1056 return (u8)((union frameqos *)(buf + (((fc & RTLLIB_FCTL_TODS) &&
1057 (fc & RTLLIB_FCTL_FROMDS)) ? 30 : 24)))->field.tid;
1069 struct rtllib_softmac_stats {
1070 unsigned int rx_ass_ok;
1071 unsigned int rx_ass_err;
1072 unsigned int rx_probe_rq;
1073 unsigned int tx_probe_rs;
1074 unsigned int tx_beacons;
1075 unsigned int rx_auth_rq;
1076 unsigned int rx_auth_rs_ok;
1077 unsigned int rx_auth_rs_err;
1078 unsigned int tx_auth_rq;
1079 unsigned int no_auth_rs;
1080 unsigned int no_ass_rs;
1081 unsigned int tx_ass_rq;
1082 unsigned int rx_ass_rq;
1083 unsigned int tx_probe_rq;
1084 unsigned int reassoc;
1085 unsigned int swtxstop;
1086 unsigned int swtxawake;
1087 unsigned char CurrentShowTxate;
1088 unsigned char last_packet_rate;
1089 unsigned int txretrycount;
1092 /* These are the data types that can make up management packets
1094 * u16 auth_algorithm;
1095 * u16 auth_sequence;
1096 * u16 beacon_interval;
1098 * u8 current_ap[ETH_ALEN];
1099 * u16 listen_interval;
1101 * u16 association_id:14, reserved:2;
1103 * u32 time_stamp[2];
1108 #define RTLLIB_DEFAULT_TX_ESSID "Penguin"
1109 #define RTLLIB_DEFAULT_BASIC_RATE 2
1111 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1112 #define MAX_SP_Len (WMM_all_frame << 4)
1113 #define RTLLIB_QOS_TID 0x0f
1114 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
1116 #define RTLLIB_DTIM_MBCAST 4
1117 #define RTLLIB_DTIM_UCAST 2
1118 #define RTLLIB_DTIM_VALID 1
1119 #define RTLLIB_DTIM_INVALID 0
1121 #define RTLLIB_PS_DISABLED 0
1122 #define RTLLIB_PS_UNICAST RTLLIB_DTIM_UCAST
1123 #define RTLLIB_PS_MBCAST RTLLIB_DTIM_MBCAST
1125 #define WME_AC_BK 0x00
1126 #define WME_AC_BE 0x01
1127 #define WME_AC_VI 0x02
1128 #define WME_AC_VO 0x03
1129 #define WME_AC_PRAM_LEN 16
1131 #define MAX_RECEIVE_BUFFER_SIZE 9100
1133 #define UP2AC(up) ( \
1134 ((up) < 1) ? WME_AC_BE : \
1135 ((up) < 3) ? WME_AC_BK : \
1136 ((up) < 4) ? WME_AC_BE : \
1137 ((up) < 6) ? WME_AC_VI : \
1140 #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
1141 #define ETHERNET_HEADER_SIZE 14 /* length of two Ethernet address
1145 ERP_NonERPpresent = 0x01,
1146 ERP_UseProtection = 0x02,
1147 ERP_BarkerPreambleMode = 0x04,
1150 struct rtllib_network {
1151 /* These entries are used to identify a unique network */
1154 /* Ensure null-terminated for any debug msgs */
1155 u8 ssid[IW_ESSID_MAX_SIZE + 1];
1157 u8 hidden_ssid[IW_ESSID_MAX_SIZE + 1];
1159 struct rtllib_qos_data qos_data;
1161 bool bWithAironetIE;
1162 bool bCkipSupported;
1167 u8 MBssid[ETH_ALEN];
1168 bool bWithCcxVerNum;
1170 /* These are network statistics */
1171 struct rtllib_rx_stats stats;
1173 u8 rates[MAX_RATES_LENGTH];
1175 u8 rates_ex[MAX_RATES_EX_LENGTH];
1177 unsigned long last_scanned;
1181 u16 beacon_interval;
1182 u16 listen_interval;
1185 u8 wpa_ie[MAX_WPA_IE_LEN];
1187 u8 rsn_ie[MAX_WPA_IE_LEN];
1189 u8 wzc_ie[MAX_WZC_IE_LEN];
1192 struct rtllib_tim_parameters tim;
1195 u64 last_dtim_sta_time;
1198 struct rtllib_wmm_ac_param wmm_param[4];
1201 u8 CountryIeBuf[MAX_IE_LEN];
1202 struct bss_ht bssht;
1203 bool broadcom_cap_exist;
1204 bool realtek_cap_exit;
1205 bool marvell_cap_exist;
1206 bool ralink_cap_exist;
1207 bool atheros_cap_exist;
1208 bool cisco_cap_exist;
1209 bool airgo_cap_exist;
1210 bool unknown_cap_exist;
1211 bool berp_info_valid;
1212 bool buseprotection;
1215 struct list_head list;
1220 /* the card is not linked at all */
1223 /* RTLLIB_ASSOCIATING* are for BSS client mode
1224 * the driver shall not perform RX filtering unless
1225 * the state is LINKED.
1226 * The driver shall just check for the state LINKED and
1227 * defaults to NOLINK for ALL the other states (including
1231 /* the association procedure will start (wq scheduling)*/
1233 RTLLIB_ASSOCIATING_RETRY,
1235 /* the association procedure is sending AUTH request*/
1236 RTLLIB_ASSOCIATING_AUTHENTICATING,
1238 /* the association procedure has successfully authenticated
1239 * and is sending association request
1241 RTLLIB_ASSOCIATING_AUTHENTICATED,
1243 /* the link is ok. the card associated to a BSS or linked
1244 * to a ibss cell or acting as an AP and creating the bss
1248 /* same as LINKED, but the driver shall apply RX filter
1249 * rules as we are in NO_LINK mode. As the card is still
1250 * logically linked, but it is doing a syncro site survey
1251 * then it will be back to LINKED state.
1253 RTLLIB_LINKED_SCANNING,
1256 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1257 #define DEFAULT_FTS 2346
1259 #define CFG_RTLLIB_RESERVE_FCS (1<<0)
1260 #define CFG_RTLLIB_COMPUTE_FCS (1<<1)
1264 struct rtllib_txb *txb;
1267 struct bandwidth_autoswitch {
1268 long threshold_20Mhzto40Mhz;
1269 long threshold_40Mhzto20Mhz;
1270 bool bforced_tx20Mhz;
1271 bool bautoswitch_enable;
1276 #define REORDER_WIN_SIZE 128
1277 #define REORDER_ENTRY_NUM 128
1278 struct rx_reorder_entry {
1279 struct list_head List;
1281 struct rtllib_rxb *prxb;
1296 enum ips_callback_function {
1297 IPS_CALLBACK_NONE = 0,
1298 IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1299 IPS_CALLBACK_JOIN_REQUEST = 2,
1302 enum rt_rf_power_state {
1308 struct rt_pwr_save_ctrl {
1311 bool bIPSModeBackup;
1312 bool bSwRfProcessing;
1313 enum rt_rf_power_state eInactivePowerState;
1314 enum ips_callback_function ReturnPoint;
1318 u8 RegMaxLPSAwakeIntvl;
1328 #define RT_RF_CHANGE_SOURCE u32
1330 #define RF_CHANGE_BY_SW BIT31
1331 #define RF_CHANGE_BY_HW BIT30
1332 #define RF_CHANGE_BY_PS BIT29
1333 #define RF_CHANGE_BY_IPS BIT28
1334 #define RF_CHANGE_BY_INIT 0
1336 enum country_code_type {
1337 COUNTRY_CODE_FCC = 0,
1338 COUNTRY_CODE_IC = 1,
1339 COUNTRY_CODE_ETSI = 2,
1340 COUNTRY_CODE_SPAIN = 3,
1341 COUNTRY_CODE_FRANCE = 4,
1342 COUNTRY_CODE_MKK = 5,
1343 COUNTRY_CODE_MKK1 = 6,
1344 COUNTRY_CODE_ISRAEL = 7,
1345 COUNTRY_CODE_TELEC = 8,
1346 COUNTRY_CODE_MIC = 9,
1347 COUNTRY_CODE_GLOBAL_DOMAIN = 10,
1348 COUNTRY_CODE_WORLD_WIDE_13 = 11,
1349 COUNTRY_CODE_TELEC_NETGEAR = 12,
1353 enum scan_op_backup_opt {
1354 SCAN_OPT_BACKUP = 0,
1359 enum fw_cmd_io_type {
1360 FW_CMD_DIG_ENABLE = 0,
1361 FW_CMD_DIG_DISABLE = 1,
1362 FW_CMD_DIG_HALT = 2,
1363 FW_CMD_DIG_RESUME = 3,
1364 FW_CMD_HIGH_PWR_ENABLE = 4,
1365 FW_CMD_HIGH_PWR_DISABLE = 5,
1366 FW_CMD_RA_RESET = 6,
1367 FW_CMD_RA_ACTIVE = 7,
1368 FW_CMD_RA_REFRESH_N = 8,
1369 FW_CMD_RA_REFRESH_BG = 9,
1370 FW_CMD_RA_INIT = 10,
1371 FW_CMD_IQK_ENABLE = 11,
1372 FW_CMD_TXPWR_TRACK_ENABLE = 12,
1373 FW_CMD_TXPWR_TRACK_DISABLE = 13,
1374 FW_CMD_TXPWR_TRACK_THERMAL = 14,
1375 FW_CMD_PAUSE_DM_BY_SCAN = 15,
1376 FW_CMD_RESUME_DM_BY_SCAN = 16,
1377 FW_CMD_RA_REFRESH_N_COMB = 17,
1378 FW_CMD_RA_REFRESH_BG_COMB = 18,
1379 FW_CMD_ANTENNA_SW_ENABLE = 19,
1380 FW_CMD_ANTENNA_SW_DISABLE = 20,
1381 FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21,
1382 FW_CMD_LPS_ENTER = 22,
1383 FW_CMD_LPS_LEAVE = 23,
1386 #define RT_MAX_LD_SLOT_NUM 10
1387 struct rt_link_detect {
1389 u32 NumRecvBcnInPeriod;
1390 u32 NumRecvDataInPeriod;
1392 u32 RxBcnNum[RT_MAX_LD_SLOT_NUM];
1393 u32 RxDataNum[RT_MAX_LD_SLOT_NUM];
1397 u32 NumTxOkInPeriod;
1398 u32 NumRxOkInPeriod;
1399 u32 NumRxUnicastOkInPeriod;
1401 bool bHigherBusyTraffic;
1402 bool bHigherBusyRxTraffic;
1405 struct sw_cam_table {
1407 u8 macaddr[ETH_ALEN];
1415 #define TOTAL_CAM_ENTRY 32
1416 struct rate_adaptive {
1417 u8 rate_adaptive_disabled;
1421 u32 high_rssi_thresh_for_ra;
1422 u32 high2low_rssi_thresh_for_ra;
1423 u8 low2high_rssi_thresh_for_ra40M;
1424 u32 low_rssi_thresh_for_ra40M;
1425 u8 low2high_rssi_thresh_for_ra20M;
1426 u32 low_rssi_thresh_for_ra20M;
1427 u32 upper_rssi_threshold_ratr;
1428 u32 middle_rssi_threshold_ratr;
1429 u32 low_rssi_threshold_ratr;
1430 u32 low_rssi_threshold_ratr_40M;
1431 u32 low_rssi_threshold_ratr_20M;
1432 u8 ping_rssi_enable;
1434 u32 ping_rssi_thresh_for_ra;
1440 #define NUM_PMKID_CACHE 16
1441 struct rt_pmkid_list {
1448 struct rt_intel_promisc_mode {
1449 bool bPromiscuousOn;
1450 bool bFilterSourceStationFrame;
1454 /*************** DRIVER STATUS *****/
1455 #define STATUS_SCANNING 0
1456 /*************** DRIVER STATUS *****/
1461 LPS_WAIT_NULL_DATA_SEND = 2,
1464 struct rtllib_device {
1465 struct pci_dev *pdev;
1466 struct net_device *dev;
1467 struct rtllib_security sec;
1469 bool disable_mgnt_queue;
1471 unsigned long status;
1474 enum rt_op_mode OpMode;
1476 /* The last AssocReq/Resp IEs */
1477 u8 *assocreq_ies, *assocresp_ies;
1478 size_t assocreq_ies_len, assocresp_ies_len;
1484 bool is_silent_reset;
1488 bool bSupportRemoteWakeUp;
1490 bool FirstIe_InScan;
1491 bool be_scan_inprogress;
1493 enum rt_rf_power_state eRFPowerState;
1494 RT_RF_CHANGE_SOURCE RfOffReason;
1497 struct rt_hi_throughput *pHTInfo;
1499 spinlock_t reorder_spinlock;
1500 u8 Regdot11HTOperationalRateSet[16];
1501 u8 Regdot11TxHTOperationalRateSet[16];
1502 u8 dot11HTOperationalRateSet[16];
1503 u8 RegHTSuppRateSet[16];
1504 u8 HTCurrentOperaRate;
1505 u8 HTHighestOperaRate;
1506 u8 bTxDisableRateFallBack;
1507 u8 bTxUseDriverAssingedRate;
1508 u8 bTxEnableFwCalcDur;
1511 struct list_head Tx_TS_Admit_List;
1512 struct list_head Tx_TS_Pending_List;
1513 struct list_head Tx_TS_Unused_List;
1514 struct tx_ts_record TxTsRecord[TOTAL_TS_NUM];
1515 struct list_head Rx_TS_Admit_List;
1516 struct list_head Rx_TS_Pending_List;
1517 struct list_head Rx_TS_Unused_List;
1518 struct rx_ts_record RxTsRecord[TOTAL_TS_NUM];
1519 struct rx_reorder_entry RxReorderEntry[128];
1520 struct list_head RxReorder_Unused_List;
1523 /* Bookkeeping structures */
1524 struct net_device_stats stats;
1525 struct rtllib_softmac_stats softmac_stats;
1527 /* Probe / Beacon management */
1528 struct list_head network_free_list;
1529 struct list_head network_list;
1530 struct rtllib_network *networks;
1534 int iw_mode; /* operating mode (IW_MODE_*) */
1535 bool bNetPromiscuousMode;
1536 struct rt_intel_promisc_mode IntelPromiscuousModeInfo;
1539 spinlock_t wpax_suitlist_lock;
1541 int tx_headroom; /* Set to size of any additional room needed at front
1542 * of allocated Tx SKBs
1546 /* WEP and other encryption related settings at the device level */
1547 int open_wep; /* Set to 1 to allow unencrypted frames */
1549 int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1553 /* If the host performs {en,de}cryption, then set to 1 */
1557 int ieee802_1x; /* is IEEE 802.1X used */
1560 bool bHalfWirelessN24GMode;
1562 int drop_unencrypted;
1563 int tkip_countermeasures;
1564 int privacy_invoked;
1569 u8 ap_mac_addr[ETH_ALEN];
1570 u16 pairwise_key_type;
1573 struct lib80211_crypt_info crypt_info;
1575 struct sw_cam_table swcamtable[TOTAL_CAM_ENTRY];
1577 struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
1579 /* Fragmentation structures */
1580 struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN];
1581 unsigned int frag_next_idx[17];
1582 u16 fts; /* Fragmentation Threshold */
1583 #define DEFAULT_RTS_THRESHOLD 2346U
1584 #define MIN_RTS_THRESHOLD 1
1585 #define MAX_RTS_THRESHOLD 2346U
1586 u16 rts; /* RTS threshold */
1588 /* Association info */
1591 /* This stores infos for the current network.
1592 * Either the network we are associated in INFRASTRUCTURE
1593 * or the network that we are creating in MASTER mode.
1594 * ad-hoc is a mixture ;-).
1595 * Note that in infrastructure mode, even when not associated,
1596 * fields bssid and essid may be valid (if wpa_set and essid_set
1597 * are true) as thy carry the value set by the user via iwconfig
1599 struct rtllib_network current_network;
1601 enum rtllib_state state;
1604 int mode; /* A, B, G */
1605 int modulation; /* CCK, OFDM */
1607 /* used for forcing the ibss workqueue to terminate
1608 * without wait for the syncro scan to terminate
1610 short sync_scan_hurryup;
1613 /* map of allowed channels. 0 is dummy */
1616 u8 active_channel_map[MAX_CHANNEL_NUMBER+1];
1619 u8 ibss_maxjoin_chal;
1621 int rate; /* current rate */
1626 /* this contains flags for selectively enable softmac support */
1627 u16 softmac_features;
1629 /* if the sequence control field is not filled by HW */
1632 /* association procedure transaction sequence number */
1635 /* AID for RTXed association responses */
1638 /* power save mode related*/
1644 struct tasklet_struct ps_task;
1649 /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1651 short scanning_continue;
1652 short proto_started;
1653 short proto_stoppping;
1655 struct mutex wx_mutex;
1656 struct mutex scan_mutex;
1657 struct semaphore ips_sem;
1659 spinlock_t mgmt_tx_lock;
1660 spinlock_t beacon_lock;
1667 /* set on initialization */
1668 unsigned int wmm_acm;
1670 /* for discarding duplicated packets in IBSS */
1671 struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
1673 /* for discarding duplicated packets in BSS */
1674 u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1675 u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1676 unsigned long last_packet_time[17];
1679 unsigned long last_rx_ps_time;
1683 /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1684 struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1685 int mgmt_queue_head;
1686 int mgmt_queue_tail;
1688 struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
1689 struct sk_buff_head skb_aggQ[MAX_QUEUE_SIZE];
1691 bool bdynamic_txpower_enable;
1693 bool bCTSToSelfEnable;
1695 u32 fsync_time_interval;
1696 u32 fsync_rate_bitmap;
1697 u8 fsync_rssi_threshold;
1700 u8 fsync_multiple_timeinterval;
1701 u32 fsync_firstdiff_ratethreshold;
1702 u32 fsync_seconddiff_ratethreshold;
1703 enum fsync_state fsync_state;
1704 bool bis_any_nonbepkts;
1705 struct bandwidth_autoswitch bandwidth_auto_switch;
1708 struct rt_link_detect LinkDetectInfo;
1709 bool bIsAggregateFrame;
1710 struct rt_pwr_save_ctrl PowerSaveControl;
1712 /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1713 struct tx_pending tx_pending;
1715 /* used if IEEE_SOFTMAC_ASSOCIATE is set */
1716 struct timer_list associate_timer;
1718 /* used if IEEE_SOFTMAC_BEACONS is set */
1719 struct timer_list beacon_timer;
1721 struct work_struct associate_complete_wq;
1722 struct work_struct ips_leave_wq;
1723 struct delayed_work associate_procedure_wq;
1724 struct delayed_work softmac_scan_wq;
1725 struct delayed_work associate_retry_wq;
1726 struct delayed_work start_ibss_wq;
1727 struct delayed_work hw_wakeup_wq;
1728 struct delayed_work hw_sleep_wq;
1729 struct delayed_work link_change_wq;
1730 struct work_struct wx_sync_scan_wq;
1733 struct rtllib_rxb *RfdArray[REORDER_WIN_SIZE];
1734 struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
1735 struct rtllib_rxb *prxbIndicateArray[REORDER_WIN_SIZE];
1737 struct sw_chnl_cmd PreCommonCmd[MAX_PRECMD_CNT];
1738 struct sw_chnl_cmd PostCommonCmd[MAX_POSTCMD_CNT];
1739 struct sw_chnl_cmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
1743 /* Callback functions */
1744 void (*set_security)(struct net_device *dev,
1745 struct rtllib_security *sec);
1747 /* Used to TX data frame by using txb structs.
1748 * this is not used if in the softmac_features
1749 * is set the flag IEEE_SOFTMAC_TX_QUEUE
1751 int (*hard_start_xmit)(struct rtllib_txb *txb,
1752 struct net_device *dev);
1754 int (*reset_port)(struct net_device *dev);
1756 /* Softmac-generated frames (management) are TXed via this
1757 * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1758 * not set. As some cards may have different HW queues that
1759 * one might want to use for data and management frames
1760 * the option to have two callbacks might be useful.
1761 * This function can't sleep.
1763 int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1764 struct net_device *dev);
1766 /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1767 * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1768 * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1769 * then also management frames are sent via this callback.
1770 * This function can't sleep.
1772 void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1773 struct net_device *dev, int rate);
1775 /* stops the HW queue for DATA frames. Useful to avoid
1776 * waste time to TX data frame when we are reassociating
1777 * This function can sleep.
1779 void (*data_hard_stop)(struct net_device *dev);
1781 /* OK this is complementing to data_poll_hard_stop */
1782 void (*data_hard_resume)(struct net_device *dev);
1784 /* ask to the driver to retune the radio.
1785 * This function can sleep. the driver should ensure
1786 * the radio has been switched before return.
1788 void (*set_chan)(struct net_device *dev, short ch);
1790 void (*rtllib_start_hw_scan)(struct net_device *dev);
1791 void (*rtllib_stop_hw_scan)(struct net_device *dev);
1793 /* indicate the driver that the link state is changed
1794 * for example it may indicate the card is associated now.
1795 * Driver might be interested in this to apply RX filter
1796 * rules or simply light the LINK led
1798 void (*link_change)(struct net_device *dev);
1800 /* these two function indicates to the HW when to start
1801 * and stop to send beacons. This is used when the
1802 * IEEE_SOFTMAC_BEACONS is not set. For now the
1803 * stop_send_bacons is NOT guaranteed to be called only
1804 * after start_send_beacons.
1806 void (*start_send_beacons)(struct net_device *dev);
1807 void (*stop_send_beacons)(struct net_device *dev);
1809 /* power save mode related */
1810 void (*sta_wake_up)(struct net_device *dev);
1811 void (*enter_sleep_state)(struct net_device *dev, u64 time);
1812 short (*ps_is_queue_empty)(struct net_device *dev);
1813 int (*handle_beacon)(struct net_device *dev,
1814 struct rtllib_beacon *beacon,
1815 struct rtllib_network *network);
1816 int (*handle_assoc_response)(struct net_device *dev,
1817 struct rtllib_assoc_response_frame *resp,
1818 struct rtllib_network *network);
1821 /* check whether Tx hw resource available */
1822 short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
1823 void (*SetBWModeHandler)(struct net_device *dev,
1824 enum ht_channel_width Bandwidth,
1825 enum ht_extchnl_offset Offset);
1826 bool (*GetNmodeSupportBySecCfg)(struct net_device *dev);
1827 void (*SetWirelessMode)(struct net_device *dev, u8 wireless_mode);
1828 bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device *dev);
1829 u8 (*rtllib_ap_sec_type)(struct rtllib_device *ieee);
1830 void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
1831 bool (*SetFwCmdHandler)(struct net_device *dev,
1832 enum fw_cmd_io_type FwCmdIO);
1833 void (*UpdateBeaconInterruptHandler)(struct net_device *dev,
1835 void (*ScanOperationBackupHandler)(struct net_device *dev,
1837 void (*LedControlHandler)(struct net_device *dev,
1838 enum led_ctl_mode LedAction);
1839 void (*SetHwRegHandler)(struct net_device *dev, u8 variable, u8 *val);
1841 void (*AllowAllDestAddrHandler)(struct net_device *dev,
1842 bool bAllowAllDA, bool WriteIntoReg);
1844 void (*rtllib_ips_leave_wq)(struct net_device *dev);
1845 void (*rtllib_ips_leave)(struct net_device *dev);
1846 void (*LeisurePSLeave)(struct net_device *dev);
1848 /* This must be the last item so that it points to the data
1849 * allocated beyond this structure by alloc_rtllib
1854 #define IEEE_A (1<<0)
1855 #define IEEE_B (1<<1)
1856 #define IEEE_G (1<<2)
1857 #define IEEE_N_24G (1<<4)
1858 #define IEEE_N_5G (1<<5)
1859 #define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G)
1861 /* Generate a 802.11 header */
1863 /* Uses the channel change callback directly
1864 * instead of [start/stop] scan callbacks
1866 #define IEEE_SOFTMAC_SCAN (1<<2)
1868 /* Perform authentication and association handshake */
1869 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
1871 /* Generate probe requests */
1872 #define IEEE_SOFTMAC_PROBERQ (1<<4)
1874 /* Generate response to probe requests */
1875 #define IEEE_SOFTMAC_PROBERS (1<<5)
1877 /* The ieee802.11 stack will manage the netif queue
1878 * wake/stop for the driver, taking care of 802.11
1879 * fragmentation. See softmac.c for details.
1881 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
1883 /* Uses only the softmac_data_hard_start_xmit
1884 * even for TX management frames.
1886 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
1888 /* Generate beacons. The stack will enqueue beacons
1891 #define IEEE_SOFTMAC_BEACONS (1<<6)
1894 static inline void *rtllib_priv(struct net_device *dev)
1896 return ((struct rtllib_device *)netdev_priv(dev))->priv;
1899 static inline int rtllib_is_empty_essid(const char *essid, int essid_len)
1901 /* Single white space is for Linksys APs */
1902 if (essid_len == 1 && essid[0] == ' ')
1905 /* Otherwise, if the entire essid is 0, we assume it is hidden */
1908 if (essid[essid_len] != '\0')
1915 static inline int rtllib_get_hdrlen(u16 fc)
1917 int hdrlen = RTLLIB_3ADDR_LEN;
1919 switch (WLAN_FC_GET_TYPE(fc)) {
1920 case RTLLIB_FTYPE_DATA:
1921 if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS))
1922 hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */
1923 if (RTLLIB_QOS_HAS_SEQ(fc))
1924 hdrlen += 2; /* QOS ctrl*/
1926 case RTLLIB_FTYPE_CTL:
1927 switch (WLAN_FC_GET_STYPE(fc)) {
1928 case RTLLIB_STYPE_CTS:
1929 case RTLLIB_STYPE_ACK:
1930 hdrlen = RTLLIB_1ADDR_LEN;
1933 hdrlen = RTLLIB_2ADDR_LEN;
1942 static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr)
1944 switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
1945 case RTLLIB_1ADDR_LEN:
1946 return ((struct rtllib_hdr_1addr *)hdr)->payload;
1947 case RTLLIB_2ADDR_LEN:
1948 return ((struct rtllib_hdr_2addr *)hdr)->payload;
1949 case RTLLIB_3ADDR_LEN:
1950 return ((struct rtllib_hdr_3addr *)hdr)->payload;
1951 case RTLLIB_4ADDR_LEN:
1952 return ((struct rtllib_hdr_4addr *)hdr)->payload;
1957 static inline int rtllib_is_ofdm_rate(u8 rate)
1959 switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
1960 case RTLLIB_OFDM_RATE_6MB:
1961 case RTLLIB_OFDM_RATE_9MB:
1962 case RTLLIB_OFDM_RATE_12MB:
1963 case RTLLIB_OFDM_RATE_18MB:
1964 case RTLLIB_OFDM_RATE_24MB:
1965 case RTLLIB_OFDM_RATE_36MB:
1966 case RTLLIB_OFDM_RATE_48MB:
1967 case RTLLIB_OFDM_RATE_54MB:
1973 static inline int rtllib_is_cck_rate(u8 rate)
1975 switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
1976 case RTLLIB_CCK_RATE_1MB:
1977 case RTLLIB_CCK_RATE_2MB:
1978 case RTLLIB_CCK_RATE_5MB:
1979 case RTLLIB_CCK_RATE_11MB:
1987 void free_rtllib(struct net_device *dev);
1988 struct net_device *alloc_rtllib(int sizeof_priv);
1992 int rtllib_encrypt_fragment(
1993 struct rtllib_device *ieee,
1994 struct sk_buff *frag,
1997 int rtllib_xmit(struct sk_buff *skb, struct net_device *dev);
1998 void rtllib_txb_free(struct rtllib_txb *);
2001 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
2002 struct rtllib_rx_stats *rx_stats);
2003 void rtllib_rx_probe_rq(struct rtllib_device *ieee,
2004 struct sk_buff *skb);
2005 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel);
2008 int rtllib_wx_get_scan(struct rtllib_device *ieee,
2009 struct iw_request_info *info,
2010 union iwreq_data *wrqu, char *key);
2011 int rtllib_wx_set_encode(struct rtllib_device *ieee,
2012 struct iw_request_info *info,
2013 union iwreq_data *wrqu, char *key);
2014 int rtllib_wx_get_encode(struct rtllib_device *ieee,
2015 struct iw_request_info *info,
2016 union iwreq_data *wrqu, char *key);
2017 int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
2018 struct iw_request_info *info,
2019 union iwreq_data *wrqu, char *extra);
2020 int rtllib_wx_set_auth(struct rtllib_device *ieee,
2021 struct iw_request_info *info,
2022 struct iw_param *data, char *extra);
2023 int rtllib_wx_set_mlme(struct rtllib_device *ieee,
2024 struct iw_request_info *info,
2025 union iwreq_data *wrqu, char *extra);
2026 int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
2028 /* rtllib_softmac.c */
2029 int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb,
2030 struct rtllib_rx_stats *rx_stats, u16 type,
2032 void rtllib_softmac_new_net(struct rtllib_device *ieee,
2033 struct rtllib_network *net);
2035 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
2036 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
2038 void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2039 void notify_wx_assoc_event(struct rtllib_device *ieee);
2040 void rtllib_start_ibss(struct rtllib_device *ieee);
2041 void rtllib_softmac_init(struct rtllib_device *ieee);
2042 void rtllib_softmac_free(struct rtllib_device *ieee);
2043 void rtllib_disassociate(struct rtllib_device *ieee);
2044 void rtllib_stop_scan(struct rtllib_device *ieee);
2045 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
2046 void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
2047 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2048 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr);
2049 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
2050 void rtllib_start_protocol(struct rtllib_device *ieee);
2051 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
2053 void rtllib_EnableNetMonitorMode(struct net_device *dev, bool bInitState);
2054 void rtllib_DisableNetMonitorMode(struct net_device *dev, bool bInitState);
2055 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, bool bInitState);
2056 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
2058 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee,
2059 u8 mesh_flag, u8 shutdown);
2060 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag);
2062 void rtllib_reset_queue(struct rtllib_device *ieee);
2063 void rtllib_wake_all_queues(struct rtllib_device *ieee);
2064 void rtllib_stop_all_queues(struct rtllib_device *ieee);
2065 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
2066 void rtllib_start_send_beacons(struct rtllib_device *ieee);
2067 void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2068 int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee,
2069 struct iw_point *p, u8 is_mesh);
2071 void notify_wx_assoc_event(struct rtllib_device *ieee);
2072 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
2074 void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee);
2075 u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
2077 /* rtllib_softmac_wx.c */
2079 int rtllib_wx_get_wap(struct rtllib_device *ieee, struct iw_request_info *info,
2080 union iwreq_data *wrqu, char *ext);
2082 int rtllib_wx_set_wap(struct rtllib_device *ieee, struct iw_request_info *info,
2083 union iwreq_data *awrq, char *extra);
2085 int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a,
2086 union iwreq_data *wrqu, char *b);
2088 int rtllib_wx_set_rate(struct rtllib_device *ieee, struct iw_request_info *info,
2089 union iwreq_data *wrqu, char *extra);
2091 int rtllib_wx_get_rate(struct rtllib_device *ieee, struct iw_request_info *info,
2092 union iwreq_data *wrqu, char *extra);
2094 int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a,
2095 union iwreq_data *wrqu, char *b);
2097 int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a,
2098 union iwreq_data *wrqu, char *b);
2100 int rtllib_wx_set_essid(struct rtllib_device *ieee, struct iw_request_info *a,
2101 union iwreq_data *wrqu, char *extra);
2103 int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a,
2104 union iwreq_data *wrqu, char *b);
2106 int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2107 union iwreq_data *wrqu, char *b);
2109 int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2110 union iwreq_data *wrqu, char *b);
2111 void rtllib_wx_sync_scan_wq(void *data);
2113 int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
2114 struct iw_request_info *info,
2115 union iwreq_data *wrqu, char *extra);
2117 int rtllib_wx_get_name(struct rtllib_device *ieee, struct iw_request_info *info,
2118 union iwreq_data *wrqu, char *extra);
2120 int rtllib_wx_set_power(struct rtllib_device *ieee,
2121 struct iw_request_info *info,
2122 union iwreq_data *wrqu, char *extra);
2124 int rtllib_wx_get_power(struct rtllib_device *ieee,
2125 struct iw_request_info *info,
2126 union iwreq_data *wrqu, char *extra);
2128 int rtllib_wx_set_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2129 union iwreq_data *wrqu, char *extra);
2131 int rtllib_wx_get_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2132 union iwreq_data *wrqu, char *extra);
2133 #define MAX_RECEIVE_BUFFER_SIZE 9100
2135 void HTSetConnectBwMode(struct rtllib_device *ieee,
2136 enum ht_channel_width Bandwidth,
2137 enum ht_extchnl_offset Offset);
2138 void HTUpdateDefaultSetting(struct rtllib_device *ieee);
2139 void HTConstructCapabilityElement(struct rtllib_device *ieee,
2140 u8 *posHTCap, u8 *len,
2141 u8 isEncrypt, bool bAssoc);
2142 void HTConstructInfoElement(struct rtllib_device *ieee,
2143 u8 *posHTInfo, u8 *len, u8 isEncrypt);
2144 void HTConstructRT2RTAggElement(struct rtllib_device *ieee,
2145 u8 *posRT2RTAgg, u8 *len);
2146 void HTOnAssocRsp(struct rtllib_device *ieee);
2147 void HTInitializeHTInfo(struct rtllib_device *ieee);
2148 void HTInitializeBssDesc(struct bss_ht *pBssHT);
2149 void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
2150 struct rtllib_network *pNetwork);
2151 void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
2152 struct rtllib_network *pNetwork);
2153 u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
2155 extern u8 MCS_FILTER_ALL[];
2156 extern u16 MCS_DATA_RATE[2][2][77];
2157 u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame);
2158 void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo);
2159 bool IsHTHalfNmodeAPs(struct rtllib_device *ieee);
2160 u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate);
2161 int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb);
2162 int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb);
2163 int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb);
2164 void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS,
2165 u8 Policy, u8 bOverwritePending);
2166 void TsInitDelBA(struct rtllib_device *ieee,
2167 struct ts_common_info *pTsCommonInfo,
2168 enum tr_select TxRxSelect);
2169 void BaSetupTimeOut(unsigned long data);
2170 void TxBaInactTimeout(unsigned long data);
2171 void RxBaInactTimeout(unsigned long data);
2172 void ResetBaEntry(struct ba_record *pBA);
2173 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS, u8 *Addr,
2174 u8 TID, enum tr_select TxRxSelect, bool bAddNewTs);
2175 void TSInitialize(struct rtllib_device *ieee);
2176 void TsStartAddBaProcess(struct rtllib_device *ieee,
2177 struct tx_ts_record *pTxTS);
2178 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr);
2179 void RemoveAllTS(struct rtllib_device *ieee);
2181 extern const long rtllib_wlan_frequencies[];
2183 static inline const char *escape_essid(const char *essid, u8 essid_len)
2185 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
2187 if (rtllib_is_empty_essid(essid, essid_len)) {
2188 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
2192 snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid);
2196 /* fun with the built-in rtllib stack... */
2197 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn);
2200 /* For the function is more related to hardware setting, it's better to use the
2201 * ieee handler to refer to it.
2203 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
2204 struct rx_ts_record *pTS);
2205 int rtllib_parse_info_param(struct rtllib_device *ieee,
2206 struct rtllib_info_element *info_element,
2208 struct rtllib_network *network,
2209 struct rtllib_rx_stats *stats);
2211 void rtllib_indicate_packets(struct rtllib_device *ieee,
2212 struct rtllib_rxb **prxbIndicateArray, u8 index);
2213 void HTUseDefaultSetting(struct rtllib_device *ieee);
2214 #define RT_ASOC_RETRY_LIMIT 5
2215 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
2217 #endif /* RTLLIB_H */