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