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
;
708 buflen
= *len
+ sizeof(*u
.get
);
709 if (buflen
< CONTROL_BUFFER_SIZE
)
710 buflen
= CONTROL_BUFFER_SIZE
;
712 if (buflen
> COMMAND_BUFFER_SIZE
) {
713 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
717 u
.buf
= priv
->command_buffer
;
720 mutex_lock(&priv
->command_lock
);
722 memset(u
.get
, 0, sizeof *u
.get
);
723 u
.get
->msg_type
= RNDIS_MSG_QUERY
;
724 u
.get
->msg_len
= cpu_to_le32(sizeof *u
.get
);
727 priv
->current_command_oid
= oid
;
728 ret
= rndis_command(dev
, u
.header
, buflen
);
729 priv
->current_command_oid
= 0;
731 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
732 __func__
, oid_to_string(oid
), ret
,
733 le32_to_cpu(u
.get_c
->status
));
736 memcpy(data
, u
.buf
+ le32_to_cpu(u
.get_c
->offset
) + 8, *len
);
738 ret
= le32_to_cpu(u
.get_c
->len
);
742 ret
= rndis_error_status(u
.get_c
->status
);
744 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
745 __func__
, oid_to_string(oid
),
746 le32_to_cpu(u
.get_c
->status
), ret
);
749 mutex_unlock(&priv
->command_lock
);
751 if (u
.buf
!= priv
->command_buffer
)
756 static int rndis_set_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int len
)
758 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
761 struct rndis_msg_hdr
*header
;
762 struct rndis_set
*set
;
763 struct rndis_set_c
*set_c
;
767 buflen
= len
+ sizeof(*u
.set
);
768 if (buflen
< CONTROL_BUFFER_SIZE
)
769 buflen
= CONTROL_BUFFER_SIZE
;
771 if (buflen
> COMMAND_BUFFER_SIZE
) {
772 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
776 u
.buf
= priv
->command_buffer
;
779 mutex_lock(&priv
->command_lock
);
781 memset(u
.set
, 0, sizeof *u
.set
);
782 u
.set
->msg_type
= RNDIS_MSG_SET
;
783 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
785 u
.set
->len
= cpu_to_le32(len
);
786 u
.set
->offset
= cpu_to_le32(sizeof(*u
.set
) - 8);
787 u
.set
->handle
= cpu_to_le32(0);
788 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
790 priv
->current_command_oid
= oid
;
791 ret
= rndis_command(dev
, u
.header
, buflen
);
792 priv
->current_command_oid
= 0;
794 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
795 __func__
, oid_to_string(oid
), ret
,
796 le32_to_cpu(u
.set_c
->status
));
799 ret
= rndis_error_status(u
.set_c
->status
);
802 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
803 __func__
, oid_to_string(oid
),
804 le32_to_cpu(u
.set_c
->status
), ret
);
807 mutex_unlock(&priv
->command_lock
);
809 if (u
.buf
!= priv
->command_buffer
)
814 static int rndis_reset(struct usbnet
*usbdev
)
816 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
817 struct rndis_reset
*reset
;
820 mutex_lock(&priv
->command_lock
);
822 reset
= (void *)priv
->command_buffer
;
823 memset(reset
, 0, sizeof(*reset
));
824 reset
->msg_type
= RNDIS_MSG_RESET
;
825 reset
->msg_len
= cpu_to_le32(sizeof(*reset
));
826 priv
->current_command_oid
= 0;
827 ret
= rndis_command(usbdev
, (void *)reset
, CONTROL_BUFFER_SIZE
);
829 mutex_unlock(&priv
->command_lock
);
837 * Specs say that we can only set config parameters only soon after device
839 * value_type: 0 = u32, 2 = unicode string
841 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
842 int value_type
, void *value
)
844 struct ndis_config_param
*infobuf
;
845 int value_len
, info_len
, param_len
, ret
, i
;
850 value_len
= sizeof(__le32
);
851 else if (value_type
== 2)
852 value_len
= strlen(value
) * sizeof(__le16
);
856 param_len
= strlen(param
) * sizeof(__le16
);
857 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
862 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
868 /* extra 12 bytes are for padding (debug output) */
869 memset(infobuf
, 0xCC, info_len
+ 12);
873 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %s\n",
876 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %d\n",
877 param
, *(u32
*)value
);
879 infobuf
->name_offs
= cpu_to_le32(sizeof(*infobuf
));
880 infobuf
->name_length
= cpu_to_le32(param_len
);
881 infobuf
->type
= cpu_to_le32(value_type
);
882 infobuf
->value_offs
= cpu_to_le32(sizeof(*infobuf
) + param_len
);
883 infobuf
->value_length
= cpu_to_le32(value_len
);
885 /* simple string to unicode string conversion */
886 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
887 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
888 unibuf
[i
] = cpu_to_le16(param
[i
]);
890 if (value_type
== 2) {
891 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
892 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
893 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
895 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
896 *dst_value
= cpu_to_le32(*(u32
*)value
);
900 netdev_dbg(dev
->net
, "info buffer (len: %d)\n", info_len
);
901 for (i
= 0; i
< info_len
; i
+= 12) {
902 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
903 netdev_dbg(dev
->net
, "%08X:%08X:%08X\n",
906 cpu_to_be32(tmp
[2]));
910 ret
= rndis_set_oid(dev
, OID_GEN_RNDIS_CONFIG_PARAMETER
,
913 netdev_dbg(dev
->net
, "setting rndis config parameter failed, %d\n",
920 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
921 char *param
, char *value
)
923 return rndis_set_config_parameter(dev
, param
, 2, value
);
927 * data conversion functions
929 static int level_to_qual(int level
)
931 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
932 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
938 static int set_infra_mode(struct usbnet
*usbdev
, int mode
);
939 static void restore_keys(struct usbnet
*usbdev
);
940 static int rndis_check_bssid_list(struct usbnet
*usbdev
);
942 static int set_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
944 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
947 ret
= rndis_set_oid(usbdev
, OID_802_11_SSID
, ssid
, sizeof(*ssid
));
949 netdev_warn(usbdev
->net
, "setting SSID failed (%08X)\n", ret
);
953 memcpy(&priv
->essid
, ssid
, sizeof(priv
->essid
));
954 priv
->radio_on
= true;
955 netdev_dbg(usbdev
->net
, "%s(): radio_on = true\n", __func__
);
961 static int set_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
965 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID
, bssid
, ETH_ALEN
);
967 netdev_warn(usbdev
->net
, "setting BSSID[%pM] failed (%08X)\n",
975 static int clear_bssid(struct usbnet
*usbdev
)
977 u8 broadcast_mac
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
979 return set_bssid(usbdev
, broadcast_mac
);
982 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
987 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID
, bssid
, &len
);
990 memset(bssid
, 0, ETH_ALEN
);
995 static int get_association_info(struct usbnet
*usbdev
,
996 struct ndis_80211_assoc_info
*info
, int len
)
998 return rndis_query_oid(usbdev
, OID_802_11_ASSOCIATION_INFORMATION
,
1002 static bool is_associated(struct usbnet
*usbdev
)
1004 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1008 if (!priv
->radio_on
)
1011 ret
= get_bssid(usbdev
, bssid
);
1013 return (ret
== 0 && !is_zero_ether_addr(bssid
));
1016 static int disassociate(struct usbnet
*usbdev
, bool reset_ssid
)
1018 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1019 struct ndis_80211_ssid ssid
;
1022 if (priv
->radio_on
) {
1023 ret
= rndis_set_oid(usbdev
, OID_802_11_DISASSOCIATE
, NULL
, 0);
1025 priv
->radio_on
= false;
1026 netdev_dbg(usbdev
->net
, "%s(): radio_on = false\n",
1034 /* disassociate causes radio to be turned off; if reset_ssid
1035 * is given, set random ssid to enable radio */
1037 /* Set device to infrastructure mode so we don't get ad-hoc
1038 * 'media connect' indications with the random ssid.
1040 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1042 ssid
.length
= cpu_to_le32(sizeof(ssid
.essid
));
1043 get_random_bytes(&ssid
.essid
[2], sizeof(ssid
.essid
)-2);
1044 ssid
.essid
[0] = 0x1;
1045 ssid
.essid
[1] = 0xff;
1046 for (i
= 2; i
< sizeof(ssid
.essid
); i
++)
1047 ssid
.essid
[i
] = 0x1 + (ssid
.essid
[i
] * 0xfe / 0xff);
1048 ret
= set_essid(usbdev
, &ssid
);
1053 static int set_auth_mode(struct usbnet
*usbdev
, u32 wpa_version
,
1054 enum nl80211_auth_type auth_type
, int keymgmt
)
1056 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1060 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1061 __func__
, wpa_version
, auth_type
, keymgmt
);
1063 if (wpa_version
& NL80211_WPA_VERSION_2
) {
1064 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1065 auth_mode
= NDIS_80211_AUTH_WPA2
;
1067 auth_mode
= NDIS_80211_AUTH_WPA2_PSK
;
1068 } else if (wpa_version
& NL80211_WPA_VERSION_1
) {
1069 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1070 auth_mode
= NDIS_80211_AUTH_WPA
;
1071 else if (keymgmt
& RNDIS_WLAN_KEY_MGMT_PSK
)
1072 auth_mode
= NDIS_80211_AUTH_WPA_PSK
;
1074 auth_mode
= NDIS_80211_AUTH_WPA_NONE
;
1075 } else if (auth_type
== NL80211_AUTHTYPE_SHARED_KEY
)
1076 auth_mode
= NDIS_80211_AUTH_SHARED
;
1077 else if (auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
)
1078 auth_mode
= NDIS_80211_AUTH_OPEN
;
1079 else if (auth_type
== NL80211_AUTHTYPE_AUTOMATIC
)
1080 auth_mode
= NDIS_80211_AUTH_AUTO_SWITCH
;
1084 tmp
= cpu_to_le32(auth_mode
);
1085 ret
= rndis_set_oid(usbdev
, OID_802_11_AUTHENTICATION_MODE
, &tmp
,
1088 netdev_warn(usbdev
->net
, "setting auth mode failed (%08X)\n",
1093 priv
->wpa_version
= wpa_version
;
1094 priv
->wpa_auth_type
= auth_type
;
1095 priv
->wpa_keymgmt
= keymgmt
;
1100 static int set_priv_filter(struct usbnet
*usbdev
)
1102 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1105 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x\n",
1106 __func__
, priv
->wpa_version
);
1108 if (priv
->wpa_version
& NL80211_WPA_VERSION_2
||
1109 priv
->wpa_version
& NL80211_WPA_VERSION_1
)
1110 tmp
= cpu_to_le32(NDIS_80211_PRIV_8021X_WEP
);
1112 tmp
= cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL
);
1114 return rndis_set_oid(usbdev
, OID_802_11_PRIVACY_FILTER
, &tmp
,
1118 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
1120 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1124 netdev_dbg(usbdev
->net
, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1125 __func__
, pairwise
, groupwise
);
1127 if (pairwise
& RNDIS_WLAN_ALG_CCMP
)
1128 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1129 else if (pairwise
& RNDIS_WLAN_ALG_TKIP
)
1130 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1131 else if (pairwise
& RNDIS_WLAN_ALG_WEP
)
1132 encr_mode
= NDIS_80211_ENCR_WEP_ENABLED
;
1133 else if (groupwise
& RNDIS_WLAN_ALG_CCMP
)
1134 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1135 else if (groupwise
& RNDIS_WLAN_ALG_TKIP
)
1136 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1138 encr_mode
= NDIS_80211_ENCR_DISABLED
;
1140 tmp
= cpu_to_le32(encr_mode
);
1141 ret
= rndis_set_oid(usbdev
, OID_802_11_ENCRYPTION_STATUS
, &tmp
,
1144 netdev_warn(usbdev
->net
, "setting encr mode failed (%08X)\n",
1149 priv
->wpa_cipher_pair
= pairwise
;
1150 priv
->wpa_cipher_group
= groupwise
;
1154 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
1156 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1160 netdev_dbg(usbdev
->net
, "%s(): infra_mode=0x%x\n",
1161 __func__
, priv
->infra_mode
);
1163 tmp
= cpu_to_le32(mode
);
1164 ret
= rndis_set_oid(usbdev
, OID_802_11_INFRASTRUCTURE_MODE
, &tmp
,
1167 netdev_warn(usbdev
->net
, "setting infra mode failed (%08X)\n",
1172 /* NDIS drivers clear keys when infrastructure mode is
1173 * changed. But Linux tools assume otherwise. So set the
1175 restore_keys(usbdev
);
1177 priv
->infra_mode
= mode
;
1181 static int set_rts_threshold(struct usbnet
*usbdev
, u32 rts_threshold
)
1185 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, rts_threshold
);
1187 if (rts_threshold
< 0 || rts_threshold
> 2347)
1188 rts_threshold
= 2347;
1190 tmp
= cpu_to_le32(rts_threshold
);
1191 return rndis_set_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
,
1195 static int set_frag_threshold(struct usbnet
*usbdev
, u32 frag_threshold
)
1199 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, frag_threshold
);
1201 if (frag_threshold
< 256 || frag_threshold
> 2346)
1202 frag_threshold
= 2346;
1204 tmp
= cpu_to_le32(frag_threshold
);
1205 return rndis_set_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1209 static void set_default_iw_params(struct usbnet
*usbdev
)
1211 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1212 set_auth_mode(usbdev
, 0, NL80211_AUTHTYPE_OPEN_SYSTEM
,
1213 RNDIS_WLAN_KEY_MGMT_NONE
);
1214 set_priv_filter(usbdev
);
1215 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1218 static int deauthenticate(struct usbnet
*usbdev
)
1222 ret
= disassociate(usbdev
, true);
1223 set_default_iw_params(usbdev
);
1227 static int set_channel(struct usbnet
*usbdev
, int channel
)
1229 struct ndis_80211_conf config
;
1230 unsigned int dsconfig
;
1233 netdev_dbg(usbdev
->net
, "%s(%d)\n", __func__
, channel
);
1235 /* this OID is valid only when not associated */
1236 if (is_associated(usbdev
))
1239 dsconfig
= ieee80211_dsss_chan_to_freq(channel
) * 1000;
1241 len
= sizeof(config
);
1242 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
1244 netdev_dbg(usbdev
->net
, "%s(): querying configuration failed\n",
1249 config
.ds_config
= cpu_to_le32(dsconfig
);
1250 ret
= rndis_set_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
,
1253 netdev_dbg(usbdev
->net
, "%s(): %d -> %d\n", __func__
, channel
, ret
);
1258 /* index must be 0 - N, as per NDIS */
1259 static int add_wep_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1262 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1263 struct ndis_80211_wep_key ndis_key
;
1267 netdev_dbg(usbdev
->net
, "%s(idx: %d, len: %d)\n",
1268 __func__
, index
, key_len
);
1270 if ((key_len
!= 5 && key_len
!= 13) || index
< 0 || index
> 3)
1274 cipher
= WLAN_CIPHER_SUITE_WEP40
;
1276 cipher
= WLAN_CIPHER_SUITE_WEP104
;
1278 memset(&ndis_key
, 0, sizeof(ndis_key
));
1280 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
));
1281 ndis_key
.length
= cpu_to_le32(key_len
);
1282 ndis_key
.index
= cpu_to_le32(index
);
1283 memcpy(&ndis_key
.material
, key
, key_len
);
1285 if (index
== priv
->encr_tx_key_index
) {
1286 ndis_key
.index
|= NDIS_80211_ADDWEP_TRANSMIT_KEY
;
1287 ret
= set_encr_mode(usbdev
, RNDIS_WLAN_ALG_WEP
,
1288 RNDIS_WLAN_ALG_NONE
);
1290 netdev_warn(usbdev
->net
, "encryption couldn't be enabled (%08X)\n",
1294 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_WEP
, &ndis_key
,
1297 netdev_warn(usbdev
->net
, "adding encryption key %d failed (%08X)\n",
1302 priv
->encr_keys
[index
].len
= key_len
;
1303 priv
->encr_keys
[index
].cipher
= cipher
;
1304 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1305 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1310 static int add_wpa_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1311 int index
, const u8
*addr
, const u8
*rx_seq
,
1312 int seq_len
, u32 cipher
, __le32 flags
)
1314 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1315 struct ndis_80211_key ndis_key
;
1319 if (index
< 0 || index
>= 4) {
1320 netdev_dbg(usbdev
->net
, "%s(): index out of range (%i)\n",
1324 if (key_len
> sizeof(ndis_key
.material
) || key_len
< 0) {
1325 netdev_dbg(usbdev
->net
, "%s(): key length out of range (%i)\n",
1329 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
) {
1330 if (!rx_seq
|| seq_len
<= 0) {
1331 netdev_dbg(usbdev
->net
, "%s(): recv seq flag without buffer\n",
1335 if (rx_seq
&& seq_len
> sizeof(ndis_key
.rsc
)) {
1336 netdev_dbg(usbdev
->net
, "%s(): too big recv seq buffer\n", __func__
);
1341 is_addr_ok
= addr
&& !is_zero_ether_addr(addr
) &&
1342 !is_broadcast_ether_addr(addr
);
1343 if ((flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) && !is_addr_ok
) {
1344 netdev_dbg(usbdev
->net
, "%s(): pairwise but bssid invalid (%pM)\n",
1349 netdev_dbg(usbdev
->net
, "%s(%i): flags:%i%i%i\n",
1351 !!(flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
),
1352 !!(flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
),
1353 !!(flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
));
1355 memset(&ndis_key
, 0, sizeof(ndis_key
));
1357 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
) -
1358 sizeof(ndis_key
.material
) + key_len
);
1359 ndis_key
.length
= cpu_to_le32(key_len
);
1360 ndis_key
.index
= cpu_to_le32(index
) | flags
;
1362 if (cipher
== WLAN_CIPHER_SUITE_TKIP
&& key_len
== 32) {
1363 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1364 * different order than NDIS spec, so swap the order here. */
1365 memcpy(ndis_key
.material
, key
, 16);
1366 memcpy(ndis_key
.material
+ 16, key
+ 24, 8);
1367 memcpy(ndis_key
.material
+ 24, key
+ 16, 8);
1369 memcpy(ndis_key
.material
, key
, key_len
);
1371 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
)
1372 memcpy(ndis_key
.rsc
, rx_seq
, seq_len
);
1374 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) {
1376 memcpy(ndis_key
.bssid
, addr
, ETH_ALEN
);
1379 if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
1380 memset(ndis_key
.bssid
, 0xff, ETH_ALEN
);
1382 get_bssid(usbdev
, ndis_key
.bssid
);
1385 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_KEY
, &ndis_key
,
1386 le32_to_cpu(ndis_key
.size
));
1387 netdev_dbg(usbdev
->net
, "%s(): OID_802_11_ADD_KEY -> %08X\n",
1392 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
1393 priv
->encr_keys
[index
].len
= key_len
;
1394 priv
->encr_keys
[index
].cipher
= cipher
;
1395 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1396 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
)
1397 memcpy(&priv
->encr_keys
[index
].bssid
, ndis_key
.bssid
, ETH_ALEN
);
1399 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1401 if (flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
)
1402 priv
->encr_tx_key_index
= index
;
1407 static int restore_key(struct usbnet
*usbdev
, int key_idx
)
1409 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1410 struct rndis_wlan_encr_key key
;
1412 if (is_wpa_key(priv
, key_idx
))
1415 key
= priv
->encr_keys
[key_idx
];
1417 netdev_dbg(usbdev
->net
, "%s(): %i:%i\n", __func__
, key_idx
, key
.len
);
1422 return add_wep_key(usbdev
, key
.material
, key
.len
, key_idx
);
1425 static void restore_keys(struct usbnet
*usbdev
)
1429 for (i
= 0; i
< 4; i
++)
1430 restore_key(usbdev
, i
);
1433 static void clear_key(struct rndis_wlan_private
*priv
, int idx
)
1435 memset(&priv
->encr_keys
[idx
], 0, sizeof(priv
->encr_keys
[idx
]));
1438 /* remove_key is for both wep and wpa */
1439 static int remove_key(struct usbnet
*usbdev
, int index
, const u8
*bssid
)
1441 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1442 struct ndis_80211_remove_key remove_key
;
1447 if (priv
->encr_keys
[index
].len
== 0)
1450 is_wpa
= is_wpa_key(priv
, index
);
1452 netdev_dbg(usbdev
->net
, "%s(): %i:%s:%i\n",
1453 __func__
, index
, is_wpa
? "wpa" : "wep",
1454 priv
->encr_keys
[index
].len
);
1456 clear_key(priv
, index
);
1459 remove_key
.size
= cpu_to_le32(sizeof(remove_key
));
1460 remove_key
.index
= cpu_to_le32(index
);
1463 if (!is_broadcast_ether_addr(bssid
))
1465 NDIS_80211_ADDKEY_PAIRWISE_KEY
;
1466 memcpy(remove_key
.bssid
, bssid
,
1467 sizeof(remove_key
.bssid
));
1469 memset(remove_key
.bssid
, 0xff,
1470 sizeof(remove_key
.bssid
));
1472 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_KEY
, &remove_key
,
1473 sizeof(remove_key
));
1477 keyindex
= cpu_to_le32(index
);
1478 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_WEP
, &keyindex
,
1481 netdev_warn(usbdev
->net
,
1482 "removing encryption key %d failed (%08X)\n",
1488 /* if it is transmit key, disable encryption */
1489 if (index
== priv
->encr_tx_key_index
)
1490 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1495 static void set_multicast_list(struct usbnet
*usbdev
)
1497 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1498 struct dev_mc_list
*mclist
;
1503 filter
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
1505 netif_addr_lock_bh(usbdev
->net
);
1506 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1507 filter
|= RNDIS_PACKET_TYPE_PROMISCUOUS
|
1508 RNDIS_PACKET_TYPE_ALL_LOCAL
;
1509 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
||
1510 netdev_mc_count(usbdev
->net
) > priv
->multicast_size
) {
1511 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1512 } else if (!netdev_mc_empty(usbdev
->net
)) {
1513 size
= min(priv
->multicast_size
, netdev_mc_count(usbdev
->net
));
1514 buf
= kmalloc(size
* ETH_ALEN
, GFP_KERNEL
);
1516 netdev_warn(usbdev
->net
,
1517 "couldn't alloc %d bytes of memory\n",
1519 netif_addr_unlock_bh(usbdev
->net
);
1524 netdev_for_each_mc_addr(mclist
, usbdev
->net
) {
1527 memcpy(buf
+ i
++ * ETH_ALEN
, mclist
->dmi_addr
, ETH_ALEN
);
1530 ret
= rndis_set_oid(usbdev
, OID_802_3_MULTICAST_LIST
, buf
,
1532 if (ret
== 0 && i
> 0)
1533 filter
|= RNDIS_PACKET_TYPE_MULTICAST
;
1535 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1537 netdev_dbg(usbdev
->net
, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1538 i
, priv
->multicast_size
, ret
);
1542 netif_addr_unlock_bh(usbdev
->net
);
1544 ret
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1547 netdev_warn(usbdev
->net
, "couldn't set packet filter: %08x\n",
1548 le32_to_cpu(filter
));
1551 netdev_dbg(usbdev
->net
, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1552 le32_to_cpu(filter
), ret
);
1558 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
1559 struct net_device
*dev
,
1560 enum nl80211_iftype type
, u32
*flags
,
1561 struct vif_params
*params
)
1563 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1564 struct usbnet
*usbdev
= priv
->usbdev
;
1568 case NL80211_IFTYPE_ADHOC
:
1569 mode
= NDIS_80211_INFRA_ADHOC
;
1571 case NL80211_IFTYPE_STATION
:
1572 mode
= NDIS_80211_INFRA_INFRA
;
1578 priv
->wdev
.iftype
= type
;
1580 return set_infra_mode(usbdev
, mode
);
1583 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1585 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1586 struct usbnet
*usbdev
= priv
->usbdev
;
1589 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
1590 err
= set_frag_threshold(usbdev
, wiphy
->frag_threshold
);
1595 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
1596 err
= set_rts_threshold(usbdev
, wiphy
->rts_threshold
);
1604 static int rndis_set_tx_power(struct wiphy
*wiphy
, enum tx_power_setting type
,
1607 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1608 struct usbnet
*usbdev
= priv
->usbdev
;
1610 netdev_dbg(usbdev
->net
, "%s(): type:0x%x dbm:%i\n",
1611 __func__
, type
, dbm
);
1613 /* Device doesn't support changing txpower after initialization, only
1614 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1617 if (type
== TX_POWER_AUTOMATIC
|| dbm
== get_bcm4320_power_dbm(priv
)) {
1618 if (!priv
->radio_on
)
1619 disassociate(usbdev
, true); /* turn on radio */
1627 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
)
1629 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1630 struct usbnet
*usbdev
= priv
->usbdev
;
1632 *dbm
= get_bcm4320_power_dbm(priv
);
1634 netdev_dbg(usbdev
->net
, "%s(): dbm:%i\n", __func__
, *dbm
);
1639 #define SCAN_DELAY_JIFFIES (6 * HZ)
1640 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
1641 struct cfg80211_scan_request
*request
)
1643 struct usbnet
*usbdev
= netdev_priv(dev
);
1644 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1648 netdev_dbg(usbdev
->net
, "cfg80211.scan\n");
1650 /* Get current bssid list from device before new scan, as new scan
1651 * clears internal bssid list.
1653 rndis_check_bssid_list(usbdev
);
1658 if (priv
->scan_request
&& priv
->scan_request
!= request
)
1661 priv
->scan_request
= request
;
1663 tmp
= cpu_to_le32(1);
1664 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
1667 /* Wait before retrieving scan results from device */
1668 queue_delayed_work(priv
->workqueue
, &priv
->scan_work
,
1669 SCAN_DELAY_JIFFIES
);
1675 static struct cfg80211_bss
*rndis_bss_info_update(struct usbnet
*usbdev
,
1676 struct ndis_80211_bssid_ex
*bssid
)
1678 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1679 struct ieee80211_channel
*channel
;
1683 u16 beacon_interval
;
1684 struct ndis_80211_fixed_ies
*fixed
;
1685 int ie_len
, bssid_len
;
1688 netdev_dbg(usbdev
->net
, " found bssid: '%.32s' [%pM]\n",
1689 bssid
->ssid
.essid
, bssid
->mac
);
1691 /* parse bssid structure */
1692 bssid_len
= le32_to_cpu(bssid
->length
);
1694 if (bssid_len
< sizeof(struct ndis_80211_bssid_ex
) +
1695 sizeof(struct ndis_80211_fixed_ies
))
1698 fixed
= (struct ndis_80211_fixed_ies
*)bssid
->ies
;
1700 ie
= (void *)(bssid
->ies
+ sizeof(struct ndis_80211_fixed_ies
));
1701 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1702 (int)le32_to_cpu(bssid
->ie_length
));
1703 ie_len
-= sizeof(struct ndis_80211_fixed_ies
);
1707 /* extract data for cfg80211_inform_bss */
1708 channel
= ieee80211_get_channel(priv
->wdev
.wiphy
,
1709 KHZ_TO_MHZ(le32_to_cpu(bssid
->config
.ds_config
)));
1713 signal
= level_to_qual(le32_to_cpu(bssid
->rssi
));
1714 timestamp
= le64_to_cpu(*(__le64
*)fixed
->timestamp
);
1715 capability
= le16_to_cpu(fixed
->capabilities
);
1716 beacon_interval
= le16_to_cpu(fixed
->beacon_interval
);
1718 return cfg80211_inform_bss(priv
->wdev
.wiphy
, channel
, bssid
->mac
,
1719 timestamp
, capability
, beacon_interval
, ie
, ie_len
, signal
,
1723 static int rndis_check_bssid_list(struct usbnet
*usbdev
)
1726 struct ndis_80211_bssid_list_ex
*bssid_list
;
1727 struct ndis_80211_bssid_ex
*bssid
;
1728 int ret
= -EINVAL
, len
, count
, bssid_len
;
1729 bool resized
= false;
1731 netdev_dbg(usbdev
->net
, "check_bssid_list\n");
1733 len
= CONTROL_BUFFER_SIZE
;
1735 buf
= kmalloc(len
, GFP_KERNEL
);
1741 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
1745 if (!resized
&& len
> CONTROL_BUFFER_SIZE
) {
1752 bssid
= bssid_list
->bssid
;
1753 bssid_len
= le32_to_cpu(bssid
->length
);
1754 count
= le32_to_cpu(bssid_list
->num_items
);
1755 netdev_dbg(usbdev
->net
, "check_bssid_list: %d BSSIDs found (buflen: %d)\n",
1758 while (count
&& ((void *)bssid
+ bssid_len
) <= (buf
+ len
)) {
1759 rndis_bss_info_update(usbdev
, bssid
);
1761 bssid
= (void *)bssid
+ bssid_len
;
1762 bssid_len
= le32_to_cpu(bssid
->length
);
1771 static void rndis_get_scan_results(struct work_struct
*work
)
1773 struct rndis_wlan_private
*priv
=
1774 container_of(work
, struct rndis_wlan_private
, scan_work
.work
);
1775 struct usbnet
*usbdev
= priv
->usbdev
;
1778 netdev_dbg(usbdev
->net
, "get_scan_results\n");
1780 if (!priv
->scan_request
)
1783 ret
= rndis_check_bssid_list(usbdev
);
1785 cfg80211_scan_done(priv
->scan_request
, ret
< 0);
1787 priv
->scan_request
= NULL
;
1790 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
1791 struct cfg80211_connect_params
*sme
)
1793 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1794 struct usbnet
*usbdev
= priv
->usbdev
;
1795 struct ieee80211_channel
*channel
= sme
->channel
;
1796 struct ndis_80211_ssid ssid
;
1797 int pairwise
= RNDIS_WLAN_ALG_NONE
;
1798 int groupwise
= RNDIS_WLAN_ALG_NONE
;
1799 int keymgmt
= RNDIS_WLAN_KEY_MGMT_NONE
;
1800 int length
, i
, ret
, chan
= -1;
1803 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1805 groupwise
= rndis_cipher_to_alg(sme
->crypto
.cipher_group
);
1806 for (i
= 0; i
< sme
->crypto
.n_ciphers_pairwise
; i
++)
1808 rndis_cipher_to_alg(sme
->crypto
.ciphers_pairwise
[i
]);
1810 if (sme
->crypto
.n_ciphers_pairwise
> 0 &&
1811 pairwise
== RNDIS_WLAN_ALG_NONE
) {
1812 netdev_err(usbdev
->net
, "Unsupported pairwise cipher\n");
1816 for (i
= 0; i
< sme
->crypto
.n_akm_suites
; i
++)
1818 rndis_akm_suite_to_key_mgmt(sme
->crypto
.akm_suites
[i
]);
1820 if (sme
->crypto
.n_akm_suites
> 0 &&
1821 keymgmt
== RNDIS_WLAN_KEY_MGMT_NONE
) {
1822 netdev_err(usbdev
->net
, "Invalid keymgmt\n");
1826 netdev_dbg(usbdev
->net
, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
1827 sme
->ssid
, sme
->bssid
, chan
,
1828 sme
->privacy
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
1829 groupwise
, pairwise
, keymgmt
);
1831 if (is_associated(usbdev
))
1832 disassociate(usbdev
, false);
1834 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1836 netdev_dbg(usbdev
->net
, "connect: set_infra_mode failed, %d\n",
1838 goto err_turn_radio_on
;
1841 ret
= set_auth_mode(usbdev
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
1844 netdev_dbg(usbdev
->net
, "connect: set_auth_mode failed, %d\n",
1846 goto err_turn_radio_on
;
1849 set_priv_filter(usbdev
);
1851 ret
= set_encr_mode(usbdev
, pairwise
, groupwise
);
1853 netdev_dbg(usbdev
->net
, "connect: set_encr_mode failed, %d\n",
1855 goto err_turn_radio_on
;
1859 ret
= set_channel(usbdev
, chan
);
1861 netdev_dbg(usbdev
->net
, "connect: set_channel failed, %d\n",
1863 goto err_turn_radio_on
;
1867 if (sme
->key
&& ((groupwise
| pairwise
) & RNDIS_WLAN_ALG_WEP
)) {
1868 priv
->encr_tx_key_index
= sme
->key_idx
;
1869 ret
= add_wep_key(usbdev
, sme
->key
, sme
->key_len
, sme
->key_idx
);
1871 netdev_dbg(usbdev
->net
, "connect: add_wep_key failed, %d (%d, %d)\n",
1872 ret
, sme
->key_len
, sme
->key_idx
);
1873 goto err_turn_radio_on
;
1877 if (sme
->bssid
&& !is_zero_ether_addr(sme
->bssid
) &&
1878 !is_broadcast_ether_addr(sme
->bssid
)) {
1879 ret
= set_bssid(usbdev
, sme
->bssid
);
1881 netdev_dbg(usbdev
->net
, "connect: set_bssid failed, %d\n",
1883 goto err_turn_radio_on
;
1886 clear_bssid(usbdev
);
1888 length
= sme
->ssid_len
;
1889 if (length
> NDIS_802_11_LENGTH_SSID
)
1890 length
= NDIS_802_11_LENGTH_SSID
;
1892 memset(&ssid
, 0, sizeof(ssid
));
1893 ssid
.length
= cpu_to_le32(length
);
1894 memcpy(ssid
.essid
, sme
->ssid
, length
);
1896 /* Pause and purge rx queue, so we don't pass packets before
1897 * 'media connect'-indication.
1899 usbnet_pause_rx(usbdev
);
1900 usbnet_purge_paused_rxq(usbdev
);
1902 ret
= set_essid(usbdev
, &ssid
);
1904 netdev_dbg(usbdev
->net
, "connect: set_essid failed, %d\n", ret
);
1908 disassociate(usbdev
, true);
1913 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1916 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1917 struct usbnet
*usbdev
= priv
->usbdev
;
1919 netdev_dbg(usbdev
->net
, "cfg80211.disconnect(%d)\n", reason_code
);
1921 priv
->connected
= false;
1922 memset(priv
->bssid
, 0, ETH_ALEN
);
1924 return deauthenticate(usbdev
);
1927 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1928 struct cfg80211_ibss_params
*params
)
1930 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1931 struct usbnet
*usbdev
= priv
->usbdev
;
1932 struct ieee80211_channel
*channel
= params
->channel
;
1933 struct ndis_80211_ssid ssid
;
1934 enum nl80211_auth_type auth_type
;
1935 int ret
, alg
, length
, chan
= -1;
1938 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1940 /* TODO: How to handle ad-hoc encryption?
1941 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
1942 * pre-shared for encryption (open/shared/wpa), is key set before
1943 * join_ibss? Which auth_type to use (not in params)? What about WPA?
1945 if (params
->privacy
) {
1946 auth_type
= NL80211_AUTHTYPE_SHARED_KEY
;
1947 alg
= RNDIS_WLAN_ALG_WEP
;
1949 auth_type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
1950 alg
= RNDIS_WLAN_ALG_NONE
;
1953 netdev_dbg(usbdev
->net
, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
1954 params
->ssid
, params
->bssid
, chan
, params
->privacy
);
1956 if (is_associated(usbdev
))
1957 disassociate(usbdev
, false);
1959 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_ADHOC
);
1961 netdev_dbg(usbdev
->net
, "join_ibss: set_infra_mode failed, %d\n",
1963 goto err_turn_radio_on
;
1966 ret
= set_auth_mode(usbdev
, 0, auth_type
, RNDIS_WLAN_KEY_MGMT_NONE
);
1968 netdev_dbg(usbdev
->net
, "join_ibss: set_auth_mode failed, %d\n",
1970 goto err_turn_radio_on
;
1973 set_priv_filter(usbdev
);
1975 ret
= set_encr_mode(usbdev
, alg
, RNDIS_WLAN_ALG_NONE
);
1977 netdev_dbg(usbdev
->net
, "join_ibss: set_encr_mode failed, %d\n",
1979 goto err_turn_radio_on
;
1983 ret
= set_channel(usbdev
, chan
);
1985 netdev_dbg(usbdev
->net
, "join_ibss: set_channel failed, %d\n",
1987 goto err_turn_radio_on
;
1991 if (params
->bssid
&& !is_zero_ether_addr(params
->bssid
) &&
1992 !is_broadcast_ether_addr(params
->bssid
)) {
1993 ret
= set_bssid(usbdev
, params
->bssid
);
1995 netdev_dbg(usbdev
->net
, "join_ibss: set_bssid failed, %d\n",
1997 goto err_turn_radio_on
;
2000 clear_bssid(usbdev
);
2002 length
= params
->ssid_len
;
2003 if (length
> NDIS_802_11_LENGTH_SSID
)
2004 length
= NDIS_802_11_LENGTH_SSID
;
2006 memset(&ssid
, 0, sizeof(ssid
));
2007 ssid
.length
= cpu_to_le32(length
);
2008 memcpy(ssid
.essid
, params
->ssid
, length
);
2010 /* Don't need to pause rx queue for ad-hoc. */
2011 usbnet_purge_paused_rxq(usbdev
);
2012 usbnet_resume_rx(usbdev
);
2014 ret
= set_essid(usbdev
, &ssid
);
2016 netdev_dbg(usbdev
->net
, "join_ibss: set_essid failed, %d\n",
2021 disassociate(usbdev
, true);
2026 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2028 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2029 struct usbnet
*usbdev
= priv
->usbdev
;
2031 netdev_dbg(usbdev
->net
, "cfg80211.leave_ibss()\n");
2033 priv
->connected
= false;
2034 memset(priv
->bssid
, 0, ETH_ALEN
);
2036 return deauthenticate(usbdev
);
2039 static int rndis_set_channel(struct wiphy
*wiphy
,
2040 struct ieee80211_channel
*chan
, enum nl80211_channel_type channel_type
)
2042 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2043 struct usbnet
*usbdev
= priv
->usbdev
;
2045 return set_channel(usbdev
,
2046 ieee80211_frequency_to_channel(chan
->center_freq
));
2049 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2050 u8 key_index
, const u8
*mac_addr
,
2051 struct key_params
*params
)
2053 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2054 struct usbnet
*usbdev
= priv
->usbdev
;
2057 netdev_dbg(usbdev
->net
, "%s(%i, %pM, %08x)\n",
2058 __func__
, key_index
, mac_addr
, params
->cipher
);
2060 switch (params
->cipher
) {
2061 case WLAN_CIPHER_SUITE_WEP40
:
2062 case WLAN_CIPHER_SUITE_WEP104
:
2063 return add_wep_key(usbdev
, params
->key
, params
->key_len
,
2065 case WLAN_CIPHER_SUITE_TKIP
:
2066 case WLAN_CIPHER_SUITE_CCMP
:
2069 if (params
->seq
&& params
->seq_len
> 0)
2070 flags
|= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
;
2072 flags
|= NDIS_80211_ADDKEY_PAIRWISE_KEY
|
2073 NDIS_80211_ADDKEY_TRANSMIT_KEY
;
2075 return add_wpa_key(usbdev
, params
->key
, params
->key_len
,
2076 key_index
, mac_addr
, params
->seq
,
2077 params
->seq_len
, params
->cipher
, flags
);
2079 netdev_dbg(usbdev
->net
, "%s(): unsupported cipher %08x\n",
2080 __func__
, params
->cipher
);
2085 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2086 u8 key_index
, const u8
*mac_addr
)
2088 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2089 struct usbnet
*usbdev
= priv
->usbdev
;
2091 netdev_dbg(usbdev
->net
, "%s(%i, %pM)\n", __func__
, key_index
, mac_addr
);
2093 return remove_key(usbdev
, key_index
, mac_addr
);
2096 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2099 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2100 struct usbnet
*usbdev
= priv
->usbdev
;
2101 struct rndis_wlan_encr_key key
;
2103 netdev_dbg(usbdev
->net
, "%s(%i)\n", __func__
, key_index
);
2105 priv
->encr_tx_key_index
= key_index
;
2107 key
= priv
->encr_keys
[key_index
];
2109 return add_wep_key(usbdev
, key
.material
, key
.len
, key_index
);
2112 static void rndis_fill_station_info(struct usbnet
*usbdev
,
2113 struct station_info
*sinfo
)
2115 __le32 linkspeed
, rssi
;
2118 memset(sinfo
, 0, sizeof(*sinfo
));
2120 len
= sizeof(linkspeed
);
2121 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &linkspeed
, &len
);
2123 sinfo
->txrate
.legacy
= le32_to_cpu(linkspeed
) / 1000;
2124 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
2128 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2130 sinfo
->signal
= level_to_qual(le32_to_cpu(rssi
));
2131 sinfo
->filled
|= STATION_INFO_SIGNAL
;
2135 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2136 u8
*mac
, struct station_info
*sinfo
)
2138 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2139 struct usbnet
*usbdev
= priv
->usbdev
;
2141 if (compare_ether_addr(priv
->bssid
, mac
))
2144 rndis_fill_station_info(usbdev
, sinfo
);
2149 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2150 int idx
, u8
*mac
, struct station_info
*sinfo
)
2152 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2153 struct usbnet
*usbdev
= priv
->usbdev
;
2158 memcpy(mac
, priv
->bssid
, ETH_ALEN
);
2160 rndis_fill_station_info(usbdev
, sinfo
);
2166 * workers, indication handlers, device poller
2168 static void rndis_wlan_do_link_up_work(struct usbnet
*usbdev
)
2170 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2171 struct ndis_80211_assoc_info
*info
;
2172 u8 assoc_buf
[sizeof(*info
) + IW_CUSTOM_MAX
+ 32];
2174 int resp_ie_len
, req_ie_len
;
2175 u8
*req_ie
, *resp_ie
;
2177 bool roamed
= false;
2179 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
&& priv
->connected
) {
2180 /* received media connect indication while connected, either
2181 * device reassociated with same AP or roamed to new. */
2190 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2191 memset(assoc_buf
, 0, sizeof(assoc_buf
));
2192 info
= (void *)assoc_buf
;
2194 /* Get association info IEs from device and send them back to
2196 ret
= get_association_info(usbdev
, info
, sizeof(assoc_buf
));
2198 req_ie_len
= le32_to_cpu(info
->req_ie_length
);
2199 if (req_ie_len
> 0) {
2200 offset
= le32_to_cpu(info
->offset_req_ies
);
2201 req_ie
= (u8
*)info
+ offset
;
2204 resp_ie_len
= le32_to_cpu(info
->resp_ie_length
);
2205 if (resp_ie_len
> 0) {
2206 offset
= le32_to_cpu(info
->offset_resp_ies
);
2207 resp_ie
= (u8
*)info
+ offset
;
2210 } else if (WARN_ON(priv
->infra_mode
!= NDIS_80211_INFRA_ADHOC
))
2213 ret
= get_bssid(usbdev
, bssid
);
2215 memset(bssid
, 0, sizeof(bssid
));
2217 netdev_dbg(usbdev
->net
, "link up work: [%pM]%s\n",
2218 bssid
, roamed
? " roamed" : "");
2220 /* Internal bss list in device always contains at least the currently
2221 * connected bss and we can get it to cfg80211 with
2222 * rndis_check_bssid_list().
2223 * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
2226 rndis_check_bssid_list(usbdev
);
2228 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2230 cfg80211_connect_result(usbdev
->net
, bssid
, req_ie
,
2231 req_ie_len
, resp_ie
,
2232 resp_ie_len
, 0, GFP_KERNEL
);
2234 cfg80211_roamed(usbdev
->net
, bssid
, req_ie
, req_ie_len
,
2235 resp_ie
, resp_ie_len
, GFP_KERNEL
);
2236 } else if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
2237 cfg80211_ibss_joined(usbdev
->net
, bssid
, GFP_KERNEL
);
2239 priv
->connected
= true;
2240 memcpy(priv
->bssid
, bssid
, ETH_ALEN
);
2242 usbnet_resume_rx(usbdev
);
2243 netif_carrier_on(usbdev
->net
);
2246 static void rndis_wlan_do_link_down_work(struct usbnet
*usbdev
)
2248 union iwreq_data evt
;
2250 netif_carrier_off(usbdev
->net
);
2253 evt
.data
.length
= 0;
2254 memset(evt
.ap_addr
.sa_data
, 0, ETH_ALEN
);
2255 wireless_send_event(usbdev
->net
, SIOCGIWAP
, &evt
, NULL
);
2258 static void rndis_wlan_worker(struct work_struct
*work
)
2260 struct rndis_wlan_private
*priv
=
2261 container_of(work
, struct rndis_wlan_private
, work
);
2262 struct usbnet
*usbdev
= priv
->usbdev
;
2264 if (test_and_clear_bit(WORK_LINK_UP
, &priv
->work_pending
))
2265 rndis_wlan_do_link_up_work(usbdev
);
2267 if (test_and_clear_bit(WORK_LINK_DOWN
, &priv
->work_pending
))
2268 rndis_wlan_do_link_down_work(usbdev
);
2270 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2271 set_multicast_list(usbdev
);
2274 static void rndis_wlan_set_multicast_list(struct net_device
*dev
)
2276 struct usbnet
*usbdev
= netdev_priv(dev
);
2277 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2279 if (test_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2282 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2283 queue_work(priv
->workqueue
, &priv
->work
);
2286 static void rndis_wlan_auth_indication(struct usbnet
*usbdev
,
2287 struct ndis_80211_status_indication
*indication
,
2292 int flags
, buflen
, key_id
;
2293 bool pairwise_error
, group_error
;
2294 struct ndis_80211_auth_request
*auth_req
;
2295 enum nl80211_key_type key_type
;
2297 /* must have at least one array entry */
2298 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2299 sizeof(struct ndis_80211_auth_request
)) {
2300 netdev_info(usbdev
->net
, "authentication indication: too short message (%i)\n",
2305 buf
= (void *)&indication
->u
.auth_request
[0];
2306 buflen
= len
- offsetof(struct ndis_80211_status_indication
, u
);
2308 while (buflen
>= sizeof(*auth_req
)) {
2309 auth_req
= (void *)buf
;
2311 flags
= le32_to_cpu(auth_req
->flags
);
2312 pairwise_error
= false;
2313 group_error
= false;
2316 type
= "reauth request";
2318 type
= "key update request";
2320 pairwise_error
= true;
2321 type
= "pairwise_error";
2325 type
= "group_error";
2328 netdev_info(usbdev
->net
, "authentication indication: %s (0x%08x)\n",
2329 type
, le32_to_cpu(auth_req
->flags
));
2331 if (pairwise_error
) {
2332 key_type
= NL80211_KEYTYPE_PAIRWISE
;
2335 cfg80211_michael_mic_failure(usbdev
->net
,
2337 key_type
, key_id
, NULL
,
2342 key_type
= NL80211_KEYTYPE_GROUP
;
2345 cfg80211_michael_mic_failure(usbdev
->net
,
2347 key_type
, key_id
, NULL
,
2351 buflen
-= le32_to_cpu(auth_req
->length
);
2352 buf
+= le32_to_cpu(auth_req
->length
);
2356 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet
*usbdev
,
2357 struct ndis_80211_status_indication
*indication
,
2360 struct ndis_80211_pmkid_cand_list
*cand_list
;
2361 int list_len
, expected_len
, i
;
2363 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2364 sizeof(struct ndis_80211_pmkid_cand_list
)) {
2365 netdev_info(usbdev
->net
, "pmkid candidate list indication: too short message (%i)\n",
2370 list_len
= le32_to_cpu(indication
->u
.cand_list
.num_candidates
) *
2371 sizeof(struct ndis_80211_pmkid_candidate
);
2372 expected_len
= sizeof(struct ndis_80211_pmkid_cand_list
) + list_len
+
2373 offsetof(struct ndis_80211_status_indication
, u
);
2375 if (len
< expected_len
) {
2376 netdev_info(usbdev
->net
, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
2381 cand_list
= &indication
->u
.cand_list
;
2383 netdev_info(usbdev
->net
, "pmkid candidate list indication: version %i, candidates %i\n",
2384 le32_to_cpu(cand_list
->version
),
2385 le32_to_cpu(cand_list
->num_candidates
));
2387 if (le32_to_cpu(cand_list
->version
) != 1)
2390 for (i
= 0; i
< le32_to_cpu(cand_list
->num_candidates
); i
++) {
2391 struct ndis_80211_pmkid_candidate
*cand
=
2392 &cand_list
->candidate_list
[i
];
2394 netdev_dbg(usbdev
->net
, "cand[%i]: flags: 0x%08x, bssid: %pM\n",
2395 i
, le32_to_cpu(cand
->flags
), cand
->bssid
);
2398 struct iw_pmkid_cand pcand
;
2399 union iwreq_data wrqu
;
2401 memset(&pcand
, 0, sizeof(pcand
));
2402 if (le32_to_cpu(cand
->flags
) & 0x01)
2403 pcand
.flags
|= IW_PMKID_CAND_PREAUTH
;
2405 memcpy(pcand
.bssid
.sa_data
, cand
->bssid
, ETH_ALEN
);
2407 memset(&wrqu
, 0, sizeof(wrqu
));
2408 wrqu
.data
.length
= sizeof(pcand
);
2409 wireless_send_event(usbdev
->net
, IWEVPMKIDCAND
, &wrqu
,
2415 static void rndis_wlan_media_specific_indication(struct usbnet
*usbdev
,
2416 struct rndis_indicate
*msg
, int buflen
)
2418 struct ndis_80211_status_indication
*indication
;
2421 offset
= offsetof(struct rndis_indicate
, status
) +
2422 le32_to_cpu(msg
->offset
);
2423 len
= le32_to_cpu(msg
->length
);
2426 netdev_info(usbdev
->net
, "media specific indication, ignore too short message (%i < 8)\n",
2431 if (offset
+ len
> buflen
) {
2432 netdev_info(usbdev
->net
, "media specific indication, too large to fit to buffer (%i > %i)\n",
2433 offset
+ len
, buflen
);
2437 indication
= (void *)((u8
*)msg
+ offset
);
2439 switch (le32_to_cpu(indication
->status_type
)) {
2440 case NDIS_80211_STATUSTYPE_RADIOSTATE
:
2441 netdev_info(usbdev
->net
, "radio state indication: %i\n",
2442 le32_to_cpu(indication
->u
.radio_status
));
2445 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
:
2446 netdev_info(usbdev
->net
, "media stream mode indication: %i\n",
2447 le32_to_cpu(indication
->u
.media_stream_mode
));
2450 case NDIS_80211_STATUSTYPE_AUTHENTICATION
:
2451 rndis_wlan_auth_indication(usbdev
, indication
, len
);
2454 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
:
2455 rndis_wlan_pmkid_cand_list_indication(usbdev
, indication
, len
);
2459 netdev_info(usbdev
->net
, "media specific indication: unknown status type 0x%08x\n",
2460 le32_to_cpu(indication
->status_type
));
2464 static void rndis_wlan_indication(struct usbnet
*usbdev
, void *ind
, int buflen
)
2466 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2467 struct rndis_indicate
*msg
= ind
;
2469 switch (msg
->status
) {
2470 case RNDIS_STATUS_MEDIA_CONNECT
:
2471 if (priv
->current_command_oid
== OID_802_11_ADD_KEY
) {
2472 /* OID_802_11_ADD_KEY causes sometimes extra
2473 * "media connect" indications which confuses driver
2474 * and userspace to think that device is
2475 * roaming/reassociating when it isn't.
2477 netdev_dbg(usbdev
->net
, "ignored OID_802_11_ADD_KEY triggered 'media connect'\n");
2481 usbnet_pause_rx(usbdev
);
2483 netdev_info(usbdev
->net
, "media connect\n");
2485 /* queue work to avoid recursive calls into rndis_command */
2486 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
2487 queue_work(priv
->workqueue
, &priv
->work
);
2490 case RNDIS_STATUS_MEDIA_DISCONNECT
:
2491 netdev_info(usbdev
->net
, "media disconnect\n");
2493 /* queue work to avoid recursive calls into rndis_command */
2494 set_bit(WORK_LINK_DOWN
, &priv
->work_pending
);
2495 queue_work(priv
->workqueue
, &priv
->work
);
2498 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION
:
2499 rndis_wlan_media_specific_indication(usbdev
, msg
, buflen
);
2503 netdev_info(usbdev
->net
, "indication: 0x%08x\n",
2504 le32_to_cpu(msg
->status
));
2509 static int rndis_wlan_get_caps(struct usbnet
*usbdev
)
2514 } networks_supported
;
2515 int len
, retval
, i
, n
;
2516 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2518 /* determine supported modes */
2519 len
= sizeof(networks_supported
);
2520 retval
= rndis_query_oid(usbdev
, OID_802_11_NETWORK_TYPES_SUPPORTED
,
2521 &networks_supported
, &len
);
2523 n
= le32_to_cpu(networks_supported
.num_items
);
2526 for (i
= 0; i
< n
; i
++) {
2527 switch (le32_to_cpu(networks_supported
.items
[i
])) {
2528 case NDIS_80211_TYPE_FREQ_HOP
:
2529 case NDIS_80211_TYPE_DIRECT_SEQ
:
2530 priv
->caps
|= CAP_MODE_80211B
;
2532 case NDIS_80211_TYPE_OFDM_A
:
2533 priv
->caps
|= CAP_MODE_80211A
;
2535 case NDIS_80211_TYPE_OFDM_G
:
2536 priv
->caps
|= CAP_MODE_80211G
;
2545 #define DEVICE_POLLER_JIFFIES (HZ)
2546 static void rndis_device_poller(struct work_struct
*work
)
2548 struct rndis_wlan_private
*priv
=
2549 container_of(work
, struct rndis_wlan_private
,
2550 dev_poller_work
.work
);
2551 struct usbnet
*usbdev
= priv
->usbdev
;
2554 int update_jiffies
= DEVICE_POLLER_JIFFIES
;
2557 /* Only check/do workaround when connected. Calling is_associated()
2558 * also polls device with rndis_command() and catches for media link
2561 if (!is_associated(usbdev
))
2565 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2567 priv
->last_qual
= level_to_qual(le32_to_cpu(rssi
));
2569 netdev_dbg(usbdev
->net
, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
2570 ret
, le32_to_cpu(rssi
), level_to_qual(le32_to_cpu(rssi
)));
2572 /* Workaround transfer stalls on poor quality links.
2573 * TODO: find right way to fix these stalls (as stalls do not happen
2574 * with ndiswrapper/windows driver). */
2575 if (priv
->param_workaround_interval
> 0 && priv
->last_qual
<= 25) {
2576 /* Decrease stats worker interval to catch stalls.
2577 * faster. Faster than 400-500ms causes packet loss,
2578 * Slower doesn't catch stalls fast enough.
2580 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
2581 if (j
> DEVICE_POLLER_JIFFIES
)
2582 j
= DEVICE_POLLER_JIFFIES
;
2587 /* Send scan OID. Use of both OIDs is required to get device
2590 tmp
= cpu_to_le32(1);
2591 rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
2594 len
= CONTROL_BUFFER_SIZE
;
2595 buf
= kmalloc(len
, GFP_KERNEL
);
2599 rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2604 if (update_jiffies
>= HZ
)
2605 update_jiffies
= round_jiffies_relative(update_jiffies
);
2607 j
= round_jiffies_relative(update_jiffies
);
2608 if (abs(j
- update_jiffies
) <= 10)
2612 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
2617 * driver/device initialization
2619 static void rndis_copy_module_params(struct usbnet
*usbdev
)
2621 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2623 priv
->param_country
[0] = modparam_country
[0];
2624 priv
->param_country
[1] = modparam_country
[1];
2625 priv
->param_country
[2] = 0;
2626 priv
->param_frameburst
= modparam_frameburst
;
2627 priv
->param_afterburner
= modparam_afterburner
;
2628 priv
->param_power_save
= modparam_power_save
;
2629 priv
->param_power_output
= modparam_power_output
;
2630 priv
->param_roamtrigger
= modparam_roamtrigger
;
2631 priv
->param_roamdelta
= modparam_roamdelta
;
2633 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
2634 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
2635 /* doesn't support EU as country code, use FI instead */
2636 if (!strcmp(priv
->param_country
, "EU"))
2637 strcpy(priv
->param_country
, "FI");
2639 if (priv
->param_power_save
< 0)
2640 priv
->param_power_save
= 0;
2641 else if (priv
->param_power_save
> 2)
2642 priv
->param_power_save
= 2;
2644 if (priv
->param_power_output
< 0)
2645 priv
->param_power_output
= 0;
2646 else if (priv
->param_power_output
> 3)
2647 priv
->param_power_output
= 3;
2649 if (priv
->param_roamtrigger
< -80)
2650 priv
->param_roamtrigger
= -80;
2651 else if (priv
->param_roamtrigger
> -60)
2652 priv
->param_roamtrigger
= -60;
2654 if (priv
->param_roamdelta
< 0)
2655 priv
->param_roamdelta
= 0;
2656 else if (priv
->param_roamdelta
> 2)
2657 priv
->param_roamdelta
= 2;
2659 if (modparam_workaround_interval
< 0)
2660 priv
->param_workaround_interval
= 500;
2662 priv
->param_workaround_interval
= modparam_workaround_interval
;
2665 static int bcm4320a_early_init(struct usbnet
*usbdev
)
2667 /* copy module parameters for bcm4320a so that iwconfig reports txpower
2668 * and workaround parameter is copied to private structure correctly.
2670 rndis_copy_module_params(usbdev
);
2672 /* bcm4320a doesn't handle configuration parameters well. Try
2673 * set any and you get partially zeroed mac and broken device.
2679 static int bcm4320b_early_init(struct usbnet
*usbdev
)
2681 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2684 rndis_copy_module_params(usbdev
);
2686 /* Early initialization settings, setting these won't have effect
2687 * if called after generic_rndis_bind().
2690 rndis_set_config_parameter_str(usbdev
, "Country", priv
->param_country
);
2691 rndis_set_config_parameter_str(usbdev
, "FrameBursting",
2692 priv
->param_frameburst
? "1" : "0");
2693 rndis_set_config_parameter_str(usbdev
, "Afterburner",
2694 priv
->param_afterburner
? "1" : "0");
2695 sprintf(buf
, "%d", priv
->param_power_save
);
2696 rndis_set_config_parameter_str(usbdev
, "PowerSaveMode", buf
);
2697 sprintf(buf
, "%d", priv
->param_power_output
);
2698 rndis_set_config_parameter_str(usbdev
, "PwrOut", buf
);
2699 sprintf(buf
, "%d", priv
->param_roamtrigger
);
2700 rndis_set_config_parameter_str(usbdev
, "RoamTrigger", buf
);
2701 sprintf(buf
, "%d", priv
->param_roamdelta
);
2702 rndis_set_config_parameter_str(usbdev
, "RoamDelta", buf
);
2707 /* same as rndis_netdev_ops but with local multicast handler */
2708 static const struct net_device_ops rndis_wlan_netdev_ops
= {
2709 .ndo_open
= usbnet_open
,
2710 .ndo_stop
= usbnet_stop
,
2711 .ndo_start_xmit
= usbnet_start_xmit
,
2712 .ndo_tx_timeout
= usbnet_tx_timeout
,
2713 .ndo_set_mac_address
= eth_mac_addr
,
2714 .ndo_validate_addr
= eth_validate_addr
,
2715 .ndo_set_multicast_list
= rndis_wlan_set_multicast_list
,
2718 static int rndis_wlan_bind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2720 struct wiphy
*wiphy
;
2721 struct rndis_wlan_private
*priv
;
2725 /* allocate wiphy and rndis private data
2726 * NOTE: We only support a single virtual interface, so wiphy
2727 * and wireless_dev are somewhat synonymous for this device.
2729 wiphy
= wiphy_new(&rndis_config_ops
, sizeof(struct rndis_wlan_private
));
2733 priv
= wiphy_priv(wiphy
);
2734 usbdev
->net
->ieee80211_ptr
= &priv
->wdev
;
2735 priv
->wdev
.wiphy
= wiphy
;
2736 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
2738 /* These have to be initialized before calling generic_rndis_bind().
2739 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
2741 usbdev
->driver_priv
= priv
;
2742 priv
->usbdev
= usbdev
;
2744 mutex_init(&priv
->command_lock
);
2746 /* because rndis_command() sleeps we need to use workqueue */
2747 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
2748 INIT_WORK(&priv
->work
, rndis_wlan_worker
);
2749 INIT_DELAYED_WORK(&priv
->dev_poller_work
, rndis_device_poller
);
2750 INIT_DELAYED_WORK(&priv
->scan_work
, rndis_get_scan_results
);
2752 /* try bind rndis_host */
2753 retval
= generic_rndis_bind(usbdev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
2757 /* generic_rndis_bind set packet filter to multicast_all+
2758 * promisc mode which doesn't work well for our devices (device
2759 * picks up rssi to closest station instead of to access point).
2761 * rndis_host wants to avoid all OID as much as possible
2762 * so do promisc/multicast handling in rndis_wlan.
2764 usbdev
->net
->netdev_ops
= &rndis_wlan_netdev_ops
;
2766 tmp
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
2767 retval
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &tmp
,
2771 retval
= rndis_query_oid(usbdev
, OID_802_3_MAXIMUM_LIST_SIZE
, &tmp
,
2773 priv
->multicast_size
= le32_to_cpu(tmp
);
2774 if (retval
< 0 || priv
->multicast_size
< 0)
2775 priv
->multicast_size
= 0;
2776 if (priv
->multicast_size
> 0)
2777 usbdev
->net
->flags
|= IFF_MULTICAST
;
2779 usbdev
->net
->flags
&= ~IFF_MULTICAST
;
2781 /* fill-out wiphy structure and register w/ cfg80211 */
2782 memcpy(wiphy
->perm_addr
, usbdev
->net
->dev_addr
, ETH_ALEN
);
2783 wiphy
->privid
= rndis_wiphy_privid
;
2784 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
2785 | BIT(NL80211_IFTYPE_ADHOC
);
2786 wiphy
->max_scan_ssids
= 1;
2788 /* TODO: fill-out band/encr information based on priv->caps */
2789 rndis_wlan_get_caps(usbdev
);
2791 memcpy(priv
->channels
, rndis_channels
, sizeof(rndis_channels
));
2792 memcpy(priv
->rates
, rndis_rates
, sizeof(rndis_rates
));
2793 priv
->band
.channels
= priv
->channels
;
2794 priv
->band
.n_channels
= ARRAY_SIZE(rndis_channels
);
2795 priv
->band
.bitrates
= priv
->rates
;
2796 priv
->band
.n_bitrates
= ARRAY_SIZE(rndis_rates
);
2797 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
2798 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_UNSPEC
;
2800 memcpy(priv
->cipher_suites
, rndis_cipher_suites
,
2801 sizeof(rndis_cipher_suites
));
2802 wiphy
->cipher_suites
= priv
->cipher_suites
;
2803 wiphy
->n_cipher_suites
= ARRAY_SIZE(rndis_cipher_suites
);
2805 set_wiphy_dev(wiphy
, &usbdev
->udev
->dev
);
2807 if (wiphy_register(wiphy
)) {
2812 set_default_iw_params(usbdev
);
2814 /* set default rts/frag */
2815 rndis_set_wiphy_params(wiphy
,
2816 WIPHY_PARAM_FRAG_THRESHOLD
| WIPHY_PARAM_RTS_THRESHOLD
);
2819 priv
->radio_on
= true;
2820 disassociate(usbdev
, true);
2821 netif_carrier_off(usbdev
->net
);
2826 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2827 cancel_delayed_work_sync(&priv
->scan_work
);
2828 cancel_work_sync(&priv
->work
);
2829 flush_workqueue(priv
->workqueue
);
2830 destroy_workqueue(priv
->workqueue
);
2836 static void rndis_wlan_unbind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
2838 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2840 /* turn radio off */
2841 disassociate(usbdev
, false);
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
);
2849 if (priv
&& priv
->wpa_ie_len
)
2850 kfree(priv
->wpa_ie
);
2852 rndis_unbind(usbdev
, intf
);
2854 wiphy_unregister(priv
->wdev
.wiphy
);
2855 wiphy_free(priv
->wdev
.wiphy
);
2858 static int rndis_wlan_reset(struct usbnet
*usbdev
)
2860 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2863 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2865 retval
= rndis_reset(usbdev
);
2867 netdev_warn(usbdev
->net
, "rndis_reset failed: %d\n", retval
);
2869 /* rndis_reset cleared multicast list, so restore here.
2870 (set_multicast_list() also turns on current packet filter) */
2871 set_multicast_list(usbdev
);
2873 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
2874 round_jiffies_relative(DEVICE_POLLER_JIFFIES
));
2876 return deauthenticate(usbdev
);
2879 static int rndis_wlan_stop(struct usbnet
*usbdev
)
2881 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2885 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2887 retval
= disassociate(usbdev
, false);
2889 priv
->work_pending
= 0;
2890 cancel_delayed_work_sync(&priv
->dev_poller_work
);
2891 cancel_delayed_work_sync(&priv
->scan_work
);
2892 cancel_work_sync(&priv
->work
);
2893 flush_workqueue(priv
->workqueue
);
2895 if (priv
->scan_request
) {
2896 cfg80211_scan_done(priv
->scan_request
, true);
2897 priv
->scan_request
= NULL
;
2900 /* Set current packet filter zero to block receiving data packets from
2903 rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
2909 static const struct driver_info bcm4320b_info
= {
2910 .description
= "Wireless RNDIS device, BCM4320b based",
2911 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2912 FLAG_AVOID_UNLINK_URBS
,
2913 .bind
= rndis_wlan_bind
,
2914 .unbind
= rndis_wlan_unbind
,
2915 .status
= rndis_status
,
2916 .rx_fixup
= rndis_rx_fixup
,
2917 .tx_fixup
= rndis_tx_fixup
,
2918 .reset
= rndis_wlan_reset
,
2919 .stop
= rndis_wlan_stop
,
2920 .early_init
= bcm4320b_early_init
,
2921 .indication
= rndis_wlan_indication
,
2924 static const struct driver_info bcm4320a_info
= {
2925 .description
= "Wireless RNDIS device, BCM4320a based",
2926 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2927 FLAG_AVOID_UNLINK_URBS
,
2928 .bind
= rndis_wlan_bind
,
2929 .unbind
= rndis_wlan_unbind
,
2930 .status
= rndis_status
,
2931 .rx_fixup
= rndis_rx_fixup
,
2932 .tx_fixup
= rndis_tx_fixup
,
2933 .reset
= rndis_wlan_reset
,
2934 .stop
= rndis_wlan_stop
,
2935 .early_init
= bcm4320a_early_init
,
2936 .indication
= rndis_wlan_indication
,
2939 static const struct driver_info rndis_wlan_info
= {
2940 .description
= "Wireless RNDIS device",
2941 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
2942 FLAG_AVOID_UNLINK_URBS
,
2943 .bind
= rndis_wlan_bind
,
2944 .unbind
= rndis_wlan_unbind
,
2945 .status
= rndis_status
,
2946 .rx_fixup
= rndis_rx_fixup
,
2947 .tx_fixup
= rndis_tx_fixup
,
2948 .reset
= rndis_wlan_reset
,
2949 .stop
= rndis_wlan_stop
,
2950 .early_init
= bcm4320a_early_init
,
2951 .indication
= rndis_wlan_indication
,
2954 /*-------------------------------------------------------------------------*/
2956 static const struct usb_device_id products
[] = {
2957 #define RNDIS_MASTER_INTERFACE \
2958 .bInterfaceClass = USB_CLASS_COMM, \
2959 .bInterfaceSubClass = 2 /* ACM */, \
2960 .bInterfaceProtocol = 0x0ff
2962 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2963 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2966 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2967 | USB_DEVICE_ID_MATCH_DEVICE
,
2969 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
2970 RNDIS_MASTER_INTERFACE
,
2971 .driver_info
= (unsigned long) &bcm4320b_info
,
2973 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2974 | USB_DEVICE_ID_MATCH_DEVICE
,
2976 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
2977 RNDIS_MASTER_INTERFACE
,
2978 .driver_info
= (unsigned long) &bcm4320b_info
,
2980 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2981 | USB_DEVICE_ID_MATCH_DEVICE
,
2983 .idProduct
= 0x011b, /* Belkin F5D7051 */
2984 RNDIS_MASTER_INTERFACE
,
2985 .driver_info
= (unsigned long) &bcm4320b_info
,
2987 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2988 | USB_DEVICE_ID_MATCH_DEVICE
,
2989 .idVendor
= 0x1799, /* Belkin has two vendor ids */
2990 .idProduct
= 0x011b, /* Belkin F5D7051 */
2991 RNDIS_MASTER_INTERFACE
,
2992 .driver_info
= (unsigned long) &bcm4320b_info
,
2994 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
2995 | USB_DEVICE_ID_MATCH_DEVICE
,
2997 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
2998 RNDIS_MASTER_INTERFACE
,
2999 .driver_info
= (unsigned long) &bcm4320b_info
,
3001 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3002 | USB_DEVICE_ID_MATCH_DEVICE
,
3004 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
3005 RNDIS_MASTER_INTERFACE
,
3006 .driver_info
= (unsigned long) &bcm4320b_info
,
3008 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3009 | USB_DEVICE_ID_MATCH_DEVICE
,
3011 .idProduct
= 0x1717, /* Asus WL169gE */
3012 RNDIS_MASTER_INTERFACE
,
3013 .driver_info
= (unsigned long) &bcm4320b_info
,
3015 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3016 | USB_DEVICE_ID_MATCH_DEVICE
,
3018 .idProduct
= 0xd11b, /* Eminent EM4045 */
3019 RNDIS_MASTER_INTERFACE
,
3020 .driver_info
= (unsigned long) &bcm4320b_info
,
3022 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3023 | USB_DEVICE_ID_MATCH_DEVICE
,
3025 .idProduct
= 0x0715, /* BT Voyager 1055 */
3026 RNDIS_MASTER_INTERFACE
,
3027 .driver_info
= (unsigned long) &bcm4320b_info
,
3029 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3030 * parameters available, hardware probably contain older firmware version with
3031 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3034 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3035 | USB_DEVICE_ID_MATCH_DEVICE
,
3037 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
3038 RNDIS_MASTER_INTERFACE
,
3039 .driver_info
= (unsigned long) &bcm4320a_info
,
3041 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3042 | USB_DEVICE_ID_MATCH_DEVICE
,
3044 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
3045 RNDIS_MASTER_INTERFACE
,
3046 .driver_info
= (unsigned long) &bcm4320a_info
,
3048 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3049 | USB_DEVICE_ID_MATCH_DEVICE
,
3051 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
3052 RNDIS_MASTER_INTERFACE
,
3053 .driver_info
= (unsigned long) &bcm4320a_info
,
3055 /* Generic Wireless RNDIS devices that we don't have exact
3056 * idVendor/idProduct/chip yet.
3059 /* RNDIS is MSFT's un-official variant of CDC ACM */
3060 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
3061 .driver_info
= (unsigned long) &rndis_wlan_info
,
3063 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3064 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
3065 .driver_info
= (unsigned long) &rndis_wlan_info
,
3069 MODULE_DEVICE_TABLE(usb
, products
);
3071 static struct usb_driver rndis_wlan_driver
= {
3072 .name
= "rndis_wlan",
3073 .id_table
= products
,
3074 .probe
= usbnet_probe
,
3075 .disconnect
= usbnet_disconnect
,
3076 .suspend
= usbnet_suspend
,
3077 .resume
= usbnet_resume
,
3080 static int __init
rndis_wlan_init(void)
3082 return usb_register(&rndis_wlan_driver
);
3084 module_init(rndis_wlan_init
);
3086 static void __exit
rndis_wlan_exit(void)
3088 usb_deregister(&rndis_wlan_driver
);
3090 module_exit(rndis_wlan_exit
);
3092 MODULE_AUTHOR("Bjorge Dijkstra");
3093 MODULE_AUTHOR("Jussi Kivilinna");
3094 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3095 MODULE_LICENSE("GPL");