Commit | Line | Data |
---|---|---|
5449c685 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: iwctl.c | |
20 | * | |
21 | * Purpose: wireless ext & ioctl functions | |
22 | * | |
23 | * Author: Lyndon Chen | |
24 | * | |
25 | * Date: July 5, 2006 | |
26 | * | |
27 | * Functions: | |
28 | * | |
29 | * Revision History: | |
30 | * | |
31 | */ | |
32 | ||
5449c685 | 33 | #include "device.h" |
5449c685 | 34 | #include "ioctl.h" |
5449c685 | 35 | #include "iocmd.h" |
5449c685 | 36 | #include "mac.h" |
5449c685 | 37 | #include "card.h" |
5449c685 | 38 | #include "hostap.h" |
5449c685 | 39 | #include "power.h" |
5449c685 | 40 | #include "rf.h" |
5449c685 FB |
41 | |
42 | #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT | |
5449c685 | 43 | #include "iowpa.h" |
5449c685 FB |
44 | #include "wpactl.h" |
45 | #endif | |
5449c685 | 46 | |
5449c685 | 47 | #include <net/iw_handler.h> |
5449c685 FB |
48 | extern WORD TxRate_iwconfig;//2008-5-8 <add> by chester |
49 | ||
50 | /*--------------------- Static Definitions -------------------------*/ | |
51 | ||
52 | //2008-0409-07, <Add> by Einsn Liu | |
53 | #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT | |
54 | #define SUPPORTED_WIRELESS_EXT 18 | |
55 | #else | |
56 | #define SUPPORTED_WIRELESS_EXT 17 | |
57 | #endif | |
58 | ||
5449c685 FB |
59 | static const long frequency_list[] = { |
60 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484, | |
61 | 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980, | |
62 | 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240, | |
63 | 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680, | |
64 | 5700, 5745, 5765, 5785, 5805, 5825 | |
65 | }; | |
66 | ||
5449c685 FB |
67 | |
68 | /*--------------------- Static Classes ----------------------------*/ | |
69 | ||
70 | ||
71 | //static int msglevel =MSG_LEVEL_DEBUG; | |
72 | static int msglevel =MSG_LEVEL_INFO; | |
73 | ||
74 | ||
75 | /*--------------------- Static Variables --------------------------*/ | |
76 | /*--------------------- Static Functions --------------------------*/ | |
77 | ||
78 | /*--------------------- Export Variables --------------------------*/ | |
79 | ||
5449c685 FB |
80 | struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev) |
81 | { | |
c9d03529 | 82 | PSDevice pDevice = netdev_priv(dev); |
5449c685 | 83 | long ldBm; |
612822f5 | 84 | |
5449c685 FB |
85 | pDevice->wstats.status = pDevice->eOPMode; |
86 | #ifdef Calcu_LinkQual | |
87 | #if 0 | |
88 | if(pDevice->byBBType == BB_TYPE_11B) { | |
89 | if(pDevice->byCurrSQ > 120) | |
90 | pDevice->scStatistic.LinkQuality = 100; | |
91 | else | |
92 | pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120; | |
93 | } | |
94 | else if(pDevice->byBBType == BB_TYPE_11G) { | |
95 | if(pDevice->byCurrSQ < 20) | |
96 | pDevice->scStatistic.LinkQuality = 100; | |
97 | else if(pDevice->byCurrSQ >96) | |
98 | pDevice->scStatistic.LinkQuality = 0; | |
99 | else | |
100 | pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76; | |
101 | } | |
102 | if(pDevice->bLinkPass !=TRUE) | |
103 | pDevice->scStatistic.LinkQuality = 0; | |
104 | #endif | |
105 | if(pDevice->scStatistic.LinkQuality > 100) | |
106 | pDevice->scStatistic.LinkQuality = 100; | |
107 | pDevice->wstats.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality; | |
108 | #else | |
109 | pDevice->wstats.qual.qual = pDevice->byCurrSQ; | |
110 | #endif | |
111 | RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm); | |
112 | pDevice->wstats.qual.level = ldBm; | |
113 | //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI; | |
114 | pDevice->wstats.qual.noise = 0; | |
115 | pDevice->wstats.qual.updated = 1; | |
116 | pDevice->wstats.discard.nwid = 0; | |
117 | pDevice->wstats.discard.code = 0; | |
118 | pDevice->wstats.discard.fragment = 0; | |
119 | pDevice->wstats.discard.retries = (U32)pDevice->scStatistic.dwTsrErr; | |
120 | pDevice->wstats.discard.misc = 0; | |
121 | pDevice->wstats.miss.beacon = 0; | |
122 | ||
123 | return &pDevice->wstats; | |
124 | } | |
125 | ||
5449c685 FB |
126 | |
127 | ||
128 | /*------------------------------------------------------------------*/ | |
129 | ||
130 | ||
131 | static int iwctl_commit(struct net_device *dev, | |
132 | struct iw_request_info *info, | |
133 | void *wrq, | |
134 | char *extra) | |
135 | { | |
7e809a9b | 136 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n"); |
5449c685 FB |
137 | |
138 | return 0; | |
139 | ||
140 | } | |
5449c685 FB |
141 | /* |
142 | * Wireless Handler : get protocol name | |
143 | */ | |
144 | ||
145 | int iwctl_giwname(struct net_device *dev, | |
146 | struct iw_request_info *info, | |
147 | char *wrq, | |
148 | char *extra) | |
149 | { | |
150 | strcpy(wrq, "802.11-a/b/g"); | |
151 | return 0; | |
152 | } | |
153 | ||
154 | int iwctl_giwnwid(struct net_device *dev, | |
155 | struct iw_request_info *info, | |
156 | struct iw_param *wrq, | |
157 | char *extra) | |
158 | { | |
159 | //wrq->value = 0x100; | |
160 | //wrq->disabled = 0; | |
161 | //wrq->fixed = 1; | |
162 | //return 0; | |
163 | return -EOPNOTSUPP; | |
164 | } | |
5449c685 FB |
165 | |
166 | /* | |
167 | * Wireless Handler : set scan | |
168 | */ | |
169 | ||
170 | int iwctl_siwscan(struct net_device *dev, | |
171 | struct iw_request_info *info, | |
172 | struct iw_point *wrq, | |
173 | char *extra) | |
174 | { | |
c9d03529 | 175 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
612822f5 JL |
176 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
177 | struct iw_scan_req *req = (struct iw_scan_req *)extra; | |
5449c685 FB |
178 | BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; |
179 | PWLAN_IE_SSID pItemSSID=NULL; | |
7e809a9b | 180 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n"); |
5449c685 FB |
181 | |
182 | ||
183 | if(pDevice->byReAssocCount > 0) { //reject scan when re-associating! | |
184 | //send scan event to wpa_Supplicant | |
185 | union iwreq_data wrqu; | |
612822f5 | 186 | PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n"); |
5449c685 FB |
187 | memset(&wrqu, 0, sizeof(wrqu)); |
188 | wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL); | |
189 | return 0; | |
190 | } | |
191 | ||
192 | spin_lock_irq(&pDevice->lock); | |
612822f5 | 193 | BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass); |
5449c685 FB |
194 | |
195 | //mike add: active scan OR passive scan OR desire_ssid scan | |
196 | if(wrq->length == sizeof(struct iw_scan_req)) { | |
197 | if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan | |
198 | memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); | |
199 | pItemSSID = (PWLAN_IE_SSID)abyScanSSID; | |
200 | pItemSSID->byElementID = WLAN_EID_SSID; | |
201 | memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len); | |
202 | if (pItemSSID->abySSID[req->essid_len - 1] == '\0') { | |
203 | if(req->essid_len>0) | |
204 | pItemSSID->len = req->essid_len - 1; | |
205 | } | |
206 | else | |
207 | pItemSSID->len = req->essid_len; | |
208 | pMgmt->eScanType = WMAC_SCAN_PASSIVE; | |
612822f5 | 209 | PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID, |
5449c685 FB |
210 | ((PWLAN_IE_SSID)abyScanSSID)->len); |
211 | bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID); | |
212 | spin_unlock_irq(&pDevice->lock); | |
213 | ||
214 | return 0; | |
215 | } | |
216 | else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan | |
217 | pMgmt->eScanType = WMAC_SCAN_PASSIVE; | |
218 | } | |
219 | } | |
220 | else { //active scan | |
221 | pMgmt->eScanType = WMAC_SCAN_ACTIVE; | |
222 | } | |
223 | ||
224 | pMgmt->eScanType = WMAC_SCAN_PASSIVE; | |
612822f5 | 225 | //printk("SIOCSIWSCAN:WLAN_CMD_BSSID_SCAN\n"); |
5449c685 FB |
226 | bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL); |
227 | spin_unlock_irq(&pDevice->lock); | |
228 | ||
229 | return 0; | |
230 | } | |
231 | ||
232 | ||
233 | /* | |
234 | * Wireless Handler : get scan results | |
235 | */ | |
236 | ||
237 | int iwctl_giwscan(struct net_device *dev, | |
238 | struct iw_request_info *info, | |
239 | struct iw_point *wrq, | |
240 | char *extra) | |
241 | { | |
242 | int ii, jj, kk; | |
c9d03529 | 243 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
244 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
245 | PKnownBSS pBSS; | |
246 | PWLAN_IE_SSID pItemSSID; | |
247 | PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates; | |
248 | char *current_ev = extra; | |
249 | char *end_buf = extra + IW_SCAN_MAX_DATA; | |
250 | char *current_val = NULL; | |
251 | struct iw_event iwe; | |
252 | long ldBm; | |
5449c685 | 253 | char buf[MAX_WPA_IE_LEN * 2 + 30]; |
5449c685 FB |
254 | |
255 | ||
7e809a9b | 256 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n"); |
5449c685 FB |
257 | |
258 | if (pMgmt->eScanState == WMAC_IS_SCANNING) { | |
259 | // In scanning.. | |
260 | return -EAGAIN; | |
261 | } | |
262 | pBSS = &(pMgmt->sBSSList[0]); | |
263 | for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) { | |
264 | if (current_ev >= end_buf) | |
265 | break; | |
266 | pBSS = &(pMgmt->sBSSList[jj]); | |
267 | if (pBSS->bActive) { | |
612822f5 | 268 | //ADD mac address |
5449c685 FB |
269 | memset(&iwe, 0, sizeof(iwe)); |
270 | iwe.cmd = SIOCGIWAP; | |
271 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
272 | memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN); | |
612822f5 | 273 | current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN); |
5449c685 FB |
274 | //ADD ssid |
275 | memset(&iwe, 0, sizeof(iwe)); | |
276 | iwe.cmd = SIOCGIWESSID; | |
277 | pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID; | |
278 | iwe.u.data.length = pItemSSID->len; | |
279 | iwe.u.data.flags = 1; | |
612822f5 | 280 | current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID); |
5449c685 FB |
281 | //ADD mode |
282 | memset(&iwe, 0, sizeof(iwe)); | |
283 | iwe.cmd = SIOCGIWMODE; | |
284 | if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) { | |
285 | iwe.u.mode = IW_MODE_INFRA; | |
286 | } | |
287 | else { | |
288 | iwe.u.mode = IW_MODE_ADHOC; | |
289 | } | |
290 | iwe.len = IW_EV_UINT_LEN; | |
612822f5 | 291 | current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_UINT_LEN); |
5449c685 FB |
292 | //ADD frequency |
293 | pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates; | |
294 | pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates; | |
295 | memset(&iwe, 0, sizeof(iwe)); | |
296 | iwe.cmd = SIOCGIWFREQ; | |
297 | iwe.u.freq.m = pBSS->uChannel; | |
298 | iwe.u.freq.e = 0; | |
299 | iwe.u.freq.i = 0; | |
612822f5 | 300 | current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN); |
5449c685 FB |
301 | //2008-0409-04, <Add> by Einsn Liu |
302 | { | |
303 | int f = (int)pBSS->uChannel - 1; | |
304 | if(f < 0)f = 0; | |
305 | iwe.u.freq.m = frequency_list[f] * 100000; | |
306 | iwe.u.freq.e = 1; | |
307 | } | |
612822f5 | 308 | current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN); |
5449c685 FB |
309 | //ADD quality |
310 | memset(&iwe, 0, sizeof(iwe)); | |
311 | iwe.cmd = IWEVQUAL; | |
312 | RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm); | |
313 | iwe.u.qual.level = ldBm; | |
314 | iwe.u.qual.noise = 0; | |
315 | //2008-0409-01, <Add> by Einsn Liu | |
316 | if(-ldBm<50){ | |
317 | iwe.u.qual.qual = 100; | |
318 | }else if(-ldBm > 90) { | |
319 | iwe.u.qual.qual = 0; | |
320 | }else { | |
321 | iwe.u.qual.qual=(40-(-ldBm-50))*100/40; | |
322 | } | |
323 | iwe.u.qual.updated=7; | |
324 | ||
325 | // iwe.u.qual.qual = 0; | |
7bb8dc2d | 326 | current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN); |
5449c685 FB |
327 | |
328 | memset(&iwe, 0, sizeof(iwe)); | |
329 | iwe.cmd = SIOCGIWENCODE; | |
330 | iwe.u.data.length = 0; | |
331 | if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) { | |
332 | iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
333 | }else { | |
334 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
335 | } | |
5449c685 | 336 | current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID); |
5449c685 FB |
337 | |
338 | memset(&iwe, 0, sizeof(iwe)); | |
339 | iwe.cmd = SIOCGIWRATE; | |
340 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | |
341 | current_val = current_ev + IW_EV_LCP_LEN; | |
342 | ||
343 | for (kk = 0 ; kk < 12 ; kk++) { | |
344 | if (pSuppRates->abyRates[kk] == 0) | |
345 | break; | |
346 | // Bit rate given in 500 kb/s units (+ 0x80) | |
347 | iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000); | |
612822f5 JL |
348 | current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN); |
349 | } | |
5449c685 FB |
350 | for (kk = 0 ; kk < 8 ; kk++) { |
351 | if (pExtSuppRates->abyRates[kk] == 0) | |
352 | break; | |
353 | // Bit rate given in 500 kb/s units (+ 0x80) | |
354 | iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000); | |
612822f5 | 355 | current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN); |
5449c685 FB |
356 | } |
357 | ||
358 | if((current_val - current_ev) > IW_EV_LCP_LEN) | |
359 | current_ev = current_val; | |
360 | ||
5449c685 FB |
361 | memset(&iwe, 0, sizeof(iwe)); |
362 | iwe.cmd = IWEVCUSTOM; | |
363 | sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval); | |
364 | iwe.u.data.length = strlen(buf); | |
612822f5 | 365 | current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf); |
5449c685 | 366 | |
5449c685 FB |
367 | if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) { |
368 | memset(&iwe, 0, sizeof(iwe)); | |
369 | iwe.cmd = IWEVGENIE; | |
370 | iwe.u.data.length = pBSS->wWPALen; | |
5449c685 | 371 | current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE); |
5449c685 FB |
372 | } |
373 | ||
374 | if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) { | |
375 | memset(&iwe, 0, sizeof(iwe)); | |
376 | iwe.cmd = IWEVGENIE; | |
377 | iwe.u.data.length = pBSS->wRSNLen; | |
5449c685 | 378 | current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE); |
5449c685 FB |
379 | } |
380 | ||
5449c685 FB |
381 | } |
382 | }// for | |
383 | ||
384 | wrq->length = current_ev - extra; | |
385 | return 0; | |
386 | ||
387 | } | |
388 | ||
5449c685 FB |
389 | |
390 | /* | |
391 | * Wireless Handler : set frequence or channel | |
392 | */ | |
393 | ||
394 | int iwctl_siwfreq(struct net_device *dev, | |
395 | struct iw_request_info *info, | |
396 | struct iw_freq *wrq, | |
397 | char *extra) | |
398 | { | |
c9d03529 | 399 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
400 | int rc = 0; |
401 | ||
7e809a9b | 402 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n"); |
5449c685 FB |
403 | |
404 | // If setting by frequency, convert to a channel | |
405 | if((wrq->e == 1) && | |
406 | (wrq->m >= (int) 2.412e8) && | |
407 | (wrq->m <= (int) 2.487e8)) { | |
408 | int f = wrq->m / 100000; | |
409 | int c = 0; | |
410 | while((c < 14) && (f != frequency_list[c])) | |
411 | c++; | |
412 | wrq->e = 0; | |
413 | wrq->m = c + 1; | |
414 | } | |
415 | // Setting by channel number | |
416 | if((wrq->m > 14) || (wrq->e > 0)) | |
417 | rc = -EOPNOTSUPP; | |
418 | else { | |
419 | int channel = wrq->m; | |
420 | if((channel < 1) || (channel > 14)) { | |
7e809a9b | 421 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m); |
5449c685 FB |
422 | rc = -EINVAL; |
423 | } else { | |
424 | // Yes ! We can set it !!! | |
7e809a9b | 425 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel); |
5449c685 FB |
426 | pDevice->uChannel = channel; |
427 | //2007-0207-04,<Add> by EinsnLiu | |
428 | //Make change effect at once | |
429 | pDevice->bCommit = TRUE; | |
430 | } | |
431 | } | |
432 | ||
433 | return rc; | |
434 | } | |
435 | ||
436 | /* | |
437 | * Wireless Handler : get frequence or channel | |
438 | */ | |
439 | ||
440 | int iwctl_giwfreq(struct net_device *dev, | |
441 | struct iw_request_info *info, | |
442 | struct iw_freq *wrq, | |
443 | char *extra) | |
444 | { | |
c9d03529 | 445 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
446 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
447 | ||
7e809a9b | 448 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n"); |
5449c685 FB |
449 | |
450 | #ifdef WEXT_USECHANNELS | |
451 | wrq->m = (int)pMgmt->uCurrChannel; | |
452 | wrq->e = 0; | |
453 | #else | |
454 | { | |
455 | int f = (int)pMgmt->uCurrChannel - 1; | |
456 | if(f < 0) | |
457 | f = 0; | |
458 | wrq->m = frequency_list[f] * 100000; | |
459 | wrq->e = 1; | |
460 | } | |
461 | #endif | |
462 | ||
463 | return 0; | |
464 | } | |
465 | ||
466 | /* | |
467 | * Wireless Handler : set operation mode | |
468 | */ | |
469 | ||
470 | int iwctl_siwmode(struct net_device *dev, | |
471 | struct iw_request_info *info, | |
472 | __u32 *wmode, | |
473 | char *extra) | |
474 | { | |
c9d03529 | 475 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
476 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
477 | int rc = 0; | |
478 | ||
7e809a9b | 479 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n"); |
5449c685 FB |
480 | |
481 | if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) { | |
7e809a9b | 482 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n"); |
5449c685 FB |
483 | return rc; |
484 | } | |
485 | ||
486 | switch(*wmode) { | |
487 | ||
488 | case IW_MODE_ADHOC: | |
489 | if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) { | |
490 | pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA; | |
491 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
492 | pDevice->bCommit = TRUE; | |
493 | } | |
494 | } | |
7e809a9b | 495 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n"); |
5449c685 FB |
496 | break; |
497 | case IW_MODE_AUTO: | |
498 | case IW_MODE_INFRA: | |
499 | if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) { | |
500 | pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA; | |
501 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
502 | pDevice->bCommit = TRUE; | |
503 | } | |
504 | } | |
7e809a9b | 505 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n"); |
5449c685 FB |
506 | break; |
507 | case IW_MODE_MASTER: | |
508 | ||
509 | pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA; | |
510 | rc = -EOPNOTSUPP; | |
511 | break; | |
512 | ||
513 | if (pMgmt->eConfigMode != WMAC_CONFIG_AP) { | |
514 | pMgmt->eConfigMode = WMAC_CONFIG_AP; | |
515 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
516 | pDevice->bCommit = TRUE; | |
517 | } | |
518 | } | |
7e809a9b | 519 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n"); |
5449c685 FB |
520 | break; |
521 | ||
522 | case IW_MODE_REPEAT: | |
523 | pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA; | |
524 | rc = -EOPNOTSUPP; | |
525 | break; | |
526 | default: | |
527 | rc = -EINVAL; | |
528 | } | |
529 | ||
530 | return rc; | |
531 | } | |
532 | ||
533 | /* | |
534 | * Wireless Handler : get operation mode | |
535 | */ | |
536 | ||
537 | int iwctl_giwmode(struct net_device *dev, | |
538 | struct iw_request_info *info, | |
539 | __u32 *wmode, | |
540 | char *extra) | |
541 | { | |
c9d03529 | 542 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
543 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
544 | ||
545 | ||
7e809a9b | 546 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n"); |
5449c685 FB |
547 | // If not managed, assume it's ad-hoc |
548 | switch (pMgmt->eConfigMode) { | |
549 | case WMAC_CONFIG_ESS_STA: | |
550 | *wmode = IW_MODE_INFRA; | |
551 | break; | |
552 | case WMAC_CONFIG_IBSS_STA: | |
553 | *wmode = IW_MODE_ADHOC; | |
554 | break; | |
555 | case WMAC_CONFIG_AUTO: | |
556 | *wmode = IW_MODE_INFRA; | |
557 | break; | |
558 | case WMAC_CONFIG_AP: | |
559 | *wmode = IW_MODE_MASTER; | |
560 | break; | |
561 | default: | |
562 | *wmode = IW_MODE_ADHOC; | |
563 | } | |
564 | ||
565 | return 0; | |
566 | } | |
567 | ||
568 | ||
569 | /* | |
570 | * Wireless Handler : get capability range | |
571 | */ | |
572 | ||
573 | int iwctl_giwrange(struct net_device *dev, | |
574 | struct iw_request_info *info, | |
575 | struct iw_point *wrq, | |
576 | char *extra) | |
577 | { | |
578 | struct iw_range *range = (struct iw_range *) extra; | |
579 | int i,k; | |
580 | BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90}; | |
581 | ||
582 | ||
7e809a9b | 583 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n"); |
5449c685 FB |
584 | if (wrq->pointer) { |
585 | wrq->length = sizeof(struct iw_range); | |
586 | memset(range, 0, sizeof(struct iw_range)); | |
587 | range->min_nwid = 0x0000; | |
588 | range->max_nwid = 0x0000; | |
589 | range->num_channels = 14; | |
590 | // Should be based on cap_rid.country to give only | |
591 | // what the current card support | |
592 | k = 0; | |
593 | for(i = 0; i < 14; i++) { | |
594 | range->freq[k].i = i + 1; // List index | |
595 | range->freq[k].m = frequency_list[i] * 100000; | |
596 | range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10 | |
597 | } | |
598 | range->num_frequency = k; | |
599 | // Hum... Should put the right values there | |
600 | #ifdef Calcu_LinkQual | |
601 | range->max_qual.qual = 100; | |
602 | #else | |
603 | range->max_qual.qual = 255; | |
604 | #endif | |
605 | range->max_qual.level = 0; | |
606 | range->max_qual.noise = 0; | |
607 | range->sensitivity = 255; | |
608 | ||
609 | for(i = 0 ; i < 13 ; i++) { | |
610 | range->bitrate[i] = abySupportedRates[i] * 500000; | |
611 | if(range->bitrate[i] == 0) | |
612 | break; | |
613 | } | |
614 | range->num_bitrates = i; | |
615 | ||
616 | // Set an indication of the max TCP throughput | |
617 | // in bit/s that we can expect using this interface. | |
618 | // May be use for QoS stuff... Jean II | |
619 | if(i > 2) | |
620 | range->throughput = 5 * 1000 * 1000; | |
621 | else | |
622 | range->throughput = 1.5 * 1000 * 1000; | |
623 | ||
624 | range->min_rts = 0; | |
625 | range->max_rts = 2312; | |
626 | range->min_frag = 256; | |
627 | range->max_frag = 2312; | |
628 | ||
629 | ||
630 | // the encoding capabilities | |
631 | range->num_encoding_sizes = 3; | |
632 | // 64(40) bits WEP | |
633 | range->encoding_size[0] = 5; | |
634 | // 128(104) bits WEP | |
635 | range->encoding_size[1] = 13; | |
636 | // 256 bits for WPA-PSK | |
637 | range->encoding_size[2] = 32; | |
638 | // 4 keys are allowed | |
639 | range->max_encoding_tokens = 4; | |
640 | ||
5449c685 FB |
641 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
642 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | |
5449c685 | 643 | |
5449c685 FB |
644 | range->min_pmp = 0; |
645 | range->max_pmp = 1000000;// 1 secs | |
646 | range->min_pmt = 0; | |
647 | range->max_pmt = 1000000;// 1 secs | |
648 | range->pmp_flags = IW_POWER_PERIOD; | |
649 | range->pmt_flags = IW_POWER_TIMEOUT; | |
650 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R; | |
651 | ||
652 | // Transmit Power - values are in mW | |
653 | ||
654 | range->txpower[0] = 100; | |
655 | range->num_txpower = 1; | |
656 | range->txpower_capa = IW_TXPOW_MWATT; | |
5449c685 FB |
657 | range->we_version_source = SUPPORTED_WIRELESS_EXT; |
658 | range->we_version_compiled = WIRELESS_EXT; | |
659 | range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME; | |
660 | range->retry_flags = IW_RETRY_LIMIT; | |
661 | range->r_time_flags = IW_RETRY_LIFETIME; | |
662 | range->min_retry = 1; | |
663 | range->max_retry = 65535; | |
664 | range->min_r_time = 1024; | |
665 | range->max_r_time = 65535 * 1024; | |
5449c685 FB |
666 | // Experimental measurements - boundary 11/5.5 Mb/s |
667 | // Note : with or without the (local->rssi), results | |
668 | // are somewhat different. - Jean II | |
669 | range->avg_qual.qual = 6; | |
670 | range->avg_qual.level = 176; // -80 dBm | |
671 | range->avg_qual.noise = 0; | |
5449c685 FB |
672 | } |
673 | ||
674 | ||
675 | return 0; | |
676 | } | |
677 | ||
678 | ||
679 | /* | |
680 | * Wireless Handler : set ap mac address | |
681 | */ | |
682 | ||
683 | int iwctl_siwap(struct net_device *dev, | |
684 | struct iw_request_info *info, | |
685 | struct sockaddr *wrq, | |
686 | char *extra) | |
687 | { | |
c9d03529 | 688 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
689 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
690 | int rc = 0; | |
612822f5 | 691 | BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00}; |
5449c685 | 692 | |
7e809a9b | 693 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n"); |
5449c685 FB |
694 | if (pMgmt->eScanState == WMAC_IS_SCANNING) { |
695 | // In scanning.. | |
696 | printk("SIOCSIWAP(??)-->In scanning...\n"); | |
697 | // return -EAGAIN; | |
698 | } | |
699 | if (wrq->sa_family != ARPHRD_ETHER) | |
700 | rc = -EINVAL; | |
701 | else { | |
702 | memset(pMgmt->abyDesireBSSID, 0xFF, 6); | |
703 | memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6); | |
704 | //2008-0409-05, <Add> by Einsn Liu | |
705 | if((pDevice->bLinkPass == TRUE) && | |
706 | (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){ | |
707 | return rc; | |
708 | } | |
709 | //mike :add | |
710 | if ((IS_BROADCAST_ADDRESS(pMgmt->abyDesireBSSID)) || | |
711 | (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){ | |
612822f5 | 712 | PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n"); |
5449c685 FB |
713 | return rc; |
714 | } | |
715 | //mike add: if desired AP is hidden ssid(there are two same BSSID in list), | |
716 | // then ignore,because you don't known which one to be connect with?? | |
717 | { | |
718 | UINT ii , uSameBssidNum=0; | |
719 | for (ii = 0; ii < MAX_BSS_NUM; ii++) { | |
720 | if (pMgmt->sBSSList[ii].bActive && | |
721 | IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID,pMgmt->abyDesireBSSID)) { | |
722 | uSameBssidNum++; | |
723 | } | |
724 | } | |
725 | if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!! | |
612822f5 | 726 | PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n"); |
5449c685 FB |
727 | return rc; |
728 | } | |
729 | } | |
612822f5 | 730 | |
5449c685 FB |
731 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { |
732 | pDevice->bCommit = TRUE; | |
733 | } | |
734 | } | |
735 | return rc; | |
736 | } | |
737 | ||
738 | /* | |
739 | * Wireless Handler : get ap mac address | |
740 | */ | |
741 | ||
742 | int iwctl_giwap(struct net_device *dev, | |
743 | struct iw_request_info *info, | |
744 | struct sockaddr *wrq, | |
745 | char *extra) | |
746 | { | |
c9d03529 | 747 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
748 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
749 | ||
750 | ||
7e809a9b | 751 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n"); |
5449c685 FB |
752 | |
753 | memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6); | |
754 | //2008-0410,<Modify> by Einsn Liu | |
755 | if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)) | |
756 | memset(wrq->sa_data, 0, 6); | |
757 | ||
758 | if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { | |
759 | memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6); | |
760 | } | |
761 | ||
762 | wrq->sa_family = ARPHRD_ETHER; | |
763 | ||
764 | return 0; | |
765 | ||
766 | } | |
767 | ||
768 | ||
769 | /* | |
770 | * Wireless Handler : get ap list | |
771 | */ | |
772 | ||
773 | int iwctl_giwaplist(struct net_device *dev, | |
774 | struct iw_request_info *info, | |
775 | struct iw_point *wrq, | |
776 | char *extra) | |
777 | { | |
778 | int ii,jj, rc = 0; | |
779 | struct sockaddr sock[IW_MAX_AP]; | |
780 | struct iw_quality qual[IW_MAX_AP]; | |
c9d03529 | 781 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
782 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
783 | ||
784 | ||
7e809a9b | 785 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n"); |
5449c685 FB |
786 | // Only super-user can see AP list |
787 | ||
788 | if (!capable(CAP_NET_ADMIN)) { | |
789 | rc = -EPERM; | |
790 | return rc; | |
791 | } | |
792 | ||
793 | if (wrq->pointer) { | |
794 | ||
795 | PKnownBSS pBSS = &(pMgmt->sBSSList[0]); | |
796 | ||
797 | for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) { | |
798 | pBSS = &(pMgmt->sBSSList[ii]); | |
799 | if (!pBSS->bActive) | |
800 | continue; | |
801 | if ( jj >= IW_MAX_AP) | |
802 | break; | |
803 | memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6); | |
804 | sock[jj].sa_family = ARPHRD_ETHER; | |
805 | qual[jj].level = pBSS->uRSSI; | |
806 | qual[jj].qual = qual[jj].noise = 0; | |
807 | qual[jj].updated = 2; | |
808 | jj++; | |
809 | } | |
810 | ||
811 | wrq->flags = 1; // Should be define'd | |
812 | wrq->length = jj; | |
813 | memcpy(extra, sock, sizeof(struct sockaddr)*jj); | |
814 | memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj); | |
815 | } | |
816 | ||
817 | return rc; | |
818 | } | |
819 | ||
820 | ||
821 | /* | |
822 | * Wireless Handler : set essid | |
823 | */ | |
824 | ||
825 | int iwctl_siwessid(struct net_device *dev, | |
826 | struct iw_request_info *info, | |
827 | struct iw_point *wrq, | |
828 | char *extra) | |
829 | { | |
c9d03529 | 830 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
831 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
832 | PWLAN_IE_SSID pItemSSID; | |
833 | //2008-0409-05, <Add> by Einsn Liu | |
834 | BYTE len; | |
835 | ||
836 | ||
7e809a9b | 837 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n"); |
5449c685 FB |
838 | pDevice->fWPA_Authened = FALSE; |
839 | if (pMgmt->eScanState == WMAC_IS_SCANNING) { | |
840 | // In scanning.. | |
841 | printk("SIOCSIWESSID(??)-->In scanning...\n"); | |
842 | // return -EAGAIN; | |
843 | } | |
844 | // Check if we asked for `any' | |
845 | if(wrq->flags == 0) { | |
5449c685 FB |
846 | // Just send an empty SSID list |
847 | memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); | |
848 | memset(pMgmt->abyDesireBSSID, 0xFF,6); | |
612822f5 | 849 | PRINT_K("set essid to 'any' \n"); |
5449c685 FB |
850 | #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT |
851 | //Unknown desired AP,so here need not associate?? | |
852 | //if(pDevice->bWPASuppWextEnabled == TRUE) { | |
853 | return 0; | |
854 | // } | |
855 | #endif | |
856 | } else { | |
857 | // Set the SSID | |
858 | memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); | |
859 | pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID; | |
860 | pItemSSID->byElementID = WLAN_EID_SSID; | |
612822f5 | 861 | |
5449c685 | 862 | memcpy(pItemSSID->abySSID, extra, wrq->length); |
612822f5 | 863 | if (pItemSSID->abySSID[wrq->length - 1] == '\0') { |
5449c685 FB |
864 | if(wrq->length>0) |
865 | pItemSSID->len = wrq->length - 1; | |
866 | } | |
867 | else | |
868 | pItemSSID->len = wrq->length; | |
869 | printk("set essid to %s \n",pItemSSID->abySSID); | |
870 | //2008-0409-05, <Add> by Einsn Liu | |
871 | len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len; | |
872 | if((pDevice->bLinkPass == TRUE) && | |
873 | (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0)) | |
874 | return 0; | |
875 | ||
612822f5 | 876 | //mike:need clear desiredBSSID |
5449c685 FB |
877 | if(pItemSSID->len==0) { |
878 | memset(pMgmt->abyDesireBSSID, 0xFF,6); | |
879 | return 0; | |
880 | } | |
881 | ||
882 | #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT | |
883 | //Wext wil order another command of siwap to link with desired AP, | |
884 | //so here need not associate?? | |
885 | if(pDevice->bWPASuppWextEnabled == TRUE) { | |
886 | /*******search if in hidden ssid mode ****/ | |
887 | { | |
888 | PKnownBSS pCurr = NULL; | |
889 | BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; | |
890 | UINT ii , uSameBssidNum=0; | |
891 | ||
892 | memset(abyTmpDesireSSID,0,sizeof(abyTmpDesireSSID)); | |
893 | memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID)); | |
894 | pCurr = BSSpSearchBSSList(pDevice, | |
895 | NULL, | |
896 | abyTmpDesireSSID, | |
897 | pMgmt->eConfigPHYMode | |
898 | ); | |
899 | ||
900 | if (pCurr == NULL){ | |
612822f5 | 901 | PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n"); |
5449c685 FB |
902 | vResetCommandTimer((HANDLE) pDevice); |
903 | pMgmt->eScanType = WMAC_SCAN_ACTIVE; | |
904 | bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID); | |
905 | bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID); | |
906 | } | |
907 | else { //mike:to find out if that desired SSID is a hidden-ssid AP , | |
908 | // by means of judging if there are two same BSSID exist in list ? | |
909 | for (ii = 0; ii < MAX_BSS_NUM; ii++) { | |
910 | if (pMgmt->sBSSList[ii].bActive && | |
911 | IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) { | |
912 | uSameBssidNum++; | |
913 | } | |
914 | } | |
915 | if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!! | |
916 | printk("SIOCSIWESSID:hidden ssid directly associate.......\n"); | |
917 | vResetCommandTimer((HANDLE) pDevice); | |
918 | pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result! | |
919 | bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID); | |
920 | bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID); | |
921 | } | |
922 | } | |
923 | } | |
924 | return 0; | |
925 | } | |
926 | #endif | |
927 | ||
7e809a9b | 928 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID); |
5449c685 FB |
929 | } |
930 | ||
931 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
932 | pDevice->bCommit = TRUE; | |
933 | } | |
934 | ||
935 | ||
936 | return 0; | |
937 | } | |
938 | ||
939 | ||
940 | /* | |
941 | * Wireless Handler : get essid | |
942 | */ | |
943 | ||
944 | int iwctl_giwessid(struct net_device *dev, | |
945 | struct iw_request_info *info, | |
946 | struct iw_point *wrq, | |
947 | char *extra) | |
948 | { | |
949 | ||
c9d03529 | 950 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
951 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
952 | PWLAN_IE_SSID pItemSSID; | |
953 | ||
7e809a9b | 954 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n"); |
5449c685 FB |
955 | |
956 | // Note : if wrq->u.data.flags != 0, we should | |
957 | // get the relevant SSID from the SSID list... | |
958 | ||
959 | // Get the current SSID | |
960 | pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; | |
961 | //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID; | |
962 | memcpy(extra, pItemSSID->abySSID , pItemSSID->len); | |
963 | extra[pItemSSID->len] = '\0'; | |
964 | wrq->length = pItemSSID->len + 1; | |
965 | //2008-0409-03, <Add> by Einsn Liu | |
5449c685 | 966 | wrq->length = pItemSSID->len; |
5449c685 FB |
967 | wrq->flags = 1; // active |
968 | ||
969 | ||
970 | return 0; | |
971 | } | |
972 | ||
973 | /* | |
974 | * Wireless Handler : set data rate | |
975 | */ | |
976 | ||
977 | int iwctl_siwrate(struct net_device *dev, | |
978 | struct iw_request_info *info, | |
979 | struct iw_param *wrq, | |
980 | char *extra) | |
981 | { | |
c9d03529 | 982 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
983 | int rc = 0; |
984 | u8 brate = 0; | |
985 | int i; | |
986 | BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90}; | |
987 | ||
988 | ||
7e809a9b | 989 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n"); |
5449c685 FB |
990 | if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) { |
991 | rc = -EINVAL; | |
992 | return rc; | |
993 | } | |
994 | ||
995 | // First : get a valid bit rate value | |
996 | ||
997 | // Which type of value | |
998 | if((wrq->value < 13) && | |
999 | (wrq->value >= 0)) { | |
1000 | // Setting by rate index | |
1001 | // Find value in the magic rate table | |
1002 | brate = wrq->value; | |
1003 | } else { | |
1004 | // Setting by frequency value | |
1005 | u8 normvalue = (u8) (wrq->value/500000); | |
1006 | ||
1007 | // Check if rate is valid | |
1008 | for(i = 0 ; i < 13 ; i++) { | |
1009 | if(normvalue == abySupportedRates[i]) { | |
1010 | brate = i; | |
1011 | break; | |
1012 | } | |
1013 | } | |
1014 | } | |
1015 | // -1 designed the max rate (mostly auto mode) | |
1016 | if(wrq->value == -1) { | |
1017 | // Get the highest available rate | |
1018 | for(i = 0 ; i < 13 ; i++) { | |
1019 | if(abySupportedRates[i] == 0) | |
1020 | break; | |
1021 | } | |
1022 | if(i != 0) | |
1023 | brate = i - 1; | |
1024 | ||
1025 | } | |
1026 | // Check that it is valid | |
1027 | // brate is index of abySupportedRates[] | |
1028 | if(brate > 13 ) { | |
1029 | rc = -EINVAL; | |
1030 | return rc; | |
1031 | } | |
1032 | ||
1033 | // Now, check if we want a fixed or auto value | |
1034 | if(wrq->fixed != 0) { | |
1035 | // Fixed mode | |
1036 | // One rate, fixed | |
1037 | printk("Rate Fix\n"); | |
1038 | pDevice->bFixRate = TRUE; | |
1039 | if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) { | |
612822f5 | 1040 | pDevice->uConnectionRate = 3; |
5449c685 FB |
1041 | } |
1042 | else { | |
1043 | pDevice->uConnectionRate = brate; | |
7e809a9b | 1044 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate); |
5449c685 FB |
1045 | } |
1046 | ||
1047 | } | |
1048 | else { | |
1049 | pDevice->bFixRate = FALSE; | |
1050 | pDevice->uConnectionRate = 13; | |
1051 | printk("auto rate:connection_rate is 13\n"); | |
612822f5 | 1052 | } |
5449c685 FB |
1053 | |
1054 | return rc; | |
1055 | } | |
1056 | ||
1057 | /* | |
1058 | * Wireless Handler : get data rate | |
1059 | */ | |
1060 | ||
1061 | int iwctl_giwrate(struct net_device *dev, | |
1062 | struct iw_request_info *info, | |
1063 | struct iw_param *wrq, | |
1064 | char *extra) | |
1065 | { | |
c9d03529 | 1066 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1067 | //2007-0118-05,<Mark> by EinsnLiu |
1068 | //Mark the unnecessary sentences. | |
1069 | // PSMgmtObject pMgmt = &(pDevice->sMgmtObj); | |
1070 | ||
7e809a9b | 1071 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n"); |
5449c685 FB |
1072 | { |
1073 | BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90}; | |
1074 | int brate = 0; | |
1075 | //2008-5-8 <modify> by chester | |
1076 | if(pDevice->bLinkPass){ | |
1077 | if(pDevice->bFixRate == TRUE){ | |
1078 | if (pDevice->uConnectionRate < 13) { | |
1079 | brate = abySupportedRates[pDevice->uConnectionRate]; | |
1080 | }else { | |
1081 | if (pDevice->byBBType == BB_TYPE_11B) | |
1082 | brate = 0x16; | |
1083 | if (pDevice->byBBType == BB_TYPE_11G) | |
1084 | brate = 0x6C; | |
1085 | if (pDevice->byBBType == BB_TYPE_11A) | |
1086 | brate = 0x6C; | |
1087 | } | |
1088 | } | |
1089 | else | |
1090 | { | |
1091 | ||
1092 | brate = abySupportedRates[TxRate_iwconfig]; | |
1093 | } | |
1094 | } | |
1095 | else brate =0; | |
1096 | //2007-0118-05,<Mark> by EinsnLiu | |
1097 | //Mark the unnecessary sentences. | |
1098 | /* | |
1099 | if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { | |
1100 | if (pDevice->byBBType == BB_TYPE_11B) | |
1101 | brate = 0x16; | |
1102 | if (pDevice->byBBType == BB_TYPE_11G) | |
1103 | brate = 0x6C; | |
1104 | if (pDevice->byBBType == BB_TYPE_11A) | |
1105 | brate = 0x6C; | |
1106 | } | |
1107 | */ | |
1108 | ||
1109 | // if (pDevice->uConnectionRate == 13) | |
1110 | // brate = abySupportedRates[pDevice->wCurrentRate]; | |
1111 | wrq->value = brate * 500000; | |
1112 | // If more than one rate, set auto | |
1113 | if (pDevice->bFixRate == TRUE) | |
1114 | wrq->fixed = TRUE; | |
1115 | } | |
1116 | ||
1117 | ||
1118 | return 0; | |
1119 | } | |
1120 | ||
1121 | ||
1122 | ||
1123 | /* | |
1124 | * Wireless Handler : set rts threshold | |
1125 | */ | |
1126 | ||
1127 | int iwctl_siwrts(struct net_device *dev, | |
1128 | struct iw_request_info *info, | |
1129 | struct iw_param *wrq, | |
1130 | char *extra) | |
1131 | { | |
c9d03529 | 1132 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1133 | int rc = 0; |
1134 | ||
7e809a9b | 1135 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n"); |
5449c685 FB |
1136 | |
1137 | { | |
1138 | int rthr = wrq->value; | |
1139 | if(wrq->disabled) | |
1140 | rthr = 2312; | |
1141 | if((rthr < 0) || (rthr > 2312)) { | |
1142 | rc = -EINVAL; | |
1143 | }else { | |
1144 | pDevice->wRTSThreshold = rthr; | |
1145 | } | |
1146 | } | |
1147 | ||
1148 | return 0; | |
1149 | } | |
1150 | ||
1151 | /* | |
1152 | * Wireless Handler : get rts | |
1153 | */ | |
1154 | ||
1155 | int iwctl_giwrts(struct net_device *dev, | |
1156 | struct iw_request_info *info, | |
1157 | struct iw_param *wrq, | |
1158 | char *extra) | |
1159 | { | |
c9d03529 | 1160 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 | 1161 | |
7e809a9b | 1162 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n"); |
5449c685 FB |
1163 | wrq->value = pDevice->wRTSThreshold; |
1164 | wrq->disabled = (wrq->value >= 2312); | |
1165 | wrq->fixed = 1; | |
1166 | ||
1167 | return 0; | |
1168 | } | |
1169 | ||
1170 | /* | |
1171 | * Wireless Handler : set fragment threshold | |
1172 | */ | |
1173 | ||
1174 | int iwctl_siwfrag(struct net_device *dev, | |
1175 | struct iw_request_info *info, | |
1176 | struct iw_param *wrq, | |
1177 | char *extra) | |
1178 | { | |
c9d03529 | 1179 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1180 | int rc = 0; |
1181 | int fthr = wrq->value; | |
1182 | ||
1183 | ||
7e809a9b | 1184 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n"); |
5449c685 FB |
1185 | |
1186 | ||
1187 | if (wrq->disabled) | |
1188 | fthr = 2312; | |
1189 | if((fthr < 256) || (fthr > 2312)) { | |
1190 | rc = -EINVAL; | |
1191 | }else { | |
1192 | fthr &= ~0x1; // Get an even value | |
1193 | pDevice->wFragmentationThreshold = (u16)fthr; | |
1194 | } | |
1195 | ||
1196 | return rc; | |
1197 | } | |
1198 | ||
1199 | /* | |
1200 | * Wireless Handler : get fragment threshold | |
1201 | */ | |
1202 | ||
1203 | int iwctl_giwfrag(struct net_device *dev, | |
1204 | struct iw_request_info *info, | |
1205 | struct iw_param *wrq, | |
1206 | char *extra) | |
1207 | { | |
c9d03529 | 1208 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 | 1209 | |
7e809a9b | 1210 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n"); |
5449c685 FB |
1211 | wrq->value = pDevice->wFragmentationThreshold; |
1212 | wrq->disabled = (wrq->value >= 2312); | |
1213 | wrq->fixed = 1; | |
1214 | ||
1215 | return 0; | |
1216 | } | |
1217 | ||
1218 | ||
1219 | ||
1220 | /* | |
1221 | * Wireless Handler : set retry threshold | |
1222 | */ | |
1223 | int iwctl_siwretry(struct net_device *dev, | |
1224 | struct iw_request_info *info, | |
1225 | struct iw_param *wrq, | |
1226 | char *extra) | |
1227 | { | |
c9d03529 | 1228 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1229 | int rc = 0; |
1230 | ||
1231 | ||
7e809a9b | 1232 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n"); |
5449c685 FB |
1233 | |
1234 | if (wrq->disabled) { | |
1235 | rc = -EINVAL; | |
1236 | return rc; | |
1237 | } | |
1238 | ||
1239 | if (wrq->flags & IW_RETRY_LIMIT) { | |
1240 | if(wrq->flags & IW_RETRY_MAX) | |
1241 | pDevice->byLongRetryLimit = wrq->value; | |
1242 | else if (wrq->flags & IW_RETRY_MIN) | |
1243 | pDevice->byShortRetryLimit = wrq->value; | |
1244 | else { | |
1245 | // No modifier : set both | |
1246 | pDevice->byShortRetryLimit = wrq->value; | |
1247 | pDevice->byLongRetryLimit = wrq->value; | |
1248 | } | |
1249 | } | |
1250 | if (wrq->flags & IW_RETRY_LIFETIME) { | |
1251 | pDevice->wMaxTransmitMSDULifetime = wrq->value; | |
1252 | } | |
1253 | ||
1254 | ||
1255 | return rc; | |
1256 | } | |
1257 | ||
1258 | /* | |
1259 | * Wireless Handler : get retry threshold | |
1260 | */ | |
1261 | int iwctl_giwretry(struct net_device *dev, | |
1262 | struct iw_request_info *info, | |
1263 | struct iw_param *wrq, | |
1264 | char *extra) | |
1265 | { | |
c9d03529 | 1266 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
7e809a9b | 1267 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n"); |
5449c685 FB |
1268 | wrq->disabled = 0; // Can't be disabled |
1269 | ||
1270 | // Note : by default, display the min retry number | |
1271 | if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
1272 | wrq->flags = IW_RETRY_LIFETIME; | |
1273 | wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms | |
1274 | } else if((wrq->flags & IW_RETRY_MAX)) { | |
1275 | wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | |
1276 | wrq->value = (int)pDevice->byLongRetryLimit; | |
1277 | } else { | |
1278 | wrq->flags = IW_RETRY_LIMIT; | |
1279 | wrq->value = (int)pDevice->byShortRetryLimit; | |
1280 | if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit) | |
1281 | wrq->flags |= IW_RETRY_MIN; | |
1282 | } | |
1283 | ||
1284 | ||
1285 | return 0; | |
1286 | } | |
1287 | ||
1288 | ||
1289 | /* | |
1290 | * Wireless Handler : set encode mode | |
1291 | */ | |
1292 | int iwctl_siwencode(struct net_device *dev, | |
1293 | struct iw_request_info *info, | |
1294 | struct iw_point *wrq, | |
1295 | char *extra) | |
1296 | { | |
c9d03529 | 1297 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1298 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1299 | DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX); | |
1300 | int ii,uu, rc = 0; | |
1301 | int index = (wrq->flags & IW_ENCODE_INDEX); | |
1302 | ||
1303 | //2007-0207-07,<Modify> by EinsnLiu | |
1304 | //There are some problems when using iwconfig encode/key command to set the WEP key. | |
1305 | //I almost rewrite this function. | |
1306 | //now it support:(assume the wireless interface's name is eth0) | |
1307 | //iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/ | |
1308 | //iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */ | |
1309 | //iwconfig eth0 key 1122334455 /*set key string to driver using index*/ | |
1310 | //iwconfig eth0 key restricted /*enable share key*/ | |
1311 | ||
1312 | PSKeyTable pkeytab; | |
1313 | ||
7e809a9b | 1314 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n"); |
5449c685 FB |
1315 | |
1316 | if((wrq->flags & IW_ENCODE_DISABLED)==0){ | |
1317 | //Not disable encryption | |
1318 | ||
1319 | if (dwKeyIndex > WLAN_WEP_NKEYS) { | |
1320 | rc = -EINVAL; | |
1321 | return rc; | |
1322 | } | |
1323 | ||
1324 | if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key | |
1325 | if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){ | |
1326 | dwKeyIndex=pDevice->byKeyIndex; | |
1327 | } | |
1328 | else dwKeyIndex=0; | |
1329 | }else dwKeyIndex--; | |
1330 | ||
1331 | ||
1332 | // Check the size of the key | |
1333 | if (wrq->length > WLAN_WEP232_KEYLEN) { | |
1334 | rc = -EINVAL; | |
1335 | return rc; | |
1336 | } | |
1337 | ||
1338 | if(wrq->length>0){//have key | |
1339 | ||
1340 | if (wrq->length == WLAN_WEP232_KEYLEN) { | |
7e809a9b | 1341 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n"); |
5449c685 FB |
1342 | } |
1343 | else if (wrq->length == WLAN_WEP104_KEYLEN) { | |
7e809a9b | 1344 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n"); |
5449c685 FB |
1345 | } |
1346 | else if (wrq->length == WLAN_WEP40_KEYLEN) { | |
7e809a9b | 1347 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex); |
5449c685 FB |
1348 | }else {//no support length |
1349 | rc = -EINVAL; | |
1350 | return rc; | |
1351 | } | |
1352 | memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN); | |
1353 | memcpy(pDevice->abyKey, extra, wrq->length); | |
1354 | ||
7e809a9b | 1355 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: "); |
5449c685 | 1356 | for (ii = 0; ii < wrq->length; ii++) { |
7e809a9b | 1357 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]); |
5449c685 FB |
1358 | } |
1359 | ||
1360 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
1361 | spin_lock_irq(&pDevice->lock); | |
1362 | KeybSetDefaultKey(&(pDevice->sKey), | |
1363 | (DWORD)(dwKeyIndex | (1 << 31)), | |
1364 | wrq->length, | |
1365 | NULL, | |
1366 | pDevice->abyKey, | |
1367 | KEY_CTL_WEP, | |
1368 | pDevice->PortOffset, | |
1369 | pDevice->byLocalID | |
1370 | ); | |
1371 | spin_unlock_irq(&pDevice->lock); | |
1372 | } | |
1373 | pDevice->byKeyIndex = (BYTE)dwKeyIndex; | |
1374 | pDevice->uKeyLength = wrq->length; | |
1375 | pDevice->bTransmitKey = TRUE; | |
1376 | pDevice->bEncryptionEnable = TRUE; | |
1377 | pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; | |
1378 | ||
1379 | }else if(index>0){ | |
1380 | //when the length is 0 the request only changes the default transmit key index | |
1381 | //check the new key has a non zero lenget | |
1382 | if(pDevice->bEncryptionEnable==FALSE) | |
1383 | { | |
1384 | rc = -EINVAL; | |
1385 | return rc; | |
1386 | } | |
7e809a9b | 1387 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n"); |
5449c685 FB |
1388 | pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]); |
1389 | if(pkeytab->GroupKey[(BYTE)dwKeyIndex].uKeyLength==0){ | |
7e809a9b | 1390 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n"); |
5449c685 FB |
1391 | rc = -EINVAL; |
1392 | return rc; | |
1393 | } | |
1394 | pDevice->byKeyIndex =(BYTE)dwKeyIndex; | |
1395 | pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31); | |
1396 | pkeytab->GroupKey[(BYTE)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31); | |
1397 | } | |
1398 | ||
1399 | }else {//disable the key | |
7e809a9b | 1400 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n"); |
5449c685 FB |
1401 | if(pDevice->bEncryptionEnable==FALSE) |
1402 | return 0; | |
1403 | pMgmt->bShareKeyAlgorithm = FALSE; | |
1404 | pDevice->bEncryptionEnable = FALSE; | |
1405 | pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; | |
1406 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
1407 | spin_lock_irq(&pDevice->lock); | |
1408 | for(uu=0;uu<MAX_KEY_TABLE;uu++) | |
1409 | MACvDisableKeyEntry(pDevice->PortOffset, uu); | |
1410 | spin_unlock_irq(&pDevice->lock); | |
1411 | } | |
1412 | } | |
1413 | //End Modify,Einsn | |
1414 | ||
1415 | /* | |
612822f5 | 1416 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n"); |
5449c685 FB |
1417 | |
1418 | // Check the size of the key | |
1419 | if (wrq->length > WLAN_WEP232_KEYLEN) { | |
1420 | rc = -EINVAL; | |
1421 | return rc; | |
1422 | } | |
1423 | ||
1424 | if (dwKeyIndex > WLAN_WEP_NKEYS) { | |
1425 | rc = -EINVAL; | |
1426 | return rc; | |
1427 | } | |
1428 | ||
1429 | if (dwKeyIndex > 0) | |
1430 | dwKeyIndex--; | |
1431 | ||
1432 | // Send the key to the card | |
1433 | if (wrq->length > 0) { | |
1434 | ||
1435 | if (wrq->length == WLAN_WEP232_KEYLEN) { | |
7e809a9b | 1436 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n"); |
5449c685 FB |
1437 | } |
1438 | else if (wrq->length == WLAN_WEP104_KEYLEN) { | |
7e809a9b | 1439 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n"); |
5449c685 FB |
1440 | } |
1441 | else if (wrq->length == WLAN_WEP40_KEYLEN) { | |
7e809a9b | 1442 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex); |
5449c685 FB |
1443 | } |
1444 | memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN); | |
1445 | memcpy(pDevice->abyKey, extra, wrq->length); | |
1446 | ||
7e809a9b | 1447 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: "); |
5449c685 | 1448 | for (ii = 0; ii < wrq->length; ii++) { |
7e809a9b | 1449 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]); |
5449c685 FB |
1450 | } |
1451 | ||
1452 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
1453 | spin_lock_irq(&pDevice->lock); | |
1454 | KeybSetDefaultKey(&(pDevice->sKey), | |
1455 | (DWORD)(pDevice->byKeyIndex | (1 << 31)), | |
1456 | pDevice->uKeyLength, | |
1457 | NULL, | |
1458 | pDevice->abyKey, | |
1459 | KEY_CTL_WEP, | |
1460 | pDevice->PortOffset, | |
1461 | pDevice->byLocalID | |
1462 | ); | |
1463 | spin_unlock_irq(&pDevice->lock); | |
1464 | } | |
1465 | pDevice->byKeyIndex = (BYTE)dwKeyIndex; | |
1466 | pDevice->uKeyLength = wrq->length; | |
1467 | pDevice->bTransmitKey = TRUE; | |
1468 | pDevice->bEncryptionEnable = TRUE; | |
1469 | pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; | |
1470 | ||
1471 | // Do we want to just set the transmit key index ? | |
1472 | if ( index < 4 ) { | |
1473 | pDevice->byKeyIndex = index; | |
1474 | } | |
267c39c9 | 1475 | else if(!(wrq->flags & IW_ENCODE_MODE)) { |
5449c685 FB |
1476 | rc = -EINVAL; |
1477 | return rc; | |
1478 | } | |
1479 | } | |
1480 | // Read the flags | |
1481 | if(wrq->flags & IW_ENCODE_DISABLED){ | |
1482 | ||
7e809a9b | 1483 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n"); |
5449c685 FB |
1484 | pMgmt->bShareKeyAlgorithm = FALSE; |
1485 | pDevice->bEncryptionEnable = FALSE; | |
1486 | pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; | |
1487 | if (pDevice->flags & DEVICE_FLAGS_OPENED) { | |
1488 | spin_lock_irq(&pDevice->lock); | |
1489 | for(uu=0;uu<MAX_KEY_TABLE;uu++) | |
1490 | MACvDisableKeyEntry(pDevice->PortOffset, uu); | |
1491 | spin_unlock_irq(&pDevice->lock); | |
1492 | } | |
1493 | } | |
1494 | */ | |
1495 | ||
1496 | if(wrq->flags & IW_ENCODE_RESTRICTED) { | |
7e809a9b | 1497 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n"); |
5449c685 FB |
1498 | pMgmt->bShareKeyAlgorithm = TRUE; |
1499 | } | |
1500 | if(wrq->flags & IW_ENCODE_OPEN) { | |
7e809a9b | 1501 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n"); |
5449c685 FB |
1502 | pMgmt->bShareKeyAlgorithm = FALSE; |
1503 | } | |
1504 | return rc; | |
1505 | } | |
1506 | ||
1507 | /* | |
1508 | * Wireless Handler : get encode mode | |
1509 | */ | |
1510 | /* | |
1511 | int iwctl_giwencode(struct net_device *dev, | |
1512 | struct iw_request_info *info, | |
1513 | struct iw_point *wrq, | |
1514 | char *extra) | |
1515 | { | |
c9d03529 | 1516 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1517 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1518 | int rc = 0; | |
1519 | char abyKey[WLAN_WEP232_KEYLEN]; | |
1520 | UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX); | |
1521 | PSKeyItem pKey = NULL; | |
1522 | ||
7e809a9b | 1523 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n"); |
5449c685 FB |
1524 | //2007-0207-06,<Add> by EinsnLiu |
1525 | //the key index in iwconfig is 1-4 when our driver is 0-3 | |
1526 | //so it can't be used directly. | |
1527 | //if the index is 0,we should used the index set by driver. | |
1528 | if (index > WLAN_WEP_NKEYS) { | |
1529 | rc = -EINVAL; | |
1530 | return rc; | |
1531 | } | |
1532 | if(index<1){//set default key | |
1533 | if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){ | |
1534 | index=pDevice->byKeyIndex; | |
1535 | } | |
1536 | else index=0; | |
1537 | }else index--; | |
1538 | //End Add,Einsn | |
1539 | ||
1540 | memset(abyKey, 0, sizeof(abyKey)); | |
1541 | // Check encryption mode | |
1542 | wrq->flags = IW_ENCODE_NOKEY; | |
1543 | // Is WEP enabled ??? | |
1544 | if (pDevice->bEncryptionEnable) | |
1545 | wrq->flags |= IW_ENCODE_ENABLED; | |
1546 | else | |
1547 | wrq->flags |= IW_ENCODE_DISABLED; | |
1548 | ||
1549 | if (pMgmt->bShareKeyAlgorithm) | |
1550 | wrq->flags |= IW_ENCODE_RESTRICTED; | |
1551 | else | |
1552 | wrq->flags |= IW_ENCODE_OPEN; | |
1553 | ||
1554 | if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){ | |
1555 | wrq->length = pKey->uKeyLength; | |
1556 | memcpy(abyKey, pKey->abyKey, pKey->uKeyLength); | |
1557 | //2007-0207-06,<Modify> by EinsnLiu | |
1558 | //only get key success need to copy data | |
1559 | //index should +1. | |
1560 | //there is not necessary to return -EINVAL when get key failed | |
1561 | //if return -EINVAL,the encryption item can't be display by the command "iwconfig". | |
1562 | wrq->flags |= index+1; | |
1563 | memcpy(extra, abyKey, WLAN_WEP232_KEYLEN); | |
1564 | } | |
1565 | ||
1566 | //else { | |
1567 | // rc = -EINVAL; | |
1568 | // return rc; | |
1569 | // } | |
1570 | ||
1571 | ||
1572 | //End Modify,Einsn | |
1573 | ||
1574 | return 0; | |
1575 | } | |
1576 | */ | |
1577 | ||
1578 | //2008-0409-06, <Add> by Einsn Liu | |
1579 | ||
1580 | int iwctl_giwencode(struct net_device *dev, | |
1581 | struct iw_request_info *info, | |
1582 | struct iw_point *wrq, | |
1583 | char *extra) | |
1584 | { | |
c9d03529 | 1585 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1586 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1587 | char abyKey[WLAN_WEP232_KEYLEN]; | |
1588 | ||
1589 | UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX); | |
1590 | PSKeyItem pKey = NULL; | |
1591 | ||
7e809a9b | 1592 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n"); |
5449c685 FB |
1593 | |
1594 | if (index > WLAN_WEP_NKEYS) { | |
1595 | return -EINVAL; | |
1596 | } | |
1597 | if(index<1){//get default key | |
1598 | if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){ | |
1599 | index=pDevice->byKeyIndex; | |
1600 | } else | |
1601 | index=0; | |
1602 | }else | |
1603 | index--; | |
1604 | ||
1605 | memset(abyKey, 0, WLAN_WEP232_KEYLEN); | |
1606 | // Check encryption mode | |
1607 | wrq->flags = IW_ENCODE_NOKEY; | |
1608 | // Is WEP enabled ??? | |
1609 | if (pDevice->bEncryptionEnable) | |
1610 | wrq->flags |= IW_ENCODE_ENABLED; | |
1611 | else | |
1612 | wrq->flags |= IW_ENCODE_DISABLED; | |
1613 | ||
1614 | if (pMgmt->bShareKeyAlgorithm) | |
1615 | wrq->flags |= IW_ENCODE_RESTRICTED; | |
1616 | else | |
1617 | wrq->flags |= IW_ENCODE_OPEN; | |
1618 | wrq->length=0; | |
1619 | ||
1620 | if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled|| | |
1621 | pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise key | |
1622 | if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){ | |
1623 | wrq->length = pKey->uKeyLength; | |
1624 | memcpy(abyKey, pKey->abyKey, pKey->uKeyLength); | |
1625 | memcpy(extra, abyKey, WLAN_WEP232_KEYLEN); | |
1626 | } | |
1627 | }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){ | |
1628 | wrq->length = pKey->uKeyLength; | |
1629 | memcpy(abyKey, pKey->abyKey, pKey->uKeyLength); | |
1630 | memcpy(extra, abyKey, WLAN_WEP232_KEYLEN); | |
1631 | } | |
1632 | ||
1633 | wrq->flags |= index+1; | |
1634 | ||
1635 | return 0; | |
1636 | } | |
1637 | ||
612822f5 | 1638 | |
5449c685 FB |
1639 | /* |
1640 | * Wireless Handler : set power mode | |
1641 | */ | |
1642 | int iwctl_siwpower(struct net_device *dev, | |
1643 | struct iw_request_info *info, | |
1644 | struct iw_param *wrq, | |
1645 | char *extra) | |
1646 | { | |
c9d03529 | 1647 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1648 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1649 | int rc = 0; | |
1650 | ||
7e809a9b | 1651 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n"); |
5449c685 FB |
1652 | |
1653 | if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) { | |
1654 | rc = -EINVAL; | |
1655 | return rc; | |
1656 | } | |
1657 | ||
1658 | if (wrq->disabled) { | |
1659 | pDevice->ePSMode = WMAC_POWER_CAM; | |
1660 | PSvDisablePowerSaving(pDevice); | |
1661 | return rc; | |
1662 | } | |
1663 | if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { | |
1664 | pDevice->ePSMode = WMAC_POWER_FAST; | |
1665 | PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval); | |
1666 | ||
1667 | } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) { | |
1668 | pDevice->ePSMode = WMAC_POWER_FAST; | |
1669 | PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval); | |
1670 | } | |
1671 | switch (wrq->flags & IW_POWER_MODE) { | |
1672 | case IW_POWER_UNICAST_R: | |
7e809a9b | 1673 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n"); |
5449c685 FB |
1674 | rc = -EINVAL; |
1675 | break; | |
1676 | case IW_POWER_ALL_R: | |
7e809a9b | 1677 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n"); |
5449c685 FB |
1678 | rc = -EINVAL; |
1679 | case IW_POWER_ON: | |
7e809a9b | 1680 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n"); |
5449c685 FB |
1681 | break; |
1682 | default: | |
1683 | rc = -EINVAL; | |
1684 | } | |
1685 | ||
1686 | return rc; | |
1687 | } | |
1688 | ||
1689 | /* | |
1690 | * Wireless Handler : get power mode | |
1691 | */ | |
1692 | int iwctl_giwpower(struct net_device *dev, | |
1693 | struct iw_request_info *info, | |
1694 | struct iw_param *wrq, | |
1695 | char *extra) | |
1696 | { | |
c9d03529 | 1697 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1698 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1699 | int mode = pDevice->ePSMode; | |
1700 | ||
1701 | ||
7e809a9b | 1702 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n"); |
5449c685 FB |
1703 | |
1704 | ||
1705 | if ((wrq->disabled = (mode == WMAC_POWER_CAM))) | |
1706 | return 0; | |
1707 | ||
1708 | if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { | |
1709 | wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10); | |
1710 | wrq->flags = IW_POWER_TIMEOUT; | |
1711 | } else { | |
1712 | wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10); | |
1713 | wrq->flags = IW_POWER_PERIOD; | |
1714 | } | |
1715 | wrq->flags |= IW_POWER_ALL_R; | |
1716 | ||
1717 | return 0; | |
1718 | } | |
1719 | ||
1720 | ||
1721 | /* | |
1722 | * Wireless Handler : get Sensitivity | |
1723 | */ | |
1724 | int iwctl_giwsens(struct net_device *dev, | |
1725 | struct iw_request_info *info, | |
1726 | struct iw_param *wrq, | |
1727 | char *extra) | |
1728 | { | |
c9d03529 | 1729 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1730 | long ldBm; |
1731 | ||
7e809a9b | 1732 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n"); |
5449c685 FB |
1733 | if (pDevice->bLinkPass == TRUE) { |
1734 | RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm); | |
1735 | wrq->value = ldBm; | |
1736 | } | |
1737 | else { | |
1738 | wrq->value = 0; | |
1739 | }; | |
1740 | wrq->disabled = (wrq->value == 0); | |
1741 | wrq->fixed = 1; | |
1742 | ||
1743 | ||
1744 | return 0; | |
1745 | } | |
1746 | ||
1747 | //2008-0409-07, <Add> by Einsn Liu | |
1748 | #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT | |
1749 | ||
1750 | int iwctl_siwauth(struct net_device *dev, | |
1751 | struct iw_request_info *info, | |
1752 | struct iw_param *wrq, | |
1753 | char *extra) | |
1754 | { | |
c9d03529 | 1755 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1756 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1757 | int ret=0; | |
1758 | static int wpa_version=0; //must be static to save the last value,einsn liu | |
1759 | static int pairwise=0; | |
1760 | ||
7e809a9b | 1761 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n"); |
5449c685 FB |
1762 | switch (wrq->flags & IW_AUTH_INDEX) { |
1763 | case IW_AUTH_WPA_VERSION: | |
1764 | wpa_version = wrq->value; | |
1765 | if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) { | |
612822f5 | 1766 | PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n"); |
5449c685 FB |
1767 | //pDevice->bWPADevEnable = FALSE; |
1768 | } | |
1769 | else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) { | |
612822f5 | 1770 | PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n"); |
5449c685 FB |
1771 | } |
1772 | else { | |
612822f5 | 1773 | PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n"); |
5449c685 FB |
1774 | } |
1775 | //pDevice->bWPASuppWextEnabled =TRUE; | |
1776 | break; | |
1777 | case IW_AUTH_CIPHER_PAIRWISE: | |
1778 | pairwise = wrq->value; | |
5449c685 FB |
1779 | if(pairwise == IW_AUTH_CIPHER_CCMP){ |
1780 | pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; | |
1781 | }else if(pairwise == IW_AUTH_CIPHER_TKIP){ | |
1782 | pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; | |
1783 | }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){ | |
1784 | pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; | |
1785 | }else if(pairwise == IW_AUTH_CIPHER_NONE){ | |
1786 | //do nothing,einsn liu | |
1787 | }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; | |
1788 | ||
1789 | break; | |
1790 | case IW_AUTH_CIPHER_GROUP: | |
1791 | if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED) | |
1792 | break; | |
1793 | if(pairwise == IW_AUTH_CIPHER_NONE){ | |
1794 | if(wrq->value == IW_AUTH_CIPHER_CCMP){ | |
1795 | pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; | |
1796 | }else { | |
1797 | pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; | |
1798 | } | |
1799 | } | |
1800 | break; | |
1801 | case IW_AUTH_KEY_MGMT: | |
1802 | ||
1803 | if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){ | |
1804 | if(wrq->value == IW_AUTH_KEY_MGMT_PSK) | |
1805 | pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK; | |
1806 | else pMgmt->eAuthenMode = WMAC_AUTH_WPA2; | |
1807 | }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){ | |
1808 | if(wrq->value == 0){ | |
1809 | pMgmt->eAuthenMode = WMAC_AUTH_WPANONE; | |
1810 | }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK) | |
1811 | pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK; | |
1812 | else pMgmt->eAuthenMode = WMAC_AUTH_WPA; | |
1813 | } | |
1814 | ||
1815 | break; | |
1816 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
1817 | break; /* FIXME */ | |
1818 | case IW_AUTH_DROP_UNENCRYPTED: | |
1819 | break; | |
1820 | case IW_AUTH_80211_AUTH_ALG: | |
1821 | if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){ | |
1822 | pMgmt->bShareKeyAlgorithm=FALSE; | |
1823 | }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){ | |
1824 | pMgmt->bShareKeyAlgorithm=TRUE; | |
1825 | } | |
1826 | break; | |
1827 | case IW_AUTH_WPA_ENABLED: | |
1828 | //pDevice->bWPADevEnable = !! wrq->value; | |
1829 | break; | |
1830 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
1831 | break; | |
1832 | case IW_AUTH_ROAMING_CONTROL: | |
1833 | ret = -EOPNOTSUPP; | |
1834 | break; | |
1835 | case IW_AUTH_PRIVACY_INVOKED: | |
1836 | pDevice->bEncryptionEnable = !!wrq->value; | |
1837 | if(pDevice->bEncryptionEnable == FALSE){ | |
1838 | wpa_version = 0; | |
1839 | pairwise = 0; | |
1840 | pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; | |
1841 | pMgmt->bShareKeyAlgorithm = FALSE; | |
1842 | pMgmt->eAuthenMode = FALSE; | |
1843 | //pDevice->bWPADevEnable = FALSE; | |
1844 | } | |
1845 | ||
1846 | break; | |
1847 | default: | |
1848 | ret = -EOPNOTSUPP; | |
1849 | break; | |
1850 | } | |
1851 | /* | |
7e809a9b JL |
1852 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version); |
1853 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise); | |
1854 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus); | |
1855 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode = %d\n",pMgmt->eAuthenMode); | |
1856 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"TRUE":"FALSE"); | |
1857 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"TRUE":"FALSE"); | |
1858 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"TRUE":"FALSE"); | |
5449c685 FB |
1859 | */ |
1860 | return ret; | |
1861 | } | |
1862 | ||
1863 | ||
1864 | int iwctl_giwauth(struct net_device *dev, | |
1865 | struct iw_request_info *info, | |
1866 | struct iw_param *wrq, | |
1867 | char *extra) | |
1868 | { | |
1869 | return -EOPNOTSUPP; | |
1870 | } | |
1871 | ||
1872 | ||
1873 | ||
1874 | int iwctl_siwgenie(struct net_device *dev, | |
1875 | struct iw_request_info *info, | |
1876 | struct iw_point *wrq, | |
1877 | char *extra) | |
1878 | { | |
c9d03529 | 1879 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1880 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1881 | int ret=0; | |
1882 | ||
1883 | if(wrq->length){ | |
1884 | if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) { | |
1885 | ret = -EINVAL; | |
1886 | goto out; | |
1887 | } | |
1888 | if(wrq->length > MAX_WPA_IE_LEN){ | |
1889 | ret = -ENOMEM; | |
1890 | goto out; | |
1891 | } | |
1892 | memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN); | |
1893 | if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){ | |
1894 | ret = -EFAULT; | |
1895 | goto out; | |
1896 | } | |
1897 | pMgmt->wWPAIELen = wrq->length; | |
1898 | }else { | |
1899 | memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN); | |
1900 | pMgmt->wWPAIELen = 0; | |
1901 | } | |
1902 | ||
1903 | out://not completely ...not necessary in wpa_supplicant 0.5.8 | |
1904 | return 0; | |
1905 | } | |
1906 | ||
1907 | int iwctl_giwgenie(struct net_device *dev, | |
1908 | struct iw_request_info *info, | |
1909 | struct iw_point *wrq, | |
1910 | char *extra) | |
1911 | { | |
c9d03529 | 1912 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1913 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
1914 | int ret=0; | |
1915 | int space = wrq->length; | |
1916 | ||
1917 | wrq->length = 0; | |
1918 | if(pMgmt->wWPAIELen > 0){ | |
1919 | wrq->length = pMgmt->wWPAIELen; | |
1920 | if(pMgmt->wWPAIELen <= space){ | |
1921 | if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){ | |
1922 | ret = -EFAULT; | |
1923 | } | |
1924 | }else | |
1925 | ret = -E2BIG; | |
1926 | } | |
1927 | ||
1928 | return ret; | |
1929 | } | |
1930 | ||
1931 | ||
1932 | int iwctl_siwencodeext(struct net_device *dev, | |
1933 | struct iw_request_info *info, | |
1934 | struct iw_point *wrq, | |
1935 | char *extra) | |
1936 | { | |
c9d03529 | 1937 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
1938 | struct iw_encode_ext *ext = (struct iw_encode_ext*)extra; |
1939 | struct viawget_wpa_param *param=NULL; | |
1940 | //original member | |
1941 | wpa_alg alg_name; | |
1942 | u8 addr[6]; | |
612822f5 | 1943 | int key_idx, set_tx=0; |
5449c685 FB |
1944 | u8 seq[IW_ENCODE_SEQ_MAX_SIZE]; |
1945 | u8 key[64]; | |
612822f5 | 1946 | size_t seq_len=0,key_len=0; |
5449c685 FB |
1947 | // |
1948 | // int ii; | |
1949 | u8 *buf; | |
1950 | size_t blen; | |
1951 | u8 key_array[64]; | |
1952 | int ret=0; | |
1953 | ||
612822f5 | 1954 | PRINT_K("SIOCSIWENCODEEXT...... \n"); |
5449c685 FB |
1955 | |
1956 | blen = sizeof(*param); | |
1957 | buf = kmalloc((int)blen, (int)GFP_KERNEL); | |
1958 | if (buf == NULL) | |
1959 | return -ENOMEM; | |
1960 | memset(buf, 0, blen); | |
1961 | param = (struct viawget_wpa_param *) buf; | |
1962 | ||
1963 | //recover alg_name | |
1964 | switch (ext->alg) { | |
1965 | case IW_ENCODE_ALG_NONE: | |
1966 | alg_name = WPA_ALG_NONE; | |
1967 | break; | |
1968 | case IW_ENCODE_ALG_WEP: | |
1969 | alg_name = WPA_ALG_WEP; | |
1970 | break; | |
1971 | case IW_ENCODE_ALG_TKIP: | |
1972 | alg_name = WPA_ALG_TKIP; | |
1973 | break; | |
1974 | case IW_ENCODE_ALG_CCMP: | |
1975 | alg_name = WPA_ALG_CCMP; | |
1976 | break; | |
1977 | default: | |
612822f5 | 1978 | PRINT_K("Unknown alg = %d\n",ext->alg); |
5449c685 FB |
1979 | ret= -ENOMEM; |
1980 | goto error; | |
1981 | } | |
1982 | //recover addr | |
1983 | memcpy(addr, ext->addr.sa_data, ETH_ALEN); | |
1984 | //recover key_idx | |
1985 | key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1; | |
1986 | //recover set_tx | |
1987 | if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) | |
1988 | set_tx = 1; | |
1989 | //recover seq,seq_len | |
1990 | if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { | |
1991 | seq_len=IW_ENCODE_SEQ_MAX_SIZE; | |
1992 | memcpy(seq, ext->rx_seq, seq_len); | |
1993 | } | |
1994 | //recover key,key_len | |
1995 | if(ext->key_len) { | |
1996 | key_len=ext->key_len; | |
1997 | memcpy(key, &ext->key[0], key_len); | |
1998 | } | |
1999 | ||
2000 | memset(key_array, 0, 64); | |
2001 | if ( key_len > 0) { | |
2002 | memcpy(key_array, key, key_len); | |
2003 | if (key_len == 32) { | |
2004 | // notice ! the oder | |
2005 | memcpy(&key_array[16], &key[24], 8); | |
2006 | memcpy(&key_array[24], &key[16], 8); | |
2007 | } | |
2008 | } | |
2009 | ||
2010 | /**************Translate iw_encode_ext to viawget_wpa_param****************/ | |
2011 | memcpy(param->addr, addr, ETH_ALEN); | |
2012 | param->u.wpa_key.alg_name = (int)alg_name; | |
2013 | param->u.wpa_key.set_tx = set_tx; | |
2014 | param->u.wpa_key.key_index = key_idx; | |
2015 | param->u.wpa_key.key_len = key_len; | |
2016 | param->u.wpa_key.key = (u8 *)key_array; | |
2017 | param->u.wpa_key.seq = (u8 *)seq; | |
2018 | param->u.wpa_key.seq_len = seq_len; | |
2019 | ||
2020 | #if 0 | |
5449c685 FB |
2021 | printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name); |
2022 | printk("param->addr=%02x:%02x:%02x:%02x:%02x:%02x\n", | |
2023 | param->addr[0],param->addr[1],param->addr[2], | |
2024 | param->addr[3],param->addr[4],param->addr[5]); | |
2025 | printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx); | |
2026 | printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index); | |
2027 | printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len); | |
2028 | printk("param->u.wpa_key.key ="); | |
2029 | for(ii=0;ii<param->u.wpa_key.key_len;ii++) | |
2030 | printk("%02x:",param->u.wpa_key.key[ii]); | |
2031 | printk("\n"); | |
2032 | printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len); | |
2033 | printk("param->u.wpa_key.seq ="); | |
2034 | for(ii=0;ii<param->u.wpa_key.seq_len;ii++) | |
2035 | printk("%02x:",param->u.wpa_key.seq[ii]); | |
2036 | printk("\n"); | |
2037 | ||
2038 | printk("...........\n"); | |
2039 | #endif | |
2040 | //****set if current action is Network Manager count?? | |
2041 | //****this method is so foolish,but there is no other way??? | |
2042 | if(param->u.wpa_key.alg_name == WPA_ALG_NONE) { | |
2043 | if(param->u.wpa_key.key_index ==0) { | |
2044 | pDevice->bwextcount++; | |
2045 | } | |
2046 | if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) { | |
2047 | pDevice->bwextcount++; | |
2048 | } | |
2049 | if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) { | |
2050 | pDevice->bwextcount++; | |
2051 | } | |
2052 | if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) { | |
2053 | pDevice->bwextcount++; | |
2054 | } | |
2055 | } | |
2056 | if( pDevice->bwextcount == 4) { | |
2057 | printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n"); | |
2058 | pDevice->bwextcount=0; | |
2059 | pDevice->bWPASuppWextEnabled = TRUE; | |
2060 | } | |
2061 | //****** | |
2062 | ||
2063 | spin_lock_irq(&pDevice->lock); | |
2064 | ret = wpa_set_keys(pDevice, param, TRUE); | |
2065 | spin_unlock_irq(&pDevice->lock); | |
2066 | ||
2067 | error: | |
2068 | kfree(param); | |
2069 | return ret; | |
2070 | } | |
2071 | ||
2072 | ||
2073 | ||
2074 | int iwctl_giwencodeext(struct net_device *dev, | |
2075 | struct iw_request_info *info, | |
2076 | struct iw_point *wrq, | |
2077 | char *extra) | |
2078 | { | |
2079 | return -EOPNOTSUPP;; | |
2080 | } | |
2081 | ||
2082 | int iwctl_siwmlme(struct net_device *dev, | |
2083 | struct iw_request_info * info, | |
2084 | struct iw_point *wrq, | |
2085 | char *extra) | |
2086 | { | |
c9d03529 | 2087 | PSDevice pDevice = (PSDevice)netdev_priv(dev); |
5449c685 FB |
2088 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
2089 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | |
2090 | //u16 reason = cpu_to_le16(mlme->reason_code); | |
2091 | int ret = 0; | |
2092 | ||
2093 | if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){ | |
2094 | ret = -EINVAL; | |
2095 | return ret; | |
2096 | } | |
2097 | switch(mlme->cmd){ | |
2098 | case IW_MLME_DEAUTH: | |
2099 | //this command seems to be not complete,please test it --einsnliu | |
2100 | //bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&reason); | |
2101 | break; | |
2102 | case IW_MLME_DISASSOC: | |
2103 | if(pDevice->bLinkPass == TRUE){ | |
2104 | printk("iwctl_siwmlme--->send DISASSOCIATE\n"); | |
2105 | //clear related flags | |
2106 | memset(pMgmt->abyDesireBSSID, 0xFF,6); | |
2107 | KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); | |
2108 | bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL); | |
2109 | } | |
2110 | break; | |
2111 | default: | |
2112 | ret = -EOPNOTSUPP; | |
2113 | } | |
2114 | ||
2115 | return ret; | |
2116 | ||
2117 | } | |
2118 | ||
2119 | #endif | |
2120 | ||
2121 | ||
2122 | /*------------------------------------------------------------------*/ | |
2123 | /* | |
2124 | * Structures to export the Wireless Handlers | |
2125 | */ | |
2126 | ||
2127 | ||
5449c685 FB |
2128 | /* |
2129 | static const iw_handler iwctl_handler[] = | |
2130 | { | |
2131 | (iw_handler) iwctl_commit, // SIOCSIWCOMMIT | |
2132 | (iw_handler) iwctl_giwname, // SIOCGIWNAME | |
2133 | (iw_handler) NULL, // SIOCSIWNWID | |
2134 | (iw_handler) NULL, // SIOCGIWNWID | |
2135 | (iw_handler) iwctl_siwfreq, // SIOCSIWFREQ | |
2136 | (iw_handler) iwctl_giwfreq, // SIOCGIWFREQ | |
2137 | (iw_handler) iwctl_siwmode, // SIOCSIWMODE | |
2138 | (iw_handler) iwctl_giwmode, // SIOCGIWMODE | |
2139 | (iw_handler) NULL, // SIOCSIWSENS | |
2140 | (iw_handler) iwctl_giwsens, // SIOCGIWSENS | |
2141 | (iw_handler) NULL, // SIOCSIWRANGE | |
2142 | (iw_handler) iwctl_giwrange, // SIOCGIWRANGE | |
2143 | (iw_handler) NULL, // SIOCSIWPRIV | |
2144 | (iw_handler) NULL, // SIOCGIWPRIV | |
2145 | (iw_handler) NULL, // SIOCSIWSTATS | |
2146 | (iw_handler) NULL, // SIOCGIWSTATS | |
2147 | (iw_handler) NULL, // SIOCSIWSPY | |
2148 | (iw_handler) NULL, // SIOCGIWSPY | |
2149 | (iw_handler) NULL, // -- hole -- | |
2150 | (iw_handler) NULL, // -- hole -- | |
2151 | (iw_handler) iwctl_siwap, // SIOCSIWAP | |
2152 | (iw_handler) iwctl_giwap, // SIOCGIWAP | |
2153 | (iw_handler) NULL, // -- hole -- 0x16 | |
2154 | (iw_handler) iwctl_giwaplist, // SIOCGIWAPLIST | |
5449c685 FB |
2155 | (iw_handler) iwctl_siwscan, // SIOCSIWSCAN |
2156 | (iw_handler) iwctl_giwscan, // SIOCGIWSCAN | |
5449c685 FB |
2157 | (iw_handler) iwctl_siwessid, // SIOCSIWESSID |
2158 | (iw_handler) iwctl_giwessid, // SIOCGIWESSID | |
2159 | (iw_handler) NULL, // SIOCSIWNICKN | |
2160 | (iw_handler) NULL, // SIOCGIWNICKN | |
2161 | (iw_handler) NULL, // -- hole -- | |
2162 | (iw_handler) NULL, // -- hole -- | |
2163 | (iw_handler) iwctl_siwrate, // SIOCSIWRATE 0x20 | |
2164 | (iw_handler) iwctl_giwrate, // SIOCGIWRATE | |
2165 | (iw_handler) iwctl_siwrts, // SIOCSIWRTS | |
2166 | (iw_handler) iwctl_giwrts, // SIOCGIWRTS | |
2167 | (iw_handler) iwctl_siwfrag, // SIOCSIWFRAG | |
2168 | (iw_handler) iwctl_giwfrag, // SIOCGIWFRAG | |
2169 | (iw_handler) NULL, // SIOCSIWTXPOW | |
2170 | (iw_handler) NULL, // SIOCGIWTXPOW | |
2171 | (iw_handler) iwctl_siwretry, // SIOCSIWRETRY | |
2172 | (iw_handler) iwctl_giwretry, // SIOCGIWRETRY | |
2173 | (iw_handler) iwctl_siwencode, // SIOCSIWENCODE | |
2174 | (iw_handler) iwctl_giwencode, // SIOCGIWENCODE | |
2175 | (iw_handler) iwctl_siwpower, // SIOCSIWPOWER | |
2176 | (iw_handler) iwctl_giwpower, // SIOCGIWPOWER | |
5449c685 FB |
2177 | (iw_handler) NULL, // -- hole -- |
2178 | (iw_handler) NULL, // -- hole -- | |
2179 | (iw_handler) iwctl_siwgenie, // SIOCSIWGENIE | |
2180 | (iw_handler) iwctl_giwgenie, // SIOCGIWGENIE | |
2181 | (iw_handler) iwctl_siwauth, // SIOCSIWAUTH | |
2182 | (iw_handler) iwctl_giwauth, // SIOCGIWAUTH | |
2183 | (iw_handler) iwctl_siwencodeext, // SIOCSIWENCODEEXT | |
2184 | (iw_handler) iwctl_giwencodeext, // SIOCGIWENCODEEXT | |
2185 | (iw_handler) NULL, // SIOCSIWPMKSA | |
2186 | (iw_handler) NULL, // -- hole -- | |
5449c685 FB |
2187 | |
2188 | }; | |
2189 | */ | |
2190 | ||
2191 | static const iw_handler iwctl_handler[] = | |
2192 | { | |
2193 | (iw_handler) iwctl_commit, // SIOCSIWCOMMIT | |
2194 | (iw_handler) NULL, // SIOCGIWNAME | |
2195 | (iw_handler) NULL, // SIOCSIWNWID | |
2196 | (iw_handler) NULL, // SIOCGIWNWID | |
2197 | (iw_handler) NULL, // SIOCSIWFREQ | |
2198 | (iw_handler) NULL, // SIOCGIWFREQ | |
2199 | (iw_handler) NULL, // SIOCSIWMODE | |
2200 | (iw_handler) NULL, // SIOCGIWMODE | |
2201 | (iw_handler) NULL, // SIOCSIWSENS | |
2202 | (iw_handler) NULL, // SIOCGIWSENS | |
2203 | (iw_handler) NULL, // SIOCSIWRANGE | |
2204 | (iw_handler) iwctl_giwrange, // SIOCGIWRANGE | |
2205 | (iw_handler) NULL, // SIOCSIWPRIV | |
2206 | (iw_handler) NULL, // SIOCGIWPRIV | |
2207 | (iw_handler) NULL, // SIOCSIWSTATS | |
2208 | (iw_handler) NULL, // SIOCGIWSTATS | |
2209 | (iw_handler) NULL, // SIOCSIWSPY | |
2210 | (iw_handler) NULL, // SIOCGIWSPY | |
2211 | (iw_handler) NULL, // -- hole -- | |
2212 | (iw_handler) NULL, // -- hole -- | |
2213 | (iw_handler) NULL, // SIOCSIWAP | |
2214 | (iw_handler) NULL, // SIOCGIWAP | |
2215 | (iw_handler) NULL, // -- hole -- 0x16 | |
2216 | (iw_handler) NULL, // SIOCGIWAPLIST | |
5449c685 FB |
2217 | (iw_handler) iwctl_siwscan, // SIOCSIWSCAN |
2218 | (iw_handler) iwctl_giwscan, // SIOCGIWSCAN | |
5449c685 FB |
2219 | (iw_handler) NULL, // SIOCSIWESSID |
2220 | (iw_handler) NULL, // SIOCGIWESSID | |
2221 | (iw_handler) NULL, // SIOCSIWNICKN | |
2222 | (iw_handler) NULL, // SIOCGIWNICKN | |
2223 | (iw_handler) NULL, // -- hole -- | |
2224 | (iw_handler) NULL, // -- hole -- | |
2225 | (iw_handler) NULL, // SIOCSIWRATE 0x20 | |
2226 | (iw_handler) NULL, // SIOCGIWRATE | |
2227 | (iw_handler) NULL, // SIOCSIWRTS | |
2228 | (iw_handler) NULL, // SIOCGIWRTS | |
2229 | (iw_handler) NULL, // SIOCSIWFRAG | |
2230 | (iw_handler) NULL, // SIOCGIWFRAG | |
2231 | (iw_handler) NULL, // SIOCSIWTXPOW | |
2232 | (iw_handler) NULL, // SIOCGIWTXPOW | |
2233 | (iw_handler) NULL, // SIOCSIWRETRY | |
2234 | (iw_handler) NULL, // SIOCGIWRETRY | |
2235 | (iw_handler) NULL, // SIOCSIWENCODE | |
2236 | (iw_handler) NULL, // SIOCGIWENCODE | |
2237 | (iw_handler) NULL, // SIOCSIWPOWER | |
2238 | (iw_handler) NULL, // SIOCGIWPOWER | |
2239 | ||
2240 | //2008-0409-07, <Add> by Einsn Liu | |
5449c685 FB |
2241 | (iw_handler) NULL, // -- hole -- |
2242 | (iw_handler) NULL, // -- hole -- | |
2243 | (iw_handler) NULL, // SIOCSIWGENIE | |
2244 | (iw_handler) NULL, // SIOCGIWGENIE | |
2245 | (iw_handler) NULL, // SIOCSIWAUTH | |
2246 | (iw_handler) NULL, // SIOCGIWAUTH | |
2247 | (iw_handler) NULL, // SIOCSIWENCODEEXT | |
2248 | (iw_handler) NULL, // SIOCGIWENCODEEXT | |
2249 | (iw_handler) NULL, // SIOCSIWPMKSA | |
2250 | (iw_handler) NULL, // -- hole -- | |
5449c685 FB |
2251 | }; |
2252 | ||
2253 | ||
2254 | static const iw_handler iwctl_private_handler[] = | |
2255 | { | |
2256 | NULL, // SIOCIWFIRSTPRIV | |
2257 | }; | |
2258 | ||
2259 | ||
2260 | struct iw_priv_args iwctl_private_args[] = { | |
2261 | { IOCTL_CMD_SET, | |
2262 | IW_PRIV_TYPE_CHAR | 1024, 0, | |
2263 | "set"}, | |
2264 | }; | |
2265 | ||
2266 | ||
2267 | ||
2268 | const struct iw_handler_def iwctl_handler_def = | |
2269 | { | |
5449c685 | 2270 | .get_wireless_stats = &iwctl_get_wireless_stats, |
5449c685 FB |
2271 | .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler), |
2272 | // .num_private = sizeof(iwctl_private_handler)/sizeof(iw_handler), | |
2273 | // .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args), | |
2274 | .num_private = 0, | |
2275 | .num_private_args = 0, | |
2276 | .standard = (iw_handler *) iwctl_handler, | |
2277 | // .private = (iw_handler *) iwctl_private_handler, | |
2278 | // .private_args = (struct iw_priv_args *)iwctl_private_args, | |
2279 | .private = NULL, | |
2280 | .private_args = NULL, | |
2281 | }; |