2 * Driver for RNDIS based wireless USB devices.
4 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
5 * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Portions of this file are based on NDISwrapper project,
22 * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
23 * http://ndiswrapper.sourceforge.net/
26 // #define DEBUG // error path messages, extra info
27 // #define VERBOSE // more; success messages
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/ethtool.h>
34 #include <linux/workqueue.h>
35 #include <linux/mutex.h>
36 #include <linux/mii.h>
37 #include <linux/usb.h>
38 #include <linux/usb/cdc.h>
39 #include <linux/wireless.h>
40 #include <linux/ieee80211.h>
41 #include <linux/if_arp.h>
42 #include <linux/ctype.h>
43 #include <linux/spinlock.h>
44 #include <linux/slab.h>
45 #include <net/iw_handler.h>
46 #include <net/cfg80211.h>
47 #include <linux/usb/usbnet.h>
48 #include <linux/usb/rndis_host.h>
51 /* NOTE: All these are settings for Broadcom chipset */
52 static char modparam_country
[4] = "EU";
53 module_param_string(country
, modparam_country
, 4, 0444);
54 MODULE_PARM_DESC(country
, "Country code (ISO 3166-1 alpha-2), default: EU");
56 static int modparam_frameburst
= 1;
57 module_param_named(frameburst
, modparam_frameburst
, int, 0444);
58 MODULE_PARM_DESC(frameburst
, "enable frame bursting (default: on)");
60 static int modparam_afterburner
= 0;
61 module_param_named(afterburner
, modparam_afterburner
, int, 0444);
62 MODULE_PARM_DESC(afterburner
,
63 "enable afterburner aka '125 High Speed Mode' (default: off)");
65 static int modparam_power_save
= 0;
66 module_param_named(power_save
, modparam_power_save
, int, 0444);
67 MODULE_PARM_DESC(power_save
,
68 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
70 static int modparam_power_output
= 3;
71 module_param_named(power_output
, modparam_power_output
, int, 0444);
72 MODULE_PARM_DESC(power_output
,
73 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
75 static int modparam_roamtrigger
= -70;
76 module_param_named(roamtrigger
, modparam_roamtrigger
, int, 0444);
77 MODULE_PARM_DESC(roamtrigger
,
78 "set roaming dBm trigger: -80=optimize for distance, "
79 "-60=bandwidth (default: -70)");
81 static int modparam_roamdelta
= 1;
82 module_param_named(roamdelta
, modparam_roamdelta
, int, 0444);
83 MODULE_PARM_DESC(roamdelta
,
84 "set roaming tendency: 0=aggressive, 1=moderate, "
85 "2=conservative (default: moderate)");
87 static int modparam_workaround_interval
;
88 module_param_named(workaround_interval
, modparam_workaround_interval
,
90 MODULE_PARM_DESC(workaround_interval
,
91 "set stall workaround interval in msecs (0=disabled) (default: 0)");
94 /* various RNDIS OID defs */
95 #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
96 #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
98 #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101)
99 #define OID_GEN_RCV_OK cpu_to_le32(0x00020102)
100 #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103)
101 #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104)
102 #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105)
104 #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
105 #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
106 #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
108 #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
109 #define OID_802_11_SSID cpu_to_le32(0x0d010102)
110 #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
111 #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
112 #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
113 #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
114 #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
115 #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
116 #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
117 #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
118 #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
119 #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
120 #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
121 #define OID_802_11_CAPABILITY cpu_to_le32(0x0d010122)
122 #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
123 #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
124 #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
125 #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
126 #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
127 #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
128 #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
129 #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
130 #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
131 #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
132 #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
135 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
136 #define WL_NOISE -96 /* typical noise level in dBm */
137 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
140 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
141 * based on wireless rndis) has default txpower of 13dBm.
142 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
143 * 100% : 20 mW ~ 13dBm
144 * 75% : 15 mW ~ 12dBm
145 * 50% : 10 mW ~ 10dBm
148 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
149 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
150 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
151 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
154 /* codes for "status" field of completion messages */
155 #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
156 #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
159 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
160 * slightly modified for datatype endianess, etc
162 #define NDIS_802_11_LENGTH_SSID 32
163 #define NDIS_802_11_LENGTH_RATES 8
164 #define NDIS_802_11_LENGTH_RATES_EX 16
166 enum ndis_80211_net_type
{
167 NDIS_80211_TYPE_FREQ_HOP
,
168 NDIS_80211_TYPE_DIRECT_SEQ
,
169 NDIS_80211_TYPE_OFDM_A
,
170 NDIS_80211_TYPE_OFDM_G
173 enum ndis_80211_net_infra
{
174 NDIS_80211_INFRA_ADHOC
,
175 NDIS_80211_INFRA_INFRA
,
176 NDIS_80211_INFRA_AUTO_UNKNOWN
179 enum ndis_80211_auth_mode
{
180 NDIS_80211_AUTH_OPEN
,
181 NDIS_80211_AUTH_SHARED
,
182 NDIS_80211_AUTH_AUTO_SWITCH
,
184 NDIS_80211_AUTH_WPA_PSK
,
185 NDIS_80211_AUTH_WPA_NONE
,
186 NDIS_80211_AUTH_WPA2
,
187 NDIS_80211_AUTH_WPA2_PSK
190 enum ndis_80211_encr_status
{
191 NDIS_80211_ENCR_WEP_ENABLED
,
192 NDIS_80211_ENCR_DISABLED
,
193 NDIS_80211_ENCR_WEP_KEY_ABSENT
,
194 NDIS_80211_ENCR_NOT_SUPPORTED
,
195 NDIS_80211_ENCR_TKIP_ENABLED
,
196 NDIS_80211_ENCR_TKIP_KEY_ABSENT
,
197 NDIS_80211_ENCR_CCMP_ENABLED
,
198 NDIS_80211_ENCR_CCMP_KEY_ABSENT
201 enum ndis_80211_priv_filter
{
202 NDIS_80211_PRIV_ACCEPT_ALL
,
203 NDIS_80211_PRIV_8021X_WEP
206 enum ndis_80211_status_type
{
207 NDIS_80211_STATUSTYPE_AUTHENTICATION
,
208 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
,
209 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
,
210 NDIS_80211_STATUSTYPE_RADIOSTATE
,
213 enum ndis_80211_media_stream_mode
{
214 NDIS_80211_MEDIA_STREAM_OFF
,
215 NDIS_80211_MEDIA_STREAM_ON
218 enum ndis_80211_radio_status
{
219 NDIS_80211_RADIO_STATUS_ON
,
220 NDIS_80211_RADIO_STATUS_HARDWARE_OFF
,
221 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF
,
224 enum ndis_80211_addkey_bits
{
225 NDIS_80211_ADDKEY_8021X_AUTH
= cpu_to_le32(1 << 28),
226 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
= cpu_to_le32(1 << 29),
227 NDIS_80211_ADDKEY_PAIRWISE_KEY
= cpu_to_le32(1 << 30),
228 NDIS_80211_ADDKEY_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
231 enum ndis_80211_addwep_bits
{
232 NDIS_80211_ADDWEP_PERCLIENT_KEY
= cpu_to_le32(1 << 30),
233 NDIS_80211_ADDWEP_TRANSMIT_KEY
= cpu_to_le32(1 << 31)
236 struct ndis_80211_auth_request
{
243 struct ndis_80211_pmkid_candidate
{
249 struct ndis_80211_pmkid_cand_list
{
251 __le32 num_candidates
;
252 struct ndis_80211_pmkid_candidate candidate_list
[0];
255 struct ndis_80211_status_indication
{
258 __le32 media_stream_mode
;
260 struct ndis_80211_auth_request auth_request
[0];
261 struct ndis_80211_pmkid_cand_list cand_list
;
265 struct ndis_80211_ssid
{
267 u8 essid
[NDIS_802_11_LENGTH_SSID
];
270 struct ndis_80211_conf_freq_hop
{
277 struct ndis_80211_conf
{
279 __le32 beacon_period
;
282 struct ndis_80211_conf_freq_hop fh_config
;
285 struct ndis_80211_bssid_ex
{
289 struct ndis_80211_ssid ssid
;
293 struct ndis_80211_conf config
;
295 u8 rates
[NDIS_802_11_LENGTH_RATES_EX
];
300 struct ndis_80211_bssid_list_ex
{
302 struct ndis_80211_bssid_ex bssid
[0];
305 struct ndis_80211_fixed_ies
{
307 __le16 beacon_interval
;
311 struct ndis_80211_wep_key
{
318 struct ndis_80211_key
{
328 struct ndis_80211_remove_key
{
335 struct ndis_config_param
{
343 struct ndis_80211_assoc_info
{
348 __le16 listen_interval
;
349 u8 cur_ap_address
[6];
351 __le32 req_ie_length
;
352 __le32 offset_req_ies
;
359 __le32 resp_ie_length
;
360 __le32 offset_resp_ies
;
363 struct ndis_80211_auth_encr_pair
{
368 struct ndis_80211_capability
{
372 __le32 num_auth_encr_pair
;
373 struct ndis_80211_auth_encr_pair auth_encr_pair
[0];
376 struct ndis_80211_bssid_info
{
381 struct ndis_80211_pmkid
{
383 __le32 bssid_info_count
;
384 struct ndis_80211_bssid_info bssid_info
[0];
390 #define NET_TYPE_11FB 0
392 #define CAP_MODE_80211A 1
393 #define CAP_MODE_80211B 2
394 #define CAP_MODE_80211G 4
395 #define CAP_MODE_MASK 7
397 #define WORK_LINK_UP (1<<0)
398 #define WORK_LINK_DOWN (1<<1)
399 #define WORK_SET_MULTICAST_LIST (1<<2)
401 #define RNDIS_WLAN_ALG_NONE 0
402 #define RNDIS_WLAN_ALG_WEP (1<<0)
403 #define RNDIS_WLAN_ALG_TKIP (1<<1)
404 #define RNDIS_WLAN_ALG_CCMP (1<<2)
406 #define RNDIS_WLAN_KEY_MGMT_NONE 0
407 #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
408 #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
410 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
412 static const struct ieee80211_channel rndis_channels
[] = {
413 { .center_freq
= 2412 },
414 { .center_freq
= 2417 },
415 { .center_freq
= 2422 },
416 { .center_freq
= 2427 },
417 { .center_freq
= 2432 },
418 { .center_freq
= 2437 },
419 { .center_freq
= 2442 },
420 { .center_freq
= 2447 },
421 { .center_freq
= 2452 },
422 { .center_freq
= 2457 },
423 { .center_freq
= 2462 },
424 { .center_freq
= 2467 },
425 { .center_freq
= 2472 },
426 { .center_freq
= 2484 },
429 static const struct ieee80211_rate rndis_rates
[] = {
431 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
432 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
433 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
444 static const u32 rndis_cipher_suites
[] = {
445 WLAN_CIPHER_SUITE_WEP40
,
446 WLAN_CIPHER_SUITE_WEP104
,
447 WLAN_CIPHER_SUITE_TKIP
,
448 WLAN_CIPHER_SUITE_CCMP
,
451 struct rndis_wlan_encr_key
{
460 /* RNDIS device private data */
461 struct rndis_wlan_private
{
462 struct usbnet
*usbdev
;
464 struct wireless_dev wdev
;
466 struct cfg80211_scan_request
*scan_request
;
468 struct workqueue_struct
*workqueue
;
469 struct delayed_work dev_poller_work
;
470 struct delayed_work scan_work
;
471 struct work_struct work
;
472 struct mutex command_lock
;
473 unsigned long work_pending
;
476 struct ieee80211_supported_band band
;
477 struct ieee80211_channel channels
[ARRAY_SIZE(rndis_channels
)];
478 struct ieee80211_rate rates
[ARRAY_SIZE(rndis_rates
)];
479 u32 cipher_suites
[ARRAY_SIZE(rndis_cipher_suites
)];
484 /* module parameters */
485 char param_country
[4];
486 int param_frameburst
;
487 int param_afterburner
;
488 int param_power_save
;
489 int param_power_output
;
490 int param_roamtrigger
;
492 u32 param_workaround_interval
;
499 struct ndis_80211_ssid essid
;
500 __le32 current_command_oid
;
502 /* encryption stuff */
503 int encr_tx_key_index
;
504 struct rndis_wlan_encr_key encr_keys
[4];
507 u8 command_buffer
[COMMAND_BUFFER_SIZE
];
513 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
514 struct net_device
*dev
,
515 enum nl80211_iftype type
, u32
*flags
,
516 struct vif_params
*params
);
518 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
519 struct cfg80211_scan_request
*request
);
521 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
);
523 static int rndis_set_tx_power(struct wiphy
*wiphy
,
524 enum nl80211_tx_power_setting type
,
526 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
);
528 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
529 struct cfg80211_connect_params
*sme
);
531 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
534 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
535 struct cfg80211_ibss_params
*params
);
537 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
);
539 static int rndis_set_channel(struct wiphy
*wiphy
, struct net_device
*dev
,
540 struct ieee80211_channel
*chan
, enum nl80211_channel_type channel_type
);
542 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
543 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
544 struct key_params
*params
);
546 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
547 u8 key_index
, bool pairwise
, const u8
*mac_addr
);
549 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
552 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
553 u8
*mac
, struct station_info
*sinfo
);
555 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
556 int idx
, u8
*mac
, struct station_info
*sinfo
);
558 static int rndis_set_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
559 struct cfg80211_pmksa
*pmksa
);
561 static int rndis_del_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
562 struct cfg80211_pmksa
*pmksa
);
564 static int rndis_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
);
566 static struct cfg80211_ops rndis_config_ops
= {
567 .change_virtual_intf
= rndis_change_virtual_intf
,
569 .set_wiphy_params
= rndis_set_wiphy_params
,
570 .set_tx_power
= rndis_set_tx_power
,
571 .get_tx_power
= rndis_get_tx_power
,
572 .connect
= rndis_connect
,
573 .disconnect
= rndis_disconnect
,
574 .join_ibss
= rndis_join_ibss
,
575 .leave_ibss
= rndis_leave_ibss
,
576 .set_channel
= rndis_set_channel
,
577 .add_key
= rndis_add_key
,
578 .del_key
= rndis_del_key
,
579 .set_default_key
= rndis_set_default_key
,
580 .get_station
= rndis_get_station
,
581 .dump_station
= rndis_dump_station
,
582 .set_pmksa
= rndis_set_pmksa
,
583 .del_pmksa
= rndis_del_pmksa
,
584 .flush_pmksa
= rndis_flush_pmksa
,
587 static void *rndis_wiphy_privid
= &rndis_wiphy_privid
;
590 static struct rndis_wlan_private
*get_rndis_wlan_priv(struct usbnet
*dev
)
592 return (struct rndis_wlan_private
*)dev
->driver_priv
;
595 static u32
get_bcm4320_power_dbm(struct rndis_wlan_private
*priv
)
597 switch (priv
->param_power_output
) {
600 return BCM4320_DEFAULT_TXPOWER_DBM_100
;
602 return BCM4320_DEFAULT_TXPOWER_DBM_75
;
604 return BCM4320_DEFAULT_TXPOWER_DBM_50
;
606 return BCM4320_DEFAULT_TXPOWER_DBM_25
;
610 static bool is_wpa_key(struct rndis_wlan_private
*priv
, int idx
)
612 int cipher
= priv
->encr_keys
[idx
].cipher
;
614 return (cipher
== WLAN_CIPHER_SUITE_CCMP
||
615 cipher
== WLAN_CIPHER_SUITE_TKIP
);
618 static int rndis_cipher_to_alg(u32 cipher
)
622 return RNDIS_WLAN_ALG_NONE
;
623 case WLAN_CIPHER_SUITE_WEP40
:
624 case WLAN_CIPHER_SUITE_WEP104
:
625 return RNDIS_WLAN_ALG_WEP
;
626 case WLAN_CIPHER_SUITE_TKIP
:
627 return RNDIS_WLAN_ALG_TKIP
;
628 case WLAN_CIPHER_SUITE_CCMP
:
629 return RNDIS_WLAN_ALG_CCMP
;
633 static int rndis_akm_suite_to_key_mgmt(u32 akm_suite
)
637 return RNDIS_WLAN_KEY_MGMT_NONE
;
638 case WLAN_AKM_SUITE_8021X
:
639 return RNDIS_WLAN_KEY_MGMT_802_1X
;
640 case WLAN_AKM_SUITE_PSK
:
641 return RNDIS_WLAN_KEY_MGMT_PSK
;
646 static const char *oid_to_string(__le32 oid
)
649 #define OID_STR(oid) case oid: return(#oid)
650 /* from rndis_host.h */
651 OID_STR(OID_802_3_PERMANENT_ADDRESS
);
652 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE
);
653 OID_STR(OID_GEN_CURRENT_PACKET_FILTER
);
654 OID_STR(OID_GEN_PHYSICAL_MEDIUM
);
656 /* from rndis_wlan.c */
657 OID_STR(OID_GEN_LINK_SPEED
);
658 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER
);
660 OID_STR(OID_GEN_XMIT_OK
);
661 OID_STR(OID_GEN_RCV_OK
);
662 OID_STR(OID_GEN_XMIT_ERROR
);
663 OID_STR(OID_GEN_RCV_ERROR
);
664 OID_STR(OID_GEN_RCV_NO_BUFFER
);
666 OID_STR(OID_802_3_CURRENT_ADDRESS
);
667 OID_STR(OID_802_3_MULTICAST_LIST
);
668 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE
);
670 OID_STR(OID_802_11_BSSID
);
671 OID_STR(OID_802_11_SSID
);
672 OID_STR(OID_802_11_INFRASTRUCTURE_MODE
);
673 OID_STR(OID_802_11_ADD_WEP
);
674 OID_STR(OID_802_11_REMOVE_WEP
);
675 OID_STR(OID_802_11_DISASSOCIATE
);
676 OID_STR(OID_802_11_AUTHENTICATION_MODE
);
677 OID_STR(OID_802_11_PRIVACY_FILTER
);
678 OID_STR(OID_802_11_BSSID_LIST_SCAN
);
679 OID_STR(OID_802_11_ENCRYPTION_STATUS
);
680 OID_STR(OID_802_11_ADD_KEY
);
681 OID_STR(OID_802_11_REMOVE_KEY
);
682 OID_STR(OID_802_11_ASSOCIATION_INFORMATION
);
683 OID_STR(OID_802_11_PMKID
);
684 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED
);
685 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE
);
686 OID_STR(OID_802_11_TX_POWER_LEVEL
);
687 OID_STR(OID_802_11_RSSI
);
688 OID_STR(OID_802_11_RSSI_TRIGGER
);
689 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD
);
690 OID_STR(OID_802_11_RTS_THRESHOLD
);
691 OID_STR(OID_802_11_SUPPORTED_RATES
);
692 OID_STR(OID_802_11_CONFIGURATION
);
693 OID_STR(OID_802_11_BSSID_LIST
);
700 static const char *oid_to_string(__le32 oid
)
706 /* translate error code */
707 static int rndis_error_status(__le32 rndis_status
)
710 switch (rndis_status
) {
711 case RNDIS_STATUS_SUCCESS
:
714 case RNDIS_STATUS_FAILURE
:
715 case RNDIS_STATUS_INVALID_DATA
:
718 case RNDIS_STATUS_NOT_SUPPORTED
:
721 case RNDIS_STATUS_ADAPTER_NOT_READY
:
722 case RNDIS_STATUS_ADAPTER_NOT_OPEN
:
729 static int rndis_query_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int *len
)
731 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
734 struct rndis_msg_hdr
*header
;
735 struct rndis_query
*get
;
736 struct rndis_query_c
*get_c
;
739 int resplen
, respoffs
, copylen
;
741 buflen
= *len
+ sizeof(*u
.get
);
742 if (buflen
< CONTROL_BUFFER_SIZE
)
743 buflen
= CONTROL_BUFFER_SIZE
;
745 if (buflen
> COMMAND_BUFFER_SIZE
) {
746 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
750 u
.buf
= priv
->command_buffer
;
753 mutex_lock(&priv
->command_lock
);
755 memset(u
.get
, 0, sizeof *u
.get
);
756 u
.get
->msg_type
= RNDIS_MSG_QUERY
;
757 u
.get
->msg_len
= cpu_to_le32(sizeof *u
.get
);
760 priv
->current_command_oid
= oid
;
761 ret
= rndis_command(dev
, u
.header
, buflen
);
762 priv
->current_command_oid
= 0;
764 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
765 __func__
, oid_to_string(oid
), ret
,
766 le32_to_cpu(u
.get_c
->status
));
769 resplen
= le32_to_cpu(u
.get_c
->len
);
770 respoffs
= le32_to_cpu(u
.get_c
->offset
) + 8;
772 if (respoffs
> buflen
) {
773 /* Device returned data offset outside buffer, error. */
774 netdev_dbg(dev
->net
, "%s(%s): received invalid "
775 "data offset: %d > %d\n", __func__
,
776 oid_to_string(oid
), respoffs
, buflen
);
782 if ((resplen
+ respoffs
) > buflen
) {
783 /* Device would have returned more data if buffer would
784 * have been big enough. Copy just the bits that we got.
786 copylen
= buflen
- respoffs
;
794 memcpy(data
, u
.buf
+ respoffs
, copylen
);
798 ret
= rndis_error_status(u
.get_c
->status
);
800 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
801 __func__
, oid_to_string(oid
),
802 le32_to_cpu(u
.get_c
->status
), ret
);
806 mutex_unlock(&priv
->command_lock
);
808 if (u
.buf
!= priv
->command_buffer
)
813 static int rndis_set_oid(struct usbnet
*dev
, __le32 oid
, void *data
, int len
)
815 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(dev
);
818 struct rndis_msg_hdr
*header
;
819 struct rndis_set
*set
;
820 struct rndis_set_c
*set_c
;
824 buflen
= len
+ sizeof(*u
.set
);
825 if (buflen
< CONTROL_BUFFER_SIZE
)
826 buflen
= CONTROL_BUFFER_SIZE
;
828 if (buflen
> COMMAND_BUFFER_SIZE
) {
829 u
.buf
= kmalloc(buflen
, GFP_KERNEL
);
833 u
.buf
= priv
->command_buffer
;
836 mutex_lock(&priv
->command_lock
);
838 memset(u
.set
, 0, sizeof *u
.set
);
839 u
.set
->msg_type
= RNDIS_MSG_SET
;
840 u
.set
->msg_len
= cpu_to_le32(sizeof(*u
.set
) + len
);
842 u
.set
->len
= cpu_to_le32(len
);
843 u
.set
->offset
= cpu_to_le32(sizeof(*u
.set
) - 8);
844 u
.set
->handle
= cpu_to_le32(0);
845 memcpy(u
.buf
+ sizeof(*u
.set
), data
, len
);
847 priv
->current_command_oid
= oid
;
848 ret
= rndis_command(dev
, u
.header
, buflen
);
849 priv
->current_command_oid
= 0;
851 netdev_dbg(dev
->net
, "%s(%s): rndis_command() failed, %d (%08x)\n",
852 __func__
, oid_to_string(oid
), ret
,
853 le32_to_cpu(u
.set_c
->status
));
856 ret
= rndis_error_status(u
.set_c
->status
);
859 netdev_dbg(dev
->net
, "%s(%s): device returned error, 0x%08x (%d)\n",
860 __func__
, oid_to_string(oid
),
861 le32_to_cpu(u
.set_c
->status
), ret
);
864 mutex_unlock(&priv
->command_lock
);
866 if (u
.buf
!= priv
->command_buffer
)
871 static int rndis_reset(struct usbnet
*usbdev
)
873 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
874 struct rndis_reset
*reset
;
877 mutex_lock(&priv
->command_lock
);
879 reset
= (void *)priv
->command_buffer
;
880 memset(reset
, 0, sizeof(*reset
));
881 reset
->msg_type
= RNDIS_MSG_RESET
;
882 reset
->msg_len
= cpu_to_le32(sizeof(*reset
));
883 priv
->current_command_oid
= 0;
884 ret
= rndis_command(usbdev
, (void *)reset
, CONTROL_BUFFER_SIZE
);
886 mutex_unlock(&priv
->command_lock
);
894 * Specs say that we can only set config parameters only soon after device
896 * value_type: 0 = u32, 2 = unicode string
898 static int rndis_set_config_parameter(struct usbnet
*dev
, char *param
,
899 int value_type
, void *value
)
901 struct ndis_config_param
*infobuf
;
902 int value_len
, info_len
, param_len
, ret
, i
;
907 value_len
= sizeof(__le32
);
908 else if (value_type
== 2)
909 value_len
= strlen(value
) * sizeof(__le16
);
913 param_len
= strlen(param
) * sizeof(__le16
);
914 info_len
= sizeof(*infobuf
) + param_len
+ value_len
;
919 infobuf
= kmalloc(info_len
, GFP_KERNEL
);
925 /* extra 12 bytes are for padding (debug output) */
926 memset(infobuf
, 0xCC, info_len
+ 12);
930 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %s\n",
933 netdev_dbg(dev
->net
, "setting config parameter: %s, value: %d\n",
934 param
, *(u32
*)value
);
936 infobuf
->name_offs
= cpu_to_le32(sizeof(*infobuf
));
937 infobuf
->name_length
= cpu_to_le32(param_len
);
938 infobuf
->type
= cpu_to_le32(value_type
);
939 infobuf
->value_offs
= cpu_to_le32(sizeof(*infobuf
) + param_len
);
940 infobuf
->value_length
= cpu_to_le32(value_len
);
942 /* simple string to unicode string conversion */
943 unibuf
= (void *)infobuf
+ sizeof(*infobuf
);
944 for (i
= 0; i
< param_len
/ sizeof(__le16
); i
++)
945 unibuf
[i
] = cpu_to_le16(param
[i
]);
947 if (value_type
== 2) {
948 unibuf
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
949 for (i
= 0; i
< value_len
/ sizeof(__le16
); i
++)
950 unibuf
[i
] = cpu_to_le16(((u8
*)value
)[i
]);
952 dst_value
= (void *)infobuf
+ sizeof(*infobuf
) + param_len
;
953 *dst_value
= cpu_to_le32(*(u32
*)value
);
957 netdev_dbg(dev
->net
, "info buffer (len: %d)\n", info_len
);
958 for (i
= 0; i
< info_len
; i
+= 12) {
959 u32
*tmp
= (u32
*)((u8
*)infobuf
+ i
);
960 netdev_dbg(dev
->net
, "%08X:%08X:%08X\n",
963 cpu_to_be32(tmp
[2]));
967 ret
= rndis_set_oid(dev
, OID_GEN_RNDIS_CONFIG_PARAMETER
,
970 netdev_dbg(dev
->net
, "setting rndis config parameter failed, %d\n",
977 static int rndis_set_config_parameter_str(struct usbnet
*dev
,
978 char *param
, char *value
)
980 return rndis_set_config_parameter(dev
, param
, 2, value
);
984 * data conversion functions
986 static int level_to_qual(int level
)
988 int qual
= 100 * (level
- WL_NOISE
) / (WL_SIGMAX
- WL_NOISE
);
989 return qual
>= 0 ? (qual
<= 100 ? qual
: 100) : 0;
995 static int set_infra_mode(struct usbnet
*usbdev
, int mode
);
996 static void restore_keys(struct usbnet
*usbdev
);
997 static int rndis_check_bssid_list(struct usbnet
*usbdev
);
999 static int set_essid(struct usbnet
*usbdev
, struct ndis_80211_ssid
*ssid
)
1001 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1004 ret
= rndis_set_oid(usbdev
, OID_802_11_SSID
, ssid
, sizeof(*ssid
));
1006 netdev_warn(usbdev
->net
, "setting SSID failed (%08X)\n", ret
);
1010 memcpy(&priv
->essid
, ssid
, sizeof(priv
->essid
));
1011 priv
->radio_on
= true;
1012 netdev_dbg(usbdev
->net
, "%s(): radio_on = true\n", __func__
);
1018 static int set_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
1022 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID
, bssid
, ETH_ALEN
);
1024 netdev_warn(usbdev
->net
, "setting BSSID[%pM] failed (%08X)\n",
1032 static int clear_bssid(struct usbnet
*usbdev
)
1034 u8 broadcast_mac
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1036 return set_bssid(usbdev
, broadcast_mac
);
1039 static int get_bssid(struct usbnet
*usbdev
, u8 bssid
[ETH_ALEN
])
1044 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID
, bssid
, &len
);
1047 memset(bssid
, 0, ETH_ALEN
);
1052 static int get_association_info(struct usbnet
*usbdev
,
1053 struct ndis_80211_assoc_info
*info
, int len
)
1055 return rndis_query_oid(usbdev
, OID_802_11_ASSOCIATION_INFORMATION
,
1059 static bool is_associated(struct usbnet
*usbdev
)
1061 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1065 if (!priv
->radio_on
)
1068 ret
= get_bssid(usbdev
, bssid
);
1070 return (ret
== 0 && !is_zero_ether_addr(bssid
));
1073 static int disassociate(struct usbnet
*usbdev
, bool reset_ssid
)
1075 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1076 struct ndis_80211_ssid ssid
;
1079 if (priv
->radio_on
) {
1080 ret
= rndis_set_oid(usbdev
, OID_802_11_DISASSOCIATE
, NULL
, 0);
1082 priv
->radio_on
= false;
1083 netdev_dbg(usbdev
->net
, "%s(): radio_on = false\n",
1091 /* disassociate causes radio to be turned off; if reset_ssid
1092 * is given, set random ssid to enable radio */
1094 /* Set device to infrastructure mode so we don't get ad-hoc
1095 * 'media connect' indications with the random ssid.
1097 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1099 ssid
.length
= cpu_to_le32(sizeof(ssid
.essid
));
1100 get_random_bytes(&ssid
.essid
[2], sizeof(ssid
.essid
)-2);
1101 ssid
.essid
[0] = 0x1;
1102 ssid
.essid
[1] = 0xff;
1103 for (i
= 2; i
< sizeof(ssid
.essid
); i
++)
1104 ssid
.essid
[i
] = 0x1 + (ssid
.essid
[i
] * 0xfe / 0xff);
1105 ret
= set_essid(usbdev
, &ssid
);
1110 static int set_auth_mode(struct usbnet
*usbdev
, u32 wpa_version
,
1111 enum nl80211_auth_type auth_type
, int keymgmt
)
1113 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1117 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1118 __func__
, wpa_version
, auth_type
, keymgmt
);
1120 if (wpa_version
& NL80211_WPA_VERSION_2
) {
1121 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1122 auth_mode
= NDIS_80211_AUTH_WPA2
;
1124 auth_mode
= NDIS_80211_AUTH_WPA2_PSK
;
1125 } else if (wpa_version
& NL80211_WPA_VERSION_1
) {
1126 if (keymgmt
& RNDIS_WLAN_KEY_MGMT_802_1X
)
1127 auth_mode
= NDIS_80211_AUTH_WPA
;
1128 else if (keymgmt
& RNDIS_WLAN_KEY_MGMT_PSK
)
1129 auth_mode
= NDIS_80211_AUTH_WPA_PSK
;
1131 auth_mode
= NDIS_80211_AUTH_WPA_NONE
;
1132 } else if (auth_type
== NL80211_AUTHTYPE_SHARED_KEY
)
1133 auth_mode
= NDIS_80211_AUTH_SHARED
;
1134 else if (auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
)
1135 auth_mode
= NDIS_80211_AUTH_OPEN
;
1136 else if (auth_type
== NL80211_AUTHTYPE_AUTOMATIC
)
1137 auth_mode
= NDIS_80211_AUTH_AUTO_SWITCH
;
1141 tmp
= cpu_to_le32(auth_mode
);
1142 ret
= rndis_set_oid(usbdev
, OID_802_11_AUTHENTICATION_MODE
, &tmp
,
1145 netdev_warn(usbdev
->net
, "setting auth mode failed (%08X)\n",
1150 priv
->wpa_version
= wpa_version
;
1155 static int set_priv_filter(struct usbnet
*usbdev
)
1157 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1160 netdev_dbg(usbdev
->net
, "%s(): wpa_version=0x%x\n",
1161 __func__
, priv
->wpa_version
);
1163 if (priv
->wpa_version
& NL80211_WPA_VERSION_2
||
1164 priv
->wpa_version
& NL80211_WPA_VERSION_1
)
1165 tmp
= cpu_to_le32(NDIS_80211_PRIV_8021X_WEP
);
1167 tmp
= cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL
);
1169 return rndis_set_oid(usbdev
, OID_802_11_PRIVACY_FILTER
, &tmp
,
1173 static int set_encr_mode(struct usbnet
*usbdev
, int pairwise
, int groupwise
)
1178 netdev_dbg(usbdev
->net
, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1179 __func__
, pairwise
, groupwise
);
1181 if (pairwise
& RNDIS_WLAN_ALG_CCMP
)
1182 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1183 else if (pairwise
& RNDIS_WLAN_ALG_TKIP
)
1184 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1185 else if (pairwise
& RNDIS_WLAN_ALG_WEP
)
1186 encr_mode
= NDIS_80211_ENCR_WEP_ENABLED
;
1187 else if (groupwise
& RNDIS_WLAN_ALG_CCMP
)
1188 encr_mode
= NDIS_80211_ENCR_CCMP_ENABLED
;
1189 else if (groupwise
& RNDIS_WLAN_ALG_TKIP
)
1190 encr_mode
= NDIS_80211_ENCR_TKIP_ENABLED
;
1192 encr_mode
= NDIS_80211_ENCR_DISABLED
;
1194 tmp
= cpu_to_le32(encr_mode
);
1195 ret
= rndis_set_oid(usbdev
, OID_802_11_ENCRYPTION_STATUS
, &tmp
,
1198 netdev_warn(usbdev
->net
, "setting encr mode failed (%08X)\n",
1206 static int set_infra_mode(struct usbnet
*usbdev
, int mode
)
1208 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1212 netdev_dbg(usbdev
->net
, "%s(): infra_mode=0x%x\n",
1213 __func__
, priv
->infra_mode
);
1215 tmp
= cpu_to_le32(mode
);
1216 ret
= rndis_set_oid(usbdev
, OID_802_11_INFRASTRUCTURE_MODE
, &tmp
,
1219 netdev_warn(usbdev
->net
, "setting infra mode failed (%08X)\n",
1224 /* NDIS drivers clear keys when infrastructure mode is
1225 * changed. But Linux tools assume otherwise. So set the
1227 restore_keys(usbdev
);
1229 priv
->infra_mode
= mode
;
1233 static int set_rts_threshold(struct usbnet
*usbdev
, u32 rts_threshold
)
1237 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, rts_threshold
);
1239 if (rts_threshold
< 0 || rts_threshold
> 2347)
1240 rts_threshold
= 2347;
1242 tmp
= cpu_to_le32(rts_threshold
);
1243 return rndis_set_oid(usbdev
, OID_802_11_RTS_THRESHOLD
, &tmp
,
1247 static int set_frag_threshold(struct usbnet
*usbdev
, u32 frag_threshold
)
1251 netdev_dbg(usbdev
->net
, "%s(): %i\n", __func__
, frag_threshold
);
1253 if (frag_threshold
< 256 || frag_threshold
> 2346)
1254 frag_threshold
= 2346;
1256 tmp
= cpu_to_le32(frag_threshold
);
1257 return rndis_set_oid(usbdev
, OID_802_11_FRAGMENTATION_THRESHOLD
, &tmp
,
1261 static void set_default_iw_params(struct usbnet
*usbdev
)
1263 set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
1264 set_auth_mode(usbdev
, 0, NL80211_AUTHTYPE_OPEN_SYSTEM
,
1265 RNDIS_WLAN_KEY_MGMT_NONE
);
1266 set_priv_filter(usbdev
);
1267 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1270 static int deauthenticate(struct usbnet
*usbdev
)
1274 ret
= disassociate(usbdev
, true);
1275 set_default_iw_params(usbdev
);
1279 static int set_channel(struct usbnet
*usbdev
, int channel
)
1281 struct ndis_80211_conf config
;
1282 unsigned int dsconfig
;
1285 netdev_dbg(usbdev
->net
, "%s(%d)\n", __func__
, channel
);
1287 /* this OID is valid only when not associated */
1288 if (is_associated(usbdev
))
1291 dsconfig
= ieee80211_dsss_chan_to_freq(channel
) * 1000;
1293 len
= sizeof(config
);
1294 ret
= rndis_query_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
, &len
);
1296 netdev_dbg(usbdev
->net
, "%s(): querying configuration failed\n",
1301 config
.ds_config
= cpu_to_le32(dsconfig
);
1302 ret
= rndis_set_oid(usbdev
, OID_802_11_CONFIGURATION
, &config
,
1305 netdev_dbg(usbdev
->net
, "%s(): %d -> %d\n", __func__
, channel
, ret
);
1310 /* index must be 0 - N, as per NDIS */
1311 static int add_wep_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1314 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1315 struct ndis_80211_wep_key ndis_key
;
1319 netdev_dbg(usbdev
->net
, "%s(idx: %d, len: %d)\n",
1320 __func__
, index
, key_len
);
1322 if ((key_len
!= 5 && key_len
!= 13) || index
< 0 || index
> 3)
1326 cipher
= WLAN_CIPHER_SUITE_WEP40
;
1328 cipher
= WLAN_CIPHER_SUITE_WEP104
;
1330 memset(&ndis_key
, 0, sizeof(ndis_key
));
1332 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
));
1333 ndis_key
.length
= cpu_to_le32(key_len
);
1334 ndis_key
.index
= cpu_to_le32(index
);
1335 memcpy(&ndis_key
.material
, key
, key_len
);
1337 if (index
== priv
->encr_tx_key_index
) {
1338 ndis_key
.index
|= NDIS_80211_ADDWEP_TRANSMIT_KEY
;
1339 ret
= set_encr_mode(usbdev
, RNDIS_WLAN_ALG_WEP
,
1340 RNDIS_WLAN_ALG_NONE
);
1342 netdev_warn(usbdev
->net
, "encryption couldn't be enabled (%08X)\n",
1346 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_WEP
, &ndis_key
,
1349 netdev_warn(usbdev
->net
, "adding encryption key %d failed (%08X)\n",
1354 priv
->encr_keys
[index
].len
= key_len
;
1355 priv
->encr_keys
[index
].cipher
= cipher
;
1356 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1357 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1362 static int add_wpa_key(struct usbnet
*usbdev
, const u8
*key
, int key_len
,
1363 int index
, const u8
*addr
, const u8
*rx_seq
,
1364 int seq_len
, u32 cipher
, __le32 flags
)
1366 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1367 struct ndis_80211_key ndis_key
;
1371 if (index
< 0 || index
>= 4) {
1372 netdev_dbg(usbdev
->net
, "%s(): index out of range (%i)\n",
1376 if (key_len
> sizeof(ndis_key
.material
) || key_len
< 0) {
1377 netdev_dbg(usbdev
->net
, "%s(): key length out of range (%i)\n",
1381 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
) {
1382 if (!rx_seq
|| seq_len
<= 0) {
1383 netdev_dbg(usbdev
->net
, "%s(): recv seq flag without buffer\n",
1387 if (rx_seq
&& seq_len
> sizeof(ndis_key
.rsc
)) {
1388 netdev_dbg(usbdev
->net
, "%s(): too big recv seq buffer\n", __func__
);
1393 is_addr_ok
= addr
&& !is_zero_ether_addr(addr
) &&
1394 !is_broadcast_ether_addr(addr
);
1395 if ((flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) && !is_addr_ok
) {
1396 netdev_dbg(usbdev
->net
, "%s(): pairwise but bssid invalid (%pM)\n",
1401 netdev_dbg(usbdev
->net
, "%s(%i): flags:%i%i%i\n",
1403 !!(flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
),
1404 !!(flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
),
1405 !!(flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
));
1407 memset(&ndis_key
, 0, sizeof(ndis_key
));
1409 ndis_key
.size
= cpu_to_le32(sizeof(ndis_key
) -
1410 sizeof(ndis_key
.material
) + key_len
);
1411 ndis_key
.length
= cpu_to_le32(key_len
);
1412 ndis_key
.index
= cpu_to_le32(index
) | flags
;
1414 if (cipher
== WLAN_CIPHER_SUITE_TKIP
&& key_len
== 32) {
1415 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1416 * different order than NDIS spec, so swap the order here. */
1417 memcpy(ndis_key
.material
, key
, 16);
1418 memcpy(ndis_key
.material
+ 16, key
+ 24, 8);
1419 memcpy(ndis_key
.material
+ 24, key
+ 16, 8);
1421 memcpy(ndis_key
.material
, key
, key_len
);
1423 if (flags
& NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
)
1424 memcpy(ndis_key
.rsc
, rx_seq
, seq_len
);
1426 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
) {
1428 memcpy(ndis_key
.bssid
, addr
, ETH_ALEN
);
1431 if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
1432 memset(ndis_key
.bssid
, 0xff, ETH_ALEN
);
1434 get_bssid(usbdev
, ndis_key
.bssid
);
1437 ret
= rndis_set_oid(usbdev
, OID_802_11_ADD_KEY
, &ndis_key
,
1438 le32_to_cpu(ndis_key
.size
));
1439 netdev_dbg(usbdev
->net
, "%s(): OID_802_11_ADD_KEY -> %08X\n",
1444 memset(&priv
->encr_keys
[index
], 0, sizeof(priv
->encr_keys
[index
]));
1445 priv
->encr_keys
[index
].len
= key_len
;
1446 priv
->encr_keys
[index
].cipher
= cipher
;
1447 memcpy(&priv
->encr_keys
[index
].material
, key
, key_len
);
1448 if (flags
& NDIS_80211_ADDKEY_PAIRWISE_KEY
)
1449 memcpy(&priv
->encr_keys
[index
].bssid
, ndis_key
.bssid
, ETH_ALEN
);
1451 memset(&priv
->encr_keys
[index
].bssid
, 0xff, ETH_ALEN
);
1453 if (flags
& NDIS_80211_ADDKEY_TRANSMIT_KEY
)
1454 priv
->encr_tx_key_index
= index
;
1459 static int restore_key(struct usbnet
*usbdev
, int key_idx
)
1461 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1462 struct rndis_wlan_encr_key key
;
1464 if (is_wpa_key(priv
, key_idx
))
1467 key
= priv
->encr_keys
[key_idx
];
1469 netdev_dbg(usbdev
->net
, "%s(): %i:%i\n", __func__
, key_idx
, key
.len
);
1474 return add_wep_key(usbdev
, key
.material
, key
.len
, key_idx
);
1477 static void restore_keys(struct usbnet
*usbdev
)
1481 for (i
= 0; i
< 4; i
++)
1482 restore_key(usbdev
, i
);
1485 static void clear_key(struct rndis_wlan_private
*priv
, int idx
)
1487 memset(&priv
->encr_keys
[idx
], 0, sizeof(priv
->encr_keys
[idx
]));
1490 /* remove_key is for both wep and wpa */
1491 static int remove_key(struct usbnet
*usbdev
, int index
, const u8
*bssid
)
1493 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1494 struct ndis_80211_remove_key remove_key
;
1499 if (priv
->encr_keys
[index
].len
== 0)
1502 is_wpa
= is_wpa_key(priv
, index
);
1504 netdev_dbg(usbdev
->net
, "%s(): %i:%s:%i\n",
1505 __func__
, index
, is_wpa
? "wpa" : "wep",
1506 priv
->encr_keys
[index
].len
);
1508 clear_key(priv
, index
);
1511 remove_key
.size
= cpu_to_le32(sizeof(remove_key
));
1512 remove_key
.index
= cpu_to_le32(index
);
1515 if (!is_broadcast_ether_addr(bssid
))
1517 NDIS_80211_ADDKEY_PAIRWISE_KEY
;
1518 memcpy(remove_key
.bssid
, bssid
,
1519 sizeof(remove_key
.bssid
));
1521 memset(remove_key
.bssid
, 0xff,
1522 sizeof(remove_key
.bssid
));
1524 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_KEY
, &remove_key
,
1525 sizeof(remove_key
));
1529 keyindex
= cpu_to_le32(index
);
1530 ret
= rndis_set_oid(usbdev
, OID_802_11_REMOVE_WEP
, &keyindex
,
1533 netdev_warn(usbdev
->net
,
1534 "removing encryption key %d failed (%08X)\n",
1540 /* if it is transmit key, disable encryption */
1541 if (index
== priv
->encr_tx_key_index
)
1542 set_encr_mode(usbdev
, RNDIS_WLAN_ALG_NONE
, RNDIS_WLAN_ALG_NONE
);
1547 static void set_multicast_list(struct usbnet
*usbdev
)
1549 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1550 struct netdev_hw_addr
*ha
;
1551 __le32 filter
, basefilter
;
1553 char *mc_addrs
= NULL
;
1556 basefilter
= filter
= RNDIS_PACKET_TYPE_DIRECTED
|
1557 RNDIS_PACKET_TYPE_BROADCAST
;
1559 if (usbdev
->net
->flags
& IFF_PROMISC
) {
1560 filter
|= RNDIS_PACKET_TYPE_PROMISCUOUS
|
1561 RNDIS_PACKET_TYPE_ALL_LOCAL
;
1562 } else if (usbdev
->net
->flags
& IFF_ALLMULTI
) {
1563 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1566 if (filter
!= basefilter
)
1570 * mc_list should be accessed holding the lock, so copy addresses to
1571 * local buffer first.
1573 netif_addr_lock_bh(usbdev
->net
);
1574 mc_count
= netdev_mc_count(usbdev
->net
);
1575 if (mc_count
> priv
->multicast_size
) {
1576 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1577 } else if (mc_count
) {
1580 mc_addrs
= kmalloc(mc_count
* ETH_ALEN
, GFP_ATOMIC
);
1582 netdev_warn(usbdev
->net
,
1583 "couldn't alloc %d bytes of memory\n",
1584 mc_count
* ETH_ALEN
);
1585 netif_addr_unlock_bh(usbdev
->net
);
1589 netdev_for_each_mc_addr(ha
, usbdev
->net
)
1590 memcpy(mc_addrs
+ i
++ * ETH_ALEN
,
1591 ha
->addr
, ETH_ALEN
);
1593 netif_addr_unlock_bh(usbdev
->net
);
1595 if (filter
!= basefilter
)
1599 ret
= rndis_set_oid(usbdev
, OID_802_3_MULTICAST_LIST
, mc_addrs
,
1600 mc_count
* ETH_ALEN
);
1603 filter
|= RNDIS_PACKET_TYPE_MULTICAST
;
1605 filter
|= RNDIS_PACKET_TYPE_ALL_MULTICAST
;
1607 netdev_dbg(usbdev
->net
, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1608 mc_count
, priv
->multicast_size
, ret
);
1612 ret
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
1615 netdev_warn(usbdev
->net
, "couldn't set packet filter: %08x\n",
1616 le32_to_cpu(filter
));
1619 netdev_dbg(usbdev
->net
, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1620 le32_to_cpu(filter
), ret
);
1624 static void debug_print_pmkids(struct usbnet
*usbdev
,
1625 struct ndis_80211_pmkid
*pmkids
,
1626 const char *func_str
)
1628 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1629 int i
, len
, count
, max_pmkids
, entry_len
;
1631 max_pmkids
= priv
->wdev
.wiphy
->max_num_pmkids
;
1632 len
= le32_to_cpu(pmkids
->length
);
1633 count
= le32_to_cpu(pmkids
->bssid_info_count
);
1635 entry_len
= (count
> 0) ? (len
- sizeof(*pmkids
)) / count
: -1;
1637 netdev_dbg(usbdev
->net
, "%s(): %d PMKIDs (data len: %d, entry len: "
1638 "%d)\n", func_str
, count
, len
, entry_len
);
1640 if (count
> max_pmkids
)
1643 for (i
= 0; i
< count
; i
++) {
1644 u32
*tmp
= (u32
*)pmkids
->bssid_info
[i
].pmkid
;
1646 netdev_dbg(usbdev
->net
, "%s(): bssid: %pM, "
1647 "pmkid: %08X:%08X:%08X:%08X\n",
1648 func_str
, pmkids
->bssid_info
[i
].bssid
,
1649 cpu_to_be32(tmp
[0]), cpu_to_be32(tmp
[1]),
1650 cpu_to_be32(tmp
[2]), cpu_to_be32(tmp
[3]));
1654 static void debug_print_pmkids(struct usbnet
*usbdev
,
1655 struct ndis_80211_pmkid
*pmkids
,
1656 const char *func_str
)
1662 static struct ndis_80211_pmkid
*get_device_pmkids(struct usbnet
*usbdev
)
1664 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1665 struct ndis_80211_pmkid
*pmkids
;
1666 int len
, ret
, max_pmkids
;
1668 max_pmkids
= priv
->wdev
.wiphy
->max_num_pmkids
;
1669 len
= sizeof(*pmkids
) + max_pmkids
* sizeof(pmkids
->bssid_info
[0]);
1671 pmkids
= kzalloc(len
, GFP_KERNEL
);
1673 return ERR_PTR(-ENOMEM
);
1675 pmkids
->length
= cpu_to_le32(len
);
1676 pmkids
->bssid_info_count
= cpu_to_le32(max_pmkids
);
1678 ret
= rndis_query_oid(usbdev
, OID_802_11_PMKID
, pmkids
, &len
);
1680 netdev_dbg(usbdev
->net
, "%s(): OID_802_11_PMKID(%d, %d)"
1681 " -> %d\n", __func__
, len
, max_pmkids
, ret
);
1684 return ERR_PTR(ret
);
1687 if (le32_to_cpu(pmkids
->bssid_info_count
) > max_pmkids
)
1688 pmkids
->bssid_info_count
= cpu_to_le32(max_pmkids
);
1690 debug_print_pmkids(usbdev
, pmkids
, __func__
);
1695 static int set_device_pmkids(struct usbnet
*usbdev
,
1696 struct ndis_80211_pmkid
*pmkids
)
1698 int ret
, len
, num_pmkids
;
1700 num_pmkids
= le32_to_cpu(pmkids
->bssid_info_count
);
1701 len
= sizeof(*pmkids
) + num_pmkids
* sizeof(pmkids
->bssid_info
[0]);
1702 pmkids
->length
= cpu_to_le32(len
);
1704 debug_print_pmkids(usbdev
, pmkids
, __func__
);
1706 ret
= rndis_set_oid(usbdev
, OID_802_11_PMKID
, pmkids
,
1707 le32_to_cpu(pmkids
->length
));
1709 netdev_dbg(usbdev
->net
, "%s(): OID_802_11_PMKID(%d, %d) -> %d"
1710 "\n", __func__
, len
, num_pmkids
, ret
);
1717 static struct ndis_80211_pmkid
*remove_pmkid(struct usbnet
*usbdev
,
1718 struct ndis_80211_pmkid
*pmkids
,
1719 struct cfg80211_pmksa
*pmksa
,
1722 int i
, len
, count
, newlen
, err
;
1724 len
= le32_to_cpu(pmkids
->length
);
1725 count
= le32_to_cpu(pmkids
->bssid_info_count
);
1727 if (count
> max_pmkids
)
1730 for (i
= 0; i
< count
; i
++)
1731 if (!compare_ether_addr(pmkids
->bssid_info
[i
].bssid
,
1735 /* pmkid not found */
1737 netdev_dbg(usbdev
->net
, "%s(): bssid not found (%pM)\n",
1738 __func__
, pmksa
->bssid
);
1743 for (; i
+ 1 < count
; i
++)
1744 pmkids
->bssid_info
[i
] = pmkids
->bssid_info
[i
+ 1];
1747 newlen
= sizeof(*pmkids
) + count
* sizeof(pmkids
->bssid_info
[0]);
1749 pmkids
->length
= cpu_to_le32(newlen
);
1750 pmkids
->bssid_info_count
= cpu_to_le32(count
);
1755 return ERR_PTR(err
);
1758 static struct ndis_80211_pmkid
*update_pmkid(struct usbnet
*usbdev
,
1759 struct ndis_80211_pmkid
*pmkids
,
1760 struct cfg80211_pmksa
*pmksa
,
1763 int i
, err
, len
, count
, newlen
;
1765 len
= le32_to_cpu(pmkids
->length
);
1766 count
= le32_to_cpu(pmkids
->bssid_info_count
);
1768 if (count
> max_pmkids
)
1771 /* update with new pmkid */
1772 for (i
= 0; i
< count
; i
++) {
1773 if (compare_ether_addr(pmkids
->bssid_info
[i
].bssid
,
1777 memcpy(pmkids
->bssid_info
[i
].pmkid
, pmksa
->pmkid
,
1783 /* out of space, return error */
1784 if (i
== max_pmkids
) {
1785 netdev_dbg(usbdev
->net
, "%s(): out of space\n", __func__
);
1791 newlen
= sizeof(*pmkids
) + (count
+ 1) * sizeof(pmkids
->bssid_info
[0]);
1793 pmkids
= krealloc(pmkids
, newlen
, GFP_KERNEL
);
1799 pmkids
->length
= cpu_to_le32(newlen
);
1800 pmkids
->bssid_info_count
= cpu_to_le32(count
+ 1);
1802 memcpy(pmkids
->bssid_info
[count
].bssid
, pmksa
->bssid
, ETH_ALEN
);
1803 memcpy(pmkids
->bssid_info
[count
].pmkid
, pmksa
->pmkid
, WLAN_PMKID_LEN
);
1808 return ERR_PTR(err
);
1814 static int rndis_change_virtual_intf(struct wiphy
*wiphy
,
1815 struct net_device
*dev
,
1816 enum nl80211_iftype type
, u32
*flags
,
1817 struct vif_params
*params
)
1819 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1820 struct usbnet
*usbdev
= priv
->usbdev
;
1824 case NL80211_IFTYPE_ADHOC
:
1825 mode
= NDIS_80211_INFRA_ADHOC
;
1827 case NL80211_IFTYPE_STATION
:
1828 mode
= NDIS_80211_INFRA_INFRA
;
1834 priv
->wdev
.iftype
= type
;
1836 return set_infra_mode(usbdev
, mode
);
1839 static int rndis_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1841 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1842 struct usbnet
*usbdev
= priv
->usbdev
;
1845 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
1846 err
= set_frag_threshold(usbdev
, wiphy
->frag_threshold
);
1851 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
1852 err
= set_rts_threshold(usbdev
, wiphy
->rts_threshold
);
1860 static int rndis_set_tx_power(struct wiphy
*wiphy
,
1861 enum nl80211_tx_power_setting type
,
1864 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1865 struct usbnet
*usbdev
= priv
->usbdev
;
1867 netdev_dbg(usbdev
->net
, "%s(): type:0x%x mbm:%i\n",
1868 __func__
, type
, mbm
);
1870 if (mbm
< 0 || (mbm
% 100))
1873 /* Device doesn't support changing txpower after initialization, only
1874 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1877 if (type
== NL80211_TX_POWER_AUTOMATIC
||
1878 MBM_TO_DBM(mbm
) == get_bcm4320_power_dbm(priv
)) {
1879 if (!priv
->radio_on
)
1880 disassociate(usbdev
, true); /* turn on radio */
1888 static int rndis_get_tx_power(struct wiphy
*wiphy
, int *dbm
)
1890 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
1891 struct usbnet
*usbdev
= priv
->usbdev
;
1893 *dbm
= get_bcm4320_power_dbm(priv
);
1895 netdev_dbg(usbdev
->net
, "%s(): dbm:%i\n", __func__
, *dbm
);
1900 #define SCAN_DELAY_JIFFIES (6 * HZ)
1901 static int rndis_scan(struct wiphy
*wiphy
, struct net_device
*dev
,
1902 struct cfg80211_scan_request
*request
)
1904 struct usbnet
*usbdev
= netdev_priv(dev
);
1905 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1909 netdev_dbg(usbdev
->net
, "cfg80211.scan\n");
1911 /* Get current bssid list from device before new scan, as new scan
1912 * clears internal bssid list.
1914 rndis_check_bssid_list(usbdev
);
1919 if (priv
->scan_request
&& priv
->scan_request
!= request
)
1922 priv
->scan_request
= request
;
1924 tmp
= cpu_to_le32(1);
1925 ret
= rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
1928 /* Wait before retrieving scan results from device */
1929 queue_delayed_work(priv
->workqueue
, &priv
->scan_work
,
1930 SCAN_DELAY_JIFFIES
);
1936 static struct cfg80211_bss
*rndis_bss_info_update(struct usbnet
*usbdev
,
1937 struct ndis_80211_bssid_ex
*bssid
)
1939 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
1940 struct ieee80211_channel
*channel
;
1944 u16 beacon_interval
;
1945 struct ndis_80211_fixed_ies
*fixed
;
1946 int ie_len
, bssid_len
;
1949 netdev_dbg(usbdev
->net
, " found bssid: '%.32s' [%pM]\n",
1950 bssid
->ssid
.essid
, bssid
->mac
);
1952 /* parse bssid structure */
1953 bssid_len
= le32_to_cpu(bssid
->length
);
1955 if (bssid_len
< sizeof(struct ndis_80211_bssid_ex
) +
1956 sizeof(struct ndis_80211_fixed_ies
))
1959 fixed
= (struct ndis_80211_fixed_ies
*)bssid
->ies
;
1961 ie
= (void *)(bssid
->ies
+ sizeof(struct ndis_80211_fixed_ies
));
1962 ie_len
= min(bssid_len
- (int)sizeof(*bssid
),
1963 (int)le32_to_cpu(bssid
->ie_length
));
1964 ie_len
-= sizeof(struct ndis_80211_fixed_ies
);
1968 /* extract data for cfg80211_inform_bss */
1969 channel
= ieee80211_get_channel(priv
->wdev
.wiphy
,
1970 KHZ_TO_MHZ(le32_to_cpu(bssid
->config
.ds_config
)));
1974 signal
= level_to_qual(le32_to_cpu(bssid
->rssi
));
1975 timestamp
= le64_to_cpu(*(__le64
*)fixed
->timestamp
);
1976 capability
= le16_to_cpu(fixed
->capabilities
);
1977 beacon_interval
= le16_to_cpu(fixed
->beacon_interval
);
1979 return cfg80211_inform_bss(priv
->wdev
.wiphy
, channel
, bssid
->mac
,
1980 timestamp
, capability
, beacon_interval
, ie
, ie_len
, signal
,
1984 static int rndis_check_bssid_list(struct usbnet
*usbdev
)
1987 struct ndis_80211_bssid_list_ex
*bssid_list
;
1988 struct ndis_80211_bssid_ex
*bssid
;
1989 int ret
= -EINVAL
, len
, count
, bssid_len
;
1990 bool resized
= false;
1992 netdev_dbg(usbdev
->net
, "check_bssid_list\n");
1994 len
= CONTROL_BUFFER_SIZE
;
1996 buf
= kmalloc(len
, GFP_KERNEL
);
2002 ret
= rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2006 if (!resized
&& len
> CONTROL_BUFFER_SIZE
) {
2013 bssid
= bssid_list
->bssid
;
2014 bssid_len
= le32_to_cpu(bssid
->length
);
2015 count
= le32_to_cpu(bssid_list
->num_items
);
2016 netdev_dbg(usbdev
->net
, "check_bssid_list: %d BSSIDs found (buflen: %d)\n",
2019 while (count
&& ((void *)bssid
+ bssid_len
) <= (buf
+ len
)) {
2020 rndis_bss_info_update(usbdev
, bssid
);
2022 bssid
= (void *)bssid
+ bssid_len
;
2023 bssid_len
= le32_to_cpu(bssid
->length
);
2032 static void rndis_get_scan_results(struct work_struct
*work
)
2034 struct rndis_wlan_private
*priv
=
2035 container_of(work
, struct rndis_wlan_private
, scan_work
.work
);
2036 struct usbnet
*usbdev
= priv
->usbdev
;
2039 netdev_dbg(usbdev
->net
, "get_scan_results\n");
2041 if (!priv
->scan_request
)
2044 ret
= rndis_check_bssid_list(usbdev
);
2046 cfg80211_scan_done(priv
->scan_request
, ret
< 0);
2048 priv
->scan_request
= NULL
;
2051 static int rndis_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
2052 struct cfg80211_connect_params
*sme
)
2054 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2055 struct usbnet
*usbdev
= priv
->usbdev
;
2056 struct ieee80211_channel
*channel
= sme
->channel
;
2057 struct ndis_80211_ssid ssid
;
2058 int pairwise
= RNDIS_WLAN_ALG_NONE
;
2059 int groupwise
= RNDIS_WLAN_ALG_NONE
;
2060 int keymgmt
= RNDIS_WLAN_KEY_MGMT_NONE
;
2061 int length
, i
, ret
, chan
= -1;
2064 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
2066 groupwise
= rndis_cipher_to_alg(sme
->crypto
.cipher_group
);
2067 for (i
= 0; i
< sme
->crypto
.n_ciphers_pairwise
; i
++)
2069 rndis_cipher_to_alg(sme
->crypto
.ciphers_pairwise
[i
]);
2071 if (sme
->crypto
.n_ciphers_pairwise
> 0 &&
2072 pairwise
== RNDIS_WLAN_ALG_NONE
) {
2073 netdev_err(usbdev
->net
, "Unsupported pairwise cipher\n");
2077 for (i
= 0; i
< sme
->crypto
.n_akm_suites
; i
++)
2079 rndis_akm_suite_to_key_mgmt(sme
->crypto
.akm_suites
[i
]);
2081 if (sme
->crypto
.n_akm_suites
> 0 &&
2082 keymgmt
== RNDIS_WLAN_KEY_MGMT_NONE
) {
2083 netdev_err(usbdev
->net
, "Invalid keymgmt\n");
2087 netdev_dbg(usbdev
->net
, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
2088 sme
->ssid
, sme
->bssid
, chan
,
2089 sme
->privacy
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
2090 groupwise
, pairwise
, keymgmt
);
2092 if (is_associated(usbdev
))
2093 disassociate(usbdev
, false);
2095 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_INFRA
);
2097 netdev_dbg(usbdev
->net
, "connect: set_infra_mode failed, %d\n",
2099 goto err_turn_radio_on
;
2102 ret
= set_auth_mode(usbdev
, sme
->crypto
.wpa_versions
, sme
->auth_type
,
2105 netdev_dbg(usbdev
->net
, "connect: set_auth_mode failed, %d\n",
2107 goto err_turn_radio_on
;
2110 set_priv_filter(usbdev
);
2112 ret
= set_encr_mode(usbdev
, pairwise
, groupwise
);
2114 netdev_dbg(usbdev
->net
, "connect: set_encr_mode failed, %d\n",
2116 goto err_turn_radio_on
;
2120 ret
= set_channel(usbdev
, chan
);
2122 netdev_dbg(usbdev
->net
, "connect: set_channel failed, %d\n",
2124 goto err_turn_radio_on
;
2128 if (sme
->key
&& ((groupwise
| pairwise
) & RNDIS_WLAN_ALG_WEP
)) {
2129 priv
->encr_tx_key_index
= sme
->key_idx
;
2130 ret
= add_wep_key(usbdev
, sme
->key
, sme
->key_len
, sme
->key_idx
);
2132 netdev_dbg(usbdev
->net
, "connect: add_wep_key failed, %d (%d, %d)\n",
2133 ret
, sme
->key_len
, sme
->key_idx
);
2134 goto err_turn_radio_on
;
2138 if (sme
->bssid
&& !is_zero_ether_addr(sme
->bssid
) &&
2139 !is_broadcast_ether_addr(sme
->bssid
)) {
2140 ret
= set_bssid(usbdev
, sme
->bssid
);
2142 netdev_dbg(usbdev
->net
, "connect: set_bssid failed, %d\n",
2144 goto err_turn_radio_on
;
2147 clear_bssid(usbdev
);
2149 length
= sme
->ssid_len
;
2150 if (length
> NDIS_802_11_LENGTH_SSID
)
2151 length
= NDIS_802_11_LENGTH_SSID
;
2153 memset(&ssid
, 0, sizeof(ssid
));
2154 ssid
.length
= cpu_to_le32(length
);
2155 memcpy(ssid
.essid
, sme
->ssid
, length
);
2157 /* Pause and purge rx queue, so we don't pass packets before
2158 * 'media connect'-indication.
2160 usbnet_pause_rx(usbdev
);
2161 usbnet_purge_paused_rxq(usbdev
);
2163 ret
= set_essid(usbdev
, &ssid
);
2165 netdev_dbg(usbdev
->net
, "connect: set_essid failed, %d\n", ret
);
2169 disassociate(usbdev
, true);
2174 static int rndis_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
2177 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2178 struct usbnet
*usbdev
= priv
->usbdev
;
2180 netdev_dbg(usbdev
->net
, "cfg80211.disconnect(%d)\n", reason_code
);
2182 priv
->connected
= false;
2183 memset(priv
->bssid
, 0, ETH_ALEN
);
2185 return deauthenticate(usbdev
);
2188 static int rndis_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
2189 struct cfg80211_ibss_params
*params
)
2191 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2192 struct usbnet
*usbdev
= priv
->usbdev
;
2193 struct ieee80211_channel
*channel
= params
->channel
;
2194 struct ndis_80211_ssid ssid
;
2195 enum nl80211_auth_type auth_type
;
2196 int ret
, alg
, length
, chan
= -1;
2199 chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
2201 /* TODO: How to handle ad-hoc encryption?
2202 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
2203 * pre-shared for encryption (open/shared/wpa), is key set before
2204 * join_ibss? Which auth_type to use (not in params)? What about WPA?
2206 if (params
->privacy
) {
2207 auth_type
= NL80211_AUTHTYPE_SHARED_KEY
;
2208 alg
= RNDIS_WLAN_ALG_WEP
;
2210 auth_type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
2211 alg
= RNDIS_WLAN_ALG_NONE
;
2214 netdev_dbg(usbdev
->net
, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
2215 params
->ssid
, params
->bssid
, chan
, params
->privacy
);
2217 if (is_associated(usbdev
))
2218 disassociate(usbdev
, false);
2220 ret
= set_infra_mode(usbdev
, NDIS_80211_INFRA_ADHOC
);
2222 netdev_dbg(usbdev
->net
, "join_ibss: set_infra_mode failed, %d\n",
2224 goto err_turn_radio_on
;
2227 ret
= set_auth_mode(usbdev
, 0, auth_type
, RNDIS_WLAN_KEY_MGMT_NONE
);
2229 netdev_dbg(usbdev
->net
, "join_ibss: set_auth_mode failed, %d\n",
2231 goto err_turn_radio_on
;
2234 set_priv_filter(usbdev
);
2236 ret
= set_encr_mode(usbdev
, alg
, RNDIS_WLAN_ALG_NONE
);
2238 netdev_dbg(usbdev
->net
, "join_ibss: set_encr_mode failed, %d\n",
2240 goto err_turn_radio_on
;
2244 ret
= set_channel(usbdev
, chan
);
2246 netdev_dbg(usbdev
->net
, "join_ibss: set_channel failed, %d\n",
2248 goto err_turn_radio_on
;
2252 if (params
->bssid
&& !is_zero_ether_addr(params
->bssid
) &&
2253 !is_broadcast_ether_addr(params
->bssid
)) {
2254 ret
= set_bssid(usbdev
, params
->bssid
);
2256 netdev_dbg(usbdev
->net
, "join_ibss: set_bssid failed, %d\n",
2258 goto err_turn_radio_on
;
2261 clear_bssid(usbdev
);
2263 length
= params
->ssid_len
;
2264 if (length
> NDIS_802_11_LENGTH_SSID
)
2265 length
= NDIS_802_11_LENGTH_SSID
;
2267 memset(&ssid
, 0, sizeof(ssid
));
2268 ssid
.length
= cpu_to_le32(length
);
2269 memcpy(ssid
.essid
, params
->ssid
, length
);
2271 /* Don't need to pause rx queue for ad-hoc. */
2272 usbnet_purge_paused_rxq(usbdev
);
2273 usbnet_resume_rx(usbdev
);
2275 ret
= set_essid(usbdev
, &ssid
);
2277 netdev_dbg(usbdev
->net
, "join_ibss: set_essid failed, %d\n",
2282 disassociate(usbdev
, true);
2287 static int rndis_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2289 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2290 struct usbnet
*usbdev
= priv
->usbdev
;
2292 netdev_dbg(usbdev
->net
, "cfg80211.leave_ibss()\n");
2294 priv
->connected
= false;
2295 memset(priv
->bssid
, 0, ETH_ALEN
);
2297 return deauthenticate(usbdev
);
2300 static int rndis_set_channel(struct wiphy
*wiphy
, struct net_device
*netdev
,
2301 struct ieee80211_channel
*chan
, enum nl80211_channel_type channel_type
)
2303 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2304 struct usbnet
*usbdev
= priv
->usbdev
;
2306 return set_channel(usbdev
,
2307 ieee80211_frequency_to_channel(chan
->center_freq
));
2310 static int rndis_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2311 u8 key_index
, bool pairwise
, const u8
*mac_addr
,
2312 struct key_params
*params
)
2314 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2315 struct usbnet
*usbdev
= priv
->usbdev
;
2318 netdev_dbg(usbdev
->net
, "%s(%i, %pM, %08x)\n",
2319 __func__
, key_index
, mac_addr
, params
->cipher
);
2321 switch (params
->cipher
) {
2322 case WLAN_CIPHER_SUITE_WEP40
:
2323 case WLAN_CIPHER_SUITE_WEP104
:
2324 return add_wep_key(usbdev
, params
->key
, params
->key_len
,
2326 case WLAN_CIPHER_SUITE_TKIP
:
2327 case WLAN_CIPHER_SUITE_CCMP
:
2330 if (params
->seq
&& params
->seq_len
> 0)
2331 flags
|= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ
;
2333 flags
|= NDIS_80211_ADDKEY_PAIRWISE_KEY
|
2334 NDIS_80211_ADDKEY_TRANSMIT_KEY
;
2336 return add_wpa_key(usbdev
, params
->key
, params
->key_len
,
2337 key_index
, mac_addr
, params
->seq
,
2338 params
->seq_len
, params
->cipher
, flags
);
2340 netdev_dbg(usbdev
->net
, "%s(): unsupported cipher %08x\n",
2341 __func__
, params
->cipher
);
2346 static int rndis_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2347 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
2349 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2350 struct usbnet
*usbdev
= priv
->usbdev
;
2352 netdev_dbg(usbdev
->net
, "%s(%i, %pM)\n", __func__
, key_index
, mac_addr
);
2354 return remove_key(usbdev
, key_index
, mac_addr
);
2357 static int rndis_set_default_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
2360 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2361 struct usbnet
*usbdev
= priv
->usbdev
;
2362 struct rndis_wlan_encr_key key
;
2364 netdev_dbg(usbdev
->net
, "%s(%i)\n", __func__
, key_index
);
2366 priv
->encr_tx_key_index
= key_index
;
2368 key
= priv
->encr_keys
[key_index
];
2370 return add_wep_key(usbdev
, key
.material
, key
.len
, key_index
);
2373 static void rndis_fill_station_info(struct usbnet
*usbdev
,
2374 struct station_info
*sinfo
)
2376 __le32 linkspeed
, rssi
;
2379 memset(sinfo
, 0, sizeof(*sinfo
));
2381 len
= sizeof(linkspeed
);
2382 ret
= rndis_query_oid(usbdev
, OID_GEN_LINK_SPEED
, &linkspeed
, &len
);
2384 sinfo
->txrate
.legacy
= le32_to_cpu(linkspeed
) / 1000;
2385 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
2389 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2391 sinfo
->signal
= level_to_qual(le32_to_cpu(rssi
));
2392 sinfo
->filled
|= STATION_INFO_SIGNAL
;
2396 static int rndis_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2397 u8
*mac
, struct station_info
*sinfo
)
2399 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2400 struct usbnet
*usbdev
= priv
->usbdev
;
2402 if (compare_ether_addr(priv
->bssid
, mac
))
2405 rndis_fill_station_info(usbdev
, sinfo
);
2410 static int rndis_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
2411 int idx
, u8
*mac
, struct station_info
*sinfo
)
2413 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2414 struct usbnet
*usbdev
= priv
->usbdev
;
2419 memcpy(mac
, priv
->bssid
, ETH_ALEN
);
2421 rndis_fill_station_info(usbdev
, sinfo
);
2426 static int rndis_set_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
2427 struct cfg80211_pmksa
*pmksa
)
2429 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2430 struct usbnet
*usbdev
= priv
->usbdev
;
2431 struct ndis_80211_pmkid
*pmkids
;
2432 u32
*tmp
= (u32
*)pmksa
->pmkid
;
2434 netdev_dbg(usbdev
->net
, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__
,
2436 cpu_to_be32(tmp
[0]), cpu_to_be32(tmp
[1]),
2437 cpu_to_be32(tmp
[2]), cpu_to_be32(tmp
[3]));
2439 pmkids
= get_device_pmkids(usbdev
);
2440 if (IS_ERR(pmkids
)) {
2441 /* couldn't read PMKID cache from device */
2442 return PTR_ERR(pmkids
);
2445 pmkids
= update_pmkid(usbdev
, pmkids
, pmksa
, wiphy
->max_num_pmkids
);
2446 if (IS_ERR(pmkids
)) {
2447 /* not found, list full, etc */
2448 return PTR_ERR(pmkids
);
2451 return set_device_pmkids(usbdev
, pmkids
);
2454 static int rndis_del_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
,
2455 struct cfg80211_pmksa
*pmksa
)
2457 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2458 struct usbnet
*usbdev
= priv
->usbdev
;
2459 struct ndis_80211_pmkid
*pmkids
;
2460 u32
*tmp
= (u32
*)pmksa
->pmkid
;
2462 netdev_dbg(usbdev
->net
, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__
,
2464 cpu_to_be32(tmp
[0]), cpu_to_be32(tmp
[1]),
2465 cpu_to_be32(tmp
[2]), cpu_to_be32(tmp
[3]));
2467 pmkids
= get_device_pmkids(usbdev
);
2468 if (IS_ERR(pmkids
)) {
2469 /* Couldn't read PMKID cache from device */
2470 return PTR_ERR(pmkids
);
2473 pmkids
= remove_pmkid(usbdev
, pmkids
, pmksa
, wiphy
->max_num_pmkids
);
2474 if (IS_ERR(pmkids
)) {
2475 /* not found, etc */
2476 return PTR_ERR(pmkids
);
2479 return set_device_pmkids(usbdev
, pmkids
);
2482 static int rndis_flush_pmksa(struct wiphy
*wiphy
, struct net_device
*netdev
)
2484 struct rndis_wlan_private
*priv
= wiphy_priv(wiphy
);
2485 struct usbnet
*usbdev
= priv
->usbdev
;
2486 struct ndis_80211_pmkid pmkid
;
2488 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
2490 memset(&pmkid
, 0, sizeof(pmkid
));
2492 pmkid
.length
= cpu_to_le32(sizeof(pmkid
));
2493 pmkid
.bssid_info_count
= cpu_to_le32(0);
2495 return rndis_set_oid(usbdev
, OID_802_11_PMKID
, &pmkid
, sizeof(pmkid
));
2499 * workers, indication handlers, device poller
2501 static void rndis_wlan_do_link_up_work(struct usbnet
*usbdev
)
2503 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2504 struct ndis_80211_assoc_info
*info
= NULL
;
2506 int resp_ie_len
, req_ie_len
;
2507 u8
*req_ie
, *resp_ie
;
2509 bool roamed
= false;
2511 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
&& priv
->connected
) {
2512 /* received media connect indication while connected, either
2513 * device reassociated with same AP or roamed to new. */
2522 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2523 info
= kzalloc(CONTROL_BUFFER_SIZE
, GFP_KERNEL
);
2525 /* No memory? Try resume work later */
2526 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
2527 queue_work(priv
->workqueue
, &priv
->work
);
2531 /* Get association info IEs from device. */
2532 ret
= get_association_info(usbdev
, info
, CONTROL_BUFFER_SIZE
);
2534 req_ie_len
= le32_to_cpu(info
->req_ie_length
);
2535 if (req_ie_len
> 0) {
2536 offset
= le32_to_cpu(info
->offset_req_ies
);
2538 if (offset
> CONTROL_BUFFER_SIZE
)
2539 offset
= CONTROL_BUFFER_SIZE
;
2541 req_ie
= (u8
*)info
+ offset
;
2543 if (offset
+ req_ie_len
> CONTROL_BUFFER_SIZE
)
2545 CONTROL_BUFFER_SIZE
- offset
;
2548 resp_ie_len
= le32_to_cpu(info
->resp_ie_length
);
2549 if (resp_ie_len
> 0) {
2550 offset
= le32_to_cpu(info
->offset_resp_ies
);
2552 if (offset
> CONTROL_BUFFER_SIZE
)
2553 offset
= CONTROL_BUFFER_SIZE
;
2555 resp_ie
= (u8
*)info
+ offset
;
2557 if (offset
+ resp_ie_len
> CONTROL_BUFFER_SIZE
)
2559 CONTROL_BUFFER_SIZE
- offset
;
2562 } else if (WARN_ON(priv
->infra_mode
!= NDIS_80211_INFRA_ADHOC
))
2565 ret
= get_bssid(usbdev
, bssid
);
2567 memset(bssid
, 0, sizeof(bssid
));
2569 netdev_dbg(usbdev
->net
, "link up work: [%pM]%s\n",
2570 bssid
, roamed
? " roamed" : "");
2572 /* Internal bss list in device always contains at least the currently
2573 * connected bss and we can get it to cfg80211 with
2574 * rndis_check_bssid_list().
2575 * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
2578 rndis_check_bssid_list(usbdev
);
2580 if (priv
->infra_mode
== NDIS_80211_INFRA_INFRA
) {
2582 cfg80211_connect_result(usbdev
->net
, bssid
, req_ie
,
2583 req_ie_len
, resp_ie
,
2584 resp_ie_len
, 0, GFP_KERNEL
);
2586 cfg80211_roamed(usbdev
->net
, bssid
, req_ie
, req_ie_len
,
2587 resp_ie
, resp_ie_len
, GFP_KERNEL
);
2588 } else if (priv
->infra_mode
== NDIS_80211_INFRA_ADHOC
)
2589 cfg80211_ibss_joined(usbdev
->net
, bssid
, GFP_KERNEL
);
2594 priv
->connected
= true;
2595 memcpy(priv
->bssid
, bssid
, ETH_ALEN
);
2597 usbnet_resume_rx(usbdev
);
2598 netif_carrier_on(usbdev
->net
);
2601 static void rndis_wlan_do_link_down_work(struct usbnet
*usbdev
)
2603 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2605 if (priv
->connected
) {
2606 priv
->connected
= false;
2607 memset(priv
->bssid
, 0, ETH_ALEN
);
2609 deauthenticate(usbdev
);
2611 cfg80211_disconnected(usbdev
->net
, 0, NULL
, 0, GFP_KERNEL
);
2614 netif_carrier_off(usbdev
->net
);
2617 static void rndis_wlan_worker(struct work_struct
*work
)
2619 struct rndis_wlan_private
*priv
=
2620 container_of(work
, struct rndis_wlan_private
, work
);
2621 struct usbnet
*usbdev
= priv
->usbdev
;
2623 if (test_and_clear_bit(WORK_LINK_UP
, &priv
->work_pending
))
2624 rndis_wlan_do_link_up_work(usbdev
);
2626 if (test_and_clear_bit(WORK_LINK_DOWN
, &priv
->work_pending
))
2627 rndis_wlan_do_link_down_work(usbdev
);
2629 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2630 set_multicast_list(usbdev
);
2633 static void rndis_wlan_set_multicast_list(struct net_device
*dev
)
2635 struct usbnet
*usbdev
= netdev_priv(dev
);
2636 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2638 if (test_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
))
2641 set_bit(WORK_SET_MULTICAST_LIST
, &priv
->work_pending
);
2642 queue_work(priv
->workqueue
, &priv
->work
);
2645 static void rndis_wlan_auth_indication(struct usbnet
*usbdev
,
2646 struct ndis_80211_status_indication
*indication
,
2651 int flags
, buflen
, key_id
;
2652 bool pairwise_error
, group_error
;
2653 struct ndis_80211_auth_request
*auth_req
;
2654 enum nl80211_key_type key_type
;
2656 /* must have at least one array entry */
2657 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2658 sizeof(struct ndis_80211_auth_request
)) {
2659 netdev_info(usbdev
->net
, "authentication indication: too short message (%i)\n",
2664 buf
= (void *)&indication
->u
.auth_request
[0];
2665 buflen
= len
- offsetof(struct ndis_80211_status_indication
, u
);
2667 while (buflen
>= sizeof(*auth_req
)) {
2668 auth_req
= (void *)buf
;
2670 flags
= le32_to_cpu(auth_req
->flags
);
2671 pairwise_error
= false;
2672 group_error
= false;
2675 type
= "reauth request";
2677 type
= "key update request";
2679 pairwise_error
= true;
2680 type
= "pairwise_error";
2684 type
= "group_error";
2687 netdev_info(usbdev
->net
, "authentication indication: %s (0x%08x)\n",
2688 type
, le32_to_cpu(auth_req
->flags
));
2690 if (pairwise_error
) {
2691 key_type
= NL80211_KEYTYPE_PAIRWISE
;
2694 cfg80211_michael_mic_failure(usbdev
->net
,
2696 key_type
, key_id
, NULL
,
2701 key_type
= NL80211_KEYTYPE_GROUP
;
2704 cfg80211_michael_mic_failure(usbdev
->net
,
2706 key_type
, key_id
, NULL
,
2710 buflen
-= le32_to_cpu(auth_req
->length
);
2711 buf
+= le32_to_cpu(auth_req
->length
);
2715 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet
*usbdev
,
2716 struct ndis_80211_status_indication
*indication
,
2719 struct ndis_80211_pmkid_cand_list
*cand_list
;
2720 int list_len
, expected_len
, i
;
2722 if (len
< offsetof(struct ndis_80211_status_indication
, u
) +
2723 sizeof(struct ndis_80211_pmkid_cand_list
)) {
2724 netdev_info(usbdev
->net
, "pmkid candidate list indication: too short message (%i)\n",
2729 list_len
= le32_to_cpu(indication
->u
.cand_list
.num_candidates
) *
2730 sizeof(struct ndis_80211_pmkid_candidate
);
2731 expected_len
= sizeof(struct ndis_80211_pmkid_cand_list
) + list_len
+
2732 offsetof(struct ndis_80211_status_indication
, u
);
2734 if (len
< expected_len
) {
2735 netdev_info(usbdev
->net
, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
2740 cand_list
= &indication
->u
.cand_list
;
2742 netdev_info(usbdev
->net
, "pmkid candidate list indication: version %i, candidates %i\n",
2743 le32_to_cpu(cand_list
->version
),
2744 le32_to_cpu(cand_list
->num_candidates
));
2746 if (le32_to_cpu(cand_list
->version
) != 1)
2749 for (i
= 0; i
< le32_to_cpu(cand_list
->num_candidates
); i
++) {
2750 struct ndis_80211_pmkid_candidate
*cand
=
2751 &cand_list
->candidate_list
[i
];
2753 netdev_dbg(usbdev
->net
, "cand[%i]: flags: 0x%08x, bssid: %pM\n",
2754 i
, le32_to_cpu(cand
->flags
), cand
->bssid
);
2757 struct iw_pmkid_cand pcand
;
2758 union iwreq_data wrqu
;
2760 memset(&pcand
, 0, sizeof(pcand
));
2761 if (le32_to_cpu(cand
->flags
) & 0x01)
2762 pcand
.flags
|= IW_PMKID_CAND_PREAUTH
;
2764 memcpy(pcand
.bssid
.sa_data
, cand
->bssid
, ETH_ALEN
);
2766 memset(&wrqu
, 0, sizeof(wrqu
));
2767 wrqu
.data
.length
= sizeof(pcand
);
2768 wireless_send_event(usbdev
->net
, IWEVPMKIDCAND
, &wrqu
,
2774 static void rndis_wlan_media_specific_indication(struct usbnet
*usbdev
,
2775 struct rndis_indicate
*msg
, int buflen
)
2777 struct ndis_80211_status_indication
*indication
;
2780 offset
= offsetof(struct rndis_indicate
, status
) +
2781 le32_to_cpu(msg
->offset
);
2782 len
= le32_to_cpu(msg
->length
);
2785 netdev_info(usbdev
->net
, "media specific indication, ignore too short message (%i < 8)\n",
2790 if (offset
+ len
> buflen
) {
2791 netdev_info(usbdev
->net
, "media specific indication, too large to fit to buffer (%i > %i)\n",
2792 offset
+ len
, buflen
);
2796 indication
= (void *)((u8
*)msg
+ offset
);
2798 switch (le32_to_cpu(indication
->status_type
)) {
2799 case NDIS_80211_STATUSTYPE_RADIOSTATE
:
2800 netdev_info(usbdev
->net
, "radio state indication: %i\n",
2801 le32_to_cpu(indication
->u
.radio_status
));
2804 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE
:
2805 netdev_info(usbdev
->net
, "media stream mode indication: %i\n",
2806 le32_to_cpu(indication
->u
.media_stream_mode
));
2809 case NDIS_80211_STATUSTYPE_AUTHENTICATION
:
2810 rndis_wlan_auth_indication(usbdev
, indication
, len
);
2813 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST
:
2814 rndis_wlan_pmkid_cand_list_indication(usbdev
, indication
, len
);
2818 netdev_info(usbdev
->net
, "media specific indication: unknown status type 0x%08x\n",
2819 le32_to_cpu(indication
->status_type
));
2823 static void rndis_wlan_indication(struct usbnet
*usbdev
, void *ind
, int buflen
)
2825 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2826 struct rndis_indicate
*msg
= ind
;
2828 switch (msg
->status
) {
2829 case RNDIS_STATUS_MEDIA_CONNECT
:
2830 if (priv
->current_command_oid
== OID_802_11_ADD_KEY
) {
2831 /* OID_802_11_ADD_KEY causes sometimes extra
2832 * "media connect" indications which confuses driver
2833 * and userspace to think that device is
2834 * roaming/reassociating when it isn't.
2836 netdev_dbg(usbdev
->net
, "ignored OID_802_11_ADD_KEY triggered 'media connect'\n");
2840 usbnet_pause_rx(usbdev
);
2842 netdev_info(usbdev
->net
, "media connect\n");
2844 /* queue work to avoid recursive calls into rndis_command */
2845 set_bit(WORK_LINK_UP
, &priv
->work_pending
);
2846 queue_work(priv
->workqueue
, &priv
->work
);
2849 case RNDIS_STATUS_MEDIA_DISCONNECT
:
2850 netdev_info(usbdev
->net
, "media disconnect\n");
2852 /* queue work to avoid recursive calls into rndis_command */
2853 set_bit(WORK_LINK_DOWN
, &priv
->work_pending
);
2854 queue_work(priv
->workqueue
, &priv
->work
);
2857 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION
:
2858 rndis_wlan_media_specific_indication(usbdev
, msg
, buflen
);
2862 netdev_info(usbdev
->net
, "indication: 0x%08x\n",
2863 le32_to_cpu(msg
->status
));
2868 static int rndis_wlan_get_caps(struct usbnet
*usbdev
, struct wiphy
*wiphy
)
2873 } networks_supported
;
2874 struct ndis_80211_capability
*caps
;
2875 u8 caps_buf
[sizeof(*caps
) + sizeof(caps
->auth_encr_pair
) * 16];
2876 int len
, retval
, i
, n
;
2877 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2879 /* determine supported modes */
2880 len
= sizeof(networks_supported
);
2881 retval
= rndis_query_oid(usbdev
, OID_802_11_NETWORK_TYPES_SUPPORTED
,
2882 &networks_supported
, &len
);
2884 n
= le32_to_cpu(networks_supported
.num_items
);
2887 for (i
= 0; i
< n
; i
++) {
2888 switch (le32_to_cpu(networks_supported
.items
[i
])) {
2889 case NDIS_80211_TYPE_FREQ_HOP
:
2890 case NDIS_80211_TYPE_DIRECT_SEQ
:
2891 priv
->caps
|= CAP_MODE_80211B
;
2893 case NDIS_80211_TYPE_OFDM_A
:
2894 priv
->caps
|= CAP_MODE_80211A
;
2896 case NDIS_80211_TYPE_OFDM_G
:
2897 priv
->caps
|= CAP_MODE_80211G
;
2903 /* get device 802.11 capabilities, number of PMKIDs */
2904 caps
= (struct ndis_80211_capability
*)caps_buf
;
2905 len
= sizeof(caps_buf
);
2906 retval
= rndis_query_oid(usbdev
, OID_802_11_CAPABILITY
, caps
, &len
);
2908 netdev_dbg(usbdev
->net
, "OID_802_11_CAPABILITY -> len %d, "
2909 "ver %d, pmkids %d, auth-encr-pairs %d\n",
2910 le32_to_cpu(caps
->length
),
2911 le32_to_cpu(caps
->version
),
2912 le32_to_cpu(caps
->num_pmkids
),
2913 le32_to_cpu(caps
->num_auth_encr_pair
));
2914 wiphy
->max_num_pmkids
= le32_to_cpu(caps
->num_pmkids
);
2916 wiphy
->max_num_pmkids
= 0;
2921 #define DEVICE_POLLER_JIFFIES (HZ)
2922 static void rndis_device_poller(struct work_struct
*work
)
2924 struct rndis_wlan_private
*priv
=
2925 container_of(work
, struct rndis_wlan_private
,
2926 dev_poller_work
.work
);
2927 struct usbnet
*usbdev
= priv
->usbdev
;
2930 int update_jiffies
= DEVICE_POLLER_JIFFIES
;
2933 /* Only check/do workaround when connected. Calling is_associated()
2934 * also polls device with rndis_command() and catches for media link
2937 if (!is_associated(usbdev
))
2941 ret
= rndis_query_oid(usbdev
, OID_802_11_RSSI
, &rssi
, &len
);
2943 priv
->last_qual
= level_to_qual(le32_to_cpu(rssi
));
2945 netdev_dbg(usbdev
->net
, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
2946 ret
, le32_to_cpu(rssi
), level_to_qual(le32_to_cpu(rssi
)));
2948 /* Workaround transfer stalls on poor quality links.
2949 * TODO: find right way to fix these stalls (as stalls do not happen
2950 * with ndiswrapper/windows driver). */
2951 if (priv
->param_workaround_interval
> 0 && priv
->last_qual
<= 25) {
2952 /* Decrease stats worker interval to catch stalls.
2953 * faster. Faster than 400-500ms causes packet loss,
2954 * Slower doesn't catch stalls fast enough.
2956 j
= msecs_to_jiffies(priv
->param_workaround_interval
);
2957 if (j
> DEVICE_POLLER_JIFFIES
)
2958 j
= DEVICE_POLLER_JIFFIES
;
2963 /* Send scan OID. Use of both OIDs is required to get device
2966 tmp
= cpu_to_le32(1);
2967 rndis_set_oid(usbdev
, OID_802_11_BSSID_LIST_SCAN
, &tmp
,
2970 len
= CONTROL_BUFFER_SIZE
;
2971 buf
= kmalloc(len
, GFP_KERNEL
);
2975 rndis_query_oid(usbdev
, OID_802_11_BSSID_LIST
, buf
, &len
);
2980 if (update_jiffies
>= HZ
)
2981 update_jiffies
= round_jiffies_relative(update_jiffies
);
2983 j
= round_jiffies_relative(update_jiffies
);
2984 if (abs(j
- update_jiffies
) <= 10)
2988 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
2993 * driver/device initialization
2995 static void rndis_copy_module_params(struct usbnet
*usbdev
)
2997 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
2999 priv
->param_country
[0] = modparam_country
[0];
3000 priv
->param_country
[1] = modparam_country
[1];
3001 priv
->param_country
[2] = 0;
3002 priv
->param_frameburst
= modparam_frameburst
;
3003 priv
->param_afterburner
= modparam_afterburner
;
3004 priv
->param_power_save
= modparam_power_save
;
3005 priv
->param_power_output
= modparam_power_output
;
3006 priv
->param_roamtrigger
= modparam_roamtrigger
;
3007 priv
->param_roamdelta
= modparam_roamdelta
;
3009 priv
->param_country
[0] = toupper(priv
->param_country
[0]);
3010 priv
->param_country
[1] = toupper(priv
->param_country
[1]);
3011 /* doesn't support EU as country code, use FI instead */
3012 if (!strcmp(priv
->param_country
, "EU"))
3013 strcpy(priv
->param_country
, "FI");
3015 if (priv
->param_power_save
< 0)
3016 priv
->param_power_save
= 0;
3017 else if (priv
->param_power_save
> 2)
3018 priv
->param_power_save
= 2;
3020 if (priv
->param_power_output
< 0)
3021 priv
->param_power_output
= 0;
3022 else if (priv
->param_power_output
> 3)
3023 priv
->param_power_output
= 3;
3025 if (priv
->param_roamtrigger
< -80)
3026 priv
->param_roamtrigger
= -80;
3027 else if (priv
->param_roamtrigger
> -60)
3028 priv
->param_roamtrigger
= -60;
3030 if (priv
->param_roamdelta
< 0)
3031 priv
->param_roamdelta
= 0;
3032 else if (priv
->param_roamdelta
> 2)
3033 priv
->param_roamdelta
= 2;
3035 if (modparam_workaround_interval
< 0)
3036 priv
->param_workaround_interval
= 500;
3038 priv
->param_workaround_interval
= modparam_workaround_interval
;
3041 static int bcm4320a_early_init(struct usbnet
*usbdev
)
3043 /* copy module parameters for bcm4320a so that iwconfig reports txpower
3044 * and workaround parameter is copied to private structure correctly.
3046 rndis_copy_module_params(usbdev
);
3048 /* bcm4320a doesn't handle configuration parameters well. Try
3049 * set any and you get partially zeroed mac and broken device.
3055 static int bcm4320b_early_init(struct usbnet
*usbdev
)
3057 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3060 rndis_copy_module_params(usbdev
);
3062 /* Early initialization settings, setting these won't have effect
3063 * if called after generic_rndis_bind().
3066 rndis_set_config_parameter_str(usbdev
, "Country", priv
->param_country
);
3067 rndis_set_config_parameter_str(usbdev
, "FrameBursting",
3068 priv
->param_frameburst
? "1" : "0");
3069 rndis_set_config_parameter_str(usbdev
, "Afterburner",
3070 priv
->param_afterburner
? "1" : "0");
3071 sprintf(buf
, "%d", priv
->param_power_save
);
3072 rndis_set_config_parameter_str(usbdev
, "PowerSaveMode", buf
);
3073 sprintf(buf
, "%d", priv
->param_power_output
);
3074 rndis_set_config_parameter_str(usbdev
, "PwrOut", buf
);
3075 sprintf(buf
, "%d", priv
->param_roamtrigger
);
3076 rndis_set_config_parameter_str(usbdev
, "RoamTrigger", buf
);
3077 sprintf(buf
, "%d", priv
->param_roamdelta
);
3078 rndis_set_config_parameter_str(usbdev
, "RoamDelta", buf
);
3083 /* same as rndis_netdev_ops but with local multicast handler */
3084 static const struct net_device_ops rndis_wlan_netdev_ops
= {
3085 .ndo_open
= usbnet_open
,
3086 .ndo_stop
= usbnet_stop
,
3087 .ndo_start_xmit
= usbnet_start_xmit
,
3088 .ndo_tx_timeout
= usbnet_tx_timeout
,
3089 .ndo_set_mac_address
= eth_mac_addr
,
3090 .ndo_validate_addr
= eth_validate_addr
,
3091 .ndo_set_multicast_list
= rndis_wlan_set_multicast_list
,
3094 static int rndis_wlan_bind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
3096 struct wiphy
*wiphy
;
3097 struct rndis_wlan_private
*priv
;
3101 /* allocate wiphy and rndis private data
3102 * NOTE: We only support a single virtual interface, so wiphy
3103 * and wireless_dev are somewhat synonymous for this device.
3105 wiphy
= wiphy_new(&rndis_config_ops
, sizeof(struct rndis_wlan_private
));
3109 priv
= wiphy_priv(wiphy
);
3110 usbdev
->net
->ieee80211_ptr
= &priv
->wdev
;
3111 priv
->wdev
.wiphy
= wiphy
;
3112 priv
->wdev
.iftype
= NL80211_IFTYPE_STATION
;
3114 /* These have to be initialized before calling generic_rndis_bind().
3115 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
3117 usbdev
->driver_priv
= priv
;
3118 priv
->usbdev
= usbdev
;
3120 mutex_init(&priv
->command_lock
);
3122 /* because rndis_command() sleeps we need to use workqueue */
3123 priv
->workqueue
= create_singlethread_workqueue("rndis_wlan");
3124 INIT_WORK(&priv
->work
, rndis_wlan_worker
);
3125 INIT_DELAYED_WORK(&priv
->dev_poller_work
, rndis_device_poller
);
3126 INIT_DELAYED_WORK(&priv
->scan_work
, rndis_get_scan_results
);
3128 /* try bind rndis_host */
3129 retval
= generic_rndis_bind(usbdev
, intf
, FLAG_RNDIS_PHYM_WIRELESS
);
3133 /* generic_rndis_bind set packet filter to multicast_all+
3134 * promisc mode which doesn't work well for our devices (device
3135 * picks up rssi to closest station instead of to access point).
3137 * rndis_host wants to avoid all OID as much as possible
3138 * so do promisc/multicast handling in rndis_wlan.
3140 usbdev
->net
->netdev_ops
= &rndis_wlan_netdev_ops
;
3142 tmp
= RNDIS_PACKET_TYPE_DIRECTED
| RNDIS_PACKET_TYPE_BROADCAST
;
3143 retval
= rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &tmp
,
3147 retval
= rndis_query_oid(usbdev
, OID_802_3_MAXIMUM_LIST_SIZE
, &tmp
,
3149 priv
->multicast_size
= le32_to_cpu(tmp
);
3150 if (retval
< 0 || priv
->multicast_size
< 0)
3151 priv
->multicast_size
= 0;
3152 if (priv
->multicast_size
> 0)
3153 usbdev
->net
->flags
|= IFF_MULTICAST
;
3155 usbdev
->net
->flags
&= ~IFF_MULTICAST
;
3157 /* fill-out wiphy structure and register w/ cfg80211 */
3158 memcpy(wiphy
->perm_addr
, usbdev
->net
->dev_addr
, ETH_ALEN
);
3159 wiphy
->privid
= rndis_wiphy_privid
;
3160 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
)
3161 | BIT(NL80211_IFTYPE_ADHOC
);
3162 wiphy
->max_scan_ssids
= 1;
3164 /* TODO: fill-out band/encr information based on priv->caps */
3165 rndis_wlan_get_caps(usbdev
, wiphy
);
3167 memcpy(priv
->channels
, rndis_channels
, sizeof(rndis_channels
));
3168 memcpy(priv
->rates
, rndis_rates
, sizeof(rndis_rates
));
3169 priv
->band
.channels
= priv
->channels
;
3170 priv
->band
.n_channels
= ARRAY_SIZE(rndis_channels
);
3171 priv
->band
.bitrates
= priv
->rates
;
3172 priv
->band
.n_bitrates
= ARRAY_SIZE(rndis_rates
);
3173 wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->band
;
3174 wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_UNSPEC
;
3176 memcpy(priv
->cipher_suites
, rndis_cipher_suites
,
3177 sizeof(rndis_cipher_suites
));
3178 wiphy
->cipher_suites
= priv
->cipher_suites
;
3179 wiphy
->n_cipher_suites
= ARRAY_SIZE(rndis_cipher_suites
);
3181 set_wiphy_dev(wiphy
, &usbdev
->udev
->dev
);
3183 if (wiphy_register(wiphy
)) {
3188 set_default_iw_params(usbdev
);
3190 /* set default rts/frag */
3191 rndis_set_wiphy_params(wiphy
,
3192 WIPHY_PARAM_FRAG_THRESHOLD
| WIPHY_PARAM_RTS_THRESHOLD
);
3195 priv
->radio_on
= true;
3196 disassociate(usbdev
, true);
3197 netif_carrier_off(usbdev
->net
);
3202 cancel_delayed_work_sync(&priv
->dev_poller_work
);
3203 cancel_delayed_work_sync(&priv
->scan_work
);
3204 cancel_work_sync(&priv
->work
);
3205 flush_workqueue(priv
->workqueue
);
3206 destroy_workqueue(priv
->workqueue
);
3212 static void rndis_wlan_unbind(struct usbnet
*usbdev
, struct usb_interface
*intf
)
3214 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3216 /* turn radio off */
3217 disassociate(usbdev
, false);
3219 cancel_delayed_work_sync(&priv
->dev_poller_work
);
3220 cancel_delayed_work_sync(&priv
->scan_work
);
3221 cancel_work_sync(&priv
->work
);
3222 flush_workqueue(priv
->workqueue
);
3223 destroy_workqueue(priv
->workqueue
);
3225 rndis_unbind(usbdev
, intf
);
3227 wiphy_unregister(priv
->wdev
.wiphy
);
3228 wiphy_free(priv
->wdev
.wiphy
);
3231 static int rndis_wlan_reset(struct usbnet
*usbdev
)
3233 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3236 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
3238 retval
= rndis_reset(usbdev
);
3240 netdev_warn(usbdev
->net
, "rndis_reset failed: %d\n", retval
);
3242 /* rndis_reset cleared multicast list, so restore here.
3243 (set_multicast_list() also turns on current packet filter) */
3244 set_multicast_list(usbdev
);
3246 queue_delayed_work(priv
->workqueue
, &priv
->dev_poller_work
,
3247 round_jiffies_relative(DEVICE_POLLER_JIFFIES
));
3249 return deauthenticate(usbdev
);
3252 static int rndis_wlan_stop(struct usbnet
*usbdev
)
3254 struct rndis_wlan_private
*priv
= get_rndis_wlan_priv(usbdev
);
3258 netdev_dbg(usbdev
->net
, "%s()\n", __func__
);
3260 retval
= disassociate(usbdev
, false);
3262 priv
->work_pending
= 0;
3263 cancel_delayed_work_sync(&priv
->dev_poller_work
);
3264 cancel_delayed_work_sync(&priv
->scan_work
);
3265 cancel_work_sync(&priv
->work
);
3266 flush_workqueue(priv
->workqueue
);
3268 if (priv
->scan_request
) {
3269 cfg80211_scan_done(priv
->scan_request
, true);
3270 priv
->scan_request
= NULL
;
3273 /* Set current packet filter zero to block receiving data packets from
3276 rndis_set_oid(usbdev
, OID_GEN_CURRENT_PACKET_FILTER
, &filter
,
3282 static const struct driver_info bcm4320b_info
= {
3283 .description
= "Wireless RNDIS device, BCM4320b based",
3284 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3285 FLAG_AVOID_UNLINK_URBS
,
3286 .bind
= rndis_wlan_bind
,
3287 .unbind
= rndis_wlan_unbind
,
3288 .status
= rndis_status
,
3289 .rx_fixup
= rndis_rx_fixup
,
3290 .tx_fixup
= rndis_tx_fixup
,
3291 .reset
= rndis_wlan_reset
,
3292 .stop
= rndis_wlan_stop
,
3293 .early_init
= bcm4320b_early_init
,
3294 .indication
= rndis_wlan_indication
,
3297 static const struct driver_info bcm4320a_info
= {
3298 .description
= "Wireless RNDIS device, BCM4320a based",
3299 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3300 FLAG_AVOID_UNLINK_URBS
,
3301 .bind
= rndis_wlan_bind
,
3302 .unbind
= rndis_wlan_unbind
,
3303 .status
= rndis_status
,
3304 .rx_fixup
= rndis_rx_fixup
,
3305 .tx_fixup
= rndis_tx_fixup
,
3306 .reset
= rndis_wlan_reset
,
3307 .stop
= rndis_wlan_stop
,
3308 .early_init
= bcm4320a_early_init
,
3309 .indication
= rndis_wlan_indication
,
3312 static const struct driver_info rndis_wlan_info
= {
3313 .description
= "Wireless RNDIS device",
3314 .flags
= FLAG_WLAN
| FLAG_FRAMING_RN
| FLAG_NO_SETINT
|
3315 FLAG_AVOID_UNLINK_URBS
,
3316 .bind
= rndis_wlan_bind
,
3317 .unbind
= rndis_wlan_unbind
,
3318 .status
= rndis_status
,
3319 .rx_fixup
= rndis_rx_fixup
,
3320 .tx_fixup
= rndis_tx_fixup
,
3321 .reset
= rndis_wlan_reset
,
3322 .stop
= rndis_wlan_stop
,
3323 .early_init
= bcm4320a_early_init
,
3324 .indication
= rndis_wlan_indication
,
3327 /*-------------------------------------------------------------------------*/
3329 static const struct usb_device_id products
[] = {
3330 #define RNDIS_MASTER_INTERFACE \
3331 .bInterfaceClass = USB_CLASS_COMM, \
3332 .bInterfaceSubClass = 2 /* ACM */, \
3333 .bInterfaceProtocol = 0x0ff
3335 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3336 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3339 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3340 | USB_DEVICE_ID_MATCH_DEVICE
,
3342 .idProduct
= 0x00bc, /* Buffalo WLI-U2-KG125S */
3343 RNDIS_MASTER_INTERFACE
,
3344 .driver_info
= (unsigned long) &bcm4320b_info
,
3346 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3347 | USB_DEVICE_ID_MATCH_DEVICE
,
3349 .idProduct
= 0x011b, /* U.S. Robotics USR5421 */
3350 RNDIS_MASTER_INTERFACE
,
3351 .driver_info
= (unsigned long) &bcm4320b_info
,
3353 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3354 | USB_DEVICE_ID_MATCH_DEVICE
,
3356 .idProduct
= 0x011b, /* Belkin F5D7051 */
3357 RNDIS_MASTER_INTERFACE
,
3358 .driver_info
= (unsigned long) &bcm4320b_info
,
3360 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3361 | USB_DEVICE_ID_MATCH_DEVICE
,
3362 .idVendor
= 0x1799, /* Belkin has two vendor ids */
3363 .idProduct
= 0x011b, /* Belkin F5D7051 */
3364 RNDIS_MASTER_INTERFACE
,
3365 .driver_info
= (unsigned long) &bcm4320b_info
,
3367 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3368 | USB_DEVICE_ID_MATCH_DEVICE
,
3370 .idProduct
= 0x0014, /* Linksys WUSB54GSv2 */
3371 RNDIS_MASTER_INTERFACE
,
3372 .driver_info
= (unsigned long) &bcm4320b_info
,
3374 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3375 | USB_DEVICE_ID_MATCH_DEVICE
,
3377 .idProduct
= 0x0026, /* Linksys WUSB54GSC */
3378 RNDIS_MASTER_INTERFACE
,
3379 .driver_info
= (unsigned long) &bcm4320b_info
,
3381 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3382 | USB_DEVICE_ID_MATCH_DEVICE
,
3384 .idProduct
= 0x1717, /* Asus WL169gE */
3385 RNDIS_MASTER_INTERFACE
,
3386 .driver_info
= (unsigned long) &bcm4320b_info
,
3388 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3389 | USB_DEVICE_ID_MATCH_DEVICE
,
3391 .idProduct
= 0xd11b, /* Eminent EM4045 */
3392 RNDIS_MASTER_INTERFACE
,
3393 .driver_info
= (unsigned long) &bcm4320b_info
,
3395 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3396 | USB_DEVICE_ID_MATCH_DEVICE
,
3398 .idProduct
= 0x0715, /* BT Voyager 1055 */
3399 RNDIS_MASTER_INTERFACE
,
3400 .driver_info
= (unsigned long) &bcm4320b_info
,
3402 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3403 * parameters available, hardware probably contain older firmware version with
3404 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3407 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3408 | USB_DEVICE_ID_MATCH_DEVICE
,
3410 .idProduct
= 0x000e, /* Linksys WUSB54GSv1 */
3411 RNDIS_MASTER_INTERFACE
,
3412 .driver_info
= (unsigned long) &bcm4320a_info
,
3414 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3415 | USB_DEVICE_ID_MATCH_DEVICE
,
3417 .idProduct
= 0x0111, /* U.S. Robotics USR5420 */
3418 RNDIS_MASTER_INTERFACE
,
3419 .driver_info
= (unsigned long) &bcm4320a_info
,
3421 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
3422 | USB_DEVICE_ID_MATCH_DEVICE
,
3424 .idProduct
= 0x004b, /* BUFFALO WLI-USB-G54 */
3425 RNDIS_MASTER_INTERFACE
,
3426 .driver_info
= (unsigned long) &bcm4320a_info
,
3428 /* Generic Wireless RNDIS devices that we don't have exact
3429 * idVendor/idProduct/chip yet.
3432 /* RNDIS is MSFT's un-official variant of CDC ACM */
3433 USB_INTERFACE_INFO(USB_CLASS_COMM
, 2 /* ACM */, 0x0ff),
3434 .driver_info
= (unsigned long) &rndis_wlan_info
,
3436 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3437 USB_INTERFACE_INFO(USB_CLASS_MISC
, 1, 1),
3438 .driver_info
= (unsigned long) &rndis_wlan_info
,
3442 MODULE_DEVICE_TABLE(usb
, products
);
3444 static struct usb_driver rndis_wlan_driver
= {
3445 .name
= "rndis_wlan",
3446 .id_table
= products
,
3447 .probe
= usbnet_probe
,
3448 .disconnect
= usbnet_disconnect
,
3449 .suspend
= usbnet_suspend
,
3450 .resume
= usbnet_resume
,
3453 static int __init
rndis_wlan_init(void)
3455 return usb_register(&rndis_wlan_driver
);
3457 module_init(rndis_wlan_init
);
3459 static void __exit
rndis_wlan_exit(void)
3461 usb_deregister(&rndis_wlan_driver
);
3463 module_exit(rndis_wlan_exit
);
3465 MODULE_AUTHOR("Bjorge Dijkstra");
3466 MODULE_AUTHOR("Jussi Kivilinna");
3467 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3468 MODULE_LICENSE("GPL");