dpc.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * File: dpc.c
  20. *
  21. * Purpose: handle dpc rx functions
  22. *
  23. * Author: Lyndon Chen
  24. *
  25. * Date: May 20, 2003
  26. *
  27. * Functions:
  28. * device_receive_frame - Rcv 802.11 frame function
  29. * s_bAPModeRxCtl- AP Rcv frame filer Ctl.
  30. * s_bAPModeRxData- AP Rcv data frame handle
  31. * s_bHandleRxEncryption- Rcv decrypted data via on-fly
  32. * s_bHostWepRxEncryption- Rcv encrypted data via host
  33. * s_byGetRateIdx- get rate index
  34. * s_vGetDASA- get data offset
  35. * s_vProcessRxMACHeader- Rcv 802.11 and translate to 802.3
  36. *
  37. * Revision History:
  38. *
  39. */
  40. #include "device.h"
  41. #include "rxtx.h"
  42. #include "tether.h"
  43. #include "card.h"
  44. #include "bssdb.h"
  45. #include "mac.h"
  46. #include "baseband.h"
  47. #include "michael.h"
  48. #include "tkip.h"
  49. #include "tcrc.h"
  50. #include "wctl.h"
  51. #include "hostap.h"
  52. #include "rf.h"
  53. #include "iowpa.h"
  54. #include "aes_ccmp.h"
  55. #include "datarate.h"
  56. #include "usbpipe.h"
  57. /*--------------------- Static Definitions -------------------------*/
  58. /*--------------------- Static Classes ----------------------------*/
  59. /*--------------------- Static Variables --------------------------*/
  60. //static int msglevel =MSG_LEVEL_DEBUG;
  61. static int msglevel =MSG_LEVEL_INFO;
  62. const BYTE acbyRxRate[MAX_RATE] =
  63. {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
  64. /*--------------------- Static Functions --------------------------*/
  65. /*--------------------- Static Definitions -------------------------*/
  66. /*--------------------- Static Functions --------------------------*/
  67. static BYTE s_byGetRateIdx(BYTE byRate);
  68. static
  69. void
  70. s_vGetDASA(
  71. PBYTE pbyRxBufferAddr,
  72. unsigned int *pcbHeaderSize,
  73. PSEthernetHeader psEthHeader
  74. );
  75. static
  76. void
  77. s_vProcessRxMACHeader (
  78. PSDevice pDevice,
  79. PBYTE pbyRxBufferAddr,
  80. unsigned int cbPacketSize,
  81. BOOL bIsWEP,
  82. BOOL bExtIV,
  83. unsigned int *pcbHeadSize
  84. );
  85. static BOOL s_bAPModeRxCtl(
  86. PSDevice pDevice,
  87. PBYTE pbyFrame,
  88. signed int iSANodeIndex
  89. );
  90. static BOOL s_bAPModeRxData (
  91. PSDevice pDevice,
  92. struct sk_buff *skb,
  93. unsigned int FrameSize,
  94. unsigned int cbHeaderOffset,
  95. signed int iSANodeIndex,
  96. signed int iDANodeIndex
  97. );
  98. static BOOL s_bHandleRxEncryption(
  99. PSDevice pDevice,
  100. PBYTE pbyFrame,
  101. unsigned int FrameSize,
  102. PBYTE pbyRsr,
  103. PBYTE pbyNewRsr,
  104. PSKeyItem * pKeyOut,
  105. int * pbExtIV,
  106. PWORD pwRxTSC15_0,
  107. PDWORD pdwRxTSC47_16
  108. );
  109. static BOOL s_bHostWepRxEncryption(
  110. PSDevice pDevice,
  111. PBYTE pbyFrame,
  112. unsigned int FrameSize,
  113. PBYTE pbyRsr,
  114. BOOL bOnFly,
  115. PSKeyItem pKey,
  116. PBYTE pbyNewRsr,
  117. int * pbExtIV,
  118. PWORD pwRxTSC15_0,
  119. PDWORD pdwRxTSC47_16
  120. );
  121. /*--------------------- Export Variables --------------------------*/
  122. /*+
  123. *
  124. * Description:
  125. * Translate Rcv 802.11 header to 802.3 header with Rx buffer
  126. *
  127. * Parameters:
  128. * In:
  129. * pDevice
  130. * dwRxBufferAddr - Address of Rcv Buffer
  131. * cbPacketSize - Rcv Packet size
  132. * bIsWEP - If Rcv with WEP
  133. * Out:
  134. * pcbHeaderSize - 802.11 header size
  135. *
  136. * Return Value: None
  137. *
  138. -*/
  139. static
  140. void
  141. s_vProcessRxMACHeader (
  142. PSDevice pDevice,
  143. PBYTE pbyRxBufferAddr,
  144. unsigned int cbPacketSize,
  145. BOOL bIsWEP,
  146. BOOL bExtIV,
  147. unsigned int *pcbHeadSize
  148. )
  149. {
  150. PBYTE pbyRxBuffer;
  151. unsigned int cbHeaderSize = 0;
  152. PWORD pwType;
  153. PS802_11Header pMACHeader;
  154. int ii;
  155. pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
  156. s_vGetDASA((PBYTE)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
  157. if (bIsWEP) {
  158. if (bExtIV) {
  159. // strip IV&ExtIV , add 8 byte
  160. cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8);
  161. } else {
  162. // strip IV , add 4 byte
  163. cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4);
  164. }
  165. }
  166. else {
  167. cbHeaderSize += WLAN_HDR_ADDR3_LEN;
  168. };
  169. pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
  170. if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_Bridgetunnel[0])) {
  171. cbHeaderSize += 6;
  172. } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
  173. cbHeaderSize += 6;
  174. pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
  175. if ((*pwType == cpu_to_le16(ETH_P_IPX)) ||
  176. (*pwType == cpu_to_le16(0xF380))) {
  177. cbHeaderSize -= 8;
  178. pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
  179. if (bIsWEP) {
  180. if (bExtIV) {
  181. *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
  182. } else {
  183. *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
  184. }
  185. }
  186. else {
  187. *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
  188. }
  189. }
  190. }
  191. else {
  192. cbHeaderSize -= 2;
  193. pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
  194. if (bIsWEP) {
  195. if (bExtIV) {
  196. *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
  197. } else {
  198. *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
  199. }
  200. }
  201. else {
  202. *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
  203. }
  204. }
  205. cbHeaderSize -= (ETH_ALEN * 2);
  206. pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
  207. for (ii = 0; ii < ETH_ALEN; ii++)
  208. *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
  209. for (ii = 0; ii < ETH_ALEN; ii++)
  210. *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
  211. *pcbHeadSize = cbHeaderSize;
  212. }
  213. static BYTE s_byGetRateIdx(BYTE byRate)
  214. {
  215. BYTE byRateIdx;
  216. for (byRateIdx = 0; byRateIdx <MAX_RATE ; byRateIdx++) {
  217. if (acbyRxRate[byRateIdx%MAX_RATE] == byRate)
  218. return byRateIdx;
  219. }
  220. return 0;
  221. }
  222. static
  223. void
  224. s_vGetDASA (
  225. PBYTE pbyRxBufferAddr,
  226. unsigned int *pcbHeaderSize,
  227. PSEthernetHeader psEthHeader
  228. )
  229. {
  230. unsigned int cbHeaderSize = 0;
  231. PS802_11Header pMACHeader;
  232. int ii;
  233. pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
  234. if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
  235. if (pMACHeader->wFrameCtl & FC_FROMDS) {
  236. for (ii = 0; ii < ETH_ALEN; ii++) {
  237. psEthHeader->abyDstAddr[ii] =
  238. pMACHeader->abyAddr1[ii];
  239. psEthHeader->abySrcAddr[ii] =
  240. pMACHeader->abyAddr3[ii];
  241. }
  242. } else {
  243. /* IBSS mode */
  244. for (ii = 0; ii < ETH_ALEN; ii++) {
  245. psEthHeader->abyDstAddr[ii] =
  246. pMACHeader->abyAddr1[ii];
  247. psEthHeader->abySrcAddr[ii] =
  248. pMACHeader->abyAddr2[ii];
  249. }
  250. }
  251. } else {
  252. /* Is AP mode.. */
  253. if (pMACHeader->wFrameCtl & FC_FROMDS) {
  254. for (ii = 0; ii < ETH_ALEN; ii++) {
  255. psEthHeader->abyDstAddr[ii] =
  256. pMACHeader->abyAddr3[ii];
  257. psEthHeader->abySrcAddr[ii] =
  258. pMACHeader->abyAddr4[ii];
  259. cbHeaderSize += 6;
  260. }
  261. } else {
  262. for (ii = 0; ii < ETH_ALEN; ii++) {
  263. psEthHeader->abyDstAddr[ii] =
  264. pMACHeader->abyAddr3[ii];
  265. psEthHeader->abySrcAddr[ii] =
  266. pMACHeader->abyAddr2[ii];
  267. }
  268. }
  269. };
  270. *pcbHeaderSize = cbHeaderSize;
  271. }
  272. BOOL
  273. RXbBulkInProcessData (
  274. PSDevice pDevice,
  275. PRCB pRCB,
  276. unsigned long BytesToIndicate
  277. )
  278. {
  279. struct net_device_stats* pStats=&pDevice->stats;
  280. struct sk_buff* skb;
  281. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  282. PSRxMgmtPacket pRxPacket = &(pMgmt->sRxPacket);
  283. PS802_11Header p802_11Header;
  284. PBYTE pbyRsr;
  285. PBYTE pbyNewRsr;
  286. PBYTE pbyRSSI;
  287. PQWORD pqwTSFTime;
  288. PBYTE pbyFrame;
  289. BOOL bDeFragRx = FALSE;
  290. unsigned int cbHeaderOffset;
  291. unsigned int FrameSize;
  292. WORD wEtherType = 0;
  293. signed int iSANodeIndex = -1;
  294. signed int iDANodeIndex = -1;
  295. unsigned int ii;
  296. unsigned int cbIVOffset;
  297. PBYTE pbyRxSts;
  298. PBYTE pbyRxRate;
  299. PBYTE pbySQ;
  300. PBYTE pby3SQ;
  301. unsigned int cbHeaderSize;
  302. PSKeyItem pKey = NULL;
  303. WORD wRxTSC15_0 = 0;
  304. DWORD dwRxTSC47_16 = 0;
  305. SKeyItem STempKey;
  306. // 802.11h RPI
  307. /* signed long ldBm = 0; */
  308. BOOL bIsWEP = FALSE;
  309. BOOL bExtIV = FALSE;
  310. DWORD dwWbkStatus;
  311. PRCB pRCBIndicate = pRCB;
  312. PBYTE pbyDAddress;
  313. PWORD pwPLCP_Length;
  314. BYTE abyVaildRate[MAX_RATE] = {2,4,11,22,12,18,24,36,48,72,96,108};
  315. WORD wPLCPwithPadding;
  316. PS802_11Header pMACHeader;
  317. BOOL bRxeapol_key = FALSE;
  318. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n");
  319. skb = pRCB->skb;
  320. //[31:16]RcvByteCount ( not include 4-byte Status )
  321. dwWbkStatus = *( (PDWORD)(skb->data) );
  322. FrameSize = (unsigned int)(dwWbkStatus >> 16);
  323. FrameSize += 4;
  324. if (BytesToIndicate != FrameSize) {
  325. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- WRONG Length 1 \n");
  326. return FALSE;
  327. }
  328. if ((BytesToIndicate > 2372) || (BytesToIndicate <= 40)) {
  329. // Frame Size error drop this packet.
  330. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n");
  331. return FALSE;
  332. }
  333. pbyDAddress = (PBYTE)(skb->data);
  334. pbyRxSts = pbyDAddress+4;
  335. pbyRxRate = pbyDAddress+5;
  336. //real Frame Size = USBFrameSize -4WbkStatus - 4RxStatus - 8TSF - 4RSR - 4SQ3 - ?Padding
  337. //if SQ3 the range is 24~27, if no SQ3 the range is 20~23
  338. //real Frame size in PLCPLength field.
  339. pwPLCP_Length = (PWORD) (pbyDAddress + 6);
  340. //Fix hardware bug => PLCP_Length error
  341. if ( ((BytesToIndicate - (*pwPLCP_Length)) > 27) ||
  342. ((BytesToIndicate - (*pwPLCP_Length)) < 24) ||
  343. (BytesToIndicate < (*pwPLCP_Length)) ) {
  344. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong PLCP Length %x\n", (int) *pwPLCP_Length);
  345. ASSERT(0);
  346. return FALSE;
  347. }
  348. for ( ii=RATE_1M;ii<MAX_RATE;ii++) {
  349. if ( *pbyRxRate == abyVaildRate[ii] ) {
  350. break;
  351. }
  352. }
  353. if ( ii==MAX_RATE ) {
  354. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong RxRate %x\n",(int) *pbyRxRate);
  355. return FALSE;
  356. }
  357. wPLCPwithPadding = ( (*pwPLCP_Length / 4) + ( (*pwPLCP_Length % 4) ? 1:0 ) ) *4;
  358. pqwTSFTime = (PQWORD) (pbyDAddress + 8 + wPLCPwithPadding);
  359. if(pDevice->byBBType == BB_TYPE_11G) {
  360. pby3SQ = pbyDAddress + 8 + wPLCPwithPadding + 12;
  361. pbySQ = pby3SQ;
  362. }
  363. else {
  364. pbySQ = pbyDAddress + 8 + wPLCPwithPadding + 8;
  365. pby3SQ = pbySQ;
  366. }
  367. pbyNewRsr = pbyDAddress + 8 + wPLCPwithPadding + 9;
  368. pbyRSSI = pbyDAddress + 8 + wPLCPwithPadding + 10;
  369. pbyRsr = pbyDAddress + 8 + wPLCPwithPadding + 11;
  370. FrameSize = *pwPLCP_Length;
  371. pbyFrame = pbyDAddress + 8;
  372. // update receive statistic counter
  373. STAvUpdateRDStatCounter(&pDevice->scStatistic,
  374. *pbyRsr,
  375. *pbyNewRsr,
  376. *pbyRxSts,
  377. *pbyRxRate,
  378. pbyFrame,
  379. FrameSize
  380. );
  381. pMACHeader = (PS802_11Header) pbyFrame;
  382. //mike add: to judge if current AP is activated?
  383. if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
  384. (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
  385. if (pMgmt->sNodeDBTable[0].bActive) {
  386. if (!compare_ether_addr(pMgmt->abyCurrBSSID, pMACHeader->abyAddr2)) {
  387. if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
  388. pMgmt->sNodeDBTable[0].uInActiveCount = 0;
  389. }
  390. }
  391. }
  392. if (!is_multicast_ether_addr(pMACHeader->abyAddr1) && !is_broadcast_ether_addr(pMACHeader->abyAddr1)) {
  393. if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) {
  394. pDevice->s802_11Counter.FrameDuplicateCount++;
  395. return FALSE;
  396. }
  397. if (compare_ether_addr(pDevice->abyCurrentNetAddr,
  398. pMACHeader->abyAddr1)) {
  399. return FALSE;
  400. }
  401. }
  402. // Use for TKIP MIC
  403. s_vGetDASA(pbyFrame, &cbHeaderSize, &pDevice->sRxEthHeader);
  404. if (!compare_ether_addr((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]),
  405. pDevice->abyCurrentNetAddr))
  406. return FALSE;
  407. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
  408. if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
  409. p802_11Header = (PS802_11Header) (pbyFrame);
  410. // get SA NodeIndex
  411. if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p802_11Header->abyAddr2), &iSANodeIndex)) {
  412. pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
  413. pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
  414. }
  415. }
  416. }
  417. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  418. if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == TRUE) {
  419. return FALSE;
  420. }
  421. }
  422. if (IS_FC_WEP(pbyFrame)) {
  423. BOOL bRxDecryOK = FALSE;
  424. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n");
  425. bIsWEP = TRUE;
  426. if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
  427. pKey = &STempKey;
  428. pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
  429. pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
  430. pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
  431. pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
  432. pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
  433. memcpy(pKey->abyKey,
  434. &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
  435. pKey->uKeyLength
  436. );
  437. bRxDecryOK = s_bHostWepRxEncryption(pDevice,
  438. pbyFrame,
  439. FrameSize,
  440. pbyRsr,
  441. pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
  442. pKey,
  443. pbyNewRsr,
  444. &bExtIV,
  445. &wRxTSC15_0,
  446. &dwRxTSC47_16);
  447. } else {
  448. bRxDecryOK = s_bHandleRxEncryption(pDevice,
  449. pbyFrame,
  450. FrameSize,
  451. pbyRsr,
  452. pbyNewRsr,
  453. &pKey,
  454. &bExtIV,
  455. &wRxTSC15_0,
  456. &dwRxTSC47_16);
  457. }
  458. if (bRxDecryOK) {
  459. if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
  460. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV Fail\n");
  461. if ( (pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
  462. (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
  463. (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
  464. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
  465. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
  466. if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
  467. pDevice->s802_11Counter.TKIPICVErrors++;
  468. } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) {
  469. pDevice->s802_11Counter.CCMPDecryptErrors++;
  470. } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_WEP)) {
  471. // pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
  472. }
  473. }
  474. return FALSE;
  475. }
  476. } else {
  477. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n");
  478. return FALSE;
  479. }
  480. if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
  481. FrameSize -= 8; // Message Integrity Code
  482. else
  483. FrameSize -= 4; // 4 is ICV
  484. }
  485. //
  486. // RX OK
  487. //
  488. /* remove the FCS/CRC length */
  489. FrameSize -= ETH_FCS_LEN;
  490. if ( !(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) && // unicast address
  491. (IS_FRAGMENT_PKT((pbyFrame)))
  492. ) {
  493. // defragment
  494. bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header) (pbyFrame), FrameSize, bIsWEP, bExtIV);
  495. pDevice->s802_11Counter.ReceivedFragmentCount++;
  496. if (bDeFragRx) {
  497. // defrag complete
  498. // TODO skb, pbyFrame
  499. skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
  500. FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
  501. pbyFrame = skb->data + 8;
  502. }
  503. else {
  504. return FALSE;
  505. }
  506. }
  507. //
  508. // Management & Control frame Handle
  509. //
  510. if ((IS_TYPE_DATA((pbyFrame))) == FALSE) {
  511. // Handle Control & Manage Frame
  512. if (IS_TYPE_MGMT((pbyFrame))) {
  513. PBYTE pbyData1;
  514. PBYTE pbyData2;
  515. pRxPacket = &(pRCB->sMngPacket);
  516. pRxPacket->p80211Header = (PUWLAN_80211HDR)(pbyFrame);
  517. pRxPacket->cbMPDULen = FrameSize;
  518. pRxPacket->uRSSI = *pbyRSSI;
  519. pRxPacket->bySQ = *pbySQ;
  520. HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime));
  521. LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
  522. if (bIsWEP) {
  523. // strip IV
  524. pbyData1 = WLAN_HDR_A3_DATA_PTR(pbyFrame);
  525. pbyData2 = WLAN_HDR_A3_DATA_PTR(pbyFrame) + 4;
  526. for (ii = 0; ii < (FrameSize - 4); ii++) {
  527. *pbyData1 = *pbyData2;
  528. pbyData1++;
  529. pbyData2++;
  530. }
  531. }
  532. pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
  533. if ( *pbyRxSts == 0 ) {
  534. //Discard beacon packet which channel is 0
  535. if ( (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_BEACON) ||
  536. (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_PROBERESP) ) {
  537. return TRUE;
  538. }
  539. }
  540. pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
  541. // hostap Deamon handle 802.11 management
  542. if (pDevice->bEnableHostapd) {
  543. skb->dev = pDevice->apdev;
  544. //skb->data += 4;
  545. //skb->tail += 4;
  546. skb->data += 8;
  547. skb->tail += 8;
  548. skb_put(skb, FrameSize);
  549. skb_reset_mac_header(skb);
  550. skb->pkt_type = PACKET_OTHERHOST;
  551. skb->protocol = htons(ETH_P_802_2);
  552. memset(skb->cb, 0, sizeof(skb->cb));
  553. netif_rx(skb);
  554. return TRUE;
  555. }
  556. //
  557. // Insert the RCB in the Recv Mng list
  558. //
  559. EnqueueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList, pRCBIndicate);
  560. pDevice->NumRecvMngList++;
  561. if ( bDeFragRx == FALSE) {
  562. pRCB->Ref++;
  563. }
  564. if (pDevice->bIsRxMngWorkItemQueued == FALSE) {
  565. pDevice->bIsRxMngWorkItemQueued = TRUE;
  566. tasklet_schedule(&pDevice->RxMngWorkItem);
  567. }
  568. }
  569. else {
  570. // Control Frame
  571. };
  572. return FALSE;
  573. }
  574. else {
  575. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  576. //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
  577. if ( !(*pbyRsr & RSR_BSSIDOK)) {
  578. if (bDeFragRx) {
  579. if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
  580. DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
  581. pDevice->dev->name);
  582. }
  583. }
  584. return FALSE;
  585. }
  586. }
  587. else {
  588. // discard DATA packet while not associate || BSSID error
  589. if ((pDevice->bLinkPass == FALSE) ||
  590. !(*pbyRsr & RSR_BSSIDOK)) {
  591. if (bDeFragRx) {
  592. if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
  593. DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
  594. pDevice->dev->name);
  595. }
  596. }
  597. return FALSE;
  598. }
  599. //mike add:station mode check eapol-key challenge--->
  600. {
  601. BYTE Protocol_Version; //802.1x Authentication
  602. BYTE Packet_Type; //802.1x Authentication
  603. BYTE Descriptor_type;
  604. WORD Key_info;
  605. if (bIsWEP)
  606. cbIVOffset = 8;
  607. else
  608. cbIVOffset = 0;
  609. wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
  610. skb->data[cbIVOffset + 8 + 24 + 6 + 1];
  611. Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1];
  612. Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1];
  613. if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header
  614. if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
  615. (Packet_Type==3)) { //802.1x OR eapol-key challenge frame receive
  616. bRxeapol_key = TRUE;
  617. Descriptor_type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2];
  618. Key_info = (skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+1]<<8) |skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+2] ;
  619. if(Descriptor_type==2) { //RSN
  620. // printk("WPA2_Rx_eapol-key_info<-----:%x\n",Key_info);
  621. }
  622. else if(Descriptor_type==254) {
  623. // printk("WPA_Rx_eapol-key_info<-----:%x\n",Key_info);
  624. }
  625. }
  626. }
  627. }
  628. //mike add:station mode check eapol-key challenge<---
  629. }
  630. }
  631. // Data frame Handle
  632. if (pDevice->bEnablePSMode) {
  633. if (IS_FC_MOREDATA((pbyFrame))) {
  634. if (*pbyRsr & RSR_ADDROK) {
  635. //PSbSendPSPOLL((PSDevice)pDevice);
  636. }
  637. }
  638. else {
  639. if (pMgmt->bInTIMWake == TRUE) {
  640. pMgmt->bInTIMWake = FALSE;
  641. }
  642. }
  643. }
  644. // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
  645. if (pDevice->bDiversityEnable && (FrameSize>50) &&
  646. (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
  647. (pDevice->bLinkPass == TRUE)) {
  648. BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
  649. }
  650. // ++++++++ For BaseBand Algorithm +++++++++++++++
  651. pDevice->uCurrRSSI = *pbyRSSI;
  652. pDevice->byCurrSQ = *pbySQ;
  653. // todo
  654. /*
  655. if ((*pbyRSSI != 0) &&
  656. (pMgmt->pCurrBSS!=NULL)) {
  657. RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
  658. // Moniter if RSSI is too strong.
  659. pMgmt->pCurrBSS->byRSSIStatCnt++;
  660. pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
  661. pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
  662. for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
  663. if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
  664. pMgmt->pCurrBSS->ldBmMAX =
  665. max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
  666. }
  667. }
  668. }
  669. */
  670. // -----------------------------------------------
  671. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == TRUE)){
  672. BYTE abyMacHdr[24];
  673. // Only 802.1x packet incoming allowed
  674. if (bIsWEP)
  675. cbIVOffset = 8;
  676. else
  677. cbIVOffset = 0;
  678. wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
  679. skb->data[cbIVOffset + 8 + 24 + 6 + 1];
  680. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wEtherType = %04x \n", wEtherType);
  681. if (wEtherType == ETH_P_PAE) {
  682. skb->dev = pDevice->apdev;
  683. if (bIsWEP == TRUE) {
  684. // strip IV header(8)
  685. memcpy(&abyMacHdr[0], (skb->data + 8), 24);
  686. memcpy((skb->data + 8 + cbIVOffset), &abyMacHdr[0], 24);
  687. }
  688. skb->data += (cbIVOffset + 8);
  689. skb->tail += (cbIVOffset + 8);
  690. skb_put(skb, FrameSize);
  691. skb_reset_mac_header(skb);
  692. skb->pkt_type = PACKET_OTHERHOST;
  693. skb->protocol = htons(ETH_P_802_2);
  694. memset(skb->cb, 0, sizeof(skb->cb));
  695. netif_rx(skb);
  696. return TRUE;
  697. }
  698. // check if 802.1x authorized
  699. if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
  700. return FALSE;
  701. }
  702. if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
  703. if (bIsWEP) {
  704. FrameSize -= 8; //MIC
  705. }
  706. }
  707. //--------------------------------------------------------------------------------
  708. // Soft MIC
  709. if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
  710. if (bIsWEP) {
  711. PDWORD pdwMIC_L;
  712. PDWORD pdwMIC_R;
  713. DWORD dwMIC_Priority;
  714. DWORD dwMICKey0 = 0, dwMICKey1 = 0;
  715. DWORD dwLocalMIC_L = 0;
  716. DWORD dwLocalMIC_R = 0;
  717. viawget_wpa_header *wpahdr;
  718. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  719. dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
  720. dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
  721. }
  722. else {
  723. if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
  724. dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
  725. dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
  726. } else if ((pKey->dwKeyIndex & BIT28) == 0) {
  727. dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
  728. dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
  729. } else {
  730. dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
  731. dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
  732. }
  733. }
  734. MIC_vInit(dwMICKey0, dwMICKey1);
  735. MIC_vAppend((PBYTE)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
  736. dwMIC_Priority = 0;
  737. MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
  738. // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
  739. MIC_vAppend((PBYTE)(skb->data + 8 + WLAN_HDR_ADDR3_LEN + 8),
  740. FrameSize - WLAN_HDR_ADDR3_LEN - 8);
  741. MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
  742. MIC_vUnInit();
  743. pdwMIC_L = (PDWORD)(skb->data + 8 + FrameSize);
  744. pdwMIC_R = (PDWORD)(skb->data + 8 + FrameSize + 4);
  745. if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
  746. (pDevice->bRxMICFail == TRUE)) {
  747. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n");
  748. pDevice->bRxMICFail = FALSE;
  749. //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
  750. pDevice->s802_11Counter.TKIPLocalMICFailures++;
  751. if (bDeFragRx) {
  752. if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
  753. DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
  754. pDevice->dev->name);
  755. }
  756. }
  757. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  758. //send event to wpa_supplicant
  759. //if(pDevice->bWPASuppWextEnabled == TRUE)
  760. {
  761. union iwreq_data wrqu;
  762. struct iw_michaelmicfailure ev;
  763. int keyidx = pbyFrame[cbHeaderSize+3] >> 6; //top two-bits
  764. memset(&ev, 0, sizeof(ev));
  765. ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
  766. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
  767. (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
  768. (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
  769. ev.flags |= IW_MICFAILURE_PAIRWISE;
  770. } else {
  771. ev.flags |= IW_MICFAILURE_GROUP;
  772. }
  773. ev.src_addr.sa_family = ARPHRD_ETHER;
  774. memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
  775. memset(&wrqu, 0, sizeof(wrqu));
  776. wrqu.data.length = sizeof(ev);
  777. PRINT_K("wireless_send_event--->IWEVMICHAELMICFAILURE\n");
  778. wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
  779. }
  780. #endif
  781. if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
  782. wpahdr = (viawget_wpa_header *)pDevice->skb->data;
  783. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
  784. (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
  785. (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
  786. //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR;
  787. wpahdr->type = VIAWGET_PTK_MIC_MSG;
  788. } else {
  789. //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_GROUP_ERROR;
  790. wpahdr->type = VIAWGET_GTK_MIC_MSG;
  791. }
  792. wpahdr->resp_ie_len = 0;
  793. wpahdr->req_ie_len = 0;
  794. skb_put(pDevice->skb, sizeof(viawget_wpa_header));
  795. pDevice->skb->dev = pDevice->wpadev;
  796. skb_reset_mac_header(pDevice->skb);
  797. pDevice->skb->pkt_type = PACKET_HOST;
  798. pDevice->skb->protocol = htons(ETH_P_802_2);
  799. memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
  800. netif_rx(pDevice->skb);
  801. pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  802. }
  803. return FALSE;
  804. }
  805. }
  806. } //---end of SOFT MIC-----------------------------------------------------------------------
  807. // ++++++++++ Reply Counter Check +++++++++++++
  808. if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
  809. (pKey->byCipherSuite == KEY_CTL_CCMP))) {
  810. if (bIsWEP) {
  811. WORD wLocalTSC15_0 = 0;
  812. DWORD dwLocalTSC47_16 = 0;
  813. unsigned long long RSC = 0;
  814. // endian issues
  815. RSC = *((unsigned long long *) &(pKey->KeyRSC));
  816. wLocalTSC15_0 = (WORD) RSC;
  817. dwLocalTSC47_16 = (DWORD) (RSC>>16);
  818. RSC = dwRxTSC47_16;
  819. RSC <<= 16;
  820. RSC += wRxTSC15_0;
  821. memcpy(&(pKey->KeyRSC), &RSC, sizeof(QWORD));
  822. if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
  823. (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
  824. // check RSC
  825. if ( (wRxTSC15_0 < wLocalTSC15_0) &&
  826. (dwRxTSC47_16 <= dwLocalTSC47_16) &&
  827. !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
  828. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC is illegal~~!\n ");
  829. if (pKey->byCipherSuite == KEY_CTL_TKIP)
  830. //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
  831. pDevice->s802_11Counter.TKIPReplays++;
  832. else
  833. //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
  834. pDevice->s802_11Counter.CCMPReplays++;
  835. if (bDeFragRx) {
  836. if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
  837. DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
  838. pDevice->dev->name);
  839. }
  840. }
  841. return FALSE;
  842. }
  843. }
  844. }
  845. } // ----- End of Reply Counter Check --------------------------
  846. s_vProcessRxMACHeader(pDevice, (PBYTE)(skb->data+8), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
  847. FrameSize -= cbHeaderOffset;
  848. cbHeaderOffset += 8; // 8 is Rcv buffer header
  849. // Null data, framesize = 12
  850. if (FrameSize < 12)
  851. return FALSE;
  852. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  853. if (s_bAPModeRxData(pDevice,
  854. skb,
  855. FrameSize,
  856. cbHeaderOffset,
  857. iSANodeIndex,
  858. iDANodeIndex
  859. ) == FALSE) {
  860. if (bDeFragRx) {
  861. if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
  862. DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
  863. pDevice->dev->name);
  864. }
  865. }
  866. return FALSE;
  867. }
  868. }
  869. skb->data += cbHeaderOffset;
  870. skb->tail += cbHeaderOffset;
  871. skb_put(skb, FrameSize);
  872. skb->protocol=eth_type_trans(skb, skb->dev);
  873. skb->ip_summed=CHECKSUM_NONE;
  874. pStats->rx_bytes +=skb->len;
  875. pStats->rx_packets++;
  876. netif_rx(skb);
  877. if (bDeFragRx) {
  878. if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
  879. DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
  880. pDevice->dev->name);
  881. }
  882. return FALSE;
  883. }
  884. return TRUE;
  885. }
  886. static BOOL s_bAPModeRxCtl (
  887. PSDevice pDevice,
  888. PBYTE pbyFrame,
  889. signed int iSANodeIndex
  890. )
  891. {
  892. PS802_11Header p802_11Header;
  893. CMD_STATUS Status;
  894. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  895. if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
  896. p802_11Header = (PS802_11Header) (pbyFrame);
  897. if (!IS_TYPE_MGMT(pbyFrame)) {
  898. // Data & PS-Poll packet
  899. // check frame class
  900. if (iSANodeIndex > 0) {
  901. // frame class 3 fliter & checking
  902. if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
  903. // send deauth notification
  904. // reason = (6) class 2 received from nonauth sta
  905. vMgrDeAuthenBeginSta(pDevice,
  906. pMgmt,
  907. (PBYTE)(p802_11Header->abyAddr2),
  908. (WLAN_MGMT_REASON_CLASS2_NONAUTH),
  909. &Status
  910. );
  911. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
  912. return TRUE;
  913. }
  914. if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
  915. // send deassoc notification
  916. // reason = (7) class 3 received from nonassoc sta
  917. vMgrDisassocBeginSta(pDevice,
  918. pMgmt,
  919. (PBYTE)(p802_11Header->abyAddr2),
  920. (WLAN_MGMT_REASON_CLASS3_NONASSOC),
  921. &Status
  922. );
  923. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
  924. return TRUE;
  925. }
  926. if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
  927. // delcare received ps-poll event
  928. if (IS_CTL_PSPOLL(pbyFrame)) {
  929. pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
  930. bScheduleCommand((void *) pDevice,
  931. WLAN_CMD_RX_PSPOLL,
  932. NULL);
  933. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
  934. }
  935. else {
  936. // check Data PS state
  937. // if PW bit off, send out all PS bufferring packets.
  938. if (!IS_FC_POWERMGT(pbyFrame)) {
  939. pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
  940. pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
  941. bScheduleCommand((void *) pDevice,
  942. WLAN_CMD_RX_PSPOLL,
  943. NULL);
  944. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
  945. }
  946. }
  947. }
  948. else {
  949. if (IS_FC_POWERMGT(pbyFrame)) {
  950. pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = TRUE;
  951. // Once if STA in PS state, enable multicast bufferring
  952. pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
  953. }
  954. else {
  955. // clear all pending PS frame.
  956. if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
  957. pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
  958. pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
  959. bScheduleCommand((void *) pDevice,
  960. WLAN_CMD_RX_PSPOLL,
  961. NULL);
  962. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
  963. }
  964. }
  965. }
  966. }
  967. else {
  968. vMgrDeAuthenBeginSta(pDevice,
  969. pMgmt,
  970. (PBYTE)(p802_11Header->abyAddr2),
  971. (WLAN_MGMT_REASON_CLASS2_NONAUTH),
  972. &Status
  973. );
  974. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
  975. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%02x-%02x-%02x=%02x-%02x-%02x \n",
  976. p802_11Header->abyAddr3[0],
  977. p802_11Header->abyAddr3[1],
  978. p802_11Header->abyAddr3[2],
  979. p802_11Header->abyAddr3[3],
  980. p802_11Header->abyAddr3[4],
  981. p802_11Header->abyAddr3[5]
  982. );
  983. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%02x-%02x-%02x=%02x-%02x-%02x \n",
  984. p802_11Header->abyAddr2[0],
  985. p802_11Header->abyAddr2[1],
  986. p802_11Header->abyAddr2[2],
  987. p802_11Header->abyAddr2[3],
  988. p802_11Header->abyAddr2[4],
  989. p802_11Header->abyAddr2[5]
  990. );
  991. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%02x-%02x-%02x=%02x-%02x-%02x \n",
  992. p802_11Header->abyAddr1[0],
  993. p802_11Header->abyAddr1[1],
  994. p802_11Header->abyAddr1[2],
  995. p802_11Header->abyAddr1[3],
  996. p802_11Header->abyAddr1[4],
  997. p802_11Header->abyAddr1[5]
  998. );
  999. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
  1000. return TRUE;
  1001. }
  1002. }
  1003. }
  1004. return FALSE;
  1005. }
  1006. static BOOL s_bHandleRxEncryption (
  1007. PSDevice pDevice,
  1008. PBYTE pbyFrame,
  1009. unsigned int FrameSize,
  1010. PBYTE pbyRsr,
  1011. PBYTE pbyNewRsr,
  1012. PSKeyItem * pKeyOut,
  1013. int * pbExtIV,
  1014. PWORD pwRxTSC15_0,
  1015. PDWORD pdwRxTSC47_16
  1016. )
  1017. {
  1018. unsigned int PayloadLen = FrameSize;
  1019. PBYTE pbyIV;
  1020. BYTE byKeyIdx;
  1021. PSKeyItem pKey = NULL;
  1022. BYTE byDecMode = KEY_CTL_WEP;
  1023. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  1024. *pwRxTSC15_0 = 0;
  1025. *pdwRxTSC47_16 = 0;
  1026. pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
  1027. if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
  1028. WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
  1029. pbyIV += 6; // 6 is 802.11 address4
  1030. PayloadLen -= 6;
  1031. }
  1032. byKeyIdx = (*(pbyIV+3) & 0xc0);
  1033. byKeyIdx >>= 6;
  1034. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
  1035. if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
  1036. (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
  1037. (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
  1038. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
  1039. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
  1040. if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
  1041. (pMgmt->byCSSPK != KEY_CTL_NONE)) {
  1042. // unicast pkt use pairwise key
  1043. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n");
  1044. if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == TRUE) {
  1045. if (pMgmt->byCSSPK == KEY_CTL_TKIP)
  1046. byDecMode = KEY_CTL_TKIP;
  1047. else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
  1048. byDecMode = KEY_CTL_CCMP;
  1049. }
  1050. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt: %d, %p\n", byDecMode, pKey);
  1051. } else {
  1052. // use group key
  1053. KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
  1054. if (pMgmt->byCSSGK == KEY_CTL_TKIP)
  1055. byDecMode = KEY_CTL_TKIP;
  1056. else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
  1057. byDecMode = KEY_CTL_CCMP;
  1058. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
  1059. }
  1060. }
  1061. // our WEP only support Default Key
  1062. if (pKey == NULL) {
  1063. // use default group key
  1064. KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
  1065. if (pMgmt->byCSSGK == KEY_CTL_TKIP)
  1066. byDecMode = KEY_CTL_TKIP;
  1067. else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
  1068. byDecMode = KEY_CTL_CCMP;
  1069. }
  1070. *pKeyOut = pKey;
  1071. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
  1072. if (pKey == NULL) {
  1073. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n");
  1074. if (byDecMode == KEY_CTL_WEP) {
  1075. // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
  1076. } else if (pDevice->bLinkPass == TRUE) {
  1077. // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
  1078. }
  1079. return FALSE;
  1080. }
  1081. if (byDecMode != pKey->byCipherSuite) {
  1082. if (byDecMode == KEY_CTL_WEP) {
  1083. // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
  1084. } else if (pDevice->bLinkPass == TRUE) {
  1085. // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
  1086. }
  1087. *pKeyOut = NULL;
  1088. return FALSE;
  1089. }
  1090. if (byDecMode == KEY_CTL_WEP) {
  1091. // handle WEP
  1092. if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
  1093. (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE)) {
  1094. // Software WEP
  1095. // 1. 3253A
  1096. // 2. WEP 256
  1097. PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
  1098. memcpy(pDevice->abyPRNG, pbyIV, 3);
  1099. memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
  1100. rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
  1101. rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
  1102. if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
  1103. *pbyNewRsr |= NEWRSR_DECRYPTOK;
  1104. }
  1105. }
  1106. } else if ((byDecMode == KEY_CTL_TKIP) ||
  1107. (byDecMode == KEY_CTL_CCMP)) {
  1108. // TKIP/AES
  1109. PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
  1110. *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
  1111. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %lx\n",*pdwRxTSC47_16);
  1112. if (byDecMode == KEY_CTL_TKIP) {
  1113. *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
  1114. } else {
  1115. *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
  1116. }
  1117. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
  1118. if ((byDecMode == KEY_CTL_TKIP) &&
  1119. (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
  1120. // Software TKIP
  1121. // 1. 3253 A
  1122. PS802_11Header pMACHeader = (PS802_11Header) (pbyFrame);
  1123. TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
  1124. rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
  1125. rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
  1126. if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
  1127. *pbyNewRsr |= NEWRSR_DECRYPTOK;
  1128. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
  1129. } else {
  1130. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
  1131. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
  1132. }
  1133. }
  1134. }// end of TKIP/AES
  1135. if ((*(pbyIV+3) & 0x20) != 0)
  1136. *pbExtIV = TRUE;
  1137. return TRUE;
  1138. }
  1139. static BOOL s_bHostWepRxEncryption (
  1140. PSDevice pDevice,
  1141. PBYTE pbyFrame,
  1142. unsigned int FrameSize,
  1143. PBYTE pbyRsr,
  1144. BOOL bOnFly,
  1145. PSKeyItem pKey,
  1146. PBYTE pbyNewRsr,
  1147. int * pbExtIV,
  1148. PWORD pwRxTSC15_0,
  1149. PDWORD pdwRxTSC47_16
  1150. )
  1151. {
  1152. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  1153. unsigned int PayloadLen = FrameSize;
  1154. PBYTE pbyIV;
  1155. BYTE byKeyIdx;
  1156. BYTE byDecMode = KEY_CTL_WEP;
  1157. PS802_11Header pMACHeader;
  1158. *pwRxTSC15_0 = 0;
  1159. *pdwRxTSC47_16 = 0;
  1160. pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
  1161. if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
  1162. WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
  1163. pbyIV += 6; // 6 is 802.11 address4
  1164. PayloadLen -= 6;
  1165. }
  1166. byKeyIdx = (*(pbyIV+3) & 0xc0);
  1167. byKeyIdx >>= 6;
  1168. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
  1169. if (pMgmt->byCSSGK == KEY_CTL_TKIP)
  1170. byDecMode = KEY_CTL_TKIP;
  1171. else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
  1172. byDecMode = KEY_CTL_CCMP;
  1173. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
  1174. if (byDecMode != pKey->byCipherSuite) {
  1175. if (byDecMode == KEY_CTL_WEP) {
  1176. // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
  1177. } else if (pDevice->bLinkPass == TRUE) {
  1178. // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
  1179. }
  1180. return FALSE;
  1181. }
  1182. if (byDecMode == KEY_CTL_WEP) {
  1183. // handle WEP
  1184. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP \n");
  1185. if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
  1186. (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE) ||
  1187. (bOnFly == FALSE)) {
  1188. // Software WEP
  1189. // 1. 3253A
  1190. // 2. WEP 256
  1191. // 3. NotOnFly
  1192. PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
  1193. memcpy(pDevice->abyPRNG, pbyIV, 3);
  1194. memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
  1195. rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
  1196. rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
  1197. if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
  1198. *pbyNewRsr |= NEWRSR_DECRYPTOK;
  1199. }
  1200. }
  1201. } else if ((byDecMode == KEY_CTL_TKIP) ||
  1202. (byDecMode == KEY_CTL_CCMP)) {
  1203. // TKIP/AES
  1204. PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
  1205. *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
  1206. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %lx\n",*pdwRxTSC47_16);
  1207. if (byDecMode == KEY_CTL_TKIP) {
  1208. *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
  1209. } else {
  1210. *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
  1211. }
  1212. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
  1213. if (byDecMode == KEY_CTL_TKIP) {
  1214. if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == FALSE)) {
  1215. // Software TKIP
  1216. // 1. 3253 A
  1217. // 2. NotOnFly
  1218. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_TKIP \n");
  1219. pMACHeader = (PS802_11Header) (pbyFrame);
  1220. TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
  1221. rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
  1222. rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
  1223. if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
  1224. *pbyNewRsr |= NEWRSR_DECRYPTOK;
  1225. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
  1226. } else {
  1227. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
  1228. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
  1229. }
  1230. }
  1231. }
  1232. if (byDecMode == KEY_CTL_CCMP) {
  1233. if (bOnFly == FALSE) {
  1234. // Software CCMP
  1235. // NotOnFly
  1236. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n");
  1237. if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
  1238. *pbyNewRsr |= NEWRSR_DECRYPTOK;
  1239. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC compare OK!\n");
  1240. } else {
  1241. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC fail!\n");
  1242. }
  1243. }
  1244. }
  1245. }// end of TKIP/AES
  1246. if ((*(pbyIV+3) & 0x20) != 0)
  1247. *pbExtIV = TRUE;
  1248. return TRUE;
  1249. }
  1250. static BOOL s_bAPModeRxData (
  1251. PSDevice pDevice,
  1252. struct sk_buff *skb,
  1253. unsigned int FrameSize,
  1254. unsigned int cbHeaderOffset,
  1255. signed int iSANodeIndex,
  1256. signed int iDANodeIndex
  1257. )
  1258. {
  1259. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  1260. BOOL bRelayAndForward = FALSE;
  1261. BOOL bRelayOnly = FALSE;
  1262. BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
  1263. WORD wAID;
  1264. struct sk_buff* skbcpy = NULL;
  1265. if (FrameSize > CB_MAX_BUF_SIZE)
  1266. return FALSE;
  1267. // check DA
  1268. if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) {
  1269. if (pMgmt->sNodeDBTable[0].bPSEnable) {
  1270. skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
  1271. // if any node in PS mode, buffer packet until DTIM.
  1272. if (skbcpy == NULL) {
  1273. DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available \n");
  1274. }
  1275. else {
  1276. skbcpy->dev = pDevice->dev;
  1277. skbcpy->len = FrameSize;
  1278. memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
  1279. skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
  1280. pMgmt->sNodeDBTable[0].wEnQueueCnt++;
  1281. // set tx map
  1282. pMgmt->abyPSTxMap[0] |= byMask[0];
  1283. }
  1284. }
  1285. else {
  1286. bRelayAndForward = TRUE;
  1287. }
  1288. }
  1289. else {
  1290. // check if relay
  1291. if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
  1292. if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
  1293. if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
  1294. // queue this skb until next PS tx, and then release.
  1295. skb->data += cbHeaderOffset;
  1296. skb->tail += cbHeaderOffset;
  1297. skb_put(skb, FrameSize);
  1298. skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
  1299. pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
  1300. wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
  1301. pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
  1302. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
  1303. iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
  1304. return TRUE;
  1305. }
  1306. else {
  1307. bRelayOnly = TRUE;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. if (bRelayOnly || bRelayAndForward) {
  1313. // relay this packet right now
  1314. if (bRelayAndForward)
  1315. iDANodeIndex = 0;
  1316. if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
  1317. bRelayPacketSend(pDevice, (PBYTE) (skb->data + cbHeaderOffset),
  1318. FrameSize, (unsigned int) iDANodeIndex);
  1319. }
  1320. if (bRelayOnly)
  1321. return FALSE;
  1322. }
  1323. // none associate, don't forward
  1324. if (pDevice->uAssocCount == 0)
  1325. return FALSE;
  1326. return TRUE;
  1327. }
  1328. void RXvWorkItem(void *Context)
  1329. {
  1330. PSDevice pDevice = (PSDevice) Context;
  1331. int ntStatus;
  1332. PRCB pRCB=NULL;
  1333. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Polling Thread\n");
  1334. spin_lock_irq(&pDevice->lock);
  1335. while ((pDevice->Flags & fMP_POST_READS) &&
  1336. MP_IS_READY(pDevice) &&
  1337. (pDevice->NumRecvFreeList != 0) ) {
  1338. pRCB = pDevice->FirstRecvFreeList;
  1339. pDevice->NumRecvFreeList--;
  1340. ASSERT(pRCB);// cannot be NULL
  1341. DequeueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList);
  1342. ntStatus = PIPEnsBulkInUsbRead(pDevice, pRCB);
  1343. }
  1344. pDevice->bIsRxWorkItemQueued = FALSE;
  1345. spin_unlock_irq(&pDevice->lock);
  1346. }
  1347. void
  1348. RXvFreeRCB(
  1349. PRCB pRCB,
  1350. BOOL bReAllocSkb
  1351. )
  1352. {
  1353. PSDevice pDevice = (PSDevice)pRCB->pDevice;
  1354. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n");
  1355. ASSERT(!pRCB->Ref); // should be 0
  1356. ASSERT(pRCB->pDevice); // shouldn't be NULL
  1357. if (bReAllocSkb == TRUE) {
  1358. pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  1359. // todo error handling
  1360. if (pRCB->skb == NULL) {
  1361. DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to re-alloc rx skb\n");
  1362. }else {
  1363. pRCB->skb->dev = pDevice->dev;
  1364. }
  1365. }
  1366. //
  1367. // Insert the RCB back in the Recv free list
  1368. //
  1369. EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
  1370. pDevice->NumRecvFreeList++;
  1371. if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) &&
  1372. (pDevice->bIsRxWorkItemQueued == FALSE) ) {
  1373. pDevice->bIsRxWorkItemQueued = TRUE;
  1374. tasklet_schedule(&pDevice->ReadWorkItem);
  1375. }
  1376. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
  1377. }
  1378. void RXvMngWorkItem(void *Context)
  1379. {
  1380. PSDevice pDevice = (PSDevice) Context;
  1381. PRCB pRCB=NULL;
  1382. PSRxMgmtPacket pRxPacket;
  1383. BOOL bReAllocSkb = FALSE;
  1384. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n");
  1385. spin_lock_irq(&pDevice->lock);
  1386. while (pDevice->NumRecvMngList!=0)
  1387. {
  1388. pRCB = pDevice->FirstRecvMngList;
  1389. pDevice->NumRecvMngList--;
  1390. DequeueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
  1391. if(!pRCB){
  1392. break;
  1393. }
  1394. ASSERT(pRCB);// cannot be NULL
  1395. pRxPacket = &(pRCB->sMngPacket);
  1396. vMgrRxManagePacket((void *) pDevice, &(pDevice->sMgmtObj), pRxPacket);
  1397. pRCB->Ref--;
  1398. if(pRCB->Ref == 0) {
  1399. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeMng %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
  1400. RXvFreeRCB(pRCB, bReAllocSkb);
  1401. } else {
  1402. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rx Mng Only we have the right to free RCB\n");
  1403. }
  1404. }
  1405. pDevice->bIsRxMngWorkItemQueued = FALSE;
  1406. spin_unlock_irq(&pDevice->lock);
  1407. }