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/ieee80211.h>
41 #include <linux/if_arp.h>
42 #include <linux/ctype.h>
43 #include <linux/spinlock.h>
44 #include <net/iw_handler.h>
45 #include <net/wireless.h>
46 #include <net/cfg80211.h>
47 #include <linux/usb/usbnet.h>
48 #include <linux/usb/rndis_host.h>
51 /* NOTE: All these are settings for Broadcom chipset */
52 static char modparam_country
[4] = "EU";
53 module_param_string(country
, modparam_country
, 4, 0444);
54 MODULE_PARM_DESC(country
, "Country code (ISO 3166-1 alpha-2), default: EU");
56 static int modparam_frameburst
= 1;
57 module_param_named(frameburst
, modparam_frameburst
, int, 0444);
58 MODULE_PARM_DESC(frameburst
, "enable frame bursting (default: on)");
60 static int modparam_afterburner
= 0;
61 module_param_named(afterburner
, modparam_afterburner
, int, 0444);
62 MODULE_PARM_DESC(afterburner
,
63 "enable afterburner aka '125 High Speed Mode' (default: off)");
65 static int modparam_power_save
= 0;
66 module_param_named(power_save
, modparam_power_save
, int, 0444);
67 MODULE_PARM_DESC(power_save
,
68 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
70 static int modparam_power_output
= 3;
71 module_param_named(power_output
, modparam_power_output
, int, 0444);
72 MODULE_PARM_DESC(power_output
,
73 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
75 static int modparam_roamtrigger
= -70;
76 module_param_named(roamtrigger
, modparam_roamtrigger
, int, 0444);
77 MODULE_PARM_DESC(roamtrigger
,
78 "set roaming dBm trigger: -80=optimize for distance, "
79 "-60=bandwidth (default: -70)");
81 static int modparam_roamdelta
= 1;
82 module_param_named(roamdelta
, modparam_roamdelta
, int, 0444);
83 MODULE_PARM_DESC(roamdelta
,
84 "set roaming tendency: 0=aggressive, 1=moderate, "
85 "2=conservative (default: moderate)");
87 static int modparam_workaround_interval
= 500;
88 module_param_named(workaround_interval
, modparam_workaround_interval
,
90 MODULE_PARM_DESC(workaround_interval
,
91 "set stall workaround interval in msecs (default: 500)");
94 /* various RNDIS OID defs */
95 #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
96 #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
98 #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101)
99 #define OID_GEN_RCV_OK cpu_to_le32(0x00020102)
100 #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103)
101 #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104)
102 #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105)
104 #define OID_802_3_PERMANENT_ADDRESS cpu_to_le32(0x01010101)
105 #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
106 #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
107 #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
109 #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
110 #define OID_802_11_SSID cpu_to_le32(0x0d010102)
111 #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
112 #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
113 #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
114 #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
115 #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
116 #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
117 #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
118 #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
119 #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
120 #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
121 #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
122 #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
123 #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
124 #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
125 #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
126 #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
127 #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
128 #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
129 #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
130 #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
131 #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
132 #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
135 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
136 #define WL_NOISE -96 /* typical noise level in dBm */
137 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
140 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
141 * based on wireless rndis) has default txpower of 13dBm.
142 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
145 #define BCM4320_DEFAULT_TXPOWER 20
148 /* codes for "status" field of completion messages */
149 #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
150 #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
153 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
154 * slightly modified for datatype endianess, etc
156 #define NDIS_802_11_LENGTH_SSID 32
157 #define NDIS_802_11_LENGTH_RATES 8
158 #define NDIS_802_11_LENGTH_RATES_EX 16
160 enum ndis_80211_net_type
{
161 ndis_80211_type_freq_hop
,
162 ndis_80211_type_direct_seq
,
163 ndis_80211_type_ofdm_a
,
164 ndis_80211_type_ofdm_g
167 enum ndis_80211_net_infra
{
168 ndis_80211_infra_adhoc
,
169 ndis_80211_infra_infra
,
170 ndis_80211_infra_auto_unknown
173 enum ndis_80211_auth_mode
{
174 ndis_80211_auth_open
,
175 ndis_80211_auth_shared
,
176 ndis_80211_auth_auto_switch
,
178 ndis_80211_auth_wpa_psk
,
179 ndis_80211_auth_wpa_none
,
180 ndis_80211_auth_wpa2
,
181 ndis_80211_auth_wpa2_psk
184 enum ndis_80211_encr_status
{
185 ndis_80211_encr_wep_enabled
,
186 ndis_80211_encr_disabled
,
187 ndis_80211_encr_wep_key_absent
,
188 ndis_80211_encr_not_supported
,
189 ndis_80211_encr_tkip_enabled
,
190 ndis_80211_encr_tkip_key_absent
,
191 ndis_80211_encr_ccmp_enabled
,
192 ndis_80211_encr_ccmp_key_absent
195 enum ndis_80211_priv_filter
{
196 ndis_80211_priv_accept_all
,
197 ndis_80211_priv_8021x_wep
200 struct ndis_80211_ssid
{
202 u8 essid
[NDIS_802_11_LENGTH_SSID
];
203 } __attribute__((packed
));
205 struct ndis_80211_conf_freq_hop
{
210 } __attribute__((packed
));
212 struct ndis_80211_conf
{
214 __le32 beacon_period
;
217 struct ndis_80211_conf_freq_hop fh_config
;
218 } __attribute__((packed
));
220 struct ndis_80211_bssid_ex
{
224 struct ndis_80211_ssid ssid
;
228 struct ndis_80211_conf config
;
230 u8 rates
[NDIS_802_11_LENGTH_RATES_EX
];
233 } __attribute__((packed
));
235 struct ndis_80211_bssid_list_ex
{
237 struct ndis_80211_bssid_ex bssid
[0];
238 } __attribute__((packed
));
240 struct ndis_80211_fixed_ies
{
242 __le16 beacon_interval
;
244 } __attribute__((packed
));
246 struct ndis_80211_wep_key
{
251 } __attribute__((packed
));
253 struct ndis_80211_key
{
261 } __attribute__((packed
));
263 struct ndis_80211_remove_key
{
267 } __attribute__((packed
));
269 struct ndis_config_param
{
275 } __attribute__((packed
));
277 struct ndis_80211_assoc_info
{
282 __le16 listen_interval
;
283 u8 cur_ap_address
[6];
285 __le32 req_ie_length
;
286 __le32 offset_req_ies
;
293 __le32 resp_ie_length
;
294 __le32 offset_resp_ies
;
295 } __attribute__((packed
));
297 /* these have to match what is in wpa_supplicant */
298 enum wpa_alg
{ WPA_ALG_NONE
, WPA_ALG_WEP
, WPA_ALG_TKIP
, WPA_ALG_CCMP
};
299 enum wpa_cipher
{ CIPHER_NONE
, CIPHER_WEP40
, CIPHER_TKIP
, CIPHER_CCMP
,
301 enum wpa_key_mgmt
{ KEY_MGMT_802_1X
, KEY_MGMT_PSK
, KEY_MGMT_NONE
,
302 KEY_MGMT_802_1X_NO_WPA
, KEY_MGMT_WPA_NONE
};
307 #define NET_TYPE_11FB 0
309 #define CAP_MODE_80211A 1
310 #define CAP_MODE_80211B 2
311 #define CAP_MODE_80211G 4
312 #define CAP_MODE_MASK 7
313 #define CAP_SUPPORT_TXPOWER 8
315 #define WORK_LINK_UP (1<<0)
316 #define WORK_LINK_DOWN (1<<1)
317 #define WORK_SET_MULTICAST_LIST (1<<2)
319 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
321 static const struct ieee80211_channel rndis_channels
[] = {
322 { .center_freq
= 2412 },
323 { .center_freq
= 2417 },
324 { .center_freq
= 2422 },
325 { .center_freq
= 2427 },
326 { .center_freq
= 2432 },
327 { .center_freq
= 2437 },
328 { .center_freq
= 2442 },
329 { .center_freq
= 2447 },
330 { .center_freq
= 2452 },
331 { .center_freq
= 2457 },
332 { .center_freq
= 2462 },
333 { .center_freq
= 2467 },
334 { .center_freq
= 2472 },
335 { .center_freq
= 2484 },
338 static const struct ieee80211_rate rndis_rates
[] = {
340 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
341 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
342 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
353 /* RNDIS device private data */
354 struct rndis_wext_private
{
355 struct usbnet
*usbdev
;
357 struct wireless_dev wdev
;
359 struct workqueue_struct
*workqueue
;
360 struct delayed_work stats_work
;
361 struct work_struct work
;
362 struct mutex command_lock
;
363 spinlock_t stats_lock
;
364 unsigned long work_pending
;
366 struct ieee80211_supported_band band
;
367 struct ieee80211_channel channels
[ARRAY_SIZE(rndis_channels
)];
368 struct ieee80211_rate rates
[ARRAY_SIZE(rndis_rates
)];
370 struct iw_statistics iwstats
;
371 struct iw_statistics privstats
;
379 /* module parameters */
380 char param_country
[4];
381 int param_frameburst
;
382 int param_afterburner
;
383 int param_power_save
;
384 int param_power_output
;
385 int param_roamtrigger
;
387 u32 param_workaround_interval
;
392 struct ndis_80211_ssid essid
;
394 /* encryption stuff */
395 int encr_tx_key_index
;
396 char encr_keys
[4][32];
404 int wpa_cipher_group
;
406 u8 command_buffer
[COMMAND_BUFFER_SIZE
];
412 static int rndis_change_virtual_intf(struct wiphy
*wiphy
, int ifindex
,
413 enum nl80211_iftype type
, u32
*flags
,
414 struct vif_params
*params
);
416 struct cfg80211_ops rndis_config_ops
= {
417 .change_virtual_intf
= rndis_change_virtual_intf
,
420 void *rndis_wiphy_privid
= &rndis_wiphy_privid
;
422 static const int bcm4320_power_output
[4] = { 25, 50, 75, 100 };
424 static const unsigned char zero_bssid
[ETH_ALEN
] = {0,};
425 static const unsigned char ffff_bssid
[ETH_ALEN
] = { 0xff, 0xff, 0xff,
429 static struct rndis_wext_private
*get_rndis_wext_priv(struct usbnet
*dev
)
431 return (struct rndis_wext_private
*)dev
->driver_priv
;
435 static u32
get_bcm4320_power(struct rndis_wext_private
*priv
)
437 return BCM4320_DEFAULT_TXPOWER
*
438 bcm4320_power_output
[priv
->param_power_output
] / 100;
442 /* translate error code */
443 static int rndis_error_status(__le32 rndis_status
)
446 switch (rndis_status
) {
447 case RNDIS_STATUS_SUCCESS
:
450 case RNDIS_STATUS_FAILURE
:
451 case RNDIS_STATUS_INVALID_DATA
:
454 case RNDIS_STATUS_NOT_SUPPORTED
:
457 case RNDIS_STATUS_ADAPTER_NOT_READY
:
458 case RNDIS_STATUS_ADAPTER_NOT_OPEN
:
466 static int rndis_query_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int *len
)
468 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
471 struct rndis_msg_hdr
*header
;
472 struct rndis_query
*get
;
473 struct rndis_query_c
*get_c
;
477 buflen
= *len
+ sizeof(*u
.get
);
478 if (buflen
< CONTROL_BUFFER_SIZE
)
479 buflen
= CONTROL_BUFFER_SIZE
;
481 if (buflen
> COMMAND_BUFFER_SIZE
) {
482 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
486 u
.buf
= priv
->command_buffer
;
489 mutex_lock(&priv
->command_lock
);
491 memset(u
.get
, 0, sizeof *u
.get
);
492 u
.get
->msg_type
= RNDIS_MSG_QUERY
;
493 u
.get
->msg_len
= cpu_to_le32(sizeof *u
.get
);
496 ret
= rndis_command(dev
, u
.header
, buflen
);
498 ret
= le32_to_cpu(u
.get_c
->len
);
499 *len
= (*len
> ret
) ? ret
: *len
;
500 memcpy(data
, u
.buf
+ le32_to_cpu(u
.get_c
->offset
) + 8, *len
);
501 ret
= rndis_error_status(u
.get_c
->status
);
504 mutex_unlock(&priv
->command_lock
);
506 if (u
.buf
!= priv
->command_buffer
)
512 static int rndis_set_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int len
)
514 struct rndis_wext_private
*priv
= get_rndis_wext_priv(dev
);
517 struct rndis_msg_hdr
*header
;
518 struct rndis_set
*set
;
519 struct rndis_set_c
*set_c
;
523 buflen
= len
+ sizeof(*u
.set
);
524 if (buflen
< CONTROL_BUFFER_SIZE
)
525 buflen
= CONTROL_BUFFER_SIZE
;
527 if (buflen
> COMMAND_BUFFER_SIZE
) {
528 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
532 u
.buf
= priv
->command_buffer
;
535 mutex_lock(&priv
->command_lock
);
537 memset(u
.set
, 0, sizeof *u
.set
);
538 u
.set
->msg_type
= RNDIS_MSG_SET
;
539 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
541 u
.set
->len
= cpu_to_le32(len
);
542 u
.set
->offset
= cpu_to_le32(sizeof(*u
.set
) - 8);
543 u
.set
->handle
= cpu_to_le32(0);
544 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
546 ret
= rndis_command(dev
, u
.header
, buflen
);
548 ret
= rndis_error_status(u
.set_c
->status
);
550 mutex_unlock(&priv
->command_lock
);
552 if (u
.buf
!= priv
->command_buffer
)
559 * Specs say that we can only set config parameters only soon after device
561 * value_type: 0 = u32, 2 = unicode string
563 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
564 int value_type
, void *value
)
566 struct ndis_config_param
*infobuf
;
567 int value_len
, info_len
, param_len
, ret
, i
;
572 value_len
= sizeof(__le32
);
573 else if (value_type
== 2)
574 value_len
= strlen(value
) * sizeof(__le16
);
578 param_len
= strlen(param
) * sizeof(__le16
);
579 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
584 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
590 /* extra 12 bytes are for padding (debug output) */
591 memset(infobuf
, 0xCC, info_len
+ 12);
595 devdbg(dev
, "setting config parameter: %s, value: %s",
598 devdbg(dev
, "setting config parameter: %s, value: %d",
599 param
, *(u32
*)value
);
601 infobuf
->name_offs
= cpu_to_le32(sizeof(*infobuf
));
602 infobuf
->name_length
= cpu_to_le32(param_len
);
603 infobuf
->type
= cpu_to_le32(value_type
);
604 infobuf
->value_offs
= cpu_to_le32(sizeof(*infobuf
) + param_len
);
605 infobuf
->value_length
= cpu_to_le32(value_len
);
607 /* simple string to unicode string conversion */
608 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
609 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
610 unibuf
[i
] = cpu_to_le16(param
[i
]);
612 if (value_type
== 2) {
613 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
614 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
615 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
617 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
618 *dst_value
= cpu_to_le32(*(u32
*)value
);
622 devdbg(dev
, "info buffer (len: %d):", info_len
);
623 for (i
= 0; i
< info_len
; i
+= 12) {
624 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
625 devdbg(dev
, "%08X:%08X:%08X",
628 cpu_to_be32(tmp
[2]));
632 ret
= rndis_set_oid(dev
, OID_GEN_RNDIS_CONFIG_PARAMETER
,
635 devdbg(dev
, "setting rndis config paramater failed, %d.", ret
);
641 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
642 char *param
, char *value
)
644 return(rndis_set_config_parameter(dev
, param
, 2, value
));
647 /*static int rndis_set_config_parameter_u32(struct usbnet *dev,
648 char *param, u32 value)
650 return(rndis_set_config_parameter(dev, param, 0, &value));
655 * data conversion functions
657 static int level_to_qual(int level
)
659 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
660 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
664 static void dsconfig_to_freq(unsigned int dsconfig
, struct iw_freq
*freq
)
670 /* see comment in wireless.h above the "struct iw_freq"
671 * definition for an explanation of this if
672 * NOTE: 1000000 is due to the kHz
674 if (dsconfig
> 1000000) {
675 freq
->m
= dsconfig
/ 10;
680 /* convert from kHz to Hz */
685 static int freq_to_dsconfig(struct iw_freq
*freq
, unsigned int *dsconfig
)
687 if (freq
->m
< 1000 && freq
->e
== 0) {
688 if (freq
->m
>= 1 && freq
->m
<= 14)
689 *dsconfig
= ieee80211_dsss_chan_to_freq(freq
->m
) * 1000;
695 for (i
= freq
->e
; i
> 0; i
--)
708 add_wep_key(struct usbnet
*usbdev
, char *key
, int key_len
, int index
);
710 static int get_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
715 ret
= rndis_query_oid(usbdev
, OID_802_11_SSID
, ssid
, &len
);
722 unsigned char tmp
[NDIS_802_11_LENGTH_SSID
+ 1];
724 memcpy(tmp
, ssid
->essid
, le32_to_cpu(ssid
->length
));
725 tmp
[le32_to_cpu(ssid
->length
)] = 0;
726 devdbg(usbdev
, "get_essid: '%s', ret: %d", tmp
, ret
);
733 static int set_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
735 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
738 ret
= rndis_set_oid(usbdev
, OID_802_11_SSID
, ssid
, sizeof(*ssid
));
740 memcpy(&priv
->essid
, ssid
, sizeof(priv
->essid
));
742 devdbg(usbdev
, "set_essid: radio_on = 1");
749 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
754 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID
, bssid
, &len
);
757 memset(bssid
, 0, ETH_ALEN
);
762 static int get_association_info(struct usbnet
*usbdev
,
763 struct ndis_80211_assoc_info
*info
, int len
)
765 return rndis_query_oid(usbdev
, OID_802_11_ASSOCIATION_INFORMATION
,
769 static int is_associated(struct usbnet
*usbdev
)
774 ret
= get_bssid(usbdev
, bssid
);
776 return(ret
== 0 && memcmp(bssid
, zero_bssid
, ETH_ALEN
) != 0);
780 static int disassociate(struct usbnet
*usbdev
, int reset_ssid
)
782 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
783 struct ndis_80211_ssid ssid
;
786 if (priv
->radio_on
) {
787 ret
= rndis_set_oid(usbdev
, OID_802_11_DISASSOCIATE
, NULL
, 0);
790 devdbg(usbdev
, "disassociate: radio_on = 0");
797 /* disassociate causes radio to be turned off; if reset_ssid
798 * is given, set random ssid to enable radio */
800 ssid
.length
= cpu_to_le32(sizeof(ssid
.essid
));
801 get_random_bytes(&ssid
.essid
[2], sizeof(ssid
.essid
)-2);
803 ssid
.essid
[1] = 0xff;
804 for (i
= 2; i
< sizeof(ssid
.essid
); i
++)
805 ssid
.essid
[i
] = 0x1 + (ssid
.essid
[i
] * 0xfe / 0xff);
806 ret
= set_essid(usbdev
, &ssid
);
812 static int set_auth_mode(struct usbnet
*usbdev
, int wpa_version
, int authalg
)
814 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
818 devdbg(usbdev
, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
819 "keymgmt=0x%x", wpa_version
, authalg
, priv
->wpa_keymgmt
);
821 if (wpa_version
& IW_AUTH_WPA_VERSION_WPA2
) {
822 if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_802_1X
)
823 auth_mode
= ndis_80211_auth_wpa2
;
825 auth_mode
= ndis_80211_auth_wpa2_psk
;
826 } else if (wpa_version
& IW_AUTH_WPA_VERSION_WPA
) {
827 if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_802_1X
)
828 auth_mode
= ndis_80211_auth_wpa
;
829 else if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_PSK
)
830 auth_mode
= ndis_80211_auth_wpa_psk
;
832 auth_mode
= ndis_80211_auth_wpa_none
;
833 } else if (authalg
& IW_AUTH_ALG_SHARED_KEY
) {
834 if (authalg
& IW_AUTH_ALG_OPEN_SYSTEM
)
835 auth_mode
= ndis_80211_auth_auto_switch
;
837 auth_mode
= ndis_80211_auth_shared
;
839 auth_mode
= ndis_80211_auth_open
;
841 tmp
= cpu_to_le32(auth_mode
);
842 ret
= rndis_set_oid(usbdev
, OID_802_11_AUTHENTICATION_MODE
, &tmp
,
845 devwarn(usbdev
, "setting auth mode failed (%08X)", ret
);
849 priv
->wpa_version
= wpa_version
;
850 priv
->wpa_authalg
= authalg
;
855 static int set_priv_filter(struct usbnet
*usbdev
)
857 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
860 devdbg(usbdev
, "set_priv_filter: wpa_version=0x%x", priv
->wpa_version
);
862 if (priv
->wpa_version
& IW_AUTH_WPA_VERSION_WPA2
||
863 priv
->wpa_version
& IW_AUTH_WPA_VERSION_WPA
)
864 tmp
= cpu_to_le32(ndis_80211_priv_8021x_wep
);
866 tmp
= cpu_to_le32(ndis_80211_priv_accept_all
);
868 return rndis_set_oid(usbdev
, OID_802_11_PRIVACY_FILTER
, &tmp
,
873 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
875 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
879 devdbg(usbdev
, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
883 if (pairwise
& IW_AUTH_CIPHER_CCMP
)
884 encr_mode
= ndis_80211_encr_ccmp_enabled
;
885 else if (pairwise
& IW_AUTH_CIPHER_TKIP
)
886 encr_mode
= ndis_80211_encr_tkip_enabled
;
888 (IW_AUTH_CIPHER_WEP40
| IW_AUTH_CIPHER_WEP104
))
889 encr_mode
= ndis_80211_encr_wep_enabled
;
890 else if (groupwise
& IW_AUTH_CIPHER_CCMP
)
891 encr_mode
= ndis_80211_encr_ccmp_enabled
;
892 else if (groupwise
& IW_AUTH_CIPHER_TKIP
)
893 encr_mode
= ndis_80211_encr_tkip_enabled
;
895 encr_mode
= ndis_80211_encr_disabled
;
897 tmp
= cpu_to_le32(encr_mode
);
898 ret
= rndis_set_oid(usbdev
, OID_802_11_ENCRYPTION_STATUS
, &tmp
,
901 devwarn(usbdev
, "setting encr mode failed (%08X)", ret
);
905 priv
->wpa_cipher_pair
= pairwise
;
906 priv
->wpa_cipher_group
= groupwise
;
911 static int set_assoc_params(struct usbnet
*usbdev
)
913 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
915 set_auth_mode(usbdev
, priv
->wpa_version
, priv
->wpa_authalg
);
916 set_priv_filter(usbdev
);
917 set_encr_mode(usbdev
, priv
->wpa_cipher_pair
, priv
->wpa_cipher_group
);
923 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
925 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
929 devdbg(usbdev
, "set_infra_mode: infra_mode=0x%x", priv
->infra_mode
);
931 tmp
= cpu_to_le32(mode
);
932 ret
= rndis_set_oid(usbdev
, OID_802_11_INFRASTRUCTURE_MODE
, &tmp
,
935 devwarn(usbdev
, "setting infra mode failed (%08X)", ret
);
939 /* NDIS drivers clear keys when infrastructure mode is
940 * changed. But Linux tools assume otherwise. So set the
942 if (priv
->wpa_keymgmt
== 0 ||
943 priv
->wpa_keymgmt
== IW_AUTH_KEY_MGMT_802_1X
) {
944 for (i
= 0; i
< 4; i
++) {
945 if (priv
->encr_key_len
[i
] > 0)
946 add_wep_key(usbdev
, priv
->encr_keys
[i
],
947 priv
->encr_key_len
[i
], i
);
951 priv
->infra_mode
= mode
;
956 static void set_default_iw_params(struct usbnet
*usbdev
)
958 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
960 priv
->wpa_keymgmt
= 0;
961 priv
->wpa_version
= 0;
963 set_infra_mode(usbdev
, ndis_80211_infra_infra
);
964 set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
965 IW_AUTH_ALG_OPEN_SYSTEM
);
966 set_priv_filter(usbdev
);
967 set_encr_mode(usbdev
, IW_AUTH_CIPHER_NONE
, IW_AUTH_CIPHER_NONE
);
971 static int deauthenticate(struct usbnet
*usbdev
)
975 ret
= disassociate(usbdev
, 1);
976 set_default_iw_params(usbdev
);
981 /* index must be 0 - N, as per NDIS */
982 static int add_wep_key(struct usbnet
*usbdev
, char *key
, int key_len
, int index
)
984 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
985 struct ndis_80211_wep_key ndis_key
;
988 if (key_len
<= 0 || key_len
> 32 || index
< 0 || index
>= 4)
991 memset(&ndis_key
, 0, sizeof(ndis_key
));
993 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
));
994 ndis_key
.length
= cpu_to_le32(key_len
);
995 ndis_key
.index
= cpu_to_le32(index
);
996 memcpy(&ndis_key
.material
, key
, key_len
);
998 if (index
== priv
->encr_tx_key_index
) {
999 ndis_key
.index
|= cpu_to_le32(1 << 31);
1000 ret
= set_encr_mode(usbdev
, IW_AUTH_CIPHER_WEP104
,
1001 IW_AUTH_CIPHER_NONE
);
1003 devwarn(usbdev
, "encryption couldn't be enabled (%08X)",
1007 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_WEP
, &ndis_key
,
1010 devwarn(usbdev
, "adding encryption key %d failed (%08X)",
1015 priv
->encr_key_len
[index
] = key_len
;
1016 memcpy(&priv
->encr_keys
[index
], key
, key_len
);
1022 /* remove_key is for both wep and wpa */
1023 static int remove_key(struct usbnet
*usbdev
, int index
, u8 bssid
[ETH_ALEN
])
1025 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1026 struct ndis_80211_remove_key remove_key
;
1030 if (priv
->encr_key_len
[index
] == 0)
1033 priv
->encr_key_len
[index
] = 0;
1034 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
1036 if (priv
->wpa_cipher_pair
== IW_AUTH_CIPHER_TKIP
||
1037 priv
->wpa_cipher_pair
== IW_AUTH_CIPHER_CCMP
||
1038 priv
->wpa_cipher_group
== IW_AUTH_CIPHER_TKIP
||
1039 priv
->wpa_cipher_group
== IW_AUTH_CIPHER_CCMP
) {
1040 remove_key
.size
= cpu_to_le32(sizeof(remove_key
));
1041 remove_key
.index
= cpu_to_le32(index
);
1044 if (memcmp(bssid
, ffff_bssid
, ETH_ALEN
) != 0)
1045 remove_key
.index
|= cpu_to_le32(1 << 30);
1046 memcpy(remove_key
.bssid
, bssid
,
1047 sizeof(remove_key
.bssid
));
1049 memset(remove_key
.bssid
, 0xff,
1050 sizeof(remove_key
.bssid
));
1052 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_KEY
, &remove_key
,
1053 sizeof(remove_key
));
1057 keyindex
= cpu_to_le32(index
);
1058 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_WEP
, &keyindex
,
1062 "removing encryption key %d failed (%08X)",
1068 /* if it is transmit key, disable encryption */
1069 if (index
== priv
->encr_tx_key_index
)
1070 set_encr_mode(usbdev
, IW_AUTH_CIPHER_NONE
, IW_AUTH_CIPHER_NONE
);
1076 static void set_multicast_list(struct usbnet
*usbdev
)
1078 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1079 struct dev_mc_list
*mclist
;
1084 filter
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
1086 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1087 filter
|= RNDIS_PACKET_TYPE_PROMISCUOUS
|
1088 RNDIS_PACKET_TYPE_ALL_LOCAL
;
1089 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
||
1090 usbdev
->net
->mc_count
> priv
->multicast_size
) {
1091 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1092 } else if (usbdev
->net
->mc_count
> 0) {
1093 size
= min(priv
->multicast_size
, usbdev
->net
->mc_count
);
1094 buf
= kmalloc(size
* ETH_ALEN
, GFP_KERNEL
);
1097 "couldn't alloc %d bytes of memory",
1102 mclist
= usbdev
->net
->mc_list
;
1103 for (i
= 0; i
< size
&& mclist
; mclist
= mclist
->next
) {
1104 if (mclist
->dmi_addrlen
!= ETH_ALEN
)
1107 memcpy(buf
+ i
* ETH_ALEN
, mclist
->dmi_addr
, ETH_ALEN
);
1111 ret
= rndis_set_oid(usbdev
, OID_802_3_MULTICAST_LIST
, buf
,
1113 if (ret
== 0 && i
> 0)
1114 filter
|= RNDIS_PACKET_TYPE_MULTICAST
;
1116 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1118 devdbg(usbdev
, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1119 i
, priv
->multicast_size
, ret
);
1124 ret
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1127 devwarn(usbdev
, "couldn't set packet filter: %08x",
1128 le32_to_cpu(filter
));
1131 devdbg(usbdev
, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1132 le32_to_cpu(filter
), ret
);
1139 static int rndis_change_virtual_intf(struct wiphy
*wiphy
, int ifindex
,
1140 enum nl80211_iftype type
, u32
*flags
,
1141 struct vif_params
*params
)
1143 struct net_device
*dev
;
1144 struct usbnet
*usbdev
;
1147 /* we're under RTNL */
1148 dev
= __dev_get_by_index(&init_net
, ifindex
);
1151 usbdev
= netdev_priv(dev
);
1154 case NL80211_IFTYPE_ADHOC
:
1155 mode
= ndis_80211_infra_adhoc
;
1157 case NL80211_IFTYPE_STATION
:
1158 mode
= ndis_80211_infra_infra
;
1164 return set_infra_mode(usbdev
, mode
);
1168 * wireless extension handlers
1171 static int rndis_iw_commit(struct net_device
*dev
,
1172 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1179 static int rndis_iw_get_range(struct net_device
*dev
,
1180 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1182 struct iw_range
*range
= (struct iw_range
*)extra
;
1183 struct usbnet
*usbdev
= netdev_priv(dev
);
1184 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1185 int len
, ret
, i
, j
, num
, has_80211g_rates
;
1189 devdbg(usbdev
, "SIOCGIWRANGE");
1191 /* clear iw_range struct */
1192 memset(range
, 0, sizeof(*range
));
1193 wrqu
->data
.length
= sizeof(*range
);
1195 range
->txpower_capa
= IW_TXPOW_MWATT
;
1196 range
->num_txpower
= 1;
1197 if (priv
->caps
& CAP_SUPPORT_TXPOWER
) {
1198 len
= sizeof(tx_power
);
1199 ret
= rndis_query_oid(usbdev
, OID_802_11_TX_POWER_LEVEL
,
1201 if (ret
== 0 && le32_to_cpu(tx_power
) != 0xFF)
1202 range
->txpower
[0] = le32_to_cpu(tx_power
);
1204 range
->txpower
[0] = get_bcm4320_power(priv
);
1206 range
->txpower
[0] = get_bcm4320_power(priv
);
1208 len
= sizeof(rates
);
1209 ret
= rndis_query_oid(usbdev
, OID_802_11_SUPPORTED_RATES
, &rates
,
1211 has_80211g_rates
= 0;
1214 for (i
= 0; i
< len
; i
++) {
1217 range
->bitrate
[j
] = (rates
[i
] & 0x7f) * 500000;
1218 /* check for non 802.11b rates */
1219 if (range
->bitrate
[j
] == 6000000 ||
1220 range
->bitrate
[j
] == 9000000 ||
1221 (range
->bitrate
[j
] >= 12000000 &&
1222 range
->bitrate
[j
] != 22000000))
1223 has_80211g_rates
= 1;
1226 range
->num_bitrates
= j
;
1228 range
->num_bitrates
= 0;
1230 /* fill in 802.11g rates */
1231 if (has_80211g_rates
) {
1232 num
= range
->num_bitrates
;
1233 for (i
= 4; i
< ARRAY_SIZE(rndis_rates
); i
++) {
1234 for (j
= 0; j
< num
; j
++) {
1235 if (range
->bitrate
[j
] ==
1236 rndis_rates
[i
].bitrate
* 100000)
1240 range
->bitrate
[range
->num_bitrates
++] =
1241 rndis_rates
[i
].bitrate
* 100000;
1242 if (range
->num_bitrates
== IW_MAX_BITRATES
)
1246 /* estimated max real througput in bps */
1247 range
->throughput
= 54 * 1000 * 1000 / 2;
1249 /* ~35% more with afterburner */
1250 if (priv
->param_afterburner
)
1251 range
->throughput
= range
->throughput
/ 100 * 135;
1253 /* estimated max real througput in bps */
1254 range
->throughput
= 11 * 1000 * 1000 / 2;
1257 range
->num_channels
= 14;
1259 for (i
= 0; (i
< 14) && (i
< IW_MAX_FREQUENCIES
); i
++) {
1260 range
->freq
[i
].i
= i
+ 1;
1261 range
->freq
[i
].m
= ieee80211_dsss_chan_to_freq(i
+ 1) * 100000;
1262 range
->freq
[i
].e
= 1;
1264 range
->num_frequency
= i
;
1267 range
->max_rts
= 2347;
1268 range
->min_frag
= 256;
1269 range
->max_frag
= 2346;
1271 range
->max_qual
.qual
= 100;
1272 range
->max_qual
.level
= 154;
1273 range
->max_qual
.updated
= IW_QUAL_QUAL_UPDATED
1274 | IW_QUAL_LEVEL_UPDATED
1275 | IW_QUAL_NOISE_INVALID
;
1277 range
->we_version_compiled
= WIRELESS_EXT
;
1278 range
->we_version_source
= WIRELESS_EXT
;
1280 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
1281 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
1286 static int rndis_iw_set_essid(struct net_device
*dev
,
1287 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *essid
)
1289 struct ndis_80211_ssid ssid
;
1290 int length
= wrqu
->essid
.length
;
1291 struct usbnet
*usbdev
= netdev_priv(dev
);
1293 devdbg(usbdev
, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1294 wrqu
->essid
.flags
, wrqu
->essid
.length
, essid
);
1296 if (length
> NDIS_802_11_LENGTH_SSID
)
1297 length
= NDIS_802_11_LENGTH_SSID
;
1299 ssid
.length
= cpu_to_le32(length
);
1301 memcpy(ssid
.essid
, essid
, length
);
1303 memset(ssid
.essid
, 0, NDIS_802_11_LENGTH_SSID
);
1305 set_assoc_params(usbdev
);
1307 if (!wrqu
->essid
.flags
|| length
== 0)
1308 return disassociate(usbdev
, 1);
1310 return set_essid(usbdev
, &ssid
);
1314 static int rndis_iw_get_essid(struct net_device
*dev
,
1315 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *essid
)
1317 struct ndis_80211_ssid ssid
;
1318 struct usbnet
*usbdev
= netdev_priv(dev
);
1321 ret
= get_essid(usbdev
, &ssid
);
1323 if (ret
== 0 && le32_to_cpu(ssid
.length
) > 0) {
1324 wrqu
->essid
.flags
= 1;
1325 wrqu
->essid
.length
= le32_to_cpu(ssid
.length
);
1326 memcpy(essid
, ssid
.essid
, wrqu
->essid
.length
);
1327 essid
[wrqu
->essid
.length
] = 0;
1329 memset(essid
, 0, sizeof(NDIS_802_11_LENGTH_SSID
));
1330 wrqu
->essid
.flags
= 0;
1331 wrqu
->essid
.length
= 0;
1333 devdbg(usbdev
, "SIOCGIWESSID: %s", essid
);
1338 static int rndis_iw_get_bssid(struct net_device
*dev
,
1339 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1341 struct usbnet
*usbdev
= netdev_priv(dev
);
1342 unsigned char bssid
[ETH_ALEN
];
1345 ret
= get_bssid(usbdev
, bssid
);
1348 devdbg(usbdev
, "SIOCGIWAP: %pM", bssid
);
1350 devdbg(usbdev
, "SIOCGIWAP: <not associated>");
1352 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1353 memcpy(wrqu
->ap_addr
.sa_data
, bssid
, ETH_ALEN
);
1359 static int rndis_iw_set_bssid(struct net_device
*dev
,
1360 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1362 struct usbnet
*usbdev
= netdev_priv(dev
);
1363 u8
*bssid
= (u8
*)wrqu
->ap_addr
.sa_data
;
1366 devdbg(usbdev
, "SIOCSIWAP: %pM", bssid
);
1368 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID
, bssid
, ETH_ALEN
);
1370 /* user apps may set ap's mac address, which is not required;
1371 * they may fail to work if this function fails, so return
1374 devwarn(usbdev
, "setting AP mac address failed (%08X)", ret
);
1380 static int rndis_iw_set_auth(struct net_device
*dev
,
1381 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1383 struct iw_param
*p
= &wrqu
->param
;
1384 struct usbnet
*usbdev
= netdev_priv(dev
);
1385 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1386 int ret
= -ENOTSUPP
;
1388 switch (p
->flags
& IW_AUTH_INDEX
) {
1389 case IW_AUTH_WPA_VERSION
:
1390 devdbg(usbdev
, "SIOCSIWAUTH: WPA_VERSION, %08x", p
->value
);
1391 priv
->wpa_version
= p
->value
;
1395 case IW_AUTH_CIPHER_PAIRWISE
:
1396 devdbg(usbdev
, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p
->value
);
1397 priv
->wpa_cipher_pair
= p
->value
;
1401 case IW_AUTH_CIPHER_GROUP
:
1402 devdbg(usbdev
, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p
->value
);
1403 priv
->wpa_cipher_group
= p
->value
;
1407 case IW_AUTH_KEY_MGMT
:
1408 devdbg(usbdev
, "SIOCSIWAUTH: KEY_MGMT, %08x", p
->value
);
1409 priv
->wpa_keymgmt
= p
->value
;
1413 case IW_AUTH_TKIP_COUNTERMEASURES
:
1414 devdbg(usbdev
, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1419 case IW_AUTH_DROP_UNENCRYPTED
:
1420 devdbg(usbdev
, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p
->value
);
1424 case IW_AUTH_80211_AUTH_ALG
:
1425 devdbg(usbdev
, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p
->value
);
1426 priv
->wpa_authalg
= p
->value
;
1430 case IW_AUTH_WPA_ENABLED
:
1431 devdbg(usbdev
, "SIOCSIWAUTH: WPA_ENABLED, %08x", p
->value
);
1432 if (wrqu
->param
.value
)
1433 deauthenticate(usbdev
);
1437 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1438 devdbg(usbdev
, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1443 case IW_AUTH_ROAMING_CONTROL
:
1444 devdbg(usbdev
, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p
->value
);
1448 case IW_AUTH_PRIVACY_INVOKED
:
1449 devdbg(usbdev
, "SIOCSIWAUTH: invalid cmd %d",
1450 wrqu
->param
.flags
& IW_AUTH_INDEX
);
1454 devdbg(usbdev
, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1455 p
->flags
& IW_AUTH_INDEX
, p
->value
);
1461 static int rndis_iw_get_auth(struct net_device
*dev
,
1462 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1464 struct iw_param
*p
= &wrqu
->param
;
1465 struct usbnet
*usbdev
= netdev_priv(dev
);
1466 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1468 switch (p
->flags
& IW_AUTH_INDEX
) {
1469 case IW_AUTH_WPA_VERSION
:
1470 p
->value
= priv
->wpa_version
;
1472 case IW_AUTH_CIPHER_PAIRWISE
:
1473 p
->value
= priv
->wpa_cipher_pair
;
1475 case IW_AUTH_CIPHER_GROUP
:
1476 p
->value
= priv
->wpa_cipher_group
;
1478 case IW_AUTH_KEY_MGMT
:
1479 p
->value
= priv
->wpa_keymgmt
;
1481 case IW_AUTH_80211_AUTH_ALG
:
1482 p
->value
= priv
->wpa_authalg
;
1485 devdbg(usbdev
, "SIOCGIWAUTH: invalid cmd %d",
1486 wrqu
->param
.flags
& IW_AUTH_INDEX
);
1493 static int rndis_iw_set_encode(struct net_device
*dev
,
1494 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1496 struct usbnet
*usbdev
= netdev_priv(dev
);
1497 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1498 int ret
, index
, key_len
;
1501 index
= (wrqu
->encoding
.flags
& IW_ENCODE_INDEX
);
1503 /* iwconfig gives index as 1 - N */
1507 index
= priv
->encr_tx_key_index
;
1509 if (index
< 0 || index
>= 4) {
1510 devwarn(usbdev
, "encryption index out of range (%u)", index
);
1514 /* remove key if disabled */
1515 if (wrqu
->data
.flags
& IW_ENCODE_DISABLED
) {
1516 if (remove_key(usbdev
, index
, NULL
))
1522 /* global encryption state (for all keys) */
1523 if (wrqu
->data
.flags
& IW_ENCODE_OPEN
)
1524 ret
= set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
1525 IW_AUTH_ALG_OPEN_SYSTEM
);
1526 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1527 ret
= set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
1528 IW_AUTH_ALG_SHARED_KEY
);
1532 if (wrqu
->data
.length
> 0) {
1533 key_len
= wrqu
->data
.length
;
1536 /* must be set as tx key */
1537 if (priv
->encr_key_len
[index
] == 0)
1539 key_len
= priv
->encr_key_len
[index
];
1540 key
= priv
->encr_keys
[index
];
1541 priv
->encr_tx_key_index
= index
;
1544 if (add_wep_key(usbdev
, key
, key_len
, index
) != 0)
1547 if (index
== priv
->encr_tx_key_index
)
1548 /* ndis drivers want essid to be set after setting encr */
1549 set_essid(usbdev
, &priv
->essid
);
1555 static int rndis_iw_set_encode_ext(struct net_device
*dev
,
1556 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1558 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1559 struct usbnet
*usbdev
= netdev_priv(dev
);
1560 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1561 struct ndis_80211_key ndis_key
;
1565 keyidx
= wrqu
->encoding
.flags
& IW_ENCODE_INDEX
;
1567 /* iwconfig gives index as 1 - N */
1571 keyidx
= priv
->encr_tx_key_index
;
1573 if (keyidx
< 0 || keyidx
>= 4)
1576 if (ext
->alg
== WPA_ALG_WEP
) {
1577 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1578 priv
->encr_tx_key_index
= keyidx
;
1579 return add_wep_key(usbdev
, ext
->key
, ext
->key_len
, keyidx
);
1582 if ((wrqu
->encoding
.flags
& IW_ENCODE_DISABLED
) ||
1583 ext
->alg
== IW_ENCODE_ALG_NONE
|| ext
->key_len
== 0)
1584 return remove_key(usbdev
, keyidx
, NULL
);
1586 if (ext
->key_len
> sizeof(ndis_key
.material
))
1589 memset(&ndis_key
, 0, sizeof(ndis_key
));
1591 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
) -
1592 sizeof(ndis_key
.material
) + ext
->key_len
);
1593 ndis_key
.length
= cpu_to_le32(ext
->key_len
);
1594 ndis_key
.index
= cpu_to_le32(keyidx
);
1596 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1597 memcpy(ndis_key
.rsc
, ext
->rx_seq
, 6);
1598 ndis_key
.index
|= cpu_to_le32(1 << 29);
1601 addr
= ext
->addr
.sa_data
;
1602 if (ext
->ext_flags
& IW_ENCODE_EXT_GROUP_KEY
) {
1604 if (priv
->infra_mode
== ndis_80211_infra_adhoc
)
1605 memset(ndis_key
.bssid
, 0xff, ETH_ALEN
);
1607 get_bssid(usbdev
, ndis_key
.bssid
);
1610 ndis_key
.index
|= cpu_to_le32(1 << 30);
1611 memcpy(ndis_key
.bssid
, addr
, ETH_ALEN
);
1614 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1615 ndis_key
.index
|= cpu_to_le32(1 << 31);
1617 if (ext
->alg
== IW_ENCODE_ALG_TKIP
&& ext
->key_len
== 32) {
1618 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1619 * different order than NDIS spec, so swap the order here. */
1620 memcpy(ndis_key
.material
, ext
->key
, 16);
1621 memcpy(ndis_key
.material
+ 16, ext
->key
+ 24, 8);
1622 memcpy(ndis_key
.material
+ 24, ext
->key
+ 16, 8);
1624 memcpy(ndis_key
.material
, ext
->key
, ext
->key_len
);
1626 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_KEY
, &ndis_key
,
1627 le32_to_cpu(ndis_key
.size
));
1628 devdbg(usbdev
, "SIOCSIWENCODEEXT: OID_802_11_ADD_KEY -> %08X", ret
);
1632 priv
->encr_key_len
[keyidx
] = ext
->key_len
;
1633 memcpy(&priv
->encr_keys
[keyidx
], ndis_key
.material
, ext
->key_len
);
1634 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1635 priv
->encr_tx_key_index
= keyidx
;
1641 static int rndis_iw_set_scan(struct net_device
*dev
,
1642 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1644 struct usbnet
*usbdev
= netdev_priv(dev
);
1645 union iwreq_data evt
;
1649 devdbg(usbdev
, "SIOCSIWSCAN");
1651 if (wrqu
->data
.flags
== 0) {
1652 tmp
= cpu_to_le32(1);
1653 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
1656 evt
.data
.length
= 0;
1657 wireless_send_event(dev
, SIOCGIWSCAN
, &evt
, NULL
);
1663 static char *rndis_translate_scan(struct net_device
*dev
,
1664 struct iw_request_info
*info
, char *cev
,
1666 struct ndis_80211_bssid_ex
*bssid
)
1668 struct usbnet
*usbdev
= netdev_priv(dev
);
1671 int bssid_len
, ie_len
, i
;
1673 struct iw_event iwe
;
1674 unsigned char sbuf
[32];
1676 bssid_len
= le32_to_cpu(bssid
->length
);
1678 devdbg(usbdev
, "BSSID %pM", bssid
->mac
);
1679 iwe
.cmd
= SIOCGIWAP
;
1680 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1681 memcpy(iwe
.u
.ap_addr
.sa_data
, bssid
->mac
, ETH_ALEN
);
1682 cev
= iwe_stream_add_event(info
, cev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
1684 devdbg(usbdev
, "SSID(%d) %s", le32_to_cpu(bssid
->ssid
.length
),
1686 iwe
.cmd
= SIOCGIWESSID
;
1687 iwe
.u
.essid
.length
= le32_to_cpu(bssid
->ssid
.length
);
1688 iwe
.u
.essid
.flags
= 1;
1689 cev
= iwe_stream_add_point(info
, cev
, end_buf
, &iwe
, bssid
->ssid
.essid
);
1691 devdbg(usbdev
, "MODE %d", le32_to_cpu(bssid
->net_infra
));
1692 iwe
.cmd
= SIOCGIWMODE
;
1693 switch (le32_to_cpu(bssid
->net_infra
)) {
1694 case ndis_80211_infra_adhoc
:
1695 iwe
.u
.mode
= IW_MODE_ADHOC
;
1697 case ndis_80211_infra_infra
:
1698 iwe
.u
.mode
= IW_MODE_INFRA
;
1700 /*case ndis_80211_infra_auto_unknown:*/
1702 iwe
.u
.mode
= IW_MODE_AUTO
;
1705 cev
= iwe_stream_add_event(info
, cev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
1707 devdbg(usbdev
, "FREQ %d kHz", le32_to_cpu(bssid
->config
.ds_config
));
1708 iwe
.cmd
= SIOCGIWFREQ
;
1709 dsconfig_to_freq(le32_to_cpu(bssid
->config
.ds_config
), &iwe
.u
.freq
);
1710 cev
= iwe_stream_add_event(info
, cev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
1712 devdbg(usbdev
, "QUAL %d", le32_to_cpu(bssid
->rssi
));
1714 iwe
.u
.qual
.qual
= level_to_qual(le32_to_cpu(bssid
->rssi
));
1715 iwe
.u
.qual
.level
= le32_to_cpu(bssid
->rssi
);
1716 iwe
.u
.qual
.updated
= IW_QUAL_QUAL_UPDATED
1717 | IW_QUAL_LEVEL_UPDATED
1718 | IW_QUAL_NOISE_INVALID
;
1719 cev
= iwe_stream_add_event(info
, cev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
1721 devdbg(usbdev
, "ENCODE %d", le32_to_cpu(bssid
->privacy
));
1722 iwe
.cmd
= SIOCGIWENCODE
;
1723 iwe
.u
.data
.length
= 0;
1724 if (le32_to_cpu(bssid
->privacy
) == ndis_80211_priv_accept_all
)
1725 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1727 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1729 cev
= iwe_stream_add_point(info
, cev
, end_buf
, &iwe
, NULL
);
1731 devdbg(usbdev
, "RATES:");
1732 current_val
= cev
+ iwe_stream_lcp_len(info
);
1733 iwe
.cmd
= SIOCGIWRATE
;
1734 for (i
= 0; i
< sizeof(bssid
->rates
); i
++) {
1735 if (bssid
->rates
[i
] & 0x7f) {
1736 iwe
.u
.bitrate
.value
=
1737 ((bssid
->rates
[i
] & 0x7f) *
1739 devdbg(usbdev
, " %d", iwe
.u
.bitrate
.value
);
1740 current_val
= iwe_stream_add_value(info
, cev
,
1741 current_val
, end_buf
, &iwe
,
1746 if ((current_val
- cev
) > iwe_stream_lcp_len(info
))
1749 beacon
= le32_to_cpu(bssid
->config
.beacon_period
);
1750 devdbg(usbdev
, "BCN_INT %d", beacon
);
1751 iwe
.cmd
= IWEVCUSTOM
;
1752 snprintf(sbuf
, sizeof(sbuf
), "bcn_int=%d", beacon
);
1753 iwe
.u
.data
.length
= strlen(sbuf
);
1754 cev
= iwe_stream_add_point(info
, cev
, end_buf
, &iwe
, sbuf
);
1756 atim
= le32_to_cpu(bssid
->config
.atim_window
);
1757 devdbg(usbdev
, "ATIM %d", atim
);
1758 iwe
.cmd
= IWEVCUSTOM
;
1759 snprintf(sbuf
, sizeof(sbuf
), "atim=%u", atim
);
1760 iwe
.u
.data
.length
= strlen(sbuf
);
1761 cev
= iwe_stream_add_point(info
, cev
, end_buf
, &iwe
, sbuf
);
1763 ie
= (void *)(bssid
->ies
+ sizeof(struct ndis_80211_fixed_ies
));
1764 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1765 (int)le32_to_cpu(bssid
->ie_length
));
1766 ie_len
-= sizeof(struct ndis_80211_fixed_ies
);
1767 while (ie_len
>= 2 && 2 + ie
[1] <= ie_len
) {
1768 if ((ie
[0] == WLAN_EID_GENERIC
&& ie
[1] >= 4 &&
1769 memcmp(ie
+ 2, "\x00\x50\xf2\x01", 4) == 0) ||
1770 ie
[0] == WLAN_EID_RSN
) {
1771 devdbg(usbdev
, "IE: WPA%d",
1772 (ie
[0] == WLAN_EID_RSN
) ? 2 : 1);
1773 iwe
.cmd
= IWEVGENIE
;
1774 /* arbitrary cut-off at 64 */
1775 iwe
.u
.data
.length
= min(ie
[1] + 2, 64);
1776 cev
= iwe_stream_add_point(info
, cev
, end_buf
, &iwe
, ie
);
1779 ie_len
-= 2 + ie
[1];
1787 static int rndis_iw_get_scan(struct net_device
*dev
,
1788 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1790 struct usbnet
*usbdev
= netdev_priv(dev
);
1793 struct ndis_80211_bssid_list_ex
*bssid_list
;
1794 struct ndis_80211_bssid_ex
*bssid
;
1795 int ret
= -EINVAL
, len
, count
, bssid_len
;
1797 devdbg(usbdev
, "SIOCGIWSCAN");
1799 len
= CONTROL_BUFFER_SIZE
;
1800 buf
= kmalloc(len
, GFP_KERNEL
);
1806 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
1812 bssid
= bssid_list
->bssid
;
1813 bssid_len
= le32_to_cpu(bssid
->length
);
1814 count
= le32_to_cpu(bssid_list
->num_items
);
1815 devdbg(usbdev
, "SIOCGIWSCAN: %d BSSIDs found", count
);
1817 while (count
&& ((void *)bssid
+ bssid_len
) <= (buf
+ len
)) {
1818 cev
= rndis_translate_scan(dev
, info
, cev
,
1819 extra
+ IW_SCAN_MAX_DATA
, bssid
);
1820 bssid
= (void *)bssid
+ bssid_len
;
1821 bssid_len
= le32_to_cpu(bssid
->length
);
1826 wrqu
->data
.length
= cev
- extra
;
1827 wrqu
->data
.flags
= 0;
1833 static int rndis_iw_set_genie(struct net_device
*dev
,
1834 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1836 struct usbnet
*usbdev
= netdev_priv(dev
);
1837 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1843 for (j
= 0; j
< wrqu
->data
.length
; j
+= 8)
1845 "SIOCSIWGENIE %04x - "
1846 "%02x %02x %02x %02x %02x %02x %02x %02x", j
,
1847 gie
[j
+ 0], gie
[j
+ 1], gie
[j
+ 2], gie
[j
+ 3],
1848 gie
[j
+ 4], gie
[j
+ 5], gie
[j
+ 6], gie
[j
+ 7]);
1850 /* clear existing IEs */
1851 if (priv
->wpa_ie_len
) {
1852 kfree(priv
->wpa_ie
);
1853 priv
->wpa_ie_len
= 0;
1857 priv
->wpa_ie
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
1859 priv
->wpa_ie_len
= wrqu
->data
.length
;
1860 memcpy(priv
->wpa_ie
, extra
, priv
->wpa_ie_len
);
1867 static int rndis_iw_get_genie(struct net_device
*dev
,
1868 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1870 struct usbnet
*usbdev
= netdev_priv(dev
);
1871 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1873 devdbg(usbdev
, "SIOCGIWGENIE");
1875 if (priv
->wpa_ie_len
== 0 || priv
->wpa_ie
== NULL
) {
1876 wrqu
->data
.length
= 0;
1880 if (wrqu
->data
.length
< priv
->wpa_ie_len
)
1883 wrqu
->data
.length
= priv
->wpa_ie_len
;
1884 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
1890 static int rndis_iw_set_rts(struct net_device
*dev
,
1891 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1893 struct usbnet
*usbdev
= netdev_priv(dev
);
1895 devdbg(usbdev
, "SIOCSIWRTS");
1897 tmp
= cpu_to_le32(wrqu
->rts
.value
);
1898 return rndis_set_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
,
1903 static int rndis_iw_get_rts(struct net_device
*dev
,
1904 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1906 struct usbnet
*usbdev
= netdev_priv(dev
);
1911 ret
= rndis_query_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
, &len
);
1913 wrqu
->rts
.value
= le32_to_cpu(tmp
);
1914 wrqu
->rts
.flags
= 1;
1915 wrqu
->rts
.disabled
= 0;
1918 devdbg(usbdev
, "SIOCGIWRTS: %d", wrqu
->rts
.value
);
1924 static int rndis_iw_set_frag(struct net_device
*dev
,
1925 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1927 struct usbnet
*usbdev
= netdev_priv(dev
);
1930 devdbg(usbdev
, "SIOCSIWFRAG");
1932 tmp
= cpu_to_le32(wrqu
->frag
.value
);
1933 return rndis_set_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1938 static int rndis_iw_get_frag(struct net_device
*dev
,
1939 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1941 struct usbnet
*usbdev
= netdev_priv(dev
);
1946 ret
= rndis_query_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1949 wrqu
->frag
.value
= le32_to_cpu(tmp
);
1950 wrqu
->frag
.flags
= 1;
1951 wrqu
->frag
.disabled
= 0;
1953 devdbg(usbdev
, "SIOCGIWFRAG: %d", wrqu
->frag
.value
);
1958 static int rndis_iw_set_nick(struct net_device
*dev
,
1959 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1961 struct usbnet
*usbdev
= netdev_priv(dev
);
1962 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1964 devdbg(usbdev
, "SIOCSIWNICK");
1966 priv
->nick_len
= wrqu
->data
.length
;
1967 if (priv
->nick_len
> 32)
1968 priv
->nick_len
= 32;
1970 memcpy(priv
->nick
, extra
, priv
->nick_len
);
1975 static int rndis_iw_get_nick(struct net_device
*dev
,
1976 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1978 struct usbnet
*usbdev
= netdev_priv(dev
);
1979 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
1981 wrqu
->data
.flags
= 1;
1982 wrqu
->data
.length
= priv
->nick_len
;
1983 memcpy(extra
, priv
->nick
, priv
->nick_len
);
1985 devdbg(usbdev
, "SIOCGIWNICK: '%s'", priv
->nick
);
1991 static int rndis_iw_set_freq(struct net_device
*dev
,
1992 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1994 struct usbnet
*usbdev
= netdev_priv(dev
);
1995 struct ndis_80211_conf config
;
1996 unsigned int dsconfig
;
1999 /* this OID is valid only when not associated */
2000 if (is_associated(usbdev
))
2004 if (freq_to_dsconfig(&wrqu
->freq
, &dsconfig
))
2007 len
= sizeof(config
);
2008 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
2010 devdbg(usbdev
, "SIOCSIWFREQ: querying configuration failed");
2014 config
.ds_config
= cpu_to_le32(dsconfig
);
2016 devdbg(usbdev
, "SIOCSIWFREQ: %d * 10^%d", wrqu
->freq
.m
, wrqu
->freq
.e
);
2017 return rndis_set_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
,
2022 static int rndis_iw_get_freq(struct net_device
*dev
,
2023 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2025 struct usbnet
*usbdev
= netdev_priv(dev
);
2026 struct ndis_80211_conf config
;
2029 len
= sizeof(config
);
2030 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
2032 dsconfig_to_freq(le32_to_cpu(config
.ds_config
), &wrqu
->freq
);
2034 devdbg(usbdev
, "SIOCGIWFREQ: %d", wrqu
->freq
.m
);
2039 static int rndis_iw_get_txpower(struct net_device
*dev
,
2040 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2042 struct usbnet
*usbdev
= netdev_priv(dev
);
2043 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2047 if (priv
->radio_on
) {
2048 if (priv
->caps
& CAP_SUPPORT_TXPOWER
) {
2049 len
= sizeof(tx_power
);
2050 ret
= rndis_query_oid(usbdev
, OID_802_11_TX_POWER_LEVEL
,
2055 /* fake incase not supported */
2056 tx_power
= cpu_to_le32(get_bcm4320_power(priv
));
2058 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
2059 wrqu
->txpower
.value
= le32_to_cpu(tx_power
);
2060 wrqu
->txpower
.disabled
= 0;
2062 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
2063 wrqu
->txpower
.value
= 0;
2064 wrqu
->txpower
.disabled
= 1;
2067 devdbg(usbdev
, "SIOCGIWTXPOW: %d", wrqu
->txpower
.value
);
2073 static int rndis_iw_set_txpower(struct net_device
*dev
,
2074 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2076 struct usbnet
*usbdev
= netdev_priv(dev
);
2077 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2078 __le32 tx_power
= 0;
2081 if (!wrqu
->txpower
.disabled
) {
2082 if (wrqu
->txpower
.flags
== IW_TXPOW_MWATT
)
2083 tx_power
= cpu_to_le32(wrqu
->txpower
.value
);
2084 else { /* wrqu->txpower.flags == IW_TXPOW_DBM */
2085 if (wrqu
->txpower
.value
> 20)
2086 tx_power
= cpu_to_le32(128);
2087 else if (wrqu
->txpower
.value
< -43)
2088 tx_power
= cpu_to_le32(127);
2091 tmp
= wrqu
->txpower
.value
;
2094 tx_power
= cpu_to_le32((unsigned char)tmp
);
2099 devdbg(usbdev
, "SIOCSIWTXPOW: %d", le32_to_cpu(tx_power
));
2101 if (le32_to_cpu(tx_power
) != 0) {
2102 if (priv
->caps
& CAP_SUPPORT_TXPOWER
) {
2103 /* turn radio on first */
2104 if (!priv
->radio_on
)
2105 disassociate(usbdev
, 1);
2107 ret
= rndis_set_oid(usbdev
, OID_802_11_TX_POWER_LEVEL
,
2108 &tx_power
, sizeof(tx_power
));
2113 /* txpower unsupported, just turn radio on */
2114 if (!priv
->radio_on
)
2115 return disassociate(usbdev
, 1);
2116 return 0; /* all ready on */
2120 /* tx_power == 0, turn off radio */
2121 return disassociate(usbdev
, 0);
2125 static int rndis_iw_get_rate(struct net_device
*dev
,
2126 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2128 struct usbnet
*usbdev
= netdev_priv(dev
);
2133 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &tmp
, &len
);
2135 wrqu
->bitrate
.value
= le32_to_cpu(tmp
) * 100;
2136 wrqu
->bitrate
.disabled
= 0;
2137 wrqu
->bitrate
.flags
= 1;
2143 static int rndis_iw_set_mlme(struct net_device
*dev
,
2144 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2146 struct usbnet
*usbdev
= netdev_priv(dev
);
2147 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2148 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
2149 unsigned char bssid
[ETH_ALEN
];
2151 get_bssid(usbdev
, bssid
);
2153 if (memcmp(bssid
, mlme
->addr
.sa_data
, ETH_ALEN
))
2156 switch (mlme
->cmd
) {
2157 case IW_MLME_DEAUTH
:
2158 return deauthenticate(usbdev
);
2159 case IW_MLME_DISASSOC
:
2160 return disassociate(usbdev
, priv
->radio_on
);
2169 static struct iw_statistics
*rndis_get_wireless_stats(struct net_device
*dev
)
2171 struct usbnet
*usbdev
= netdev_priv(dev
);
2172 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2173 unsigned long flags
;
2175 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2176 memcpy(&priv
->iwstats
, &priv
->privstats
, sizeof(priv
->iwstats
));
2177 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2179 return &priv
->iwstats
;
2183 #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2184 static const iw_handler rndis_iw_handler
[] =
2186 IW_IOCTL(SIOCSIWCOMMIT
) = rndis_iw_commit
,
2187 IW_IOCTL(SIOCGIWNAME
) = (iw_handler
) cfg80211_wext_giwname
,
2188 IW_IOCTL(SIOCSIWFREQ
) = rndis_iw_set_freq
,
2189 IW_IOCTL(SIOCGIWFREQ
) = rndis_iw_get_freq
,
2190 IW_IOCTL(SIOCSIWMODE
) = (iw_handler
) cfg80211_wext_siwmode
,
2191 IW_IOCTL(SIOCGIWMODE
) = (iw_handler
) cfg80211_wext_giwmode
,
2192 IW_IOCTL(SIOCGIWRANGE
) = rndis_iw_get_range
,
2193 IW_IOCTL(SIOCSIWAP
) = rndis_iw_set_bssid
,
2194 IW_IOCTL(SIOCGIWAP
) = rndis_iw_get_bssid
,
2195 IW_IOCTL(SIOCSIWSCAN
) = rndis_iw_set_scan
,
2196 IW_IOCTL(SIOCGIWSCAN
) = rndis_iw_get_scan
,
2197 IW_IOCTL(SIOCSIWESSID
) = rndis_iw_set_essid
,
2198 IW_IOCTL(SIOCGIWESSID
) = rndis_iw_get_essid
,
2199 IW_IOCTL(SIOCSIWNICKN
) = rndis_iw_set_nick
,
2200 IW_IOCTL(SIOCGIWNICKN
) = rndis_iw_get_nick
,
2201 IW_IOCTL(SIOCGIWRATE
) = rndis_iw_get_rate
,
2202 IW_IOCTL(SIOCSIWRTS
) = rndis_iw_set_rts
,
2203 IW_IOCTL(SIOCGIWRTS
) = rndis_iw_get_rts
,
2204 IW_IOCTL(SIOCSIWFRAG
) = rndis_iw_set_frag
,
2205 IW_IOCTL(SIOCGIWFRAG
) = rndis_iw_get_frag
,
2206 IW_IOCTL(SIOCSIWTXPOW
) = rndis_iw_set_txpower
,
2207 IW_IOCTL(SIOCGIWTXPOW
) = rndis_iw_get_txpower
,
2208 IW_IOCTL(SIOCSIWENCODE
) = rndis_iw_set_encode
,
2209 IW_IOCTL(SIOCSIWENCODEEXT
) = rndis_iw_set_encode_ext
,
2210 IW_IOCTL(SIOCSIWAUTH
) = rndis_iw_set_auth
,
2211 IW_IOCTL(SIOCGIWAUTH
) = rndis_iw_get_auth
,
2212 IW_IOCTL(SIOCSIWGENIE
) = rndis_iw_set_genie
,
2213 IW_IOCTL(SIOCGIWGENIE
) = rndis_iw_get_genie
,
2214 IW_IOCTL(SIOCSIWMLME
) = rndis_iw_set_mlme
,
2217 static const iw_handler rndis_wext_private_handler
[] = {
2220 static const struct iw_priv_args rndis_wext_private_args
[] = {
2224 static const struct iw_handler_def rndis_iw_handlers
= {
2225 .num_standard
= ARRAY_SIZE(rndis_iw_handler
),
2226 .num_private
= ARRAY_SIZE(rndis_wext_private_handler
),
2227 .num_private_args
= ARRAY_SIZE(rndis_wext_private_args
),
2228 .standard
= (iw_handler
*)rndis_iw_handler
,
2229 .private = (iw_handler
*)rndis_wext_private_handler
,
2230 .private_args
= (struct iw_priv_args
*)rndis_wext_private_args
,
2231 .get_wireless_stats
= rndis_get_wireless_stats
,
2235 static void rndis_wext_worker(struct work_struct
*work
)
2237 struct rndis_wext_private
*priv
=
2238 container_of(work
, struct rndis_wext_private
, work
);
2239 struct usbnet
*usbdev
= priv
->usbdev
;
2240 union iwreq_data evt
;
2241 unsigned char bssid
[ETH_ALEN
];
2242 struct ndis_80211_assoc_info
*info
;
2243 int assoc_size
= sizeof(*info
) + IW_CUSTOM_MAX
+ 32;
2246 if (test_and_clear_bit(WORK_LINK_UP
, &priv
->work_pending
)) {
2247 netif_carrier_on(usbdev
->net
);
2249 info
= kzalloc(assoc_size
, GFP_KERNEL
);
2253 /* Get association info IEs from device and send them back to
2255 ret
= get_association_info(usbdev
, info
, assoc_size
);
2257 evt
.data
.length
= le32_to_cpu(info
->req_ie_length
);
2258 if (evt
.data
.length
> 0) {
2259 offset
= le32_to_cpu(info
->offset_req_ies
);
2260 wireless_send_event(usbdev
->net
,
2261 IWEVASSOCREQIE
, &evt
,
2262 (char *)info
+ offset
);
2265 evt
.data
.length
= le32_to_cpu(info
->resp_ie_length
);
2266 if (evt
.data
.length
> 0) {
2267 offset
= le32_to_cpu(info
->offset_resp_ies
);
2268 wireless_send_event(usbdev
->net
,
2269 IWEVASSOCRESPIE
, &evt
,
2270 (char *)info
+ offset
);
2277 ret
= get_bssid(usbdev
, bssid
);
2280 evt
.data
.length
= 0;
2281 memcpy(evt
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
2282 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2286 if (test_and_clear_bit(WORK_LINK_DOWN
, &priv
->work_pending
)) {
2287 netif_carrier_off(usbdev
->net
);
2290 evt
.data
.length
= 0;
2291 memset(evt
.ap_addr
.sa_data
, 0, ETH_ALEN
);
2292 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2295 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2296 set_multicast_list(usbdev
);
2299 static void rndis_wext_set_multicast_list(struct net_device
*dev
)
2301 struct usbnet
*usbdev
= netdev_priv(dev
);
2302 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2304 if (test_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2307 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2308 queue_work(priv
->workqueue
, &priv
->work
);
2311 static void rndis_wext_link_change(struct usbnet
*usbdev
, int state
)
2313 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2315 /* queue work to avoid recursive calls into rndis_command */
2316 set_bit(state
? WORK_LINK_UP
: WORK_LINK_DOWN
, &priv
->work_pending
);
2317 queue_work(priv
->workqueue
, &priv
->work
);
2321 static int rndis_wext_get_caps(struct usbnet
*usbdev
)
2326 } networks_supported
;
2327 int len
, retval
, i
, n
;
2329 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2331 /* determine if supports setting txpower */
2332 len
= sizeof(tx_power
);
2333 retval
= rndis_query_oid(usbdev
, OID_802_11_TX_POWER_LEVEL
, &tx_power
,
2335 if (retval
== 0 && le32_to_cpu(tx_power
) != 0xFF)
2336 priv
->caps
|= CAP_SUPPORT_TXPOWER
;
2338 /* determine supported modes */
2339 len
= sizeof(networks_supported
);
2340 retval
= rndis_query_oid(usbdev
, OID_802_11_NETWORK_TYPES_SUPPORTED
,
2341 &networks_supported
, &len
);
2343 n
= le32_to_cpu(networks_supported
.num_items
);
2346 for (i
= 0; i
< n
; i
++) {
2347 switch (le32_to_cpu(networks_supported
.items
[i
])) {
2348 case ndis_80211_type_freq_hop
:
2349 case ndis_80211_type_direct_seq
:
2350 priv
->caps
|= CAP_MODE_80211B
;
2352 case ndis_80211_type_ofdm_a
:
2353 priv
->caps
|= CAP_MODE_80211A
;
2355 case ndis_80211_type_ofdm_g
:
2356 priv
->caps
|= CAP_MODE_80211G
;
2366 #define STATS_UPDATE_JIFFIES (HZ)
2367 static void rndis_update_wireless_stats(struct work_struct
*work
)
2369 struct rndis_wext_private
*priv
=
2370 container_of(work
, struct rndis_wext_private
, stats_work
.work
);
2371 struct usbnet
*usbdev
= priv
->usbdev
;
2372 struct iw_statistics iwstats
;
2375 unsigned long flags
;
2376 int update_jiffies
= STATS_UPDATE_JIFFIES
;
2379 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2380 memcpy(&iwstats
, &priv
->privstats
, sizeof(iwstats
));
2381 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2383 /* only update stats when connected */
2384 if (!is_associated(usbdev
)) {
2385 iwstats
.qual
.qual
= 0;
2386 iwstats
.qual
.level
= 0;
2387 iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2388 | IW_QUAL_LEVEL_UPDATED
2389 | IW_QUAL_NOISE_INVALID
2390 | IW_QUAL_QUAL_INVALID
2391 | IW_QUAL_LEVEL_INVALID
;
2396 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2398 devdbg(usbdev
, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret
,
2401 memset(&iwstats
.qual
, 0, sizeof(iwstats
.qual
));
2402 iwstats
.qual
.qual
= level_to_qual(le32_to_cpu(rssi
));
2403 iwstats
.qual
.level
= le32_to_cpu(rssi
);
2404 iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2405 | IW_QUAL_LEVEL_UPDATED
2406 | IW_QUAL_NOISE_INVALID
;
2409 memset(&iwstats
.discard
, 0, sizeof(iwstats
.discard
));
2412 ret
= rndis_query_oid(usbdev
, OID_GEN_XMIT_ERROR
, &tmp
, &len
);
2414 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2417 ret
= rndis_query_oid(usbdev
, OID_GEN_RCV_ERROR
, &tmp
, &len
);
2419 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2422 ret
= rndis_query_oid(usbdev
, OID_GEN_RCV_NO_BUFFER
, &tmp
, &len
);
2424 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2426 /* Workaround transfer stalls on poor quality links.
2427 * TODO: find right way to fix these stalls (as stalls do not happen
2428 * with ndiswrapper/windows driver). */
2429 if (iwstats
.qual
.qual
<= 25) {
2430 /* Decrease stats worker interval to catch stalls.
2431 * faster. Faster than 400-500ms causes packet loss,
2432 * Slower doesn't catch stalls fast enough.
2434 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
2435 if (j
> STATS_UPDATE_JIFFIES
)
2436 j
= STATS_UPDATE_JIFFIES
;
2441 /* Send scan OID. Use of both OIDs is required to get device
2444 tmp
= cpu_to_le32(1);
2445 rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
2448 len
= CONTROL_BUFFER_SIZE
;
2449 buf
= kmalloc(len
, GFP_KERNEL
);
2453 rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2457 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2458 memcpy(&priv
->privstats
, &iwstats
, sizeof(iwstats
));
2459 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2461 if (update_jiffies
>= HZ
)
2462 update_jiffies
= round_jiffies_relative(update_jiffies
);
2464 j
= round_jiffies_relative(update_jiffies
);
2465 if (abs(j
- update_jiffies
) <= 10)
2469 queue_delayed_work(priv
->workqueue
, &priv
->stats_work
, update_jiffies
);
2473 static int bcm4320_early_init(struct usbnet
*usbdev
)
2475 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2478 /* Early initialization settings, setting these won't have effect
2479 * if called after generic_rndis_bind().
2482 priv
->param_country
[0] = modparam_country
[0];
2483 priv
->param_country
[1] = modparam_country
[1];
2484 priv
->param_country
[2] = 0;
2485 priv
->param_frameburst
= modparam_frameburst
;
2486 priv
->param_afterburner
= modparam_afterburner
;
2487 priv
->param_power_save
= modparam_power_save
;
2488 priv
->param_power_output
= modparam_power_output
;
2489 priv
->param_roamtrigger
= modparam_roamtrigger
;
2490 priv
->param_roamdelta
= modparam_roamdelta
;
2492 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
2493 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
2494 /* doesn't support EU as country code, use FI instead */
2495 if (!strcmp(priv
->param_country
, "EU"))
2496 strcpy(priv
->param_country
, "FI");
2498 if (priv
->param_power_save
< 0)
2499 priv
->param_power_save
= 0;
2500 else if (priv
->param_power_save
> 2)
2501 priv
->param_power_save
= 2;
2503 if (priv
->param_power_output
< 0)
2504 priv
->param_power_output
= 0;
2505 else if (priv
->param_power_output
> 3)
2506 priv
->param_power_output
= 3;
2508 if (priv
->param_roamtrigger
< -80)
2509 priv
->param_roamtrigger
= -80;
2510 else if (priv
->param_roamtrigger
> -60)
2511 priv
->param_roamtrigger
= -60;
2513 if (priv
->param_roamdelta
< 0)
2514 priv
->param_roamdelta
= 0;
2515 else if (priv
->param_roamdelta
> 2)
2516 priv
->param_roamdelta
= 2;
2518 if (modparam_workaround_interval
< 0)
2519 priv
->param_workaround_interval
= 500;
2521 priv
->param_workaround_interval
= modparam_workaround_interval
;
2523 rndis_set_config_parameter_str(usbdev
, "Country", priv
->param_country
);
2524 rndis_set_config_parameter_str(usbdev
, "FrameBursting",
2525 priv
->param_frameburst
? "1" : "0");
2526 rndis_set_config_parameter_str(usbdev
, "Afterburner",
2527 priv
->param_afterburner
? "1" : "0");
2528 sprintf(buf
, "%d", priv
->param_power_save
);
2529 rndis_set_config_parameter_str(usbdev
, "PowerSaveMode", buf
);
2530 sprintf(buf
, "%d", priv
->param_power_output
);
2531 rndis_set_config_parameter_str(usbdev
, "PwrOut", buf
);
2532 sprintf(buf
, "%d", priv
->param_roamtrigger
);
2533 rndis_set_config_parameter_str(usbdev
, "RoamTrigger", buf
);
2534 sprintf(buf
, "%d", priv
->param_roamdelta
);
2535 rndis_set_config_parameter_str(usbdev
, "RoamDelta", buf
);
2540 /* same as rndis_netdev_ops but with local multicast handler */
2541 static const struct net_device_ops rndis_wext_netdev_ops
= {
2542 .ndo_open
= usbnet_open
,
2543 .ndo_stop
= usbnet_stop
,
2544 .ndo_start_xmit
= usbnet_start_xmit
,
2545 .ndo_tx_timeout
= usbnet_tx_timeout
,
2546 .ndo_set_mac_address
= eth_mac_addr
,
2547 .ndo_validate_addr
= eth_validate_addr
,
2548 .ndo_set_multicast_list
= rndis_wext_set_multicast_list
,
2552 static int rndis_wext_bind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2554 struct wiphy
*wiphy
;
2555 struct rndis_wext_private
*priv
;
2559 /* allocate wiphy and rndis private data
2560 * NOTE: We only support a single virtual interface, so wiphy
2561 * and wireless_dev are somewhat synonymous for this device.
2563 wiphy
= wiphy_new(&rndis_config_ops
, sizeof(struct rndis_wext_private
));
2567 priv
= wiphy_priv(wiphy
);
2568 usbdev
->net
->ieee80211_ptr
= &priv
->wdev
;
2569 priv
->wdev
.wiphy
= wiphy
;
2570 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
2572 /* These have to be initialized before calling generic_rndis_bind().
2573 * Otherwise we'll be in big trouble in rndis_wext_early_init().
2575 usbdev
->driver_priv
= priv
;
2576 usbdev
->net
->wireless_handlers
= &rndis_iw_handlers
;
2577 priv
->usbdev
= usbdev
;
2579 mutex_init(&priv
->command_lock
);
2580 spin_lock_init(&priv
->stats_lock
);
2582 /* try bind rndis_host */
2583 retval
= generic_rndis_bind(usbdev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
2587 /* generic_rndis_bind set packet filter to multicast_all+
2588 * promisc mode which doesn't work well for our devices (device
2589 * picks up rssi to closest station instead of to access point).
2591 * rndis_host wants to avoid all OID as much as possible
2592 * so do promisc/multicast handling in rndis_wext.
2594 usbdev
->net
->netdev_ops
= &rndis_wext_netdev_ops
;
2596 tmp
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
2597 retval
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &tmp
,
2601 retval
= rndis_query_oid(usbdev
, OID_802_3_MAXIMUM_LIST_SIZE
, &tmp
,
2603 priv
->multicast_size
= le32_to_cpu(tmp
);
2604 if (retval
< 0 || priv
->multicast_size
< 0)
2605 priv
->multicast_size
= 0;
2606 if (priv
->multicast_size
> 0)
2607 usbdev
->net
->flags
|= IFF_MULTICAST
;
2609 usbdev
->net
->flags
&= ~IFF_MULTICAST
;
2611 priv
->iwstats
.qual
.qual
= 0;
2612 priv
->iwstats
.qual
.level
= 0;
2613 priv
->iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2614 | IW_QUAL_LEVEL_UPDATED
2615 | IW_QUAL_NOISE_INVALID
2616 | IW_QUAL_QUAL_INVALID
2617 | IW_QUAL_LEVEL_INVALID
;
2619 /* fill-out wiphy structure and register w/ cfg80211 */
2620 memcpy(wiphy
->perm_addr
, usbdev
->net
->dev_addr
, ETH_ALEN
);
2621 wiphy
->privid
= rndis_wiphy_privid
;
2622 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
2623 | BIT(NL80211_IFTYPE_ADHOC
);
2624 wiphy
->max_scan_ssids
= 1;
2626 /* TODO: fill-out band information based on priv->caps */
2627 rndis_wext_get_caps(usbdev
);
2629 memcpy(priv
->channels
, rndis_channels
, sizeof(rndis_channels
));
2630 memcpy(priv
->rates
, rndis_rates
, sizeof(rndis_rates
));
2631 priv
->band
.channels
= priv
->channels
;
2632 priv
->band
.n_channels
= ARRAY_SIZE(rndis_channels
);
2633 priv
->band
.bitrates
= priv
->rates
;
2634 priv
->band
.n_bitrates
= ARRAY_SIZE(rndis_rates
);
2635 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
2637 set_wiphy_dev(wiphy
, &usbdev
->udev
->dev
);
2639 if (wiphy_register(wiphy
)) {
2644 set_default_iw_params(usbdev
);
2648 disassociate(usbdev
, 1);
2649 netif_carrier_off(usbdev
->net
);
2651 /* because rndis_command() sleeps we need to use workqueue */
2652 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
2653 INIT_DELAYED_WORK(&priv
->stats_work
, rndis_update_wireless_stats
);
2654 queue_delayed_work(priv
->workqueue
, &priv
->stats_work
,
2655 round_jiffies_relative(STATS_UPDATE_JIFFIES
));
2656 INIT_WORK(&priv
->work
, rndis_wext_worker
);
2666 static void rndis_wext_unbind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2668 struct rndis_wext_private
*priv
= get_rndis_wext_priv(usbdev
);
2670 /* turn radio off */
2671 disassociate(usbdev
, 0);
2673 cancel_delayed_work_sync(&priv
->stats_work
);
2674 cancel_work_sync(&priv
->work
);
2675 flush_workqueue(priv
->workqueue
);
2676 destroy_workqueue(priv
->workqueue
);
2678 if (priv
&& priv
->wpa_ie_len
)
2679 kfree(priv
->wpa_ie
);
2681 rndis_unbind(usbdev
, intf
);
2683 wiphy_unregister(priv
->wdev
.wiphy
);
2684 wiphy_free(priv
->wdev
.wiphy
);
2688 static int rndis_wext_reset(struct usbnet
*usbdev
)
2690 return deauthenticate(usbdev
);
2694 static const struct driver_info bcm4320b_info
= {
2695 .description
= "Wireless RNDIS device, BCM4320b based",
2696 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
,
2697 .bind
= rndis_wext_bind
,
2698 .unbind
= rndis_wext_unbind
,
2699 .status
= rndis_status
,
2700 .rx_fixup
= rndis_rx_fixup
,
2701 .tx_fixup
= rndis_tx_fixup
,
2702 .reset
= rndis_wext_reset
,
2703 .early_init
= bcm4320_early_init
,
2704 .link_change
= rndis_wext_link_change
,
2707 static const struct driver_info bcm4320a_info
= {
2708 .description
= "Wireless RNDIS device, BCM4320a based",
2709 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
,
2710 .bind
= rndis_wext_bind
,
2711 .unbind
= rndis_wext_unbind
,
2712 .status
= rndis_status
,
2713 .rx_fixup
= rndis_rx_fixup
,
2714 .tx_fixup
= rndis_tx_fixup
,
2715 .reset
= rndis_wext_reset
,
2716 .early_init
= bcm4320_early_init
,
2717 .link_change
= rndis_wext_link_change
,
2720 static const struct driver_info rndis_wext_info
= {
2721 .description
= "Wireless RNDIS device",
2722 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
,
2723 .bind
= rndis_wext_bind
,
2724 .unbind
= rndis_wext_unbind
,
2725 .status
= rndis_status
,
2726 .rx_fixup
= rndis_rx_fixup
,
2727 .tx_fixup
= rndis_tx_fixup
,
2728 .reset
= rndis_wext_reset
,
2729 .early_init
= bcm4320_early_init
,
2730 .link_change
= rndis_wext_link_change
,
2733 /*-------------------------------------------------------------------------*/
2735 static const struct usb_device_id products
[] = {
2736 #define RNDIS_MASTER_INTERFACE \
2737 .bInterfaceClass = USB_CLASS_COMM, \
2738 .bInterfaceSubClass = 2 /* ACM */, \
2739 .bInterfaceProtocol = 0x0ff
2741 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2742 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2745 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2746 | USB_DEVICE_ID_MATCH_DEVICE
,
2748 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
2749 RNDIS_MASTER_INTERFACE
,
2750 .driver_info
= (unsigned long) &bcm4320b_info
,
2752 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2753 | USB_DEVICE_ID_MATCH_DEVICE
,
2755 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
2756 RNDIS_MASTER_INTERFACE
,
2757 .driver_info
= (unsigned long) &bcm4320b_info
,
2759 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2760 | USB_DEVICE_ID_MATCH_DEVICE
,
2762 .idProduct
= 0x011b, /* Belkin F5D7051 */
2763 RNDIS_MASTER_INTERFACE
,
2764 .driver_info
= (unsigned long) &bcm4320b_info
,
2766 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2767 | USB_DEVICE_ID_MATCH_DEVICE
,
2768 .idVendor
= 0x1799, /* Belkin has two vendor ids */
2769 .idProduct
= 0x011b, /* Belkin F5D7051 */
2770 RNDIS_MASTER_INTERFACE
,
2771 .driver_info
= (unsigned long) &bcm4320b_info
,
2773 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2774 | USB_DEVICE_ID_MATCH_DEVICE
,
2776 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
2777 RNDIS_MASTER_INTERFACE
,
2778 .driver_info
= (unsigned long) &bcm4320b_info
,
2780 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2781 | USB_DEVICE_ID_MATCH_DEVICE
,
2783 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
2784 RNDIS_MASTER_INTERFACE
,
2785 .driver_info
= (unsigned long) &bcm4320b_info
,
2787 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2788 | USB_DEVICE_ID_MATCH_DEVICE
,
2790 .idProduct
= 0x1717, /* Asus WL169gE */
2791 RNDIS_MASTER_INTERFACE
,
2792 .driver_info
= (unsigned long) &bcm4320b_info
,
2794 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2795 | USB_DEVICE_ID_MATCH_DEVICE
,
2797 .idProduct
= 0xd11b, /* Eminent EM4045 */
2798 RNDIS_MASTER_INTERFACE
,
2799 .driver_info
= (unsigned long) &bcm4320b_info
,
2801 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2802 | USB_DEVICE_ID_MATCH_DEVICE
,
2804 .idProduct
= 0x0715, /* BT Voyager 1055 */
2805 RNDIS_MASTER_INTERFACE
,
2806 .driver_info
= (unsigned long) &bcm4320b_info
,
2808 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
2809 * parameters available, hardware probably contain older firmware version with
2810 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
2813 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2814 | USB_DEVICE_ID_MATCH_DEVICE
,
2816 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
2817 RNDIS_MASTER_INTERFACE
,
2818 .driver_info
= (unsigned long) &bcm4320a_info
,
2820 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2821 | USB_DEVICE_ID_MATCH_DEVICE
,
2823 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
2824 RNDIS_MASTER_INTERFACE
,
2825 .driver_info
= (unsigned long) &bcm4320a_info
,
2827 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2828 | USB_DEVICE_ID_MATCH_DEVICE
,
2830 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
2831 RNDIS_MASTER_INTERFACE
,
2832 .driver_info
= (unsigned long) &bcm4320a_info
,
2834 /* Generic Wireless RNDIS devices that we don't have exact
2835 * idVendor/idProduct/chip yet.
2838 /* RNDIS is MSFT's un-official variant of CDC ACM */
2839 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
2840 .driver_info
= (unsigned long) &rndis_wext_info
,
2842 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
2843 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
2844 .driver_info
= (unsigned long) &rndis_wext_info
,
2848 MODULE_DEVICE_TABLE(usb
, products
);
2850 static struct usb_driver rndis_wlan_driver
= {
2851 .name
= "rndis_wlan",
2852 .id_table
= products
,
2853 .probe
= usbnet_probe
,
2854 .disconnect
= usbnet_disconnect
,
2855 .suspend
= usbnet_suspend
,
2856 .resume
= usbnet_resume
,
2859 static int __init
rndis_wlan_init(void)
2861 return usb_register(&rndis_wlan_driver
);
2863 module_init(rndis_wlan_init
);
2865 static void __exit
rndis_wlan_exit(void)
2867 usb_deregister(&rndis_wlan_driver
);
2869 module_exit(rndis_wlan_exit
);
2871 MODULE_AUTHOR("Bjorge Dijkstra");
2872 MODULE_AUTHOR("Jussi Kivilinna");
2873 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
2874 MODULE_LICENSE("GPL");