2 * Driver for RNDIS based wireless USB devices.
4 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
5 * Copyright (C) 2008-2009 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/cfg80211.h>
46 #include <linux/usb/usbnet.h>
47 #include <linux/usb/rndis_host.h>
50 /* NOTE: All these are settings for Broadcom chipset */
51 static char modparam_country
[4] = "EU";
52 module_param_string(country
, modparam_country
, 4, 0444);
53 MODULE_PARM_DESC(country
, "Country code (ISO 3166-1 alpha-2), default: EU");
55 static int modparam_frameburst
= 1;
56 module_param_named(frameburst
, modparam_frameburst
, int, 0444);
57 MODULE_PARM_DESC(frameburst
, "enable frame bursting (default: on)");
59 static int modparam_afterburner
= 0;
60 module_param_named(afterburner
, modparam_afterburner
, int, 0444);
61 MODULE_PARM_DESC(afterburner
,
62 "enable afterburner aka '125 High Speed Mode' (default: off)");
64 static int modparam_power_save
= 0;
65 module_param_named(power_save
, modparam_power_save
, int, 0444);
66 MODULE_PARM_DESC(power_save
,
67 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
69 static int modparam_power_output
= 3;
70 module_param_named(power_output
, modparam_power_output
, int, 0444);
71 MODULE_PARM_DESC(power_output
,
72 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
74 static int modparam_roamtrigger
= -70;
75 module_param_named(roamtrigger
, modparam_roamtrigger
, int, 0444);
76 MODULE_PARM_DESC(roamtrigger
,
77 "set roaming dBm trigger: -80=optimize for distance, "
78 "-60=bandwidth (default: -70)");
80 static int modparam_roamdelta
= 1;
81 module_param_named(roamdelta
, modparam_roamdelta
, int, 0444);
82 MODULE_PARM_DESC(roamdelta
,
83 "set roaming tendency: 0=aggressive, 1=moderate, "
84 "2=conservative (default: moderate)");
86 static int modparam_workaround_interval
= 500;
87 module_param_named(workaround_interval
, modparam_workaround_interval
,
89 MODULE_PARM_DESC(workaround_interval
,
90 "set stall workaround interval in msecs (default: 500)");
93 /* various RNDIS OID defs */
94 #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
95 #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
97 #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101)
98 #define OID_GEN_RCV_OK cpu_to_le32(0x00020102)
99 #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103)
100 #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104)
101 #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105)
103 #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
104 #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
105 #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
107 #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
108 #define OID_802_11_SSID cpu_to_le32(0x0d010102)
109 #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
110 #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
111 #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
112 #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
113 #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
114 #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
115 #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
116 #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
117 #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
118 #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
119 #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
120 #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
121 #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
122 #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
123 #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
124 #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
125 #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
126 #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
127 #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
128 #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
129 #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
130 #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
133 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
134 #define WL_NOISE -96 /* typical noise level in dBm */
135 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
138 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
139 * based on wireless rndis) has default txpower of 13dBm.
140 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
141 * 100% : 20 mW ~ 13dBm
142 * 75% : 15 mW ~ 12dBm
143 * 50% : 10 mW ~ 10dBm
146 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
147 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
148 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
149 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
152 /* codes for "status" field of completion messages */
153 #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
154 #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
157 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
158 * slightly modified for datatype endianess, etc
160 #define NDIS_802_11_LENGTH_SSID 32
161 #define NDIS_802_11_LENGTH_RATES 8
162 #define NDIS_802_11_LENGTH_RATES_EX 16
164 enum ndis_80211_net_type
{
165 NDIS_80211_TYPE_FREQ_HOP
,
166 NDIS_80211_TYPE_DIRECT_SEQ
,
167 NDIS_80211_TYPE_OFDM_A
,
168 NDIS_80211_TYPE_OFDM_G
171 enum ndis_80211_net_infra
{
172 NDIS_80211_INFRA_ADHOC
,
173 NDIS_80211_INFRA_INFRA
,
174 NDIS_80211_INFRA_AUTO_UNKNOWN
177 enum ndis_80211_auth_mode
{
178 NDIS_80211_AUTH_OPEN
,
179 NDIS_80211_AUTH_SHARED
,
180 NDIS_80211_AUTH_AUTO_SWITCH
,
182 NDIS_80211_AUTH_WPA_PSK
,
183 NDIS_80211_AUTH_WPA_NONE
,
184 NDIS_80211_AUTH_WPA2
,
185 NDIS_80211_AUTH_WPA2_PSK
188 enum ndis_80211_encr_status
{
189 NDIS_80211_ENCR_WEP_ENABLED
,
190 NDIS_80211_ENCR_DISABLED
,
191 NDIS_80211_ENCR_WEP_KEY_ABSENT
,
192 NDIS_80211_ENCR_NOT_SUPPORTED
,
193 NDIS_80211_ENCR_TKIP_ENABLED
,
194 NDIS_80211_ENCR_TKIP_KEY_ABSENT
,
195 NDIS_80211_ENCR_CCMP_ENABLED
,
196 NDIS_80211_ENCR_CCMP_KEY_ABSENT
199 enum ndis_80211_priv_filter
{
200 NDIS_80211_PRIV_ACCEPT_ALL
,
201 NDIS_80211_PRIV_8021X_WEP
204 enum ndis_80211_status_type
{
205 NDIS_80211_STATUSTYPE_AUTHENTICATION
,
206 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
,
207 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
,
208 NDIS_80211_STATUSTYPE_RADIOSTATE
,
211 enum ndis_80211_media_stream_mode
{
212 NDIS_80211_MEDIA_STREAM_OFF
,
213 NDIS_80211_MEDIA_STREAM_ON
216 enum ndis_80211_radio_status
{
217 NDIS_80211_RADIO_STATUS_ON
,
218 NDIS_80211_RADIO_STATUS_HARDWARE_OFF
,
219 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF
,
222 enum ndis_80211_addkey_bits
{
223 NDIS_80211_ADDKEY_8021X_AUTH
= cpu_to_le32(1 << 28),
224 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
= cpu_to_le32(1 << 29),
225 NDIS_80211_ADDKEY_PAIRWISE_KEY
= cpu_to_le32(1 << 30),
226 NDIS_80211_ADDKEY_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
229 enum ndis_80211_addwep_bits
{
230 NDIS_80211_ADDWEP_PERCLIENT_KEY
= cpu_to_le32(1 << 30),
231 NDIS_80211_ADDWEP_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
234 struct ndis_80211_auth_request
{
239 } __attribute__((packed
));
241 struct ndis_80211_pmkid_candidate
{
245 } __attribute__((packed
));
247 struct ndis_80211_pmkid_cand_list
{
249 __le32 num_candidates
;
250 struct ndis_80211_pmkid_candidate candidate_list
[0];
251 } __attribute__((packed
));
253 struct ndis_80211_status_indication
{
256 enum ndis_80211_media_stream_mode media_stream_mode
;
257 enum ndis_80211_radio_status radio_status
;
258 struct ndis_80211_auth_request auth_request
[0];
259 struct ndis_80211_pmkid_cand_list cand_list
;
261 } __attribute__((packed
));
263 struct ndis_80211_ssid
{
265 u8 essid
[NDIS_802_11_LENGTH_SSID
];
266 } __attribute__((packed
));
268 struct ndis_80211_conf_freq_hop
{
273 } __attribute__((packed
));
275 struct ndis_80211_conf
{
277 __le32 beacon_period
;
280 struct ndis_80211_conf_freq_hop fh_config
;
281 } __attribute__((packed
));
283 struct ndis_80211_bssid_ex
{
287 struct ndis_80211_ssid ssid
;
291 struct ndis_80211_conf config
;
293 u8 rates
[NDIS_802_11_LENGTH_RATES_EX
];
296 } __attribute__((packed
));
298 struct ndis_80211_bssid_list_ex
{
300 struct ndis_80211_bssid_ex bssid
[0];
301 } __attribute__((packed
));
303 struct ndis_80211_fixed_ies
{
305 __le16 beacon_interval
;
307 } __attribute__((packed
));
309 struct ndis_80211_wep_key
{
314 } __attribute__((packed
));
316 struct ndis_80211_key
{
324 } __attribute__((packed
));
326 struct ndis_80211_remove_key
{
331 } __attribute__((packed
));
333 struct ndis_config_param
{
339 } __attribute__((packed
));
341 struct ndis_80211_assoc_info
{
346 __le16 listen_interval
;
347 u8 cur_ap_address
[6];
349 __le32 req_ie_length
;
350 __le32 offset_req_ies
;
357 __le32 resp_ie_length
;
358 __le32 offset_resp_ies
;
359 } __attribute__((packed
));
361 /* these have to match what is in wpa_supplicant */
362 enum wpa_alg
{ WPA_ALG_NONE
, WPA_ALG_WEP
, WPA_ALG_TKIP
, WPA_ALG_CCMP
};
363 enum wpa_cipher
{ CIPHER_NONE
, CIPHER_WEP40
, CIPHER_TKIP
, CIPHER_CCMP
,
365 enum wpa_key_mgmt
{ KEY_MGMT_802_1X
, KEY_MGMT_PSK
, KEY_MGMT_NONE
,
366 KEY_MGMT_802_1X_NO_WPA
, KEY_MGMT_WPA_NONE
};
371 #define NET_TYPE_11FB 0
373 #define CAP_MODE_80211A 1
374 #define CAP_MODE_80211B 2
375 #define CAP_MODE_80211G 4
376 #define CAP_MODE_MASK 7
378 #define WORK_LINK_UP (1<<0)
379 #define WORK_LINK_DOWN (1<<1)
380 #define WORK_SET_MULTICAST_LIST (1<<2)
382 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
384 static const struct ieee80211_channel rndis_channels
[] = {
385 { .center_freq
= 2412 },
386 { .center_freq
= 2417 },
387 { .center_freq
= 2422 },
388 { .center_freq
= 2427 },
389 { .center_freq
= 2432 },
390 { .center_freq
= 2437 },
391 { .center_freq
= 2442 },
392 { .center_freq
= 2447 },
393 { .center_freq
= 2452 },
394 { .center_freq
= 2457 },
395 { .center_freq
= 2462 },
396 { .center_freq
= 2467 },
397 { .center_freq
= 2472 },
398 { .center_freq
= 2484 },
401 static const struct ieee80211_rate rndis_rates
[] = {
403 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
404 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
405 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
416 struct rndis_wlan_encr_key
{
425 /* RNDIS device private data */
426 struct rndis_wlan_private
{
427 struct usbnet
*usbdev
;
429 struct wireless_dev wdev
;
431 struct cfg80211_scan_request
*scan_request
;
433 struct workqueue_struct
*workqueue
;
434 struct delayed_work stats_work
;
435 struct delayed_work scan_work
;
436 struct work_struct work
;
437 struct mutex command_lock
;
438 spinlock_t stats_lock
;
439 unsigned long work_pending
;
441 struct ieee80211_supported_band band
;
442 struct ieee80211_channel channels
[ARRAY_SIZE(rndis_channels
)];
443 struct ieee80211_rate rates
[ARRAY_SIZE(rndis_rates
)];
445 struct iw_statistics iwstats
;
446 struct iw_statistics privstats
;
451 /* module parameters */
452 char param_country
[4];
453 int param_frameburst
;
454 int param_afterburner
;
455 int param_power_save
;
456 int param_power_output
;
457 int param_roamtrigger
;
459 u32 param_workaround_interval
;
464 struct ndis_80211_ssid essid
;
466 /* encryption stuff */
467 int encr_tx_key_index
;
468 struct rndis_wlan_encr_key encr_keys
[4];
475 int wpa_cipher_group
;
477 u8 command_buffer
[COMMAND_BUFFER_SIZE
];
483 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
484 struct net_device
*dev
,
485 enum nl80211_iftype type
, u32
*flags
,
486 struct vif_params
*params
);
488 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
489 struct cfg80211_scan_request
*request
);
491 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
);
493 static int rndis_set_tx_power(struct wiphy
*wiphy
, enum tx_power_setting type
,
495 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
);
497 static struct cfg80211_ops rndis_config_ops
= {
498 .change_virtual_intf
= rndis_change_virtual_intf
,
500 .set_wiphy_params
= rndis_set_wiphy_params
,
501 .set_tx_power
= rndis_set_tx_power
,
502 .get_tx_power
= rndis_get_tx_power
,
505 static void *rndis_wiphy_privid
= &rndis_wiphy_privid
;
508 static const unsigned char zero_bssid
[ETH_ALEN
] = {0,};
509 static const unsigned char ffff_bssid
[ETH_ALEN
] = { 0xff, 0xff, 0xff,
513 static struct rndis_wlan_private
*get_rndis_wlan_priv(struct usbnet
*dev
)
515 return (struct rndis_wlan_private
*)dev
->driver_priv
;
519 static u32
get_bcm4320_power_dbm(struct rndis_wlan_private
*priv
)
521 switch (priv
->param_power_output
) {
524 return BCM4320_DEFAULT_TXPOWER_DBM_100
;
526 return BCM4320_DEFAULT_TXPOWER_DBM_75
;
528 return BCM4320_DEFAULT_TXPOWER_DBM_50
;
530 return BCM4320_DEFAULT_TXPOWER_DBM_25
;
535 static bool is_wpa_key(struct rndis_wlan_private
*priv
, int idx
)
537 int cipher
= priv
->encr_keys
[idx
].cipher
;
539 return (cipher
== WLAN_CIPHER_SUITE_CCMP
||
540 cipher
== WLAN_CIPHER_SUITE_TKIP
);
545 static const char *oid_to_string(__le32 oid
)
548 #define OID_STR(oid) case oid: return(#oid)
549 /* from rndis_host.h */
550 OID_STR(OID_802_3_PERMANENT_ADDRESS
);
551 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE
);
552 OID_STR(OID_GEN_CURRENT_PACKET_FILTER
);
553 OID_STR(OID_GEN_PHYSICAL_MEDIUM
);
555 /* from rndis_wlan.c */
556 OID_STR(OID_GEN_LINK_SPEED
);
557 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER
);
559 OID_STR(OID_GEN_XMIT_OK
);
560 OID_STR(OID_GEN_RCV_OK
);
561 OID_STR(OID_GEN_XMIT_ERROR
);
562 OID_STR(OID_GEN_RCV_ERROR
);
563 OID_STR(OID_GEN_RCV_NO_BUFFER
);
565 OID_STR(OID_802_3_CURRENT_ADDRESS
);
566 OID_STR(OID_802_3_MULTICAST_LIST
);
567 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE
);
569 OID_STR(OID_802_11_BSSID
);
570 OID_STR(OID_802_11_SSID
);
571 OID_STR(OID_802_11_INFRASTRUCTURE_MODE
);
572 OID_STR(OID_802_11_ADD_WEP
);
573 OID_STR(OID_802_11_REMOVE_WEP
);
574 OID_STR(OID_802_11_DISASSOCIATE
);
575 OID_STR(OID_802_11_AUTHENTICATION_MODE
);
576 OID_STR(OID_802_11_PRIVACY_FILTER
);
577 OID_STR(OID_802_11_BSSID_LIST_SCAN
);
578 OID_STR(OID_802_11_ENCRYPTION_STATUS
);
579 OID_STR(OID_802_11_ADD_KEY
);
580 OID_STR(OID_802_11_REMOVE_KEY
);
581 OID_STR(OID_802_11_ASSOCIATION_INFORMATION
);
582 OID_STR(OID_802_11_PMKID
);
583 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED
);
584 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE
);
585 OID_STR(OID_802_11_TX_POWER_LEVEL
);
586 OID_STR(OID_802_11_RSSI
);
587 OID_STR(OID_802_11_RSSI_TRIGGER
);
588 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD
);
589 OID_STR(OID_802_11_RTS_THRESHOLD
);
590 OID_STR(OID_802_11_SUPPORTED_RATES
);
591 OID_STR(OID_802_11_CONFIGURATION
);
592 OID_STR(OID_802_11_BSSID_LIST
);
599 static const char *oid_to_string(__le32 oid
)
606 /* translate error code */
607 static int rndis_error_status(__le32 rndis_status
)
610 switch (rndis_status
) {
611 case RNDIS_STATUS_SUCCESS
:
614 case RNDIS_STATUS_FAILURE
:
615 case RNDIS_STATUS_INVALID_DATA
:
618 case RNDIS_STATUS_NOT_SUPPORTED
:
621 case RNDIS_STATUS_ADAPTER_NOT_READY
:
622 case RNDIS_STATUS_ADAPTER_NOT_OPEN
:
630 static int rndis_query_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int *len
)
632 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
635 struct rndis_msg_hdr
*header
;
636 struct rndis_query
*get
;
637 struct rndis_query_c
*get_c
;
641 buflen
= *len
+ sizeof(*u
.get
);
642 if (buflen
< CONTROL_BUFFER_SIZE
)
643 buflen
= CONTROL_BUFFER_SIZE
;
645 if (buflen
> COMMAND_BUFFER_SIZE
) {
646 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
650 u
.buf
= priv
->command_buffer
;
653 mutex_lock(&priv
->command_lock
);
655 memset(u
.get
, 0, sizeof *u
.get
);
656 u
.get
->msg_type
= RNDIS_MSG_QUERY
;
657 u
.get
->msg_len
= cpu_to_le32(sizeof *u
.get
);
660 ret
= rndis_command(dev
, u
.header
, buflen
);
662 devdbg(dev
, "rndis_query_oid(%s): rndis_command() failed, %d "
663 "(%08x)", oid_to_string(oid
), ret
,
664 le32_to_cpu(u
.get_c
->status
));
667 ret
= le32_to_cpu(u
.get_c
->len
);
668 *len
= (*len
> ret
) ? ret
: *len
;
669 memcpy(data
, u
.buf
+ le32_to_cpu(u
.get_c
->offset
) + 8, *len
);
670 ret
= rndis_error_status(u
.get_c
->status
);
673 devdbg(dev
, "rndis_query_oid(%s): device returned "
674 "error, 0x%08x (%d)", oid_to_string(oid
),
675 le32_to_cpu(u
.get_c
->status
), ret
);
678 mutex_unlock(&priv
->command_lock
);
680 if (u
.buf
!= priv
->command_buffer
)
686 static int rndis_set_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int len
)
688 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
691 struct rndis_msg_hdr
*header
;
692 struct rndis_set
*set
;
693 struct rndis_set_c
*set_c
;
697 buflen
= len
+ sizeof(*u
.set
);
698 if (buflen
< CONTROL_BUFFER_SIZE
)
699 buflen
= CONTROL_BUFFER_SIZE
;
701 if (buflen
> COMMAND_BUFFER_SIZE
) {
702 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
706 u
.buf
= priv
->command_buffer
;
709 mutex_lock(&priv
->command_lock
);
711 memset(u
.set
, 0, sizeof *u
.set
);
712 u
.set
->msg_type
= RNDIS_MSG_SET
;
713 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
715 u
.set
->len
= cpu_to_le32(len
);
716 u
.set
->offset
= cpu_to_le32(sizeof(*u
.set
) - 8);
717 u
.set
->handle
= cpu_to_le32(0);
718 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
720 ret
= rndis_command(dev
, u
.header
, buflen
);
722 devdbg(dev
, "rndis_set_oid(%s): rndis_command() failed, %d "
723 "(%08x)", oid_to_string(oid
), ret
,
724 le32_to_cpu(u
.set_c
->status
));
727 ret
= rndis_error_status(u
.set_c
->status
);
730 devdbg(dev
, "rndis_set_oid(%s): device returned error, "
731 "0x%08x (%d)", oid_to_string(oid
),
732 le32_to_cpu(u
.set_c
->status
), ret
);
735 mutex_unlock(&priv
->command_lock
);
737 if (u
.buf
!= priv
->command_buffer
)
743 static int rndis_reset(struct usbnet
*usbdev
)
745 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
746 struct rndis_reset
*reset
;
749 mutex_lock(&priv
->command_lock
);
751 reset
= (void *)priv
->command_buffer
;
752 memset(reset
, 0, sizeof(*reset
));
753 reset
->msg_type
= RNDIS_MSG_RESET
;
754 reset
->msg_len
= cpu_to_le32(sizeof(*reset
));
755 ret
= rndis_command(usbdev
, (void *)reset
, CONTROL_BUFFER_SIZE
);
757 mutex_unlock(&priv
->command_lock
);
766 * Specs say that we can only set config parameters only soon after device
768 * value_type: 0 = u32, 2 = unicode string
770 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
771 int value_type
, void *value
)
773 struct ndis_config_param
*infobuf
;
774 int value_len
, info_len
, param_len
, ret
, i
;
779 value_len
= sizeof(__le32
);
780 else if (value_type
== 2)
781 value_len
= strlen(value
) * sizeof(__le16
);
785 param_len
= strlen(param
) * sizeof(__le16
);
786 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
791 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
797 /* extra 12 bytes are for padding (debug output) */
798 memset(infobuf
, 0xCC, info_len
+ 12);
802 devdbg(dev
, "setting config parameter: %s, value: %s",
805 devdbg(dev
, "setting config parameter: %s, value: %d",
806 param
, *(u32
*)value
);
808 infobuf
->name_offs
= cpu_to_le32(sizeof(*infobuf
));
809 infobuf
->name_length
= cpu_to_le32(param_len
);
810 infobuf
->type
= cpu_to_le32(value_type
);
811 infobuf
->value_offs
= cpu_to_le32(sizeof(*infobuf
) + param_len
);
812 infobuf
->value_length
= cpu_to_le32(value_len
);
814 /* simple string to unicode string conversion */
815 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
816 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
817 unibuf
[i
] = cpu_to_le16(param
[i
]);
819 if (value_type
== 2) {
820 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
821 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
822 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
824 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
825 *dst_value
= cpu_to_le32(*(u32
*)value
);
829 devdbg(dev
, "info buffer (len: %d):", info_len
);
830 for (i
= 0; i
< info_len
; i
+= 12) {
831 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
832 devdbg(dev
, "%08X:%08X:%08X",
835 cpu_to_be32(tmp
[2]));
839 ret
= rndis_set_oid(dev
, OID_GEN_RNDIS_CONFIG_PARAMETER
,
842 devdbg(dev
, "setting rndis config parameter failed, %d.", ret
);
848 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
849 char *param
, char *value
)
851 return(rndis_set_config_parameter(dev
, param
, 2, value
));
854 /*static int rndis_set_config_parameter_u32(struct usbnet *dev,
855 char *param, u32 value)
857 return(rndis_set_config_parameter(dev, param, 0, &value));
862 * data conversion functions
864 static int level_to_qual(int level
)
866 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
867 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
871 static void dsconfig_to_freq(unsigned int dsconfig
, struct iw_freq
*freq
)
877 /* see comment in wireless.h above the "struct iw_freq"
878 * definition for an explanation of this if
879 * NOTE: 1000000 is due to the kHz
881 if (dsconfig
> 1000000) {
882 freq
->m
= dsconfig
/ 10;
887 /* convert from kHz to Hz */
892 static int freq_to_dsconfig(struct iw_freq
*freq
, unsigned int *dsconfig
)
894 if (freq
->m
< 1000 && freq
->e
== 0) {
895 if (freq
->m
>= 1 && freq
->m
<= 14)
896 *dsconfig
= ieee80211_dsss_chan_to_freq(freq
->m
) * 1000;
902 for (i
= freq
->e
; i
> 0; i
--)
914 static void restore_keys(struct usbnet
*usbdev
);
916 static int get_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
921 ret
= rndis_query_oid(usbdev
, OID_802_11_SSID
, ssid
, &len
);
928 unsigned char tmp
[NDIS_802_11_LENGTH_SSID
+ 1];
930 memcpy(tmp
, ssid
->essid
, le32_to_cpu(ssid
->length
));
931 tmp
[le32_to_cpu(ssid
->length
)] = 0;
932 devdbg(usbdev
, "get_essid: '%s', ret: %d", tmp
, ret
);
939 static int set_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
941 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
944 ret
= rndis_set_oid(usbdev
, OID_802_11_SSID
, ssid
, sizeof(*ssid
));
946 memcpy(&priv
->essid
, ssid
, sizeof(priv
->essid
));
948 devdbg(usbdev
, "set_essid: radio_on = 1");
955 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
960 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID
, bssid
, &len
);
963 memset(bssid
, 0, ETH_ALEN
);
968 static int get_association_info(struct usbnet
*usbdev
,
969 struct ndis_80211_assoc_info
*info
, int len
)
971 return rndis_query_oid(usbdev
, OID_802_11_ASSOCIATION_INFORMATION
,
975 static int is_associated(struct usbnet
*usbdev
)
980 ret
= get_bssid(usbdev
, bssid
);
982 return(ret
== 0 && memcmp(bssid
, zero_bssid
, ETH_ALEN
) != 0);
986 static int disassociate(struct usbnet
*usbdev
, int reset_ssid
)
988 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
989 struct ndis_80211_ssid ssid
;
992 if (priv
->radio_on
) {
993 ret
= rndis_set_oid(usbdev
, OID_802_11_DISASSOCIATE
, NULL
, 0);
996 devdbg(usbdev
, "disassociate: radio_on = 0");
1003 /* disassociate causes radio to be turned off; if reset_ssid
1004 * is given, set random ssid to enable radio */
1006 ssid
.length
= cpu_to_le32(sizeof(ssid
.essid
));
1007 get_random_bytes(&ssid
.essid
[2], sizeof(ssid
.essid
)-2);
1008 ssid
.essid
[0] = 0x1;
1009 ssid
.essid
[1] = 0xff;
1010 for (i
= 2; i
< sizeof(ssid
.essid
); i
++)
1011 ssid
.essid
[i
] = 0x1 + (ssid
.essid
[i
] * 0xfe / 0xff);
1012 ret
= set_essid(usbdev
, &ssid
);
1018 static int set_auth_mode(struct usbnet
*usbdev
, int wpa_version
, int authalg
)
1020 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1024 devdbg(usbdev
, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
1025 "keymgmt=0x%x", wpa_version
, authalg
, priv
->wpa_keymgmt
);
1027 if (wpa_version
& IW_AUTH_WPA_VERSION_WPA2
) {
1028 if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_802_1X
)
1029 auth_mode
= NDIS_80211_AUTH_WPA2
;
1031 auth_mode
= NDIS_80211_AUTH_WPA2_PSK
;
1032 } else if (wpa_version
& IW_AUTH_WPA_VERSION_WPA
) {
1033 if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_802_1X
)
1034 auth_mode
= NDIS_80211_AUTH_WPA
;
1035 else if (priv
->wpa_keymgmt
& IW_AUTH_KEY_MGMT_PSK
)
1036 auth_mode
= NDIS_80211_AUTH_WPA_PSK
;
1038 auth_mode
= NDIS_80211_AUTH_WPA_NONE
;
1039 } else if (authalg
& IW_AUTH_ALG_SHARED_KEY
) {
1040 if (authalg
& IW_AUTH_ALG_OPEN_SYSTEM
)
1041 auth_mode
= NDIS_80211_AUTH_AUTO_SWITCH
;
1043 auth_mode
= NDIS_80211_AUTH_SHARED
;
1045 auth_mode
= NDIS_80211_AUTH_OPEN
;
1047 tmp
= cpu_to_le32(auth_mode
);
1048 ret
= rndis_set_oid(usbdev
, OID_802_11_AUTHENTICATION_MODE
, &tmp
,
1051 devwarn(usbdev
, "setting auth mode failed (%08X)", ret
);
1055 priv
->wpa_version
= wpa_version
;
1056 priv
->wpa_authalg
= authalg
;
1061 static int set_priv_filter(struct usbnet
*usbdev
)
1063 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1066 devdbg(usbdev
, "set_priv_filter: wpa_version=0x%x", priv
->wpa_version
);
1068 if (priv
->wpa_version
& IW_AUTH_WPA_VERSION_WPA2
||
1069 priv
->wpa_version
& IW_AUTH_WPA_VERSION_WPA
)
1070 tmp
= cpu_to_le32(NDIS_80211_PRIV_8021X_WEP
);
1072 tmp
= cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL
);
1074 return rndis_set_oid(usbdev
, OID_802_11_PRIVACY_FILTER
, &tmp
,
1079 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
1081 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1085 devdbg(usbdev
, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
1089 if (pairwise
& IW_AUTH_CIPHER_CCMP
)
1090 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1091 else if (pairwise
& IW_AUTH_CIPHER_TKIP
)
1092 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1094 (IW_AUTH_CIPHER_WEP40
| IW_AUTH_CIPHER_WEP104
))
1095 encr_mode
= NDIS_80211_ENCR_WEP_ENABLED
;
1096 else if (groupwise
& IW_AUTH_CIPHER_CCMP
)
1097 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1098 else if (groupwise
& IW_AUTH_CIPHER_TKIP
)
1099 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1101 encr_mode
= NDIS_80211_ENCR_DISABLED
;
1103 tmp
= cpu_to_le32(encr_mode
);
1104 ret
= rndis_set_oid(usbdev
, OID_802_11_ENCRYPTION_STATUS
, &tmp
,
1107 devwarn(usbdev
, "setting encr mode failed (%08X)", ret
);
1111 priv
->wpa_cipher_pair
= pairwise
;
1112 priv
->wpa_cipher_group
= groupwise
;
1117 static int set_assoc_params(struct usbnet
*usbdev
)
1119 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1121 set_auth_mode(usbdev
, priv
->wpa_version
, priv
->wpa_authalg
);
1122 set_priv_filter(usbdev
);
1123 set_encr_mode(usbdev
, priv
->wpa_cipher_pair
, priv
->wpa_cipher_group
);
1129 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
1131 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1135 devdbg(usbdev
, "set_infra_mode: infra_mode=0x%x", priv
->infra_mode
);
1137 tmp
= cpu_to_le32(mode
);
1138 ret
= rndis_set_oid(usbdev
, OID_802_11_INFRASTRUCTURE_MODE
, &tmp
,
1141 devwarn(usbdev
, "setting infra mode failed (%08X)", ret
);
1145 /* NDIS drivers clear keys when infrastructure mode is
1146 * changed. But Linux tools assume otherwise. So set the
1148 restore_keys(usbdev
);
1150 priv
->infra_mode
= mode
;
1155 static int set_rts_threshold(struct usbnet
*usbdev
, u32 rts_threshold
)
1159 devdbg(usbdev
, "set_rts_threshold %i", rts_threshold
);
1161 if (rts_threshold
< 0 || rts_threshold
> 2347)
1162 rts_threshold
= 2347;
1164 tmp
= cpu_to_le32(rts_threshold
);
1165 return rndis_set_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
,
1170 static int set_frag_threshold(struct usbnet
*usbdev
, u32 frag_threshold
)
1174 devdbg(usbdev
, "set_frag_threshold %i", frag_threshold
);
1176 if (frag_threshold
< 256 || frag_threshold
> 2346)
1177 frag_threshold
= 2346;
1179 tmp
= cpu_to_le32(frag_threshold
);
1180 return rndis_set_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1185 static void set_default_iw_params(struct usbnet
*usbdev
)
1187 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1189 priv
->wpa_keymgmt
= 0;
1190 priv
->wpa_version
= 0;
1192 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1193 set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
1194 IW_AUTH_ALG_OPEN_SYSTEM
);
1195 set_priv_filter(usbdev
);
1196 set_encr_mode(usbdev
, IW_AUTH_CIPHER_NONE
, IW_AUTH_CIPHER_NONE
);
1200 static int deauthenticate(struct usbnet
*usbdev
)
1204 ret
= disassociate(usbdev
, 1);
1205 set_default_iw_params(usbdev
);
1210 /* index must be 0 - N, as per NDIS */
1211 static int add_wep_key(struct usbnet
*usbdev
, char *key
, int key_len
, int index
)
1213 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1214 struct ndis_80211_wep_key ndis_key
;
1217 if ((key_len
!= 5 || key_len
!= 13) || index
< 0 || index
> 3)
1221 cipher
= WLAN_CIPHER_SUITE_WEP40
;
1223 cipher
= WLAN_CIPHER_SUITE_WEP104
;
1225 memset(&ndis_key
, 0, sizeof(ndis_key
));
1227 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
));
1228 ndis_key
.length
= cpu_to_le32(key_len
);
1229 ndis_key
.index
= cpu_to_le32(index
);
1230 memcpy(&ndis_key
.material
, key
, key_len
);
1232 if (index
== priv
->encr_tx_key_index
) {
1233 ndis_key
.index
|= NDIS_80211_ADDWEP_TRANSMIT_KEY
;
1234 ret
= set_encr_mode(usbdev
, IW_AUTH_CIPHER_WEP104
,
1235 IW_AUTH_CIPHER_NONE
);
1237 devwarn(usbdev
, "encryption couldn't be enabled (%08X)",
1241 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_WEP
, &ndis_key
,
1244 devwarn(usbdev
, "adding encryption key %d failed (%08X)",
1249 priv
->encr_keys
[index
].len
= key_len
;
1250 priv
->encr_keys
[index
].cipher
= cipher
;
1251 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1252 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1258 static int add_wpa_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1259 int index
, const u8
*addr
, const u8
*rx_seq
, int cipher
,
1262 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1263 struct ndis_80211_key ndis_key
;
1267 if (index
< 0 || index
>= 4) {
1268 devdbg(usbdev
, "add_wpa_key: index out of range (%i)", index
);
1271 if (key_len
> sizeof(ndis_key
.material
) || key_len
< 0) {
1272 devdbg(usbdev
, "add_wpa_key: key length out of range (%i)",
1276 if ((flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
) && !rx_seq
) {
1277 devdbg(usbdev
, "add_wpa_key: recv seq flag without buffer");
1280 is_addr_ok
= addr
&& memcmp(addr
, zero_bssid
, ETH_ALEN
) != 0 &&
1281 memcmp(addr
, ffff_bssid
, ETH_ALEN
) != 0;
1282 if ((flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) && !is_addr_ok
) {
1283 devdbg(usbdev
, "add_wpa_key: pairwise but bssid invalid (%pM)",
1288 devdbg(usbdev
, "add_wpa_key(%i): flags:%i%i%i", index
,
1289 !!(flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
),
1290 !!(flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
),
1291 !!(flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
));
1293 memset(&ndis_key
, 0, sizeof(ndis_key
));
1295 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
) -
1296 sizeof(ndis_key
.material
) + key_len
);
1297 ndis_key
.length
= cpu_to_le32(key_len
);
1298 ndis_key
.index
= cpu_to_le32(index
) | flags
;
1300 if (cipher
== WLAN_CIPHER_SUITE_TKIP
&& key_len
== 32) {
1301 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1302 * different order than NDIS spec, so swap the order here. */
1303 memcpy(ndis_key
.material
, key
, 16);
1304 memcpy(ndis_key
.material
+ 16, key
+ 24, 8);
1305 memcpy(ndis_key
.material
+ 24, key
+ 16, 8);
1307 memcpy(ndis_key
.material
, key
, key_len
);
1309 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
)
1310 memcpy(ndis_key
.rsc
, rx_seq
, 6);
1312 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) {
1314 memcpy(ndis_key
.bssid
, addr
, ETH_ALEN
);
1317 if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
1318 memset(ndis_key
.bssid
, 0xff, ETH_ALEN
);
1320 get_bssid(usbdev
, ndis_key
.bssid
);
1323 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_KEY
, &ndis_key
,
1324 le32_to_cpu(ndis_key
.size
));
1325 devdbg(usbdev
, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret
);
1329 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
1330 priv
->encr_keys
[index
].len
= key_len
;
1331 priv
->encr_keys
[index
].cipher
= cipher
;
1332 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1333 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
)
1334 memcpy(&priv
->encr_keys
[index
].bssid
, ndis_key
.bssid
, ETH_ALEN
);
1336 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1338 if (flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
)
1339 priv
->encr_tx_key_index
= index
;
1345 static int restore_key(struct usbnet
*usbdev
, int key_idx
)
1347 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1348 struct rndis_wlan_encr_key key
;
1351 key
= priv
->encr_keys
[key_idx
];
1353 devdbg(usbdev
, "restore_key: %i:%s:%i", key_idx
,
1354 is_wpa_key(priv
, key_idx
) ? "wpa" : "wep",
1360 if (is_wpa_key(priv
, key_idx
)) {
1363 /*if (priv->encr_tx_key_index == key_idx)
1364 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;*/
1366 if (memcmp(key
.bssid
, zero_bssid
, ETH_ALEN
) != 0 &&
1367 memcmp(key
.bssid
, ffff_bssid
, ETH_ALEN
) != 0)
1368 flags
|= NDIS_80211_ADDKEY_PAIRWISE_KEY
;
1370 return add_wpa_key(usbdev
, key
.material
, key
.len
, key_idx
,
1371 key
.bssid
, NULL
, key
.cipher
, flags
);
1374 return add_wep_key(usbdev
, key
.material
, key
.len
, key_idx
);
1378 static void restore_keys(struct usbnet
*usbdev
)
1382 for (i
= 0; i
< 4; i
++)
1383 restore_key(usbdev
, i
);
1387 static void clear_key(struct rndis_wlan_private
*priv
, int idx
)
1389 memset(&priv
->encr_keys
[idx
], 0, sizeof(priv
->encr_keys
[idx
]));
1393 /* remove_key is for both wep and wpa */
1394 static int remove_key(struct usbnet
*usbdev
, int index
, u8 bssid
[ETH_ALEN
])
1396 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1397 struct ndis_80211_remove_key remove_key
;
1402 if (priv
->encr_keys
[index
].len
== 0)
1405 is_wpa
= is_wpa_key(priv
, index
);
1407 devdbg(usbdev
, "remove_key: %i:%s:%i", index
, is_wpa
? "wpa" : "wep",
1408 priv
->encr_keys
[index
].len
);
1410 clear_key(priv
, index
);
1413 remove_key
.size
= cpu_to_le32(sizeof(remove_key
));
1414 remove_key
.index
= cpu_to_le32(index
);
1417 if (memcmp(bssid
, ffff_bssid
, ETH_ALEN
) != 0)
1419 NDIS_80211_ADDKEY_PAIRWISE_KEY
;
1420 memcpy(remove_key
.bssid
, bssid
,
1421 sizeof(remove_key
.bssid
));
1423 memset(remove_key
.bssid
, 0xff,
1424 sizeof(remove_key
.bssid
));
1426 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_KEY
, &remove_key
,
1427 sizeof(remove_key
));
1431 keyindex
= cpu_to_le32(index
);
1432 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_WEP
, &keyindex
,
1436 "removing encryption key %d failed (%08X)",
1442 /* if it is transmit key, disable encryption */
1443 if (index
== priv
->encr_tx_key_index
)
1444 set_encr_mode(usbdev
, IW_AUTH_CIPHER_NONE
, IW_AUTH_CIPHER_NONE
);
1450 static void set_multicast_list(struct usbnet
*usbdev
)
1452 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1453 struct dev_mc_list
*mclist
;
1458 filter
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
1460 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1461 filter
|= RNDIS_PACKET_TYPE_PROMISCUOUS
|
1462 RNDIS_PACKET_TYPE_ALL_LOCAL
;
1463 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
||
1464 usbdev
->net
->mc_count
> priv
->multicast_size
) {
1465 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1466 } else if (usbdev
->net
->mc_count
> 0) {
1467 size
= min(priv
->multicast_size
, usbdev
->net
->mc_count
);
1468 buf
= kmalloc(size
* ETH_ALEN
, GFP_KERNEL
);
1471 "couldn't alloc %d bytes of memory",
1476 mclist
= usbdev
->net
->mc_list
;
1477 for (i
= 0; i
< size
&& mclist
; mclist
= mclist
->next
) {
1478 if (mclist
->dmi_addrlen
!= ETH_ALEN
)
1481 memcpy(buf
+ i
* ETH_ALEN
, mclist
->dmi_addr
, ETH_ALEN
);
1485 ret
= rndis_set_oid(usbdev
, OID_802_3_MULTICAST_LIST
, buf
,
1487 if (ret
== 0 && i
> 0)
1488 filter
|= RNDIS_PACKET_TYPE_MULTICAST
;
1490 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1492 devdbg(usbdev
, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1493 i
, priv
->multicast_size
, ret
);
1498 ret
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1501 devwarn(usbdev
, "couldn't set packet filter: %08x",
1502 le32_to_cpu(filter
));
1505 devdbg(usbdev
, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1506 le32_to_cpu(filter
), ret
);
1513 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
1514 struct net_device
*dev
,
1515 enum nl80211_iftype type
, u32
*flags
,
1516 struct vif_params
*params
)
1518 struct usbnet
*usbdev
= netdev_priv(dev
);
1522 case NL80211_IFTYPE_ADHOC
:
1523 mode
= NDIS_80211_INFRA_ADHOC
;
1525 case NL80211_IFTYPE_STATION
:
1526 mode
= NDIS_80211_INFRA_INFRA
;
1532 return set_infra_mode(usbdev
, mode
);
1536 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1538 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1539 struct usbnet
*usbdev
= priv
->usbdev
;
1542 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
1543 err
= set_frag_threshold(usbdev
, wiphy
->frag_threshold
);
1548 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
1549 err
= set_rts_threshold(usbdev
, wiphy
->rts_threshold
);
1558 static int rndis_set_tx_power(struct wiphy
*wiphy
, enum tx_power_setting type
,
1561 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1562 struct usbnet
*usbdev
= priv
->usbdev
;
1564 devdbg(usbdev
, "rndis_set_tx_power type:0x%x dbm:%i", type
, dbm
);
1566 /* Device doesn't support changing txpower after initialization, only
1567 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1570 if (type
== TX_POWER_AUTOMATIC
|| dbm
== get_bcm4320_power_dbm(priv
)) {
1571 if (!priv
->radio_on
)
1572 disassociate(usbdev
, 1); /* turn on radio */
1581 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
)
1583 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1584 struct usbnet
*usbdev
= priv
->usbdev
;
1586 *dbm
= get_bcm4320_power_dbm(priv
);
1588 devdbg(usbdev
, "rndis_get_tx_power dbm:%i", *dbm
);
1594 #define SCAN_DELAY_JIFFIES (HZ)
1595 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
1596 struct cfg80211_scan_request
*request
)
1598 struct usbnet
*usbdev
= netdev_priv(dev
);
1599 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1603 devdbg(usbdev
, "cfg80211.scan");
1608 if (priv
->scan_request
&& priv
->scan_request
!= request
)
1611 priv
->scan_request
= request
;
1613 tmp
= cpu_to_le32(1);
1614 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
1617 /* Wait before retrieving scan results from device */
1618 queue_delayed_work(priv
->workqueue
, &priv
->scan_work
,
1619 SCAN_DELAY_JIFFIES
);
1626 static struct cfg80211_bss
*rndis_bss_info_update(struct usbnet
*usbdev
,
1627 struct ndis_80211_bssid_ex
*bssid
)
1629 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1630 struct ieee80211_channel
*channel
;
1634 u16 beacon_interval
;
1635 struct ndis_80211_fixed_ies
*fixed
;
1636 int ie_len
, bssid_len
;
1639 /* parse bssid structure */
1640 bssid_len
= le32_to_cpu(bssid
->length
);
1642 if (bssid_len
< sizeof(struct ndis_80211_bssid_ex
) +
1643 sizeof(struct ndis_80211_fixed_ies
))
1646 fixed
= (struct ndis_80211_fixed_ies
*)bssid
->ies
;
1648 ie
= (void *)(bssid
->ies
+ sizeof(struct ndis_80211_fixed_ies
));
1649 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1650 (int)le32_to_cpu(bssid
->ie_length
));
1651 ie_len
-= sizeof(struct ndis_80211_fixed_ies
);
1655 /* extract data for cfg80211_inform_bss */
1656 channel
= ieee80211_get_channel(priv
->wdev
.wiphy
,
1657 KHZ_TO_MHZ(le32_to_cpu(bssid
->config
.ds_config
)));
1661 signal
= level_to_qual(le32_to_cpu(bssid
->rssi
));
1662 timestamp
= le64_to_cpu(*(__le64
*)fixed
->timestamp
);
1663 capability
= le16_to_cpu(fixed
->capabilities
);
1664 beacon_interval
= le16_to_cpu(fixed
->beacon_interval
);
1666 return cfg80211_inform_bss(priv
->wdev
.wiphy
, channel
, bssid
->mac
,
1667 timestamp
, capability
, beacon_interval
, ie
, ie_len
, signal
,
1672 static int rndis_check_bssid_list(struct usbnet
*usbdev
)
1675 struct ndis_80211_bssid_list_ex
*bssid_list
;
1676 struct ndis_80211_bssid_ex
*bssid
;
1677 int ret
= -EINVAL
, len
, count
, bssid_len
;
1679 devdbg(usbdev
, "check_bssid_list");
1681 len
= CONTROL_BUFFER_SIZE
;
1682 buf
= kmalloc(len
, GFP_KERNEL
);
1688 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
1693 bssid
= bssid_list
->bssid
;
1694 bssid_len
= le32_to_cpu(bssid
->length
);
1695 count
= le32_to_cpu(bssid_list
->num_items
);
1696 devdbg(usbdev
, "check_bssid_list: %d BSSIDs found", count
);
1698 while (count
&& ((void *)bssid
+ bssid_len
) <= (buf
+ len
)) {
1699 rndis_bss_info_update(usbdev
, bssid
);
1701 bssid
= (void *)bssid
+ bssid_len
;
1702 bssid_len
= le32_to_cpu(bssid
->length
);
1712 static void rndis_get_scan_results(struct work_struct
*work
)
1714 struct rndis_wlan_private
*priv
=
1715 container_of(work
, struct rndis_wlan_private
, scan_work
.work
);
1716 struct usbnet
*usbdev
= priv
->usbdev
;
1719 devdbg(usbdev
, "get_scan_results");
1721 if (!priv
->scan_request
)
1724 ret
= rndis_check_bssid_list(usbdev
);
1726 cfg80211_scan_done(priv
->scan_request
, ret
< 0);
1728 priv
->scan_request
= NULL
;
1733 * wireless extension handlers
1736 static int rndis_iw_commit(struct net_device
*dev
,
1737 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1744 static int rndis_iw_set_essid(struct net_device
*dev
,
1745 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *essid
)
1747 struct ndis_80211_ssid ssid
;
1748 int length
= wrqu
->essid
.length
;
1749 struct usbnet
*usbdev
= netdev_priv(dev
);
1751 devdbg(usbdev
, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1752 wrqu
->essid
.flags
, wrqu
->essid
.length
, essid
);
1754 if (length
> NDIS_802_11_LENGTH_SSID
)
1755 length
= NDIS_802_11_LENGTH_SSID
;
1757 ssid
.length
= cpu_to_le32(length
);
1759 memcpy(ssid
.essid
, essid
, length
);
1761 memset(ssid
.essid
, 0, NDIS_802_11_LENGTH_SSID
);
1763 set_assoc_params(usbdev
);
1765 if (!wrqu
->essid
.flags
|| length
== 0)
1766 return disassociate(usbdev
, 1);
1768 return set_essid(usbdev
, &ssid
);
1772 static int rndis_iw_get_essid(struct net_device
*dev
,
1773 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *essid
)
1775 struct ndis_80211_ssid ssid
;
1776 struct usbnet
*usbdev
= netdev_priv(dev
);
1779 ret
= get_essid(usbdev
, &ssid
);
1781 if (ret
== 0 && le32_to_cpu(ssid
.length
) > 0) {
1782 wrqu
->essid
.flags
= 1;
1783 wrqu
->essid
.length
= le32_to_cpu(ssid
.length
);
1784 memcpy(essid
, ssid
.essid
, wrqu
->essid
.length
);
1785 essid
[wrqu
->essid
.length
] = 0;
1787 memset(essid
, 0, sizeof(NDIS_802_11_LENGTH_SSID
));
1788 wrqu
->essid
.flags
= 0;
1789 wrqu
->essid
.length
= 0;
1791 devdbg(usbdev
, "SIOCGIWESSID: %s", essid
);
1796 static int rndis_iw_get_bssid(struct net_device
*dev
,
1797 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1799 struct usbnet
*usbdev
= netdev_priv(dev
);
1800 unsigned char bssid
[ETH_ALEN
];
1803 ret
= get_bssid(usbdev
, bssid
);
1806 devdbg(usbdev
, "SIOCGIWAP: %pM", bssid
);
1808 devdbg(usbdev
, "SIOCGIWAP: <not associated>");
1810 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1811 memcpy(wrqu
->ap_addr
.sa_data
, bssid
, ETH_ALEN
);
1817 static int rndis_iw_set_bssid(struct net_device
*dev
,
1818 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1820 struct usbnet
*usbdev
= netdev_priv(dev
);
1821 u8
*bssid
= (u8
*)wrqu
->ap_addr
.sa_data
;
1824 devdbg(usbdev
, "SIOCSIWAP: %pM", bssid
);
1826 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID
, bssid
, ETH_ALEN
);
1828 /* user apps may set ap's mac address, which is not required;
1829 * they may fail to work if this function fails, so return
1832 devwarn(usbdev
, "setting AP mac address failed (%08X)", ret
);
1838 static int rndis_iw_set_auth(struct net_device
*dev
,
1839 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1841 struct iw_param
*p
= &wrqu
->param
;
1842 struct usbnet
*usbdev
= netdev_priv(dev
);
1843 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1844 int ret
= -ENOTSUPP
;
1846 switch (p
->flags
& IW_AUTH_INDEX
) {
1847 case IW_AUTH_WPA_VERSION
:
1848 devdbg(usbdev
, "SIOCSIWAUTH: WPA_VERSION, %08x", p
->value
);
1849 priv
->wpa_version
= p
->value
;
1853 case IW_AUTH_CIPHER_PAIRWISE
:
1854 devdbg(usbdev
, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p
->value
);
1855 priv
->wpa_cipher_pair
= p
->value
;
1859 case IW_AUTH_CIPHER_GROUP
:
1860 devdbg(usbdev
, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p
->value
);
1861 priv
->wpa_cipher_group
= p
->value
;
1865 case IW_AUTH_KEY_MGMT
:
1866 devdbg(usbdev
, "SIOCSIWAUTH: KEY_MGMT, %08x", p
->value
);
1867 priv
->wpa_keymgmt
= p
->value
;
1871 case IW_AUTH_TKIP_COUNTERMEASURES
:
1872 devdbg(usbdev
, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1877 case IW_AUTH_DROP_UNENCRYPTED
:
1878 devdbg(usbdev
, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p
->value
);
1882 case IW_AUTH_80211_AUTH_ALG
:
1883 devdbg(usbdev
, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p
->value
);
1884 priv
->wpa_authalg
= p
->value
;
1888 case IW_AUTH_WPA_ENABLED
:
1889 devdbg(usbdev
, "SIOCSIWAUTH: WPA_ENABLED, %08x", p
->value
);
1890 if (wrqu
->param
.value
)
1891 deauthenticate(usbdev
);
1895 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1896 devdbg(usbdev
, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1901 case IW_AUTH_ROAMING_CONTROL
:
1902 devdbg(usbdev
, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p
->value
);
1906 case IW_AUTH_PRIVACY_INVOKED
:
1907 devdbg(usbdev
, "SIOCSIWAUTH: invalid cmd %d",
1908 wrqu
->param
.flags
& IW_AUTH_INDEX
);
1912 devdbg(usbdev
, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1913 p
->flags
& IW_AUTH_INDEX
, p
->value
);
1919 static int rndis_iw_get_auth(struct net_device
*dev
,
1920 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1922 struct iw_param
*p
= &wrqu
->param
;
1923 struct usbnet
*usbdev
= netdev_priv(dev
);
1924 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1926 switch (p
->flags
& IW_AUTH_INDEX
) {
1927 case IW_AUTH_WPA_VERSION
:
1928 p
->value
= priv
->wpa_version
;
1930 case IW_AUTH_CIPHER_PAIRWISE
:
1931 p
->value
= priv
->wpa_cipher_pair
;
1933 case IW_AUTH_CIPHER_GROUP
:
1934 p
->value
= priv
->wpa_cipher_group
;
1936 case IW_AUTH_KEY_MGMT
:
1937 p
->value
= priv
->wpa_keymgmt
;
1939 case IW_AUTH_80211_AUTH_ALG
:
1940 p
->value
= priv
->wpa_authalg
;
1943 devdbg(usbdev
, "SIOCGIWAUTH: invalid cmd %d",
1944 wrqu
->param
.flags
& IW_AUTH_INDEX
);
1951 static int rndis_iw_set_encode(struct net_device
*dev
,
1952 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1954 struct usbnet
*usbdev
= netdev_priv(dev
);
1955 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1956 struct rndis_wlan_encr_key key
;
1957 int ret
, index
, key_len
;
1960 index
= (wrqu
->encoding
.flags
& IW_ENCODE_INDEX
);
1962 /* iwconfig gives index as 1 - N */
1966 index
= priv
->encr_tx_key_index
;
1968 if (index
< 0 || index
>= 4) {
1969 devwarn(usbdev
, "encryption index out of range (%u)", index
);
1973 /* remove key if disabled */
1974 if (wrqu
->data
.flags
& IW_ENCODE_DISABLED
) {
1975 if (remove_key(usbdev
, index
, NULL
))
1981 /* global encryption state (for all keys) */
1982 if (wrqu
->data
.flags
& IW_ENCODE_OPEN
)
1983 ret
= set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
1984 IW_AUTH_ALG_OPEN_SYSTEM
);
1985 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1986 ret
= set_auth_mode(usbdev
, IW_AUTH_WPA_VERSION_DISABLED
,
1987 IW_AUTH_ALG_SHARED_KEY
);
1991 if (wrqu
->data
.length
> 0) {
1992 key_len
= wrqu
->data
.length
;
1995 /* must be set as tx key */
1996 if (priv
->encr_keys
[index
].len
== 0)
1998 key
= priv
->encr_keys
[index
];
2000 keybuf
= key
.material
;
2001 priv
->encr_tx_key_index
= index
;
2004 if (add_wep_key(usbdev
, keybuf
, key_len
, index
) != 0)
2007 if (index
== priv
->encr_tx_key_index
)
2008 /* ndis drivers want essid to be set after setting encr */
2009 set_essid(usbdev
, &priv
->essid
);
2015 static int rndis_iw_set_encode_ext(struct net_device
*dev
,
2016 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2018 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
2019 struct usbnet
*usbdev
= netdev_priv(dev
);
2020 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2021 int keyidx
, flags
, cipher
;
2023 keyidx
= wrqu
->encoding
.flags
& IW_ENCODE_INDEX
;
2025 /* iwconfig gives index as 1 - N */
2029 keyidx
= priv
->encr_tx_key_index
;
2031 if (keyidx
< 0 || keyidx
>= 4) {
2032 devwarn(usbdev
, "encryption index out of range (%u)", keyidx
);
2036 if (ext
->alg
== WPA_ALG_WEP
) {
2037 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
2038 priv
->encr_tx_key_index
= keyidx
;
2039 return add_wep_key(usbdev
, ext
->key
, ext
->key_len
, keyidx
);
2043 if (ext
->alg
== IW_ENCODE_ALG_TKIP
)
2044 cipher
= WLAN_CIPHER_SUITE_TKIP
;
2045 else if (ext
->alg
== IW_ENCODE_ALG_CCMP
)
2046 cipher
= WLAN_CIPHER_SUITE_CCMP
;
2048 if ((wrqu
->encoding
.flags
& IW_ENCODE_DISABLED
) ||
2049 ext
->alg
== IW_ENCODE_ALG_NONE
|| ext
->key_len
== 0)
2050 return remove_key(usbdev
, keyidx
, NULL
);
2056 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
2057 flags
|= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
;
2058 if (!(ext
->ext_flags
& IW_ENCODE_EXT_GROUP_KEY
))
2059 flags
|= NDIS_80211_ADDKEY_PAIRWISE_KEY
;
2060 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
2061 flags
|= NDIS_80211_ADDKEY_TRANSMIT_KEY
;
2063 return add_wpa_key(usbdev
, ext
->key
, ext
->key_len
, keyidx
,
2064 (u8
*)&ext
->addr
.sa_data
, ext
->rx_seq
, cipher
,
2069 static int rndis_iw_set_genie(struct net_device
*dev
,
2070 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2072 struct usbnet
*usbdev
= netdev_priv(dev
);
2073 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2079 for (j
= 0; j
< wrqu
->data
.length
; j
+= 8)
2081 "SIOCSIWGENIE %04x - "
2082 "%02x %02x %02x %02x %02x %02x %02x %02x", j
,
2083 gie
[j
+ 0], gie
[j
+ 1], gie
[j
+ 2], gie
[j
+ 3],
2084 gie
[j
+ 4], gie
[j
+ 5], gie
[j
+ 6], gie
[j
+ 7]);
2086 /* clear existing IEs */
2087 if (priv
->wpa_ie_len
) {
2088 kfree(priv
->wpa_ie
);
2089 priv
->wpa_ie_len
= 0;
2093 priv
->wpa_ie
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
2095 priv
->wpa_ie_len
= wrqu
->data
.length
;
2096 memcpy(priv
->wpa_ie
, extra
, priv
->wpa_ie_len
);
2103 static int rndis_iw_get_genie(struct net_device
*dev
,
2104 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2106 struct usbnet
*usbdev
= netdev_priv(dev
);
2107 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2109 devdbg(usbdev
, "SIOCGIWGENIE");
2111 if (priv
->wpa_ie_len
== 0 || priv
->wpa_ie
== NULL
) {
2112 wrqu
->data
.length
= 0;
2116 if (wrqu
->data
.length
< priv
->wpa_ie_len
)
2119 wrqu
->data
.length
= priv
->wpa_ie_len
;
2120 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
2126 static int rndis_iw_set_freq(struct net_device
*dev
,
2127 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2129 struct usbnet
*usbdev
= netdev_priv(dev
);
2130 struct ndis_80211_conf config
;
2131 unsigned int dsconfig
;
2134 /* this OID is valid only when not associated */
2135 if (is_associated(usbdev
))
2139 if (freq_to_dsconfig(&wrqu
->freq
, &dsconfig
))
2142 len
= sizeof(config
);
2143 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
2145 devdbg(usbdev
, "SIOCSIWFREQ: querying configuration failed");
2149 config
.ds_config
= cpu_to_le32(dsconfig
);
2151 devdbg(usbdev
, "SIOCSIWFREQ: %d * 10^%d", wrqu
->freq
.m
, wrqu
->freq
.e
);
2152 return rndis_set_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
,
2157 static int rndis_iw_get_freq(struct net_device
*dev
,
2158 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2160 struct usbnet
*usbdev
= netdev_priv(dev
);
2161 struct ndis_80211_conf config
;
2164 len
= sizeof(config
);
2165 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
2167 dsconfig_to_freq(le32_to_cpu(config
.ds_config
), &wrqu
->freq
);
2169 devdbg(usbdev
, "SIOCGIWFREQ: %d", wrqu
->freq
.m
);
2174 static int rndis_iw_get_rate(struct net_device
*dev
,
2175 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2177 struct usbnet
*usbdev
= netdev_priv(dev
);
2182 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &tmp
, &len
);
2184 wrqu
->bitrate
.value
= le32_to_cpu(tmp
) * 100;
2185 wrqu
->bitrate
.disabled
= 0;
2186 wrqu
->bitrate
.flags
= 1;
2192 static int rndis_iw_set_mlme(struct net_device
*dev
,
2193 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
2195 struct usbnet
*usbdev
= netdev_priv(dev
);
2196 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2197 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
2198 unsigned char bssid
[ETH_ALEN
];
2200 get_bssid(usbdev
, bssid
);
2202 if (memcmp(bssid
, mlme
->addr
.sa_data
, ETH_ALEN
))
2205 switch (mlme
->cmd
) {
2206 case IW_MLME_DEAUTH
:
2207 return deauthenticate(usbdev
);
2208 case IW_MLME_DISASSOC
:
2209 return disassociate(usbdev
, priv
->radio_on
);
2218 static struct iw_statistics
*rndis_get_wireless_stats(struct net_device
*dev
)
2220 struct usbnet
*usbdev
= netdev_priv(dev
);
2221 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2222 unsigned long flags
;
2224 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2225 memcpy(&priv
->iwstats
, &priv
->privstats
, sizeof(priv
->iwstats
));
2226 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2228 return &priv
->iwstats
;
2232 #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2233 static const iw_handler rndis_iw_handler
[] =
2235 IW_IOCTL(SIOCSIWCOMMIT
) = rndis_iw_commit
,
2236 IW_IOCTL(SIOCGIWNAME
) = (iw_handler
) cfg80211_wext_giwname
,
2237 IW_IOCTL(SIOCSIWFREQ
) = rndis_iw_set_freq
,
2238 IW_IOCTL(SIOCGIWFREQ
) = rndis_iw_get_freq
,
2239 IW_IOCTL(SIOCSIWMODE
) = (iw_handler
) cfg80211_wext_siwmode
,
2240 IW_IOCTL(SIOCGIWMODE
) = (iw_handler
) cfg80211_wext_giwmode
,
2241 IW_IOCTL(SIOCGIWRANGE
) = (iw_handler
) cfg80211_wext_giwrange
,
2242 IW_IOCTL(SIOCSIWAP
) = rndis_iw_set_bssid
,
2243 IW_IOCTL(SIOCGIWAP
) = rndis_iw_get_bssid
,
2244 IW_IOCTL(SIOCSIWSCAN
) = (iw_handler
) cfg80211_wext_siwscan
,
2245 IW_IOCTL(SIOCGIWSCAN
) = (iw_handler
) cfg80211_wext_giwscan
,
2246 IW_IOCTL(SIOCSIWESSID
) = rndis_iw_set_essid
,
2247 IW_IOCTL(SIOCGIWESSID
) = rndis_iw_get_essid
,
2248 IW_IOCTL(SIOCGIWRATE
) = rndis_iw_get_rate
,
2249 IW_IOCTL(SIOCSIWRTS
) = (iw_handler
) cfg80211_wext_siwrts
,
2250 IW_IOCTL(SIOCGIWRTS
) = (iw_handler
) cfg80211_wext_giwrts
,
2251 IW_IOCTL(SIOCSIWFRAG
) = (iw_handler
) cfg80211_wext_siwfrag
,
2252 IW_IOCTL(SIOCGIWFRAG
) = (iw_handler
) cfg80211_wext_giwfrag
,
2253 IW_IOCTL(SIOCSIWTXPOW
) = (iw_handler
) cfg80211_wext_siwtxpower
,
2254 IW_IOCTL(SIOCGIWTXPOW
) = (iw_handler
) cfg80211_wext_giwtxpower
,
2255 IW_IOCTL(SIOCSIWENCODE
) = rndis_iw_set_encode
,
2256 IW_IOCTL(SIOCSIWENCODEEXT
) = rndis_iw_set_encode_ext
,
2257 IW_IOCTL(SIOCSIWAUTH
) = rndis_iw_set_auth
,
2258 IW_IOCTL(SIOCGIWAUTH
) = rndis_iw_get_auth
,
2259 IW_IOCTL(SIOCSIWGENIE
) = rndis_iw_set_genie
,
2260 IW_IOCTL(SIOCGIWGENIE
) = rndis_iw_get_genie
,
2261 IW_IOCTL(SIOCSIWMLME
) = rndis_iw_set_mlme
,
2264 static const iw_handler rndis_wlan_private_handler
[] = {
2267 static const struct iw_priv_args rndis_wlan_private_args
[] = {
2271 static const struct iw_handler_def rndis_iw_handlers
= {
2272 .num_standard
= ARRAY_SIZE(rndis_iw_handler
),
2273 .num_private
= ARRAY_SIZE(rndis_wlan_private_handler
),
2274 .num_private_args
= ARRAY_SIZE(rndis_wlan_private_args
),
2275 .standard
= (iw_handler
*)rndis_iw_handler
,
2276 .private = (iw_handler
*)rndis_wlan_private_handler
,
2277 .private_args
= (struct iw_priv_args
*)rndis_wlan_private_args
,
2278 .get_wireless_stats
= rndis_get_wireless_stats
,
2282 static void rndis_wlan_worker(struct work_struct
*work
)
2284 struct rndis_wlan_private
*priv
=
2285 container_of(work
, struct rndis_wlan_private
, work
);
2286 struct usbnet
*usbdev
= priv
->usbdev
;
2287 union iwreq_data evt
;
2288 unsigned char bssid
[ETH_ALEN
];
2289 struct ndis_80211_assoc_info
*info
;
2290 int assoc_size
= sizeof(*info
) + IW_CUSTOM_MAX
+ 32;
2293 if (test_and_clear_bit(WORK_LINK_UP
, &priv
->work_pending
)) {
2294 netif_carrier_on(usbdev
->net
);
2296 info
= kzalloc(assoc_size
, GFP_KERNEL
);
2300 /* Get association info IEs from device and send them back to
2302 ret
= get_association_info(usbdev
, info
, assoc_size
);
2304 evt
.data
.length
= le32_to_cpu(info
->req_ie_length
);
2305 if (evt
.data
.length
> 0) {
2306 offset
= le32_to_cpu(info
->offset_req_ies
);
2307 wireless_send_event(usbdev
->net
,
2308 IWEVASSOCREQIE
, &evt
,
2309 (char *)info
+ offset
);
2312 evt
.data
.length
= le32_to_cpu(info
->resp_ie_length
);
2313 if (evt
.data
.length
> 0) {
2314 offset
= le32_to_cpu(info
->offset_resp_ies
);
2315 wireless_send_event(usbdev
->net
,
2316 IWEVASSOCRESPIE
, &evt
,
2317 (char *)info
+ offset
);
2324 ret
= get_bssid(usbdev
, bssid
);
2327 evt
.data
.length
= 0;
2328 memcpy(evt
.ap_addr
.sa_data
, bssid
, ETH_ALEN
);
2329 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2333 if (test_and_clear_bit(WORK_LINK_DOWN
, &priv
->work_pending
)) {
2334 netif_carrier_off(usbdev
->net
);
2337 evt
.data
.length
= 0;
2338 memset(evt
.ap_addr
.sa_data
, 0, ETH_ALEN
);
2339 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2342 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2343 set_multicast_list(usbdev
);
2346 static void rndis_wlan_set_multicast_list(struct net_device
*dev
)
2348 struct usbnet
*usbdev
= netdev_priv(dev
);
2349 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2351 if (test_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2354 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2355 queue_work(priv
->workqueue
, &priv
->work
);
2359 static void rndis_wlan_auth_indication(struct usbnet
*usbdev
,
2360 struct ndis_80211_status_indication
*indication
,
2366 bool pairwise_error
, group_error
;
2367 struct ndis_80211_auth_request
*auth_req
;
2369 /* must have at least one array entry */
2370 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2371 sizeof(struct ndis_80211_auth_request
)) {
2372 devinfo(usbdev
, "authentication indication: "
2373 "too short message (%i)", len
);
2377 buf
= (void *)&indication
->u
.auth_request
[0];
2378 buflen
= len
- offsetof(struct ndis_80211_status_indication
, u
);
2380 while (buflen
>= sizeof(*auth_req
)) {
2381 auth_req
= (void *)buf
;
2383 flags
= le32_to_cpu(auth_req
->flags
);
2384 pairwise_error
= false;
2385 group_error
= false;
2388 type
= "reauth request";
2390 type
= "key update request";
2392 pairwise_error
= true;
2393 type
= "pairwise_error";
2397 type
= "group_error";
2400 devinfo(usbdev
, "authentication indication: %s (0x%08x)", type
,
2401 le32_to_cpu(auth_req
->flags
));
2403 if (pairwise_error
|| group_error
) {
2404 union iwreq_data wrqu
;
2405 struct iw_michaelmicfailure micfailure
;
2407 memset(&micfailure
, 0, sizeof(micfailure
));
2409 micfailure
.flags
|= IW_MICFAILURE_PAIRWISE
;
2411 micfailure
.flags
|= IW_MICFAILURE_GROUP
;
2413 memcpy(micfailure
.src_addr
.sa_data
, auth_req
->bssid
,
2416 memset(&wrqu
, 0, sizeof(wrqu
));
2417 wrqu
.data
.length
= sizeof(micfailure
);
2418 wireless_send_event(usbdev
->net
, IWEVMICHAELMICFAILURE
,
2419 &wrqu
, (u8
*)&micfailure
);
2422 buflen
-= le32_to_cpu(auth_req
->length
);
2423 buf
+= le32_to_cpu(auth_req
->length
);
2427 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet
*usbdev
,
2428 struct ndis_80211_status_indication
*indication
,
2431 struct ndis_80211_pmkid_cand_list
*cand_list
;
2432 int list_len
, expected_len
, i
;
2434 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2435 sizeof(struct ndis_80211_pmkid_cand_list
)) {
2436 devinfo(usbdev
, "pmkid candidate list indication: "
2437 "too short message (%i)", len
);
2441 list_len
= le32_to_cpu(indication
->u
.cand_list
.num_candidates
) *
2442 sizeof(struct ndis_80211_pmkid_candidate
);
2443 expected_len
= sizeof(struct ndis_80211_pmkid_cand_list
) + list_len
+
2444 offsetof(struct ndis_80211_status_indication
, u
);
2446 if (len
< expected_len
) {
2447 devinfo(usbdev
, "pmkid candidate list indication: "
2448 "list larger than buffer (%i < %i)",
2453 cand_list
= &indication
->u
.cand_list
;
2455 devinfo(usbdev
, "pmkid candidate list indication: "
2456 "version %i, candidates %i",
2457 le32_to_cpu(cand_list
->version
),
2458 le32_to_cpu(cand_list
->num_candidates
));
2460 if (le32_to_cpu(cand_list
->version
) != 1)
2463 for (i
= 0; i
< le32_to_cpu(cand_list
->num_candidates
); i
++) {
2464 struct iw_pmkid_cand pcand
;
2465 union iwreq_data wrqu
;
2466 struct ndis_80211_pmkid_candidate
*cand
=
2467 &cand_list
->candidate_list
[i
];
2469 devdbg(usbdev
, "cand[%i]: flags: 0x%08x, bssid: %pM",
2470 i
, le32_to_cpu(cand
->flags
), cand
->bssid
);
2472 memset(&pcand
, 0, sizeof(pcand
));
2473 if (le32_to_cpu(cand
->flags
) & 0x01)
2474 pcand
.flags
|= IW_PMKID_CAND_PREAUTH
;
2476 memcpy(pcand
.bssid
.sa_data
, cand
->bssid
, ETH_ALEN
);
2478 memset(&wrqu
, 0, sizeof(wrqu
));
2479 wrqu
.data
.length
= sizeof(pcand
);
2480 wireless_send_event(usbdev
->net
, IWEVPMKIDCAND
, &wrqu
,
2485 static void rndis_wlan_media_specific_indication(struct usbnet
*usbdev
,
2486 struct rndis_indicate
*msg
, int buflen
)
2488 struct ndis_80211_status_indication
*indication
;
2491 offset
= offsetof(struct rndis_indicate
, status
) +
2492 le32_to_cpu(msg
->offset
);
2493 len
= le32_to_cpu(msg
->length
);
2496 devinfo(usbdev
, "media specific indication, "
2497 "ignore too short message (%i < 8)", len
);
2501 if (offset
+ len
> buflen
) {
2502 devinfo(usbdev
, "media specific indication, "
2503 "too large to fit to buffer (%i > %i)",
2504 offset
+ len
, buflen
);
2508 indication
= (void *)((u8
*)msg
+ offset
);
2510 switch (le32_to_cpu(indication
->status_type
)) {
2511 case NDIS_80211_STATUSTYPE_RADIOSTATE
:
2512 devinfo(usbdev
, "radio state indication: %i",
2513 le32_to_cpu(indication
->u
.radio_status
));
2516 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
:
2517 devinfo(usbdev
, "media stream mode indication: %i",
2518 le32_to_cpu(indication
->u
.media_stream_mode
));
2521 case NDIS_80211_STATUSTYPE_AUTHENTICATION
:
2522 rndis_wlan_auth_indication(usbdev
, indication
, len
);
2525 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
:
2526 rndis_wlan_pmkid_cand_list_indication(usbdev
, indication
, len
);
2530 devinfo(usbdev
, "media specific indication: "
2531 "unknown status type 0x%08x",
2532 le32_to_cpu(indication
->status_type
));
2537 static void rndis_wlan_indication(struct usbnet
*usbdev
, void *ind
, int buflen
)
2539 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2540 struct rndis_indicate
*msg
= ind
;
2542 switch (msg
->status
) {
2543 case RNDIS_STATUS_MEDIA_CONNECT
:
2544 devinfo(usbdev
, "media connect");
2546 /* queue work to avoid recursive calls into rndis_command */
2547 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
2548 queue_work(priv
->workqueue
, &priv
->work
);
2551 case RNDIS_STATUS_MEDIA_DISCONNECT
:
2552 devinfo(usbdev
, "media disconnect");
2554 /* queue work to avoid recursive calls into rndis_command */
2555 set_bit(WORK_LINK_DOWN
, &priv
->work_pending
);
2556 queue_work(priv
->workqueue
, &priv
->work
);
2559 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION
:
2560 rndis_wlan_media_specific_indication(usbdev
, msg
, buflen
);
2564 devinfo(usbdev
, "indication: 0x%08x",
2565 le32_to_cpu(msg
->status
));
2571 static int rndis_wlan_get_caps(struct usbnet
*usbdev
)
2576 } networks_supported
;
2577 int len
, retval
, i
, n
;
2578 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2580 /* determine supported modes */
2581 len
= sizeof(networks_supported
);
2582 retval
= rndis_query_oid(usbdev
, OID_802_11_NETWORK_TYPES_SUPPORTED
,
2583 &networks_supported
, &len
);
2585 n
= le32_to_cpu(networks_supported
.num_items
);
2588 for (i
= 0; i
< n
; i
++) {
2589 switch (le32_to_cpu(networks_supported
.items
[i
])) {
2590 case NDIS_80211_TYPE_FREQ_HOP
:
2591 case NDIS_80211_TYPE_DIRECT_SEQ
:
2592 priv
->caps
|= CAP_MODE_80211B
;
2594 case NDIS_80211_TYPE_OFDM_A
:
2595 priv
->caps
|= CAP_MODE_80211A
;
2597 case NDIS_80211_TYPE_OFDM_G
:
2598 priv
->caps
|= CAP_MODE_80211G
;
2608 #define STATS_UPDATE_JIFFIES (HZ)
2609 static void rndis_update_wireless_stats(struct work_struct
*work
)
2611 struct rndis_wlan_private
*priv
=
2612 container_of(work
, struct rndis_wlan_private
, stats_work
.work
);
2613 struct usbnet
*usbdev
= priv
->usbdev
;
2614 struct iw_statistics iwstats
;
2617 unsigned long flags
;
2618 int update_jiffies
= STATS_UPDATE_JIFFIES
;
2621 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2622 memcpy(&iwstats
, &priv
->privstats
, sizeof(iwstats
));
2623 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2625 /* only update stats when connected */
2626 if (!is_associated(usbdev
)) {
2627 iwstats
.qual
.qual
= 0;
2628 iwstats
.qual
.level
= 0;
2629 iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2630 | IW_QUAL_LEVEL_UPDATED
2631 | IW_QUAL_NOISE_INVALID
2632 | IW_QUAL_QUAL_INVALID
2633 | IW_QUAL_LEVEL_INVALID
;
2638 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2640 devdbg(usbdev
, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret
,
2643 memset(&iwstats
.qual
, 0, sizeof(iwstats
.qual
));
2644 iwstats
.qual
.qual
= level_to_qual(le32_to_cpu(rssi
));
2645 iwstats
.qual
.level
= level_to_qual(le32_to_cpu(rssi
));
2646 iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2647 | IW_QUAL_LEVEL_UPDATED
2648 | IW_QUAL_NOISE_INVALID
;
2651 memset(&iwstats
.discard
, 0, sizeof(iwstats
.discard
));
2654 ret
= rndis_query_oid(usbdev
, OID_GEN_XMIT_ERROR
, &tmp
, &len
);
2656 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2659 ret
= rndis_query_oid(usbdev
, OID_GEN_RCV_ERROR
, &tmp
, &len
);
2661 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2664 ret
= rndis_query_oid(usbdev
, OID_GEN_RCV_NO_BUFFER
, &tmp
, &len
);
2666 iwstats
.discard
.misc
+= le32_to_cpu(tmp
);
2668 /* Workaround transfer stalls on poor quality links.
2669 * TODO: find right way to fix these stalls (as stalls do not happen
2670 * with ndiswrapper/windows driver). */
2671 if (iwstats
.qual
.qual
<= 25) {
2672 /* Decrease stats worker interval to catch stalls.
2673 * faster. Faster than 400-500ms causes packet loss,
2674 * Slower doesn't catch stalls fast enough.
2676 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
2677 if (j
> STATS_UPDATE_JIFFIES
)
2678 j
= STATS_UPDATE_JIFFIES
;
2683 /* Send scan OID. Use of both OIDs is required to get device
2686 tmp
= cpu_to_le32(1);
2687 rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
2690 len
= CONTROL_BUFFER_SIZE
;
2691 buf
= kmalloc(len
, GFP_KERNEL
);
2695 rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2699 spin_lock_irqsave(&priv
->stats_lock
, flags
);
2700 memcpy(&priv
->privstats
, &iwstats
, sizeof(iwstats
));
2701 spin_unlock_irqrestore(&priv
->stats_lock
, flags
);
2703 if (update_jiffies
>= HZ
)
2704 update_jiffies
= round_jiffies_relative(update_jiffies
);
2706 j
= round_jiffies_relative(update_jiffies
);
2707 if (abs(j
- update_jiffies
) <= 10)
2711 queue_delayed_work(priv
->workqueue
, &priv
->stats_work
, update_jiffies
);
2715 static int bcm4320a_early_init(struct usbnet
*usbdev
)
2717 /* bcm4320a doesn't handle configuration parameters well. Try
2718 * set any and you get partially zeroed mac and broken device.
2725 static int bcm4320b_early_init(struct usbnet
*usbdev
)
2727 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2730 /* Early initialization settings, setting these won't have effect
2731 * if called after generic_rndis_bind().
2734 priv
->param_country
[0] = modparam_country
[0];
2735 priv
->param_country
[1] = modparam_country
[1];
2736 priv
->param_country
[2] = 0;
2737 priv
->param_frameburst
= modparam_frameburst
;
2738 priv
->param_afterburner
= modparam_afterburner
;
2739 priv
->param_power_save
= modparam_power_save
;
2740 priv
->param_power_output
= modparam_power_output
;
2741 priv
->param_roamtrigger
= modparam_roamtrigger
;
2742 priv
->param_roamdelta
= modparam_roamdelta
;
2744 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
2745 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
2746 /* doesn't support EU as country code, use FI instead */
2747 if (!strcmp(priv
->param_country
, "EU"))
2748 strcpy(priv
->param_country
, "FI");
2750 if (priv
->param_power_save
< 0)
2751 priv
->param_power_save
= 0;
2752 else if (priv
->param_power_save
> 2)
2753 priv
->param_power_save
= 2;
2755 if (priv
->param_power_output
< 0)
2756 priv
->param_power_output
= 0;
2757 else if (priv
->param_power_output
> 3)
2758 priv
->param_power_output
= 3;
2760 if (priv
->param_roamtrigger
< -80)
2761 priv
->param_roamtrigger
= -80;
2762 else if (priv
->param_roamtrigger
> -60)
2763 priv
->param_roamtrigger
= -60;
2765 if (priv
->param_roamdelta
< 0)
2766 priv
->param_roamdelta
= 0;
2767 else if (priv
->param_roamdelta
> 2)
2768 priv
->param_roamdelta
= 2;
2770 if (modparam_workaround_interval
< 0)
2771 priv
->param_workaround_interval
= 500;
2773 priv
->param_workaround_interval
= modparam_workaround_interval
;
2775 rndis_set_config_parameter_str(usbdev
, "Country", priv
->param_country
);
2776 rndis_set_config_parameter_str(usbdev
, "FrameBursting",
2777 priv
->param_frameburst
? "1" : "0");
2778 rndis_set_config_parameter_str(usbdev
, "Afterburner",
2779 priv
->param_afterburner
? "1" : "0");
2780 sprintf(buf
, "%d", priv
->param_power_save
);
2781 rndis_set_config_parameter_str(usbdev
, "PowerSaveMode", buf
);
2782 sprintf(buf
, "%d", priv
->param_power_output
);
2783 rndis_set_config_parameter_str(usbdev
, "PwrOut", buf
);
2784 sprintf(buf
, "%d", priv
->param_roamtrigger
);
2785 rndis_set_config_parameter_str(usbdev
, "RoamTrigger", buf
);
2786 sprintf(buf
, "%d", priv
->param_roamdelta
);
2787 rndis_set_config_parameter_str(usbdev
, "RoamDelta", buf
);
2792 /* same as rndis_netdev_ops but with local multicast handler */
2793 static const struct net_device_ops rndis_wlan_netdev_ops
= {
2794 .ndo_open
= usbnet_open
,
2795 .ndo_stop
= usbnet_stop
,
2796 .ndo_start_xmit
= usbnet_start_xmit
,
2797 .ndo_tx_timeout
= usbnet_tx_timeout
,
2798 .ndo_set_mac_address
= eth_mac_addr
,
2799 .ndo_validate_addr
= eth_validate_addr
,
2800 .ndo_set_multicast_list
= rndis_wlan_set_multicast_list
,
2804 static int rndis_wlan_bind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2806 struct wiphy
*wiphy
;
2807 struct rndis_wlan_private
*priv
;
2811 /* allocate wiphy and rndis private data
2812 * NOTE: We only support a single virtual interface, so wiphy
2813 * and wireless_dev are somewhat synonymous for this device.
2815 wiphy
= wiphy_new(&rndis_config_ops
, sizeof(struct rndis_wlan_private
));
2819 priv
= wiphy_priv(wiphy
);
2820 usbdev
->net
->ieee80211_ptr
= &priv
->wdev
;
2821 priv
->wdev
.wiphy
= wiphy
;
2822 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
2824 /* These have to be initialized before calling generic_rndis_bind().
2825 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
2827 usbdev
->driver_priv
= priv
;
2828 usbdev
->net
->wireless_handlers
= &rndis_iw_handlers
;
2829 priv
->usbdev
= usbdev
;
2831 mutex_init(&priv
->command_lock
);
2832 spin_lock_init(&priv
->stats_lock
);
2834 /* because rndis_command() sleeps we need to use workqueue */
2835 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
2836 INIT_WORK(&priv
->work
, rndis_wlan_worker
);
2837 INIT_DELAYED_WORK(&priv
->stats_work
, rndis_update_wireless_stats
);
2838 INIT_DELAYED_WORK(&priv
->scan_work
, rndis_get_scan_results
);
2840 /* try bind rndis_host */
2841 retval
= generic_rndis_bind(usbdev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
2845 /* generic_rndis_bind set packet filter to multicast_all+
2846 * promisc mode which doesn't work well for our devices (device
2847 * picks up rssi to closest station instead of to access point).
2849 * rndis_host wants to avoid all OID as much as possible
2850 * so do promisc/multicast handling in rndis_wlan.
2852 usbdev
->net
->netdev_ops
= &rndis_wlan_netdev_ops
;
2854 tmp
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
2855 retval
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &tmp
,
2859 retval
= rndis_query_oid(usbdev
, OID_802_3_MAXIMUM_LIST_SIZE
, &tmp
,
2861 priv
->multicast_size
= le32_to_cpu(tmp
);
2862 if (retval
< 0 || priv
->multicast_size
< 0)
2863 priv
->multicast_size
= 0;
2864 if (priv
->multicast_size
> 0)
2865 usbdev
->net
->flags
|= IFF_MULTICAST
;
2867 usbdev
->net
->flags
&= ~IFF_MULTICAST
;
2869 priv
->iwstats
.qual
.qual
= 0;
2870 priv
->iwstats
.qual
.level
= 0;
2871 priv
->iwstats
.qual
.updated
= IW_QUAL_QUAL_UPDATED
2872 | IW_QUAL_LEVEL_UPDATED
2873 | IW_QUAL_NOISE_INVALID
2874 | IW_QUAL_QUAL_INVALID
2875 | IW_QUAL_LEVEL_INVALID
;
2877 /* fill-out wiphy structure and register w/ cfg80211 */
2878 memcpy(wiphy
->perm_addr
, usbdev
->net
->dev_addr
, ETH_ALEN
);
2879 wiphy
->privid
= rndis_wiphy_privid
;
2880 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
2881 | BIT(NL80211_IFTYPE_ADHOC
);
2882 wiphy
->max_scan_ssids
= 1;
2884 /* TODO: fill-out band information based on priv->caps */
2885 rndis_wlan_get_caps(usbdev
);
2887 memcpy(priv
->channels
, rndis_channels
, sizeof(rndis_channels
));
2888 memcpy(priv
->rates
, rndis_rates
, sizeof(rndis_rates
));
2889 priv
->band
.channels
= priv
->channels
;
2890 priv
->band
.n_channels
= ARRAY_SIZE(rndis_channels
);
2891 priv
->band
.bitrates
= priv
->rates
;
2892 priv
->band
.n_bitrates
= ARRAY_SIZE(rndis_rates
);
2893 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
2894 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_UNSPEC
;
2896 set_wiphy_dev(wiphy
, &usbdev
->udev
->dev
);
2898 if (wiphy_register(wiphy
)) {
2903 set_default_iw_params(usbdev
);
2905 /* set default rts/frag */
2906 rndis_set_wiphy_params(wiphy
,
2907 WIPHY_PARAM_FRAG_THRESHOLD
| WIPHY_PARAM_RTS_THRESHOLD
);
2911 disassociate(usbdev
, 1);
2912 netif_carrier_off(usbdev
->net
);
2917 cancel_delayed_work_sync(&priv
->stats_work
);
2918 cancel_delayed_work_sync(&priv
->scan_work
);
2919 cancel_work_sync(&priv
->work
);
2920 flush_workqueue(priv
->workqueue
);
2921 destroy_workqueue(priv
->workqueue
);
2928 static void rndis_wlan_unbind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2930 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2932 /* turn radio off */
2933 disassociate(usbdev
, 0);
2935 cancel_delayed_work_sync(&priv
->stats_work
);
2936 cancel_delayed_work_sync(&priv
->scan_work
);
2937 cancel_work_sync(&priv
->work
);
2938 flush_workqueue(priv
->workqueue
);
2939 destroy_workqueue(priv
->workqueue
);
2941 if (priv
&& priv
->wpa_ie_len
)
2942 kfree(priv
->wpa_ie
);
2944 rndis_unbind(usbdev
, intf
);
2946 wiphy_unregister(priv
->wdev
.wiphy
);
2947 wiphy_free(priv
->wdev
.wiphy
);
2951 static int rndis_wlan_reset(struct usbnet
*usbdev
)
2953 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2956 devdbg(usbdev
, "rndis_wlan_reset");
2958 retval
= rndis_reset(usbdev
);
2960 devwarn(usbdev
, "rndis_reset() failed: %d", retval
);
2962 /* rndis_reset cleared multicast list, so restore here.
2963 (set_multicast_list() also turns on current packet filter) */
2964 set_multicast_list(usbdev
);
2966 queue_delayed_work(priv
->workqueue
, &priv
->stats_work
,
2967 round_jiffies_relative(STATS_UPDATE_JIFFIES
));
2969 return deauthenticate(usbdev
);
2973 static int rndis_wlan_stop(struct usbnet
*usbdev
)
2975 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2979 devdbg(usbdev
, "rndis_wlan_stop");
2981 retval
= disassociate(usbdev
, 0);
2983 priv
->work_pending
= 0;
2984 cancel_delayed_work_sync(&priv
->stats_work
);
2985 cancel_delayed_work_sync(&priv
->scan_work
);
2986 cancel_work_sync(&priv
->work
);
2987 flush_workqueue(priv
->workqueue
);
2989 if (priv
->scan_request
) {
2990 cfg80211_scan_done(priv
->scan_request
, true);
2991 priv
->scan_request
= NULL
;
2994 /* Set current packet filter zero to block receiving data packets from
2997 rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
3004 static const struct driver_info bcm4320b_info
= {
3005 .description
= "Wireless RNDIS device, BCM4320b based",
3006 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3007 FLAG_AVOID_UNLINK_URBS
,
3008 .bind
= rndis_wlan_bind
,
3009 .unbind
= rndis_wlan_unbind
,
3010 .status
= rndis_status
,
3011 .rx_fixup
= rndis_rx_fixup
,
3012 .tx_fixup
= rndis_tx_fixup
,
3013 .reset
= rndis_wlan_reset
,
3014 .stop
= rndis_wlan_stop
,
3015 .early_init
= bcm4320b_early_init
,
3016 .indication
= rndis_wlan_indication
,
3019 static const struct driver_info bcm4320a_info
= {
3020 .description
= "Wireless RNDIS device, BCM4320a based",
3021 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3022 FLAG_AVOID_UNLINK_URBS
,
3023 .bind
= rndis_wlan_bind
,
3024 .unbind
= rndis_wlan_unbind
,
3025 .status
= rndis_status
,
3026 .rx_fixup
= rndis_rx_fixup
,
3027 .tx_fixup
= rndis_tx_fixup
,
3028 .reset
= rndis_wlan_reset
,
3029 .stop
= rndis_wlan_stop
,
3030 .early_init
= bcm4320a_early_init
,
3031 .indication
= rndis_wlan_indication
,
3034 static const struct driver_info rndis_wlan_info
= {
3035 .description
= "Wireless RNDIS device",
3036 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3037 FLAG_AVOID_UNLINK_URBS
,
3038 .bind
= rndis_wlan_bind
,
3039 .unbind
= rndis_wlan_unbind
,
3040 .status
= rndis_status
,
3041 .rx_fixup
= rndis_rx_fixup
,
3042 .tx_fixup
= rndis_tx_fixup
,
3043 .reset
= rndis_wlan_reset
,
3044 .stop
= rndis_wlan_stop
,
3045 .early_init
= bcm4320a_early_init
,
3046 .indication
= rndis_wlan_indication
,
3049 /*-------------------------------------------------------------------------*/
3051 static const struct usb_device_id products
[] = {
3052 #define RNDIS_MASTER_INTERFACE \
3053 .bInterfaceClass = USB_CLASS_COMM, \
3054 .bInterfaceSubClass = 2 /* ACM */, \
3055 .bInterfaceProtocol = 0x0ff
3057 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3058 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3061 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3062 | USB_DEVICE_ID_MATCH_DEVICE
,
3064 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
3065 RNDIS_MASTER_INTERFACE
,
3066 .driver_info
= (unsigned long) &bcm4320b_info
,
3068 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3069 | USB_DEVICE_ID_MATCH_DEVICE
,
3071 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
3072 RNDIS_MASTER_INTERFACE
,
3073 .driver_info
= (unsigned long) &bcm4320b_info
,
3075 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3076 | USB_DEVICE_ID_MATCH_DEVICE
,
3078 .idProduct
= 0x011b, /* Belkin F5D7051 */
3079 RNDIS_MASTER_INTERFACE
,
3080 .driver_info
= (unsigned long) &bcm4320b_info
,
3082 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3083 | USB_DEVICE_ID_MATCH_DEVICE
,
3084 .idVendor
= 0x1799, /* Belkin has two vendor ids */
3085 .idProduct
= 0x011b, /* Belkin F5D7051 */
3086 RNDIS_MASTER_INTERFACE
,
3087 .driver_info
= (unsigned long) &bcm4320b_info
,
3089 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3090 | USB_DEVICE_ID_MATCH_DEVICE
,
3092 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
3093 RNDIS_MASTER_INTERFACE
,
3094 .driver_info
= (unsigned long) &bcm4320b_info
,
3096 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3097 | USB_DEVICE_ID_MATCH_DEVICE
,
3099 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
3100 RNDIS_MASTER_INTERFACE
,
3101 .driver_info
= (unsigned long) &bcm4320b_info
,
3103 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3104 | USB_DEVICE_ID_MATCH_DEVICE
,
3106 .idProduct
= 0x1717, /* Asus WL169gE */
3107 RNDIS_MASTER_INTERFACE
,
3108 .driver_info
= (unsigned long) &bcm4320b_info
,
3110 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3111 | USB_DEVICE_ID_MATCH_DEVICE
,
3113 .idProduct
= 0xd11b, /* Eminent EM4045 */
3114 RNDIS_MASTER_INTERFACE
,
3115 .driver_info
= (unsigned long) &bcm4320b_info
,
3117 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3118 | USB_DEVICE_ID_MATCH_DEVICE
,
3120 .idProduct
= 0x0715, /* BT Voyager 1055 */
3121 RNDIS_MASTER_INTERFACE
,
3122 .driver_info
= (unsigned long) &bcm4320b_info
,
3124 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3125 * parameters available, hardware probably contain older firmware version with
3126 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3129 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3130 | USB_DEVICE_ID_MATCH_DEVICE
,
3132 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
3133 RNDIS_MASTER_INTERFACE
,
3134 .driver_info
= (unsigned long) &bcm4320a_info
,
3136 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3137 | USB_DEVICE_ID_MATCH_DEVICE
,
3139 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
3140 RNDIS_MASTER_INTERFACE
,
3141 .driver_info
= (unsigned long) &bcm4320a_info
,
3143 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3144 | USB_DEVICE_ID_MATCH_DEVICE
,
3146 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
3147 RNDIS_MASTER_INTERFACE
,
3148 .driver_info
= (unsigned long) &bcm4320a_info
,
3150 /* Generic Wireless RNDIS devices that we don't have exact
3151 * idVendor/idProduct/chip yet.
3154 /* RNDIS is MSFT's un-official variant of CDC ACM */
3155 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
3156 .driver_info
= (unsigned long) &rndis_wlan_info
,
3158 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3159 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
3160 .driver_info
= (unsigned long) &rndis_wlan_info
,
3164 MODULE_DEVICE_TABLE(usb
, products
);
3166 static struct usb_driver rndis_wlan_driver
= {
3167 .name
= "rndis_wlan",
3168 .id_table
= products
,
3169 .probe
= usbnet_probe
,
3170 .disconnect
= usbnet_disconnect
,
3171 .suspend
= usbnet_suspend
,
3172 .resume
= usbnet_resume
,
3175 static int __init
rndis_wlan_init(void)
3177 return usb_register(&rndis_wlan_driver
);
3179 module_init(rndis_wlan_init
);
3181 static void __exit
rndis_wlan_exit(void)
3183 usb_deregister(&rndis_wlan_driver
);
3185 module_exit(rndis_wlan_exit
);
3187 MODULE_AUTHOR("Bjorge Dijkstra");
3188 MODULE_AUTHOR("Jussi Kivilinna");
3189 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3190 MODULE_LICENSE("GPL");