dpc.c 54 KB

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