2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
21 * Purpose: private ioctl functions
25 * Date: Auguest 20, 2003
41 #ifdef WPA_SM_Transtatus
42 SWPAResult wpa_Result;
45 int private_ioctl(struct vnt_private *pDevice, struct ifreq *rq)
47 PSCmdRequest pReq = (PSCmdRequest)rq;
48 PSMgmtObject pMgmt = pDevice->pMgmt;
50 PWLAN_IE_SSID pItemSSID;
52 SCmdZoneTypeSet sZoneTypeCmd;
54 SCmdStartAP sStartAPCmd;
61 unsigned int cbListCount;
65 unsigned char abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
66 unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
67 unsigned long dwKeyIndex = 0;
68 unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
73 switch (pReq->wCmdCode) {
74 case WLAN_CMD_BSS_SCAN:
75 pr_debug("WLAN_CMD_BSS_SCAN..begin\n");
76 if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
81 pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
82 if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
84 if (pItemSSID->len != 0) {
85 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
86 memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
89 if (pDevice->bMACSuspend == true) {
90 if (pDevice->bRadioOff == true)
91 CARDbRadioPowerOn(pDevice);
92 vMgrTimerInit(pDevice);
93 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
94 add_timer(&pMgmt->sTimerSecondCallback);
95 pDevice->bMACSuspend = false;
97 spin_lock_irq(&pDevice->lock);
98 if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
99 BSSvClearBSSList((void *)pDevice, false);
101 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
103 if (pItemSSID->len != 0)
104 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
106 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
107 spin_unlock_irq(&pDevice->lock);
110 case WLAN_CMD_ZONETYPE_SET:
111 /* mike add :can't support. */
112 result = -EOPNOTSUPP;
115 if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
120 if (sZoneTypeCmd.bWrite == true) {
122 if (sZoneTypeCmd.ZoneType == ZoneType_USA) {
124 pr_debug("set_ZoneType:USA\n");
125 } else if (sZoneTypeCmd.ZoneType == ZoneType_Japan) {
127 pr_debug("set_ZoneType:Japan\n");
128 } else if (sZoneTypeCmd.ZoneType == ZoneType_Europe) {
130 pr_debug("set_ZoneType:Europe\n");
134 unsigned char zonetype = 0;
136 if (zonetype == 0x00) { /* USA */
137 sZoneTypeCmd.ZoneType = ZoneType_USA;
138 } else if (zonetype == 0x01) { /* Japan */
139 sZoneTypeCmd.ZoneType = ZoneType_Japan;
140 } else if (zonetype == 0x02) { /* Europe */
141 sZoneTypeCmd.ZoneType = ZoneType_Europe;
142 } else { /* Unknown ZoneType */
143 pr_err("Error:ZoneType[%x] Unknown ???\n", zonetype);
147 if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
154 case WLAN_CMD_BSS_JOIN:
155 if (pDevice->bMACSuspend == true) {
156 if (pDevice->bRadioOff == true)
157 CARDbRadioPowerOn(pDevice);
158 vMgrTimerInit(pDevice);
159 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
160 add_timer(&pMgmt->sTimerSecondCallback);
161 pDevice->bMACSuspend = false;
164 if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
169 pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
170 if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
172 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
173 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
174 if (sJoinCmd.wBSSType == ADHOC) {
175 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
176 pr_debug("ioct set to adhoc mode\n");
178 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
179 pr_debug("ioct set to STA mode\n");
181 if (sJoinCmd.bPSEnable == true) {
182 pDevice->ePSMode = WMAC_POWER_FAST;
183 pMgmt->wListenInterval = 2;
184 pr_debug("Power Saving On\n");
186 pDevice->ePSMode = WMAC_POWER_CAM;
187 pMgmt->wListenInterval = 1;
188 pr_debug("Power Saving Off\n");
191 if (sJoinCmd.bShareKeyAuth == true) {
192 pMgmt->bShareKeyAlgorithm = true;
193 pr_debug("Share Key\n");
195 pMgmt->bShareKeyAlgorithm = false;
196 pr_debug("Open System\n");
198 pDevice->uChannel = sJoinCmd.uChannel;
199 netif_stop_queue(pDevice->dev);
200 spin_lock_irq(&pDevice->lock);
201 pMgmt->eCurrState = WMAC_STATE_IDLE;
202 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
203 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
204 spin_unlock_irq(&pDevice->lock);
207 case WLAN_CMD_SET_WEP:
208 pr_debug("WLAN_CMD_SET_WEP Key\n");
209 memset(&sWEPCmd, 0, sizeof(SCmdSetWEP));
210 if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
214 if (sWEPCmd.bEnableWep != true) {
215 pDevice->bEncryptionEnable = false;
216 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
217 MACvDisableDefaultKey(pDevice->PortOffset);
218 pr_debug("WEP function disable\n");
222 for (ii = 0; ii < WLAN_WEP_NKEYS; ii++) {
223 if (sWEPCmd.bWepKeyAvailable[ii]) {
224 if (ii == sWEPCmd.byKeyIndex)
225 dwKeyIndex = ii | (1 << 31);
229 KeybSetDefaultKey(&(pDevice->sKey),
231 sWEPCmd.auWepKeyLength[ii],
233 (unsigned char *)&sWEPCmd.abyWepKey[ii][0],
239 pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
240 pDevice->bTransmitKey = true;
241 pDevice->bEncryptionEnable = true;
242 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
245 case WLAN_CMD_GET_LINK: {
246 SCmdLinkStatus sLinkStatus;
248 pr_debug("WLAN_CMD_GET_LINK status\n");
250 memset(&sLinkStatus, 0, sizeof(sLinkStatus));
252 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
253 sLinkStatus.wBSSType = ADHOC;
255 sLinkStatus.wBSSType = INFRA;
257 if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
258 sLinkStatus.byState = ADHOC_JOINTED;
260 sLinkStatus.byState = ADHOC_STARTED;
262 sLinkStatus.uChannel = pMgmt->uCurrChannel;
263 if (pDevice->bLinkPass == true) {
264 sLinkStatus.bLink = true;
265 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
266 memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
267 memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
268 sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
269 pr_debug(" Link Success!\n");
271 sLinkStatus.bLink = false;
272 sLinkStatus.uLinkRate = 0;
274 if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
280 case WLAN_CMD_GET_LISTLEN:
282 pBSS = &(pMgmt->sBSSList[0]);
283 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
284 pBSS = &(pMgmt->sBSSList[ii]);
289 sList.uItem = cbListCount;
290 if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
297 case WLAN_CMD_GET_LIST:
298 if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
302 if (sList.uItem > (ULONG_MAX - sizeof(SBSSIDList)) / sizeof(SBSSIDItem)) {
306 pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)),
312 pList->uItem = sList.uItem;
313 pBSS = &(pMgmt->sBSSList[0]);
314 for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
315 pBSS = &(pMgmt->sBSSList[jj]);
317 pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
318 pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
319 pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
320 RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
321 pList->sBSSIDList[ii].uRSSI = (unsigned int)ldBm;
322 memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
323 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
324 memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
325 memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
326 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
327 pList->sBSSIDList[ii].byNetType = INFRA;
329 pList->sBSSIDList[ii].byNetType = ADHOC;
331 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
332 pList->sBSSIDList[ii].bWEPOn = true;
334 pList->sBSSIDList[ii].bWEPOn = false;
337 if (ii >= pList->uItem)
342 if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
350 case WLAN_CMD_GET_MIB:
351 if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
357 case WLAN_CMD_GET_STAT:
358 if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
364 case WLAN_CMD_STOP_MAC:
365 pr_debug("WLAN_CMD_STOP_MAC\n");
366 netif_stop_queue(pDevice->dev);
368 spin_lock_irq(&pDevice->lock);
369 if (pDevice->bRadioOff == false)
370 CARDbRadioPowerOff(pDevice);
372 pDevice->bLinkPass = false;
373 memset(pMgmt->abyCurrBSSID, 0, 6);
374 pMgmt->eCurrState = WMAC_STATE_IDLE;
375 del_timer(&pDevice->sTimerCommand);
376 del_timer(&pMgmt->sTimerSecondCallback);
377 pDevice->bCmdRunning = false;
378 pDevice->bMACSuspend = true;
379 MACvIntDisable(pDevice->PortOffset);
380 spin_unlock_irq(&pDevice->lock);
383 case WLAN_CMD_START_MAC:
384 pr_debug("WLAN_CMD_START_MAC\n");
386 if (pDevice->bMACSuspend == true) {
387 if (pDevice->bRadioOff == true)
388 CARDbRadioPowerOn(pDevice);
389 vMgrTimerInit(pDevice);
390 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
391 add_timer(&pMgmt->sTimerSecondCallback);
392 pDevice->bMACSuspend = false;
396 case WLAN_CMD_SET_HOSTAPD:
397 pr_debug("WLAN_CMD_SET_HOSTAPD\n");
399 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
403 if (sValue.dwValue == 1) {
404 if (vt6655_hostap_set_hostapd(pDevice, 1, 1) == 0) {
405 pr_debug("Enable HOSTAP\n");
411 vt6655_hostap_set_hostapd(pDevice, 0, 1);
412 pr_debug("Disable HOSTAP\n");
416 case WLAN_CMD_SET_HOSTAPD_STA:
417 pr_debug("WLAN_CMD_SET_HOSTAPD_STA\n");
420 case WLAN_CMD_SET_802_1X:
421 pr_debug("WLAN_CMD_SET_802_1X\n");
422 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
427 if (sValue.dwValue == 1) {
428 pDevice->bEnable8021x = true;
429 pr_debug("Enable 802.1x\n");
431 pDevice->bEnable8021x = false;
432 pr_debug("Disable 802.1x\n");
436 case WLAN_CMD_SET_HOST_WEP:
437 pr_debug("WLAN_CMD_SET_HOST_WEP\n");
438 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
443 if (sValue.dwValue == 1) {
444 pDevice->bEnableHostWEP = true;
445 pr_debug("Enable HostWEP\n");
447 pDevice->bEnableHostWEP = false;
448 pr_debug("Disable HostWEP\n");
452 case WLAN_CMD_SET_WPA:
453 pr_debug("WLAN_CMD_SET_WPA\n");
455 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
459 if (sValue.dwValue == 1) {
460 pr_debug("up wpadev\n");
461 eth_hw_addr_inherit(pDevice->wpadev, pDevice->dev);
462 pDevice->bWPADEVUp = true;
464 pr_debug("close wpadev\n");
465 pDevice->bWPADEVUp = false;
469 case WLAN_CMD_AP_START:
470 pr_debug("WLAN_CMD_AP_START\n");
471 if (pDevice->bRadioOff == true) {
472 CARDbRadioPowerOn(pDevice);
473 vMgrTimerInit(pDevice);
474 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
475 add_timer(&pMgmt->sTimerSecondCallback);
477 if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
482 if (sStartAPCmd.wBSSType == AP) {
483 pMgmt->eConfigMode = WMAC_CONFIG_AP;
484 pr_debug("ioct set to AP mode\n");
486 pr_debug("ioct BSS type not set to AP mode\n");
491 if (sStartAPCmd.wBBPType == PHY80211g)
492 pMgmt->byAPBBType = PHY_TYPE_11G;
493 else if (sStartAPCmd.wBBPType == PHY80211a)
494 pMgmt->byAPBBType = PHY_TYPE_11A;
496 pMgmt->byAPBBType = PHY_TYPE_11B;
498 pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
499 if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
501 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
502 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
504 if ((sStartAPCmd.uChannel > 0) && (sStartAPCmd.uChannel <= 14))
505 pDevice->uChannel = sStartAPCmd.uChannel;
507 if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
508 pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
510 pMgmt->wIBSSBeaconPeriod = 100;
512 if (sStartAPCmd.bShareKeyAuth == true) {
513 pMgmt->bShareKeyAlgorithm = true;
514 pr_debug("Share Key\n");
516 pMgmt->bShareKeyAlgorithm = false;
517 pr_debug("Open System\n");
519 memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);
521 if (sStartAPCmd.byBasicRate & BIT3) {
522 pMgmt->abyIBSSSuppRates[2] |= BIT7;
523 pMgmt->abyIBSSSuppRates[3] |= BIT7;
524 pMgmt->abyIBSSSuppRates[4] |= BIT7;
525 pMgmt->abyIBSSSuppRates[5] |= BIT7;
526 } else if (sStartAPCmd.byBasicRate & BIT2) {
527 pMgmt->abyIBSSSuppRates[2] |= BIT7;
528 pMgmt->abyIBSSSuppRates[3] |= BIT7;
529 pMgmt->abyIBSSSuppRates[4] |= BIT7;
530 } else if (sStartAPCmd.byBasicRate & BIT1) {
531 pMgmt->abyIBSSSuppRates[2] |= BIT7;
532 pMgmt->abyIBSSSuppRates[3] |= BIT7;
533 } else if (sStartAPCmd.byBasicRate & BIT1) {
534 pMgmt->abyIBSSSuppRates[2] |= BIT7;
537 pMgmt->abyIBSSSuppRates[2] |= BIT7;
538 pMgmt->abyIBSSSuppRates[3] |= BIT7;
541 pr_debug("Support Rate= %*ph\n",
542 4, pMgmt->abyIBSSSuppRates + 2);
544 netif_stop_queue(pDevice->dev);
545 spin_lock_irq(&pDevice->lock);
546 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
547 spin_unlock_irq(&pDevice->lock);
550 case WLAN_CMD_GET_NODE_CNT:
552 pNode = &(pMgmt->sNodeDBTable[0]);
553 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
554 pNode = &(pMgmt->sNodeDBTable[ii]);
560 sNodeList.uItem = cbListCount;
561 if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
568 case WLAN_CMD_GET_NODE_LIST:
569 if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
573 if (sNodeList.uItem > (ULONG_MAX - sizeof(SNodeList)) / sizeof(SNodeItem)) {
577 pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)),
579 if (pNodeList == NULL) {
583 pNodeList->uItem = sNodeList.uItem;
584 pNode = &(pMgmt->sNodeDBTable[0]);
585 for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
586 pNode = &(pMgmt->sNodeDBTable[ii]);
587 if (pNode->bActive) {
588 pNodeList->sNodeList[jj].wAID = pNode->wAID;
589 memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
590 pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
591 pNodeList->sNodeList[jj].wInActiveCount = (unsigned short)pNode->uInActiveCount;
592 pNodeList->sNodeList[jj].wEnQueueCnt = (unsigned short)pNode->wEnQueueCnt;
593 pNodeList->sNodeList[jj].wFlags = (unsigned short)pNode->dwFlags;
594 pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
595 pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
596 pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
597 memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
598 pr_debug("key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
599 pNodeList->sNodeList[jj].abyWepKey[0],
600 pNodeList->sNodeList[jj].abyWepKey[1],
601 pNodeList->sNodeList[jj].abyWepKey[2],
602 pNodeList->sNodeList[jj].abyWepKey[3],
603 pNodeList->sNodeList[jj].abyWepKey[4]);
604 pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
605 pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
606 pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
607 pNodeList->sNodeList[jj].wFailureRatio = (unsigned short)pNode->uFailureRatio;
609 if (jj >= pNodeList->uItem)
613 if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
621 #ifdef WPA_SM_Transtatus
623 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
624 wpa_Result.proto = 0;
625 wpa_Result.key_mgmt = 0;
626 wpa_Result.eap_type = 0;
627 wpa_Result.authenticated = false;
628 pDevice->fWPA_Authened = false;
629 if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
634 if (wpa_Result.authenticated == true) {
637 union iwreq_data wrqu;
639 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
641 memset(&wrqu, 0, sizeof(wrqu));
642 wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
643 wrqu.data.length = pItemSSID->len;
644 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
647 pDevice->fWPA_Authened = true; /* is successful peer to wpa_Result.authenticated? */
654 pr_debug("Private command not support..\n");