wcmd.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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: wcmd.c
  20. *
  21. * Purpose: Handles the management command interface functions
  22. *
  23. * Author: Lyndon Chen
  24. *
  25. * Date: May 8, 2003
  26. *
  27. * Functions:
  28. * s_vProbeChannel - Active scan channel
  29. * s_MgrMakeProbeRequest - Make ProbeRequest packet
  30. * CommandTimer - Timer function to handle command
  31. * s_bCommandComplete - Command Complete function
  32. * bScheduleCommand - Push Command and wait Command Scheduler to do
  33. * vCommandTimer- Command call back functions
  34. * vCommandTimerWait- Call back timer
  35. * s_bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
  36. *
  37. * Revision History:
  38. *
  39. */
  40. #include "ttype.h"
  41. #include "tmacro.h"
  42. #include "device.h"
  43. #include "mac.h"
  44. #include "card.h"
  45. #include "80211hdr.h"
  46. #include "wcmd.h"
  47. #include "wmgr.h"
  48. #include "power.h"
  49. #include "wctl.h"
  50. #include "baseband.h"
  51. #include "control.h"
  52. #include "rxtx.h"
  53. #include "rf.h"
  54. #include "rndis.h"
  55. #include "channel.h"
  56. #include "iowpa.h"
  57. /*--------------------- Static Definitions -------------------------*/
  58. /*--------------------- Static Classes ----------------------------*/
  59. /*--------------------- Static Variables --------------------------*/
  60. static int msglevel =MSG_LEVEL_INFO;
  61. //static int msglevel =MSG_LEVEL_DEBUG;
  62. /*--------------------- Static Functions --------------------------*/
  63. static
  64. void
  65. s_vProbeChannel(
  66. PSDevice pDevice
  67. );
  68. static
  69. PSTxMgmtPacket
  70. s_MgrMakeProbeRequest(
  71. PSDevice pDevice,
  72. PSMgmtObject pMgmt,
  73. PBYTE pScanBSSID,
  74. PWLAN_IE_SSID pSSID,
  75. PWLAN_IE_SUPP_RATES pCurrRates,
  76. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  77. );
  78. static
  79. BOOL
  80. s_bCommandComplete (
  81. PSDevice pDevice
  82. );
  83. static BOOL s_bClearBSSID_SCAN(void *hDeviceContext);
  84. /*--------------------- Export Variables --------------------------*/
  85. /*--------------------- Export Functions --------------------------*/
  86. /*
  87. * Description:
  88. * Stop AdHoc beacon during scan process
  89. *
  90. * Parameters:
  91. * In:
  92. * pDevice - Pointer to the adapter
  93. * Out:
  94. * none
  95. *
  96. * Return Value: none
  97. *
  98. */
  99. static
  100. void
  101. vAdHocBeaconStop(PSDevice pDevice)
  102. {
  103. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  104. BOOL bStop;
  105. /*
  106. * temporarily stop Beacon packet for AdHoc Server
  107. * if all of the following coditions are met:
  108. * (1) STA is in AdHoc mode
  109. * (2) VT3253 is programmed as automatic Beacon Transmitting
  110. * (3) One of the following conditions is met
  111. * (3.1) AdHoc channel is in B/G band and the
  112. * current scan channel is in A band
  113. * or
  114. * (3.2) AdHoc channel is in A mode
  115. */
  116. bStop = FALSE;
  117. if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
  118. (pMgmt->eCurrState >= WMAC_STATE_STARTED))
  119. {
  120. if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
  121. (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
  122. {
  123. bStop = TRUE;
  124. }
  125. if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
  126. {
  127. bStop = TRUE;
  128. }
  129. }
  130. if (bStop)
  131. {
  132. //PMESG(("STOP_BEACON: IBSSChannel = %u, ScanChannel = %u\n",
  133. // pMgmt->uIBSSChannel, pMgmt->uScanChannel));
  134. MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
  135. }
  136. } /* vAdHocBeaconStop */
  137. /*
  138. * Description:
  139. * Restart AdHoc beacon after scan process complete
  140. *
  141. * Parameters:
  142. * In:
  143. * pDevice - Pointer to the adapter
  144. * Out:
  145. * none
  146. *
  147. * Return Value: none
  148. *
  149. */
  150. static
  151. void
  152. vAdHocBeaconRestart(PSDevice pDevice)
  153. {
  154. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  155. /*
  156. * Restart Beacon packet for AdHoc Server
  157. * if all of the following coditions are met:
  158. * (1) STA is in AdHoc mode
  159. * (2) VT3253 is programmed as automatic Beacon Transmitting
  160. */
  161. if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
  162. (pMgmt->eCurrState >= WMAC_STATE_STARTED))
  163. {
  164. //PMESG(("RESTART_BEACON\n"));
  165. MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
  166. }
  167. }
  168. /*+
  169. *
  170. * Routine Description:
  171. * Prepare and send probe request management frames.
  172. *
  173. *
  174. * Return Value:
  175. * none.
  176. *
  177. -*/
  178. static
  179. void
  180. s_vProbeChannel(
  181. PSDevice pDevice
  182. )
  183. {
  184. //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
  185. BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
  186. BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
  187. //6M, 9M, 12M, 48M
  188. BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
  189. BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
  190. PBYTE pbyRate;
  191. PSTxMgmtPacket pTxPacket;
  192. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  193. unsigned int ii;
  194. if (pDevice->byBBType == BB_TYPE_11A) {
  195. pbyRate = &abyCurrSuppRatesA[0];
  196. } else if (pDevice->byBBType == BB_TYPE_11B) {
  197. pbyRate = &abyCurrSuppRatesB[0];
  198. } else {
  199. pbyRate = &abyCurrSuppRatesG[0];
  200. }
  201. // build an assocreq frame and send it
  202. pTxPacket = s_MgrMakeProbeRequest
  203. (
  204. pDevice,
  205. pMgmt,
  206. pMgmt->abyScanBSSID,
  207. (PWLAN_IE_SSID)pMgmt->abyScanSSID,
  208. (PWLAN_IE_SUPP_RATES)pbyRate,
  209. (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
  210. );
  211. if (pTxPacket != NULL ){
  212. for (ii = 0; ii < 1 ; ii++) {
  213. if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
  214. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
  215. }
  216. else {
  217. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
  218. }
  219. }
  220. }
  221. }
  222. /*+
  223. *
  224. * Routine Description:
  225. * Constructs an probe request frame
  226. *
  227. *
  228. * Return Value:
  229. * A ptr to Tx frame or NULL on allocation failue
  230. *
  231. -*/
  232. PSTxMgmtPacket
  233. s_MgrMakeProbeRequest(
  234. PSDevice pDevice,
  235. PSMgmtObject pMgmt,
  236. PBYTE pScanBSSID,
  237. PWLAN_IE_SSID pSSID,
  238. PWLAN_IE_SUPP_RATES pCurrRates,
  239. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  240. )
  241. {
  242. PSTxMgmtPacket pTxPacket = NULL;
  243. WLAN_FR_PROBEREQ sFrame;
  244. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  245. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
  246. pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
  247. sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
  248. sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
  249. vMgrEncodeProbeRequest(&sFrame);
  250. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  251. (
  252. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  253. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
  254. ));
  255. memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
  256. memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  257. memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
  258. // Copy the SSID, pSSID->len=0 indicate broadcast SSID
  259. sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
  260. sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
  261. memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
  262. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  263. sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
  264. memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
  265. // Copy the extension rate set
  266. if (pDevice->byBBType == BB_TYPE_11G) {
  267. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  268. sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
  269. memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
  270. }
  271. pTxPacket->cbMPDULen = sFrame.len;
  272. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  273. return pTxPacket;
  274. }
  275. void vCommandTimerWait(void *hDeviceContext, unsigned int MSecond)
  276. {
  277. PSDevice pDevice = (PSDevice)hDeviceContext;
  278. init_timer(&pDevice->sTimerCommand);
  279. pDevice->sTimerCommand.data = (unsigned long)pDevice;
  280. pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
  281. // RUN_AT :1 msec ~= (HZ/1024)
  282. pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
  283. add_timer(&pDevice->sTimerCommand);
  284. return;
  285. }
  286. void vRunCommand(void *hDeviceContext)
  287. {
  288. PSDevice pDevice = (PSDevice)hDeviceContext;
  289. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  290. PWLAN_IE_SSID pItemSSID;
  291. PWLAN_IE_SSID pItemSSIDCurr;
  292. CMD_STATUS Status;
  293. unsigned int ii;
  294. BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
  295. struct sk_buff *skb;
  296. BYTE byData;
  297. if (pDevice->dwDiagRefCount != 0)
  298. return;
  299. if (pDevice->bCmdRunning != TRUE)
  300. return;
  301. spin_lock_irq(&pDevice->lock);
  302. switch ( pDevice->eCommandState ) {
  303. case WLAN_CMD_SCAN_START:
  304. pDevice->byReAssocCount = 0;
  305. if (pDevice->bRadioOff == TRUE) {
  306. s_bCommandComplete(pDevice);
  307. spin_unlock_irq(&pDevice->lock);
  308. return;
  309. }
  310. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  311. s_bCommandComplete(pDevice);
  312. spin_unlock_irq(&pDevice->lock);
  313. return;
  314. }
  315. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
  316. if (pMgmt->uScanChannel == 0 ) {
  317. pMgmt->uScanChannel = pDevice->byMinChannel;
  318. }
  319. if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
  320. pMgmt->eScanState = WMAC_NO_SCANNING;
  321. if (pDevice->byBBType != pDevice->byScanBBType) {
  322. pDevice->byBBType = pDevice->byScanBBType;
  323. CARDvSetBSSMode(pDevice);
  324. }
  325. if (pDevice->bUpdateBBVGA) {
  326. BBvSetShortSlotTime(pDevice);
  327. BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
  328. BBvUpdatePreEDThreshold(pDevice, FALSE);
  329. }
  330. // Set channel back
  331. vAdHocBeaconRestart(pDevice);
  332. // Set channel back
  333. CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
  334. // Set Filter
  335. if (pMgmt->bCurrBSSIDFilterOn) {
  336. MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
  337. pDevice->byRxMode |= RCR_BSSID;
  338. }
  339. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
  340. pDevice->bStopDataPkt = FALSE;
  341. s_bCommandComplete(pDevice);
  342. spin_unlock_irq(&pDevice->lock);
  343. return;
  344. } else {
  345. if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
  346. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
  347. s_bCommandComplete(pDevice);
  348. spin_unlock_irq(&pDevice->lock);
  349. return;
  350. }
  351. if (pMgmt->uScanChannel == pDevice->byMinChannel) {
  352. // pMgmt->eScanType = WMAC_SCAN_ACTIVE; //mike mark
  353. pMgmt->abyScanBSSID[0] = 0xFF;
  354. pMgmt->abyScanBSSID[1] = 0xFF;
  355. pMgmt->abyScanBSSID[2] = 0xFF;
  356. pMgmt->abyScanBSSID[3] = 0xFF;
  357. pMgmt->abyScanBSSID[4] = 0xFF;
  358. pMgmt->abyScanBSSID[5] = 0xFF;
  359. pItemSSID->byElementID = WLAN_EID_SSID;
  360. // clear bssid list
  361. /* BSSvClearBSSList((void *) pDevice,
  362. pDevice->bLinkPass); */
  363. pMgmt->eScanState = WMAC_IS_SCANNING;
  364. pDevice->byScanBBType = pDevice->byBBType; //lucas
  365. pDevice->bStopDataPkt = TRUE;
  366. // Turn off RCR_BSSID filter every time
  367. MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
  368. pDevice->byRxMode &= ~RCR_BSSID;
  369. }
  370. //lucas
  371. vAdHocBeaconStop(pDevice);
  372. if ((pDevice->byBBType != BB_TYPE_11A) && (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
  373. pDevice->byBBType = BB_TYPE_11A;
  374. CARDvSetBSSMode(pDevice);
  375. }
  376. else if ((pDevice->byBBType == BB_TYPE_11A) && (pMgmt->uScanChannel <= CB_MAX_CHANNEL_24G)) {
  377. pDevice->byBBType = BB_TYPE_11G;
  378. CARDvSetBSSMode(pDevice);
  379. }
  380. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning.... channel: [%d]\n", pMgmt->uScanChannel);
  381. // Set channel
  382. CARDbSetMediaChannel(pDevice, pMgmt->uScanChannel);
  383. // Set Baseband to be more sensitive.
  384. if (pDevice->bUpdateBBVGA) {
  385. BBvSetShortSlotTime(pDevice);
  386. BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
  387. BBvUpdatePreEDThreshold(pDevice, TRUE);
  388. }
  389. pMgmt->uScanChannel++;
  390. while (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
  391. pMgmt->uScanChannel <= pDevice->byMaxChannel ){
  392. pMgmt->uScanChannel++;
  393. }
  394. if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
  395. // Set Baseband to be not sensitive and rescan
  396. pDevice->eCommandState = WLAN_CMD_SCAN_END;
  397. }
  398. if ((pMgmt->b11hEnable == FALSE) ||
  399. (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
  400. s_vProbeChannel(pDevice);
  401. spin_unlock_irq(&pDevice->lock);
  402. vCommandTimerWait((void *) pDevice, 100);
  403. return;
  404. } else {
  405. spin_unlock_irq(&pDevice->lock);
  406. vCommandTimerWait((void *) pDevice, WCMD_PASSIVE_SCAN_TIME);
  407. return;
  408. }
  409. }
  410. break;
  411. case WLAN_CMD_SCAN_END:
  412. // Set Baseband's sensitivity back.
  413. if (pDevice->byBBType != pDevice->byScanBBType) {
  414. pDevice->byBBType = pDevice->byScanBBType;
  415. CARDvSetBSSMode(pDevice);
  416. }
  417. if (pDevice->bUpdateBBVGA) {
  418. BBvSetShortSlotTime(pDevice);
  419. BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
  420. BBvUpdatePreEDThreshold(pDevice, FALSE);
  421. }
  422. // Set channel back
  423. vAdHocBeaconRestart(pDevice);
  424. // Set channel back
  425. CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
  426. // Set Filter
  427. if (pMgmt->bCurrBSSIDFilterOn) {
  428. MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
  429. pDevice->byRxMode |= RCR_BSSID;
  430. }
  431. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
  432. pMgmt->eScanState = WMAC_NO_SCANNING;
  433. pDevice->bStopDataPkt = FALSE;
  434. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  435. if(pMgmt->eScanType == WMAC_SCAN_PASSIVE)
  436. {
  437. //send scan event to wpa_Supplicant
  438. union iwreq_data wrqu;
  439. PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
  440. memset(&wrqu, 0, sizeof(wrqu));
  441. wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
  442. }
  443. #endif
  444. s_bCommandComplete(pDevice);
  445. break;
  446. case WLAN_CMD_DISASSOCIATE_START :
  447. pDevice->byReAssocCount = 0;
  448. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
  449. (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
  450. s_bCommandComplete(pDevice);
  451. spin_unlock_irq(&pDevice->lock);
  452. return;
  453. } else {
  454. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  455. pDevice->bwextstep0 = FALSE;
  456. pDevice->bwextstep1 = FALSE;
  457. pDevice->bwextstep2 = FALSE;
  458. pDevice->bwextstep3 = FALSE;
  459. pDevice->bWPASuppWextEnabled = FALSE;
  460. #endif
  461. pDevice->fWPA_Authened = FALSE;
  462. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
  463. // reason = 8 : disassoc because sta has left
  464. vMgrDisassocBeginSta((void *) pDevice,
  465. pMgmt,
  466. pMgmt->abyCurrBSSID,
  467. (8),
  468. &Status);
  469. pDevice->bLinkPass = FALSE;
  470. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
  471. // unlock command busy
  472. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  473. pItemSSID->len = 0;
  474. memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
  475. pMgmt->eCurrState = WMAC_STATE_IDLE;
  476. pMgmt->sNodeDBTable[0].bActive = FALSE;
  477. // pDevice->bBeaconBufReady = FALSE;
  478. }
  479. netif_stop_queue(pDevice->dev);
  480. if (pDevice->bNeedRadioOFF == TRUE)
  481. CARDbRadioPowerOff(pDevice);
  482. s_bCommandComplete(pDevice);
  483. break;
  484. case WLAN_CMD_SSID_START:
  485. pDevice->byReAssocCount = 0;
  486. if (pDevice->bRadioOff == TRUE) {
  487. s_bCommandComplete(pDevice);
  488. spin_unlock_irq(&pDevice->lock);
  489. return;
  490. }
  491. memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
  492. ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
  493. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
  494. pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  495. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
  496. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
  497. if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
  498. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
  499. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
  500. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
  501. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
  502. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
  503. }
  504. if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
  505. ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
  506. if (pItemSSID->len == pItemSSIDCurr->len) {
  507. if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
  508. s_bCommandComplete(pDevice);
  509. spin_unlock_irq(&pDevice->lock);
  510. return;
  511. }
  512. }
  513. netif_stop_queue(pDevice->dev);
  514. pDevice->bLinkPass = FALSE;
  515. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
  516. }
  517. // set initial state
  518. pMgmt->eCurrState = WMAC_STATE_IDLE;
  519. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  520. PSvDisablePowerSaving((void *) pDevice);
  521. BSSvClearNodeDBTable(pDevice, 0);
  522. vMgrJoinBSSBegin((void *) pDevice, &Status);
  523. // if Infra mode
  524. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
  525. // Call mgr to begin the deauthentication
  526. // reason = (3) because sta has left ESS
  527. if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
  528. vMgrDeAuthenBeginSta((void *)pDevice,
  529. pMgmt,
  530. pMgmt->abyCurrBSSID,
  531. (3),
  532. &Status);
  533. }
  534. // Call mgr to begin the authentication
  535. vMgrAuthenBeginSta((void *) pDevice, pMgmt, &Status);
  536. if (Status == CMD_STATUS_SUCCESS) {
  537. pDevice->byLinkWaitCount = 0;
  538. pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
  539. vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT);
  540. spin_unlock_irq(&pDevice->lock);
  541. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
  542. return;
  543. }
  544. }
  545. // if Adhoc mode
  546. else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  547. if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
  548. if (netif_queue_stopped(pDevice->dev)){
  549. netif_wake_queue(pDevice->dev);
  550. }
  551. pDevice->bLinkPass = TRUE;
  552. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
  553. pMgmt->sNodeDBTable[0].bActive = TRUE;
  554. pMgmt->sNodeDBTable[0].uInActiveCount = 0;
  555. }
  556. else {
  557. // start own IBSS
  558. DBG_PRT(MSG_LEVEL_DEBUG,
  559. KERN_INFO "CreateOwn IBSS by CurrMode = IBSS_STA\n");
  560. vMgrCreateOwnIBSS((void *) pDevice, &Status);
  561. if (Status != CMD_STATUS_SUCCESS){
  562. DBG_PRT(MSG_LEVEL_DEBUG,
  563. KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
  564. }
  565. BSSvAddMulticastNode(pDevice);
  566. }
  567. s_bClearBSSID_SCAN(pDevice);
  568. }
  569. // if SSID not found
  570. else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
  571. if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
  572. pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
  573. // start own IBSS
  574. DBG_PRT(MSG_LEVEL_DEBUG,
  575. KERN_INFO "CreateOwn IBSS by CurrMode = STANDBY\n");
  576. vMgrCreateOwnIBSS((void *) pDevice, &Status);
  577. if (Status != CMD_STATUS_SUCCESS){
  578. DBG_PRT(MSG_LEVEL_DEBUG,
  579. KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
  580. }
  581. BSSvAddMulticastNode(pDevice);
  582. s_bClearBSSID_SCAN(pDevice);
  583. /*
  584. pDevice->bLinkPass = TRUE;
  585. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
  586. if (netif_queue_stopped(pDevice->dev)){
  587. netif_wake_queue(pDevice->dev);
  588. }
  589. s_bClearBSSID_SCAN(pDevice);
  590. */
  591. }
  592. else {
  593. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
  594. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  595. // if(pDevice->bWPASuppWextEnabled == TRUE)
  596. {
  597. union iwreq_data wrqu;
  598. memset(&wrqu, 0, sizeof (wrqu));
  599. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  600. PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
  601. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  602. }
  603. #endif
  604. }
  605. }
  606. s_bCommandComplete(pDevice);
  607. break;
  608. case WLAN_AUTHENTICATE_WAIT :
  609. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
  610. if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
  611. pDevice->byLinkWaitCount = 0;
  612. // Call mgr to begin the association
  613. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
  614. vMgrAssocBeginSta((void *) pDevice, pMgmt, &Status);
  615. if (Status == CMD_STATUS_SUCCESS) {
  616. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
  617. pDevice->byLinkWaitCount = 0;
  618. pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
  619. vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT);
  620. spin_unlock_irq(&pDevice->lock);
  621. return;
  622. }
  623. }
  624. else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
  625. printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
  626. }
  627. else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
  628. pDevice->byLinkWaitCount ++;
  629. printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
  630. spin_unlock_irq(&pDevice->lock);
  631. vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT/2);
  632. return;
  633. }
  634. pDevice->byLinkWaitCount = 0;
  635. s_bCommandComplete(pDevice);
  636. break;
  637. case WLAN_ASSOCIATE_WAIT :
  638. if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
  639. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
  640. if (pDevice->ePSMode != WMAC_POWER_CAM) {
  641. PSvEnablePowerSaving((void *) pDevice,
  642. pMgmt->wListenInterval);
  643. }
  644. /*
  645. if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
  646. KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
  647. }
  648. */
  649. pDevice->byLinkWaitCount = 0;
  650. pDevice->byReAssocCount = 0;
  651. pDevice->bLinkPass = TRUE;
  652. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
  653. s_bClearBSSID_SCAN(pDevice);
  654. if (netif_queue_stopped(pDevice->dev)){
  655. netif_wake_queue(pDevice->dev);
  656. }
  657. if(pDevice->IsTxDataTrigger != FALSE) { //TxDataTimer is not triggered at the first time
  658. // printk("Re-initial TxDataTimer****\n");
  659. del_timer(&pDevice->sTimerTxData);
  660. init_timer(&pDevice->sTimerTxData);
  661. pDevice->sTimerTxData.data = (unsigned long) pDevice;
  662. pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
  663. pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
  664. pDevice->fTxDataInSleep = FALSE;
  665. pDevice->nTxDataTimeCout = 0;
  666. }
  667. else {
  668. // printk("mike:-->First time triger TimerTxData InSleep\n");
  669. }
  670. pDevice->IsTxDataTrigger = TRUE;
  671. add_timer(&pDevice->sTimerTxData);
  672. }
  673. else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
  674. printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
  675. }
  676. else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
  677. pDevice->byLinkWaitCount ++;
  678. printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
  679. spin_unlock_irq(&pDevice->lock);
  680. vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT/2);
  681. return;
  682. }
  683. pDevice->byLinkWaitCount = 0;
  684. s_bCommandComplete(pDevice);
  685. break;
  686. case WLAN_CMD_AP_MODE_START :
  687. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
  688. if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
  689. del_timer(&pMgmt->sTimerSecondCallback);
  690. pMgmt->eCurrState = WMAC_STATE_IDLE;
  691. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  692. pDevice->bLinkPass = FALSE;
  693. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
  694. if (pDevice->bEnableHostWEP == TRUE)
  695. BSSvClearNodeDBTable(pDevice, 1);
  696. else
  697. BSSvClearNodeDBTable(pDevice, 0);
  698. pDevice->uAssocCount = 0;
  699. pMgmt->eCurrState = WMAC_STATE_IDLE;
  700. pDevice->bFixRate = FALSE;
  701. vMgrCreateOwnIBSS((void *) pDevice, &Status);
  702. if (Status != CMD_STATUS_SUCCESS) {
  703. DBG_PRT(MSG_LEVEL_DEBUG,
  704. KERN_INFO "vMgrCreateOwnIBSS fail!\n");
  705. }
  706. // alway turn off unicast bit
  707. MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_UNICAST);
  708. pDevice->byRxMode &= ~RCR_UNICAST;
  709. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
  710. BSSvAddMulticastNode(pDevice);
  711. if (netif_queue_stopped(pDevice->dev)){
  712. netif_wake_queue(pDevice->dev);
  713. }
  714. pDevice->bLinkPass = TRUE;
  715. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
  716. add_timer(&pMgmt->sTimerSecondCallback);
  717. }
  718. s_bCommandComplete(pDevice);
  719. break;
  720. case WLAN_CMD_TX_PSPACKET_START :
  721. // DTIM Multicast tx
  722. if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
  723. while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
  724. if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
  725. pMgmt->abyPSTxMap[0] &= ~byMask[0];
  726. pDevice->bMoreData = FALSE;
  727. }
  728. else {
  729. pDevice->bMoreData = TRUE;
  730. }
  731. if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
  732. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
  733. }
  734. pMgmt->sNodeDBTable[0].wEnQueueCnt--;
  735. }
  736. }
  737. // PS nodes tx
  738. for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
  739. if (pMgmt->sNodeDBTable[ii].bActive &&
  740. pMgmt->sNodeDBTable[ii].bRxPSPoll) {
  741. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
  742. ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
  743. while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
  744. if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
  745. // clear tx map
  746. pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
  747. ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
  748. pDevice->bMoreData = FALSE;
  749. }
  750. else {
  751. pDevice->bMoreData = TRUE;
  752. }
  753. if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
  754. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
  755. }
  756. pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
  757. // check if sta ps enable, wait next pspoll
  758. // if sta ps disable, send all pending buffers.
  759. if (pMgmt->sNodeDBTable[ii].bPSEnable)
  760. break;
  761. }
  762. if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
  763. // clear tx map
  764. pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
  765. ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
  766. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
  767. }
  768. pMgmt->sNodeDBTable[ii].bRxPSPoll = FALSE;
  769. }
  770. }
  771. s_bCommandComplete(pDevice);
  772. break;
  773. case WLAN_CMD_RADIO_START:
  774. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
  775. // if (pDevice->bRadioCmd == TRUE)
  776. // CARDbRadioPowerOn(pDevice);
  777. // else
  778. // CARDbRadioPowerOff(pDevice);
  779. {
  780. int ntStatus = STATUS_SUCCESS;
  781. BYTE byTmp;
  782. ntStatus = CONTROLnsRequestIn(pDevice,
  783. MESSAGE_TYPE_READ,
  784. MAC_REG_GPIOCTL1,
  785. MESSAGE_REQUEST_MACREG,
  786. 1,
  787. &byTmp);
  788. if ( ntStatus != STATUS_SUCCESS ) {
  789. s_bCommandComplete(pDevice);
  790. spin_unlock_irq(&pDevice->lock);
  791. return;
  792. }
  793. if ( (byTmp & GPIO3_DATA) == 0 ) {
  794. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_OFF........................\n");
  795. // Old commands are useless.
  796. // empty command Q
  797. pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
  798. pDevice->uCmdDequeueIdx = 0;
  799. pDevice->uCmdEnqueueIdx = 0;
  800. //0415pDevice->bCmdRunning = FALSE;
  801. pDevice->bCmdClear = TRUE;
  802. pDevice->bStopTx0Pkt = FALSE;
  803. pDevice->bStopDataPkt = TRUE;
  804. pDevice->byKeyIndex = 0;
  805. pDevice->bTransmitKey = FALSE;
  806. spin_unlock_irq(&pDevice->lock);
  807. KeyvInitTable(pDevice,&pDevice->sKey);
  808. spin_lock_irq(&pDevice->lock);
  809. pMgmt->byCSSPK = KEY_CTL_NONE;
  810. pMgmt->byCSSGK = KEY_CTL_NONE;
  811. if (pDevice->bLinkPass == TRUE) {
  812. // reason = 8 : disassoc because sta has left
  813. vMgrDisassocBeginSta((void *) pDevice,
  814. pMgmt,
  815. pMgmt->abyCurrBSSID,
  816. (8),
  817. &Status);
  818. pDevice->bLinkPass = FALSE;
  819. // unlock command busy
  820. pMgmt->eCurrState = WMAC_STATE_IDLE;
  821. pMgmt->sNodeDBTable[0].bActive = FALSE;
  822. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  823. // if(pDevice->bWPASuppWextEnabled == TRUE)
  824. {
  825. union iwreq_data wrqu;
  826. memset(&wrqu, 0, sizeof (wrqu));
  827. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  828. PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
  829. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  830. }
  831. #endif
  832. }
  833. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  834. pDevice->bwextstep0 = FALSE;
  835. pDevice->bwextstep1 = FALSE;
  836. pDevice->bwextstep2 = FALSE;
  837. pDevice->bwextstep3 = FALSE;
  838. pDevice->bWPASuppWextEnabled = FALSE;
  839. #endif
  840. //clear current SSID
  841. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  842. pItemSSID->len = 0;
  843. memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
  844. //clear dessire SSID
  845. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
  846. pItemSSID->len = 0;
  847. memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
  848. netif_stop_queue(pDevice->dev);
  849. CARDbRadioPowerOff(pDevice);
  850. MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
  851. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF);
  852. pDevice->bHWRadioOff = TRUE;
  853. } else {
  854. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
  855. pDevice->bHWRadioOff = FALSE;
  856. CARDbRadioPowerOn(pDevice);
  857. MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
  858. ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON);
  859. }
  860. }
  861. s_bCommandComplete(pDevice);
  862. break;
  863. case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
  864. pDevice->bStopDataPkt = TRUE;
  865. pDevice->byBBVGACurrent = pDevice->byBBVGANew;
  866. BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
  867. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
  868. pDevice->bStopDataPkt = FALSE;
  869. s_bCommandComplete(pDevice);
  870. break;
  871. case WLAN_CMD_TBTT_WAKEUP_START:
  872. PSbIsNextTBTTWakeUp(pDevice);
  873. s_bCommandComplete(pDevice);
  874. break;
  875. case WLAN_CMD_BECON_SEND_START:
  876. bMgrPrepareBeaconToSend(pDevice, pMgmt);
  877. s_bCommandComplete(pDevice);
  878. break;
  879. case WLAN_CMD_SETPOWER_START:
  880. RFbSetPower(pDevice, pDevice->wCurrentRate, pMgmt->uCurrChannel);
  881. s_bCommandComplete(pDevice);
  882. break;
  883. case WLAN_CMD_CHANGE_ANTENNA_START:
  884. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
  885. if ( pDevice->dwRxAntennaSel == 0) {
  886. pDevice->dwRxAntennaSel=1;
  887. if (pDevice->bTxRxAntInv == TRUE)
  888. BBvSetAntennaMode(pDevice, ANT_RXA);
  889. else
  890. BBvSetAntennaMode(pDevice, ANT_RXB);
  891. } else {
  892. pDevice->dwRxAntennaSel=0;
  893. if (pDevice->bTxRxAntInv == TRUE)
  894. BBvSetAntennaMode(pDevice, ANT_RXB);
  895. else
  896. BBvSetAntennaMode(pDevice, ANT_RXA);
  897. }
  898. s_bCommandComplete(pDevice);
  899. break;
  900. case WLAN_CMD_REMOVE_ALLKEY_START:
  901. KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
  902. s_bCommandComplete(pDevice);
  903. break;
  904. case WLAN_CMD_MAC_DISPOWERSAVING_START:
  905. ControlvReadByte (pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
  906. if ( (byData & PSCTL_PS) != 0 ) {
  907. // disable power saving hw function
  908. CONTROLnsRequestOut(pDevice,
  909. MESSAGE_TYPE_DISABLE_PS,
  910. 0,
  911. 0,
  912. 0,
  913. NULL
  914. );
  915. }
  916. s_bCommandComplete(pDevice);
  917. break;
  918. case WLAN_CMD_11H_CHSW_START:
  919. CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
  920. pDevice->bChannelSwitch = FALSE;
  921. pMgmt->uCurrChannel = pDevice->byNewChannel;
  922. pDevice->bStopDataPkt = FALSE;
  923. s_bCommandComplete(pDevice);
  924. break;
  925. default:
  926. s_bCommandComplete(pDevice);
  927. break;
  928. } //switch
  929. spin_unlock_irq(&pDevice->lock);
  930. return;
  931. }
  932. static
  933. BOOL
  934. s_bCommandComplete (
  935. PSDevice pDevice
  936. )
  937. {
  938. PWLAN_IE_SSID pSSID;
  939. BOOL bRadioCmd = FALSE;
  940. //WORD wDeAuthenReason = 0;
  941. BOOL bForceSCAN = TRUE;
  942. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  943. pDevice->eCommandState = WLAN_CMD_IDLE;
  944. if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
  945. //Command Queue Empty
  946. pDevice->bCmdRunning = FALSE;
  947. return TRUE;
  948. }
  949. else {
  950. pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
  951. pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
  952. bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
  953. bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
  954. ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
  955. pDevice->cbFreeCmdQueue++;
  956. pDevice->bCmdRunning = TRUE;
  957. switch ( pDevice->eCommand ) {
  958. case WLAN_CMD_BSSID_SCAN:
  959. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
  960. pDevice->eCommandState = WLAN_CMD_SCAN_START;
  961. pMgmt->uScanChannel = 0;
  962. if (pSSID->len != 0) {
  963. memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  964. } else {
  965. memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  966. }
  967. /*
  968. if ((bForceSCAN == FALSE) && (pDevice->bLinkPass == TRUE)) {
  969. if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
  970. ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
  971. pDevice->eCommandState = WLAN_CMD_IDLE;
  972. }
  973. }
  974. */
  975. break;
  976. case WLAN_CMD_SSID:
  977. pDevice->eCommandState = WLAN_CMD_SSID_START;
  978. if (pSSID->len > WLAN_SSID_MAXLEN)
  979. pSSID->len = WLAN_SSID_MAXLEN;
  980. if (pSSID->len != 0)
  981. memcpy(pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  982. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
  983. break;
  984. case WLAN_CMD_DISASSOCIATE:
  985. pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
  986. break;
  987. case WLAN_CMD_RX_PSPOLL:
  988. pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
  989. break;
  990. case WLAN_CMD_RUN_AP:
  991. pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
  992. break;
  993. case WLAN_CMD_RADIO:
  994. pDevice->eCommandState = WLAN_CMD_RADIO_START;
  995. pDevice->bRadioCmd = bRadioCmd;
  996. break;
  997. case WLAN_CMD_CHANGE_BBSENSITIVITY:
  998. pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
  999. break;
  1000. case WLAN_CMD_TBTT_WAKEUP:
  1001. pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
  1002. break;
  1003. case WLAN_CMD_BECON_SEND:
  1004. pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
  1005. break;
  1006. case WLAN_CMD_SETPOWER:
  1007. pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
  1008. break;
  1009. case WLAN_CMD_CHANGE_ANTENNA:
  1010. pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
  1011. break;
  1012. case WLAN_CMD_REMOVE_ALLKEY:
  1013. pDevice->eCommandState = WLAN_CMD_REMOVE_ALLKEY_START;
  1014. break;
  1015. case WLAN_CMD_MAC_DISPOWERSAVING:
  1016. pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
  1017. break;
  1018. case WLAN_CMD_11H_CHSW:
  1019. pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
  1020. break;
  1021. default:
  1022. break;
  1023. }
  1024. vCommandTimerWait((void *) pDevice, 0);
  1025. }
  1026. return TRUE;
  1027. }
  1028. BOOL bScheduleCommand(void *hDeviceContext,
  1029. CMD_CODE eCommand,
  1030. PBYTE pbyItem0)
  1031. {
  1032. PSDevice pDevice = (PSDevice)hDeviceContext;
  1033. if (pDevice->cbFreeCmdQueue == 0) {
  1034. return (FALSE);
  1035. }
  1036. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
  1037. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = TRUE;
  1038. memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  1039. if (pbyItem0 != NULL) {
  1040. switch (eCommand) {
  1041. case WLAN_CMD_BSSID_SCAN:
  1042. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = FALSE;
  1043. memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
  1044. pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  1045. break;
  1046. case WLAN_CMD_SSID:
  1047. memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
  1048. pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  1049. break;
  1050. case WLAN_CMD_DISASSOCIATE:
  1051. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
  1052. break;
  1053. /*
  1054. case WLAN_CMD_DEAUTH:
  1055. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((PWORD)pbyItem0);
  1056. break;
  1057. */
  1058. case WLAN_CMD_RADIO:
  1059. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
  1060. break;
  1061. default:
  1062. break;
  1063. }
  1064. }
  1065. ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
  1066. pDevice->cbFreeCmdQueue--;
  1067. if (pDevice->bCmdRunning == FALSE) {
  1068. s_bCommandComplete(pDevice);
  1069. }
  1070. else {
  1071. }
  1072. return (TRUE);
  1073. }
  1074. /*
  1075. * Description:
  1076. * Clear BSSID_SCAN cmd in CMD Queue
  1077. *
  1078. * Parameters:
  1079. * In:
  1080. * hDeviceContext - Pointer to the adapter
  1081. * eCommand - Command
  1082. * Out:
  1083. * none
  1084. *
  1085. * Return Value: TRUE if success; otherwise FALSE
  1086. *
  1087. */
  1088. static BOOL s_bClearBSSID_SCAN(void *hDeviceContext)
  1089. {
  1090. PSDevice pDevice = (PSDevice)hDeviceContext;
  1091. unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
  1092. unsigned int ii;
  1093. if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
  1094. for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
  1095. if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
  1096. pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
  1097. ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
  1098. if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
  1099. break;
  1100. }
  1101. }
  1102. return TRUE;
  1103. }
  1104. //mike add:reset command timer
  1105. void vResetCommandTimer(void *hDeviceContext)
  1106. {
  1107. PSDevice pDevice = (PSDevice)hDeviceContext;
  1108. //delete timer
  1109. del_timer(&pDevice->sTimerCommand);
  1110. //init timer
  1111. init_timer(&pDevice->sTimerCommand);
  1112. pDevice->sTimerCommand.data = (unsigned long)pDevice;
  1113. pDevice->sTimerCommand.function = (TimerFunction)vRunCommand;
  1114. pDevice->sTimerCommand.expires = RUN_AT(HZ);
  1115. pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
  1116. pDevice->uCmdDequeueIdx = 0;
  1117. pDevice->uCmdEnqueueIdx = 0;
  1118. pDevice->eCommandState = WLAN_CMD_IDLE;
  1119. pDevice->bCmdRunning = FALSE;
  1120. pDevice->bCmdClear = FALSE;
  1121. }
  1122. void BSSvSecondTxData(void *hDeviceContext)
  1123. {
  1124. PSDevice pDevice = (PSDevice)hDeviceContext;
  1125. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  1126. pDevice->nTxDataTimeCout++;
  1127. if(pDevice->nTxDataTimeCout<4) //don't tx data if timer less than 40s
  1128. {
  1129. // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
  1130. // (int)pDevice->nTxDataTimeCout);
  1131. pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
  1132. add_timer(&pDevice->sTimerTxData);
  1133. return;
  1134. }
  1135. spin_lock_irq(&pDevice->lock);
  1136. //is wap_supplicant running successful OR only open && sharekey mode!
  1137. if(((pDevice->bLinkPass ==TRUE)&&(pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
  1138. (pDevice->fWPA_Authened == TRUE)) { //wpa linking
  1139. // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
  1140. pDevice->fTxDataInSleep = TRUE;
  1141. PSbSendNullPacket(pDevice); //send null packet
  1142. pDevice->fTxDataInSleep = FALSE;
  1143. }
  1144. spin_unlock_irq(&pDevice->lock);
  1145. pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
  1146. add_timer(&pDevice->sTimerTxData);
  1147. return;
  1148. }