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