rtllib.h 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  1. /*
  2. * Merged with mainline rtllib.h in Aug 2004. Original ieee802_11
  3. * remains copyright by the original authors
  4. *
  5. * Portions of the merged code are based on Host AP (software wireless
  6. * LAN access point) driver for Intersil Prism2/2.5/3.
  7. *
  8. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  9. * <jkmaline@cc.hut.fi>
  10. * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
  11. *
  12. * Adaption to a generic IEEE 802.11 stack by James Ketrenos
  13. * <jketreno@linux.intel.com>
  14. * Copyright (c) 2004, Intel Corporation
  15. *
  16. * Modified for Realtek's wi-fi cards by Andrea Merello
  17. * <andrea.merello@gmail.com>
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License version 2 as
  21. * published by the Free Software Foundation. See README and COPYING for
  22. * more details.
  23. */
  24. #ifndef RTLLIB_H
  25. #define RTLLIB_H
  26. #include <linux/if_ether.h> /* ETH_ALEN */
  27. #include <linux/kernel.h> /* ARRAY_SIZE */
  28. #include <linux/module.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/jiffies.h>
  31. #include <linux/timer.h>
  32. #include <linux/sched.h>
  33. #include <linux/mutex.h>
  34. #include <linux/delay.h>
  35. #include <linux/wireless.h>
  36. #include "rtllib_debug.h"
  37. #include "rtl819x_HT.h"
  38. #include "rtl819x_BA.h"
  39. #include "rtl819x_TS.h"
  40. #include <linux/netdevice.h>
  41. #include <linux/if_arp.h> /* ARPHRD_ETHER */
  42. #include <net/lib80211.h>
  43. #define MAX_PRECMD_CNT 16
  44. #define MAX_RFDEPENDCMD_CNT 16
  45. #define MAX_POSTCMD_CNT 16
  46. #ifndef WIRELESS_SPY
  47. #define WIRELESS_SPY
  48. #endif
  49. #include <net/iw_handler.h>
  50. #ifndef IW_MODE_MONITOR
  51. #define IW_MODE_MONITOR 6
  52. #endif
  53. #ifndef IWEVCUSTOM
  54. #define IWEVCUSTOM 0x8c02
  55. #endif
  56. #ifndef IW_CUSTOM_MAX
  57. /* Max number of char in custom event - use multiple of them if needed */
  58. #define IW_CUSTOM_MAX 256 /* In bytes */
  59. #endif
  60. #define skb_tail_pointer_rsl(skb) skb_tail_pointer(skb)
  61. #define queue_delayed_work_rsl(x, y, z) queue_delayed_work(x, y, z)
  62. #define INIT_DELAYED_WORK_RSL(x, y, z) INIT_DELAYED_WORK(x, y)
  63. #define queue_work_rsl(x, y) queue_work(x, y)
  64. #define INIT_WORK_RSL(x, y, z) INIT_WORK(x, y)
  65. #define container_of_work_rsl(x, y, z) container_of(x, y, z)
  66. #define container_of_dwork_rsl(x, y, z) \
  67. container_of(to_delayed_work(x), y, z)
  68. #define iwe_stream_add_event_rsl(info, start, stop, iwe, len) \
  69. iwe_stream_add_event(info, start, stop, iwe, len)
  70. #define iwe_stream_add_point_rsl(info, start, stop, iwe, p) \
  71. iwe_stream_add_point(info, start, stop, iwe, p)
  72. static inline void *netdev_priv_rsl(struct net_device *dev)
  73. {
  74. return netdev_priv(dev);
  75. }
  76. #define KEY_TYPE_NA 0x0
  77. #define KEY_TYPE_WEP40 0x1
  78. #define KEY_TYPE_TKIP 0x2
  79. #define KEY_TYPE_CCMP 0x4
  80. #define KEY_TYPE_WEP104 0x5
  81. /* added for rtl819x tx procedure */
  82. #define MAX_QUEUE_SIZE 0x10
  83. #define BK_QUEUE 0
  84. #define BE_QUEUE 1
  85. #define VI_QUEUE 2
  86. #define VO_QUEUE 3
  87. #define HCCA_QUEUE 4
  88. #define TXCMD_QUEUE 5
  89. #define MGNT_QUEUE 6
  90. #define HIGH_QUEUE 7
  91. #define BEACON_QUEUE 8
  92. #ifndef IW_MODE_MESH
  93. #define IW_MODE_MESH 7
  94. #endif
  95. #define IE_CISCO_FLAG_POSITION 0x08
  96. #define SUPPORT_CKIP_MIC 0x08
  97. #define SUPPORT_CKIP_PK 0x10
  98. #define RT_RF_OFF_LEVL_HALT_NIC BIT3
  99. #define RT_IN_PS_LEVEL(pPSC, _PS_FLAG) \
  100. ((pPSC->CurPsLevel & _PS_FLAG) ? true : false)
  101. #define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG) \
  102. (pPSC->CurPsLevel &= (~(_PS_FLAG)))
  103. #define RT_SET_PS_LEVEL(pPSC, _PS_FLAG) (pPSC->CurPsLevel |= _PS_FLAG)
  104. /* defined for skb cb field */
  105. /* At most 28 byte */
  106. struct cb_desc {
  107. /* Tx Desc Related flags (8-9) */
  108. u8 bLastIniPkt:1;
  109. u8 bCmdOrInit:1;
  110. u8 bFirstSeg:1;
  111. u8 bLastSeg:1;
  112. u8 bEncrypt:1;
  113. u8 bTxDisableRateFallBack:1;
  114. u8 bTxUseDriverAssingedRate:1;
  115. u8 bHwSec:1;
  116. u8 nStuckCount;
  117. /* Tx Firmware Related flags (10-11)*/
  118. u8 bCTSEnable:1;
  119. u8 bRTSEnable:1;
  120. u8 bUseShortGI:1;
  121. u8 bUseShortPreamble:1;
  122. u8 bTxEnableFwCalcDur:1;
  123. u8 bAMPDUEnable:1;
  124. u8 bRTSSTBC:1;
  125. u8 RTSSC:1;
  126. u8 bRTSBW:1;
  127. u8 bPacketBW:1;
  128. u8 bRTSUseShortPreamble:1;
  129. u8 bRTSUseShortGI:1;
  130. u8 bMulticast:1;
  131. u8 bBroadcast:1;
  132. u8 drv_agg_enable:1;
  133. u8 reserved2:1;
  134. /* Tx Desc related element(12-19) */
  135. u8 rata_index;
  136. u8 queue_index;
  137. u16 txbuf_size;
  138. u8 RATRIndex;
  139. u8 bAMSDU:1;
  140. u8 bFromAggrQ:1;
  141. u8 reserved6:6;
  142. u8 macId;
  143. u8 priority;
  144. /* Tx firmware related element(20-27) */
  145. u8 data_rate;
  146. u8 rts_rate;
  147. u8 ampdu_factor;
  148. u8 ampdu_density;
  149. u8 DrvAggrNum;
  150. u8 bdhcp;
  151. u16 pkt_size;
  152. u8 bIsSpecialDataFrame;
  153. u8 bBTTxPacket;
  154. u8 bIsBTProbRsp;
  155. };
  156. enum sw_chnl_cmd_id {
  157. CmdID_End,
  158. CmdID_SetTxPowerLevel,
  159. CmdID_BBRegWrite10,
  160. CmdID_WritePortUlong,
  161. CmdID_WritePortUshort,
  162. CmdID_WritePortUchar,
  163. CmdID_RF_WriteReg,
  164. };
  165. struct sw_chnl_cmd {
  166. enum sw_chnl_cmd_id CmdID;
  167. u32 Para1;
  168. u32 Para2;
  169. u32 msDelay;
  170. } __packed;
  171. /*--------------------------Define -------------------------------------------*/
  172. #define MGN_1M 0x02
  173. #define MGN_2M 0x04
  174. #define MGN_5_5M 0x0b
  175. #define MGN_11M 0x16
  176. #define MGN_6M 0x0c
  177. #define MGN_9M 0x12
  178. #define MGN_12M 0x18
  179. #define MGN_18M 0x24
  180. #define MGN_24M 0x30
  181. #define MGN_36M 0x48
  182. #define MGN_48M 0x60
  183. #define MGN_54M 0x6c
  184. #define MGN_MCS0 0x80
  185. #define MGN_MCS1 0x81
  186. #define MGN_MCS2 0x82
  187. #define MGN_MCS3 0x83
  188. #define MGN_MCS4 0x84
  189. #define MGN_MCS5 0x85
  190. #define MGN_MCS6 0x86
  191. #define MGN_MCS7 0x87
  192. #define MGN_MCS8 0x88
  193. #define MGN_MCS9 0x89
  194. #define MGN_MCS10 0x8a
  195. #define MGN_MCS11 0x8b
  196. #define MGN_MCS12 0x8c
  197. #define MGN_MCS13 0x8d
  198. #define MGN_MCS14 0x8e
  199. #define MGN_MCS15 0x8f
  200. enum hw_variables {
  201. HW_VAR_ETHER_ADDR,
  202. HW_VAR_MULTICAST_REG,
  203. HW_VAR_BASIC_RATE,
  204. HW_VAR_BSSID,
  205. HW_VAR_MEDIA_STATUS,
  206. HW_VAR_SECURITY_CONF,
  207. HW_VAR_BEACON_INTERVAL,
  208. HW_VAR_ATIM_WINDOW,
  209. HW_VAR_LISTEN_INTERVAL,
  210. HW_VAR_CS_COUNTER,
  211. HW_VAR_DEFAULTKEY0,
  212. HW_VAR_DEFAULTKEY1,
  213. HW_VAR_DEFAULTKEY2,
  214. HW_VAR_DEFAULTKEY3,
  215. HW_VAR_SIFS,
  216. HW_VAR_DIFS,
  217. HW_VAR_EIFS,
  218. HW_VAR_SLOT_TIME,
  219. HW_VAR_ACK_PREAMBLE,
  220. HW_VAR_CW_CONFIG,
  221. HW_VAR_CW_VALUES,
  222. HW_VAR_RATE_FALLBACK_CONTROL,
  223. HW_VAR_CONTENTION_WINDOW,
  224. HW_VAR_RETRY_COUNT,
  225. HW_VAR_TR_SWITCH,
  226. HW_VAR_COMMAND,
  227. HW_VAR_WPA_CONFIG,
  228. HW_VAR_AMPDU_MIN_SPACE,
  229. HW_VAR_SHORTGI_DENSITY,
  230. HW_VAR_AMPDU_FACTOR,
  231. HW_VAR_MCS_RATE_AVAILABLE,
  232. HW_VAR_AC_PARAM,
  233. HW_VAR_ACM_CTRL,
  234. HW_VAR_DIS_Req_Qsize,
  235. HW_VAR_CCX_CHNL_LOAD,
  236. HW_VAR_CCX_NOISE_HISTOGRAM,
  237. HW_VAR_CCX_CLM_NHM,
  238. HW_VAR_TxOPLimit,
  239. HW_VAR_TURBO_MODE,
  240. HW_VAR_RF_STATE,
  241. HW_VAR_RF_OFF_BY_HW,
  242. HW_VAR_BUS_SPEED,
  243. HW_VAR_SET_DEV_POWER,
  244. HW_VAR_RCR,
  245. HW_VAR_RATR_0,
  246. HW_VAR_RRSR,
  247. HW_VAR_CPU_RST,
  248. HW_VAR_CECHK_BSSID,
  249. HW_VAR_LBK_MODE,
  250. HW_VAR_AES_11N_FIX,
  251. HW_VAR_USB_RX_AGGR,
  252. HW_VAR_USER_CONTROL_TURBO_MODE,
  253. HW_VAR_RETRY_LIMIT,
  254. HW_VAR_INIT_TX_RATE,
  255. HW_VAR_TX_RATE_REG,
  256. HW_VAR_EFUSE_USAGE,
  257. HW_VAR_EFUSE_BYTES,
  258. HW_VAR_AUTOLOAD_STATUS,
  259. HW_VAR_RF_2R_DISABLE,
  260. HW_VAR_SET_RPWM,
  261. HW_VAR_H2C_FW_PWRMODE,
  262. HW_VAR_H2C_FW_JOINBSSRPT,
  263. HW_VAR_1X1_RECV_COMBINE,
  264. HW_VAR_STOP_SEND_BEACON,
  265. HW_VAR_TSF_TIMER,
  266. HW_VAR_IO_CMD,
  267. HW_VAR_RF_RECOVERY,
  268. HW_VAR_H2C_FW_UPDATE_GTK,
  269. HW_VAR_WF_MASK,
  270. HW_VAR_WF_CRC,
  271. HW_VAR_WF_IS_MAC_ADDR,
  272. HW_VAR_H2C_FW_OFFLOAD,
  273. HW_VAR_RESET_WFCRC,
  274. HW_VAR_HANDLE_FW_C2H,
  275. HW_VAR_DL_FW_RSVD_PAGE,
  276. HW_VAR_AID,
  277. HW_VAR_HW_SEQ_ENABLE,
  278. HW_VAR_CORRECT_TSF,
  279. HW_VAR_BCN_VALID,
  280. HW_VAR_FWLPS_RF_ON,
  281. HW_VAR_DUAL_TSF_RST,
  282. HW_VAR_SWITCH_EPHY_WoWLAN,
  283. HW_VAR_INT_MIGRATION,
  284. HW_VAR_INT_AC,
  285. HW_VAR_RF_TIMING,
  286. };
  287. enum rt_op_mode {
  288. RT_OP_MODE_AP,
  289. RT_OP_MODE_INFRASTRUCTURE,
  290. RT_OP_MODE_IBSS,
  291. RT_OP_MODE_NO_LINK,
  292. };
  293. #define aSifsTime \
  294. (((priv->rtllib->current_network.mode == IEEE_A) \
  295. || (priv->rtllib->current_network.mode == IEEE_N_24G) \
  296. || (priv->rtllib->current_network.mode == IEEE_N_5G)) ? 16 : 10)
  297. #define MGMT_QUEUE_NUM 5
  298. #define MAX_IE_LEN 0xff
  299. #define msleep_interruptible_rsl msleep_interruptible
  300. /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
  301. * 6.2.1.1.2.
  302. *
  303. * The figure in section 7.1.2 suggests a body size of up to 2312
  304. * bytes is allowed, which is a bit confusing, I suspect this
  305. * represents the 2304 bytes of real data, plus a possible 8 bytes of
  306. * WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro)
  307. */
  308. #define RTLLIB_1ADDR_LEN 10
  309. #define RTLLIB_2ADDR_LEN 16
  310. #define RTLLIB_3ADDR_LEN 24
  311. #define RTLLIB_4ADDR_LEN 30
  312. #define RTLLIB_FCS_LEN 4
  313. #define RTLLIB_SKBBUFFER_SIZE 2500
  314. #define MIN_FRAG_THRESHOLD 256U
  315. #define MAX_FRAG_THRESHOLD 2346U
  316. /* Frame control field constants */
  317. #define RTLLIB_FCTL_FTYPE 0x000c
  318. #define RTLLIB_FCTL_STYPE 0x00f0
  319. #define RTLLIB_FCTL_FRAMETYPE 0x00fc
  320. #define RTLLIB_FCTL_TODS 0x0100
  321. #define RTLLIB_FCTL_FROMDS 0x0200
  322. #define RTLLIB_FCTL_DSTODS 0x0300
  323. #define RTLLIB_FCTL_MOREFRAGS 0x0400
  324. #define RTLLIB_FCTL_RETRY 0x0800
  325. #define RTLLIB_FCTL_PM 0x1000
  326. #define RTLLIB_FCTL_MOREDATA 0x2000
  327. #define RTLLIB_FCTL_WEP 0x4000
  328. #define RTLLIB_FCTL_ORDER 0x8000
  329. #define RTLLIB_FTYPE_MGMT 0x0000
  330. #define RTLLIB_FTYPE_CTL 0x0004
  331. #define RTLLIB_FTYPE_DATA 0x0008
  332. /* management */
  333. #define RTLLIB_STYPE_ASSOC_REQ 0x0000
  334. #define RTLLIB_STYPE_ASSOC_RESP 0x0010
  335. #define RTLLIB_STYPE_REASSOC_REQ 0x0020
  336. #define RTLLIB_STYPE_REASSOC_RESP 0x0030
  337. #define RTLLIB_STYPE_PROBE_REQ 0x0040
  338. #define RTLLIB_STYPE_PROBE_RESP 0x0050
  339. #define RTLLIB_STYPE_BEACON 0x0080
  340. #define RTLLIB_STYPE_ATIM 0x0090
  341. #define RTLLIB_STYPE_DISASSOC 0x00A0
  342. #define RTLLIB_STYPE_AUTH 0x00B0
  343. #define RTLLIB_STYPE_DEAUTH 0x00C0
  344. #define RTLLIB_STYPE_MANAGE_ACT 0x00D0
  345. /* control */
  346. #define RTLLIB_STYPE_PSPOLL 0x00A0
  347. #define RTLLIB_STYPE_RTS 0x00B0
  348. #define RTLLIB_STYPE_CTS 0x00C0
  349. #define RTLLIB_STYPE_ACK 0x00D0
  350. /* data */
  351. #define RTLLIB_STYPE_DATA 0x0000
  352. #define RTLLIB_STYPE_DATA_CFACK 0x0010
  353. #define RTLLIB_STYPE_DATA_CFPOLL 0x0020
  354. #define RTLLIB_STYPE_DATA_CFACKPOLL 0x0030
  355. #define RTLLIB_STYPE_NULLFUNC 0x0040
  356. #define RTLLIB_STYPE_QOS_DATA 0x0080
  357. #define RTLLIB_STYPE_QOS_NULL 0x00C0
  358. #define RTLLIB_SCTL_FRAG 0x000F
  359. #define RTLLIB_SCTL_SEQ 0xFFF0
  360. /* QOS control */
  361. #define RTLLIB_QCTL_TID 0x000F
  362. #define FC_QOS_BIT BIT7
  363. #define IsDataFrame(pdu) (((pdu[0] & 0x0C) == 0x08) ? true : false)
  364. #define IsLegacyDataFrame(pdu) (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
  365. #define IsQoSDataFrame(pframe) \
  366. ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) == \
  367. (RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA))
  368. #define Frame_Order(pframe) (*(u16 *)pframe&RTLLIB_FCTL_ORDER)
  369. #define SN_LESS(a, b) (((a-b)&0x800) != 0)
  370. #define SN_EQUAL(a, b) (a == b)
  371. #define MAX_DEV_ADDR_SIZE 8
  372. enum act_category {
  373. ACT_CAT_QOS = 1,
  374. ACT_CAT_DLS = 2,
  375. ACT_CAT_BA = 3,
  376. ACT_CAT_HT = 7,
  377. ACT_CAT_WMM = 17,
  378. };
  379. enum ba_action {
  380. ACT_ADDBAREQ = 0,
  381. ACT_ADDBARSP = 1,
  382. ACT_DELBA = 2,
  383. };
  384. enum init_gain_op_type {
  385. IG_Backup = 0,
  386. IG_Restore,
  387. IG_Max
  388. };
  389. enum led_ctl_mode {
  390. LED_CTL_POWER_ON = 1,
  391. LED_CTL_LINK = 2,
  392. LED_CTL_NO_LINK = 3,
  393. LED_CTL_TX = 4,
  394. LED_CTL_RX = 5,
  395. LED_CTL_SITE_SURVEY = 6,
  396. LED_CTL_POWER_OFF = 7,
  397. LED_CTL_START_TO_LINK = 8,
  398. };
  399. enum rt_rf_type_def {
  400. RF_1T2R = 0,
  401. RF_2T4R,
  402. };
  403. enum wireless_mode {
  404. WIRELESS_MODE_UNKNOWN = 0x00,
  405. WIRELESS_MODE_A = 0x01,
  406. WIRELESS_MODE_B = 0x02,
  407. WIRELESS_MODE_G = 0x04,
  408. WIRELESS_MODE_AUTO = 0x08,
  409. WIRELESS_MODE_N_24G = 0x10,
  410. WIRELESS_MODE_N_5G = 0x20
  411. };
  412. #ifndef ETH_P_PAE
  413. #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
  414. #define ETH_P_IP 0x0800 /* Internet Protocol packet */
  415. #define ETH_P_ARP 0x0806 /* Address Resolution packet */
  416. #endif /* ETH_P_PAE */
  417. #ifndef ETH_P_80211_RAW
  418. #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
  419. #endif
  420. /* IEEE 802.11 defines */
  421. #define P80211_OUI_LEN 3
  422. struct rtllib_snap_hdr {
  423. u8 dsap; /* always 0xAA */
  424. u8 ssap; /* always 0xAA */
  425. u8 ctrl; /* always 0x03 */
  426. u8 oui[P80211_OUI_LEN]; /* organizational universal id */
  427. } __packed;
  428. enum _REG_PREAMBLE_MODE {
  429. PREAMBLE_LONG = 1,
  430. PREAMBLE_AUTO = 2,
  431. PREAMBLE_SHORT = 3,
  432. };
  433. #define SNAP_SIZE sizeof(struct rtllib_snap_hdr)
  434. #define WLAN_FC_GET_TYPE(fc) ((fc) & RTLLIB_FCTL_FTYPE)
  435. #define WLAN_FC_GET_STYPE(fc) ((fc) & RTLLIB_FCTL_STYPE)
  436. #define WLAN_FC_MORE_DATA(fc) ((fc) & RTLLIB_FCTL_MOREDATA)
  437. #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & RTLLIB_FCTL_FRAMETYPE)
  438. #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTLLIB_SCTL_FRAG)
  439. #define WLAN_GET_SEQ_SEQ(seq) (((seq) & RTLLIB_SCTL_SEQ) >> 4)
  440. /* Authentication algorithms */
  441. #define WLAN_AUTH_OPEN 0
  442. #define WLAN_AUTH_SHARED_KEY 1
  443. #define WLAN_AUTH_LEAP 128
  444. #define WLAN_CAPABILITY_ESS (1<<0)
  445. #define WLAN_CAPABILITY_IBSS (1<<1)
  446. #define WLAN_CAPABILITY_PRIVACY (1<<4)
  447. #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
  448. #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
  449. #define RTLLIB_STATMASK_SIGNAL (1<<0)
  450. #define RTLLIB_STATMASK_RSSI (1<<1)
  451. #define RTLLIB_STATMASK_NOISE (1<<2)
  452. #define RTLLIB_STATMASK_WEMASK 0x7
  453. #define RTLLIB_CCK_MODULATION (1<<0)
  454. #define RTLLIB_OFDM_MODULATION (1<<1)
  455. #define RTLLIB_24GHZ_BAND (1<<0)
  456. #define RTLLIB_52GHZ_BAND (1<<1)
  457. #define RTLLIB_CCK_RATE_LEN 4
  458. #define RTLLIB_CCK_RATE_1MB 0x02
  459. #define RTLLIB_CCK_RATE_2MB 0x04
  460. #define RTLLIB_CCK_RATE_5MB 0x0B
  461. #define RTLLIB_CCK_RATE_11MB 0x16
  462. #define RTLLIB_OFDM_RATE_LEN 8
  463. #define RTLLIB_OFDM_RATE_6MB 0x0C
  464. #define RTLLIB_OFDM_RATE_9MB 0x12
  465. #define RTLLIB_OFDM_RATE_12MB 0x18
  466. #define RTLLIB_OFDM_RATE_18MB 0x24
  467. #define RTLLIB_OFDM_RATE_24MB 0x30
  468. #define RTLLIB_OFDM_RATE_36MB 0x48
  469. #define RTLLIB_OFDM_RATE_48MB 0x60
  470. #define RTLLIB_OFDM_RATE_54MB 0x6C
  471. #define RTLLIB_BASIC_RATE_MASK 0x80
  472. /* this is stolen and modified from the madwifi driver*/
  473. #define RTLLIB_FC0_TYPE_MASK 0x0c
  474. #define RTLLIB_FC0_TYPE_DATA 0x08
  475. #define RTLLIB_FC0_SUBTYPE_MASK 0xB0
  476. #define RTLLIB_FC0_SUBTYPE_QOS 0x80
  477. #define RTLLIB_QOS_HAS_SEQ(fc) \
  478. (((fc) & (RTLLIB_FC0_TYPE_MASK | RTLLIB_FC0_SUBTYPE_MASK)) == \
  479. (RTLLIB_FC0_TYPE_DATA | RTLLIB_FC0_SUBTYPE_QOS))
  480. /* this is stolen from ipw2200 driver */
  481. #define IEEE_IBSS_MAC_HASH_SIZE 31
  482. struct ieee_ibss_seq {
  483. u8 mac[ETH_ALEN];
  484. u16 seq_num[17];
  485. u16 frag_num[17];
  486. unsigned long packet_time[17];
  487. struct list_head list;
  488. };
  489. /* NOTE: This data is for statistical purposes; not all hardware provides this
  490. * information for frames received. Not setting these will not cause
  491. * any adverse affects.
  492. */
  493. struct rtllib_rx_stats {
  494. u64 mac_time;
  495. s8 rssi;
  496. u8 signal;
  497. u8 noise;
  498. u16 rate; /* in 100 kbps */
  499. u8 received_channel;
  500. u8 control;
  501. u8 mask;
  502. u8 freq;
  503. u16 len;
  504. u64 tsf;
  505. u32 beacon_time;
  506. u8 nic_type;
  507. u16 Length;
  508. u8 SignalQuality;
  509. s32 RecvSignalPower;
  510. s8 RxPower;
  511. u8 SignalStrength;
  512. u16 bHwError:1;
  513. u16 bCRC:1;
  514. u16 bICV:1;
  515. u16 bShortPreamble:1;
  516. u16 Antenna:1;
  517. u16 Decrypted:1;
  518. u16 Wakeup:1;
  519. u16 Reserved0:1;
  520. u8 AGC;
  521. u32 TimeStampLow;
  522. u32 TimeStampHigh;
  523. bool bShift;
  524. bool bIsQosData;
  525. u8 RxDrvInfoSize;
  526. u8 RxBufShift;
  527. bool bIsAMPDU;
  528. bool bFirstMPDU;
  529. bool bContainHTC;
  530. bool RxIs40MHzPacket;
  531. u32 RxPWDBAll;
  532. u8 RxMIMOSignalStrength[4];
  533. s8 RxMIMOSignalQuality[2];
  534. bool bPacketMatchBSSID;
  535. bool bIsCCK;
  536. bool bPacketToSelf;
  537. u16 packetlength;
  538. u16 fraglength;
  539. u16 fragoffset;
  540. u16 ntotalfrag;
  541. bool bPacketBeacon;
  542. bool bToSelfBA;
  543. u16 Seq_Num;
  544. };
  545. /* IEEE 802.11 requires that STA supports concurrent reception of at least
  546. * three fragmented frames. This define can be increased to support more
  547. * concurrent frames, but it should be noted that each entry can consume about
  548. * 2 kB of RAM and increasing cache size will slow down frame reassembly.
  549. */
  550. #define RTLLIB_FRAG_CACHE_LEN 4
  551. struct rtllib_frag_entry {
  552. unsigned long first_frag_time;
  553. unsigned int seq;
  554. unsigned int last_frag;
  555. struct sk_buff *skb;
  556. u8 src_addr[ETH_ALEN];
  557. u8 dst_addr[ETH_ALEN];
  558. };
  559. struct rtllib_device;
  560. #define SEC_ACTIVE_KEY (1<<4)
  561. #define SEC_AUTH_MODE (1<<5)
  562. #define SEC_UNICAST_GROUP (1<<6)
  563. #define SEC_LEVEL (1<<7)
  564. #define SEC_ENABLED (1<<8)
  565. #define SEC_LEVEL_0 0 /* None */
  566. #define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */
  567. #define SEC_LEVEL_2 2 /* Level 1 + TKIP */
  568. #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
  569. #define SEC_LEVEL_3 4 /* Level 2 + CCMP */
  570. #define SEC_ALG_NONE 0
  571. #define SEC_ALG_WEP 1
  572. #define SEC_ALG_TKIP 2
  573. #define SEC_ALG_CCMP 4
  574. #define WEP_KEY_LEN 13
  575. #define SCM_KEY_LEN 32
  576. struct rtllib_security {
  577. u16 active_key:2,
  578. enabled:1,
  579. auth_mode:2,
  580. auth_algo:4,
  581. unicast_uses_group:1,
  582. encrypt:1;
  583. u8 key_sizes[NUM_WEP_KEYS];
  584. u8 keys[NUM_WEP_KEYS][SCM_KEY_LEN];
  585. u8 level;
  586. u16 flags;
  587. } __packed;
  588. /* 802.11 data frame from AP
  589. * ,-------------------------------------------------------------------.
  590. * Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
  591. * |------|------|---------|---------|---------|------|---------|------|
  592. * Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs |
  593. * | | tion | (BSSID) | | | ence | data | |
  594. * `-------------------------------------------------------------------'
  595. * Total: 28-2340 bytes
  596. */
  597. /* Management Frame Information Element Types */
  598. enum rtllib_mfie {
  599. MFIE_TYPE_SSID = 0,
  600. MFIE_TYPE_RATES = 1,
  601. MFIE_TYPE_FH_SET = 2,
  602. MFIE_TYPE_DS_SET = 3,
  603. MFIE_TYPE_CF_SET = 4,
  604. MFIE_TYPE_TIM = 5,
  605. MFIE_TYPE_IBSS_SET = 6,
  606. MFIE_TYPE_COUNTRY = 7,
  607. MFIE_TYPE_HOP_PARAMS = 8,
  608. MFIE_TYPE_HOP_TABLE = 9,
  609. MFIE_TYPE_REQUEST = 10,
  610. MFIE_TYPE_CHALLENGE = 16,
  611. MFIE_TYPE_POWER_CONSTRAINT = 32,
  612. MFIE_TYPE_POWER_CAPABILITY = 33,
  613. MFIE_TYPE_TPC_REQUEST = 34,
  614. MFIE_TYPE_TPC_REPORT = 35,
  615. MFIE_TYPE_SUPP_CHANNELS = 36,
  616. MFIE_TYPE_CSA = 37,
  617. MFIE_TYPE_MEASURE_REQUEST = 38,
  618. MFIE_TYPE_MEASURE_REPORT = 39,
  619. MFIE_TYPE_QUIET = 40,
  620. MFIE_TYPE_IBSS_DFS = 41,
  621. MFIE_TYPE_ERP = 42,
  622. MFIE_TYPE_HT_CAP = 45,
  623. MFIE_TYPE_RSN = 48,
  624. MFIE_TYPE_RATES_EX = 50,
  625. MFIE_TYPE_HT_INFO = 61,
  626. MFIE_TYPE_AIRONET = 133,
  627. MFIE_TYPE_GENERIC = 221,
  628. MFIE_TYPE_QOS_PARAMETER = 222,
  629. };
  630. /* Minimal header; can be used for passing 802.11 frames with sufficient
  631. * information to determine what type of underlying data type is actually
  632. * stored in the data.
  633. */
  634. struct rtllib_pspoll_hdr {
  635. __le16 frame_ctl;
  636. __le16 aid;
  637. u8 bssid[ETH_ALEN];
  638. u8 ta[ETH_ALEN];
  639. } __packed;
  640. struct rtllib_hdr {
  641. __le16 frame_ctl;
  642. __le16 duration_id;
  643. u8 payload[0];
  644. } __packed;
  645. struct rtllib_hdr_1addr {
  646. __le16 frame_ctl;
  647. __le16 duration_id;
  648. u8 addr1[ETH_ALEN];
  649. u8 payload[0];
  650. } __packed;
  651. struct rtllib_hdr_2addr {
  652. __le16 frame_ctl;
  653. __le16 duration_id;
  654. u8 addr1[ETH_ALEN];
  655. u8 addr2[ETH_ALEN];
  656. u8 payload[0];
  657. } __packed;
  658. struct rtllib_hdr_3addr {
  659. __le16 frame_ctl;
  660. __le16 duration_id;
  661. u8 addr1[ETH_ALEN];
  662. u8 addr2[ETH_ALEN];
  663. u8 addr3[ETH_ALEN];
  664. __le16 seq_ctl;
  665. u8 payload[0];
  666. } __packed;
  667. struct rtllib_hdr_4addr {
  668. __le16 frame_ctl;
  669. __le16 duration_id;
  670. u8 addr1[ETH_ALEN];
  671. u8 addr2[ETH_ALEN];
  672. u8 addr3[ETH_ALEN];
  673. __le16 seq_ctl;
  674. u8 addr4[ETH_ALEN];
  675. u8 payload[0];
  676. } __packed;
  677. struct rtllib_hdr_3addrqos {
  678. __le16 frame_ctl;
  679. __le16 duration_id;
  680. u8 addr1[ETH_ALEN];
  681. u8 addr2[ETH_ALEN];
  682. u8 addr3[ETH_ALEN];
  683. __le16 seq_ctl;
  684. __le16 qos_ctl;
  685. u8 payload[0];
  686. } __packed;
  687. struct rtllib_hdr_4addrqos {
  688. __le16 frame_ctl;
  689. __le16 duration_id;
  690. u8 addr1[ETH_ALEN];
  691. u8 addr2[ETH_ALEN];
  692. u8 addr3[ETH_ALEN];
  693. __le16 seq_ctl;
  694. u8 addr4[ETH_ALEN];
  695. __le16 qos_ctl;
  696. u8 payload[0];
  697. } __packed;
  698. struct rtllib_info_element {
  699. u8 id;
  700. u8 len;
  701. u8 data[0];
  702. } __packed;
  703. struct rtllib_authentication {
  704. struct rtllib_hdr_3addr header;
  705. __le16 algorithm;
  706. __le16 transaction;
  707. __le16 status;
  708. /*challenge*/
  709. struct rtllib_info_element info_element[0];
  710. } __packed;
  711. struct rtllib_disauth {
  712. struct rtllib_hdr_3addr header;
  713. __le16 reason;
  714. } __packed;
  715. struct rtllib_disassoc {
  716. struct rtllib_hdr_3addr header;
  717. __le16 reason;
  718. } __packed;
  719. struct rtllib_probe_request {
  720. struct rtllib_hdr_3addr header;
  721. /* SSID, supported rates */
  722. struct rtllib_info_element info_element[0];
  723. } __packed;
  724. struct rtllib_probe_response {
  725. struct rtllib_hdr_3addr header;
  726. u32 time_stamp[2];
  727. __le16 beacon_interval;
  728. __le16 capability;
  729. /* SSID, supported rates, FH params, DS params,
  730. * CF params, IBSS params, TIM (if beacon), RSN
  731. */
  732. struct rtllib_info_element info_element[0];
  733. } __packed;
  734. /* Alias beacon for probe_response */
  735. #define rtllib_beacon rtllib_probe_response
  736. struct rtllib_assoc_request_frame {
  737. struct rtllib_hdr_3addr header;
  738. __le16 capability;
  739. __le16 listen_interval;
  740. /* SSID, supported rates, RSN */
  741. struct rtllib_info_element info_element[0];
  742. } __packed;
  743. struct rtllib_assoc_response_frame {
  744. struct rtllib_hdr_3addr header;
  745. __le16 capability;
  746. __le16 status;
  747. __le16 aid;
  748. struct rtllib_info_element info_element[0]; /* supported rates */
  749. } __packed;
  750. struct rtllib_txb {
  751. u8 nr_frags;
  752. u8 encrypted;
  753. u8 queue_index;
  754. u8 rts_included;
  755. u16 reserved;
  756. __le16 frag_size;
  757. __le16 payload_size;
  758. struct sk_buff *fragments[0];
  759. };
  760. #define MAX_SUBFRAME_COUNT 64
  761. struct rtllib_rxb {
  762. u8 nr_subframes;
  763. struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
  764. u8 dst[ETH_ALEN];
  765. u8 src[ETH_ALEN];
  766. } __packed;
  767. union frameqos {
  768. u16 shortdata;
  769. u8 chardata[2];
  770. struct {
  771. u16 tid:4;
  772. u16 eosp:1;
  773. u16 ack_policy:2;
  774. u16 reserved:1;
  775. u16 txop:8;
  776. } field;
  777. };
  778. /* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs
  779. * only use 8, and then use extended rates for the remaining supported
  780. * rates. Other APs, however, stick all of their supported rates on the
  781. * main rates information element...
  782. */
  783. #define MAX_RATES_LENGTH ((u8)12)
  784. #define MAX_RATES_EX_LENGTH ((u8)16)
  785. #define MAX_NETWORK_COUNT 96
  786. #define MAX_CHANNEL_NUMBER 161
  787. #define RTLLIB_SOFTMAC_SCAN_TIME 100
  788. #define RTLLIB_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
  789. #define MAX_WPA_IE_LEN 64
  790. #define MAX_WZC_IE_LEN 256
  791. #define NETWORK_EMPTY_ESSID (1<<0)
  792. #define NETWORK_HAS_OFDM (1<<1)
  793. #define NETWORK_HAS_CCK (1<<2)
  794. /* QoS structure */
  795. #define NETWORK_HAS_QOS_PARAMETERS (1<<3)
  796. #define NETWORK_HAS_QOS_INFORMATION (1<<4)
  797. #define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | \
  798. NETWORK_HAS_QOS_INFORMATION)
  799. /* 802.11h */
  800. #define NETWORK_HAS_ERP_VALUE (1<<10)
  801. #define QOS_QUEUE_NUM 4
  802. #define QOS_OUI_LEN 3
  803. #define QOS_OUI_TYPE 2
  804. #define QOS_ELEMENT_ID 221
  805. #define QOS_OUI_INFO_SUB_TYPE 0
  806. #define QOS_OUI_PARAM_SUB_TYPE 1
  807. #define QOS_VERSION_1 1
  808. struct rtllib_qos_information_element {
  809. u8 elementID;
  810. u8 length;
  811. u8 qui[QOS_OUI_LEN];
  812. u8 qui_type;
  813. u8 qui_subtype;
  814. u8 version;
  815. u8 ac_info;
  816. } __packed;
  817. struct rtllib_qos_ac_parameter {
  818. u8 aci_aifsn;
  819. u8 ecw_min_max;
  820. __le16 tx_op_limit;
  821. } __packed;
  822. struct rtllib_qos_parameter_info {
  823. struct rtllib_qos_information_element info_element;
  824. u8 reserved;
  825. struct rtllib_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
  826. } __packed;
  827. struct rtllib_qos_parameters {
  828. __le16 cw_min[QOS_QUEUE_NUM];
  829. __le16 cw_max[QOS_QUEUE_NUM];
  830. u8 aifs[QOS_QUEUE_NUM];
  831. u8 flag[QOS_QUEUE_NUM];
  832. __le16 tx_op_limit[QOS_QUEUE_NUM];
  833. } __packed;
  834. struct rtllib_qos_data {
  835. struct rtllib_qos_parameters parameters;
  836. unsigned int wmm_acm;
  837. int active;
  838. int supported;
  839. u8 param_count;
  840. u8 old_param_count;
  841. };
  842. struct rtllib_tim_parameters {
  843. u8 tim_count;
  844. u8 tim_period;
  845. } __packed;
  846. struct rtllib_wmm_ac_param {
  847. u8 ac_aci_acm_aifsn;
  848. u8 ac_ecwmin_ecwmax;
  849. u16 ac_txop_limit;
  850. };
  851. enum eap_type {
  852. EAP_PACKET = 0,
  853. EAPOL_START,
  854. EAPOL_LOGOFF,
  855. EAPOL_KEY,
  856. EAPOL_ENCAP_ASF_ALERT
  857. };
  858. static const char * const eap_types[] = {
  859. [EAP_PACKET] = "EAP-Packet",
  860. [EAPOL_START] = "EAPOL-Start",
  861. [EAPOL_LOGOFF] = "EAPOL-Logoff",
  862. [EAPOL_KEY] = "EAPOL-Key",
  863. [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
  864. };
  865. static inline const char *eap_get_type(int type)
  866. {
  867. return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" :
  868. eap_types[type];
  869. }
  870. static inline u8 Frame_QoSTID(u8 *buf)
  871. {
  872. struct rtllib_hdr_3addr *hdr;
  873. u16 fc;
  874. hdr = (struct rtllib_hdr_3addr *)buf;
  875. fc = le16_to_cpu(hdr->frame_ctl);
  876. return (u8)((union frameqos *)(buf + (((fc & RTLLIB_FCTL_TODS) &&
  877. (fc & RTLLIB_FCTL_FROMDS)) ? 30 : 24)))->field.tid;
  878. }
  879. struct eapol {
  880. u8 snap[6];
  881. u16 ethertype;
  882. u8 version;
  883. u8 type;
  884. u16 length;
  885. } __packed;
  886. struct rtllib_softmac_stats {
  887. unsigned int rx_ass_ok;
  888. unsigned int rx_ass_err;
  889. unsigned int rx_probe_rq;
  890. unsigned int tx_probe_rs;
  891. unsigned int tx_beacons;
  892. unsigned int rx_auth_rq;
  893. unsigned int rx_auth_rs_ok;
  894. unsigned int rx_auth_rs_err;
  895. unsigned int tx_auth_rq;
  896. unsigned int no_auth_rs;
  897. unsigned int no_ass_rs;
  898. unsigned int tx_ass_rq;
  899. unsigned int rx_ass_rq;
  900. unsigned int tx_probe_rq;
  901. unsigned int reassoc;
  902. unsigned int swtxstop;
  903. unsigned int swtxawake;
  904. unsigned char CurrentShowTxate;
  905. unsigned char last_packet_rate;
  906. unsigned int txretrycount;
  907. };
  908. /* These are the data types that can make up management packets
  909. *
  910. * u16 auth_algorithm;
  911. * u16 auth_sequence;
  912. * u16 beacon_interval;
  913. * u16 capability;
  914. * u8 current_ap[ETH_ALEN];
  915. * u16 listen_interval;
  916. * struct {
  917. * u16 association_id:14, reserved:2;
  918. * } __packed;
  919. * u32 time_stamp[2];
  920. * u16 reason;
  921. * u16 status;
  922. */
  923. #define RTLLIB_DEFAULT_TX_ESSID "Penguin"
  924. #define RTLLIB_DEFAULT_BASIC_RATE 2
  925. enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
  926. #define MAX_SP_Len (WMM_all_frame << 4)
  927. #define RTLLIB_QOS_TID 0x0f
  928. #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
  929. #define RTLLIB_DTIM_MBCAST 4
  930. #define RTLLIB_DTIM_UCAST 2
  931. #define RTLLIB_DTIM_VALID 1
  932. #define RTLLIB_DTIM_INVALID 0
  933. #define RTLLIB_PS_DISABLED 0
  934. #define RTLLIB_PS_UNICAST RTLLIB_DTIM_UCAST
  935. #define RTLLIB_PS_MBCAST RTLLIB_DTIM_MBCAST
  936. #define WME_AC_BK 0x00
  937. #define WME_AC_BE 0x01
  938. #define WME_AC_VI 0x02
  939. #define WME_AC_VO 0x03
  940. #define WME_AC_PRAM_LEN 16
  941. #define MAX_RECEIVE_BUFFER_SIZE 9100
  942. #define UP2AC(up) ( \
  943. ((up) < 1) ? WME_AC_BE : \
  944. ((up) < 3) ? WME_AC_BK : \
  945. ((up) < 4) ? WME_AC_BE : \
  946. ((up) < 6) ? WME_AC_VI : \
  947. WME_AC_VO)
  948. #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
  949. #define ETHERNET_HEADER_SIZE 14 /* length of two Ethernet address
  950. * plus ether type
  951. */
  952. enum erp_t {
  953. ERP_NonERPpresent = 0x01,
  954. ERP_UseProtection = 0x02,
  955. ERP_BarkerPreambleMode = 0x04,
  956. };
  957. struct rtllib_network {
  958. /* These entries are used to identify a unique network */
  959. u8 bssid[ETH_ALEN];
  960. u8 channel;
  961. /* Ensure null-terminated for any debug msgs */
  962. u8 ssid[IW_ESSID_MAX_SIZE + 1];
  963. u8 ssid_len;
  964. u8 hidden_ssid[IW_ESSID_MAX_SIZE + 1];
  965. u8 hidden_ssid_len;
  966. struct rtllib_qos_data qos_data;
  967. bool bWithAironetIE;
  968. bool bCkipSupported;
  969. bool bCcxRmEnable;
  970. u16 CcxRmState[2];
  971. bool bMBssidValid;
  972. u8 MBssidMask;
  973. u8 MBssid[ETH_ALEN];
  974. bool bWithCcxVerNum;
  975. u8 BssCcxVerNumber;
  976. /* These are network statistics */
  977. struct rtllib_rx_stats stats;
  978. u16 capability;
  979. u8 rates[MAX_RATES_LENGTH];
  980. u8 rates_len;
  981. u8 rates_ex[MAX_RATES_EX_LENGTH];
  982. u8 rates_ex_len;
  983. unsigned long last_scanned;
  984. u8 mode;
  985. u32 flags;
  986. u32 time_stamp[2];
  987. u16 beacon_interval;
  988. u16 listen_interval;
  989. u16 atim_window;
  990. u8 erp_value;
  991. u8 wpa_ie[MAX_WPA_IE_LEN];
  992. size_t wpa_ie_len;
  993. u8 rsn_ie[MAX_WPA_IE_LEN];
  994. size_t rsn_ie_len;
  995. u8 wzc_ie[MAX_WZC_IE_LEN];
  996. size_t wzc_ie_len;
  997. struct rtllib_tim_parameters tim;
  998. u8 dtim_period;
  999. u8 dtim_data;
  1000. u64 last_dtim_sta_time;
  1001. u8 wmm_info;
  1002. struct rtllib_wmm_ac_param wmm_param[4];
  1003. u8 Turbo_Enable;
  1004. u16 CountryIeLen;
  1005. u8 CountryIeBuf[MAX_IE_LEN];
  1006. struct bss_ht bssht;
  1007. bool broadcom_cap_exist;
  1008. bool realtek_cap_exit;
  1009. bool marvell_cap_exist;
  1010. bool ralink_cap_exist;
  1011. bool atheros_cap_exist;
  1012. bool cisco_cap_exist;
  1013. bool airgo_cap_exist;
  1014. bool unknown_cap_exist;
  1015. bool berp_info_valid;
  1016. bool buseprotection;
  1017. u8 SignalStrength;
  1018. u8 RSSI;
  1019. struct list_head list;
  1020. };
  1021. enum rtllib_state {
  1022. /* the card is not linked at all */
  1023. RTLLIB_NOLINK = 0,
  1024. /* RTLLIB_ASSOCIATING* are for BSS client mode
  1025. * the driver shall not perform RX filtering unless
  1026. * the state is LINKED.
  1027. * The driver shall just check for the state LINKED and
  1028. * defaults to NOLINK for ALL the other states (including
  1029. * LINKED_SCANNING)
  1030. */
  1031. /* the association procedure will start (wq scheduling)*/
  1032. RTLLIB_ASSOCIATING,
  1033. RTLLIB_ASSOCIATING_RETRY,
  1034. /* the association procedure is sending AUTH request*/
  1035. RTLLIB_ASSOCIATING_AUTHENTICATING,
  1036. /* the association procedure has successfully authenticated
  1037. * and is sending association request
  1038. */
  1039. RTLLIB_ASSOCIATING_AUTHENTICATED,
  1040. /* the link is ok. the card associated to a BSS or linked
  1041. * to a ibss cell or acting as an AP and creating the bss
  1042. */
  1043. RTLLIB_LINKED,
  1044. /* same as LINKED, but the driver shall apply RX filter
  1045. * rules as we are in NO_LINK mode. As the card is still
  1046. * logically linked, but it is doing a syncro site survey
  1047. * then it will be back to LINKED state.
  1048. */
  1049. RTLLIB_LINKED_SCANNING,
  1050. };
  1051. #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
  1052. #define DEFAULT_FTS 2346
  1053. #define CFG_RTLLIB_RESERVE_FCS (1<<0)
  1054. #define CFG_RTLLIB_COMPUTE_FCS (1<<1)
  1055. struct tx_pending {
  1056. int frag;
  1057. struct rtllib_txb *txb;
  1058. };
  1059. struct bandwidth_autoswitch {
  1060. long threshold_20Mhzto40Mhz;
  1061. long threshold_40Mhzto20Mhz;
  1062. bool bforced_tx20Mhz;
  1063. bool bautoswitch_enable;
  1064. };
  1065. #define REORDER_WIN_SIZE 128
  1066. #define REORDER_ENTRY_NUM 128
  1067. struct rx_reorder_entry {
  1068. struct list_head List;
  1069. u16 SeqNum;
  1070. struct rtllib_rxb *prxb;
  1071. };
  1072. enum fsync_state {
  1073. Default_Fsync,
  1074. HW_Fsync,
  1075. SW_Fsync
  1076. };
  1077. enum rt_ps_mode {
  1078. eActive,
  1079. eMaxPs,
  1080. eFastPs,
  1081. eAutoPs,
  1082. };
  1083. enum ips_callback_function {
  1084. IPS_CALLBACK_NONE = 0,
  1085. IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
  1086. IPS_CALLBACK_JOIN_REQUEST = 2,
  1087. };
  1088. enum rt_rf_power_state {
  1089. eRfOn,
  1090. eRfSleep,
  1091. eRfOff
  1092. };
  1093. struct rt_pwr_save_ctrl {
  1094. bool bInactivePs;
  1095. bool bIPSModeBackup;
  1096. bool bSwRfProcessing;
  1097. enum rt_rf_power_state eInactivePowerState;
  1098. enum ips_callback_function ReturnPoint;
  1099. bool bLeisurePs;
  1100. u8 LpsIdleCount;
  1101. u8 RegMaxLPSAwakeIntvl;
  1102. u8 LPSAwakeIntvl;
  1103. u32 CurPsLevel;
  1104. u32 RegRfPsLevel;
  1105. bool bFwCtrlLPS;
  1106. };
  1107. #define RT_RF_CHANGE_SOURCE u32
  1108. #define RF_CHANGE_BY_SW BIT31
  1109. #define RF_CHANGE_BY_HW BIT30
  1110. #define RF_CHANGE_BY_PS BIT29
  1111. #define RF_CHANGE_BY_IPS BIT28
  1112. #define RF_CHANGE_BY_INIT 0
  1113. enum country_code_type {
  1114. COUNTRY_CODE_FCC = 0,
  1115. COUNTRY_CODE_IC = 1,
  1116. COUNTRY_CODE_ETSI = 2,
  1117. COUNTRY_CODE_SPAIN = 3,
  1118. COUNTRY_CODE_FRANCE = 4,
  1119. COUNTRY_CODE_MKK = 5,
  1120. COUNTRY_CODE_MKK1 = 6,
  1121. COUNTRY_CODE_ISRAEL = 7,
  1122. COUNTRY_CODE_TELEC = 8,
  1123. COUNTRY_CODE_MIC = 9,
  1124. COUNTRY_CODE_GLOBAL_DOMAIN = 10,
  1125. COUNTRY_CODE_WORLD_WIDE_13 = 11,
  1126. COUNTRY_CODE_TELEC_NETGEAR = 12,
  1127. COUNTRY_CODE_MAX
  1128. };
  1129. enum scan_op_backup_opt {
  1130. SCAN_OPT_BACKUP = 0,
  1131. SCAN_OPT_RESTORE,
  1132. SCAN_OPT_MAX
  1133. };
  1134. enum fw_cmd_io_type {
  1135. FW_CMD_DIG_ENABLE = 0,
  1136. FW_CMD_DIG_DISABLE = 1,
  1137. FW_CMD_DIG_HALT = 2,
  1138. FW_CMD_DIG_RESUME = 3,
  1139. FW_CMD_HIGH_PWR_ENABLE = 4,
  1140. FW_CMD_HIGH_PWR_DISABLE = 5,
  1141. FW_CMD_RA_RESET = 6,
  1142. FW_CMD_RA_ACTIVE = 7,
  1143. FW_CMD_RA_REFRESH_N = 8,
  1144. FW_CMD_RA_REFRESH_BG = 9,
  1145. FW_CMD_RA_INIT = 10,
  1146. FW_CMD_IQK_ENABLE = 11,
  1147. FW_CMD_TXPWR_TRACK_ENABLE = 12,
  1148. FW_CMD_TXPWR_TRACK_DISABLE = 13,
  1149. FW_CMD_TXPWR_TRACK_THERMAL = 14,
  1150. FW_CMD_PAUSE_DM_BY_SCAN = 15,
  1151. FW_CMD_RESUME_DM_BY_SCAN = 16,
  1152. FW_CMD_RA_REFRESH_N_COMB = 17,
  1153. FW_CMD_RA_REFRESH_BG_COMB = 18,
  1154. FW_CMD_ANTENNA_SW_ENABLE = 19,
  1155. FW_CMD_ANTENNA_SW_DISABLE = 20,
  1156. FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21,
  1157. FW_CMD_LPS_ENTER = 22,
  1158. FW_CMD_LPS_LEAVE = 23,
  1159. };
  1160. #define RT_MAX_LD_SLOT_NUM 10
  1161. struct rt_link_detect {
  1162. u32 NumRecvBcnInPeriod;
  1163. u32 NumRecvDataInPeriod;
  1164. u32 RxBcnNum[RT_MAX_LD_SLOT_NUM];
  1165. u32 RxDataNum[RT_MAX_LD_SLOT_NUM];
  1166. u16 SlotNum;
  1167. u16 SlotIndex;
  1168. u32 NumTxOkInPeriod;
  1169. u32 NumRxOkInPeriod;
  1170. u32 NumRxUnicastOkInPeriod;
  1171. bool bBusyTraffic;
  1172. bool bHigherBusyTraffic;
  1173. bool bHigherBusyRxTraffic;
  1174. };
  1175. struct sw_cam_table {
  1176. u8 macaddr[ETH_ALEN];
  1177. bool bused;
  1178. u8 key_buf[16];
  1179. u16 key_type;
  1180. u8 useDK;
  1181. u8 key_index;
  1182. };
  1183. #define TOTAL_CAM_ENTRY 32
  1184. struct rate_adaptive {
  1185. u8 rate_adaptive_disabled;
  1186. u8 ratr_state;
  1187. u16 reserve;
  1188. u32 high_rssi_thresh_for_ra;
  1189. u32 high2low_rssi_thresh_for_ra;
  1190. u8 low2high_rssi_thresh_for_ra40M;
  1191. u32 low_rssi_thresh_for_ra40M;
  1192. u8 low2high_rssi_thresh_for_ra20M;
  1193. u32 low_rssi_thresh_for_ra20M;
  1194. u32 upper_rssi_threshold_ratr;
  1195. u32 middle_rssi_threshold_ratr;
  1196. u32 low_rssi_threshold_ratr;
  1197. u32 low_rssi_threshold_ratr_40M;
  1198. u32 low_rssi_threshold_ratr_20M;
  1199. u8 ping_rssi_enable;
  1200. u32 ping_rssi_ratr;
  1201. u32 ping_rssi_thresh_for_ra;
  1202. u32 last_ratr;
  1203. u8 PreRATRState;
  1204. };
  1205. #define NUM_PMKID_CACHE 16
  1206. struct rt_pmkid_list {
  1207. u8 Bssid[ETH_ALEN];
  1208. u8 PMKID[16];
  1209. u8 SsidBuf[33];
  1210. u8 bUsed;
  1211. };
  1212. struct rt_intel_promisc_mode {
  1213. bool bPromiscuousOn;
  1214. bool bFilterSourceStationFrame;
  1215. };
  1216. /*************** DRIVER STATUS *****/
  1217. #define STATUS_SCANNING 0
  1218. /*************** DRIVER STATUS *****/
  1219. enum {
  1220. LPS_IS_WAKE = 0,
  1221. LPS_IS_SLEEP = 1,
  1222. LPS_WAIT_NULL_DATA_SEND = 2,
  1223. };
  1224. struct rtllib_device {
  1225. struct pci_dev *pdev;
  1226. struct net_device *dev;
  1227. struct rtllib_security sec;
  1228. bool disable_mgnt_queue;
  1229. unsigned long status;
  1230. u8 CntAfterLink;
  1231. enum rt_op_mode OpMode;
  1232. /* The last AssocReq/Resp IEs */
  1233. u8 *assocreq_ies, *assocresp_ies;
  1234. size_t assocreq_ies_len, assocresp_ies_len;
  1235. bool bForcedBgMode;
  1236. u8 RF_Type;
  1237. u8 hwsec_active;
  1238. bool is_silent_reset;
  1239. bool is_roaming;
  1240. bool ieee_up;
  1241. bool cannot_notify;
  1242. bool bSupportRemoteWakeUp;
  1243. bool actscanning;
  1244. bool FirstIe_InScan;
  1245. bool be_scan_inprogress;
  1246. bool beinretry;
  1247. enum rt_rf_power_state eRFPowerState;
  1248. RT_RF_CHANGE_SOURCE RfOffReason;
  1249. bool is_set_key;
  1250. bool wx_set_enc;
  1251. struct rt_hi_throughput *pHTInfo;
  1252. spinlock_t reorder_spinlock;
  1253. u8 Regdot11HTOperationalRateSet[16];
  1254. u8 Regdot11TxHTOperationalRateSet[16];
  1255. u8 dot11HTOperationalRateSet[16];
  1256. u8 RegHTSuppRateSet[16];
  1257. u8 HTCurrentOperaRate;
  1258. u8 HTHighestOperaRate;
  1259. u8 bTxDisableRateFallBack;
  1260. u8 bTxUseDriverAssingedRate;
  1261. u8 bTxEnableFwCalcDur;
  1262. atomic_t atm_swbw;
  1263. struct list_head Tx_TS_Admit_List;
  1264. struct list_head Tx_TS_Pending_List;
  1265. struct list_head Tx_TS_Unused_List;
  1266. struct tx_ts_record TxTsRecord[TOTAL_TS_NUM];
  1267. struct list_head Rx_TS_Admit_List;
  1268. struct list_head Rx_TS_Pending_List;
  1269. struct list_head Rx_TS_Unused_List;
  1270. struct rx_ts_record RxTsRecord[TOTAL_TS_NUM];
  1271. struct rx_reorder_entry RxReorderEntry[128];
  1272. struct list_head RxReorder_Unused_List;
  1273. /* Bookkeeping structures */
  1274. struct net_device_stats stats;
  1275. struct rtllib_softmac_stats softmac_stats;
  1276. /* Probe / Beacon management */
  1277. struct list_head network_free_list;
  1278. struct list_head network_list;
  1279. struct rtllib_network *networks;
  1280. int scans;
  1281. int scan_age;
  1282. int iw_mode; /* operating mode (IW_MODE_*) */
  1283. bool bNetPromiscuousMode;
  1284. struct rt_intel_promisc_mode IntelPromiscuousModeInfo;
  1285. spinlock_t lock;
  1286. spinlock_t wpax_suitlist_lock;
  1287. int tx_headroom; /* Set to size of any additional room needed at front
  1288. * of allocated Tx SKBs
  1289. */
  1290. u32 config;
  1291. /* WEP and other encryption related settings at the device level */
  1292. int open_wep; /* Set to 1 to allow unencrypted frames */
  1293. int auth_mode;
  1294. int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
  1295. * WEP key changes
  1296. */
  1297. /* If the host performs {en,de}cryption, then set to 1 */
  1298. int host_encrypt;
  1299. int host_decrypt;
  1300. int ieee802_1x; /* is IEEE 802.1X used */
  1301. /* WPA data */
  1302. bool bHalfWirelessN24GMode;
  1303. int wpa_enabled;
  1304. int drop_unencrypted;
  1305. int tkip_countermeasures;
  1306. int privacy_invoked;
  1307. size_t wpa_ie_len;
  1308. u8 *wpa_ie;
  1309. size_t wps_ie_len;
  1310. u8 *wps_ie;
  1311. u8 ap_mac_addr[ETH_ALEN];
  1312. u16 pairwise_key_type;
  1313. u16 group_key_type;
  1314. struct lib80211_crypt_info crypt_info;
  1315. struct sw_cam_table swcamtable[TOTAL_CAM_ENTRY];
  1316. struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
  1317. /* Fragmentation structures */
  1318. struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN];
  1319. unsigned int frag_next_idx[17];
  1320. u16 fts; /* Fragmentation Threshold */
  1321. #define DEFAULT_RTS_THRESHOLD 2346U
  1322. #define MIN_RTS_THRESHOLD 1
  1323. #define MAX_RTS_THRESHOLD 2346U
  1324. u16 rts; /* RTS threshold */
  1325. /* Association info */
  1326. u8 bssid[ETH_ALEN];
  1327. /* This stores infos for the current network.
  1328. * Either the network we are associated in INFRASTRUCTURE
  1329. * or the network that we are creating in MASTER mode.
  1330. * ad-hoc is a mixture ;-).
  1331. * Note that in infrastructure mode, even when not associated,
  1332. * fields bssid and essid may be valid (if wpa_set and essid_set
  1333. * are true) as thy carry the value set by the user via iwconfig
  1334. */
  1335. struct rtllib_network current_network;
  1336. enum rtllib_state state;
  1337. int short_slot;
  1338. int mode; /* A, B, G */
  1339. int modulation; /* CCK, OFDM */
  1340. /* used for forcing the ibss workqueue to terminate
  1341. * without wait for the syncro scan to terminate
  1342. */
  1343. short sync_scan_hurryup;
  1344. u16 scan_watch_dog;
  1345. /* map of allowed channels. 0 is dummy */
  1346. void *pDot11dInfo;
  1347. bool bGlobalDomain;
  1348. u8 active_channel_map[MAX_CHANNEL_NUMBER+1];
  1349. u8 IbssStartChnl;
  1350. u8 ibss_maxjoin_chal;
  1351. int rate; /* current rate */
  1352. int basic_rate;
  1353. short active_scan;
  1354. /* this contains flags for selectively enable softmac support */
  1355. u16 softmac_features;
  1356. /* if the sequence control field is not filled by HW */
  1357. u16 seq_ctrl[5];
  1358. /* association procedure transaction sequence number */
  1359. u16 associate_seq;
  1360. /* AID for RTXed association responses */
  1361. u16 assoc_id;
  1362. /* power save mode related*/
  1363. u8 ack_tx_to_ieee;
  1364. short ps;
  1365. short sta_sleep;
  1366. int ps_timeout;
  1367. int ps_period;
  1368. struct tasklet_struct ps_task;
  1369. u64 ps_time;
  1370. bool polling;
  1371. short raw_tx;
  1372. /* used if IEEE_SOFTMAC_TX_QUEUE is set */
  1373. short queue_stop;
  1374. short scanning_continue;
  1375. short proto_started;
  1376. short proto_stoppping;
  1377. struct mutex wx_mutex;
  1378. struct mutex scan_mutex;
  1379. struct mutex ips_mutex;
  1380. spinlock_t mgmt_tx_lock;
  1381. spinlock_t beacon_lock;
  1382. short beacon_txing;
  1383. short wap_set;
  1384. short ssid_set;
  1385. /* set on initialization */
  1386. unsigned int wmm_acm;
  1387. /* for discarding duplicated packets in IBSS */
  1388. struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
  1389. /* for discarding duplicated packets in BSS */
  1390. u16 last_rxseq_num[17]; /* rx seq previous per-tid */
  1391. u16 last_rxfrag_num[17];/* tx frag previous per-tid */
  1392. unsigned long last_packet_time[17];
  1393. /* for PS mode */
  1394. unsigned long last_rx_ps_time;
  1395. bool bAwakePktSent;
  1396. u8 LPSDelayCnt;
  1397. /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
  1398. struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
  1399. int mgmt_queue_head;
  1400. int mgmt_queue_tail;
  1401. u8 AsocRetryCount;
  1402. struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
  1403. struct sk_buff_head skb_aggQ[MAX_QUEUE_SIZE];
  1404. bool bdynamic_txpower_enable;
  1405. bool bCTSToSelfEnable;
  1406. u32 fsync_time_interval;
  1407. u32 fsync_rate_bitmap;
  1408. u8 fsync_rssi_threshold;
  1409. bool bfsync_enable;
  1410. u8 fsync_multiple_timeinterval;
  1411. u32 fsync_firstdiff_ratethreshold;
  1412. u32 fsync_seconddiff_ratethreshold;
  1413. enum fsync_state fsync_state;
  1414. bool bis_any_nonbepkts;
  1415. struct bandwidth_autoswitch bandwidth_auto_switch;
  1416. bool FwRWRF;
  1417. struct rt_link_detect LinkDetectInfo;
  1418. bool bIsAggregateFrame;
  1419. struct rt_pwr_save_ctrl PowerSaveControl;
  1420. /* used if IEEE_SOFTMAC_TX_QUEUE is set */
  1421. struct tx_pending tx_pending;
  1422. /* used if IEEE_SOFTMAC_ASSOCIATE is set */
  1423. struct timer_list associate_timer;
  1424. /* used if IEEE_SOFTMAC_BEACONS is set */
  1425. struct timer_list beacon_timer;
  1426. u8 need_sw_enc;
  1427. struct work_struct associate_complete_wq;
  1428. struct work_struct ips_leave_wq;
  1429. struct delayed_work associate_procedure_wq;
  1430. struct delayed_work softmac_scan_wq;
  1431. struct delayed_work associate_retry_wq;
  1432. struct delayed_work start_ibss_wq;
  1433. struct delayed_work hw_wakeup_wq;
  1434. struct delayed_work hw_sleep_wq;
  1435. struct delayed_work link_change_wq;
  1436. struct work_struct wx_sync_scan_wq;
  1437. union {
  1438. struct rtllib_rxb *RfdArray[REORDER_WIN_SIZE];
  1439. struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
  1440. struct rtllib_rxb *prxbIndicateArray[REORDER_WIN_SIZE];
  1441. struct {
  1442. struct sw_chnl_cmd PreCommonCmd[MAX_PRECMD_CNT];
  1443. struct sw_chnl_cmd PostCommonCmd[MAX_POSTCMD_CNT];
  1444. struct sw_chnl_cmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
  1445. };
  1446. };
  1447. /* Callback functions */
  1448. void (*set_security)(struct net_device *dev,
  1449. struct rtllib_security *sec);
  1450. /* Used to TX data frame by using txb structs.
  1451. * this is not used if in the softmac_features
  1452. * is set the flag IEEE_SOFTMAC_TX_QUEUE
  1453. */
  1454. int (*hard_start_xmit)(struct rtllib_txb *txb,
  1455. struct net_device *dev);
  1456. int (*reset_port)(struct net_device *dev);
  1457. /* Softmac-generated frames (management) are TXed via this
  1458. * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
  1459. * not set. As some cards may have different HW queues that
  1460. * one might want to use for data and management frames
  1461. * the option to have two callbacks might be useful.
  1462. * This function can't sleep.
  1463. */
  1464. int (*softmac_hard_start_xmit)(struct sk_buff *skb,
  1465. struct net_device *dev);
  1466. /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
  1467. * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
  1468. * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
  1469. * then also management frames are sent via this callback.
  1470. * This function can't sleep.
  1471. */
  1472. void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
  1473. struct net_device *dev, int rate);
  1474. /* stops the HW queue for DATA frames. Useful to avoid
  1475. * waste time to TX data frame when we are reassociating
  1476. * This function can sleep.
  1477. */
  1478. void (*data_hard_stop)(struct net_device *dev);
  1479. /* OK this is complementing to data_poll_hard_stop */
  1480. void (*data_hard_resume)(struct net_device *dev);
  1481. /* ask to the driver to retune the radio.
  1482. * This function can sleep. the driver should ensure
  1483. * the radio has been switched before return.
  1484. */
  1485. void (*set_chan)(struct net_device *dev, short ch);
  1486. void (*rtllib_start_hw_scan)(struct net_device *dev);
  1487. void (*rtllib_stop_hw_scan)(struct net_device *dev);
  1488. /* indicate the driver that the link state is changed
  1489. * for example it may indicate the card is associated now.
  1490. * Driver might be interested in this to apply RX filter
  1491. * rules or simply light the LINK led
  1492. */
  1493. void (*link_change)(struct net_device *dev);
  1494. /* these two function indicates to the HW when to start
  1495. * and stop to send beacons. This is used when the
  1496. * IEEE_SOFTMAC_BEACONS is not set. For now the
  1497. * stop_send_bacons is NOT guaranteed to be called only
  1498. * after start_send_beacons.
  1499. */
  1500. void (*start_send_beacons)(struct net_device *dev);
  1501. void (*stop_send_beacons)(struct net_device *dev);
  1502. /* power save mode related */
  1503. void (*sta_wake_up)(struct net_device *dev);
  1504. void (*enter_sleep_state)(struct net_device *dev, u64 time);
  1505. short (*ps_is_queue_empty)(struct net_device *dev);
  1506. int (*handle_beacon)(struct net_device *dev,
  1507. struct rtllib_beacon *beacon,
  1508. struct rtllib_network *network);
  1509. int (*handle_assoc_response)(struct net_device *dev,
  1510. struct rtllib_assoc_response_frame *resp,
  1511. struct rtllib_network *network);
  1512. /* check whether Tx hw resource available */
  1513. short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
  1514. void (*SetBWModeHandler)(struct net_device *dev,
  1515. enum ht_channel_width Bandwidth,
  1516. enum ht_extchnl_offset Offset);
  1517. bool (*GetNmodeSupportBySecCfg)(struct net_device *dev);
  1518. void (*SetWirelessMode)(struct net_device *dev, u8 wireless_mode);
  1519. bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device *dev);
  1520. u8 (*rtllib_ap_sec_type)(struct rtllib_device *ieee);
  1521. void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
  1522. bool (*SetFwCmdHandler)(struct net_device *dev,
  1523. enum fw_cmd_io_type FwCmdIO);
  1524. void (*UpdateBeaconInterruptHandler)(struct net_device *dev,
  1525. bool start);
  1526. void (*ScanOperationBackupHandler)(struct net_device *dev,
  1527. u8 Operation);
  1528. void (*LedControlHandler)(struct net_device *dev,
  1529. enum led_ctl_mode LedAction);
  1530. void (*SetHwRegHandler)(struct net_device *dev, u8 variable, u8 *val);
  1531. void (*AllowAllDestAddrHandler)(struct net_device *dev,
  1532. bool bAllowAllDA, bool WriteIntoReg);
  1533. void (*rtllib_ips_leave_wq)(struct net_device *dev);
  1534. void (*rtllib_ips_leave)(struct net_device *dev);
  1535. void (*LeisurePSLeave)(struct net_device *dev);
  1536. /* This must be the last item so that it points to the data
  1537. * allocated beyond this structure by alloc_rtllib
  1538. */
  1539. u8 priv[0];
  1540. };
  1541. #define IEEE_A (1<<0)
  1542. #define IEEE_B (1<<1)
  1543. #define IEEE_G (1<<2)
  1544. #define IEEE_N_24G (1<<4)
  1545. #define IEEE_N_5G (1<<5)
  1546. #define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G)
  1547. /* Generate a 802.11 header */
  1548. /* Uses the channel change callback directly
  1549. * instead of [start/stop] scan callbacks
  1550. */
  1551. #define IEEE_SOFTMAC_SCAN (1<<2)
  1552. /* Perform authentication and association handshake */
  1553. #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
  1554. /* Generate probe requests */
  1555. #define IEEE_SOFTMAC_PROBERQ (1<<4)
  1556. /* Generate response to probe requests */
  1557. #define IEEE_SOFTMAC_PROBERS (1<<5)
  1558. /* The ieee802.11 stack will manage the netif queue
  1559. * wake/stop for the driver, taking care of 802.11
  1560. * fragmentation. See softmac.c for details.
  1561. */
  1562. #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
  1563. /* Uses only the softmac_data_hard_start_xmit
  1564. * even for TX management frames.
  1565. */
  1566. #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
  1567. /* Generate beacons. The stack will enqueue beacons
  1568. * to the card
  1569. */
  1570. #define IEEE_SOFTMAC_BEACONS (1<<6)
  1571. static inline void *rtllib_priv(struct net_device *dev)
  1572. {
  1573. return ((struct rtllib_device *)netdev_priv(dev))->priv;
  1574. }
  1575. static inline int rtllib_is_empty_essid(const char *essid, int essid_len)
  1576. {
  1577. /* Single white space is for Linksys APs */
  1578. if (essid_len == 1 && essid[0] == ' ')
  1579. return 1;
  1580. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  1581. while (essid_len) {
  1582. essid_len--;
  1583. if (essid[essid_len] != '\0')
  1584. return 0;
  1585. }
  1586. return 1;
  1587. }
  1588. static inline int rtllib_get_hdrlen(u16 fc)
  1589. {
  1590. int hdrlen = RTLLIB_3ADDR_LEN;
  1591. switch (WLAN_FC_GET_TYPE(fc)) {
  1592. case RTLLIB_FTYPE_DATA:
  1593. if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS))
  1594. hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */
  1595. if (RTLLIB_QOS_HAS_SEQ(fc))
  1596. hdrlen += 2; /* QOS ctrl*/
  1597. break;
  1598. case RTLLIB_FTYPE_CTL:
  1599. switch (WLAN_FC_GET_STYPE(fc)) {
  1600. case RTLLIB_STYPE_CTS:
  1601. case RTLLIB_STYPE_ACK:
  1602. hdrlen = RTLLIB_1ADDR_LEN;
  1603. break;
  1604. default:
  1605. hdrlen = RTLLIB_2ADDR_LEN;
  1606. break;
  1607. }
  1608. break;
  1609. }
  1610. return hdrlen;
  1611. }
  1612. static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr)
  1613. {
  1614. switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
  1615. case RTLLIB_1ADDR_LEN:
  1616. return ((struct rtllib_hdr_1addr *)hdr)->payload;
  1617. case RTLLIB_2ADDR_LEN:
  1618. return ((struct rtllib_hdr_2addr *)hdr)->payload;
  1619. case RTLLIB_3ADDR_LEN:
  1620. return ((struct rtllib_hdr_3addr *)hdr)->payload;
  1621. case RTLLIB_4ADDR_LEN:
  1622. return ((struct rtllib_hdr_4addr *)hdr)->payload;
  1623. }
  1624. return NULL;
  1625. }
  1626. static inline int rtllib_is_ofdm_rate(u8 rate)
  1627. {
  1628. switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
  1629. case RTLLIB_OFDM_RATE_6MB:
  1630. case RTLLIB_OFDM_RATE_9MB:
  1631. case RTLLIB_OFDM_RATE_12MB:
  1632. case RTLLIB_OFDM_RATE_18MB:
  1633. case RTLLIB_OFDM_RATE_24MB:
  1634. case RTLLIB_OFDM_RATE_36MB:
  1635. case RTLLIB_OFDM_RATE_48MB:
  1636. case RTLLIB_OFDM_RATE_54MB:
  1637. return 1;
  1638. }
  1639. return 0;
  1640. }
  1641. static inline int rtllib_is_cck_rate(u8 rate)
  1642. {
  1643. switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
  1644. case RTLLIB_CCK_RATE_1MB:
  1645. case RTLLIB_CCK_RATE_2MB:
  1646. case RTLLIB_CCK_RATE_5MB:
  1647. case RTLLIB_CCK_RATE_11MB:
  1648. return 1;
  1649. }
  1650. return 0;
  1651. }
  1652. /* rtllib.c */
  1653. void free_rtllib(struct net_device *dev);
  1654. struct net_device *alloc_rtllib(int sizeof_priv);
  1655. /* rtllib_tx.c */
  1656. int rtllib_encrypt_fragment(
  1657. struct rtllib_device *ieee,
  1658. struct sk_buff *frag,
  1659. int hdr_len);
  1660. int rtllib_xmit(struct sk_buff *skb, struct net_device *dev);
  1661. void rtllib_txb_free(struct rtllib_txb *);
  1662. /* rtllib_rx.c */
  1663. int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
  1664. struct rtllib_rx_stats *rx_stats);
  1665. void rtllib_rx_probe_rq(struct rtllib_device *ieee,
  1666. struct sk_buff *skb);
  1667. int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel);
  1668. /* rtllib_wx.c */
  1669. int rtllib_wx_get_scan(struct rtllib_device *ieee,
  1670. struct iw_request_info *info,
  1671. union iwreq_data *wrqu, char *key);
  1672. int rtllib_wx_set_encode(struct rtllib_device *ieee,
  1673. struct iw_request_info *info,
  1674. union iwreq_data *wrqu, char *key);
  1675. int rtllib_wx_get_encode(struct rtllib_device *ieee,
  1676. struct iw_request_info *info,
  1677. union iwreq_data *wrqu, char *key);
  1678. int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
  1679. struct iw_request_info *info,
  1680. union iwreq_data *wrqu, char *extra);
  1681. int rtllib_wx_set_auth(struct rtllib_device *ieee,
  1682. struct iw_request_info *info,
  1683. struct iw_param *data, char *extra);
  1684. int rtllib_wx_set_mlme(struct rtllib_device *ieee,
  1685. struct iw_request_info *info,
  1686. union iwreq_data *wrqu, char *extra);
  1687. int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
  1688. /* rtllib_softmac.c */
  1689. int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb,
  1690. struct rtllib_rx_stats *rx_stats, u16 type,
  1691. u16 stype);
  1692. void rtllib_softmac_new_net(struct rtllib_device *ieee,
  1693. struct rtllib_network *net);
  1694. void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
  1695. void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
  1696. void rtllib_stop_send_beacons(struct rtllib_device *ieee);
  1697. void notify_wx_assoc_event(struct rtllib_device *ieee);
  1698. void rtllib_start_ibss(struct rtllib_device *ieee);
  1699. void rtllib_softmac_init(struct rtllib_device *ieee);
  1700. void rtllib_softmac_free(struct rtllib_device *ieee);
  1701. void rtllib_disassociate(struct rtllib_device *ieee);
  1702. void rtllib_stop_scan(struct rtllib_device *ieee);
  1703. bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
  1704. void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
  1705. void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
  1706. void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr);
  1707. void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
  1708. void rtllib_start_protocol(struct rtllib_device *ieee);
  1709. void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
  1710. void rtllib_EnableNetMonitorMode(struct net_device *dev, bool bInitState);
  1711. void rtllib_DisableNetMonitorMode(struct net_device *dev, bool bInitState);
  1712. void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, bool bInitState);
  1713. void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
  1714. bool bInitState);
  1715. void rtllib_softmac_stop_protocol(struct rtllib_device *ieee,
  1716. u8 mesh_flag, u8 shutdown);
  1717. void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag);
  1718. void rtllib_reset_queue(struct rtllib_device *ieee);
  1719. void rtllib_wake_all_queues(struct rtllib_device *ieee);
  1720. void rtllib_stop_all_queues(struct rtllib_device *ieee);
  1721. struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
  1722. void rtllib_start_send_beacons(struct rtllib_device *ieee);
  1723. void rtllib_stop_send_beacons(struct rtllib_device *ieee);
  1724. void notify_wx_assoc_event(struct rtllib_device *ieee);
  1725. void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
  1726. void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee);
  1727. u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
  1728. /* rtllib_softmac_wx.c */
  1729. int rtllib_wx_get_wap(struct rtllib_device *ieee, struct iw_request_info *info,
  1730. union iwreq_data *wrqu, char *ext);
  1731. int rtllib_wx_set_wap(struct rtllib_device *ieee, struct iw_request_info *info,
  1732. union iwreq_data *awrq, char *extra);
  1733. int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a,
  1734. union iwreq_data *wrqu, char *b);
  1735. int rtllib_wx_set_rate(struct rtllib_device *ieee, struct iw_request_info *info,
  1736. union iwreq_data *wrqu, char *extra);
  1737. int rtllib_wx_get_rate(struct rtllib_device *ieee, struct iw_request_info *info,
  1738. union iwreq_data *wrqu, char *extra);
  1739. int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a,
  1740. union iwreq_data *wrqu, char *b);
  1741. int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a,
  1742. union iwreq_data *wrqu, char *b);
  1743. int rtllib_wx_set_essid(struct rtllib_device *ieee, struct iw_request_info *a,
  1744. union iwreq_data *wrqu, char *extra);
  1745. int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a,
  1746. union iwreq_data *wrqu, char *b);
  1747. int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
  1748. union iwreq_data *wrqu, char *b);
  1749. int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a,
  1750. union iwreq_data *wrqu, char *b);
  1751. void rtllib_wx_sync_scan_wq(void *data);
  1752. int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
  1753. struct iw_request_info *info,
  1754. union iwreq_data *wrqu, char *extra);
  1755. int rtllib_wx_get_name(struct rtllib_device *ieee, struct iw_request_info *info,
  1756. union iwreq_data *wrqu, char *extra);
  1757. int rtllib_wx_set_power(struct rtllib_device *ieee,
  1758. struct iw_request_info *info,
  1759. union iwreq_data *wrqu, char *extra);
  1760. int rtllib_wx_get_power(struct rtllib_device *ieee,
  1761. struct iw_request_info *info,
  1762. union iwreq_data *wrqu, char *extra);
  1763. int rtllib_wx_set_rts(struct rtllib_device *ieee, struct iw_request_info *info,
  1764. union iwreq_data *wrqu, char *extra);
  1765. int rtllib_wx_get_rts(struct rtllib_device *ieee, struct iw_request_info *info,
  1766. union iwreq_data *wrqu, char *extra);
  1767. #define MAX_RECEIVE_BUFFER_SIZE 9100
  1768. void HTSetConnectBwMode(struct rtllib_device *ieee,
  1769. enum ht_channel_width Bandwidth,
  1770. enum ht_extchnl_offset Offset);
  1771. void HTUpdateDefaultSetting(struct rtllib_device *ieee);
  1772. void HTConstructCapabilityElement(struct rtllib_device *ieee,
  1773. u8 *posHTCap, u8 *len,
  1774. u8 isEncrypt, bool bAssoc);
  1775. void HTConstructInfoElement(struct rtllib_device *ieee,
  1776. u8 *posHTInfo, u8 *len, u8 isEncrypt);
  1777. void HTConstructRT2RTAggElement(struct rtllib_device *ieee,
  1778. u8 *posRT2RTAgg, u8 *len);
  1779. void HTOnAssocRsp(struct rtllib_device *ieee);
  1780. void HTInitializeHTInfo(struct rtllib_device *ieee);
  1781. void HTInitializeBssDesc(struct bss_ht *pBssHT);
  1782. void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
  1783. struct rtllib_network *pNetwork);
  1784. void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
  1785. struct rtllib_network *pNetwork);
  1786. u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
  1787. u8 *pMCSFilter);
  1788. extern u8 MCS_FILTER_ALL[];
  1789. extern u16 MCS_DATA_RATE[2][2][77];
  1790. u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame);
  1791. void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo);
  1792. bool IsHTHalfNmodeAPs(struct rtllib_device *ieee);
  1793. u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate);
  1794. int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb);
  1795. int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb);
  1796. int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb);
  1797. void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS,
  1798. u8 Policy, u8 bOverwritePending);
  1799. void TsInitDelBA(struct rtllib_device *ieee,
  1800. struct ts_common_info *pTsCommonInfo,
  1801. enum tr_select TxRxSelect);
  1802. void BaSetupTimeOut(struct timer_list *t);
  1803. void TxBaInactTimeout(struct timer_list *t);
  1804. void RxBaInactTimeout(struct timer_list *t);
  1805. void ResetBaEntry(struct ba_record *pBA);
  1806. bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS, u8 *Addr,
  1807. u8 TID, enum tr_select TxRxSelect, bool bAddNewTs);
  1808. void TSInitialize(struct rtllib_device *ieee);
  1809. void TsStartAddBaProcess(struct rtllib_device *ieee,
  1810. struct tx_ts_record *pTxTS);
  1811. void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr);
  1812. void RemoveAllTS(struct rtllib_device *ieee);
  1813. extern const long rtllib_wlan_frequencies[];
  1814. static inline const char *escape_essid(const char *essid, u8 essid_len)
  1815. {
  1816. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  1817. if (rtllib_is_empty_essid(essid, essid_len)) {
  1818. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  1819. return escaped;
  1820. }
  1821. snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid);
  1822. return escaped;
  1823. }
  1824. /* fun with the built-in rtllib stack... */
  1825. bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn);
  1826. /* For the function is more related to hardware setting, it's better to use the
  1827. * ieee handler to refer to it.
  1828. */
  1829. void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
  1830. struct rx_ts_record *pTS);
  1831. int rtllib_parse_info_param(struct rtllib_device *ieee,
  1832. struct rtllib_info_element *info_element,
  1833. u16 length,
  1834. struct rtllib_network *network,
  1835. struct rtllib_rx_stats *stats);
  1836. void rtllib_indicate_packets(struct rtllib_device *ieee,
  1837. struct rtllib_rxb **prxbIndicateArray, u8 index);
  1838. void HTUseDefaultSetting(struct rtllib_device *ieee);
  1839. #define RT_ASOC_RETRY_LIMIT 5
  1840. u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
  1841. #endif /* RTLLIB_H */