2 * Driver for RNDIS based wireless USB devices.
4 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
5 * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Portions of this file are based on NDISwrapper project,
22 * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
23 * http://ndiswrapper.sourceforge.net/
26 // #define DEBUG // error path messages, extra info
27 // #define VERBOSE // more; success messages
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/ethtool.h>
34 #include <linux/workqueue.h>
35 #include <linux/mutex.h>
36 #include <linux/mii.h>
37 #include <linux/usb.h>
38 #include <linux/usb/cdc.h>
39 #include <linux/wireless.h>
40 #include <linux/ieee80211.h>
41 #include <linux/if_arp.h>
42 #include <linux/ctype.h>
43 #include <linux/spinlock.h>
44 #include <net/iw_handler.h>
45 #include <net/cfg80211.h>
46 #include <linux/usb/usbnet.h>
47 #include <linux/usb/rndis_host.h>
50 /* NOTE: All these are settings for Broadcom chipset */
51 static char modparam_country[4] = "EU";
52 module_param_string(country, modparam_country, 4, 0444);
53 MODULE_PARM_DESC(country, "Country code (ISO 3166-1 alpha-2), default: EU");
55 static int modparam_frameburst = 1;
56 module_param_named(frameburst, modparam_frameburst, int, 0444);
57 MODULE_PARM_DESC(frameburst, "enable frame bursting (default: on)");
59 static int modparam_afterburner = 0;
60 module_param_named(afterburner, modparam_afterburner, int, 0444);
61 MODULE_PARM_DESC(afterburner,
62 "enable afterburner aka '125 High Speed Mode' (default: off)");
64 static int modparam_power_save = 0;
65 module_param_named(power_save, modparam_power_save, int, 0444);
66 MODULE_PARM_DESC(power_save,
67 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
69 static int modparam_power_output = 3;
70 module_param_named(power_output, modparam_power_output, int, 0444);
71 MODULE_PARM_DESC(power_output,
72 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
74 static int modparam_roamtrigger = -70;
75 module_param_named(roamtrigger, modparam_roamtrigger, int, 0444);
76 MODULE_PARM_DESC(roamtrigger,
77 "set roaming dBm trigger: -80=optimize for distance, "
78 "-60=bandwidth (default: -70)");
80 static int modparam_roamdelta = 1;
81 module_param_named(roamdelta, modparam_roamdelta, int, 0444);
82 MODULE_PARM_DESC(roamdelta,
83 "set roaming tendency: 0=aggressive, 1=moderate, "
84 "2=conservative (default: moderate)");
86 static int modparam_workaround_interval = 500;
87 module_param_named(workaround_interval, modparam_workaround_interval,
89 MODULE_PARM_DESC(workaround_interval,
90 "set stall workaround interval in msecs (default: 500)");
93 /* various RNDIS OID defs */
94 #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
95 #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
97 #define OID_GEN_XMIT_OK cpu_to_le32(0x00020101)
98 #define OID_GEN_RCV_OK cpu_to_le32(0x00020102)
99 #define OID_GEN_XMIT_ERROR cpu_to_le32(0x00020103)
100 #define OID_GEN_RCV_ERROR cpu_to_le32(0x00020104)
101 #define OID_GEN_RCV_NO_BUFFER cpu_to_le32(0x00020105)
103 #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
104 #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
105 #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
107 #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
108 #define OID_802_11_SSID cpu_to_le32(0x0d010102)
109 #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
110 #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
111 #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
112 #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
113 #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
114 #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
115 #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
116 #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
117 #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
118 #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
119 #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
120 #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
121 #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
122 #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
123 #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
124 #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
125 #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
126 #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
127 #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
128 #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
129 #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
130 #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
133 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
134 #define WL_NOISE -96 /* typical noise level in dBm */
135 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
138 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
139 * based on wireless rndis) has default txpower of 13dBm.
140 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
141 * 100% : 20 mW ~ 13dBm
142 * 75% : 15 mW ~ 12dBm
143 * 50% : 10 mW ~ 10dBm
146 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
147 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
148 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
149 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
152 /* codes for "status" field of completion messages */
153 #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
154 #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
157 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
158 * slightly modified for datatype endianess, etc
160 #define NDIS_802_11_LENGTH_SSID 32
161 #define NDIS_802_11_LENGTH_RATES 8
162 #define NDIS_802_11_LENGTH_RATES_EX 16
164 enum ndis_80211_net_type {
165 NDIS_80211_TYPE_FREQ_HOP,
166 NDIS_80211_TYPE_DIRECT_SEQ,
167 NDIS_80211_TYPE_OFDM_A,
168 NDIS_80211_TYPE_OFDM_G
171 enum ndis_80211_net_infra {
172 NDIS_80211_INFRA_ADHOC,
173 NDIS_80211_INFRA_INFRA,
174 NDIS_80211_INFRA_AUTO_UNKNOWN
177 enum ndis_80211_auth_mode {
178 NDIS_80211_AUTH_OPEN,
179 NDIS_80211_AUTH_SHARED,
180 NDIS_80211_AUTH_AUTO_SWITCH,
182 NDIS_80211_AUTH_WPA_PSK,
183 NDIS_80211_AUTH_WPA_NONE,
184 NDIS_80211_AUTH_WPA2,
185 NDIS_80211_AUTH_WPA2_PSK
188 enum ndis_80211_encr_status {
189 NDIS_80211_ENCR_WEP_ENABLED,
190 NDIS_80211_ENCR_DISABLED,
191 NDIS_80211_ENCR_WEP_KEY_ABSENT,
192 NDIS_80211_ENCR_NOT_SUPPORTED,
193 NDIS_80211_ENCR_TKIP_ENABLED,
194 NDIS_80211_ENCR_TKIP_KEY_ABSENT,
195 NDIS_80211_ENCR_CCMP_ENABLED,
196 NDIS_80211_ENCR_CCMP_KEY_ABSENT
199 enum ndis_80211_priv_filter {
200 NDIS_80211_PRIV_ACCEPT_ALL,
201 NDIS_80211_PRIV_8021X_WEP
204 enum ndis_80211_status_type {
205 NDIS_80211_STATUSTYPE_AUTHENTICATION,
206 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE,
207 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST,
208 NDIS_80211_STATUSTYPE_RADIOSTATE,
211 enum ndis_80211_media_stream_mode {
212 NDIS_80211_MEDIA_STREAM_OFF,
213 NDIS_80211_MEDIA_STREAM_ON
216 enum ndis_80211_radio_status {
217 NDIS_80211_RADIO_STATUS_ON,
218 NDIS_80211_RADIO_STATUS_HARDWARE_OFF,
219 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF,
222 enum ndis_80211_addkey_bits {
223 NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
224 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
225 NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
226 NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
229 enum ndis_80211_addwep_bits {
230 NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
231 NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
234 struct ndis_80211_auth_request {
239 } __attribute__((packed));
241 struct ndis_80211_pmkid_candidate {
245 } __attribute__((packed));
247 struct ndis_80211_pmkid_cand_list {
249 __le32 num_candidates;
250 struct ndis_80211_pmkid_candidate candidate_list[0];
251 } __attribute__((packed));
253 struct ndis_80211_status_indication {
256 enum ndis_80211_media_stream_mode media_stream_mode;
257 enum ndis_80211_radio_status radio_status;
258 struct ndis_80211_auth_request auth_request[0];
259 struct ndis_80211_pmkid_cand_list cand_list;
261 } __attribute__((packed));
263 struct ndis_80211_ssid {
265 u8 essid[NDIS_802_11_LENGTH_SSID];
266 } __attribute__((packed));
268 struct ndis_80211_conf_freq_hop {
273 } __attribute__((packed));
275 struct ndis_80211_conf {
277 __le32 beacon_period;
280 struct ndis_80211_conf_freq_hop fh_config;
281 } __attribute__((packed));
283 struct ndis_80211_bssid_ex {
287 struct ndis_80211_ssid ssid;
291 struct ndis_80211_conf config;
293 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
296 } __attribute__((packed));
298 struct ndis_80211_bssid_list_ex {
300 struct ndis_80211_bssid_ex bssid[0];
301 } __attribute__((packed));
303 struct ndis_80211_fixed_ies {
305 __le16 beacon_interval;
307 } __attribute__((packed));
309 struct ndis_80211_wep_key {
314 } __attribute__((packed));
316 struct ndis_80211_key {
324 } __attribute__((packed));
326 struct ndis_80211_remove_key {
331 } __attribute__((packed));
333 struct ndis_config_param {
339 } __attribute__((packed));
341 struct ndis_80211_assoc_info {
346 __le16 listen_interval;
347 u8 cur_ap_address[6];
349 __le32 req_ie_length;
350 __le32 offset_req_ies;
357 __le32 resp_ie_length;
358 __le32 offset_resp_ies;
359 } __attribute__((packed));
361 /* these have to match what is in wpa_supplicant */
362 enum wpa_alg { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP };
363 enum wpa_cipher { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
365 enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
366 KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE };
371 #define NET_TYPE_11FB 0
373 #define CAP_MODE_80211A 1
374 #define CAP_MODE_80211B 2
375 #define CAP_MODE_80211G 4
376 #define CAP_MODE_MASK 7
378 #define WORK_LINK_UP (1<<0)
379 #define WORK_LINK_DOWN (1<<1)
380 #define WORK_SET_MULTICAST_LIST (1<<2)
382 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
384 static const struct ieee80211_channel rndis_channels[] = {
385 { .center_freq = 2412 },
386 { .center_freq = 2417 },
387 { .center_freq = 2422 },
388 { .center_freq = 2427 },
389 { .center_freq = 2432 },
390 { .center_freq = 2437 },
391 { .center_freq = 2442 },
392 { .center_freq = 2447 },
393 { .center_freq = 2452 },
394 { .center_freq = 2457 },
395 { .center_freq = 2462 },
396 { .center_freq = 2467 },
397 { .center_freq = 2472 },
398 { .center_freq = 2484 },
401 static const struct ieee80211_rate rndis_rates[] = {
403 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
404 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
405 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
416 /* RNDIS device private data */
417 struct rndis_wlan_private {
418 struct usbnet *usbdev;
420 struct wireless_dev wdev;
422 struct cfg80211_scan_request *scan_request;
424 struct workqueue_struct *workqueue;
425 struct delayed_work stats_work;
426 struct delayed_work scan_work;
427 struct work_struct work;
428 struct mutex command_lock;
429 spinlock_t stats_lock;
430 unsigned long work_pending;
432 struct ieee80211_supported_band band;
433 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
434 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
436 struct iw_statistics iwstats;
437 struct iw_statistics privstats;
442 /* module parameters */
443 char param_country[4];
444 int param_frameburst;
445 int param_afterburner;
446 int param_power_save;
447 int param_power_output;
448 int param_roamtrigger;
450 u32 param_workaround_interval;
455 struct ndis_80211_ssid essid;
457 /* encryption stuff */
458 int encr_tx_key_index;
459 char encr_keys[4][32];
461 char encr_key_wpa[4];
468 int wpa_cipher_group;
470 u8 command_buffer[COMMAND_BUFFER_SIZE];
476 static int rndis_change_virtual_intf(struct wiphy *wiphy,
477 struct net_device *dev,
478 enum nl80211_iftype type, u32 *flags,
479 struct vif_params *params);
481 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
482 struct cfg80211_scan_request *request);
484 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
486 static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
488 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
490 static struct cfg80211_ops rndis_config_ops = {
491 .change_virtual_intf = rndis_change_virtual_intf,
493 .set_wiphy_params = rndis_set_wiphy_params,
494 .set_tx_power = rndis_set_tx_power,
495 .get_tx_power = rndis_get_tx_power,
498 static void *rndis_wiphy_privid = &rndis_wiphy_privid;
501 static const unsigned char zero_bssid[ETH_ALEN] = {0,};
502 static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff,
506 static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
508 return (struct rndis_wlan_private *)dev->driver_priv;
512 static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
514 switch (priv->param_power_output) {
517 return BCM4320_DEFAULT_TXPOWER_DBM_100;
519 return BCM4320_DEFAULT_TXPOWER_DBM_75;
521 return BCM4320_DEFAULT_TXPOWER_DBM_50;
523 return BCM4320_DEFAULT_TXPOWER_DBM_25;
529 static const char *oid_to_string(__le32 oid)
532 #define OID_STR(oid) case oid: return(#oid)
533 /* from rndis_host.h */
534 OID_STR(OID_802_3_PERMANENT_ADDRESS);
535 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
536 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
537 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
539 /* from rndis_wlan.c */
540 OID_STR(OID_GEN_LINK_SPEED);
541 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
543 OID_STR(OID_GEN_XMIT_OK);
544 OID_STR(OID_GEN_RCV_OK);
545 OID_STR(OID_GEN_XMIT_ERROR);
546 OID_STR(OID_GEN_RCV_ERROR);
547 OID_STR(OID_GEN_RCV_NO_BUFFER);
549 OID_STR(OID_802_3_CURRENT_ADDRESS);
550 OID_STR(OID_802_3_MULTICAST_LIST);
551 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
553 OID_STR(OID_802_11_BSSID);
554 OID_STR(OID_802_11_SSID);
555 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
556 OID_STR(OID_802_11_ADD_WEP);
557 OID_STR(OID_802_11_REMOVE_WEP);
558 OID_STR(OID_802_11_DISASSOCIATE);
559 OID_STR(OID_802_11_AUTHENTICATION_MODE);
560 OID_STR(OID_802_11_PRIVACY_FILTER);
561 OID_STR(OID_802_11_BSSID_LIST_SCAN);
562 OID_STR(OID_802_11_ENCRYPTION_STATUS);
563 OID_STR(OID_802_11_ADD_KEY);
564 OID_STR(OID_802_11_REMOVE_KEY);
565 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
566 OID_STR(OID_802_11_PMKID);
567 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
568 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
569 OID_STR(OID_802_11_TX_POWER_LEVEL);
570 OID_STR(OID_802_11_RSSI);
571 OID_STR(OID_802_11_RSSI_TRIGGER);
572 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
573 OID_STR(OID_802_11_RTS_THRESHOLD);
574 OID_STR(OID_802_11_SUPPORTED_RATES);
575 OID_STR(OID_802_11_CONFIGURATION);
576 OID_STR(OID_802_11_BSSID_LIST);
583 static const char *oid_to_string(__le32 oid)
590 /* translate error code */
591 static int rndis_error_status(__le32 rndis_status)
594 switch (rndis_status) {
595 case RNDIS_STATUS_SUCCESS:
598 case RNDIS_STATUS_FAILURE:
599 case RNDIS_STATUS_INVALID_DATA:
602 case RNDIS_STATUS_NOT_SUPPORTED:
605 case RNDIS_STATUS_ADAPTER_NOT_READY:
606 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
614 static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
616 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
619 struct rndis_msg_hdr *header;
620 struct rndis_query *get;
621 struct rndis_query_c *get_c;
625 buflen = *len + sizeof(*u.get);
626 if (buflen < CONTROL_BUFFER_SIZE)
627 buflen = CONTROL_BUFFER_SIZE;
629 if (buflen > COMMAND_BUFFER_SIZE) {
630 u.buf = kmalloc(buflen, GFP_KERNEL);
634 u.buf = priv->command_buffer;
637 mutex_lock(&priv->command_lock);
639 memset(u.get, 0, sizeof *u.get);
640 u.get->msg_type = RNDIS_MSG_QUERY;
641 u.get->msg_len = cpu_to_le32(sizeof *u.get);
644 ret = rndis_command(dev, u.header, buflen);
646 devdbg(dev, "rndis_query_oid(%s): rndis_command() failed, %d "
647 "(%08x)", oid_to_string(oid), ret,
648 le32_to_cpu(u.get_c->status));
651 ret = le32_to_cpu(u.get_c->len);
652 *len = (*len > ret) ? ret : *len;
653 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
654 ret = rndis_error_status(u.get_c->status);
657 devdbg(dev, "rndis_query_oid(%s): device returned "
658 "error, 0x%08x (%d)", oid_to_string(oid),
659 le32_to_cpu(u.get_c->status), ret);
662 mutex_unlock(&priv->command_lock);
664 if (u.buf != priv->command_buffer)
670 static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
672 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
675 struct rndis_msg_hdr *header;
676 struct rndis_set *set;
677 struct rndis_set_c *set_c;
681 buflen = len + sizeof(*u.set);
682 if (buflen < CONTROL_BUFFER_SIZE)
683 buflen = CONTROL_BUFFER_SIZE;
685 if (buflen > COMMAND_BUFFER_SIZE) {
686 u.buf = kmalloc(buflen, GFP_KERNEL);
690 u.buf = priv->command_buffer;
693 mutex_lock(&priv->command_lock);
695 memset(u.set, 0, sizeof *u.set);
696 u.set->msg_type = RNDIS_MSG_SET;
697 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
699 u.set->len = cpu_to_le32(len);
700 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
701 u.set->handle = cpu_to_le32(0);
702 memcpy(u.buf + sizeof(*u.set), data, len);
704 ret = rndis_command(dev, u.header, buflen);
706 devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
707 "(%08x)", oid_to_string(oid), ret,
708 le32_to_cpu(u.set_c->status));
711 ret = rndis_error_status(u.set_c->status);
714 devdbg(dev, "rndis_set_oid(%s): device returned error, "
715 "0x%08x (%d)", oid_to_string(oid),
716 le32_to_cpu(u.set_c->status), ret);
719 mutex_unlock(&priv->command_lock);
721 if (u.buf != priv->command_buffer)
727 static int rndis_reset(struct usbnet *usbdev)
729 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
730 struct rndis_reset *reset;
733 mutex_lock(&priv->command_lock);
735 reset = (void *)priv->command_buffer;
736 memset(reset, 0, sizeof(*reset));
737 reset->msg_type = RNDIS_MSG_RESET;
738 reset->msg_len = cpu_to_le32(sizeof(*reset));
739 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
741 mutex_unlock(&priv->command_lock);
750 * Specs say that we can only set config parameters only soon after device
752 * value_type: 0 = u32, 2 = unicode string
754 static int rndis_set_config_parameter(struct usbnet *dev, char *param,
755 int value_type, void *value)
757 struct ndis_config_param *infobuf;
758 int value_len, info_len, param_len, ret, i;
763 value_len = sizeof(__le32);
764 else if (value_type == 2)
765 value_len = strlen(value) * sizeof(__le16);
769 param_len = strlen(param) * sizeof(__le16);
770 info_len = sizeof(*infobuf) + param_len + value_len;
775 infobuf = kmalloc(info_len, GFP_KERNEL);
781 /* extra 12 bytes are for padding (debug output) */
782 memset(infobuf, 0xCC, info_len + 12);
786 devdbg(dev, "setting config parameter: %s, value: %s",
789 devdbg(dev, "setting config parameter: %s, value: %d",
790 param, *(u32 *)value);
792 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
793 infobuf->name_length = cpu_to_le32(param_len);
794 infobuf->type = cpu_to_le32(value_type);
795 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
796 infobuf->value_length = cpu_to_le32(value_len);
798 /* simple string to unicode string conversion */
799 unibuf = (void *)infobuf + sizeof(*infobuf);
800 for (i = 0; i < param_len / sizeof(__le16); i++)
801 unibuf[i] = cpu_to_le16(param[i]);
803 if (value_type == 2) {
804 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
805 for (i = 0; i < value_len / sizeof(__le16); i++)
806 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
808 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
809 *dst_value = cpu_to_le32(*(u32 *)value);
813 devdbg(dev, "info buffer (len: %d):", info_len);
814 for (i = 0; i < info_len; i += 12) {
815 u32 *tmp = (u32 *)((u8 *)infobuf + i);
816 devdbg(dev, "%08X:%08X:%08X",
819 cpu_to_be32(tmp[2]));
823 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
826 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
832 static int rndis_set_config_parameter_str(struct usbnet *dev,
833 char *param, char *value)
835 return(rndis_set_config_parameter(dev, param, 2, value));
838 /*static int rndis_set_config_parameter_u32(struct usbnet *dev,
839 char *param, u32 value)
841 return(rndis_set_config_parameter(dev, param, 0, &value));
846 * data conversion functions
848 static int level_to_qual(int level)
850 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
851 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
855 static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
861 /* see comment in wireless.h above the "struct iw_freq"
862 * definition for an explanation of this if
863 * NOTE: 1000000 is due to the kHz
865 if (dsconfig > 1000000) {
866 freq->m = dsconfig / 10;
871 /* convert from kHz to Hz */
876 static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
878 if (freq->m < 1000 && freq->e == 0) {
879 if (freq->m >= 1 && freq->m <= 14)
880 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
886 for (i = freq->e; i > 0; i--)
899 add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index);
901 static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
906 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
913 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
915 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
916 tmp[le32_to_cpu(ssid->length)] = 0;
917 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
924 static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
926 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
929 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
931 memcpy(&priv->essid, ssid, sizeof(priv->essid));
933 devdbg(usbdev, "set_essid: radio_on = 1");
940 static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
945 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
948 memset(bssid, 0, ETH_ALEN);
953 static int get_association_info(struct usbnet *usbdev,
954 struct ndis_80211_assoc_info *info, int len)
956 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
960 static int is_associated(struct usbnet *usbdev)
965 ret = get_bssid(usbdev, bssid);
967 return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0);
971 static int disassociate(struct usbnet *usbdev, int reset_ssid)
973 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
974 struct ndis_80211_ssid ssid;
977 if (priv->radio_on) {
978 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
981 devdbg(usbdev, "disassociate: radio_on = 0");
988 /* disassociate causes radio to be turned off; if reset_ssid
989 * is given, set random ssid to enable radio */
991 ssid.length = cpu_to_le32(sizeof(ssid.essid));
992 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
994 ssid.essid[1] = 0xff;
995 for (i = 2; i < sizeof(ssid.essid); i++)
996 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
997 ret = set_essid(usbdev, &ssid);
1003 static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
1005 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1009 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
1010 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
1012 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
1013 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
1014 auth_mode = NDIS_80211_AUTH_WPA2;
1016 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
1017 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
1018 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
1019 auth_mode = NDIS_80211_AUTH_WPA;
1020 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
1021 auth_mode = NDIS_80211_AUTH_WPA_PSK;
1023 auth_mode = NDIS_80211_AUTH_WPA_NONE;
1024 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
1025 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
1026 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
1028 auth_mode = NDIS_80211_AUTH_SHARED;
1030 auth_mode = NDIS_80211_AUTH_OPEN;
1032 tmp = cpu_to_le32(auth_mode);
1033 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1036 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
1040 priv->wpa_version = wpa_version;
1041 priv->wpa_authalg = authalg;
1046 static int set_priv_filter(struct usbnet *usbdev)
1048 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1051 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
1053 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
1054 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
1055 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
1057 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
1059 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1064 static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1066 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1070 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
1074 if (pairwise & IW_AUTH_CIPHER_CCMP)
1075 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1076 else if (pairwise & IW_AUTH_CIPHER_TKIP)
1077 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1079 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
1080 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
1081 else if (groupwise & IW_AUTH_CIPHER_CCMP)
1082 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1083 else if (groupwise & IW_AUTH_CIPHER_TKIP)
1084 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1086 encr_mode = NDIS_80211_ENCR_DISABLED;
1088 tmp = cpu_to_le32(encr_mode);
1089 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1092 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
1096 priv->wpa_cipher_pair = pairwise;
1097 priv->wpa_cipher_group = groupwise;
1102 static int set_assoc_params(struct usbnet *usbdev)
1104 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1106 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
1107 set_priv_filter(usbdev);
1108 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
1114 static int set_infra_mode(struct usbnet *usbdev, int mode)
1116 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1120 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
1122 tmp = cpu_to_le32(mode);
1123 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1126 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
1130 /* NDIS drivers clear keys when infrastructure mode is
1131 * changed. But Linux tools assume otherwise. So set the
1133 if (priv->wpa_keymgmt == 0 ||
1134 priv->wpa_keymgmt == IW_AUTH_KEY_MGMT_802_1X) {
1135 for (i = 0; i < 4; i++) {
1136 if (priv->encr_key_len[i] > 0 && !priv->encr_key_wpa[i])
1137 add_wep_key(usbdev, priv->encr_keys[i],
1138 priv->encr_key_len[i], i);
1142 priv->infra_mode = mode;
1147 static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1151 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1153 if (rts_threshold < 0 || rts_threshold > 2347)
1154 rts_threshold = 2347;
1156 tmp = cpu_to_le32(rts_threshold);
1157 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1162 static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1166 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1168 if (frag_threshold < 256 || frag_threshold > 2346)
1169 frag_threshold = 2346;
1171 tmp = cpu_to_le32(frag_threshold);
1172 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1177 static void set_default_iw_params(struct usbnet *usbdev)
1179 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1181 priv->wpa_keymgmt = 0;
1182 priv->wpa_version = 0;
1184 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1185 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1186 IW_AUTH_ALG_OPEN_SYSTEM);
1187 set_priv_filter(usbdev);
1188 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1192 static int deauthenticate(struct usbnet *usbdev)
1196 ret = disassociate(usbdev, 1);
1197 set_default_iw_params(usbdev);
1202 /* index must be 0 - N, as per NDIS */
1203 static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
1205 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1206 struct ndis_80211_wep_key ndis_key;
1209 if (key_len <= 0 || key_len > 32 || index < 0 || index >= 4)
1212 memset(&ndis_key, 0, sizeof(ndis_key));
1214 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1215 ndis_key.length = cpu_to_le32(key_len);
1216 ndis_key.index = cpu_to_le32(index);
1217 memcpy(&ndis_key.material, key, key_len);
1219 if (index == priv->encr_tx_key_index) {
1220 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
1221 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1222 IW_AUTH_CIPHER_NONE);
1224 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1228 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1231 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1236 priv->encr_key_len[index] = key_len;
1237 priv->encr_key_wpa[index] = 0;
1238 memcpy(&priv->encr_keys[index], key, key_len);
1244 static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
1245 int index, const struct sockaddr *addr,
1246 const u8 *rx_seq, int alg, int flags)
1248 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1249 struct ndis_80211_key ndis_key;
1252 if (index < 0 || index >= 4)
1254 if (key_len > sizeof(ndis_key.material) || key_len < 0)
1256 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq)
1258 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !addr)
1261 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
1262 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1263 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1264 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
1266 memset(&ndis_key, 0, sizeof(ndis_key));
1268 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1269 sizeof(ndis_key.material) + key_len);
1270 ndis_key.length = cpu_to_le32(key_len);
1271 ndis_key.index = cpu_to_le32(index) | flags;
1273 if (alg == IW_ENCODE_ALG_TKIP && key_len == 32) {
1274 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1275 * different order than NDIS spec, so swap the order here. */
1276 memcpy(ndis_key.material, key, 16);
1277 memcpy(ndis_key.material + 16, key + 24, 8);
1278 memcpy(ndis_key.material + 24, key + 16, 8);
1280 memcpy(ndis_key.material, key, key_len);
1282 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
1283 memcpy(ndis_key.rsc, rx_seq, 6);
1285 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
1287 memcpy(ndis_key.bssid, addr->sa_data, ETH_ALEN);
1290 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
1291 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1293 get_bssid(usbdev, ndis_key.bssid);
1296 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1297 le32_to_cpu(ndis_key.size));
1298 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1302 priv->encr_key_len[index] = key_len;
1303 priv->encr_key_wpa[index] = 1;
1305 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
1306 priv->encr_tx_key_index = index;
1312 /* remove_key is for both wep and wpa */
1313 static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1315 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1316 struct ndis_80211_remove_key remove_key;
1320 if (priv->encr_key_len[index] == 0)
1323 priv->encr_key_len[index] = 0;
1324 priv->encr_key_wpa[index] = 0;
1325 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1327 if (priv->wpa_cipher_pair == IW_AUTH_CIPHER_TKIP ||
1328 priv->wpa_cipher_pair == IW_AUTH_CIPHER_CCMP ||
1329 priv->wpa_cipher_group == IW_AUTH_CIPHER_TKIP ||
1330 priv->wpa_cipher_group == IW_AUTH_CIPHER_CCMP) {
1331 remove_key.size = cpu_to_le32(sizeof(remove_key));
1332 remove_key.index = cpu_to_le32(index);
1335 if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0)
1337 NDIS_80211_ADDKEY_PAIRWISE_KEY;
1338 memcpy(remove_key.bssid, bssid,
1339 sizeof(remove_key.bssid));
1341 memset(remove_key.bssid, 0xff,
1342 sizeof(remove_key.bssid));
1344 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1345 sizeof(remove_key));
1349 keyindex = cpu_to_le32(index);
1350 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1354 "removing encryption key %d failed (%08X)",
1360 /* if it is transmit key, disable encryption */
1361 if (index == priv->encr_tx_key_index)
1362 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1368 static void set_multicast_list(struct usbnet *usbdev)
1370 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1371 struct dev_mc_list *mclist;
1376 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1378 if (usbdev->net->flags & IFF_PROMISC) {
1379 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1380 RNDIS_PACKET_TYPE_ALL_LOCAL;
1381 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1382 usbdev->net->mc_count > priv->multicast_size) {
1383 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1384 } else if (usbdev->net->mc_count > 0) {
1385 size = min(priv->multicast_size, usbdev->net->mc_count);
1386 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1389 "couldn't alloc %d bytes of memory",
1394 mclist = usbdev->net->mc_list;
1395 for (i = 0; i < size && mclist; mclist = mclist->next) {
1396 if (mclist->dmi_addrlen != ETH_ALEN)
1399 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1403 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1405 if (ret == 0 && i > 0)
1406 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1408 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1410 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1411 i, priv->multicast_size, ret);
1416 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1419 devwarn(usbdev, "couldn't set packet filter: %08x",
1420 le32_to_cpu(filter));
1423 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1424 le32_to_cpu(filter), ret);
1431 static int rndis_change_virtual_intf(struct wiphy *wiphy,
1432 struct net_device *dev,
1433 enum nl80211_iftype type, u32 *flags,
1434 struct vif_params *params)
1436 struct usbnet *usbdev = netdev_priv(dev);
1440 case NL80211_IFTYPE_ADHOC:
1441 mode = NDIS_80211_INFRA_ADHOC;
1443 case NL80211_IFTYPE_STATION:
1444 mode = NDIS_80211_INFRA_INFRA;
1450 return set_infra_mode(usbdev, mode);
1454 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1456 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1457 struct usbnet *usbdev = priv->usbdev;
1460 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1461 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1466 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1467 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1476 static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1479 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1480 struct usbnet *usbdev = priv->usbdev;
1482 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1484 /* Device doesn't support changing txpower after initialization, only
1485 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1488 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1489 if (!priv->radio_on)
1490 disassociate(usbdev, 1); /* turn on radio */
1499 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1501 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1502 struct usbnet *usbdev = priv->usbdev;
1504 *dbm = get_bcm4320_power_dbm(priv);
1506 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1512 #define SCAN_DELAY_JIFFIES (HZ)
1513 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1514 struct cfg80211_scan_request *request)
1516 struct usbnet *usbdev = netdev_priv(dev);
1517 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1521 devdbg(usbdev, "cfg80211.scan");
1526 if (priv->scan_request && priv->scan_request != request)
1529 priv->scan_request = request;
1531 tmp = cpu_to_le32(1);
1532 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1535 /* Wait before retrieving scan results from device */
1536 queue_delayed_work(priv->workqueue, &priv->scan_work,
1537 SCAN_DELAY_JIFFIES);
1544 static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1545 struct ndis_80211_bssid_ex *bssid)
1547 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1548 struct ieee80211_channel *channel;
1552 u16 beacon_interval;
1553 struct ndis_80211_fixed_ies *fixed;
1554 int ie_len, bssid_len;
1557 /* parse bssid structure */
1558 bssid_len = le32_to_cpu(bssid->length);
1560 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1561 sizeof(struct ndis_80211_fixed_ies))
1564 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1566 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1567 ie_len = min(bssid_len - (int)sizeof(*bssid),
1568 (int)le32_to_cpu(bssid->ie_length));
1569 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1573 /* extract data for cfg80211_inform_bss */
1574 channel = ieee80211_get_channel(priv->wdev.wiphy,
1575 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1579 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1580 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1581 capability = le16_to_cpu(fixed->capabilities);
1582 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1584 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1585 timestamp, capability, beacon_interval, ie, ie_len, signal,
1590 static int rndis_check_bssid_list(struct usbnet *usbdev)
1593 struct ndis_80211_bssid_list_ex *bssid_list;
1594 struct ndis_80211_bssid_ex *bssid;
1595 int ret = -EINVAL, len, count, bssid_len;
1597 devdbg(usbdev, "check_bssid_list");
1599 len = CONTROL_BUFFER_SIZE;
1600 buf = kmalloc(len, GFP_KERNEL);
1606 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1611 bssid = bssid_list->bssid;
1612 bssid_len = le32_to_cpu(bssid->length);
1613 count = le32_to_cpu(bssid_list->num_items);
1614 devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count);
1616 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1617 rndis_bss_info_update(usbdev, bssid);
1619 bssid = (void *)bssid + bssid_len;
1620 bssid_len = le32_to_cpu(bssid->length);
1630 static void rndis_get_scan_results(struct work_struct *work)
1632 struct rndis_wlan_private *priv =
1633 container_of(work, struct rndis_wlan_private, scan_work.work);
1634 struct usbnet *usbdev = priv->usbdev;
1637 devdbg(usbdev, "get_scan_results");
1639 if (!priv->scan_request)
1642 ret = rndis_check_bssid_list(usbdev);
1644 cfg80211_scan_done(priv->scan_request, ret < 0);
1646 priv->scan_request = NULL;
1651 * wireless extension handlers
1654 static int rndis_iw_commit(struct net_device *dev,
1655 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1662 static int rndis_iw_set_essid(struct net_device *dev,
1663 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1665 struct ndis_80211_ssid ssid;
1666 int length = wrqu->essid.length;
1667 struct usbnet *usbdev = netdev_priv(dev);
1669 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1670 wrqu->essid.flags, wrqu->essid.length, essid);
1672 if (length > NDIS_802_11_LENGTH_SSID)
1673 length = NDIS_802_11_LENGTH_SSID;
1675 ssid.length = cpu_to_le32(length);
1677 memcpy(ssid.essid, essid, length);
1679 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
1681 set_assoc_params(usbdev);
1683 if (!wrqu->essid.flags || length == 0)
1684 return disassociate(usbdev, 1);
1686 return set_essid(usbdev, &ssid);
1690 static int rndis_iw_get_essid(struct net_device *dev,
1691 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1693 struct ndis_80211_ssid ssid;
1694 struct usbnet *usbdev = netdev_priv(dev);
1697 ret = get_essid(usbdev, &ssid);
1699 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
1700 wrqu->essid.flags = 1;
1701 wrqu->essid.length = le32_to_cpu(ssid.length);
1702 memcpy(essid, ssid.essid, wrqu->essid.length);
1703 essid[wrqu->essid.length] = 0;
1705 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1706 wrqu->essid.flags = 0;
1707 wrqu->essid.length = 0;
1709 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1714 static int rndis_iw_get_bssid(struct net_device *dev,
1715 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1717 struct usbnet *usbdev = netdev_priv(dev);
1718 unsigned char bssid[ETH_ALEN];
1721 ret = get_bssid(usbdev, bssid);
1724 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
1726 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1728 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1729 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1735 static int rndis_iw_set_bssid(struct net_device *dev,
1736 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1738 struct usbnet *usbdev = netdev_priv(dev);
1739 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
1742 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
1744 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1746 /* user apps may set ap's mac address, which is not required;
1747 * they may fail to work if this function fails, so return
1750 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1756 static int rndis_iw_set_auth(struct net_device *dev,
1757 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1759 struct iw_param *p = &wrqu->param;
1760 struct usbnet *usbdev = netdev_priv(dev);
1761 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1762 int ret = -ENOTSUPP;
1764 switch (p->flags & IW_AUTH_INDEX) {
1765 case IW_AUTH_WPA_VERSION:
1766 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1767 priv->wpa_version = p->value;
1771 case IW_AUTH_CIPHER_PAIRWISE:
1772 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1773 priv->wpa_cipher_pair = p->value;
1777 case IW_AUTH_CIPHER_GROUP:
1778 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1779 priv->wpa_cipher_group = p->value;
1783 case IW_AUTH_KEY_MGMT:
1784 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1785 priv->wpa_keymgmt = p->value;
1789 case IW_AUTH_TKIP_COUNTERMEASURES:
1790 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1795 case IW_AUTH_DROP_UNENCRYPTED:
1796 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1800 case IW_AUTH_80211_AUTH_ALG:
1801 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1802 priv->wpa_authalg = p->value;
1806 case IW_AUTH_WPA_ENABLED:
1807 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1808 if (wrqu->param.value)
1809 deauthenticate(usbdev);
1813 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1814 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1819 case IW_AUTH_ROAMING_CONTROL:
1820 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1824 case IW_AUTH_PRIVACY_INVOKED:
1825 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1826 wrqu->param.flags & IW_AUTH_INDEX);
1830 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1831 p->flags & IW_AUTH_INDEX, p->value);
1837 static int rndis_iw_get_auth(struct net_device *dev,
1838 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1840 struct iw_param *p = &wrqu->param;
1841 struct usbnet *usbdev = netdev_priv(dev);
1842 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1844 switch (p->flags & IW_AUTH_INDEX) {
1845 case IW_AUTH_WPA_VERSION:
1846 p->value = priv->wpa_version;
1848 case IW_AUTH_CIPHER_PAIRWISE:
1849 p->value = priv->wpa_cipher_pair;
1851 case IW_AUTH_CIPHER_GROUP:
1852 p->value = priv->wpa_cipher_group;
1854 case IW_AUTH_KEY_MGMT:
1855 p->value = priv->wpa_keymgmt;
1857 case IW_AUTH_80211_AUTH_ALG:
1858 p->value = priv->wpa_authalg;
1861 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1862 wrqu->param.flags & IW_AUTH_INDEX);
1869 static int rndis_iw_set_encode(struct net_device *dev,
1870 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1872 struct usbnet *usbdev = netdev_priv(dev);
1873 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1874 int ret, index, key_len;
1877 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
1879 /* iwconfig gives index as 1 - N */
1883 index = priv->encr_tx_key_index;
1885 if (index < 0 || index >= 4) {
1886 devwarn(usbdev, "encryption index out of range (%u)", index);
1890 /* remove key if disabled */
1891 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
1892 if (remove_key(usbdev, index, NULL))
1898 /* global encryption state (for all keys) */
1899 if (wrqu->data.flags & IW_ENCODE_OPEN)
1900 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1901 IW_AUTH_ALG_OPEN_SYSTEM);
1902 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1903 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1904 IW_AUTH_ALG_SHARED_KEY);
1908 if (wrqu->data.length > 0) {
1909 key_len = wrqu->data.length;
1912 /* must be set as tx key */
1913 if (priv->encr_key_len[index] == 0)
1915 key_len = priv->encr_key_len[index];
1916 key = priv->encr_keys[index];
1917 priv->encr_tx_key_index = index;
1920 if (add_wep_key(usbdev, key, key_len, index) != 0)
1923 if (index == priv->encr_tx_key_index)
1924 /* ndis drivers want essid to be set after setting encr */
1925 set_essid(usbdev, &priv->essid);
1931 static int rndis_iw_set_encode_ext(struct net_device *dev,
1932 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1934 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1935 struct usbnet *usbdev = netdev_priv(dev);
1936 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1939 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
1941 /* iwconfig gives index as 1 - N */
1945 keyidx = priv->encr_tx_key_index;
1947 if (keyidx < 0 || keyidx >= 4)
1950 if (ext->alg == WPA_ALG_WEP) {
1951 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1952 priv->encr_tx_key_index = keyidx;
1953 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
1956 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
1957 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
1958 return remove_key(usbdev, keyidx, NULL);
1961 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
1962 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
1963 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
1964 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
1965 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1966 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
1968 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx, &ext->addr,
1969 ext->rx_seq, ext->alg, flags);
1973 static int rndis_iw_set_genie(struct net_device *dev,
1974 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1976 struct usbnet *usbdev = netdev_priv(dev);
1977 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1983 for (j = 0; j < wrqu->data.length; j += 8)
1985 "SIOCSIWGENIE %04x - "
1986 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
1987 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
1988 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
1990 /* clear existing IEs */
1991 if (priv->wpa_ie_len) {
1992 kfree(priv->wpa_ie);
1993 priv->wpa_ie_len = 0;
1997 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
1999 priv->wpa_ie_len = wrqu->data.length;
2000 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
2007 static int rndis_iw_get_genie(struct net_device *dev,
2008 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2010 struct usbnet *usbdev = netdev_priv(dev);
2011 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2013 devdbg(usbdev, "SIOCGIWGENIE");
2015 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
2016 wrqu->data.length = 0;
2020 if (wrqu->data.length < priv->wpa_ie_len)
2023 wrqu->data.length = priv->wpa_ie_len;
2024 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
2030 static int rndis_iw_set_freq(struct net_device *dev,
2031 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2033 struct usbnet *usbdev = netdev_priv(dev);
2034 struct ndis_80211_conf config;
2035 unsigned int dsconfig;
2038 /* this OID is valid only when not associated */
2039 if (is_associated(usbdev))
2043 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
2046 len = sizeof(config);
2047 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2049 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
2053 config.ds_config = cpu_to_le32(dsconfig);
2055 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
2056 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
2061 static int rndis_iw_get_freq(struct net_device *dev,
2062 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2064 struct usbnet *usbdev = netdev_priv(dev);
2065 struct ndis_80211_conf config;
2068 len = sizeof(config);
2069 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2071 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
2073 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
2078 static int rndis_iw_get_rate(struct net_device *dev,
2079 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2081 struct usbnet *usbdev = netdev_priv(dev);
2086 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
2088 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
2089 wrqu->bitrate.disabled = 0;
2090 wrqu->bitrate.flags = 1;
2096 static int rndis_iw_set_mlme(struct net_device *dev,
2097 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2099 struct usbnet *usbdev = netdev_priv(dev);
2100 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2101 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2102 unsigned char bssid[ETH_ALEN];
2104 get_bssid(usbdev, bssid);
2106 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
2109 switch (mlme->cmd) {
2110 case IW_MLME_DEAUTH:
2111 return deauthenticate(usbdev);
2112 case IW_MLME_DISASSOC:
2113 return disassociate(usbdev, priv->radio_on);
2122 static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
2124 struct usbnet *usbdev = netdev_priv(dev);
2125 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2126 unsigned long flags;
2128 spin_lock_irqsave(&priv->stats_lock, flags);
2129 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2130 spin_unlock_irqrestore(&priv->stats_lock, flags);
2132 return &priv->iwstats;
2136 #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2137 static const iw_handler rndis_iw_handler[] =
2139 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
2140 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
2141 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2142 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
2143 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2144 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
2145 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
2146 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2147 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
2148 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2149 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
2150 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2151 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
2152 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
2153 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2154 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2155 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2156 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
2157 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2158 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
2159 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2160 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2161 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2162 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2163 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2164 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2165 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2168 static const iw_handler rndis_wlan_private_handler[] = {
2171 static const struct iw_priv_args rndis_wlan_private_args[] = {
2175 static const struct iw_handler_def rndis_iw_handlers = {
2176 .num_standard = ARRAY_SIZE(rndis_iw_handler),
2177 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2178 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
2179 .standard = (iw_handler *)rndis_iw_handler,
2180 .private = (iw_handler *)rndis_wlan_private_handler,
2181 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
2182 .get_wireless_stats = rndis_get_wireless_stats,
2186 static void rndis_wlan_worker(struct work_struct *work)
2188 struct rndis_wlan_private *priv =
2189 container_of(work, struct rndis_wlan_private, work);
2190 struct usbnet *usbdev = priv->usbdev;
2191 union iwreq_data evt;
2192 unsigned char bssid[ETH_ALEN];
2193 struct ndis_80211_assoc_info *info;
2194 int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32;
2197 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) {
2198 netif_carrier_on(usbdev->net);
2200 info = kzalloc(assoc_size, GFP_KERNEL);
2204 /* Get association info IEs from device and send them back to
2206 ret = get_association_info(usbdev, info, assoc_size);
2208 evt.data.length = le32_to_cpu(info->req_ie_length);
2209 if (evt.data.length > 0) {
2210 offset = le32_to_cpu(info->offset_req_ies);
2211 wireless_send_event(usbdev->net,
2212 IWEVASSOCREQIE, &evt,
2213 (char *)info + offset);
2216 evt.data.length = le32_to_cpu(info->resp_ie_length);
2217 if (evt.data.length > 0) {
2218 offset = le32_to_cpu(info->offset_resp_ies);
2219 wireless_send_event(usbdev->net,
2220 IWEVASSOCRESPIE, &evt,
2221 (char *)info + offset);
2228 ret = get_bssid(usbdev, bssid);
2231 evt.data.length = 0;
2232 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
2233 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2237 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) {
2238 netif_carrier_off(usbdev->net);
2241 evt.data.length = 0;
2242 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2243 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2246 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2247 set_multicast_list(usbdev);
2250 static void rndis_wlan_set_multicast_list(struct net_device *dev)
2252 struct usbnet *usbdev = netdev_priv(dev);
2253 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2255 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2258 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2259 queue_work(priv->workqueue, &priv->work);
2263 static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2264 struct ndis_80211_status_indication *indication,
2270 bool pairwise_error, group_error;
2271 struct ndis_80211_auth_request *auth_req;
2273 /* must have at least one array entry */
2274 if (len < offsetof(struct ndis_80211_status_indication, u) +
2275 sizeof(struct ndis_80211_auth_request)) {
2276 devinfo(usbdev, "authentication indication: "
2277 "too short message (%i)", len);
2281 buf = (void *)&indication->u.auth_request[0];
2282 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2284 while (buflen >= sizeof(*auth_req)) {
2285 auth_req = (void *)buf;
2287 flags = le32_to_cpu(auth_req->flags);
2288 pairwise_error = false;
2289 group_error = false;
2292 type = "reauth request";
2294 type = "key update request";
2296 pairwise_error = true;
2297 type = "pairwise_error";
2301 type = "group_error";
2304 devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
2305 le32_to_cpu(auth_req->flags));
2307 if (pairwise_error || group_error) {
2308 union iwreq_data wrqu;
2309 struct iw_michaelmicfailure micfailure;
2311 memset(&micfailure, 0, sizeof(micfailure));
2313 micfailure.flags |= IW_MICFAILURE_PAIRWISE;
2315 micfailure.flags |= IW_MICFAILURE_GROUP;
2317 memcpy(micfailure.src_addr.sa_data, auth_req->bssid,
2320 memset(&wrqu, 0, sizeof(wrqu));
2321 wrqu.data.length = sizeof(micfailure);
2322 wireless_send_event(usbdev->net, IWEVMICHAELMICFAILURE,
2323 &wrqu, (u8 *)&micfailure);
2326 buflen -= le32_to_cpu(auth_req->length);
2327 buf += le32_to_cpu(auth_req->length);
2331 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2332 struct ndis_80211_status_indication *indication,
2335 struct ndis_80211_pmkid_cand_list *cand_list;
2336 int list_len, expected_len, i;
2338 if (len < offsetof(struct ndis_80211_status_indication, u) +
2339 sizeof(struct ndis_80211_pmkid_cand_list)) {
2340 devinfo(usbdev, "pmkid candidate list indication: "
2341 "too short message (%i)", len);
2345 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2346 sizeof(struct ndis_80211_pmkid_candidate);
2347 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2348 offsetof(struct ndis_80211_status_indication, u);
2350 if (len < expected_len) {
2351 devinfo(usbdev, "pmkid candidate list indication: "
2352 "list larger than buffer (%i < %i)",
2357 cand_list = &indication->u.cand_list;
2359 devinfo(usbdev, "pmkid candidate list indication: "
2360 "version %i, candidates %i",
2361 le32_to_cpu(cand_list->version),
2362 le32_to_cpu(cand_list->num_candidates));
2364 if (le32_to_cpu(cand_list->version) != 1)
2367 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
2368 struct iw_pmkid_cand pcand;
2369 union iwreq_data wrqu;
2370 struct ndis_80211_pmkid_candidate *cand =
2371 &cand_list->candidate_list[i];
2373 devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
2374 i, le32_to_cpu(cand->flags), cand->bssid);
2376 memset(&pcand, 0, sizeof(pcand));
2377 if (le32_to_cpu(cand->flags) & 0x01)
2378 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2380 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2382 memset(&wrqu, 0, sizeof(wrqu));
2383 wrqu.data.length = sizeof(pcand);
2384 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2389 static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2390 struct rndis_indicate *msg, int buflen)
2392 struct ndis_80211_status_indication *indication;
2395 offset = offsetof(struct rndis_indicate, status) +
2396 le32_to_cpu(msg->offset);
2397 len = le32_to_cpu(msg->length);
2400 devinfo(usbdev, "media specific indication, "
2401 "ignore too short message (%i < 8)", len);
2405 if (offset + len > buflen) {
2406 devinfo(usbdev, "media specific indication, "
2407 "too large to fit to buffer (%i > %i)",
2408 offset + len, buflen);
2412 indication = (void *)((u8 *)msg + offset);
2414 switch (le32_to_cpu(indication->status_type)) {
2415 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2416 devinfo(usbdev, "radio state indication: %i",
2417 le32_to_cpu(indication->u.radio_status));
2420 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2421 devinfo(usbdev, "media stream mode indication: %i",
2422 le32_to_cpu(indication->u.media_stream_mode));
2425 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2426 rndis_wlan_auth_indication(usbdev, indication, len);
2429 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2430 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2434 devinfo(usbdev, "media specific indication: "
2435 "unknown status type 0x%08x",
2436 le32_to_cpu(indication->status_type));
2441 static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
2443 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2444 struct rndis_indicate *msg = ind;
2446 switch (msg->status) {
2447 case RNDIS_STATUS_MEDIA_CONNECT:
2448 devinfo(usbdev, "media connect");
2450 /* queue work to avoid recursive calls into rndis_command */
2451 set_bit(WORK_LINK_UP, &priv->work_pending);
2452 queue_work(priv->workqueue, &priv->work);
2455 case RNDIS_STATUS_MEDIA_DISCONNECT:
2456 devinfo(usbdev, "media disconnect");
2458 /* queue work to avoid recursive calls into rndis_command */
2459 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2460 queue_work(priv->workqueue, &priv->work);
2463 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2464 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2468 devinfo(usbdev, "indication: 0x%08x",
2469 le32_to_cpu(msg->status));
2475 static int rndis_wlan_get_caps(struct usbnet *usbdev)
2480 } networks_supported;
2481 int len, retval, i, n;
2482 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2484 /* determine supported modes */
2485 len = sizeof(networks_supported);
2486 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
2487 &networks_supported, &len);
2489 n = le32_to_cpu(networks_supported.num_items);
2492 for (i = 0; i < n; i++) {
2493 switch (le32_to_cpu(networks_supported.items[i])) {
2494 case NDIS_80211_TYPE_FREQ_HOP:
2495 case NDIS_80211_TYPE_DIRECT_SEQ:
2496 priv->caps |= CAP_MODE_80211B;
2498 case NDIS_80211_TYPE_OFDM_A:
2499 priv->caps |= CAP_MODE_80211A;
2501 case NDIS_80211_TYPE_OFDM_G:
2502 priv->caps |= CAP_MODE_80211G;
2512 #define STATS_UPDATE_JIFFIES (HZ)
2513 static void rndis_update_wireless_stats(struct work_struct *work)
2515 struct rndis_wlan_private *priv =
2516 container_of(work, struct rndis_wlan_private, stats_work.work);
2517 struct usbnet *usbdev = priv->usbdev;
2518 struct iw_statistics iwstats;
2521 unsigned long flags;
2522 int update_jiffies = STATS_UPDATE_JIFFIES;
2525 spin_lock_irqsave(&priv->stats_lock, flags);
2526 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2527 spin_unlock_irqrestore(&priv->stats_lock, flags);
2529 /* only update stats when connected */
2530 if (!is_associated(usbdev)) {
2531 iwstats.qual.qual = 0;
2532 iwstats.qual.level = 0;
2533 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2534 | IW_QUAL_LEVEL_UPDATED
2535 | IW_QUAL_NOISE_INVALID
2536 | IW_QUAL_QUAL_INVALID
2537 | IW_QUAL_LEVEL_INVALID;
2542 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2544 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2547 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2548 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
2549 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
2550 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2551 | IW_QUAL_LEVEL_UPDATED
2552 | IW_QUAL_NOISE_INVALID;
2555 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2558 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2560 iwstats.discard.misc += le32_to_cpu(tmp);
2563 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2565 iwstats.discard.misc += le32_to_cpu(tmp);
2568 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2570 iwstats.discard.misc += le32_to_cpu(tmp);
2572 /* Workaround transfer stalls on poor quality links.
2573 * TODO: find right way to fix these stalls (as stalls do not happen
2574 * with ndiswrapper/windows driver). */
2575 if (iwstats.qual.qual <= 25) {
2576 /* Decrease stats worker interval to catch stalls.
2577 * faster. Faster than 400-500ms causes packet loss,
2578 * Slower doesn't catch stalls fast enough.
2580 j = msecs_to_jiffies(priv->param_workaround_interval);
2581 if (j > STATS_UPDATE_JIFFIES)
2582 j = STATS_UPDATE_JIFFIES;
2587 /* Send scan OID. Use of both OIDs is required to get device
2590 tmp = cpu_to_le32(1);
2591 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2594 len = CONTROL_BUFFER_SIZE;
2595 buf = kmalloc(len, GFP_KERNEL);
2599 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2603 spin_lock_irqsave(&priv->stats_lock, flags);
2604 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2605 spin_unlock_irqrestore(&priv->stats_lock, flags);
2607 if (update_jiffies >= HZ)
2608 update_jiffies = round_jiffies_relative(update_jiffies);
2610 j = round_jiffies_relative(update_jiffies);
2611 if (abs(j - update_jiffies) <= 10)
2615 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2619 static int bcm4320a_early_init(struct usbnet *usbdev)
2621 /* bcm4320a doesn't handle configuration parameters well. Try
2622 * set any and you get partially zeroed mac and broken device.
2629 static int bcm4320b_early_init(struct usbnet *usbdev)
2631 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2634 /* Early initialization settings, setting these won't have effect
2635 * if called after generic_rndis_bind().
2638 priv->param_country[0] = modparam_country[0];
2639 priv->param_country[1] = modparam_country[1];
2640 priv->param_country[2] = 0;
2641 priv->param_frameburst = modparam_frameburst;
2642 priv->param_afterburner = modparam_afterburner;
2643 priv->param_power_save = modparam_power_save;
2644 priv->param_power_output = modparam_power_output;
2645 priv->param_roamtrigger = modparam_roamtrigger;
2646 priv->param_roamdelta = modparam_roamdelta;
2648 priv->param_country[0] = toupper(priv->param_country[0]);
2649 priv->param_country[1] = toupper(priv->param_country[1]);
2650 /* doesn't support EU as country code, use FI instead */
2651 if (!strcmp(priv->param_country, "EU"))
2652 strcpy(priv->param_country, "FI");
2654 if (priv->param_power_save < 0)
2655 priv->param_power_save = 0;
2656 else if (priv->param_power_save > 2)
2657 priv->param_power_save = 2;
2659 if (priv->param_power_output < 0)
2660 priv->param_power_output = 0;
2661 else if (priv->param_power_output > 3)
2662 priv->param_power_output = 3;
2664 if (priv->param_roamtrigger < -80)
2665 priv->param_roamtrigger = -80;
2666 else if (priv->param_roamtrigger > -60)
2667 priv->param_roamtrigger = -60;
2669 if (priv->param_roamdelta < 0)
2670 priv->param_roamdelta = 0;
2671 else if (priv->param_roamdelta > 2)
2672 priv->param_roamdelta = 2;
2674 if (modparam_workaround_interval < 0)
2675 priv->param_workaround_interval = 500;
2677 priv->param_workaround_interval = modparam_workaround_interval;
2679 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2680 rndis_set_config_parameter_str(usbdev, "FrameBursting",
2681 priv->param_frameburst ? "1" : "0");
2682 rndis_set_config_parameter_str(usbdev, "Afterburner",
2683 priv->param_afterburner ? "1" : "0");
2684 sprintf(buf, "%d", priv->param_power_save);
2685 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
2686 sprintf(buf, "%d", priv->param_power_output);
2687 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
2688 sprintf(buf, "%d", priv->param_roamtrigger);
2689 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
2690 sprintf(buf, "%d", priv->param_roamdelta);
2691 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
2696 /* same as rndis_netdev_ops but with local multicast handler */
2697 static const struct net_device_ops rndis_wlan_netdev_ops = {
2698 .ndo_open = usbnet_open,
2699 .ndo_stop = usbnet_stop,
2700 .ndo_start_xmit = usbnet_start_xmit,
2701 .ndo_tx_timeout = usbnet_tx_timeout,
2702 .ndo_set_mac_address = eth_mac_addr,
2703 .ndo_validate_addr = eth_validate_addr,
2704 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
2708 static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
2710 struct wiphy *wiphy;
2711 struct rndis_wlan_private *priv;
2715 /* allocate wiphy and rndis private data
2716 * NOTE: We only support a single virtual interface, so wiphy
2717 * and wireless_dev are somewhat synonymous for this device.
2719 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
2723 priv = wiphy_priv(wiphy);
2724 usbdev->net->ieee80211_ptr = &priv->wdev;
2725 priv->wdev.wiphy = wiphy;
2726 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2728 /* These have to be initialized before calling generic_rndis_bind().
2729 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
2731 usbdev->driver_priv = priv;
2732 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2733 priv->usbdev = usbdev;
2735 mutex_init(&priv->command_lock);
2736 spin_lock_init(&priv->stats_lock);
2738 /* because rndis_command() sleeps we need to use workqueue */
2739 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
2740 INIT_WORK(&priv->work, rndis_wlan_worker);
2741 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2742 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2744 /* try bind rndis_host */
2745 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
2749 /* generic_rndis_bind set packet filter to multicast_all+
2750 * promisc mode which doesn't work well for our devices (device
2751 * picks up rssi to closest station instead of to access point).
2753 * rndis_host wants to avoid all OID as much as possible
2754 * so do promisc/multicast handling in rndis_wlan.
2756 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
2758 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
2759 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
2763 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2765 priv->multicast_size = le32_to_cpu(tmp);
2766 if (retval < 0 || priv->multicast_size < 0)
2767 priv->multicast_size = 0;
2768 if (priv->multicast_size > 0)
2769 usbdev->net->flags |= IFF_MULTICAST;
2771 usbdev->net->flags &= ~IFF_MULTICAST;
2773 priv->iwstats.qual.qual = 0;
2774 priv->iwstats.qual.level = 0;
2775 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2776 | IW_QUAL_LEVEL_UPDATED
2777 | IW_QUAL_NOISE_INVALID
2778 | IW_QUAL_QUAL_INVALID
2779 | IW_QUAL_LEVEL_INVALID;
2781 /* fill-out wiphy structure and register w/ cfg80211 */
2782 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2783 wiphy->privid = rndis_wiphy_privid;
2784 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2785 | BIT(NL80211_IFTYPE_ADHOC);
2786 wiphy->max_scan_ssids = 1;
2788 /* TODO: fill-out band information based on priv->caps */
2789 rndis_wlan_get_caps(usbdev);
2791 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2792 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2793 priv->band.channels = priv->channels;
2794 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2795 priv->band.bitrates = priv->rates;
2796 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2797 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
2798 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2800 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2802 if (wiphy_register(wiphy)) {
2807 set_default_iw_params(usbdev);
2809 /* set default rts/frag */
2810 rndis_set_wiphy_params(wiphy,
2811 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2815 disassociate(usbdev, 1);
2816 netif_carrier_off(usbdev->net);
2821 cancel_delayed_work_sync(&priv->stats_work);
2822 cancel_delayed_work_sync(&priv->scan_work);
2823 cancel_work_sync(&priv->work);
2824 flush_workqueue(priv->workqueue);
2825 destroy_workqueue(priv->workqueue);
2832 static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
2834 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2836 /* turn radio off */
2837 disassociate(usbdev, 0);
2839 cancel_delayed_work_sync(&priv->stats_work);
2840 cancel_delayed_work_sync(&priv->scan_work);
2841 cancel_work_sync(&priv->work);
2842 flush_workqueue(priv->workqueue);
2843 destroy_workqueue(priv->workqueue);
2845 if (priv && priv->wpa_ie_len)
2846 kfree(priv->wpa_ie);
2848 rndis_unbind(usbdev, intf);
2850 wiphy_unregister(priv->wdev.wiphy);
2851 wiphy_free(priv->wdev.wiphy);
2855 static int rndis_wlan_reset(struct usbnet *usbdev)
2857 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2860 devdbg(usbdev, "rndis_wlan_reset");
2862 retval = rndis_reset(usbdev);
2864 devwarn(usbdev, "rndis_reset() failed: %d", retval);
2866 /* rndis_reset cleared multicast list, so restore here.
2867 (set_multicast_list() also turns on current packet filter) */
2868 set_multicast_list(usbdev);
2870 queue_delayed_work(priv->workqueue, &priv->stats_work,
2871 round_jiffies_relative(STATS_UPDATE_JIFFIES));
2873 return deauthenticate(usbdev);
2877 static int rndis_wlan_stop(struct usbnet *usbdev)
2879 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2883 devdbg(usbdev, "rndis_wlan_stop");
2885 retval = disassociate(usbdev, 0);
2887 priv->work_pending = 0;
2888 cancel_delayed_work_sync(&priv->stats_work);
2889 cancel_delayed_work_sync(&priv->scan_work);
2890 cancel_work_sync(&priv->work);
2891 flush_workqueue(priv->workqueue);
2893 if (priv->scan_request) {
2894 cfg80211_scan_done(priv->scan_request, true);
2895 priv->scan_request = NULL;
2898 /* Set current packet filter zero to block receiving data packets from
2901 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
2908 static const struct driver_info bcm4320b_info = {
2909 .description = "Wireless RNDIS device, BCM4320b based",
2910 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2911 FLAG_AVOID_UNLINK_URBS,
2912 .bind = rndis_wlan_bind,
2913 .unbind = rndis_wlan_unbind,
2914 .status = rndis_status,
2915 .rx_fixup = rndis_rx_fixup,
2916 .tx_fixup = rndis_tx_fixup,
2917 .reset = rndis_wlan_reset,
2918 .stop = rndis_wlan_stop,
2919 .early_init = bcm4320b_early_init,
2920 .indication = rndis_wlan_indication,
2923 static const struct driver_info bcm4320a_info = {
2924 .description = "Wireless RNDIS device, BCM4320a based",
2925 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2926 FLAG_AVOID_UNLINK_URBS,
2927 .bind = rndis_wlan_bind,
2928 .unbind = rndis_wlan_unbind,
2929 .status = rndis_status,
2930 .rx_fixup = rndis_rx_fixup,
2931 .tx_fixup = rndis_tx_fixup,
2932 .reset = rndis_wlan_reset,
2933 .stop = rndis_wlan_stop,
2934 .early_init = bcm4320a_early_init,
2935 .indication = rndis_wlan_indication,
2938 static const struct driver_info rndis_wlan_info = {
2939 .description = "Wireless RNDIS device",
2940 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2941 FLAG_AVOID_UNLINK_URBS,
2942 .bind = rndis_wlan_bind,
2943 .unbind = rndis_wlan_unbind,
2944 .status = rndis_status,
2945 .rx_fixup = rndis_rx_fixup,
2946 .tx_fixup = rndis_tx_fixup,
2947 .reset = rndis_wlan_reset,
2948 .stop = rndis_wlan_stop,
2949 .early_init = bcm4320a_early_init,
2950 .indication = rndis_wlan_indication,
2953 /*-------------------------------------------------------------------------*/
2955 static const struct usb_device_id products [] = {
2956 #define RNDIS_MASTER_INTERFACE \
2957 .bInterfaceClass = USB_CLASS_COMM, \
2958 .bInterfaceSubClass = 2 /* ACM */, \
2959 .bInterfaceProtocol = 0x0ff
2961 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2962 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2965 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2966 | USB_DEVICE_ID_MATCH_DEVICE,
2968 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
2969 RNDIS_MASTER_INTERFACE,
2970 .driver_info = (unsigned long) &bcm4320b_info,
2972 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2973 | USB_DEVICE_ID_MATCH_DEVICE,
2975 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
2976 RNDIS_MASTER_INTERFACE,
2977 .driver_info = (unsigned long) &bcm4320b_info,
2979 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2980 | USB_DEVICE_ID_MATCH_DEVICE,
2982 .idProduct = 0x011b, /* Belkin F5D7051 */
2983 RNDIS_MASTER_INTERFACE,
2984 .driver_info = (unsigned long) &bcm4320b_info,
2986 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2987 | USB_DEVICE_ID_MATCH_DEVICE,
2988 .idVendor = 0x1799, /* Belkin has two vendor ids */
2989 .idProduct = 0x011b, /* Belkin F5D7051 */
2990 RNDIS_MASTER_INTERFACE,
2991 .driver_info = (unsigned long) &bcm4320b_info,
2993 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2994 | USB_DEVICE_ID_MATCH_DEVICE,
2996 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
2997 RNDIS_MASTER_INTERFACE,
2998 .driver_info = (unsigned long) &bcm4320b_info,
3000 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3001 | USB_DEVICE_ID_MATCH_DEVICE,
3003 .idProduct = 0x0026, /* Linksys WUSB54GSC */
3004 RNDIS_MASTER_INTERFACE,
3005 .driver_info = (unsigned long) &bcm4320b_info,
3007 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3008 | USB_DEVICE_ID_MATCH_DEVICE,
3010 .idProduct = 0x1717, /* Asus WL169gE */
3011 RNDIS_MASTER_INTERFACE,
3012 .driver_info = (unsigned long) &bcm4320b_info,
3014 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3015 | USB_DEVICE_ID_MATCH_DEVICE,
3017 .idProduct = 0xd11b, /* Eminent EM4045 */
3018 RNDIS_MASTER_INTERFACE,
3019 .driver_info = (unsigned long) &bcm4320b_info,
3021 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3022 | USB_DEVICE_ID_MATCH_DEVICE,
3024 .idProduct = 0x0715, /* BT Voyager 1055 */
3025 RNDIS_MASTER_INTERFACE,
3026 .driver_info = (unsigned long) &bcm4320b_info,
3028 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3029 * parameters available, hardware probably contain older firmware version with
3030 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3033 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3034 | USB_DEVICE_ID_MATCH_DEVICE,
3036 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3037 RNDIS_MASTER_INTERFACE,
3038 .driver_info = (unsigned long) &bcm4320a_info,
3040 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3041 | USB_DEVICE_ID_MATCH_DEVICE,
3043 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3044 RNDIS_MASTER_INTERFACE,
3045 .driver_info = (unsigned long) &bcm4320a_info,
3047 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3048 | USB_DEVICE_ID_MATCH_DEVICE,
3050 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3051 RNDIS_MASTER_INTERFACE,
3052 .driver_info = (unsigned long) &bcm4320a_info,
3054 /* Generic Wireless RNDIS devices that we don't have exact
3055 * idVendor/idProduct/chip yet.
3058 /* RNDIS is MSFT's un-official variant of CDC ACM */
3059 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3060 .driver_info = (unsigned long) &rndis_wlan_info,
3062 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3063 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
3064 .driver_info = (unsigned long) &rndis_wlan_info,
3068 MODULE_DEVICE_TABLE(usb, products);
3070 static struct usb_driver rndis_wlan_driver = {
3071 .name = "rndis_wlan",
3072 .id_table = products,
3073 .probe = usbnet_probe,
3074 .disconnect = usbnet_disconnect,
3075 .suspend = usbnet_suspend,
3076 .resume = usbnet_resume,
3079 static int __init rndis_wlan_init(void)
3081 return usb_register(&rndis_wlan_driver);
3083 module_init(rndis_wlan_init);
3085 static void __exit rndis_wlan_exit(void)
3087 usb_deregister(&rndis_wlan_driver);
3089 module_exit(rndis_wlan_exit);
3091 MODULE_AUTHOR("Bjorge Dijkstra");
3092 MODULE_AUTHOR("Jussi Kivilinna");
3093 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3094 MODULE_LICENSE("GPL");