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
45 static const long frequency_list
[] = {
46 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
47 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
48 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
49 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
50 5700, 5745, 5765, 5785, 5805, 5825
53 static int msglevel
= MSG_LEVEL_INFO
;
55 struct iw_statistics
*iwctl_get_wireless_stats(struct net_device
*dev
)
57 struct vnt_private
*pDevice
= netdev_priv(dev
);
60 pDevice
->wstats
.status
= pDevice
->eOPMode
;
61 if (pDevice
->scStatistic
.LinkQuality
> 100)
62 pDevice
->scStatistic
.LinkQuality
= 100;
63 pDevice
->wstats
.qual
.qual
= (u8
)pDevice
->scStatistic
.LinkQuality
;
64 RFvRSSITodBm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
65 pDevice
->wstats
.qual
.level
= ldBm
;
66 pDevice
->wstats
.qual
.noise
= 0;
67 pDevice
->wstats
.qual
.updated
= 1;
68 pDevice
->wstats
.discard
.nwid
= 0;
69 pDevice
->wstats
.discard
.code
= 0;
70 pDevice
->wstats
.discard
.fragment
= 0;
71 pDevice
->wstats
.discard
.misc
= 0;
72 pDevice
->wstats
.miss
.beacon
= 0;
73 return &pDevice
->wstats
;
77 * Wireless Handler: get protocol name
79 int iwctl_giwname(struct net_device
*dev
, struct iw_request_info
*info
,
80 union iwreq_data
*wrqu
, char *extra
)
82 strcpy(wrqu
->name
, "802.11-a/b/g");
87 * Wireless Handler: set scan
89 int iwctl_siwscan(struct net_device
*dev
, struct iw_request_info
*info
,
90 union iwreq_data
*wrqu
, char *extra
)
92 struct vnt_private
*pDevice
= netdev_priv(dev
);
93 struct iw_point
*wrq
= &wrqu
->data
;
94 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
95 struct iw_scan_req
*req
= (struct iw_scan_req
*)extra
;
96 u8 abyScanSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
97 PWLAN_IE_SSID pItemSSID
= NULL
;
99 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
102 PRINT_K(" SIOCSIWSCAN\n");
107 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
109 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
113 if (pDevice
->byReAssocCount
> 0) { // reject scan when re-associating!
114 // send scan event to wpa_Supplicant
115 union iwreq_data wrqu
;
116 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
117 memset(&wrqu
, 0, sizeof(wrqu
));
118 wireless_send_event(pDevice
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
122 spin_lock_irq(&pDevice
->lock
);
124 BSSvClearBSSList((void *)pDevice
, pDevice
->bLinkPass
);
126 // mike add: active scan OR passive scan OR desire_ssid scan
127 if (wrq
->length
== sizeof(struct iw_scan_req
)) {
128 if (wrq
->flags
& IW_SCAN_THIS_ESSID
) { // desire_ssid scan
129 memset(abyScanSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
130 pItemSSID
= (PWLAN_IE_SSID
)abyScanSSID
;
131 pItemSSID
->byElementID
= WLAN_EID_SSID
;
132 memcpy(pItemSSID
->abySSID
, req
->essid
, (int)req
->essid_len
);
133 if (pItemSSID
->abySSID
[req
->essid_len
] == '\0') {
134 if (req
->essid_len
> 0)
135 pItemSSID
->len
= req
->essid_len
;
137 pItemSSID
->len
= req
->essid_len
;
139 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
140 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID
)abyScanSSID
)->abySSID
,
141 ((PWLAN_IE_SSID
)abyScanSSID
)->len
);
142 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, abyScanSSID
);
143 spin_unlock_irq(&pDevice
->lock
);
146 } else if (req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) { // passive scan
147 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
149 } else { // active scan
150 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
153 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
154 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
155 spin_unlock_irq(&pDevice
->lock
);
161 * Wireless Handler : get scan results
163 int iwctl_giwscan(struct net_device
*dev
, struct iw_request_info
*info
,
164 union iwreq_data
*wrqu
, char *extra
)
166 struct iw_point
*wrq
= &wrqu
->data
;
170 struct vnt_private
*pDevice
= netdev_priv(dev
);
171 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
173 PWLAN_IE_SSID pItemSSID
;
174 PWLAN_IE_SUPP_RATES pSuppRates
;
175 PWLAN_IE_SUPP_RATES pExtSuppRates
;
176 char *current_ev
= extra
;
177 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
178 char *current_val
= NULL
;
182 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSCAN\n");
187 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
191 pBSS
= &(pMgmt
->sBSSList
[0]);
192 for (ii
= 0, jj
= 0; jj
< MAX_BSS_NUM
; jj
++) {
193 if (current_ev
>= end_buf
)
195 pBSS
= &(pMgmt
->sBSSList
[jj
]);
198 memset(&iwe
, 0, sizeof(iwe
));
200 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
201 memcpy(iwe
.u
.ap_addr
.sa_data
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
202 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
204 memset(&iwe
, 0, sizeof(iwe
));
205 iwe
.cmd
= SIOCGIWESSID
;
206 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
207 iwe
.u
.data
.length
= pItemSSID
->len
;
208 iwe
.u
.data
.flags
= 1;
209 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
211 memset(&iwe
, 0, sizeof(iwe
));
212 iwe
.cmd
= SIOCGIWMODE
;
213 if (WLAN_GET_CAP_INFO_ESS(pBSS
->wCapInfo
))
214 iwe
.u
.mode
= IW_MODE_INFRA
;
216 iwe
.u
.mode
= IW_MODE_ADHOC
;
217 iwe
.len
= IW_EV_UINT_LEN
;
218 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
220 pSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abySuppRates
;
221 pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abyExtSuppRates
;
222 memset(&iwe
, 0, sizeof(iwe
));
223 iwe
.cmd
= SIOCGIWFREQ
;
224 iwe
.u
.freq
.m
= pBSS
->uChannel
;
227 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
229 int f
= (int)pBSS
->uChannel
- 1;
232 iwe
.u
.freq
.m
= frequency_list
[f
] * 100000;
235 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
237 memset(&iwe
, 0, sizeof(iwe
));
239 RFvRSSITodBm(pDevice
, (u8
)(pBSS
->uRSSI
), &ldBm
);
240 iwe
.u
.qual
.level
= ldBm
;
241 iwe
.u
.qual
.noise
= 0;
244 iwe
.u
.qual
.qual
= 100;
248 iwe
.u
.qual
.qual
= (40 - (-ldBm
- 50)) * 100 / 40;
249 iwe
.u
.qual
.updated
= 7;
251 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
253 memset(&iwe
, 0, sizeof(iwe
));
254 iwe
.cmd
= SIOCGIWENCODE
;
255 iwe
.u
.data
.length
= 0;
256 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS
->wCapInfo
))
257 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
259 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
260 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
262 memset(&iwe
, 0, sizeof(iwe
));
263 iwe
.cmd
= SIOCGIWRATE
;
264 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
265 current_val
= current_ev
+ IW_EV_LCP_LEN
;
267 for (kk
= 0; kk
< 12; kk
++) {
268 if (pSuppRates
->abyRates
[kk
] == 0)
270 // Bit rate given in 500 kb/s units (+ 0x80)
271 iwe
.u
.bitrate
.value
= ((pSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
272 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
274 for (kk
= 0; kk
< 8; kk
++) {
275 if (pExtSuppRates
->abyRates
[kk
] == 0)
277 // Bit rate given in 500 kb/s units (+ 0x80)
278 iwe
.u
.bitrate
.value
= ((pExtSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
279 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
282 if ((current_val
- current_ev
) > IW_EV_LCP_LEN
)
283 current_ev
= current_val
;
285 if ((pBSS
->wWPALen
> 0) && (pBSS
->wWPALen
<= MAX_WPA_IE_LEN
)) {
286 memset(&iwe
, 0, sizeof(iwe
));
288 iwe
.u
.data
.length
= pBSS
->wWPALen
;
289 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byWPAIE
);
292 if ((pBSS
->wRSNLen
> 0) && (pBSS
->wRSNLen
<= MAX_WPA_IE_LEN
)) {
293 memset(&iwe
, 0, sizeof(iwe
));
295 iwe
.u
.data
.length
= pBSS
->wRSNLen
;
296 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byRSNIE
);
300 wrq
->length
= current_ev
- extra
;
305 * Wireless Handler: set frequence or channel
307 int iwctl_siwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
308 union iwreq_data
*wrqu
, char *extra
)
310 struct vnt_private
*pDevice
= netdev_priv(dev
);
311 struct iw_freq
*wrq
= &wrqu
->freq
;
314 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFREQ\n");
316 // If setting by frequency, convert to a channel
317 if ((wrq
->e
== 1) && (wrq
->m
>= (int)2.412e8
) &&
318 (wrq
->m
<= (int)2.487e8
)) {
319 int f
= wrq
->m
/ 100000;
321 while ((c
< 14) && (f
!= frequency_list
[c
]))
326 // Setting by channel number
327 if ((wrq
->m
> 14) || (wrq
->e
> 0)) {
330 int channel
= wrq
->m
;
331 if ((channel
< 1) || (channel
> 14)) {
332 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: New channel value of %d is invalid!\n", dev
->name
, wrq
->m
);
335 // Yes ! We can set it !!!
336 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set to channel = %d\n", channel
);
337 pDevice
->uChannel
= channel
;
344 * Wireless Handler: get frequence or channel
346 int iwctl_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
347 union iwreq_data
*wrqu
, char *extra
)
349 struct vnt_private
*pDevice
= netdev_priv(dev
);
350 struct iw_freq
*wrq
= &wrqu
->freq
;
351 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
353 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFREQ\n");
358 #ifdef WEXT_USECHANNELS
359 wrq
->m
= (int)pMgmt
->uCurrChannel
;
363 int f
= (int)pMgmt
->uCurrChannel
- 1;
366 wrq
->m
= frequency_list
[f
] * 100000;
374 * Wireless Handler: set operation mode
376 int iwctl_siwmode(struct net_device
*dev
, struct iw_request_info
*info
,
377 union iwreq_data
*wrqu
, char *extra
)
379 struct vnt_private
*pDevice
= netdev_priv(dev
);
380 __u32
*wmode
= &wrqu
->mode
;
381 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
384 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMODE\n");
389 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
&& pDevice
->bEnableHostapd
) {
390 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
391 "Can't set operation mode, hostapd is running\n");
397 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_IBSS_STA
) {
398 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
399 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
400 pDevice
->bCommit
= true;
402 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to ad-hoc\n");
406 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_ESS_STA
) {
407 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
408 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
409 pDevice
->bCommit
= true;
411 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to infrastructure\n");
415 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
419 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_AP
) {
420 pMgmt
->eConfigMode
= WMAC_CONFIG_AP
;
421 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
422 pDevice
->bCommit
= true;
424 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to Access Point\n");
428 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
435 if (pDevice
->bCommit
) {
436 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
437 netif_stop_queue(pDevice
->dev
);
438 spin_lock_irq(&pDevice
->lock
);
439 bScheduleCommand((void *) pDevice
,
440 WLAN_CMD_RUN_AP
, NULL
);
441 spin_unlock_irq(&pDevice
->lock
);
443 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
444 "Commit the settings\n");
446 spin_lock_irq(&pDevice
->lock
);
448 if (pDevice
->bLinkPass
&&
449 memcmp(pMgmt
->abyCurrSSID
,
450 pMgmt
->abyDesireSSID
,
451 WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
)) {
452 bScheduleCommand((void *) pDevice
,
453 WLAN_CMD_DISASSOCIATE
, NULL
);
455 pDevice
->bLinkPass
= false;
456 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
457 memset(pMgmt
->abyCurrBSSID
, 0, 6);
460 ControlvMaskByte(pDevice
,
461 MESSAGE_REQUEST_MACREG
, MAC_REG_PAPEDELAY
,
462 LEDSTS_STS
, LEDSTS_SLOW
);
464 netif_stop_queue(pDevice
->dev
);
466 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
468 if (!pDevice
->bWPASuppWextEnabled
)
469 bScheduleCommand((void *) pDevice
,
471 pMgmt
->abyDesireSSID
);
473 bScheduleCommand((void *) pDevice
,
477 spin_unlock_irq(&pDevice
->lock
);
479 pDevice
->bCommit
= false;
486 * Wireless Handler: get operation mode
488 int iwctl_giwmode(struct net_device
*dev
, struct iw_request_info
*info
,
489 union iwreq_data
*wrqu
, char *extra
)
491 struct vnt_private
*pDevice
= netdev_priv(dev
);
492 __u32
*wmode
= &wrqu
->mode
;
493 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
495 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWMODE\n");
500 // If not managed, assume it's ad-hoc
501 switch (pMgmt
->eConfigMode
) {
502 case WMAC_CONFIG_ESS_STA
:
503 *wmode
= IW_MODE_INFRA
;
505 case WMAC_CONFIG_IBSS_STA
:
506 *wmode
= IW_MODE_ADHOC
;
508 case WMAC_CONFIG_AUTO
:
509 *wmode
= IW_MODE_INFRA
;
512 *wmode
= IW_MODE_MASTER
;
515 *wmode
= IW_MODE_ADHOC
;
522 * Wireless Handler: get capability range
524 int iwctl_giwrange(struct net_device
*dev
, struct iw_request_info
*info
,
525 union iwreq_data
*wrqu
, char *extra
)
527 struct iw_point
*wrq
= &wrqu
->data
;
528 struct iw_range
*range
= (struct iw_range
*)extra
;
531 u8 abySupportedRates
[13] = {
532 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
536 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRANGE\n");
538 wrq
->length
= sizeof(struct iw_range
);
539 memset(range
, 0, sizeof(struct iw_range
));
540 range
->min_nwid
= 0x0000;
541 range
->max_nwid
= 0x0000;
542 range
->num_channels
= 14;
543 // Should be based on cap_rid.country to give only
544 // what the current card support
546 for (i
= 0; i
< 14; i
++) {
547 range
->freq
[k
].i
= i
+ 1; // List index
548 range
->freq
[k
].m
= frequency_list
[i
] * 100000;
549 range
->freq
[k
++].e
= 1; // Values in table in MHz -> * 10^5 * 10
551 range
->num_frequency
= k
;
552 // Hum... Should put the right values there
553 range
->max_qual
.qual
= 100;
554 range
->max_qual
.level
= 0;
555 range
->max_qual
.noise
= 0;
556 range
->sensitivity
= 255;
558 for (i
= 0; i
< 13; i
++) {
559 range
->bitrate
[i
] = abySupportedRates
[i
] * 500000;
560 if (range
->bitrate
[i
] == 0)
563 range
->num_bitrates
= i
;
565 // Set an indication of the max TCP throughput
566 // in bit/s that we can expect using this interface.
567 // May be use for QoS stuff... Jean II
569 range
->throughput
= 5 * 1000 * 1000;
571 range
->throughput
= 1.5 * 1000 * 1000;
574 range
->max_rts
= 2312;
575 range
->min_frag
= 256;
576 range
->max_frag
= 2312;
578 // the encoding capabilities
579 range
->num_encoding_sizes
= 3;
581 range
->encoding_size
[0] = 5;
583 range
->encoding_size
[1] = 13;
584 // 256 bits for WPA-PSK
585 range
->encoding_size
[2] = 32;
586 // 4 keys are allowed
587 range
->max_encoding_tokens
= 4;
589 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
590 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
593 range
->max_pmp
= 1000000; // 1 secs
595 range
->max_pmt
= 1000000; // 1 secs
596 range
->pmp_flags
= IW_POWER_PERIOD
;
597 range
->pmt_flags
= IW_POWER_TIMEOUT
;
598 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_ALL_R
;
600 // Transmit Power - values are in mW
601 range
->txpower
[0] = 100;
602 range
->num_txpower
= 1;
603 range
->txpower_capa
= IW_TXPOW_MWATT
;
604 range
->we_version_source
= WIRELESS_EXT
;
605 range
->we_version_compiled
= WIRELESS_EXT
;
606 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
607 range
->retry_flags
= IW_RETRY_LIMIT
;
608 range
->r_time_flags
= IW_RETRY_LIFETIME
;
609 range
->min_retry
= 1;
610 range
->max_retry
= 65535;
611 range
->min_r_time
= 1024;
612 range
->max_r_time
= 65535 * 1024;
613 // Experimental measurements - boundary 11/5.5 Mb/s
614 // Note : with or without the (local->rssi), results
615 // are somewhat different. - Jean II
616 range
->avg_qual
.qual
= 6;
617 range
->avg_qual
.level
= 176; // -80 dBm
618 range
->avg_qual
.noise
= 0;
625 * Wireless Handler : set ap mac address
627 int iwctl_siwap(struct net_device
*dev
, struct iw_request_info
*info
,
628 union iwreq_data
*wrqu
, char *extra
)
630 struct vnt_private
*pDevice
= netdev_priv(dev
);
631 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
632 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
634 u8 ZeroBSSID
[WLAN_BSSID_LEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
636 PRINT_K(" SIOCSIWAP\n");
641 if (wrq
->sa_family
!= ARPHRD_ETHER
) {
644 memcpy(pMgmt
->abyDesireBSSID
, wrq
->sa_data
, 6);
646 if ((is_broadcast_ether_addr(pMgmt
->abyDesireBSSID
)) ||
647 (memcmp(pMgmt
->abyDesireBSSID
, ZeroBSSID
, 6) == 0)) {
648 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
651 // mike add: if desired AP is hidden ssid(there are
652 // two same BSSID in list), then ignore,because you
653 // don't known which one to be connect with??
656 unsigned uSameBssidNum
= 0;
657 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
658 if (pMgmt
->sBSSList
[ii
].bActive
&&
659 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
660 pMgmt
->abyDesireBSSID
)) {
664 if (uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
665 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
670 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
671 pDevice
->bCommit
= true;
677 * Wireless Handler: get ap mac address
679 int iwctl_giwap(struct net_device
*dev
, struct iw_request_info
*info
,
680 union iwreq_data
*wrqu
, char *extra
)
682 struct vnt_private
*pDevice
= netdev_priv(dev
);
683 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
684 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
686 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAP\n");
691 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
693 if ((pDevice
->bLinkPass
== false) && (pMgmt
->eCurrMode
!= WMAC_MODE_ESS_AP
))
694 memset(wrq
->sa_data
, 0, 6);
696 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)
697 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
699 wrq
->sa_family
= ARPHRD_ETHER
;
704 * Wireless Handler: get ap list
706 int iwctl_giwaplist(struct net_device
*dev
, struct iw_request_info
*info
,
707 union iwreq_data
*wrqu
, char *extra
)
709 struct iw_point
*wrq
= &wrqu
->data
;
710 struct sockaddr
*sock
;
711 struct iw_quality
*qual
;
712 struct vnt_private
*pDevice
= netdev_priv(dev
);
713 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
714 PKnownBSS pBSS
= &pMgmt
->sBSSList
[0];
718 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAPLIST\n");
719 /* Only super-user can see AP list */
724 if (!capable(CAP_NET_ADMIN
))
730 sock
= kzalloc(sizeof(struct sockaddr
) * IW_MAX_AP
, GFP_KERNEL
);
733 qual
= kzalloc(sizeof(struct iw_quality
) * IW_MAX_AP
, GFP_KERNEL
);
739 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
740 if (!pBSS
[ii
].bActive
)
744 memcpy(sock
[jj
].sa_data
, pBSS
[ii
].abyBSSID
, 6);
745 sock
[jj
].sa_family
= ARPHRD_ETHER
;
746 qual
[jj
].level
= pBSS
[ii
].uRSSI
;
747 qual
[jj
].qual
= qual
[jj
].noise
= 0;
748 qual
[jj
].updated
= 2;
752 wrq
->flags
= 1; /* Should be defined */
754 memcpy(extra
, sock
, sizeof(struct sockaddr
) * jj
);
755 memcpy(extra
+ sizeof(struct sockaddr
) * jj
, qual
,
756 sizeof(struct iw_quality
) * jj
);
765 * Wireless Handler: set essid
767 int iwctl_siwessid(struct net_device
*dev
, struct iw_request_info
*info
,
768 union iwreq_data
*wrqu
, char *extra
)
770 struct vnt_private
*pDevice
= netdev_priv(dev
);
771 struct iw_point
*wrq
= &wrqu
->essid
;
772 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
773 PWLAN_IE_SSID pItemSSID
;
778 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
781 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWESSID :\n");
783 pDevice
->fWPA_Authened
= false;
784 // Check if we asked for `any'
785 if (wrq
->flags
== 0) {
786 // Just send an empty SSID list
787 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
788 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
789 PRINT_K("set essid to 'any'\n");
790 // Unknown desired AP, so here need not associate??
794 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
795 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
796 pItemSSID
->byElementID
= WLAN_EID_SSID
;
798 memcpy(pItemSSID
->abySSID
, extra
, wrq
->length
);
799 if (pItemSSID
->abySSID
[wrq
->length
] == '\0') {
801 pItemSSID
->len
= wrq
->length
;
803 pItemSSID
->len
= wrq
->length
;
805 PRINT_K("set essid to %s\n", pItemSSID
->abySSID
);
807 // mike: need clear desiredBSSID
808 if (pItemSSID
->len
== 0) {
809 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
813 // Wext wil order another command of siwap to link
814 // with desired AP, so here need not associate??
815 if (pDevice
->bWPASuppWextEnabled
== true) {
816 /*******search if in hidden ssid mode ****/
817 PKnownBSS pCurr
= NULL
;
818 u8 abyTmpDesireSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
820 unsigned uSameBssidNum
= 0;
822 memcpy(abyTmpDesireSSID
, pMgmt
->abyDesireSSID
, sizeof(abyTmpDesireSSID
));
823 pCurr
= BSSpSearchBSSList(pDevice
, NULL
,
825 pDevice
->eConfigPHYMode
);
828 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
829 vResetCommandTimer((void *)pDevice
);
830 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
831 bScheduleCommand((void *)pDevice
,
833 pMgmt
->abyDesireSSID
);
834 bScheduleCommand((void *)pDevice
,
836 pMgmt
->abyDesireSSID
);
837 } else { // mike: to find out if that desired SSID is a
838 // hidden-ssid AP, by means of judging if there
839 // are two same BSSID exist in list ?
840 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
841 if (pMgmt
->sBSSList
[ii
].bActive
&&
842 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
847 if (uSameBssidNum
>= 2) { // hit: desired AP is in hidden ssid mode!!!
848 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
849 vResetCommandTimer((void *)pDevice
);
850 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
; // this scan type, you'll submit scan result!
851 bScheduleCommand((void *)pDevice
,
853 pMgmt
->abyDesireSSID
);
854 bScheduleCommand((void *)pDevice
,
856 pMgmt
->abyDesireSSID
);
862 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set essid = %s\n", pItemSSID
->abySSID
);
865 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
866 pDevice
->bCommit
= true;
872 * Wireless Handler: get essid
874 int iwctl_giwessid(struct net_device
*dev
, struct iw_request_info
*info
,
875 union iwreq_data
*wrqu
, char *extra
)
877 struct vnt_private
*pDevice
= netdev_priv(dev
);
878 struct iw_point
*wrq
= &wrqu
->essid
;
879 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
880 PWLAN_IE_SSID pItemSSID
;
882 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWESSID\n");
887 // Note: if wrq->u.data.flags != 0, we should get the relevant
888 // SSID from the SSID list...
890 // Get the current SSID
891 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
892 memcpy(extra
, pItemSSID
->abySSID
, pItemSSID
->len
);
893 extra
[pItemSSID
->len
] = '\0';
895 wrq
->length
= pItemSSID
->len
;
896 wrq
->flags
= 1; // active
902 * Wireless Handler: set data rate
904 int iwctl_siwrate(struct net_device
*dev
, struct iw_request_info
*info
,
905 union iwreq_data
*wrqu
, char *extra
)
907 struct vnt_private
*pDevice
= netdev_priv(dev
);
908 struct iw_param
*wrq
= &wrqu
->bitrate
;
912 u8 abySupportedRates
[13] = {
913 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
917 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRATE\n");
918 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
923 // First: get a valid bit rate value
925 // Which type of value
926 if ((wrq
->value
< 13) && (wrq
->value
>= 0)) {
927 // Setting by rate index
928 // Find value in the magic rate table
931 // Setting by frequency value
932 u8 normvalue
= (u8
)(wrq
->value
/500000);
934 // Check if rate is valid
935 for (i
= 0; i
< 13; i
++) {
936 if (normvalue
== abySupportedRates
[i
]) {
942 // -1 designed the max rate (mostly auto mode)
943 if (wrq
->value
== -1) {
944 // Get the highest available rate
945 for (i
= 0; i
< 13; i
++) {
946 if (abySupportedRates
[i
] == 0)
953 // Check that it is valid
954 // brate is index of abySupportedRates[]
960 // Now, check if we want a fixed or auto value
961 if (wrq
->fixed
!= 0) {
964 pDevice
->bFixRate
= true;
965 if ((pDevice
->byBBType
== BB_TYPE_11B
) && (brate
> 3)) {
966 pDevice
->uConnectionRate
= 3;
968 pDevice
->uConnectionRate
= brate
;
969 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fixed to Rate %d\n", pDevice
->uConnectionRate
);
972 pDevice
->bFixRate
= false;
973 pDevice
->uConnectionRate
= 13;
980 * Wireless Handler: get data rate
982 int iwctl_giwrate(struct net_device
*dev
, struct iw_request_info
*info
,
983 union iwreq_data
*wrqu
, char *extra
)
985 struct vnt_private
*pDevice
= netdev_priv(dev
);
986 struct iw_param
*wrq
= &wrqu
->bitrate
;
987 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
989 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRATE\n");
995 u8 abySupportedRates
[13] = {
996 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
997 0x48, 0x60, 0x6C, 0x90
1001 if (pDevice
->uConnectionRate
< 13) {
1002 brate
= abySupportedRates
[pDevice
->uConnectionRate
];
1004 if (pDevice
->byBBType
== BB_TYPE_11B
)
1006 if (pDevice
->byBBType
== BB_TYPE_11G
)
1008 if (pDevice
->byBBType
== BB_TYPE_11A
)
1011 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
1012 if (pDevice
->byBBType
== BB_TYPE_11B
)
1014 if (pDevice
->byBBType
== BB_TYPE_11G
)
1016 if (pDevice
->byBBType
== BB_TYPE_11A
)
1019 if (pDevice
->uConnectionRate
== 13)
1020 brate
= abySupportedRates
[pDevice
->wCurrentRate
];
1021 wrq
->value
= brate
* 500000;
1022 // If more than one rate, set auto
1023 if (pDevice
->bFixRate
== true)
1031 * Wireless Handler: set rts threshold
1033 int iwctl_siwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1034 union iwreq_data
*wrqu
, char *extra
)
1036 struct vnt_private
*pDevice
= netdev_priv(dev
);
1037 struct iw_param
*wrq
= &wrqu
->rts
;
1039 if ((wrq
->value
< 0 || wrq
->value
> 2312) && !wrq
->disabled
)
1042 else if (wrq
->disabled
)
1043 pDevice
->wRTSThreshold
= 2312;
1045 pDevice
->wRTSThreshold
= wrq
->value
;
1051 * Wireless Handler: get rts
1053 int iwctl_giwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1054 union iwreq_data
*wrqu
, char *extra
)
1056 struct vnt_private
*pDevice
= netdev_priv(dev
);
1057 struct iw_param
*wrq
= &wrqu
->rts
;
1059 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRTS\n");
1060 wrq
->value
= pDevice
->wRTSThreshold
;
1061 wrq
->disabled
= (wrq
->value
>= 2312);
1067 * Wireless Handler: set fragment threshold
1069 int iwctl_siwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1070 union iwreq_data
*wrqu
, char *extra
)
1072 struct vnt_private
*pDevice
= netdev_priv(dev
);
1073 struct iw_param
*wrq
= &wrqu
->frag
;
1075 int fthr
= wrq
->value
;
1077 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFRAG\n");
1081 if ((fthr
< 256) || (fthr
> 2312)) {
1084 fthr
&= ~0x1; // Get an even value
1085 pDevice
->wFragmentationThreshold
= (u16
)fthr
;
1091 * Wireless Handler: get fragment threshold
1093 int iwctl_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1094 union iwreq_data
*wrqu
, char *extra
)
1096 struct vnt_private
*pDevice
= netdev_priv(dev
);
1097 struct iw_param
*wrq
= &wrqu
->frag
;
1099 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFRAG\n");
1100 wrq
->value
= pDevice
->wFragmentationThreshold
;
1101 wrq
->disabled
= (wrq
->value
>= 2312);
1107 * Wireless Handler: set retry threshold
1109 int iwctl_siwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1110 union iwreq_data
*wrqu
, char *extra
)
1112 struct vnt_private
*pDevice
= netdev_priv(dev
);
1113 struct iw_param
*wrq
= &wrqu
->retry
;
1116 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRETRY\n");
1118 if (wrq
->disabled
) {
1123 if (wrq
->flags
& IW_RETRY_LIMIT
) {
1124 if (wrq
->flags
& IW_RETRY_MAX
) {
1125 pDevice
->byLongRetryLimit
= wrq
->value
;
1126 } else if (wrq
->flags
& IW_RETRY_MIN
) {
1127 pDevice
->byShortRetryLimit
= wrq
->value
;
1129 // No modifier : set both
1130 pDevice
->byShortRetryLimit
= wrq
->value
;
1131 pDevice
->byLongRetryLimit
= wrq
->value
;
1134 if (wrq
->flags
& IW_RETRY_LIFETIME
)
1135 pDevice
->wMaxTransmitMSDULifetime
= wrq
->value
;
1140 * Wireless Handler: get retry threshold
1142 int iwctl_giwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1143 union iwreq_data
*wrqu
, char *extra
)
1145 struct vnt_private
*pDevice
= netdev_priv(dev
);
1146 struct iw_param
*wrq
= &wrqu
->retry
;
1147 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRETRY\n");
1148 wrq
->disabled
= 0; // Can't be disabled
1150 // Note: by default, display the min retry number
1151 if ((wrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1152 wrq
->flags
= IW_RETRY_LIFETIME
;
1153 wrq
->value
= (int)pDevice
->wMaxTransmitMSDULifetime
; // ms
1154 } else if ((wrq
->flags
& IW_RETRY_MAX
)) {
1155 wrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1156 wrq
->value
= (int)pDevice
->byLongRetryLimit
;
1158 wrq
->flags
= IW_RETRY_LIMIT
;
1159 wrq
->value
= (int)pDevice
->byShortRetryLimit
;
1160 if ((int)pDevice
->byShortRetryLimit
!= (int)pDevice
->byLongRetryLimit
)
1161 wrq
->flags
|= IW_RETRY_MIN
;
1167 * Wireless Handler: set encode mode
1169 int iwctl_siwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1170 union iwreq_data
*wrqu
, char *extra
)
1172 struct vnt_private
*pDevice
= netdev_priv(dev
);
1173 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1174 struct iw_point
*wrq
= &wrqu
->encoding
;
1175 u32 dwKeyIndex
= (u32
)(wrq
->flags
& IW_ENCODE_INDEX
);
1179 int index
= (wrq
->flags
& IW_ENCODE_INDEX
);
1181 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODE\n");
1186 // Check the size of the key
1187 if (wrq
->length
> WLAN_WEP232_KEYLEN
) {
1192 if (dwKeyIndex
> WLAN_WEP_NKEYS
) {
1200 // Send the key to the card
1201 if (wrq
->length
> 0) {
1202 if (wrq
->length
== WLAN_WEP232_KEYLEN
) {
1203 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 232 bit wep key\n");
1204 } else if (wrq
->length
== WLAN_WEP104_KEYLEN
) {
1205 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 104 bit wep key\n");
1206 } else if (wrq
->length
== WLAN_WEP40_KEYLEN
) {
1207 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 40 bit wep key, index= %d\n", (int)dwKeyIndex
);
1209 memset(pDevice
->abyKey
, 0, WLAN_WEP232_KEYLEN
);
1210 memcpy(pDevice
->abyKey
, extra
, wrq
->length
);
1212 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"abyKey: ");
1213 for (ii
= 0; ii
< wrq
->length
; ii
++)
1214 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pDevice
->abyKey
[ii
]);
1216 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1217 spin_lock_irq(&pDevice
->lock
);
1218 KeybSetDefaultKey(pDevice
,
1220 dwKeyIndex
| (1 << 31),
1224 spin_unlock_irq(&pDevice
->lock
);
1226 pDevice
->byKeyIndex
= (u8
)dwKeyIndex
;
1227 pDevice
->uKeyLength
= wrq
->length
;
1228 pDevice
->bTransmitKey
= true;
1229 pDevice
->bEncryptionEnable
= true;
1230 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1232 // Do we want to just set the transmit key index?
1234 pDevice
->byKeyIndex
= index
;
1235 } else if (!(wrq
->flags
& IW_ENCODE_MODE
)) {
1241 if (wrq
->flags
& IW_ENCODE_DISABLED
) {
1242 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disable WEP function\n");
1243 pMgmt
->bShareKeyAlgorithm
= false;
1244 pDevice
->bEncryptionEnable
= false;
1245 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1246 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1247 spin_lock_irq(&pDevice
->lock
);
1248 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++)
1249 MACvDisableKeyEntry(pDevice
, uu
);
1250 spin_unlock_irq(&pDevice
->lock
);
1253 if (wrq
->flags
& IW_ENCODE_RESTRICTED
) {
1254 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & ShareKey System\n");
1255 pMgmt
->bShareKeyAlgorithm
= true;
1257 if (wrq
->flags
& IW_ENCODE_OPEN
) {
1258 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & Open System\n");
1259 pMgmt
->bShareKeyAlgorithm
= false;
1262 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1267 int iwctl_giwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1268 union iwreq_data
*wrqu
, char *extra
)
1270 struct vnt_private
*pDevice
= netdev_priv(dev
);
1271 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1272 struct iw_point
*wrq
= &wrqu
->encoding
;
1273 char abyKey
[WLAN_WEP232_KEYLEN
];
1275 unsigned index
= (unsigned)(wrq
->flags
& IW_ENCODE_INDEX
);
1276 PSKeyItem pKey
= NULL
;
1278 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODE\n");
1283 if (index
> WLAN_WEP_NKEYS
)
1285 if (index
< 1) { // get default key
1286 if (pDevice
->byKeyIndex
< WLAN_WEP_NKEYS
)
1287 index
= pDevice
->byKeyIndex
;
1294 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1295 // Check encryption mode
1296 wrq
->flags
= IW_ENCODE_NOKEY
;
1297 // Is WEP enabled ???
1298 if (pDevice
->bEncryptionEnable
)
1299 wrq
->flags
|= IW_ENCODE_ENABLED
;
1301 wrq
->flags
|= IW_ENCODE_DISABLED
;
1303 if (pMgmt
->bShareKeyAlgorithm
)
1304 wrq
->flags
|= IW_ENCODE_RESTRICTED
;
1306 wrq
->flags
|= IW_ENCODE_OPEN
;
1309 if ((index
== 0) && (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
||
1310 pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)) { // get wpa pairwise key
1311 if (KeybGetKey(&(pDevice
->sKey
), pMgmt
->abyCurrBSSID
, 0xffffffff, &pKey
)) {
1312 wrq
->length
= pKey
->uKeyLength
;
1313 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1314 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1316 } else if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, (u8
)index
, &pKey
)) {
1317 wrq
->length
= pKey
->uKeyLength
;
1318 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1319 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1322 wrq
->flags
|= index
+ 1;
1327 * Wireless Handler: set power mode
1329 int iwctl_siwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1330 union iwreq_data
*wrqu
, char *extra
)
1332 struct vnt_private
*pDevice
= netdev_priv(dev
);
1333 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1334 struct iw_param
*wrq
= &wrqu
->power
;
1337 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER\n");
1342 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
1347 spin_lock_irq(&pDevice
->lock
);
1349 if (wrq
->disabled
) {
1350 pDevice
->ePSMode
= WMAC_POWER_CAM
;
1351 PSvDisablePowerSaving(pDevice
);
1352 spin_unlock_irq(&pDevice
->lock
);
1355 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1356 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1357 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1359 } else if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_PERIOD
) {
1360 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1361 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1364 spin_unlock_irq(&pDevice
->lock
);
1366 switch (wrq
->flags
& IW_POWER_MODE
) {
1367 case IW_POWER_UNICAST_R
:
1368 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1371 case IW_POWER_ALL_R
:
1372 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ALL_R\n");
1375 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ON\n");
1385 * Wireless Handler: get power mode
1387 int iwctl_giwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1388 union iwreq_data
*wrqu
, char *extra
)
1390 struct vnt_private
*pDevice
= netdev_priv(dev
);
1391 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1392 struct iw_param
*wrq
= &wrqu
->power
;
1393 int mode
= pDevice
->ePSMode
;
1395 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPOWER\n");
1400 if ((wrq
->disabled
= (mode
== WMAC_POWER_CAM
)))
1403 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1404 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1405 pMgmt
->wCurrBeaconPeriod
) / 100);
1406 wrq
->flags
= IW_POWER_TIMEOUT
;
1408 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1409 pMgmt
->wCurrBeaconPeriod
) / 100);
1410 wrq
->flags
= IW_POWER_PERIOD
;
1413 wrq
->flags
|= IW_POWER_ALL_R
;
1418 * Wireless Handler: get Sensitivity
1420 int iwctl_giwsens(struct net_device
*dev
, struct iw_request_info
*info
,
1421 union iwreq_data
*wrqu
, char *extra
)
1423 struct vnt_private
*pDevice
= netdev_priv(dev
);
1424 struct iw_param
*wrq
= &wrqu
->sens
;
1427 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSENS\n");
1428 if (pDevice
->bLinkPass
== true) {
1429 RFvRSSITodBm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
1434 wrq
->disabled
= (wrq
->value
== 0);
1439 int iwctl_siwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1440 union iwreq_data
*wrqu
, char *extra
)
1442 struct vnt_private
*pDevice
= netdev_priv(dev
);
1443 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1444 struct iw_param
*wrq
= &wrqu
->param
;
1446 static int wpa_version
= 0; // must be static to save the last value, einsn liu
1447 static int pairwise
= 0;
1452 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH\n");
1453 switch (wrq
->flags
& IW_AUTH_INDEX
) {
1454 case IW_AUTH_WPA_VERSION
:
1455 wpa_version
= wrq
->value
;
1456 if (wrq
->value
== IW_AUTH_WPA_VERSION_DISABLED
) {
1457 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1458 } else if (wrq
->value
== IW_AUTH_WPA_VERSION_WPA
) {
1459 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1461 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1464 case IW_AUTH_CIPHER_PAIRWISE
:
1465 pairwise
= wrq
->value
;
1466 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise
);
1467 if (pairwise
== IW_AUTH_CIPHER_CCMP
) {
1468 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1469 } else if (pairwise
== IW_AUTH_CIPHER_TKIP
) {
1470 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1471 } else if (pairwise
== IW_AUTH_CIPHER_WEP40
||
1472 pairwise
== IW_AUTH_CIPHER_WEP104
) {
1473 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1474 } else if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1475 // do nothing, einsn liu
1477 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1480 case IW_AUTH_CIPHER_GROUP
:
1481 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq
->value
);
1482 if (wpa_version
== IW_AUTH_WPA_VERSION_DISABLED
)
1484 if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1485 if (wrq
->value
== IW_AUTH_CIPHER_CCMP
)
1486 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1488 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1491 case IW_AUTH_KEY_MGMT
:
1492 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version
, wrq
->value
);
1493 if (wpa_version
== IW_AUTH_WPA_VERSION_WPA2
) {
1494 if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1495 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
1496 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
1497 } else if (wpa_version
== IW_AUTH_WPA_VERSION_WPA
) {
1498 if (wrq
->value
== 0) {
1499 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
1500 } else if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1501 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
1503 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
1506 case IW_AUTH_TKIP_COUNTERMEASURES
:
1508 case IW_AUTH_DROP_UNENCRYPTED
:
1510 case IW_AUTH_80211_AUTH_ALG
:
1511 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq
->value
);
1512 if (wrq
->value
== IW_AUTH_ALG_OPEN_SYSTEM
)
1513 pMgmt
->bShareKeyAlgorithm
= false;
1514 else if (wrq
->value
== IW_AUTH_ALG_SHARED_KEY
)
1515 pMgmt
->bShareKeyAlgorithm
= true;
1517 case IW_AUTH_WPA_ENABLED
:
1519 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1521 case IW_AUTH_ROAMING_CONTROL
:
1524 case IW_AUTH_PRIVACY_INVOKED
:
1525 pDevice
->bEncryptionEnable
= !!wrq
->value
;
1526 if (pDevice
->bEncryptionEnable
== false) {
1529 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1530 pMgmt
->bShareKeyAlgorithm
= false;
1531 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
1532 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1536 PRINT_K("iwctl_siwauth: not supported %x\n", wrq
->flags
);
1543 int iwctl_giwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1544 union iwreq_data
*wrqu
, char *extra
)
1549 int iwctl_siwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1550 union iwreq_data
*wrqu
, char *extra
)
1552 struct vnt_private
*pDevice
= netdev_priv(dev
);
1553 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1554 struct iw_point
*wrq
= &wrqu
->data
;
1561 if ((wrq
->length
< 2) || (extra
[1] + 2 != wrq
->length
)) {
1565 if (wrq
->length
> MAX_WPA_IE_LEN
) {
1569 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1570 if (copy_from_user(pMgmt
->abyWPAIE
, extra
, wrq
->length
)) {
1574 pMgmt
->wWPAIELen
= wrq
->length
;
1576 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1577 pMgmt
->wWPAIELen
= 0;
1580 out
: // not completely ...not necessary in wpa_supplicant 0.5.8
1584 int iwctl_giwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1585 union iwreq_data
*wrqu
, char *extra
)
1587 struct vnt_private
*pDevice
= netdev_priv(dev
);
1588 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1589 struct iw_point
*wrq
= &wrqu
->data
;
1591 int space
= wrq
->length
;
1597 if (pMgmt
->wWPAIELen
> 0) {
1598 wrq
->length
= pMgmt
->wWPAIELen
;
1599 if (pMgmt
->wWPAIELen
<= space
) {
1600 if (copy_to_user(extra
, pMgmt
->abyWPAIE
, pMgmt
->wWPAIELen
)) {
1610 int iwctl_siwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1611 union iwreq_data
*wrqu
, char *extra
)
1613 struct vnt_private
*pDevice
= netdev_priv(dev
);
1614 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1615 struct iw_point
*wrq
= &wrqu
->encoding
;
1616 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1617 struct viawget_wpa_param
*param
= NULL
;
1623 u8 seq
[IW_ENCODE_SEQ_MAX_SIZE
];
1631 PRINT_K("SIOCSIWENCODEEXT......\n");
1636 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
1639 buf
= kzalloc(sizeof(struct viawget_wpa_param
), GFP_KERNEL
);
1643 param
= (struct viawget_wpa_param
*)buf
;
1647 case IW_ENCODE_ALG_NONE
:
1648 alg_name
= WPA_ALG_NONE
;
1650 case IW_ENCODE_ALG_WEP
:
1651 alg_name
= WPA_ALG_WEP
;
1653 case IW_ENCODE_ALG_TKIP
:
1654 alg_name
= WPA_ALG_TKIP
;
1656 case IW_ENCODE_ALG_CCMP
:
1657 alg_name
= WPA_ALG_CCMP
;
1660 PRINT_K("Unknown alg = %d\n", ext
->alg
);
1665 memcpy(addr
, ext
->addr
.sa_data
, ETH_ALEN
);
1667 key_idx
= (wrq
->flags
&IW_ENCODE_INDEX
) - 1;
1669 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1671 // recover seq,seq_len
1672 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1673 seq_len
= IW_ENCODE_SEQ_MAX_SIZE
;
1674 memcpy(seq
, ext
->rx_seq
, seq_len
);
1676 // recover key,key_len
1678 key_len
= ext
->key_len
;
1679 memcpy(key
, &ext
->key
[0], key_len
);
1681 memset(key_array
, 0, 64);
1683 memcpy(key_array
, key
, key_len
);
1684 if (key_len
== 32) {
1685 // notice ! the oder
1686 memcpy(&key_array
[16], &key
[24], 8);
1687 memcpy(&key_array
[24], &key
[16], 8);
1691 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1692 memcpy(param
->addr
, addr
, ETH_ALEN
);
1693 param
->u
.wpa_key
.alg_name
= (int)alg_name
;
1694 param
->u
.wpa_key
.set_tx
= set_tx
;
1695 param
->u
.wpa_key
.key_index
= key_idx
;
1696 param
->u
.wpa_key
.key_len
= key_len
;
1697 param
->u
.wpa_key
.key
= (u8
*)key_array
;
1698 param
->u
.wpa_key
.seq
= (u8
*)seq
;
1699 param
->u
.wpa_key
.seq_len
= seq_len
;
1701 /****set if current action is Network Manager count?? */
1702 /****this method is so foolish,but there is no other way??? */
1703 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
1704 if (param
->u
.wpa_key
.key_index
== 0) {
1705 pDevice
->bwextstep0
= true;
1707 if ((pDevice
->bwextstep0
== true) && (param
->u
.wpa_key
.key_index
== 1)) {
1708 pDevice
->bwextstep0
= false;
1709 pDevice
->bwextstep1
= true;
1711 if ((pDevice
->bwextstep1
== true) && (param
->u
.wpa_key
.key_index
== 2)) {
1712 pDevice
->bwextstep1
= false;
1713 pDevice
->bwextstep2
= true;
1715 if ((pDevice
->bwextstep2
== true) && (param
->u
.wpa_key
.key_index
== 3)) {
1716 pDevice
->bwextstep2
= false;
1717 pDevice
->bwextstep3
= true;
1720 if (pDevice
->bwextstep3
== true) {
1721 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1722 pDevice
->bwextstep0
= false;
1723 pDevice
->bwextstep1
= false;
1724 pDevice
->bwextstep2
= false;
1725 pDevice
->bwextstep3
= false;
1726 pDevice
->bWPASuppWextEnabled
= true;
1727 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1728 KeyvInitTable(pDevice
, &pDevice
->sKey
);
1731 spin_lock_irq(&pDevice
->lock
);
1732 ret
= wpa_set_keys(pDevice
, param
);
1733 spin_unlock_irq(&pDevice
->lock
);
1740 int iwctl_giwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1741 union iwreq_data
*wrqu
, char *extra
)
1746 int iwctl_siwmlme(struct net_device
*dev
, struct iw_request_info
*info
,
1747 union iwreq_data
*wrqu
, char *extra
)
1749 struct vnt_private
*pDevice
= netdev_priv(dev
);
1750 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1751 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1754 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME\n");
1759 if (memcmp(pMgmt
->abyCurrBSSID
, mlme
->addr
.sa_data
, ETH_ALEN
)) {
1763 switch (mlme
->cmd
) {
1764 case IW_MLME_DEAUTH
:
1765 case IW_MLME_DISASSOC
:
1766 if (pDevice
->bLinkPass
== true) {
1767 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1768 bScheduleCommand((void *)pDevice
, WLAN_CMD_DISASSOCIATE
,
1778 static int iwctl_config_commit(struct net_device
*dev
,
1779 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1781 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"SIOCSIWCOMMIT\n");
1786 static const iw_handler iwctl_handler
[] = {
1787 IW_HANDLER(SIOCSIWCOMMIT
, iwctl_config_commit
),
1788 IW_HANDLER(SIOCGIWNAME
, iwctl_giwname
),
1789 IW_HANDLER(SIOCSIWFREQ
, iwctl_siwfreq
),
1790 IW_HANDLER(SIOCGIWFREQ
, iwctl_giwfreq
),
1791 IW_HANDLER(SIOCSIWMODE
, iwctl_siwmode
),
1792 IW_HANDLER(SIOCGIWMODE
, iwctl_giwmode
),
1793 IW_HANDLER(SIOCGIWSENS
, iwctl_giwsens
),
1794 IW_HANDLER(SIOCGIWRANGE
, iwctl_giwrange
),
1795 IW_HANDLER(SIOCSIWAP
, iwctl_siwap
),
1796 IW_HANDLER(SIOCGIWAP
, iwctl_giwap
),
1797 IW_HANDLER(SIOCSIWMLME
, iwctl_siwmlme
),
1798 IW_HANDLER(SIOCGIWAPLIST
, iwctl_giwaplist
),
1799 IW_HANDLER(SIOCSIWSCAN
, iwctl_siwscan
),
1800 IW_HANDLER(SIOCGIWSCAN
, iwctl_giwscan
),
1801 IW_HANDLER(SIOCSIWESSID
, iwctl_siwessid
),
1802 IW_HANDLER(SIOCGIWESSID
, iwctl_giwessid
),
1803 IW_HANDLER(SIOCSIWRATE
, iwctl_siwrate
),
1804 IW_HANDLER(SIOCGIWRATE
, iwctl_giwrate
),
1805 IW_HANDLER(SIOCSIWRTS
, iwctl_siwrts
),
1806 IW_HANDLER(SIOCGIWRTS
, iwctl_giwrts
),
1807 IW_HANDLER(SIOCSIWFRAG
, iwctl_siwfrag
),
1808 IW_HANDLER(SIOCGIWFRAG
, iwctl_giwfrag
),
1809 IW_HANDLER(SIOCSIWRETRY
, iwctl_siwretry
),
1810 IW_HANDLER(SIOCGIWRETRY
, iwctl_giwretry
),
1811 IW_HANDLER(SIOCSIWENCODE
, iwctl_siwencode
),
1812 IW_HANDLER(SIOCGIWENCODE
, iwctl_giwencode
),
1813 IW_HANDLER(SIOCSIWPOWER
, iwctl_siwpower
),
1814 IW_HANDLER(SIOCGIWPOWER
, iwctl_giwpower
),
1815 IW_HANDLER(SIOCSIWGENIE
, iwctl_siwgenie
),
1816 IW_HANDLER(SIOCGIWGENIE
, iwctl_giwgenie
),
1817 IW_HANDLER(SIOCSIWAUTH
, iwctl_siwauth
),
1818 IW_HANDLER(SIOCGIWAUTH
, iwctl_giwauth
),
1819 IW_HANDLER(SIOCSIWENCODEEXT
, iwctl_siwencodeext
),
1820 IW_HANDLER(SIOCGIWENCODEEXT
, iwctl_giwencodeext
)
1823 static const iw_handler iwctl_private_handler
[] = {
1824 NULL
, // SIOCIWFIRSTPRIV
1827 const struct iw_handler_def iwctl_handler_def
= {
1828 .get_wireless_stats
= &iwctl_get_wireless_stats
,
1829 .num_standard
= ARRAY_SIZE(iwctl_handler
),
1831 .num_private_args
= 0,
1832 .standard
= iwctl_handler
,
1834 .private_args
= NULL
,