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