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
;
87 module_param_named(workaround_interval
, modparam_workaround_interval
,
89 MODULE_PARM_DESC(workaround_interval
,
90 "set stall workaround interval in msecs (0=disabled) (default: 0)");
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 __le32 media_stream_mode
;
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
));
364 #define NET_TYPE_11FB 0
366 #define CAP_MODE_80211A 1
367 #define CAP_MODE_80211B 2
368 #define CAP_MODE_80211G 4
369 #define CAP_MODE_MASK 7
371 #define WORK_LINK_UP (1<<0)
372 #define WORK_LINK_DOWN (1<<1)
373 #define WORK_SET_MULTICAST_LIST (1<<2)
375 #define RNDIS_WLAN_ALG_NONE 0
376 #define RNDIS_WLAN_ALG_WEP (1<<0)
377 #define RNDIS_WLAN_ALG_TKIP (1<<1)
378 #define RNDIS_WLAN_ALG_CCMP (1<<2)
380 #define RNDIS_WLAN_KEY_MGMT_NONE 0
381 #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
382 #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
384 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
386 static const struct ieee80211_channel rndis_channels
[] = {
387 { .center_freq
= 2412 },
388 { .center_freq
= 2417 },
389 { .center_freq
= 2422 },
390 { .center_freq
= 2427 },
391 { .center_freq
= 2432 },
392 { .center_freq
= 2437 },
393 { .center_freq
= 2442 },
394 { .center_freq
= 2447 },
395 { .center_freq
= 2452 },
396 { .center_freq
= 2457 },
397 { .center_freq
= 2462 },
398 { .center_freq
= 2467 },
399 { .center_freq
= 2472 },
400 { .center_freq
= 2484 },
403 static const struct ieee80211_rate rndis_rates
[] = {
405 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
406 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
407 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
418 static const u32 rndis_cipher_suites
[] = {
419 WLAN_CIPHER_SUITE_WEP40
,
420 WLAN_CIPHER_SUITE_WEP104
,
421 WLAN_CIPHER_SUITE_TKIP
,
422 WLAN_CIPHER_SUITE_CCMP
,
425 struct rndis_wlan_encr_key
{
434 /* RNDIS device private data */
435 struct rndis_wlan_private
{
436 struct usbnet
*usbdev
;
438 struct wireless_dev wdev
;
440 struct cfg80211_scan_request
*scan_request
;
442 struct workqueue_struct
*workqueue
;
443 struct delayed_work dev_poller_work
;
444 struct delayed_work scan_work
;
445 struct work_struct work
;
446 struct mutex command_lock
;
447 unsigned long work_pending
;
450 struct ieee80211_supported_band band
;
451 struct ieee80211_channel channels
[ARRAY_SIZE(rndis_channels
)];
452 struct ieee80211_rate rates
[ARRAY_SIZE(rndis_rates
)];
453 u32 cipher_suites
[ARRAY_SIZE(rndis_cipher_suites
)];
458 /* module parameters */
459 char param_country
[4];
460 int param_frameburst
;
461 int param_afterburner
;
462 int param_power_save
;
463 int param_power_output
;
464 int param_roamtrigger
;
466 u32 param_workaround_interval
;
473 struct ndis_80211_ssid essid
;
474 __le32 current_command_oid
;
476 /* encryption stuff */
477 int encr_tx_key_index
;
478 struct rndis_wlan_encr_key encr_keys
[4];
479 enum nl80211_auth_type wpa_auth_type
;
485 int wpa_cipher_group
;
487 u8 command_buffer
[COMMAND_BUFFER_SIZE
];
493 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
494 struct net_device
*dev
,
495 enum nl80211_iftype type
, u32
*flags
,
496 struct vif_params
*params
);
498 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
499 struct cfg80211_scan_request
*request
);
501 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
);
503 static int rndis_set_tx_power(struct wiphy
*wiphy
, enum tx_power_setting type
,
505 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
);
507 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
508 struct cfg80211_connect_params
*sme
);
510 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
513 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
514 struct cfg80211_ibss_params
*params
);
516 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
);
518 static int rndis_set_channel(struct wiphy
*wiphy
,
519 struct ieee80211_channel
*chan
, enum nl80211_channel_type channel_type
);
521 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
522 u8 key_index
, const u8
*mac_addr
,
523 struct key_params
*params
);
525 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
526 u8 key_index
, const u8
*mac_addr
);
528 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
531 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
532 u8
*mac
, struct station_info
*sinfo
);
534 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
535 int idx
, u8
*mac
, struct station_info
*sinfo
);
537 static struct cfg80211_ops rndis_config_ops
= {
538 .change_virtual_intf
= rndis_change_virtual_intf
,
540 .set_wiphy_params
= rndis_set_wiphy_params
,
541 .set_tx_power
= rndis_set_tx_power
,
542 .get_tx_power
= rndis_get_tx_power
,
543 .connect
= rndis_connect
,
544 .disconnect
= rndis_disconnect
,
545 .join_ibss
= rndis_join_ibss
,
546 .leave_ibss
= rndis_leave_ibss
,
547 .set_channel
= rndis_set_channel
,
548 .add_key
= rndis_add_key
,
549 .del_key
= rndis_del_key
,
550 .set_default_key
= rndis_set_default_key
,
551 .get_station
= rndis_get_station
,
552 .dump_station
= rndis_dump_station
,
555 static void *rndis_wiphy_privid
= &rndis_wiphy_privid
;
558 static struct rndis_wlan_private
*get_rndis_wlan_priv(struct usbnet
*dev
)
560 return (struct rndis_wlan_private
*)dev
->driver_priv
;
563 static u32
get_bcm4320_power_dbm(struct rndis_wlan_private
*priv
)
565 switch (priv
->param_power_output
) {
568 return BCM4320_DEFAULT_TXPOWER_DBM_100
;
570 return BCM4320_DEFAULT_TXPOWER_DBM_75
;
572 return BCM4320_DEFAULT_TXPOWER_DBM_50
;
574 return BCM4320_DEFAULT_TXPOWER_DBM_25
;
578 static bool is_wpa_key(struct rndis_wlan_private
*priv
, int idx
)
580 int cipher
= priv
->encr_keys
[idx
].cipher
;
582 return (cipher
== WLAN_CIPHER_SUITE_CCMP
||
583 cipher
== WLAN_CIPHER_SUITE_TKIP
);
586 static int rndis_cipher_to_alg(u32 cipher
)
590 return RNDIS_WLAN_ALG_NONE
;
591 case WLAN_CIPHER_SUITE_WEP40
:
592 case WLAN_CIPHER_SUITE_WEP104
:
593 return RNDIS_WLAN_ALG_WEP
;
594 case WLAN_CIPHER_SUITE_TKIP
:
595 return RNDIS_WLAN_ALG_TKIP
;
596 case WLAN_CIPHER_SUITE_CCMP
:
597 return RNDIS_WLAN_ALG_CCMP
;
601 static int rndis_akm_suite_to_key_mgmt(u32 akm_suite
)
605 return RNDIS_WLAN_KEY_MGMT_NONE
;
606 case WLAN_AKM_SUITE_8021X
:
607 return RNDIS_WLAN_KEY_MGMT_802_1X
;
608 case WLAN_AKM_SUITE_PSK
:
609 return RNDIS_WLAN_KEY_MGMT_PSK
;
614 static const char *oid_to_string(__le32 oid
)
617 #define OID_STR(oid) case oid: return(#oid)
618 /* from rndis_host.h */
619 OID_STR(OID_802_3_PERMANENT_ADDRESS
);
620 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE
);
621 OID_STR(OID_GEN_CURRENT_PACKET_FILTER
);
622 OID_STR(OID_GEN_PHYSICAL_MEDIUM
);
624 /* from rndis_wlan.c */
625 OID_STR(OID_GEN_LINK_SPEED
);
626 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER
);
628 OID_STR(OID_GEN_XMIT_OK
);
629 OID_STR(OID_GEN_RCV_OK
);
630 OID_STR(OID_GEN_XMIT_ERROR
);
631 OID_STR(OID_GEN_RCV_ERROR
);
632 OID_STR(OID_GEN_RCV_NO_BUFFER
);
634 OID_STR(OID_802_3_CURRENT_ADDRESS
);
635 OID_STR(OID_802_3_MULTICAST_LIST
);
636 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE
);
638 OID_STR(OID_802_11_BSSID
);
639 OID_STR(OID_802_11_SSID
);
640 OID_STR(OID_802_11_INFRASTRUCTURE_MODE
);
641 OID_STR(OID_802_11_ADD_WEP
);
642 OID_STR(OID_802_11_REMOVE_WEP
);
643 OID_STR(OID_802_11_DISASSOCIATE
);
644 OID_STR(OID_802_11_AUTHENTICATION_MODE
);
645 OID_STR(OID_802_11_PRIVACY_FILTER
);
646 OID_STR(OID_802_11_BSSID_LIST_SCAN
);
647 OID_STR(OID_802_11_ENCRYPTION_STATUS
);
648 OID_STR(OID_802_11_ADD_KEY
);
649 OID_STR(OID_802_11_REMOVE_KEY
);
650 OID_STR(OID_802_11_ASSOCIATION_INFORMATION
);
651 OID_STR(OID_802_11_PMKID
);
652 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED
);
653 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE
);
654 OID_STR(OID_802_11_TX_POWER_LEVEL
);
655 OID_STR(OID_802_11_RSSI
);
656 OID_STR(OID_802_11_RSSI_TRIGGER
);
657 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD
);
658 OID_STR(OID_802_11_RTS_THRESHOLD
);
659 OID_STR(OID_802_11_SUPPORTED_RATES
);
660 OID_STR(OID_802_11_CONFIGURATION
);
661 OID_STR(OID_802_11_BSSID_LIST
);
668 static const char *oid_to_string(__le32 oid
)
674 /* translate error code */
675 static int rndis_error_status(__le32 rndis_status
)
678 switch (rndis_status
) {
679 case RNDIS_STATUS_SUCCESS
:
682 case RNDIS_STATUS_FAILURE
:
683 case RNDIS_STATUS_INVALID_DATA
:
686 case RNDIS_STATUS_NOT_SUPPORTED
:
689 case RNDIS_STATUS_ADAPTER_NOT_READY
:
690 case RNDIS_STATUS_ADAPTER_NOT_OPEN
:
697 static int rndis_query_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int *len
)
699 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
702 struct rndis_msg_hdr
*header
;
703 struct rndis_query
*get
;
704 struct rndis_query_c
*get_c
;
707 int resplen
, respoffs
, copylen
;
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 resplen
= le32_to_cpu(u
.get_c
->len
);
738 respoffs
= le32_to_cpu(u
.get_c
->offset
) + 8;
740 if (respoffs
> buflen
) {
741 /* Device returned data offset outside buffer, error. */
742 netdev_dbg(dev
->net
, "%s(%s): received invalid "
743 "data offset: %d > %d\n", __func__
,
744 oid_to_string(oid
), respoffs
, buflen
);
750 if ((resplen
+ respoffs
) > buflen
) {
751 /* Device would have returned more data if buffer would
752 * have been big enough. Copy just the bits that we got.
754 copylen
= buflen
- respoffs
;
762 memcpy(data
, u
.buf
+ respoffs
, copylen
);
766 ret
= rndis_error_status(u
.get_c
->status
);
768 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
769 __func__
, oid_to_string(oid
),
770 le32_to_cpu(u
.get_c
->status
), ret
);
774 mutex_unlock(&priv
->command_lock
);
776 if (u
.buf
!= priv
->command_buffer
)
781 static int rndis_set_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int len
)
783 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
786 struct rndis_msg_hdr
*header
;
787 struct rndis_set
*set
;
788 struct rndis_set_c
*set_c
;
792 buflen
= len
+ sizeof(*u
.set
);
793 if (buflen
< CONTROL_BUFFER_SIZE
)
794 buflen
= CONTROL_BUFFER_SIZE
;
796 if (buflen
> COMMAND_BUFFER_SIZE
) {
797 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
801 u
.buf
= priv
->command_buffer
;
804 mutex_lock(&priv
->command_lock
);
806 memset(u
.set
, 0, sizeof *u
.set
);
807 u
.set
->msg_type
= RNDIS_MSG_SET
;
808 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
810 u
.set
->len
= cpu_to_le32(len
);
811 u
.set
->offset
= cpu_to_le32(sizeof(*u
.set
) - 8);
812 u
.set
->handle
= cpu_to_le32(0);
813 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
815 priv
->current_command_oid
= oid
;
816 ret
= rndis_command(dev
, u
.header
, buflen
);
817 priv
->current_command_oid
= 0;
819 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
820 __func__
, oid_to_string(oid
), ret
,
821 le32_to_cpu(u
.set_c
->status
));
824 ret
= rndis_error_status(u
.set_c
->status
);
827 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
828 __func__
, oid_to_string(oid
),
829 le32_to_cpu(u
.set_c
->status
), ret
);
832 mutex_unlock(&priv
->command_lock
);
834 if (u
.buf
!= priv
->command_buffer
)
839 static int rndis_reset(struct usbnet
*usbdev
)
841 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
842 struct rndis_reset
*reset
;
845 mutex_lock(&priv
->command_lock
);
847 reset
= (void *)priv
->command_buffer
;
848 memset(reset
, 0, sizeof(*reset
));
849 reset
->msg_type
= RNDIS_MSG_RESET
;
850 reset
->msg_len
= cpu_to_le32(sizeof(*reset
));
851 priv
->current_command_oid
= 0;
852 ret
= rndis_command(usbdev
, (void *)reset
, CONTROL_BUFFER_SIZE
);
854 mutex_unlock(&priv
->command_lock
);
862 * Specs say that we can only set config parameters only soon after device
864 * value_type: 0 = u32, 2 = unicode string
866 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
867 int value_type
, void *value
)
869 struct ndis_config_param
*infobuf
;
870 int value_len
, info_len
, param_len
, ret
, i
;
875 value_len
= sizeof(__le32
);
876 else if (value_type
== 2)
877 value_len
= strlen(value
) * sizeof(__le16
);
881 param_len
= strlen(param
) * sizeof(__le16
);
882 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
887 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
893 /* extra 12 bytes are for padding (debug output) */
894 memset(infobuf
, 0xCC, info_len
+ 12);
898 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %s\n",
901 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %d\n",
902 param
, *(u32
*)value
);
904 infobuf
->name_offs
= cpu_to_le32(sizeof(*infobuf
));
905 infobuf
->name_length
= cpu_to_le32(param_len
);
906 infobuf
->type
= cpu_to_le32(value_type
);
907 infobuf
->value_offs
= cpu_to_le32(sizeof(*infobuf
) + param_len
);
908 infobuf
->value_length
= cpu_to_le32(value_len
);
910 /* simple string to unicode string conversion */
911 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
912 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
913 unibuf
[i
] = cpu_to_le16(param
[i
]);
915 if (value_type
== 2) {
916 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
917 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
918 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
920 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
921 *dst_value
= cpu_to_le32(*(u32
*)value
);
925 netdev_dbg(dev
->net
, "info buffer (len: %d)\n", info_len
);
926 for (i
= 0; i
< info_len
; i
+= 12) {
927 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
928 netdev_dbg(dev
->net
, "%08X:%08X:%08X\n",
931 cpu_to_be32(tmp
[2]));
935 ret
= rndis_set_oid(dev
, OID_GEN_RNDIS_CONFIG_PARAMETER
,
938 netdev_dbg(dev
->net
, "setting rndis config parameter failed, %d\n",
945 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
946 char *param
, char *value
)
948 return rndis_set_config_parameter(dev
, param
, 2, value
);
952 * data conversion functions
954 static int level_to_qual(int level
)
956 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
957 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
963 static int set_infra_mode(struct usbnet
*usbdev
, int mode
);
964 static void restore_keys(struct usbnet
*usbdev
);
965 static int rndis_check_bssid_list(struct usbnet
*usbdev
);
967 static int set_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
969 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
972 ret
= rndis_set_oid(usbdev
, OID_802_11_SSID
, ssid
, sizeof(*ssid
));
974 netdev_warn(usbdev
->net
, "setting SSID failed (%08X)\n", ret
);
978 memcpy(&priv
->essid
, ssid
, sizeof(priv
->essid
));
979 priv
->radio_on
= true;
980 netdev_dbg(usbdev
->net
, "%s(): radio_on = true\n", __func__
);
986 static int set_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
990 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID
, bssid
, ETH_ALEN
);
992 netdev_warn(usbdev
->net
, "setting BSSID[%pM] failed (%08X)\n",
1000 static int clear_bssid(struct usbnet
*usbdev
)
1002 u8 broadcast_mac
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1004 return set_bssid(usbdev
, broadcast_mac
);
1007 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
1012 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID
, bssid
, &len
);
1015 memset(bssid
, 0, ETH_ALEN
);
1020 static int get_association_info(struct usbnet
*usbdev
,
1021 struct ndis_80211_assoc_info
*info
, int len
)
1023 return rndis_query_oid(usbdev
, OID_802_11_ASSOCIATION_INFORMATION
,
1027 static bool is_associated(struct usbnet
*usbdev
)
1029 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1033 if (!priv
->radio_on
)
1036 ret
= get_bssid(usbdev
, bssid
);
1038 return (ret
== 0 && !is_zero_ether_addr(bssid
));
1041 static int disassociate(struct usbnet
*usbdev
, bool reset_ssid
)
1043 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1044 struct ndis_80211_ssid ssid
;
1047 if (priv
->radio_on
) {
1048 ret
= rndis_set_oid(usbdev
, OID_802_11_DISASSOCIATE
, NULL
, 0);
1050 priv
->radio_on
= false;
1051 netdev_dbg(usbdev
->net
, "%s(): radio_on = false\n",
1059 /* disassociate causes radio to be turned off; if reset_ssid
1060 * is given, set random ssid to enable radio */
1062 /* Set device to infrastructure mode so we don't get ad-hoc
1063 * 'media connect' indications with the random ssid.
1065 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1067 ssid
.length
= cpu_to_le32(sizeof(ssid
.essid
));
1068 get_random_bytes(&ssid
.essid
[2], sizeof(ssid
.essid
)-2);
1069 ssid
.essid
[0] = 0x1;
1070 ssid
.essid
[1] = 0xff;
1071 for (i
= 2; i
< sizeof(ssid
.essid
); i
++)
1072 ssid
.essid
[i
] = 0x1 + (ssid
.essid
[i
] * 0xfe / 0xff);
1073 ret
= set_essid(usbdev
, &ssid
);
1078 static int set_auth_mode(struct usbnet
*usbdev
, u32 wpa_version
,
1079 enum nl80211_auth_type auth_type
, int keymgmt
)
1081 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1085 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1086 __func__
, wpa_version
, auth_type
, keymgmt
);
1088 if (wpa_version
& NL80211_WPA_VERSION_2
) {
1089 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1090 auth_mode
= NDIS_80211_AUTH_WPA2
;
1092 auth_mode
= NDIS_80211_AUTH_WPA2_PSK
;
1093 } else if (wpa_version
& NL80211_WPA_VERSION_1
) {
1094 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1095 auth_mode
= NDIS_80211_AUTH_WPA
;
1096 else if (keymgmt
& RNDIS_WLAN_KEY_MGMT_PSK
)
1097 auth_mode
= NDIS_80211_AUTH_WPA_PSK
;
1099 auth_mode
= NDIS_80211_AUTH_WPA_NONE
;
1100 } else if (auth_type
== NL80211_AUTHTYPE_SHARED_KEY
)
1101 auth_mode
= NDIS_80211_AUTH_SHARED
;
1102 else if (auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
)
1103 auth_mode
= NDIS_80211_AUTH_OPEN
;
1104 else if (auth_type
== NL80211_AUTHTYPE_AUTOMATIC
)
1105 auth_mode
= NDIS_80211_AUTH_AUTO_SWITCH
;
1109 tmp
= cpu_to_le32(auth_mode
);
1110 ret
= rndis_set_oid(usbdev
, OID_802_11_AUTHENTICATION_MODE
, &tmp
,
1113 netdev_warn(usbdev
->net
, "setting auth mode failed (%08X)\n",
1118 priv
->wpa_version
= wpa_version
;
1119 priv
->wpa_auth_type
= auth_type
;
1120 priv
->wpa_keymgmt
= keymgmt
;
1125 static int set_priv_filter(struct usbnet
*usbdev
)
1127 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1130 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x\n",
1131 __func__
, priv
->wpa_version
);
1133 if (priv
->wpa_version
& NL80211_WPA_VERSION_2
||
1134 priv
->wpa_version
& NL80211_WPA_VERSION_1
)
1135 tmp
= cpu_to_le32(NDIS_80211_PRIV_8021X_WEP
);
1137 tmp
= cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL
);
1139 return rndis_set_oid(usbdev
, OID_802_11_PRIVACY_FILTER
, &tmp
,
1143 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
1145 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1149 netdev_dbg(usbdev
->net
, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1150 __func__
, pairwise
, groupwise
);
1152 if (pairwise
& RNDIS_WLAN_ALG_CCMP
)
1153 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1154 else if (pairwise
& RNDIS_WLAN_ALG_TKIP
)
1155 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1156 else if (pairwise
& RNDIS_WLAN_ALG_WEP
)
1157 encr_mode
= NDIS_80211_ENCR_WEP_ENABLED
;
1158 else if (groupwise
& RNDIS_WLAN_ALG_CCMP
)
1159 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1160 else if (groupwise
& RNDIS_WLAN_ALG_TKIP
)
1161 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1163 encr_mode
= NDIS_80211_ENCR_DISABLED
;
1165 tmp
= cpu_to_le32(encr_mode
);
1166 ret
= rndis_set_oid(usbdev
, OID_802_11_ENCRYPTION_STATUS
, &tmp
,
1169 netdev_warn(usbdev
->net
, "setting encr mode failed (%08X)\n",
1174 priv
->wpa_cipher_pair
= pairwise
;
1175 priv
->wpa_cipher_group
= groupwise
;
1179 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
1181 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1185 netdev_dbg(usbdev
->net
, "%s(): infra_mode=0x%x\n",
1186 __func__
, priv
->infra_mode
);
1188 tmp
= cpu_to_le32(mode
);
1189 ret
= rndis_set_oid(usbdev
, OID_802_11_INFRASTRUCTURE_MODE
, &tmp
,
1192 netdev_warn(usbdev
->net
, "setting infra mode failed (%08X)\n",
1197 /* NDIS drivers clear keys when infrastructure mode is
1198 * changed. But Linux tools assume otherwise. So set the
1200 restore_keys(usbdev
);
1202 priv
->infra_mode
= mode
;
1206 static int set_rts_threshold(struct usbnet
*usbdev
, u32 rts_threshold
)
1210 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, rts_threshold
);
1212 if (rts_threshold
< 0 || rts_threshold
> 2347)
1213 rts_threshold
= 2347;
1215 tmp
= cpu_to_le32(rts_threshold
);
1216 return rndis_set_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
,
1220 static int set_frag_threshold(struct usbnet
*usbdev
, u32 frag_threshold
)
1224 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, frag_threshold
);
1226 if (frag_threshold
< 256 || frag_threshold
> 2346)
1227 frag_threshold
= 2346;
1229 tmp
= cpu_to_le32(frag_threshold
);
1230 return rndis_set_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1234 static void set_default_iw_params(struct usbnet
*usbdev
)
1236 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1237 set_auth_mode(usbdev
, 0, NL80211_AUTHTYPE_OPEN_SYSTEM
,
1238 RNDIS_WLAN_KEY_MGMT_NONE
);
1239 set_priv_filter(usbdev
);
1240 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1243 static int deauthenticate(struct usbnet
*usbdev
)
1247 ret
= disassociate(usbdev
, true);
1248 set_default_iw_params(usbdev
);
1252 static int set_channel(struct usbnet
*usbdev
, int channel
)
1254 struct ndis_80211_conf config
;
1255 unsigned int dsconfig
;
1258 netdev_dbg(usbdev
->net
, "%s(%d)\n", __func__
, channel
);
1260 /* this OID is valid only when not associated */
1261 if (is_associated(usbdev
))
1264 dsconfig
= ieee80211_dsss_chan_to_freq(channel
) * 1000;
1266 len
= sizeof(config
);
1267 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
1269 netdev_dbg(usbdev
->net
, "%s(): querying configuration failed\n",
1274 config
.ds_config
= cpu_to_le32(dsconfig
);
1275 ret
= rndis_set_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
,
1278 netdev_dbg(usbdev
->net
, "%s(): %d -> %d\n", __func__
, channel
, ret
);
1283 /* index must be 0 - N, as per NDIS */
1284 static int add_wep_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1287 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1288 struct ndis_80211_wep_key ndis_key
;
1292 netdev_dbg(usbdev
->net
, "%s(idx: %d, len: %d)\n",
1293 __func__
, index
, key_len
);
1295 if ((key_len
!= 5 && key_len
!= 13) || index
< 0 || index
> 3)
1299 cipher
= WLAN_CIPHER_SUITE_WEP40
;
1301 cipher
= WLAN_CIPHER_SUITE_WEP104
;
1303 memset(&ndis_key
, 0, sizeof(ndis_key
));
1305 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
));
1306 ndis_key
.length
= cpu_to_le32(key_len
);
1307 ndis_key
.index
= cpu_to_le32(index
);
1308 memcpy(&ndis_key
.material
, key
, key_len
);
1310 if (index
== priv
->encr_tx_key_index
) {
1311 ndis_key
.index
|= NDIS_80211_ADDWEP_TRANSMIT_KEY
;
1312 ret
= set_encr_mode(usbdev
, RNDIS_WLAN_ALG_WEP
,
1313 RNDIS_WLAN_ALG_NONE
);
1315 netdev_warn(usbdev
->net
, "encryption couldn't be enabled (%08X)\n",
1319 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_WEP
, &ndis_key
,
1322 netdev_warn(usbdev
->net
, "adding encryption key %d failed (%08X)\n",
1327 priv
->encr_keys
[index
].len
= key_len
;
1328 priv
->encr_keys
[index
].cipher
= cipher
;
1329 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1330 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1335 static int add_wpa_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1336 int index
, const u8
*addr
, const u8
*rx_seq
,
1337 int seq_len
, u32 cipher
, __le32 flags
)
1339 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1340 struct ndis_80211_key ndis_key
;
1344 if (index
< 0 || index
>= 4) {
1345 netdev_dbg(usbdev
->net
, "%s(): index out of range (%i)\n",
1349 if (key_len
> sizeof(ndis_key
.material
) || key_len
< 0) {
1350 netdev_dbg(usbdev
->net
, "%s(): key length out of range (%i)\n",
1354 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
) {
1355 if (!rx_seq
|| seq_len
<= 0) {
1356 netdev_dbg(usbdev
->net
, "%s(): recv seq flag without buffer\n",
1360 if (rx_seq
&& seq_len
> sizeof(ndis_key
.rsc
)) {
1361 netdev_dbg(usbdev
->net
, "%s(): too big recv seq buffer\n", __func__
);
1366 is_addr_ok
= addr
&& !is_zero_ether_addr(addr
) &&
1367 !is_broadcast_ether_addr(addr
);
1368 if ((flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) && !is_addr_ok
) {
1369 netdev_dbg(usbdev
->net
, "%s(): pairwise but bssid invalid (%pM)\n",
1374 netdev_dbg(usbdev
->net
, "%s(%i): flags:%i%i%i\n",
1376 !!(flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
),
1377 !!(flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
),
1378 !!(flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
));
1380 memset(&ndis_key
, 0, sizeof(ndis_key
));
1382 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
) -
1383 sizeof(ndis_key
.material
) + key_len
);
1384 ndis_key
.length
= cpu_to_le32(key_len
);
1385 ndis_key
.index
= cpu_to_le32(index
) | flags
;
1387 if (cipher
== WLAN_CIPHER_SUITE_TKIP
&& key_len
== 32) {
1388 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1389 * different order than NDIS spec, so swap the order here. */
1390 memcpy(ndis_key
.material
, key
, 16);
1391 memcpy(ndis_key
.material
+ 16, key
+ 24, 8);
1392 memcpy(ndis_key
.material
+ 24, key
+ 16, 8);
1394 memcpy(ndis_key
.material
, key
, key_len
);
1396 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
)
1397 memcpy(ndis_key
.rsc
, rx_seq
, seq_len
);
1399 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) {
1401 memcpy(ndis_key
.bssid
, addr
, ETH_ALEN
);
1404 if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
1405 memset(ndis_key
.bssid
, 0xff, ETH_ALEN
);
1407 get_bssid(usbdev
, ndis_key
.bssid
);
1410 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_KEY
, &ndis_key
,
1411 le32_to_cpu(ndis_key
.size
));
1412 netdev_dbg(usbdev
->net
, "%s(): OID_802_11_ADD_KEY -> %08X\n",
1417 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
1418 priv
->encr_keys
[index
].len
= key_len
;
1419 priv
->encr_keys
[index
].cipher
= cipher
;
1420 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1421 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
)
1422 memcpy(&priv
->encr_keys
[index
].bssid
, ndis_key
.bssid
, ETH_ALEN
);
1424 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1426 if (flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
)
1427 priv
->encr_tx_key_index
= index
;
1432 static int restore_key(struct usbnet
*usbdev
, int key_idx
)
1434 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1435 struct rndis_wlan_encr_key key
;
1437 if (is_wpa_key(priv
, key_idx
))
1440 key
= priv
->encr_keys
[key_idx
];
1442 netdev_dbg(usbdev
->net
, "%s(): %i:%i\n", __func__
, key_idx
, key
.len
);
1447 return add_wep_key(usbdev
, key
.material
, key
.len
, key_idx
);
1450 static void restore_keys(struct usbnet
*usbdev
)
1454 for (i
= 0; i
< 4; i
++)
1455 restore_key(usbdev
, i
);
1458 static void clear_key(struct rndis_wlan_private
*priv
, int idx
)
1460 memset(&priv
->encr_keys
[idx
], 0, sizeof(priv
->encr_keys
[idx
]));
1463 /* remove_key is for both wep and wpa */
1464 static int remove_key(struct usbnet
*usbdev
, int index
, const u8
*bssid
)
1466 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1467 struct ndis_80211_remove_key remove_key
;
1472 if (priv
->encr_keys
[index
].len
== 0)
1475 is_wpa
= is_wpa_key(priv
, index
);
1477 netdev_dbg(usbdev
->net
, "%s(): %i:%s:%i\n",
1478 __func__
, index
, is_wpa
? "wpa" : "wep",
1479 priv
->encr_keys
[index
].len
);
1481 clear_key(priv
, index
);
1484 remove_key
.size
= cpu_to_le32(sizeof(remove_key
));
1485 remove_key
.index
= cpu_to_le32(index
);
1488 if (!is_broadcast_ether_addr(bssid
))
1490 NDIS_80211_ADDKEY_PAIRWISE_KEY
;
1491 memcpy(remove_key
.bssid
, bssid
,
1492 sizeof(remove_key
.bssid
));
1494 memset(remove_key
.bssid
, 0xff,
1495 sizeof(remove_key
.bssid
));
1497 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_KEY
, &remove_key
,
1498 sizeof(remove_key
));
1502 keyindex
= cpu_to_le32(index
);
1503 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_WEP
, &keyindex
,
1506 netdev_warn(usbdev
->net
,
1507 "removing encryption key %d failed (%08X)\n",
1513 /* if it is transmit key, disable encryption */
1514 if (index
== priv
->encr_tx_key_index
)
1515 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1520 static void set_multicast_list(struct usbnet
*usbdev
)
1522 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1523 struct dev_mc_list
*mclist
;
1528 filter
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
1530 netif_addr_lock_bh(usbdev
->net
);
1531 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1532 filter
|= RNDIS_PACKET_TYPE_PROMISCUOUS
|
1533 RNDIS_PACKET_TYPE_ALL_LOCAL
;
1534 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
||
1535 netdev_mc_count(usbdev
->net
) > priv
->multicast_size
) {
1536 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1537 } else if (!netdev_mc_empty(usbdev
->net
)) {
1538 size
= min(priv
->multicast_size
, netdev_mc_count(usbdev
->net
));
1539 buf
= kmalloc(size
* ETH_ALEN
, GFP_KERNEL
);
1541 netdev_warn(usbdev
->net
,
1542 "couldn't alloc %d bytes of memory\n",
1544 netif_addr_unlock_bh(usbdev
->net
);
1549 netdev_for_each_mc_addr(mclist
, usbdev
->net
) {
1552 memcpy(buf
+ i
++ * ETH_ALEN
, mclist
->dmi_addr
, ETH_ALEN
);
1555 ret
= rndis_set_oid(usbdev
, OID_802_3_MULTICAST_LIST
, buf
,
1557 if (ret
== 0 && i
> 0)
1558 filter
|= RNDIS_PACKET_TYPE_MULTICAST
;
1560 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1562 netdev_dbg(usbdev
->net
, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1563 i
, priv
->multicast_size
, ret
);
1567 netif_addr_unlock_bh(usbdev
->net
);
1569 ret
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1572 netdev_warn(usbdev
->net
, "couldn't set packet filter: %08x\n",
1573 le32_to_cpu(filter
));
1576 netdev_dbg(usbdev
->net
, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1577 le32_to_cpu(filter
), ret
);
1583 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
1584 struct net_device
*dev
,
1585 enum nl80211_iftype type
, u32
*flags
,
1586 struct vif_params
*params
)
1588 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1589 struct usbnet
*usbdev
= priv
->usbdev
;
1593 case NL80211_IFTYPE_ADHOC
:
1594 mode
= NDIS_80211_INFRA_ADHOC
;
1596 case NL80211_IFTYPE_STATION
:
1597 mode
= NDIS_80211_INFRA_INFRA
;
1603 priv
->wdev
.iftype
= type
;
1605 return set_infra_mode(usbdev
, mode
);
1608 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1610 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1611 struct usbnet
*usbdev
= priv
->usbdev
;
1614 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
1615 err
= set_frag_threshold(usbdev
, wiphy
->frag_threshold
);
1620 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
1621 err
= set_rts_threshold(usbdev
, wiphy
->rts_threshold
);
1629 static int rndis_set_tx_power(struct wiphy
*wiphy
, enum tx_power_setting type
,
1632 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1633 struct usbnet
*usbdev
= priv
->usbdev
;
1635 netdev_dbg(usbdev
->net
, "%s(): type:0x%x dbm:%i\n",
1636 __func__
, type
, dbm
);
1638 /* Device doesn't support changing txpower after initialization, only
1639 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1642 if (type
== TX_POWER_AUTOMATIC
|| dbm
== get_bcm4320_power_dbm(priv
)) {
1643 if (!priv
->radio_on
)
1644 disassociate(usbdev
, true); /* turn on radio */
1652 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
)
1654 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1655 struct usbnet
*usbdev
= priv
->usbdev
;
1657 *dbm
= get_bcm4320_power_dbm(priv
);
1659 netdev_dbg(usbdev
->net
, "%s(): dbm:%i\n", __func__
, *dbm
);
1664 #define SCAN_DELAY_JIFFIES (6 * HZ)
1665 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
1666 struct cfg80211_scan_request
*request
)
1668 struct usbnet
*usbdev
= netdev_priv(dev
);
1669 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1673 netdev_dbg(usbdev
->net
, "cfg80211.scan\n");
1675 /* Get current bssid list from device before new scan, as new scan
1676 * clears internal bssid list.
1678 rndis_check_bssid_list(usbdev
);
1683 if (priv
->scan_request
&& priv
->scan_request
!= request
)
1686 priv
->scan_request
= request
;
1688 tmp
= cpu_to_le32(1);
1689 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
1692 /* Wait before retrieving scan results from device */
1693 queue_delayed_work(priv
->workqueue
, &priv
->scan_work
,
1694 SCAN_DELAY_JIFFIES
);
1700 static struct cfg80211_bss
*rndis_bss_info_update(struct usbnet
*usbdev
,
1701 struct ndis_80211_bssid_ex
*bssid
)
1703 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1704 struct ieee80211_channel
*channel
;
1708 u16 beacon_interval
;
1709 struct ndis_80211_fixed_ies
*fixed
;
1710 int ie_len
, bssid_len
;
1713 netdev_dbg(usbdev
->net
, " found bssid: '%.32s' [%pM]\n",
1714 bssid
->ssid
.essid
, bssid
->mac
);
1716 /* parse bssid structure */
1717 bssid_len
= le32_to_cpu(bssid
->length
);
1719 if (bssid_len
< sizeof(struct ndis_80211_bssid_ex
) +
1720 sizeof(struct ndis_80211_fixed_ies
))
1723 fixed
= (struct ndis_80211_fixed_ies
*)bssid
->ies
;
1725 ie
= (void *)(bssid
->ies
+ sizeof(struct ndis_80211_fixed_ies
));
1726 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1727 (int)le32_to_cpu(bssid
->ie_length
));
1728 ie_len
-= sizeof(struct ndis_80211_fixed_ies
);
1732 /* extract data for cfg80211_inform_bss */
1733 channel
= ieee80211_get_channel(priv
->wdev
.wiphy
,
1734 KHZ_TO_MHZ(le32_to_cpu(bssid
->config
.ds_config
)));
1738 signal
= level_to_qual(le32_to_cpu(bssid
->rssi
));
1739 timestamp
= le64_to_cpu(*(__le64
*)fixed
->timestamp
);
1740 capability
= le16_to_cpu(fixed
->capabilities
);
1741 beacon_interval
= le16_to_cpu(fixed
->beacon_interval
);
1743 return cfg80211_inform_bss(priv
->wdev
.wiphy
, channel
, bssid
->mac
,
1744 timestamp
, capability
, beacon_interval
, ie
, ie_len
, signal
,
1748 static int rndis_check_bssid_list(struct usbnet
*usbdev
)
1751 struct ndis_80211_bssid_list_ex
*bssid_list
;
1752 struct ndis_80211_bssid_ex
*bssid
;
1753 int ret
= -EINVAL
, len
, count
, bssid_len
;
1754 bool resized
= false;
1756 netdev_dbg(usbdev
->net
, "check_bssid_list\n");
1758 len
= CONTROL_BUFFER_SIZE
;
1760 buf
= kmalloc(len
, GFP_KERNEL
);
1766 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
1770 if (!resized
&& len
> CONTROL_BUFFER_SIZE
) {
1777 bssid
= bssid_list
->bssid
;
1778 bssid_len
= le32_to_cpu(bssid
->length
);
1779 count
= le32_to_cpu(bssid_list
->num_items
);
1780 netdev_dbg(usbdev
->net
, "check_bssid_list: %d BSSIDs found (buflen: %d)\n",
1783 while (count
&& ((void *)bssid
+ bssid_len
) <= (buf
+ len
)) {
1784 rndis_bss_info_update(usbdev
, bssid
);
1786 bssid
= (void *)bssid
+ bssid_len
;
1787 bssid_len
= le32_to_cpu(bssid
->length
);
1796 static void rndis_get_scan_results(struct work_struct
*work
)
1798 struct rndis_wlan_private
*priv
=
1799 container_of(work
, struct rndis_wlan_private
, scan_work
.work
);
1800 struct usbnet
*usbdev
= priv
->usbdev
;
1803 netdev_dbg(usbdev
->net
, "get_scan_results\n");
1805 if (!priv
->scan_request
)
1808 ret
= rndis_check_bssid_list(usbdev
);
1810 cfg80211_scan_done(priv
->scan_request
, ret
< 0);
1812 priv
->scan_request
= NULL
;
1815 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
1816 struct cfg80211_connect_params
*sme
)
1818 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1819 struct usbnet
*usbdev
= priv
->usbdev
;
1820 struct ieee80211_channel
*channel
= sme
->channel
;
1821 struct ndis_80211_ssid ssid
;
1822 int pairwise
= RNDIS_WLAN_ALG_NONE
;
1823 int groupwise
= RNDIS_WLAN_ALG_NONE
;
1824 int keymgmt
= RNDIS_WLAN_KEY_MGMT_NONE
;
1825 int length
, i
, ret
, chan
= -1;
1828 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1830 groupwise
= rndis_cipher_to_alg(sme
->crypto
.cipher_group
);
1831 for (i
= 0; i
< sme
->crypto
.n_ciphers_pairwise
; i
++)
1833 rndis_cipher_to_alg(sme
->crypto
.ciphers_pairwise
[i
]);
1835 if (sme
->crypto
.n_ciphers_pairwise
> 0 &&
1836 pairwise
== RNDIS_WLAN_ALG_NONE
) {
1837 netdev_err(usbdev
->net
, "Unsupported pairwise cipher\n");
1841 for (i
= 0; i
< sme
->crypto
.n_akm_suites
; i
++)
1843 rndis_akm_suite_to_key_mgmt(sme
->crypto
.akm_suites
[i
]);
1845 if (sme
->crypto
.n_akm_suites
> 0 &&
1846 keymgmt
== RNDIS_WLAN_KEY_MGMT_NONE
) {
1847 netdev_err(usbdev
->net
, "Invalid keymgmt\n");
1851 netdev_dbg(usbdev
->net
, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
1852 sme
->ssid
, sme
->bssid
, chan
,
1853 sme
->privacy
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
1854 groupwise
, pairwise
, keymgmt
);
1856 if (is_associated(usbdev
))
1857 disassociate(usbdev
, false);
1859 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1861 netdev_dbg(usbdev
->net
, "connect: set_infra_mode failed, %d\n",
1863 goto err_turn_radio_on
;
1866 ret
= set_auth_mode(usbdev
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
1869 netdev_dbg(usbdev
->net
, "connect: set_auth_mode failed, %d\n",
1871 goto err_turn_radio_on
;
1874 set_priv_filter(usbdev
);
1876 ret
= set_encr_mode(usbdev
, pairwise
, groupwise
);
1878 netdev_dbg(usbdev
->net
, "connect: set_encr_mode failed, %d\n",
1880 goto err_turn_radio_on
;
1884 ret
= set_channel(usbdev
, chan
);
1886 netdev_dbg(usbdev
->net
, "connect: set_channel failed, %d\n",
1888 goto err_turn_radio_on
;
1892 if (sme
->key
&& ((groupwise
| pairwise
) & RNDIS_WLAN_ALG_WEP
)) {
1893 priv
->encr_tx_key_index
= sme
->key_idx
;
1894 ret
= add_wep_key(usbdev
, sme
->key
, sme
->key_len
, sme
->key_idx
);
1896 netdev_dbg(usbdev
->net
, "connect: add_wep_key failed, %d (%d, %d)\n",
1897 ret
, sme
->key_len
, sme
->key_idx
);
1898 goto err_turn_radio_on
;
1902 if (sme
->bssid
&& !is_zero_ether_addr(sme
->bssid
) &&
1903 !is_broadcast_ether_addr(sme
->bssid
)) {
1904 ret
= set_bssid(usbdev
, sme
->bssid
);
1906 netdev_dbg(usbdev
->net
, "connect: set_bssid failed, %d\n",
1908 goto err_turn_radio_on
;
1911 clear_bssid(usbdev
);
1913 length
= sme
->ssid_len
;
1914 if (length
> NDIS_802_11_LENGTH_SSID
)
1915 length
= NDIS_802_11_LENGTH_SSID
;
1917 memset(&ssid
, 0, sizeof(ssid
));
1918 ssid
.length
= cpu_to_le32(length
);
1919 memcpy(ssid
.essid
, sme
->ssid
, length
);
1921 /* Pause and purge rx queue, so we don't pass packets before
1922 * 'media connect'-indication.
1924 usbnet_pause_rx(usbdev
);
1925 usbnet_purge_paused_rxq(usbdev
);
1927 ret
= set_essid(usbdev
, &ssid
);
1929 netdev_dbg(usbdev
->net
, "connect: set_essid failed, %d\n", ret
);
1933 disassociate(usbdev
, true);
1938 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1941 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1942 struct usbnet
*usbdev
= priv
->usbdev
;
1944 netdev_dbg(usbdev
->net
, "cfg80211.disconnect(%d)\n", reason_code
);
1946 priv
->connected
= false;
1947 memset(priv
->bssid
, 0, ETH_ALEN
);
1949 return deauthenticate(usbdev
);
1952 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1953 struct cfg80211_ibss_params
*params
)
1955 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1956 struct usbnet
*usbdev
= priv
->usbdev
;
1957 struct ieee80211_channel
*channel
= params
->channel
;
1958 struct ndis_80211_ssid ssid
;
1959 enum nl80211_auth_type auth_type
;
1960 int ret
, alg
, length
, chan
= -1;
1963 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1965 /* TODO: How to handle ad-hoc encryption?
1966 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
1967 * pre-shared for encryption (open/shared/wpa), is key set before
1968 * join_ibss? Which auth_type to use (not in params)? What about WPA?
1970 if (params
->privacy
) {
1971 auth_type
= NL80211_AUTHTYPE_SHARED_KEY
;
1972 alg
= RNDIS_WLAN_ALG_WEP
;
1974 auth_type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
1975 alg
= RNDIS_WLAN_ALG_NONE
;
1978 netdev_dbg(usbdev
->net
, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
1979 params
->ssid
, params
->bssid
, chan
, params
->privacy
);
1981 if (is_associated(usbdev
))
1982 disassociate(usbdev
, false);
1984 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_ADHOC
);
1986 netdev_dbg(usbdev
->net
, "join_ibss: set_infra_mode failed, %d\n",
1988 goto err_turn_radio_on
;
1991 ret
= set_auth_mode(usbdev
, 0, auth_type
, RNDIS_WLAN_KEY_MGMT_NONE
);
1993 netdev_dbg(usbdev
->net
, "join_ibss: set_auth_mode failed, %d\n",
1995 goto err_turn_radio_on
;
1998 set_priv_filter(usbdev
);
2000 ret
= set_encr_mode(usbdev
, alg
, RNDIS_WLAN_ALG_NONE
);
2002 netdev_dbg(usbdev
->net
, "join_ibss: set_encr_mode failed, %d\n",
2004 goto err_turn_radio_on
;
2008 ret
= set_channel(usbdev
, chan
);
2010 netdev_dbg(usbdev
->net
, "join_ibss: set_channel failed, %d\n",
2012 goto err_turn_radio_on
;
2016 if (params
->bssid
&& !is_zero_ether_addr(params
->bssid
) &&
2017 !is_broadcast_ether_addr(params
->bssid
)) {
2018 ret
= set_bssid(usbdev
, params
->bssid
);
2020 netdev_dbg(usbdev
->net
, "join_ibss: set_bssid failed, %d\n",
2022 goto err_turn_radio_on
;
2025 clear_bssid(usbdev
);
2027 length
= params
->ssid_len
;
2028 if (length
> NDIS_802_11_LENGTH_SSID
)
2029 length
= NDIS_802_11_LENGTH_SSID
;
2031 memset(&ssid
, 0, sizeof(ssid
));
2032 ssid
.length
= cpu_to_le32(length
);
2033 memcpy(ssid
.essid
, params
->ssid
, length
);
2035 /* Don't need to pause rx queue for ad-hoc. */
2036 usbnet_purge_paused_rxq(usbdev
);
2037 usbnet_resume_rx(usbdev
);
2039 ret
= set_essid(usbdev
, &ssid
);
2041 netdev_dbg(usbdev
->net
, "join_ibss: set_essid failed, %d\n",
2046 disassociate(usbdev
, true);
2051 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2053 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2054 struct usbnet
*usbdev
= priv
->usbdev
;
2056 netdev_dbg(usbdev
->net
, "cfg80211.leave_ibss()\n");
2058 priv
->connected
= false;
2059 memset(priv
->bssid
, 0, ETH_ALEN
);
2061 return deauthenticate(usbdev
);
2064 static int rndis_set_channel(struct wiphy
*wiphy
,
2065 struct ieee80211_channel
*chan
, enum nl80211_channel_type channel_type
)
2067 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2068 struct usbnet
*usbdev
= priv
->usbdev
;
2070 return set_channel(usbdev
,
2071 ieee80211_frequency_to_channel(chan
->center_freq
));
2074 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2075 u8 key_index
, const u8
*mac_addr
,
2076 struct key_params
*params
)
2078 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2079 struct usbnet
*usbdev
= priv
->usbdev
;
2082 netdev_dbg(usbdev
->net
, "%s(%i, %pM, %08x)\n",
2083 __func__
, key_index
, mac_addr
, params
->cipher
);
2085 switch (params
->cipher
) {
2086 case WLAN_CIPHER_SUITE_WEP40
:
2087 case WLAN_CIPHER_SUITE_WEP104
:
2088 return add_wep_key(usbdev
, params
->key
, params
->key_len
,
2090 case WLAN_CIPHER_SUITE_TKIP
:
2091 case WLAN_CIPHER_SUITE_CCMP
:
2094 if (params
->seq
&& params
->seq_len
> 0)
2095 flags
|= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
;
2097 flags
|= NDIS_80211_ADDKEY_PAIRWISE_KEY
|
2098 NDIS_80211_ADDKEY_TRANSMIT_KEY
;
2100 return add_wpa_key(usbdev
, params
->key
, params
->key_len
,
2101 key_index
, mac_addr
, params
->seq
,
2102 params
->seq_len
, params
->cipher
, flags
);
2104 netdev_dbg(usbdev
->net
, "%s(): unsupported cipher %08x\n",
2105 __func__
, params
->cipher
);
2110 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2111 u8 key_index
, const u8
*mac_addr
)
2113 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2114 struct usbnet
*usbdev
= priv
->usbdev
;
2116 netdev_dbg(usbdev
->net
, "%s(%i, %pM)\n", __func__
, key_index
, mac_addr
);
2118 return remove_key(usbdev
, key_index
, mac_addr
);
2121 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2124 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2125 struct usbnet
*usbdev
= priv
->usbdev
;
2126 struct rndis_wlan_encr_key key
;
2128 netdev_dbg(usbdev
->net
, "%s(%i)\n", __func__
, key_index
);
2130 priv
->encr_tx_key_index
= key_index
;
2132 key
= priv
->encr_keys
[key_index
];
2134 return add_wep_key(usbdev
, key
.material
, key
.len
, key_index
);
2137 static void rndis_fill_station_info(struct usbnet
*usbdev
,
2138 struct station_info
*sinfo
)
2140 __le32 linkspeed
, rssi
;
2143 memset(sinfo
, 0, sizeof(*sinfo
));
2145 len
= sizeof(linkspeed
);
2146 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &linkspeed
, &len
);
2148 sinfo
->txrate
.legacy
= le32_to_cpu(linkspeed
) / 1000;
2149 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
2153 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2155 sinfo
->signal
= level_to_qual(le32_to_cpu(rssi
));
2156 sinfo
->filled
|= STATION_INFO_SIGNAL
;
2160 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2161 u8
*mac
, struct station_info
*sinfo
)
2163 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2164 struct usbnet
*usbdev
= priv
->usbdev
;
2166 if (compare_ether_addr(priv
->bssid
, mac
))
2169 rndis_fill_station_info(usbdev
, sinfo
);
2174 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2175 int idx
, u8
*mac
, struct station_info
*sinfo
)
2177 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2178 struct usbnet
*usbdev
= priv
->usbdev
;
2183 memcpy(mac
, priv
->bssid
, ETH_ALEN
);
2185 rndis_fill_station_info(usbdev
, sinfo
);
2191 * workers, indication handlers, device poller
2193 static void rndis_wlan_do_link_up_work(struct usbnet
*usbdev
)
2195 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2196 struct ndis_80211_assoc_info
*info
;
2197 u8 assoc_buf
[sizeof(*info
) + IW_CUSTOM_MAX
+ 32];
2199 int resp_ie_len
, req_ie_len
;
2200 u8
*req_ie
, *resp_ie
;
2202 bool roamed
= false;
2204 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
&& priv
->connected
) {
2205 /* received media connect indication while connected, either
2206 * device reassociated with same AP or roamed to new. */
2215 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2216 memset(assoc_buf
, 0, sizeof(assoc_buf
));
2217 info
= (void *)assoc_buf
;
2219 /* Get association info IEs from device and send them back to
2221 ret
= get_association_info(usbdev
, info
, sizeof(assoc_buf
));
2223 req_ie_len
= le32_to_cpu(info
->req_ie_length
);
2224 if (req_ie_len
> 0) {
2225 offset
= le32_to_cpu(info
->offset_req_ies
);
2226 req_ie
= (u8
*)info
+ offset
;
2229 resp_ie_len
= le32_to_cpu(info
->resp_ie_length
);
2230 if (resp_ie_len
> 0) {
2231 offset
= le32_to_cpu(info
->offset_resp_ies
);
2232 resp_ie
= (u8
*)info
+ offset
;
2235 } else if (WARN_ON(priv
->infra_mode
!= NDIS_80211_INFRA_ADHOC
))
2238 ret
= get_bssid(usbdev
, bssid
);
2240 memset(bssid
, 0, sizeof(bssid
));
2242 netdev_dbg(usbdev
->net
, "link up work: [%pM]%s\n",
2243 bssid
, roamed
? " roamed" : "");
2245 /* Internal bss list in device always contains at least the currently
2246 * connected bss and we can get it to cfg80211 with
2247 * rndis_check_bssid_list().
2248 * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
2251 rndis_check_bssid_list(usbdev
);
2253 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2255 cfg80211_connect_result(usbdev
->net
, bssid
, req_ie
,
2256 req_ie_len
, resp_ie
,
2257 resp_ie_len
, 0, GFP_KERNEL
);
2259 cfg80211_roamed(usbdev
->net
, bssid
, req_ie
, req_ie_len
,
2260 resp_ie
, resp_ie_len
, GFP_KERNEL
);
2261 } else if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
2262 cfg80211_ibss_joined(usbdev
->net
, bssid
, GFP_KERNEL
);
2264 priv
->connected
= true;
2265 memcpy(priv
->bssid
, bssid
, ETH_ALEN
);
2267 usbnet_resume_rx(usbdev
);
2268 netif_carrier_on(usbdev
->net
);
2271 static void rndis_wlan_do_link_down_work(struct usbnet
*usbdev
)
2273 union iwreq_data evt
;
2275 netif_carrier_off(usbdev
->net
);
2278 evt
.data
.length
= 0;
2279 memset(evt
.ap_addr
.sa_data
, 0, ETH_ALEN
);
2280 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2283 static void rndis_wlan_worker(struct work_struct
*work
)
2285 struct rndis_wlan_private
*priv
=
2286 container_of(work
, struct rndis_wlan_private
, work
);
2287 struct usbnet
*usbdev
= priv
->usbdev
;
2289 if (test_and_clear_bit(WORK_LINK_UP
, &priv
->work_pending
))
2290 rndis_wlan_do_link_up_work(usbdev
);
2292 if (test_and_clear_bit(WORK_LINK_DOWN
, &priv
->work_pending
))
2293 rndis_wlan_do_link_down_work(usbdev
);
2295 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2296 set_multicast_list(usbdev
);
2299 static void rndis_wlan_set_multicast_list(struct net_device
*dev
)
2301 struct usbnet
*usbdev
= netdev_priv(dev
);
2302 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2304 if (test_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2307 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2308 queue_work(priv
->workqueue
, &priv
->work
);
2311 static void rndis_wlan_auth_indication(struct usbnet
*usbdev
,
2312 struct ndis_80211_status_indication
*indication
,
2317 int flags
, buflen
, key_id
;
2318 bool pairwise_error
, group_error
;
2319 struct ndis_80211_auth_request
*auth_req
;
2320 enum nl80211_key_type key_type
;
2322 /* must have at least one array entry */
2323 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2324 sizeof(struct ndis_80211_auth_request
)) {
2325 netdev_info(usbdev
->net
, "authentication indication: too short message (%i)\n",
2330 buf
= (void *)&indication
->u
.auth_request
[0];
2331 buflen
= len
- offsetof(struct ndis_80211_status_indication
, u
);
2333 while (buflen
>= sizeof(*auth_req
)) {
2334 auth_req
= (void *)buf
;
2336 flags
= le32_to_cpu(auth_req
->flags
);
2337 pairwise_error
= false;
2338 group_error
= false;
2341 type
= "reauth request";
2343 type
= "key update request";
2345 pairwise_error
= true;
2346 type
= "pairwise_error";
2350 type
= "group_error";
2353 netdev_info(usbdev
->net
, "authentication indication: %s (0x%08x)\n",
2354 type
, le32_to_cpu(auth_req
->flags
));
2356 if (pairwise_error
) {
2357 key_type
= NL80211_KEYTYPE_PAIRWISE
;
2360 cfg80211_michael_mic_failure(usbdev
->net
,
2362 key_type
, key_id
, NULL
,
2367 key_type
= NL80211_KEYTYPE_GROUP
;
2370 cfg80211_michael_mic_failure(usbdev
->net
,
2372 key_type
, key_id
, NULL
,
2376 buflen
-= le32_to_cpu(auth_req
->length
);
2377 buf
+= le32_to_cpu(auth_req
->length
);
2381 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet
*usbdev
,
2382 struct ndis_80211_status_indication
*indication
,
2385 struct ndis_80211_pmkid_cand_list
*cand_list
;
2386 int list_len
, expected_len
, i
;
2388 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2389 sizeof(struct ndis_80211_pmkid_cand_list
)) {
2390 netdev_info(usbdev
->net
, "pmkid candidate list indication: too short message (%i)\n",
2395 list_len
= le32_to_cpu(indication
->u
.cand_list
.num_candidates
) *
2396 sizeof(struct ndis_80211_pmkid_candidate
);
2397 expected_len
= sizeof(struct ndis_80211_pmkid_cand_list
) + list_len
+
2398 offsetof(struct ndis_80211_status_indication
, u
);
2400 if (len
< expected_len
) {
2401 netdev_info(usbdev
->net
, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
2406 cand_list
= &indication
->u
.cand_list
;
2408 netdev_info(usbdev
->net
, "pmkid candidate list indication: version %i, candidates %i\n",
2409 le32_to_cpu(cand_list
->version
),
2410 le32_to_cpu(cand_list
->num_candidates
));
2412 if (le32_to_cpu(cand_list
->version
) != 1)
2415 for (i
= 0; i
< le32_to_cpu(cand_list
->num_candidates
); i
++) {
2416 struct ndis_80211_pmkid_candidate
*cand
=
2417 &cand_list
->candidate_list
[i
];
2419 netdev_dbg(usbdev
->net
, "cand[%i]: flags: 0x%08x, bssid: %pM\n",
2420 i
, le32_to_cpu(cand
->flags
), cand
->bssid
);
2423 struct iw_pmkid_cand pcand
;
2424 union iwreq_data wrqu
;
2426 memset(&pcand
, 0, sizeof(pcand
));
2427 if (le32_to_cpu(cand
->flags
) & 0x01)
2428 pcand
.flags
|= IW_PMKID_CAND_PREAUTH
;
2430 memcpy(pcand
.bssid
.sa_data
, cand
->bssid
, ETH_ALEN
);
2432 memset(&wrqu
, 0, sizeof(wrqu
));
2433 wrqu
.data
.length
= sizeof(pcand
);
2434 wireless_send_event(usbdev
->net
, IWEVPMKIDCAND
, &wrqu
,
2440 static void rndis_wlan_media_specific_indication(struct usbnet
*usbdev
,
2441 struct rndis_indicate
*msg
, int buflen
)
2443 struct ndis_80211_status_indication
*indication
;
2446 offset
= offsetof(struct rndis_indicate
, status
) +
2447 le32_to_cpu(msg
->offset
);
2448 len
= le32_to_cpu(msg
->length
);
2451 netdev_info(usbdev
->net
, "media specific indication, ignore too short message (%i < 8)\n",
2456 if (offset
+ len
> buflen
) {
2457 netdev_info(usbdev
->net
, "media specific indication, too large to fit to buffer (%i > %i)\n",
2458 offset
+ len
, buflen
);
2462 indication
= (void *)((u8
*)msg
+ offset
);
2464 switch (le32_to_cpu(indication
->status_type
)) {
2465 case NDIS_80211_STATUSTYPE_RADIOSTATE
:
2466 netdev_info(usbdev
->net
, "radio state indication: %i\n",
2467 le32_to_cpu(indication
->u
.radio_status
));
2470 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
:
2471 netdev_info(usbdev
->net
, "media stream mode indication: %i\n",
2472 le32_to_cpu(indication
->u
.media_stream_mode
));
2475 case NDIS_80211_STATUSTYPE_AUTHENTICATION
:
2476 rndis_wlan_auth_indication(usbdev
, indication
, len
);
2479 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
:
2480 rndis_wlan_pmkid_cand_list_indication(usbdev
, indication
, len
);
2484 netdev_info(usbdev
->net
, "media specific indication: unknown status type 0x%08x\n",
2485 le32_to_cpu(indication
->status_type
));
2489 static void rndis_wlan_indication(struct usbnet
*usbdev
, void *ind
, int buflen
)
2491 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2492 struct rndis_indicate
*msg
= ind
;
2494 switch (msg
->status
) {
2495 case RNDIS_STATUS_MEDIA_CONNECT
:
2496 if (priv
->current_command_oid
== OID_802_11_ADD_KEY
) {
2497 /* OID_802_11_ADD_KEY causes sometimes extra
2498 * "media connect" indications which confuses driver
2499 * and userspace to think that device is
2500 * roaming/reassociating when it isn't.
2502 netdev_dbg(usbdev
->net
, "ignored OID_802_11_ADD_KEY triggered 'media connect'\n");
2506 usbnet_pause_rx(usbdev
);
2508 netdev_info(usbdev
->net
, "media connect\n");
2510 /* queue work to avoid recursive calls into rndis_command */
2511 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
2512 queue_work(priv
->workqueue
, &priv
->work
);
2515 case RNDIS_STATUS_MEDIA_DISCONNECT
:
2516 netdev_info(usbdev
->net
, "media disconnect\n");
2518 /* queue work to avoid recursive calls into rndis_command */
2519 set_bit(WORK_LINK_DOWN
, &priv
->work_pending
);
2520 queue_work(priv
->workqueue
, &priv
->work
);
2523 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION
:
2524 rndis_wlan_media_specific_indication(usbdev
, msg
, buflen
);
2528 netdev_info(usbdev
->net
, "indication: 0x%08x\n",
2529 le32_to_cpu(msg
->status
));
2534 static int rndis_wlan_get_caps(struct usbnet
*usbdev
)
2539 } networks_supported
;
2540 int len
, retval
, i
, n
;
2541 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2543 /* determine supported modes */
2544 len
= sizeof(networks_supported
);
2545 retval
= rndis_query_oid(usbdev
, OID_802_11_NETWORK_TYPES_SUPPORTED
,
2546 &networks_supported
, &len
);
2548 n
= le32_to_cpu(networks_supported
.num_items
);
2551 for (i
= 0; i
< n
; i
++) {
2552 switch (le32_to_cpu(networks_supported
.items
[i
])) {
2553 case NDIS_80211_TYPE_FREQ_HOP
:
2554 case NDIS_80211_TYPE_DIRECT_SEQ
:
2555 priv
->caps
|= CAP_MODE_80211B
;
2557 case NDIS_80211_TYPE_OFDM_A
:
2558 priv
->caps
|= CAP_MODE_80211A
;
2560 case NDIS_80211_TYPE_OFDM_G
:
2561 priv
->caps
|= CAP_MODE_80211G
;
2570 #define DEVICE_POLLER_JIFFIES (HZ)
2571 static void rndis_device_poller(struct work_struct
*work
)
2573 struct rndis_wlan_private
*priv
=
2574 container_of(work
, struct rndis_wlan_private
,
2575 dev_poller_work
.work
);
2576 struct usbnet
*usbdev
= priv
->usbdev
;
2579 int update_jiffies
= DEVICE_POLLER_JIFFIES
;
2582 /* Only check/do workaround when connected. Calling is_associated()
2583 * also polls device with rndis_command() and catches for media link
2586 if (!is_associated(usbdev
))
2590 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2592 priv
->last_qual
= level_to_qual(le32_to_cpu(rssi
));
2594 netdev_dbg(usbdev
->net
, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
2595 ret
, le32_to_cpu(rssi
), level_to_qual(le32_to_cpu(rssi
)));
2597 /* Workaround transfer stalls on poor quality links.
2598 * TODO: find right way to fix these stalls (as stalls do not happen
2599 * with ndiswrapper/windows driver). */
2600 if (priv
->param_workaround_interval
> 0 && priv
->last_qual
<= 25) {
2601 /* Decrease stats worker interval to catch stalls.
2602 * faster. Faster than 400-500ms causes packet loss,
2603 * Slower doesn't catch stalls fast enough.
2605 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
2606 if (j
> DEVICE_POLLER_JIFFIES
)
2607 j
= DEVICE_POLLER_JIFFIES
;
2612 /* Send scan OID. Use of both OIDs is required to get device
2615 tmp
= cpu_to_le32(1);
2616 rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
2619 len
= CONTROL_BUFFER_SIZE
;
2620 buf
= kmalloc(len
, GFP_KERNEL
);
2624 rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2629 if (update_jiffies
>= HZ
)
2630 update_jiffies
= round_jiffies_relative(update_jiffies
);
2632 j
= round_jiffies_relative(update_jiffies
);
2633 if (abs(j
- update_jiffies
) <= 10)
2637 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
2642 * driver/device initialization
2644 static void rndis_copy_module_params(struct usbnet
*usbdev
)
2646 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2648 priv
->param_country
[0] = modparam_country
[0];
2649 priv
->param_country
[1] = modparam_country
[1];
2650 priv
->param_country
[2] = 0;
2651 priv
->param_frameburst
= modparam_frameburst
;
2652 priv
->param_afterburner
= modparam_afterburner
;
2653 priv
->param_power_save
= modparam_power_save
;
2654 priv
->param_power_output
= modparam_power_output
;
2655 priv
->param_roamtrigger
= modparam_roamtrigger
;
2656 priv
->param_roamdelta
= modparam_roamdelta
;
2658 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
2659 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
2660 /* doesn't support EU as country code, use FI instead */
2661 if (!strcmp(priv
->param_country
, "EU"))
2662 strcpy(priv
->param_country
, "FI");
2664 if (priv
->param_power_save
< 0)
2665 priv
->param_power_save
= 0;
2666 else if (priv
->param_power_save
> 2)
2667 priv
->param_power_save
= 2;
2669 if (priv
->param_power_output
< 0)
2670 priv
->param_power_output
= 0;
2671 else if (priv
->param_power_output
> 3)
2672 priv
->param_power_output
= 3;
2674 if (priv
->param_roamtrigger
< -80)
2675 priv
->param_roamtrigger
= -80;
2676 else if (priv
->param_roamtrigger
> -60)
2677 priv
->param_roamtrigger
= -60;
2679 if (priv
->param_roamdelta
< 0)
2680 priv
->param_roamdelta
= 0;
2681 else if (priv
->param_roamdelta
> 2)
2682 priv
->param_roamdelta
= 2;
2684 if (modparam_workaround_interval
< 0)
2685 priv
->param_workaround_interval
= 500;
2687 priv
->param_workaround_interval
= modparam_workaround_interval
;
2690 static int bcm4320a_early_init(struct usbnet
*usbdev
)
2692 /* copy module parameters for bcm4320a so that iwconfig reports txpower
2693 * and workaround parameter is copied to private structure correctly.
2695 rndis_copy_module_params(usbdev
);
2697 /* bcm4320a doesn't handle configuration parameters well. Try
2698 * set any and you get partially zeroed mac and broken device.
2704 static int bcm4320b_early_init(struct usbnet
*usbdev
)
2706 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2709 rndis_copy_module_params(usbdev
);
2711 /* Early initialization settings, setting these won't have effect
2712 * if called after generic_rndis_bind().
2715 rndis_set_config_parameter_str(usbdev
, "Country", priv
->param_country
);
2716 rndis_set_config_parameter_str(usbdev
, "FrameBursting",
2717 priv
->param_frameburst
? "1" : "0");
2718 rndis_set_config_parameter_str(usbdev
, "Afterburner",
2719 priv
->param_afterburner
? "1" : "0");
2720 sprintf(buf
, "%d", priv
->param_power_save
);
2721 rndis_set_config_parameter_str(usbdev
, "PowerSaveMode", buf
);
2722 sprintf(buf
, "%d", priv
->param_power_output
);
2723 rndis_set_config_parameter_str(usbdev
, "PwrOut", buf
);
2724 sprintf(buf
, "%d", priv
->param_roamtrigger
);
2725 rndis_set_config_parameter_str(usbdev
, "RoamTrigger", buf
);
2726 sprintf(buf
, "%d", priv
->param_roamdelta
);
2727 rndis_set_config_parameter_str(usbdev
, "RoamDelta", buf
);
2732 /* same as rndis_netdev_ops but with local multicast handler */
2733 static const struct net_device_ops rndis_wlan_netdev_ops
= {
2734 .ndo_open
= usbnet_open
,
2735 .ndo_stop
= usbnet_stop
,
2736 .ndo_start_xmit
= usbnet_start_xmit
,
2737 .ndo_tx_timeout
= usbnet_tx_timeout
,
2738 .ndo_set_mac_address
= eth_mac_addr
,
2739 .ndo_validate_addr
= eth_validate_addr
,
2740 .ndo_set_multicast_list
= rndis_wlan_set_multicast_list
,
2743 static int rndis_wlan_bind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2745 struct wiphy
*wiphy
;
2746 struct rndis_wlan_private
*priv
;
2750 /* allocate wiphy and rndis private data
2751 * NOTE: We only support a single virtual interface, so wiphy
2752 * and wireless_dev are somewhat synonymous for this device.
2754 wiphy
= wiphy_new(&rndis_config_ops
, sizeof(struct rndis_wlan_private
));
2758 priv
= wiphy_priv(wiphy
);
2759 usbdev
->net
->ieee80211_ptr
= &priv
->wdev
;
2760 priv
->wdev
.wiphy
= wiphy
;
2761 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
2763 /* These have to be initialized before calling generic_rndis_bind().
2764 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
2766 usbdev
->driver_priv
= priv
;
2767 priv
->usbdev
= usbdev
;
2769 mutex_init(&priv
->command_lock
);
2771 /* because rndis_command() sleeps we need to use workqueue */
2772 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
2773 INIT_WORK(&priv
->work
, rndis_wlan_worker
);
2774 INIT_DELAYED_WORK(&priv
->dev_poller_work
, rndis_device_poller
);
2775 INIT_DELAYED_WORK(&priv
->scan_work
, rndis_get_scan_results
);
2777 /* try bind rndis_host */
2778 retval
= generic_rndis_bind(usbdev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
2782 /* generic_rndis_bind set packet filter to multicast_all+
2783 * promisc mode which doesn't work well for our devices (device
2784 * picks up rssi to closest station instead of to access point).
2786 * rndis_host wants to avoid all OID as much as possible
2787 * so do promisc/multicast handling in rndis_wlan.
2789 usbdev
->net
->netdev_ops
= &rndis_wlan_netdev_ops
;
2791 tmp
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
2792 retval
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &tmp
,
2796 retval
= rndis_query_oid(usbdev
, OID_802_3_MAXIMUM_LIST_SIZE
, &tmp
,
2798 priv
->multicast_size
= le32_to_cpu(tmp
);
2799 if (retval
< 0 || priv
->multicast_size
< 0)
2800 priv
->multicast_size
= 0;
2801 if (priv
->multicast_size
> 0)
2802 usbdev
->net
->flags
|= IFF_MULTICAST
;
2804 usbdev
->net
->flags
&= ~IFF_MULTICAST
;
2806 /* fill-out wiphy structure and register w/ cfg80211 */
2807 memcpy(wiphy
->perm_addr
, usbdev
->net
->dev_addr
, ETH_ALEN
);
2808 wiphy
->privid
= rndis_wiphy_privid
;
2809 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
2810 | BIT(NL80211_IFTYPE_ADHOC
);
2811 wiphy
->max_scan_ssids
= 1;
2813 /* TODO: fill-out band/encr information based on priv->caps */
2814 rndis_wlan_get_caps(usbdev
);
2816 memcpy(priv
->channels
, rndis_channels
, sizeof(rndis_channels
));
2817 memcpy(priv
->rates
, rndis_rates
, sizeof(rndis_rates
));
2818 priv
->band
.channels
= priv
->channels
;
2819 priv
->band
.n_channels
= ARRAY_SIZE(rndis_channels
);
2820 priv
->band
.bitrates
= priv
->rates
;
2821 priv
->band
.n_bitrates
= ARRAY_SIZE(rndis_rates
);
2822 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
2823 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_UNSPEC
;
2825 memcpy(priv
->cipher_suites
, rndis_cipher_suites
,
2826 sizeof(rndis_cipher_suites
));
2827 wiphy
->cipher_suites
= priv
->cipher_suites
;
2828 wiphy
->n_cipher_suites
= ARRAY_SIZE(rndis_cipher_suites
);
2830 set_wiphy_dev(wiphy
, &usbdev
->udev
->dev
);
2832 if (wiphy_register(wiphy
)) {
2837 set_default_iw_params(usbdev
);
2839 /* set default rts/frag */
2840 rndis_set_wiphy_params(wiphy
,
2841 WIPHY_PARAM_FRAG_THRESHOLD
| WIPHY_PARAM_RTS_THRESHOLD
);
2844 priv
->radio_on
= true;
2845 disassociate(usbdev
, true);
2846 netif_carrier_off(usbdev
->net
);
2851 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2852 cancel_delayed_work_sync(&priv
->scan_work
);
2853 cancel_work_sync(&priv
->work
);
2854 flush_workqueue(priv
->workqueue
);
2855 destroy_workqueue(priv
->workqueue
);
2861 static void rndis_wlan_unbind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2863 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2865 /* turn radio off */
2866 disassociate(usbdev
, false);
2868 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2869 cancel_delayed_work_sync(&priv
->scan_work
);
2870 cancel_work_sync(&priv
->work
);
2871 flush_workqueue(priv
->workqueue
);
2872 destroy_workqueue(priv
->workqueue
);
2874 if (priv
&& priv
->wpa_ie_len
)
2875 kfree(priv
->wpa_ie
);
2877 rndis_unbind(usbdev
, intf
);
2879 wiphy_unregister(priv
->wdev
.wiphy
);
2880 wiphy_free(priv
->wdev
.wiphy
);
2883 static int rndis_wlan_reset(struct usbnet
*usbdev
)
2885 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2888 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2890 retval
= rndis_reset(usbdev
);
2892 netdev_warn(usbdev
->net
, "rndis_reset failed: %d\n", retval
);
2894 /* rndis_reset cleared multicast list, so restore here.
2895 (set_multicast_list() also turns on current packet filter) */
2896 set_multicast_list(usbdev
);
2898 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
2899 round_jiffies_relative(DEVICE_POLLER_JIFFIES
));
2901 return deauthenticate(usbdev
);
2904 static int rndis_wlan_stop(struct usbnet
*usbdev
)
2906 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2910 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2912 retval
= disassociate(usbdev
, false);
2914 priv
->work_pending
= 0;
2915 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2916 cancel_delayed_work_sync(&priv
->scan_work
);
2917 cancel_work_sync(&priv
->work
);
2918 flush_workqueue(priv
->workqueue
);
2920 if (priv
->scan_request
) {
2921 cfg80211_scan_done(priv
->scan_request
, true);
2922 priv
->scan_request
= NULL
;
2925 /* Set current packet filter zero to block receiving data packets from
2928 rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
2934 static const struct driver_info bcm4320b_info
= {
2935 .description
= "Wireless RNDIS device, BCM4320b based",
2936 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2937 FLAG_AVOID_UNLINK_URBS
,
2938 .bind
= rndis_wlan_bind
,
2939 .unbind
= rndis_wlan_unbind
,
2940 .status
= rndis_status
,
2941 .rx_fixup
= rndis_rx_fixup
,
2942 .tx_fixup
= rndis_tx_fixup
,
2943 .reset
= rndis_wlan_reset
,
2944 .stop
= rndis_wlan_stop
,
2945 .early_init
= bcm4320b_early_init
,
2946 .indication
= rndis_wlan_indication
,
2949 static const struct driver_info bcm4320a_info
= {
2950 .description
= "Wireless RNDIS device, BCM4320a based",
2951 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2952 FLAG_AVOID_UNLINK_URBS
,
2953 .bind
= rndis_wlan_bind
,
2954 .unbind
= rndis_wlan_unbind
,
2955 .status
= rndis_status
,
2956 .rx_fixup
= rndis_rx_fixup
,
2957 .tx_fixup
= rndis_tx_fixup
,
2958 .reset
= rndis_wlan_reset
,
2959 .stop
= rndis_wlan_stop
,
2960 .early_init
= bcm4320a_early_init
,
2961 .indication
= rndis_wlan_indication
,
2964 static const struct driver_info rndis_wlan_info
= {
2965 .description
= "Wireless RNDIS device",
2966 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2967 FLAG_AVOID_UNLINK_URBS
,
2968 .bind
= rndis_wlan_bind
,
2969 .unbind
= rndis_wlan_unbind
,
2970 .status
= rndis_status
,
2971 .rx_fixup
= rndis_rx_fixup
,
2972 .tx_fixup
= rndis_tx_fixup
,
2973 .reset
= rndis_wlan_reset
,
2974 .stop
= rndis_wlan_stop
,
2975 .early_init
= bcm4320a_early_init
,
2976 .indication
= rndis_wlan_indication
,
2979 /*-------------------------------------------------------------------------*/
2981 static const struct usb_device_id products
[] = {
2982 #define RNDIS_MASTER_INTERFACE \
2983 .bInterfaceClass = USB_CLASS_COMM, \
2984 .bInterfaceSubClass = 2 /* ACM */, \
2985 .bInterfaceProtocol = 0x0ff
2987 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2988 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2991 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2992 | USB_DEVICE_ID_MATCH_DEVICE
,
2994 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
2995 RNDIS_MASTER_INTERFACE
,
2996 .driver_info
= (unsigned long) &bcm4320b_info
,
2998 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2999 | USB_DEVICE_ID_MATCH_DEVICE
,
3001 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
3002 RNDIS_MASTER_INTERFACE
,
3003 .driver_info
= (unsigned long) &bcm4320b_info
,
3005 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3006 | USB_DEVICE_ID_MATCH_DEVICE
,
3008 .idProduct
= 0x011b, /* Belkin F5D7051 */
3009 RNDIS_MASTER_INTERFACE
,
3010 .driver_info
= (unsigned long) &bcm4320b_info
,
3012 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3013 | USB_DEVICE_ID_MATCH_DEVICE
,
3014 .idVendor
= 0x1799, /* Belkin has two vendor ids */
3015 .idProduct
= 0x011b, /* Belkin F5D7051 */
3016 RNDIS_MASTER_INTERFACE
,
3017 .driver_info
= (unsigned long) &bcm4320b_info
,
3019 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3020 | USB_DEVICE_ID_MATCH_DEVICE
,
3022 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
3023 RNDIS_MASTER_INTERFACE
,
3024 .driver_info
= (unsigned long) &bcm4320b_info
,
3026 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3027 | USB_DEVICE_ID_MATCH_DEVICE
,
3029 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
3030 RNDIS_MASTER_INTERFACE
,
3031 .driver_info
= (unsigned long) &bcm4320b_info
,
3033 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3034 | USB_DEVICE_ID_MATCH_DEVICE
,
3036 .idProduct
= 0x1717, /* Asus WL169gE */
3037 RNDIS_MASTER_INTERFACE
,
3038 .driver_info
= (unsigned long) &bcm4320b_info
,
3040 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3041 | USB_DEVICE_ID_MATCH_DEVICE
,
3043 .idProduct
= 0xd11b, /* Eminent EM4045 */
3044 RNDIS_MASTER_INTERFACE
,
3045 .driver_info
= (unsigned long) &bcm4320b_info
,
3047 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3048 | USB_DEVICE_ID_MATCH_DEVICE
,
3050 .idProduct
= 0x0715, /* BT Voyager 1055 */
3051 RNDIS_MASTER_INTERFACE
,
3052 .driver_info
= (unsigned long) &bcm4320b_info
,
3054 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3055 * parameters available, hardware probably contain older firmware version with
3056 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3059 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3060 | USB_DEVICE_ID_MATCH_DEVICE
,
3062 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
3063 RNDIS_MASTER_INTERFACE
,
3064 .driver_info
= (unsigned long) &bcm4320a_info
,
3066 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3067 | USB_DEVICE_ID_MATCH_DEVICE
,
3069 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
3070 RNDIS_MASTER_INTERFACE
,
3071 .driver_info
= (unsigned long) &bcm4320a_info
,
3073 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3074 | USB_DEVICE_ID_MATCH_DEVICE
,
3076 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
3077 RNDIS_MASTER_INTERFACE
,
3078 .driver_info
= (unsigned long) &bcm4320a_info
,
3080 /* Generic Wireless RNDIS devices that we don't have exact
3081 * idVendor/idProduct/chip yet.
3084 /* RNDIS is MSFT's un-official variant of CDC ACM */
3085 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
3086 .driver_info
= (unsigned long) &rndis_wlan_info
,
3088 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3089 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
3090 .driver_info
= (unsigned long) &rndis_wlan_info
,
3094 MODULE_DEVICE_TABLE(usb
, products
);
3096 static struct usb_driver rndis_wlan_driver
= {
3097 .name
= "rndis_wlan",
3098 .id_table
= products
,
3099 .probe
= usbnet_probe
,
3100 .disconnect
= usbnet_disconnect
,
3101 .suspend
= usbnet_suspend
,
3102 .resume
= usbnet_resume
,
3105 static int __init
rndis_wlan_init(void)
3107 return usb_register(&rndis_wlan_driver
);
3109 module_init(rndis_wlan_init
);
3111 static void __exit
rndis_wlan_exit(void)
3113 usb_deregister(&rndis_wlan_driver
);
3115 module_exit(rndis_wlan_exit
);
3117 MODULE_AUTHOR("Bjorge Dijkstra");
3118 MODULE_AUTHOR("Jussi Kivilinna");
3119 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3120 MODULE_LICENSE("GPL");