2 * Driver for RNDIS based wireless USB devices.
4 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
5 * Copyright (C) 2008 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Portions of this file are based on NDISwrapper project,
22 * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
23 * http://ndiswrapper.sourceforge.net/
26 // #define DEBUG // error path messages, extra info
27 // #define VERBOSE // more; success messages
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/ethtool.h>
34 #include <linux/workqueue.h>
35 #include <linux/mutex.h>
36 #include <linux/mii.h>
37 #include <linux/usb.h>
38 #include <linux/usb/cdc.h>
39 #include <linux/wireless.h>
40 #include <linux/if_arp.h>
41 #include <linux/ctype.h>
42 #include <linux/spinlock.h>
43 #include <net/iw_handler.h>
44 #include <net/ieee80211.h>
45 #include <linux/usb/usbnet.h>
46 #include <linux/usb/rndis_host.h>
49 /* NOTE: All these are settings for Broadcom chipset */
50 static char modparam_country
[4] = "EU";
51 module_param_string(country
, modparam_country
, 4, 0444);
52 MODULE_PARM_DESC(country
, "Country code (ISO 3166-1 alpha-2), default: EU");
54 static int modparam_frameburst
= 1;
55 module_param_named(frameburst
, modparam_frameburst
, int, 0444);
56 MODULE_PARM_DESC(frameburst
, "enable frame bursting (default: on)");
58 static int modparam_afterburner
= 0;
59 module_param_named(afterburner
, modparam_afterburner
, int, 0444);
60 MODULE_PARM_DESC(afterburner
,
61 "enable afterburner aka '125 High Speed Mode' (default: off)");
63 static int modparam_power_save
= 0;
64 module_param_named(power_save
, modparam_power_save
, int, 0444);
65 MODULE_PARM_DESC(power_save
,
66 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
68 static int modparam_power_output
= 3;
69 module_param_named(power_output
, modparam_power_output
, int, 0444);
70 MODULE_PARM_DESC(power_output
,
71 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
73 static int modparam_roamtrigger
= -70;
74 module_param_named(roamtrigger
, modparam_roamtrigger
, int, 0444);
75 MODULE_PARM_DESC(roamtrigger
,
76 "set roaming dBm trigger: -80=optimize for distance, "
77 "-60=bandwidth (default: -70)");
79 static int modparam_roamdelta
= 1;
80 module_param_named(roamdelta
, modparam_roamdelta
, int, 0444);
81 MODULE_PARM_DESC(roamdelta
,
82 "set roaming tendency: 0=aggressive, 1=moderate, "
83 "2=conservative (default: moderate)");
85 static int modparam_workaround_interval
= 500;
86 module_param_named(workaround_interval
, modparam_workaround_interval
,
88 MODULE_PARM_DESC(workaround_interval
,
89 "set stall workaround interval in msecs (default: 500)");
92 /* various RNDIS OID defs */
93 #define OID_GEN_LINK_SPEED ccpu2(0x00010107)
94 #define OID_GEN_RNDIS_CONFIG_PARAMETER ccpu2(0x0001021b)
96 #define OID_GEN_XMIT_OK ccpu2(0x00020101)
97 #define OID_GEN_RCV_OK ccpu2(0x00020102)
98 #define OID_GEN_XMIT_ERROR ccpu2(0x00020103)
99 #define OID_GEN_RCV_ERROR ccpu2(0x00020104)
100 #define OID_GEN_RCV_NO_BUFFER ccpu2(0x00020105)
102 #define OID_802_3_PERMANENT_ADDRESS ccpu2(0x01010101)
103 #define OID_802_3_CURRENT_ADDRESS ccpu2(0x01010102)
104 #define OID_802_3_MULTICAST_LIST ccpu2(0x01010103)
105 #define OID_802_3_MAXIMUM_LIST_SIZE ccpu2(0x01010104)
107 #define OID_802_11_BSSID ccpu2(0x0d010101)
108 #define OID_802_11_SSID ccpu2(0x0d010102)
109 #define OID_802_11_INFRASTRUCTURE_MODE ccpu2(0x0d010108)
110 #define OID_802_11_ADD_WEP ccpu2(0x0d010113)
111 #define OID_802_11_REMOVE_WEP ccpu2(0x0d010114)
112 #define OID_802_11_DISASSOCIATE ccpu2(0x0d010115)
113 #define OID_802_11_AUTHENTICATION_MODE ccpu2(0x0d010118)
114 #define OID_802_11_PRIVACY_FILTER ccpu2(0x0d010119)
115 #define OID_802_11_BSSID_LIST_SCAN ccpu2(0x0d01011a)
116 #define OID_802_11_ENCRYPTION_STATUS ccpu2(0x0d01011b)
117 #define OID_802_11_ADD_KEY ccpu2(0x0d01011d)
118 #define OID_802_11_REMOVE_KEY ccpu2(0x0d01011e)
119 #define OID_802_11_PMKID ccpu2(0x0d010123)
120 #define OID_802_11_NETWORK_TYPES_SUPPORTED ccpu2(0x0d010203)
121 #define OID_802_11_NETWORK_TYPE_IN_USE ccpu2(0x0d010204)
122 #define OID_802_11_TX_POWER_LEVEL ccpu2(0x0d010205)
123 #define OID_802_11_RSSI ccpu2(0x0d010206)
124 #define OID_802_11_RSSI_TRIGGER ccpu2(0x0d010207)
125 #define OID_802_11_FRAGMENTATION_THRESHOLD ccpu2(0x0d010209)
126 #define OID_802_11_RTS_THRESHOLD ccpu2(0x0d01020a)
127 #define OID_802_11_SUPPORTED_RATES ccpu2(0x0d01020e)
128 #define OID_802_11_CONFIGURATION ccpu2(0x0d010211)
129 #define OID_802_11_BSSID_LIST ccpu2(0x0d010217)
132 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
133 #define WL_NOISE -96 /* typical noise level in dBm */
134 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
137 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
138 * based on wireless rndis) has default txpower of 13dBm.
139 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
142 #define BCM4320_DEFAULT_TXPOWER 20
145 /* codes for "status" field of completion messages */
146 #define RNDIS_STATUS_ADAPTER_NOT_READY ccpu2(0xc0010011)
147 #define RNDIS_STATUS_ADAPTER_NOT_OPEN ccpu2(0xc0010012)
150 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
151 * slightly modified for datatype endianess, etc
153 #define NDIS_802_11_LENGTH_SSID 32
154 #define NDIS_802_11_LENGTH_RATES 8
155 #define NDIS_802_11_LENGTH_RATES_EX 16
157 struct NDIS_802_11_SSID
{
159 u8 Ssid
[NDIS_802_11_LENGTH_SSID
];
160 } __attribute__((packed
));
162 enum NDIS_802_11_NETWORK_TYPE
{
167 Ndis802_11NetworkTypeMax
170 struct NDIS_802_11_CONFIGURATION_FH
{
175 } __attribute__((packed
));
177 struct NDIS_802_11_CONFIGURATION
{
182 struct NDIS_802_11_CONFIGURATION_FH FHConfig
;
183 } __attribute__((packed
));
185 enum NDIS_802_11_NETWORK_INFRASTRUCTURE
{
187 Ndis802_11Infrastructure
,
188 Ndis802_11AutoUnknown
,
189 Ndis802_11InfrastructureMax
192 enum NDIS_802_11_AUTHENTICATION_MODE
{
193 Ndis802_11AuthModeOpen
,
194 Ndis802_11AuthModeShared
,
195 Ndis802_11AuthModeAutoSwitch
,
196 Ndis802_11AuthModeWPA
,
197 Ndis802_11AuthModeWPAPSK
,
198 Ndis802_11AuthModeWPANone
,
199 Ndis802_11AuthModeWPA2
,
200 Ndis802_11AuthModeWPA2PSK
,
201 Ndis802_11AuthModeMax
204 enum NDIS_802_11_ENCRYPTION_STATUS
{
205 Ndis802_11WEPEnabled
,
206 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
207 Ndis802_11WEPDisabled
,
208 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
209 Ndis802_11WEPKeyAbsent
,
210 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
211 Ndis802_11WEPNotSupported
,
212 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
213 Ndis802_11Encryption2Enabled
,
214 Ndis802_11Encryption2KeyAbsent
,
215 Ndis802_11Encryption3Enabled
,
216 Ndis802_11Encryption3KeyAbsent
219 enum NDIS_802_11_PRIVACY_FILTER
{
220 Ndis802_11PrivFilterAcceptAll
,
221 Ndis802_11PrivFilter8021xWEP
224 struct NDIS_WLAN_BSSID_EX
{
228 struct NDIS_802_11_SSID Ssid
;
231 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
232 enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse
;
234 __le32 NetworkTypeInUse
;
235 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
236 struct NDIS_802_11_CONFIGURATION Configuration
;
237 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
238 enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode
;
240 __le32 InfrastructureMode
;
241 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
242 u8 SupportedRates
[NDIS_802_11_LENGTH_RATES_EX
];
245 } __attribute__((packed
));
247 struct NDIS_802_11_BSSID_LIST_EX
{
248 __le32 NumberOfItems
;
249 struct NDIS_WLAN_BSSID_EX Bssid
[0];
250 } __attribute__((packed
));
252 struct NDIS_802_11_FIXED_IEs
{
254 __le16 BeaconInterval
;
256 } __attribute__((packed
));
258 struct NDIS_802_11_WEP
{
263 } __attribute__((packed
));
265 struct NDIS_802_11_KEY
{
271 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
275 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
277 } __attribute__((packed
));
279 struct NDIS_802_11_REMOVE_KEY
{
283 } __attribute__((packed
));
285 struct RNDIS_CONFIG_PARAMETER_INFOBUFFER
{
286 __le32 ParameterNameOffset
;
287 __le32 ParameterNameLength
;
288 __le32 ParameterType
;
289 __le32 ParameterValueOffset
;
290 __le32 ParameterValueLength
;
291 } __attribute__((packed
));
293 /* these have to match what is in wpa_supplicant */
294 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
295 enum { WPA_ALG_NONE
, WPA_ALG_WEP
, WPA_ALG_TKIP
, WPA_ALG_CCMP
} wpa_alg
;
296 enum { CIPHER_NONE
, CIPHER_WEP40
, CIPHER_TKIP
, CIPHER_CCMP
, CIPHER_WEP104
}
298 enum { KEY_MGMT_802_1X
, KEY_MGMT_PSK
, KEY_MGMT_NONE
, KEY_MGMT_802_1X_NO_WPA
,
299 KEY_MGMT_WPA_NONE
} wpa_key_mgmt
;
301 enum wpa_alg
{ WPA_ALG_NONE
, WPA_ALG_WEP
, WPA_ALG_TKIP
, WPA_ALG_CCMP
};
302 enum wpa_cipher
{ CIPHER_NONE
, CIPHER_WEP40
, CIPHER_TKIP
, CIPHER_CCMP
,
304 enum wpa_key_mgmt
{ KEY_MGMT_802_1X
, KEY_MGMT_PSK
, KEY_MGMT_NONE
,
305 KEY_MGMT_802_1X_NO_WPA
, KEY_MGMT_WPA_NONE
};
306 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
311 #define NET_TYPE_11FB 0
313 #define CAP_MODE_80211A 1
314 #define CAP_MODE_80211B 2
315 #define CAP_MODE_80211G 4
316 #define CAP_MODE_MASK 7
317 #define CAP_SUPPORT_TXPOWER 8
319 #define WORK_CONNECTION_EVENT (1<<0)
320 #define WORK_SET_MULTICAST_LIST (1<<1)
322 /* RNDIS device private data */
323 struct rndis_wext_private
{
326 struct usbnet
*usbdev
;
328 struct workqueue_struct
*workqueue
;
329 struct delayed_work stats_work
;
330 struct work_struct work
;
331 struct mutex command_lock
;
332 spinlock_t stats_lock
;
333 unsigned long work_pending
;
335 struct iw_statistics iwstats
;
336 struct iw_statistics privstats
;
344 /* module parameters */
345 char param_country
[4];
346 int param_frameburst
;
347 int param_afterburner
;
348 int param_power_save
;
349 int param_power_output
;
350 int param_roamtrigger
;
352 u32 param_workaround_interval
;
357 struct NDIS_802_11_SSID essid
;
359 /* encryption stuff */
360 int encr_tx_key_index
;
361 char encr_keys
[4][32];
369 int wpa_cipher_group
;
373 static const int freq_chan
[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
374 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
376 static const int rates_80211g
[8] = { 6, 9, 12, 18, 24, 36, 48, 54 };
378 static const int bcm4320_power_output
[4] = { 25, 50, 75, 100 };
380 static const unsigned char zero_bssid
[ETH_ALEN
] = {0,};
381 static const unsigned char ffff_bssid
[ETH_ALEN
] = { 0xff, 0xff, 0xff,
385 static struct rndis_wext_private
*get_rndis_wext_priv(struct usbnet
*dev
)
387 return (struct rndis_wext_private
*)dev
->driver_priv
;
391 static u32
get_bcm4320_power(struct rndis_wext_private
*priv
)
393 return BCM4320_DEFAULT_TXPOWER
*
394 bcm4320_power_output
[priv
->param_power_output
] / 100;
398 /* translate error code */
399 static int rndis_error_status(__le32 rndis_status
)
402 switch (rndis_status
) {
403 case RNDIS_STATUS_SUCCESS
:
406 case RNDIS_STATUS_FAILURE
:
407 case RNDIS_STATUS_INVALID_DATA
:
410 case RNDIS_STATUS_NOT_SUPPORTED
:
413 case RNDIS_STATUS_ADAPTER_NOT_READY
:
414 case RNDIS_STATUS_ADAPTER_NOT_OPEN
:
422 static int rndis_query_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int *len
)
424 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
427 struct rndis_msg_hdr
*header
;
428 struct rndis_query
*get
;
429 struct rndis_query_c
*get_c
;
433 buflen
= *len
+ sizeof(*u
.get
);
434 if (buflen
< CONTROL_BUFFER_SIZE
)
435 buflen
= CONTROL_BUFFER_SIZE
;
436 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
439 memset(u
.get
, 0, sizeof *u
.get
);
440 u
.get
->msg_type
= RNDIS_MSG_QUERY
;
441 u
.get
->msg_len
= ccpu2(sizeof *u
.get
);
444 mutex_lock(&priv
->command_lock
);
445 ret
= rndis_command(dev
, u
.header
);
446 mutex_unlock(&priv
->command_lock
);
449 ret
= le32_to_cpu(u
.get_c
->len
);
450 *len
= (*len
> ret
) ? ret
: *len
;
451 memcpy(data
, u
.buf
+ le32_to_cpu(u
.get_c
->offset
) + 8, *len
);
452 ret
= rndis_error_status(u
.get_c
->status
);
460 static int rndis_set_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int len
)
462 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
465 struct rndis_msg_hdr
*header
;
466 struct rndis_set
*set
;
467 struct rndis_set_c
*set_c
;
471 buflen
= len
+ sizeof(*u
.set
);
472 if (buflen
< CONTROL_BUFFER_SIZE
)
473 buflen
= CONTROL_BUFFER_SIZE
;
474 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
478 memset(u
.set
, 0, sizeof *u
.set
);
479 u
.set
->msg_type
= RNDIS_MSG_SET
;
480 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
482 u
.set
->len
= cpu_to_le32(len
);
483 u
.set
->offset
= ccpu2(sizeof(*u
.set
) - 8);
484 u
.set
->handle
= ccpu2(0);
485 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
487 mutex_lock(&priv
->command_lock
);
488 ret
= rndis_command(dev
, u
.header
);
489 mutex_unlock(&priv
->command_lock
);
492 ret
= rndis_error_status(u
.set_c
->status
);
500 * Specs say that we can only set config parameters only soon after device
502 * value_type: 0 = u32, 2 = unicode string
504 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
505 int value_type
, void *value
)
507 struct RNDIS_CONFIG_PARAMETER_INFOBUFFER
*infobuf
;
508 int value_len
, info_len
, param_len
, ret
, i
;
513 value_len
= sizeof(__le32
);
514 else if (value_type
== 2)
515 value_len
= strlen(value
) * sizeof(__le16
);
519 param_len
= strlen(param
) * sizeof(__le16
);
520 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
525 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
531 /* extra 12 bytes are for padding (debug output) */
532 memset(infobuf
, 0xCC, info_len
+ 12);
536 devdbg(dev
, "setting config parameter: %s, value: %s",
539 devdbg(dev
, "setting config parameter: %s, value: %d",
540 param
, *(u32
*)value
);
542 infobuf
->ParameterNameOffset
= cpu_to_le32(sizeof(*infobuf
));
543 infobuf
->ParameterNameLength
= cpu_to_le32(param_len
);
544 infobuf
->ParameterType
= cpu_to_le32(value_type
);
545 infobuf
->ParameterValueOffset
= cpu_to_le32(sizeof(*infobuf
) +
547 infobuf
->ParameterValueLength
= cpu_to_le32(value_len
);
549 /* simple string to unicode string conversion */
550 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
551 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
552 unibuf
[i
] = cpu_to_le16(param
[i
]);
554 if (value_type
== 2) {
555 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
556 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
557 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
559 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
560 *dst_value
= cpu_to_le32(*(u32
*)value
);
564 devdbg(dev
, "info buffer (len: %d):", info_len
);
565 for (i
= 0; i
< info_len
; i
+= 12) {
566 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
567 devdbg(dev
, "%08X:%08X:%08X",
570 cpu_to_be32(tmp
[2]));
574 ret
= rndis_set_oid(dev
, OID_GEN_RNDIS_CONFIG_PARAMETER
,
577 devdbg(dev
, "setting rndis config paramater failed, %d.", ret
);
583 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
584 char *param
, char *value
)
586 return(rndis_set_config_parameter(dev
, param
, 2, value
));
589 /*static int rndis_set_config_parameter_u32(struct usbnet *dev,
590 char *param, u32 value)
592 return(rndis_set_config_parameter(dev, param, 0, &value));
597 * data conversion functions
599 static int level_to_qual(int level
)
601 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
602 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
606 static void dsconfig_to_freq(unsigned int dsconfig
, struct iw_freq
*freq
)
612 /* see comment in wireless.h above the "struct iw_freq"
613 * definition for an explanation of this if
614 * NOTE: 1000000 is due to the kHz
616 if (dsconfig
> 1000000) {
617 freq
->m
= dsconfig
/ 10;
622 /* convert from kHz to Hz */
627 static int freq_to_dsconfig(struct iw_freq
*freq
, unsigned int *dsconfig
)
629 if (freq
->m
< 1000 && freq
->e
== 0) {
631 freq
->m
<= (sizeof(freq_chan
) / sizeof(freq_chan
[0])))
632 *dsconfig
= freq_chan
[freq
->m
- 1] * 1000;
638 for (i
= freq
->e
; i
> 0; i
--)
651 add_wep_key(struct usbnet
*usbdev
, char *key
, int key_len
, int index
);
653 static int get_essid(struct usbnet
*usbdev
, struct NDIS_802_11_SSID
*ssid
)
658 ret
= rndis_query_oid(usbdev
, OID_802_11_SSID
, ssid
, &len
);
661 ssid
->SsidLength
= 0;
665 unsigned char tmp
[NDIS_802_11_LENGTH_SSID
+ 1];
667 memcpy(tmp
, ssid
->Ssid
, le32_to_cpu(ssid
->SsidLength
));
668 tmp
[le32_to_cpu(ssid
->SsidLength
)] = 0;
669 devdbg(usbdev
, "get_essid: '%s', ret: %d", tmp
, ret
);
676 static int set_essid(struct usbnet
*usbdev
, struct NDIS_802_11_SSID
*ssid
)
678 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
681 ret
= rndis_set_oid(usbdev
, OID_802_11_SSID
, ssid
, sizeof(*ssid
));
683 memcpy(&priv
->essid
, ssid
, sizeof(priv
->essid
));
685 devdbg(usbdev
, "set_essid: radio_on = 1");
692 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
697 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID
, bssid
, &len
);
700 memset(bssid
, 0, ETH_ALEN
);
706 static int is_associated(struct usbnet
*usbdev
)
711 ret
= get_bssid(usbdev
, bssid
);
713 return(ret
== 0 && memcmp(bssid
, zero_bssid
, ETH_ALEN
) != 0);
717 static int disassociate(struct usbnet
*usbdev
, int reset_ssid
)
719 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
720 struct NDIS_802_11_SSID ssid
;
723 if (priv
->radio_on
) {
724 ret
= rndis_set_oid(usbdev
, OID_802_11_DISASSOCIATE
, NULL
, 0);
727 devdbg(usbdev
, "disassociate: radio_on = 0");
734 /* disassociate causes radio to be turned off; if reset_ssid
735 * is given, set random ssid to enable radio */
737 ssid
.SsidLength
= cpu_to_le32(sizeof(ssid
.Ssid
));
738 get_random_bytes(&ssid
.Ssid
[2], sizeof(ssid
.Ssid
)-2);
741 for (i
= 2; i
< sizeof(ssid
.Ssid
); i
++)
742 ssid
.Ssid
[i
] = 0x1 + (ssid
.Ssid
[i
] * 0xfe / 0xff);
743 ret
= set_essid(usbdev
, &ssid
);
749 static int set_auth_mode(struct usbnet
*usbdev
, int wpa_version
, int authalg
)
751 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
755 devdbg(usbdev
, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
756 "keymgmt=0x%x", wpa_version
, authalg
, priv
->wpa_keymgmt
);
758 if (wpa_version
& IW_AUTH_WPA_VERSION_WPA2
) {
759 if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_802_1X
)
760 auth_mode
= Ndis802_11AuthModeWPA2
;
762 auth_mode
= Ndis802_11AuthModeWPA2PSK
;
763 } else if (wpa_version
& IW_AUTH_WPA_VERSION_WPA
) {
764 if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_802_1X
)
765 auth_mode
= Ndis802_11AuthModeWPA
;
766 else if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_PSK
)
767 auth_mode
= Ndis802_11AuthModeWPAPSK
;
769 auth_mode
= Ndis802_11AuthModeWPANone
;
770 } else if (authalg
& IW_AUTH_ALG_SHARED_KEY
) {
771 if (authalg
& IW_AUTH_ALG_OPEN_SYSTEM
)
772 auth_mode
= Ndis802_11AuthModeAutoSwitch
;
774 auth_mode
= Ndis802_11AuthModeShared
;
776 auth_mode
= Ndis802_11AuthModeOpen
;
778 tmp
= cpu_to_le32(auth_mode
);
779 ret
= rndis_set_oid(usbdev
, OID_802_11_AUTHENTICATION_MODE
, &tmp
,
782 devwarn(usbdev
, "setting auth mode failed (%08X)", ret
);
786 priv
->wpa_version
= wpa_version
;
787 priv
->wpa_authalg
= authalg
;
792 static int set_priv_filter(struct usbnet
*usbdev
)
794 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
797 devdbg(usbdev
, "set_priv_filter: wpa_version=0x%x", priv
->wpa_version
);
799 if (priv
->wpa_version
& IW_AUTH_WPA_VERSION_WPA2
||
800 priv
->wpa_version
& IW_AUTH_WPA_VERSION_WPA
)
801 tmp
= cpu_to_le32(Ndis802_11PrivFilter8021xWEP
);
803 tmp
= cpu_to_le32(Ndis802_11PrivFilterAcceptAll
);
805 return rndis_set_oid(usbdev
, OID_802_11_PRIVACY_FILTER
, &tmp
,
810 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
812 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
816 devdbg(usbdev
, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
820 if (pairwise
& IW_AUTH_CIPHER_CCMP
)
821 encr_mode
= Ndis802_11Encryption3Enabled
;
822 else if (pairwise
& IW_AUTH_CIPHER_TKIP
)
823 encr_mode
= Ndis802_11Encryption2Enabled
;
825 (IW_AUTH_CIPHER_WEP40
| IW_AUTH_CIPHER_WEP104
))
826 encr_mode
= Ndis802_11Encryption1Enabled
;
827 else if (groupwise
& IW_AUTH_CIPHER_CCMP
)
828 encr_mode
= Ndis802_11Encryption3Enabled
;
829 else if (groupwise
& IW_AUTH_CIPHER_TKIP
)
830 encr_mode
= Ndis802_11Encryption2Enabled
;
832 encr_mode
= Ndis802_11EncryptionDisabled
;
834 tmp
= cpu_to_le32(encr_mode
);
835 ret
= rndis_set_oid(usbdev
, OID_802_11_ENCRYPTION_STATUS
, &tmp
,
838 devwarn(usbdev
, "setting encr mode failed (%08X)", ret
);
842 priv
->wpa_cipher_pair
= pairwise
;
843 priv
->wpa_cipher_group
= groupwise
;
848 static int set_assoc_params(struct usbnet
*usbdev
)
850 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
852 set_auth_mode(usbdev
, priv
->wpa_version
, priv
->wpa_authalg
);
853 set_priv_filter(usbdev
);
854 set_encr_mode(usbdev
, priv
->wpa_cipher_pair
, priv
->wpa_cipher_group
);
860 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
862 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
866 devdbg(usbdev
, "set_infra_mode: infra_mode=0x%x", priv
->infra_mode
);
868 tmp
= cpu_to_le32(mode
);
869 ret
= rndis_set_oid(usbdev
, OID_802_11_INFRASTRUCTURE_MODE
, &tmp
,
872 devwarn(usbdev
, "setting infra mode failed (%08X)", ret
);
876 /* NDIS drivers clear keys when infrastructure mode is
877 * changed. But Linux tools assume otherwise. So set the
879 if (priv
->wpa_keymgmt
== 0 ||
880 priv
->wpa_keymgmt
== IW_AUTH_KEY_MGMT_802_1X
) {
881 for (i
= 0; i
< 4; i
++) {
882 if (priv
->encr_key_len
[i
] > 0)
883 add_wep_key(usbdev
, priv
->encr_keys
[i
],
884 priv
->encr_key_len
[i
], i
);
888 priv
->infra_mode
= mode
;
893 static void set_default_iw_params(struct usbnet
*usbdev
)
895 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
897 priv
->wpa_keymgmt
= 0;
898 priv
->wpa_version
= 0;
900 set_infra_mode(usbdev
, Ndis802_11Infrastructure
);
901 set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
902 IW_AUTH_ALG_OPEN_SYSTEM
);
903 set_priv_filter(usbdev
);
904 set_encr_mode(usbdev
, IW_AUTH_CIPHER_NONE
, IW_AUTH_CIPHER_NONE
);
908 static int deauthenticate(struct usbnet
*usbdev
)
912 ret
= disassociate(usbdev
, 1);
913 set_default_iw_params(usbdev
);
918 /* index must be 0 - N, as per NDIS */
919 static int add_wep_key(struct usbnet
*usbdev
, char *key
, int key_len
, int index
)
921 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
922 struct NDIS_802_11_WEP ndis_key
;
925 if (key_len
<= 0 || key_len
> 32 || index
< 0 || index
>= 4)
928 memset(&ndis_key
, 0, sizeof(ndis_key
));
930 ndis_key
.Length
= cpu_to_le32(sizeof(ndis_key
));
931 ndis_key
.KeyLength
= cpu_to_le32(key_len
);
932 ndis_key
.KeyIndex
= cpu_to_le32(index
);
933 memcpy(&ndis_key
.KeyMaterial
, key
, key_len
);
935 if (index
== priv
->encr_tx_key_index
) {
936 ndis_key
.KeyIndex
|= cpu_to_le32(1 << 31);
937 ret
= set_encr_mode(usbdev
, IW_AUTH_CIPHER_WEP104
,
938 IW_AUTH_CIPHER_NONE
);
940 devwarn(usbdev
, "encryption couldn't be enabled (%08X)",
944 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_WEP
, &ndis_key
,
947 devwarn(usbdev
, "adding encryption key %d failed (%08X)",
952 priv
->encr_key_len
[index
] = key_len
;
953 memcpy(&priv
->encr_keys
[index
], key
, key_len
);
959 /* remove_key is for both wep and wpa */
960 static int remove_key(struct usbnet
*usbdev
, int index
, u8 bssid
[ETH_ALEN
])
962 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
963 struct NDIS_802_11_REMOVE_KEY remove_key
;
967 if (priv
->encr_key_len
[index
] == 0)
970 priv
->encr_key_len
[index
] = 0;
971 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
973 if (priv
->wpa_cipher_pair
== IW_AUTH_CIPHER_TKIP
||
974 priv
->wpa_cipher_pair
== IW_AUTH_CIPHER_CCMP
||
975 priv
->wpa_cipher_group
== IW_AUTH_CIPHER_TKIP
||
976 priv
->wpa_cipher_group
== IW_AUTH_CIPHER_CCMP
) {
977 remove_key
.Length
= cpu_to_le32(sizeof(remove_key
));
978 remove_key
.KeyIndex
= cpu_to_le32(index
);
981 if (memcmp(bssid
, ffff_bssid
, ETH_ALEN
) != 0)
982 remove_key
.KeyIndex
|= cpu_to_le32(1 << 30);
983 memcpy(remove_key
.Bssid
, bssid
,
984 sizeof(remove_key
.Bssid
));
986 memset(remove_key
.Bssid
, 0xff,
987 sizeof(remove_key
.Bssid
));
989 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_KEY
, &remove_key
,
994 keyindex
= cpu_to_le32(index
);
995 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_WEP
, &keyindex
,
999 "removing encryption key %d failed (%08X)",
1005 /* if it is transmit key, disable encryption */
1006 if (index
== priv
->encr_tx_key_index
)
1007 set_encr_mode(usbdev
, IW_AUTH_CIPHER_NONE
, IW_AUTH_CIPHER_NONE
);
1013 static void set_multicast_list(struct usbnet
*usbdev
)
1015 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1016 struct dev_mc_list
*mclist
;
1021 filter
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
1023 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1024 filter
|= RNDIS_PACKET_TYPE_PROMISCUOUS
|
1025 RNDIS_PACKET_TYPE_ALL_LOCAL
;
1026 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
||
1027 usbdev
->net
->mc_count
> priv
->multicast_size
) {
1028 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1029 } else if (usbdev
->net
->mc_count
> 0) {
1030 size
= min(priv
->multicast_size
, usbdev
->net
->mc_count
);
1031 buf
= kmalloc(size
* ETH_ALEN
, GFP_KERNEL
);
1034 "couldn't alloc %d bytes of memory",
1039 mclist
= usbdev
->net
->mc_list
;
1040 for (i
= 0; i
< size
&& mclist
; mclist
= mclist
->next
) {
1041 if (mclist
->dmi_addrlen
!= ETH_ALEN
)
1044 memcpy(buf
+ i
* ETH_ALEN
, mclist
->dmi_addr
, ETH_ALEN
);
1048 ret
= rndis_set_oid(usbdev
, OID_802_3_MULTICAST_LIST
, buf
,
1050 if (ret
== 0 && i
> 0)
1051 filter
|= RNDIS_PACKET_TYPE_MULTICAST
;
1053 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1055 devdbg(usbdev
, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1056 i
, priv
->multicast_size
, ret
);
1061 ret
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1064 devwarn(usbdev
, "couldn't set packet filter: %08x",
1065 le32_to_cpu(filter
));
1068 devdbg(usbdev
, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1069 le32_to_cpu(filter
), ret
);
1074 * wireless extension handlers
1077 static int rndis_iw_commit(struct net_device
*dev
,
1078 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1085 static int rndis_iw_get_range(struct net_device
*dev
,
1086 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1088 struct iw_range
*range
= (struct iw_range
*)extra
;
1089 struct usbnet
*usbdev
= dev
->priv
;
1090 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1091 int len
, ret
, i
, j
, num
, has_80211g_rates
;
1095 devdbg(usbdev
, "SIOCGIWRANGE");
1097 /* clear iw_range struct */
1098 memset(range
, 0, sizeof(*range
));
1099 wrqu
->data
.length
= sizeof(*range
);
1101 range
->txpower_capa
= IW_TXPOW_MWATT
;
1102 range
->num_txpower
= 1;
1103 if (priv
->caps
& CAP_SUPPORT_TXPOWER
) {
1104 len
= sizeof(tx_power
);
1105 ret
= rndis_query_oid(usbdev
, OID_802_11_TX_POWER_LEVEL
,
1107 if (ret
== 0 && le32_to_cpu(tx_power
) != 0xFF)
1108 range
->txpower
[0] = le32_to_cpu(tx_power
);
1110 range
->txpower
[0] = get_bcm4320_power(priv
);
1112 range
->txpower
[0] = get_bcm4320_power(priv
);
1114 len
= sizeof(rates
);
1115 ret
= rndis_query_oid(usbdev
, OID_802_11_SUPPORTED_RATES
, &rates
,
1117 has_80211g_rates
= 0;
1120 for (i
= 0; i
< len
; i
++) {
1123 range
->bitrate
[j
] = (rates
[i
] & 0x7f) * 500000;
1124 /* check for non 802.11b rates */
1125 if (range
->bitrate
[j
] == 6000000 ||
1126 range
->bitrate
[j
] == 9000000 ||
1127 (range
->bitrate
[j
] >= 12000000 &&
1128 range
->bitrate
[j
] != 22000000))
1129 has_80211g_rates
= 1;
1132 range
->num_bitrates
= j
;
1134 range
->num_bitrates
= 0;
1136 /* fill in 802.11g rates */
1137 if (has_80211g_rates
) {
1138 num
= range
->num_bitrates
;
1139 for (i
= 0; i
< sizeof(rates_80211g
); i
++) {
1140 for (j
= 0; j
< num
; j
++) {
1141 if (range
->bitrate
[j
] ==
1142 rates_80211g
[i
] * 1000000)
1146 range
->bitrate
[range
->num_bitrates
++] =
1147 rates_80211g
[i
] * 1000000;
1148 if (range
->num_bitrates
== IW_MAX_BITRATES
)
1152 /* estimated max real througput in bps */
1153 range
->throughput
= 54 * 1000 * 1000 / 2;
1155 /* ~35% more with afterburner */
1156 if (priv
->param_afterburner
)
1157 range
->throughput
= range
->throughput
/ 100 * 135;
1159 /* estimated max real througput in bps */
1160 range
->throughput
= 11 * 1000 * 1000 / 2;
1163 range
->num_channels
= (sizeof(freq_chan
)/sizeof(freq_chan
[0]));
1165 for (i
= 0; i
< (sizeof(freq_chan
)/sizeof(freq_chan
[0])) &&
1166 i
< IW_MAX_FREQUENCIES
; i
++) {
1167 range
->freq
[i
].i
= i
+ 1;
1168 range
->freq
[i
].m
= freq_chan
[i
] * 100000;
1169 range
->freq
[i
].e
= 1;
1171 range
->num_frequency
= i
;
1174 range
->max_rts
= 2347;
1175 range
->min_frag
= 256;
1176 range
->max_frag
= 2346;
1178 range
->max_qual
.qual
= 100;
1179 range
->max_qual
.level
= 154;
1180 range
->max_qual
.updated
= IW_QUAL_QUAL_UPDATED
1181 | IW_QUAL_LEVEL_UPDATED
1182 | IW_QUAL_NOISE_INVALID
;
1184 range
->we_version_compiled
= WIRELESS_EXT
;
1185 range
->we_version_source
= WIRELESS_EXT
;
1187 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
1188 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
1193 static int rndis_iw_get_name(struct net_device
*dev
,
1194 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1196 struct usbnet
*usbdev
= dev
->priv
;
1197 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1199 strcpy(wrqu
->name
, priv
->name
);
1204 static int rndis_iw_set_essid(struct net_device
*dev
,
1205 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *essid
)
1207 struct NDIS_802_11_SSID ssid
;
1208 int length
= wrqu
->essid
.length
;
1209 struct usbnet
*usbdev
= dev
->priv
;
1211 devdbg(usbdev
, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1212 wrqu
->essid
.flags
, wrqu
->essid
.length
, essid
);
1214 if (length
> NDIS_802_11_LENGTH_SSID
)
1215 length
= NDIS_802_11_LENGTH_SSID
;
1217 ssid
.SsidLength
= cpu_to_le32(length
);
1219 memcpy(ssid
.Ssid
, essid
, length
);
1221 memset(ssid
.Ssid
, 0, NDIS_802_11_LENGTH_SSID
);
1223 set_assoc_params(usbdev
);
1225 if (!wrqu
->essid
.flags
|| length
== 0)
1226 return disassociate(usbdev
, 1);
1228 return set_essid(usbdev
, &ssid
);
1232 static int rndis_iw_get_essid(struct net_device
*dev
,
1233 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *essid
)
1235 struct NDIS_802_11_SSID ssid
;
1236 struct usbnet
*usbdev
= dev
->priv
;
1239 ret
= get_essid(usbdev
, &ssid
);
1241 if (ret
== 0 && le32_to_cpu(ssid
.SsidLength
) > 0) {
1242 wrqu
->essid
.flags
= 1;
1243 wrqu
->essid
.length
= le32_to_cpu(ssid
.SsidLength
);
1244 memcpy(essid
, ssid
.Ssid
, wrqu
->essid
.length
);
1245 essid
[wrqu
->essid
.length
] = 0;
1247 memset(essid
, 0, sizeof(NDIS_802_11_LENGTH_SSID
));
1248 wrqu
->essid
.flags
= 0;
1249 wrqu
->essid
.length
= 0;
1251 devdbg(usbdev
, "SIOCGIWESSID: %s", essid
);
1256 static int rndis_iw_get_bssid(struct net_device
*dev
,
1257 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1259 struct usbnet
*usbdev
= dev
->priv
;
1260 unsigned char bssid
[ETH_ALEN
];
1262 DECLARE_MAC_BUF(mac
);
1264 ret
= get_bssid(usbdev
, bssid
);
1267 devdbg(usbdev
, "SIOCGIWAP: %s", print_mac(mac
, bssid
));
1269 devdbg(usbdev
, "SIOCGIWAP: <not associated>");
1271 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1272 memcpy(wrqu
->ap_addr
.sa_data
, bssid
, ETH_ALEN
);
1278 static int rndis_iw_set_bssid(struct net_device
*dev
,
1279 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1281 struct usbnet
*usbdev
= dev
->priv
;
1282 u8
*bssid
= (u8
*)wrqu
->ap_addr
.sa_data
;
1283 DECLARE_MAC_BUF(mac
);
1286 devdbg(usbdev
, "SIOCSIWAP: %s", print_mac(mac
, bssid
));
1288 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID
, bssid
, ETH_ALEN
);
1290 /* user apps may set ap's mac address, which is not required;
1291 * they may fail to work if this function fails, so return
1294 devwarn(usbdev
, "setting AP mac address failed (%08X)", ret
);
1300 static int rndis_iw_set_auth(struct net_device
*dev
,
1301 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1303 struct iw_param
*p
= &wrqu
->param
;
1304 struct usbnet
*usbdev
= dev
->priv
;
1305 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1306 int ret
= -ENOTSUPP
;
1308 switch (p
->flags
& IW_AUTH_INDEX
) {
1309 case IW_AUTH_WPA_VERSION
:
1310 devdbg(usbdev
, "SIOCSIWAUTH: WPA_VERSION, %08x", p
->value
);
1311 priv
->wpa_version
= p
->value
;
1315 case IW_AUTH_CIPHER_PAIRWISE
:
1316 devdbg(usbdev
, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p
->value
);
1317 priv
->wpa_cipher_pair
= p
->value
;
1321 case IW_AUTH_CIPHER_GROUP
:
1322 devdbg(usbdev
, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p
->value
);
1323 priv
->wpa_cipher_group
= p
->value
;
1327 case IW_AUTH_KEY_MGMT
:
1328 devdbg(usbdev
, "SIOCSIWAUTH: KEY_MGMT, %08x", p
->value
);
1329 priv
->wpa_keymgmt
= p
->value
;
1333 case IW_AUTH_TKIP_COUNTERMEASURES
:
1334 devdbg(usbdev
, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1339 case IW_AUTH_DROP_UNENCRYPTED
:
1340 devdbg(usbdev
, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p
->value
);
1344 case IW_AUTH_80211_AUTH_ALG
:
1345 devdbg(usbdev
, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p
->value
);
1346 priv
->wpa_authalg
= p
->value
;
1350 case IW_AUTH_WPA_ENABLED
:
1351 devdbg(usbdev
, "SIOCSIWAUTH: WPA_ENABLED, %08x", p
->value
);
1352 if (wrqu
->param
.value
)
1353 deauthenticate(usbdev
);
1357 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1358 devdbg(usbdev
, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1363 case IW_AUTH_ROAMING_CONTROL
:
1364 devdbg(usbdev
, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p
->value
);
1368 case IW_AUTH_PRIVACY_INVOKED
:
1369 devdbg(usbdev
, "SIOCSIWAUTH: invalid cmd %d",
1370 wrqu
->param
.flags
& IW_AUTH_INDEX
);
1374 devdbg(usbdev
, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1375 p
->flags
& IW_AUTH_INDEX
, p
->value
);
1381 static int rndis_iw_get_auth(struct net_device
*dev
,
1382 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1384 struct iw_param
*p
= &wrqu
->param
;
1385 struct usbnet
*usbdev
= dev
->priv
;
1386 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1388 switch (p
->flags
& IW_AUTH_INDEX
) {
1389 case IW_AUTH_WPA_VERSION
:
1390 p
->value
= priv
->wpa_version
;
1392 case IW_AUTH_CIPHER_PAIRWISE
:
1393 p
->value
= priv
->wpa_cipher_pair
;
1395 case IW_AUTH_CIPHER_GROUP
:
1396 p
->value
= priv
->wpa_cipher_group
;
1398 case IW_AUTH_KEY_MGMT
:
1399 p
->value
= priv
->wpa_keymgmt
;
1401 case IW_AUTH_80211_AUTH_ALG
:
1402 p
->value
= priv
->wpa_authalg
;
1405 devdbg(usbdev
, "SIOCGIWAUTH: invalid cmd %d",
1406 wrqu
->param
.flags
& IW_AUTH_INDEX
);
1413 static int rndis_iw_get_mode(struct net_device
*dev
,
1414 struct iw_request_info
*info
,
1415 union iwreq_data
*wrqu
, char *extra
)
1417 struct usbnet
*usbdev
= dev
->priv
;
1418 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1420 switch (priv
->infra_mode
) {
1421 case Ndis802_11IBSS
:
1422 wrqu
->mode
= IW_MODE_ADHOC
;
1424 case Ndis802_11Infrastructure
:
1425 wrqu
->mode
= IW_MODE_INFRA
;
1427 /*case Ndis802_11AutoUnknown:*/
1429 wrqu
->mode
= IW_MODE_AUTO
;
1432 devdbg(usbdev
, "SIOCGIWMODE: %08x", wrqu
->mode
);
1437 static int rndis_iw_set_mode(struct net_device
*dev
,
1438 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1440 struct usbnet
*usbdev
= dev
->priv
;
1443 devdbg(usbdev
, "SIOCSIWMODE: %08x", wrqu
->mode
);
1445 switch (wrqu
->mode
) {
1447 mode
= Ndis802_11IBSS
;
1450 mode
= Ndis802_11Infrastructure
;
1452 /*case IW_MODE_AUTO:*/
1454 mode
= Ndis802_11AutoUnknown
;
1458 return set_infra_mode(usbdev
, mode
);
1462 static int rndis_iw_set_encode(struct net_device
*dev
,
1463 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1465 struct usbnet
*usbdev
= dev
->priv
;
1466 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1467 int ret
, index
, key_len
;
1470 index
= (wrqu
->encoding
.flags
& IW_ENCODE_INDEX
);
1472 /* iwconfig gives index as 1 - N */
1476 index
= priv
->encr_tx_key_index
;
1478 if (index
< 0 || index
>= 4) {
1479 devwarn(usbdev
, "encryption index out of range (%u)", index
);
1483 /* remove key if disabled */
1484 if (wrqu
->data
.flags
& IW_ENCODE_DISABLED
) {
1485 if (remove_key(usbdev
, index
, NULL
))
1491 /* global encryption state (for all keys) */
1492 if (wrqu
->data
.flags
& IW_ENCODE_OPEN
)
1493 ret
= set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
1494 IW_AUTH_ALG_OPEN_SYSTEM
);
1495 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1496 ret
= set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
1497 IW_AUTH_ALG_SHARED_KEY
);
1501 if (wrqu
->data
.length
> 0) {
1502 key_len
= wrqu
->data
.length
;
1505 /* must be set as tx key */
1506 if (priv
->encr_key_len
[index
] == 0)
1508 key_len
= priv
->encr_key_len
[index
];
1509 key
= priv
->encr_keys
[index
];
1510 priv
->encr_tx_key_index
= index
;
1513 if (add_wep_key(usbdev
, key
, key_len
, index
) != 0)
1516 if (index
== priv
->encr_tx_key_index
)
1517 /* ndis drivers want essid to be set after setting encr */
1518 set_essid(usbdev
, &priv
->essid
);
1524 static int rndis_iw_set_encode_ext(struct net_device
*dev
,
1525 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1527 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1528 struct usbnet
*usbdev
= dev
->priv
;
1529 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1530 struct NDIS_802_11_KEY ndis_key
;
1531 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
1535 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
1538 keyidx
= wrqu
->encoding
.flags
& IW_ENCODE_INDEX
;
1540 /* iwconfig gives index as 1 - N */
1544 keyidx
= priv
->encr_tx_key_index
;
1546 if (keyidx
< 0 || keyidx
>= 4)
1549 if (ext
->alg
== WPA_ALG_WEP
) {
1550 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1551 priv
->encr_tx_key_index
= keyidx
;
1552 return add_wep_key(usbdev
, ext
->key
, ext
->key_len
, keyidx
);
1555 if ((wrqu
->encoding
.flags
& IW_ENCODE_DISABLED
) ||
1556 ext
->alg
== IW_ENCODE_ALG_NONE
|| ext
->key_len
== 0)
1557 return remove_key(usbdev
, keyidx
, NULL
);
1559 if (ext
->key_len
> sizeof(ndis_key
.KeyMaterial
))
1562 memset(&ndis_key
, 0, sizeof(ndis_key
));
1564 ndis_key
.Length
= cpu_to_le32(sizeof(ndis_key
) -
1565 sizeof(ndis_key
.KeyMaterial
) + ext
->key_len
);
1566 ndis_key
.KeyLength
= cpu_to_le32(ext
->key_len
);
1567 ndis_key
.KeyIndex
= cpu_to_le32(keyidx
);
1569 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1570 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
1571 for (i
= 0; i
< 6; i
++)
1573 cpu_to_le64(ext
->rx_seq
[i
] << (i
* 8));
1575 memcpy(ndis_key
.KeyRSC
, ext
->rx_seq
, 6);
1576 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
1577 ndis_key
.KeyIndex
|= cpu_to_le32(1 << 29);
1580 addr
= ext
->addr
.sa_data
;
1581 if (ext
->ext_flags
& IW_ENCODE_EXT_GROUP_KEY
) {
1583 if (priv
->infra_mode
== Ndis802_11IBSS
)
1584 memset(ndis_key
.Bssid
, 0xff, ETH_ALEN
);
1586 get_bssid(usbdev
, ndis_key
.Bssid
);
1589 ndis_key
.KeyIndex
|= cpu_to_le32(1 << 30);
1590 memcpy(ndis_key
.Bssid
, addr
, ETH_ALEN
);
1593 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1594 ndis_key
.KeyIndex
|= cpu_to_le32(1 << 31);
1596 if (ext
->alg
== IW_ENCODE_ALG_TKIP
&& ext
->key_len
== 32) {
1597 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1598 * different order than NDIS spec, so swap the order here. */
1599 memcpy(ndis_key
.KeyMaterial
, ext
->key
, 16);
1600 memcpy(ndis_key
.KeyMaterial
+ 16, ext
->key
+ 24, 8);
1601 memcpy(ndis_key
.KeyMaterial
+ 24, ext
->key
+ 16, 8);
1603 memcpy(ndis_key
.KeyMaterial
, ext
->key
, ext
->key_len
);
1605 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_KEY
, &ndis_key
,
1606 le32_to_cpu(ndis_key
.Length
));
1607 devdbg(usbdev
, "SIOCSIWENCODEEXT: OID_802_11_ADD_KEY -> %08X", ret
);
1611 priv
->encr_key_len
[keyidx
] = ext
->key_len
;
1612 memcpy(&priv
->encr_keys
[keyidx
], ndis_key
.KeyMaterial
, ext
->key_len
);
1613 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1614 priv
->encr_tx_key_index
= keyidx
;
1620 static int rndis_iw_set_scan(struct net_device
*dev
,
1621 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1623 struct iw_param
*param
= &wrqu
->param
;
1624 struct usbnet
*usbdev
= dev
->priv
;
1625 union iwreq_data evt
;
1629 devdbg(usbdev
, "SIOCSIWSCAN");
1631 if (param
->flags
== 0) {
1633 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
1636 evt
.data
.length
= 0;
1637 wireless_send_event(dev
, SIOCGIWSCAN
, &evt
, NULL
);
1643 static char *rndis_translate_scan(struct net_device
*dev
,
1644 char *cev
, char *end_buf
, struct NDIS_WLAN_BSSID_EX
*bssid
)
1647 struct usbnet
*usbdev
= dev
->priv
;
1649 struct ieee80211_info_element
*ie
;
1651 int bssid_len
, ie_len
, i
;
1653 struct iw_event iwe
;
1654 unsigned char sbuf
[32];
1655 DECLARE_MAC_BUF(mac
);
1657 bssid_len
= le32_to_cpu(bssid
->Length
);
1659 devdbg(usbdev
, "BSSID %s", print_mac(mac
, bssid
->MacAddress
));
1660 iwe
.cmd
= SIOCGIWAP
;
1661 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1662 memcpy(iwe
.u
.ap_addr
.sa_data
, bssid
->MacAddress
, ETH_ALEN
);
1663 cev
= iwe_stream_add_event(cev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
1665 devdbg(usbdev
, "SSID(%d) %s",
1666 le32_to_cpu(bssid
->Ssid
.SsidLength
),
1668 iwe
.cmd
= SIOCGIWESSID
;
1669 iwe
.u
.essid
.length
= le32_to_cpu(bssid
->Ssid
.SsidLength
);
1670 iwe
.u
.essid
.flags
= 1;
1671 cev
= iwe_stream_add_point(cev
, end_buf
, &iwe
,
1674 devdbg(usbdev
, "MODE %d",
1675 le32_to_cpu(bssid
->InfrastructureMode
));
1676 iwe
.cmd
= SIOCGIWMODE
;
1677 switch (le32_to_cpu(bssid
->InfrastructureMode
)) {
1678 case Ndis802_11IBSS
:
1679 iwe
.u
.mode
= IW_MODE_ADHOC
;
1681 case Ndis802_11Infrastructure
:
1682 iwe
.u
.mode
= IW_MODE_INFRA
;
1684 /*case Ndis802_11AutoUnknown:*/
1686 iwe
.u
.mode
= IW_MODE_AUTO
;
1689 cev
= iwe_stream_add_event(cev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
1691 devdbg(usbdev
, "FREQ %d kHz",
1692 le32_to_cpu(bssid
->Configuration
.DSConfig
));
1693 iwe
.cmd
= SIOCGIWFREQ
;
1694 dsconfig_to_freq(le32_to_cpu(bssid
->Configuration
.DSConfig
),
1696 cev
= iwe_stream_add_event(cev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
1698 devdbg(usbdev
, "QUAL %d", le32_to_cpu(bssid
->Rssi
));
1700 iwe
.u
.qual
.qual
= level_to_qual(le32_to_cpu(bssid
->Rssi
));
1701 iwe
.u
.qual
.level
= le32_to_cpu(bssid
->Rssi
);
1702 iwe
.u
.qual
.updated
= IW_QUAL_QUAL_UPDATED
1703 | IW_QUAL_LEVEL_UPDATED
1704 | IW_QUAL_NOISE_INVALID
;
1705 cev
= iwe_stream_add_event(cev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
1707 devdbg(usbdev
, "ENCODE %d", le32_to_cpu(bssid
->Privacy
));
1708 iwe
.cmd
= SIOCGIWENCODE
;
1709 iwe
.u
.data
.length
= 0;
1710 if (le32_to_cpu(bssid
->Privacy
) == Ndis802_11PrivFilterAcceptAll
)
1711 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1713 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1715 cev
= iwe_stream_add_point(cev
, end_buf
, &iwe
, NULL
);
1717 devdbg(usbdev
, "RATES:");
1718 current_val
= cev
+ IW_EV_LCP_LEN
;
1719 iwe
.cmd
= SIOCGIWRATE
;
1720 for (i
= 0; i
< sizeof(bssid
->SupportedRates
); i
++) {
1721 if (bssid
->SupportedRates
[i
] & 0x7f) {
1722 iwe
.u
.bitrate
.value
=
1723 ((bssid
->SupportedRates
[i
] & 0x7f) *
1725 devdbg(usbdev
, " %d", iwe
.u
.bitrate
.value
);
1726 current_val
= iwe_stream_add_value(cev
,
1727 current_val
, end_buf
, &iwe
,
1732 if ((current_val
- cev
) > IW_EV_LCP_LEN
)
1735 beacon
= le32_to_cpu(bssid
->Configuration
.BeaconPeriod
);
1736 devdbg(usbdev
, "BCN_INT %d", beacon
);
1737 iwe
.cmd
= IWEVCUSTOM
;
1738 snprintf(sbuf
, sizeof(sbuf
), "bcn_int=%d", beacon
);
1739 iwe
.u
.data
.length
= strlen(sbuf
);
1740 cev
= iwe_stream_add_point(cev
, end_buf
, &iwe
, sbuf
);
1742 atim
= le32_to_cpu(bssid
->Configuration
.ATIMWindow
);
1743 devdbg(usbdev
, "ATIM %d", atim
);
1744 iwe
.cmd
= IWEVCUSTOM
;
1745 snprintf(sbuf
, sizeof(sbuf
), "atim=%u", atim
);
1746 iwe
.u
.data
.length
= strlen(sbuf
);
1747 cev
= iwe_stream_add_point(cev
, end_buf
, &iwe
, sbuf
);
1749 ie
= (void *)(bssid
->IEs
+ sizeof(struct NDIS_802_11_FIXED_IEs
));
1750 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1751 (int)le32_to_cpu(bssid
->IELength
));
1752 ie_len
-= sizeof(struct NDIS_802_11_FIXED_IEs
);
1753 while (ie_len
>= sizeof(*ie
) && sizeof(*ie
) + ie
->len
<= ie_len
) {
1754 if ((ie
->id
== MFIE_TYPE_GENERIC
&& ie
->len
>= 4 &&
1755 memcmp(ie
->data
, "\x00\x50\xf2\x01", 4) == 0) ||
1756 ie
->id
== MFIE_TYPE_RSN
) {
1757 devdbg(usbdev
, "IE: WPA%d",
1758 (ie
->id
== MFIE_TYPE_RSN
) ? 2 : 1);
1759 iwe
.cmd
= IWEVGENIE
;
1760 iwe
.u
.data
.length
= min(ie
->len
+ 2, MAX_WPA_IE_LEN
);
1761 cev
= iwe_stream_add_point(cev
, end_buf
, &iwe
,
1765 ie_len
-= sizeof(*ie
) + ie
->len
;
1766 ie
= (struct ieee80211_info_element
*)&ie
->data
[ie
->len
];
1773 static int rndis_iw_get_scan(struct net_device
*dev
,
1774 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1776 struct usbnet
*usbdev
= dev
->priv
;
1779 struct NDIS_802_11_BSSID_LIST_EX
*bssid_list
;
1780 struct NDIS_WLAN_BSSID_EX
*bssid
;
1781 int ret
= -EINVAL
, len
, count
, bssid_len
;
1783 devdbg(usbdev
, "SIOCGIWSCAN");
1785 len
= CONTROL_BUFFER_SIZE
;
1786 buf
= kmalloc(len
, GFP_KERNEL
);
1792 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
1798 bssid
= bssid_list
->Bssid
;
1799 bssid_len
= le32_to_cpu(bssid
->Length
);
1800 count
= le32_to_cpu(bssid_list
->NumberOfItems
);
1801 devdbg(usbdev
, "SIOCGIWSCAN: %d BSSIDs found", count
);
1803 while (count
&& ((void *)bssid
+ bssid_len
) <= (buf
+ len
)) {
1804 cev
= rndis_translate_scan(dev
, cev
, extra
+ IW_SCAN_MAX_DATA
,
1806 bssid
= (void *)bssid
+ bssid_len
;
1807 bssid_len
= le32_to_cpu(bssid
->Length
);
1812 wrqu
->data
.length
= cev
- extra
;
1813 wrqu
->data
.flags
= 0;
1819 static int rndis_iw_set_genie(struct net_device
*dev
,
1820 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1822 struct usbnet
*usbdev
= dev
->priv
;
1823 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1829 for (j
= 0; j
< wrqu
->data
.length
; j
+= 8)
1831 "SIOCSIWGENIE %04x - "
1832 "%02x %02x %02x %02x %02x %02x %02x %02x", j
,
1833 gie
[j
+ 0], gie
[j
+ 1], gie
[j
+ 2], gie
[j
+ 3],
1834 gie
[j
+ 4], gie
[j
+ 5], gie
[j
+ 6], gie
[j
+ 7]);
1836 /* clear existing IEs */
1837 if (priv
->wpa_ie_len
) {
1838 kfree(priv
->wpa_ie
);
1839 priv
->wpa_ie_len
= 0;
1843 priv
->wpa_ie
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
1845 priv
->wpa_ie_len
= wrqu
->data
.length
;
1846 memcpy(priv
->wpa_ie
, extra
, priv
->wpa_ie_len
);
1853 static int rndis_iw_get_genie(struct net_device
*dev
,
1854 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1856 struct usbnet
*usbdev
= dev
->priv
;
1857 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1859 devdbg(usbdev
, "SIOCGIWGENIE");
1861 if (priv
->wpa_ie_len
== 0 || priv
->wpa_ie
== NULL
) {
1862 wrqu
->data
.length
= 0;
1866 if (wrqu
->data
.length
< priv
->wpa_ie_len
)
1869 wrqu
->data
.length
= priv
->wpa_ie_len
;
1870 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
1876 static int rndis_iw_set_rts(struct net_device
*dev
,
1877 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1879 struct usbnet
*usbdev
= dev
->priv
;
1881 devdbg(usbdev
, "SIOCSIWRTS");
1883 tmp
= cpu_to_le32(wrqu
->rts
.value
);
1884 return rndis_set_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
,
1889 static int rndis_iw_get_rts(struct net_device
*dev
,
1890 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1892 struct usbnet
*usbdev
= dev
->priv
;
1897 ret
= rndis_query_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
, &len
);
1899 wrqu
->rts
.value
= le32_to_cpu(tmp
);
1900 wrqu
->rts
.flags
= 1;
1901 wrqu
->rts
.disabled
= 0;
1904 devdbg(usbdev
, "SIOCGIWRTS: %d", wrqu
->rts
.value
);
1910 static int rndis_iw_set_frag(struct net_device
*dev
,
1911 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1913 struct usbnet
*usbdev
= dev
->priv
;
1916 devdbg(usbdev
, "SIOCSIWFRAG");
1918 tmp
= cpu_to_le32(wrqu
->frag
.value
);
1919 return rndis_set_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1924 static int rndis_iw_get_frag(struct net_device
*dev
,
1925 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1927 struct usbnet
*usbdev
= dev
->priv
;
1932 ret
= rndis_query_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1935 wrqu
->frag
.value
= le32_to_cpu(tmp
);
1936 wrqu
->frag
.flags
= 1;
1937 wrqu
->frag
.disabled
= 0;
1939 devdbg(usbdev
, "SIOCGIWFRAG: %d", wrqu
->frag
.value
);
1944 static int rndis_iw_set_nick(struct net_device
*dev
,
1945 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1947 struct usbnet
*usbdev
= dev
->priv
;
1948 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1950 devdbg(usbdev
, "SIOCSIWNICK");
1952 priv
->nick_len
= wrqu
->data
.length
;
1953 if (priv
->nick_len
> 32)
1954 priv
->nick_len
= 32;
1956 memcpy(priv
->nick
, extra
, priv
->nick_len
);
1961 static int rndis_iw_get_nick(struct net_device
*dev
,
1962 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1964 struct usbnet
*usbdev
= dev
->priv
;
1965 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1967 wrqu
->data
.flags
= 1;
1968 wrqu
->data
.length
= priv
->nick_len
;
1969 memcpy(extra
, priv
->nick
, priv
->nick_len
);
1971 devdbg(usbdev
, "SIOCGIWNICK: '%s'", priv
->nick
);
1977 static int rndis_iw_set_freq(struct net_device
*dev
,
1978 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1980 struct usbnet
*usbdev
= dev
->priv
;
1981 struct NDIS_802_11_CONFIGURATION config
;
1982 unsigned int dsconfig
;
1985 /* this OID is valid only when not associated */
1986 if (is_associated(usbdev
))
1990 if (freq_to_dsconfig(&wrqu
->freq
, &dsconfig
))
1993 len
= sizeof(config
);
1994 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
1996 devdbg(usbdev
, "SIOCSIWFREQ: querying configuration failed");
2000 config
.DSConfig
= cpu_to_le32(dsconfig
);
2002 devdbg(usbdev
, "SIOCSIWFREQ: %d * 10^%d", wrqu
->freq
.m
, wrqu
->freq
.e
);
2003 return rndis_set_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
,
2008 static int rndis_iw_get_freq(struct net_device
*dev
,
2009 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2011 struct usbnet
*usbdev
= dev
->priv
;
2012 struct NDIS_802_11_CONFIGURATION config
;
2015 len
= sizeof(config
);
2016 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
2018 dsconfig_to_freq(le32_to_cpu(config
.DSConfig
), &wrqu
->freq
);
2020 devdbg(usbdev
, "SIOCGIWFREQ: %d", wrqu
->freq
.m
);
2025 static int rndis_iw_get_txpower(struct net_device
*dev
,
2026 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2028 struct usbnet
*usbdev
= dev
->priv
;
2029 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2033 if (priv
->radio_on
) {
2034 if (priv
->caps
& CAP_SUPPORT_TXPOWER
) {
2035 len
= sizeof(tx_power
);
2036 ret
= rndis_query_oid(usbdev
, OID_802_11_TX_POWER_LEVEL
,
2041 /* fake incase not supported */
2042 tx_power
= cpu_to_le32(get_bcm4320_power(priv
));
2044 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
2045 wrqu
->txpower
.value
= le32_to_cpu(tx_power
);
2046 wrqu
->txpower
.disabled
= 0;
2048 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
2049 wrqu
->txpower
.value
= 0;
2050 wrqu
->txpower
.disabled
= 1;
2053 devdbg(usbdev
, "SIOCGIWTXPOW: %d", wrqu
->txpower
.value
);
2059 static int rndis_iw_set_txpower(struct net_device
*dev
,
2060 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2062 struct usbnet
*usbdev
= dev
->priv
;
2063 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2064 __le32 tx_power
= 0;
2067 if (!wrqu
->txpower
.disabled
) {
2068 if (wrqu
->txpower
.flags
== IW_TXPOW_MWATT
)
2069 tx_power
= cpu_to_le32(wrqu
->txpower
.value
);
2070 else { /* wrqu->txpower.flags == IW_TXPOW_DBM */
2071 if (wrqu
->txpower
.value
> 20)
2072 tx_power
= cpu_to_le32(128);
2073 else if (wrqu
->txpower
.value
< -43)
2074 tx_power
= cpu_to_le32(127);
2077 tmp
= wrqu
->txpower
.value
;
2080 tx_power
= cpu_to_le32((unsigned char)tmp
);
2085 devdbg(usbdev
, "SIOCSIWTXPOW: %d", le32_to_cpu(tx_power
));
2087 if (le32_to_cpu(tx_power
) != 0) {
2088 if (priv
->caps
& CAP_SUPPORT_TXPOWER
) {
2089 /* turn radio on first */
2090 if (!priv
->radio_on
)
2091 disassociate(usbdev
, 1);
2093 ret
= rndis_set_oid(usbdev
, OID_802_11_TX_POWER_LEVEL
,
2094 &tx_power
, sizeof(tx_power
));
2099 /* txpower unsupported, just turn radio on */
2100 if (!priv
->radio_on
)
2101 return disassociate(usbdev
, 1);
2102 return 0; /* all ready on */
2106 /* tx_power == 0, turn off radio */
2107 return disassociate(usbdev
, 0);
2111 static int rndis_iw_get_rate(struct net_device
*dev
,
2112 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2114 struct usbnet
*usbdev
= dev
->priv
;
2119 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &tmp
, &len
);
2121 wrqu
->bitrate
.value
= le32_to_cpu(tmp
) * 100;
2122 wrqu
->bitrate
.disabled
= 0;
2123 wrqu
->bitrate
.flags
= 1;
2129 static int rndis_iw_set_mlme(struct net_device
*dev
,
2130 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2132 struct usbnet
*usbdev
= dev
->priv
;
2133 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2134 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
2135 unsigned char bssid
[ETH_ALEN
];
2137 get_bssid(usbdev
, bssid
);
2139 if (memcmp(bssid
, mlme
->addr
.sa_data
, ETH_ALEN
))
2142 switch (mlme
->cmd
) {
2143 case IW_MLME_DEAUTH
:
2144 return deauthenticate(usbdev
);
2145 case IW_MLME_DISASSOC
:
2146 return disassociate(usbdev
, priv
->radio_on
);
2155 static struct iw_statistics
*rndis_get_wireless_stats(struct net_device
*dev
)
2157 struct usbnet
*usbdev
= dev
->priv
;
2158 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2159 unsigned long flags
;
2161 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2162 memcpy(&priv
->iwstats
, &priv
->privstats
, sizeof(priv
->iwstats
));
2163 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2165 return &priv
->iwstats
;
2169 #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2170 static const iw_handler rndis_iw_handler
[] =
2172 IW_IOCTL(SIOCSIWCOMMIT
) = rndis_iw_commit
,
2173 IW_IOCTL(SIOCGIWNAME
) = rndis_iw_get_name
,
2174 IW_IOCTL(SIOCSIWFREQ
) = rndis_iw_set_freq
,
2175 IW_IOCTL(SIOCGIWFREQ
) = rndis_iw_get_freq
,
2176 IW_IOCTL(SIOCSIWMODE
) = rndis_iw_set_mode
,
2177 IW_IOCTL(SIOCGIWMODE
) = rndis_iw_get_mode
,
2178 IW_IOCTL(SIOCGIWRANGE
) = rndis_iw_get_range
,
2179 IW_IOCTL(SIOCSIWAP
) = rndis_iw_set_bssid
,
2180 IW_IOCTL(SIOCGIWAP
) = rndis_iw_get_bssid
,
2181 IW_IOCTL(SIOCSIWSCAN
) = rndis_iw_set_scan
,
2182 IW_IOCTL(SIOCGIWSCAN
) = rndis_iw_get_scan
,
2183 IW_IOCTL(SIOCSIWESSID
) = rndis_iw_set_essid
,
2184 IW_IOCTL(SIOCGIWESSID
) = rndis_iw_get_essid
,
2185 IW_IOCTL(SIOCSIWNICKN
) = rndis_iw_set_nick
,
2186 IW_IOCTL(SIOCGIWNICKN
) = rndis_iw_get_nick
,
2187 IW_IOCTL(SIOCGIWRATE
) = rndis_iw_get_rate
,
2188 IW_IOCTL(SIOCSIWRTS
) = rndis_iw_set_rts
,
2189 IW_IOCTL(SIOCGIWRTS
) = rndis_iw_get_rts
,
2190 IW_IOCTL(SIOCSIWFRAG
) = rndis_iw_set_frag
,
2191 IW_IOCTL(SIOCGIWFRAG
) = rndis_iw_get_frag
,
2192 IW_IOCTL(SIOCSIWTXPOW
) = rndis_iw_set_txpower
,
2193 IW_IOCTL(SIOCGIWTXPOW
) = rndis_iw_get_txpower
,
2194 IW_IOCTL(SIOCSIWENCODE
) = rndis_iw_set_encode
,
2195 IW_IOCTL(SIOCSIWENCODEEXT
) = rndis_iw_set_encode_ext
,
2196 IW_IOCTL(SIOCSIWAUTH
) = rndis_iw_set_auth
,
2197 IW_IOCTL(SIOCGIWAUTH
) = rndis_iw_get_auth
,
2198 IW_IOCTL(SIOCSIWGENIE
) = rndis_iw_set_genie
,
2199 IW_IOCTL(SIOCGIWGENIE
) = rndis_iw_get_genie
,
2200 IW_IOCTL(SIOCSIWMLME
) = rndis_iw_set_mlme
,
2203 static const iw_handler rndis_wext_private_handler
[] = {
2206 static const struct iw_priv_args rndis_wext_private_args
[] = {
2210 static const struct iw_handler_def rndis_iw_handlers
= {
2211 .num_standard
= ARRAY_SIZE(rndis_iw_handler
),
2212 .num_private
= ARRAY_SIZE(rndis_wext_private_handler
),
2213 .num_private_args
= ARRAY_SIZE(rndis_wext_private_args
),
2214 .standard
= (iw_handler
*)rndis_iw_handler
,
2215 .private = (iw_handler
*)rndis_wext_private_handler
,
2216 .private_args
= (struct iw_priv_args
*)rndis_wext_private_args
,
2217 .get_wireless_stats
= rndis_get_wireless_stats
,
2221 static void rndis_wext_worker(struct work_struct
*work
)
2223 struct rndis_wext_private
*priv
=
2224 container_of(work
, struct rndis_wext_private
, work
);
2225 struct usbnet
*usbdev
= priv
->usbdev
;
2226 union iwreq_data evt
;
2227 unsigned char bssid
[ETH_ALEN
];
2230 if (test_and_clear_bit(WORK_CONNECTION_EVENT
, &priv
->work_pending
)) {
2231 ret
= get_bssid(usbdev
, bssid
);
2235 evt
.data
.length
= 0;
2236 memcpy(evt
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
2237 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2241 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2242 set_multicast_list(usbdev
);
2245 static void rndis_wext_set_multicast_list(struct net_device
*dev
)
2247 struct usbnet
*usbdev
= dev
->priv
;
2248 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2250 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2251 queue_work(priv
->workqueue
, &priv
->work
);
2254 static void rndis_wext_link_change(struct usbnet
*dev
, int state
)
2256 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
2257 union iwreq_data evt
;
2260 /* queue work to avoid recursive calls into rndis_command */
2261 set_bit(WORK_CONNECTION_EVENT
, &priv
->work_pending
);
2262 queue_work(priv
->workqueue
, &priv
->work
);
2265 evt
.data
.length
= 0;
2266 memset(evt
.ap_addr
.sa_data
, 0, ETH_ALEN
);
2267 wireless_send_event(dev
->net
, SIOCGIWAP
, &evt
, NULL
);
2272 static int rndis_wext_get_caps(struct usbnet
*dev
)
2277 } networks_supported
;
2278 int len
, retval
, i
, n
;
2280 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
2282 /* determine if supports setting txpower */
2283 len
= sizeof(tx_power
);
2284 retval
= rndis_query_oid(dev
, OID_802_11_TX_POWER_LEVEL
, &tx_power
,
2286 if (retval
== 0 && le32_to_cpu(tx_power
) != 0xFF)
2287 priv
->caps
|= CAP_SUPPORT_TXPOWER
;
2289 /* determine supported modes */
2290 len
= sizeof(networks_supported
);
2291 retval
= rndis_query_oid(dev
, OID_802_11_NETWORK_TYPES_SUPPORTED
,
2292 &networks_supported
, &len
);
2294 n
= le32_to_cpu(networks_supported
.num_items
);
2297 for (i
= 0; i
< n
; i
++) {
2298 switch (le32_to_cpu(networks_supported
.items
[i
])) {
2301 priv
->caps
|= CAP_MODE_80211B
;
2303 case Ndis802_11OFDM5
:
2304 priv
->caps
|= CAP_MODE_80211A
;
2306 case Ndis802_11OFDM24
:
2307 priv
->caps
|= CAP_MODE_80211G
;
2311 if (priv
->caps
& CAP_MODE_80211A
)
2312 strcat(priv
->name
, "a");
2313 if (priv
->caps
& CAP_MODE_80211B
)
2314 strcat(priv
->name
, "b");
2315 if (priv
->caps
& CAP_MODE_80211G
)
2316 strcat(priv
->name
, "g");
2323 #define STATS_UPDATE_JIFFIES (HZ)
2324 static void rndis_update_wireless_stats(struct work_struct
*work
)
2326 struct rndis_wext_private
*priv
=
2327 container_of(work
, struct rndis_wext_private
, stats_work
.work
);
2328 struct usbnet
*usbdev
= priv
->usbdev
;
2329 struct iw_statistics iwstats
;
2331 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
2332 int len
, ret
, bitrate
, j
;
2335 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
2336 unsigned long flags
;
2337 int update_jiffies
= STATS_UPDATE_JIFFIES
;
2340 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2341 memcpy(&iwstats
, &priv
->privstats
, sizeof(iwstats
));
2342 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2344 /* only update stats when connected */
2345 if (!is_associated(usbdev
)) {
2346 iwstats
.qual
.qual
= 0;
2347 iwstats
.qual
.level
= 0;
2348 iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2349 | IW_QUAL_LEVEL_UPDATED
2350 | IW_QUAL_NOISE_INVALID
2351 | IW_QUAL_QUAL_INVALID
2352 | IW_QUAL_LEVEL_INVALID
;
2357 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2359 devdbg(usbdev
, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret
,
2362 memset(&iwstats
.qual
, 0, sizeof(iwstats
.qual
));
2363 iwstats
.qual
.qual
= level_to_qual(le32_to_cpu(rssi
));
2364 iwstats
.qual
.level
= le32_to_cpu(rssi
);
2365 iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2366 | IW_QUAL_LEVEL_UPDATED
2367 | IW_QUAL_NOISE_INVALID
;
2370 memset(&iwstats
.discard
, 0, sizeof(iwstats
.discard
));
2373 ret
= rndis_query_oid(usbdev
, OID_GEN_XMIT_ERROR
, &tmp
, &len
);
2375 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2378 ret
= rndis_query_oid(usbdev
, OID_GEN_RCV_ERROR
, &tmp
, &len
);
2380 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2383 ret
= rndis_query_oid(usbdev
, OID_GEN_RCV_NO_BUFFER
, &tmp
, &len
);
2385 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2387 <<<<<<< HEAD
:drivers
/net
/wireless
/rndis_wlan
.c
2388 /* Workaround transfer stalls on poor quality links. */
2390 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &tmp
, &len
);
2392 bitrate
= le32_to_cpu(tmp
) * 100;
2393 if (bitrate
> 11000000)
2397 /* Workaround transfer stalls on poor quality links.
2398 * TODO: find right way to fix these stalls (as stalls do not happen
2399 * with ndiswrapper/windows driver). */
2400 if (iwstats
.qual
.qual
<= 25) {
2401 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/wireless
/rndis_wlan
.c
2402 /* Decrease stats worker interval to catch stalls.
2403 * faster. Faster than 400-500ms causes packet loss,
2404 * Slower doesn't catch stalls fast enough.
2406 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
2407 if (j
> STATS_UPDATE_JIFFIES
)
2408 j
= STATS_UPDATE_JIFFIES
;
2413 /* Send scan OID. Use of both OIDs is required to get device
2417 rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
2420 len
= CONTROL_BUFFER_SIZE
;
2421 buf
= kmalloc(len
, GFP_KERNEL
);
2425 rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2429 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2430 memcpy(&priv
->privstats
, &iwstats
, sizeof(iwstats
));
2431 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2433 if (update_jiffies
>= HZ
)
2434 update_jiffies
= round_jiffies_relative(update_jiffies
);
2436 j
= round_jiffies_relative(update_jiffies
);
2437 if (abs(j
- update_jiffies
) <= 10)
2441 queue_delayed_work(priv
->workqueue
, &priv
->stats_work
, update_jiffies
);
2445 static int bcm4320_early_init(struct usbnet
*dev
)
2447 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
2450 /* Early initialization settings, setting these won't have effect
2451 * if called after generic_rndis_bind().
2454 priv
->param_country
[0] = modparam_country
[0];
2455 priv
->param_country
[1] = modparam_country
[1];
2456 priv
->param_country
[2] = 0;
2457 priv
->param_frameburst
= modparam_frameburst
;
2458 priv
->param_afterburner
= modparam_afterburner
;
2459 priv
->param_power_save
= modparam_power_save
;
2460 priv
->param_power_output
= modparam_power_output
;
2461 priv
->param_roamtrigger
= modparam_roamtrigger
;
2462 priv
->param_roamdelta
= modparam_roamdelta
;
2463 priv
->param_workaround_interval
= modparam_workaround_interval
;
2465 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
2466 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
2467 /* doesn't support EU as country code, use FI instead */
2468 if (!strcmp(priv
->param_country
, "EU"))
2469 strcpy(priv
->param_country
, "FI");
2471 if (priv
->param_power_save
< 0)
2472 priv
->param_power_save
= 0;
2473 else if (priv
->param_power_save
> 2)
2474 priv
->param_power_save
= 2;
2476 if (priv
->param_roamtrigger
< -80)
2477 priv
->param_roamtrigger
= -80;
2478 else if (priv
->param_roamtrigger
> -60)
2479 priv
->param_roamtrigger
= -60;
2481 if (priv
->param_roamdelta
< 0)
2482 priv
->param_roamdelta
= 0;
2483 else if (priv
->param_roamdelta
> 2)
2484 priv
->param_roamdelta
= 2;
2486 if (priv
->param_workaround_interval
< 0)
2487 priv
->param_workaround_interval
= 500;
2489 rndis_set_config_parameter_str(dev
, "Country", priv
->param_country
);
2490 rndis_set_config_parameter_str(dev
, "FrameBursting",
2491 priv
->param_frameburst
? "1" : "0");
2492 rndis_set_config_parameter_str(dev
, "Afterburner",
2493 priv
->param_afterburner
? "1" : "0");
2494 sprintf(buf
, "%d", priv
->param_power_save
);
2495 rndis_set_config_parameter_str(dev
, "PowerSaveMode", buf
);
2496 sprintf(buf
, "%d", priv
->param_power_output
);
2497 rndis_set_config_parameter_str(dev
, "PwrOut", buf
);
2498 sprintf(buf
, "%d", priv
->param_roamtrigger
);
2499 rndis_set_config_parameter_str(dev
, "RoamTrigger", buf
);
2500 sprintf(buf
, "%d", priv
->param_roamdelta
);
2501 rndis_set_config_parameter_str(dev
, "RoamDelta", buf
);
2507 static int rndis_wext_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
2509 struct net_device
*net
= dev
->net
;
2510 struct rndis_wext_private
*priv
;
2514 /* allocate rndis private data */
2515 priv
= kmalloc(sizeof(struct rndis_wext_private
), GFP_KERNEL
);
2519 /* These have to be initialized before calling generic_rndis_bind().
2520 * Otherwise we'll be in big trouble in rndis_wext_early_init().
2522 dev
->driver_priv
= priv
;
2523 memset(priv
, 0, sizeof(*priv
));
2524 memset(priv
->name
, 0, sizeof(priv
->name
));
2525 strcpy(priv
->name
, "IEEE802.11");
2526 net
->wireless_handlers
= &rndis_iw_handlers
;
2529 mutex_init(&priv
->command_lock
);
2530 spin_lock_init(&priv
->stats_lock
);
2532 /* try bind rndis_host */
2533 retval
= generic_rndis_bind(dev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
2537 /* generic_rndis_bind set packet filter to multicast_all+
2538 * promisc mode which doesn't work well for our devices (device
2539 * picks up rssi to closest station instead of to access point).
2541 * rndis_host wants to avoid all OID as much as possible
2542 * so do promisc/multicast handling in rndis_wext.
2544 dev
->net
->set_multicast_list
= rndis_wext_set_multicast_list
;
2545 tmp
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
2546 retval
= rndis_set_oid(dev
, OID_GEN_CURRENT_PACKET_FILTER
, &tmp
,
2550 retval
= rndis_query_oid(dev
, OID_802_3_MAXIMUM_LIST_SIZE
, &tmp
, &len
);
2551 priv
->multicast_size
= le32_to_cpu(tmp
);
2552 if (retval
< 0 || priv
->multicast_size
< 0)
2553 priv
->multicast_size
= 0;
2554 if (priv
->multicast_size
> 0)
2555 dev
->net
->flags
|= IFF_MULTICAST
;
2557 dev
->net
->flags
&= ~IFF_MULTICAST
;
2559 priv
->iwstats
.qual
.qual
= 0;
2560 priv
->iwstats
.qual
.level
= 0;
2561 priv
->iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2562 | IW_QUAL_LEVEL_UPDATED
2563 | IW_QUAL_NOISE_INVALID
2564 | IW_QUAL_QUAL_INVALID
2565 | IW_QUAL_LEVEL_INVALID
;
2567 rndis_wext_get_caps(dev
);
2568 set_default_iw_params(dev
);
2572 disassociate(dev
, 1);
2574 /* because rndis_command() sleeps we need to use workqueue */
2575 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
2576 INIT_DELAYED_WORK(&priv
->stats_work
, rndis_update_wireless_stats
);
2577 queue_delayed_work(priv
->workqueue
, &priv
->stats_work
,
2578 round_jiffies_relative(STATS_UPDATE_JIFFIES
));
2579 INIT_WORK(&priv
->work
, rndis_wext_worker
);
2589 static void rndis_wext_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
2591 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
2593 /* turn radio off */
2594 disassociate(dev
, 0);
2596 cancel_delayed_work_sync(&priv
->stats_work
);
2597 cancel_work_sync(&priv
->work
);
2598 flush_workqueue(priv
->workqueue
);
2599 destroy_workqueue(priv
->workqueue
);
2601 if (priv
&& priv
->wpa_ie_len
)
2602 kfree(priv
->wpa_ie
);
2605 rndis_unbind(dev
, intf
);
2609 static int rndis_wext_reset(struct usbnet
*dev
)
2611 return deauthenticate(dev
);
2615 static const struct driver_info bcm4320b_info
= {
2616 .description
= "Wireless RNDIS device, BCM4320b based",
2617 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
,
2618 .bind
= rndis_wext_bind
,
2619 .unbind
= rndis_wext_unbind
,
2620 .status
= rndis_status
,
2621 .rx_fixup
= rndis_rx_fixup
,
2622 .tx_fixup
= rndis_tx_fixup
,
2623 .reset
= rndis_wext_reset
,
2624 .early_init
= bcm4320_early_init
,
2625 .link_change
= rndis_wext_link_change
,
2628 static const struct driver_info bcm4320a_info
= {
2629 .description
= "Wireless RNDIS device, BCM4320a based",
2630 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
,
2631 .bind
= rndis_wext_bind
,
2632 .unbind
= rndis_wext_unbind
,
2633 .status
= rndis_status
,
2634 .rx_fixup
= rndis_rx_fixup
,
2635 .tx_fixup
= rndis_tx_fixup
,
2636 .reset
= rndis_wext_reset
,
2637 .early_init
= bcm4320_early_init
,
2638 .link_change
= rndis_wext_link_change
,
2641 static const struct driver_info rndis_wext_info
= {
2642 .description
= "Wireless RNDIS device",
2643 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
,
2644 .bind
= rndis_wext_bind
,
2645 .unbind
= rndis_wext_unbind
,
2646 .status
= rndis_status
,
2647 .rx_fixup
= rndis_rx_fixup
,
2648 .tx_fixup
= rndis_tx_fixup
,
2649 .reset
= rndis_wext_reset
,
2650 .early_init
= bcm4320_early_init
,
2651 .link_change
= rndis_wext_link_change
,
2654 /*-------------------------------------------------------------------------*/
2656 static const struct usb_device_id products
[] = {
2657 #define RNDIS_MASTER_INTERFACE \
2658 .bInterfaceClass = USB_CLASS_COMM, \
2659 .bInterfaceSubClass = 2 /* ACM */, \
2660 .bInterfaceProtocol = 0x0ff
2662 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2663 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2666 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2667 | USB_DEVICE_ID_MATCH_DEVICE
,
2669 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
2670 RNDIS_MASTER_INTERFACE
,
2671 .driver_info
= (unsigned long) &bcm4320b_info
,
2673 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2674 | USB_DEVICE_ID_MATCH_DEVICE
,
2676 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
2677 RNDIS_MASTER_INTERFACE
,
2678 .driver_info
= (unsigned long) &bcm4320b_info
,
2680 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2681 | USB_DEVICE_ID_MATCH_DEVICE
,
2683 .idProduct
= 0x011b, /* Belkin F5D7051 */
2684 RNDIS_MASTER_INTERFACE
,
2685 .driver_info
= (unsigned long) &bcm4320b_info
,
2687 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2688 | USB_DEVICE_ID_MATCH_DEVICE
,
2689 .idVendor
= 0x1799, /* Belkin has two vendor ids */
2690 .idProduct
= 0x011b, /* Belkin F5D7051 */
2691 RNDIS_MASTER_INTERFACE
,
2692 .driver_info
= (unsigned long) &bcm4320b_info
,
2694 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2695 | USB_DEVICE_ID_MATCH_DEVICE
,
2697 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
2698 RNDIS_MASTER_INTERFACE
,
2699 .driver_info
= (unsigned long) &bcm4320b_info
,
2701 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2702 | USB_DEVICE_ID_MATCH_DEVICE
,
2704 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
2705 RNDIS_MASTER_INTERFACE
,
2706 .driver_info
= (unsigned long) &bcm4320b_info
,
2708 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2709 | USB_DEVICE_ID_MATCH_DEVICE
,
2711 .idProduct
= 0x1717, /* Asus WL169gE */
2712 RNDIS_MASTER_INTERFACE
,
2713 .driver_info
= (unsigned long) &bcm4320b_info
,
2715 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2716 | USB_DEVICE_ID_MATCH_DEVICE
,
2718 .idProduct
= 0xd11b, /* Eminent EM4045 */
2719 RNDIS_MASTER_INTERFACE
,
2720 .driver_info
= (unsigned long) &bcm4320b_info
,
2722 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2723 | USB_DEVICE_ID_MATCH_DEVICE
,
2725 .idProduct
= 0x0715, /* BT Voyager 1055 */
2726 RNDIS_MASTER_INTERFACE
,
2727 .driver_info
= (unsigned long) &bcm4320b_info
,
2729 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
2730 * parameters available, hardware probably contain older firmware version with
2731 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
2734 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2735 | USB_DEVICE_ID_MATCH_DEVICE
,
2737 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
2738 RNDIS_MASTER_INTERFACE
,
2739 .driver_info
= (unsigned long) &bcm4320a_info
,
2741 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2742 | USB_DEVICE_ID_MATCH_DEVICE
,
2744 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
2745 RNDIS_MASTER_INTERFACE
,
2746 .driver_info
= (unsigned long) &bcm4320a_info
,
2748 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2749 | USB_DEVICE_ID_MATCH_DEVICE
,
2751 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
2752 RNDIS_MASTER_INTERFACE
,
2753 .driver_info
= (unsigned long) &bcm4320a_info
,
2755 /* Generic Wireless RNDIS devices that we don't have exact
2756 * idVendor/idProduct/chip yet.
2759 /* RNDIS is MSFT's un-official variant of CDC ACM */
2760 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
2761 .driver_info
= (unsigned long) &rndis_wext_info
,
2763 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
2764 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
2765 .driver_info
= (unsigned long) &rndis_wext_info
,
2769 MODULE_DEVICE_TABLE(usb
, products
);
2771 static struct usb_driver rndis_wlan_driver
= {
2772 .name
= "rndis_wlan",
2773 .id_table
= products
,
2774 .probe
= usbnet_probe
,
2775 .disconnect
= usbnet_disconnect
,
2776 .suspend
= usbnet_suspend
,
2777 .resume
= usbnet_resume
,
2780 static int __init
rndis_wlan_init(void)
2782 return usb_register(&rndis_wlan_driver
);
2784 module_init(rndis_wlan_init
);
2786 static void __exit
rndis_wlan_exit(void)
2788 usb_deregister(&rndis_wlan_driver
);
2790 module_exit(rndis_wlan_exit
);
2792 MODULE_AUTHOR("Bjorge Dijkstra");
2793 MODULE_AUTHOR("Jussi Kivilinna");
2794 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
2795 MODULE_LICENSE("GPL");