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 <linux/slab.h>
45 #include <net/iw_handler.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
;
88 module_param_named(workaround_interval
, modparam_workaround_interval
,
90 MODULE_PARM_DESC(workaround_interval
,
91 "set stall workaround interval in msecs (0=disabled) (default: 0)");
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_CURRENT_ADDRESS cpu_to_le32(0x01010102)
105 #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
106 #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
108 #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
109 #define OID_802_11_SSID cpu_to_le32(0x0d010102)
110 #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
111 #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
112 #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
113 #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
114 #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
115 #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
116 #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
117 #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
118 #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
119 #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
120 #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
121 #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
122 #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
123 #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
124 #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
125 #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
126 #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
127 #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
128 #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
129 #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
130 #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
131 #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
134 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
135 #define WL_NOISE -96 /* typical noise level in dBm */
136 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
139 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
140 * based on wireless rndis) has default txpower of 13dBm.
141 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
142 * 100% : 20 mW ~ 13dBm
143 * 75% : 15 mW ~ 12dBm
144 * 50% : 10 mW ~ 10dBm
147 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
148 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
149 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
150 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
153 /* codes for "status" field of completion messages */
154 #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
155 #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
158 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
159 * slightly modified for datatype endianess, etc
161 #define NDIS_802_11_LENGTH_SSID 32
162 #define NDIS_802_11_LENGTH_RATES 8
163 #define NDIS_802_11_LENGTH_RATES_EX 16
165 enum ndis_80211_net_type
{
166 NDIS_80211_TYPE_FREQ_HOP
,
167 NDIS_80211_TYPE_DIRECT_SEQ
,
168 NDIS_80211_TYPE_OFDM_A
,
169 NDIS_80211_TYPE_OFDM_G
172 enum ndis_80211_net_infra
{
173 NDIS_80211_INFRA_ADHOC
,
174 NDIS_80211_INFRA_INFRA
,
175 NDIS_80211_INFRA_AUTO_UNKNOWN
178 enum ndis_80211_auth_mode
{
179 NDIS_80211_AUTH_OPEN
,
180 NDIS_80211_AUTH_SHARED
,
181 NDIS_80211_AUTH_AUTO_SWITCH
,
183 NDIS_80211_AUTH_WPA_PSK
,
184 NDIS_80211_AUTH_WPA_NONE
,
185 NDIS_80211_AUTH_WPA2
,
186 NDIS_80211_AUTH_WPA2_PSK
189 enum ndis_80211_encr_status
{
190 NDIS_80211_ENCR_WEP_ENABLED
,
191 NDIS_80211_ENCR_DISABLED
,
192 NDIS_80211_ENCR_WEP_KEY_ABSENT
,
193 NDIS_80211_ENCR_NOT_SUPPORTED
,
194 NDIS_80211_ENCR_TKIP_ENABLED
,
195 NDIS_80211_ENCR_TKIP_KEY_ABSENT
,
196 NDIS_80211_ENCR_CCMP_ENABLED
,
197 NDIS_80211_ENCR_CCMP_KEY_ABSENT
200 enum ndis_80211_priv_filter
{
201 NDIS_80211_PRIV_ACCEPT_ALL
,
202 NDIS_80211_PRIV_8021X_WEP
205 enum ndis_80211_status_type
{
206 NDIS_80211_STATUSTYPE_AUTHENTICATION
,
207 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
,
208 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
,
209 NDIS_80211_STATUSTYPE_RADIOSTATE
,
212 enum ndis_80211_media_stream_mode
{
213 NDIS_80211_MEDIA_STREAM_OFF
,
214 NDIS_80211_MEDIA_STREAM_ON
217 enum ndis_80211_radio_status
{
218 NDIS_80211_RADIO_STATUS_ON
,
219 NDIS_80211_RADIO_STATUS_HARDWARE_OFF
,
220 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF
,
223 enum ndis_80211_addkey_bits
{
224 NDIS_80211_ADDKEY_8021X_AUTH
= cpu_to_le32(1 << 28),
225 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
= cpu_to_le32(1 << 29),
226 NDIS_80211_ADDKEY_PAIRWISE_KEY
= cpu_to_le32(1 << 30),
227 NDIS_80211_ADDKEY_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
230 enum ndis_80211_addwep_bits
{
231 NDIS_80211_ADDWEP_PERCLIENT_KEY
= cpu_to_le32(1 << 30),
232 NDIS_80211_ADDWEP_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
235 struct ndis_80211_auth_request
{
240 } __attribute__((packed
));
242 struct ndis_80211_pmkid_candidate
{
246 } __attribute__((packed
));
248 struct ndis_80211_pmkid_cand_list
{
250 __le32 num_candidates
;
251 struct ndis_80211_pmkid_candidate candidate_list
[0];
252 } __attribute__((packed
));
254 struct ndis_80211_status_indication
{
257 __le32 media_stream_mode
;
259 struct ndis_80211_auth_request auth_request
[0];
260 struct ndis_80211_pmkid_cand_list cand_list
;
262 } __attribute__((packed
));
264 struct ndis_80211_ssid
{
266 u8 essid
[NDIS_802_11_LENGTH_SSID
];
267 } __attribute__((packed
));
269 struct ndis_80211_conf_freq_hop
{
274 } __attribute__((packed
));
276 struct ndis_80211_conf
{
278 __le32 beacon_period
;
281 struct ndis_80211_conf_freq_hop fh_config
;
282 } __attribute__((packed
));
284 struct ndis_80211_bssid_ex
{
288 struct ndis_80211_ssid ssid
;
292 struct ndis_80211_conf config
;
294 u8 rates
[NDIS_802_11_LENGTH_RATES_EX
];
297 } __attribute__((packed
));
299 struct ndis_80211_bssid_list_ex
{
301 struct ndis_80211_bssid_ex bssid
[0];
302 } __attribute__((packed
));
304 struct ndis_80211_fixed_ies
{
306 __le16 beacon_interval
;
308 } __attribute__((packed
));
310 struct ndis_80211_wep_key
{
315 } __attribute__((packed
));
317 struct ndis_80211_key
{
325 } __attribute__((packed
));
327 struct ndis_80211_remove_key
{
332 } __attribute__((packed
));
334 struct ndis_config_param
{
340 } __attribute__((packed
));
342 struct ndis_80211_assoc_info
{
347 __le16 listen_interval
;
348 u8 cur_ap_address
[6];
350 __le32 req_ie_length
;
351 __le32 offset_req_ies
;
358 __le32 resp_ie_length
;
359 __le32 offset_resp_ies
;
360 } __attribute__((packed
));
365 #define NET_TYPE_11FB 0
367 #define CAP_MODE_80211A 1
368 #define CAP_MODE_80211B 2
369 #define CAP_MODE_80211G 4
370 #define CAP_MODE_MASK 7
372 #define WORK_LINK_UP (1<<0)
373 #define WORK_LINK_DOWN (1<<1)
374 #define WORK_SET_MULTICAST_LIST (1<<2)
376 #define RNDIS_WLAN_ALG_NONE 0
377 #define RNDIS_WLAN_ALG_WEP (1<<0)
378 #define RNDIS_WLAN_ALG_TKIP (1<<1)
379 #define RNDIS_WLAN_ALG_CCMP (1<<2)
381 #define RNDIS_WLAN_KEY_MGMT_NONE 0
382 #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
383 #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
385 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
387 static const struct ieee80211_channel rndis_channels
[] = {
388 { .center_freq
= 2412 },
389 { .center_freq
= 2417 },
390 { .center_freq
= 2422 },
391 { .center_freq
= 2427 },
392 { .center_freq
= 2432 },
393 { .center_freq
= 2437 },
394 { .center_freq
= 2442 },
395 { .center_freq
= 2447 },
396 { .center_freq
= 2452 },
397 { .center_freq
= 2457 },
398 { .center_freq
= 2462 },
399 { .center_freq
= 2467 },
400 { .center_freq
= 2472 },
401 { .center_freq
= 2484 },
404 static const struct ieee80211_rate rndis_rates
[] = {
406 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
407 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
408 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
419 static const u32 rndis_cipher_suites
[] = {
420 WLAN_CIPHER_SUITE_WEP40
,
421 WLAN_CIPHER_SUITE_WEP104
,
422 WLAN_CIPHER_SUITE_TKIP
,
423 WLAN_CIPHER_SUITE_CCMP
,
426 struct rndis_wlan_encr_key
{
435 /* RNDIS device private data */
436 struct rndis_wlan_private
{
437 struct usbnet
*usbdev
;
439 struct wireless_dev wdev
;
441 struct cfg80211_scan_request
*scan_request
;
443 struct workqueue_struct
*workqueue
;
444 struct delayed_work dev_poller_work
;
445 struct delayed_work scan_work
;
446 struct work_struct work
;
447 struct mutex command_lock
;
448 unsigned long work_pending
;
451 struct ieee80211_supported_band band
;
452 struct ieee80211_channel channels
[ARRAY_SIZE(rndis_channels
)];
453 struct ieee80211_rate rates
[ARRAY_SIZE(rndis_rates
)];
454 u32 cipher_suites
[ARRAY_SIZE(rndis_cipher_suites
)];
459 /* module parameters */
460 char param_country
[4];
461 int param_frameburst
;
462 int param_afterburner
;
463 int param_power_save
;
464 int param_power_output
;
465 int param_roamtrigger
;
467 u32 param_workaround_interval
;
474 struct ndis_80211_ssid essid
;
475 __le32 current_command_oid
;
477 /* encryption stuff */
478 int encr_tx_key_index
;
479 struct rndis_wlan_encr_key encr_keys
[4];
480 enum nl80211_auth_type wpa_auth_type
;
486 int wpa_cipher_group
;
488 u8 command_buffer
[COMMAND_BUFFER_SIZE
];
494 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
495 struct net_device
*dev
,
496 enum nl80211_iftype type
, u32
*flags
,
497 struct vif_params
*params
);
499 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
500 struct cfg80211_scan_request
*request
);
502 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
);
504 static int rndis_set_tx_power(struct wiphy
*wiphy
, enum tx_power_setting type
,
506 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
);
508 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
509 struct cfg80211_connect_params
*sme
);
511 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
514 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
515 struct cfg80211_ibss_params
*params
);
517 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
);
519 static int rndis_set_channel(struct wiphy
*wiphy
,
520 struct ieee80211_channel
*chan
, enum nl80211_channel_type channel_type
);
522 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
523 u8 key_index
, const u8
*mac_addr
,
524 struct key_params
*params
);
526 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
527 u8 key_index
, const u8
*mac_addr
);
529 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
532 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
533 u8
*mac
, struct station_info
*sinfo
);
535 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
536 int idx
, u8
*mac
, struct station_info
*sinfo
);
538 static struct cfg80211_ops rndis_config_ops
= {
539 .change_virtual_intf
= rndis_change_virtual_intf
,
541 .set_wiphy_params
= rndis_set_wiphy_params
,
542 .set_tx_power
= rndis_set_tx_power
,
543 .get_tx_power
= rndis_get_tx_power
,
544 .connect
= rndis_connect
,
545 .disconnect
= rndis_disconnect
,
546 .join_ibss
= rndis_join_ibss
,
547 .leave_ibss
= rndis_leave_ibss
,
548 .set_channel
= rndis_set_channel
,
549 .add_key
= rndis_add_key
,
550 .del_key
= rndis_del_key
,
551 .set_default_key
= rndis_set_default_key
,
552 .get_station
= rndis_get_station
,
553 .dump_station
= rndis_dump_station
,
556 static void *rndis_wiphy_privid
= &rndis_wiphy_privid
;
559 static struct rndis_wlan_private
*get_rndis_wlan_priv(struct usbnet
*dev
)
561 return (struct rndis_wlan_private
*)dev
->driver_priv
;
564 static u32
get_bcm4320_power_dbm(struct rndis_wlan_private
*priv
)
566 switch (priv
->param_power_output
) {
569 return BCM4320_DEFAULT_TXPOWER_DBM_100
;
571 return BCM4320_DEFAULT_TXPOWER_DBM_75
;
573 return BCM4320_DEFAULT_TXPOWER_DBM_50
;
575 return BCM4320_DEFAULT_TXPOWER_DBM_25
;
579 static bool is_wpa_key(struct rndis_wlan_private
*priv
, int idx
)
581 int cipher
= priv
->encr_keys
[idx
].cipher
;
583 return (cipher
== WLAN_CIPHER_SUITE_CCMP
||
584 cipher
== WLAN_CIPHER_SUITE_TKIP
);
587 static int rndis_cipher_to_alg(u32 cipher
)
591 return RNDIS_WLAN_ALG_NONE
;
592 case WLAN_CIPHER_SUITE_WEP40
:
593 case WLAN_CIPHER_SUITE_WEP104
:
594 return RNDIS_WLAN_ALG_WEP
;
595 case WLAN_CIPHER_SUITE_TKIP
:
596 return RNDIS_WLAN_ALG_TKIP
;
597 case WLAN_CIPHER_SUITE_CCMP
:
598 return RNDIS_WLAN_ALG_CCMP
;
602 static int rndis_akm_suite_to_key_mgmt(u32 akm_suite
)
606 return RNDIS_WLAN_KEY_MGMT_NONE
;
607 case WLAN_AKM_SUITE_8021X
:
608 return RNDIS_WLAN_KEY_MGMT_802_1X
;
609 case WLAN_AKM_SUITE_PSK
:
610 return RNDIS_WLAN_KEY_MGMT_PSK
;
615 static const char *oid_to_string(__le32 oid
)
618 #define OID_STR(oid) case oid: return(#oid)
619 /* from rndis_host.h */
620 OID_STR(OID_802_3_PERMANENT_ADDRESS
);
621 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE
);
622 OID_STR(OID_GEN_CURRENT_PACKET_FILTER
);
623 OID_STR(OID_GEN_PHYSICAL_MEDIUM
);
625 /* from rndis_wlan.c */
626 OID_STR(OID_GEN_LINK_SPEED
);
627 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER
);
629 OID_STR(OID_GEN_XMIT_OK
);
630 OID_STR(OID_GEN_RCV_OK
);
631 OID_STR(OID_GEN_XMIT_ERROR
);
632 OID_STR(OID_GEN_RCV_ERROR
);
633 OID_STR(OID_GEN_RCV_NO_BUFFER
);
635 OID_STR(OID_802_3_CURRENT_ADDRESS
);
636 OID_STR(OID_802_3_MULTICAST_LIST
);
637 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE
);
639 OID_STR(OID_802_11_BSSID
);
640 OID_STR(OID_802_11_SSID
);
641 OID_STR(OID_802_11_INFRASTRUCTURE_MODE
);
642 OID_STR(OID_802_11_ADD_WEP
);
643 OID_STR(OID_802_11_REMOVE_WEP
);
644 OID_STR(OID_802_11_DISASSOCIATE
);
645 OID_STR(OID_802_11_AUTHENTICATION_MODE
);
646 OID_STR(OID_802_11_PRIVACY_FILTER
);
647 OID_STR(OID_802_11_BSSID_LIST_SCAN
);
648 OID_STR(OID_802_11_ENCRYPTION_STATUS
);
649 OID_STR(OID_802_11_ADD_KEY
);
650 OID_STR(OID_802_11_REMOVE_KEY
);
651 OID_STR(OID_802_11_ASSOCIATION_INFORMATION
);
652 OID_STR(OID_802_11_PMKID
);
653 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED
);
654 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE
);
655 OID_STR(OID_802_11_TX_POWER_LEVEL
);
656 OID_STR(OID_802_11_RSSI
);
657 OID_STR(OID_802_11_RSSI_TRIGGER
);
658 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD
);
659 OID_STR(OID_802_11_RTS_THRESHOLD
);
660 OID_STR(OID_802_11_SUPPORTED_RATES
);
661 OID_STR(OID_802_11_CONFIGURATION
);
662 OID_STR(OID_802_11_BSSID_LIST
);
669 static const char *oid_to_string(__le32 oid
)
675 /* translate error code */
676 static int rndis_error_status(__le32 rndis_status
)
679 switch (rndis_status
) {
680 case RNDIS_STATUS_SUCCESS
:
683 case RNDIS_STATUS_FAILURE
:
684 case RNDIS_STATUS_INVALID_DATA
:
687 case RNDIS_STATUS_NOT_SUPPORTED
:
690 case RNDIS_STATUS_ADAPTER_NOT_READY
:
691 case RNDIS_STATUS_ADAPTER_NOT_OPEN
:
698 static int rndis_query_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int *len
)
700 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
703 struct rndis_msg_hdr
*header
;
704 struct rndis_query
*get
;
705 struct rndis_query_c
*get_c
;
709 buflen
= *len
+ sizeof(*u
.get
);
710 if (buflen
< CONTROL_BUFFER_SIZE
)
711 buflen
= CONTROL_BUFFER_SIZE
;
713 if (buflen
> COMMAND_BUFFER_SIZE
) {
714 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
718 u
.buf
= priv
->command_buffer
;
721 mutex_lock(&priv
->command_lock
);
723 memset(u
.get
, 0, sizeof *u
.get
);
724 u
.get
->msg_type
= RNDIS_MSG_QUERY
;
725 u
.get
->msg_len
= cpu_to_le32(sizeof *u
.get
);
728 priv
->current_command_oid
= oid
;
729 ret
= rndis_command(dev
, u
.header
, buflen
);
730 priv
->current_command_oid
= 0;
732 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
733 __func__
, oid_to_string(oid
), ret
,
734 le32_to_cpu(u
.get_c
->status
));
737 memcpy(data
, u
.buf
+ le32_to_cpu(u
.get_c
->offset
) + 8, *len
);
739 ret
= le32_to_cpu(u
.get_c
->len
);
743 ret
= rndis_error_status(u
.get_c
->status
);
745 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
746 __func__
, oid_to_string(oid
),
747 le32_to_cpu(u
.get_c
->status
), ret
);
750 mutex_unlock(&priv
->command_lock
);
752 if (u
.buf
!= priv
->command_buffer
)
757 static int rndis_set_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int len
)
759 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
762 struct rndis_msg_hdr
*header
;
763 struct rndis_set
*set
;
764 struct rndis_set_c
*set_c
;
768 buflen
= len
+ sizeof(*u
.set
);
769 if (buflen
< CONTROL_BUFFER_SIZE
)
770 buflen
= CONTROL_BUFFER_SIZE
;
772 if (buflen
> COMMAND_BUFFER_SIZE
) {
773 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
777 u
.buf
= priv
->command_buffer
;
780 mutex_lock(&priv
->command_lock
);
782 memset(u
.set
, 0, sizeof *u
.set
);
783 u
.set
->msg_type
= RNDIS_MSG_SET
;
784 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
786 u
.set
->len
= cpu_to_le32(len
);
787 u
.set
->offset
= cpu_to_le32(sizeof(*u
.set
) - 8);
788 u
.set
->handle
= cpu_to_le32(0);
789 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
791 priv
->current_command_oid
= oid
;
792 ret
= rndis_command(dev
, u
.header
, buflen
);
793 priv
->current_command_oid
= 0;
795 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
796 __func__
, oid_to_string(oid
), ret
,
797 le32_to_cpu(u
.set_c
->status
));
800 ret
= rndis_error_status(u
.set_c
->status
);
803 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
804 __func__
, oid_to_string(oid
),
805 le32_to_cpu(u
.set_c
->status
), ret
);
808 mutex_unlock(&priv
->command_lock
);
810 if (u
.buf
!= priv
->command_buffer
)
815 static int rndis_reset(struct usbnet
*usbdev
)
817 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
818 struct rndis_reset
*reset
;
821 mutex_lock(&priv
->command_lock
);
823 reset
= (void *)priv
->command_buffer
;
824 memset(reset
, 0, sizeof(*reset
));
825 reset
->msg_type
= RNDIS_MSG_RESET
;
826 reset
->msg_len
= cpu_to_le32(sizeof(*reset
));
827 priv
->current_command_oid
= 0;
828 ret
= rndis_command(usbdev
, (void *)reset
, CONTROL_BUFFER_SIZE
);
830 mutex_unlock(&priv
->command_lock
);
838 * Specs say that we can only set config parameters only soon after device
840 * value_type: 0 = u32, 2 = unicode string
842 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
843 int value_type
, void *value
)
845 struct ndis_config_param
*infobuf
;
846 int value_len
, info_len
, param_len
, ret
, i
;
851 value_len
= sizeof(__le32
);
852 else if (value_type
== 2)
853 value_len
= strlen(value
) * sizeof(__le16
);
857 param_len
= strlen(param
) * sizeof(__le16
);
858 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
863 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
869 /* extra 12 bytes are for padding (debug output) */
870 memset(infobuf
, 0xCC, info_len
+ 12);
874 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %s\n",
877 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %d\n",
878 param
, *(u32
*)value
);
880 infobuf
->name_offs
= cpu_to_le32(sizeof(*infobuf
));
881 infobuf
->name_length
= cpu_to_le32(param_len
);
882 infobuf
->type
= cpu_to_le32(value_type
);
883 infobuf
->value_offs
= cpu_to_le32(sizeof(*infobuf
) + param_len
);
884 infobuf
->value_length
= cpu_to_le32(value_len
);
886 /* simple string to unicode string conversion */
887 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
888 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
889 unibuf
[i
] = cpu_to_le16(param
[i
]);
891 if (value_type
== 2) {
892 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
893 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
894 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
896 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
897 *dst_value
= cpu_to_le32(*(u32
*)value
);
901 netdev_dbg(dev
->net
, "info buffer (len: %d)\n", info_len
);
902 for (i
= 0; i
< info_len
; i
+= 12) {
903 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
904 netdev_dbg(dev
->net
, "%08X:%08X:%08X\n",
907 cpu_to_be32(tmp
[2]));
911 ret
= rndis_set_oid(dev
, OID_GEN_RNDIS_CONFIG_PARAMETER
,
914 netdev_dbg(dev
->net
, "setting rndis config parameter failed, %d\n",
921 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
922 char *param
, char *value
)
924 return rndis_set_config_parameter(dev
, param
, 2, value
);
928 * data conversion functions
930 static int level_to_qual(int level
)
932 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
933 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
939 static int set_infra_mode(struct usbnet
*usbdev
, int mode
);
940 static void restore_keys(struct usbnet
*usbdev
);
941 static int rndis_check_bssid_list(struct usbnet
*usbdev
);
943 static int set_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
945 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
948 ret
= rndis_set_oid(usbdev
, OID_802_11_SSID
, ssid
, sizeof(*ssid
));
950 netdev_warn(usbdev
->net
, "setting SSID failed (%08X)\n", ret
);
954 memcpy(&priv
->essid
, ssid
, sizeof(priv
->essid
));
955 priv
->radio_on
= true;
956 netdev_dbg(usbdev
->net
, "%s(): radio_on = true\n", __func__
);
962 static int set_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
966 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID
, bssid
, ETH_ALEN
);
968 netdev_warn(usbdev
->net
, "setting BSSID[%pM] failed (%08X)\n",
976 static int clear_bssid(struct usbnet
*usbdev
)
978 u8 broadcast_mac
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
980 return set_bssid(usbdev
, broadcast_mac
);
983 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
988 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID
, bssid
, &len
);
991 memset(bssid
, 0, ETH_ALEN
);
996 static int get_association_info(struct usbnet
*usbdev
,
997 struct ndis_80211_assoc_info
*info
, int len
)
999 return rndis_query_oid(usbdev
, OID_802_11_ASSOCIATION_INFORMATION
,
1003 static bool is_associated(struct usbnet
*usbdev
)
1005 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1009 if (!priv
->radio_on
)
1012 ret
= get_bssid(usbdev
, bssid
);
1014 return (ret
== 0 && !is_zero_ether_addr(bssid
));
1017 static int disassociate(struct usbnet
*usbdev
, bool reset_ssid
)
1019 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1020 struct ndis_80211_ssid ssid
;
1023 if (priv
->radio_on
) {
1024 ret
= rndis_set_oid(usbdev
, OID_802_11_DISASSOCIATE
, NULL
, 0);
1026 priv
->radio_on
= false;
1027 netdev_dbg(usbdev
->net
, "%s(): radio_on = false\n",
1035 /* disassociate causes radio to be turned off; if reset_ssid
1036 * is given, set random ssid to enable radio */
1038 /* Set device to infrastructure mode so we don't get ad-hoc
1039 * 'media connect' indications with the random ssid.
1041 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1043 ssid
.length
= cpu_to_le32(sizeof(ssid
.essid
));
1044 get_random_bytes(&ssid
.essid
[2], sizeof(ssid
.essid
)-2);
1045 ssid
.essid
[0] = 0x1;
1046 ssid
.essid
[1] = 0xff;
1047 for (i
= 2; i
< sizeof(ssid
.essid
); i
++)
1048 ssid
.essid
[i
] = 0x1 + (ssid
.essid
[i
] * 0xfe / 0xff);
1049 ret
= set_essid(usbdev
, &ssid
);
1054 static int set_auth_mode(struct usbnet
*usbdev
, u32 wpa_version
,
1055 enum nl80211_auth_type auth_type
, int keymgmt
)
1057 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1061 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1062 __func__
, wpa_version
, auth_type
, keymgmt
);
1064 if (wpa_version
& NL80211_WPA_VERSION_2
) {
1065 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1066 auth_mode
= NDIS_80211_AUTH_WPA2
;
1068 auth_mode
= NDIS_80211_AUTH_WPA2_PSK
;
1069 } else if (wpa_version
& NL80211_WPA_VERSION_1
) {
1070 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1071 auth_mode
= NDIS_80211_AUTH_WPA
;
1072 else if (keymgmt
& RNDIS_WLAN_KEY_MGMT_PSK
)
1073 auth_mode
= NDIS_80211_AUTH_WPA_PSK
;
1075 auth_mode
= NDIS_80211_AUTH_WPA_NONE
;
1076 } else if (auth_type
== NL80211_AUTHTYPE_SHARED_KEY
)
1077 auth_mode
= NDIS_80211_AUTH_SHARED
;
1078 else if (auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
)
1079 auth_mode
= NDIS_80211_AUTH_OPEN
;
1080 else if (auth_type
== NL80211_AUTHTYPE_AUTOMATIC
)
1081 auth_mode
= NDIS_80211_AUTH_AUTO_SWITCH
;
1085 tmp
= cpu_to_le32(auth_mode
);
1086 ret
= rndis_set_oid(usbdev
, OID_802_11_AUTHENTICATION_MODE
, &tmp
,
1089 netdev_warn(usbdev
->net
, "setting auth mode failed (%08X)\n",
1094 priv
->wpa_version
= wpa_version
;
1095 priv
->wpa_auth_type
= auth_type
;
1096 priv
->wpa_keymgmt
= keymgmt
;
1101 static int set_priv_filter(struct usbnet
*usbdev
)
1103 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1106 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x\n",
1107 __func__
, priv
->wpa_version
);
1109 if (priv
->wpa_version
& NL80211_WPA_VERSION_2
||
1110 priv
->wpa_version
& NL80211_WPA_VERSION_1
)
1111 tmp
= cpu_to_le32(NDIS_80211_PRIV_8021X_WEP
);
1113 tmp
= cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL
);
1115 return rndis_set_oid(usbdev
, OID_802_11_PRIVACY_FILTER
, &tmp
,
1119 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
1121 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1125 netdev_dbg(usbdev
->net
, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1126 __func__
, pairwise
, groupwise
);
1128 if (pairwise
& RNDIS_WLAN_ALG_CCMP
)
1129 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1130 else if (pairwise
& RNDIS_WLAN_ALG_TKIP
)
1131 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1132 else if (pairwise
& RNDIS_WLAN_ALG_WEP
)
1133 encr_mode
= NDIS_80211_ENCR_WEP_ENABLED
;
1134 else if (groupwise
& RNDIS_WLAN_ALG_CCMP
)
1135 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1136 else if (groupwise
& RNDIS_WLAN_ALG_TKIP
)
1137 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1139 encr_mode
= NDIS_80211_ENCR_DISABLED
;
1141 tmp
= cpu_to_le32(encr_mode
);
1142 ret
= rndis_set_oid(usbdev
, OID_802_11_ENCRYPTION_STATUS
, &tmp
,
1145 netdev_warn(usbdev
->net
, "setting encr mode failed (%08X)\n",
1150 priv
->wpa_cipher_pair
= pairwise
;
1151 priv
->wpa_cipher_group
= groupwise
;
1155 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
1157 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1161 netdev_dbg(usbdev
->net
, "%s(): infra_mode=0x%x\n",
1162 __func__
, priv
->infra_mode
);
1164 tmp
= cpu_to_le32(mode
);
1165 ret
= rndis_set_oid(usbdev
, OID_802_11_INFRASTRUCTURE_MODE
, &tmp
,
1168 netdev_warn(usbdev
->net
, "setting infra mode failed (%08X)\n",
1173 /* NDIS drivers clear keys when infrastructure mode is
1174 * changed. But Linux tools assume otherwise. So set the
1176 restore_keys(usbdev
);
1178 priv
->infra_mode
= mode
;
1182 static int set_rts_threshold(struct usbnet
*usbdev
, u32 rts_threshold
)
1186 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, rts_threshold
);
1188 if (rts_threshold
< 0 || rts_threshold
> 2347)
1189 rts_threshold
= 2347;
1191 tmp
= cpu_to_le32(rts_threshold
);
1192 return rndis_set_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
,
1196 static int set_frag_threshold(struct usbnet
*usbdev
, u32 frag_threshold
)
1200 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, frag_threshold
);
1202 if (frag_threshold
< 256 || frag_threshold
> 2346)
1203 frag_threshold
= 2346;
1205 tmp
= cpu_to_le32(frag_threshold
);
1206 return rndis_set_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1210 static void set_default_iw_params(struct usbnet
*usbdev
)
1212 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1213 set_auth_mode(usbdev
, 0, NL80211_AUTHTYPE_OPEN_SYSTEM
,
1214 RNDIS_WLAN_KEY_MGMT_NONE
);
1215 set_priv_filter(usbdev
);
1216 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1219 static int deauthenticate(struct usbnet
*usbdev
)
1223 ret
= disassociate(usbdev
, true);
1224 set_default_iw_params(usbdev
);
1228 static int set_channel(struct usbnet
*usbdev
, int channel
)
1230 struct ndis_80211_conf config
;
1231 unsigned int dsconfig
;
1234 netdev_dbg(usbdev
->net
, "%s(%d)\n", __func__
, channel
);
1236 /* this OID is valid only when not associated */
1237 if (is_associated(usbdev
))
1240 dsconfig
= ieee80211_dsss_chan_to_freq(channel
) * 1000;
1242 len
= sizeof(config
);
1243 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
1245 netdev_dbg(usbdev
->net
, "%s(): querying configuration failed\n",
1250 config
.ds_config
= cpu_to_le32(dsconfig
);
1251 ret
= rndis_set_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
,
1254 netdev_dbg(usbdev
->net
, "%s(): %d -> %d\n", __func__
, channel
, ret
);
1259 /* index must be 0 - N, as per NDIS */
1260 static int add_wep_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1263 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1264 struct ndis_80211_wep_key ndis_key
;
1268 netdev_dbg(usbdev
->net
, "%s(idx: %d, len: %d)\n",
1269 __func__
, index
, key_len
);
1271 if ((key_len
!= 5 && key_len
!= 13) || index
< 0 || index
> 3)
1275 cipher
= WLAN_CIPHER_SUITE_WEP40
;
1277 cipher
= WLAN_CIPHER_SUITE_WEP104
;
1279 memset(&ndis_key
, 0, sizeof(ndis_key
));
1281 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
));
1282 ndis_key
.length
= cpu_to_le32(key_len
);
1283 ndis_key
.index
= cpu_to_le32(index
);
1284 memcpy(&ndis_key
.material
, key
, key_len
);
1286 if (index
== priv
->encr_tx_key_index
) {
1287 ndis_key
.index
|= NDIS_80211_ADDWEP_TRANSMIT_KEY
;
1288 ret
= set_encr_mode(usbdev
, RNDIS_WLAN_ALG_WEP
,
1289 RNDIS_WLAN_ALG_NONE
);
1291 netdev_warn(usbdev
->net
, "encryption couldn't be enabled (%08X)\n",
1295 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_WEP
, &ndis_key
,
1298 netdev_warn(usbdev
->net
, "adding encryption key %d failed (%08X)\n",
1303 priv
->encr_keys
[index
].len
= key_len
;
1304 priv
->encr_keys
[index
].cipher
= cipher
;
1305 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1306 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1311 static int add_wpa_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1312 int index
, const u8
*addr
, const u8
*rx_seq
,
1313 int seq_len
, u32 cipher
, __le32 flags
)
1315 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1316 struct ndis_80211_key ndis_key
;
1320 if (index
< 0 || index
>= 4) {
1321 netdev_dbg(usbdev
->net
, "%s(): index out of range (%i)\n",
1325 if (key_len
> sizeof(ndis_key
.material
) || key_len
< 0) {
1326 netdev_dbg(usbdev
->net
, "%s(): key length out of range (%i)\n",
1330 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
) {
1331 if (!rx_seq
|| seq_len
<= 0) {
1332 netdev_dbg(usbdev
->net
, "%s(): recv seq flag without buffer\n",
1336 if (rx_seq
&& seq_len
> sizeof(ndis_key
.rsc
)) {
1337 netdev_dbg(usbdev
->net
, "%s(): too big recv seq buffer\n", __func__
);
1342 is_addr_ok
= addr
&& !is_zero_ether_addr(addr
) &&
1343 !is_broadcast_ether_addr(addr
);
1344 if ((flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) && !is_addr_ok
) {
1345 netdev_dbg(usbdev
->net
, "%s(): pairwise but bssid invalid (%pM)\n",
1350 netdev_dbg(usbdev
->net
, "%s(%i): flags:%i%i%i\n",
1352 !!(flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
),
1353 !!(flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
),
1354 !!(flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
));
1356 memset(&ndis_key
, 0, sizeof(ndis_key
));
1358 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
) -
1359 sizeof(ndis_key
.material
) + key_len
);
1360 ndis_key
.length
= cpu_to_le32(key_len
);
1361 ndis_key
.index
= cpu_to_le32(index
) | flags
;
1363 if (cipher
== WLAN_CIPHER_SUITE_TKIP
&& key_len
== 32) {
1364 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1365 * different order than NDIS spec, so swap the order here. */
1366 memcpy(ndis_key
.material
, key
, 16);
1367 memcpy(ndis_key
.material
+ 16, key
+ 24, 8);
1368 memcpy(ndis_key
.material
+ 24, key
+ 16, 8);
1370 memcpy(ndis_key
.material
, key
, key_len
);
1372 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
)
1373 memcpy(ndis_key
.rsc
, rx_seq
, seq_len
);
1375 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) {
1377 memcpy(ndis_key
.bssid
, addr
, ETH_ALEN
);
1380 if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
1381 memset(ndis_key
.bssid
, 0xff, ETH_ALEN
);
1383 get_bssid(usbdev
, ndis_key
.bssid
);
1386 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_KEY
, &ndis_key
,
1387 le32_to_cpu(ndis_key
.size
));
1388 netdev_dbg(usbdev
->net
, "%s(): OID_802_11_ADD_KEY -> %08X\n",
1393 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
1394 priv
->encr_keys
[index
].len
= key_len
;
1395 priv
->encr_keys
[index
].cipher
= cipher
;
1396 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1397 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
)
1398 memcpy(&priv
->encr_keys
[index
].bssid
, ndis_key
.bssid
, ETH_ALEN
);
1400 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1402 if (flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
)
1403 priv
->encr_tx_key_index
= index
;
1408 static int restore_key(struct usbnet
*usbdev
, int key_idx
)
1410 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1411 struct rndis_wlan_encr_key key
;
1413 if (is_wpa_key(priv
, key_idx
))
1416 key
= priv
->encr_keys
[key_idx
];
1418 netdev_dbg(usbdev
->net
, "%s(): %i:%i\n", __func__
, key_idx
, key
.len
);
1423 return add_wep_key(usbdev
, key
.material
, key
.len
, key_idx
);
1426 static void restore_keys(struct usbnet
*usbdev
)
1430 for (i
= 0; i
< 4; i
++)
1431 restore_key(usbdev
, i
);
1434 static void clear_key(struct rndis_wlan_private
*priv
, int idx
)
1436 memset(&priv
->encr_keys
[idx
], 0, sizeof(priv
->encr_keys
[idx
]));
1439 /* remove_key is for both wep and wpa */
1440 static int remove_key(struct usbnet
*usbdev
, int index
, const u8
*bssid
)
1442 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1443 struct ndis_80211_remove_key remove_key
;
1448 if (priv
->encr_keys
[index
].len
== 0)
1451 is_wpa
= is_wpa_key(priv
, index
);
1453 netdev_dbg(usbdev
->net
, "%s(): %i:%s:%i\n",
1454 __func__
, index
, is_wpa
? "wpa" : "wep",
1455 priv
->encr_keys
[index
].len
);
1457 clear_key(priv
, index
);
1460 remove_key
.size
= cpu_to_le32(sizeof(remove_key
));
1461 remove_key
.index
= cpu_to_le32(index
);
1464 if (!is_broadcast_ether_addr(bssid
))
1466 NDIS_80211_ADDKEY_PAIRWISE_KEY
;
1467 memcpy(remove_key
.bssid
, bssid
,
1468 sizeof(remove_key
.bssid
));
1470 memset(remove_key
.bssid
, 0xff,
1471 sizeof(remove_key
.bssid
));
1473 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_KEY
, &remove_key
,
1474 sizeof(remove_key
));
1478 keyindex
= cpu_to_le32(index
);
1479 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_WEP
, &keyindex
,
1482 netdev_warn(usbdev
->net
,
1483 "removing encryption key %d failed (%08X)\n",
1489 /* if it is transmit key, disable encryption */
1490 if (index
== priv
->encr_tx_key_index
)
1491 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1496 static void set_multicast_list(struct usbnet
*usbdev
)
1498 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1499 struct dev_mc_list
*mclist
;
1500 __le32 filter
, basefilter
;
1502 char *mc_addrs
= NULL
;
1505 basefilter
= filter
= RNDIS_PACKET_TYPE_DIRECTED
|
1506 RNDIS_PACKET_TYPE_BROADCAST
;
1508 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1509 filter
|= RNDIS_PACKET_TYPE_PROMISCUOUS
|
1510 RNDIS_PACKET_TYPE_ALL_LOCAL
;
1511 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
) {
1512 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1515 if (filter
!= basefilter
)
1519 * mc_list should be accessed holding the lock, so copy addresses to
1520 * local buffer first.
1522 netif_addr_lock_bh(usbdev
->net
);
1523 mc_count
= netdev_mc_count(usbdev
->net
);
1524 if (mc_count
> priv
->multicast_size
) {
1525 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1526 } else if (mc_count
) {
1529 mc_addrs
= kmalloc(mc_count
* ETH_ALEN
, GFP_ATOMIC
);
1531 netdev_warn(usbdev
->net
,
1532 "couldn't alloc %d bytes of memory\n",
1533 mc_count
* ETH_ALEN
);
1534 netif_addr_unlock_bh(usbdev
->net
);
1538 netdev_for_each_mc_addr(mclist
, usbdev
->net
)
1539 memcpy(mc_addrs
+ i
++ * ETH_ALEN
,
1540 mclist
->dmi_addr
, ETH_ALEN
);
1542 netif_addr_unlock_bh(usbdev
->net
);
1544 if (filter
!= basefilter
)
1548 ret
= rndis_set_oid(usbdev
, OID_802_3_MULTICAST_LIST
, mc_addrs
,
1549 mc_count
* ETH_ALEN
);
1552 filter
|= RNDIS_PACKET_TYPE_MULTICAST
;
1554 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1556 netdev_dbg(usbdev
->net
, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1557 mc_count
, priv
->multicast_size
, ret
);
1561 ret
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1564 netdev_warn(usbdev
->net
, "couldn't set packet filter: %08x\n",
1565 le32_to_cpu(filter
));
1568 netdev_dbg(usbdev
->net
, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1569 le32_to_cpu(filter
), ret
);
1575 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
1576 struct net_device
*dev
,
1577 enum nl80211_iftype type
, u32
*flags
,
1578 struct vif_params
*params
)
1580 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1581 struct usbnet
*usbdev
= priv
->usbdev
;
1585 case NL80211_IFTYPE_ADHOC
:
1586 mode
= NDIS_80211_INFRA_ADHOC
;
1588 case NL80211_IFTYPE_STATION
:
1589 mode
= NDIS_80211_INFRA_INFRA
;
1595 priv
->wdev
.iftype
= type
;
1597 return set_infra_mode(usbdev
, mode
);
1600 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1602 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1603 struct usbnet
*usbdev
= priv
->usbdev
;
1606 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
1607 err
= set_frag_threshold(usbdev
, wiphy
->frag_threshold
);
1612 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
1613 err
= set_rts_threshold(usbdev
, wiphy
->rts_threshold
);
1621 static int rndis_set_tx_power(struct wiphy
*wiphy
, enum tx_power_setting type
,
1624 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1625 struct usbnet
*usbdev
= priv
->usbdev
;
1627 netdev_dbg(usbdev
->net
, "%s(): type:0x%x dbm:%i\n",
1628 __func__
, type
, dbm
);
1630 /* Device doesn't support changing txpower after initialization, only
1631 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1634 if (type
== TX_POWER_AUTOMATIC
|| dbm
== get_bcm4320_power_dbm(priv
)) {
1635 if (!priv
->radio_on
)
1636 disassociate(usbdev
, true); /* turn on radio */
1644 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
)
1646 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1647 struct usbnet
*usbdev
= priv
->usbdev
;
1649 *dbm
= get_bcm4320_power_dbm(priv
);
1651 netdev_dbg(usbdev
->net
, "%s(): dbm:%i\n", __func__
, *dbm
);
1656 #define SCAN_DELAY_JIFFIES (6 * HZ)
1657 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
1658 struct cfg80211_scan_request
*request
)
1660 struct usbnet
*usbdev
= netdev_priv(dev
);
1661 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1665 netdev_dbg(usbdev
->net
, "cfg80211.scan\n");
1667 /* Get current bssid list from device before new scan, as new scan
1668 * clears internal bssid list.
1670 rndis_check_bssid_list(usbdev
);
1675 if (priv
->scan_request
&& priv
->scan_request
!= request
)
1678 priv
->scan_request
= request
;
1680 tmp
= cpu_to_le32(1);
1681 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
1684 /* Wait before retrieving scan results from device */
1685 queue_delayed_work(priv
->workqueue
, &priv
->scan_work
,
1686 SCAN_DELAY_JIFFIES
);
1692 static struct cfg80211_bss
*rndis_bss_info_update(struct usbnet
*usbdev
,
1693 struct ndis_80211_bssid_ex
*bssid
)
1695 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1696 struct ieee80211_channel
*channel
;
1700 u16 beacon_interval
;
1701 struct ndis_80211_fixed_ies
*fixed
;
1702 int ie_len
, bssid_len
;
1705 netdev_dbg(usbdev
->net
, " found bssid: '%.32s' [%pM]\n",
1706 bssid
->ssid
.essid
, bssid
->mac
);
1708 /* parse bssid structure */
1709 bssid_len
= le32_to_cpu(bssid
->length
);
1711 if (bssid_len
< sizeof(struct ndis_80211_bssid_ex
) +
1712 sizeof(struct ndis_80211_fixed_ies
))
1715 fixed
= (struct ndis_80211_fixed_ies
*)bssid
->ies
;
1717 ie
= (void *)(bssid
->ies
+ sizeof(struct ndis_80211_fixed_ies
));
1718 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1719 (int)le32_to_cpu(bssid
->ie_length
));
1720 ie_len
-= sizeof(struct ndis_80211_fixed_ies
);
1724 /* extract data for cfg80211_inform_bss */
1725 channel
= ieee80211_get_channel(priv
->wdev
.wiphy
,
1726 KHZ_TO_MHZ(le32_to_cpu(bssid
->config
.ds_config
)));
1730 signal
= level_to_qual(le32_to_cpu(bssid
->rssi
));
1731 timestamp
= le64_to_cpu(*(__le64
*)fixed
->timestamp
);
1732 capability
= le16_to_cpu(fixed
->capabilities
);
1733 beacon_interval
= le16_to_cpu(fixed
->beacon_interval
);
1735 return cfg80211_inform_bss(priv
->wdev
.wiphy
, channel
, bssid
->mac
,
1736 timestamp
, capability
, beacon_interval
, ie
, ie_len
, signal
,
1740 static int rndis_check_bssid_list(struct usbnet
*usbdev
)
1743 struct ndis_80211_bssid_list_ex
*bssid_list
;
1744 struct ndis_80211_bssid_ex
*bssid
;
1745 int ret
= -EINVAL
, len
, count
, bssid_len
;
1746 bool resized
= false;
1748 netdev_dbg(usbdev
->net
, "check_bssid_list\n");
1750 len
= CONTROL_BUFFER_SIZE
;
1752 buf
= kmalloc(len
, GFP_KERNEL
);
1758 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
1762 if (!resized
&& len
> CONTROL_BUFFER_SIZE
) {
1769 bssid
= bssid_list
->bssid
;
1770 bssid_len
= le32_to_cpu(bssid
->length
);
1771 count
= le32_to_cpu(bssid_list
->num_items
);
1772 netdev_dbg(usbdev
->net
, "check_bssid_list: %d BSSIDs found (buflen: %d)\n",
1775 while (count
&& ((void *)bssid
+ bssid_len
) <= (buf
+ len
)) {
1776 rndis_bss_info_update(usbdev
, bssid
);
1778 bssid
= (void *)bssid
+ bssid_len
;
1779 bssid_len
= le32_to_cpu(bssid
->length
);
1788 static void rndis_get_scan_results(struct work_struct
*work
)
1790 struct rndis_wlan_private
*priv
=
1791 container_of(work
, struct rndis_wlan_private
, scan_work
.work
);
1792 struct usbnet
*usbdev
= priv
->usbdev
;
1795 netdev_dbg(usbdev
->net
, "get_scan_results\n");
1797 if (!priv
->scan_request
)
1800 ret
= rndis_check_bssid_list(usbdev
);
1802 cfg80211_scan_done(priv
->scan_request
, ret
< 0);
1804 priv
->scan_request
= NULL
;
1807 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
1808 struct cfg80211_connect_params
*sme
)
1810 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1811 struct usbnet
*usbdev
= priv
->usbdev
;
1812 struct ieee80211_channel
*channel
= sme
->channel
;
1813 struct ndis_80211_ssid ssid
;
1814 int pairwise
= RNDIS_WLAN_ALG_NONE
;
1815 int groupwise
= RNDIS_WLAN_ALG_NONE
;
1816 int keymgmt
= RNDIS_WLAN_KEY_MGMT_NONE
;
1817 int length
, i
, ret
, chan
= -1;
1820 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1822 groupwise
= rndis_cipher_to_alg(sme
->crypto
.cipher_group
);
1823 for (i
= 0; i
< sme
->crypto
.n_ciphers_pairwise
; i
++)
1825 rndis_cipher_to_alg(sme
->crypto
.ciphers_pairwise
[i
]);
1827 if (sme
->crypto
.n_ciphers_pairwise
> 0 &&
1828 pairwise
== RNDIS_WLAN_ALG_NONE
) {
1829 netdev_err(usbdev
->net
, "Unsupported pairwise cipher\n");
1833 for (i
= 0; i
< sme
->crypto
.n_akm_suites
; i
++)
1835 rndis_akm_suite_to_key_mgmt(sme
->crypto
.akm_suites
[i
]);
1837 if (sme
->crypto
.n_akm_suites
> 0 &&
1838 keymgmt
== RNDIS_WLAN_KEY_MGMT_NONE
) {
1839 netdev_err(usbdev
->net
, "Invalid keymgmt\n");
1843 netdev_dbg(usbdev
->net
, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
1844 sme
->ssid
, sme
->bssid
, chan
,
1845 sme
->privacy
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
1846 groupwise
, pairwise
, keymgmt
);
1848 if (is_associated(usbdev
))
1849 disassociate(usbdev
, false);
1851 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1853 netdev_dbg(usbdev
->net
, "connect: set_infra_mode failed, %d\n",
1855 goto err_turn_radio_on
;
1858 ret
= set_auth_mode(usbdev
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
1861 netdev_dbg(usbdev
->net
, "connect: set_auth_mode failed, %d\n",
1863 goto err_turn_radio_on
;
1866 set_priv_filter(usbdev
);
1868 ret
= set_encr_mode(usbdev
, pairwise
, groupwise
);
1870 netdev_dbg(usbdev
->net
, "connect: set_encr_mode failed, %d\n",
1872 goto err_turn_radio_on
;
1876 ret
= set_channel(usbdev
, chan
);
1878 netdev_dbg(usbdev
->net
, "connect: set_channel failed, %d\n",
1880 goto err_turn_radio_on
;
1884 if (sme
->key
&& ((groupwise
| pairwise
) & RNDIS_WLAN_ALG_WEP
)) {
1885 priv
->encr_tx_key_index
= sme
->key_idx
;
1886 ret
= add_wep_key(usbdev
, sme
->key
, sme
->key_len
, sme
->key_idx
);
1888 netdev_dbg(usbdev
->net
, "connect: add_wep_key failed, %d (%d, %d)\n",
1889 ret
, sme
->key_len
, sme
->key_idx
);
1890 goto err_turn_radio_on
;
1894 if (sme
->bssid
&& !is_zero_ether_addr(sme
->bssid
) &&
1895 !is_broadcast_ether_addr(sme
->bssid
)) {
1896 ret
= set_bssid(usbdev
, sme
->bssid
);
1898 netdev_dbg(usbdev
->net
, "connect: set_bssid failed, %d\n",
1900 goto err_turn_radio_on
;
1903 clear_bssid(usbdev
);
1905 length
= sme
->ssid_len
;
1906 if (length
> NDIS_802_11_LENGTH_SSID
)
1907 length
= NDIS_802_11_LENGTH_SSID
;
1909 memset(&ssid
, 0, sizeof(ssid
));
1910 ssid
.length
= cpu_to_le32(length
);
1911 memcpy(ssid
.essid
, sme
->ssid
, length
);
1913 /* Pause and purge rx queue, so we don't pass packets before
1914 * 'media connect'-indication.
1916 usbnet_pause_rx(usbdev
);
1917 usbnet_purge_paused_rxq(usbdev
);
1919 ret
= set_essid(usbdev
, &ssid
);
1921 netdev_dbg(usbdev
->net
, "connect: set_essid failed, %d\n", ret
);
1925 disassociate(usbdev
, true);
1930 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1933 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1934 struct usbnet
*usbdev
= priv
->usbdev
;
1936 netdev_dbg(usbdev
->net
, "cfg80211.disconnect(%d)\n", reason_code
);
1938 priv
->connected
= false;
1939 memset(priv
->bssid
, 0, ETH_ALEN
);
1941 return deauthenticate(usbdev
);
1944 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1945 struct cfg80211_ibss_params
*params
)
1947 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1948 struct usbnet
*usbdev
= priv
->usbdev
;
1949 struct ieee80211_channel
*channel
= params
->channel
;
1950 struct ndis_80211_ssid ssid
;
1951 enum nl80211_auth_type auth_type
;
1952 int ret
, alg
, length
, chan
= -1;
1955 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1957 /* TODO: How to handle ad-hoc encryption?
1958 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
1959 * pre-shared for encryption (open/shared/wpa), is key set before
1960 * join_ibss? Which auth_type to use (not in params)? What about WPA?
1962 if (params
->privacy
) {
1963 auth_type
= NL80211_AUTHTYPE_SHARED_KEY
;
1964 alg
= RNDIS_WLAN_ALG_WEP
;
1966 auth_type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
1967 alg
= RNDIS_WLAN_ALG_NONE
;
1970 netdev_dbg(usbdev
->net
, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
1971 params
->ssid
, params
->bssid
, chan
, params
->privacy
);
1973 if (is_associated(usbdev
))
1974 disassociate(usbdev
, false);
1976 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_ADHOC
);
1978 netdev_dbg(usbdev
->net
, "join_ibss: set_infra_mode failed, %d\n",
1980 goto err_turn_radio_on
;
1983 ret
= set_auth_mode(usbdev
, 0, auth_type
, RNDIS_WLAN_KEY_MGMT_NONE
);
1985 netdev_dbg(usbdev
->net
, "join_ibss: set_auth_mode failed, %d\n",
1987 goto err_turn_radio_on
;
1990 set_priv_filter(usbdev
);
1992 ret
= set_encr_mode(usbdev
, alg
, RNDIS_WLAN_ALG_NONE
);
1994 netdev_dbg(usbdev
->net
, "join_ibss: set_encr_mode failed, %d\n",
1996 goto err_turn_radio_on
;
2000 ret
= set_channel(usbdev
, chan
);
2002 netdev_dbg(usbdev
->net
, "join_ibss: set_channel failed, %d\n",
2004 goto err_turn_radio_on
;
2008 if (params
->bssid
&& !is_zero_ether_addr(params
->bssid
) &&
2009 !is_broadcast_ether_addr(params
->bssid
)) {
2010 ret
= set_bssid(usbdev
, params
->bssid
);
2012 netdev_dbg(usbdev
->net
, "join_ibss: set_bssid failed, %d\n",
2014 goto err_turn_radio_on
;
2017 clear_bssid(usbdev
);
2019 length
= params
->ssid_len
;
2020 if (length
> NDIS_802_11_LENGTH_SSID
)
2021 length
= NDIS_802_11_LENGTH_SSID
;
2023 memset(&ssid
, 0, sizeof(ssid
));
2024 ssid
.length
= cpu_to_le32(length
);
2025 memcpy(ssid
.essid
, params
->ssid
, length
);
2027 /* Don't need to pause rx queue for ad-hoc. */
2028 usbnet_purge_paused_rxq(usbdev
);
2029 usbnet_resume_rx(usbdev
);
2031 ret
= set_essid(usbdev
, &ssid
);
2033 netdev_dbg(usbdev
->net
, "join_ibss: set_essid failed, %d\n",
2038 disassociate(usbdev
, true);
2043 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2045 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2046 struct usbnet
*usbdev
= priv
->usbdev
;
2048 netdev_dbg(usbdev
->net
, "cfg80211.leave_ibss()\n");
2050 priv
->connected
= false;
2051 memset(priv
->bssid
, 0, ETH_ALEN
);
2053 return deauthenticate(usbdev
);
2056 static int rndis_set_channel(struct wiphy
*wiphy
,
2057 struct ieee80211_channel
*chan
, enum nl80211_channel_type channel_type
)
2059 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2060 struct usbnet
*usbdev
= priv
->usbdev
;
2062 return set_channel(usbdev
,
2063 ieee80211_frequency_to_channel(chan
->center_freq
));
2066 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2067 u8 key_index
, const u8
*mac_addr
,
2068 struct key_params
*params
)
2070 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2071 struct usbnet
*usbdev
= priv
->usbdev
;
2074 netdev_dbg(usbdev
->net
, "%s(%i, %pM, %08x)\n",
2075 __func__
, key_index
, mac_addr
, params
->cipher
);
2077 switch (params
->cipher
) {
2078 case WLAN_CIPHER_SUITE_WEP40
:
2079 case WLAN_CIPHER_SUITE_WEP104
:
2080 return add_wep_key(usbdev
, params
->key
, params
->key_len
,
2082 case WLAN_CIPHER_SUITE_TKIP
:
2083 case WLAN_CIPHER_SUITE_CCMP
:
2086 if (params
->seq
&& params
->seq_len
> 0)
2087 flags
|= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
;
2089 flags
|= NDIS_80211_ADDKEY_PAIRWISE_KEY
|
2090 NDIS_80211_ADDKEY_TRANSMIT_KEY
;
2092 return add_wpa_key(usbdev
, params
->key
, params
->key_len
,
2093 key_index
, mac_addr
, params
->seq
,
2094 params
->seq_len
, params
->cipher
, flags
);
2096 netdev_dbg(usbdev
->net
, "%s(): unsupported cipher %08x\n",
2097 __func__
, params
->cipher
);
2102 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2103 u8 key_index
, const u8
*mac_addr
)
2105 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2106 struct usbnet
*usbdev
= priv
->usbdev
;
2108 netdev_dbg(usbdev
->net
, "%s(%i, %pM)\n", __func__
, key_index
, mac_addr
);
2110 return remove_key(usbdev
, key_index
, mac_addr
);
2113 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2116 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2117 struct usbnet
*usbdev
= priv
->usbdev
;
2118 struct rndis_wlan_encr_key key
;
2120 netdev_dbg(usbdev
->net
, "%s(%i)\n", __func__
, key_index
);
2122 priv
->encr_tx_key_index
= key_index
;
2124 key
= priv
->encr_keys
[key_index
];
2126 return add_wep_key(usbdev
, key
.material
, key
.len
, key_index
);
2129 static void rndis_fill_station_info(struct usbnet
*usbdev
,
2130 struct station_info
*sinfo
)
2132 __le32 linkspeed
, rssi
;
2135 memset(sinfo
, 0, sizeof(*sinfo
));
2137 len
= sizeof(linkspeed
);
2138 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &linkspeed
, &len
);
2140 sinfo
->txrate
.legacy
= le32_to_cpu(linkspeed
) / 1000;
2141 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
2145 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2147 sinfo
->signal
= level_to_qual(le32_to_cpu(rssi
));
2148 sinfo
->filled
|= STATION_INFO_SIGNAL
;
2152 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2153 u8
*mac
, struct station_info
*sinfo
)
2155 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2156 struct usbnet
*usbdev
= priv
->usbdev
;
2158 if (compare_ether_addr(priv
->bssid
, mac
))
2161 rndis_fill_station_info(usbdev
, sinfo
);
2166 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2167 int idx
, u8
*mac
, struct station_info
*sinfo
)
2169 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2170 struct usbnet
*usbdev
= priv
->usbdev
;
2175 memcpy(mac
, priv
->bssid
, ETH_ALEN
);
2177 rndis_fill_station_info(usbdev
, sinfo
);
2183 * workers, indication handlers, device poller
2185 static void rndis_wlan_do_link_up_work(struct usbnet
*usbdev
)
2187 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2188 struct ndis_80211_assoc_info
*info
;
2189 u8 assoc_buf
[sizeof(*info
) + IW_CUSTOM_MAX
+ 32];
2191 int resp_ie_len
, req_ie_len
;
2192 u8
*req_ie
, *resp_ie
;
2194 bool roamed
= false;
2196 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
&& priv
->connected
) {
2197 /* received media connect indication while connected, either
2198 * device reassociated with same AP or roamed to new. */
2207 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2208 memset(assoc_buf
, 0, sizeof(assoc_buf
));
2209 info
= (void *)assoc_buf
;
2211 /* Get association info IEs from device and send them back to
2213 ret
= get_association_info(usbdev
, info
, sizeof(assoc_buf
));
2215 req_ie_len
= le32_to_cpu(info
->req_ie_length
);
2216 if (req_ie_len
> 0) {
2217 offset
= le32_to_cpu(info
->offset_req_ies
);
2218 req_ie
= (u8
*)info
+ offset
;
2221 resp_ie_len
= le32_to_cpu(info
->resp_ie_length
);
2222 if (resp_ie_len
> 0) {
2223 offset
= le32_to_cpu(info
->offset_resp_ies
);
2224 resp_ie
= (u8
*)info
+ offset
;
2227 } else if (WARN_ON(priv
->infra_mode
!= NDIS_80211_INFRA_ADHOC
))
2230 ret
= get_bssid(usbdev
, bssid
);
2232 memset(bssid
, 0, sizeof(bssid
));
2234 netdev_dbg(usbdev
->net
, "link up work: [%pM]%s\n",
2235 bssid
, roamed
? " roamed" : "");
2237 /* Internal bss list in device always contains at least the currently
2238 * connected bss and we can get it to cfg80211 with
2239 * rndis_check_bssid_list().
2240 * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
2243 rndis_check_bssid_list(usbdev
);
2245 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2247 cfg80211_connect_result(usbdev
->net
, bssid
, req_ie
,
2248 req_ie_len
, resp_ie
,
2249 resp_ie_len
, 0, GFP_KERNEL
);
2251 cfg80211_roamed(usbdev
->net
, bssid
, req_ie
, req_ie_len
,
2252 resp_ie
, resp_ie_len
, GFP_KERNEL
);
2253 } else if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
2254 cfg80211_ibss_joined(usbdev
->net
, bssid
, GFP_KERNEL
);
2256 priv
->connected
= true;
2257 memcpy(priv
->bssid
, bssid
, ETH_ALEN
);
2259 usbnet_resume_rx(usbdev
);
2260 netif_carrier_on(usbdev
->net
);
2263 static void rndis_wlan_do_link_down_work(struct usbnet
*usbdev
)
2265 union iwreq_data evt
;
2267 netif_carrier_off(usbdev
->net
);
2270 evt
.data
.length
= 0;
2271 memset(evt
.ap_addr
.sa_data
, 0, ETH_ALEN
);
2272 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2275 static void rndis_wlan_worker(struct work_struct
*work
)
2277 struct rndis_wlan_private
*priv
=
2278 container_of(work
, struct rndis_wlan_private
, work
);
2279 struct usbnet
*usbdev
= priv
->usbdev
;
2281 if (test_and_clear_bit(WORK_LINK_UP
, &priv
->work_pending
))
2282 rndis_wlan_do_link_up_work(usbdev
);
2284 if (test_and_clear_bit(WORK_LINK_DOWN
, &priv
->work_pending
))
2285 rndis_wlan_do_link_down_work(usbdev
);
2287 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2288 set_multicast_list(usbdev
);
2291 static void rndis_wlan_set_multicast_list(struct net_device
*dev
)
2293 struct usbnet
*usbdev
= netdev_priv(dev
);
2294 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2296 if (test_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2299 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2300 queue_work(priv
->workqueue
, &priv
->work
);
2303 static void rndis_wlan_auth_indication(struct usbnet
*usbdev
,
2304 struct ndis_80211_status_indication
*indication
,
2309 int flags
, buflen
, key_id
;
2310 bool pairwise_error
, group_error
;
2311 struct ndis_80211_auth_request
*auth_req
;
2312 enum nl80211_key_type key_type
;
2314 /* must have at least one array entry */
2315 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2316 sizeof(struct ndis_80211_auth_request
)) {
2317 netdev_info(usbdev
->net
, "authentication indication: too short message (%i)\n",
2322 buf
= (void *)&indication
->u
.auth_request
[0];
2323 buflen
= len
- offsetof(struct ndis_80211_status_indication
, u
);
2325 while (buflen
>= sizeof(*auth_req
)) {
2326 auth_req
= (void *)buf
;
2328 flags
= le32_to_cpu(auth_req
->flags
);
2329 pairwise_error
= false;
2330 group_error
= false;
2333 type
= "reauth request";
2335 type
= "key update request";
2337 pairwise_error
= true;
2338 type
= "pairwise_error";
2342 type
= "group_error";
2345 netdev_info(usbdev
->net
, "authentication indication: %s (0x%08x)\n",
2346 type
, le32_to_cpu(auth_req
->flags
));
2348 if (pairwise_error
) {
2349 key_type
= NL80211_KEYTYPE_PAIRWISE
;
2352 cfg80211_michael_mic_failure(usbdev
->net
,
2354 key_type
, key_id
, NULL
,
2359 key_type
= NL80211_KEYTYPE_GROUP
;
2362 cfg80211_michael_mic_failure(usbdev
->net
,
2364 key_type
, key_id
, NULL
,
2368 buflen
-= le32_to_cpu(auth_req
->length
);
2369 buf
+= le32_to_cpu(auth_req
->length
);
2373 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet
*usbdev
,
2374 struct ndis_80211_status_indication
*indication
,
2377 struct ndis_80211_pmkid_cand_list
*cand_list
;
2378 int list_len
, expected_len
, i
;
2380 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2381 sizeof(struct ndis_80211_pmkid_cand_list
)) {
2382 netdev_info(usbdev
->net
, "pmkid candidate list indication: too short message (%i)\n",
2387 list_len
= le32_to_cpu(indication
->u
.cand_list
.num_candidates
) *
2388 sizeof(struct ndis_80211_pmkid_candidate
);
2389 expected_len
= sizeof(struct ndis_80211_pmkid_cand_list
) + list_len
+
2390 offsetof(struct ndis_80211_status_indication
, u
);
2392 if (len
< expected_len
) {
2393 netdev_info(usbdev
->net
, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
2398 cand_list
= &indication
->u
.cand_list
;
2400 netdev_info(usbdev
->net
, "pmkid candidate list indication: version %i, candidates %i\n",
2401 le32_to_cpu(cand_list
->version
),
2402 le32_to_cpu(cand_list
->num_candidates
));
2404 if (le32_to_cpu(cand_list
->version
) != 1)
2407 for (i
= 0; i
< le32_to_cpu(cand_list
->num_candidates
); i
++) {
2408 struct ndis_80211_pmkid_candidate
*cand
=
2409 &cand_list
->candidate_list
[i
];
2411 netdev_dbg(usbdev
->net
, "cand[%i]: flags: 0x%08x, bssid: %pM\n",
2412 i
, le32_to_cpu(cand
->flags
), cand
->bssid
);
2415 struct iw_pmkid_cand pcand
;
2416 union iwreq_data wrqu
;
2418 memset(&pcand
, 0, sizeof(pcand
));
2419 if (le32_to_cpu(cand
->flags
) & 0x01)
2420 pcand
.flags
|= IW_PMKID_CAND_PREAUTH
;
2422 memcpy(pcand
.bssid
.sa_data
, cand
->bssid
, ETH_ALEN
);
2424 memset(&wrqu
, 0, sizeof(wrqu
));
2425 wrqu
.data
.length
= sizeof(pcand
);
2426 wireless_send_event(usbdev
->net
, IWEVPMKIDCAND
, &wrqu
,
2432 static void rndis_wlan_media_specific_indication(struct usbnet
*usbdev
,
2433 struct rndis_indicate
*msg
, int buflen
)
2435 struct ndis_80211_status_indication
*indication
;
2438 offset
= offsetof(struct rndis_indicate
, status
) +
2439 le32_to_cpu(msg
->offset
);
2440 len
= le32_to_cpu(msg
->length
);
2443 netdev_info(usbdev
->net
, "media specific indication, ignore too short message (%i < 8)\n",
2448 if (offset
+ len
> buflen
) {
2449 netdev_info(usbdev
->net
, "media specific indication, too large to fit to buffer (%i > %i)\n",
2450 offset
+ len
, buflen
);
2454 indication
= (void *)((u8
*)msg
+ offset
);
2456 switch (le32_to_cpu(indication
->status_type
)) {
2457 case NDIS_80211_STATUSTYPE_RADIOSTATE
:
2458 netdev_info(usbdev
->net
, "radio state indication: %i\n",
2459 le32_to_cpu(indication
->u
.radio_status
));
2462 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
:
2463 netdev_info(usbdev
->net
, "media stream mode indication: %i\n",
2464 le32_to_cpu(indication
->u
.media_stream_mode
));
2467 case NDIS_80211_STATUSTYPE_AUTHENTICATION
:
2468 rndis_wlan_auth_indication(usbdev
, indication
, len
);
2471 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
:
2472 rndis_wlan_pmkid_cand_list_indication(usbdev
, indication
, len
);
2476 netdev_info(usbdev
->net
, "media specific indication: unknown status type 0x%08x\n",
2477 le32_to_cpu(indication
->status_type
));
2481 static void rndis_wlan_indication(struct usbnet
*usbdev
, void *ind
, int buflen
)
2483 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2484 struct rndis_indicate
*msg
= ind
;
2486 switch (msg
->status
) {
2487 case RNDIS_STATUS_MEDIA_CONNECT
:
2488 if (priv
->current_command_oid
== OID_802_11_ADD_KEY
) {
2489 /* OID_802_11_ADD_KEY causes sometimes extra
2490 * "media connect" indications which confuses driver
2491 * and userspace to think that device is
2492 * roaming/reassociating when it isn't.
2494 netdev_dbg(usbdev
->net
, "ignored OID_802_11_ADD_KEY triggered 'media connect'\n");
2498 usbnet_pause_rx(usbdev
);
2500 netdev_info(usbdev
->net
, "media connect\n");
2502 /* queue work to avoid recursive calls into rndis_command */
2503 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
2504 queue_work(priv
->workqueue
, &priv
->work
);
2507 case RNDIS_STATUS_MEDIA_DISCONNECT
:
2508 netdev_info(usbdev
->net
, "media disconnect\n");
2510 /* queue work to avoid recursive calls into rndis_command */
2511 set_bit(WORK_LINK_DOWN
, &priv
->work_pending
);
2512 queue_work(priv
->workqueue
, &priv
->work
);
2515 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION
:
2516 rndis_wlan_media_specific_indication(usbdev
, msg
, buflen
);
2520 netdev_info(usbdev
->net
, "indication: 0x%08x\n",
2521 le32_to_cpu(msg
->status
));
2526 static int rndis_wlan_get_caps(struct usbnet
*usbdev
)
2531 } networks_supported
;
2532 int len
, retval
, i
, n
;
2533 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2535 /* determine supported modes */
2536 len
= sizeof(networks_supported
);
2537 retval
= rndis_query_oid(usbdev
, OID_802_11_NETWORK_TYPES_SUPPORTED
,
2538 &networks_supported
, &len
);
2540 n
= le32_to_cpu(networks_supported
.num_items
);
2543 for (i
= 0; i
< n
; i
++) {
2544 switch (le32_to_cpu(networks_supported
.items
[i
])) {
2545 case NDIS_80211_TYPE_FREQ_HOP
:
2546 case NDIS_80211_TYPE_DIRECT_SEQ
:
2547 priv
->caps
|= CAP_MODE_80211B
;
2549 case NDIS_80211_TYPE_OFDM_A
:
2550 priv
->caps
|= CAP_MODE_80211A
;
2552 case NDIS_80211_TYPE_OFDM_G
:
2553 priv
->caps
|= CAP_MODE_80211G
;
2562 #define DEVICE_POLLER_JIFFIES (HZ)
2563 static void rndis_device_poller(struct work_struct
*work
)
2565 struct rndis_wlan_private
*priv
=
2566 container_of(work
, struct rndis_wlan_private
,
2567 dev_poller_work
.work
);
2568 struct usbnet
*usbdev
= priv
->usbdev
;
2571 int update_jiffies
= DEVICE_POLLER_JIFFIES
;
2574 /* Only check/do workaround when connected. Calling is_associated()
2575 * also polls device with rndis_command() and catches for media link
2578 if (!is_associated(usbdev
))
2582 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2584 priv
->last_qual
= level_to_qual(le32_to_cpu(rssi
));
2586 netdev_dbg(usbdev
->net
, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
2587 ret
, le32_to_cpu(rssi
), level_to_qual(le32_to_cpu(rssi
)));
2589 /* Workaround transfer stalls on poor quality links.
2590 * TODO: find right way to fix these stalls (as stalls do not happen
2591 * with ndiswrapper/windows driver). */
2592 if (priv
->param_workaround_interval
> 0 && priv
->last_qual
<= 25) {
2593 /* Decrease stats worker interval to catch stalls.
2594 * faster. Faster than 400-500ms causes packet loss,
2595 * Slower doesn't catch stalls fast enough.
2597 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
2598 if (j
> DEVICE_POLLER_JIFFIES
)
2599 j
= DEVICE_POLLER_JIFFIES
;
2604 /* Send scan OID. Use of both OIDs is required to get device
2607 tmp
= cpu_to_le32(1);
2608 rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
2611 len
= CONTROL_BUFFER_SIZE
;
2612 buf
= kmalloc(len
, GFP_KERNEL
);
2616 rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2621 if (update_jiffies
>= HZ
)
2622 update_jiffies
= round_jiffies_relative(update_jiffies
);
2624 j
= round_jiffies_relative(update_jiffies
);
2625 if (abs(j
- update_jiffies
) <= 10)
2629 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
2634 * driver/device initialization
2636 static void rndis_copy_module_params(struct usbnet
*usbdev
)
2638 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2640 priv
->param_country
[0] = modparam_country
[0];
2641 priv
->param_country
[1] = modparam_country
[1];
2642 priv
->param_country
[2] = 0;
2643 priv
->param_frameburst
= modparam_frameburst
;
2644 priv
->param_afterburner
= modparam_afterburner
;
2645 priv
->param_power_save
= modparam_power_save
;
2646 priv
->param_power_output
= modparam_power_output
;
2647 priv
->param_roamtrigger
= modparam_roamtrigger
;
2648 priv
->param_roamdelta
= modparam_roamdelta
;
2650 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
2651 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
2652 /* doesn't support EU as country code, use FI instead */
2653 if (!strcmp(priv
->param_country
, "EU"))
2654 strcpy(priv
->param_country
, "FI");
2656 if (priv
->param_power_save
< 0)
2657 priv
->param_power_save
= 0;
2658 else if (priv
->param_power_save
> 2)
2659 priv
->param_power_save
= 2;
2661 if (priv
->param_power_output
< 0)
2662 priv
->param_power_output
= 0;
2663 else if (priv
->param_power_output
> 3)
2664 priv
->param_power_output
= 3;
2666 if (priv
->param_roamtrigger
< -80)
2667 priv
->param_roamtrigger
= -80;
2668 else if (priv
->param_roamtrigger
> -60)
2669 priv
->param_roamtrigger
= -60;
2671 if (priv
->param_roamdelta
< 0)
2672 priv
->param_roamdelta
= 0;
2673 else if (priv
->param_roamdelta
> 2)
2674 priv
->param_roamdelta
= 2;
2676 if (modparam_workaround_interval
< 0)
2677 priv
->param_workaround_interval
= 500;
2679 priv
->param_workaround_interval
= modparam_workaround_interval
;
2682 static int bcm4320a_early_init(struct usbnet
*usbdev
)
2684 /* copy module parameters for bcm4320a so that iwconfig reports txpower
2685 * and workaround parameter is copied to private structure correctly.
2687 rndis_copy_module_params(usbdev
);
2689 /* bcm4320a doesn't handle configuration parameters well. Try
2690 * set any and you get partially zeroed mac and broken device.
2696 static int bcm4320b_early_init(struct usbnet
*usbdev
)
2698 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2701 rndis_copy_module_params(usbdev
);
2703 /* Early initialization settings, setting these won't have effect
2704 * if called after generic_rndis_bind().
2707 rndis_set_config_parameter_str(usbdev
, "Country", priv
->param_country
);
2708 rndis_set_config_parameter_str(usbdev
, "FrameBursting",
2709 priv
->param_frameburst
? "1" : "0");
2710 rndis_set_config_parameter_str(usbdev
, "Afterburner",
2711 priv
->param_afterburner
? "1" : "0");
2712 sprintf(buf
, "%d", priv
->param_power_save
);
2713 rndis_set_config_parameter_str(usbdev
, "PowerSaveMode", buf
);
2714 sprintf(buf
, "%d", priv
->param_power_output
);
2715 rndis_set_config_parameter_str(usbdev
, "PwrOut", buf
);
2716 sprintf(buf
, "%d", priv
->param_roamtrigger
);
2717 rndis_set_config_parameter_str(usbdev
, "RoamTrigger", buf
);
2718 sprintf(buf
, "%d", priv
->param_roamdelta
);
2719 rndis_set_config_parameter_str(usbdev
, "RoamDelta", buf
);
2724 /* same as rndis_netdev_ops but with local multicast handler */
2725 static const struct net_device_ops rndis_wlan_netdev_ops
= {
2726 .ndo_open
= usbnet_open
,
2727 .ndo_stop
= usbnet_stop
,
2728 .ndo_start_xmit
= usbnet_start_xmit
,
2729 .ndo_tx_timeout
= usbnet_tx_timeout
,
2730 .ndo_set_mac_address
= eth_mac_addr
,
2731 .ndo_validate_addr
= eth_validate_addr
,
2732 .ndo_set_multicast_list
= rndis_wlan_set_multicast_list
,
2735 static int rndis_wlan_bind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2737 struct wiphy
*wiphy
;
2738 struct rndis_wlan_private
*priv
;
2742 /* allocate wiphy and rndis private data
2743 * NOTE: We only support a single virtual interface, so wiphy
2744 * and wireless_dev are somewhat synonymous for this device.
2746 wiphy
= wiphy_new(&rndis_config_ops
, sizeof(struct rndis_wlan_private
));
2750 priv
= wiphy_priv(wiphy
);
2751 usbdev
->net
->ieee80211_ptr
= &priv
->wdev
;
2752 priv
->wdev
.wiphy
= wiphy
;
2753 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
2755 /* These have to be initialized before calling generic_rndis_bind().
2756 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
2758 usbdev
->driver_priv
= priv
;
2759 priv
->usbdev
= usbdev
;
2761 mutex_init(&priv
->command_lock
);
2763 /* because rndis_command() sleeps we need to use workqueue */
2764 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
2765 INIT_WORK(&priv
->work
, rndis_wlan_worker
);
2766 INIT_DELAYED_WORK(&priv
->dev_poller_work
, rndis_device_poller
);
2767 INIT_DELAYED_WORK(&priv
->scan_work
, rndis_get_scan_results
);
2769 /* try bind rndis_host */
2770 retval
= generic_rndis_bind(usbdev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
2774 /* generic_rndis_bind set packet filter to multicast_all+
2775 * promisc mode which doesn't work well for our devices (device
2776 * picks up rssi to closest station instead of to access point).
2778 * rndis_host wants to avoid all OID as much as possible
2779 * so do promisc/multicast handling in rndis_wlan.
2781 usbdev
->net
->netdev_ops
= &rndis_wlan_netdev_ops
;
2783 tmp
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
2784 retval
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &tmp
,
2788 retval
= rndis_query_oid(usbdev
, OID_802_3_MAXIMUM_LIST_SIZE
, &tmp
,
2790 priv
->multicast_size
= le32_to_cpu(tmp
);
2791 if (retval
< 0 || priv
->multicast_size
< 0)
2792 priv
->multicast_size
= 0;
2793 if (priv
->multicast_size
> 0)
2794 usbdev
->net
->flags
|= IFF_MULTICAST
;
2796 usbdev
->net
->flags
&= ~IFF_MULTICAST
;
2798 /* fill-out wiphy structure and register w/ cfg80211 */
2799 memcpy(wiphy
->perm_addr
, usbdev
->net
->dev_addr
, ETH_ALEN
);
2800 wiphy
->privid
= rndis_wiphy_privid
;
2801 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
2802 | BIT(NL80211_IFTYPE_ADHOC
);
2803 wiphy
->max_scan_ssids
= 1;
2805 /* TODO: fill-out band/encr information based on priv->caps */
2806 rndis_wlan_get_caps(usbdev
);
2808 memcpy(priv
->channels
, rndis_channels
, sizeof(rndis_channels
));
2809 memcpy(priv
->rates
, rndis_rates
, sizeof(rndis_rates
));
2810 priv
->band
.channels
= priv
->channels
;
2811 priv
->band
.n_channels
= ARRAY_SIZE(rndis_channels
);
2812 priv
->band
.bitrates
= priv
->rates
;
2813 priv
->band
.n_bitrates
= ARRAY_SIZE(rndis_rates
);
2814 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
2815 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_UNSPEC
;
2817 memcpy(priv
->cipher_suites
, rndis_cipher_suites
,
2818 sizeof(rndis_cipher_suites
));
2819 wiphy
->cipher_suites
= priv
->cipher_suites
;
2820 wiphy
->n_cipher_suites
= ARRAY_SIZE(rndis_cipher_suites
);
2822 set_wiphy_dev(wiphy
, &usbdev
->udev
->dev
);
2824 if (wiphy_register(wiphy
)) {
2829 set_default_iw_params(usbdev
);
2831 /* set default rts/frag */
2832 rndis_set_wiphy_params(wiphy
,
2833 WIPHY_PARAM_FRAG_THRESHOLD
| WIPHY_PARAM_RTS_THRESHOLD
);
2836 priv
->radio_on
= true;
2837 disassociate(usbdev
, true);
2838 netif_carrier_off(usbdev
->net
);
2843 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2844 cancel_delayed_work_sync(&priv
->scan_work
);
2845 cancel_work_sync(&priv
->work
);
2846 flush_workqueue(priv
->workqueue
);
2847 destroy_workqueue(priv
->workqueue
);
2853 static void rndis_wlan_unbind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2855 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2857 /* turn radio off */
2858 disassociate(usbdev
, false);
2860 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2861 cancel_delayed_work_sync(&priv
->scan_work
);
2862 cancel_work_sync(&priv
->work
);
2863 flush_workqueue(priv
->workqueue
);
2864 destroy_workqueue(priv
->workqueue
);
2866 if (priv
&& priv
->wpa_ie_len
)
2867 kfree(priv
->wpa_ie
);
2869 rndis_unbind(usbdev
, intf
);
2871 wiphy_unregister(priv
->wdev
.wiphy
);
2872 wiphy_free(priv
->wdev
.wiphy
);
2875 static int rndis_wlan_reset(struct usbnet
*usbdev
)
2877 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2880 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2882 retval
= rndis_reset(usbdev
);
2884 netdev_warn(usbdev
->net
, "rndis_reset failed: %d\n", retval
);
2886 /* rndis_reset cleared multicast list, so restore here.
2887 (set_multicast_list() also turns on current packet filter) */
2888 set_multicast_list(usbdev
);
2890 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
2891 round_jiffies_relative(DEVICE_POLLER_JIFFIES
));
2893 return deauthenticate(usbdev
);
2896 static int rndis_wlan_stop(struct usbnet
*usbdev
)
2898 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2902 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2904 retval
= disassociate(usbdev
, false);
2906 priv
->work_pending
= 0;
2907 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2908 cancel_delayed_work_sync(&priv
->scan_work
);
2909 cancel_work_sync(&priv
->work
);
2910 flush_workqueue(priv
->workqueue
);
2912 if (priv
->scan_request
) {
2913 cfg80211_scan_done(priv
->scan_request
, true);
2914 priv
->scan_request
= NULL
;
2917 /* Set current packet filter zero to block receiving data packets from
2920 rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
2926 static const struct driver_info bcm4320b_info
= {
2927 .description
= "Wireless RNDIS device, BCM4320b based",
2928 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2929 FLAG_AVOID_UNLINK_URBS
,
2930 .bind
= rndis_wlan_bind
,
2931 .unbind
= rndis_wlan_unbind
,
2932 .status
= rndis_status
,
2933 .rx_fixup
= rndis_rx_fixup
,
2934 .tx_fixup
= rndis_tx_fixup
,
2935 .reset
= rndis_wlan_reset
,
2936 .stop
= rndis_wlan_stop
,
2937 .early_init
= bcm4320b_early_init
,
2938 .indication
= rndis_wlan_indication
,
2941 static const struct driver_info bcm4320a_info
= {
2942 .description
= "Wireless RNDIS device, BCM4320a based",
2943 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2944 FLAG_AVOID_UNLINK_URBS
,
2945 .bind
= rndis_wlan_bind
,
2946 .unbind
= rndis_wlan_unbind
,
2947 .status
= rndis_status
,
2948 .rx_fixup
= rndis_rx_fixup
,
2949 .tx_fixup
= rndis_tx_fixup
,
2950 .reset
= rndis_wlan_reset
,
2951 .stop
= rndis_wlan_stop
,
2952 .early_init
= bcm4320a_early_init
,
2953 .indication
= rndis_wlan_indication
,
2956 static const struct driver_info rndis_wlan_info
= {
2957 .description
= "Wireless RNDIS device",
2958 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2959 FLAG_AVOID_UNLINK_URBS
,
2960 .bind
= rndis_wlan_bind
,
2961 .unbind
= rndis_wlan_unbind
,
2962 .status
= rndis_status
,
2963 .rx_fixup
= rndis_rx_fixup
,
2964 .tx_fixup
= rndis_tx_fixup
,
2965 .reset
= rndis_wlan_reset
,
2966 .stop
= rndis_wlan_stop
,
2967 .early_init
= bcm4320a_early_init
,
2968 .indication
= rndis_wlan_indication
,
2971 /*-------------------------------------------------------------------------*/
2973 static const struct usb_device_id products
[] = {
2974 #define RNDIS_MASTER_INTERFACE \
2975 .bInterfaceClass = USB_CLASS_COMM, \
2976 .bInterfaceSubClass = 2 /* ACM */, \
2977 .bInterfaceProtocol = 0x0ff
2979 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2980 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2983 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2984 | USB_DEVICE_ID_MATCH_DEVICE
,
2986 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
2987 RNDIS_MASTER_INTERFACE
,
2988 .driver_info
= (unsigned long) &bcm4320b_info
,
2990 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2991 | USB_DEVICE_ID_MATCH_DEVICE
,
2993 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
2994 RNDIS_MASTER_INTERFACE
,
2995 .driver_info
= (unsigned long) &bcm4320b_info
,
2997 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2998 | USB_DEVICE_ID_MATCH_DEVICE
,
3000 .idProduct
= 0x011b, /* Belkin F5D7051 */
3001 RNDIS_MASTER_INTERFACE
,
3002 .driver_info
= (unsigned long) &bcm4320b_info
,
3004 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3005 | USB_DEVICE_ID_MATCH_DEVICE
,
3006 .idVendor
= 0x1799, /* Belkin has two vendor ids */
3007 .idProduct
= 0x011b, /* Belkin F5D7051 */
3008 RNDIS_MASTER_INTERFACE
,
3009 .driver_info
= (unsigned long) &bcm4320b_info
,
3011 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3012 | USB_DEVICE_ID_MATCH_DEVICE
,
3014 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
3015 RNDIS_MASTER_INTERFACE
,
3016 .driver_info
= (unsigned long) &bcm4320b_info
,
3018 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3019 | USB_DEVICE_ID_MATCH_DEVICE
,
3021 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
3022 RNDIS_MASTER_INTERFACE
,
3023 .driver_info
= (unsigned long) &bcm4320b_info
,
3025 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3026 | USB_DEVICE_ID_MATCH_DEVICE
,
3028 .idProduct
= 0x1717, /* Asus WL169gE */
3029 RNDIS_MASTER_INTERFACE
,
3030 .driver_info
= (unsigned long) &bcm4320b_info
,
3032 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3033 | USB_DEVICE_ID_MATCH_DEVICE
,
3035 .idProduct
= 0xd11b, /* Eminent EM4045 */
3036 RNDIS_MASTER_INTERFACE
,
3037 .driver_info
= (unsigned long) &bcm4320b_info
,
3039 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3040 | USB_DEVICE_ID_MATCH_DEVICE
,
3042 .idProduct
= 0x0715, /* BT Voyager 1055 */
3043 RNDIS_MASTER_INTERFACE
,
3044 .driver_info
= (unsigned long) &bcm4320b_info
,
3046 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3047 * parameters available, hardware probably contain older firmware version with
3048 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3051 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3052 | USB_DEVICE_ID_MATCH_DEVICE
,
3054 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
3055 RNDIS_MASTER_INTERFACE
,
3056 .driver_info
= (unsigned long) &bcm4320a_info
,
3058 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3059 | USB_DEVICE_ID_MATCH_DEVICE
,
3061 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
3062 RNDIS_MASTER_INTERFACE
,
3063 .driver_info
= (unsigned long) &bcm4320a_info
,
3065 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3066 | USB_DEVICE_ID_MATCH_DEVICE
,
3068 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
3069 RNDIS_MASTER_INTERFACE
,
3070 .driver_info
= (unsigned long) &bcm4320a_info
,
3072 /* Generic Wireless RNDIS devices that we don't have exact
3073 * idVendor/idProduct/chip yet.
3076 /* RNDIS is MSFT's un-official variant of CDC ACM */
3077 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
3078 .driver_info
= (unsigned long) &rndis_wlan_info
,
3080 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3081 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
3082 .driver_info
= (unsigned long) &rndis_wlan_info
,
3086 MODULE_DEVICE_TABLE(usb
, products
);
3088 static struct usb_driver rndis_wlan_driver
= {
3089 .name
= "rndis_wlan",
3090 .id_table
= products
,
3091 .probe
= usbnet_probe
,
3092 .disconnect
= usbnet_disconnect
,
3093 .suspend
= usbnet_suspend
,
3094 .resume
= usbnet_resume
,
3097 static int __init
rndis_wlan_init(void)
3099 return usb_register(&rndis_wlan_driver
);
3101 module_init(rndis_wlan_init
);
3103 static void __exit
rndis_wlan_exit(void)
3105 usb_deregister(&rndis_wlan_driver
);
3107 module_exit(rndis_wlan_exit
);
3109 MODULE_AUTHOR("Bjorge Dijkstra");
3110 MODULE_AUTHOR("Jussi Kivilinna");
3111 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3112 MODULE_LICENSE("GPL");