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/ieee80211.h>
40 #include <linux/if_arp.h>
41 #include <linux/ctype.h>
42 #include <linux/spinlock.h>
43 #include <linux/slab.h>
44 #include <net/cfg80211.h>
45 #include <linux/usb/usbnet.h>
46 #include <linux/usb/rndis_host.h>
49 /* NOTE: All these are settings for Broadcom chipset */
50 static char modparam_country[4] = "EU";
51 module_param_string(country, modparam_country, 4, 0444);
52 MODULE_PARM_DESC(country, "Country code (ISO 3166-1 alpha-2), default: EU");
54 static int modparam_frameburst = 1;
55 module_param_named(frameburst, modparam_frameburst, int, 0444);
56 MODULE_PARM_DESC(frameburst, "enable frame bursting (default: on)");
58 static int modparam_afterburner = 0;
59 module_param_named(afterburner, modparam_afterburner, int, 0444);
60 MODULE_PARM_DESC(afterburner,
61 "enable afterburner aka '125 High Speed Mode' (default: off)");
63 static int modparam_power_save = 0;
64 module_param_named(power_save, modparam_power_save, int, 0444);
65 MODULE_PARM_DESC(power_save,
66 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
68 static int modparam_power_output = 3;
69 module_param_named(power_output, modparam_power_output, int, 0444);
70 MODULE_PARM_DESC(power_output,
71 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
73 static int modparam_roamtrigger = -70;
74 module_param_named(roamtrigger, modparam_roamtrigger, int, 0444);
75 MODULE_PARM_DESC(roamtrigger,
76 "set roaming dBm trigger: -80=optimize for distance, "
77 "-60=bandwidth (default: -70)");
79 static int modparam_roamdelta = 1;
80 module_param_named(roamdelta, modparam_roamdelta, int, 0444);
81 MODULE_PARM_DESC(roamdelta,
82 "set roaming tendency: 0=aggressive, 1=moderate, "
83 "2=conservative (default: moderate)");
85 static int modparam_workaround_interval;
86 module_param_named(workaround_interval, modparam_workaround_interval,
88 MODULE_PARM_DESC(workaround_interval,
89 "set stall workaround interval in msecs (0=disabled) (default: 0)");
92 /* various RNDIS OID defs */
93 #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
94 #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
96 #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101)
97 #define OID_GEN_RCV_OK cpu_to_le32(0x00020102)
98 #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103)
99 #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104)
100 #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105)
102 #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
103 #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
104 #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
106 #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
107 #define OID_802_11_SSID cpu_to_le32(0x0d010102)
108 #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
109 #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
110 #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
111 #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
112 #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
113 #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
114 #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
115 #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
116 #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
117 #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
118 #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
119 #define OID_802_11_CAPABILITY cpu_to_le32(0x0d010122)
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_POWER_MODE cpu_to_le32(0x0d010216)
131 #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
134 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
135 #define WL_NOISE -96 /* typical noise level in dBm */
136 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
139 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
140 * based on wireless rndis) has default txpower of 13dBm.
141 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
142 * 100% : 20 mW ~ 13dBm
143 * 75% : 15 mW ~ 12dBm
144 * 50% : 10 mW ~ 10dBm
147 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
148 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
149 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
150 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
153 /* codes for "status" field of completion messages */
154 #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
155 #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
158 /* Known device types */
159 #define RNDIS_UNKNOWN 0
160 #define RNDIS_BCM4320A 1
161 #define RNDIS_BCM4320B 2
164 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
165 * slightly modified for datatype endianess, etc
167 #define NDIS_802_11_LENGTH_SSID 32
168 #define NDIS_802_11_LENGTH_RATES 8
169 #define NDIS_802_11_LENGTH_RATES_EX 16
171 enum ndis_80211_net_type {
172 NDIS_80211_TYPE_FREQ_HOP,
173 NDIS_80211_TYPE_DIRECT_SEQ,
174 NDIS_80211_TYPE_OFDM_A,
175 NDIS_80211_TYPE_OFDM_G
178 enum ndis_80211_net_infra {
179 NDIS_80211_INFRA_ADHOC,
180 NDIS_80211_INFRA_INFRA,
181 NDIS_80211_INFRA_AUTO_UNKNOWN
184 enum ndis_80211_auth_mode {
185 NDIS_80211_AUTH_OPEN,
186 NDIS_80211_AUTH_SHARED,
187 NDIS_80211_AUTH_AUTO_SWITCH,
189 NDIS_80211_AUTH_WPA_PSK,
190 NDIS_80211_AUTH_WPA_NONE,
191 NDIS_80211_AUTH_WPA2,
192 NDIS_80211_AUTH_WPA2_PSK
195 enum ndis_80211_encr_status {
196 NDIS_80211_ENCR_WEP_ENABLED,
197 NDIS_80211_ENCR_DISABLED,
198 NDIS_80211_ENCR_WEP_KEY_ABSENT,
199 NDIS_80211_ENCR_NOT_SUPPORTED,
200 NDIS_80211_ENCR_TKIP_ENABLED,
201 NDIS_80211_ENCR_TKIP_KEY_ABSENT,
202 NDIS_80211_ENCR_CCMP_ENABLED,
203 NDIS_80211_ENCR_CCMP_KEY_ABSENT
206 enum ndis_80211_priv_filter {
207 NDIS_80211_PRIV_ACCEPT_ALL,
208 NDIS_80211_PRIV_8021X_WEP
211 enum ndis_80211_status_type {
212 NDIS_80211_STATUSTYPE_AUTHENTICATION,
213 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE,
214 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST,
215 NDIS_80211_STATUSTYPE_RADIOSTATE,
218 enum ndis_80211_media_stream_mode {
219 NDIS_80211_MEDIA_STREAM_OFF,
220 NDIS_80211_MEDIA_STREAM_ON
223 enum ndis_80211_radio_status {
224 NDIS_80211_RADIO_STATUS_ON,
225 NDIS_80211_RADIO_STATUS_HARDWARE_OFF,
226 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF,
229 enum ndis_80211_addkey_bits {
230 NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
231 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
232 NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
233 NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
236 enum ndis_80211_addwep_bits {
237 NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
238 NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
241 enum ndis_80211_power_mode {
242 NDIS_80211_POWER_MODE_CAM,
243 NDIS_80211_POWER_MODE_MAX_PSP,
244 NDIS_80211_POWER_MODE_FAST_PSP,
247 enum ndis_80211_pmkid_cand_list_flag_bits {
248 NDIS_80211_PMKID_CAND_PREAUTH = cpu_to_le32(1 << 0)
251 struct ndis_80211_auth_request {
258 struct ndis_80211_pmkid_candidate {
264 struct ndis_80211_pmkid_cand_list {
266 __le32 num_candidates;
267 struct ndis_80211_pmkid_candidate candidate_list[0];
270 struct ndis_80211_status_indication {
273 __le32 media_stream_mode;
275 struct ndis_80211_auth_request auth_request[0];
276 struct ndis_80211_pmkid_cand_list cand_list;
280 struct ndis_80211_ssid {
282 u8 essid[NDIS_802_11_LENGTH_SSID];
285 struct ndis_80211_conf_freq_hop {
292 struct ndis_80211_conf {
294 __le32 beacon_period;
297 struct ndis_80211_conf_freq_hop fh_config;
300 struct ndis_80211_bssid_ex {
304 struct ndis_80211_ssid ssid;
308 struct ndis_80211_conf config;
310 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
315 struct ndis_80211_bssid_list_ex {
317 struct ndis_80211_bssid_ex bssid[0];
320 struct ndis_80211_fixed_ies {
322 __le16 beacon_interval;
326 struct ndis_80211_wep_key {
333 struct ndis_80211_key {
343 struct ndis_80211_remove_key {
350 struct ndis_config_param {
358 struct ndis_80211_assoc_info {
363 __le16 listen_interval;
364 u8 cur_ap_address[6];
366 __le32 req_ie_length;
367 __le32 offset_req_ies;
374 __le32 resp_ie_length;
375 __le32 offset_resp_ies;
378 struct ndis_80211_auth_encr_pair {
383 struct ndis_80211_capability {
387 __le32 num_auth_encr_pair;
388 struct ndis_80211_auth_encr_pair auth_encr_pair[0];
391 struct ndis_80211_bssid_info {
396 struct ndis_80211_pmkid {
398 __le32 bssid_info_count;
399 struct ndis_80211_bssid_info bssid_info[0];
405 #define CAP_MODE_80211A 1
406 #define CAP_MODE_80211B 2
407 #define CAP_MODE_80211G 4
408 #define CAP_MODE_MASK 7
410 #define WORK_LINK_UP (1<<0)
411 #define WORK_LINK_DOWN (1<<1)
412 #define WORK_SET_MULTICAST_LIST (1<<2)
414 #define RNDIS_WLAN_ALG_NONE 0
415 #define RNDIS_WLAN_ALG_WEP (1<<0)
416 #define RNDIS_WLAN_ALG_TKIP (1<<1)
417 #define RNDIS_WLAN_ALG_CCMP (1<<2)
419 #define RNDIS_WLAN_NUM_KEYS 4
420 #define RNDIS_WLAN_KEY_MGMT_NONE 0
421 #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
422 #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
424 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
426 static const struct ieee80211_channel rndis_channels[] = {
427 { .center_freq = 2412 },
428 { .center_freq = 2417 },
429 { .center_freq = 2422 },
430 { .center_freq = 2427 },
431 { .center_freq = 2432 },
432 { .center_freq = 2437 },
433 { .center_freq = 2442 },
434 { .center_freq = 2447 },
435 { .center_freq = 2452 },
436 { .center_freq = 2457 },
437 { .center_freq = 2462 },
438 { .center_freq = 2467 },
439 { .center_freq = 2472 },
440 { .center_freq = 2484 },
443 static const struct ieee80211_rate rndis_rates[] = {
445 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
446 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
447 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
458 static const u32 rndis_cipher_suites[] = {
459 WLAN_CIPHER_SUITE_WEP40,
460 WLAN_CIPHER_SUITE_WEP104,
461 WLAN_CIPHER_SUITE_TKIP,
462 WLAN_CIPHER_SUITE_CCMP,
465 struct rndis_wlan_encr_key {
474 /* RNDIS device private data */
475 struct rndis_wlan_private {
476 struct usbnet *usbdev;
478 struct wireless_dev wdev;
480 struct cfg80211_scan_request *scan_request;
482 struct workqueue_struct *workqueue;
483 struct delayed_work dev_poller_work;
484 struct delayed_work scan_work;
485 struct work_struct work;
486 struct mutex command_lock;
487 unsigned long work_pending;
491 int last_cqm_event_rssi;
493 struct ieee80211_supported_band band;
494 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
495 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
496 u32 cipher_suites[ARRAY_SIZE(rndis_cipher_suites)];
502 /* module parameters */
503 char param_country[4];
504 int param_frameburst;
505 int param_afterburner;
506 int param_power_save;
507 int param_power_output;
508 int param_roamtrigger;
510 u32 param_workaround_interval;
518 __le32 current_command_oid;
520 /* encryption stuff */
521 int encr_tx_key_index;
522 struct rndis_wlan_encr_key encr_keys[RNDIS_WLAN_NUM_KEYS];
525 u8 command_buffer[COMMAND_BUFFER_SIZE];
531 static int rndis_change_virtual_intf(struct wiphy *wiphy,
532 struct net_device *dev,
533 enum nl80211_iftype type, u32 *flags,
534 struct vif_params *params);
536 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
537 struct cfg80211_scan_request *request);
539 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
541 static int rndis_set_tx_power(struct wiphy *wiphy,
542 enum nl80211_tx_power_setting type,
544 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
546 static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
547 struct cfg80211_connect_params *sme);
549 static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
552 static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
553 struct cfg80211_ibss_params *params);
555 static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev);
557 static int rndis_set_channel(struct wiphy *wiphy, struct net_device *dev,
558 struct ieee80211_channel *chan, enum nl80211_channel_type channel_type);
560 static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
561 u8 key_index, bool pairwise, const u8 *mac_addr,
562 struct key_params *params);
564 static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
565 u8 key_index, bool pairwise, const u8 *mac_addr);
567 static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
568 u8 key_index, bool unicast, bool multicast);
570 static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
571 u8 *mac, struct station_info *sinfo);
573 static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
574 int idx, u8 *mac, struct station_info *sinfo);
576 static int rndis_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
577 struct cfg80211_pmksa *pmksa);
579 static int rndis_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
580 struct cfg80211_pmksa *pmksa);
582 static int rndis_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev);
584 static int rndis_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
585 bool enabled, int timeout);
587 static int rndis_set_cqm_rssi_config(struct wiphy *wiphy,
588 struct net_device *dev,
589 s32 rssi_thold, u32 rssi_hyst);
591 static const struct cfg80211_ops rndis_config_ops = {
592 .change_virtual_intf = rndis_change_virtual_intf,
594 .set_wiphy_params = rndis_set_wiphy_params,
595 .set_tx_power = rndis_set_tx_power,
596 .get_tx_power = rndis_get_tx_power,
597 .connect = rndis_connect,
598 .disconnect = rndis_disconnect,
599 .join_ibss = rndis_join_ibss,
600 .leave_ibss = rndis_leave_ibss,
601 .set_channel = rndis_set_channel,
602 .add_key = rndis_add_key,
603 .del_key = rndis_del_key,
604 .set_default_key = rndis_set_default_key,
605 .get_station = rndis_get_station,
606 .dump_station = rndis_dump_station,
607 .set_pmksa = rndis_set_pmksa,
608 .del_pmksa = rndis_del_pmksa,
609 .flush_pmksa = rndis_flush_pmksa,
610 .set_power_mgmt = rndis_set_power_mgmt,
611 .set_cqm_rssi_config = rndis_set_cqm_rssi_config,
614 static void *rndis_wiphy_privid = &rndis_wiphy_privid;
617 static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
619 return (struct rndis_wlan_private *)dev->driver_priv;
622 static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
624 switch (priv->param_power_output) {
627 return BCM4320_DEFAULT_TXPOWER_DBM_100;
629 return BCM4320_DEFAULT_TXPOWER_DBM_75;
631 return BCM4320_DEFAULT_TXPOWER_DBM_50;
633 return BCM4320_DEFAULT_TXPOWER_DBM_25;
637 static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
639 int cipher = priv->encr_keys[idx].cipher;
641 return (cipher == WLAN_CIPHER_SUITE_CCMP ||
642 cipher == WLAN_CIPHER_SUITE_TKIP);
645 static int rndis_cipher_to_alg(u32 cipher)
649 return RNDIS_WLAN_ALG_NONE;
650 case WLAN_CIPHER_SUITE_WEP40:
651 case WLAN_CIPHER_SUITE_WEP104:
652 return RNDIS_WLAN_ALG_WEP;
653 case WLAN_CIPHER_SUITE_TKIP:
654 return RNDIS_WLAN_ALG_TKIP;
655 case WLAN_CIPHER_SUITE_CCMP:
656 return RNDIS_WLAN_ALG_CCMP;
660 static int rndis_akm_suite_to_key_mgmt(u32 akm_suite)
664 return RNDIS_WLAN_KEY_MGMT_NONE;
665 case WLAN_AKM_SUITE_8021X:
666 return RNDIS_WLAN_KEY_MGMT_802_1X;
667 case WLAN_AKM_SUITE_PSK:
668 return RNDIS_WLAN_KEY_MGMT_PSK;
673 static const char *oid_to_string(__le32 oid)
676 #define OID_STR(oid) case oid: return(#oid)
677 /* from rndis_host.h */
678 OID_STR(OID_802_3_PERMANENT_ADDRESS);
679 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
680 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
681 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
683 /* from rndis_wlan.c */
684 OID_STR(OID_GEN_LINK_SPEED);
685 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
687 OID_STR(OID_GEN_XMIT_OK);
688 OID_STR(OID_GEN_RCV_OK);
689 OID_STR(OID_GEN_XMIT_ERROR);
690 OID_STR(OID_GEN_RCV_ERROR);
691 OID_STR(OID_GEN_RCV_NO_BUFFER);
693 OID_STR(OID_802_3_CURRENT_ADDRESS);
694 OID_STR(OID_802_3_MULTICAST_LIST);
695 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
697 OID_STR(OID_802_11_BSSID);
698 OID_STR(OID_802_11_SSID);
699 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
700 OID_STR(OID_802_11_ADD_WEP);
701 OID_STR(OID_802_11_REMOVE_WEP);
702 OID_STR(OID_802_11_DISASSOCIATE);
703 OID_STR(OID_802_11_AUTHENTICATION_MODE);
704 OID_STR(OID_802_11_PRIVACY_FILTER);
705 OID_STR(OID_802_11_BSSID_LIST_SCAN);
706 OID_STR(OID_802_11_ENCRYPTION_STATUS);
707 OID_STR(OID_802_11_ADD_KEY);
708 OID_STR(OID_802_11_REMOVE_KEY);
709 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
710 OID_STR(OID_802_11_CAPABILITY);
711 OID_STR(OID_802_11_PMKID);
712 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
713 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
714 OID_STR(OID_802_11_TX_POWER_LEVEL);
715 OID_STR(OID_802_11_RSSI);
716 OID_STR(OID_802_11_RSSI_TRIGGER);
717 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
718 OID_STR(OID_802_11_RTS_THRESHOLD);
719 OID_STR(OID_802_11_SUPPORTED_RATES);
720 OID_STR(OID_802_11_CONFIGURATION);
721 OID_STR(OID_802_11_POWER_MODE);
722 OID_STR(OID_802_11_BSSID_LIST);
729 static const char *oid_to_string(__le32 oid)
735 /* translate error code */
736 static int rndis_error_status(__le32 rndis_status)
739 switch (rndis_status) {
740 case RNDIS_STATUS_SUCCESS:
743 case RNDIS_STATUS_FAILURE:
744 case RNDIS_STATUS_INVALID_DATA:
747 case RNDIS_STATUS_NOT_SUPPORTED:
750 case RNDIS_STATUS_ADAPTER_NOT_READY:
751 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
758 static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
760 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
763 struct rndis_msg_hdr *header;
764 struct rndis_query *get;
765 struct rndis_query_c *get_c;
768 int resplen, respoffs, copylen;
770 buflen = *len + sizeof(*u.get);
771 if (buflen < CONTROL_BUFFER_SIZE)
772 buflen = CONTROL_BUFFER_SIZE;
774 if (buflen > COMMAND_BUFFER_SIZE) {
775 u.buf = kmalloc(buflen, GFP_KERNEL);
779 u.buf = priv->command_buffer;
782 mutex_lock(&priv->command_lock);
784 memset(u.get, 0, sizeof *u.get);
785 u.get->msg_type = RNDIS_MSG_QUERY;
786 u.get->msg_len = cpu_to_le32(sizeof *u.get);
789 priv->current_command_oid = oid;
790 ret = rndis_command(dev, u.header, buflen);
791 priv->current_command_oid = 0;
793 netdev_dbg(dev->net, "%s(%s): rndis_command() failed, %d (%08x)\n",
794 __func__, oid_to_string(oid), ret,
795 le32_to_cpu(u.get_c->status));
798 resplen = le32_to_cpu(u.get_c->len);
799 respoffs = le32_to_cpu(u.get_c->offset) + 8;
801 if (respoffs > buflen) {
802 /* Device returned data offset outside buffer, error. */
803 netdev_dbg(dev->net, "%s(%s): received invalid "
804 "data offset: %d > %d\n", __func__,
805 oid_to_string(oid), respoffs, buflen);
811 if ((resplen + respoffs) > buflen) {
812 /* Device would have returned more data if buffer would
813 * have been big enough. Copy just the bits that we got.
815 copylen = buflen - respoffs;
823 memcpy(data, u.buf + respoffs, copylen);
827 ret = rndis_error_status(u.get_c->status);
829 netdev_dbg(dev->net, "%s(%s): device returned error, 0x%08x (%d)\n",
830 __func__, oid_to_string(oid),
831 le32_to_cpu(u.get_c->status), ret);
835 mutex_unlock(&priv->command_lock);
837 if (u.buf != priv->command_buffer)
842 static int rndis_set_oid(struct usbnet *dev, __le32 oid, const void *data,
845 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
848 struct rndis_msg_hdr *header;
849 struct rndis_set *set;
850 struct rndis_set_c *set_c;
854 buflen = len + sizeof(*u.set);
855 if (buflen < CONTROL_BUFFER_SIZE)
856 buflen = CONTROL_BUFFER_SIZE;
858 if (buflen > COMMAND_BUFFER_SIZE) {
859 u.buf = kmalloc(buflen, GFP_KERNEL);
863 u.buf = priv->command_buffer;
866 mutex_lock(&priv->command_lock);
868 memset(u.set, 0, sizeof *u.set);
869 u.set->msg_type = RNDIS_MSG_SET;
870 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
872 u.set->len = cpu_to_le32(len);
873 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
874 u.set->handle = cpu_to_le32(0);
875 memcpy(u.buf + sizeof(*u.set), data, len);
877 priv->current_command_oid = oid;
878 ret = rndis_command(dev, u.header, buflen);
879 priv->current_command_oid = 0;
881 netdev_dbg(dev->net, "%s(%s): rndis_command() failed, %d (%08x)\n",
882 __func__, oid_to_string(oid), ret,
883 le32_to_cpu(u.set_c->status));
886 ret = rndis_error_status(u.set_c->status);
889 netdev_dbg(dev->net, "%s(%s): device returned error, 0x%08x (%d)\n",
890 __func__, oid_to_string(oid),
891 le32_to_cpu(u.set_c->status), ret);
894 mutex_unlock(&priv->command_lock);
896 if (u.buf != priv->command_buffer)
901 static int rndis_reset(struct usbnet *usbdev)
903 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
904 struct rndis_reset *reset;
907 mutex_lock(&priv->command_lock);
909 reset = (void *)priv->command_buffer;
910 memset(reset, 0, sizeof(*reset));
911 reset->msg_type = RNDIS_MSG_RESET;
912 reset->msg_len = cpu_to_le32(sizeof(*reset));
913 priv->current_command_oid = 0;
914 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
916 mutex_unlock(&priv->command_lock);
924 * Specs say that we can only set config parameters only soon after device
926 * value_type: 0 = u32, 2 = unicode string
928 static int rndis_set_config_parameter(struct usbnet *dev, char *param,
929 int value_type, void *value)
931 struct ndis_config_param *infobuf;
932 int value_len, info_len, param_len, ret, i;
937 value_len = sizeof(__le32);
938 else if (value_type == 2)
939 value_len = strlen(value) * sizeof(__le16);
943 param_len = strlen(param) * sizeof(__le16);
944 info_len = sizeof(*infobuf) + param_len + value_len;
949 infobuf = kmalloc(info_len, GFP_KERNEL);
955 /* extra 12 bytes are for padding (debug output) */
956 memset(infobuf, 0xCC, info_len + 12);
960 netdev_dbg(dev->net, "setting config parameter: %s, value: %s\n",
963 netdev_dbg(dev->net, "setting config parameter: %s, value: %d\n",
964 param, *(u32 *)value);
966 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
967 infobuf->name_length = cpu_to_le32(param_len);
968 infobuf->type = cpu_to_le32(value_type);
969 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
970 infobuf->value_length = cpu_to_le32(value_len);
972 /* simple string to unicode string conversion */
973 unibuf = (void *)infobuf + sizeof(*infobuf);
974 for (i = 0; i < param_len / sizeof(__le16); i++)
975 unibuf[i] = cpu_to_le16(param[i]);
977 if (value_type == 2) {
978 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
979 for (i = 0; i < value_len / sizeof(__le16); i++)
980 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
982 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
983 *dst_value = cpu_to_le32(*(u32 *)value);
987 netdev_dbg(dev->net, "info buffer (len: %d)\n", info_len);
988 for (i = 0; i < info_len; i += 12) {
989 u32 *tmp = (u32 *)((u8 *)infobuf + i);
990 netdev_dbg(dev->net, "%08X:%08X:%08X\n",
993 cpu_to_be32(tmp[2]));
997 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
1000 netdev_dbg(dev->net, "setting rndis config parameter failed, %d\n",
1007 static int rndis_set_config_parameter_str(struct usbnet *dev,
1008 char *param, char *value)
1010 return rndis_set_config_parameter(dev, param, 2, value);
1014 * data conversion functions
1016 static int level_to_qual(int level)
1018 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
1019 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
1025 static int set_infra_mode(struct usbnet *usbdev, int mode);
1026 static void restore_keys(struct usbnet *usbdev);
1027 static int rndis_check_bssid_list(struct usbnet *usbdev, u8 *match_bssid,
1030 static int rndis_start_bssid_list_scan(struct usbnet *usbdev)
1034 /* Note: OID_802_11_BSSID_LIST_SCAN clears internal BSS list. */
1035 tmp = cpu_to_le32(1);
1036 return rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1040 static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
1042 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1045 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
1047 netdev_warn(usbdev->net, "setting SSID failed (%08X)\n", ret);
1051 priv->radio_on = true;
1052 netdev_dbg(usbdev->net, "%s(): radio_on = true\n", __func__);
1058 static int set_bssid(struct usbnet *usbdev, const u8 *bssid)
1062 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1064 netdev_warn(usbdev->net, "setting BSSID[%pM] failed (%08X)\n",
1072 static int clear_bssid(struct usbnet *usbdev)
1074 static const u8 broadcast_mac[ETH_ALEN] = {
1075 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
1078 return set_bssid(usbdev, broadcast_mac);
1081 static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
1086 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
1089 memset(bssid, 0, ETH_ALEN);
1094 static int get_association_info(struct usbnet *usbdev,
1095 struct ndis_80211_assoc_info *info, int len)
1097 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
1101 static bool is_associated(struct usbnet *usbdev)
1103 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1107 if (!priv->radio_on)
1110 ret = get_bssid(usbdev, bssid);
1112 return (ret == 0 && !is_zero_ether_addr(bssid));
1115 static int disassociate(struct usbnet *usbdev, bool reset_ssid)
1117 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1118 struct ndis_80211_ssid ssid;
1121 if (priv->radio_on) {
1122 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
1124 priv->radio_on = false;
1125 netdev_dbg(usbdev->net, "%s(): radio_on = false\n",
1133 /* disassociate causes radio to be turned off; if reset_ssid
1134 * is given, set random ssid to enable radio */
1136 /* Set device to infrastructure mode so we don't get ad-hoc
1137 * 'media connect' indications with the random ssid.
1139 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1141 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1142 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1143 ssid.essid[0] = 0x1;
1144 ssid.essid[1] = 0xff;
1145 for (i = 2; i < sizeof(ssid.essid); i++)
1146 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
1147 ret = set_essid(usbdev, &ssid);
1152 static int set_auth_mode(struct usbnet *usbdev, u32 wpa_version,
1153 enum nl80211_auth_type auth_type, int keymgmt)
1155 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1159 netdev_dbg(usbdev->net, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1160 __func__, wpa_version, auth_type, keymgmt);
1162 if (wpa_version & NL80211_WPA_VERSION_2) {
1163 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
1164 auth_mode = NDIS_80211_AUTH_WPA2;
1166 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
1167 } else if (wpa_version & NL80211_WPA_VERSION_1) {
1168 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
1169 auth_mode = NDIS_80211_AUTH_WPA;
1170 else if (keymgmt & RNDIS_WLAN_KEY_MGMT_PSK)
1171 auth_mode = NDIS_80211_AUTH_WPA_PSK;
1173 auth_mode = NDIS_80211_AUTH_WPA_NONE;
1174 } else if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
1175 auth_mode = NDIS_80211_AUTH_SHARED;
1176 else if (auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
1177 auth_mode = NDIS_80211_AUTH_OPEN;
1178 else if (auth_type == NL80211_AUTHTYPE_AUTOMATIC)
1179 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
1183 tmp = cpu_to_le32(auth_mode);
1184 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1187 netdev_warn(usbdev->net, "setting auth mode failed (%08X)\n",
1192 priv->wpa_version = wpa_version;
1197 static int set_priv_filter(struct usbnet *usbdev)
1199 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1202 netdev_dbg(usbdev->net, "%s(): wpa_version=0x%x\n",
1203 __func__, priv->wpa_version);
1205 if (priv->wpa_version & NL80211_WPA_VERSION_2 ||
1206 priv->wpa_version & NL80211_WPA_VERSION_1)
1207 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
1209 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
1211 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1215 static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1220 netdev_dbg(usbdev->net, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1221 __func__, pairwise, groupwise);
1223 if (pairwise & RNDIS_WLAN_ALG_CCMP)
1224 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1225 else if (pairwise & RNDIS_WLAN_ALG_TKIP)
1226 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1227 else if (pairwise & RNDIS_WLAN_ALG_WEP)
1228 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
1229 else if (groupwise & RNDIS_WLAN_ALG_CCMP)
1230 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1231 else if (groupwise & RNDIS_WLAN_ALG_TKIP)
1232 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1234 encr_mode = NDIS_80211_ENCR_DISABLED;
1236 tmp = cpu_to_le32(encr_mode);
1237 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1240 netdev_warn(usbdev->net, "setting encr mode failed (%08X)\n",
1248 static int set_infra_mode(struct usbnet *usbdev, int mode)
1250 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1254 netdev_dbg(usbdev->net, "%s(): infra_mode=0x%x\n",
1255 __func__, priv->infra_mode);
1257 tmp = cpu_to_le32(mode);
1258 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1261 netdev_warn(usbdev->net, "setting infra mode failed (%08X)\n",
1266 /* NDIS drivers clear keys when infrastructure mode is
1267 * changed. But Linux tools assume otherwise. So set the
1269 restore_keys(usbdev);
1271 priv->infra_mode = mode;
1275 static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1279 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
1281 if (rts_threshold < 0 || rts_threshold > 2347)
1282 rts_threshold = 2347;
1284 tmp = cpu_to_le32(rts_threshold);
1285 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1289 static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1293 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, frag_threshold);
1295 if (frag_threshold < 256 || frag_threshold > 2346)
1296 frag_threshold = 2346;
1298 tmp = cpu_to_le32(frag_threshold);
1299 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1303 static void set_default_iw_params(struct usbnet *usbdev)
1305 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1306 set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
1307 RNDIS_WLAN_KEY_MGMT_NONE);
1308 set_priv_filter(usbdev);
1309 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
1312 static int deauthenticate(struct usbnet *usbdev)
1316 ret = disassociate(usbdev, true);
1317 set_default_iw_params(usbdev);
1321 static int set_channel(struct usbnet *usbdev, int channel)
1323 struct ndis_80211_conf config;
1324 unsigned int dsconfig;
1327 netdev_dbg(usbdev->net, "%s(%d)\n", __func__, channel);
1329 /* this OID is valid only when not associated */
1330 if (is_associated(usbdev))
1333 dsconfig = ieee80211_dsss_chan_to_freq(channel) * 1000;
1335 len = sizeof(config);
1336 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1338 netdev_dbg(usbdev->net, "%s(): querying configuration failed\n",
1343 config.ds_config = cpu_to_le32(dsconfig);
1344 ret = rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
1347 netdev_dbg(usbdev->net, "%s(): %d -> %d\n", __func__, channel, ret);
1352 static struct ieee80211_channel *get_current_channel(struct usbnet *usbdev,
1353 u16 *beacon_interval)
1355 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1356 struct ieee80211_channel *channel;
1357 struct ndis_80211_conf config;
1360 /* Get channel and beacon interval */
1361 len = sizeof(config);
1362 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1363 netdev_dbg(usbdev->net, "%s(): OID_802_11_CONFIGURATION -> %d\n",
1368 channel = ieee80211_get_channel(priv->wdev.wiphy,
1369 KHZ_TO_MHZ(le32_to_cpu(config.ds_config)));
1373 if (beacon_interval)
1374 *beacon_interval = le16_to_cpu(config.beacon_period);
1378 /* index must be 0 - N, as per NDIS */
1379 static int add_wep_key(struct usbnet *usbdev, const u8 *key, int key_len,
1382 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1383 struct ndis_80211_wep_key ndis_key;
1387 netdev_dbg(usbdev->net, "%s(idx: %d, len: %d)\n",
1388 __func__, index, key_len);
1390 if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
1394 cipher = WLAN_CIPHER_SUITE_WEP40;
1396 cipher = WLAN_CIPHER_SUITE_WEP104;
1398 memset(&ndis_key, 0, sizeof(ndis_key));
1400 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1401 ndis_key.length = cpu_to_le32(key_len);
1402 ndis_key.index = cpu_to_le32(index);
1403 memcpy(&ndis_key.material, key, key_len);
1405 if (index == priv->encr_tx_key_index) {
1406 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
1407 ret = set_encr_mode(usbdev, RNDIS_WLAN_ALG_WEP,
1408 RNDIS_WLAN_ALG_NONE);
1410 netdev_warn(usbdev->net, "encryption couldn't be enabled (%08X)\n",
1414 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1417 netdev_warn(usbdev->net, "adding encryption key %d failed (%08X)\n",
1422 priv->encr_keys[index].len = key_len;
1423 priv->encr_keys[index].cipher = cipher;
1424 memcpy(&priv->encr_keys[index].material, key, key_len);
1425 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
1430 static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
1431 int index, const u8 *addr, const u8 *rx_seq,
1432 int seq_len, u32 cipher, __le32 flags)
1434 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1435 struct ndis_80211_key ndis_key;
1439 if (index < 0 || index >= 4) {
1440 netdev_dbg(usbdev->net, "%s(): index out of range (%i)\n",
1444 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1445 netdev_dbg(usbdev->net, "%s(): key length out of range (%i)\n",
1449 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) {
1450 if (!rx_seq || seq_len <= 0) {
1451 netdev_dbg(usbdev->net, "%s(): recv seq flag without buffer\n",
1455 if (rx_seq && seq_len > sizeof(ndis_key.rsc)) {
1456 netdev_dbg(usbdev->net, "%s(): too big recv seq buffer\n", __func__);
1461 is_addr_ok = addr && !is_zero_ether_addr(addr) &&
1462 !is_broadcast_ether_addr(addr);
1463 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1464 netdev_dbg(usbdev->net, "%s(): pairwise but bssid invalid (%pM)\n",
1469 netdev_dbg(usbdev->net, "%s(%i): flags:%i%i%i\n",
1471 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1472 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1473 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
1475 memset(&ndis_key, 0, sizeof(ndis_key));
1477 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1478 sizeof(ndis_key.material) + key_len);
1479 ndis_key.length = cpu_to_le32(key_len);
1480 ndis_key.index = cpu_to_le32(index) | flags;
1482 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
1483 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1484 * different order than NDIS spec, so swap the order here. */
1485 memcpy(ndis_key.material, key, 16);
1486 memcpy(ndis_key.material + 16, key + 24, 8);
1487 memcpy(ndis_key.material + 24, key + 16, 8);
1489 memcpy(ndis_key.material, key, key_len);
1491 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
1492 memcpy(ndis_key.rsc, rx_seq, seq_len);
1494 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
1496 memcpy(ndis_key.bssid, addr, ETH_ALEN);
1499 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
1500 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1502 get_bssid(usbdev, ndis_key.bssid);
1505 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1506 le32_to_cpu(ndis_key.size));
1507 netdev_dbg(usbdev->net, "%s(): OID_802_11_ADD_KEY -> %08X\n",
1512 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1513 priv->encr_keys[index].len = key_len;
1514 priv->encr_keys[index].cipher = cipher;
1515 memcpy(&priv->encr_keys[index].material, key, key_len);
1516 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1517 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1519 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
1521 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
1522 priv->encr_tx_key_index = index;
1527 static int restore_key(struct usbnet *usbdev, int key_idx)
1529 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1530 struct rndis_wlan_encr_key key;
1532 if (is_wpa_key(priv, key_idx))
1535 key = priv->encr_keys[key_idx];
1537 netdev_dbg(usbdev->net, "%s(): %i:%i\n", __func__, key_idx, key.len);
1542 return add_wep_key(usbdev, key.material, key.len, key_idx);
1545 static void restore_keys(struct usbnet *usbdev)
1549 for (i = 0; i < 4; i++)
1550 restore_key(usbdev, i);
1553 static void clear_key(struct rndis_wlan_private *priv, int idx)
1555 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1558 /* remove_key is for both wep and wpa */
1559 static int remove_key(struct usbnet *usbdev, int index, const u8 *bssid)
1561 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1562 struct ndis_80211_remove_key remove_key;
1567 if (index >= RNDIS_WLAN_NUM_KEYS)
1570 if (priv->encr_keys[index].len == 0)
1573 is_wpa = is_wpa_key(priv, index);
1575 netdev_dbg(usbdev->net, "%s(): %i:%s:%i\n",
1576 __func__, index, is_wpa ? "wpa" : "wep",
1577 priv->encr_keys[index].len);
1579 clear_key(priv, index);
1582 remove_key.size = cpu_to_le32(sizeof(remove_key));
1583 remove_key.index = cpu_to_le32(index);
1586 if (!is_broadcast_ether_addr(bssid))
1588 NDIS_80211_ADDKEY_PAIRWISE_KEY;
1589 memcpy(remove_key.bssid, bssid,
1590 sizeof(remove_key.bssid));
1592 memset(remove_key.bssid, 0xff,
1593 sizeof(remove_key.bssid));
1595 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1596 sizeof(remove_key));
1600 keyindex = cpu_to_le32(index);
1601 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1604 netdev_warn(usbdev->net,
1605 "removing encryption key %d failed (%08X)\n",
1611 /* if it is transmit key, disable encryption */
1612 if (index == priv->encr_tx_key_index)
1613 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
1618 static void set_multicast_list(struct usbnet *usbdev)
1620 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1621 struct netdev_hw_addr *ha;
1622 __le32 filter, basefilter;
1624 char *mc_addrs = NULL;
1627 basefilter = filter = RNDIS_PACKET_TYPE_DIRECTED |
1628 RNDIS_PACKET_TYPE_BROADCAST;
1630 if (usbdev->net->flags & IFF_PROMISC) {
1631 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1632 RNDIS_PACKET_TYPE_ALL_LOCAL;
1633 } else if (usbdev->net->flags & IFF_ALLMULTI) {
1634 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1637 if (filter != basefilter)
1641 * mc_list should be accessed holding the lock, so copy addresses to
1642 * local buffer first.
1644 netif_addr_lock_bh(usbdev->net);
1645 mc_count = netdev_mc_count(usbdev->net);
1646 if (mc_count > priv->multicast_size) {
1647 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1648 } else if (mc_count) {
1651 mc_addrs = kmalloc(mc_count * ETH_ALEN, GFP_ATOMIC);
1653 netdev_warn(usbdev->net,
1654 "couldn't alloc %d bytes of memory\n",
1655 mc_count * ETH_ALEN);
1656 netif_addr_unlock_bh(usbdev->net);
1660 netdev_for_each_mc_addr(ha, usbdev->net)
1661 memcpy(mc_addrs + i++ * ETH_ALEN,
1662 ha->addr, ETH_ALEN);
1664 netif_addr_unlock_bh(usbdev->net);
1666 if (filter != basefilter)
1670 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, mc_addrs,
1671 mc_count * ETH_ALEN);
1674 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1676 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1678 netdev_dbg(usbdev->net, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1679 mc_count, priv->multicast_size, ret);
1683 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1686 netdev_warn(usbdev->net, "couldn't set packet filter: %08x\n",
1687 le32_to_cpu(filter));
1690 netdev_dbg(usbdev->net, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1691 le32_to_cpu(filter), ret);
1695 static void debug_print_pmkids(struct usbnet *usbdev,
1696 struct ndis_80211_pmkid *pmkids,
1697 const char *func_str)
1699 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1700 int i, len, count, max_pmkids, entry_len;
1702 max_pmkids = priv->wdev.wiphy->max_num_pmkids;
1703 len = le32_to_cpu(pmkids->length);
1704 count = le32_to_cpu(pmkids->bssid_info_count);
1706 entry_len = (count > 0) ? (len - sizeof(*pmkids)) / count : -1;
1708 netdev_dbg(usbdev->net, "%s(): %d PMKIDs (data len: %d, entry len: "
1709 "%d)\n", func_str, count, len, entry_len);
1711 if (count > max_pmkids)
1714 for (i = 0; i < count; i++) {
1715 u32 *tmp = (u32 *)pmkids->bssid_info[i].pmkid;
1717 netdev_dbg(usbdev->net, "%s(): bssid: %pM, "
1718 "pmkid: %08X:%08X:%08X:%08X\n",
1719 func_str, pmkids->bssid_info[i].bssid,
1720 cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
1721 cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
1725 static void debug_print_pmkids(struct usbnet *usbdev,
1726 struct ndis_80211_pmkid *pmkids,
1727 const char *func_str)
1733 static struct ndis_80211_pmkid *get_device_pmkids(struct usbnet *usbdev)
1735 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1736 struct ndis_80211_pmkid *pmkids;
1737 int len, ret, max_pmkids;
1739 max_pmkids = priv->wdev.wiphy->max_num_pmkids;
1740 len = sizeof(*pmkids) + max_pmkids * sizeof(pmkids->bssid_info[0]);
1742 pmkids = kzalloc(len, GFP_KERNEL);
1744 return ERR_PTR(-ENOMEM);
1746 pmkids->length = cpu_to_le32(len);
1747 pmkids->bssid_info_count = cpu_to_le32(max_pmkids);
1749 ret = rndis_query_oid(usbdev, OID_802_11_PMKID, pmkids, &len);
1751 netdev_dbg(usbdev->net, "%s(): OID_802_11_PMKID(%d, %d)"
1752 " -> %d\n", __func__, len, max_pmkids, ret);
1755 return ERR_PTR(ret);
1758 if (le32_to_cpu(pmkids->bssid_info_count) > max_pmkids)
1759 pmkids->bssid_info_count = cpu_to_le32(max_pmkids);
1761 debug_print_pmkids(usbdev, pmkids, __func__);
1766 static int set_device_pmkids(struct usbnet *usbdev,
1767 struct ndis_80211_pmkid *pmkids)
1769 int ret, len, num_pmkids;
1771 num_pmkids = le32_to_cpu(pmkids->bssid_info_count);
1772 len = sizeof(*pmkids) + num_pmkids * sizeof(pmkids->bssid_info[0]);
1773 pmkids->length = cpu_to_le32(len);
1775 debug_print_pmkids(usbdev, pmkids, __func__);
1777 ret = rndis_set_oid(usbdev, OID_802_11_PMKID, pmkids,
1778 le32_to_cpu(pmkids->length));
1780 netdev_dbg(usbdev->net, "%s(): OID_802_11_PMKID(%d, %d) -> %d"
1781 "\n", __func__, len, num_pmkids, ret);
1788 static struct ndis_80211_pmkid *remove_pmkid(struct usbnet *usbdev,
1789 struct ndis_80211_pmkid *pmkids,
1790 struct cfg80211_pmksa *pmksa,
1793 int i, count, newlen, err;
1795 count = le32_to_cpu(pmkids->bssid_info_count);
1797 if (count > max_pmkids)
1800 for (i = 0; i < count; i++)
1801 if (!compare_ether_addr(pmkids->bssid_info[i].bssid,
1805 /* pmkid not found */
1807 netdev_dbg(usbdev->net, "%s(): bssid not found (%pM)\n",
1808 __func__, pmksa->bssid);
1813 for (; i + 1 < count; i++)
1814 pmkids->bssid_info[i] = pmkids->bssid_info[i + 1];
1817 newlen = sizeof(*pmkids) + count * sizeof(pmkids->bssid_info[0]);
1819 pmkids->length = cpu_to_le32(newlen);
1820 pmkids->bssid_info_count = cpu_to_le32(count);
1825 return ERR_PTR(err);
1828 static struct ndis_80211_pmkid *update_pmkid(struct usbnet *usbdev,
1829 struct ndis_80211_pmkid *pmkids,
1830 struct cfg80211_pmksa *pmksa,
1833 int i, err, count, newlen;
1835 count = le32_to_cpu(pmkids->bssid_info_count);
1837 if (count > max_pmkids)
1840 /* update with new pmkid */
1841 for (i = 0; i < count; i++) {
1842 if (compare_ether_addr(pmkids->bssid_info[i].bssid,
1846 memcpy(pmkids->bssid_info[i].pmkid, pmksa->pmkid,
1852 /* out of space, return error */
1853 if (i == max_pmkids) {
1854 netdev_dbg(usbdev->net, "%s(): out of space\n", __func__);
1860 newlen = sizeof(*pmkids) + (count + 1) * sizeof(pmkids->bssid_info[0]);
1862 pmkids = krealloc(pmkids, newlen, GFP_KERNEL);
1868 pmkids->length = cpu_to_le32(newlen);
1869 pmkids->bssid_info_count = cpu_to_le32(count + 1);
1871 memcpy(pmkids->bssid_info[count].bssid, pmksa->bssid, ETH_ALEN);
1872 memcpy(pmkids->bssid_info[count].pmkid, pmksa->pmkid, WLAN_PMKID_LEN);
1877 return ERR_PTR(err);
1883 static int rndis_change_virtual_intf(struct wiphy *wiphy,
1884 struct net_device *dev,
1885 enum nl80211_iftype type, u32 *flags,
1886 struct vif_params *params)
1888 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1889 struct usbnet *usbdev = priv->usbdev;
1893 case NL80211_IFTYPE_ADHOC:
1894 mode = NDIS_80211_INFRA_ADHOC;
1896 case NL80211_IFTYPE_STATION:
1897 mode = NDIS_80211_INFRA_INFRA;
1903 priv->wdev.iftype = type;
1905 return set_infra_mode(usbdev, mode);
1908 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1910 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1911 struct usbnet *usbdev = priv->usbdev;
1914 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1915 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1920 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1921 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1929 static int rndis_set_tx_power(struct wiphy *wiphy,
1930 enum nl80211_tx_power_setting type,
1933 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1934 struct usbnet *usbdev = priv->usbdev;
1936 netdev_dbg(usbdev->net, "%s(): type:0x%x mbm:%i\n",
1937 __func__, type, mbm);
1939 if (mbm < 0 || (mbm % 100))
1942 /* Device doesn't support changing txpower after initialization, only
1943 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1946 if (type == NL80211_TX_POWER_AUTOMATIC ||
1947 MBM_TO_DBM(mbm) == get_bcm4320_power_dbm(priv)) {
1948 if (!priv->radio_on)
1949 disassociate(usbdev, true); /* turn on radio */
1957 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1959 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1960 struct usbnet *usbdev = priv->usbdev;
1962 *dbm = get_bcm4320_power_dbm(priv);
1964 netdev_dbg(usbdev->net, "%s(): dbm:%i\n", __func__, *dbm);
1969 #define SCAN_DELAY_JIFFIES (6 * HZ)
1970 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1971 struct cfg80211_scan_request *request)
1973 struct usbnet *usbdev = netdev_priv(dev);
1974 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1976 int delay = SCAN_DELAY_JIFFIES;
1978 netdev_dbg(usbdev->net, "cfg80211.scan\n");
1980 /* Get current bssid list from device before new scan, as new scan
1981 * clears internal bssid list.
1983 rndis_check_bssid_list(usbdev, NULL, NULL);
1988 if (priv->scan_request && priv->scan_request != request)
1991 priv->scan_request = request;
1993 ret = rndis_start_bssid_list_scan(usbdev);
1995 if (priv->device_type == RNDIS_BCM4320A)
1998 /* Wait before retrieving scan results from device */
1999 queue_delayed_work(priv->workqueue, &priv->scan_work, delay);
2005 static bool rndis_bss_info_update(struct usbnet *usbdev,
2006 struct ndis_80211_bssid_ex *bssid)
2008 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2009 struct ieee80211_channel *channel;
2010 struct cfg80211_bss *bss;
2014 u16 beacon_interval;
2015 struct ndis_80211_fixed_ies *fixed;
2016 int ie_len, bssid_len;
2019 netdev_dbg(usbdev->net, " found bssid: '%.32s' [%pM], len: %d\n",
2020 bssid->ssid.essid, bssid->mac, le32_to_cpu(bssid->length));
2022 /* parse bssid structure */
2023 bssid_len = le32_to_cpu(bssid->length);
2025 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
2026 sizeof(struct ndis_80211_fixed_ies))
2029 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
2031 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
2032 ie_len = min(bssid_len - (int)sizeof(*bssid),
2033 (int)le32_to_cpu(bssid->ie_length));
2034 ie_len -= sizeof(struct ndis_80211_fixed_ies);
2038 /* extract data for cfg80211_inform_bss */
2039 channel = ieee80211_get_channel(priv->wdev.wiphy,
2040 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
2044 signal = level_to_qual(le32_to_cpu(bssid->rssi));
2045 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
2046 capability = le16_to_cpu(fixed->capabilities);
2047 beacon_interval = le16_to_cpu(fixed->beacon_interval);
2049 bss = cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
2050 timestamp, capability, beacon_interval, ie, ie_len, signal,
2052 cfg80211_put_bss(bss);
2054 return (bss != NULL);
2057 static struct ndis_80211_bssid_ex *next_bssid_list_item(
2058 struct ndis_80211_bssid_ex *bssid,
2059 int *bssid_len, void *buf, int len)
2061 void *buf_end, *bssid_end;
2063 buf_end = (char *)buf + len;
2064 bssid_end = (char *)bssid + *bssid_len;
2066 if ((int)(buf_end - bssid_end) < sizeof(bssid->length)) {
2070 bssid = (void *)((char *)bssid + *bssid_len);
2071 *bssid_len = le32_to_cpu(bssid->length);
2076 static bool check_bssid_list_item(struct ndis_80211_bssid_ex *bssid,
2077 int bssid_len, void *buf, int len)
2079 void *buf_end, *bssid_end;
2081 if (!bssid || bssid_len <= 0 || bssid_len > len)
2084 buf_end = (char *)buf + len;
2085 bssid_end = (char *)bssid + bssid_len;
2087 return (int)(buf_end - bssid_end) >= 0 && (int)(bssid_end - buf) >= 0;
2090 static int rndis_check_bssid_list(struct usbnet *usbdev, u8 *match_bssid,
2094 struct ndis_80211_bssid_list_ex *bssid_list;
2095 struct ndis_80211_bssid_ex *bssid;
2096 int ret = -EINVAL, len, count, bssid_len, real_count, new_len;
2098 netdev_dbg(usbdev->net, "%s()\n", __func__);
2100 len = CONTROL_BUFFER_SIZE;
2102 buf = kzalloc(len, GFP_KERNEL);
2108 /* BSSID-list might have got bigger last time we checked, keep
2109 * resizing until it won't get any bigger.
2112 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &new_len);
2113 if (ret != 0 || new_len < sizeof(struct ndis_80211_bssid_list_ex))
2116 if (new_len > len) {
2125 count = le32_to_cpu(bssid_list->num_items);
2127 netdev_dbg(usbdev->net, "%s(): buflen: %d\n", __func__, len);
2130 bssid = next_bssid_list_item(bssid_list->bssid, &bssid_len, buf, len);
2132 /* Device returns incorrect 'num_items'. Workaround by ignoring the
2133 * received 'num_items' and walking through full bssid buffer instead.
2135 while (check_bssid_list_item(bssid, bssid_len, buf, len)) {
2136 if (rndis_bss_info_update(usbdev, bssid) && match_bssid &&
2138 if (compare_ether_addr(bssid->mac, match_bssid))
2143 bssid = next_bssid_list_item(bssid, &bssid_len, buf, len);
2146 netdev_dbg(usbdev->net, "%s(): num_items from device: %d, really found:"
2147 " %d\n", __func__, count, real_count);
2154 static void rndis_get_scan_results(struct work_struct *work)
2156 struct rndis_wlan_private *priv =
2157 container_of(work, struct rndis_wlan_private, scan_work.work);
2158 struct usbnet *usbdev = priv->usbdev;
2161 netdev_dbg(usbdev->net, "get_scan_results\n");
2163 if (!priv->scan_request)
2166 ret = rndis_check_bssid_list(usbdev, NULL, NULL);
2168 cfg80211_scan_done(priv->scan_request, ret < 0);
2170 priv->scan_request = NULL;
2173 static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
2174 struct cfg80211_connect_params *sme)
2176 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2177 struct usbnet *usbdev = priv->usbdev;
2178 struct ieee80211_channel *channel = sme->channel;
2179 struct ndis_80211_ssid ssid;
2180 int pairwise = RNDIS_WLAN_ALG_NONE;
2181 int groupwise = RNDIS_WLAN_ALG_NONE;
2182 int keymgmt = RNDIS_WLAN_KEY_MGMT_NONE;
2183 int length, i, ret, chan = -1;
2186 chan = ieee80211_frequency_to_channel(channel->center_freq);
2188 groupwise = rndis_cipher_to_alg(sme->crypto.cipher_group);
2189 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
2191 rndis_cipher_to_alg(sme->crypto.ciphers_pairwise[i]);
2193 if (sme->crypto.n_ciphers_pairwise > 0 &&
2194 pairwise == RNDIS_WLAN_ALG_NONE) {
2195 netdev_err(usbdev->net, "Unsupported pairwise cipher\n");
2199 for (i = 0; i < sme->crypto.n_akm_suites; i++)
2201 rndis_akm_suite_to_key_mgmt(sme->crypto.akm_suites[i]);
2203 if (sme->crypto.n_akm_suites > 0 &&
2204 keymgmt == RNDIS_WLAN_KEY_MGMT_NONE) {
2205 netdev_err(usbdev->net, "Invalid keymgmt\n");
2209 netdev_dbg(usbdev->net, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
2210 sme->ssid, sme->bssid, chan,
2211 sme->privacy, sme->crypto.wpa_versions, sme->auth_type,
2212 groupwise, pairwise, keymgmt);
2214 if (is_associated(usbdev))
2215 disassociate(usbdev, false);
2217 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
2219 netdev_dbg(usbdev->net, "connect: set_infra_mode failed, %d\n",
2221 goto err_turn_radio_on;
2224 ret = set_auth_mode(usbdev, sme->crypto.wpa_versions, sme->auth_type,
2227 netdev_dbg(usbdev->net, "connect: set_auth_mode failed, %d\n",
2229 goto err_turn_radio_on;
2232 set_priv_filter(usbdev);
2234 ret = set_encr_mode(usbdev, pairwise, groupwise);
2236 netdev_dbg(usbdev->net, "connect: set_encr_mode failed, %d\n",
2238 goto err_turn_radio_on;
2242 ret = set_channel(usbdev, chan);
2244 netdev_dbg(usbdev->net, "connect: set_channel failed, %d\n",
2246 goto err_turn_radio_on;
2250 if (sme->key && ((groupwise | pairwise) & RNDIS_WLAN_ALG_WEP)) {
2251 priv->encr_tx_key_index = sme->key_idx;
2252 ret = add_wep_key(usbdev, sme->key, sme->key_len, sme->key_idx);
2254 netdev_dbg(usbdev->net, "connect: add_wep_key failed, %d (%d, %d)\n",
2255 ret, sme->key_len, sme->key_idx);
2256 goto err_turn_radio_on;
2260 if (sme->bssid && !is_zero_ether_addr(sme->bssid) &&
2261 !is_broadcast_ether_addr(sme->bssid)) {
2262 ret = set_bssid(usbdev, sme->bssid);
2264 netdev_dbg(usbdev->net, "connect: set_bssid failed, %d\n",
2266 goto err_turn_radio_on;
2269 clear_bssid(usbdev);
2271 length = sme->ssid_len;
2272 if (length > NDIS_802_11_LENGTH_SSID)
2273 length = NDIS_802_11_LENGTH_SSID;
2275 memset(&ssid, 0, sizeof(ssid));
2276 ssid.length = cpu_to_le32(length);
2277 memcpy(ssid.essid, sme->ssid, length);
2279 /* Pause and purge rx queue, so we don't pass packets before
2280 * 'media connect'-indication.
2282 usbnet_pause_rx(usbdev);
2283 usbnet_purge_paused_rxq(usbdev);
2285 ret = set_essid(usbdev, &ssid);
2287 netdev_dbg(usbdev->net, "connect: set_essid failed, %d\n", ret);
2291 disassociate(usbdev, true);
2296 static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
2299 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2300 struct usbnet *usbdev = priv->usbdev;
2302 netdev_dbg(usbdev->net, "cfg80211.disconnect(%d)\n", reason_code);
2304 priv->connected = false;
2305 memset(priv->bssid, 0, ETH_ALEN);
2307 return deauthenticate(usbdev);
2310 static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2311 struct cfg80211_ibss_params *params)
2313 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2314 struct usbnet *usbdev = priv->usbdev;
2315 struct ieee80211_channel *channel = params->channel;
2316 struct ndis_80211_ssid ssid;
2317 enum nl80211_auth_type auth_type;
2318 int ret, alg, length, chan = -1;
2321 chan = ieee80211_frequency_to_channel(channel->center_freq);
2323 /* TODO: How to handle ad-hoc encryption?
2324 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
2325 * pre-shared for encryption (open/shared/wpa), is key set before
2326 * join_ibss? Which auth_type to use (not in params)? What about WPA?
2328 if (params->privacy) {
2329 auth_type = NL80211_AUTHTYPE_SHARED_KEY;
2330 alg = RNDIS_WLAN_ALG_WEP;
2332 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2333 alg = RNDIS_WLAN_ALG_NONE;
2336 netdev_dbg(usbdev->net, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
2337 params->ssid, params->bssid, chan, params->privacy);
2339 if (is_associated(usbdev))
2340 disassociate(usbdev, false);
2342 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_ADHOC);
2344 netdev_dbg(usbdev->net, "join_ibss: set_infra_mode failed, %d\n",
2346 goto err_turn_radio_on;
2349 ret = set_auth_mode(usbdev, 0, auth_type, RNDIS_WLAN_KEY_MGMT_NONE);
2351 netdev_dbg(usbdev->net, "join_ibss: set_auth_mode failed, %d\n",
2353 goto err_turn_radio_on;
2356 set_priv_filter(usbdev);
2358 ret = set_encr_mode(usbdev, alg, RNDIS_WLAN_ALG_NONE);
2360 netdev_dbg(usbdev->net, "join_ibss: set_encr_mode failed, %d\n",
2362 goto err_turn_radio_on;
2366 ret = set_channel(usbdev, chan);
2368 netdev_dbg(usbdev->net, "join_ibss: set_channel failed, %d\n",
2370 goto err_turn_radio_on;
2374 if (params->bssid && !is_zero_ether_addr(params->bssid) &&
2375 !is_broadcast_ether_addr(params->bssid)) {
2376 ret = set_bssid(usbdev, params->bssid);
2378 netdev_dbg(usbdev->net, "join_ibss: set_bssid failed, %d\n",
2380 goto err_turn_radio_on;
2383 clear_bssid(usbdev);
2385 length = params->ssid_len;
2386 if (length > NDIS_802_11_LENGTH_SSID)
2387 length = NDIS_802_11_LENGTH_SSID;
2389 memset(&ssid, 0, sizeof(ssid));
2390 ssid.length = cpu_to_le32(length);
2391 memcpy(ssid.essid, params->ssid, length);
2393 /* Don't need to pause rx queue for ad-hoc. */
2394 usbnet_purge_paused_rxq(usbdev);
2395 usbnet_resume_rx(usbdev);
2397 ret = set_essid(usbdev, &ssid);
2399 netdev_dbg(usbdev->net, "join_ibss: set_essid failed, %d\n",
2404 disassociate(usbdev, true);
2409 static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2411 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2412 struct usbnet *usbdev = priv->usbdev;
2414 netdev_dbg(usbdev->net, "cfg80211.leave_ibss()\n");
2416 priv->connected = false;
2417 memset(priv->bssid, 0, ETH_ALEN);
2419 return deauthenticate(usbdev);
2422 static int rndis_set_channel(struct wiphy *wiphy, struct net_device *netdev,
2423 struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
2425 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2426 struct usbnet *usbdev = priv->usbdev;
2428 return set_channel(usbdev,
2429 ieee80211_frequency_to_channel(chan->center_freq));
2432 static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
2433 u8 key_index, bool pairwise, const u8 *mac_addr,
2434 struct key_params *params)
2436 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2437 struct usbnet *usbdev = priv->usbdev;
2440 netdev_dbg(usbdev->net, "%s(%i, %pM, %08x)\n",
2441 __func__, key_index, mac_addr, params->cipher);
2443 switch (params->cipher) {
2444 case WLAN_CIPHER_SUITE_WEP40:
2445 case WLAN_CIPHER_SUITE_WEP104:
2446 return add_wep_key(usbdev, params->key, params->key_len,
2448 case WLAN_CIPHER_SUITE_TKIP:
2449 case WLAN_CIPHER_SUITE_CCMP:
2452 if (params->seq && params->seq_len > 0)
2453 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
2455 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY |
2456 NDIS_80211_ADDKEY_TRANSMIT_KEY;
2458 return add_wpa_key(usbdev, params->key, params->key_len,
2459 key_index, mac_addr, params->seq,
2460 params->seq_len, params->cipher, flags);
2462 netdev_dbg(usbdev->net, "%s(): unsupported cipher %08x\n",
2463 __func__, params->cipher);
2468 static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
2469 u8 key_index, bool pairwise, const u8 *mac_addr)
2471 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2472 struct usbnet *usbdev = priv->usbdev;
2474 netdev_dbg(usbdev->net, "%s(%i, %pM)\n", __func__, key_index, mac_addr);
2476 return remove_key(usbdev, key_index, mac_addr);
2479 static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
2480 u8 key_index, bool unicast, bool multicast)
2482 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2483 struct usbnet *usbdev = priv->usbdev;
2484 struct rndis_wlan_encr_key key;
2486 netdev_dbg(usbdev->net, "%s(%i)\n", __func__, key_index);
2488 if (key_index >= RNDIS_WLAN_NUM_KEYS)
2491 priv->encr_tx_key_index = key_index;
2493 if (is_wpa_key(priv, key_index))
2496 key = priv->encr_keys[key_index];
2498 return add_wep_key(usbdev, key.material, key.len, key_index);
2501 static void rndis_fill_station_info(struct usbnet *usbdev,
2502 struct station_info *sinfo)
2504 __le32 linkspeed, rssi;
2507 memset(sinfo, 0, sizeof(*sinfo));
2509 len = sizeof(linkspeed);
2510 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &linkspeed, &len);
2512 sinfo->txrate.legacy = le32_to_cpu(linkspeed) / 1000;
2513 sinfo->filled |= STATION_INFO_TX_BITRATE;
2517 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2519 sinfo->signal = level_to_qual(le32_to_cpu(rssi));
2520 sinfo->filled |= STATION_INFO_SIGNAL;
2524 static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
2525 u8 *mac, struct station_info *sinfo)
2527 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2528 struct usbnet *usbdev = priv->usbdev;
2530 if (compare_ether_addr(priv->bssid, mac))
2533 rndis_fill_station_info(usbdev, sinfo);
2538 static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
2539 int idx, u8 *mac, struct station_info *sinfo)
2541 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2542 struct usbnet *usbdev = priv->usbdev;
2547 memcpy(mac, priv->bssid, ETH_ALEN);
2549 rndis_fill_station_info(usbdev, sinfo);
2554 static int rndis_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
2555 struct cfg80211_pmksa *pmksa)
2557 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2558 struct usbnet *usbdev = priv->usbdev;
2559 struct ndis_80211_pmkid *pmkids;
2560 u32 *tmp = (u32 *)pmksa->pmkid;
2562 netdev_dbg(usbdev->net, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
2564 cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
2565 cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
2567 pmkids = get_device_pmkids(usbdev);
2568 if (IS_ERR(pmkids)) {
2569 /* couldn't read PMKID cache from device */
2570 return PTR_ERR(pmkids);
2573 pmkids = update_pmkid(usbdev, pmkids, pmksa, wiphy->max_num_pmkids);
2574 if (IS_ERR(pmkids)) {
2575 /* not found, list full, etc */
2576 return PTR_ERR(pmkids);
2579 return set_device_pmkids(usbdev, pmkids);
2582 static int rndis_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
2583 struct cfg80211_pmksa *pmksa)
2585 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2586 struct usbnet *usbdev = priv->usbdev;
2587 struct ndis_80211_pmkid *pmkids;
2588 u32 *tmp = (u32 *)pmksa->pmkid;
2590 netdev_dbg(usbdev->net, "%s(%pM, %08X:%08X:%08X:%08X)\n", __func__,
2592 cpu_to_be32(tmp[0]), cpu_to_be32(tmp[1]),
2593 cpu_to_be32(tmp[2]), cpu_to_be32(tmp[3]));
2595 pmkids = get_device_pmkids(usbdev);
2596 if (IS_ERR(pmkids)) {
2597 /* Couldn't read PMKID cache from device */
2598 return PTR_ERR(pmkids);
2601 pmkids = remove_pmkid(usbdev, pmkids, pmksa, wiphy->max_num_pmkids);
2602 if (IS_ERR(pmkids)) {
2603 /* not found, etc */
2604 return PTR_ERR(pmkids);
2607 return set_device_pmkids(usbdev, pmkids);
2610 static int rndis_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
2612 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2613 struct usbnet *usbdev = priv->usbdev;
2614 struct ndis_80211_pmkid pmkid;
2616 netdev_dbg(usbdev->net, "%s()\n", __func__);
2618 memset(&pmkid, 0, sizeof(pmkid));
2620 pmkid.length = cpu_to_le32(sizeof(pmkid));
2621 pmkid.bssid_info_count = cpu_to_le32(0);
2623 return rndis_set_oid(usbdev, OID_802_11_PMKID, &pmkid, sizeof(pmkid));
2626 static int rndis_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2627 bool enabled, int timeout)
2629 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2630 struct usbnet *usbdev = priv->usbdev;
2635 if (priv->device_type != RNDIS_BCM4320B)
2638 netdev_dbg(usbdev->net, "%s(): %s, %d\n", __func__,
2639 enabled ? "enabled" : "disabled",
2643 power_mode = NDIS_80211_POWER_MODE_FAST_PSP;
2645 power_mode = NDIS_80211_POWER_MODE_CAM;
2647 if (power_mode == priv->power_mode)
2650 priv->power_mode = power_mode;
2652 mode = cpu_to_le32(power_mode);
2653 ret = rndis_set_oid(usbdev, OID_802_11_POWER_MODE, &mode, sizeof(mode));
2655 netdev_dbg(usbdev->net, "%s(): OID_802_11_POWER_MODE -> %d\n",
2661 static int rndis_set_cqm_rssi_config(struct wiphy *wiphy,
2662 struct net_device *dev,
2663 s32 rssi_thold, u32 rssi_hyst)
2665 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2667 priv->cqm_rssi_thold = rssi_thold;
2668 priv->cqm_rssi_hyst = rssi_hyst;
2669 priv->last_cqm_event_rssi = 0;
2674 static void rndis_wlan_craft_connected_bss(struct usbnet *usbdev, u8 *bssid,
2675 struct ndis_80211_assoc_info *info)
2677 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2678 struct ieee80211_channel *channel;
2679 struct ndis_80211_ssid ssid;
2680 struct cfg80211_bss *bss;
2684 u16 beacon_interval = 0;
2687 int len, ret, ie_len;
2689 /* Get signal quality, in case of error use rssi=0 and ignore error. */
2692 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2693 signal = level_to_qual(le32_to_cpu(rssi));
2695 netdev_dbg(usbdev->net, "%s(): OID_802_11_RSSI -> %d, "
2696 "rssi:%d, qual: %d\n", __func__, ret, le32_to_cpu(rssi),
2697 level_to_qual(le32_to_cpu(rssi)));
2699 /* Get AP capabilities */
2701 capability = le16_to_cpu(info->resp_ie.capa);
2703 /* Set atleast ESS/IBSS capability */
2704 capability = (priv->infra_mode == NDIS_80211_INFRA_INFRA) ?
2705 WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS;
2708 /* Get channel and beacon interval */
2709 channel = get_current_channel(usbdev, &beacon_interval);
2711 netdev_warn(usbdev->net, "%s(): could not get channel.\n",
2716 /* Get SSID, in case of error, use zero length SSID and ignore error. */
2718 memset(&ssid, 0, sizeof(ssid));
2719 ret = rndis_query_oid(usbdev, OID_802_11_SSID, &ssid, &len);
2720 netdev_dbg(usbdev->net, "%s(): OID_802_11_SSID -> %d, len: %d, ssid: "
2721 "'%.32s'\n", __func__, ret,
2722 le32_to_cpu(ssid.length), ssid.essid);
2724 if (le32_to_cpu(ssid.length) > 32)
2725 ssid.length = cpu_to_le32(32);
2727 ie_buf[0] = WLAN_EID_SSID;
2728 ie_buf[1] = le32_to_cpu(ssid.length);
2729 memcpy(&ie_buf[2], ssid.essid, le32_to_cpu(ssid.length));
2731 ie_len = le32_to_cpu(ssid.length) + 2;
2736 netdev_dbg(usbdev->net, "%s(): channel:%d(freq), bssid:[%pM], tsf:%d, "
2737 "capa:%x, beacon int:%d, resp_ie(len:%d, essid:'%.32s'), "
2738 "signal:%d\n", __func__, (channel ? channel->center_freq : -1),
2739 bssid, (u32)timestamp, capability, beacon_interval, ie_len,
2740 ssid.essid, signal);
2742 bss = cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid,
2743 timestamp, capability, beacon_interval, ie_buf, ie_len,
2744 signal, GFP_KERNEL);
2745 cfg80211_put_bss(bss);
2749 * workers, indication handlers, device poller
2751 static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
2753 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2754 struct ndis_80211_assoc_info *info = NULL;
2756 unsigned int resp_ie_len, req_ie_len;
2757 unsigned int offset;
2758 u8 *req_ie, *resp_ie;
2760 bool roamed = false;
2763 if (priv->infra_mode == NDIS_80211_INFRA_INFRA && priv->connected) {
2764 /* received media connect indication while connected, either
2765 * device reassociated with same AP or roamed to new. */
2774 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2775 info = kzalloc(CONTROL_BUFFER_SIZE, GFP_KERNEL);
2777 /* No memory? Try resume work later */
2778 set_bit(WORK_LINK_UP, &priv->work_pending);
2779 queue_work(priv->workqueue, &priv->work);
2783 /* Get association info IEs from device. */
2784 ret = get_association_info(usbdev, info, CONTROL_BUFFER_SIZE);
2786 req_ie_len = le32_to_cpu(info->req_ie_length);
2787 if (req_ie_len > CONTROL_BUFFER_SIZE)
2788 req_ie_len = CONTROL_BUFFER_SIZE;
2789 if (req_ie_len != 0) {
2790 offset = le32_to_cpu(info->offset_req_ies);
2792 if (offset > CONTROL_BUFFER_SIZE)
2793 offset = CONTROL_BUFFER_SIZE;
2795 req_ie = (u8 *)info + offset;
2797 if (offset + req_ie_len > CONTROL_BUFFER_SIZE)
2799 CONTROL_BUFFER_SIZE - offset;
2802 resp_ie_len = le32_to_cpu(info->resp_ie_length);
2803 if (resp_ie_len > CONTROL_BUFFER_SIZE)
2804 resp_ie_len = CONTROL_BUFFER_SIZE;
2805 if (resp_ie_len != 0) {
2806 offset = le32_to_cpu(info->offset_resp_ies);
2808 if (offset > CONTROL_BUFFER_SIZE)
2809 offset = CONTROL_BUFFER_SIZE;
2811 resp_ie = (u8 *)info + offset;
2813 if (offset + resp_ie_len > CONTROL_BUFFER_SIZE)
2815 CONTROL_BUFFER_SIZE - offset;
2818 /* Since rndis_wlan_craft_connected_bss() might use info
2819 * later and expects info to contain valid data if
2820 * non-null, free info and set NULL here.
2825 } else if (WARN_ON(priv->infra_mode != NDIS_80211_INFRA_ADHOC))
2828 ret = get_bssid(usbdev, bssid);
2830 memset(bssid, 0, sizeof(bssid));
2832 netdev_dbg(usbdev->net, "link up work: [%pM]%s\n",
2833 bssid, roamed ? " roamed" : "");
2835 /* Internal bss list in device should contain at least the currently
2836 * connected bss and we can get it to cfg80211 with
2837 * rndis_check_bssid_list().
2839 * NDIS spec says: "If the device is associated, but the associated
2840 * BSSID is not in its BSSID scan list, then the driver must add an
2841 * entry for the BSSID at the end of the data that it returns in
2842 * response to query of OID_802_11_BSSID_LIST."
2844 * NOTE: Seems to be true for BCM4320b variant, but not BCM4320a.
2847 rndis_check_bssid_list(usbdev, bssid, &match_bss);
2849 if (!is_zero_ether_addr(bssid) && !match_bss) {
2850 /* Couldn't get bss from device, we need to manually craft bss
2853 rndis_wlan_craft_connected_bss(usbdev, bssid, info);
2856 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2858 cfg80211_connect_result(usbdev->net, bssid, req_ie,
2859 req_ie_len, resp_ie,
2860 resp_ie_len, 0, GFP_KERNEL);
2862 cfg80211_roamed(usbdev->net,
2863 get_current_channel(usbdev, NULL),
2864 bssid, req_ie, req_ie_len,
2865 resp_ie, resp_ie_len, GFP_KERNEL);
2866 } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
2867 cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
2872 priv->connected = true;
2873 memcpy(priv->bssid, bssid, ETH_ALEN);
2875 usbnet_resume_rx(usbdev);
2876 netif_carrier_on(usbdev->net);
2879 static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
2881 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2883 if (priv->connected) {
2884 priv->connected = false;
2885 memset(priv->bssid, 0, ETH_ALEN);
2887 deauthenticate(usbdev);
2889 cfg80211_disconnected(usbdev->net, 0, NULL, 0, GFP_KERNEL);
2892 netif_carrier_off(usbdev->net);
2895 static void rndis_wlan_worker(struct work_struct *work)
2897 struct rndis_wlan_private *priv =
2898 container_of(work, struct rndis_wlan_private, work);
2899 struct usbnet *usbdev = priv->usbdev;
2901 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
2902 rndis_wlan_do_link_up_work(usbdev);
2904 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
2905 rndis_wlan_do_link_down_work(usbdev);
2907 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2908 set_multicast_list(usbdev);
2911 static void rndis_wlan_set_multicast_list(struct net_device *dev)
2913 struct usbnet *usbdev = netdev_priv(dev);
2914 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2916 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2919 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2920 queue_work(priv->workqueue, &priv->work);
2923 static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2924 struct ndis_80211_status_indication *indication,
2929 int flags, buflen, key_id;
2930 bool pairwise_error, group_error;
2931 struct ndis_80211_auth_request *auth_req;
2932 enum nl80211_key_type key_type;
2934 /* must have at least one array entry */
2935 if (len < offsetof(struct ndis_80211_status_indication, u) +
2936 sizeof(struct ndis_80211_auth_request)) {
2937 netdev_info(usbdev->net, "authentication indication: too short message (%i)\n",
2942 buf = (void *)&indication->u.auth_request[0];
2943 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2945 while (buflen >= sizeof(*auth_req)) {
2946 auth_req = (void *)buf;
2948 flags = le32_to_cpu(auth_req->flags);
2949 pairwise_error = false;
2950 group_error = false;
2953 type = "reauth request";
2955 type = "key update request";
2957 pairwise_error = true;
2958 type = "pairwise_error";
2962 type = "group_error";
2965 netdev_info(usbdev->net, "authentication indication: %s (0x%08x)\n",
2966 type, le32_to_cpu(auth_req->flags));
2968 if (pairwise_error) {
2969 key_type = NL80211_KEYTYPE_PAIRWISE;
2972 cfg80211_michael_mic_failure(usbdev->net,
2974 key_type, key_id, NULL,
2979 key_type = NL80211_KEYTYPE_GROUP;
2982 cfg80211_michael_mic_failure(usbdev->net,
2984 key_type, key_id, NULL,
2988 buflen -= le32_to_cpu(auth_req->length);
2989 buf += le32_to_cpu(auth_req->length);
2993 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2994 struct ndis_80211_status_indication *indication,
2997 struct ndis_80211_pmkid_cand_list *cand_list;
2998 int list_len, expected_len, i;
3000 if (len < offsetof(struct ndis_80211_status_indication, u) +
3001 sizeof(struct ndis_80211_pmkid_cand_list)) {
3002 netdev_info(usbdev->net, "pmkid candidate list indication: too short message (%i)\n",
3007 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
3008 sizeof(struct ndis_80211_pmkid_candidate);
3009 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
3010 offsetof(struct ndis_80211_status_indication, u);
3012 if (len < expected_len) {
3013 netdev_info(usbdev->net, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
3018 cand_list = &indication->u.cand_list;
3020 netdev_info(usbdev->net, "pmkid candidate list indication: version %i, candidates %i\n",
3021 le32_to_cpu(cand_list->version),
3022 le32_to_cpu(cand_list->num_candidates));
3024 if (le32_to_cpu(cand_list->version) != 1)
3027 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
3028 struct ndis_80211_pmkid_candidate *cand =
3029 &cand_list->candidate_list[i];
3030 bool preauth = !!(cand->flags & NDIS_80211_PMKID_CAND_PREAUTH);
3032 netdev_dbg(usbdev->net, "cand[%i]: flags: 0x%08x, preauth: %d, bssid: %pM\n",
3033 i, le32_to_cpu(cand->flags), preauth, cand->bssid);
3035 cfg80211_pmksa_candidate_notify(usbdev->net, i, cand->bssid,
3036 preauth, GFP_ATOMIC);
3040 static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
3041 struct rndis_indicate *msg, int buflen)
3043 struct ndis_80211_status_indication *indication;
3046 offset = offsetof(struct rndis_indicate, status) +
3047 le32_to_cpu(msg->offset);
3048 len = le32_to_cpu(msg->length);
3051 netdev_info(usbdev->net, "media specific indication, ignore too short message (%i < 8)\n",
3056 if (offset + len > buflen) {
3057 netdev_info(usbdev->net, "media specific indication, too large to fit to buffer (%i > %i)\n",
3058 offset + len, buflen);
3062 indication = (void *)((u8 *)msg + offset);
3064 switch (le32_to_cpu(indication->status_type)) {
3065 case NDIS_80211_STATUSTYPE_RADIOSTATE:
3066 netdev_info(usbdev->net, "radio state indication: %i\n",
3067 le32_to_cpu(indication->u.radio_status));
3070 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
3071 netdev_info(usbdev->net, "media stream mode indication: %i\n",
3072 le32_to_cpu(indication->u.media_stream_mode));
3075 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
3076 rndis_wlan_auth_indication(usbdev, indication, len);
3079 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
3080 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
3084 netdev_info(usbdev->net, "media specific indication: unknown status type 0x%08x\n",
3085 le32_to_cpu(indication->status_type));
3089 static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
3091 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3092 struct rndis_indicate *msg = ind;
3094 switch (msg->status) {
3095 case RNDIS_STATUS_MEDIA_CONNECT:
3096 if (priv->current_command_oid == OID_802_11_ADD_KEY) {
3097 /* OID_802_11_ADD_KEY causes sometimes extra
3098 * "media connect" indications which confuses driver
3099 * and userspace to think that device is
3100 * roaming/reassociating when it isn't.
3102 netdev_dbg(usbdev->net, "ignored OID_802_11_ADD_KEY triggered 'media connect'\n");
3106 usbnet_pause_rx(usbdev);
3108 netdev_info(usbdev->net, "media connect\n");
3110 /* queue work to avoid recursive calls into rndis_command */
3111 set_bit(WORK_LINK_UP, &priv->work_pending);
3112 queue_work(priv->workqueue, &priv->work);
3115 case RNDIS_STATUS_MEDIA_DISCONNECT:
3116 netdev_info(usbdev->net, "media disconnect\n");
3118 /* queue work to avoid recursive calls into rndis_command */
3119 set_bit(WORK_LINK_DOWN, &priv->work_pending);
3120 queue_work(priv->workqueue, &priv->work);
3123 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
3124 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
3128 netdev_info(usbdev->net, "indication: 0x%08x\n",
3129 le32_to_cpu(msg->status));
3134 static int rndis_wlan_get_caps(struct usbnet *usbdev, struct wiphy *wiphy)
3139 } networks_supported;
3140 struct ndis_80211_capability *caps;
3141 u8 caps_buf[sizeof(*caps) + sizeof(caps->auth_encr_pair) * 16];
3142 int len, retval, i, n;
3143 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3145 /* determine supported modes */
3146 len = sizeof(networks_supported);
3147 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
3148 &networks_supported, &len);
3150 n = le32_to_cpu(networks_supported.num_items);
3153 for (i = 0; i < n; i++) {
3154 switch (le32_to_cpu(networks_supported.items[i])) {
3155 case NDIS_80211_TYPE_FREQ_HOP:
3156 case NDIS_80211_TYPE_DIRECT_SEQ:
3157 priv->caps |= CAP_MODE_80211B;
3159 case NDIS_80211_TYPE_OFDM_A:
3160 priv->caps |= CAP_MODE_80211A;
3162 case NDIS_80211_TYPE_OFDM_G:
3163 priv->caps |= CAP_MODE_80211G;
3169 /* get device 802.11 capabilities, number of PMKIDs */
3170 caps = (struct ndis_80211_capability *)caps_buf;
3171 len = sizeof(caps_buf);
3172 retval = rndis_query_oid(usbdev, OID_802_11_CAPABILITY, caps, &len);
3174 netdev_dbg(usbdev->net, "OID_802_11_CAPABILITY -> len %d, "
3175 "ver %d, pmkids %d, auth-encr-pairs %d\n",
3176 le32_to_cpu(caps->length),
3177 le32_to_cpu(caps->version),
3178 le32_to_cpu(caps->num_pmkids),
3179 le32_to_cpu(caps->num_auth_encr_pair));
3180 wiphy->max_num_pmkids = le32_to_cpu(caps->num_pmkids);
3182 wiphy->max_num_pmkids = 0;
3187 static void rndis_do_cqm(struct usbnet *usbdev, s32 rssi)
3189 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3190 enum nl80211_cqm_rssi_threshold_event event;
3191 int thold, hyst, last_event;
3193 if (priv->cqm_rssi_thold >= 0 || rssi >= 0)
3195 if (priv->infra_mode != NDIS_80211_INFRA_INFRA)
3198 last_event = priv->last_cqm_event_rssi;
3199 thold = priv->cqm_rssi_thold;
3200 hyst = priv->cqm_rssi_hyst;
3202 if (rssi < thold && (last_event == 0 || rssi < last_event - hyst))
3203 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
3204 else if (rssi > thold && (last_event == 0 || rssi > last_event + hyst))
3205 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
3209 priv->last_cqm_event_rssi = rssi;
3210 cfg80211_cqm_rssi_notify(usbdev->net, event, GFP_KERNEL);
3213 #define DEVICE_POLLER_JIFFIES (HZ)
3214 static void rndis_device_poller(struct work_struct *work)
3216 struct rndis_wlan_private *priv =
3217 container_of(work, struct rndis_wlan_private,
3218 dev_poller_work.work);
3219 struct usbnet *usbdev = priv->usbdev;
3222 int update_jiffies = DEVICE_POLLER_JIFFIES;
3225 /* Only check/do workaround when connected. Calling is_associated()
3226 * also polls device with rndis_command() and catches for media link
3229 if (!is_associated(usbdev)) {
3230 /* Workaround bad scanning in BCM4320a devices with active
3231 * background scanning when not associated.
3233 if (priv->device_type == RNDIS_BCM4320A && priv->radio_on &&
3234 !priv->scan_request) {
3235 /* Get previous scan results */
3236 rndis_check_bssid_list(usbdev, NULL, NULL);
3238 /* Initiate new scan */
3239 rndis_start_bssid_list_scan(usbdev);
3246 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
3248 priv->last_qual = level_to_qual(le32_to_cpu(rssi));
3249 rndis_do_cqm(usbdev, le32_to_cpu(rssi));
3252 netdev_dbg(usbdev->net, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
3253 ret, le32_to_cpu(rssi), level_to_qual(le32_to_cpu(rssi)));
3255 /* Workaround transfer stalls on poor quality links.
3256 * TODO: find right way to fix these stalls (as stalls do not happen
3257 * with ndiswrapper/windows driver). */
3258 if (priv->param_workaround_interval > 0 && priv->last_qual <= 25) {
3259 /* Decrease stats worker interval to catch stalls.
3260 * faster. Faster than 400-500ms causes packet loss,
3261 * Slower doesn't catch stalls fast enough.
3263 j = msecs_to_jiffies(priv->param_workaround_interval);
3264 if (j > DEVICE_POLLER_JIFFIES)
3265 j = DEVICE_POLLER_JIFFIES;
3270 /* Send scan OID. Use of both OIDs is required to get device
3273 tmp = cpu_to_le32(1);
3274 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
3277 len = CONTROL_BUFFER_SIZE;
3278 buf = kmalloc(len, GFP_KERNEL);
3282 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
3287 if (update_jiffies >= HZ)
3288 update_jiffies = round_jiffies_relative(update_jiffies);
3290 j = round_jiffies_relative(update_jiffies);
3291 if (abs(j - update_jiffies) <= 10)
3295 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
3300 * driver/device initialization
3302 static void rndis_copy_module_params(struct usbnet *usbdev, int device_type)
3304 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3306 priv->device_type = device_type;
3308 priv->param_country[0] = modparam_country[0];
3309 priv->param_country[1] = modparam_country[1];
3310 priv->param_country[2] = 0;
3311 priv->param_frameburst = modparam_frameburst;
3312 priv->param_afterburner = modparam_afterburner;
3313 priv->param_power_save = modparam_power_save;
3314 priv->param_power_output = modparam_power_output;
3315 priv->param_roamtrigger = modparam_roamtrigger;
3316 priv->param_roamdelta = modparam_roamdelta;
3318 priv->param_country[0] = toupper(priv->param_country[0]);
3319 priv->param_country[1] = toupper(priv->param_country[1]);
3320 /* doesn't support EU as country code, use FI instead */
3321 if (!strcmp(priv->param_country, "EU"))
3322 strcpy(priv->param_country, "FI");
3324 if (priv->param_power_save < 0)
3325 priv->param_power_save = 0;
3326 else if (priv->param_power_save > 2)
3327 priv->param_power_save = 2;
3329 if (priv->param_power_output < 0)
3330 priv->param_power_output = 0;
3331 else if (priv->param_power_output > 3)
3332 priv->param_power_output = 3;
3334 if (priv->param_roamtrigger < -80)
3335 priv->param_roamtrigger = -80;
3336 else if (priv->param_roamtrigger > -60)
3337 priv->param_roamtrigger = -60;
3339 if (priv->param_roamdelta < 0)
3340 priv->param_roamdelta = 0;
3341 else if (priv->param_roamdelta > 2)
3342 priv->param_roamdelta = 2;
3344 if (modparam_workaround_interval < 0)
3345 priv->param_workaround_interval = 500;
3347 priv->param_workaround_interval = modparam_workaround_interval;
3350 static int unknown_early_init(struct usbnet *usbdev)
3352 /* copy module parameters for unknown so that iwconfig reports txpower
3353 * and workaround parameter is copied to private structure correctly.
3355 rndis_copy_module_params(usbdev, RNDIS_UNKNOWN);
3357 /* This is unknown device, so do not try set configuration parameters.
3363 static int bcm4320a_early_init(struct usbnet *usbdev)
3365 /* copy module parameters for bcm4320a so that iwconfig reports txpower
3366 * and workaround parameter is copied to private structure correctly.
3368 rndis_copy_module_params(usbdev, RNDIS_BCM4320A);
3370 /* bcm4320a doesn't handle configuration parameters well. Try
3371 * set any and you get partially zeroed mac and broken device.
3377 static int bcm4320b_early_init(struct usbnet *usbdev)
3379 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3382 rndis_copy_module_params(usbdev, RNDIS_BCM4320B);
3384 /* Early initialization settings, setting these won't have effect
3385 * if called after generic_rndis_bind().
3388 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
3389 rndis_set_config_parameter_str(usbdev, "FrameBursting",
3390 priv->param_frameburst ? "1" : "0");
3391 rndis_set_config_parameter_str(usbdev, "Afterburner",
3392 priv->param_afterburner ? "1" : "0");
3393 sprintf(buf, "%d", priv->param_power_save);
3394 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
3395 sprintf(buf, "%d", priv->param_power_output);
3396 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
3397 sprintf(buf, "%d", priv->param_roamtrigger);
3398 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
3399 sprintf(buf, "%d", priv->param_roamdelta);
3400 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
3405 /* same as rndis_netdev_ops but with local multicast handler */
3406 static const struct net_device_ops rndis_wlan_netdev_ops = {
3407 .ndo_open = usbnet_open,
3408 .ndo_stop = usbnet_stop,
3409 .ndo_start_xmit = usbnet_start_xmit,
3410 .ndo_tx_timeout = usbnet_tx_timeout,
3411 .ndo_set_mac_address = eth_mac_addr,
3412 .ndo_validate_addr = eth_validate_addr,
3413 .ndo_set_rx_mode = rndis_wlan_set_multicast_list,
3416 static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
3418 struct wiphy *wiphy;
3419 struct rndis_wlan_private *priv;
3423 /* allocate wiphy and rndis private data
3424 * NOTE: We only support a single virtual interface, so wiphy
3425 * and wireless_dev are somewhat synonymous for this device.
3427 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
3431 priv = wiphy_priv(wiphy);
3432 usbdev->net->ieee80211_ptr = &priv->wdev;
3433 priv->wdev.wiphy = wiphy;
3434 priv->wdev.iftype = NL80211_IFTYPE_STATION;
3436 /* These have to be initialized before calling generic_rndis_bind().
3437 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
3439 usbdev->driver_priv = priv;
3440 priv->usbdev = usbdev;
3442 mutex_init(&priv->command_lock);
3444 /* because rndis_command() sleeps we need to use workqueue */
3445 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
3446 INIT_WORK(&priv->work, rndis_wlan_worker);
3447 INIT_DELAYED_WORK(&priv->dev_poller_work, rndis_device_poller);
3448 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
3450 /* try bind rndis_host */
3451 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
3455 /* generic_rndis_bind set packet filter to multicast_all+
3456 * promisc mode which doesn't work well for our devices (device
3457 * picks up rssi to closest station instead of to access point).
3459 * rndis_host wants to avoid all OID as much as possible
3460 * so do promisc/multicast handling in rndis_wlan.
3462 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
3464 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
3465 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
3469 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
3471 priv->multicast_size = le32_to_cpu(tmp);
3472 if (retval < 0 || priv->multicast_size < 0)
3473 priv->multicast_size = 0;
3474 if (priv->multicast_size > 0)
3475 usbdev->net->flags |= IFF_MULTICAST;
3477 usbdev->net->flags &= ~IFF_MULTICAST;
3479 /* fill-out wiphy structure and register w/ cfg80211 */
3480 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
3481 wiphy->privid = rndis_wiphy_privid;
3482 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
3483 | BIT(NL80211_IFTYPE_ADHOC);
3484 wiphy->max_scan_ssids = 1;
3486 /* TODO: fill-out band/encr information based on priv->caps */
3487 rndis_wlan_get_caps(usbdev, wiphy);
3489 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
3490 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
3491 priv->band.channels = priv->channels;
3492 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
3493 priv->band.bitrates = priv->rates;
3494 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
3495 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3496 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
3498 memcpy(priv->cipher_suites, rndis_cipher_suites,
3499 sizeof(rndis_cipher_suites));
3500 wiphy->cipher_suites = priv->cipher_suites;
3501 wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
3503 set_wiphy_dev(wiphy, &usbdev->udev->dev);
3505 if (wiphy_register(wiphy)) {
3510 set_default_iw_params(usbdev);
3512 priv->power_mode = -1;
3514 /* set default rts/frag */
3515 rndis_set_wiphy_params(wiphy,
3516 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
3518 /* turn radio off on init */
3519 priv->radio_on = false;
3520 disassociate(usbdev, false);
3521 netif_carrier_off(usbdev->net);
3526 cancel_delayed_work_sync(&priv->dev_poller_work);
3527 cancel_delayed_work_sync(&priv->scan_work);
3528 cancel_work_sync(&priv->work);
3529 flush_workqueue(priv->workqueue);
3530 destroy_workqueue(priv->workqueue);
3536 static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
3538 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3540 /* turn radio off */
3541 disassociate(usbdev, false);
3543 cancel_delayed_work_sync(&priv->dev_poller_work);
3544 cancel_delayed_work_sync(&priv->scan_work);
3545 cancel_work_sync(&priv->work);
3546 flush_workqueue(priv->workqueue);
3547 destroy_workqueue(priv->workqueue);
3549 rndis_unbind(usbdev, intf);
3551 wiphy_unregister(priv->wdev.wiphy);
3552 wiphy_free(priv->wdev.wiphy);
3555 static int rndis_wlan_reset(struct usbnet *usbdev)
3557 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3560 netdev_dbg(usbdev->net, "%s()\n", __func__);
3562 retval = rndis_reset(usbdev);
3564 netdev_warn(usbdev->net, "rndis_reset failed: %d\n", retval);
3566 /* rndis_reset cleared multicast list, so restore here.
3567 (set_multicast_list() also turns on current packet filter) */
3568 set_multicast_list(usbdev);
3570 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
3571 round_jiffies_relative(DEVICE_POLLER_JIFFIES));
3573 return deauthenticate(usbdev);
3576 static int rndis_wlan_stop(struct usbnet *usbdev)
3578 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3582 netdev_dbg(usbdev->net, "%s()\n", __func__);
3584 retval = disassociate(usbdev, false);
3586 priv->work_pending = 0;
3587 cancel_delayed_work_sync(&priv->dev_poller_work);
3588 cancel_delayed_work_sync(&priv->scan_work);
3589 cancel_work_sync(&priv->work);
3590 flush_workqueue(priv->workqueue);
3592 if (priv->scan_request) {
3593 cfg80211_scan_done(priv->scan_request, true);
3594 priv->scan_request = NULL;
3597 /* Set current packet filter zero to block receiving data packets from
3600 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
3606 static const struct driver_info bcm4320b_info = {
3607 .description = "Wireless RNDIS device, BCM4320b based",
3608 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3609 FLAG_AVOID_UNLINK_URBS,
3610 .bind = rndis_wlan_bind,
3611 .unbind = rndis_wlan_unbind,
3612 .status = rndis_status,
3613 .rx_fixup = rndis_rx_fixup,
3614 .tx_fixup = rndis_tx_fixup,
3615 .reset = rndis_wlan_reset,
3616 .stop = rndis_wlan_stop,
3617 .early_init = bcm4320b_early_init,
3618 .indication = rndis_wlan_indication,
3621 static const struct driver_info bcm4320a_info = {
3622 .description = "Wireless RNDIS device, BCM4320a based",
3623 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3624 FLAG_AVOID_UNLINK_URBS,
3625 .bind = rndis_wlan_bind,
3626 .unbind = rndis_wlan_unbind,
3627 .status = rndis_status,
3628 .rx_fixup = rndis_rx_fixup,
3629 .tx_fixup = rndis_tx_fixup,
3630 .reset = rndis_wlan_reset,
3631 .stop = rndis_wlan_stop,
3632 .early_init = bcm4320a_early_init,
3633 .indication = rndis_wlan_indication,
3636 static const struct driver_info rndis_wlan_info = {
3637 .description = "Wireless RNDIS device",
3638 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3639 FLAG_AVOID_UNLINK_URBS,
3640 .bind = rndis_wlan_bind,
3641 .unbind = rndis_wlan_unbind,
3642 .status = rndis_status,
3643 .rx_fixup = rndis_rx_fixup,
3644 .tx_fixup = rndis_tx_fixup,
3645 .reset = rndis_wlan_reset,
3646 .stop = rndis_wlan_stop,
3647 .early_init = unknown_early_init,
3648 .indication = rndis_wlan_indication,
3651 /*-------------------------------------------------------------------------*/
3653 static const struct usb_device_id products [] = {
3654 #define RNDIS_MASTER_INTERFACE \
3655 .bInterfaceClass = USB_CLASS_COMM, \
3656 .bInterfaceSubClass = 2 /* ACM */, \
3657 .bInterfaceProtocol = 0x0ff
3659 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3660 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3663 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3664 | USB_DEVICE_ID_MATCH_DEVICE,
3666 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
3667 RNDIS_MASTER_INTERFACE,
3668 .driver_info = (unsigned long) &bcm4320b_info,
3670 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3671 | USB_DEVICE_ID_MATCH_DEVICE,
3673 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
3674 RNDIS_MASTER_INTERFACE,
3675 .driver_info = (unsigned long) &bcm4320b_info,
3677 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3678 | USB_DEVICE_ID_MATCH_DEVICE,
3680 .idProduct = 0x011b, /* Belkin F5D7051 */
3681 RNDIS_MASTER_INTERFACE,
3682 .driver_info = (unsigned long) &bcm4320b_info,
3684 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3685 | USB_DEVICE_ID_MATCH_DEVICE,
3686 .idVendor = 0x1799, /* Belkin has two vendor ids */
3687 .idProduct = 0x011b, /* Belkin F5D7051 */
3688 RNDIS_MASTER_INTERFACE,
3689 .driver_info = (unsigned long) &bcm4320b_info,
3691 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3692 | USB_DEVICE_ID_MATCH_DEVICE,
3694 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
3695 RNDIS_MASTER_INTERFACE,
3696 .driver_info = (unsigned long) &bcm4320b_info,
3698 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3699 | USB_DEVICE_ID_MATCH_DEVICE,
3701 .idProduct = 0x0026, /* Linksys WUSB54GSC */
3702 RNDIS_MASTER_INTERFACE,
3703 .driver_info = (unsigned long) &bcm4320b_info,
3705 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3706 | USB_DEVICE_ID_MATCH_DEVICE,
3708 .idProduct = 0x1717, /* Asus WL169gE */
3709 RNDIS_MASTER_INTERFACE,
3710 .driver_info = (unsigned long) &bcm4320b_info,
3712 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3713 | USB_DEVICE_ID_MATCH_DEVICE,
3715 .idProduct = 0xd11b, /* Eminent EM4045 */
3716 RNDIS_MASTER_INTERFACE,
3717 .driver_info = (unsigned long) &bcm4320b_info,
3719 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3720 | USB_DEVICE_ID_MATCH_DEVICE,
3722 .idProduct = 0x0715, /* BT Voyager 1055 */
3723 RNDIS_MASTER_INTERFACE,
3724 .driver_info = (unsigned long) &bcm4320b_info,
3726 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3727 * parameters available, hardware probably contain older firmware version with
3728 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3731 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3732 | USB_DEVICE_ID_MATCH_DEVICE,
3734 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3735 RNDIS_MASTER_INTERFACE,
3736 .driver_info = (unsigned long) &bcm4320a_info,
3738 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3739 | USB_DEVICE_ID_MATCH_DEVICE,
3741 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3742 RNDIS_MASTER_INTERFACE,
3743 .driver_info = (unsigned long) &bcm4320a_info,
3745 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3746 | USB_DEVICE_ID_MATCH_DEVICE,
3748 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3749 RNDIS_MASTER_INTERFACE,
3750 .driver_info = (unsigned long) &bcm4320a_info,
3752 /* Generic Wireless RNDIS devices that we don't have exact
3753 * idVendor/idProduct/chip yet.
3756 /* RNDIS is MSFT's un-official variant of CDC ACM */
3757 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3758 .driver_info = (unsigned long) &rndis_wlan_info,
3760 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3761 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
3762 .driver_info = (unsigned long) &rndis_wlan_info,
3766 MODULE_DEVICE_TABLE(usb, products);
3768 static struct usb_driver rndis_wlan_driver = {
3769 .name = "rndis_wlan",
3770 .id_table = products,
3771 .probe = usbnet_probe,
3772 .disconnect = usbnet_disconnect,
3773 .suspend = usbnet_suspend,
3774 .resume = usbnet_resume,
3777 module_usb_driver(rndis_wlan_driver);
3779 MODULE_AUTHOR("Bjorge Dijkstra");
3780 MODULE_AUTHOR("Jussi Kivilinna");
3781 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3782 MODULE_LICENSE("GPL");