blob: 4869107a2bcaa479195525c0351aadc1b8ace977 [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
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: ioctl.c
20 *
21 * Purpose: private ioctl functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Auguest 20, 2003
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33
34#if !defined(__IOCTL_H__)
35#include "ioctl.h"
36#endif
37#if !defined(__IOCMD_H__)
38#include "iocmd.h"
39#endif
40#if !defined(__MAC_H__)
41#include "mac.h"
42#endif
43#if !defined(__CARD_H__)
44#include "card.h"
45#endif
46#if !defined(__HOSTAP_H__)
47#include "hostap.h"
48#endif
49#if !defined(__UMEM_H__)
50#include "umem.h"
51#endif
52#if !defined(__WPACTL_H__)
53#include "wpactl.h"
54#endif
55#if !defined(__RF_H__)
56#include "rf.h"
57#endif
58
59
60/*--------------------- Static Definitions -------------------------*/
61
62/*--------------------- Static Classes ----------------------------*/
63
64/*--------------------- Static Variables --------------------------*/
65//static int msglevel =MSG_LEVEL_DEBUG;
66static int msglevel =MSG_LEVEL_INFO;
67
68/*--------------------- Static Functions --------------------------*/
69
70#ifdef WPA_SM_Transtatus
71 SWPAResult wpa_Result;
72#endif
73
74
75/*--------------------- Export Variables --------------------------*/
76
77int private_ioctl(PSDevice pDevice, struct ifreq *rq) {
78
79 PSCmdRequest pReq = (PSCmdRequest)rq;
80 PSMgmtObject pMgmt = pDevice->pMgmt;
81 int result = 0;
82 PWLAN_IE_SSID pItemSSID;
83 SCmdBSSJoin sJoinCmd;
84 SCmdZoneTypeSet sZoneTypeCmd;
85 SCmdScan sScanCmd;
86 SCmdStartAP sStartAPCmd;
87 SCmdSetWEP sWEPCmd;
88 SCmdValue sValue;
89 SBSSIDList sList;
90 SNodeList sNodeList;
91 PSBSSIDList pList;
92 PSNodeList pNodeList;
93 UINT cbListCount;
94 PKnownBSS pBSS;
95 PKnownNodeDB pNode;
96 UINT ii, jj;
97 SCmdLinkStatus sLinkStatus;
98 BYTE abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
99 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
100 DWORD dwKeyIndex= 0;
101 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
102 LONG ldBm;
103
104
105 pReq->wResult = 0;
106
107 switch(pReq->wCmdCode) {
108
109 case WLAN_CMD_BSS_SCAN:
110
111 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin \n");
112 if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
113 result = -EFAULT;
114 break;
115 };
116
117 pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
118 if (pItemSSID->len != 0) {
119 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
120 memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
121 }
122
123 if (pDevice->bMACSuspend == TRUE) {
124 if (pDevice->bRadioOff == TRUE)
125 CARDbRadioPowerOn(pDevice);
126 vMgrTimerInit(pDevice);
127 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
128 add_timer(&pMgmt->sTimerSecondCallback);
129 pDevice->bMACSuspend = FALSE;
130 }
131 spin_lock_irq(&pDevice->lock);
132 if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
133 BSSvClearBSSList((HANDLE)pDevice, FALSE);
134 else
135 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
136
137 if (pItemSSID->len != 0)
138 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
139 else
140 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
141 spin_unlock_irq(&pDevice->lock);
142 break;
143
144 case WLAN_CMD_ZONETYPE_SET:
145 //mike add :cann't support.
146 result=-EOPNOTSUPP;
147 break;
148
149 if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
150 result = -EFAULT;
151 break;
152 };
153
154 if(sZoneTypeCmd.bWrite==TRUE) {
155 //////write zonetype
156 if(sZoneTypeCmd.ZoneType == ZoneType_USA) {
157 //set to USA
158 printk("set_ZoneType:USA\n");
159 }
160 else if(sZoneTypeCmd.ZoneType == ZoneType_Japan) {
161 //set to Japan
162 printk("set_ZoneType:Japan\n");
163 }
164 else if(sZoneTypeCmd.ZoneType == ZoneType_Europe) {
165 //set to Europe
166 printk("set_ZoneType:Europe\n");
167 }
168 }
169 else {
170 ///////read zonetype
171 BYTE zonetype=0;
172
173
174 if(zonetype == 0x00) { //USA
175 sZoneTypeCmd.ZoneType = ZoneType_USA;
176 }
177 else if(zonetype == 0x01) { //Japan
178 sZoneTypeCmd.ZoneType = ZoneType_Japan;
179 }
180 else if(zonetype == 0x02) { //Europe
181 sZoneTypeCmd.ZoneType = ZoneType_Europe;
182 }
183 else { //Unknow ZoneType
184 printk("Error:ZoneType[%x] Unknown ???\n",zonetype);
185 result = -EFAULT;
186 break;
187 }
188 if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
189 result = -EFAULT;
190 break;
191 };
192 }
193
194 break;
195
196 case WLAN_CMD_BSS_JOIN:
197
198 if (pDevice->bMACSuspend == TRUE) {
199 if (pDevice->bRadioOff == TRUE)
200 CARDbRadioPowerOn(pDevice);
201 vMgrTimerInit(pDevice);
202 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
203 add_timer(&pMgmt->sTimerSecondCallback);
204 pDevice->bMACSuspend = FALSE;
205 }
206
207 if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
208 result = -EFAULT;
209 break;
210 };
211
212 pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
213 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
214 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
215 if (sJoinCmd.wBSSType == ADHOC) {
216 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
217 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to adhoc mode\n");
218 }
219 else {
220 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
221 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to STA mode\n");
222 }
223 if (sJoinCmd.bPSEnable == TRUE) {
224 pDevice->ePSMode = WMAC_POWER_FAST;
225// pDevice->ePSMode = WMAC_POWER_MAX;
226 pMgmt->wListenInterval = 2;
227 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving On\n");
228 }
229 else {
230 pDevice->ePSMode = WMAC_POWER_CAM;
231 pMgmt->wListenInterval = 1;
232 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving Off \n");
233 }
234
235 if (sJoinCmd.bShareKeyAuth == TRUE){
236 pMgmt->bShareKeyAlgorithm = TRUE;
237 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
238 }
239 else {
240 pMgmt->bShareKeyAlgorithm = FALSE;
241 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
242 }
243 pDevice->uChannel = sJoinCmd.uChannel;
244 netif_stop_queue(pDevice->dev);
245 spin_lock_irq(&pDevice->lock);
246 pMgmt->eCurrState = WMAC_STATE_IDLE;
247 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
248 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
249 spin_unlock_irq(&pDevice->lock);
250 break;
251
252 case WLAN_CMD_SET_WEP:
253
254 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WEP Key. \n");
255 memset(&sWEPCmd, 0 ,sizeof(SCmdSetWEP));
256 if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
257 result = -EFAULT;
258 break;
259 };
260 if (sWEPCmd.bEnableWep != TRUE) {
261 pDevice->bEncryptionEnable = FALSE;
262 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
263 MACvDisableDefaultKey(pDevice->PortOffset);
264 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP function disable. \n");
265 break;
266 }
267
268 for (ii = 0; ii < WLAN_WEP_NKEYS; ii ++) {
269 if (sWEPCmd.bWepKeyAvailable[ii]) {
270 if (ii == sWEPCmd.byKeyIndex)
271 //2006-1123-02,<Modify> by EinsnLiu
272 //Evaluate the "dwKeyIndex" error
273 // dwKeyIndex |= (1 << 31);
274 dwKeyIndex =ii|(1 << 31);
275 else
276 dwKeyIndex = ii;
277
278 KeybSetDefaultKey(&(pDevice->sKey),
279 dwKeyIndex,
280 sWEPCmd.auWepKeyLength[ii],
281 NULL,
282 (PBYTE)&sWEPCmd.abyWepKey[ii][0],
283 KEY_CTL_WEP,
284 pDevice->PortOffset,
285 pDevice->byLocalID);
286 }
287 }
288 pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
289 pDevice->bTransmitKey = TRUE;
290 pDevice->bEncryptionEnable = TRUE;
291 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
292
293 break;
294
295 case WLAN_CMD_GET_LINK:
296 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_GET_LINK status. \n");
297
298 memset(sLinkStatus.abySSID, 0 , WLAN_SSID_MAXLEN + 1);
299
300 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
301 sLinkStatus.wBSSType = ADHOC;
302 else
303 sLinkStatus.wBSSType = INFRA;
304
305 if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
306 sLinkStatus.byState = ADHOC_JOINTED;
307 else
308 sLinkStatus.byState = ADHOC_STARTED;
309
310 sLinkStatus.uChannel = pMgmt->uCurrChannel;
311 if (pDevice->bLinkPass == TRUE) {
312 sLinkStatus.bLink = TRUE;
313 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
314 memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
315 memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
316 sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
317 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Link Success ! \n");
318 }
319 else {
320 sLinkStatus.bLink = FALSE;
321 }
322 if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
323 result = -EFAULT;
324 break;
325 };
326
327 break;
328
329 case WLAN_CMD_GET_LISTLEN:
330 cbListCount = 0;
331 pBSS = &(pMgmt->sBSSList[0]);
332 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
333 pBSS = &(pMgmt->sBSSList[ii]);
334 if (!pBSS->bActive)
335 continue;
336 cbListCount++;
337 };
338 sList.uItem = cbListCount;
339 if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
340 result = -EFAULT;
341 break;
342 };
343 pReq->wResult = 0;
344 break;
345
346 case WLAN_CMD_GET_LIST:
347 if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
348 result = -EFAULT;
349 break;
350 };
351 pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), (int)GFP_ATOMIC);
352 if (pList == NULL) {
353 result = -ENOMEM;
354 break;
355 }
356 pList->uItem = sList.uItem;
357 pBSS = &(pMgmt->sBSSList[0]);
358 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
359 pBSS = &(pMgmt->sBSSList[jj]);
360 if (pBSS->bActive) {
361 pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
362 pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
363 pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
364// pList->sBSSIDList[ii].uRSSI = pBSS->uRSSI;
365 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
366 pList->sBSSIDList[ii].uRSSI = (UINT)ldBm;
367 memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
368 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
369 memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
370 memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
371 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
372 pList->sBSSIDList[ii].byNetType = INFRA;
373 }
374 else {
375 pList->sBSSIDList[ii].byNetType = ADHOC;
376 }
377 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
378 pList->sBSSIDList[ii].bWEPOn = TRUE;
379 }
380 else {
381 pList->sBSSIDList[ii].bWEPOn = FALSE;
382 }
383 ii ++;
384 if (ii >= pList->uItem)
385 break;
386 }
387 }
388
389 if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
390 result = -EFAULT;
391 break;
392 };
393 kfree(pList);
394 pReq->wResult = 0;
395 break;
396
397 case WLAN_CMD_GET_MIB:
398 if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
399 result = -EFAULT;
400 break;
401 };
402 break;
403
404 case WLAN_CMD_GET_STAT:
405 if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
406 result = -EFAULT;
407 break;
408 };
409 break;
410 case WLAN_CMD_STOP_MAC:
411
412 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n");
413 netif_stop_queue(pDevice->dev);
414
415 spin_lock_irq(&pDevice->lock);
416 if (pDevice->bRadioOff == FALSE) {
417 CARDbRadioPowerOff(pDevice);
418 }
419 pDevice->bLinkPass = FALSE;
420 memset(pMgmt->abyCurrBSSID, 0, 6);
421 pMgmt->eCurrState = WMAC_STATE_IDLE;
422 del_timer(&pDevice->sTimerCommand);
423 del_timer(&pMgmt->sTimerSecondCallback);
424 pDevice->bCmdRunning = FALSE;
425 pDevice->bMACSuspend = TRUE;
426 MACvIntDisable(pDevice->PortOffset);
427 spin_unlock_irq(&pDevice->lock);
428
429 break;
430
431 case WLAN_CMD_START_MAC:
432
433 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_START_MAC\n");
434
435 if (pDevice->bMACSuspend == TRUE) {
436 if (pDevice->bRadioOff == TRUE)
437 CARDbRadioPowerOn(pDevice);
438 vMgrTimerInit(pDevice);
439 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
440 add_timer(&pMgmt->sTimerSecondCallback);
441 pDevice->bMACSuspend = FALSE;
442 }
443 break;
444
445 case WLAN_CMD_SET_HOSTAPD:
446
447 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD\n");
448
449 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
450 result = -EFAULT;
451 break;
452 };
453 if (sValue.dwValue == 1) {
454 if (hostap_set_hostapd(pDevice, 1, 1) == 0){
455 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HOSTAP\n");
456 }
457 else {
458 result = -EFAULT;
459 break;
460 }
461 }
462 else {
463 hostap_set_hostapd(pDevice, 0, 1);
464 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HOSTAP\n");
465 }
466
467 break;
468
469 case WLAN_CMD_SET_HOSTAPD_STA:
470
471 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD_STA\n");
472
473 break;
474 case WLAN_CMD_SET_802_1X:
475
476 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_802_1X\n");
477 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
478 result = -EFAULT;
479 break;
480 };
481
482 if (sValue.dwValue == 1) {
483 pDevice->bEnable8021x = TRUE;
484 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable 802.1x\n");
485 }
486 else {
487 pDevice->bEnable8021x = FALSE;
488 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable 802.1x\n");
489 }
490
491 break;
492
493
494 case WLAN_CMD_SET_HOST_WEP:
495
496 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOST_WEP\n");
497 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
498 result = -EFAULT;
499 break;
500 };
501
502 if (sValue.dwValue == 1) {
503 pDevice->bEnableHostWEP = TRUE;
504 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HostWEP\n");
505 }
506 else {
507 pDevice->bEnableHostWEP = FALSE;
508 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HostWEP\n");
509 }
510
511 break;
512
513 case WLAN_CMD_SET_WPA:
514 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WPA\n");
515
516 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
517 result = -EFAULT;
518 break;
519 };
520 if (sValue.dwValue == 1) {
521 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n");
522 memcpy(pDevice->wpadev->dev_addr, pDevice->dev->dev_addr, U_ETHER_ADDR_LEN);
523 pDevice->bWPADEVUp = TRUE;
524 }
525 else {
526 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n");
527 pDevice->bWPADEVUp = FALSE;
528 }
529
530 break;
531
532 case WLAN_CMD_AP_START:
533
534 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_AP_START\n");
535 if (pDevice->bRadioOff == TRUE) {
536 CARDbRadioPowerOn(pDevice);
537 vMgrTimerInit(pDevice);
538 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
539 add_timer(&pMgmt->sTimerSecondCallback);
540 }
541 if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
542 result = -EFAULT;
543 break;
544 };
545
546 if (sStartAPCmd.wBSSType == AP) {
547 pMgmt->eConfigMode = WMAC_CONFIG_AP;
548 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to AP mode\n");
549 }
550 else {
551 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct BSS type not set to AP mode\n");
552 result = -EFAULT;
553 break;
554 }
555
556
557 if (sStartAPCmd.wBBPType == PHY80211g) {
558 pMgmt->byAPBBType = PHY_TYPE_11G;
559 }
560 else if (sStartAPCmd.wBBPType == PHY80211a) {
561 pMgmt->byAPBBType = PHY_TYPE_11A;
562 }
563 else {
564 pMgmt->byAPBBType = PHY_TYPE_11B;
565 }
566
567 pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
568 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
569 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
570
571 if ((sStartAPCmd.uChannel > 0)&&(sStartAPCmd.uChannel <= 14))
572 pDevice->uChannel = sStartAPCmd.uChannel;
573
574 if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
575 pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
576 else
577 pMgmt->wIBSSBeaconPeriod = 100;
578
579 if (sStartAPCmd.bShareKeyAuth == TRUE){
580 pMgmt->bShareKeyAlgorithm = TRUE;
581 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
582 }
583 else {
584 pMgmt->bShareKeyAlgorithm = FALSE;
585 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
586 }
587 memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);
588
589 if (sStartAPCmd.byBasicRate & BIT3) {
590 pMgmt->abyIBSSSuppRates[2] |= BIT7;
591 pMgmt->abyIBSSSuppRates[3] |= BIT7;
592 pMgmt->abyIBSSSuppRates[4] |= BIT7;
593 pMgmt->abyIBSSSuppRates[5] |= BIT7;
594 }else if (sStartAPCmd.byBasicRate & BIT2) {
595 pMgmt->abyIBSSSuppRates[2] |= BIT7;
596 pMgmt->abyIBSSSuppRates[3] |= BIT7;
597 pMgmt->abyIBSSSuppRates[4] |= BIT7;
598 }else if (sStartAPCmd.byBasicRate & BIT1) {
599 pMgmt->abyIBSSSuppRates[2] |= BIT7;
600 pMgmt->abyIBSSSuppRates[3] |= BIT7;
601 }else if (sStartAPCmd.byBasicRate & BIT1) {
602 pMgmt->abyIBSSSuppRates[2] |= BIT7;
603 }else {
604 //default 1,2M
605 pMgmt->abyIBSSSuppRates[2] |= BIT7;
606 pMgmt->abyIBSSSuppRates[3] |= BIT7;
607 }
608
609 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %x %x %x %x\n",
610 pMgmt->abyIBSSSuppRates[2],
611 pMgmt->abyIBSSSuppRates[3],
612 pMgmt->abyIBSSSuppRates[4],
613 pMgmt->abyIBSSSuppRates[5]
614 );
615
616 netif_stop_queue(pDevice->dev);
617 spin_lock_irq(&pDevice->lock);
618 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
619 spin_unlock_irq(&pDevice->lock);
620 break;
621
622 case WLAN_CMD_GET_NODE_CNT:
623
624 cbListCount = 0;
625 pNode = &(pMgmt->sNodeDBTable[0]);
626 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
627 pNode = &(pMgmt->sNodeDBTable[ii]);
628 if (!pNode->bActive)
629 continue;
630 cbListCount++;
631 };
632
633 sNodeList.uItem = cbListCount;
634 if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
635 result = -EFAULT;
636 break;
637 };
638 pReq->wResult = 0;
639 break;
640
641 case WLAN_CMD_GET_NODE_LIST:
642
643 if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
644 result = -EFAULT;
645 break;
646 };
647 pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC);
648 if (pNodeList == NULL) {
649 result = -ENOMEM;
650 break;
651 }
652 pNodeList->uItem = sNodeList.uItem;
653 pNode = &(pMgmt->sNodeDBTable[0]);
654 for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
655 pNode = &(pMgmt->sNodeDBTable[ii]);
656 if (pNode->bActive) {
657 pNodeList->sNodeList[jj].wAID = pNode->wAID;
658 memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
659 pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
660 pNodeList->sNodeList[jj].wInActiveCount = (WORD)pNode->uInActiveCount;
661 pNodeList->sNodeList[jj].wEnQueueCnt = (WORD)pNode->wEnQueueCnt;
662 pNodeList->sNodeList[jj].wFlags = (WORD)pNode->dwFlags;
663 pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
664 pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
665 pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
666 memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
667 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
668 pNodeList->sNodeList[jj].abyWepKey[0],
669 pNodeList->sNodeList[jj].abyWepKey[1],
670 pNodeList->sNodeList[jj].abyWepKey[2],
671 pNodeList->sNodeList[jj].abyWepKey[3],
672 pNodeList->sNodeList[jj].abyWepKey[4]
673 );
674 pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
675 pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
676 pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
677 pNodeList->sNodeList[jj].wFailureRatio = (WORD)pNode->uFailureRatio;
678 jj ++;
679 if (jj >= pNodeList->uItem)
680 break;
681 }
682 };
683 if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
684 result = -EFAULT;
685 break;
686 };
687 kfree(pNodeList);
688 pReq->wResult = 0;
689 break;
690
691#ifdef WPA_SM_Transtatus
692 case 0xFF:
693 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
694 wpa_Result.proto = 0;
695 wpa_Result.key_mgmt = 0;
696 wpa_Result.eap_type = 0;
697 wpa_Result.authenticated = FALSE;
698 pDevice->fWPA_Authened = FALSE;
699 if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
700 result = -EFAULT;
701 break;
702 }
703
704 if(wpa_Result.authenticated==TRUE) {
705 #ifdef SndEvt_ToAPI
706 {
707 union iwreq_data wrqu;
708
709 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
710
711 memset(&wrqu, 0, sizeof(wrqu));
712 wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
713 wrqu.data.length =pItemSSID->len;
714 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
715 }
716 #endif
717 pDevice->fWPA_Authened = TRUE; //is sucessful peer to wpa_Result.authenticated?
718}
719
720 //printk("get private wpa_supplicant announce WPA SM\n");
721 //printk("wpa-->ifname=%s\n",wpa_Result.ifname);
722 //printk("wpa-->proto=%d\n",wpa_Result.proto);
723 //printk("wpa-->key-mgmt=%d\n",wpa_Result.key_mgmt);
724 //printk("wpa-->eap_type=%d\n",wpa_Result.eap_type);
725 //printk("wpa-->authenticated is %s\n",(wpa_Result.authenticated==TRUE)?"TRUE":"FALSE");
726
727 pReq->wResult = 0;
728 break;
729#endif
730
731
732 default:
733 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Private command not support..\n");
734 }
735
736 return result;
737}
738
739/*
740VOID
741vConfigWEPKey (
742 IN PSDevice pDevice,
743 IN DWORD dwKeyIndex,
744 IN PBYTE pbyKey,
745 IN ULONG uKeyLength
746 )
747{
748 int ii;
749
750
751 ZERO_MEMORY(&pDevice->abyWepKey[dwKeyIndex][0], WLAN_WEPMAX_KEYLEN);
752 MEMvCopy(&pDevice->abyWepKey[dwKeyIndex][0], pbyKey, uKeyLength);
753
754 pDevice->bWepKeyAvailable[dwKeyIndex] = TRUE;
755 pDevice->auWepKeyLength[dwKeyIndex] = uKeyLength;
756
757 MACvSetDefaultKeyEntry(pDevice->PortOffset, uKeyLength, dwKeyIndex,
758 (PDWORD) &(pDevice->abyWepKey[dwKeyIndex][0]), pDevice->byLocalID);
759
760 if (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported) {
761 for(ii=0; ii<MAX_GROUP_KEY; ii++) {
762 if ((pDevice->bWepKeyAvailable[ii] == TRUE) &&
763 (pDevice->auWepKeyLength[ii] == WLAN_WEP232_KEYLEN)) {
764 pDevice->uCurrentWEPMode = TX_WEP_SW232;
765 MACvDisableDefaultKey(pDevice->PortOffset);
766 break;
767 }
768 }
769 if ((ii == MAX_GROUP_KEY) &&
770 (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported)) {
771 MACvEnableDefaultKey(pDevice->PortOffset, pDevice->byLocalID);
772 }
773 }
774}
775*/