/kern_2.6.32/drivers/staging/rt3090/rtmp.h

http://omnia2droid.googlecode.com/ · C++ Header · 6873 lines · 4998 code · 1315 blank · 560 comment · 96 complexity · 6fd45c494fabd737451d1d3036c7fffa MD5 · raw file

Large files are truncated click here to view the full file

  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. Module Name:
  27. rtmp.h
  28. Abstract:
  29. Miniport generic portion header file
  30. Revision History:
  31. Who When What
  32. -------- ---------- ----------------------------------------------
  33. Paul Lin 2002-08-01 created
  34. James Tan 2002-09-06 modified (Revise NTCRegTable)
  35. John Chang 2004-09-06 modified for RT2600
  36. */
  37. #ifndef __RTMP_H__
  38. #define __RTMP_H__
  39. #include "link_list.h"
  40. #include "spectrum_def.h"
  41. #include "rtmp_dot11.h"
  42. #ifdef MLME_EX
  43. #include "mlme_ex_def.h"
  44. #endif // MLME_EX //
  45. #ifdef CONFIG_STA_SUPPORT
  46. #endif // CONFIG_STA_SUPPORT //
  47. #undef AP_WSC_INCLUDED
  48. #undef STA_WSC_INCLUDED
  49. #undef WSC_INCLUDED
  50. #ifdef CONFIG_STA_SUPPORT
  51. #endif // CONFIG_STA_SUPPORT //
  52. #if defined(AP_WSC_INCLUDED) || defined(STA_WSC_INCLUDED)
  53. #define WSC_INCLUDED
  54. #endif
  55. #include "rtmp_chip.h"
  56. typedef struct _RTMP_ADAPTER RTMP_ADAPTER;
  57. typedef struct _RTMP_ADAPTER *PRTMP_ADAPTER;
  58. typedef struct _RTMP_CHIP_OP_ RTMP_CHIP_OP;
  59. //#define DBG 1
  60. //#define DBG_DIAGNOSE 1
  61. //+++Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function
  62. #define MAX_DATAMM_RETRY 3
  63. #define MGMT_USE_QUEUE_FLAG 0x80
  64. //---Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function
  65. #define MAXSEQ (0xFFF)
  66. #if defined(CONFIG_AP_SUPPORT) && defined(CONFIG_STA_SUPPORT)
  67. #define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd) if(_pAd->OpMode == OPMODE_AP)
  68. #define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd) if(_pAd->OpMode == OPMODE_STA)
  69. #else
  70. #define IF_DEV_CONFIG_OPMODE_ON_AP(_pAd)
  71. #define IF_DEV_CONFIG_OPMODE_ON_STA(_pAd)
  72. #endif
  73. extern unsigned char SNAP_AIRONET[];
  74. extern unsigned char CISCO_OUI[];
  75. extern UCHAR BaSizeArray[4];
  76. extern UCHAR BROADCAST_ADDR[MAC_ADDR_LEN];
  77. extern UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN];
  78. extern ULONG BIT32[32];
  79. extern UCHAR BIT8[8];
  80. extern char* CipherName[];
  81. extern char* MCSToMbps[];
  82. extern UCHAR RxwiMCSToOfdmRate[12];
  83. extern UCHAR SNAP_802_1H[6];
  84. extern UCHAR SNAP_BRIDGE_TUNNEL[6];
  85. extern UCHAR SNAP_AIRONET[8];
  86. extern UCHAR CKIP_LLC_SNAP[8];
  87. extern UCHAR EAPOL_LLC_SNAP[8];
  88. extern UCHAR EAPOL[2];
  89. extern UCHAR IPX[2];
  90. extern UCHAR APPLE_TALK[2];
  91. extern UCHAR RateIdToPlcpSignal[12]; // see IEEE802.11a-1999 p.14
  92. extern UCHAR OfdmRateToRxwiMCS[];
  93. extern UCHAR OfdmSignalToRateId[16] ;
  94. extern UCHAR default_cwmin[4];
  95. extern UCHAR default_cwmax[4];
  96. extern UCHAR default_sta_aifsn[4];
  97. extern UCHAR MapUserPriorityToAccessCategory[8];
  98. extern USHORT RateUpPER[];
  99. extern USHORT RateDownPER[];
  100. extern UCHAR Phy11BNextRateDownward[];
  101. extern UCHAR Phy11BNextRateUpward[];
  102. extern UCHAR Phy11BGNextRateDownward[];
  103. extern UCHAR Phy11BGNextRateUpward[];
  104. extern UCHAR Phy11ANextRateDownward[];
  105. extern UCHAR Phy11ANextRateUpward[];
  106. extern CHAR RssiSafeLevelForTxRate[];
  107. extern UCHAR RateIdToMbps[];
  108. extern USHORT RateIdTo500Kbps[];
  109. extern UCHAR CipherSuiteWpaNoneTkip[];
  110. extern UCHAR CipherSuiteWpaNoneTkipLen;
  111. extern UCHAR CipherSuiteWpaNoneAes[];
  112. extern UCHAR CipherSuiteWpaNoneAesLen;
  113. extern UCHAR SsidIe;
  114. extern UCHAR SupRateIe;
  115. extern UCHAR ExtRateIe;
  116. #ifdef DOT11_N_SUPPORT
  117. extern UCHAR HtCapIe;
  118. extern UCHAR AddHtInfoIe;
  119. extern UCHAR NewExtChanIe;
  120. #ifdef DOT11N_DRAFT3
  121. extern UCHAR ExtHtCapIe;
  122. #endif // DOT11N_DRAFT3 //
  123. #endif // DOT11_N_SUPPORT //
  124. extern UCHAR ErpIe;
  125. extern UCHAR DsIe;
  126. extern UCHAR TimIe;
  127. extern UCHAR WpaIe;
  128. extern UCHAR Wpa2Ie;
  129. extern UCHAR IbssIe;
  130. extern UCHAR Ccx2Ie;
  131. extern UCHAR WapiIe;
  132. extern UCHAR WPA_OUI[];
  133. extern UCHAR RSN_OUI[];
  134. extern UCHAR WAPI_OUI[];
  135. extern UCHAR WME_INFO_ELEM[];
  136. extern UCHAR WME_PARM_ELEM[];
  137. extern UCHAR Ccx2QosInfo[];
  138. extern UCHAR Ccx2IeInfo[];
  139. extern UCHAR RALINK_OUI[];
  140. extern UCHAR PowerConstraintIE[];
  141. extern UCHAR RateSwitchTable[];
  142. extern UCHAR RateSwitchTable11B[];
  143. extern UCHAR RateSwitchTable11G[];
  144. extern UCHAR RateSwitchTable11BG[];
  145. #ifdef DOT11_N_SUPPORT
  146. extern UCHAR RateSwitchTable11BGN1S[];
  147. extern UCHAR RateSwitchTable11BGN2S[];
  148. extern UCHAR RateSwitchTable11BGN2SForABand[];
  149. extern UCHAR RateSwitchTable11N1S[];
  150. extern UCHAR RateSwitchTable11N2S[];
  151. extern UCHAR RateSwitchTable11N2SForABand[];
  152. #ifdef CONFIG_STA_SUPPORT
  153. extern UCHAR PRE_N_HT_OUI[];
  154. #endif // CONFIG_STA_SUPPORT //
  155. #endif // DOT11_N_SUPPORT //
  156. #ifdef RALINK_ATE
  157. typedef struct _ATE_INFO {
  158. UCHAR Mode;
  159. CHAR TxPower0;
  160. CHAR TxPower1;
  161. CHAR TxAntennaSel;
  162. CHAR RxAntennaSel;
  163. TXWI_STRUC TxWI; // TXWI
  164. USHORT QID;
  165. UCHAR Addr1[MAC_ADDR_LEN];
  166. UCHAR Addr2[MAC_ADDR_LEN];
  167. UCHAR Addr3[MAC_ADDR_LEN];
  168. UCHAR Channel;
  169. UINT32 TxLength;
  170. UINT32 TxCount;
  171. UINT32 TxDoneCount; // Tx DMA Done
  172. UINT32 RFFreqOffset;
  173. BOOLEAN bRxFER; // Show Rx Frame Error Rate
  174. BOOLEAN bQATxStart; // Have compiled QA in and use it to ATE tx.
  175. BOOLEAN bQARxStart; // Have compiled QA in and use it to ATE rx.
  176. #ifdef RTMP_MAC_PCI
  177. BOOLEAN bFWLoading; // Reload firmware when ATE is done.
  178. #endif // RTMP_MAC_PCI //
  179. UINT32 RxTotalCnt;
  180. UINT32 RxCntPerSec;
  181. CHAR LastSNR0; // last received SNR
  182. CHAR LastSNR1; // last received SNR for 2nd antenna
  183. CHAR LastRssi0; // last received RSSI
  184. CHAR LastRssi1; // last received RSSI for 2nd antenna
  185. CHAR LastRssi2; // last received RSSI for 3rd antenna
  186. CHAR AvgRssi0; // last 8 frames' average RSSI
  187. CHAR AvgRssi1; // last 8 frames' average RSSI
  188. CHAR AvgRssi2; // last 8 frames' average RSSI
  189. SHORT AvgRssi0X8; // sum of last 8 frames' RSSI
  190. SHORT AvgRssi1X8; // sum of last 8 frames' RSSI
  191. SHORT AvgRssi2X8; // sum of last 8 frames' RSSI
  192. UINT32 NumOfAvgRssiSample;
  193. #ifdef RALINK_28xx_QA
  194. // Tx frame
  195. USHORT HLen; // Header Length
  196. USHORT PLen; // Pattern Length
  197. UCHAR Header[32]; // Header buffer
  198. UCHAR Pattern[32]; // Pattern buffer
  199. USHORT DLen; // Data Length
  200. USHORT seq;
  201. UINT32 CID;
  202. RTMP_OS_PID AtePid;
  203. // counters
  204. UINT32 U2M;
  205. UINT32 OtherData;
  206. UINT32 Beacon;
  207. UINT32 OtherCount;
  208. UINT32 TxAc0;
  209. UINT32 TxAc1;
  210. UINT32 TxAc2;
  211. UINT32 TxAc3;
  212. /*UINT32 TxHCCA;*/
  213. UINT32 TxMgmt;
  214. UINT32 RSSI0;
  215. UINT32 RSSI1;
  216. UINT32 RSSI2;
  217. UINT32 SNR0;
  218. UINT32 SNR1;
  219. // TxStatus : 0 --> task is idle, 1 --> task is running
  220. UCHAR TxStatus;
  221. #endif // RALINK_28xx_QA //
  222. } ATE_INFO, *PATE_INFO;
  223. #ifdef RALINK_28xx_QA
  224. struct ate_racfghdr {
  225. UINT32 magic_no;
  226. USHORT command_type;
  227. USHORT command_id;
  228. USHORT length;
  229. USHORT sequence;
  230. USHORT status;
  231. UCHAR data[2046];
  232. } __attribute__((packed));
  233. #endif // RALINK_28xx_QA //
  234. #endif // RALINK_ATE //
  235. typedef struct _RSSI_SAMPLE {
  236. CHAR LastRssi0; // last received RSSI
  237. CHAR LastRssi1; // last received RSSI
  238. CHAR LastRssi2; // last received RSSI
  239. CHAR AvgRssi0;
  240. CHAR AvgRssi1;
  241. CHAR AvgRssi2;
  242. SHORT AvgRssi0X8;
  243. SHORT AvgRssi1X8;
  244. SHORT AvgRssi2X8;
  245. } RSSI_SAMPLE;
  246. //
  247. // Queue structure and macros
  248. //
  249. typedef struct _QUEUE_ENTRY {
  250. struct _QUEUE_ENTRY *Next;
  251. } QUEUE_ENTRY, *PQUEUE_ENTRY;
  252. // Queue structure
  253. typedef struct _QUEUE_HEADER {
  254. PQUEUE_ENTRY Head;
  255. PQUEUE_ENTRY Tail;
  256. ULONG Number;
  257. } QUEUE_HEADER, *PQUEUE_HEADER;
  258. #define InitializeQueueHeader(QueueHeader) \
  259. { \
  260. (QueueHeader)->Head = (QueueHeader)->Tail = NULL; \
  261. (QueueHeader)->Number = 0; \
  262. }
  263. #define RemoveHeadQueue(QueueHeader) \
  264. (QueueHeader)->Head; \
  265. { \
  266. PQUEUE_ENTRY pNext; \
  267. if ((QueueHeader)->Head != NULL) \
  268. { \
  269. pNext = (QueueHeader)->Head->Next; \
  270. (QueueHeader)->Head->Next = NULL; \
  271. (QueueHeader)->Head = pNext; \
  272. if (pNext == NULL) \
  273. (QueueHeader)->Tail = NULL; \
  274. (QueueHeader)->Number--; \
  275. } \
  276. }
  277. #define InsertHeadQueue(QueueHeader, QueueEntry) \
  278. { \
  279. ((PQUEUE_ENTRY)QueueEntry)->Next = (QueueHeader)->Head; \
  280. (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
  281. if ((QueueHeader)->Tail == NULL) \
  282. (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
  283. (QueueHeader)->Number++; \
  284. }
  285. #define InsertTailQueue(QueueHeader, QueueEntry) \
  286. { \
  287. ((PQUEUE_ENTRY)QueueEntry)->Next = NULL; \
  288. if ((QueueHeader)->Tail) \
  289. (QueueHeader)->Tail->Next = (PQUEUE_ENTRY)(QueueEntry); \
  290. else \
  291. (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
  292. (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
  293. (QueueHeader)->Number++; \
  294. }
  295. #define InsertTailQueueAc(pAd, pEntry, QueueHeader, QueueEntry) \
  296. { \
  297. ((PQUEUE_ENTRY)QueueEntry)->Next = NULL; \
  298. if ((QueueHeader)->Tail) \
  299. (QueueHeader)->Tail->Next = (PQUEUE_ENTRY)(QueueEntry); \
  300. else \
  301. (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
  302. (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
  303. (QueueHeader)->Number++; \
  304. }
  305. //
  306. // Macros for flag and ref count operations
  307. //
  308. #define RTMP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
  309. #define RTMP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
  310. #define RTMP_CLEAR_FLAGS(_M) ((_M)->Flags = 0)
  311. #define RTMP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0)
  312. #define RTMP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
  313. // Macro for power save flag.
  314. #define RTMP_SET_PSFLAG(_M, _F) ((_M)->PSFlags |= (_F))
  315. #define RTMP_CLEAR_PSFLAG(_M, _F) ((_M)->PSFlags &= ~(_F))
  316. #define RTMP_CLEAR_PSFLAGS(_M) ((_M)->PSFlags = 0)
  317. #define RTMP_TEST_PSFLAG(_M, _F) (((_M)->PSFlags & (_F)) != 0)
  318. #define RTMP_TEST_PSFLAGS(_M, _F) (((_M)->PSFlags & (_F)) == (_F))
  319. #define OPSTATUS_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags |= (_F))
  320. #define OPSTATUS_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F))
  321. #define OPSTATUS_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0)
  322. #define CLIENT_STATUS_SET_FLAG(_pEntry,_F) ((_pEntry)->ClientStatusFlags |= (_F))
  323. #define CLIENT_STATUS_CLEAR_FLAG(_pEntry,_F) ((_pEntry)->ClientStatusFlags &= ~(_F))
  324. #define CLIENT_STATUS_TEST_FLAG(_pEntry,_F) (((_pEntry)->ClientStatusFlags & (_F)) != 0)
  325. #define RX_FILTER_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter |= (_F))
  326. #define RX_FILTER_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter &= ~(_F))
  327. #define RX_FILTER_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0)
  328. #ifdef CONFIG_STA_SUPPORT
  329. #define STA_NO_SECURITY_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
  330. #define STA_WEP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
  331. #define STA_TKIP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
  332. #define STA_AES_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
  333. #define STA_TGN_WIFI_ON(_p) (_p->StaCfg.bTGnWifiTest == TRUE)
  334. #endif // CONFIG_STA_SUPPORT //
  335. #define CKIP_KP_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
  336. #define CKIP_CMIC_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
  337. #define INC_RING_INDEX(_idx, _RingSize) \
  338. { \
  339. (_idx) = (_idx+1) % (_RingSize); \
  340. }
  341. #ifdef DOT11_N_SUPPORT
  342. // StaActive.SupportedHtPhy.MCSSet is copied from AP beacon. Don't need to update here.
  343. #define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
  344. { \
  345. _pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth; \
  346. _pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs; \
  347. _pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF; \
  348. _pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20; \
  349. _pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40; \
  350. _pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC; \
  351. _pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC; \
  352. _pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset; \
  353. _pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth; \
  354. _pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode; \
  355. _pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent; \
  356. NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(UCHAR) * 16);\
  357. }
  358. #define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability) \
  359. { \
  360. _pAd->MacTab.Content[BSSID_WCID].AMsduSize = (UCHAR)(_pHtCapability->HtCapInfo.AMsduSize); \
  361. _pAd->MacTab.Content[BSSID_WCID].MmpsMode= (UCHAR)(_pHtCapability->HtCapInfo.MimoPs); \
  362. _pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (UCHAR)(_pHtCapability->HtCapParm.MaxRAmpduFactor); \
  363. }
  364. #endif // DOT11_N_SUPPORT //
  365. //
  366. // MACRO for 32-bit PCI register read / write
  367. //
  368. // Usage : RTMP_IO_READ32(
  369. // PRTMP_ADAPTER pAd,
  370. // ULONG Register_Offset,
  371. // PULONG pValue)
  372. //
  373. // RTMP_IO_WRITE32(
  374. // PRTMP_ADAPTER pAd,
  375. // ULONG Register_Offset,
  376. // ULONG Value)
  377. //
  378. //
  379. // Common fragment list structure - Identical to the scatter gather frag list structure
  380. //
  381. //#define RTMP_SCATTER_GATHER_ELEMENT SCATTER_GATHER_ELEMENT
  382. //#define PRTMP_SCATTER_GATHER_ELEMENT PSCATTER_GATHER_ELEMENT
  383. #define NIC_MAX_PHYS_BUF_COUNT 8
  384. typedef struct _RTMP_SCATTER_GATHER_ELEMENT {
  385. PVOID Address;
  386. ULONG Length;
  387. PULONG Reserved;
  388. } RTMP_SCATTER_GATHER_ELEMENT, *PRTMP_SCATTER_GATHER_ELEMENT;
  389. typedef struct _RTMP_SCATTER_GATHER_LIST {
  390. ULONG NumberOfElements;
  391. PULONG Reserved;
  392. RTMP_SCATTER_GATHER_ELEMENT Elements[NIC_MAX_PHYS_BUF_COUNT];
  393. } RTMP_SCATTER_GATHER_LIST, *PRTMP_SCATTER_GATHER_LIST;
  394. //
  395. // Some utility macros
  396. //
  397. #ifndef min
  398. #define min(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
  399. #endif
  400. #ifndef max
  401. #define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
  402. #endif
  403. #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))))
  404. #define INC_COUNTER64(Val) (Val.QuadPart++)
  405. #define INFRA_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON))
  406. #define ADHOC_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON))
  407. #define MONITOR_ON(_p) (((_p)->StaCfg.BssType) == BSS_MONITOR)
  408. #define IDLE_ON(_p) (!INFRA_ON(_p) && !ADHOC_ON(_p))
  409. // Check LEAP & CCKM flags
  410. #define LEAP_ON(_p) (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
  411. #define LEAP_CCKM_ON(_p) ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
  412. // if orginal Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required
  413. #define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap) \
  414. { \
  415. if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) \
  416. { \
  417. _pExtraLlcSnapEncap = SNAP_802_1H; \
  418. if (NdisEqualMemory(IPX, _pBufVA + 12, 2) || \
  419. NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2)) \
  420. { \
  421. _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
  422. } \
  423. } \
  424. else \
  425. { \
  426. _pExtraLlcSnapEncap = NULL; \
  427. } \
  428. }
  429. // New Define for new Tx Path.
  430. #define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap) \
  431. { \
  432. if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500) \
  433. { \
  434. _pExtraLlcSnapEncap = SNAP_802_1H; \
  435. if (NdisEqualMemory(IPX, _pBufVA, 2) || \
  436. NdisEqualMemory(APPLE_TALK, _pBufVA, 2)) \
  437. { \
  438. _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
  439. } \
  440. } \
  441. else \
  442. { \
  443. _pExtraLlcSnapEncap = NULL; \
  444. } \
  445. }
  446. #define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType) \
  447. { \
  448. NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN); \
  449. NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN); \
  450. NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \
  451. }
  452. // if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way.
  453. // else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field
  454. // else remove the LLC/SNAP field from the result Ethernet frame
  455. // Patch for WHQL only, which did not turn on Netbios but use IPX within its payload
  456. // Note:
  457. // _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO
  458. // _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed
  459. #define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP) \
  460. { \
  461. char LLC_Len[2]; \
  462. \
  463. _pRemovedLLCSNAP = NULL; \
  464. if (NdisEqualMemory(SNAP_802_1H, _pData, 6) || \
  465. NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6)) \
  466. { \
  467. PUCHAR pProto = _pData + 6; \
  468. \
  469. if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) && \
  470. NdisEqualMemory(SNAP_802_1H, _pData, 6)) \
  471. { \
  472. LLC_Len[0] = (UCHAR)(_DataSize / 256); \
  473. LLC_Len[1] = (UCHAR)(_DataSize % 256); \
  474. MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
  475. } \
  476. else \
  477. { \
  478. MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto); \
  479. _pRemovedLLCSNAP = _pData; \
  480. _DataSize -= LENGTH_802_1_H; \
  481. _pData += LENGTH_802_1_H; \
  482. } \
  483. } \
  484. else \
  485. { \
  486. LLC_Len[0] = (UCHAR)(_DataSize / 256); \
  487. LLC_Len[1] = (UCHAR)(_DataSize % 256); \
  488. MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
  489. } \
  490. }
  491. // Enqueue this frame to MLME engine
  492. // We need to enqueue the whole frame because MLME need to pass data type
  493. // information from 802.11 header
  494. #ifdef RTMP_MAC_PCI
  495. #define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal) \
  496. { \
  497. UINT32 High32TSF, Low32TSF; \
  498. RTMP_IO_READ32(_pAd, TSF_TIMER_DW1, &High32TSF); \
  499. RTMP_IO_READ32(_pAd, TSF_TIMER_DW0, &Low32TSF); \
  500. MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (UCHAR)_Rssi0, (UCHAR)_Rssi1,(UCHAR)_Rssi2,_FrameSize, _pFrame, (UCHAR)_PlcpSignal); \
  501. }
  502. #endif // RTMP_MAC_PCI //
  503. #define MAC_ADDR_EQUAL(pAddr1,pAddr2) RTMPEqualMemory((PVOID)(pAddr1), (PVOID)(pAddr2), MAC_ADDR_LEN)
  504. #define SSID_EQUAL(ssid1, len1, ssid2, len2) ((len1==len2) && (RTMPEqualMemory(ssid1, ssid2, len1)))
  505. //
  506. // Check if it is Japan W53(ch52,56,60,64) channel.
  507. //
  508. #define JapanChannelCheck(channel) ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
  509. #ifdef CONFIG_STA_SUPPORT
  510. #define STA_EXTRA_SETTING(_pAd)
  511. #define STA_PORT_SECURED(_pAd) \
  512. { \
  513. BOOLEAN Cancelled; \
  514. (_pAd)->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \
  515. NdisAcquireSpinLock(&((_pAd)->MacTabLock)); \
  516. (_pAd)->MacTab.Content[BSSID_WCID].PortSecured = (_pAd)->StaCfg.PortSecured; \
  517. (_pAd)->MacTab.Content[BSSID_WCID].PrivacyFilter = Ndis802_11PrivFilterAcceptAll;\
  518. NdisReleaseSpinLock(&(_pAd)->MacTabLock); \
  519. RTMPCancelTimer(&((_pAd)->Mlme.LinkDownTimer), &Cancelled);\
  520. STA_EXTRA_SETTING(_pAd); \
  521. }
  522. #endif // CONFIG_STA_SUPPORT //
  523. //
  524. // Data buffer for DMA operation, the buffer must be contiguous physical memory
  525. // Both DMA to / from CPU use the same structure.
  526. //
  527. typedef struct _RTMP_DMABUF
  528. {
  529. ULONG AllocSize;
  530. PVOID AllocVa; // TxBuf virtual address
  531. NDIS_PHYSICAL_ADDRESS AllocPa; // TxBuf physical address
  532. } RTMP_DMABUF, *PRTMP_DMABUF;
  533. //
  534. // Control block (Descriptor) for all ring descriptor DMA operation, buffer must be
  535. // contiguous physical memory. NDIS_PACKET stored the binding Rx packet descriptor
  536. // which won't be released, driver has to wait until upper layer return the packet
  537. // before giveing up this rx ring descriptor to ASIC. NDIS_BUFFER is assocaited pair
  538. // to describe the packet buffer. For Tx, NDIS_PACKET stored the tx packet descriptor
  539. // which driver should ACK upper layer when the tx is physically done or failed.
  540. //
  541. typedef struct _RTMP_DMACB
  542. {
  543. ULONG AllocSize; // Control block size
  544. PVOID AllocVa; // Control block virtual address
  545. NDIS_PHYSICAL_ADDRESS AllocPa; // Control block physical address
  546. PNDIS_PACKET pNdisPacket;
  547. PNDIS_PACKET pNextNdisPacket;
  548. RTMP_DMABUF DmaBuf; // Associated DMA buffer structure
  549. } RTMP_DMACB, *PRTMP_DMACB;
  550. typedef struct _RTMP_TX_RING
  551. {
  552. RTMP_DMACB Cell[TX_RING_SIZE];
  553. UINT32 TxCpuIdx;
  554. UINT32 TxDmaIdx;
  555. UINT32 TxSwFreeIdx; // software next free tx index
  556. } RTMP_TX_RING, *PRTMP_TX_RING;
  557. typedef struct _RTMP_RX_RING
  558. {
  559. RTMP_DMACB Cell[RX_RING_SIZE];
  560. UINT32 RxCpuIdx;
  561. UINT32 RxDmaIdx;
  562. INT32 RxSwReadIdx; // software next read index
  563. } RTMP_RX_RING, *PRTMP_RX_RING;
  564. typedef struct _RTMP_MGMT_RING
  565. {
  566. RTMP_DMACB Cell[MGMT_RING_SIZE];
  567. UINT32 TxCpuIdx;
  568. UINT32 TxDmaIdx;
  569. UINT32 TxSwFreeIdx; // software next free tx index
  570. } RTMP_MGMT_RING, *PRTMP_MGMT_RING;
  571. //
  572. // Statistic counter structure
  573. //
  574. typedef struct _COUNTER_802_3
  575. {
  576. // General Stats
  577. ULONG GoodTransmits;
  578. ULONG GoodReceives;
  579. ULONG TxErrors;
  580. ULONG RxErrors;
  581. ULONG RxNoBuffer;
  582. // Ethernet Stats
  583. ULONG RcvAlignmentErrors;
  584. ULONG OneCollision;
  585. ULONG MoreCollisions;
  586. } COUNTER_802_3, *PCOUNTER_802_3;
  587. typedef struct _COUNTER_802_11 {
  588. ULONG Length;
  589. LARGE_INTEGER LastTransmittedFragmentCount;
  590. LARGE_INTEGER TransmittedFragmentCount;
  591. LARGE_INTEGER MulticastTransmittedFrameCount;
  592. LARGE_INTEGER FailedCount;
  593. LARGE_INTEGER RetryCount;
  594. LARGE_INTEGER MultipleRetryCount;
  595. LARGE_INTEGER RTSSuccessCount;
  596. LARGE_INTEGER RTSFailureCount;
  597. LARGE_INTEGER ACKFailureCount;
  598. LARGE_INTEGER FrameDuplicateCount;
  599. LARGE_INTEGER ReceivedFragmentCount;
  600. LARGE_INTEGER MulticastReceivedFrameCount;
  601. LARGE_INTEGER FCSErrorCount;
  602. } COUNTER_802_11, *PCOUNTER_802_11;
  603. typedef struct _COUNTER_RALINK {
  604. ULONG TransmittedByteCount; // both successful and failure, used to calculate TX throughput
  605. ULONG ReceivedByteCount; // both CRC okay and CRC error, used to calculate RX throughput
  606. ULONG BeenDisassociatedCount;
  607. ULONG BadCQIAutoRecoveryCount;
  608. ULONG PoorCQIRoamingCount;
  609. ULONG MgmtRingFullCount;
  610. ULONG RxCountSinceLastNULL;
  611. ULONG RxCount;
  612. ULONG RxRingErrCount;
  613. ULONG KickTxCount;
  614. ULONG TxRingErrCount;
  615. LARGE_INTEGER RealFcsErrCount;
  616. ULONG PendingNdisPacketCount;
  617. ULONG OneSecOsTxCount[NUM_OF_TX_RING];
  618. ULONG OneSecDmaDoneCount[NUM_OF_TX_RING];
  619. UINT32 OneSecTxDoneCount;
  620. ULONG OneSecRxCount;
  621. UINT32 OneSecTxAggregationCount;
  622. UINT32 OneSecRxAggregationCount;
  623. UINT32 OneSecReceivedByteCount;
  624. UINT32 OneSecFrameDuplicateCount;
  625. UINT32 OneSecTransmittedByteCount; // both successful and failure, used to calculate TX throughput
  626. UINT32 OneSecTxNoRetryOkCount;
  627. UINT32 OneSecTxRetryOkCount;
  628. UINT32 OneSecTxFailCount;
  629. UINT32 OneSecFalseCCACnt; // CCA error count, for debug purpose, might move to global counter
  630. UINT32 OneSecRxOkCnt; // RX without error
  631. UINT32 OneSecRxOkDataCnt; // unicast-to-me DATA frame count
  632. UINT32 OneSecRxFcsErrCnt; // CRC error
  633. UINT32 OneSecBeaconSentCnt;
  634. UINT32 LastOneSecTotalTxCount; // OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount
  635. UINT32 LastOneSecRxOkDataCnt; // OneSecRxOkDataCnt
  636. ULONG DuplicateRcv;
  637. ULONG TxAggCount;
  638. ULONG TxNonAggCount;
  639. ULONG TxAgg1MPDUCount;
  640. ULONG TxAgg2MPDUCount;
  641. ULONG TxAgg3MPDUCount;
  642. ULONG TxAgg4MPDUCount;
  643. ULONG TxAgg5MPDUCount;
  644. ULONG TxAgg6MPDUCount;
  645. ULONG TxAgg7MPDUCount;
  646. ULONG TxAgg8MPDUCount;
  647. ULONG TxAgg9MPDUCount;
  648. ULONG TxAgg10MPDUCount;
  649. ULONG TxAgg11MPDUCount;
  650. ULONG TxAgg12MPDUCount;
  651. ULONG TxAgg13MPDUCount;
  652. ULONG TxAgg14MPDUCount;
  653. ULONG TxAgg15MPDUCount;
  654. ULONG TxAgg16MPDUCount;
  655. LARGE_INTEGER TransmittedOctetsInAMSDU;
  656. LARGE_INTEGER TransmittedAMSDUCount;
  657. LARGE_INTEGER ReceivedOctesInAMSDUCount;
  658. LARGE_INTEGER ReceivedAMSDUCount;
  659. LARGE_INTEGER TransmittedAMPDUCount;
  660. LARGE_INTEGER TransmittedMPDUsInAMPDUCount;
  661. LARGE_INTEGER TransmittedOctetsInAMPDUCount;
  662. LARGE_INTEGER MPDUInReceivedAMPDUCount;
  663. } COUNTER_RALINK, *PCOUNTER_RALINK;
  664. typedef struct _COUNTER_DRS {
  665. // to record the each TX rate's quality. 0 is best, the bigger the worse.
  666. USHORT TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
  667. UCHAR PER[MAX_STEP_OF_TX_RATE_SWITCH];
  668. UCHAR TxRateUpPenalty; // extra # of second penalty due to last unstable condition
  669. ULONG CurrTxRateStableTime; // # of second in current TX rate
  670. BOOLEAN fNoisyEnvironment;
  671. BOOLEAN fLastSecAccordingRSSI;
  672. UCHAR LastSecTxRateChangeAction; // 0: no change, 1:rate UP, 2:rate down
  673. UCHAR LastTimeTxRateChangeAction; //Keep last time value of LastSecTxRateChangeAction
  674. ULONG LastTxOkCount;
  675. } COUNTER_DRS, *PCOUNTER_DRS;
  676. /***************************************************************************
  677. * security key related data structure
  678. **************************************************************************/
  679. typedef struct _CIPHER_KEY {
  680. UCHAR Key[16]; // right now we implement 4 keys, 128 bits max
  681. UCHAR RxMic[8]; // make alignment
  682. UCHAR TxMic[8];
  683. UCHAR TxTsc[6]; // 48bit TSC value
  684. UCHAR RxTsc[6]; // 48bit TSC value
  685. UCHAR CipherAlg; // 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128
  686. UCHAR KeyLen;
  687. #ifdef CONFIG_STA_SUPPORT
  688. UCHAR BssId[6];
  689. #endif // CONFIG_STA_SUPPORT //
  690. // Key length for each key, 0: entry is invalid
  691. UCHAR Type; // Indicate Pairwise/Group when reporting MIC error
  692. } CIPHER_KEY, *PCIPHER_KEY;
  693. // structure to define WPA Group Key Rekey Interval
  694. typedef struct PACKED _RT_802_11_WPA_REKEY {
  695. ULONG ReKeyMethod; // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
  696. ULONG ReKeyInterval; // time-based: seconds, packet-based: kilo-packets
  697. } RT_WPA_REKEY,*PRT_WPA_REKEY, RT_802_11_WPA_REKEY, *PRT_802_11_WPA_REKEY;
  698. typedef struct {
  699. UCHAR Addr[MAC_ADDR_LEN];
  700. UCHAR ErrorCode[2]; //00 01-Invalid authentication type
  701. //00 02-Authentication timeout
  702. //00 03-Challenge from AP failed
  703. //00 04-Challenge to AP failed
  704. BOOLEAN Reported;
  705. } ROGUEAP_ENTRY, *PROGUEAP_ENTRY;
  706. typedef struct {
  707. UCHAR RogueApNr;
  708. ROGUEAP_ENTRY RogueApEntry[MAX_LEN_OF_BSS_TABLE];
  709. } ROGUEAP_TABLE, *PROGUEAP_TABLE;
  710. //
  711. // Cisco IAPP format
  712. //
  713. typedef struct _CISCO_IAPP_CONTENT_
  714. {
  715. USHORT Length; //IAPP Length
  716. UCHAR MessageType; //IAPP type
  717. UCHAR FunctionCode; //IAPP function type
  718. UCHAR DestinaionMAC[MAC_ADDR_LEN];
  719. UCHAR SourceMAC[MAC_ADDR_LEN];
  720. USHORT Tag; //Tag(element IE) - Adjacent AP report
  721. USHORT TagLength; //Length of element not including 4 byte header
  722. UCHAR OUI[4]; //0x00, 0x40, 0x96, 0x00
  723. UCHAR PreviousAP[MAC_ADDR_LEN]; //MAC Address of access point
  724. USHORT Channel;
  725. USHORT SsidLen;
  726. UCHAR Ssid[MAX_LEN_OF_SSID];
  727. USHORT Seconds; //Seconds that the client has been disassociated.
  728. } CISCO_IAPP_CONTENT, *PCISCO_IAPP_CONTENT;
  729. /*
  730. * Fragment Frame structure
  731. */
  732. typedef struct _FRAGMENT_FRAME {
  733. PNDIS_PACKET pFragPacket;
  734. ULONG RxSize;
  735. USHORT Sequence;
  736. USHORT LastFrag;
  737. ULONG Flags; // Some extra frame information. bit 0: LLC presented
  738. } FRAGMENT_FRAME, *PFRAGMENT_FRAME;
  739. //
  740. // Packet information for NdisQueryPacket
  741. //
  742. typedef struct _PACKET_INFO {
  743. UINT PhysicalBufferCount; // Physical breaks of buffer descripor chained
  744. UINT BufferCount ; // Number of Buffer descriptor chained
  745. UINT TotalPacketLength ; // Self explained
  746. PNDIS_BUFFER pFirstBuffer; // Pointer to first buffer descriptor
  747. } PACKET_INFO, *PPACKET_INFO;
  748. //
  749. // Arcfour Structure Added by PaulWu
  750. //
  751. typedef struct _ARCFOUR
  752. {
  753. UINT X;
  754. UINT Y;
  755. UCHAR STATE[256];
  756. } ARCFOURCONTEXT, *PARCFOURCONTEXT;
  757. //
  758. // Tkip Key structure which RC4 key & MIC calculation
  759. //
  760. typedef struct _TKIP_KEY_INFO {
  761. UINT nBytesInM; // # bytes in M for MICKEY
  762. ULONG IV16;
  763. ULONG IV32;
  764. ULONG K0; // for MICKEY Low
  765. ULONG K1; // for MICKEY Hig
  766. ULONG L; // Current state for MICKEY
  767. ULONG R; // Current state for MICKEY
  768. ULONG M; // Message accumulator for MICKEY
  769. UCHAR RC4KEY[16];
  770. UCHAR MIC[8];
  771. } TKIP_KEY_INFO, *PTKIP_KEY_INFO;
  772. //
  773. // Private / Misc data, counters for driver internal use
  774. //
  775. typedef struct __PRIVATE_STRUC {
  776. UINT SystemResetCnt; // System reset counter
  777. UINT TxRingFullCnt; // Tx ring full occurrance number
  778. UINT PhyRxErrCnt; // PHY Rx error count, for debug purpose, might move to global counter
  779. // Variables for WEP encryption / decryption in rtmp_wep.c
  780. UINT FCSCRC32;
  781. ARCFOURCONTEXT WEPCONTEXT;
  782. // Tkip stuff
  783. TKIP_KEY_INFO Tx;
  784. TKIP_KEY_INFO Rx;
  785. } PRIVATE_STRUC, *PPRIVATE_STRUC;
  786. /***************************************************************************
  787. * Channel and BBP related data structures
  788. **************************************************************************/
  789. // structure to tune BBP R66 (BBP TUNING)
  790. typedef struct _BBP_R66_TUNING {
  791. BOOLEAN bEnable;
  792. USHORT FalseCcaLowerThreshold; // default 100
  793. USHORT FalseCcaUpperThreshold; // default 512
  794. UCHAR R66Delta;
  795. UCHAR R66CurrentValue;
  796. BOOLEAN R66LowerUpperSelect; //Before LinkUp, Used LowerBound or UpperBound as R66 value.
  797. } BBP_R66_TUNING, *PBBP_R66_TUNING;
  798. // structure to store channel TX power
  799. typedef struct _CHANNEL_TX_POWER {
  800. USHORT RemainingTimeForUse; //unit: sec
  801. UCHAR Channel;
  802. #ifdef DOT11N_DRAFT3
  803. BOOLEAN bEffectedChannel; // For BW 40 operating in 2.4GHz , the "effected channel" is the channel that is covered in 40Mhz.
  804. #endif // DOT11N_DRAFT3 //
  805. CHAR Power;
  806. CHAR Power2;
  807. UCHAR MaxTxPwr;
  808. UCHAR DfsReq;
  809. } CHANNEL_TX_POWER, *PCHANNEL_TX_POWER;
  810. // structure to store 802.11j channel TX power
  811. typedef struct _CHANNEL_11J_TX_POWER {
  812. UCHAR Channel;
  813. UCHAR BW; // BW_10 or BW_20
  814. CHAR Power;
  815. CHAR Power2;
  816. USHORT RemainingTimeForUse; //unit: sec
  817. } CHANNEL_11J_TX_POWER, *PCHANNEL_11J_TX_POWER;
  818. typedef struct _SOFT_RX_ANT_DIVERSITY_STRUCT {
  819. UCHAR EvaluatePeriod; // 0:not evalute status, 1: evaluate status, 2: switching status
  820. UCHAR EvaluateStableCnt;
  821. UCHAR Pair1PrimaryRxAnt; // 0:Ant-E1, 1:Ant-E2
  822. UCHAR Pair1SecondaryRxAnt; // 0:Ant-E1, 1:Ant-E2
  823. UCHAR Pair2PrimaryRxAnt; // 0:Ant-E3, 1:Ant-E4
  824. UCHAR Pair2SecondaryRxAnt; // 0:Ant-E3, 1:Ant-E4
  825. #ifdef CONFIG_STA_SUPPORT
  826. SHORT Pair1AvgRssi[2]; // AvgRssi[0]:E1, AvgRssi[1]:E2
  827. SHORT Pair2AvgRssi[2]; // AvgRssi[0]:E3, AvgRssi[1]:E4
  828. #endif // CONFIG_STA_SUPPORT //
  829. SHORT Pair1LastAvgRssi; //
  830. SHORT Pair2LastAvgRssi; //
  831. ULONG RcvPktNumWhenEvaluate;
  832. BOOLEAN FirstPktArrivedWhenEvaluate;
  833. RALINK_TIMER_STRUCT RxAntDiversityTimer;
  834. } SOFT_RX_ANT_DIVERSITY, *PSOFT_RX_ANT_DIVERSITY;
  835. /***************************************************************************
  836. * structure for radar detection and channel switch
  837. **************************************************************************/
  838. typedef struct _RADAR_DETECT_STRUCT {
  839. //BOOLEAN IEEE80211H; // 0: disable, 1: enable IEEE802.11h
  840. UCHAR CSCount; //Channel switch counter
  841. UCHAR CSPeriod; //Channel switch period (beacon count)
  842. UCHAR RDCount; //Radar detection counter
  843. UCHAR RDMode; //Radar Detection mode
  844. UCHAR RDDurRegion; //Radar detection duration region
  845. UCHAR BBPR16;
  846. UCHAR BBPR17;
  847. UCHAR BBPR18;
  848. UCHAR BBPR21;
  849. UCHAR BBPR22;
  850. UCHAR BBPR64;
  851. ULONG InServiceMonitorCount; // unit: sec
  852. UINT8 DfsSessionTime;
  853. #ifdef DFS_FCC_BW40_FIX
  854. CHAR DfsSessionFccOff;
  855. #endif
  856. BOOLEAN bFastDfs;
  857. UINT8 ChMovingTime;
  858. UINT8 LongPulseRadarTh;
  859. #ifdef MERGE_ARCH_TEAM
  860. CHAR AvgRssiReq;
  861. ULONG DfsLowerLimit;
  862. ULONG DfsUpperLimit;
  863. UINT8 FixDfsLimit;
  864. ULONG upperlimit;
  865. ULONG lowerlimit;
  866. #endif // MERGE_ARCH_TEAM //
  867. } RADAR_DETECT_STRUCT, *PRADAR_DETECT_STRUCT;
  868. #ifdef CARRIER_DETECTION_SUPPORT
  869. typedef enum CD_STATE_n
  870. {
  871. CD_NORMAL,
  872. CD_SILENCE,
  873. CD_MAX_STATE
  874. } CD_STATE;
  875. #ifdef TONE_RADAR_DETECT_SUPPORT
  876. #define CARRIER_DETECT_RECHECK_TIME 3
  877. #ifdef CARRIER_SENSE_NEW_ALGO
  878. #define CARRIER_DETECT_CRITIRIA 400
  879. #define CARRIER_DETECT_STOP_RATIO 0x11
  880. #define CARRIER_DETECT_STOP_RATIO_OLD_3090 2
  881. #endif // CARRIER_SENSE_NEW_ALGO //
  882. #define CARRIER_DETECT_STOP_RECHECK_TIME 4
  883. #define CARRIER_DETECT_CRITIRIA_A 230
  884. #define CARRIER_DETECT_DELTA 7
  885. #define CARRIER_DETECT_DIV_FLAG 0
  886. #ifdef RT3090
  887. #define CARRIER_DETECT_THRESHOLD_3090A 0x1fffffff
  888. #endif // RT3090 //
  889. #ifdef RT3390
  890. #define CARRIER_DETECT_THRESHOLD 0x0fffffff
  891. #endif // RT3390 //
  892. #ifndef RT3390
  893. #define CARRIER_DETECT_THRESHOLD 0x0fffffff
  894. #endif // RT3390 //
  895. #endif // TONE_RADAR_DETECT_SUPPORT //
  896. typedef struct CARRIER_DETECTION_s
  897. {
  898. BOOLEAN Enable;
  899. UINT8 CDSessionTime;
  900. UINT8 CDPeriod;
  901. CD_STATE CD_State;
  902. #ifdef TONE_RADAR_DETECT_SUPPORT
  903. UINT8 delta;
  904. UINT8 div_flag;
  905. UINT32 threshold;
  906. UINT8 recheck;
  907. UINT8 recheck1;
  908. UINT8 recheck2;
  909. UINT32 TimeStamp;
  910. UINT32 criteria;
  911. UINT32 CarrierDebug;
  912. ULONG idle_time;
  913. ULONG busy_time;
  914. ULONG Debug;
  915. #endif // TONE_RADAR_DETECT_SUPPORT //
  916. }CARRIER_DETECTION_STRUCT, *PCARRIER_DETECTION_STRUCT;
  917. #endif // CARRIER_DETECTION_SUPPORT //
  918. #ifdef NEW_DFS
  919. typedef struct _NewDFSDebug
  920. {
  921. UCHAR channel;
  922. ULONG wait_time;
  923. UCHAR delta_delay_range;
  924. UCHAR delta_delay_step;
  925. UCHAR EL_range;
  926. UCHAR EL_step;
  927. UCHAR EH_range;
  928. UCHAR EH_step;
  929. UCHAR WL_range;
  930. UCHAR WL_step;
  931. UCHAR WH_range;
  932. UCHAR WH_step;
  933. ULONG T_expected;
  934. ULONG T_margin;
  935. UCHAR start;
  936. ULONG count;
  937. ULONG idx;
  938. }NewDFSDebug, *pNewDFSDebug;
  939. #define NEW_DFS_FCC_5_ENT_NUM 5
  940. #define NEW_DFS_DBG_PORT_ENT_NUM_POWER 8
  941. #define NEW_DFS_DBG_PORT_ENT_NUM (1 << NEW_DFS_DBG_PORT_ENT_NUM_POWER) // CE Debug Port entry number, 256
  942. #define NEW_DFS_DBG_PORT_MASK 0xff
  943. // Matched Period definition
  944. #define NEW_DFS_MPERIOD_ENT_NUM_POWER 8
  945. #define NEW_DFS_MPERIOD_ENT_NUM (1 << NEW_DFS_MPERIOD_ENT_NUM_POWER) // CE Period Table entry number, 512
  946. #define NEW_DFS_MAX_CHANNEL 4
  947. typedef struct _NewDFSDebugPort{
  948. ULONG counter;
  949. ULONG timestamp;
  950. USHORT width;
  951. USHORT start_idx; // start index to period table
  952. USHORT end_idx; // end index to period table
  953. }NewDFSDebugPort, *pNewDFSDebugPort;
  954. // Matched Period Table
  955. typedef struct _NewDFSMPeriod{
  956. USHORT idx;
  957. USHORT width;
  958. USHORT idx2;
  959. USHORT width2;
  960. ULONG period;
  961. }NewDFSMPeriod, *pNewDFSMPeriod;
  962. #endif // NEW_DFS //
  963. typedef enum _ABGBAND_STATE_ {
  964. UNKNOWN_BAND,
  965. BG_BAND,
  966. A_BAND,
  967. } ABGBAND_STATE;
  968. #ifdef RTMP_MAC_PCI
  969. #ifdef CONFIG_STA_SUPPORT
  970. // Power save method control
  971. typedef union _PS_CONTROL {
  972. struct {
  973. ULONG EnablePSinIdle:1; // Enable radio off when not connect to AP. radio on only when sitesurvey,
  974. ULONG EnableNewPS:1; // Enable new Chip power save fucntion . New method can only be applied in chip version after 2872. and PCIe.
  975. ULONG rt30xxPowerMode:2; // Power Level Mode for rt30xx chip
  976. ULONG rt30xxFollowHostASPM:1; // Card Follows Host's setting for rt30xx chip.
  977. ULONG rt30xxForceASPMTest:1; // Force enable L1 for rt30xx chip. This has higher priority than rt30xxFollowHostASPM Mode.
  978. ULONG rsv:26; // Radio Measurement Enable
  979. } field;
  980. ULONG word;
  981. } PS_CONTROL, *PPS_CONTROL;
  982. #endif // CONFIG_STA_SUPPORT //
  983. #endif // RTMP_MAC_PCI //
  984. /***************************************************************************
  985. * structure for MLME state machine
  986. **************************************************************************/
  987. typedef struct _MLME_STRUCT {
  988. #ifdef CONFIG_STA_SUPPORT
  989. // STA state machines
  990. STATE_MACHINE CntlMachine;
  991. STATE_MACHINE AssocMachine;
  992. STATE_MACHINE AuthMachine;
  993. STATE_MACHINE AuthRspMachine;
  994. STATE_MACHINE SyncMachine;
  995. STATE_MACHINE WpaPskMachine;
  996. STATE_MACHINE LeapMachine;
  997. STATE_MACHINE_FUNC AssocFunc[ASSOC_FUNC_SIZE];
  998. STATE_MACHINE_FUNC AuthFunc[AUTH_FUNC_SIZE];
  999. STATE_MACHINE_FUNC AuthRspFunc[AUTH_RSP_FUNC_SIZE];
  1000. STATE_MACHINE_FUNC SyncFunc[SYNC_FUNC_SIZE];
  1001. #endif // CONFIG_STA_SUPPORT //
  1002. STATE_MACHINE_FUNC ActFunc[ACT_FUNC_SIZE];
  1003. // Action
  1004. STATE_MACHINE ActMachine;
  1005. #ifdef QOS_DLS_SUPPORT
  1006. STATE_MACHINE DlsMachine;
  1007. STATE_MACHINE_FUNC DlsFunc[DLS_FUNC_SIZE];
  1008. #endif // QOS_DLS_SUPPORT //
  1009. // common WPA state machine
  1010. STATE_MACHINE WpaMachine;
  1011. STATE_MACHINE_FUNC WpaFunc[WPA_FUNC_SIZE];
  1012. ULONG ChannelQuality; // 0..100, Channel Quality Indication for Roaming
  1013. ULONG Now32; // latch the value of NdisGetSystemUpTime()
  1014. ULONG LastSendNULLpsmTime;
  1015. BOOLEAN bRunning;
  1016. NDIS_SPIN_LOCK TaskLock;
  1017. MLME_QUEUE Queue;
  1018. UINT ShiftReg;
  1019. RALINK_TIMER_STRUCT PeriodicTimer;
  1020. RALINK_TIMER_STRUCT APSDPeriodicTimer;
  1021. RALINK_TIMER_STRUCT LinkDownTimer;
  1022. RALINK_TIMER_STRUCT LinkUpTimer;
  1023. #ifdef RTMP_MAC_PCI
  1024. UCHAR bPsPollTimerRunning;
  1025. RALINK_TIMER_STRUCT PsPollTimer;
  1026. RALINK_TIMER_STRUCT RadioOnOffTimer;
  1027. #endif // RTMP_MAC_PCI //
  1028. ULONG PeriodicRound;
  1029. ULONG OneSecPeriodicRound;
  1030. UCHAR RealRxPath;
  1031. BOOLEAN bLowThroughput;
  1032. BOOLEAN bEnableAutoAntennaCheck;
  1033. RALINK_TIMER_STRUCT RxAntEvalTimer;
  1034. #ifdef RT30xx
  1035. UCHAR CaliBW40RfR24;
  1036. UCHAR CaliBW20RfR24;
  1037. #endif // RT30xx //
  1038. } MLME_STRUCT, *PMLME_STRUCT;
  1039. #ifdef DOT11_N_SUPPORT
  1040. /***************************************************************************
  1041. * 802.11 N related data structures
  1042. **************************************************************************/
  1043. struct reordering_mpdu
  1044. {
  1045. struct reordering_mpdu *next;
  1046. PNDIS_PACKET pPacket; /* coverted to 802.3 frame */
  1047. int Sequence; /* sequence number of MPDU */
  1048. BOOLEAN bAMSDU;
  1049. };
  1050. struct reordering_list
  1051. {
  1052. struct reordering_mpdu *next;
  1053. int qlen;
  1054. };
  1055. struct reordering_mpdu_pool
  1056. {
  1057. PVOID mem;
  1058. NDIS_SPIN_LOCK lock;
  1059. struct reordering_list freelist;
  1060. };
  1061. typedef enum _REC_BLOCKACK_STATUS
  1062. {
  1063. Recipient_NONE=0,
  1064. Recipient_USED,
  1065. Recipient_HandleRes,
  1066. Recipient_Accept
  1067. } REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS;
  1068. typedef enum _ORI_BLOCKACK_STATUS
  1069. {
  1070. Originator_NONE=0,
  1071. Originator_USED,
  1072. Originator_WaitRes,
  1073. Originator_Done
  1074. } ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS;
  1075. typedef struct _BA_ORI_ENTRY{
  1076. UCHAR Wcid;
  1077. UCHAR TID;
  1078. UCHAR BAWinSize;
  1079. UCHAR Token;
  1080. // Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header.
  1081. USHORT Sequence;
  1082. USHORT TimeOutValue;
  1083. ORI_BLOCKACK_STATUS ORI_BA_Status;
  1084. RALINK_TIMER_STRUCT ORIBATimer;
  1085. PVOID pAdapter;
  1086. } BA_ORI_ENTRY, *PBA_ORI_ENTRY;
  1087. typedef struct _BA_REC_ENTRY {
  1088. UCHAR Wcid;
  1089. UCHAR TID;
  1090. UCHAR BAWinSize; // 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU.
  1091. //UCHAR NumOfRxPkt;
  1092. //UCHAR Curindidx; // the head in the RX reordering buffer
  1093. USHORT LastIndSeq;
  1094. // USHORT LastIndSeqAtTimer;
  1095. USHORT TimeOutValue;
  1096. RALINK_TIMER_STRUCT RECBATimer;
  1097. ULONG LastIndSeqAtTimer;
  1098. ULONG nDropPacket;
  1099. ULONG rcvSeq;
  1100. REC_BLOCKACK_STATUS REC_BA_Status;
  1101. // UCHAR RxBufIdxUsed;
  1102. // corresponding virtual address for RX reordering packet storage.
  1103. //RTMP_REORDERDMABUF MAP_RXBuf[MAX_RX_REORDERBUF];
  1104. NDIS_SPIN_LOCK RxReRingLock; // Rx Ring spinlock
  1105. // struct _BA_REC_ENTRY *pNext;
  1106. PVOID pAdapter;
  1107. struct reordering_list list;
  1108. } BA_REC_ENTRY, *PBA_REC_ENTRY;
  1109. typedef struct {
  1110. ULONG numAsRecipient; // I am recipient of numAsRecipient clients. These client are in the BARecEntry[]
  1111. ULONG numAsOriginator; // I am originator of numAsOriginator clients. These clients are in the BAOriEntry[]
  1112. ULONG numDoneOriginator; // count Done Originator sessions
  1113. BA_ORI_ENTRY BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE];
  1114. BA_REC_ENTRY BARecEntry[MAX_LEN_OF_BA_REC_TABLE];
  1115. } BA_TABLE, *PBA_TABLE;
  1116. //For QureyBATableOID use;
  1117. typedef struct PACKED _OID_BA_REC_ENTRY{
  1118. UCHAR MACAddr[MAC_ADDR_LEN];
  1119. UCHAR BaBitmap; // if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize
  1120. UCHAR rsv;
  1121. UCHAR BufSize[8];
  1122. REC_BLOCKACK_STATUS REC_BA_Status[8];
  1123. } OID_BA_REC_ENTRY, *POID_BA_REC_ENTRY;
  1124. //For QureyBATableOID use;
  1125. typedef struct PACKED _OID_BA_ORI_ENTRY{
  1126. UCHAR MACAddr[MAC_ADDR_LEN];
  1127. UCHAR BaBitmap; // if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize, read ORI_BA_Status[TID] for status
  1128. UCHAR rsv;
  1129. UCHAR BufSize[8];
  1130. ORI_BLOCKACK_STATUS ORI_BA_Status[8];
  1131. } OID_BA_ORI_ENTRY, *POID_BA_ORI_ENTRY;
  1132. typedef struct _QUERYBA_TABLE{
  1133. OID_BA_ORI_ENTRY BAOriEntry[32];
  1134. OID_BA_REC_ENTRY BARecEntry[32];
  1135. UCHAR OriNum;// Number of below BAOriEntry
  1136. UCHAR RecNum;// Number of below BARecEntry
  1137. } QUERYBA_TABLE, *PQUERYBA_TABLE;
  1138. typedef union _BACAP_STRUC {
  1139. #ifdef RT_BIG_ENDIAN
  1140. struct {
  1141. UINT32 :4;
  1142. UINT32 b2040CoexistScanSup:1; //As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz.
  1143. UINT32 bHtAdhoc:1; // adhoc can use ht rate.
  1144. UINT32 MMPSmode:2; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
  1145. UINT32 AmsduSize:1; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
  1146. UINT32 AmsduEnable:1; //Enable AMSDU transmisstion
  1147. UINT32 MpduDensity:3;
  1148. UINT32 Policy:2; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use
  1149. UINT32 AutoBA:1; // automatically BA
  1150. UINT32 TxBAWinLimit:8;
  1151. UINT32 RxBAWinLimit:8;
  1152. } field;
  1153. #else
  1154. struct {
  1155. UINT32 RxBAWinLimit:8;
  1156. UINT32 TxBAWinLimit:8;
  1157. UINT32 AutoBA:1; // automatically BA
  1158. UINT32 Policy:2; // 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use
  1159. UINT32 MpduDensity:3;
  1160. UINT32 AmsduEnable:1; //Enable AMSDU transmisstion
  1161. UINT32 AmsduSize:1; // 0:3839, 1:7935 bytes. UINT MSDUSizeToBytes[] = { 3839, 7935};
  1162. UINT32 MMPSmode:2; // MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable
  1163. UINT32 bHtAdhoc:1; // adhoc can use ht rate.
  1164. UINT32 b2040CoexistScanSup:1; //As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz.
  1165. UINT32 :4;
  1166. } field;
  1167. #endif
  1168. UINT32 word;
  1169. } BACAP_STRUC, *PBACAP_STRUC;
  1170. typedef struct {
  1171. BOOLEAN IsRecipient;
  1172. UCHAR MACAddr[MAC_ADDR_LEN];
  1173. UCHAR TID;
  1174. UCHAR nMSDU;
  1175. USHORT TimeOut;
  1176. BOOLEAN bAllTid; // If True, delete all TID for BA sessions with this MACaddr.
  1177. } OID_ADD_BA_ENTRY, *POID_ADD_BA_ENTRY;
  1178. #ifdef DOT11N_DRAFT3
  1179. typedef enum _BSS2040COEXIST_FLAG{
  1180. BSS_2040_COEXIST_DISABLE = 0,
  1181. BSS_2040_COEXIST_TIMER_FIRED = 1,
  1182. BSS_2040_COEXIST_INFO_SYNC = 2,
  1183. BSS_2040_COEXIST_INFO_NOTIFY = 4,
  1184. }BSS2040COEXIST_FLAG;
  1185. #endif // DOT11N_DRAFT3 //
  1186. #define IS_HT_STA(_pMacEntry) \
  1187. (_pMacEntry->MaxHTPhyMode.field.MODE >= MODE_HTMIX)
  1188. #define IS_HT_RATE(_pMacEntry) \
  1189. (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
  1190. #define PEER_IS_HT_RATE(_pMacEntry) \
  1191. (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
  1192. #endif // DOT11_N_SUPPORT //
  1193. //This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second. (Details see MLMEPeriodic)
  1194. typedef struct _IOT_STRUC {
  1195. UCHAR Threshold[2];
  1196. UCHAR ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE]; // compare with threshold[0]
  1197. UCHAR RefreshNum[MAX_LEN_OF_BA_REC_TABLE]; // compare with threshold[1]
  1198. ULONG OneSecInWindowCount;
  1199. ULONG OneSecFrameDuplicateCount;
  1200. ULONG OneSecOutWindowCount;
  1201. UCHAR DelOriAct;
  1202. UCHAR DelRecAct;
  1203. UCHAR RTSShortProt;
  1204. UCHAR RTSLongProt;
  1205. BOOLEAN bRTSLongProtOn;
  1206. #ifdef CONFIG_STA_SUPPORT
  1207. BOOLEAN bLastAtheros;
  1208. BOOLEAN bCurrentAtheros;
  1209. BOOLEAN bNowAtherosBurstOn;
  1210. BOOLEAN bNextDisableRxBA;
  1211. BOOLEAN bToggle;
  1212. #endif // CONFIG_STA_SUPPORT //
  1213. } IOT_STRUC, *PIOT_STRUC;
  1214. // This is the registry setting for 802.11n transmit setting. Used in advanced page.
  1215. typedef union _REG_TRANSMIT_SETTING {
  1216. #ifdef RT_BIG_ENDIAN
  1217. struct {
  1218. UINT32 rsv:13;
  1219. UINT32 EXTCHA:2;
  1220. UINT32 HTMODE:1;
  1221. UINT32 TRANSNO:2;
  1222. UINT32 STBC:1; //SPACE
  1223. UINT32 ShortGI:1;
  1224. UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
  1225. UINT32 TxBF:1; // 3*3
  1226. UINT32 rsv0:10;
  1227. //UINT32 MCS:7; // MCS
  1228. //UINT32 PhyMode:4;
  1229. } field;
  1230. #else
  1231. struct {
  1232. //UINT32 PhyMode:4;
  1233. //UINT32 MCS:7; // MCS
  1234. UINT32 rsv0:10;
  1235. UINT32 TxBF:1;
  1236. UINT32 BW:1; //channel bandwidth 20MHz or 40 MHz
  1237. UINT32 ShortGI:1;
  1238. UINT32 STBC:1; //SPACE
  1239. UINT32 TRANSNO:2;
  1240. UINT32 HTMODE:1;
  1241. UINT32 EXTCHA:2;
  1242. UINT32 rsv:13;
  1243. } field;
  1244. #endif
  1245. UINT32 word;
  1246. } REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING;
  1247. typedef union _DESIRED_TRANSMIT_SETTING {
  1248. #ifdef RT_BI