2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: wireless ext & ioctl functions
46 static const long frequency_list
[] = {
47 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
48 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
49 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
50 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
51 5700, 5745, 5765, 5785, 5805, 5825
54 static int msglevel
= MSG_LEVEL_INFO
;
56 struct iw_statistics
*iwctl_get_wireless_stats(struct net_device
*dev
)
58 struct vnt_private
*pDevice
= netdev_priv(dev
);
61 pDevice
->wstats
.status
= pDevice
->op_mode
;
62 RFvRSSITodBm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
63 pDevice
->wstats
.qual
.level
= ldBm
;
64 pDevice
->wstats
.qual
.noise
= 0;
65 pDevice
->wstats
.qual
.updated
= 1;
66 pDevice
->wstats
.discard
.nwid
= 0;
67 pDevice
->wstats
.discard
.code
= 0;
68 pDevice
->wstats
.discard
.fragment
= 0;
69 pDevice
->wstats
.discard
.misc
= 0;
70 pDevice
->wstats
.miss
.beacon
= 0;
71 return &pDevice
->wstats
;
75 * Wireless Handler: get protocol name
77 int iwctl_giwname(struct net_device
*dev
, struct iw_request_info
*info
,
78 union iwreq_data
*wrqu
, char *extra
)
80 strcpy(wrqu
->name
, "802.11-a/b/g");
85 * Wireless Handler: set scan
87 int iwctl_siwscan(struct net_device
*dev
, struct iw_request_info
*info
,
88 union iwreq_data
*wrqu
, char *extra
)
90 struct vnt_private
*pDevice
= netdev_priv(dev
);
91 struct iw_point
*wrq
= &wrqu
->data
;
92 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
93 struct iw_scan_req
*req
= (struct iw_scan_req
*)extra
;
94 u8 abyScanSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
95 PWLAN_IE_SSID pItemSSID
= NULL
;
97 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
100 PRINT_K(" SIOCSIWSCAN\n");
105 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
107 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
111 if (pDevice
->byReAssocCount
> 0) { // reject scan when re-associating!
112 // send scan event to wpa_Supplicant
113 union iwreq_data wrqu
;
114 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
115 memset(&wrqu
, 0, sizeof(wrqu
));
116 wireless_send_event(pDevice
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
120 spin_lock_irq(&pDevice
->lock
);
122 BSSvClearBSSList((void *)pDevice
, pDevice
->bLinkPass
);
124 // mike add: active scan OR passive scan OR desire_ssid scan
125 if (wrq
->length
== sizeof(struct iw_scan_req
)) {
126 if (wrq
->flags
& IW_SCAN_THIS_ESSID
) { // desire_ssid scan
127 memset(abyScanSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
128 pItemSSID
= (PWLAN_IE_SSID
)abyScanSSID
;
129 pItemSSID
->byElementID
= WLAN_EID_SSID
;
130 memcpy(pItemSSID
->abySSID
, req
->essid
, (int)req
->essid_len
);
131 if (pItemSSID
->abySSID
[req
->essid_len
] == '\0') {
132 if (req
->essid_len
> 0)
133 pItemSSID
->len
= req
->essid_len
;
135 pItemSSID
->len
= req
->essid_len
;
137 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
138 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID
)abyScanSSID
)->abySSID
,
139 ((PWLAN_IE_SSID
)abyScanSSID
)->len
);
140 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, abyScanSSID
);
141 spin_unlock_irq(&pDevice
->lock
);
144 } else if (req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) { // passive scan
145 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
147 } else { // active scan
148 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
151 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
152 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
153 spin_unlock_irq(&pDevice
->lock
);
159 * Wireless Handler : get scan results
161 int iwctl_giwscan(struct net_device
*dev
, struct iw_request_info
*info
,
162 union iwreq_data
*wrqu
, char *extra
)
164 struct iw_point
*wrq
= &wrqu
->data
;
168 struct vnt_private
*pDevice
= netdev_priv(dev
);
169 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
171 PWLAN_IE_SSID pItemSSID
;
172 PWLAN_IE_SUPP_RATES pSuppRates
;
173 PWLAN_IE_SUPP_RATES pExtSuppRates
;
174 char *current_ev
= extra
;
175 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
176 char *current_val
= NULL
;
180 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSCAN\n");
185 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
189 pBSS
= &(pMgmt
->sBSSList
[0]);
190 for (ii
= 0, jj
= 0; jj
< MAX_BSS_NUM
; jj
++) {
191 if (current_ev
>= end_buf
)
193 pBSS
= &(pMgmt
->sBSSList
[jj
]);
196 memset(&iwe
, 0, sizeof(iwe
));
198 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
199 memcpy(iwe
.u
.ap_addr
.sa_data
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
200 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
202 memset(&iwe
, 0, sizeof(iwe
));
203 iwe
.cmd
= SIOCGIWESSID
;
204 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
205 iwe
.u
.data
.length
= pItemSSID
->len
;
206 iwe
.u
.data
.flags
= 1;
207 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
209 memset(&iwe
, 0, sizeof(iwe
));
210 iwe
.cmd
= SIOCGIWMODE
;
211 if (WLAN_GET_CAP_INFO_ESS(pBSS
->wCapInfo
))
212 iwe
.u
.mode
= IW_MODE_INFRA
;
214 iwe
.u
.mode
= IW_MODE_ADHOC
;
215 iwe
.len
= IW_EV_UINT_LEN
;
216 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
218 pSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abySuppRates
;
219 pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abyExtSuppRates
;
220 memset(&iwe
, 0, sizeof(iwe
));
221 iwe
.cmd
= SIOCGIWFREQ
;
222 iwe
.u
.freq
.m
= pBSS
->uChannel
;
225 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
227 int f
= (int)pBSS
->uChannel
- 1;
230 iwe
.u
.freq
.m
= frequency_list
[f
] * 100000;
233 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
235 memset(&iwe
, 0, sizeof(iwe
));
237 RFvRSSITodBm(pDevice
, (u8
)(pBSS
->uRSSI
), &ldBm
);
238 iwe
.u
.qual
.level
= ldBm
;
239 iwe
.u
.qual
.noise
= 0;
242 iwe
.u
.qual
.qual
= 100;
246 iwe
.u
.qual
.qual
= (40 - (-ldBm
- 50)) * 100 / 40;
247 iwe
.u
.qual
.updated
= 7;
249 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
251 memset(&iwe
, 0, sizeof(iwe
));
252 iwe
.cmd
= SIOCGIWENCODE
;
253 iwe
.u
.data
.length
= 0;
254 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS
->wCapInfo
))
255 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
257 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
258 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
260 memset(&iwe
, 0, sizeof(iwe
));
261 iwe
.cmd
= SIOCGIWRATE
;
262 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
263 current_val
= current_ev
+ IW_EV_LCP_LEN
;
265 for (kk
= 0; kk
< 12; kk
++) {
266 if (pSuppRates
->abyRates
[kk
] == 0)
268 // Bit rate given in 500 kb/s units (+ 0x80)
269 iwe
.u
.bitrate
.value
= ((pSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
270 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
272 for (kk
= 0; kk
< 8; kk
++) {
273 if (pExtSuppRates
->abyRates
[kk
] == 0)
275 // Bit rate given in 500 kb/s units (+ 0x80)
276 iwe
.u
.bitrate
.value
= ((pExtSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
277 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
280 if ((current_val
- current_ev
) > IW_EV_LCP_LEN
)
281 current_ev
= current_val
;
283 if ((pBSS
->wWPALen
> 0) && (pBSS
->wWPALen
<= MAX_WPA_IE_LEN
)) {
284 memset(&iwe
, 0, sizeof(iwe
));
286 iwe
.u
.data
.length
= pBSS
->wWPALen
;
287 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byWPAIE
);
290 if ((pBSS
->wRSNLen
> 0) && (pBSS
->wRSNLen
<= MAX_WPA_IE_LEN
)) {
291 memset(&iwe
, 0, sizeof(iwe
));
293 iwe
.u
.data
.length
= pBSS
->wRSNLen
;
294 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byRSNIE
);
298 wrq
->length
= current_ev
- extra
;
303 * Wireless Handler: set frequence or channel
305 int iwctl_siwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
306 union iwreq_data
*wrqu
, char *extra
)
308 struct vnt_private
*pDevice
= netdev_priv(dev
);
309 struct iw_freq
*wrq
= &wrqu
->freq
;
312 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFREQ\n");
314 // If setting by frequency, convert to a channel
315 if ((wrq
->e
== 1) && (wrq
->m
>= (int)2.412e8
) &&
316 (wrq
->m
<= (int)2.487e8
)) {
317 int f
= wrq
->m
/ 100000;
319 while ((c
< 14) && (f
!= frequency_list
[c
]))
324 // Setting by channel number
325 if ((wrq
->m
> 14) || (wrq
->e
> 0)) {
328 int channel
= wrq
->m
;
329 if ((channel
< 1) || (channel
> 14)) {
330 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: New channel value of %d is invalid!\n", dev
->name
, wrq
->m
);
333 // Yes ! We can set it !!!
334 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set to channel = %d\n", channel
);
335 pDevice
->uChannel
= channel
;
342 * Wireless Handler: get frequence or channel
344 int iwctl_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
345 union iwreq_data
*wrqu
, char *extra
)
347 struct vnt_private
*pDevice
= netdev_priv(dev
);
348 struct iw_freq
*wrq
= &wrqu
->freq
;
349 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
351 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFREQ\n");
356 #ifdef WEXT_USECHANNELS
357 wrq
->m
= (int)pMgmt
->uCurrChannel
;
361 int f
= (int)pMgmt
->uCurrChannel
- 1;
364 wrq
->m
= frequency_list
[f
] * 100000;
372 * Wireless Handler: set operation mode
374 int iwctl_siwmode(struct net_device
*dev
, struct iw_request_info
*info
,
375 union iwreq_data
*wrqu
, char *extra
)
377 struct vnt_private
*pDevice
= netdev_priv(dev
);
378 __u32
*wmode
= &wrqu
->mode
;
379 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
382 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMODE\n");
387 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
&& pDevice
->bEnableHostapd
) {
388 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
389 "Can't set operation mode, hostapd is running\n");
395 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_IBSS_STA
) {
396 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
397 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
398 pDevice
->bCommit
= true;
400 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to ad-hoc\n");
404 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_ESS_STA
) {
405 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
406 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
407 pDevice
->bCommit
= true;
409 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to infrastructure\n");
413 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
417 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_AP
) {
418 pMgmt
->eConfigMode
= WMAC_CONFIG_AP
;
419 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
420 pDevice
->bCommit
= true;
422 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to Access Point\n");
426 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
433 if (pDevice
->bCommit
) {
434 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
435 netif_stop_queue(pDevice
->dev
);
436 spin_lock_irq(&pDevice
->lock
);
437 bScheduleCommand((void *) pDevice
,
438 WLAN_CMD_RUN_AP
, NULL
);
439 spin_unlock_irq(&pDevice
->lock
);
441 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
442 "Commit the settings\n");
444 spin_lock_irq(&pDevice
->lock
);
446 if (pDevice
->bLinkPass
&&
447 memcmp(pMgmt
->abyCurrSSID
,
448 pMgmt
->abyDesireSSID
,
449 WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
)) {
450 bScheduleCommand((void *) pDevice
,
451 WLAN_CMD_DISASSOCIATE
, NULL
);
453 pDevice
->bLinkPass
= false;
454 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
455 memset(pMgmt
->abyCurrBSSID
, 0, 6);
458 ControlvMaskByte(pDevice
,
459 MESSAGE_REQUEST_MACREG
, MAC_REG_PAPEDELAY
,
460 LEDSTS_STS
, LEDSTS_SLOW
);
462 netif_stop_queue(pDevice
->dev
);
464 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
466 if (!pDevice
->bWPASuppWextEnabled
)
467 bScheduleCommand((void *) pDevice
,
469 pMgmt
->abyDesireSSID
);
471 bScheduleCommand((void *) pDevice
,
475 spin_unlock_irq(&pDevice
->lock
);
477 pDevice
->bCommit
= false;
484 * Wireless Handler: get operation mode
486 int iwctl_giwmode(struct net_device
*dev
, struct iw_request_info
*info
,
487 union iwreq_data
*wrqu
, char *extra
)
489 struct vnt_private
*pDevice
= netdev_priv(dev
);
490 __u32
*wmode
= &wrqu
->mode
;
491 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
493 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWMODE\n");
498 // If not managed, assume it's ad-hoc
499 switch (pMgmt
->eConfigMode
) {
500 case WMAC_CONFIG_ESS_STA
:
501 *wmode
= IW_MODE_INFRA
;
503 case WMAC_CONFIG_IBSS_STA
:
504 *wmode
= IW_MODE_ADHOC
;
506 case WMAC_CONFIG_AUTO
:
507 *wmode
= IW_MODE_INFRA
;
510 *wmode
= IW_MODE_MASTER
;
513 *wmode
= IW_MODE_ADHOC
;
520 * Wireless Handler: get capability range
522 int iwctl_giwrange(struct net_device
*dev
, struct iw_request_info
*info
,
523 union iwreq_data
*wrqu
, char *extra
)
525 struct iw_point
*wrq
= &wrqu
->data
;
526 struct iw_range
*range
= (struct iw_range
*)extra
;
529 u8 abySupportedRates
[13] = {
530 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
534 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRANGE\n");
536 wrq
->length
= sizeof(struct iw_range
);
537 memset(range
, 0, sizeof(struct iw_range
));
538 range
->min_nwid
= 0x0000;
539 range
->max_nwid
= 0x0000;
540 range
->num_channels
= 14;
541 // Should be based on cap_rid.country to give only
542 // what the current card support
544 for (i
= 0; i
< 14; i
++) {
545 range
->freq
[k
].i
= i
+ 1; // List index
546 range
->freq
[k
].m
= frequency_list
[i
] * 100000;
547 range
->freq
[k
++].e
= 1; // Values in table in MHz -> * 10^5 * 10
549 range
->num_frequency
= k
;
550 // Hum... Should put the right values there
551 range
->max_qual
.qual
= 100;
552 range
->max_qual
.level
= 0;
553 range
->max_qual
.noise
= 0;
554 range
->sensitivity
= 255;
556 for (i
= 0; i
< 13; i
++) {
557 range
->bitrate
[i
] = abySupportedRates
[i
] * 500000;
558 if (range
->bitrate
[i
] == 0)
561 range
->num_bitrates
= i
;
563 // Set an indication of the max TCP throughput
564 // in bit/s that we can expect using this interface.
565 // May be use for QoS stuff... Jean II
567 range
->throughput
= 5 * 1000 * 1000;
569 range
->throughput
= 1.5 * 1000 * 1000;
572 range
->max_rts
= 2312;
573 range
->min_frag
= 256;
574 range
->max_frag
= 2312;
576 // the encoding capabilities
577 range
->num_encoding_sizes
= 3;
579 range
->encoding_size
[0] = 5;
581 range
->encoding_size
[1] = 13;
582 // 256 bits for WPA-PSK
583 range
->encoding_size
[2] = 32;
584 // 4 keys are allowed
585 range
->max_encoding_tokens
= 4;
587 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
588 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
591 range
->max_pmp
= 1000000; // 1 secs
593 range
->max_pmt
= 1000000; // 1 secs
594 range
->pmp_flags
= IW_POWER_PERIOD
;
595 range
->pmt_flags
= IW_POWER_TIMEOUT
;
596 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_ALL_R
;
598 // Transmit Power - values are in mW
599 range
->txpower
[0] = 100;
600 range
->num_txpower
= 1;
601 range
->txpower_capa
= IW_TXPOW_MWATT
;
602 range
->we_version_source
= WIRELESS_EXT
;
603 range
->we_version_compiled
= WIRELESS_EXT
;
604 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
605 range
->retry_flags
= IW_RETRY_LIMIT
;
606 range
->r_time_flags
= IW_RETRY_LIFETIME
;
607 range
->min_retry
= 1;
608 range
->max_retry
= 65535;
609 range
->min_r_time
= 1024;
610 range
->max_r_time
= 65535 * 1024;
611 // Experimental measurements - boundary 11/5.5 Mb/s
612 // Note : with or without the (local->rssi), results
613 // are somewhat different. - Jean II
614 range
->avg_qual
.qual
= 6;
615 range
->avg_qual
.level
= 176; // -80 dBm
616 range
->avg_qual
.noise
= 0;
623 * Wireless Handler : set ap mac address
625 int iwctl_siwap(struct net_device
*dev
, struct iw_request_info
*info
,
626 union iwreq_data
*wrqu
, char *extra
)
628 struct vnt_private
*pDevice
= netdev_priv(dev
);
629 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
630 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
632 u8 ZeroBSSID
[WLAN_BSSID_LEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
634 PRINT_K(" SIOCSIWAP\n");
639 if (wrq
->sa_family
!= ARPHRD_ETHER
) {
642 memcpy(pMgmt
->abyDesireBSSID
, wrq
->sa_data
, 6);
644 if ((is_broadcast_ether_addr(pMgmt
->abyDesireBSSID
)) ||
645 (memcmp(pMgmt
->abyDesireBSSID
, ZeroBSSID
, 6) == 0)) {
646 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
649 // mike add: if desired AP is hidden ssid(there are
650 // two same BSSID in list), then ignore,because you
651 // don't known which one to be connect with??
654 unsigned uSameBssidNum
= 0;
655 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
656 if (pMgmt
->sBSSList
[ii
].bActive
&&
657 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
658 pMgmt
->abyDesireBSSID
)) {
662 if (uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
663 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
668 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
669 pDevice
->bCommit
= true;
675 * Wireless Handler: get ap mac address
677 int iwctl_giwap(struct net_device
*dev
, struct iw_request_info
*info
,
678 union iwreq_data
*wrqu
, char *extra
)
680 struct vnt_private
*pDevice
= netdev_priv(dev
);
681 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
682 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
684 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAP\n");
689 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
691 if ((pDevice
->bLinkPass
== false) && (pMgmt
->eCurrMode
!= WMAC_MODE_ESS_AP
))
692 memset(wrq
->sa_data
, 0, 6);
694 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)
695 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
697 wrq
->sa_family
= ARPHRD_ETHER
;
702 * Wireless Handler: get ap list
704 int iwctl_giwaplist(struct net_device
*dev
, struct iw_request_info
*info
,
705 union iwreq_data
*wrqu
, char *extra
)
707 struct iw_point
*wrq
= &wrqu
->data
;
708 struct sockaddr
*sock
;
709 struct iw_quality
*qual
;
710 struct vnt_private
*pDevice
= netdev_priv(dev
);
711 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
712 PKnownBSS pBSS
= &pMgmt
->sBSSList
[0];
716 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAPLIST\n");
717 /* Only super-user can see AP list */
722 if (!capable(CAP_NET_ADMIN
))
728 sock
= kcalloc(IW_MAX_AP
, sizeof(struct sockaddr
), GFP_KERNEL
);
731 qual
= kcalloc(IW_MAX_AP
, sizeof(struct iw_quality
), GFP_KERNEL
);
737 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
738 if (!pBSS
[ii
].bActive
)
742 memcpy(sock
[jj
].sa_data
, pBSS
[ii
].abyBSSID
, 6);
743 sock
[jj
].sa_family
= ARPHRD_ETHER
;
744 qual
[jj
].level
= pBSS
[ii
].uRSSI
;
745 qual
[jj
].qual
= qual
[jj
].noise
= 0;
746 qual
[jj
].updated
= 2;
750 wrq
->flags
= 1; /* Should be defined */
752 memcpy(extra
, sock
, sizeof(struct sockaddr
) * jj
);
753 memcpy(extra
+ sizeof(struct sockaddr
) * jj
, qual
,
754 sizeof(struct iw_quality
) * jj
);
763 * Wireless Handler: set essid
765 int iwctl_siwessid(struct net_device
*dev
, struct iw_request_info
*info
,
766 union iwreq_data
*wrqu
, char *extra
)
768 struct vnt_private
*pDevice
= netdev_priv(dev
);
769 struct iw_point
*wrq
= &wrqu
->essid
;
770 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
771 PWLAN_IE_SSID pItemSSID
;
776 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
779 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWESSID :\n");
781 pDevice
->fWPA_Authened
= false;
782 // Check if we asked for `any'
783 if (wrq
->flags
== 0) {
784 // Just send an empty SSID list
785 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
786 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
787 PRINT_K("set essid to 'any'\n");
788 // Unknown desired AP, so here need not associate??
792 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
793 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
794 pItemSSID
->byElementID
= WLAN_EID_SSID
;
796 memcpy(pItemSSID
->abySSID
, extra
, wrq
->length
);
797 if (pItemSSID
->abySSID
[wrq
->length
] == '\0') {
799 pItemSSID
->len
= wrq
->length
;
801 pItemSSID
->len
= wrq
->length
;
803 PRINT_K("set essid to %s\n", pItemSSID
->abySSID
);
805 // mike: need clear desiredBSSID
806 if (pItemSSID
->len
== 0) {
807 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
811 // Wext wil order another command of siwap to link
812 // with desired AP, so here need not associate??
813 if (pDevice
->bWPASuppWextEnabled
== true) {
814 /*******search if in hidden ssid mode ****/
815 PKnownBSS pCurr
= NULL
;
816 u8 abyTmpDesireSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
818 unsigned uSameBssidNum
= 0;
820 memcpy(abyTmpDesireSSID
, pMgmt
->abyDesireSSID
, sizeof(abyTmpDesireSSID
));
821 pCurr
= BSSpSearchBSSList(pDevice
, NULL
,
823 pDevice
->eConfigPHYMode
);
826 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
827 vResetCommandTimer((void *)pDevice
);
828 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
829 bScheduleCommand((void *)pDevice
,
831 pMgmt
->abyDesireSSID
);
832 bScheduleCommand((void *)pDevice
,
834 pMgmt
->abyDesireSSID
);
835 } else { // mike: to find out if that desired SSID is a
836 // hidden-ssid AP, by means of judging if there
837 // are two same BSSID exist in list ?
838 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
839 if (pMgmt
->sBSSList
[ii
].bActive
&&
840 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
845 if (uSameBssidNum
>= 2) { // hit: desired AP is in hidden ssid mode!!!
846 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
847 vResetCommandTimer((void *)pDevice
);
848 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
; // this scan type, you'll submit scan result!
849 bScheduleCommand((void *)pDevice
,
851 pMgmt
->abyDesireSSID
);
852 bScheduleCommand((void *)pDevice
,
854 pMgmt
->abyDesireSSID
);
860 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set essid = %s\n", pItemSSID
->abySSID
);
863 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
864 pDevice
->bCommit
= true;
870 * Wireless Handler: get essid
872 int iwctl_giwessid(struct net_device
*dev
, struct iw_request_info
*info
,
873 union iwreq_data
*wrqu
, char *extra
)
875 struct vnt_private
*pDevice
= netdev_priv(dev
);
876 struct iw_point
*wrq
= &wrqu
->essid
;
877 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
878 PWLAN_IE_SSID pItemSSID
;
880 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWESSID\n");
885 // Note: if wrq->u.data.flags != 0, we should get the relevant
886 // SSID from the SSID list...
888 // Get the current SSID
889 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
890 memcpy(extra
, pItemSSID
->abySSID
, pItemSSID
->len
);
891 extra
[pItemSSID
->len
] = '\0';
893 wrq
->length
= pItemSSID
->len
;
894 wrq
->flags
= 1; // active
900 * Wireless Handler: set data rate
902 int iwctl_siwrate(struct net_device
*dev
, struct iw_request_info
*info
,
903 union iwreq_data
*wrqu
, char *extra
)
905 struct vnt_private
*pDevice
= netdev_priv(dev
);
906 struct iw_param
*wrq
= &wrqu
->bitrate
;
910 u8 abySupportedRates
[13] = {
911 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
915 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRATE\n");
916 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
921 // First: get a valid bit rate value
923 // Which type of value
924 if ((wrq
->value
< 13) && (wrq
->value
>= 0)) {
925 // Setting by rate index
926 // Find value in the magic rate table
929 // Setting by frequency value
930 u8 normvalue
= (u8
)(wrq
->value
/500000);
932 // Check if rate is valid
933 for (i
= 0; i
< 13; i
++) {
934 if (normvalue
== abySupportedRates
[i
]) {
940 // -1 designed the max rate (mostly auto mode)
941 if (wrq
->value
== -1) {
942 // Get the highest available rate
943 for (i
= 0; i
< 13; i
++) {
944 if (abySupportedRates
[i
] == 0)
951 // Check that it is valid
952 // brate is index of abySupportedRates[]
958 // Now, check if we want a fixed or auto value
959 if (wrq
->fixed
!= 0) {
962 pDevice
->bFixRate
= true;
963 if ((pDevice
->byBBType
== BB_TYPE_11B
) && (brate
> 3)) {
964 pDevice
->uConnectionRate
= 3;
966 pDevice
->uConnectionRate
= brate
;
967 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fixed to Rate %d\n", pDevice
->uConnectionRate
);
970 pDevice
->bFixRate
= false;
971 pDevice
->uConnectionRate
= 13;
978 * Wireless Handler: get data rate
980 int iwctl_giwrate(struct net_device
*dev
, struct iw_request_info
*info
,
981 union iwreq_data
*wrqu
, char *extra
)
983 struct vnt_private
*pDevice
= netdev_priv(dev
);
984 struct iw_param
*wrq
= &wrqu
->bitrate
;
985 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
987 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRATE\n");
993 u8 abySupportedRates
[13] = {
994 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
995 0x48, 0x60, 0x6C, 0x90
999 if (pDevice
->uConnectionRate
< 13) {
1000 brate
= abySupportedRates
[pDevice
->uConnectionRate
];
1002 if (pDevice
->byBBType
== BB_TYPE_11B
)
1004 if (pDevice
->byBBType
== BB_TYPE_11G
)
1006 if (pDevice
->byBBType
== BB_TYPE_11A
)
1009 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
1010 if (pDevice
->byBBType
== BB_TYPE_11B
)
1012 if (pDevice
->byBBType
== BB_TYPE_11G
)
1014 if (pDevice
->byBBType
== BB_TYPE_11A
)
1017 if (pDevice
->uConnectionRate
== 13)
1018 brate
= abySupportedRates
[pDevice
->wCurrentRate
];
1019 wrq
->value
= brate
* 500000;
1020 // If more than one rate, set auto
1021 if (pDevice
->bFixRate
== true)
1029 * Wireless Handler: set rts threshold
1031 int iwctl_siwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1032 union iwreq_data
*wrqu
, char *extra
)
1034 struct vnt_private
*pDevice
= netdev_priv(dev
);
1035 struct iw_param
*wrq
= &wrqu
->rts
;
1037 if ((wrq
->value
< 0 || wrq
->value
> 2312) && !wrq
->disabled
)
1040 else if (wrq
->disabled
)
1041 pDevice
->wRTSThreshold
= 2312;
1043 pDevice
->wRTSThreshold
= wrq
->value
;
1049 * Wireless Handler: get rts
1051 int iwctl_giwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1052 union iwreq_data
*wrqu
, char *extra
)
1054 struct vnt_private
*pDevice
= netdev_priv(dev
);
1055 struct iw_param
*wrq
= &wrqu
->rts
;
1057 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRTS\n");
1058 wrq
->value
= pDevice
->wRTSThreshold
;
1059 wrq
->disabled
= (wrq
->value
>= 2312);
1065 * Wireless Handler: set fragment threshold
1067 int iwctl_siwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1068 union iwreq_data
*wrqu
, char *extra
)
1070 struct vnt_private
*pDevice
= netdev_priv(dev
);
1071 struct iw_param
*wrq
= &wrqu
->frag
;
1073 int fthr
= wrq
->value
;
1075 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFRAG\n");
1079 if ((fthr
< 256) || (fthr
> 2312)) {
1082 fthr
&= ~0x1; // Get an even value
1083 pDevice
->wFragmentationThreshold
= (u16
)fthr
;
1089 * Wireless Handler: get fragment threshold
1091 int iwctl_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1092 union iwreq_data
*wrqu
, char *extra
)
1094 struct vnt_private
*pDevice
= netdev_priv(dev
);
1095 struct iw_param
*wrq
= &wrqu
->frag
;
1097 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFRAG\n");
1098 wrq
->value
= pDevice
->wFragmentationThreshold
;
1099 wrq
->disabled
= (wrq
->value
>= 2312);
1105 * Wireless Handler: set retry threshold
1107 int iwctl_siwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1108 union iwreq_data
*wrqu
, char *extra
)
1110 struct vnt_private
*pDevice
= netdev_priv(dev
);
1111 struct iw_param
*wrq
= &wrqu
->retry
;
1114 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRETRY\n");
1116 if (wrq
->disabled
) {
1121 if (wrq
->flags
& IW_RETRY_LIMIT
) {
1122 if (wrq
->flags
& IW_RETRY_MAX
) {
1123 pDevice
->byLongRetryLimit
= wrq
->value
;
1124 } else if (wrq
->flags
& IW_RETRY_MIN
) {
1125 pDevice
->byShortRetryLimit
= wrq
->value
;
1127 // No modifier : set both
1128 pDevice
->byShortRetryLimit
= wrq
->value
;
1129 pDevice
->byLongRetryLimit
= wrq
->value
;
1132 if (wrq
->flags
& IW_RETRY_LIFETIME
)
1133 pDevice
->wMaxTransmitMSDULifetime
= wrq
->value
;
1138 * Wireless Handler: get retry threshold
1140 int iwctl_giwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1141 union iwreq_data
*wrqu
, char *extra
)
1143 struct vnt_private
*pDevice
= netdev_priv(dev
);
1144 struct iw_param
*wrq
= &wrqu
->retry
;
1145 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRETRY\n");
1146 wrq
->disabled
= 0; // Can't be disabled
1148 // Note: by default, display the min retry number
1149 if ((wrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1150 wrq
->flags
= IW_RETRY_LIFETIME
;
1151 wrq
->value
= (int)pDevice
->wMaxTransmitMSDULifetime
; // ms
1152 } else if ((wrq
->flags
& IW_RETRY_MAX
)) {
1153 wrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1154 wrq
->value
= (int)pDevice
->byLongRetryLimit
;
1156 wrq
->flags
= IW_RETRY_LIMIT
;
1157 wrq
->value
= (int)pDevice
->byShortRetryLimit
;
1158 if ((int)pDevice
->byShortRetryLimit
!= (int)pDevice
->byLongRetryLimit
)
1159 wrq
->flags
|= IW_RETRY_MIN
;
1165 * Wireless Handler: set encode mode
1167 int iwctl_siwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1168 union iwreq_data
*wrqu
, char *extra
)
1170 struct vnt_private
*pDevice
= netdev_priv(dev
);
1171 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1172 struct iw_point
*wrq
= &wrqu
->encoding
;
1173 u32 dwKeyIndex
= (u32
)(wrq
->flags
& IW_ENCODE_INDEX
);
1177 int index
= (wrq
->flags
& IW_ENCODE_INDEX
);
1179 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODE\n");
1184 // Check the size of the key
1185 if (wrq
->length
> WLAN_WEP232_KEYLEN
) {
1190 if (dwKeyIndex
> WLAN_WEP_NKEYS
) {
1198 // Send the key to the card
1199 if (wrq
->length
> 0) {
1200 if (wrq
->length
== WLAN_WEP232_KEYLEN
) {
1201 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 232 bit wep key\n");
1202 } else if (wrq
->length
== WLAN_WEP104_KEYLEN
) {
1203 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 104 bit wep key\n");
1204 } else if (wrq
->length
== WLAN_WEP40_KEYLEN
) {
1205 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 40 bit wep key, index= %d\n", (int)dwKeyIndex
);
1207 memset(pDevice
->abyKey
, 0, WLAN_WEP232_KEYLEN
);
1208 memcpy(pDevice
->abyKey
, extra
, wrq
->length
);
1210 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"abyKey: ");
1211 for (ii
= 0; ii
< wrq
->length
; ii
++)
1212 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pDevice
->abyKey
[ii
]);
1214 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1215 spin_lock_irq(&pDevice
->lock
);
1216 KeybSetDefaultKey(pDevice
,
1218 dwKeyIndex
| (1 << 31),
1222 spin_unlock_irq(&pDevice
->lock
);
1224 pDevice
->byKeyIndex
= (u8
)dwKeyIndex
;
1225 pDevice
->uKeyLength
= wrq
->length
;
1226 pDevice
->bTransmitKey
= true;
1227 pDevice
->bEncryptionEnable
= true;
1228 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1230 // Do we want to just set the transmit key index?
1232 pDevice
->byKeyIndex
= index
;
1233 } else if (!(wrq
->flags
& IW_ENCODE_MODE
)) {
1239 if (wrq
->flags
& IW_ENCODE_DISABLED
) {
1240 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disable WEP function\n");
1241 pMgmt
->bShareKeyAlgorithm
= false;
1242 pDevice
->bEncryptionEnable
= false;
1243 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1244 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1245 spin_lock_irq(&pDevice
->lock
);
1246 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++)
1247 MACvDisableKeyEntry(pDevice
, uu
);
1248 spin_unlock_irq(&pDevice
->lock
);
1251 if (wrq
->flags
& IW_ENCODE_RESTRICTED
) {
1252 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & ShareKey System\n");
1253 pMgmt
->bShareKeyAlgorithm
= true;
1255 if (wrq
->flags
& IW_ENCODE_OPEN
) {
1256 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & Open System\n");
1257 pMgmt
->bShareKeyAlgorithm
= false;
1260 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1265 int iwctl_giwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1266 union iwreq_data
*wrqu
, char *extra
)
1268 struct vnt_private
*pDevice
= netdev_priv(dev
);
1269 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1270 struct iw_point
*wrq
= &wrqu
->encoding
;
1271 char abyKey
[WLAN_WEP232_KEYLEN
];
1273 unsigned index
= (unsigned)(wrq
->flags
& IW_ENCODE_INDEX
);
1274 PSKeyItem pKey
= NULL
;
1276 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODE\n");
1281 if (index
> WLAN_WEP_NKEYS
)
1283 if (index
< 1) { // get default key
1284 if (pDevice
->byKeyIndex
< WLAN_WEP_NKEYS
)
1285 index
= pDevice
->byKeyIndex
;
1292 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1293 // Check encryption mode
1294 wrq
->flags
= IW_ENCODE_NOKEY
;
1295 // Is WEP enabled ???
1296 if (pDevice
->bEncryptionEnable
)
1297 wrq
->flags
|= IW_ENCODE_ENABLED
;
1299 wrq
->flags
|= IW_ENCODE_DISABLED
;
1301 if (pMgmt
->bShareKeyAlgorithm
)
1302 wrq
->flags
|= IW_ENCODE_RESTRICTED
;
1304 wrq
->flags
|= IW_ENCODE_OPEN
;
1307 if ((index
== 0) && (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
||
1308 pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)) { // get wpa pairwise key
1309 if (KeybGetKey(&(pDevice
->sKey
), pMgmt
->abyCurrBSSID
, 0xffffffff, &pKey
)) {
1310 wrq
->length
= pKey
->uKeyLength
;
1311 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1312 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1314 } else if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, (u8
)index
, &pKey
)) {
1315 wrq
->length
= pKey
->uKeyLength
;
1316 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1317 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1320 wrq
->flags
|= index
+ 1;
1325 * Wireless Handler: set power mode
1327 int iwctl_siwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1328 union iwreq_data
*wrqu
, char *extra
)
1330 struct vnt_private
*pDevice
= netdev_priv(dev
);
1331 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1332 struct iw_param
*wrq
= &wrqu
->power
;
1335 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER\n");
1340 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
1345 spin_lock_irq(&pDevice
->lock
);
1347 if (wrq
->disabled
) {
1348 pDevice
->ePSMode
= WMAC_POWER_CAM
;
1349 PSvDisablePowerSaving(pDevice
);
1350 spin_unlock_irq(&pDevice
->lock
);
1353 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1354 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1355 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1357 } else if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_PERIOD
) {
1358 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1359 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1362 spin_unlock_irq(&pDevice
->lock
);
1364 switch (wrq
->flags
& IW_POWER_MODE
) {
1365 case IW_POWER_UNICAST_R
:
1366 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1369 case IW_POWER_ALL_R
:
1370 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ALL_R\n");
1373 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ON\n");
1383 * Wireless Handler: get power mode
1385 int iwctl_giwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1386 union iwreq_data
*wrqu
, char *extra
)
1388 struct vnt_private
*pDevice
= netdev_priv(dev
);
1389 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1390 struct iw_param
*wrq
= &wrqu
->power
;
1391 int mode
= pDevice
->ePSMode
;
1393 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPOWER\n");
1398 wrq
->disabled
= (mode
== WMAC_POWER_CAM
);
1402 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1403 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1404 pMgmt
->wCurrBeaconPeriod
) / 100);
1405 wrq
->flags
= IW_POWER_TIMEOUT
;
1407 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1408 pMgmt
->wCurrBeaconPeriod
) / 100);
1409 wrq
->flags
= IW_POWER_PERIOD
;
1412 wrq
->flags
|= IW_POWER_ALL_R
;
1417 * Wireless Handler: get Sensitivity
1419 int iwctl_giwsens(struct net_device
*dev
, struct iw_request_info
*info
,
1420 union iwreq_data
*wrqu
, char *extra
)
1422 struct vnt_private
*pDevice
= netdev_priv(dev
);
1423 struct iw_param
*wrq
= &wrqu
->sens
;
1426 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSENS\n");
1427 if (pDevice
->bLinkPass
== true) {
1428 RFvRSSITodBm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
1433 wrq
->disabled
= (wrq
->value
== 0);
1438 int iwctl_siwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1439 union iwreq_data
*wrqu
, char *extra
)
1441 struct vnt_private
*pDevice
= netdev_priv(dev
);
1442 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1443 struct iw_param
*wrq
= &wrqu
->param
;
1445 static int wpa_version
= 0; // must be static to save the last value, einsn liu
1446 static int pairwise
= 0;
1451 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH\n");
1452 switch (wrq
->flags
& IW_AUTH_INDEX
) {
1453 case IW_AUTH_WPA_VERSION
:
1454 wpa_version
= wrq
->value
;
1455 if (wrq
->value
== IW_AUTH_WPA_VERSION_DISABLED
) {
1456 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1457 } else if (wrq
->value
== IW_AUTH_WPA_VERSION_WPA
) {
1458 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1460 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1463 case IW_AUTH_CIPHER_PAIRWISE
:
1464 pairwise
= wrq
->value
;
1465 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise
);
1466 if (pairwise
== IW_AUTH_CIPHER_CCMP
) {
1467 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1468 } else if (pairwise
== IW_AUTH_CIPHER_TKIP
) {
1469 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1470 } else if (pairwise
== IW_AUTH_CIPHER_WEP40
||
1471 pairwise
== IW_AUTH_CIPHER_WEP104
) {
1472 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1473 } else if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1474 // do nothing, einsn liu
1476 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1479 case IW_AUTH_CIPHER_GROUP
:
1480 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq
->value
);
1481 if (wpa_version
== IW_AUTH_WPA_VERSION_DISABLED
)
1483 if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1484 if (wrq
->value
== IW_AUTH_CIPHER_CCMP
)
1485 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1487 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1490 case IW_AUTH_KEY_MGMT
:
1491 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version
, wrq
->value
);
1492 if (wpa_version
== IW_AUTH_WPA_VERSION_WPA2
) {
1493 if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1494 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
1495 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
1496 } else if (wpa_version
== IW_AUTH_WPA_VERSION_WPA
) {
1497 if (wrq
->value
== 0) {
1498 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
1499 } else if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1500 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
1502 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
1505 case IW_AUTH_TKIP_COUNTERMEASURES
:
1507 case IW_AUTH_DROP_UNENCRYPTED
:
1509 case IW_AUTH_80211_AUTH_ALG
:
1510 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq
->value
);
1511 if (wrq
->value
== IW_AUTH_ALG_OPEN_SYSTEM
)
1512 pMgmt
->bShareKeyAlgorithm
= false;
1513 else if (wrq
->value
== IW_AUTH_ALG_SHARED_KEY
)
1514 pMgmt
->bShareKeyAlgorithm
= true;
1516 case IW_AUTH_WPA_ENABLED
:
1518 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1520 case IW_AUTH_ROAMING_CONTROL
:
1523 case IW_AUTH_PRIVACY_INVOKED
:
1524 pDevice
->bEncryptionEnable
= !!wrq
->value
;
1525 if (pDevice
->bEncryptionEnable
== false) {
1528 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1529 pMgmt
->bShareKeyAlgorithm
= false;
1530 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
1531 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1535 PRINT_K("iwctl_siwauth: not supported %x\n", wrq
->flags
);
1542 int iwctl_giwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1543 union iwreq_data
*wrqu
, char *extra
)
1548 int iwctl_siwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1549 union iwreq_data
*wrqu
, char *extra
)
1551 struct vnt_private
*pDevice
= netdev_priv(dev
);
1552 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1553 struct iw_point
*wrq
= &wrqu
->data
;
1560 if ((wrq
->length
< 2) || (extra
[1] + 2 != wrq
->length
)) {
1564 if (wrq
->length
> MAX_WPA_IE_LEN
) {
1568 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1570 memcpy(pMgmt
->abyWPAIE
, extra
, wrq
->length
);
1571 pMgmt
->wWPAIELen
= wrq
->length
;
1573 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1574 pMgmt
->wWPAIELen
= 0;
1577 out
: // not completely ...not necessary in wpa_supplicant 0.5.8
1581 int iwctl_giwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1582 union iwreq_data
*wrqu
, char *extra
)
1584 struct vnt_private
*pDevice
= netdev_priv(dev
);
1585 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1586 struct iw_point
*wrq
= &wrqu
->data
;
1588 int space
= wrq
->length
;
1594 if (pMgmt
->wWPAIELen
> 0) {
1595 wrq
->length
= pMgmt
->wWPAIELen
;
1597 if (pMgmt
->wWPAIELen
<= space
)
1598 memcpy(extra
, pMgmt
->abyWPAIE
, pMgmt
->wWPAIELen
);
1605 int iwctl_siwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1606 union iwreq_data
*wrqu
, char *extra
)
1608 struct vnt_private
*pDevice
= netdev_priv(dev
);
1609 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1610 struct iw_point
*wrq
= &wrqu
->encoding
;
1611 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1612 struct viawget_wpa_param
*param
= NULL
;
1618 u8 seq
[IW_ENCODE_SEQ_MAX_SIZE
];
1626 PRINT_K("SIOCSIWENCODEEXT......\n");
1631 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
1634 buf
= kzalloc(sizeof(struct viawget_wpa_param
), GFP_KERNEL
);
1638 param
= (struct viawget_wpa_param
*)buf
;
1642 case IW_ENCODE_ALG_NONE
:
1643 alg_name
= WPA_ALG_NONE
;
1645 case IW_ENCODE_ALG_WEP
:
1646 alg_name
= WPA_ALG_WEP
;
1648 case IW_ENCODE_ALG_TKIP
:
1649 alg_name
= WPA_ALG_TKIP
;
1651 case IW_ENCODE_ALG_CCMP
:
1652 alg_name
= WPA_ALG_CCMP
;
1655 PRINT_K("Unknown alg = %d\n", ext
->alg
);
1660 memcpy(addr
, ext
->addr
.sa_data
, ETH_ALEN
);
1662 key_idx
= (wrq
->flags
&IW_ENCODE_INDEX
) - 1;
1664 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1666 // recover seq,seq_len
1667 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1668 seq_len
= IW_ENCODE_SEQ_MAX_SIZE
;
1669 memcpy(seq
, ext
->rx_seq
, seq_len
);
1671 // recover key,key_len
1673 key_len
= ext
->key_len
;
1674 memcpy(key
, &ext
->key
[0], key_len
);
1676 memset(key_array
, 0, 64);
1678 memcpy(key_array
, key
, key_len
);
1679 if (key_len
== 32) {
1680 // notice ! the oder
1681 memcpy(&key_array
[16], &key
[24], 8);
1682 memcpy(&key_array
[24], &key
[16], 8);
1686 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1687 memcpy(param
->addr
, addr
, ETH_ALEN
);
1688 param
->u
.wpa_key
.alg_name
= (int)alg_name
;
1689 param
->u
.wpa_key
.set_tx
= set_tx
;
1690 param
->u
.wpa_key
.key_index
= key_idx
;
1691 param
->u
.wpa_key
.key_len
= key_len
;
1692 param
->u
.wpa_key
.key
= (u8
*)key_array
;
1693 param
->u
.wpa_key
.seq
= (u8
*)seq
;
1694 param
->u
.wpa_key
.seq_len
= seq_len
;
1696 /****set if current action is Network Manager count?? */
1697 /****this method is so foolish,but there is no other way??? */
1698 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
1699 if (param
->u
.wpa_key
.key_index
== 0) {
1700 pDevice
->bwextstep0
= true;
1702 if ((pDevice
->bwextstep0
== true) && (param
->u
.wpa_key
.key_index
== 1)) {
1703 pDevice
->bwextstep0
= false;
1704 pDevice
->bwextstep1
= true;
1706 if ((pDevice
->bwextstep1
== true) && (param
->u
.wpa_key
.key_index
== 2)) {
1707 pDevice
->bwextstep1
= false;
1708 pDevice
->bwextstep2
= true;
1710 if ((pDevice
->bwextstep2
== true) && (param
->u
.wpa_key
.key_index
== 3)) {
1711 pDevice
->bwextstep2
= false;
1712 pDevice
->bwextstep3
= true;
1715 if (pDevice
->bwextstep3
== true) {
1716 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1717 pDevice
->bwextstep0
= false;
1718 pDevice
->bwextstep1
= false;
1719 pDevice
->bwextstep2
= false;
1720 pDevice
->bwextstep3
= false;
1721 pDevice
->bWPASuppWextEnabled
= true;
1722 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1723 KeyvInitTable(pDevice
, &pDevice
->sKey
);
1726 spin_lock_irq(&pDevice
->lock
);
1727 ret
= wpa_set_keys(pDevice
, param
);
1728 spin_unlock_irq(&pDevice
->lock
);
1735 int iwctl_giwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1736 union iwreq_data
*wrqu
, char *extra
)
1741 int iwctl_siwmlme(struct net_device
*dev
, struct iw_request_info
*info
,
1742 union iwreq_data
*wrqu
, char *extra
)
1744 struct vnt_private
*pDevice
= netdev_priv(dev
);
1745 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1746 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1749 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME\n");
1754 if (memcmp(pMgmt
->abyCurrBSSID
, mlme
->addr
.sa_data
, ETH_ALEN
)) {
1758 switch (mlme
->cmd
) {
1759 case IW_MLME_DEAUTH
:
1760 case IW_MLME_DISASSOC
:
1761 if (pDevice
->bLinkPass
== true) {
1762 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1763 bScheduleCommand((void *)pDevice
, WLAN_CMD_DISASSOCIATE
,
1773 static int iwctl_config_commit(struct net_device
*dev
,
1774 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1776 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"SIOCSIWCOMMIT\n");
1781 static const iw_handler iwctl_handler
[] = {
1782 IW_HANDLER(SIOCSIWCOMMIT
, iwctl_config_commit
),
1783 IW_HANDLER(SIOCGIWNAME
, iwctl_giwname
),
1784 IW_HANDLER(SIOCSIWFREQ
, iwctl_siwfreq
),
1785 IW_HANDLER(SIOCGIWFREQ
, iwctl_giwfreq
),
1786 IW_HANDLER(SIOCSIWMODE
, iwctl_siwmode
),
1787 IW_HANDLER(SIOCGIWMODE
, iwctl_giwmode
),
1788 IW_HANDLER(SIOCGIWSENS
, iwctl_giwsens
),
1789 IW_HANDLER(SIOCGIWRANGE
, iwctl_giwrange
),
1790 IW_HANDLER(SIOCSIWAP
, iwctl_siwap
),
1791 IW_HANDLER(SIOCGIWAP
, iwctl_giwap
),
1792 IW_HANDLER(SIOCSIWMLME
, iwctl_siwmlme
),
1793 IW_HANDLER(SIOCGIWAPLIST
, iwctl_giwaplist
),
1794 IW_HANDLER(SIOCSIWSCAN
, iwctl_siwscan
),
1795 IW_HANDLER(SIOCGIWSCAN
, iwctl_giwscan
),
1796 IW_HANDLER(SIOCSIWESSID
, iwctl_siwessid
),
1797 IW_HANDLER(SIOCGIWESSID
, iwctl_giwessid
),
1798 IW_HANDLER(SIOCSIWRATE
, iwctl_siwrate
),
1799 IW_HANDLER(SIOCGIWRATE
, iwctl_giwrate
),
1800 IW_HANDLER(SIOCSIWRTS
, iwctl_siwrts
),
1801 IW_HANDLER(SIOCGIWRTS
, iwctl_giwrts
),
1802 IW_HANDLER(SIOCSIWFRAG
, iwctl_siwfrag
),
1803 IW_HANDLER(SIOCGIWFRAG
, iwctl_giwfrag
),
1804 IW_HANDLER(SIOCSIWRETRY
, iwctl_siwretry
),
1805 IW_HANDLER(SIOCGIWRETRY
, iwctl_giwretry
),
1806 IW_HANDLER(SIOCSIWENCODE
, iwctl_siwencode
),
1807 IW_HANDLER(SIOCGIWENCODE
, iwctl_giwencode
),
1808 IW_HANDLER(SIOCSIWPOWER
, iwctl_siwpower
),
1809 IW_HANDLER(SIOCGIWPOWER
, iwctl_giwpower
),
1810 IW_HANDLER(SIOCSIWGENIE
, iwctl_siwgenie
),
1811 IW_HANDLER(SIOCGIWGENIE
, iwctl_giwgenie
),
1812 IW_HANDLER(SIOCSIWAUTH
, iwctl_siwauth
),
1813 IW_HANDLER(SIOCGIWAUTH
, iwctl_giwauth
),
1814 IW_HANDLER(SIOCSIWENCODEEXT
, iwctl_siwencodeext
),
1815 IW_HANDLER(SIOCGIWENCODEEXT
, iwctl_giwencodeext
)
1818 static const iw_handler iwctl_private_handler
[] = {
1819 NULL
, // SIOCIWFIRSTPRIV
1822 const struct iw_handler_def iwctl_handler_def
= {
1823 .get_wireless_stats
= &iwctl_get_wireless_stats
,
1824 .num_standard
= ARRAY_SIZE(iwctl_handler
),
1826 .num_private_args
= 0,
1827 .standard
= iwctl_handler
,
1829 .private_args
= NULL
,