wcmd.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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. * 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 "rxtx.h"
  52. #include "rf.h"
  53. #include "iowpa.h"
  54. #include "channel.h"
  55. /*--------------------- Static Definitions -------------------------*/
  56. /*--------------------- Static Classes ----------------------------*/
  57. /*--------------------- Static Variables --------------------------*/
  58. static int msglevel =MSG_LEVEL_INFO;
  59. //static int msglevel =MSG_LEVEL_DEBUG;
  60. /*--------------------- Static Functions --------------------------*/
  61. static
  62. void
  63. s_vProbeChannel(
  64. PSDevice pDevice
  65. );
  66. static
  67. PSTxMgmtPacket
  68. s_MgrMakeProbeRequest(
  69. PSDevice pDevice,
  70. PSMgmtObject pMgmt,
  71. unsigned char *pScanBSSID,
  72. PWLAN_IE_SSID pSSID,
  73. PWLAN_IE_SUPP_RATES pCurrRates,
  74. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  75. );
  76. static
  77. bool
  78. s_bCommandComplete (
  79. PSDevice pDevice
  80. );
  81. /*--------------------- Export Variables --------------------------*/
  82. /*--------------------- Export Functions --------------------------*/
  83. /*
  84. * Description:
  85. * Stop AdHoc beacon during scan process
  86. *
  87. * Parameters:
  88. * In:
  89. * pDevice - Pointer to the adapter
  90. * Out:
  91. * none
  92. *
  93. * Return Value: none
  94. *
  95. */
  96. static
  97. void
  98. vAdHocBeaconStop(PSDevice pDevice)
  99. {
  100. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  101. bool bStop;
  102. /*
  103. * temporarily stop Beacon packet for AdHoc Server
  104. * if all of the following coditions are met:
  105. * (1) STA is in AdHoc mode
  106. * (2) VT3253 is programmed as automatic Beacon Transmitting
  107. * (3) One of the following conditions is met
  108. * (3.1) AdHoc channel is in B/G band and the
  109. * current scan channel is in A band
  110. * or
  111. * (3.2) AdHoc channel is in A mode
  112. */
  113. bStop = false;
  114. if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
  115. (pMgmt->eCurrState >= WMAC_STATE_STARTED))
  116. {
  117. if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
  118. (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
  119. {
  120. bStop = true;
  121. }
  122. if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
  123. {
  124. bStop = true;
  125. }
  126. }
  127. if (bStop)
  128. {
  129. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
  130. }
  131. } /* vAdHocBeaconStop */
  132. /*
  133. * Description:
  134. * Restart AdHoc beacon after scan process complete
  135. *
  136. * Parameters:
  137. * In:
  138. * pDevice - Pointer to the adapter
  139. * Out:
  140. * none
  141. *
  142. * Return Value: none
  143. *
  144. */
  145. static
  146. void
  147. vAdHocBeaconRestart(PSDevice pDevice)
  148. {
  149. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  150. /*
  151. * Restart Beacon packet for AdHoc Server
  152. * if all of the following coditions are met:
  153. * (1) STA is in AdHoc mode
  154. * (2) VT3253 is programmed as automatic Beacon Transmitting
  155. */
  156. if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
  157. (pMgmt->eCurrState >= WMAC_STATE_STARTED))
  158. {
  159. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
  160. }
  161. }
  162. /*+
  163. *
  164. * Routine Description:
  165. * Prepare and send probe request management frames.
  166. *
  167. *
  168. * Return Value:
  169. * none.
  170. *
  171. -*/
  172. static
  173. void
  174. s_vProbeChannel(
  175. PSDevice pDevice
  176. )
  177. {
  178. //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
  179. unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
  180. unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
  181. //6M, 9M, 12M, 48M
  182. unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
  183. unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
  184. unsigned char *pbyRate;
  185. PSTxMgmtPacket pTxPacket;
  186. PSMgmtObject pMgmt = pDevice->pMgmt;
  187. unsigned int ii;
  188. if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
  189. pbyRate = &abyCurrSuppRatesA[0];
  190. } else if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
  191. pbyRate = &abyCurrSuppRatesB[0];
  192. } else {
  193. pbyRate = &abyCurrSuppRatesG[0];
  194. }
  195. // build an assocreq frame and send it
  196. pTxPacket = s_MgrMakeProbeRequest
  197. (
  198. pDevice,
  199. pMgmt,
  200. pMgmt->abyScanBSSID,
  201. (PWLAN_IE_SSID)pMgmt->abyScanSSID,
  202. (PWLAN_IE_SUPP_RATES)pbyRate,
  203. (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
  204. );
  205. if (pTxPacket != NULL ){
  206. for (ii = 0; ii < 2 ; ii++) {
  207. if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
  208. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
  209. }
  210. else {
  211. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
  212. }
  213. }
  214. }
  215. }
  216. /*+
  217. *
  218. * Routine Description:
  219. * Constructs an probe request frame
  220. *
  221. *
  222. * Return Value:
  223. * A ptr to Tx frame or NULL on allocation failue
  224. *
  225. -*/
  226. PSTxMgmtPacket
  227. s_MgrMakeProbeRequest(
  228. PSDevice pDevice,
  229. PSMgmtObject pMgmt,
  230. unsigned char *pScanBSSID,
  231. PWLAN_IE_SSID pSSID,
  232. PWLAN_IE_SUPP_RATES pCurrRates,
  233. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  234. )
  235. {
  236. PSTxMgmtPacket pTxPacket = NULL;
  237. WLAN_FR_PROBEREQ sFrame;
  238. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  239. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
  240. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  241. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  242. sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
  243. vMgrEncodeProbeRequest(&sFrame);
  244. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  245. (
  246. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  247. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
  248. ));
  249. memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
  250. memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  251. memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
  252. // Copy the SSID, pSSID->len=0 indicate broadcast SSID
  253. sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
  254. sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
  255. memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
  256. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  257. sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
  258. memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
  259. // Copy the extension rate set
  260. if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
  261. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  262. sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
  263. memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
  264. }
  265. pTxPacket->cbMPDULen = sFrame.len;
  266. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  267. return pTxPacket;
  268. }
  269. void
  270. vCommandTimerWait(
  271. void *hDeviceContext,
  272. unsigned int MSecond
  273. )
  274. {
  275. PSDevice pDevice = (PSDevice)hDeviceContext;
  276. init_timer(&pDevice->sTimerCommand);
  277. pDevice->sTimerCommand.data = (unsigned long) pDevice;
  278. pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
  279. // RUN_AT :1 msec ~= (HZ/1024)
  280. pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
  281. add_timer(&pDevice->sTimerCommand);
  282. return;
  283. }
  284. void
  285. vCommandTimer (
  286. void *hDeviceContext
  287. )
  288. {
  289. PSDevice pDevice = (PSDevice)hDeviceContext;
  290. PSMgmtObject pMgmt = pDevice->pMgmt;
  291. PWLAN_IE_SSID pItemSSID;
  292. PWLAN_IE_SSID pItemSSIDCurr;
  293. CMD_STATUS Status;
  294. unsigned int ii;
  295. unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
  296. struct sk_buff *skb;
  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. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
  313. spin_unlock_irq(&pDevice->lock);
  314. return;
  315. }
  316. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SCAN_START\n");
  317. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
  318. // wait all Data TD complete
  319. if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
  320. spin_unlock_irq(&pDevice->lock);
  321. vCommandTimerWait((void *)pDevice, 10);
  322. return;
  323. }
  324. if (pMgmt->uScanChannel == 0 ) {
  325. pMgmt->uScanChannel = pDevice->byMinChannel;
  326. // Set Baseband to be more sensitive.
  327. }
  328. if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
  329. pMgmt->eScanState = WMAC_NO_SCANNING;
  330. // Set Baseband's sensitivity back.
  331. // Set channel back
  332. set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
  333. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
  334. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  335. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
  336. } else {
  337. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
  338. }
  339. vAdHocBeaconRestart(pDevice);
  340. s_bCommandComplete(pDevice);
  341. } else {
  342. //2008-8-4 <add> by chester
  343. if (!is_channel_valid(pMgmt->uScanChannel)) {
  344. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
  345. s_bCommandComplete(pDevice);
  346. return;
  347. }
  348. //printk("chester-pMgmt->uScanChannel=%d,pDevice->byMaxChannel=%d\n",pMgmt->uScanChannel,pDevice->byMaxChannel);
  349. if (pMgmt->uScanChannel == pDevice->byMinChannel) {
  350. //pMgmt->eScanType = WMAC_SCAN_ACTIVE;
  351. pMgmt->abyScanBSSID[0] = 0xFF;
  352. pMgmt->abyScanBSSID[1] = 0xFF;
  353. pMgmt->abyScanBSSID[2] = 0xFF;
  354. pMgmt->abyScanBSSID[3] = 0xFF;
  355. pMgmt->abyScanBSSID[4] = 0xFF;
  356. pMgmt->abyScanBSSID[5] = 0xFF;
  357. pItemSSID->byElementID = WLAN_EID_SSID;
  358. // clear bssid list
  359. // BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
  360. pMgmt->eScanState = WMAC_IS_SCANNING;
  361. }
  362. vAdHocBeaconStop(pDevice);
  363. if (set_channel(pMgmt->pAdapter, pMgmt->uScanChannel) == true) {
  364. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SCAN Channel: %d\n", pMgmt->uScanChannel);
  365. } else {
  366. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SET SCAN Channel Fail: %d\n", pMgmt->uScanChannel);
  367. }
  368. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_UNKNOWN);
  369. // printk("chester-mxch=%d\n",pDevice->byMaxChannel);
  370. // printk("chester-ch=%d\n",pMgmt->uScanChannel);
  371. pMgmt->uScanChannel++;
  372. //2008-8-4 <modify> by chester
  373. if (!is_channel_valid(pMgmt->uScanChannel) &&
  374. pMgmt->uScanChannel <= pDevice->byMaxChannel ){
  375. pMgmt->uScanChannel=pDevice->byMaxChannel+1;
  376. pMgmt->eCommandState = WLAN_CMD_SCAN_END;
  377. }
  378. if ((pMgmt->b11hEnable == false) ||
  379. (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
  380. s_vProbeChannel(pDevice);
  381. spin_unlock_irq(&pDevice->lock);
  382. vCommandTimerWait((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
  383. return;
  384. } else {
  385. spin_unlock_irq(&pDevice->lock);
  386. vCommandTimerWait((void *)pDevice, WCMD_PASSIVE_SCAN_TIME);
  387. return;
  388. }
  389. }
  390. break;
  391. case WLAN_CMD_SCAN_END:
  392. // Set Baseband's sensitivity back.
  393. // Set channel back
  394. set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
  395. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
  396. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  397. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
  398. } else {
  399. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
  400. }
  401. pMgmt->eScanState = WMAC_NO_SCANNING;
  402. vAdHocBeaconRestart(pDevice);
  403. //2008-0409-07, <Add> by Einsn Liu
  404. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  405. if(pMgmt->eScanType == WMAC_SCAN_PASSIVE)
  406. {//send scan event to wpa_Supplicant
  407. union iwreq_data wrqu;
  408. memset(&wrqu, 0, sizeof(wrqu));
  409. wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
  410. }
  411. #endif
  412. s_bCommandComplete(pDevice);
  413. break;
  414. case WLAN_CMD_DISASSOCIATE_START :
  415. pDevice->byReAssocCount = 0;
  416. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
  417. (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
  418. s_bCommandComplete(pDevice);
  419. spin_unlock_irq(&pDevice->lock);
  420. return;
  421. } else {
  422. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
  423. // reason = 8 : disassoc because sta has left
  424. vMgrDisassocBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (8), &Status);
  425. pDevice->bLinkPass = false;
  426. // unlock command busy
  427. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  428. pItemSSID->len = 0;
  429. memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
  430. pMgmt->eCurrState = WMAC_STATE_IDLE;
  431. pMgmt->sNodeDBTable[0].bActive = false;
  432. // pDevice->bBeaconBufReady = false;
  433. }
  434. netif_stop_queue(pDevice->dev);
  435. pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
  436. // wait all Control TD complete
  437. if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
  438. vCommandTimerWait((void *)pDevice, 10);
  439. spin_unlock_irq(&pDevice->lock);
  440. return;
  441. }
  442. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" CARDbRadioPowerOff\n");
  443. //2008-09-02 <mark> by chester
  444. // CARDbRadioPowerOff(pDevice);
  445. s_bCommandComplete(pDevice);
  446. break;
  447. case WLAN_DISASSOCIATE_WAIT :
  448. // wait all Control TD complete
  449. if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
  450. vCommandTimerWait((void *)pDevice, 10);
  451. spin_unlock_irq(&pDevice->lock);
  452. return;
  453. }
  454. //2008-09-02 <mark> by chester
  455. // CARDbRadioPowerOff(pDevice);
  456. s_bCommandComplete(pDevice);
  457. break;
  458. case WLAN_CMD_SSID_START:
  459. pDevice->byReAssocCount = 0;
  460. if (pDevice->bRadioOff == true) {
  461. s_bCommandComplete(pDevice);
  462. spin_unlock_irq(&pDevice->lock);
  463. return;
  464. }
  465. //printk("chester-currmode=%d\n",pMgmt->eCurrMode);
  466. printk("chester-abyDesireSSID=%s\n",((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
  467. //memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
  468. //((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
  469. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
  470. pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  471. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
  472. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
  473. if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
  474. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
  475. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
  476. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
  477. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
  478. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
  479. }
  480. if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
  481. ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
  482. if (pItemSSID->len == pItemSSIDCurr->len) {
  483. if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
  484. s_bCommandComplete(pDevice);
  485. spin_unlock_irq(&pDevice->lock);
  486. return;
  487. }
  488. }
  489. netif_stop_queue(pDevice->dev);
  490. pDevice->bLinkPass = false;
  491. }
  492. // set initial state
  493. pMgmt->eCurrState = WMAC_STATE_IDLE;
  494. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  495. PSvDisablePowerSaving((void *)pDevice);
  496. BSSvClearNodeDBTable(pDevice, 0);
  497. vMgrJoinBSSBegin((void *)pDevice, &Status);
  498. // if Infra mode
  499. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
  500. // Call mgr to begin the deauthentication
  501. // reason = (3) because sta has left ESS
  502. if (pMgmt->eCurrState>= WMAC_STATE_AUTH) {
  503. vMgrDeAuthenBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
  504. }
  505. // Call mgr to begin the authentication
  506. vMgrAuthenBeginSta((void *)pDevice, pMgmt, &Status);
  507. if (Status == CMD_STATUS_SUCCESS) {
  508. pDevice->byLinkWaitCount = 0;
  509. pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
  510. vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT);
  511. spin_unlock_irq(&pDevice->lock);
  512. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
  513. return;
  514. }
  515. }
  516. // if Adhoc mode
  517. else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  518. if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
  519. if (netif_queue_stopped(pDevice->dev)){
  520. netif_wake_queue(pDevice->dev);
  521. }
  522. pDevice->bLinkPass = true;
  523. pMgmt->sNodeDBTable[0].bActive = true;
  524. pMgmt->sNodeDBTable[0].uInActiveCount = 0;
  525. bClearBSSID_SCAN(pDevice);
  526. }
  527. else {
  528. // start own IBSS
  529. vMgrCreateOwnIBSS((void *)pDevice, &Status);
  530. if (Status != CMD_STATUS_SUCCESS){
  531. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
  532. }
  533. BSSvAddMulticastNode(pDevice);
  534. }
  535. }
  536. // if SSID not found
  537. else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
  538. if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
  539. pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
  540. // start own IBSS
  541. vMgrCreateOwnIBSS((void *)pDevice, &Status);
  542. if (Status != CMD_STATUS_SUCCESS){
  543. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_IBSS_CREATE fail ! \n");
  544. }
  545. BSSvAddMulticastNode(pDevice);
  546. if (netif_queue_stopped(pDevice->dev)){
  547. netif_wake_queue(pDevice->dev);
  548. }
  549. pDevice->bLinkPass = true;
  550. }
  551. else {
  552. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
  553. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  554. // if(pDevice->bWPASuppWextEnabled == true)
  555. {
  556. union iwreq_data wrqu;
  557. memset(&wrqu, 0, sizeof (wrqu));
  558. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  559. printk("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
  560. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  561. }
  562. #endif
  563. }
  564. }
  565. s_bCommandComplete(pDevice);
  566. break;
  567. case WLAN_AUTHENTICATE_WAIT :
  568. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
  569. if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
  570. // Call mgr to begin the association
  571. pDevice->byLinkWaitCount = 0;
  572. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
  573. vMgrAssocBeginSta((void *)pDevice, pMgmt, &Status);
  574. if (Status == CMD_STATUS_SUCCESS) {
  575. pDevice->byLinkWaitCount = 0;
  576. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
  577. pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
  578. vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT);
  579. spin_unlock_irq(&pDevice->lock);
  580. return;
  581. }
  582. }
  583. else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
  584. printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
  585. }
  586. else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
  587. pDevice->byLinkWaitCount ++;
  588. printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
  589. spin_unlock_irq(&pDevice->lock);
  590. vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
  591. return;
  592. }
  593. pDevice->byLinkWaitCount = 0;
  594. #if 0
  595. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  596. // if(pDevice->bWPASuppWextEnabled == true)
  597. {
  598. union iwreq_data wrqu;
  599. memset(&wrqu, 0, sizeof (wrqu));
  600. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  601. printk("wireless_send_event--->SIOCGIWAP(disassociated:AUTHENTICATE_WAIT_timeout)\n");
  602. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  603. }
  604. #endif
  605. #endif
  606. s_bCommandComplete(pDevice);
  607. break;
  608. case WLAN_ASSOCIATE_WAIT :
  609. if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
  610. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
  611. if (pDevice->ePSMode != WMAC_POWER_CAM) {
  612. PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
  613. }
  614. if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
  615. KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
  616. }
  617. pDevice->bLinkPass = true;
  618. pDevice->byLinkWaitCount = 0;
  619. pDevice->byReAssocCount = 0;
  620. bClearBSSID_SCAN(pDevice);
  621. if (pDevice->byFOETuning) {
  622. BBvSetFOE(pDevice->PortOffset);
  623. PSbSendNullPacket(pDevice);
  624. }
  625. if (netif_queue_stopped(pDevice->dev)){
  626. netif_wake_queue(pDevice->dev);
  627. }
  628. #ifdef TxInSleep
  629. if(pDevice->IsTxDataTrigger != false) { //TxDataTimer is not triggered at the first time
  630. // printk("Re-initial TxDataTimer****\n");
  631. del_timer(&pDevice->sTimerTxData);
  632. init_timer(&pDevice->sTimerTxData);
  633. pDevice->sTimerTxData.data = (unsigned long) pDevice;
  634. pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
  635. pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
  636. pDevice->fTxDataInSleep = false;
  637. pDevice->nTxDataTimeCout = 0;
  638. }
  639. else {
  640. // printk("mike:-->First time triger TimerTxData InSleep\n");
  641. }
  642. pDevice->IsTxDataTrigger = true;
  643. add_timer(&pDevice->sTimerTxData);
  644. #endif
  645. }
  646. else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
  647. printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
  648. }
  649. else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
  650. pDevice->byLinkWaitCount ++;
  651. printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
  652. spin_unlock_irq(&pDevice->lock);
  653. vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
  654. return;
  655. }
  656. pDevice->byLinkWaitCount = 0;
  657. #if 0
  658. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  659. // if(pDevice->bWPASuppWextEnabled == true)
  660. {
  661. union iwreq_data wrqu;
  662. memset(&wrqu, 0, sizeof (wrqu));
  663. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  664. printk("wireless_send_event--->SIOCGIWAP(disassociated:ASSOCIATE_WAIT_timeout)\n");
  665. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  666. }
  667. #endif
  668. #endif
  669. s_bCommandComplete(pDevice);
  670. break;
  671. case WLAN_CMD_AP_MODE_START :
  672. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
  673. if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
  674. del_timer(&pMgmt->sTimerSecondCallback);
  675. pMgmt->eCurrState = WMAC_STATE_IDLE;
  676. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  677. pDevice->bLinkPass = false;
  678. if (pDevice->bEnableHostWEP == true)
  679. BSSvClearNodeDBTable(pDevice, 1);
  680. else
  681. BSSvClearNodeDBTable(pDevice, 0);
  682. pDevice->uAssocCount = 0;
  683. pMgmt->eCurrState = WMAC_STATE_IDLE;
  684. pDevice->bFixRate = false;
  685. vMgrCreateOwnIBSS((void *)pDevice, &Status);
  686. if (Status != CMD_STATUS_SUCCESS){
  687. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " vMgrCreateOwnIBSS fail ! \n");
  688. }
  689. // alway turn off unicast bit
  690. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
  691. pDevice->byRxMode &= ~RCR_UNICAST;
  692. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
  693. BSSvAddMulticastNode(pDevice);
  694. if (netif_queue_stopped(pDevice->dev)){
  695. netif_wake_queue(pDevice->dev);
  696. }
  697. pDevice->bLinkPass = true;
  698. add_timer(&pMgmt->sTimerSecondCallback);
  699. }
  700. s_bCommandComplete(pDevice);
  701. break;
  702. case WLAN_CMD_TX_PSPACKET_START :
  703. // DTIM Multicast tx
  704. if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
  705. while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
  706. if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
  707. pMgmt->abyPSTxMap[0] &= ~byMask[0];
  708. pDevice->bMoreData = false;
  709. }
  710. else {
  711. pDevice->bMoreData = true;
  712. }
  713. if (!device_dma0_xmit(pDevice, skb, 0)) {
  714. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
  715. }
  716. pMgmt->sNodeDBTable[0].wEnQueueCnt--;
  717. }
  718. }
  719. // PS nodes tx
  720. for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
  721. if (pMgmt->sNodeDBTable[ii].bActive &&
  722. pMgmt->sNodeDBTable[ii].bRxPSPoll) {
  723. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
  724. ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
  725. while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
  726. if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
  727. // clear tx map
  728. pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
  729. ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
  730. pDevice->bMoreData = false;
  731. }
  732. else {
  733. pDevice->bMoreData = true;
  734. }
  735. if (!device_dma0_xmit(pDevice, skb, ii)) {
  736. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
  737. }
  738. pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
  739. // check if sta ps enable, wait next pspoll
  740. // if sta ps disable, send all pending buffers.
  741. if (pMgmt->sNodeDBTable[ii].bPSEnable)
  742. break;
  743. }
  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. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
  749. }
  750. pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
  751. }
  752. }
  753. s_bCommandComplete(pDevice);
  754. break;
  755. case WLAN_CMD_RADIO_START :
  756. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
  757. if (pDevice->bRadioCmd == true)
  758. CARDbRadioPowerOn(pDevice);
  759. else
  760. CARDbRadioPowerOff(pDevice);
  761. s_bCommandComplete(pDevice);
  762. break;
  763. case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE :
  764. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
  765. // wait all TD complete
  766. if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
  767. vCommandTimerWait((void *)pDevice, 10);
  768. spin_unlock_irq(&pDevice->lock);
  769. return;
  770. }
  771. if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
  772. vCommandTimerWait((void *)pDevice, 10);
  773. spin_unlock_irq(&pDevice->lock);
  774. return;
  775. }
  776. pDevice->byBBVGACurrent = pDevice->byBBVGANew;
  777. BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
  778. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
  779. s_bCommandComplete(pDevice);
  780. break;
  781. default :
  782. s_bCommandComplete(pDevice);
  783. break;
  784. } //switch
  785. spin_unlock_irq(&pDevice->lock);
  786. return;
  787. }
  788. static
  789. bool
  790. s_bCommandComplete (
  791. PSDevice pDevice
  792. )
  793. {
  794. PWLAN_IE_SSID pSSID;
  795. bool bRadioCmd = false;
  796. //unsigned short wDeAuthenReason = 0;
  797. bool bForceSCAN = true;
  798. PSMgmtObject pMgmt = pDevice->pMgmt;
  799. pDevice->eCommandState = WLAN_CMD_IDLE;
  800. if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
  801. //Command Queue Empty
  802. pDevice->bCmdRunning = false;
  803. return true;
  804. }
  805. else {
  806. pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
  807. pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
  808. bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
  809. bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
  810. ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
  811. pDevice->cbFreeCmdQueue++;
  812. pDevice->bCmdRunning = true;
  813. switch ( pDevice->eCommand ) {
  814. case WLAN_CMD_BSSID_SCAN:
  815. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
  816. pDevice->eCommandState = WLAN_CMD_SCAN_START;
  817. pMgmt->uScanChannel = 0;
  818. if (pSSID->len != 0) {
  819. memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  820. } else {
  821. memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  822. }
  823. /*
  824. if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
  825. if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
  826. ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
  827. pDevice->eCommandState = WLAN_CMD_IDLE;
  828. }
  829. }
  830. */
  831. break;
  832. case WLAN_CMD_SSID:
  833. pDevice->eCommandState = WLAN_CMD_SSID_START;
  834. if (pSSID->len > WLAN_SSID_MAXLEN)
  835. pSSID->len = WLAN_SSID_MAXLEN;
  836. if (pSSID->len != 0)
  837. memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  838. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
  839. break;
  840. case WLAN_CMD_DISASSOCIATE:
  841. pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
  842. break;
  843. case WLAN_CMD_RX_PSPOLL:
  844. pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
  845. break;
  846. case WLAN_CMD_RUN_AP:
  847. pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
  848. break;
  849. case WLAN_CMD_RADIO:
  850. pDevice->eCommandState = WLAN_CMD_RADIO_START;
  851. pDevice->bRadioCmd = bRadioCmd;
  852. break;
  853. case WLAN_CMD_CHANGE_BBSENSITIVITY:
  854. pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
  855. break;
  856. default:
  857. break;
  858. }
  859. vCommandTimerWait((void *)pDevice, 0);
  860. }
  861. return true;
  862. }
  863. bool bScheduleCommand (
  864. void *hDeviceContext,
  865. CMD_CODE eCommand,
  866. unsigned char *pbyItem0
  867. )
  868. {
  869. PSDevice pDevice = (PSDevice)hDeviceContext;
  870. if (pDevice->cbFreeCmdQueue == 0) {
  871. return (false);
  872. }
  873. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
  874. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
  875. memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  876. if (pbyItem0 != NULL) {
  877. switch (eCommand) {
  878. case WLAN_CMD_BSSID_SCAN:
  879. memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
  880. pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  881. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
  882. break;
  883. case WLAN_CMD_SSID:
  884. memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
  885. pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  886. break;
  887. case WLAN_CMD_DISASSOCIATE:
  888. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
  889. break;
  890. /*
  891. case WLAN_CMD_DEAUTH:
  892. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((unsigned short *)pbyItem0);
  893. break;
  894. */
  895. case WLAN_CMD_RX_PSPOLL:
  896. break;
  897. case WLAN_CMD_RADIO:
  898. pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
  899. break;
  900. case WLAN_CMD_CHANGE_BBSENSITIVITY:
  901. pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
  902. break;
  903. default:
  904. break;
  905. }
  906. }
  907. ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
  908. pDevice->cbFreeCmdQueue--;
  909. if (pDevice->bCmdRunning == false) {
  910. s_bCommandComplete(pDevice);
  911. }
  912. else {
  913. }
  914. return (true);
  915. }
  916. /*
  917. * Description:
  918. * Clear BSSID_SCAN cmd in CMD Queue
  919. *
  920. * Parameters:
  921. * In:
  922. * hDeviceContext - Pointer to the adapter
  923. * eCommand - Command
  924. * Out:
  925. * none
  926. *
  927. * Return Value: true if success; otherwise false
  928. *
  929. */
  930. bool bClearBSSID_SCAN (
  931. void *hDeviceContext
  932. )
  933. {
  934. PSDevice pDevice = (PSDevice)hDeviceContext;
  935. unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
  936. unsigned int ii;
  937. if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
  938. for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
  939. if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
  940. pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
  941. ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
  942. if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
  943. break;
  944. }
  945. }
  946. return true;
  947. }
  948. //mike add:reset command timer
  949. void
  950. vResetCommandTimer(
  951. void *hDeviceContext
  952. )
  953. {
  954. PSDevice pDevice = (PSDevice)hDeviceContext;
  955. //delete timer
  956. del_timer(&pDevice->sTimerCommand);
  957. //init timer
  958. init_timer(&pDevice->sTimerCommand);
  959. pDevice->sTimerCommand.data = (unsigned long) pDevice;
  960. pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
  961. pDevice->sTimerCommand.expires = RUN_AT(HZ);
  962. pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
  963. pDevice->uCmdDequeueIdx = 0;
  964. pDevice->uCmdEnqueueIdx = 0;
  965. pDevice->eCommandState = WLAN_CMD_IDLE;
  966. pDevice->bCmdRunning = false;
  967. pDevice->bCmdClear = false;
  968. }
  969. #ifdef TxInSleep
  970. void
  971. BSSvSecondTxData(
  972. void *hDeviceContext
  973. )
  974. {
  975. PSDevice pDevice = (PSDevice)hDeviceContext;
  976. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  977. pDevice->nTxDataTimeCout++;
  978. if(pDevice->nTxDataTimeCout<4) //don't tx data if timer less than 40s
  979. {
  980. // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
  981. // (int)pDevice->nTxDataTimeCout);
  982. pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
  983. add_timer(&pDevice->sTimerTxData);
  984. return;
  985. }
  986. spin_lock_irq(&pDevice->lock);
  987. #if 1
  988. if(((pDevice->bLinkPass ==true)&&(pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
  989. (pDevice->fWPA_Authened == true)) { //wpa linking
  990. #else
  991. if(pDevice->bLinkPass ==true) {
  992. #endif
  993. // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
  994. pDevice->fTxDataInSleep = true;
  995. PSbSendNullPacket(pDevice); //send null packet
  996. pDevice->fTxDataInSleep = false;
  997. }
  998. spin_unlock_irq(&pDevice->lock);
  999. pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
  1000. add_timer(&pDevice->sTimerTxData);
  1001. return;
  1002. }
  1003. #endif