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