• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/staging/rt2860/
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify  *
11 * it under the terms of the GNU General Public License as published by  *
12 * the Free Software Foundation; either version 2 of the License, or     *
13 * (at your option) any later version.                                   *
14 *                                                                       *
15 * This program is distributed in the hope that it will be useful,       *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18 * GNU General Public License for more details.                          *
19 *                                                                       *
20 * You should have received a copy of the GNU General Public License     *
21 * along with this program; if not, write to the                         *
22 * Free Software Foundation, Inc.,                                       *
23 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24 *                                                                       *
25 *************************************************************************
26
27    Module Name:
28    rtmp.h
29
30    Abstract:
31    Miniport generic portion header file
32
33    Revision History:
34    Who         When          What
35    --------    ----------    ----------------------------------------------
36    Paul Lin    2002-08-01    created
37    James Tan   2002-09-06    modified (Revise NTCRegTable)
38    John Chang  2004-09-06    modified for RT2600
39*/
40#ifndef __RTMP_H__
41#define __RTMP_H__
42
43#include "spectrum_def.h"
44#include "rtmp_dot11.h"
45#include "rtmp_chip.h"
46
47struct rt_rtmp_adapter;
48
49/*#define DBG           1 */
50
51/*#define DBG_DIAGNOSE          1 */
52
53/*+++Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */
54#define MAX_DATAMM_RETRY	3
55#define MGMT_USE_QUEUE_FLAG	0x80
56/*---Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */
57
58#define	MAXSEQ		(0xFFF)
59
60extern unsigned char SNAP_AIRONET[];
61extern unsigned char CISCO_OUI[];
62extern u8 BaSizeArray[4];
63
64extern u8 BROADCAST_ADDR[MAC_ADDR_LEN];
65extern u8 ZERO_MAC_ADDR[MAC_ADDR_LEN];
66extern unsigned long BIT32[32];
67extern u8 BIT8[8];
68extern char *CipherName[];
69extern char *MCSToMbps[];
70extern u8 RxwiMCSToOfdmRate[12];
71extern u8 SNAP_802_1H[6];
72extern u8 SNAP_BRIDGE_TUNNEL[6];
73extern u8 SNAP_AIRONET[8];
74extern u8 CKIP_LLC_SNAP[8];
75extern u8 EAPOL_LLC_SNAP[8];
76extern u8 EAPOL[2];
77extern u8 IPX[2];
78extern u8 APPLE_TALK[2];
79extern u8 RateIdToPlcpSignal[12];	/* see IEEE802.11a-1999 p.14 */
80extern u8 OfdmRateToRxwiMCS[];
81extern u8 OfdmSignalToRateId[16];
82extern u8 default_cwmin[4];
83extern u8 default_cwmax[4];
84extern u8 default_sta_aifsn[4];
85extern u8 MapUserPriorityToAccessCategory[8];
86
87extern u16 RateUpPER[];
88extern u16 RateDownPER[];
89extern u8 Phy11BNextRateDownward[];
90extern u8 Phy11BNextRateUpward[];
91extern u8 Phy11BGNextRateDownward[];
92extern u8 Phy11BGNextRateUpward[];
93extern u8 Phy11ANextRateDownward[];
94extern u8 Phy11ANextRateUpward[];
95extern char RssiSafeLevelForTxRate[];
96extern u8 RateIdToMbps[];
97extern u16 RateIdTo500Kbps[];
98
99extern u8 CipherSuiteWpaNoneTkip[];
100extern u8 CipherSuiteWpaNoneTkipLen;
101
102extern u8 CipherSuiteWpaNoneAes[];
103extern u8 CipherSuiteWpaNoneAesLen;
104
105extern u8 SsidIe;
106extern u8 SupRateIe;
107extern u8 ExtRateIe;
108
109extern u8 HtCapIe;
110extern u8 AddHtInfoIe;
111extern u8 NewExtChanIe;
112
113extern u8 ErpIe;
114extern u8 DsIe;
115extern u8 TimIe;
116extern u8 WpaIe;
117extern u8 Wpa2Ie;
118extern u8 IbssIe;
119extern u8 Ccx2Ie;
120extern u8 WapiIe;
121
122extern u8 WPA_OUI[];
123extern u8 RSN_OUI[];
124extern u8 WAPI_OUI[];
125extern u8 WME_INFO_ELEM[];
126extern u8 WME_PARM_ELEM[];
127extern u8 Ccx2QosInfo[];
128extern u8 Ccx2IeInfo[];
129extern u8 RALINK_OUI[];
130extern u8 PowerConstraintIE[];
131
132extern u8 RateSwitchTable[];
133extern u8 RateSwitchTable11B[];
134extern u8 RateSwitchTable11G[];
135extern u8 RateSwitchTable11BG[];
136
137extern u8 RateSwitchTable11BGN1S[];
138extern u8 RateSwitchTable11BGN2S[];
139extern u8 RateSwitchTable11BGN2SForABand[];
140extern u8 RateSwitchTable11N1S[];
141extern u8 RateSwitchTable11N2S[];
142extern u8 RateSwitchTable11N2SForABand[];
143
144extern u8 PRE_N_HT_OUI[];
145
146struct rt_rssi_sample {
147	char LastRssi0;		/* last received RSSI */
148	char LastRssi1;		/* last received RSSI */
149	char LastRssi2;		/* last received RSSI */
150	char AvgRssi0;
151	char AvgRssi1;
152	char AvgRssi2;
153	short AvgRssi0X8;
154	short AvgRssi1X8;
155	short AvgRssi2X8;
156};
157
158/* */
159/*  Queue structure and macros */
160/* */
161struct rt_queue_entry;
162
163struct rt_queue_entry {
164	struct rt_queue_entry *Next;
165};
166
167/* Queue structure */
168struct rt_queue_header {
169	struct rt_queue_entry *Head;
170	struct rt_queue_entry *Tail;
171	unsigned long Number;
172};
173
174#define InitializeQueueHeader(QueueHeader)              \
175{                                                       \
176	(QueueHeader)->Head = (QueueHeader)->Tail = NULL;   \
177	(QueueHeader)->Number = 0;                          \
178}
179
180#define RemoveHeadQueue(QueueHeader)                \
181(QueueHeader)->Head;                                \
182{                                                   \
183	struct rt_queue_entry *pNext;                             \
184	if ((QueueHeader)->Head != NULL) {				\
185		pNext = (QueueHeader)->Head->Next;          \
186		(QueueHeader)->Head->Next = NULL;		\
187		(QueueHeader)->Head = pNext;                \
188		if (pNext == NULL)                          \
189			(QueueHeader)->Tail = NULL;             \
190		(QueueHeader)->Number--;                    \
191	}												\
192}
193
194#define InsertHeadQueue(QueueHeader, QueueEntry)            \
195{                                                           \
196		((struct rt_queue_entry *)QueueEntry)->Next = (QueueHeader)->Head; \
197		(QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry);       \
198		if ((QueueHeader)->Tail == NULL)                        \
199			(QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry);   \
200		(QueueHeader)->Number++;                                \
201}
202
203#define InsertTailQueue(QueueHeader, QueueEntry)                \
204{                                                               \
205	((struct rt_queue_entry *)QueueEntry)->Next = NULL;                    \
206	if ((QueueHeader)->Tail)                                    \
207		(QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry); \
208	else                                                        \
209		(QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry);       \
210	(QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry);           \
211	(QueueHeader)->Number++;                                    \
212}
213
214#define InsertTailQueueAc(pAd, pEntry, QueueHeader, QueueEntry)			\
215{																		\
216	((struct rt_queue_entry *)QueueEntry)->Next = NULL;							\
217	if ((QueueHeader)->Tail)											\
218		(QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry);			\
219	else																\
220		(QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry);				\
221	(QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry);					\
222	(QueueHeader)->Number++;											\
223}
224
225/* */
226/*  Macros for flag and ref count operations */
227/* */
228#define RTMP_SET_FLAG(_M, _F)       ((_M)->Flags |= (_F))
229#define RTMP_CLEAR_FLAG(_M, _F)     ((_M)->Flags &= ~(_F))
230#define RTMP_CLEAR_FLAGS(_M)        ((_M)->Flags = 0)
231#define RTMP_TEST_FLAG(_M, _F)      (((_M)->Flags & (_F)) != 0)
232#define RTMP_TEST_FLAGS(_M, _F)     (((_M)->Flags & (_F)) == (_F))
233/* Macro for power save flag. */
234#define RTMP_SET_PSFLAG(_M, _F)       ((_M)->PSFlags |= (_F))
235#define RTMP_CLEAR_PSFLAG(_M, _F)     ((_M)->PSFlags &= ~(_F))
236#define RTMP_CLEAR_PSFLAGS(_M)        ((_M)->PSFlags = 0)
237#define RTMP_TEST_PSFLAG(_M, _F)      (((_M)->PSFlags & (_F)) != 0)
238#define RTMP_TEST_PSFLAGS(_M, _F)     (((_M)->PSFlags & (_F)) == (_F))
239
240#define OPSTATUS_SET_FLAG(_pAd, _F)     ((_pAd)->CommonCfg.OpStatusFlags |= (_F))
241#define OPSTATUS_CLEAR_FLAG(_pAd, _F)   ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F))
242#define OPSTATUS_TEST_FLAG(_pAd, _F)    (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0)
243
244#define CLIENT_STATUS_SET_FLAG(_pEntry, _F)      ((_pEntry)->ClientStatusFlags |= (_F))
245#define CLIENT_STATUS_CLEAR_FLAG(_pEntry, _F)    ((_pEntry)->ClientStatusFlags &= ~(_F))
246#define CLIENT_STATUS_TEST_FLAG(_pEntry, _F)     (((_pEntry)->ClientStatusFlags & (_F)) != 0)
247
248#define RX_FILTER_SET_FLAG(_pAd, _F)    ((_pAd)->CommonCfg.PacketFilter |= (_F))
249#define RX_FILTER_CLEAR_FLAG(_pAd, _F)  ((_pAd)->CommonCfg.PacketFilter &= ~(_F))
250#define RX_FILTER_TEST_FLAG(_pAd, _F)   (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0)
251
252#define STA_NO_SECURITY_ON(_p)          (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
253#define STA_WEP_ON(_p)                  (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
254#define STA_TKIP_ON(_p)                 (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
255#define STA_AES_ON(_p)                  (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
256
257#define STA_TGN_WIFI_ON(_p)             (_p->StaCfg.bTGnWifiTest == TRUE)
258
259#define CKIP_KP_ON(_p)				((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
260#define CKIP_CMIC_ON(_p)			((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
261
262#define INC_RING_INDEX(_idx, _RingSize)    \
263{                                          \
264    (_idx) = (_idx+1) % (_RingSize);       \
265}
266
267/* StaActive.SupportedHtPhy.MCSSet is copied from AP beacon.  Don't need to update here. */
268#define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd)                                 \
269{                                                                                       \
270	_pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth;      \
271	_pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs;      \
272	_pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF;      \
273	_pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20;      \
274	_pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40;      \
275	_pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC;      \
276	_pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC;      \
277	_pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset;      \
278	_pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth;      \
279	_pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode;      \
280	_pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent;      \
281	NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(u8) * 16);\
282}
283
284#define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability)                                 \
285{                                                                                       \
286	_pAd->MacTab.Content[BSSID_WCID].AMsduSize = (u8)(_pHtCapability->HtCapInfo.AMsduSize);	\
287	_pAd->MacTab.Content[BSSID_WCID].MmpsMode = (u8)(_pHtCapability->HtCapInfo.MimoPs);	\
288	_pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (u8)(_pHtCapability->HtCapParm.MaxRAmpduFactor);	\
289}
290
291/* */
292/* MACRO for 32-bit PCI register read / write */
293/* */
294/* Usage : RTMP_IO_READ32( */
295/*              struct rt_rtmp_adapter *pAd, */
296/*              unsigned long Register_Offset, */
297/*              unsigned long * pValue) */
298/* */
299/*         RTMP_IO_WRITE32( */
300/*              struct rt_rtmp_adapter *pAd, */
301/*              unsigned long Register_Offset, */
302/*              unsigned long Value) */
303/* */
304
305/* */
306/* Common fragment list structure -  Identical to the scatter gather frag list structure */
307/* */
308/*#define struct rt_rtmp_sg_element         SCATTER_GATHER_ELEMENT */
309/*#define struct rt_rtmp_sg_element *PSCATTER_GATHER_ELEMENT */
310#define NIC_MAX_PHYS_BUF_COUNT              8
311
312struct rt_rtmp_sg_element {
313	void *Address;
314	unsigned long Length;
315	unsigned long *Reserved;
316};
317
318struct rt_rtmp_sg_list {
319	unsigned long NumberOfElements;
320	unsigned long *Reserved;
321	struct rt_rtmp_sg_element Elements[NIC_MAX_PHYS_BUF_COUNT];
322};
323
324/* */
325/*  Some utility macros */
326/* */
327#ifndef min
328#define min(_a, _b)     (((_a) < (_b)) ? (_a) : (_b))
329#endif
330
331#ifndef max
332#define max(_a, _b)     (((_a) > (_b)) ? (_a) : (_b))
333#endif
334
335#define GET_LNA_GAIN(_pAd)	((_pAd->LatchRfRegs.Channel <= 14) ? (_pAd->BLNAGain) : ((_pAd->LatchRfRegs.Channel <= 64) ? (_pAd->ALNAGain0) : ((_pAd->LatchRfRegs.Channel <= 128) ? (_pAd->ALNAGain1) : (_pAd->ALNAGain2))))
336
337#define INC_COUNTER64(Val)          (Val.QuadPart++)
338
339#define INFRA_ON(_p)                (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON))
340#define ADHOC_ON(_p)                (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON))
341#define MONITOR_ON(_p)              (((_p)->StaCfg.BssType) == BSS_MONITOR)
342#define IDLE_ON(_p)                 (!INFRA_ON(_p) && !ADHOC_ON(_p))
343
344/* Check LEAP & CCKM flags */
345#define LEAP_ON(_p)                 (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
346#define LEAP_CCKM_ON(_p)            ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
347
348/* if orginal Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required */
349#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap)		\
350{																\
351	if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) {	\
352		_pExtraLlcSnapEncap = SNAP_802_1H;						\
353		if (NdisEqualMemory(IPX, _pBufVA + 12, 2) || 			\
354			NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2)) {	\
355			_pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL;			\
356		}														\
357	}															\
358	else {				\
359		_pExtraLlcSnapEncap = NULL;								\
360	}															\
361}
362
363/* New Define for new Tx Path. */
364#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap)	\
365{																\
366	if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500) {		\
367		_pExtraLlcSnapEncap = SNAP_802_1H;						\
368		if (NdisEqualMemory(IPX, _pBufVA, 2) || 				\
369			NdisEqualMemory(APPLE_TALK, _pBufVA, 2)) {		\
370			_pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL;			\
371		}														\
372	}															\
373	else {		\
374		_pExtraLlcSnapEncap = NULL;								\
375	}															\
376}
377
378#define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType)                   \
379{                                                                       \
380    NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN);                           \
381    NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN);          \
382    NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \
383}
384
385/* if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way. */
386/* else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field */
387/* else remove the LLC/SNAP field from the result Ethernet frame */
388/* Patch for WHQL only, which did not turn on Netbios but use IPX within its payload */
389/* Note: */
390/*     _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO */
391/*     _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed */
392#define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP)      \
393{                                                                       \
394    char LLC_Len[2];                                                    \
395									\
396    _pRemovedLLCSNAP = NULL;                                            \
397    if (NdisEqualMemory(SNAP_802_1H, _pData, 6)  ||                     \
398	NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6))	{		\
399	u8 *pProto = _pData + 6;					\
400									\
401	if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) &&  \
402		NdisEqualMemory(SNAP_802_1H, _pData, 6))	{	\
403		LLC_Len[0] = (u8)(_DataSize / 256);			\
404		LLC_Len[1] = (u8)(_DataSize % 256);			\
405		MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len);	\
406	}								\
407	else	{							\
408		MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto);	\
409		_pRemovedLLCSNAP = _pData;				\
410		_DataSize -= LENGTH_802_1_H;				\
411		_pData += LENGTH_802_1_H;				\
412	}								\
413    }                                                                   \
414	else	{							\
415	LLC_Len[0] = (u8)(_DataSize / 256);				\
416	LLC_Len[1] = (u8)(_DataSize % 256);				\
417	MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len);		\
418    }                                                                   \
419}
420
421/* Enqueue this frame to MLME engine */
422/* We need to enqueue the whole frame because MLME need to pass data type */
423/* information from 802.11 header */
424#ifdef RTMP_MAC_PCI
425#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal)        \
426{                                                                                       \
427    u32 High32TSF, Low32TSF;                                                          \
428    RTMP_IO_READ32(_pAd, TSF_TIMER_DW1, &High32TSF);                                       \
429    RTMP_IO_READ32(_pAd, TSF_TIMER_DW0, &Low32TSF);                                        \
430    MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal);   \
431}
432#endif /* RTMP_MAC_PCI // */
433#ifdef RTMP_MAC_USB
434#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal)        \
435{                                                                                       \
436    u32 High32TSF = 0, Low32TSF = 0;                                                          \
437    MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal);   \
438}
439#endif /* RTMP_MAC_USB // */
440
441#define MAC_ADDR_EQUAL(pAddr1, pAddr2)           RTMPEqualMemory((void *)(pAddr1), (void *)(pAddr2), MAC_ADDR_LEN)
442#define SSID_EQUAL(ssid1, len1, ssid2, len2)    ((len1 == len2) && (RTMPEqualMemory(ssid1, ssid2, len1)))
443
444/* */
445/* Check if it is Japan W53(ch52,56,60,64) channel. */
446/* */
447#define JapanChannelCheck(channel)  ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
448
449#define STA_EXTRA_SETTING(_pAd)
450
451#define STA_PORT_SECURED(_pAd) \
452{ \
453	BOOLEAN	Cancelled; \
454	(_pAd)->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \
455	NdisAcquireSpinLock(&((_pAd)->MacTabLock)); \
456	(_pAd)->MacTab.Content[BSSID_WCID].PortSecured = (_pAd)->StaCfg.PortSecured; \
457	(_pAd)->MacTab.Content[BSSID_WCID].PrivacyFilter = Ndis802_11PrivFilterAcceptAll;\
458	NdisReleaseSpinLock(&(_pAd)->MacTabLock); \
459	RTMPCancelTimer(&((_pAd)->Mlme.LinkDownTimer), &Cancelled);\
460	STA_EXTRA_SETTING(_pAd); \
461}
462
463/* */
464/*  Data buffer for DMA operation, the buffer must be contiguous physical memory */
465/*  Both DMA to / from CPU use the same structure. */
466/* */
467struct rt_rtmp_dmabuf {
468	unsigned long AllocSize;
469	void *AllocVa;		/* TxBuf virtual address */
470	dma_addr_t AllocPa;	/* TxBuf physical address */
471};
472
473/* */
474/* Control block (Descriptor) for all ring descriptor DMA operation, buffer must be */
475/* contiguous physical memory. char stored the binding Rx packet descriptor */
476/* which won't be released, driver has to wait until upper layer return the packet */
477/* before giveing up this rx ring descriptor to ASIC. NDIS_BUFFER is assocaited pair */
478/* to describe the packet buffer. For Tx, char stored the tx packet descriptor */
479/* which driver should ACK upper layer when the tx is physically done or failed. */
480/* */
481struct rt_rtmp_dmacb {
482	unsigned long AllocSize;	/* Control block size */
483	void *AllocVa;		/* Control block virtual address */
484	dma_addr_t AllocPa;	/* Control block physical address */
485	void *pNdisPacket;
486	void *pNextNdisPacket;
487
488	struct rt_rtmp_dmabuf DmaBuf;	/* Associated DMA buffer structure */
489};
490
491struct rt_rtmp_tx_ring {
492	struct rt_rtmp_dmacb Cell[TX_RING_SIZE];
493	u32 TxCpuIdx;
494	u32 TxDmaIdx;
495	u32 TxSwFreeIdx;	/* software next free tx index */
496};
497
498struct rt_rtmp_rx_ring {
499	struct rt_rtmp_dmacb Cell[RX_RING_SIZE];
500	u32 RxCpuIdx;
501	u32 RxDmaIdx;
502	int RxSwReadIdx;	/* software next read index */
503};
504
505struct rt_rtmp_mgmt_ring {
506	struct rt_rtmp_dmacb Cell[MGMT_RING_SIZE];
507	u32 TxCpuIdx;
508	u32 TxDmaIdx;
509	u32 TxSwFreeIdx;	/* software next free tx index */
510};
511
512/* */
513/*  Statistic counter structure */
514/* */
515struct rt_counter_802_3 {
516	/* General Stats */
517	unsigned long GoodTransmits;
518	unsigned long GoodReceives;
519	unsigned long TxErrors;
520	unsigned long RxErrors;
521	unsigned long RxNoBuffer;
522
523	/* Ethernet Stats */
524	unsigned long RcvAlignmentErrors;
525	unsigned long OneCollision;
526	unsigned long MoreCollisions;
527
528};
529
530struct rt_counter_802_11 {
531	unsigned long Length;
532	LARGE_INTEGER LastTransmittedFragmentCount;
533	LARGE_INTEGER TransmittedFragmentCount;
534	LARGE_INTEGER MulticastTransmittedFrameCount;
535	LARGE_INTEGER FailedCount;
536	LARGE_INTEGER RetryCount;
537	LARGE_INTEGER MultipleRetryCount;
538	LARGE_INTEGER RTSSuccessCount;
539	LARGE_INTEGER RTSFailureCount;
540	LARGE_INTEGER ACKFailureCount;
541	LARGE_INTEGER FrameDuplicateCount;
542	LARGE_INTEGER ReceivedFragmentCount;
543	LARGE_INTEGER MulticastReceivedFrameCount;
544	LARGE_INTEGER FCSErrorCount;
545};
546
547struct rt_counter_ralink {
548	unsigned long TransmittedByteCount;	/* both successful and failure, used to calculate TX throughput */
549	unsigned long ReceivedByteCount;	/* both CRC okay and CRC error, used to calculate RX throughput */
550	unsigned long BeenDisassociatedCount;
551	unsigned long BadCQIAutoRecoveryCount;
552	unsigned long PoorCQIRoamingCount;
553	unsigned long MgmtRingFullCount;
554	unsigned long RxCountSinceLastNULL;
555	unsigned long RxCount;
556	unsigned long RxRingErrCount;
557	unsigned long KickTxCount;
558	unsigned long TxRingErrCount;
559	LARGE_INTEGER RealFcsErrCount;
560	unsigned long PendingNdisPacketCount;
561
562	unsigned long OneSecOsTxCount[NUM_OF_TX_RING];
563	unsigned long OneSecDmaDoneCount[NUM_OF_TX_RING];
564	u32 OneSecTxDoneCount;
565	unsigned long OneSecRxCount;
566	u32 OneSecTxAggregationCount;
567	u32 OneSecRxAggregationCount;
568	u32 OneSecReceivedByteCount;
569	u32 OneSecFrameDuplicateCount;
570
571	u32 OneSecTransmittedByteCount;	/* both successful and failure, used to calculate TX throughput */
572	u32 OneSecTxNoRetryOkCount;
573	u32 OneSecTxRetryOkCount;
574	u32 OneSecTxFailCount;
575	u32 OneSecFalseCCACnt;	/* CCA error count, for debug purpose, might move to global counter */
576	u32 OneSecRxOkCnt;	/* RX without error */
577	u32 OneSecRxOkDataCnt;	/* unicast-to-me DATA frame count */
578	u32 OneSecRxFcsErrCnt;	/* CRC error */
579	u32 OneSecBeaconSentCnt;
580	u32 LastOneSecTotalTxCount;	/* OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount */
581	u32 LastOneSecRxOkDataCnt;	/* OneSecRxOkDataCnt */
582	unsigned long DuplicateRcv;
583	unsigned long TxAggCount;
584	unsigned long TxNonAggCount;
585	unsigned long TxAgg1MPDUCount;
586	unsigned long TxAgg2MPDUCount;
587	unsigned long TxAgg3MPDUCount;
588	unsigned long TxAgg4MPDUCount;
589	unsigned long TxAgg5MPDUCount;
590	unsigned long TxAgg6MPDUCount;
591	unsigned long TxAgg7MPDUCount;
592	unsigned long TxAgg8MPDUCount;
593	unsigned long TxAgg9MPDUCount;
594	unsigned long TxAgg10MPDUCount;
595	unsigned long TxAgg11MPDUCount;
596	unsigned long TxAgg12MPDUCount;
597	unsigned long TxAgg13MPDUCount;
598	unsigned long TxAgg14MPDUCount;
599	unsigned long TxAgg15MPDUCount;
600	unsigned long TxAgg16MPDUCount;
601
602	LARGE_INTEGER TransmittedOctetsInAMSDU;
603	LARGE_INTEGER TransmittedAMSDUCount;
604	LARGE_INTEGER ReceivedOctesInAMSDUCount;
605	LARGE_INTEGER ReceivedAMSDUCount;
606	LARGE_INTEGER TransmittedAMPDUCount;
607	LARGE_INTEGER TransmittedMPDUsInAMPDUCount;
608	LARGE_INTEGER TransmittedOctetsInAMPDUCount;
609	LARGE_INTEGER MPDUInReceivedAMPDUCount;
610};
611
612struct rt_counter_drs {
613	/* to record the each TX rate's quality. 0 is best, the bigger the worse. */
614	u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
615	u8 PER[MAX_STEP_OF_TX_RATE_SWITCH];
616	u8 TxRateUpPenalty;	/* extra # of second penalty due to last unstable condition */
617	unsigned long CurrTxRateStableTime;	/* # of second in current TX rate */
618	BOOLEAN fNoisyEnvironment;
619	BOOLEAN fLastSecAccordingRSSI;
620	u8 LastSecTxRateChangeAction;	/* 0: no change, 1:rate UP, 2:rate down */
621	u8 LastTimeTxRateChangeAction;	/*Keep last time value of LastSecTxRateChangeAction */
622	unsigned long LastTxOkCount;
623};
624
625/***************************************************************************
626  *	security key related data structure
627  **************************************************************************/
628struct rt_cipher_key {
629	u8 Key[16];		/* right now we implement 4 keys, 128 bits max */
630	u8 RxMic[8];		/* make alignment */
631	u8 TxMic[8];
632	u8 TxTsc[6];		/* 48bit TSC value */
633	u8 RxTsc[6];		/* 48bit TSC value */
634	u8 CipherAlg;	/* 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128 */
635	u8 KeyLen;
636	u8 BssId[6];
637	/* Key length for each key, 0: entry is invalid */
638	u8 Type;		/* Indicate Pairwise/Group when reporting MIC error */
639};
640
641/* structure to define WPA Group Key Rekey Interval */
642struct PACKED rt_802_11_wpa_rekey {
643	unsigned long ReKeyMethod;	/* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
644	unsigned long ReKeyInterval;	/* time-based: seconds, packet-based: kilo-packets */
645};
646
647#ifdef RTMP_MAC_USB
648/***************************************************************************
649  *	RTUSB I/O related data structure
650  **************************************************************************/
651struct rt_set_asic_wcid {
652	unsigned long WCID;		/* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
653	unsigned long SetTid;		/* time-based: seconds, packet-based: kilo-packets */
654	unsigned long DeleteTid;	/* time-based: seconds, packet-based: kilo-packets */
655	u8 Addr[MAC_ADDR_LEN];	/* avoid in interrupt when write key */
656};
657
658struct rt_set_asic_wcid_attri {
659	unsigned long WCID;		/* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
660	unsigned long Cipher;		/* ASIC Cipher definition */
661	u8 Addr[ETH_LENGTH_OF_ADDRESS];
662};
663
664/* for USB interface, avoid in interrupt when write key */
665struct rt_add_pairwise_key_entry {
666	u8 MacAddr[6];
667	u16 MacTabMatchWCID;	/* ASIC */
668	struct rt_cipher_key CipherKey;
669};
670
671/* Cipher suite type for mixed mode group cipher, P802.11i-2004 */
672typedef enum _RT_802_11_CIPHER_SUITE_TYPE {
673	Cipher_Type_NONE,
674	Cipher_Type_WEP40,
675	Cipher_Type_TKIP,
676	Cipher_Type_RSVD,
677	Cipher_Type_CCMP,
678	Cipher_Type_WEP104
679} RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE;
680#endif /* RTMP_MAC_USB // */
681
682struct rt_rogueap_entry {
683	u8 Addr[MAC_ADDR_LEN];
684	u8 ErrorCode[2];	/*00 01-Invalid authentication type */
685	/*00 02-Authentication timeout */
686	/*00 03-Challenge from AP failed */
687	/*00 04-Challenge to AP failed */
688	BOOLEAN Reported;
689};
690
691struct rt_rogueap_table {
692	u8 RogueApNr;
693	struct rt_rogueap_entry RogueApEntry[MAX_LEN_OF_BSS_TABLE];
694};
695
696/* */
697/* Cisco IAPP format */
698/* */
699struct rt_cisco_iapp_content {
700	u16 Length;		/*IAPP Length */
701	u8 MessageType;	/*IAPP type */
702	u8 FunctionCode;	/*IAPP function type */
703	u8 DestinaionMAC[MAC_ADDR_LEN];
704	u8 SourceMAC[MAC_ADDR_LEN];
705	u16 Tag;		/*Tag(element IE) - Adjacent AP report */
706	u16 TagLength;	/*Length of element not including 4 byte header */
707	u8 OUI[4];		/*0x00, 0x40, 0x96, 0x00 */
708	u8 PreviousAP[MAC_ADDR_LEN];	/*MAC Address of access point */
709	u16 Channel;
710	u16 SsidLen;
711	u8 Ssid[MAX_LEN_OF_SSID];
712	u16 Seconds;		/*Seconds that the client has been disassociated. */
713};
714
715/*
716  *	Fragment Frame structure
717  */
718struct rt_fragment_frame {
719	void *pFragPacket;
720	unsigned long RxSize;
721	u16 Sequence;
722	u16 LastFrag;
723	unsigned long Flags;		/* Some extra frame information. bit 0: LLC presented */
724};
725
726/* */
727/* Packet information for NdisQueryPacket */
728/* */
729struct rt_packet_info {
730	u32 PhysicalBufferCount;	/* Physical breaks of buffer descripor chained */
731	u32 BufferCount;	/* Number of Buffer descriptor chained */
732	u32 TotalPacketLength;	/* Self explained */
733	char *pFirstBuffer;	/* Pointer to first buffer descriptor */
734};
735
736/* */
737/*  Arcfour Structure Added by PaulWu */
738/* */
739struct rt_arcfourcontext {
740	u32 X;
741	u32 Y;
742	u8 STATE[256];
743};
744
745/* */
746/* Tkip Key structure which RC4 key & MIC calculation */
747/* */
748struct rt_tkip_key_info {
749	u32 nBytesInM;		/* # bytes in M for MICKEY */
750	unsigned long IV16;
751	unsigned long IV32;
752	unsigned long K0;		/* for MICKEY Low */
753	unsigned long K1;		/* for MICKEY Hig */
754	unsigned long L;		/* Current state for MICKEY */
755	unsigned long R;		/* Current state for MICKEY */
756	unsigned long M;		/* Message accumulator for MICKEY */
757	u8 RC4KEY[16];
758	u8 MIC[8];
759};
760
761/* */
762/* Private / Misc data, counters for driver internal use */
763/* */
764struct rt_private {
765	u32 SystemResetCnt;	/* System reset counter */
766	u32 TxRingFullCnt;	/* Tx ring full occurrance number */
767	u32 PhyRxErrCnt;	/* PHY Rx error count, for debug purpose, might move to global counter */
768	/* Variables for WEP encryption / decryption in rtmp_wep.c */
769	u32 FCSCRC32;
770	struct rt_arcfourcontext WEPCONTEXT;
771	/* Tkip stuff */
772	struct rt_tkip_key_info Tx;
773	struct rt_tkip_key_info Rx;
774};
775
776/***************************************************************************
777  *	Channel and BBP related data structures
778  **************************************************************************/
779/* structure to tune BBP R66 (BBP TUNING) */
780struct rt_bbp_r66_tuning {
781	BOOLEAN bEnable;
782	u16 FalseCcaLowerThreshold;	/* default 100 */
783	u16 FalseCcaUpperThreshold;	/* default 512 */
784	u8 R66Delta;
785	u8 R66CurrentValue;
786	BOOLEAN R66LowerUpperSelect;	/*Before LinkUp, Used LowerBound or UpperBound as R66 value. */
787};
788
789/* structure to store channel TX power */
790struct rt_channel_tx_power {
791	u16 RemainingTimeForUse;	/*unit: sec */
792	u8 Channel;
793	char Power;
794	char Power2;
795	u8 MaxTxPwr;
796	u8 DfsReq;
797};
798
799/* structure to store 802.11j channel TX power */
800struct rt_channel_11j_tx_power {
801	u8 Channel;
802	u8 BW;		/* BW_10 or BW_20 */
803	char Power;
804	char Power2;
805	u16 RemainingTimeForUse;	/*unit: sec */
806};
807
808struct rt_soft_rx_ant_diversity {
809	u8 EvaluatePeriod;	/* 0:not evalute status, 1: evaluate status, 2: switching status */
810	u8 EvaluateStableCnt;
811	u8 Pair1PrimaryRxAnt;	/* 0:Ant-E1, 1:Ant-E2 */
812	u8 Pair1SecondaryRxAnt;	/* 0:Ant-E1, 1:Ant-E2 */
813	u8 Pair2PrimaryRxAnt;	/* 0:Ant-E3, 1:Ant-E4 */
814	u8 Pair2SecondaryRxAnt;	/* 0:Ant-E3, 1:Ant-E4 */
815	short Pair1AvgRssi[2];	/* AvgRssi[0]:E1, AvgRssi[1]:E2 */
816	short Pair2AvgRssi[2];	/* AvgRssi[0]:E3, AvgRssi[1]:E4 */
817	short Pair1LastAvgRssi;	/* */
818	short Pair2LastAvgRssi;	/* */
819	unsigned long RcvPktNumWhenEvaluate;
820	BOOLEAN FirstPktArrivedWhenEvaluate;
821	struct rt_ralink_timer RxAntDiversityTimer;
822};
823
824/***************************************************************************
825  *	structure for radar detection and channel switch
826  **************************************************************************/
827struct rt_radar_detect {
828	/*BOOLEAN           IEEE80211H;                     // 0: disable, 1: enable IEEE802.11h */
829	u8 CSCount;		/*Channel switch counter */
830	u8 CSPeriod;		/*Channel switch period (beacon count) */
831	u8 RDCount;		/*Radar detection counter */
832	u8 RDMode;		/*Radar Detection mode */
833	u8 RDDurRegion;	/*Radar detection duration region */
834	u8 BBPR16;
835	u8 BBPR17;
836	u8 BBPR18;
837	u8 BBPR21;
838	u8 BBPR22;
839	u8 BBPR64;
840	unsigned long InServiceMonitorCount;	/* unit: sec */
841	u8 DfsSessionTime;
842	BOOLEAN bFastDfs;
843	u8 ChMovingTime;
844	u8 LongPulseRadarTh;
845};
846
847typedef enum _ABGBAND_STATE_ {
848	UNKNOWN_BAND,
849	BG_BAND,
850	A_BAND,
851} ABGBAND_STATE;
852
853#ifdef RTMP_MAC_PCI
854/* Power save method control */
855typedef union _PS_CONTROL {
856	struct {
857		unsigned long EnablePSinIdle:1;	/* Enable radio off when not connect to AP. radio on only when sitesurvey, */
858		unsigned long EnableNewPS:1;	/* Enable new  Chip power save fucntion . New method can only be applied in chip version after 2872. and PCIe. */
859		unsigned long rt30xxPowerMode:2;	/* Power Level Mode for rt30xx chip */
860		unsigned long rt30xxFollowHostASPM:1;	/* Card Follows Host's setting for rt30xx chip. */
861		unsigned long rt30xxForceASPMTest:1;	/* Force enable L1 for rt30xx chip. This has higher priority than rt30xxFollowHostASPM Mode. */
862		unsigned long rsv:26;	/* Radio Measurement Enable */
863	} field;
864	unsigned long word;
865} PS_CONTROL, *PPS_CONTROL;
866#endif /* RTMP_MAC_PCI // */
867
868/***************************************************************************
869  *	structure for MLME state machine
870  **************************************************************************/
871struct rt_mlme {
872	/* STA state machines */
873	struct rt_state_machine CntlMachine;
874	struct rt_state_machine AssocMachine;
875	struct rt_state_machine AuthMachine;
876	struct rt_state_machine AuthRspMachine;
877	struct rt_state_machine SyncMachine;
878	struct rt_state_machine WpaPskMachine;
879	struct rt_state_machine LeapMachine;
880	STATE_MACHINE_FUNC AssocFunc[ASSOC_FUNC_SIZE];
881	STATE_MACHINE_FUNC AuthFunc[AUTH_FUNC_SIZE];
882	STATE_MACHINE_FUNC AuthRspFunc[AUTH_RSP_FUNC_SIZE];
883	STATE_MACHINE_FUNC SyncFunc[SYNC_FUNC_SIZE];
884	STATE_MACHINE_FUNC ActFunc[ACT_FUNC_SIZE];
885	/* Action */
886	struct rt_state_machine ActMachine;
887
888	/* common WPA state machine */
889	struct rt_state_machine WpaMachine;
890	STATE_MACHINE_FUNC WpaFunc[WPA_FUNC_SIZE];
891
892	unsigned long ChannelQuality;	/* 0..100, Channel Quality Indication for Roaming */
893	unsigned long Now32;		/* latch the value of NdisGetSystemUpTime() */
894	unsigned long LastSendNULLpsmTime;
895
896	BOOLEAN bRunning;
897	spinlock_t TaskLock;
898	struct rt_mlme_queue Queue;
899
900	u32 ShiftReg;
901
902	struct rt_ralink_timer PeriodicTimer;
903	struct rt_ralink_timer APSDPeriodicTimer;
904	struct rt_ralink_timer LinkDownTimer;
905	struct rt_ralink_timer LinkUpTimer;
906#ifdef RTMP_MAC_PCI
907	u8 bPsPollTimerRunning;
908	struct rt_ralink_timer PsPollTimer;
909	struct rt_ralink_timer RadioOnOffTimer;
910#endif				/* RTMP_MAC_PCI // */
911	unsigned long PeriodicRound;
912	unsigned long OneSecPeriodicRound;
913
914	u8 RealRxPath;
915	BOOLEAN bLowThroughput;
916	BOOLEAN bEnableAutoAntennaCheck;
917	struct rt_ralink_timer RxAntEvalTimer;
918
919#ifdef RT30xx
920	u8 CaliBW40RfR24;
921	u8 CaliBW20RfR24;
922#endif				/* RT30xx // */
923
924#ifdef RTMP_MAC_USB
925	struct rt_ralink_timer AutoWakeupTimer;
926	BOOLEAN AutoWakeupTimerRunning;
927#endif				/* RTMP_MAC_USB // */
928};
929
930/***************************************************************************
931  *	802.11 N related data structures
932  **************************************************************************/
933struct reordering_mpdu {
934	struct reordering_mpdu *next;
935	void *pPacket;	/* coverted to 802.3 frame */
936	int Sequence;		/* sequence number of MPDU */
937	BOOLEAN bAMSDU;
938};
939
940struct reordering_list {
941	struct reordering_mpdu *next;
942	int qlen;
943};
944
945struct reordering_mpdu_pool {
946	void *mem;
947	spinlock_t lock;
948	struct reordering_list freelist;
949};
950
951typedef enum _REC_BLOCKACK_STATUS {
952	Recipient_NONE = 0,
953	Recipient_USED,
954	Recipient_HandleRes,
955	Recipient_Accept
956} REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS;
957
958typedef enum _ORI_BLOCKACK_STATUS {
959	Originator_NONE = 0,
960	Originator_USED,
961	Originator_WaitRes,
962	Originator_Done
963} ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS;
964
965struct rt_ba_ori_entry {
966	u8 Wcid;
967	u8 TID;
968	u8 BAWinSize;
969	u8 Token;
970/* Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header. */
971	u16 Sequence;
972	u16 TimeOutValue;
973	ORI_BLOCKACK_STATUS ORI_BA_Status;
974	struct rt_ralink_timer ORIBATimer;
975	void *pAdapter;
976};
977
978struct rt_ba_rec_entry {
979	u8 Wcid;
980	u8 TID;
981	u8 BAWinSize;	/* 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU. */
982	/*u8 NumOfRxPkt; */
983	/*u8    Curindidx; // the head in the RX reordering buffer */
984	u16 LastIndSeq;
985/*      u16          LastIndSeqAtTimer; */
986	u16 TimeOutValue;
987	struct rt_ralink_timer RECBATimer;
988	unsigned long LastIndSeqAtTimer;
989	unsigned long nDropPacket;
990	unsigned long rcvSeq;
991	REC_BLOCKACK_STATUS REC_BA_Status;
992/*      u8   RxBufIdxUsed; */
993	/* corresponding virtual address for RX reordering packet storage. */
994	/*RTMP_REORDERDMABUF MAP_RXBuf[MAX_RX_REORDERBUF]; */
995	spinlock_t RxReRingLock;	/* Rx Ring spinlock */
996/*      struct _BA_REC_ENTRY *pNext; */
997	void *pAdapter;
998	struct reordering_list list;
999};
1000
1001struct rt_ba_table {
1002	unsigned long numAsRecipient;	/* I am recipient of numAsRecipient clients. These client are in the BARecEntry[] */
1003	unsigned long numAsOriginator;	/* I am originator of   numAsOriginator clients. These clients are in the BAOriEntry[] */
1004	unsigned long numDoneOriginator;	/* count Done Originator sessions */
1005	struct rt_ba_ori_entry BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE];
1006	struct rt_ba_rec_entry BARecEntry[MAX_LEN_OF_BA_REC_TABLE];
1007};
1008
1009/*For QureyBATableOID use; */
1010struct PACKED rt_oid_ba_rec_entry {
1011	u8 MACAddr[MAC_ADDR_LEN];
1012	u8 BaBitmap;		/* if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize */
1013	u8 rsv;
1014	u8 BufSize[8];
1015	REC_BLOCKACK_STATUS REC_BA_Status[8];
1016};
1017
1018/*For QureyBATableOID use; */
1019struct PACKED rt_oid_ba_ori_entry {
1020	u8 MACAddr[MAC_ADDR_LEN];
1021	u8 BaBitmap;		/* if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize, read ORI_BA_Status[TID] for status */
1022	u8 rsv;
1023	u8 BufSize[8];
1024	ORI_BLOCKACK_STATUS ORI_BA_Status[8];
1025};
1026
1027struct rt_queryba_table {
1028	struct rt_oid_ba_ori_entry BAOriEntry[32];
1029	struct rt_oid_ba_rec_entry BARecEntry[32];
1030	u8 OriNum;		/* Number of below BAOriEntry */
1031	u8 RecNum;		/* Number of below BARecEntry */
1032};
1033
1034typedef union _BACAP_STRUC {
1035	struct {
1036		u32 RxBAWinLimit:8;
1037		u32 TxBAWinLimit:8;
1038		u32 AutoBA:1;	/* automatically BA */
1039		u32 Policy:2;	/* 0: DELAY_BA 1:IMMED_BA  (//BA Policy subfiled value in ADDBA frame)   2:BA-not use */
1040		u32 MpduDensity:3;
1041		u32 AmsduEnable:1;	/*Enable AMSDU transmisstion */
1042		u32 AmsduSize:1;	/* 0:3839, 1:7935 bytes. u32  MSDUSizeToBytes[]        = { 3839, 7935}; */
1043		u32 MMPSmode:2;	/* MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable */
1044		u32 bHtAdhoc:1;	/* adhoc can use ht rate. */
1045		u32 b2040CoexistScanSup:1;	/*As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz. */
1046		u32: 4;
1047	} field;
1048	u32 word;
1049} BACAP_STRUC, *PBACAP_STRUC;
1050
1051struct rt_oid_add_ba_entry {
1052	BOOLEAN IsRecipient;
1053	u8 MACAddr[MAC_ADDR_LEN];
1054	u8 TID;
1055	u8 nMSDU;
1056	u16 TimeOut;
1057	BOOLEAN bAllTid;	/* If True, delete all TID for BA sessions with this MACaddr. */
1058};
1059
1060#define IS_HT_STA(_pMacEntry)	\
1061	(_pMacEntry->MaxHTPhyMode.field.MODE >= MODE_HTMIX)
1062
1063#define IS_HT_RATE(_pMacEntry)	\
1064	(_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
1065
1066#define PEER_IS_HT_RATE(_pMacEntry)	\
1067	(_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
1068
1069/*This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second.  (Details see MLMEPeriodic) */
1070struct rt_iot {
1071	u8 Threshold[2];
1072	u8 ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE];	/* compare with threshold[0] */
1073	u8 RefreshNum[MAX_LEN_OF_BA_REC_TABLE];	/* compare with threshold[1] */
1074	unsigned long OneSecInWindowCount;
1075	unsigned long OneSecFrameDuplicateCount;
1076	unsigned long OneSecOutWindowCount;
1077	u8 DelOriAct;
1078	u8 DelRecAct;
1079	u8 RTSShortProt;
1080	u8 RTSLongProt;
1081	BOOLEAN bRTSLongProtOn;
1082	BOOLEAN bLastAtheros;
1083	BOOLEAN bCurrentAtheros;
1084	BOOLEAN bNowAtherosBurstOn;
1085	BOOLEAN bNextDisableRxBA;
1086	BOOLEAN bToggle;
1087};
1088
1089/* This is the registry setting for 802.11n transmit setting.  Used in advanced page. */
1090typedef union _REG_TRANSMIT_SETTING {
1091	struct {
1092		/*u32  PhyMode:4; */
1093		/*u32  MCS:7;                 // MCS */
1094		u32 rsv0:10;
1095		u32 TxBF:1;
1096		u32 BW:1;	/*channel bandwidth 20MHz or 40 MHz */
1097		u32 ShortGI:1;
1098		u32 STBC:1;	/*SPACE */
1099		u32 TRANSNO:2;
1100		u32 HTMODE:1;
1101		u32 EXTCHA:2;
1102		u32 rsv:13;
1103	} field;
1104	u32 word;
1105} REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING;
1106
1107typedef union _DESIRED_TRANSMIT_SETTING {
1108	struct {
1109		u16 MCS:7;	/* MCS */
1110		u16 PhyMode:4;
1111		u16 FixedTxMode:2;	/* If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode. */
1112		u16 rsv:3;
1113	} field;
1114	u16 word;
1115} DESIRED_TRANSMIT_SETTING, *PDESIRED_TRANSMIT_SETTING;
1116
1117#ifdef RTMP_MAC_USB
1118/***************************************************************************
1119  *	USB-based chip Beacon related data structures
1120  **************************************************************************/
1121#define BEACON_BITMAP_MASK		0xff
1122struct rt_beacon_sync {
1123	u8 BeaconBuf[HW_BEACON_MAX_COUNT][HW_BEACON_OFFSET];
1124	u8 BeaconTxWI[HW_BEACON_MAX_COUNT][TXWI_SIZE];
1125	unsigned long TimIELocationInBeacon[HW_BEACON_MAX_COUNT];
1126	unsigned long CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT];
1127	BOOLEAN EnableBeacon;	/* trigger to enable beacon transmission. */
1128	u8 BeaconBitMap;	/* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change. */
1129	u8 DtimBitOn;	/* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change. */
1130};
1131#endif /* RTMP_MAC_USB // */
1132
1133/***************************************************************************
1134  *	Multiple SSID related data structures
1135  **************************************************************************/
1136#define WLAN_MAX_NUM_OF_TIM			((MAX_LEN_OF_MAC_TABLE >> 3) + 1)	/* /8 + 1 */
1137#define WLAN_CT_TIM_BCMC_OFFSET		0	/* unit: 32B */
1138
1139/* clear bcmc TIM bit */
1140#define WLAN_MR_TIM_BCMC_CLEAR(apidx) \
1141	pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] &= ~BIT8[0];
1142
1143/* set bcmc TIM bit */
1144#define WLAN_MR_TIM_BCMC_SET(apidx) \
1145	pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] |= BIT8[0];
1146
1147/* clear a station PS TIM bit */
1148#define WLAN_MR_TIM_BIT_CLEAR(ad_p, apidx, wcid) \
1149	{	u8 tim_offset = wcid >> 3; \
1150		u8 bit_offset = wcid & 0x7; \
1151		ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] &= (~BIT8[bit_offset]); }
1152
1153/* set a station PS TIM bit */
1154#define WLAN_MR_TIM_BIT_SET(ad_p, apidx, wcid) \
1155	{	u8 tim_offset = wcid >> 3; \
1156		u8 bit_offset = wcid & 0x7; \
1157		ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] |= BIT8[bit_offset]; }
1158
1159/* configuration common to OPMODE_AP as well as OPMODE_STA */
1160struct rt_common_config {
1161
1162	BOOLEAN bCountryFlag;
1163	u8 CountryCode[3];
1164	u8 Geography;
1165	u8 CountryRegion;	/* Enum of country region, 0:FCC, 1:IC, 2:ETSI, 3:SPAIN, 4:France, 5:MKK, 6:MKK1, 7:Israel */
1166	u8 CountryRegionForABand;	/* Enum of country region for A band */
1167	u8 PhyMode;		/* PHY_11A, PHY_11B, PHY_11BG_MIXED, PHY_ABG_MIXED */
1168	u16 Dsifs;		/* in units of usec */
1169	unsigned long PacketFilter;	/* Packet filter for receiving */
1170	u8 RegulatoryClass;
1171
1172	char Ssid[MAX_LEN_OF_SSID];	/* NOT NULL-terminated */
1173	u8 SsidLen;		/* the actual ssid length in used */
1174	u8 LastSsidLen;	/* the actual ssid length in used */
1175	char LastSsid[MAX_LEN_OF_SSID];	/* NOT NULL-terminated */
1176	u8 LastBssid[MAC_ADDR_LEN];
1177
1178	u8 Bssid[MAC_ADDR_LEN];
1179	u16 BeaconPeriod;
1180	u8 Channel;
1181	u8 CentralChannel;	/* Central Channel when using 40MHz is indicating. not real channel. */
1182
1183	u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
1184	u8 SupRateLen;
1185	u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1186	u8 ExtRateLen;
1187	u8 DesireRate[MAX_LEN_OF_SUPPORTED_RATES];	/* OID_802_11_DESIRED_RATES */
1188	u8 MaxDesiredRate;
1189	u8 ExpectedACKRate[MAX_LEN_OF_SUPPORTED_RATES];
1190
1191	unsigned long BasicRateBitmap;	/* backup basic ratebitmap */
1192
1193	BOOLEAN bAPSDCapable;
1194	BOOLEAN bInServicePeriod;
1195	BOOLEAN bAPSDAC_BE;
1196	BOOLEAN bAPSDAC_BK;
1197	BOOLEAN bAPSDAC_VI;
1198	BOOLEAN bAPSDAC_VO;
1199
1200	/* because TSPEC can modify the APSD flag, we need to keep the APSD flag
1201	   requested in association stage from the station;
1202	   we need to recover the APSD flag after the TSPEC is deleted. */
1203	BOOLEAN bACMAPSDBackup[4];	/* for delivery-enabled & trigger-enabled both */
1204	BOOLEAN bACMAPSDTr[4];	/* no use */
1205
1206	BOOLEAN bNeedSendTriggerFrame;
1207	BOOLEAN bAPSDForcePowerSave;	/* Force power save mode, should only use in APSD-STAUT */
1208	unsigned long TriggerTimerCount;
1209	u8 MaxSPLength;
1210	u8 BBPCurrentBW;	/* BW_10,       BW_20, BW_40 */
1211	/* move to MULTISSID_STRUCT for MBSS */
1212	/*HTTRANSMIT_SETTING    HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI. */
1213	REG_TRANSMIT_SETTING RegTransmitSetting;	/*registry transmit setting. this is for reading registry setting only. not useful. */
1214	/*u8       FixedTxMode;              // Fixed Tx Mode (CCK, OFDM), for HT fixed tx mode (GF, MIX) , refer to RegTransmitSetting.field.HTMode */
1215	u8 TxRate;		/* Same value to fill in TXD. TxRate is 6-bit */
1216	u8 MaxTxRate;	/* RATE_1, RATE_2, RATE_5_5, RATE_11 */
1217	u8 TxRateIndex;	/* Tx rate index in RateSwitchTable */
1218	u8 TxRateTableSize;	/* Valid Tx rate table size in RateSwitchTable */
1219	/*BOOLEAN               bAutoTxRateSwitch; */
1220	u8 MinTxRate;	/* RATE_1, RATE_2, RATE_5_5, RATE_11 */
1221	u8 RtsRate;		/* RATE_xxx */
1222	HTTRANSMIT_SETTING MlmeTransmit;	/* MGMT frame PHY rate setting when operatin at Ht rate. */
1223	u8 MlmeRate;		/* RATE_xxx, used to send MLME frames */
1224	u8 BasicMlmeRate;	/* Default Rate for sending MLME frames */
1225
1226	u16 RtsThreshold;	/* in unit of BYTE */
1227	u16 FragmentThreshold;	/* in unit of BYTE */
1228
1229	u8 TxPower;		/* in unit of mW */
1230	unsigned long TxPowerPercentage;	/* 0~100 % */
1231	unsigned long TxPowerDefault;	/* keep for TxPowerPercentage */
1232	u8 PwrConstraint;
1233
1234	BACAP_STRUC BACapability;	/*   NO USE = 0XFF  ;  IMMED_BA =1  ;  DELAY_BA=0 */
1235	BACAP_STRUC REGBACapability;	/*   NO USE = 0XFF  ;  IMMED_BA =1  ;  DELAY_BA=0 */
1236
1237	struct rt_iot IOTestParm;	/* 802.11n InterOpbility Test Parameter; */
1238	unsigned long TxPreamble;	/* Rt802_11PreambleLong, Rt802_11PreambleShort, Rt802_11PreambleAuto */
1239	BOOLEAN bUseZeroToDisableFragment;	/* Microsoft use 0 as disable */
1240	unsigned long UseBGProtection;	/* 0: auto, 1: always use, 2: always not use */
1241	BOOLEAN bUseShortSlotTime;	/* 0: disable, 1 - use short slot (9us) */
1242	BOOLEAN bEnableTxBurst;	/* 1: enble TX PACKET BURST (when BA is established or AP is not a legacy WMM AP), 0: disable TX PACKET BURST */
1243	BOOLEAN bAggregationCapable;	/* 1: enable TX aggregation when the peer supports it */
1244	BOOLEAN bPiggyBackCapable;	/* 1: enable TX piggy-back according MAC's version */
1245	BOOLEAN bIEEE80211H;	/* 1: enable IEEE802.11h spec. */
1246	unsigned long DisableOLBCDetect;	/* 0: enable OLBC detect; 1 disable OLBC detect */
1247
1248	BOOLEAN bRdg;
1249
1250	BOOLEAN bWmmCapable;	/* 0:disable WMM, 1:enable WMM */
1251	struct rt_qos_capability_parm APQosCapability;	/* QOS capability of the current associated AP */
1252	struct rt_edca_parm APEdcaParm;	/* EDCA parameters of the current associated AP */
1253	struct rt_qbss_load_parm APQbssLoad;	/* QBSS load of the current associated AP */
1254	u8 AckPolicy[4];	/* ACK policy of the specified AC. see ACK_xxx */
1255	BOOLEAN bDLSCapable;	/* 0:disable DLS, 1:enable DLS */
1256	/* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */
1257	/* BOOLEAN control, either ON or OFF. These flags should always be accessed via */
1258	/* OPSTATUS_TEST_FLAG(), OPSTATUS_SET_FLAG(), OP_STATUS_CLEAR_FLAG() macros. */
1259	/* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition */
1260	unsigned long OpStatusFlags;
1261
1262	BOOLEAN NdisRadioStateOff;	/*For HCT 12.0, set this flag to TRUE instead of called MlmeRadioOff. */
1263	ABGBAND_STATE BandState;	/* For setting BBP used on B/G or A mode. */
1264
1265	/* IEEE802.11H--DFS. */
1266	struct rt_radar_detect RadarDetect;
1267
1268	/* HT */
1269	u8 BASize;		/* USer desired BAWindowSize. Should not exceed our max capability */
1270	/*struct rt_ht_capability      SupportedHtPhy; */
1271	struct rt_ht_capability DesiredHtPhy;
1272	struct rt_ht_capability_ie HtCapability;
1273	struct rt_add_ht_info_ie AddHTInfo;	/* Useful as AP. */
1274	/*This IE is used with channel switch announcement element when changing to a new 40MHz. */
1275	/*This IE is included in channel switch ammouncement frames 7.4.1.5, beacons, probe Rsp. */
1276	struct rt_new_ext_chan_ie NewExtChanOffset;	/*7.3.2.20A, 1 if extension channel is above the control channel, 3 if below, 0 if not present */
1277
1278	BOOLEAN bHTProtect;
1279	BOOLEAN bMIMOPSEnable;
1280	BOOLEAN bBADecline;
1281/*2008/11/05: KH add to support Antenna power-saving of AP<-- */
1282	BOOLEAN bGreenAPEnable;
1283/*2008/11/05: KH add to support Antenna power-saving of AP--> */
1284	BOOLEAN bDisableReordering;
1285	BOOLEAN bForty_Mhz_Intolerant;
1286	BOOLEAN bExtChannelSwitchAnnouncement;
1287	BOOLEAN bRcvBSSWidthTriggerEvents;
1288	unsigned long LastRcvBSSWidthTriggerEventsTime;
1289
1290	u8 TxBASize;
1291
1292	/* Enable wireless event */
1293	BOOLEAN bWirelessEvent;
1294	BOOLEAN bWiFiTest;	/* Enable this parameter for WiFi test */
1295
1296	/* Tx & Rx Stream number selection */
1297	u8 TxStream;
1298	u8 RxStream;
1299
1300	BOOLEAN bHardwareRadio;	/* Hardware controlled Radio enabled */
1301
1302#ifdef RTMP_MAC_USB
1303	BOOLEAN bMultipleIRP;	/* Multiple Bulk IN flag */
1304	u8 NumOfBulkInIRP;	/* if bMultipleIRP == TRUE, NumOfBulkInIRP will be 4 otherwise be 1 */
1305	struct rt_ht_capability SupportedHtPhy;
1306	unsigned long MaxPktOneTxBulk;
1307	u8 TxBulkFactor;
1308	u8 RxBulkFactor;
1309
1310	BOOLEAN IsUpdateBeacon;
1311	struct rt_beacon_sync *pBeaconSync;
1312	struct rt_ralink_timer BeaconUpdateTimer;
1313	u32 BeaconAdjust;
1314	u32 BeaconFactor;
1315	u32 BeaconRemain;
1316#endif				/* RTMP_MAC_USB // */
1317
1318	spinlock_t MeasureReqTabLock;
1319	struct rt_measure_req_tab *pMeasureReqTab;
1320
1321	spinlock_t TpcReqTabLock;
1322	struct rt_tpc_req_tab *pTpcReqTab;
1323
1324	BOOLEAN PSPXlink;	/* 0: Disable. 1: Enable */
1325
1326#if defined(RT305x) || defined(RT30xx)
1327	/* request by Gary, for High Power issue */
1328	u8 HighPowerPatchDisabled;
1329#endif
1330
1331	BOOLEAN HT_DisallowTKIP;	/* Restrict the encryption type in 11n HT mode */
1332};
1333
1334/* Modified by Wu Xi-Kun 4/21/2006 */
1335/* STA configuration and status */
1336struct rt_sta_admin_config {
1337	/* GROUP 1 - */
1338	/*   User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */
1339	/*   the user intended configuration, but not necessary fully equal to the final */
1340	/*   settings in ACTIVE BSS after negotiation/compromize with the BSS holder (either */
1341	/*   AP or IBSS holder). */
1342	/*   Once initialized, user configuration can only be changed via OID_xxx */
1343	u8 BssType;		/* BSS_INFRA or BSS_ADHOC */
1344	u16 AtimWin;		/* used when starting a new IBSS */
1345
1346	/* GROUP 2 - */
1347	/*   User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */
1348	/*   the user intended configuration, and should be always applied to the final */
1349	/*   settings in ACTIVE BSS without compromising with the BSS holder. */
1350	/*   Once initialized, user configuration can only be changed via OID_xxx */
1351	u8 RssiTrigger;
1352	u8 RssiTriggerMode;	/* RSSI_TRIGGERED_UPON_BELOW_THRESHOLD or RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD */
1353	u16 DefaultListenCount;	/* default listen count; */
1354	unsigned long WindowsPowerMode;	/* Power mode for AC power */
1355	unsigned long WindowsBatteryPowerMode;	/* Power mode for battery if exists */
1356	BOOLEAN bWindowsACCAMEnable;	/* Enable CAM power mode when AC on */
1357	BOOLEAN bAutoReconnect;	/* Set to TRUE when setting OID_802_11_SSID with no matching BSSID */
1358	unsigned long WindowsPowerProfile;	/* Windows power profile, for NDIS5.1 PnP */
1359
1360	/* MIB:ieee802dot11.dot11smt(1).dot11StationConfigTable(1) */
1361	u16 Psm;		/* power management mode   (PWR_ACTIVE|PWR_SAVE) */
1362	u16 DisassocReason;
1363	u8 DisassocSta[MAC_ADDR_LEN];
1364	u16 DeauthReason;
1365	u8 DeauthSta[MAC_ADDR_LEN];
1366	u16 AuthFailReason;
1367	u8 AuthFailSta[MAC_ADDR_LEN];
1368
1369	NDIS_802_11_PRIVACY_FILTER PrivacyFilter;	/* PrivacyFilter enum for 802.1X */
1370	NDIS_802_11_AUTHENTICATION_MODE AuthMode;	/* This should match to whatever microsoft defined */
1371	NDIS_802_11_WEP_STATUS WepStatus;
1372	NDIS_802_11_WEP_STATUS OrigWepStatus;	/* Original wep status set from OID */
1373
1374	/* Add to support different cipher suite for WPA2/WPA mode */
1375	NDIS_802_11_ENCRYPTION_STATUS GroupCipher;	/* Multicast cipher suite */
1376	NDIS_802_11_ENCRYPTION_STATUS PairCipher;	/* Unicast cipher suite */
1377	BOOLEAN bMixCipher;	/* Indicate current Pair & Group use different cipher suites */
1378	u16 RsnCapability;
1379
1380	NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
1381
1382	u8 WpaPassPhrase[64];	/* WPA PSK pass phrase */
1383	u32 WpaPassPhraseLen;	/* the length of WPA PSK pass phrase */
1384	u8 PMK[32];		/* WPA PSK mode PMK */
1385	u8 PTK[64];		/* WPA PSK mode PTK */
1386	u8 GTK[32];		/* GTK from authenticator */
1387	struct rt_bssid_info SavedPMK[PMKID_NO];
1388	u32 SavedPMKNum;	/* Saved PMKID number */
1389
1390	u8 DefaultKeyId;
1391
1392	/* WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED */
1393	u8 PortSecured;
1394
1395	/* For WPA countermeasures */
1396	unsigned long LastMicErrorTime;	/* record last MIC error time */
1397	unsigned long MicErrCnt;	/* Should be 0, 1, 2, then reset to zero (after disassoiciation). */
1398	BOOLEAN bBlockAssoc;	/* Block associate attempt for 60 seconds after counter measure occurred. */
1399	/* For WPA-PSK supplicant state */
1400	WPA_STATE WpaState;	/* Default is SS_NOTUSE and handled by microsoft 802.1x */
1401	u8 ReplayCounter[8];
1402	u8 ANonce[32];	/* ANonce for WPA-PSK from aurhenticator */
1403	u8 SNonce[32];	/* SNonce for WPA-PSK */
1404
1405	u8 LastSNR0;		/* last received BEACON's SNR */
1406	u8 LastSNR1;		/* last received BEACON's SNR for 2nd  antenna */
1407	struct rt_rssi_sample RssiSample;
1408	unsigned long NumOfAvgRssiSample;
1409
1410	unsigned long LastBeaconRxTime;	/* OS's timestamp of the last BEACON RX time */
1411	unsigned long Last11bBeaconRxTime;	/* OS's timestamp of the last 11B BEACON RX time */
1412	unsigned long Last11gBeaconRxTime;	/* OS's timestamp of the last 11G BEACON RX time */
1413	unsigned long Last20NBeaconRxTime;	/* OS's timestamp of the last 20MHz N BEACON RX time */
1414
1415	unsigned long LastScanTime;	/* Record last scan time for issue BSSID_SCAN_LIST */
1416	unsigned long ScanCnt;		/* Scan counts since most recent SSID, BSSID, SCAN OID request */
1417	BOOLEAN bSwRadio;	/* Software controlled Radio On/Off, TRUE: On */
1418	BOOLEAN bHwRadio;	/* Hardware controlled Radio On/Off, TRUE: On */
1419	BOOLEAN bRadio;		/* Radio state, And of Sw & Hw radio state */
1420	BOOLEAN bHardwareRadio;	/* Hardware controlled Radio enabled */
1421	BOOLEAN bShowHiddenSSID;	/* Show all known SSID in SSID list get operation */
1422
1423	/* New for WPA, windows want us to keep association information and */
1424	/* Fixed IEs from last association response */
1425	struct rt_ndis_802_11_association_information AssocInfo;
1426	u16 ReqVarIELen;	/* Length of next VIE include EID & Length */
1427	u8 ReqVarIEs[MAX_VIE_LEN];	/* The content saved here should be little-endian format. */
1428	u16 ResVarIELen;	/* Length of next VIE include EID & Length */
1429	u8 ResVarIEs[MAX_VIE_LEN];
1430
1431	u8 RSNIE_Len;
1432	u8 RSN_IE[MAX_LEN_OF_RSNIE];	/* The content saved here should be little-endian format. */
1433
1434	unsigned long CLBusyBytes;	/* Save the total bytes received durning channel load scan time */
1435	u16 RPIDensity[8];	/* Array for RPI density collection */
1436
1437	u8 RMReqCnt;		/* Number of measurement request saved. */
1438	u8 CurrentRMReqIdx;	/* Number of measurement request saved. */
1439	BOOLEAN ParallelReq;	/* Parallel measurement, only one request performed, */
1440	/* It must be the same channel with maximum duration */
1441	u16 ParallelDuration;	/* Maximum duration for parallel measurement */
1442	u8 ParallelChannel;	/* Only one channel with parallel measurement */
1443	u16 IAPPToken;	/* IAPP dialog token */
1444	/* Hack for channel load and noise histogram parameters */
1445	u8 NHFactor;		/* Parameter for Noise histogram */
1446	u8 CLFactor;		/* Parameter for channel load */
1447
1448	struct rt_ralink_timer StaQuickResponeForRateUpTimer;
1449	BOOLEAN StaQuickResponeForRateUpTimerRunning;
1450
1451	u8 DtimCount;	/* 0.. DtimPeriod-1 */
1452	u8 DtimPeriod;	/* default = 3 */
1453
1454	/*////////////////////////////////////////////////////////////////////////////////////// */
1455	/* This is only for WHQL test. */
1456	BOOLEAN WhqlTest;
1457	/*////////////////////////////////////////////////////////////////////////////////////// */
1458
1459	struct rt_ralink_timer WpaDisassocAndBlockAssocTimer;
1460	/* Fast Roaming */
1461	BOOLEAN bAutoRoaming;	/* 0:disable auto roaming by RSSI, 1:enable auto roaming by RSSI */
1462	char dBmToRoam;		/* the condition to roam when receiving Rssi less than this value. It's negative value. */
1463
1464	BOOLEAN IEEE8021X;
1465	BOOLEAN IEEE8021x_required_keys;
1466	struct rt_cipher_key DesireSharedKey[4];	/* Record user desired WEP keys */
1467	u8 DesireSharedKeyId;
1468
1469	/* 0: driver ignores wpa_supplicant */
1470	/* 1: wpa_supplicant initiates scanning and AP selection */
1471	/* 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters */
1472	u8 WpaSupplicantUP;
1473	u8 WpaSupplicantScanCount;
1474	BOOLEAN bRSN_IE_FromWpaSupplicant;
1475
1476	char dev_name[16];
1477	u16 OriDevType;
1478
1479	BOOLEAN bTGnWifiTest;
1480	BOOLEAN bScanReqIsFromWebUI;
1481
1482	HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;	/* For transmit phy setting in TXWI. */
1483	DESIRED_TRANSMIT_SETTING DesiredTransmitSetting;
1484	struct rt_ht_phy_info DesiredHtPhyInfo;
1485	BOOLEAN bAutoTxRateSwitch;
1486
1487#ifdef RTMP_MAC_PCI
1488	u8 BBPR3;
1489	/* PS Control has 2 meanings for advanced power save function. */
1490	/* 1. EnablePSinIdle : When no connection, always radio off except need to do site survey. */
1491	/* 2. EnableNewPS  : will save more current in sleep or radio off mode. */
1492	PS_CONTROL PSControl;
1493#endif				/* RTMP_MAC_PCI // */
1494
1495	BOOLEAN bAutoConnectByBssid;
1496	unsigned long BeaconLostTime;	/* seconds */
1497	BOOLEAN bForceTxBurst;	/* 1: force enble TX PACKET BURST, 0: disable */
1498};
1499
1500/* This data structure keep the current active BSS/IBSS's configuration that this STA */
1501/* had agreed upon joining the network. Which means these parameters are usually decided */
1502/* by the BSS/IBSS creator instead of user configuration. Data in this data structurre */
1503/* is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE. */
1504/* Normally, after SCAN or failed roaming attempts, we need to recover back to */
1505/* the current active settings. */
1506struct rt_sta_active_config {
1507	u16 Aid;
1508	u16 AtimWin;		/* in kusec; IBSS parameter set element */
1509	u16 CapabilityInfo;
1510	u16 CfpMaxDuration;
1511	u16 CfpPeriod;
1512
1513	/* Copy supported rate from desired AP's beacon. We are trying to match */
1514	/* AP's supported and extended rate settings. */
1515	u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
1516	u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1517	u8 SupRateLen;
1518	u8 ExtRateLen;
1519	/* Copy supported ht from desired AP's beacon. We are trying to match */
1520	struct rt_ht_phy_info SupportedPhyInfo;
1521	struct rt_ht_capability SupportedHtPhy;
1522};
1523
1524struct rt_mac_table_entry;
1525
1526struct rt_mac_table_entry {
1527	/*Choose 1 from ValidAsWDS and ValidAsCLI  to validize. */
1528	BOOLEAN ValidAsCLI;	/* Sta mode, set this TRUE after Linkup,too. */
1529	BOOLEAN ValidAsWDS;	/* This is WDS Entry. only for AP mode. */
1530	BOOLEAN ValidAsApCli;	/*This is a AP-Client entry, only for AP mode which enable AP-Client functions. */
1531	BOOLEAN ValidAsMesh;
1532	BOOLEAN ValidAsDls;	/* This is DLS Entry. only for STA mode. */
1533	BOOLEAN isCached;
1534	BOOLEAN bIAmBadAtheros;	/* Flag if this is Atheros chip that has IOT problem.  We need to turn on RTS/CTS protection. */
1535
1536	u8 EnqueueEapolStartTimerRunning;	/* Enqueue EAPoL-Start for triggering EAP SM */
1537	/*jan for wpa */
1538	/* record which entry revoke MIC Failure , if it leaves the BSS itself, AP won't update aMICFailTime MIB */
1539	u8 CMTimerRunning;
1540	u8 apidx;		/* MBSS number */
1541	u8 RSNIE_Len;
1542	u8 RSN_IE[MAX_LEN_OF_RSNIE];
1543	u8 ANonce[LEN_KEY_DESC_NONCE];
1544	u8 SNonce[LEN_KEY_DESC_NONCE];
1545	u8 R_Counter[LEN_KEY_DESC_REPLAY];
1546	u8 PTK[64];
1547	u8 ReTryCounter;
1548	struct rt_ralink_timer RetryTimer;
1549	struct rt_ralink_timer EnqueueStartForPSKTimer;	/* A timer which enqueue EAPoL-Start for triggering PSK SM */
1550	NDIS_802_11_AUTHENTICATION_MODE AuthMode;	/* This should match to whatever microsoft defined */
1551	NDIS_802_11_WEP_STATUS WepStatus;
1552	NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
1553	AP_WPA_STATE WpaState;
1554	GTK_STATE GTKState;
1555	u16 PortSecured;
1556	NDIS_802_11_PRIVACY_FILTER PrivacyFilter;	/* PrivacyFilter enum for 802.1X */
1557	struct rt_cipher_key PairwiseKey;
1558	void *pAd;
1559	int PMKID_CacheIdx;
1560	u8 PMKID[LEN_PMKID];
1561
1562	u8 Addr[MAC_ADDR_LEN];
1563	u8 PsMode;
1564	SST Sst;
1565	AUTH_STATE AuthState;	/* for SHARED KEY authentication state machine used only */
1566	BOOLEAN IsReassocSta;	/* Indicate whether this is a reassociation procedure */
1567	u16 Aid;
1568	u16 CapabilityInfo;
1569	u8 LastRssi;
1570	unsigned long NoDataIdleCount;
1571	u16 StationKeepAliveCount;	/* unit: second */
1572	unsigned long PsQIdleCount;
1573	struct rt_queue_header PsQueue;
1574
1575	u32 StaConnectTime;	/* the live time of this station since associated with AP */
1576
1577	BOOLEAN bSendBAR;
1578	u16 NoBADataCountDown;
1579
1580	u32 CachedBuf[16];	/* u32 (4 bytes) for alignment */
1581	u32 TxBFCount;		/* 3*3 */
1582	u32 FIFOCount;
1583	u32 DebugFIFOCount;
1584	u32 DebugTxCount;
1585	BOOLEAN bDlsInit;
1586
1587/*==================================================== */
1588/*WDS entry needs these */
1589/* if ValidAsWDS==TRUE, MatchWDSTabIdx is the index in WdsTab.MacTab */
1590	u32 MatchWDSTabIdx;
1591	u8 MaxSupportedRate;
1592	u8 CurrTxRate;
1593	u8 CurrTxRateIndex;
1594	/* to record the each TX rate's quality. 0 is best, the bigger the worse. */
1595	u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
1596/*      u16          OneSecTxOkCount; */
1597	u32 OneSecTxNoRetryOkCount;
1598	u32 OneSecTxRetryOkCount;
1599	u32 OneSecTxFailCount;
1600	u32 ContinueTxFailCnt;
1601	u32 CurrTxRateStableTime;	/* # of second in current TX rate */
1602	u8 TxRateUpPenalty;	/* extra # of second penalty due to last unstable condition */
1603/*==================================================== */
1604
1605	BOOLEAN fNoisyEnvironment;
1606	BOOLEAN fLastSecAccordingRSSI;
1607	u8 LastSecTxRateChangeAction;	/* 0: no change, 1:rate UP, 2:rate down */
1608	char LastTimeTxRateChangeAction;	/*Keep last time value of LastSecTxRateChangeAction */
1609	unsigned long LastTxOkCount;
1610	u8 PER[MAX_STEP_OF_TX_RATE_SWITCH];
1611
1612	/* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */
1613	/* BOOLEAN control, either ON or OFF. These flags should always be accessed via */
1614	/* CLIENT_STATUS_TEST_FLAG(), CLIENT_STATUS_SET_FLAG(), CLIENT_STATUS_CLEAR_FLAG() macros. */
1615	/* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition. fCLIENT_STATUS_AMSDU_INUSED */
1616	unsigned long ClientStatusFlags;
1617
1618	HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;	/* For transmit phy setting in TXWI. */
1619
1620	/* HT EWC MIMO-N used parameters */
1621	u16 RXBAbitmap;	/* fill to on-chip  RXWI_BA_BITMASK in 8.1.3RX attribute entry format */
1622	u16 TXBAbitmap;	/* This bitmap as originator, only keep in software used to mark AMPDU bit in TXWI */
1623	u16 TXAutoBAbitmap;
1624	u16 BADeclineBitmap;
1625	u16 BARecWcidArray[NUM_OF_TID];	/* The mapping wcid of recipient session. if RXBAbitmap bit is masked */
1626	u16 BAOriWcidArray[NUM_OF_TID];	/* The mapping wcid of originator session. if TXBAbitmap bit is masked */
1627	u16 BAOriSequence[NUM_OF_TID];	/* The mapping wcid of originator session. if TXBAbitmap bit is masked */
1628
1629	/* 802.11n features. */
1630	u8 MpduDensity;
1631	u8 MaxRAmpduFactor;
1632	u8 AMsduSize;
1633	u8 MmpsMode;		/* MIMO power save more. */
1634
1635	struct rt_ht_capability_ie HTCapability;
1636
1637	BOOLEAN bAutoTxRateSwitch;
1638
1639	u8 RateLen;
1640	struct rt_mac_table_entry *pNext;
1641	u16 TxSeq[NUM_OF_TID];
1642	u16 NonQosDataSeq;
1643
1644	struct rt_rssi_sample RssiSample;
1645
1646	u32 TXMCSExpected[16];
1647	u32 TXMCSSuccessful[16];
1648	u32 TXMCSFailed[16];
1649	u32 TXMCSAutoFallBack[16][16];
1650
1651	unsigned long LastBeaconRxTime;
1652
1653	unsigned long AssocDeadLine;
1654};
1655
1656struct rt_mac_table {
1657	u16 Size;
1658	struct rt_mac_table_entry *Hash[HASH_TABLE_SIZE];
1659	struct rt_mac_table_entry Content[MAX_LEN_OF_MAC_TABLE];
1660	struct rt_queue_header McastPsQueue;
1661	unsigned long PsQIdleCount;
1662	BOOLEAN fAnyStationInPsm;
1663	BOOLEAN fAnyStationBadAtheros;	/* Check if any Station is atheros 802.11n Chip.  We need to use RTS/CTS with Atheros 802,.11n chip. */
1664	BOOLEAN fAnyTxOPForceDisable;	/* Check if it is necessary to disable BE TxOP */
1665	BOOLEAN fAllStationAsRalink;	/* Check if all stations are ralink-chipset */
1666	BOOLEAN fAnyStationIsLegacy;	/* Check if I use legacy rate to transmit to my BSS Station/ */
1667	BOOLEAN fAnyStationNonGF;	/* Check if any Station can't support GF. */
1668	BOOLEAN fAnyStation20Only;	/* Check if any Station can't support GF. */
1669	BOOLEAN fAnyStationMIMOPSDynamic;	/* Check if any Station is MIMO Dynamic */
1670	BOOLEAN fAnyBASession;	/* Check if there is BA session.  Force turn on RTS/CTS */
1671/*2008/10/28: KH add to support Antenna power-saving of AP<-- */
1672/*2008/10/28: KH add to support Antenna power-saving of AP--> */
1673};
1674
1675struct wificonf {
1676	BOOLEAN bShortGI;
1677	BOOLEAN bGreenField;
1678};
1679
1680struct rt_rtmp_dev_info {
1681	u8 chipName[16];
1682	RTMP_INF_TYPE infType;
1683};
1684
1685struct rt_rtmp_chip_op {
1686	/*  Calibration access related callback functions */
1687	int (*eeinit) (struct rt_rtmp_adapter *pAd);	/* int (*eeinit)(struct rt_rtmp_adapter *pAd); */
1688	int (*eeread) (struct rt_rtmp_adapter *pAd, u16 offset, u16 *pValue);	/* int (*eeread)(struct rt_rtmp_adapter *pAd, int offset, u16 *pValue); */
1689
1690	/* MCU related callback functions */
1691	int (*loadFirmware) (struct rt_rtmp_adapter *pAd);	/* int (*loadFirmware)(struct rt_rtmp_adapter *pAd); */
1692	int (*eraseFirmware) (struct rt_rtmp_adapter *pAd);	/* int (*eraseFirmware)(struct rt_rtmp_adapter *pAd); */
1693	int (*sendCommandToMcu) (struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1);;	/* int (*sendCommandToMcu)(struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1); */
1694
1695	/* RF access related callback functions */
1696	struct rt_reg_pair *pRFRegTable;
1697	void (*AsicRfInit) (struct rt_rtmp_adapter *pAd);
1698	void (*AsicRfTurnOn) (struct rt_rtmp_adapter *pAd);
1699	void (*AsicRfTurnOff) (struct rt_rtmp_adapter *pAd);
1700	void (*AsicReverseRfFromSleepMode) (struct rt_rtmp_adapter *pAd);
1701	void (*AsicHaltAction) (struct rt_rtmp_adapter *pAd);
1702};
1703
1704/* */
1705/*  The miniport adapter structure */
1706/* */
1707struct rt_rtmp_adapter {
1708	void *OS_Cookie;	/* save specific structure relative to OS */
1709	struct net_device *net_dev;
1710	unsigned long VirtualIfCnt;
1711	const struct firmware *firmware;
1712
1713	struct rt_rtmp_chip_op chipOps;
1714	u16 ThisTbttNumToNextWakeUp;
1715
1716#ifdef RTMP_MAC_PCI
1717/*****************************************************************************************/
1718/*      PCI related parameters																  */
1719/*****************************************************************************************/
1720	u8 *CSRBaseAddress;	/* PCI MMIO Base Address, all access will use */
1721	unsigned int irq_num;
1722
1723	u16 LnkCtrlBitMask;
1724	u16 RLnkCtrlConfiguration;
1725	u16 RLnkCtrlOffset;
1726	u16 HostLnkCtrlConfiguration;
1727	u16 HostLnkCtrlOffset;
1728	u16 PCIePowerSaveLevel;
1729	unsigned long Rt3xxHostLinkCtrl;	/* USed for 3090F chip */
1730	unsigned long Rt3xxRalinkLinkCtrl;	/* USed for 3090F chip */
1731	u16 DeviceID;	/* Read from PCI config */
1732	unsigned long AccessBBPFailCount;
1733	BOOLEAN bPCIclkOff;	/* flag that indicate if the PICE power status in Configuration SPace.. */
1734	BOOLEAN bPCIclkOffDisableTx;	/* */
1735
1736	BOOLEAN brt30xxBanMcuCmd;	/*when = 0xff means all commands are ok to set . */
1737	BOOLEAN b3090ESpecialChip;	/*3090E special chip that write EEPROM 0x24=0x9280. */
1738	unsigned long CheckDmaBusyCount;	/* Check Interrupt Status Register Count. */
1739
1740	u32 int_enable_reg;
1741	u32 int_disable_mask;
1742	u32 int_pending;
1743
1744	struct rt_rtmp_dmabuf TxBufSpace[NUM_OF_TX_RING];	/* Shared memory of all 1st pre-allocated TxBuf associated with each TXD */
1745	struct rt_rtmp_dmabuf RxDescRing;	/* Shared memory for RX descriptors */
1746	struct rt_rtmp_dmabuf TxDescRing[NUM_OF_TX_RING];	/* Shared memory for Tx descriptors */
1747	struct rt_rtmp_tx_ring TxRing[NUM_OF_TX_RING];	/* AC0~4 + HCCA */
1748#endif				/* RTMP_MAC_PCI // */
1749
1750	spinlock_t irq_lock;
1751	u8 irq_disabled;
1752
1753#ifdef RTMP_MAC_USB
1754/*****************************************************************************************/
1755/*      USB related parameters                                                           */
1756/*****************************************************************************************/
1757	struct usb_config_descriptor *config;
1758	u32 BulkInEpAddr;	/* bulk-in endpoint address */
1759	u32 BulkOutEpAddr[6];	/* bulk-out endpoint address */
1760
1761	u32 NumberOfPipes;
1762	u16 BulkOutMaxPacketSize;
1763	u16 BulkInMaxPacketSize;
1764
1765	/*======Control Flags */
1766	long PendingIoCount;
1767	unsigned long BulkFlags;
1768	BOOLEAN bUsbTxBulkAggre;	/* Flags for bulk out data priority */
1769
1770	/*======Cmd Thread */
1771	struct rt_cmdq CmdQ;
1772	spinlock_t CmdQLock;	/* CmdQLock spinlock */
1773	struct rt_rtmp_os_task cmdQTask;
1774
1775	/*======Semaphores (event) */
1776	struct semaphore UsbVendorReq_semaphore;
1777	void *UsbVendorReqBuf;
1778	wait_queue_head_t *wait;
1779#endif				/* RTMP_MAC_USB // */
1780
1781/*****************************************************************************************/
1782/*      RBUS related parameters																  */
1783/*****************************************************************************************/
1784
1785/*****************************************************************************************/
1786/*      Both PCI/USB related parameters														  */
1787/*****************************************************************************************/
1788	/*struct rt_rtmp_dev_info                 chipInfo; */
1789	RTMP_INF_TYPE infType;
1790
1791/*****************************************************************************************/
1792/*      Driver Mgmt related parameters														  */
1793/*****************************************************************************************/
1794	struct rt_rtmp_os_task mlmeTask;
1795#ifdef RTMP_TIMER_TASK_SUPPORT
1796	/* If you want use timer task to handle the timer related jobs, enable this. */
1797	struct rt_rtmp_timer_task_queue TimerQ;
1798	spinlock_t TimerQLock;
1799	struct rt_rtmp_os_task timerTask;
1800#endif				/* RTMP_TIMER_TASK_SUPPORT // */
1801
1802/*****************************************************************************************/
1803/*      Tx related parameters                                                           */
1804/*****************************************************************************************/
1805	BOOLEAN DeQueueRunning[NUM_OF_TX_RING];	/* for ensuring RTUSBDeQueuePacket get call once */
1806	spinlock_t DeQueueLock[NUM_OF_TX_RING];
1807
1808#ifdef RTMP_MAC_USB
1809	/* Data related context and AC specified, 4 AC supported */
1810	spinlock_t BulkOutLock[6];	/* BulkOut spinlock for 4 ACs */
1811	spinlock_t MLMEBulkOutLock;	/* MLME BulkOut lock */
1812
1813	struct rt_ht_tx_context TxContext[NUM_OF_TX_RING];
1814	spinlock_t TxContextQueueLock[NUM_OF_TX_RING];	/* TxContextQueue spinlock */
1815
1816	/* 4 sets of Bulk Out index and pending flag */
1817	u8 NextBulkOutIndex[4];	/* only used for 4 EDCA bulkout pipe */
1818
1819	BOOLEAN BulkOutPending[6];	/* used for total 6 bulkout pipe */
1820	u8 bulkResetPipeid;
1821	BOOLEAN MgmtBulkPending;
1822	unsigned long bulkResetReq[6];
1823#endif				/* RTMP_MAC_USB // */
1824
1825	/* resource for software backlog queues */
1826	struct rt_queue_header TxSwQueue[NUM_OF_TX_RING];	/* 4 AC + 1 HCCA */
1827	spinlock_t TxSwQueueLock[NUM_OF_TX_RING];	/* TxSwQueue spinlock */
1828
1829	struct rt_rtmp_dmabuf MgmtDescRing;	/* Shared memory for MGMT descriptors */
1830	struct rt_rtmp_mgmt_ring MgmtRing;
1831	spinlock_t MgmtRingLock;	/* Prio Ring spinlock */
1832
1833/*****************************************************************************************/
1834/*      Rx related parameters                                                           */
1835/*****************************************************************************************/
1836
1837#ifdef RTMP_MAC_PCI
1838	struct rt_rtmp_rx_ring RxRing;
1839	spinlock_t RxRingLock;	/* Rx Ring spinlock */
1840#ifdef RT3090
1841	spinlock_t McuCmdLock;	/*MCU Command Queue spinlock */
1842#endif				/* RT3090 // */
1843#endif				/* RTMP_MAC_PCI // */
1844#ifdef RTMP_MAC_USB
1845	struct rt_rx_context RxContext[RX_RING_SIZE];	/* 1 for redundant multiple IRP bulk in. */
1846	spinlock_t BulkInLock;	/* BulkIn spinlock for 4 ACs */
1847	u8 PendingRx;	/* The Maximum pending Rx value should be       RX_RING_SIZE. */
1848	u8 NextRxBulkInIndex;	/* Indicate the current RxContext Index which hold by Host controller. */
1849	u8 NextRxBulkInReadIndex;	/* Indicate the current RxContext Index which driver can read & process it. */
1850	unsigned long NextRxBulkInPosition;	/* Want to contatenate 2 URB buffer while 1st is bulkin failed URB. This Position is 1st URB TransferLength. */
1851	unsigned long TransferBufferLength;	/* current length of the packet buffer */
1852	unsigned long ReadPosition;	/* current read position in a packet buffer */
1853#endif				/* RTMP_MAC_USB // */
1854
1855/*****************************************************************************************/
1856/*      ASIC related parameters                                                          */
1857/*****************************************************************************************/
1858	u32 MACVersion;	/* MAC version. Record rt2860C(0x28600100) or rt2860D (0x28600101).. */
1859
1860	/* --------------------------- */
1861	/* E2PROM */
1862	/* --------------------------- */
1863	unsigned long EepromVersion;	/* byte 0: version, byte 1: revision, byte 2~3: unused */
1864	unsigned long FirmwareVersion;	/* byte 0: Minor version, byte 1: Major version, otherwise unused. */
1865	u16 EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
1866	u8 EEPROMAddressNum;	/* 93c46=6  93c66=8 */
1867	BOOLEAN EepromAccess;
1868	u8 EFuseTag;
1869
1870	/* --------------------------- */
1871	/* BBP Control */
1872	/* --------------------------- */
1873	u8 BbpWriteLatch[140];	/* record last BBP register value written via BBP_IO_WRITE/BBP_IO_WRITE_VY_REG_ID */
1874	char BbpRssiToDbmDelta;	/* change from u8 to char for high power */
1875	struct rt_bbp_r66_tuning BbpTuning;
1876
1877	/* ---------------------------- */
1878	/* RFIC control */
1879	/* ---------------------------- */
1880	u8 RfIcType;		/* RFIC_xxx */
1881	unsigned long RfFreqOffset;	/* Frequency offset for channel switching */
1882	struct rt_rtmp_rf_regs LatchRfRegs;	/* latch th latest RF programming value since RF IC doesn't support READ */
1883
1884	EEPROM_ANTENNA_STRUC Antenna;	/* Since ANtenna definition is different for a & g. We need to save it for future reference. */
1885	EEPROM_NIC_CONFIG2_STRUC NicConfig2;
1886
1887	/* This soft Rx Antenna Diversity mechanism is used only when user set */
1888	/* RX Antenna = DIVERSITY ON */
1889	struct rt_soft_rx_ant_diversity RxAnt;
1890
1891	u8 RFProgSeq;
1892	struct rt_channel_tx_power TxPower[MAX_NUM_OF_CHANNELS];	/* Store Tx power value for all channels. */
1893	struct rt_channel_tx_power ChannelList[MAX_NUM_OF_CHANNELS];	/* list all supported channels for site survey */
1894	struct rt_channel_11j_tx_power TxPower11J[MAX_NUM_OF_11JCHANNELS];	/* 802.11j channel and bw */
1895	struct rt_channel_11j_tx_power ChannelList11J[MAX_NUM_OF_11JCHANNELS];	/* list all supported channels for site survey */
1896
1897	u8 ChannelListNum;	/* number of channel in ChannelList[] */
1898	u8 Bbp94;
1899	BOOLEAN BbpForCCK;
1900	unsigned long Tx20MPwrCfgABand[5];
1901	unsigned long Tx20MPwrCfgGBand[5];
1902	unsigned long Tx40MPwrCfgABand[5];
1903	unsigned long Tx40MPwrCfgGBand[5];
1904
1905	BOOLEAN bAutoTxAgcA;	/* Enable driver auto Tx Agc control */
1906	u8 TssiRefA;		/* Store Tssi reference value as 25 temperature. */
1907	u8 TssiPlusBoundaryA[5];	/* Tssi boundary for increase Tx power to compensate. */
1908	u8 TssiMinusBoundaryA[5];	/* Tssi boundary for decrease Tx power to compensate. */
1909	u8 TxAgcStepA;	/* Store Tx TSSI delta increment / decrement value */
1910	char TxAgcCompensateA;	/* Store the compensation (TxAgcStep * (idx-1)) */
1911
1912	BOOLEAN bAutoTxAgcG;	/* Enable driver auto Tx Agc control */
1913	u8 TssiRefG;		/* Store Tssi reference value as 25 temperature. */
1914	u8 TssiPlusBoundaryG[5];	/* Tssi boundary for increase Tx power to compensate. */
1915	u8 TssiMinusBoundaryG[5];	/* Tssi boundary for decrease Tx power to compensate. */
1916	u8 TxAgcStepG;	/* Store Tx TSSI delta increment / decrement value */
1917	char TxAgcCompensateG;	/* Store the compensation (TxAgcStep * (idx-1)) */
1918
1919	char BGRssiOffset0;	/* Store B/G RSSI#0 Offset value on EEPROM 0x46h */
1920	char BGRssiOffset1;	/* Store B/G RSSI#1 Offset value */
1921	char BGRssiOffset2;	/* Store B/G RSSI#2 Offset value */
1922
1923	char ARssiOffset0;	/* Store A RSSI#0 Offset value on EEPROM 0x4Ah */
1924	char ARssiOffset1;	/* Store A RSSI#1 Offset value */
1925	char ARssiOffset2;	/* Store A RSSI#2 Offset value */
1926
1927	char BLNAGain;		/* Store B/G external LNA#0 value on EEPROM 0x44h */
1928	char ALNAGain0;		/* Store A external LNA#0 value for ch36~64 */
1929	char ALNAGain1;		/* Store A external LNA#1 value for ch100~128 */
1930	char ALNAGain2;		/* Store A external LNA#2 value for ch132~165 */
1931#ifdef RT30xx
1932	/* for 3572 */
1933	u8 Bbp25;
1934	u8 Bbp26;
1935
1936	u8 TxMixerGain24G;	/* Tx mixer gain value from EEPROM to improve Tx EVM / Tx DAC, 2.4G */
1937	u8 TxMixerGain5G;
1938#endif				/* RT30xx // */
1939	/* ---------------------------- */
1940	/* LED control */
1941	/* ---------------------------- */
1942	MCU_LEDCS_STRUC LedCntl;
1943	u16 Led1;		/* read from EEPROM 0x3c */
1944	u16 Led2;		/* EEPROM 0x3e */
1945	u16 Led3;		/* EEPROM 0x40 */
1946	u8 LedIndicatorStrength;
1947	u8 RssiSingalstrengthOffet;
1948	BOOLEAN bLedOnScanning;
1949	u8 LedStatus;
1950
1951/*****************************************************************************************/
1952/*      802.11 related parameters                                                        */
1953/*****************************************************************************************/
1954	/* outgoing BEACON frame buffer and corresponding TXD */
1955	struct rt_txwi BeaconTxWI;
1956	u8 *BeaconBuf;
1957	u16 BeaconOffset[HW_BEACON_MAX_COUNT];
1958
1959	/* pre-build PS-POLL and NULL frame upon link up. for efficiency purpose. */
1960	struct rt_pspoll_frame PsPollFrame;
1961	struct rt_header_802_11 NullFrame;
1962
1963#ifdef RTMP_MAC_USB
1964	struct rt_tx_context BeaconContext[BEACON_RING_SIZE];
1965	struct rt_tx_context NullContext;
1966	struct rt_tx_context PsPollContext;
1967	struct rt_tx_context RTSContext;
1968#endif				/* RTMP_MAC_USB // */
1969
1970/*=========AP=========== */
1971
1972/*=======STA=========== */
1973	/* ----------------------------------------------- */
1974	/* STA specific configuration & operation status */
1975	/* used only when pAd->OpMode == OPMODE_STA */
1976	/* ----------------------------------------------- */
1977	struct rt_sta_admin_config StaCfg;	/* user desired settings */
1978	struct rt_sta_active_config StaActive;	/* valid only when ADHOC_ON(pAd) || INFRA_ON(pAd) */
1979	char nickname[IW_ESSID_MAX_SIZE + 1];	/* nickname, only used in the iwconfig i/f */
1980	int PreMediaState;
1981
1982/*=======Common=========== */
1983	/* OP mode: either AP or STA */
1984	u8 OpMode;		/* OPMODE_STA, OPMODE_AP */
1985
1986	int IndicateMediaState;	/* Base on Indication state, default is NdisMediaStateDisConnected */
1987
1988	/* MAT related parameters */
1989
1990	/* configuration: read from Registry & E2PROM */
1991	BOOLEAN bLocalAdminMAC;	/* Use user changed MAC */
1992	u8 PermanentAddress[MAC_ADDR_LEN];	/* Factory default MAC address */
1993	u8 CurrentAddress[MAC_ADDR_LEN];	/* User changed MAC address */
1994
1995	/* ------------------------------------------------------ */
1996	/* common configuration to both OPMODE_STA and OPMODE_AP */
1997	/* ------------------------------------------------------ */
1998	struct rt_common_config CommonCfg;
1999	struct rt_mlme Mlme;
2000
2001	/* AP needs those vaiables for site survey feature. */
2002	struct rt_mlme_aux MlmeAux;	/* temporary settings used during MLME state machine */
2003	struct rt_bss_table ScanTab;	/* store the latest SCAN result */
2004
2005	/*About MacTab, the sta driver will use #0 and #1 for multicast and AP. */
2006	struct rt_mac_table MacTab;	/* ASIC on-chip WCID entry table.  At TX, ASIC always use key according to this on-chip table. */
2007	spinlock_t MacTabLock;
2008
2009	struct rt_ba_table BATable;
2010
2011	spinlock_t BATabLock;
2012	struct rt_ralink_timer RECBATimer;
2013
2014	/* encryption/decryption KEY tables */
2015	struct rt_cipher_key SharedKey[MAX_MBSSID_NUM][4];	/* STA always use SharedKey[BSS0][0..3] */
2016
2017	/* RX re-assembly buffer for fragmentation */
2018	struct rt_fragment_frame FragFrame;	/* Frame storage for fragment frame */
2019
2020	/* various Counters */
2021	struct rt_counter_802_3 Counters8023;	/* 802.3 counters */
2022	struct rt_counter_802_11 WlanCounters;	/* 802.11 MIB counters */
2023	struct rt_counter_ralink RalinkCounters;	/* Ralink propriety counters */
2024	struct rt_counter_drs DrsCounters;	/* counters for Dynamic TX Rate Switching */
2025	struct rt_private PrivateInfo;	/* Private information & counters */
2026
2027	/* flags, see fRTMP_ADAPTER_xxx flags */
2028	unsigned long Flags;		/* Represent current device status */
2029	unsigned long PSFlags;		/* Power Save operation flag. */
2030
2031	/* current TX sequence # */
2032	u16 Sequence;
2033
2034	/* Control disconnect / connect event generation */
2035	/*+++Didn't used anymore */
2036	unsigned long LinkDownTime;
2037	/*--- */
2038	unsigned long LastRxRate;
2039	unsigned long LastTxRate;
2040	/*+++Used only for Station */
2041	BOOLEAN bConfigChanged;	/* Config Change flag for the same SSID setting */
2042	/*--- */
2043
2044	unsigned long ExtraInfo;	/* Extra information for displaying status */
2045	unsigned long SystemErrorBitmap;	/* b0: E2PROM version error */
2046
2047	/*+++Didn't used anymore */
2048	unsigned long MacIcVersion;	/* MAC/BBP serial interface issue solved after ver.D */
2049	/*--- */
2050
2051	/* --------------------------- */
2052	/* System event log */
2053	/* --------------------------- */
2054	struct rt_802_11_event_table EventTab;
2055
2056	BOOLEAN HTCEnable;
2057
2058	/*****************************************************************************************/
2059	/*      Statistic related parameters                                                     */
2060	/*****************************************************************************************/
2061#ifdef RTMP_MAC_USB
2062	unsigned long BulkOutDataOneSecCount;
2063	unsigned long BulkInDataOneSecCount;
2064	unsigned long BulkLastOneSecCount;	/* BulkOutDataOneSecCount + BulkInDataOneSecCount */
2065	unsigned long watchDogRxCnt;
2066	unsigned long watchDogRxOverFlowCnt;
2067	unsigned long watchDogTxPendingCnt[NUM_OF_TX_RING];
2068	int TransferedLength[NUM_OF_TX_RING];
2069#endif				/* RTMP_MAC_USB // */
2070
2071	BOOLEAN bUpdateBcnCntDone;
2072	unsigned long watchDogMacDeadlock;	/* prevent MAC/BBP into deadlock condition */
2073	/* ---------------------------- */
2074	/* DEBUG paramerts */
2075	/* ---------------------------- */
2076	/*unsigned long         DebugSetting[4]; */
2077	BOOLEAN bBanAllBaSetup;
2078	BOOLEAN bPromiscuous;
2079
2080	/* ---------------------------- */
2081	/* rt2860c emulation-use Parameters */
2082	/* ---------------------------- */
2083	/*unsigned long         rtsaccu[30]; */
2084	/*unsigned long         ctsaccu[30]; */
2085	/*unsigned long         cfendaccu[30]; */
2086	/*unsigned long         bacontent[16]; */
2087	/*unsigned long         rxint[RX_RING_SIZE+1]; */
2088	/*u8         rcvba[60]; */
2089	BOOLEAN bLinkAdapt;
2090	BOOLEAN bForcePrintTX;
2091	BOOLEAN bForcePrintRX;
2092	/*BOOLEAN               bDisablescanning;               //defined in RT2870 USB */
2093	BOOLEAN bStaFifoTest;
2094	BOOLEAN bProtectionTest;
2095	BOOLEAN bBroadComHT;
2096	/*+++Following add from RT2870 USB. */
2097	unsigned long BulkOutReq;
2098	unsigned long BulkOutComplete;
2099	unsigned long BulkOutCompleteOther;
2100	unsigned long BulkOutCompleteCancel;	/* seems not use now? */
2101	unsigned long BulkInReq;
2102	unsigned long BulkInComplete;
2103	unsigned long BulkInCompleteFail;
2104	/*--- */
2105
2106	struct wificonf WIFItestbed;
2107
2108	struct reordering_mpdu_pool mpdu_blk_pool;
2109
2110	unsigned long OneSecondnonBEpackets;	/* record non BE packets per second */
2111
2112	struct iw_statistics iw_stats;
2113
2114	struct net_device_stats stats;
2115
2116	unsigned long TbttTickCount;
2117#ifdef PCI_MSI_SUPPORT
2118	BOOLEAN HaveMsi;
2119#endif				/* PCI_MSI_SUPPORT // */
2120
2121	u8 is_on;
2122
2123#define TIME_BASE			(1000000/OS_HZ)
2124#define TIME_ONE_SECOND		(1000000/TIME_BASE)
2125	u8 flg_be_adjust;
2126	unsigned long be_adjust_last_time;
2127
2128	u8 FlgCtsEnabled;
2129	u8 PM_FlgSuspend;
2130
2131#ifdef RT30xx
2132#ifdef RTMP_EFUSE_SUPPORT
2133	BOOLEAN bUseEfuse;
2134	u8 EEPROMImage[1024];
2135#endif				/* RTMP_EFUSE_SUPPORT // */
2136#endif				/* RT30xx // */
2137};
2138
2139#define DELAYINTMASK		0x0003fffb
2140#define INTMASK				0x0003fffb
2141#define IndMask				0x0003fffc
2142#define RxINT				0x00000005	/* Delayed Rx or indivi rx */
2143#define TxDataInt			0x000000fa	/* Delayed Tx or indivi tx */
2144#define TxMgmtInt			0x00000102	/* Delayed Tx or indivi tx */
2145#define TxCoherent			0x00020000	/* tx coherent */
2146#define RxCoherent			0x00010000	/* rx coherent */
2147#define McuCommand			0x00000200	/* mcu */
2148#define PreTBTTInt			0x00001000	/* Pre-TBTT interrupt */
2149#define TBTTInt				0x00000800	/* TBTT interrupt */
2150#define GPTimeOutInt			0x00008000	/* GPtimeout interrupt */
2151#define AutoWakeupInt		0x00004000	/* AutoWakeupInt interrupt */
2152#define FifoStaFullInt			0x00002000	/*  fifo statistics full interrupt */
2153
2154/***************************************************************************
2155  *	Rx Path software control block related data structures
2156  **************************************************************************/
2157struct rt_rx_blk {
2158	RT28XX_RXD_STRUC RxD;
2159	struct rt_rxwi *pRxWI;
2160	struct rt_header_802_11 *pHeader;
2161	void *pRxPacket;
2162	u8 *pData;
2163	u16 DataSize;
2164	u16 Flags;
2165	u8 UserPriority;	/* for calculate TKIP MIC using */
2166};
2167
2168#define RX_BLK_SET_FLAG(_pRxBlk, _flag)		(_pRxBlk->Flags |= _flag)
2169#define RX_BLK_TEST_FLAG(_pRxBlk, _flag)	(_pRxBlk->Flags & _flag)
2170#define RX_BLK_CLEAR_FLAG(_pRxBlk, _flag)	(_pRxBlk->Flags &= ~(_flag))
2171
2172#define fRX_WDS			0x0001
2173#define fRX_AMSDU       0x0002
2174#define fRX_ARALINK     0x0004
2175#define fRX_HTC         0x0008
2176#define fRX_PAD         0x0010
2177#define fRX_AMPDU       0x0020
2178#define fRX_QOS			0x0040
2179#define fRX_INFRA		0x0080
2180#define fRX_EAP			0x0100
2181#define fRX_MESH		0x0200
2182#define fRX_APCLI		0x0400
2183#define fRX_DLS			0x0800
2184#define fRX_WPI			0x1000
2185
2186#define LENGTH_AMSDU_SUBFRAMEHEAD	14
2187#define LENGTH_ARALINK_SUBFRAMEHEAD	14
2188#define LENGTH_ARALINK_HEADER_FIELD	 2
2189
2190/***************************************************************************
2191  *	Tx Path software control block related data structures
2192  **************************************************************************/
2193#define TX_UNKOWN_FRAME			0x00
2194#define TX_MCAST_FRAME			0x01
2195#define TX_LEGACY_FRAME			0x02
2196#define TX_AMPDU_FRAME			0x04
2197#define TX_AMSDU_FRAME			0x08
2198#define TX_RALINK_FRAME			0x10
2199#define TX_FRAG_FRAME			0x20
2200
2201/*      Currently the sizeof(struct rt_tx_blk) is 148 bytes. */
2202struct rt_tx_blk {
2203	u8 QueIdx;
2204	u8 TxFrameType;	/* Indicate the Transmission type of the all frames in one batch */
2205	u8 TotalFrameNum;	/* Total frame number want to send-out in one batch */
2206	u16 TotalFragNum;	/* Total frame fragments required in one batch */
2207	u16 TotalFrameLen;	/* Total length of all frames want to send-out in one batch */
2208
2209	struct rt_queue_header TxPacketList;
2210	struct rt_mac_table_entry *pMacEntry;	/* NULL: packet with 802.11 RA field is multicast/broadcast address */
2211	HTTRANSMIT_SETTING *pTransmit;
2212
2213	/* Following structure used for the characteristics of a specific packet. */
2214	void *pPacket;
2215	u8 *pSrcBufHeader;	/* Reference to the head of sk_buff->data */
2216	u8 *pSrcBufData;	/* Reference to the sk_buff->data, will changed depends on hanlding progresss */
2217	u32 SrcBufLen;		/* Length of packet payload which not including Layer 2 header */
2218	u8 *pExtraLlcSnapEncap;	/* NULL means no extra LLC/SNAP is required */
2219	u8 HeaderBuf[128];	/* TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP */
2220	/*RT2870 2.1.0.0 uses only 80 bytes */
2221	/*RT3070 2.1.1.0 uses only 96 bytes */
2222	/*RT3090 2.1.0.0 uses only 96 bytes */
2223	u8 MpduHeaderLen;	/* 802.11 header length NOT including the padding */
2224	u8 HdrPadLen;	/* recording Header Padding Length; */
2225	u8 apidx;		/* The interface associated to this packet */
2226	u8 Wcid;		/* The MAC entry associated to this packet */
2227	u8 UserPriority;	/* priority class of packet */
2228	u8 FrameGap;		/* what kind of IFS this packet use */
2229	u8 MpduReqNum;	/* number of fragments of this frame */
2230	u8 TxRate;		/* TODO: Obsoleted? Should change to MCS? */
2231	u8 CipherAlg;	/* cipher alogrithm */
2232	struct rt_cipher_key *pKey;
2233
2234	u16 Flags;		/*See following definitions for detail. */
2235
2236	/*YOU SHOULD NOT TOUCH IT! Following parameters are used for hardware-depended layer. */
2237	unsigned long Priv;		/* Hardware specific value saved in here. */
2238};
2239
2240#define fTX_bRtsRequired		0x0001	/* Indicate if need send RTS frame for protection. Not used in RT2860/RT2870. */
2241#define fTX_bAckRequired       	0x0002	/* the packet need ack response */
2242#define fTX_bPiggyBack     		0x0004	/* Legacy device use Piggback or not */
2243#define fTX_bHTRate         	0x0008	/* allow to use HT rate */
2244#define fTX_bForceNonQoS       	0x0010	/* force to transmit frame without WMM-QoS in HT mode */
2245#define fTX_bAllowFrag       	0x0020	/* allow to fragment the packet, A-MPDU, A-MSDU, A-Ralink is not allowed to fragment */
2246#define fTX_bMoreData			0x0040	/* there are more data packets in PowerSave Queue */
2247#define fTX_bWMM				0x0080	/* QOS Data */
2248#define fTX_bClearEAPFrame		0x0100
2249
2250#define TX_BLK_SET_FLAG(_pTxBlk, _flag)		(_pTxBlk->Flags |= _flag)
2251#define TX_BLK_TEST_FLAG(_pTxBlk, _flag)	(((_pTxBlk->Flags & _flag) == _flag) ? 1 : 0)
2252#define TX_BLK_CLEAR_FLAG(_pTxBlk, _flag)	(_pTxBlk->Flags &= ~(_flag))
2253
2254/***************************************************************************
2255  *	Other static inline function definitions
2256  **************************************************************************/
2257static inline void ConvertMulticastIP2MAC(u8 *pIpAddr,
2258					  u8 **ppMacAddr,
2259					  u16 ProtoType)
2260{
2261	if (pIpAddr == NULL)
2262		return;
2263
2264	if (ppMacAddr == NULL || *ppMacAddr == NULL)
2265		return;
2266
2267	switch (ProtoType) {
2268	case ETH_P_IPV6:
2269/*                      memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */
2270		*(*ppMacAddr) = 0x33;
2271		*(*ppMacAddr + 1) = 0x33;
2272		*(*ppMacAddr + 2) = pIpAddr[12];
2273		*(*ppMacAddr + 3) = pIpAddr[13];
2274		*(*ppMacAddr + 4) = pIpAddr[14];
2275		*(*ppMacAddr + 5) = pIpAddr[15];
2276		break;
2277
2278	case ETH_P_IP:
2279	default:
2280/*                      memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */
2281		*(*ppMacAddr) = 0x01;
2282		*(*ppMacAddr + 1) = 0x00;
2283		*(*ppMacAddr + 2) = 0x5e;
2284		*(*ppMacAddr + 3) = pIpAddr[1] & 0x7f;
2285		*(*ppMacAddr + 4) = pIpAddr[2];
2286		*(*ppMacAddr + 5) = pIpAddr[3];
2287		break;
2288	}
2289
2290	return;
2291}
2292
2293char *GetPhyMode(int Mode);
2294char *GetBW(int BW);
2295
2296/* */
2297/*  Private routines in rtmp_init.c */
2298/* */
2299int RTMPAllocAdapterBlock(void *handle,
2300				  struct rt_rtmp_adapter **ppAdapter);
2301
2302int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd);
2303
2304void RTMPFreeAdapter(struct rt_rtmp_adapter *pAd);
2305
2306int NICReadRegParameters(struct rt_rtmp_adapter *pAd,
2307				 void *WrapperConfigurationContext);
2308
2309#ifdef RTMP_RF_RW_SUPPORT
2310void NICInitRFRegisters(struct rt_rtmp_adapter *pAd);
2311
2312void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd);
2313
2314int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd,
2315				  u8 regID, u8 value);
2316
2317int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd,
2318				 u8 regID, u8 *pValue);
2319#endif /* RTMP_RF_RW_SUPPORT // */
2320
2321void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr);
2322
2323void NICInitAsicFromEEPROM(struct rt_rtmp_adapter *pAd);
2324
2325int NICInitializeAdapter(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset);
2326
2327int NICInitializeAsic(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset);
2328
2329void NICIssueReset(struct rt_rtmp_adapter *pAd);
2330
2331void RTMPRingCleanUp(struct rt_rtmp_adapter *pAd, u8 RingType);
2332
2333void UserCfgInit(struct rt_rtmp_adapter *pAd);
2334
2335void NICResetFromError(struct rt_rtmp_adapter *pAd);
2336
2337int NICLoadFirmware(struct rt_rtmp_adapter *pAd);
2338
2339void NICEraseFirmware(struct rt_rtmp_adapter *pAd);
2340
2341int NICLoadRateSwitchingParams(struct rt_rtmp_adapter *pAd);
2342
2343BOOLEAN NICCheckForHang(struct rt_rtmp_adapter *pAd);
2344
2345void NICUpdateFifoStaCounters(struct rt_rtmp_adapter *pAd);
2346
2347void NICUpdateRawCounters(struct rt_rtmp_adapter *pAd);
2348
2349void RTMPZeroMemory(void *pSrc, unsigned long Length);
2350
2351unsigned long RTMPCompareMemory(void *pSrc1, void *pSrc2, unsigned long Length);
2352
2353void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length);
2354
2355void AtoH(char *src, u8 *dest, int destlen);
2356
2357void RTMPPatchMacBbpBug(struct rt_rtmp_adapter *pAd);
2358
2359void RTMPInitTimer(struct rt_rtmp_adapter *pAd,
2360		   struct rt_ralink_timer *pTimer,
2361		   void *pTimerFunc, void *pData, IN BOOLEAN Repeat);
2362
2363void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value);
2364
2365void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value);
2366
2367void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled);
2368
2369void RTMPSetLED(struct rt_rtmp_adapter *pAd, u8 Status);
2370
2371void RTMPSetSignalLED(struct rt_rtmp_adapter *pAd, IN NDIS_802_11_RSSI Dbm);
2372
2373void RTMPEnableRxTx(struct rt_rtmp_adapter *pAd);
2374
2375/* */
2376/* prototype in action.c */
2377/* */
2378void ActionStateMachineInit(struct rt_rtmp_adapter *pAd,
2379			    struct rt_state_machine *S,
2380			    OUT STATE_MACHINE_FUNC Trans[]);
2381
2382void MlmeADDBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2383
2384void MlmeDELBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2385
2386void MlmeDLSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2387
2388void MlmeInvalidAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2389
2390void MlmeQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2391
2392void PeerAddBAReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2393
2394void PeerAddBARspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2395
2396void PeerDelBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2397
2398void PeerBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2399
2400void SendPSMPAction(struct rt_rtmp_adapter *pAd, u8 Wcid, u8 Psmp);
2401
2402void PeerRMAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2403
2404void PeerPublicAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2405
2406void PeerHTAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2407
2408void PeerQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2409
2410void RECBATimerTimeout(void *SystemSpecific1,
2411		       void *FunctionContext,
2412		       void *SystemSpecific2, void *SystemSpecific3);
2413
2414void ORIBATimerTimeout(struct rt_rtmp_adapter *pAd);
2415
2416void SendRefreshBAR(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
2417
2418void ActHeaderInit(struct rt_rtmp_adapter *pAd,
2419		   struct rt_header_802_11 *pHdr80211,
2420		   u8 *Addr1, u8 *Addr2, u8 *Addr3);
2421
2422void BarHeaderInit(struct rt_rtmp_adapter *pAd,
2423		   struct rt_frame_bar *pCntlBar, u8 *pDA, u8 *pSA);
2424
2425void InsertActField(struct rt_rtmp_adapter *pAd,
2426		    u8 *pFrameBuf,
2427		    unsigned long *pFrameLen, u8 Category, u8 ActCode);
2428
2429BOOLEAN CntlEnqueueForRecv(struct rt_rtmp_adapter *pAd,
2430			   unsigned long Wcid,
2431			   unsigned long MsgLen, struct rt_frame_ba_req *pMsg);
2432
2433/* */
2434/* Private routines in rtmp_data.c */
2435/* */
2436BOOLEAN RTMPHandleRxDoneInterrupt(struct rt_rtmp_adapter *pAd);
2437
2438BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd,
2439					 INT_SOURCE_CSR_STRUC TxRingBitmap);
2440
2441void RTMPHandleMgmtRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd);
2442
2443void RTMPHandleTBTTInterrupt(struct rt_rtmp_adapter *pAd);
2444
2445void RTMPHandlePreTBTTInterrupt(struct rt_rtmp_adapter *pAd);
2446
2447void RTMPHandleTwakeupInterrupt(struct rt_rtmp_adapter *pAd);
2448
2449void RTMPHandleRxCoherentInterrupt(struct rt_rtmp_adapter *pAd);
2450
2451BOOLEAN TxFrameIsAggregatible(struct rt_rtmp_adapter *pAd,
2452			      u8 *pPrevAddr1, u8 *p8023hdr);
2453
2454BOOLEAN PeerIsAggreOn(struct rt_rtmp_adapter *pAd,
2455		      unsigned long TxRate, struct rt_mac_table_entry *pMacEntry);
2456
2457int Sniff2BytesFromNdisBuffer(char *pFirstBuffer,
2458				      u8 DesiredOffset,
2459				      u8 *pByte0, u8 *pByte1);
2460
2461int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket);
2462
2463void STASendPackets(void *MiniportAdapterContext,
2464		    void **ppPacketArray, u32 NumberOfPackets);
2465
2466void RTMPDeQueuePacket(struct rt_rtmp_adapter *pAd,
2467		       IN BOOLEAN bIntContext,
2468		       u8 QueIdx, u8 Max_Tx_Packets);
2469
2470int RTMPHardTransmit(struct rt_rtmp_adapter *pAd,
2471			     void *pPacket,
2472			     u8 QueIdx, unsigned long *pFreeTXDLeft);
2473
2474int STAHardTransmit(struct rt_rtmp_adapter *pAd,
2475			    struct rt_tx_blk *pTxBlk, u8 QueIdx);
2476
2477void STARxEAPOLFrameIndicate(struct rt_rtmp_adapter *pAd,
2478			     struct rt_mac_table_entry *pEntry,
2479			     struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
2480
2481int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd,
2482			       u8 RingType,
2483			       u8 NumberRequired, u8 *FreeNumberIs);
2484
2485int MlmeHardTransmit(struct rt_rtmp_adapter *pAd,
2486			     u8 QueIdx, void *pPacket);
2487
2488int MlmeHardTransmitMgmtRing(struct rt_rtmp_adapter *pAd,
2489				     u8 QueIdx, void *pPacket);
2490
2491#ifdef RTMP_MAC_PCI
2492int MlmeHardTransmitTxRing(struct rt_rtmp_adapter *pAd,
2493				   u8 QueIdx, void *pPacket);
2494
2495int MlmeDataHardTransmit(struct rt_rtmp_adapter *pAd,
2496				 u8 QueIdx, void *pPacket);
2497
2498void RTMPWriteTxDescriptor(struct rt_rtmp_adapter *pAd,
2499			   struct rt_txd *pTxD, IN BOOLEAN bWIV, u8 QSEL);
2500#endif /* RTMP_MAC_PCI // */
2501
2502u16 RTMPCalcDuration(struct rt_rtmp_adapter *pAd, u8 Rate, unsigned long Size);
2503
2504void RTMPWriteTxWI(struct rt_rtmp_adapter *pAd, struct rt_txwi * pTxWI, IN BOOLEAN FRAG, IN BOOLEAN CFACK, IN BOOLEAN InsTimestamp, IN BOOLEAN AMPDU, IN BOOLEAN Ack, IN BOOLEAN NSeq,	/* HW new a sequence. */
2505		   u8 BASize,
2506		   u8 WCID,
2507		   unsigned long Length,
2508		   u8 PID,
2509		   u8 TID,
2510		   u8 TxRate,
2511		   u8 Txopmode,
2512		   IN BOOLEAN CfAck, IN HTTRANSMIT_SETTING *pTransmit);
2513
2514void RTMPWriteTxWI_Data(struct rt_rtmp_adapter *pAd,
2515			struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk);
2516
2517void RTMPWriteTxWI_Cache(struct rt_rtmp_adapter *pAd,
2518			 struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk);
2519
2520void RTMPSuspendMsduTransmission(struct rt_rtmp_adapter *pAd);
2521
2522void RTMPResumeMsduTransmission(struct rt_rtmp_adapter *pAd);
2523
2524int MiniportMMRequest(struct rt_rtmp_adapter *pAd,
2525			      u8 QueIdx, u8 *pData, u32 Length);
2526
2527/*+++mark by shiang, now this function merge to MiniportMMRequest() */
2528/*---mark by shiang, now this function merge to MiniportMMRequest() */
2529
2530void RTMPSendNullFrame(struct rt_rtmp_adapter *pAd,
2531		       u8 TxRate, IN BOOLEAN bQosNull);
2532
2533void RTMPSendDisassociationFrame(struct rt_rtmp_adapter *pAd);
2534
2535void RTMPSendRTSFrame(struct rt_rtmp_adapter *pAd,
2536		      u8 *pDA,
2537		      IN unsigned int NextMpduSize,
2538		      u8 TxRate,
2539		      u8 RTSRate,
2540		      u16 AckDuration,
2541		      u8 QueIdx, u8 FrameGap);
2542
2543struct rt_queue_header *RTMPCheckTxSwQueue(struct rt_rtmp_adapter *pAd, u8 * QueIdx);
2544
2545void RTMPReportMicError(struct rt_rtmp_adapter *pAd, struct rt_cipher_key *pWpaKey);
2546
2547void WpaMicFailureReportFrame(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2548
2549void WpaDisassocApAndBlockAssoc(void *SystemSpecific1,
2550				void *FunctionContext,
2551				void *SystemSpecific2,
2552				void *SystemSpecific3);
2553
2554void WpaStaPairwiseKeySetting(struct rt_rtmp_adapter *pAd);
2555
2556void WpaStaGroupKeySetting(struct rt_rtmp_adapter *pAd);
2557
2558int RTMPCloneNdisPacket(struct rt_rtmp_adapter *pAd,
2559				IN BOOLEAN pInsAMSDUHdr,
2560				void *pInPacket,
2561				void **ppOutPacket);
2562
2563int RTMPAllocateNdisPacket(struct rt_rtmp_adapter *pAd,
2564				   void **pPacket,
2565				   u8 *pHeader,
2566				   u32 HeaderLen,
2567				   u8 *pData, u32 DataLen);
2568
2569void RTMPFreeNdisPacket(struct rt_rtmp_adapter *pAd, void *pPacket);
2570
2571BOOLEAN RTMPFreeTXDUponTxDmaDone(struct rt_rtmp_adapter *pAd, u8 QueIdx);
2572
2573BOOLEAN RTMPCheckDHCPFrame(struct rt_rtmp_adapter *pAd, void *pPacket);
2574
2575BOOLEAN RTMPCheckEtherType(struct rt_rtmp_adapter *pAd, void *pPacket);
2576
2577/* */
2578/* Private routines in rtmp_wep.c */
2579/* */
2580void RTMPInitWepEngine(struct rt_rtmp_adapter *pAd,
2581		       u8 *pKey,
2582		       u8 KeyId, u8 KeyLen, u8 *pDest);
2583
2584void RTMPEncryptData(struct rt_rtmp_adapter *pAd,
2585		     u8 *pSrc, u8 *pDest, u32 Len);
2586
2587BOOLEAN RTMPSoftDecryptWEP(struct rt_rtmp_adapter *pAd,
2588			   u8 *pData,
2589			   unsigned long DataByteCnt, struct rt_cipher_key *pGroupKey);
2590
2591void RTMPSetICV(struct rt_rtmp_adapter *pAd, u8 *pDest);
2592
2593void ARCFOUR_INIT(struct rt_arcfourcontext *Ctx, u8 *pKey, u32 KeyLen);
2594
2595u8 ARCFOUR_BYTE(struct rt_arcfourcontext *Ctx);
2596
2597void ARCFOUR_DECRYPT(struct rt_arcfourcontext *Ctx,
2598		     u8 *pDest, u8 *pSrc, u32 Len);
2599
2600void ARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
2601		     u8 *pDest, u8 *pSrc, u32 Len);
2602
2603void WPAARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
2604			u8 *pDest, u8 *pSrc, u32 Len);
2605
2606u32 RTMP_CALC_FCS32(u32 Fcs, u8 *Cp, int Len);
2607
2608/* */
2609/* MLME routines */
2610/* */
2611
2612/* Asic/RF/BBP related functions */
2613
2614void AsicAdjustTxPower(struct rt_rtmp_adapter *pAd);
2615
2616void AsicUpdateProtect(struct rt_rtmp_adapter *pAd,
2617		       u16 OperaionMode,
2618		       u8 SetMask,
2619		       IN BOOLEAN bDisableBGProtect, IN BOOLEAN bNonGFExist);
2620
2621void AsicSwitchChannel(struct rt_rtmp_adapter *pAd,
2622		       u8 Channel, IN BOOLEAN bScan);
2623
2624void AsicLockChannel(struct rt_rtmp_adapter *pAd, u8 Channel);
2625
2626void AsicRfTuningExec(void *SystemSpecific1,
2627		      void *FunctionContext,
2628		      void *SystemSpecific2, void *SystemSpecific3);
2629
2630void AsicResetBBPAgent(struct rt_rtmp_adapter *pAd);
2631
2632void AsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
2633			     u16 TbttNumToNextWakeUp);
2634
2635void AsicForceSleep(struct rt_rtmp_adapter *pAd);
2636
2637void AsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
2638
2639void AsicSetBssid(struct rt_rtmp_adapter *pAd, u8 *pBssid);
2640
2641void AsicSetMcastWC(struct rt_rtmp_adapter *pAd);
2642
2643void AsicDelWcidTab(struct rt_rtmp_adapter *pAd, u8 Wcid);
2644
2645void AsicEnableRDG(struct rt_rtmp_adapter *pAd);
2646
2647void AsicDisableRDG(struct rt_rtmp_adapter *pAd);
2648
2649void AsicDisableSync(struct rt_rtmp_adapter *pAd);
2650
2651void AsicEnableBssSync(struct rt_rtmp_adapter *pAd);
2652
2653void AsicEnableIbssSync(struct rt_rtmp_adapter *pAd);
2654
2655void AsicSetEdcaParm(struct rt_rtmp_adapter *pAd, struct rt_edca_parm *pEdcaParm);
2656
2657void AsicSetSlotTime(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUseShortSlotTime);
2658
2659void AsicAddSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2660			   u8 BssIndex,
2661			   u8 KeyIdx,
2662			   u8 CipherAlg,
2663			   u8 *pKey, u8 *pTxMic, u8 *pRxMic);
2664
2665void AsicRemoveSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2666			      u8 BssIndex, u8 KeyIdx);
2667
2668void AsicUpdateWCIDAttribute(struct rt_rtmp_adapter *pAd,
2669			     u16 WCID,
2670			     u8 BssIndex,
2671			     u8 CipherAlg,
2672			     IN BOOLEAN bUsePairewiseKeyTable);
2673
2674void AsicUpdateWCIDIVEIV(struct rt_rtmp_adapter *pAd,
2675			 u16 WCID, unsigned long uIV, unsigned long uEIV);
2676
2677void AsicUpdateRxWCIDTable(struct rt_rtmp_adapter *pAd,
2678			   u16 WCID, u8 *pAddr);
2679
2680void AsicAddKeyEntry(struct rt_rtmp_adapter *pAd,
2681		     u16 WCID,
2682		     u8 BssIndex,
2683		     u8 KeyIdx,
2684		     struct rt_cipher_key *pCipherKey,
2685		     IN BOOLEAN bUsePairewiseKeyTable, IN BOOLEAN bTxKey);
2686
2687void AsicAddPairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2688			     u8 *pAddr,
2689			     u8 WCID, struct rt_cipher_key *pCipherKey);
2690
2691void AsicRemovePairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2692				u8 BssIdx, u8 Wcid);
2693
2694BOOLEAN AsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
2695			     u8 Command,
2696			     u8 Token, u8 Arg0, u8 Arg1);
2697
2698#ifdef RTMP_MAC_PCI
2699BOOLEAN AsicCheckCommanOk(struct rt_rtmp_adapter *pAd, u8 Command);
2700#endif /* RTMP_MAC_PCI // */
2701
2702void MacAddrRandomBssid(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2703
2704void MgtMacHeaderInit(struct rt_rtmp_adapter *pAd,
2705		      struct rt_header_802_11 *pHdr80211,
2706		      u8 SubType,
2707		      u8 ToDs, u8 *pDA, u8 *pBssid);
2708
2709void MlmeRadioOff(struct rt_rtmp_adapter *pAd);
2710
2711void MlmeRadioOn(struct rt_rtmp_adapter *pAd);
2712
2713void BssTableInit(struct rt_bss_table *Tab);
2714
2715void BATableInit(struct rt_rtmp_adapter *pAd, struct rt_ba_table *Tab);
2716
2717unsigned long BssTableSearch(struct rt_bss_table *Tab, u8 *pBssid, u8 Channel);
2718
2719unsigned long BssSsidTableSearch(struct rt_bss_table *Tab,
2720			 u8 *pBssid,
2721			 u8 *pSsid, u8 SsidLen, u8 Channel);
2722
2723unsigned long BssTableSearchWithSSID(struct rt_bss_table *Tab,
2724			     u8 *Bssid,
2725			     u8 *pSsid,
2726			     u8 SsidLen, u8 Channel);
2727
2728unsigned long BssSsidTableSearchBySSID(struct rt_bss_table *Tab,
2729			       u8 *pSsid, u8 SsidLen);
2730
2731void BssTableDeleteEntry(struct rt_bss_table *pTab,
2732			 u8 *pBssid, u8 Channel);
2733
2734void BATableDeleteORIEntry(struct rt_rtmp_adapter *pAd,
2735			   struct rt_ba_ori_entry *pBAORIEntry);
2736
2737void BssEntrySet(struct rt_rtmp_adapter *pAd, struct rt_bss_entry *pBss, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo,	/* AP might use this additional ht info IE */
2738		 u8 HtCapabilityLen,
2739		 u8 AddHtInfoLen,
2740		 u8 NewExtChanOffset,
2741		 u8 Channel,
2742		 char Rssi,
2743		 IN LARGE_INTEGER TimeStamp,
2744		 u8 CkipFlag,
2745		 struct rt_edca_parm *pEdcaParm,
2746		 struct rt_qos_capability_parm *pQosCapability,
2747		 struct rt_qbss_load_parm *pQbssLoad,
2748		 u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE);
2749
2750unsigned long BssTableSetEntry(struct rt_rtmp_adapter *pAd, struct rt_bss_table *pTab, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo,	/* AP might use this additional ht info IE */
2751		       u8 HtCapabilityLen,
2752		       u8 AddHtInfoLen,
2753		       u8 NewExtChanOffset,
2754		       u8 Channel,
2755		       char Rssi,
2756		       IN LARGE_INTEGER TimeStamp,
2757		       u8 CkipFlag,
2758		       struct rt_edca_parm *pEdcaParm,
2759		       struct rt_qos_capability_parm *pQosCapability,
2760		       struct rt_qbss_load_parm *pQbssLoad,
2761		       u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE);
2762
2763void BATableInsertEntry(struct rt_rtmp_adapter *pAd,
2764			u16 Aid,
2765			u16 TimeOutValue,
2766			u16 StartingSeq,
2767			u8 TID,
2768			u8 BAWinSize,
2769			u8 OriginatorStatus, IN BOOLEAN IsRecipient);
2770
2771void BssTableSsidSort(struct rt_rtmp_adapter *pAd,
2772		      struct rt_bss_table *OutTab, char Ssid[], u8 SsidLen);
2773
2774void BssTableSortByRssi(struct rt_bss_table *OutTab);
2775
2776void BssCipherParse(struct rt_bss_entry *pBss);
2777
2778int MlmeQueueInit(struct rt_mlme_queue *Queue);
2779
2780void MlmeQueueDestroy(struct rt_mlme_queue *Queue);
2781
2782BOOLEAN MlmeEnqueue(struct rt_rtmp_adapter *pAd,
2783		    unsigned long Machine,
2784		    unsigned long MsgType, unsigned long MsgLen, void *Msg);
2785
2786BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd,
2787			   unsigned long Wcid,
2788			   unsigned long TimeStampHigh,
2789			   unsigned long TimeStampLow,
2790			   u8 Rssi0,
2791			   u8 Rssi1,
2792			   u8 Rssi2,
2793			   unsigned long MsgLen, void *Msg, u8 Signal);
2794
2795BOOLEAN MlmeDequeue(struct rt_mlme_queue *Queue, struct rt_mlme_queue_elem **Elem);
2796
2797void MlmeRestartStateMachine(struct rt_rtmp_adapter *pAd);
2798
2799BOOLEAN MlmeQueueEmpty(struct rt_mlme_queue *Queue);
2800
2801BOOLEAN MlmeQueueFull(struct rt_mlme_queue *Queue);
2802
2803BOOLEAN MsgTypeSubst(struct rt_rtmp_adapter *pAd,
2804		     struct rt_frame_802_11 *pFrame,
2805		     int *Machine, int *MsgType);
2806
2807void StateMachineInit(struct rt_state_machine *Sm,
2808		      IN STATE_MACHINE_FUNC Trans[],
2809		      unsigned long StNr,
2810		      unsigned long MsgNr,
2811		      IN STATE_MACHINE_FUNC DefFunc,
2812		      unsigned long InitState, unsigned long Base);
2813
2814void StateMachineSetAction(struct rt_state_machine *S,
2815			   unsigned long St, unsigned long Msg, IN STATE_MACHINE_FUNC F);
2816
2817void StateMachinePerformAction(struct rt_rtmp_adapter *pAd,
2818			       struct rt_state_machine *S, struct rt_mlme_queue_elem *Elem);
2819
2820void Drop(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2821
2822void AssocStateMachineInit(struct rt_rtmp_adapter *pAd,
2823			   struct rt_state_machine *Sm,
2824			   OUT STATE_MACHINE_FUNC Trans[]);
2825
2826void ReassocTimeout(void *SystemSpecific1,
2827		    void *FunctionContext,
2828		    void *SystemSpecific2, void *SystemSpecific3);
2829
2830void AssocTimeout(void *SystemSpecific1,
2831		  void *FunctionContext,
2832		  void *SystemSpecific2, void *SystemSpecific3);
2833
2834void DisassocTimeout(void *SystemSpecific1,
2835		     void *FunctionContext,
2836		     void *SystemSpecific2, void *SystemSpecific3);
2837
2838/*---------------------------------------------- */
2839void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2840
2841void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2842
2843void MlmeDisassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2844
2845void PeerAssocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2846
2847void PeerReassocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2848
2849void PeerDisassocAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2850
2851void DisassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2852
2853void AssocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2854
2855void ReassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2856
2857void Cls3errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2858
2859void InvalidStateWhenAssoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2860
2861void InvalidStateWhenReassoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2862
2863void InvalidStateWhenDisassociate(struct rt_rtmp_adapter *pAd,
2864				  struct rt_mlme_queue_elem *Elem);
2865
2866#ifdef RTMP_MAC_USB
2867void MlmeCntlConfirm(struct rt_rtmp_adapter *pAd, unsigned long MsgType, u16 Msg);
2868#endif /* RTMP_MAC_USB // */
2869
2870void ComposePsPoll(struct rt_rtmp_adapter *pAd);
2871
2872void ComposeNullFrame(struct rt_rtmp_adapter *pAd);
2873
2874void AssocPostProc(struct rt_rtmp_adapter *pAd,
2875		   u8 *pAddr2,
2876		   u16 CapabilityInfo,
2877		   u16 Aid,
2878		   u8 SupRate[],
2879		   u8 SupRateLen,
2880		   u8 ExtRate[],
2881		   u8 ExtRateLen,
2882		   struct rt_edca_parm *pEdcaParm,
2883		   struct rt_ht_capability_ie *pHtCapability,
2884		   u8 HtCapabilityLen, struct rt_add_ht_info_ie *pAddHtInfo);
2885
2886void AuthStateMachineInit(struct rt_rtmp_adapter *pAd,
2887			  struct rt_state_machine *sm, OUT STATE_MACHINE_FUNC Trans[]);
2888
2889void AuthTimeout(void *SystemSpecific1,
2890		 void *FunctionContext,
2891		 void *SystemSpecific2, void *SystemSpecific3);
2892
2893void MlmeAuthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2894
2895void PeerAuthRspAtSeq2Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2896
2897void PeerAuthRspAtSeq4Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2898
2899void AuthTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2900
2901void Cls2errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2902
2903void MlmeDeauthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2904
2905void InvalidStateWhenAuth(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2906
2907/*============================================= */
2908
2909void AuthRspStateMachineInit(struct rt_rtmp_adapter *pAd,
2910			     struct rt_state_machine *Sm,
2911			     IN STATE_MACHINE_FUNC Trans[]);
2912
2913void PeerDeauthAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2914
2915void PeerAuthSimpleRspGenAndSend(struct rt_rtmp_adapter *pAd,
2916				 struct rt_header_802_11 *pHdr80211,
2917				 u16 Alg,
2918				 u16 Seq,
2919				 u16 Reason, u16 Status);
2920
2921/* */
2922/* Private routines in dls.c */
2923/* */
2924
2925/*======================================== */
2926
2927void SyncStateMachineInit(struct rt_rtmp_adapter *pAd,
2928			  struct rt_state_machine *Sm,
2929			  OUT STATE_MACHINE_FUNC Trans[]);
2930
2931void BeaconTimeout(void *SystemSpecific1,
2932		   void *FunctionContext,
2933		   void *SystemSpecific2, void *SystemSpecific3);
2934
2935void ScanTimeout(void *SystemSpecific1,
2936		 void *FunctionContext,
2937		 void *SystemSpecific2, void *SystemSpecific3);
2938
2939void InvalidStateWhenScan(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2940
2941void InvalidStateWhenJoin(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2942
2943void InvalidStateWhenStart(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2944
2945void EnqueueProbeRequest(struct rt_rtmp_adapter *pAd);
2946
2947BOOLEAN ScanRunning(struct rt_rtmp_adapter *pAd);
2948/*========================================= */
2949
2950void MlmeCntlInit(struct rt_rtmp_adapter *pAd,
2951		  struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[]);
2952
2953void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd,
2954				  struct rt_state_machine *S,
2955				  struct rt_mlme_queue_elem *Elem);
2956
2957void CntlIdleProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2958
2959void CntlOidScanProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2960
2961void CntlOidSsidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2962
2963void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2964
2965void CntlMlmeRoamingProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2966
2967void CntlWaitDisassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2968
2969void CntlWaitJoinProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2970
2971void CntlWaitReassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2972
2973void CntlWaitStartProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2974
2975void CntlWaitAuthProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2976
2977void CntlWaitAuthProc2(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2978
2979void CntlWaitAssocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2980
2981void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType);
2982
2983void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP);
2984
2985void IterateOnBssTab(struct rt_rtmp_adapter *pAd);
2986
2987void IterateOnBssTab2(struct rt_rtmp_adapter *pAd);;
2988
2989void JoinParmFill(struct rt_rtmp_adapter *pAd,
2990		  struct rt_mlme_join_req *JoinReq, unsigned long BssIdx);
2991
2992void AssocParmFill(struct rt_rtmp_adapter *pAd,
2993		   struct rt_mlme_assoc_req *AssocReq,
2994		   u8 *pAddr,
2995		   u16 CapabilityInfo,
2996		   unsigned long Timeout, u16 ListenIntv);
2997
2998void ScanParmFill(struct rt_rtmp_adapter *pAd,
2999		  struct rt_mlme_scan_req *ScanReq,
3000		  char Ssid[],
3001		  u8 SsidLen, u8 BssType, u8 ScanType);
3002
3003void DisassocParmFill(struct rt_rtmp_adapter *pAd,
3004		      struct rt_mlme_disassoc_req *DisassocReq,
3005		      u8 *pAddr, u16 Reason);
3006
3007void StartParmFill(struct rt_rtmp_adapter *pAd,
3008		   struct rt_mlme_start_req *StartReq,
3009		   char Ssid[], u8 SsidLen);
3010
3011void AuthParmFill(struct rt_rtmp_adapter *pAd,
3012		  struct rt_mlme_auth_req *AuthReq,
3013		  u8 *pAddr, u16 Alg);
3014
3015void EnqueuePsPoll(struct rt_rtmp_adapter *pAd);
3016
3017void EnqueueBeaconFrame(struct rt_rtmp_adapter *pAd);
3018
3019void MlmeJoinReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3020
3021void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3022
3023void MlmeStartReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3024
3025void ScanTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3026
3027void BeaconTimeoutAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3028
3029void PeerBeaconAtScanAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3030
3031void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3032
3033void PeerBeacon(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3034
3035void PeerProbeReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3036
3037void ScanNextChannel(struct rt_rtmp_adapter *pAd);
3038
3039unsigned long MakeIbssBeacon(struct rt_rtmp_adapter *pAd);
3040
3041BOOLEAN MlmeScanReqSanity(struct rt_rtmp_adapter *pAd,
3042			  void *Msg,
3043			  unsigned long MsgLen,
3044			  u8 *BssType,
3045			  char ssid[],
3046			  u8 *SsidLen, u8 *ScanType);
3047
3048BOOLEAN PeerBeaconAndProbeRspSanity(struct rt_rtmp_adapter *pAd,
3049				    void *Msg,
3050				    unsigned long MsgLen,
3051				    u8 MsgChannel,
3052				    u8 *pAddr2,
3053				    u8 *pBssid,
3054				    char Ssid[],
3055				    u8 *pSsidLen,
3056				    u8 *pBssType,
3057				    u16 *pBeaconPeriod,
3058				    u8 *pChannel,
3059				    u8 *pNewChannel,
3060				    OUT LARGE_INTEGER *pTimestamp,
3061				    struct rt_cf_parm *pCfParm,
3062				    u16 *pAtimWin,
3063				    u16 *pCapabilityInfo,
3064				    u8 *pErp,
3065				    u8 *pDtimCount,
3066				    u8 *pDtimPeriod,
3067				    u8 *pBcastFlag,
3068				    u8 *pMessageToMe,
3069				    u8 SupRate[],
3070				    u8 *pSupRateLen,
3071				    u8 ExtRate[],
3072				    u8 *pExtRateLen,
3073				    u8 *pCkipFlag,
3074				    u8 *pAironetCellPowerLimit,
3075				    struct rt_edca_parm *pEdcaParm,
3076				    struct rt_qbss_load_parm *pQbssLoad,
3077				    struct rt_qos_capability_parm *pQosCapability,
3078				    unsigned long *pRalinkIe,
3079				    u8 *pHtCapabilityLen,
3080				    u8 *pPreNHtCapabilityLen,
3081				    struct rt_ht_capability_ie *pHtCapability,
3082				    u8 *AddHtInfoLen,
3083				    struct rt_add_ht_info_ie *AddHtInfo,
3084				    u8 *NewExtChannel,
3085				    u16 *LengthVIE,
3086				    struct rt_ndis_802_11_variable_ies *pVIE);
3087
3088BOOLEAN PeerAddBAReqActionSanity(struct rt_rtmp_adapter *pAd,
3089				 void *pMsg,
3090				 unsigned long MsgLen, u8 *pAddr2);
3091
3092BOOLEAN PeerAddBARspActionSanity(struct rt_rtmp_adapter *pAd,
3093				 void *pMsg, unsigned long MsgLen);
3094
3095BOOLEAN PeerDelBAActionSanity(struct rt_rtmp_adapter *pAd,
3096			      u8 Wcid, void *pMsg, unsigned long MsgLen);
3097
3098BOOLEAN MlmeAssocReqSanity(struct rt_rtmp_adapter *pAd,
3099			   void *Msg,
3100			   unsigned long MsgLen,
3101			   u8 *pApAddr,
3102			   u16 *CapabilityInfo,
3103			   unsigned long *Timeout, u16 *ListenIntv);
3104
3105BOOLEAN MlmeAuthReqSanity(struct rt_rtmp_adapter *pAd,
3106			  void *Msg,
3107			  unsigned long MsgLen,
3108			  u8 *pAddr,
3109			  unsigned long *Timeout, u16 *Alg);
3110
3111BOOLEAN MlmeStartReqSanity(struct rt_rtmp_adapter *pAd,
3112			   void *Msg,
3113			   unsigned long MsgLen,
3114			   char Ssid[], u8 *Ssidlen);
3115
3116BOOLEAN PeerAuthSanity(struct rt_rtmp_adapter *pAd,
3117		       void *Msg,
3118		       unsigned long MsgLen,
3119		       u8 *pAddr,
3120		       u16 *Alg,
3121		       u16 *Seq,
3122		       u16 *Status, char ChlgText[]);
3123
3124BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void *pMsg, unsigned long MsgLen, u8 *pAddr2, u16 *pCapabilityInfo, u16 *pStatus, u16 *pAid, u8 SupRate[], u8 *pSupRateLen, u8 ExtRate[], u8 *pExtRateLen, struct rt_ht_capability_ie *pHtCapability, struct rt_add_ht_info_ie *pAddHtInfo,	/* AP might use this additional ht info IE */
3125			   u8 *pHtCapabilityLen,
3126			   u8 *pAddHtInfoLen,
3127			   u8 *pNewExtChannelOffset,
3128			   struct rt_edca_parm *pEdcaParm, u8 *pCkipFlag);
3129
3130BOOLEAN PeerDisassocSanity(struct rt_rtmp_adapter *pAd,
3131			   void *Msg,
3132			   unsigned long MsgLen,
3133			   u8 *pAddr2, u16 *Reason);
3134
3135BOOLEAN PeerWpaMessageSanity(struct rt_rtmp_adapter *pAd,
3136			     struct rt_eapol_packet *pMsg,
3137			     unsigned long MsgLen,
3138			     u8 MsgType, struct rt_mac_table_entry *pEntry);
3139
3140BOOLEAN PeerDeauthSanity(struct rt_rtmp_adapter *pAd,
3141			 void *Msg,
3142			 unsigned long MsgLen,
3143			 u8 *pAddr2, u16 *Reason);
3144
3145BOOLEAN PeerProbeReqSanity(struct rt_rtmp_adapter *pAd,
3146			   void *Msg,
3147			   unsigned long MsgLen,
3148			   u8 *pAddr2,
3149			   char Ssid[], u8 *pSsidLen);
3150
3151BOOLEAN GetTimBit(char *Ptr,
3152		  u16 Aid,
3153		  u8 *TimLen,
3154		  u8 *BcastFlag,
3155		  u8 *DtimCount,
3156		  u8 *DtimPeriod, u8 *MessageToMe);
3157
3158u8 ChannelSanity(struct rt_rtmp_adapter *pAd, u8 channel);
3159
3160NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(struct rt_bss_entry *pBss);
3161
3162BOOLEAN MlmeDelBAReqSanity(struct rt_rtmp_adapter *pAd,
3163			   void *Msg, unsigned long MsgLen);
3164
3165BOOLEAN MlmeAddBAReqSanity(struct rt_rtmp_adapter *pAd,
3166			   void *Msg, unsigned long MsgLen, u8 *pAddr2);
3167
3168unsigned long MakeOutgoingFrame(u8 *Buffer, unsigned long *Length, ...);
3169
3170void LfsrInit(struct rt_rtmp_adapter *pAd, unsigned long Seed);
3171
3172u8 RandomByte(struct rt_rtmp_adapter *pAd);
3173
3174void AsicUpdateAutoFallBackTable(struct rt_rtmp_adapter *pAd, u8 *pTxRate);
3175
3176void MlmePeriodicExec(void *SystemSpecific1,
3177		      void *FunctionContext,
3178		      void *SystemSpecific2, void *SystemSpecific3);
3179
3180void LinkDownExec(void *SystemSpecific1,
3181		  void *FunctionContext,
3182		  void *SystemSpecific2, void *SystemSpecific3);
3183
3184void STAMlmePeriodicExec(struct rt_rtmp_adapter *pAd);
3185
3186void MlmeAutoScan(struct rt_rtmp_adapter *pAd);
3187
3188void MlmeAutoReconnectLastSSID(struct rt_rtmp_adapter *pAd);
3189
3190BOOLEAN MlmeValidateSSID(u8 *pSsid, u8 SsidLen);
3191
3192void MlmeCheckForRoaming(struct rt_rtmp_adapter *pAd, unsigned long Now32);
3193
3194BOOLEAN MlmeCheckForFastRoaming(struct rt_rtmp_adapter *pAd);
3195
3196void MlmeDynamicTxRateSwitching(struct rt_rtmp_adapter *pAd);
3197
3198void MlmeSetTxRate(struct rt_rtmp_adapter *pAd,
3199		   struct rt_mac_table_entry *pEntry, struct rt_rtmp_tx_rate_switch * pTxRate);
3200
3201void MlmeSelectTxRateTable(struct rt_rtmp_adapter *pAd,
3202			   struct rt_mac_table_entry *pEntry,
3203			   u8 **ppTable,
3204			   u8 *pTableSize, u8 *pInitTxRateIdx);
3205
3206void MlmeCalculateChannelQuality(struct rt_rtmp_adapter *pAd,
3207				 struct rt_mac_table_entry *pMacEntry, unsigned long Now);
3208
3209void MlmeCheckPsmChange(struct rt_rtmp_adapter *pAd, unsigned long Now32);
3210
3211void MlmeSetPsmBit(struct rt_rtmp_adapter *pAd, u16 psm);
3212
3213void MlmeSetTxPreamble(struct rt_rtmp_adapter *pAd, u16 TxPreamble);
3214
3215void UpdateBasicRateBitmap(struct rt_rtmp_adapter *pAd);
3216
3217void MlmeUpdateTxRates(struct rt_rtmp_adapter *pAd,
3218		       IN BOOLEAN bLinkUp, u8 apidx);
3219
3220void MlmeUpdateHtTxRates(struct rt_rtmp_adapter *pAd, u8 apidx);
3221
3222void RTMPCheckRates(struct rt_rtmp_adapter *pAd,
3223		    IN u8 SupRate[], IN u8 *SupRateLen);
3224
3225BOOLEAN RTMPCheckChannel(struct rt_rtmp_adapter *pAd,
3226			 u8 CentralChannel, u8 Channel);
3227
3228BOOLEAN RTMPCheckHt(struct rt_rtmp_adapter *pAd,
3229		    u8 Wcid,
3230		    struct rt_ht_capability_ie *pHtCapability,
3231		    struct rt_add_ht_info_ie *pAddHtInfo);
3232
3233void StaQuickResponeForRateUpExec(void *SystemSpecific1,
3234				  void *FunctionContext,
3235				  void *SystemSpecific2,
3236				  void *SystemSpecific3);
3237
3238void RTMPUpdateMlmeRate(struct rt_rtmp_adapter *pAd);
3239
3240char RTMPMaxRssi(struct rt_rtmp_adapter *pAd,
3241		 char Rssi0, char Rssi1, char Rssi2);
3242
3243#ifdef RT30xx
3244void AsicSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant);
3245
3246void RTMPFilterCalibration(struct rt_rtmp_adapter *pAd);
3247
3248#ifdef RTMP_EFUSE_SUPPORT
3249/*2008/09/11:KH add to support efuse<-- */
3250int set_eFuseGetFreeBlockCount_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3251
3252int set_eFusedump_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3253
3254void eFusePhysicalReadRegisters(struct rt_rtmp_adapter *pAd,
3255				u16 Offset,
3256				u16 Length, u16 *pData);
3257
3258int RtmpEfuseSupportCheck(struct rt_rtmp_adapter *pAd);
3259
3260void eFuseGetFreeBlockCount(struct rt_rtmp_adapter *pAd, u32 *EfuseFreeBlock);
3261
3262int eFuse_init(struct rt_rtmp_adapter *pAd);
3263/*2008/09/11:KH add to support efuse--> */
3264#endif /* RTMP_EFUSE_SUPPORT // */
3265
3266/* add by johnli, RF power sequence setup */
3267void RT30xxLoadRFNormalModeSetup(struct rt_rtmp_adapter *pAd);
3268
3269void RT30xxLoadRFSleepModeSetup(struct rt_rtmp_adapter *pAd);
3270
3271void RT30xxReverseRFSleepModeSetup(struct rt_rtmp_adapter *pAd);
3272/* end johnli */
3273
3274#ifdef RT3070
3275void NICInitRT3070RFRegisters(struct rt_rtmp_adapter *pAd);
3276#endif /* RT3070 // */
3277#ifdef RT3090
3278void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd);
3279#endif /* RT3090 // */
3280
3281void RT30xxHaltAction(struct rt_rtmp_adapter *pAd);
3282
3283void RT30xxSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant);
3284#endif /* RT30xx // */
3285
3286void AsicEvaluateRxAnt(struct rt_rtmp_adapter *pAd);
3287
3288void AsicRxAntEvalTimeout(void *SystemSpecific1,
3289			  void *FunctionContext,
3290			  void *SystemSpecific2, void *SystemSpecific3);
3291
3292void APSDPeriodicExec(void *SystemSpecific1,
3293		      void *FunctionContext,
3294		      void *SystemSpecific2, void *SystemSpecific3);
3295
3296BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(struct rt_rtmp_adapter *pAd,
3297					   struct rt_mac_table_entry *pEntry);
3298
3299u8 RTMPStaFixedTxMode(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3300
3301void RTMPUpdateLegacyTxSetting(u8 fixed_tx_mode, struct rt_mac_table_entry *pEntry);
3302
3303BOOLEAN RTMPAutoRateSwitchCheck(struct rt_rtmp_adapter *pAd);
3304
3305int MlmeInit(struct rt_rtmp_adapter *pAd);
3306
3307void MlmeHandler(struct rt_rtmp_adapter *pAd);
3308
3309void MlmeHalt(struct rt_rtmp_adapter *pAd);
3310
3311void MlmeResetRalinkCounters(struct rt_rtmp_adapter *pAd);
3312
3313void BuildChannelList(struct rt_rtmp_adapter *pAd);
3314
3315u8 FirstChannel(struct rt_rtmp_adapter *pAd);
3316
3317u8 NextChannel(struct rt_rtmp_adapter *pAd, u8 channel);
3318
3319void ChangeToCellPowerLimit(struct rt_rtmp_adapter *pAd,
3320			    u8 AironetCellPowerLimit);
3321
3322/* */
3323/* Prototypes of function definition in rtmp_tkip.c */
3324/* */
3325void RTMPInitTkipEngine(struct rt_rtmp_adapter *pAd,
3326			u8 *pTKey,
3327			u8 KeyId,
3328			u8 *pTA,
3329			u8 *pMICKey,
3330			u8 *pTSC, unsigned long *pIV16, unsigned long *pIV32);
3331
3332void RTMPInitMICEngine(struct rt_rtmp_adapter *pAd,
3333		       u8 *pKey,
3334		       u8 *pDA,
3335		       u8 *pSA, u8 UserPriority, u8 *pMICKey);
3336
3337BOOLEAN RTMPTkipCompareMICValue(struct rt_rtmp_adapter *pAd,
3338				u8 *pSrc,
3339				u8 *pDA,
3340				u8 *pSA,
3341				u8 *pMICKey,
3342				u8 UserPriority, u32 Len);
3343
3344void RTMPCalculateMICValue(struct rt_rtmp_adapter *pAd,
3345			   void *pPacket,
3346			   u8 *pEncap,
3347			   struct rt_cipher_key *pKey, u8 apidx);
3348
3349void RTMPTkipAppendByte(struct rt_tkip_key_info *pTkip, u8 uChar);
3350
3351void RTMPTkipAppend(struct rt_tkip_key_info *pTkip, u8 *pSrc, u32 nBytes);
3352
3353void RTMPTkipGetMIC(struct rt_tkip_key_info *pTkip);
3354
3355BOOLEAN RTMPSoftDecryptTKIP(struct rt_rtmp_adapter *pAd,
3356			    u8 *pData,
3357			    unsigned long DataByteCnt,
3358			    u8 UserPriority, struct rt_cipher_key *pWpaKey);
3359
3360BOOLEAN RTMPSoftDecryptAES(struct rt_rtmp_adapter *pAd,
3361			   u8 *pData,
3362			   unsigned long DataByteCnt, struct rt_cipher_key *pWpaKey);
3363
3364/* */
3365/* Prototypes of function definition in cmm_info.c */
3366/* */
3367int RT_CfgSetCountryRegion(struct rt_rtmp_adapter *pAd, char *arg, int band);
3368
3369int RT_CfgSetWirelessMode(struct rt_rtmp_adapter *pAd, char *arg);
3370
3371int RT_CfgSetShortSlot(struct rt_rtmp_adapter *pAd, char *arg);
3372
3373int RT_CfgSetWepKey(struct rt_rtmp_adapter *pAd,
3374		    char *keyString,
3375		    struct rt_cipher_key *pSharedKey, int keyIdx);
3376
3377int RT_CfgSetWPAPSKKey(struct rt_rtmp_adapter *pAd,
3378		       char *keyString,
3379		       u8 *pHashStr,
3380		       int hashStrLen, u8 *pPMKBuf);
3381
3382/* */
3383/* Prototypes of function definition in cmm_info.c */
3384/* */
3385void RTMPWPARemoveAllKeys(struct rt_rtmp_adapter *pAd);
3386
3387void RTMPSetPhyMode(struct rt_rtmp_adapter *pAd, unsigned long phymode);
3388
3389void RTMPUpdateHTIE(struct rt_ht_capability *pRtHt,
3390		    u8 *pMcsSet,
3391		    struct rt_ht_capability_ie *pHtCapability,
3392		    struct rt_add_ht_info_ie *pAddHtInfo);
3393
3394void RTMPAddWcidAttributeEntry(struct rt_rtmp_adapter *pAd,
3395			       u8 BssIdx,
3396			       u8 KeyIdx,
3397			       u8 CipherAlg, struct rt_mac_table_entry *pEntry);
3398
3399char *GetEncryptType(char enc);
3400
3401char *GetAuthMode(char auth);
3402
3403void RTMPSetHT(struct rt_rtmp_adapter *pAd, struct rt_oid_set_ht_phymode *pHTPhyMode);
3404
3405void RTMPSetIndividualHT(struct rt_rtmp_adapter *pAd, u8 apidx);
3406
3407void RTMPSendWirelessEvent(struct rt_rtmp_adapter *pAd,
3408			   u16 Event_flag,
3409			   u8 *pAddr, u8 BssIdx, char Rssi);
3410
3411char ConvertToRssi(struct rt_rtmp_adapter *pAd, char Rssi, u8 RssiNumber);
3412
3413/*===================================
3414	Function prototype in cmm_wpa.c
3415  =================================== */
3416void RTMPToWirelessSta(struct rt_rtmp_adapter *pAd,
3417		       struct rt_mac_table_entry *pEntry,
3418		       u8 *pHeader802_3,
3419		       u32 HdrLen,
3420		       u8 *pData,
3421		       u32 DataLen, IN BOOLEAN bClearFrame);
3422
3423void WpaDerivePTK(struct rt_rtmp_adapter *pAd,
3424		  u8 *PMK,
3425		  u8 *ANonce,
3426		  u8 *AA,
3427		  u8 *SNonce,
3428		  u8 *SA, u8 *output, u32 len);
3429
3430void GenRandom(struct rt_rtmp_adapter *pAd, u8 *macAddr, u8 *random);
3431
3432BOOLEAN RTMPCheckWPAframe(struct rt_rtmp_adapter *pAd,
3433			  struct rt_mac_table_entry *pEntry,
3434			  u8 *pData,
3435			  unsigned long DataByteCount, u8 FromWhichBSSID);
3436
3437void AES_GTK_KEY_UNWRAP(u8 *key,
3438			u8 *plaintext,
3439			u32 c_len, u8 *ciphertext);
3440
3441BOOLEAN RTMPParseEapolKeyData(struct rt_rtmp_adapter *pAd,
3442			      u8 *pKeyData,
3443			      u8 KeyDataLen,
3444			      u8 GroupKeyIndex,
3445			      u8 MsgType,
3446			      IN BOOLEAN bWPA2, struct rt_mac_table_entry *pEntry);
3447
3448void ConstructEapolMsg(struct rt_mac_table_entry *pEntry,
3449		       u8 GroupKeyWepStatus,
3450		       u8 MsgType,
3451		       u8 DefaultKeyIdx,
3452		       u8 *KeyNonce,
3453		       u8 *TxRSC,
3454		       u8 *GTK,
3455		       u8 *RSNIE,
3456		       u8 RSNIE_Len, struct rt_eapol_packet *pMsg);
3457
3458int RTMPSoftDecryptBroadCastData(struct rt_rtmp_adapter *pAd,
3459					 struct rt_rx_blk *pRxBlk,
3460					 IN NDIS_802_11_ENCRYPTION_STATUS
3461					 GroupCipher,
3462					 struct rt_cipher_key *pShard_key);
3463
3464void RTMPMakeRSNIE(struct rt_rtmp_adapter *pAd,
3465		   u32 AuthMode, u32 WepStatus, u8 apidx);
3466
3467/* */
3468/* function prototype in ap_wpa.c */
3469/* */
3470void RTMPGetTxTscFromAsic(struct rt_rtmp_adapter *pAd,
3471			  u8 apidx, u8 *pTxTsc);
3472
3473void APInstallPairwiseKey(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3474
3475u32 APValidateRSNIE(struct rt_rtmp_adapter *pAd,
3476		     struct rt_mac_table_entry *pEntry,
3477		     u8 *pRsnIe, u8 rsnie_len);
3478
3479void HandleCounterMeasure(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3480
3481void WPAStart4WayHS(struct rt_rtmp_adapter *pAd,
3482		    struct rt_mac_table_entry *pEntry, unsigned long TimeInterval);
3483
3484void WPAStart2WayGroupHS(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3485
3486void PeerPairMsg1Action(struct rt_rtmp_adapter *pAd,
3487			struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3488
3489void PeerPairMsg2Action(struct rt_rtmp_adapter *pAd,
3490			struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3491
3492void PeerPairMsg3Action(struct rt_rtmp_adapter *pAd,
3493			struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3494
3495void PeerPairMsg4Action(struct rt_rtmp_adapter *pAd,
3496			struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3497
3498void PeerGroupMsg1Action(struct rt_rtmp_adapter *pAd,
3499			 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3500
3501void PeerGroupMsg2Action(struct rt_rtmp_adapter *pAd,
3502			 struct rt_mac_table_entry *pEntry,
3503			 void *Msg, u32 MsgLen);
3504
3505void WpaDeriveGTK(u8 *PMK,
3506		  u8 *GNonce,
3507		  u8 *AA, u8 *output, u32 len);
3508
3509void AES_GTK_KEY_WRAP(u8 *key,
3510		      u8 *plaintext,
3511		      u32 p_len, u8 *ciphertext);
3512
3513/*typedef void (*TIMER_FUNCTION)(unsigned long); */
3514
3515/* timeout -- ms */
3516void RTMP_SetPeriodicTimer(struct timer_list *pTimer,
3517			   IN unsigned long timeout);
3518
3519void RTMP_OS_Init_Timer(struct rt_rtmp_adapter *pAd,
3520			struct timer_list *pTimer,
3521			IN TIMER_FUNCTION function, void *data);
3522
3523void RTMP_OS_Add_Timer(struct timer_list *pTimer,
3524		       IN unsigned long timeout);
3525
3526void RTMP_OS_Mod_Timer(struct timer_list *pTimer,
3527		       IN unsigned long timeout);
3528
3529void RTMP_OS_Del_Timer(struct timer_list *pTimer,
3530		       OUT BOOLEAN *pCancelled);
3531
3532void RTMP_OS_Release_Packet(struct rt_rtmp_adapter *pAd, struct rt_queue_entry *pEntry);
3533
3534void RTMPusecDelay(unsigned long usec);
3535
3536int os_alloc_mem(struct rt_rtmp_adapter *pAd,
3537			 u8 **mem, unsigned long size);
3538
3539int os_free_mem(struct rt_rtmp_adapter *pAd, void *mem);
3540
3541void RTMP_AllocateSharedMemory(struct rt_rtmp_adapter *pAd,
3542			       unsigned long Length,
3543			       IN BOOLEAN Cached,
3544			       void **VirtualAddress,
3545			       dma_addr_t *PhysicalAddress);
3546
3547void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd);
3548
3549int AdapterBlockAllocateMemory(void *handle, void **ppAd);
3550
3551void RTMP_AllocateTxDescMemory(struct rt_rtmp_adapter *pAd,
3552			       u32 Index,
3553			       unsigned long Length,
3554			       IN BOOLEAN Cached,
3555			       void **VirtualAddress,
3556			       dma_addr_t *PhysicalAddress);
3557
3558void RTMP_AllocateFirstTxBuffer(struct rt_rtmp_adapter *pAd,
3559				u32 Index,
3560				unsigned long Length,
3561				IN BOOLEAN Cached,
3562				void **VirtualAddress,
3563				dma_addr_t *PhysicalAddress);
3564
3565void RTMP_FreeFirstTxBuffer(struct rt_rtmp_adapter *pAd,
3566			    unsigned long Length,
3567			    IN BOOLEAN Cached,
3568			    void *VirtualAddress,
3569			    dma_addr_t PhysicalAddress);
3570
3571void RTMP_AllocateMgmtDescMemory(struct rt_rtmp_adapter *pAd,
3572				 unsigned long Length,
3573				 IN BOOLEAN Cached,
3574				 void **VirtualAddress,
3575				 dma_addr_t *PhysicalAddress);
3576
3577void RTMP_AllocateRxDescMemory(struct rt_rtmp_adapter *pAd,
3578			       unsigned long Length,
3579			       IN BOOLEAN Cached,
3580			       void **VirtualAddress,
3581			       dma_addr_t *PhysicalAddress);
3582
3583void RTMP_FreeDescMemory(struct rt_rtmp_adapter *pAd,
3584			 unsigned long Length,
3585			 void *VirtualAddress,
3586			 dma_addr_t PhysicalAddress);
3587
3588void *RtmpOSNetPktAlloc(struct rt_rtmp_adapter *pAd, IN int size);
3589
3590void *RTMP_AllocateRxPacketBuffer(struct rt_rtmp_adapter *pAd,
3591					 unsigned long Length,
3592					 IN BOOLEAN Cached,
3593					 void **VirtualAddress,
3594					 OUT dma_addr_t *PhysicalAddress);
3595
3596void *RTMP_AllocateTxPacketBuffer(struct rt_rtmp_adapter *pAd,
3597					 unsigned long Length,
3598					 IN BOOLEAN Cached,
3599					 void **VirtualAddress);
3600
3601void *RTMP_AllocateFragPacketBuffer(struct rt_rtmp_adapter *pAd,
3602					   unsigned long Length);
3603
3604void RTMP_QueryPacketInfo(void *pPacket,
3605			  struct rt_packet_info *pPacketInfo,
3606			  u8 **pSrcBufVA, u32 *pSrcBufLen);
3607
3608void RTMP_QueryNextPacketInfo(void **ppPacket,
3609			      struct rt_packet_info *pPacketInfo,
3610			      u8 **pSrcBufVA, u32 *pSrcBufLen);
3611
3612BOOLEAN RTMP_FillTxBlkInfo(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk);
3613
3614struct rt_rtmp_sg_list *rt_get_sg_list_from_packet(void *pPacket,
3615						struct rt_rtmp_sg_list *sg);
3616
3617void announce_802_3_packet(struct rt_rtmp_adapter *pAd, void *pPacket);
3618
3619u32 BA_Reorder_AMSDU_Annnounce(struct rt_rtmp_adapter *pAd, void *pPacket);
3620
3621struct net_device *get_netdev_from_bssid(struct rt_rtmp_adapter *pAd, u8 FromWhichBSSID);
3622
3623void *duplicate_pkt(struct rt_rtmp_adapter *pAd,
3624			   u8 *pHeader802_3,
3625			   u32 HdrLen,
3626			   u8 *pData,
3627			   unsigned long DataSize, u8 FromWhichBSSID);
3628
3629void *duplicate_pkt_with_TKIP_MIC(struct rt_rtmp_adapter *pAd,
3630					 void *pOldPkt);
3631
3632void ba_flush_reordering_timeout_mpdus(struct rt_rtmp_adapter *pAd,
3633				       struct rt_ba_rec_entry *pBAEntry,
3634				       unsigned long Now32);
3635
3636void BAOriSessionSetUp(struct rt_rtmp_adapter *pAd,
3637		       struct rt_mac_table_entry *pEntry,
3638		       u8 TID,
3639		       u16 TimeOut,
3640		       unsigned long DelayTime, IN BOOLEAN isForced);
3641
3642void BASessionTearDownALL(struct rt_rtmp_adapter *pAd, u8 Wcid);
3643
3644BOOLEAN OS_Need_Clone_Packet(void);
3645
3646void build_tx_packet(struct rt_rtmp_adapter *pAd,
3647		     void *pPacket,
3648		     u8 *pFrame, unsigned long FrameLen);
3649
3650void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd,
3651			  u8 Wcid,
3652			  u8 TID,
3653			  IN BOOLEAN bPassive, IN BOOLEAN bForceSend);
3654
3655void BARecSessionTearDown(struct rt_rtmp_adapter *pAd,
3656			  u8 Wcid, u8 TID, IN BOOLEAN bPassive);
3657
3658BOOLEAN ba_reordering_resource_init(struct rt_rtmp_adapter *pAd, int num);
3659void ba_reordering_resource_release(struct rt_rtmp_adapter *pAd);
3660
3661char *rstrtok(char *s, IN const char *ct);
3662
3663/*//////// common ioctl functions ////////// */
3664int SetCommonHT(struct rt_rtmp_adapter *pAd);
3665
3666int WpaCheckEapCode(struct rt_rtmp_adapter *pAd,
3667		    u8 *pFrame, u16 FrameLen, u16 OffSet);
3668
3669void WpaSendMicFailureToWpaSupplicant(struct rt_rtmp_adapter *pAd,
3670				      IN BOOLEAN bUnicast);
3671
3672int wext_notify_event_assoc(struct rt_rtmp_adapter *pAd);
3673
3674BOOLEAN STARxDoneInterruptHandle(struct rt_rtmp_adapter *pAd, IN BOOLEAN argc);
3675
3676/* AMPDU packet indication */
3677void Indicate_AMPDU_Packet(struct rt_rtmp_adapter *pAd,
3678			   struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3679
3680/* AMSDU packet indication */
3681void Indicate_AMSDU_Packet(struct rt_rtmp_adapter *pAd,
3682			   struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3683
3684/* Normal legacy Rx packet indication */
3685void Indicate_Legacy_Packet(struct rt_rtmp_adapter *pAd,
3686			    struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3687
3688void Indicate_EAPOL_Packet(struct rt_rtmp_adapter *pAd,
3689			   struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3690
3691void update_os_packet_info(struct rt_rtmp_adapter *pAd,
3692			   struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3693
3694void wlan_802_11_to_802_3_packet(struct rt_rtmp_adapter *pAd,
3695				 struct rt_rx_blk *pRxBlk,
3696				 u8 *pHeader802_3,
3697				 u8 FromWhichBSSID);
3698
3699/* remove LLC and get 802_3 Header */
3700#define  RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(_pRxBlk, _pHeader802_3)	\
3701{																				\
3702	u8 *_pRemovedLLCSNAP = NULL, *_pDA, *_pSA;                                 \
3703																				\
3704	if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_MESH))	{            \
3705		_pDA = _pRxBlk->pHeader->Addr3;                                         \
3706		_pSA = (u8 *)_pRxBlk->pHeader + sizeof(struct rt_header_802_11);                \
3707	}                                                                           \
3708	else	{\
3709		if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_INFRA))	{\
3710			_pDA = _pRxBlk->pHeader->Addr1;                                     \
3711		if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_DLS))									\
3712			_pSA = _pRxBlk->pHeader->Addr2;										\
3713		else																	\
3714			_pSA = _pRxBlk->pHeader->Addr3;                                     \
3715		}                                                                       \
3716		else	{	\
3717			_pDA = _pRxBlk->pHeader->Addr1;                                     \
3718			_pSA = _pRxBlk->pHeader->Addr2;                                     \
3719		}                                                                       \
3720	}                                                                           \
3721																				\
3722	CONVERT_TO_802_3(_pHeader802_3, _pDA, _pSA, _pRxBlk->pData, 				\
3723		_pRxBlk->DataSize, _pRemovedLLCSNAP);                                   \
3724}
3725
3726void Sta_Announce_or_Forward_802_3_Packet(struct rt_rtmp_adapter *pAd,
3727					  void *pPacket,
3728					  u8 FromWhichBSSID);
3729
3730#define ANNOUNCE_OR_FORWARD_802_3_PACKET(_pAd, _pPacket, _FromWhichBSS)\
3731			Sta_Announce_or_Forward_802_3_Packet(_pAd, _pPacket, _FromWhichBSS);
3732			/*announce_802_3_packet(_pAd, _pPacket); */
3733
3734void *DuplicatePacket(struct rt_rtmp_adapter *pAd,
3735			     void *pPacket, u8 FromWhichBSSID);
3736
3737void *ClonePacket(struct rt_rtmp_adapter *pAd,
3738			 void *pPacket,
3739			 u8 *pData, unsigned long DataSize);
3740
3741/* Normal, AMPDU or AMSDU */
3742void CmmRxnonRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
3743				 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3744
3745void CmmRxRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
3746			      struct rt_mac_table_entry *pEntry,
3747			      struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3748
3749void Update_Rssi_Sample(struct rt_rtmp_adapter *pAd,
3750			struct rt_rssi_sample *pRssi, struct rt_rxwi * pRxWI);
3751
3752void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd,
3753				 OUT PRT28XX_RXD_STRUC pSaveRxD,
3754				 OUT BOOLEAN *pbReschedule,
3755				 IN u32 *pRxPending);
3756
3757void *RTMPDeFragmentDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk);
3758
3759enum {
3760	DIDmsg_lnxind_wlansniffrm = 0x00000044,
3761	DIDmsg_lnxind_wlansniffrm_hosttime = 0x00010044,
3762	DIDmsg_lnxind_wlansniffrm_mactime = 0x00020044,
3763	DIDmsg_lnxind_wlansniffrm_channel = 0x00030044,
3764	DIDmsg_lnxind_wlansniffrm_rssi = 0x00040044,
3765	DIDmsg_lnxind_wlansniffrm_sq = 0x00050044,
3766	DIDmsg_lnxind_wlansniffrm_signal = 0x00060044,
3767	DIDmsg_lnxind_wlansniffrm_noise = 0x00070044,
3768	DIDmsg_lnxind_wlansniffrm_rate = 0x00080044,
3769	DIDmsg_lnxind_wlansniffrm_istx = 0x00090044,
3770	DIDmsg_lnxind_wlansniffrm_frmlen = 0x000A0044
3771};
3772enum {
3773	P80211ENUM_msgitem_status_no_value = 0x00
3774};
3775enum {
3776	P80211ENUM_truth_false = 0x00,
3777	P80211ENUM_truth_true = 0x01
3778};
3779
3780/* Definition from madwifi */
3781struct rt_p80211item_uint32 {
3782	u32 did;
3783	u16 status;
3784	u16 len;
3785	u32 data;
3786};
3787
3788struct rt_wlan_ng_prism2_header {
3789	u32 msgcode;
3790	u32 msglen;
3791#define WLAN_DEVNAMELEN_MAX 16
3792	u8 devname[WLAN_DEVNAMELEN_MAX];
3793	struct rt_p80211item_uint32 hosttime;
3794	struct rt_p80211item_uint32 mactime;
3795	struct rt_p80211item_uint32 channel;
3796	struct rt_p80211item_uint32 rssi;
3797	struct rt_p80211item_uint32 sq;
3798	struct rt_p80211item_uint32 signal;
3799	struct rt_p80211item_uint32 noise;
3800	struct rt_p80211item_uint32 rate;
3801	struct rt_p80211item_uint32 istx;
3802	struct rt_p80211item_uint32 frmlen;
3803};
3804
3805/* The radio capture header precedes the 802.11 header. */
3806struct PACKED rt_ieee80211_radiotap_header {
3807	u8 it_version;	/* Version 0. Only increases
3808				 * for drastic changes,
3809				 * introduction of compatible
3810				 * new fields does not count.
3811				 */
3812	u8 it_pad;
3813	u16 it_len;		/* length of the whole
3814				 * header in bytes, including
3815				 * it_version, it_pad,
3816				 * it_len, and data fields.
3817				 */
3818	u32 it_present;	/* A bitmap telling which
3819				 * fields are present. Set bit 31
3820				 * (0x80000000) to extend the
3821				 * bitmap by another 32 bits.
3822				 * Additional extensions are made
3823				 * by setting bit 31.
3824				 */
3825};
3826
3827enum ieee80211_radiotap_type {
3828	IEEE80211_RADIOTAP_TSFT = 0,
3829	IEEE80211_RADIOTAP_FLAGS = 1,
3830	IEEE80211_RADIOTAP_RATE = 2,
3831	IEEE80211_RADIOTAP_CHANNEL = 3,
3832	IEEE80211_RADIOTAP_FHSS = 4,
3833	IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
3834	IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
3835	IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
3836	IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
3837	IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
3838	IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
3839	IEEE80211_RADIOTAP_ANTENNA = 11,
3840	IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
3841	IEEE80211_RADIOTAP_DB_ANTNOISE = 13
3842};
3843
3844#define WLAN_RADIOTAP_PRESENT (			\
3845	(1 << IEEE80211_RADIOTAP_TSFT)	|	\
3846	(1 << IEEE80211_RADIOTAP_FLAGS) |	\
3847	(1 << IEEE80211_RADIOTAP_RATE)  | 	\
3848	 0)
3849
3850struct rt_wlan_radiotap_header {
3851	struct rt_ieee80211_radiotap_header wt_ihdr;
3852	long long wt_tsft;
3853	u8 wt_flags;
3854	u8 wt_rate;
3855};
3856/* Definition from madwifi */
3857
3858void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk);
3859
3860void RTMPSetDesiredRates(struct rt_rtmp_adapter *pAdapter, long Rates);
3861
3862int Set_FixedTxMode_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3863
3864BOOLEAN RT28XXChipsetCheck(IN void *_dev_p);
3865
3866void RT28XXDMADisable(struct rt_rtmp_adapter *pAd);
3867
3868void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd);
3869
3870void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd,
3871			       int apidx,
3872			       unsigned long BeaconLen, unsigned long UpdatePos);
3873
3874int rt28xx_init(struct rt_rtmp_adapter *pAd,
3875		char *pDefaultMac, char *pHostName);
3876
3877int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd);
3878
3879void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd);
3880
3881int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd);
3882
3883void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd);
3884
3885void tbtt_tasklet(unsigned long data);
3886
3887struct net_device *RtmpPhyNetDevInit(struct rt_rtmp_adapter *pAd,
3888			   struct rt_rtmp_os_netdev_op_hook *pNetHook);
3889
3890BOOLEAN RtmpPhyNetDevExit(struct rt_rtmp_adapter *pAd, struct net_device *net_dev);
3891
3892int RtmpRaDevCtrlInit(struct rt_rtmp_adapter *pAd, IN RTMP_INF_TYPE infType);
3893
3894BOOLEAN RtmpRaDevCtrlExit(struct rt_rtmp_adapter *pAd);
3895
3896#ifdef RTMP_MAC_PCI
3897/* */
3898/* Function Prototype in cmm_data_pci.c */
3899/* */
3900u16 RtmpPCI_WriteTxResource(struct rt_rtmp_adapter *pAd,
3901			       struct rt_tx_blk *pTxBlk,
3902			       IN BOOLEAN bIsLast, u16 *FreeNumber);
3903
3904u16 RtmpPCI_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
3905				     struct rt_tx_blk *pTxBlk,
3906				     IN BOOLEAN bIsLast,
3907				     u16 *FreeNumber);
3908
3909u16 RtmpPCI_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
3910				    struct rt_tx_blk *pTxBlk,
3911				    u8 frameNum, u16 *FreeNumber);
3912
3913u16 RtmpPCI_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
3914				   struct rt_tx_blk *pTxBlk,
3915				   u8 fragNum, u16 *FreeNumber);
3916
3917u16 RtmpPCI_WriteSubTxResource(struct rt_rtmp_adapter *pAd,
3918				  struct rt_tx_blk *pTxBlk,
3919				  IN BOOLEAN bIsLast, u16 *FreeNumber);
3920
3921void RtmpPCI_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
3922				  struct rt_tx_blk *pTxBlk,
3923				  u16 totalMPDUSize,
3924				  u16 FirstTxIdx);
3925
3926void RtmpPCIDataLastTxIdx(struct rt_rtmp_adapter *pAd,
3927			  u8 QueIdx, u16 LastTxIdx);
3928
3929void RtmpPCIDataKickOut(struct rt_rtmp_adapter *pAd,
3930			struct rt_tx_blk *pTxBlk, u8 QueIdx);
3931
3932int RtmpPCIMgmtKickOut(struct rt_rtmp_adapter *pAd,
3933		       u8 QueIdx,
3934		       void *pPacket,
3935		       u8 *pSrcBufVA, u32 SrcBufLen);
3936
3937int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
3938			     struct rt_header_802_11 *pHeader,
3939			     struct rt_rxwi *pRxWI, IN PRT28XX_RXD_STRUC pRxD);
3940
3941BOOLEAN RT28xxPciAsicRadioOff(struct rt_rtmp_adapter *pAd,
3942			      u8 Level, u16 TbttNumToNextWakeUp);
3943
3944BOOLEAN RT28xxPciAsicRadioOn(struct rt_rtmp_adapter *pAd, u8 Level);
3945
3946void RTMPInitPCIeLinkCtrlValue(struct rt_rtmp_adapter *pAd);
3947
3948void RTMPFindHostPCIDev(struct rt_rtmp_adapter *pAd);
3949
3950void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level);
3951
3952void RTMPPCIeLinkCtrlSetting(struct rt_rtmp_adapter *pAd, u16 Max);
3953
3954void RTMPrt3xSetPCIePowerLinkCtrl(struct rt_rtmp_adapter *pAd);
3955
3956void PsPollWakeExec(void *SystemSpecific1,
3957		    void *FunctionContext,
3958		    void *SystemSpecific2, void *SystemSpecific3);
3959
3960void RadioOnExec(void *SystemSpecific1,
3961		 void *FunctionContext,
3962		 void *SystemSpecific2, void *SystemSpecific3);
3963
3964void RT28xxPciStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
3965
3966void RT28xxPciStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
3967					 u16 TbttNumToNextWakeUp);
3968
3969void RT28xxPciMlmeRadioOn(struct rt_rtmp_adapter *pAd);
3970
3971void RT28xxPciMlmeRadioOFF(struct rt_rtmp_adapter *pAd);
3972#endif /* RTMP_MAC_PCI // */
3973
3974#ifdef RTMP_MAC_USB
3975/* */
3976/* Function Prototype in rtusb_bulk.c */
3977/* */
3978void RTUSBInitTxDesc(struct rt_rtmp_adapter *pAd,
3979		     struct rt_tx_context *pTxContext,
3980		     u8 BulkOutPipeId, IN usb_complete_t Func);
3981
3982void RTUSBInitHTTxDesc(struct rt_rtmp_adapter *pAd,
3983		       struct rt_ht_tx_context *pTxContext,
3984		       u8 BulkOutPipeId,
3985		       unsigned long BulkOutSize, IN usb_complete_t Func);
3986
3987void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext);
3988
3989void RTUSBCleanUpDataBulkOutQueue(struct rt_rtmp_adapter *pAd);
3990
3991void RTUSBCancelPendingBulkOutIRP(struct rt_rtmp_adapter *pAd);
3992
3993void RTUSBBulkOutDataPacket(struct rt_rtmp_adapter *pAd,
3994			    u8 BulkOutPipeId, u8 Index);
3995
3996void RTUSBBulkOutNullFrame(struct rt_rtmp_adapter *pAd);
3997
3998void RTUSBBulkOutRTSFrame(struct rt_rtmp_adapter *pAd);
3999
4000void RTUSBCancelPendingBulkInIRP(struct rt_rtmp_adapter *pAd);
4001
4002void RTUSBCancelPendingIRPs(struct rt_rtmp_adapter *pAd);
4003
4004void RTUSBBulkOutMLMEPacket(struct rt_rtmp_adapter *pAd, u8 Index);
4005
4006void RTUSBBulkOutPsPoll(struct rt_rtmp_adapter *pAd);
4007
4008void RTUSBCleanUpMLMEBulkOutQueue(struct rt_rtmp_adapter *pAd);
4009
4010void RTUSBKickBulkOut(struct rt_rtmp_adapter *pAd);
4011
4012void RTUSBBulkReceive(struct rt_rtmp_adapter *pAd);
4013
4014void DoBulkIn(struct rt_rtmp_adapter *pAd);
4015
4016void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext);
4017
4018void RTUSBBulkRxHandle(IN unsigned long data);
4019
4020/* */
4021/* Function Prototype in rtusb_io.c */
4022/* */
4023int RTUSBMultiRead(struct rt_rtmp_adapter *pAd,
4024			u16 Offset, u8 *pData, u16 length);
4025
4026int RTUSBMultiWrite(struct rt_rtmp_adapter *pAd,
4027		    u16 Offset, const u8 *pData, u16 length);
4028
4029int RTUSBMultiWrite_OneByte(struct rt_rtmp_adapter *pAd,
4030			    u16 Offset, const u8 *pData);
4031
4032int RTUSBReadBBPRegister(struct rt_rtmp_adapter *pAd,
4033			      u8 Id, u8 *pValue);
4034
4035int RTUSBWriteBBPRegister(struct rt_rtmp_adapter *pAd,
4036			       u8 Id, u8 Value);
4037
4038int RTUSBWriteRFRegister(struct rt_rtmp_adapter *pAd, u32 Value);
4039
4040int RTUSB_VendorRequest(struct rt_rtmp_adapter *pAd,
4041			     u32 TransferFlags,
4042			     u8 ReservedBits,
4043			     u8 Request,
4044			     u16 Value,
4045			     u16 Index,
4046			     void *TransferBuffer,
4047			     u32 TransferBufferLength);
4048
4049int RTUSBReadEEPROM(struct rt_rtmp_adapter *pAd,
4050			 u16 Offset, u8 *pData, u16 length);
4051
4052int RTUSBWriteEEPROM(struct rt_rtmp_adapter *pAd,
4053			  u16 Offset, u8 *pData, u16 length);
4054
4055void RTUSBPutToSleep(struct rt_rtmp_adapter *pAd);
4056
4057int RTUSBWakeUp(struct rt_rtmp_adapter *pAd);
4058
4059void RTUSBInitializeCmdQ(struct rt_cmdq *cmdq);
4060
4061int RTUSBEnqueueCmdFromNdis(struct rt_rtmp_adapter *pAd,
4062				    IN NDIS_OID Oid,
4063				    IN BOOLEAN SetInformation,
4064				    void *pInformationBuffer,
4065				    u32 InformationBufferLength);
4066
4067int RTUSBEnqueueInternalCmd(struct rt_rtmp_adapter *pAd,
4068				    IN NDIS_OID Oid,
4069				    void *pInformationBuffer,
4070				    u32 InformationBufferLength);
4071
4072void RTUSBDequeueCmd(struct rt_cmdq *cmdq, struct rt_cmdqelmt * * pcmdqelmt);
4073
4074int RTUSBCmdThread(IN void *Context);
4075
4076void RTUSBBssBeaconExit(struct rt_rtmp_adapter *pAd);
4077
4078void RTUSBBssBeaconStop(struct rt_rtmp_adapter *pAd);
4079
4080void RTUSBBssBeaconStart(struct rt_rtmp_adapter *pAd);
4081
4082void RTUSBBssBeaconInit(struct rt_rtmp_adapter *pAd);
4083
4084void RTUSBWatchDog(struct rt_rtmp_adapter *pAd);
4085
4086int RTUSBWriteMACRegister(struct rt_rtmp_adapter *pAd,
4087			       u16 Offset, u32 Value);
4088
4089int RTUSBReadMACRegister(struct rt_rtmp_adapter *pAd,
4090			      u16 Offset, u32 *pValue);
4091
4092int RTUSBSingleWrite(struct rt_rtmp_adapter *pAd,
4093			  u16 Offset, u16 Value);
4094
4095int RTUSBFirmwareWrite(struct rt_rtmp_adapter *pAd,
4096		       const u8 *pFwImage, unsigned long FwLen);
4097
4098int RTUSBVenderReset(struct rt_rtmp_adapter *pAd);
4099
4100int RTUSBSetHardWareRegister(struct rt_rtmp_adapter *pAdapter, void *pBuf);
4101
4102int RTUSBQueryHardWareRegister(struct rt_rtmp_adapter *pAdapter,
4103				       void *pBuf);
4104
4105void CMDHandler(struct rt_rtmp_adapter *pAd);
4106
4107int RTUSBWriteHWMACAddress(struct rt_rtmp_adapter *pAdapter);
4108
4109void MacTableInitialize(struct rt_rtmp_adapter *pAd);
4110
4111void MlmeSetPsm(struct rt_rtmp_adapter *pAd, u16 psm);
4112
4113int RTMPWPAAddKeyProc(struct rt_rtmp_adapter *pAd, void *pBuf);
4114
4115void AsicRxAntEvalAction(struct rt_rtmp_adapter *pAd);
4116
4117void append_pkt(struct rt_rtmp_adapter *pAd,
4118		u8 *pHeader802_3,
4119		u32 HdrLen,
4120		u8 *pData,
4121		unsigned long DataSize, void **ppPacket);
4122
4123u32 deaggregate_AMSDU_announce(struct rt_rtmp_adapter *pAd,
4124				void *pPacket,
4125				u8 *pData, unsigned long DataSize);
4126
4127int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
4128			     struct rt_header_802_11 *pHeader,
4129			     struct rt_rxwi *pRxWI,
4130			     IN PRT28XX_RXD_STRUC pRxINFO);
4131
4132void RTUSBMlmeHardTransmit(struct rt_rtmp_adapter *pAd, struct rt_mgmt *pMgmt);
4133
4134int MlmeThread(void *Context);
4135
4136/* */
4137/* Function Prototype in rtusb_data.c */
4138/* */
4139int RTUSBFreeDescriptorRequest(struct rt_rtmp_adapter *pAd,
4140				       u8 BulkOutPipeId,
4141				       u32 NumberRequired);
4142
4143BOOLEAN RTUSBNeedQueueBackForAgg(struct rt_rtmp_adapter *pAd, u8 BulkOutPipeId);
4144
4145void RTMPWriteTxInfo(struct rt_rtmp_adapter *pAd,
4146		     struct rt_txinfo *pTxInfo,
4147		     u16 USBDMApktLen,
4148		     IN BOOLEAN bWiv,
4149		     u8 QueueSel, u8 NextValid, u8 TxBurst);
4150
4151/* */
4152/* Function Prototype in cmm_data_usb.c */
4153/* */
4154u16 RtmpUSB_WriteSubTxResource(struct rt_rtmp_adapter *pAd,
4155				  struct rt_tx_blk *pTxBlk,
4156				  IN BOOLEAN bIsLast, u16 *FreeNumber);
4157
4158u16 RtmpUSB_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
4159				     struct rt_tx_blk *pTxBlk,
4160				     IN BOOLEAN bIsLast,
4161				     u16 *FreeNumber);
4162
4163u16 RtmpUSB_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
4164				   struct rt_tx_blk *pTxBlk,
4165				   u8 fragNum, u16 *FreeNumber);
4166
4167u16 RtmpUSB_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
4168				    struct rt_tx_blk *pTxBlk,
4169				    u8 frameNum, u16 *FreeNumber);
4170
4171void RtmpUSB_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
4172				  struct rt_tx_blk *pTxBlk,
4173				  u16 totalMPDUSize, u16 TxIdx);
4174
4175void RtmpUSBDataLastTxIdx(struct rt_rtmp_adapter *pAd,
4176			  u8 QueIdx, u16 TxIdx);
4177
4178void RtmpUSBDataKickOut(struct rt_rtmp_adapter *pAd,
4179			struct rt_tx_blk *pTxBlk, u8 QueIdx);
4180
4181int RtmpUSBMgmtKickOut(struct rt_rtmp_adapter *pAd,
4182		       u8 QueIdx,
4183		       void *pPacket,
4184		       u8 *pSrcBufVA, u32 SrcBufLen);
4185
4186void RtmpUSBNullFrameKickOut(struct rt_rtmp_adapter *pAd,
4187			     u8 QueIdx,
4188			     u8 *pNullFrame, u32 frameLen);
4189
4190void RtmpUsbStaAsicForceWakeupTimeout(void *SystemSpecific1,
4191				      void *FunctionContext,
4192				      void *SystemSpecific2,
4193				      void *SystemSpecific3);
4194
4195void RT28xxUsbStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
4196
4197void RT28xxUsbStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
4198					 u16 TbttNumToNextWakeUp);
4199
4200void RT28xxUsbMlmeRadioOn(struct rt_rtmp_adapter *pAd);
4201
4202void RT28xxUsbMlmeRadioOFF(struct rt_rtmp_adapter *pAd);
4203#endif /* RTMP_MAC_USB // */
4204
4205void AsicTurnOffRFClk(struct rt_rtmp_adapter *pAd, u8 Channel);
4206
4207void AsicTurnOnRFClk(struct rt_rtmp_adapter *pAd, u8 Channel);
4208
4209#ifdef RTMP_TIMER_TASK_SUPPORT
4210int RtmpTimerQThread(IN void *Context);
4211
4212struct rt_rtmp_timer_task_entry *RtmpTimerQInsert(struct rt_rtmp_adapter *pAd,
4213					struct rt_ralink_timer *pTimer);
4214
4215BOOLEAN RtmpTimerQRemove(struct rt_rtmp_adapter *pAd,
4216			 struct rt_ralink_timer *pTimer);
4217
4218void RtmpTimerQExit(struct rt_rtmp_adapter *pAd);
4219
4220void RtmpTimerQInit(struct rt_rtmp_adapter *pAd);
4221#endif /* RTMP_TIMER_TASK_SUPPORT // */
4222
4223void AsicStaBbpTuning(struct rt_rtmp_adapter *pAd);
4224
4225BOOLEAN StaAddMacTableEntry(struct rt_rtmp_adapter *pAd,
4226			    struct rt_mac_table_entry *pEntry,
4227			    u8 MaxSupportedRateIn500Kbps,
4228			    struct rt_ht_capability_ie *pHtCapability,
4229			    u8 HtCapabilityLen,
4230			    struct rt_add_ht_info_ie *pAddHtInfo,
4231			    u8 AddHtInfoLen, u16 CapabilityInfo);
4232
4233BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd,
4234		     struct rt_mlme_queue_elem *pElem,
4235		     struct rt_ralink_timer *pAuthTimer,
4236		     char *pSMName,
4237		     u16 SeqNo,
4238		     u8 *pNewElement, unsigned long ElementLen);
4239
4240void RTMP_IndicateMediaState(struct rt_rtmp_adapter *pAd);
4241
4242void ReSyncBeaconTime(struct rt_rtmp_adapter *pAd);
4243
4244void RTMPSetAGCInitValue(struct rt_rtmp_adapter *pAd, u8 BandWidth);
4245
4246int rt28xx_close(struct net_device *dev);
4247int rt28xx_open(struct net_device *dev);
4248
4249#define VIRTUAL_IF_INC(__pAd) ((__pAd)->VirtualIfCnt++)
4250#define VIRTUAL_IF_DEC(__pAd) ((__pAd)->VirtualIfCnt--)
4251#define VIRTUAL_IF_NUM(__pAd) ((__pAd)->VirtualIfCnt)
4252
4253__inline int VIRTUAL_IF_UP(struct rt_rtmp_adapter *pAd)
4254{
4255	if (VIRTUAL_IF_NUM(pAd) == 0) {
4256		if (rt28xx_open(pAd->net_dev) != 0) {
4257			DBGPRINT(RT_DEBUG_TRACE,
4258				 ("rt28xx_open return fail!\n"));
4259			return -1;
4260		}
4261	} else {
4262	}
4263	VIRTUAL_IF_INC(pAd);
4264	return 0;
4265}
4266
4267__inline void VIRTUAL_IF_DOWN(struct rt_rtmp_adapter *pAd)
4268{
4269	VIRTUAL_IF_DEC(pAd);
4270	if (VIRTUAL_IF_NUM(pAd) == 0)
4271		rt28xx_close(pAd->net_dev);
4272	return;
4273}
4274
4275/*
4276	OS Related funciton prototype definitions.
4277	TODO: Maybe we need to move these function prototypes to other proper place.
4278*/
4279int RtmpOSWrielessEventSend(struct rt_rtmp_adapter *pAd,
4280			    u32 eventType,
4281			    int flags,
4282			    u8 *pSrcMac,
4283			    u8 *pData, u32 dataLen);
4284
4285int RtmpOSNetDevAddrSet(struct net_device *pNetDev, u8 *pMacAddr);
4286
4287int RtmpOSNetDevAttach(struct net_device *pNetDev,
4288		       struct rt_rtmp_os_netdev_op_hook *pDevOpHook);
4289
4290void RtmpOSNetDevClose(struct net_device *pNetDev);
4291
4292void RtmpOSNetDevDetach(struct net_device *pNetDev);
4293
4294int RtmpOSNetDevAlloc(struct net_device **pNewNetDev, u32 privDataSize);
4295
4296void RtmpOSNetDevFree(struct net_device *pNetDev);
4297
4298struct net_device *RtmpOSNetDevGetByName(struct net_device *pNetDev, char *pDevName);
4299
4300void RtmpOSNetDeviceRefPut(struct net_device *pNetDev);
4301
4302struct net_device *RtmpOSNetDevCreate(struct rt_rtmp_adapter *pAd,
4303			    int devType,
4304			    int devNum,
4305			    int privMemSize, char *pNamePrefix);
4306
4307/*
4308	Task operation related function prototypes
4309*/
4310void RtmpOSTaskCustomize(struct rt_rtmp_os_task *pTask);
4311
4312int RtmpOSTaskNotifyToExit(struct rt_rtmp_os_task *pTask);
4313
4314int RtmpOSTaskKill(struct rt_rtmp_os_task *pTask);
4315
4316int RtmpOSTaskInit(struct rt_rtmp_os_task *pTask,
4317			   char *pTaskName, void * pPriv);
4318
4319int RtmpOSTaskAttach(struct rt_rtmp_os_task *pTask,
4320			     IN int (*fn) (void *), IN void *arg);
4321
4322/*
4323	File operation related function prototypes
4324*/
4325struct file *RtmpOSFileOpen(IN char *pPath, IN int flag, IN int mode);
4326
4327int RtmpOSFileClose(struct file *osfd);
4328
4329void RtmpOSFileSeek(struct file *osfd, IN int offset);
4330
4331int RtmpOSFileRead(struct file *osfd, IN char *pDataPtr, IN int readLen);
4332
4333int RtmpOSFileWrite(struct file *osfd, IN char *pDataPtr, IN int writeLen);
4334
4335#endif /* __RTMP_H__ */
4336