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