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 struct rndis_wlan_encr_key {
425 /* RNDIS device private data */
426 struct rndis_wlan_private {
427 struct usbnet *usbdev;
429 struct wireless_dev wdev;
431 struct cfg80211_scan_request *scan_request;
433 struct workqueue_struct *workqueue;
434 struct delayed_work stats_work;
435 struct delayed_work scan_work;
436 struct work_struct work;
437 struct mutex command_lock;
438 spinlock_t stats_lock;
439 unsigned long work_pending;
441 struct ieee80211_supported_band band;
442 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
443 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
445 struct iw_statistics iwstats;
446 struct iw_statistics privstats;
451 /* module parameters */
452 char param_country[4];
453 int param_frameburst;
454 int param_afterburner;
455 int param_power_save;
456 int param_power_output;
457 int param_roamtrigger;
459 u32 param_workaround_interval;
464 struct ndis_80211_ssid essid;
466 /* encryption stuff */
467 int encr_tx_key_index;
468 struct rndis_wlan_encr_key encr_keys[4];
475 int wpa_cipher_group;
477 u8 command_buffer[COMMAND_BUFFER_SIZE];
483 static int rndis_change_virtual_intf(struct wiphy *wiphy,
484 struct net_device *dev,
485 enum nl80211_iftype type, u32 *flags,
486 struct vif_params *params);
488 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
489 struct cfg80211_scan_request *request);
491 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
493 static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
495 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
497 static struct cfg80211_ops rndis_config_ops = {
498 .change_virtual_intf = rndis_change_virtual_intf,
500 .set_wiphy_params = rndis_set_wiphy_params,
501 .set_tx_power = rndis_set_tx_power,
502 .get_tx_power = rndis_get_tx_power,
505 static void *rndis_wiphy_privid = &rndis_wiphy_privid;
508 static const unsigned char zero_bssid[ETH_ALEN] = {0,};
509 static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff,
513 static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
515 return (struct rndis_wlan_private *)dev->driver_priv;
519 static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
521 switch (priv->param_power_output) {
524 return BCM4320_DEFAULT_TXPOWER_DBM_100;
526 return BCM4320_DEFAULT_TXPOWER_DBM_75;
528 return BCM4320_DEFAULT_TXPOWER_DBM_50;
530 return BCM4320_DEFAULT_TXPOWER_DBM_25;
535 static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
537 int cipher = priv->encr_keys[idx].cipher;
539 return (cipher == WLAN_CIPHER_SUITE_CCMP ||
540 cipher == WLAN_CIPHER_SUITE_TKIP);
545 static const char *oid_to_string(__le32 oid)
548 #define OID_STR(oid) case oid: return(#oid)
549 /* from rndis_host.h */
550 OID_STR(OID_802_3_PERMANENT_ADDRESS);
551 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
552 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
553 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
555 /* from rndis_wlan.c */
556 OID_STR(OID_GEN_LINK_SPEED);
557 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
559 OID_STR(OID_GEN_XMIT_OK);
560 OID_STR(OID_GEN_RCV_OK);
561 OID_STR(OID_GEN_XMIT_ERROR);
562 OID_STR(OID_GEN_RCV_ERROR);
563 OID_STR(OID_GEN_RCV_NO_BUFFER);
565 OID_STR(OID_802_3_CURRENT_ADDRESS);
566 OID_STR(OID_802_3_MULTICAST_LIST);
567 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
569 OID_STR(OID_802_11_BSSID);
570 OID_STR(OID_802_11_SSID);
571 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
572 OID_STR(OID_802_11_ADD_WEP);
573 OID_STR(OID_802_11_REMOVE_WEP);
574 OID_STR(OID_802_11_DISASSOCIATE);
575 OID_STR(OID_802_11_AUTHENTICATION_MODE);
576 OID_STR(OID_802_11_PRIVACY_FILTER);
577 OID_STR(OID_802_11_BSSID_LIST_SCAN);
578 OID_STR(OID_802_11_ENCRYPTION_STATUS);
579 OID_STR(OID_802_11_ADD_KEY);
580 OID_STR(OID_802_11_REMOVE_KEY);
581 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
582 OID_STR(OID_802_11_PMKID);
583 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
584 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
585 OID_STR(OID_802_11_TX_POWER_LEVEL);
586 OID_STR(OID_802_11_RSSI);
587 OID_STR(OID_802_11_RSSI_TRIGGER);
588 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
589 OID_STR(OID_802_11_RTS_THRESHOLD);
590 OID_STR(OID_802_11_SUPPORTED_RATES);
591 OID_STR(OID_802_11_CONFIGURATION);
592 OID_STR(OID_802_11_BSSID_LIST);
599 static const char *oid_to_string(__le32 oid)
606 /* translate error code */
607 static int rndis_error_status(__le32 rndis_status)
610 switch (rndis_status) {
611 case RNDIS_STATUS_SUCCESS:
614 case RNDIS_STATUS_FAILURE:
615 case RNDIS_STATUS_INVALID_DATA:
618 case RNDIS_STATUS_NOT_SUPPORTED:
621 case RNDIS_STATUS_ADAPTER_NOT_READY:
622 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
630 static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
632 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
635 struct rndis_msg_hdr *header;
636 struct rndis_query *get;
637 struct rndis_query_c *get_c;
641 buflen = *len + sizeof(*u.get);
642 if (buflen < CONTROL_BUFFER_SIZE)
643 buflen = CONTROL_BUFFER_SIZE;
645 if (buflen > COMMAND_BUFFER_SIZE) {
646 u.buf = kmalloc(buflen, GFP_KERNEL);
650 u.buf = priv->command_buffer;
653 mutex_lock(&priv->command_lock);
655 memset(u.get, 0, sizeof *u.get);
656 u.get->msg_type = RNDIS_MSG_QUERY;
657 u.get->msg_len = cpu_to_le32(sizeof *u.get);
660 ret = rndis_command(dev, u.header, buflen);
662 devdbg(dev, "rndis_query_oid(%s): rndis_command() failed, %d "
663 "(%08x)", oid_to_string(oid), ret,
664 le32_to_cpu(u.get_c->status));
667 ret = le32_to_cpu(u.get_c->len);
668 *len = (*len > ret) ? ret : *len;
669 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
670 ret = rndis_error_status(u.get_c->status);
673 devdbg(dev, "rndis_query_oid(%s): device returned "
674 "error, 0x%08x (%d)", oid_to_string(oid),
675 le32_to_cpu(u.get_c->status), ret);
678 mutex_unlock(&priv->command_lock);
680 if (u.buf != priv->command_buffer)
686 static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
688 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
691 struct rndis_msg_hdr *header;
692 struct rndis_set *set;
693 struct rndis_set_c *set_c;
697 buflen = len + sizeof(*u.set);
698 if (buflen < CONTROL_BUFFER_SIZE)
699 buflen = CONTROL_BUFFER_SIZE;
701 if (buflen > COMMAND_BUFFER_SIZE) {
702 u.buf = kmalloc(buflen, GFP_KERNEL);
706 u.buf = priv->command_buffer;
709 mutex_lock(&priv->command_lock);
711 memset(u.set, 0, sizeof *u.set);
712 u.set->msg_type = RNDIS_MSG_SET;
713 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
715 u.set->len = cpu_to_le32(len);
716 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
717 u.set->handle = cpu_to_le32(0);
718 memcpy(u.buf + sizeof(*u.set), data, len);
720 ret = rndis_command(dev, u.header, buflen);
722 devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
723 "(%08x)", oid_to_string(oid), ret,
724 le32_to_cpu(u.set_c->status));
727 ret = rndis_error_status(u.set_c->status);
730 devdbg(dev, "rndis_set_oid(%s): device returned error, "
731 "0x%08x (%d)", oid_to_string(oid),
732 le32_to_cpu(u.set_c->status), ret);
735 mutex_unlock(&priv->command_lock);
737 if (u.buf != priv->command_buffer)
743 static int rndis_reset(struct usbnet *usbdev)
745 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
746 struct rndis_reset *reset;
749 mutex_lock(&priv->command_lock);
751 reset = (void *)priv->command_buffer;
752 memset(reset, 0, sizeof(*reset));
753 reset->msg_type = RNDIS_MSG_RESET;
754 reset->msg_len = cpu_to_le32(sizeof(*reset));
755 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
757 mutex_unlock(&priv->command_lock);
766 * Specs say that we can only set config parameters only soon after device
768 * value_type: 0 = u32, 2 = unicode string
770 static int rndis_set_config_parameter(struct usbnet *dev, char *param,
771 int value_type, void *value)
773 struct ndis_config_param *infobuf;
774 int value_len, info_len, param_len, ret, i;
779 value_len = sizeof(__le32);
780 else if (value_type == 2)
781 value_len = strlen(value) * sizeof(__le16);
785 param_len = strlen(param) * sizeof(__le16);
786 info_len = sizeof(*infobuf) + param_len + value_len;
791 infobuf = kmalloc(info_len, GFP_KERNEL);
797 /* extra 12 bytes are for padding (debug output) */
798 memset(infobuf, 0xCC, info_len + 12);
802 devdbg(dev, "setting config parameter: %s, value: %s",
805 devdbg(dev, "setting config parameter: %s, value: %d",
806 param, *(u32 *)value);
808 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
809 infobuf->name_length = cpu_to_le32(param_len);
810 infobuf->type = cpu_to_le32(value_type);
811 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
812 infobuf->value_length = cpu_to_le32(value_len);
814 /* simple string to unicode string conversion */
815 unibuf = (void *)infobuf + sizeof(*infobuf);
816 for (i = 0; i < param_len / sizeof(__le16); i++)
817 unibuf[i] = cpu_to_le16(param[i]);
819 if (value_type == 2) {
820 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
821 for (i = 0; i < value_len / sizeof(__le16); i++)
822 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
824 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
825 *dst_value = cpu_to_le32(*(u32 *)value);
829 devdbg(dev, "info buffer (len: %d):", info_len);
830 for (i = 0; i < info_len; i += 12) {
831 u32 *tmp = (u32 *)((u8 *)infobuf + i);
832 devdbg(dev, "%08X:%08X:%08X",
835 cpu_to_be32(tmp[2]));
839 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
842 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
848 static int rndis_set_config_parameter_str(struct usbnet *dev,
849 char *param, char *value)
851 return(rndis_set_config_parameter(dev, param, 2, value));
854 /*static int rndis_set_config_parameter_u32(struct usbnet *dev,
855 char *param, u32 value)
857 return(rndis_set_config_parameter(dev, param, 0, &value));
862 * data conversion functions
864 static int level_to_qual(int level)
866 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
867 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
871 static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
877 /* see comment in wireless.h above the "struct iw_freq"
878 * definition for an explanation of this if
879 * NOTE: 1000000 is due to the kHz
881 if (dsconfig > 1000000) {
882 freq->m = dsconfig / 10;
887 /* convert from kHz to Hz */
892 static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
894 if (freq->m < 1000 && freq->e == 0) {
895 if (freq->m >= 1 && freq->m <= 14)
896 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
902 for (i = freq->e; i > 0; i--)
914 static void restore_keys(struct usbnet *usbdev);
916 static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
921 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
928 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
930 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
931 tmp[le32_to_cpu(ssid->length)] = 0;
932 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
939 static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
941 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
944 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
946 memcpy(&priv->essid, ssid, sizeof(priv->essid));
948 devdbg(usbdev, "set_essid: radio_on = 1");
955 static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
960 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
963 memset(bssid, 0, ETH_ALEN);
968 static int get_association_info(struct usbnet *usbdev,
969 struct ndis_80211_assoc_info *info, int len)
971 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
975 static int is_associated(struct usbnet *usbdev)
980 ret = get_bssid(usbdev, bssid);
982 return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0);
986 static int disassociate(struct usbnet *usbdev, int reset_ssid)
988 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
989 struct ndis_80211_ssid ssid;
992 if (priv->radio_on) {
993 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
996 devdbg(usbdev, "disassociate: radio_on = 0");
1003 /* disassociate causes radio to be turned off; if reset_ssid
1004 * is given, set random ssid to enable radio */
1006 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1007 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1008 ssid.essid[0] = 0x1;
1009 ssid.essid[1] = 0xff;
1010 for (i = 2; i < sizeof(ssid.essid); i++)
1011 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
1012 ret = set_essid(usbdev, &ssid);
1018 static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
1020 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1024 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
1025 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
1027 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
1028 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
1029 auth_mode = NDIS_80211_AUTH_WPA2;
1031 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
1032 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
1033 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
1034 auth_mode = NDIS_80211_AUTH_WPA;
1035 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
1036 auth_mode = NDIS_80211_AUTH_WPA_PSK;
1038 auth_mode = NDIS_80211_AUTH_WPA_NONE;
1039 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
1040 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
1041 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
1043 auth_mode = NDIS_80211_AUTH_SHARED;
1045 auth_mode = NDIS_80211_AUTH_OPEN;
1047 tmp = cpu_to_le32(auth_mode);
1048 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1051 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
1055 priv->wpa_version = wpa_version;
1056 priv->wpa_authalg = authalg;
1061 static int set_priv_filter(struct usbnet *usbdev)
1063 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1066 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
1068 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
1069 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
1070 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
1072 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
1074 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1079 static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1081 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1085 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
1089 if (pairwise & IW_AUTH_CIPHER_CCMP)
1090 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1091 else if (pairwise & IW_AUTH_CIPHER_TKIP)
1092 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1094 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
1095 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
1096 else if (groupwise & IW_AUTH_CIPHER_CCMP)
1097 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1098 else if (groupwise & IW_AUTH_CIPHER_TKIP)
1099 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1101 encr_mode = NDIS_80211_ENCR_DISABLED;
1103 tmp = cpu_to_le32(encr_mode);
1104 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1107 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
1111 priv->wpa_cipher_pair = pairwise;
1112 priv->wpa_cipher_group = groupwise;
1117 static int set_assoc_params(struct usbnet *usbdev)
1119 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1121 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
1122 set_priv_filter(usbdev);
1123 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
1129 static int set_infra_mode(struct usbnet *usbdev, int mode)
1131 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1135 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
1137 tmp = cpu_to_le32(mode);
1138 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1141 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
1145 /* NDIS drivers clear keys when infrastructure mode is
1146 * changed. But Linux tools assume otherwise. So set the
1148 restore_keys(usbdev);
1150 priv->infra_mode = mode;
1155 static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1159 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1161 if (rts_threshold < 0 || rts_threshold > 2347)
1162 rts_threshold = 2347;
1164 tmp = cpu_to_le32(rts_threshold);
1165 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1170 static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1174 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1176 if (frag_threshold < 256 || frag_threshold > 2346)
1177 frag_threshold = 2346;
1179 tmp = cpu_to_le32(frag_threshold);
1180 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1185 static void set_default_iw_params(struct usbnet *usbdev)
1187 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1189 priv->wpa_keymgmt = 0;
1190 priv->wpa_version = 0;
1192 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1193 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1194 IW_AUTH_ALG_OPEN_SYSTEM);
1195 set_priv_filter(usbdev);
1196 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1200 static int deauthenticate(struct usbnet *usbdev)
1204 ret = disassociate(usbdev, 1);
1205 set_default_iw_params(usbdev);
1210 /* index must be 0 - N, as per NDIS */
1211 static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
1213 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1214 struct ndis_80211_wep_key ndis_key;
1217 if ((key_len != 5 || key_len != 13) || index < 0 || index > 3)
1221 cipher = WLAN_CIPHER_SUITE_WEP40;
1223 cipher = WLAN_CIPHER_SUITE_WEP104;
1225 memset(&ndis_key, 0, sizeof(ndis_key));
1227 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1228 ndis_key.length = cpu_to_le32(key_len);
1229 ndis_key.index = cpu_to_le32(index);
1230 memcpy(&ndis_key.material, key, key_len);
1232 if (index == priv->encr_tx_key_index) {
1233 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
1234 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1235 IW_AUTH_CIPHER_NONE);
1237 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1241 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1244 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1249 priv->encr_keys[index].len = key_len;
1250 priv->encr_keys[index].cipher = cipher;
1251 memcpy(&priv->encr_keys[index].material, key, key_len);
1252 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
1258 static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
1259 int index, const u8 *addr, const u8 *rx_seq, int cipher,
1262 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1263 struct ndis_80211_key ndis_key;
1267 if (index < 0 || index >= 4) {
1268 devdbg(usbdev, "add_wpa_key: index out of range (%i)", index);
1271 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1272 devdbg(usbdev, "add_wpa_key: key length out of range (%i)",
1276 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq) {
1277 devdbg(usbdev, "add_wpa_key: recv seq flag without buffer");
1280 is_addr_ok = addr && memcmp(addr, zero_bssid, ETH_ALEN) != 0 &&
1281 memcmp(addr, ffff_bssid, ETH_ALEN) != 0;
1282 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1283 devdbg(usbdev, "add_wpa_key: pairwise but bssid invalid (%pM)",
1288 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
1289 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1290 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1291 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
1293 memset(&ndis_key, 0, sizeof(ndis_key));
1295 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1296 sizeof(ndis_key.material) + key_len);
1297 ndis_key.length = cpu_to_le32(key_len);
1298 ndis_key.index = cpu_to_le32(index) | flags;
1300 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
1301 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1302 * different order than NDIS spec, so swap the order here. */
1303 memcpy(ndis_key.material, key, 16);
1304 memcpy(ndis_key.material + 16, key + 24, 8);
1305 memcpy(ndis_key.material + 24, key + 16, 8);
1307 memcpy(ndis_key.material, key, key_len);
1309 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
1310 memcpy(ndis_key.rsc, rx_seq, 6);
1312 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
1314 memcpy(ndis_key.bssid, addr, ETH_ALEN);
1317 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
1318 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1320 get_bssid(usbdev, ndis_key.bssid);
1323 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1324 le32_to_cpu(ndis_key.size));
1325 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1329 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1330 priv->encr_keys[index].len = key_len;
1331 priv->encr_keys[index].cipher = cipher;
1332 memcpy(&priv->encr_keys[index].material, key, key_len);
1333 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1334 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1336 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
1338 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
1339 priv->encr_tx_key_index = index;
1345 static int restore_key(struct usbnet *usbdev, int key_idx)
1347 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1348 struct rndis_wlan_encr_key key;
1351 key = priv->encr_keys[key_idx];
1353 devdbg(usbdev, "restore_key: %i:%s:%i", key_idx,
1354 is_wpa_key(priv, key_idx) ? "wpa" : "wep",
1360 if (is_wpa_key(priv, key_idx)) {
1363 /*if (priv->encr_tx_key_index == key_idx)
1364 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;*/
1366 if (memcmp(key.bssid, zero_bssid, ETH_ALEN) != 0 &&
1367 memcmp(key.bssid, ffff_bssid, ETH_ALEN) != 0)
1368 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
1370 return add_wpa_key(usbdev, key.material, key.len, key_idx,
1371 key.bssid, NULL, key.cipher, flags);
1374 return add_wep_key(usbdev, key.material, key.len, key_idx);
1378 static void restore_keys(struct usbnet *usbdev)
1382 for (i = 0; i < 4; i++)
1383 restore_key(usbdev, i);
1387 static void clear_key(struct rndis_wlan_private *priv, int idx)
1389 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1393 /* remove_key is for both wep and wpa */
1394 static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1396 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1397 struct ndis_80211_remove_key remove_key;
1402 if (priv->encr_keys[index].len == 0)
1405 is_wpa = is_wpa_key(priv, index);
1407 devdbg(usbdev, "remove_key: %i:%s:%i", index, is_wpa ? "wpa" : "wep",
1408 priv->encr_keys[index].len);
1410 clear_key(priv, index);
1413 remove_key.size = cpu_to_le32(sizeof(remove_key));
1414 remove_key.index = cpu_to_le32(index);
1417 if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0)
1419 NDIS_80211_ADDKEY_PAIRWISE_KEY;
1420 memcpy(remove_key.bssid, bssid,
1421 sizeof(remove_key.bssid));
1423 memset(remove_key.bssid, 0xff,
1424 sizeof(remove_key.bssid));
1426 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1427 sizeof(remove_key));
1431 keyindex = cpu_to_le32(index);
1432 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1436 "removing encryption key %d failed (%08X)",
1442 /* if it is transmit key, disable encryption */
1443 if (index == priv->encr_tx_key_index)
1444 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1450 static void set_multicast_list(struct usbnet *usbdev)
1452 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1453 struct dev_mc_list *mclist;
1458 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1460 if (usbdev->net->flags & IFF_PROMISC) {
1461 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1462 RNDIS_PACKET_TYPE_ALL_LOCAL;
1463 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1464 usbdev->net->mc_count > priv->multicast_size) {
1465 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1466 } else if (usbdev->net->mc_count > 0) {
1467 size = min(priv->multicast_size, usbdev->net->mc_count);
1468 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1471 "couldn't alloc %d bytes of memory",
1476 mclist = usbdev->net->mc_list;
1477 for (i = 0; i < size && mclist; mclist = mclist->next) {
1478 if (mclist->dmi_addrlen != ETH_ALEN)
1481 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1485 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1487 if (ret == 0 && i > 0)
1488 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1490 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1492 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1493 i, priv->multicast_size, ret);
1498 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1501 devwarn(usbdev, "couldn't set packet filter: %08x",
1502 le32_to_cpu(filter));
1505 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1506 le32_to_cpu(filter), ret);
1513 static int rndis_change_virtual_intf(struct wiphy *wiphy,
1514 struct net_device *dev,
1515 enum nl80211_iftype type, u32 *flags,
1516 struct vif_params *params)
1518 struct usbnet *usbdev = netdev_priv(dev);
1522 case NL80211_IFTYPE_ADHOC:
1523 mode = NDIS_80211_INFRA_ADHOC;
1525 case NL80211_IFTYPE_STATION:
1526 mode = NDIS_80211_INFRA_INFRA;
1532 return set_infra_mode(usbdev, mode);
1536 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1538 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1539 struct usbnet *usbdev = priv->usbdev;
1542 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1543 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1548 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1549 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1558 static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1561 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1562 struct usbnet *usbdev = priv->usbdev;
1564 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1566 /* Device doesn't support changing txpower after initialization, only
1567 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1570 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1571 if (!priv->radio_on)
1572 disassociate(usbdev, 1); /* turn on radio */
1581 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1583 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1584 struct usbnet *usbdev = priv->usbdev;
1586 *dbm = get_bcm4320_power_dbm(priv);
1588 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1594 #define SCAN_DELAY_JIFFIES (HZ)
1595 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1596 struct cfg80211_scan_request *request)
1598 struct usbnet *usbdev = netdev_priv(dev);
1599 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1603 devdbg(usbdev, "cfg80211.scan");
1608 if (priv->scan_request && priv->scan_request != request)
1611 priv->scan_request = request;
1613 tmp = cpu_to_le32(1);
1614 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1617 /* Wait before retrieving scan results from device */
1618 queue_delayed_work(priv->workqueue, &priv->scan_work,
1619 SCAN_DELAY_JIFFIES);
1626 static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1627 struct ndis_80211_bssid_ex *bssid)
1629 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1630 struct ieee80211_channel *channel;
1634 u16 beacon_interval;
1635 struct ndis_80211_fixed_ies *fixed;
1636 int ie_len, bssid_len;
1639 /* parse bssid structure */
1640 bssid_len = le32_to_cpu(bssid->length);
1642 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1643 sizeof(struct ndis_80211_fixed_ies))
1646 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1648 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1649 ie_len = min(bssid_len - (int)sizeof(*bssid),
1650 (int)le32_to_cpu(bssid->ie_length));
1651 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1655 /* extract data for cfg80211_inform_bss */
1656 channel = ieee80211_get_channel(priv->wdev.wiphy,
1657 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1661 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1662 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1663 capability = le16_to_cpu(fixed->capabilities);
1664 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1666 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1667 timestamp, capability, beacon_interval, ie, ie_len, signal,
1672 static int rndis_check_bssid_list(struct usbnet *usbdev)
1675 struct ndis_80211_bssid_list_ex *bssid_list;
1676 struct ndis_80211_bssid_ex *bssid;
1677 int ret = -EINVAL, len, count, bssid_len;
1679 devdbg(usbdev, "check_bssid_list");
1681 len = CONTROL_BUFFER_SIZE;
1682 buf = kmalloc(len, GFP_KERNEL);
1688 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1693 bssid = bssid_list->bssid;
1694 bssid_len = le32_to_cpu(bssid->length);
1695 count = le32_to_cpu(bssid_list->num_items);
1696 devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count);
1698 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1699 rndis_bss_info_update(usbdev, bssid);
1701 bssid = (void *)bssid + bssid_len;
1702 bssid_len = le32_to_cpu(bssid->length);
1712 static void rndis_get_scan_results(struct work_struct *work)
1714 struct rndis_wlan_private *priv =
1715 container_of(work, struct rndis_wlan_private, scan_work.work);
1716 struct usbnet *usbdev = priv->usbdev;
1719 devdbg(usbdev, "get_scan_results");
1721 if (!priv->scan_request)
1724 ret = rndis_check_bssid_list(usbdev);
1726 cfg80211_scan_done(priv->scan_request, ret < 0);
1728 priv->scan_request = NULL;
1733 * wireless extension handlers
1736 static int rndis_iw_commit(struct net_device *dev,
1737 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1744 static int rndis_iw_set_essid(struct net_device *dev,
1745 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1747 struct ndis_80211_ssid ssid;
1748 int length = wrqu->essid.length;
1749 struct usbnet *usbdev = netdev_priv(dev);
1751 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1752 wrqu->essid.flags, wrqu->essid.length, essid);
1754 if (length > NDIS_802_11_LENGTH_SSID)
1755 length = NDIS_802_11_LENGTH_SSID;
1757 ssid.length = cpu_to_le32(length);
1759 memcpy(ssid.essid, essid, length);
1761 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
1763 set_assoc_params(usbdev);
1765 if (!wrqu->essid.flags || length == 0)
1766 return disassociate(usbdev, 1);
1768 /* Pause and purge rx queue, so we don't pass packets before
1769 * 'media connect'-indication.
1771 usbnet_pause_rx(usbdev);
1772 usbnet_purge_paused_rxq(usbdev);
1774 return set_essid(usbdev, &ssid);
1779 static int rndis_iw_get_essid(struct net_device *dev,
1780 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1782 struct ndis_80211_ssid ssid;
1783 struct usbnet *usbdev = netdev_priv(dev);
1786 ret = get_essid(usbdev, &ssid);
1788 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
1789 wrqu->essid.flags = 1;
1790 wrqu->essid.length = le32_to_cpu(ssid.length);
1791 memcpy(essid, ssid.essid, wrqu->essid.length);
1792 essid[wrqu->essid.length] = 0;
1794 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1795 wrqu->essid.flags = 0;
1796 wrqu->essid.length = 0;
1798 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1803 static int rndis_iw_get_bssid(struct net_device *dev,
1804 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1806 struct usbnet *usbdev = netdev_priv(dev);
1807 unsigned char bssid[ETH_ALEN];
1810 ret = get_bssid(usbdev, bssid);
1813 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
1815 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1817 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1818 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1824 static int rndis_iw_set_bssid(struct net_device *dev,
1825 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1827 struct usbnet *usbdev = netdev_priv(dev);
1828 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
1831 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
1833 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1835 /* user apps may set ap's mac address, which is not required;
1836 * they may fail to work if this function fails, so return
1839 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1845 static int rndis_iw_set_auth(struct net_device *dev,
1846 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1848 struct iw_param *p = &wrqu->param;
1849 struct usbnet *usbdev = netdev_priv(dev);
1850 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1851 int ret = -ENOTSUPP;
1853 switch (p->flags & IW_AUTH_INDEX) {
1854 case IW_AUTH_WPA_VERSION:
1855 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1856 priv->wpa_version = p->value;
1860 case IW_AUTH_CIPHER_PAIRWISE:
1861 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1862 priv->wpa_cipher_pair = p->value;
1866 case IW_AUTH_CIPHER_GROUP:
1867 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1868 priv->wpa_cipher_group = p->value;
1872 case IW_AUTH_KEY_MGMT:
1873 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1874 priv->wpa_keymgmt = p->value;
1878 case IW_AUTH_TKIP_COUNTERMEASURES:
1879 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1884 case IW_AUTH_DROP_UNENCRYPTED:
1885 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1889 case IW_AUTH_80211_AUTH_ALG:
1890 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1891 priv->wpa_authalg = p->value;
1895 case IW_AUTH_WPA_ENABLED:
1896 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1897 if (wrqu->param.value)
1898 deauthenticate(usbdev);
1902 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1903 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1908 case IW_AUTH_ROAMING_CONTROL:
1909 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1913 case IW_AUTH_PRIVACY_INVOKED:
1914 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1915 wrqu->param.flags & IW_AUTH_INDEX);
1919 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1920 p->flags & IW_AUTH_INDEX, p->value);
1926 static int rndis_iw_get_auth(struct net_device *dev,
1927 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1929 struct iw_param *p = &wrqu->param;
1930 struct usbnet *usbdev = netdev_priv(dev);
1931 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1933 switch (p->flags & IW_AUTH_INDEX) {
1934 case IW_AUTH_WPA_VERSION:
1935 p->value = priv->wpa_version;
1937 case IW_AUTH_CIPHER_PAIRWISE:
1938 p->value = priv->wpa_cipher_pair;
1940 case IW_AUTH_CIPHER_GROUP:
1941 p->value = priv->wpa_cipher_group;
1943 case IW_AUTH_KEY_MGMT:
1944 p->value = priv->wpa_keymgmt;
1946 case IW_AUTH_80211_AUTH_ALG:
1947 p->value = priv->wpa_authalg;
1950 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1951 wrqu->param.flags & IW_AUTH_INDEX);
1958 static int rndis_iw_set_encode(struct net_device *dev,
1959 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1961 struct usbnet *usbdev = netdev_priv(dev);
1962 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1963 struct rndis_wlan_encr_key key;
1964 int ret, index, key_len;
1967 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
1969 /* iwconfig gives index as 1 - N */
1973 index = priv->encr_tx_key_index;
1975 if (index < 0 || index >= 4) {
1976 devwarn(usbdev, "encryption index out of range (%u)", index);
1980 /* remove key if disabled */
1981 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
1982 if (remove_key(usbdev, index, NULL))
1988 /* global encryption state (for all keys) */
1989 if (wrqu->data.flags & IW_ENCODE_OPEN)
1990 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1991 IW_AUTH_ALG_OPEN_SYSTEM);
1992 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1993 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1994 IW_AUTH_ALG_SHARED_KEY);
1998 if (wrqu->data.length > 0) {
1999 key_len = wrqu->data.length;
2002 /* must be set as tx key */
2003 if (priv->encr_keys[index].len == 0)
2005 key = priv->encr_keys[index];
2007 keybuf = key.material;
2008 priv->encr_tx_key_index = index;
2011 if (add_wep_key(usbdev, keybuf, key_len, index) != 0)
2014 if (index == priv->encr_tx_key_index)
2015 /* ndis drivers want essid to be set after setting encr */
2016 set_essid(usbdev, &priv->essid);
2022 static int rndis_iw_set_encode_ext(struct net_device *dev,
2023 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2025 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2026 struct usbnet *usbdev = netdev_priv(dev);
2027 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2028 int keyidx, flags, cipher;
2030 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
2032 /* iwconfig gives index as 1 - N */
2036 keyidx = priv->encr_tx_key_index;
2038 if (keyidx < 0 || keyidx >= 4) {
2039 devwarn(usbdev, "encryption index out of range (%u)", keyidx);
2043 if (ext->alg == WPA_ALG_WEP) {
2044 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2045 priv->encr_tx_key_index = keyidx;
2046 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
2050 if (ext->alg == IW_ENCODE_ALG_TKIP)
2051 cipher = WLAN_CIPHER_SUITE_TKIP;
2052 else if (ext->alg == IW_ENCODE_ALG_CCMP)
2053 cipher = WLAN_CIPHER_SUITE_CCMP;
2055 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
2056 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
2057 return remove_key(usbdev, keyidx, NULL);
2063 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
2064 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
2065 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
2066 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
2067 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2068 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
2070 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx,
2071 (u8 *)&ext->addr.sa_data, ext->rx_seq, cipher,
2076 static int rndis_iw_set_genie(struct net_device *dev,
2077 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2079 struct usbnet *usbdev = netdev_priv(dev);
2080 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2086 for (j = 0; j < wrqu->data.length; j += 8)
2088 "SIOCSIWGENIE %04x - "
2089 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
2090 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
2091 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
2093 /* clear existing IEs */
2094 if (priv->wpa_ie_len) {
2095 kfree(priv->wpa_ie);
2096 priv->wpa_ie_len = 0;
2100 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
2102 priv->wpa_ie_len = wrqu->data.length;
2103 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
2110 static int rndis_iw_get_genie(struct net_device *dev,
2111 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2113 struct usbnet *usbdev = netdev_priv(dev);
2114 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2116 devdbg(usbdev, "SIOCGIWGENIE");
2118 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
2119 wrqu->data.length = 0;
2123 if (wrqu->data.length < priv->wpa_ie_len)
2126 wrqu->data.length = priv->wpa_ie_len;
2127 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
2133 static int rndis_iw_set_freq(struct net_device *dev,
2134 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2136 struct usbnet *usbdev = netdev_priv(dev);
2137 struct ndis_80211_conf config;
2138 unsigned int dsconfig;
2141 /* this OID is valid only when not associated */
2142 if (is_associated(usbdev))
2146 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
2149 len = sizeof(config);
2150 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2152 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
2156 config.ds_config = cpu_to_le32(dsconfig);
2158 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
2159 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
2164 static int rndis_iw_get_freq(struct net_device *dev,
2165 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2167 struct usbnet *usbdev = netdev_priv(dev);
2168 struct ndis_80211_conf config;
2171 len = sizeof(config);
2172 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2174 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
2176 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
2181 static int rndis_iw_get_rate(struct net_device *dev,
2182 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2184 struct usbnet *usbdev = netdev_priv(dev);
2189 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
2191 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
2192 wrqu->bitrate.disabled = 0;
2193 wrqu->bitrate.flags = 1;
2199 static int rndis_iw_set_mlme(struct net_device *dev,
2200 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2202 struct usbnet *usbdev = netdev_priv(dev);
2203 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2204 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2205 unsigned char bssid[ETH_ALEN];
2207 get_bssid(usbdev, bssid);
2209 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
2212 switch (mlme->cmd) {
2213 case IW_MLME_DEAUTH:
2214 return deauthenticate(usbdev);
2215 case IW_MLME_DISASSOC:
2216 return disassociate(usbdev, priv->radio_on);
2225 static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
2227 struct usbnet *usbdev = netdev_priv(dev);
2228 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2229 unsigned long flags;
2231 spin_lock_irqsave(&priv->stats_lock, flags);
2232 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2233 spin_unlock_irqrestore(&priv->stats_lock, flags);
2235 return &priv->iwstats;
2239 #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2240 static const iw_handler rndis_iw_handler[] =
2242 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
2243 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
2244 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2245 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
2246 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2247 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
2248 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
2249 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2250 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
2251 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2252 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
2253 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2254 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
2255 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
2256 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2257 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2258 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2259 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
2260 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2261 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
2262 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2263 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2264 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2265 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2266 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2267 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2268 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2271 static const iw_handler rndis_wlan_private_handler[] = {
2274 static const struct iw_priv_args rndis_wlan_private_args[] = {
2278 static const struct iw_handler_def rndis_iw_handlers = {
2279 .num_standard = ARRAY_SIZE(rndis_iw_handler),
2280 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2281 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
2282 .standard = (iw_handler *)rndis_iw_handler,
2283 .private = (iw_handler *)rndis_wlan_private_handler,
2284 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
2285 .get_wireless_stats = rndis_get_wireless_stats,
2289 static void rndis_wlan_worker(struct work_struct *work)
2291 struct rndis_wlan_private *priv =
2292 container_of(work, struct rndis_wlan_private, work);
2293 struct usbnet *usbdev = priv->usbdev;
2294 union iwreq_data evt;
2295 unsigned char bssid[ETH_ALEN];
2296 struct ndis_80211_assoc_info *info;
2297 int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32;
2300 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) {
2301 netif_carrier_on(usbdev->net);
2303 info = kzalloc(assoc_size, GFP_KERNEL);
2307 /* Get association info IEs from device and send them back to
2309 ret = get_association_info(usbdev, info, assoc_size);
2311 evt.data.length = le32_to_cpu(info->req_ie_length);
2312 if (evt.data.length > 0) {
2313 offset = le32_to_cpu(info->offset_req_ies);
2314 wireless_send_event(usbdev->net,
2315 IWEVASSOCREQIE, &evt,
2316 (char *)info + offset);
2319 evt.data.length = le32_to_cpu(info->resp_ie_length);
2320 if (evt.data.length > 0) {
2321 offset = le32_to_cpu(info->offset_resp_ies);
2322 wireless_send_event(usbdev->net,
2323 IWEVASSOCRESPIE, &evt,
2324 (char *)info + offset);
2331 ret = get_bssid(usbdev, bssid);
2334 evt.data.length = 0;
2335 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
2336 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2339 usbnet_resume_rx(usbdev);
2342 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) {
2343 netif_carrier_off(usbdev->net);
2346 evt.data.length = 0;
2347 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2348 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2351 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2352 set_multicast_list(usbdev);
2355 static void rndis_wlan_set_multicast_list(struct net_device *dev)
2357 struct usbnet *usbdev = netdev_priv(dev);
2358 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2360 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2363 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2364 queue_work(priv->workqueue, &priv->work);
2368 static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2369 struct ndis_80211_status_indication *indication,
2375 bool pairwise_error, group_error;
2376 struct ndis_80211_auth_request *auth_req;
2378 /* must have at least one array entry */
2379 if (len < offsetof(struct ndis_80211_status_indication, u) +
2380 sizeof(struct ndis_80211_auth_request)) {
2381 devinfo(usbdev, "authentication indication: "
2382 "too short message (%i)", len);
2386 buf = (void *)&indication->u.auth_request[0];
2387 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2389 while (buflen >= sizeof(*auth_req)) {
2390 auth_req = (void *)buf;
2392 flags = le32_to_cpu(auth_req->flags);
2393 pairwise_error = false;
2394 group_error = false;
2397 type = "reauth request";
2399 type = "key update request";
2401 pairwise_error = true;
2402 type = "pairwise_error";
2406 type = "group_error";
2409 devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
2410 le32_to_cpu(auth_req->flags));
2412 if (pairwise_error || group_error) {
2413 union iwreq_data wrqu;
2414 struct iw_michaelmicfailure micfailure;
2416 memset(&micfailure, 0, sizeof(micfailure));
2418 micfailure.flags |= IW_MICFAILURE_PAIRWISE;
2420 micfailure.flags |= IW_MICFAILURE_GROUP;
2422 memcpy(micfailure.src_addr.sa_data, auth_req->bssid,
2425 memset(&wrqu, 0, sizeof(wrqu));
2426 wrqu.data.length = sizeof(micfailure);
2427 wireless_send_event(usbdev->net, IWEVMICHAELMICFAILURE,
2428 &wrqu, (u8 *)&micfailure);
2431 buflen -= le32_to_cpu(auth_req->length);
2432 buf += le32_to_cpu(auth_req->length);
2436 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2437 struct ndis_80211_status_indication *indication,
2440 struct ndis_80211_pmkid_cand_list *cand_list;
2441 int list_len, expected_len, i;
2443 if (len < offsetof(struct ndis_80211_status_indication, u) +
2444 sizeof(struct ndis_80211_pmkid_cand_list)) {
2445 devinfo(usbdev, "pmkid candidate list indication: "
2446 "too short message (%i)", len);
2450 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2451 sizeof(struct ndis_80211_pmkid_candidate);
2452 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2453 offsetof(struct ndis_80211_status_indication, u);
2455 if (len < expected_len) {
2456 devinfo(usbdev, "pmkid candidate list indication: "
2457 "list larger than buffer (%i < %i)",
2462 cand_list = &indication->u.cand_list;
2464 devinfo(usbdev, "pmkid candidate list indication: "
2465 "version %i, candidates %i",
2466 le32_to_cpu(cand_list->version),
2467 le32_to_cpu(cand_list->num_candidates));
2469 if (le32_to_cpu(cand_list->version) != 1)
2472 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
2473 struct iw_pmkid_cand pcand;
2474 union iwreq_data wrqu;
2475 struct ndis_80211_pmkid_candidate *cand =
2476 &cand_list->candidate_list[i];
2478 devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
2479 i, le32_to_cpu(cand->flags), cand->bssid);
2481 memset(&pcand, 0, sizeof(pcand));
2482 if (le32_to_cpu(cand->flags) & 0x01)
2483 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2485 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2487 memset(&wrqu, 0, sizeof(wrqu));
2488 wrqu.data.length = sizeof(pcand);
2489 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2494 static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2495 struct rndis_indicate *msg, int buflen)
2497 struct ndis_80211_status_indication *indication;
2500 offset = offsetof(struct rndis_indicate, status) +
2501 le32_to_cpu(msg->offset);
2502 len = le32_to_cpu(msg->length);
2505 devinfo(usbdev, "media specific indication, "
2506 "ignore too short message (%i < 8)", len);
2510 if (offset + len > buflen) {
2511 devinfo(usbdev, "media specific indication, "
2512 "too large to fit to buffer (%i > %i)",
2513 offset + len, buflen);
2517 indication = (void *)((u8 *)msg + offset);
2519 switch (le32_to_cpu(indication->status_type)) {
2520 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2521 devinfo(usbdev, "radio state indication: %i",
2522 le32_to_cpu(indication->u.radio_status));
2525 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2526 devinfo(usbdev, "media stream mode indication: %i",
2527 le32_to_cpu(indication->u.media_stream_mode));
2530 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2531 rndis_wlan_auth_indication(usbdev, indication, len);
2534 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2535 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2539 devinfo(usbdev, "media specific indication: "
2540 "unknown status type 0x%08x",
2541 le32_to_cpu(indication->status_type));
2546 static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
2548 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2549 struct rndis_indicate *msg = ind;
2551 switch (msg->status) {
2552 case RNDIS_STATUS_MEDIA_CONNECT:
2553 usbnet_pause_rx(usbdev);
2555 devinfo(usbdev, "media connect");
2557 /* queue work to avoid recursive calls into rndis_command */
2558 set_bit(WORK_LINK_UP, &priv->work_pending);
2559 queue_work(priv->workqueue, &priv->work);
2562 case RNDIS_STATUS_MEDIA_DISCONNECT:
2563 devinfo(usbdev, "media disconnect");
2565 /* queue work to avoid recursive calls into rndis_command */
2566 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2567 queue_work(priv->workqueue, &priv->work);
2570 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2571 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2575 devinfo(usbdev, "indication: 0x%08x",
2576 le32_to_cpu(msg->status));
2582 static int rndis_wlan_get_caps(struct usbnet *usbdev)
2587 } networks_supported;
2588 int len, retval, i, n;
2589 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2591 /* determine supported modes */
2592 len = sizeof(networks_supported);
2593 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
2594 &networks_supported, &len);
2596 n = le32_to_cpu(networks_supported.num_items);
2599 for (i = 0; i < n; i++) {
2600 switch (le32_to_cpu(networks_supported.items[i])) {
2601 case NDIS_80211_TYPE_FREQ_HOP:
2602 case NDIS_80211_TYPE_DIRECT_SEQ:
2603 priv->caps |= CAP_MODE_80211B;
2605 case NDIS_80211_TYPE_OFDM_A:
2606 priv->caps |= CAP_MODE_80211A;
2608 case NDIS_80211_TYPE_OFDM_G:
2609 priv->caps |= CAP_MODE_80211G;
2619 #define STATS_UPDATE_JIFFIES (HZ)
2620 static void rndis_update_wireless_stats(struct work_struct *work)
2622 struct rndis_wlan_private *priv =
2623 container_of(work, struct rndis_wlan_private, stats_work.work);
2624 struct usbnet *usbdev = priv->usbdev;
2625 struct iw_statistics iwstats;
2628 unsigned long flags;
2629 int update_jiffies = STATS_UPDATE_JIFFIES;
2632 spin_lock_irqsave(&priv->stats_lock, flags);
2633 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2634 spin_unlock_irqrestore(&priv->stats_lock, flags);
2636 /* only update stats when connected */
2637 if (!is_associated(usbdev)) {
2638 iwstats.qual.qual = 0;
2639 iwstats.qual.level = 0;
2640 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2641 | IW_QUAL_LEVEL_UPDATED
2642 | IW_QUAL_NOISE_INVALID
2643 | IW_QUAL_QUAL_INVALID
2644 | IW_QUAL_LEVEL_INVALID;
2649 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2651 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2654 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2655 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
2656 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
2657 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2658 | IW_QUAL_LEVEL_UPDATED
2659 | IW_QUAL_NOISE_INVALID;
2662 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2665 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2667 iwstats.discard.misc += le32_to_cpu(tmp);
2670 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2672 iwstats.discard.misc += le32_to_cpu(tmp);
2675 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2677 iwstats.discard.misc += le32_to_cpu(tmp);
2679 /* Workaround transfer stalls on poor quality links.
2680 * TODO: find right way to fix these stalls (as stalls do not happen
2681 * with ndiswrapper/windows driver). */
2682 if (iwstats.qual.qual <= 25) {
2683 /* Decrease stats worker interval to catch stalls.
2684 * faster. Faster than 400-500ms causes packet loss,
2685 * Slower doesn't catch stalls fast enough.
2687 j = msecs_to_jiffies(priv->param_workaround_interval);
2688 if (j > STATS_UPDATE_JIFFIES)
2689 j = STATS_UPDATE_JIFFIES;
2694 /* Send scan OID. Use of both OIDs is required to get device
2697 tmp = cpu_to_le32(1);
2698 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2701 len = CONTROL_BUFFER_SIZE;
2702 buf = kmalloc(len, GFP_KERNEL);
2706 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2710 spin_lock_irqsave(&priv->stats_lock, flags);
2711 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2712 spin_unlock_irqrestore(&priv->stats_lock, flags);
2714 if (update_jiffies >= HZ)
2715 update_jiffies = round_jiffies_relative(update_jiffies);
2717 j = round_jiffies_relative(update_jiffies);
2718 if (abs(j - update_jiffies) <= 10)
2722 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2726 static int bcm4320a_early_init(struct usbnet *usbdev)
2728 /* bcm4320a doesn't handle configuration parameters well. Try
2729 * set any and you get partially zeroed mac and broken device.
2736 static int bcm4320b_early_init(struct usbnet *usbdev)
2738 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2741 /* Early initialization settings, setting these won't have effect
2742 * if called after generic_rndis_bind().
2745 priv->param_country[0] = modparam_country[0];
2746 priv->param_country[1] = modparam_country[1];
2747 priv->param_country[2] = 0;
2748 priv->param_frameburst = modparam_frameburst;
2749 priv->param_afterburner = modparam_afterburner;
2750 priv->param_power_save = modparam_power_save;
2751 priv->param_power_output = modparam_power_output;
2752 priv->param_roamtrigger = modparam_roamtrigger;
2753 priv->param_roamdelta = modparam_roamdelta;
2755 priv->param_country[0] = toupper(priv->param_country[0]);
2756 priv->param_country[1] = toupper(priv->param_country[1]);
2757 /* doesn't support EU as country code, use FI instead */
2758 if (!strcmp(priv->param_country, "EU"))
2759 strcpy(priv->param_country, "FI");
2761 if (priv->param_power_save < 0)
2762 priv->param_power_save = 0;
2763 else if (priv->param_power_save > 2)
2764 priv->param_power_save = 2;
2766 if (priv->param_power_output < 0)
2767 priv->param_power_output = 0;
2768 else if (priv->param_power_output > 3)
2769 priv->param_power_output = 3;
2771 if (priv->param_roamtrigger < -80)
2772 priv->param_roamtrigger = -80;
2773 else if (priv->param_roamtrigger > -60)
2774 priv->param_roamtrigger = -60;
2776 if (priv->param_roamdelta < 0)
2777 priv->param_roamdelta = 0;
2778 else if (priv->param_roamdelta > 2)
2779 priv->param_roamdelta = 2;
2781 if (modparam_workaround_interval < 0)
2782 priv->param_workaround_interval = 500;
2784 priv->param_workaround_interval = modparam_workaround_interval;
2786 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2787 rndis_set_config_parameter_str(usbdev, "FrameBursting",
2788 priv->param_frameburst ? "1" : "0");
2789 rndis_set_config_parameter_str(usbdev, "Afterburner",
2790 priv->param_afterburner ? "1" : "0");
2791 sprintf(buf, "%d", priv->param_power_save);
2792 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
2793 sprintf(buf, "%d", priv->param_power_output);
2794 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
2795 sprintf(buf, "%d", priv->param_roamtrigger);
2796 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
2797 sprintf(buf, "%d", priv->param_roamdelta);
2798 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
2803 /* same as rndis_netdev_ops but with local multicast handler */
2804 static const struct net_device_ops rndis_wlan_netdev_ops = {
2805 .ndo_open = usbnet_open,
2806 .ndo_stop = usbnet_stop,
2807 .ndo_start_xmit = usbnet_start_xmit,
2808 .ndo_tx_timeout = usbnet_tx_timeout,
2809 .ndo_set_mac_address = eth_mac_addr,
2810 .ndo_validate_addr = eth_validate_addr,
2811 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
2815 static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
2817 struct wiphy *wiphy;
2818 struct rndis_wlan_private *priv;
2822 /* allocate wiphy and rndis private data
2823 * NOTE: We only support a single virtual interface, so wiphy
2824 * and wireless_dev are somewhat synonymous for this device.
2826 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
2830 priv = wiphy_priv(wiphy);
2831 usbdev->net->ieee80211_ptr = &priv->wdev;
2832 priv->wdev.wiphy = wiphy;
2833 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2835 /* These have to be initialized before calling generic_rndis_bind().
2836 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
2838 usbdev->driver_priv = priv;
2839 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2840 priv->usbdev = usbdev;
2842 mutex_init(&priv->command_lock);
2843 spin_lock_init(&priv->stats_lock);
2845 /* because rndis_command() sleeps we need to use workqueue */
2846 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
2847 INIT_WORK(&priv->work, rndis_wlan_worker);
2848 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2849 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2851 /* try bind rndis_host */
2852 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
2856 /* generic_rndis_bind set packet filter to multicast_all+
2857 * promisc mode which doesn't work well for our devices (device
2858 * picks up rssi to closest station instead of to access point).
2860 * rndis_host wants to avoid all OID as much as possible
2861 * so do promisc/multicast handling in rndis_wlan.
2863 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
2865 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
2866 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
2870 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2872 priv->multicast_size = le32_to_cpu(tmp);
2873 if (retval < 0 || priv->multicast_size < 0)
2874 priv->multicast_size = 0;
2875 if (priv->multicast_size > 0)
2876 usbdev->net->flags |= IFF_MULTICAST;
2878 usbdev->net->flags &= ~IFF_MULTICAST;
2880 priv->iwstats.qual.qual = 0;
2881 priv->iwstats.qual.level = 0;
2882 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2883 | IW_QUAL_LEVEL_UPDATED
2884 | IW_QUAL_NOISE_INVALID
2885 | IW_QUAL_QUAL_INVALID
2886 | IW_QUAL_LEVEL_INVALID;
2888 /* fill-out wiphy structure and register w/ cfg80211 */
2889 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2890 wiphy->privid = rndis_wiphy_privid;
2891 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2892 | BIT(NL80211_IFTYPE_ADHOC);
2893 wiphy->max_scan_ssids = 1;
2895 /* TODO: fill-out band information based on priv->caps */
2896 rndis_wlan_get_caps(usbdev);
2898 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2899 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2900 priv->band.channels = priv->channels;
2901 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2902 priv->band.bitrates = priv->rates;
2903 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2904 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
2905 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2907 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2909 if (wiphy_register(wiphy)) {
2914 set_default_iw_params(usbdev);
2916 /* set default rts/frag */
2917 rndis_set_wiphy_params(wiphy,
2918 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2922 disassociate(usbdev, 1);
2923 netif_carrier_off(usbdev->net);
2928 cancel_delayed_work_sync(&priv->stats_work);
2929 cancel_delayed_work_sync(&priv->scan_work);
2930 cancel_work_sync(&priv->work);
2931 flush_workqueue(priv->workqueue);
2932 destroy_workqueue(priv->workqueue);
2939 static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
2941 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2943 /* turn radio off */
2944 disassociate(usbdev, 0);
2946 cancel_delayed_work_sync(&priv->stats_work);
2947 cancel_delayed_work_sync(&priv->scan_work);
2948 cancel_work_sync(&priv->work);
2949 flush_workqueue(priv->workqueue);
2950 destroy_workqueue(priv->workqueue);
2952 if (priv && priv->wpa_ie_len)
2953 kfree(priv->wpa_ie);
2955 rndis_unbind(usbdev, intf);
2957 wiphy_unregister(priv->wdev.wiphy);
2958 wiphy_free(priv->wdev.wiphy);
2962 static int rndis_wlan_reset(struct usbnet *usbdev)
2964 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2967 devdbg(usbdev, "rndis_wlan_reset");
2969 retval = rndis_reset(usbdev);
2971 devwarn(usbdev, "rndis_reset() failed: %d", retval);
2973 /* rndis_reset cleared multicast list, so restore here.
2974 (set_multicast_list() also turns on current packet filter) */
2975 set_multicast_list(usbdev);
2977 queue_delayed_work(priv->workqueue, &priv->stats_work,
2978 round_jiffies_relative(STATS_UPDATE_JIFFIES));
2980 return deauthenticate(usbdev);
2984 static int rndis_wlan_stop(struct usbnet *usbdev)
2986 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2990 devdbg(usbdev, "rndis_wlan_stop");
2992 retval = disassociate(usbdev, 0);
2994 priv->work_pending = 0;
2995 cancel_delayed_work_sync(&priv->stats_work);
2996 cancel_delayed_work_sync(&priv->scan_work);
2997 cancel_work_sync(&priv->work);
2998 flush_workqueue(priv->workqueue);
3000 if (priv->scan_request) {
3001 cfg80211_scan_done(priv->scan_request, true);
3002 priv->scan_request = NULL;
3005 /* Set current packet filter zero to block receiving data packets from
3008 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
3015 static const struct driver_info bcm4320b_info = {
3016 .description = "Wireless RNDIS device, BCM4320b based",
3017 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3018 FLAG_AVOID_UNLINK_URBS,
3019 .bind = rndis_wlan_bind,
3020 .unbind = rndis_wlan_unbind,
3021 .status = rndis_status,
3022 .rx_fixup = rndis_rx_fixup,
3023 .tx_fixup = rndis_tx_fixup,
3024 .reset = rndis_wlan_reset,
3025 .stop = rndis_wlan_stop,
3026 .early_init = bcm4320b_early_init,
3027 .indication = rndis_wlan_indication,
3030 static const struct driver_info bcm4320a_info = {
3031 .description = "Wireless RNDIS device, BCM4320a based",
3032 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3033 FLAG_AVOID_UNLINK_URBS,
3034 .bind = rndis_wlan_bind,
3035 .unbind = rndis_wlan_unbind,
3036 .status = rndis_status,
3037 .rx_fixup = rndis_rx_fixup,
3038 .tx_fixup = rndis_tx_fixup,
3039 .reset = rndis_wlan_reset,
3040 .stop = rndis_wlan_stop,
3041 .early_init = bcm4320a_early_init,
3042 .indication = rndis_wlan_indication,
3045 static const struct driver_info rndis_wlan_info = {
3046 .description = "Wireless RNDIS device",
3047 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3048 FLAG_AVOID_UNLINK_URBS,
3049 .bind = rndis_wlan_bind,
3050 .unbind = rndis_wlan_unbind,
3051 .status = rndis_status,
3052 .rx_fixup = rndis_rx_fixup,
3053 .tx_fixup = rndis_tx_fixup,
3054 .reset = rndis_wlan_reset,
3055 .stop = rndis_wlan_stop,
3056 .early_init = bcm4320a_early_init,
3057 .indication = rndis_wlan_indication,
3060 /*-------------------------------------------------------------------------*/
3062 static const struct usb_device_id products [] = {
3063 #define RNDIS_MASTER_INTERFACE \
3064 .bInterfaceClass = USB_CLASS_COMM, \
3065 .bInterfaceSubClass = 2 /* ACM */, \
3066 .bInterfaceProtocol = 0x0ff
3068 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3069 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3072 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3073 | USB_DEVICE_ID_MATCH_DEVICE,
3075 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
3076 RNDIS_MASTER_INTERFACE,
3077 .driver_info = (unsigned long) &bcm4320b_info,
3079 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3080 | USB_DEVICE_ID_MATCH_DEVICE,
3082 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
3083 RNDIS_MASTER_INTERFACE,
3084 .driver_info = (unsigned long) &bcm4320b_info,
3086 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3087 | USB_DEVICE_ID_MATCH_DEVICE,
3089 .idProduct = 0x011b, /* Belkin F5D7051 */
3090 RNDIS_MASTER_INTERFACE,
3091 .driver_info = (unsigned long) &bcm4320b_info,
3093 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3094 | USB_DEVICE_ID_MATCH_DEVICE,
3095 .idVendor = 0x1799, /* Belkin has two vendor ids */
3096 .idProduct = 0x011b, /* Belkin F5D7051 */
3097 RNDIS_MASTER_INTERFACE,
3098 .driver_info = (unsigned long) &bcm4320b_info,
3100 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3101 | USB_DEVICE_ID_MATCH_DEVICE,
3103 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
3104 RNDIS_MASTER_INTERFACE,
3105 .driver_info = (unsigned long) &bcm4320b_info,
3107 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3108 | USB_DEVICE_ID_MATCH_DEVICE,
3110 .idProduct = 0x0026, /* Linksys WUSB54GSC */
3111 RNDIS_MASTER_INTERFACE,
3112 .driver_info = (unsigned long) &bcm4320b_info,
3114 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3115 | USB_DEVICE_ID_MATCH_DEVICE,
3117 .idProduct = 0x1717, /* Asus WL169gE */
3118 RNDIS_MASTER_INTERFACE,
3119 .driver_info = (unsigned long) &bcm4320b_info,
3121 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3122 | USB_DEVICE_ID_MATCH_DEVICE,
3124 .idProduct = 0xd11b, /* Eminent EM4045 */
3125 RNDIS_MASTER_INTERFACE,
3126 .driver_info = (unsigned long) &bcm4320b_info,
3128 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3129 | USB_DEVICE_ID_MATCH_DEVICE,
3131 .idProduct = 0x0715, /* BT Voyager 1055 */
3132 RNDIS_MASTER_INTERFACE,
3133 .driver_info = (unsigned long) &bcm4320b_info,
3135 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3136 * parameters available, hardware probably contain older firmware version with
3137 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3140 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3141 | USB_DEVICE_ID_MATCH_DEVICE,
3143 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3144 RNDIS_MASTER_INTERFACE,
3145 .driver_info = (unsigned long) &bcm4320a_info,
3147 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3148 | USB_DEVICE_ID_MATCH_DEVICE,
3150 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3151 RNDIS_MASTER_INTERFACE,
3152 .driver_info = (unsigned long) &bcm4320a_info,
3154 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3155 | USB_DEVICE_ID_MATCH_DEVICE,
3157 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3158 RNDIS_MASTER_INTERFACE,
3159 .driver_info = (unsigned long) &bcm4320a_info,
3161 /* Generic Wireless RNDIS devices that we don't have exact
3162 * idVendor/idProduct/chip yet.
3165 /* RNDIS is MSFT's un-official variant of CDC ACM */
3166 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3167 .driver_info = (unsigned long) &rndis_wlan_info,
3169 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3170 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
3171 .driver_info = (unsigned long) &rndis_wlan_info,
3175 MODULE_DEVICE_TABLE(usb, products);
3177 static struct usb_driver rndis_wlan_driver = {
3178 .name = "rndis_wlan",
3179 .id_table = products,
3180 .probe = usbnet_probe,
3181 .disconnect = usbnet_disconnect,
3182 .suspend = usbnet_suspend,
3183 .resume = usbnet_resume,
3186 static int __init rndis_wlan_init(void)
3188 return usb_register(&rndis_wlan_driver);
3190 module_init(rndis_wlan_init);
3192 static void __exit rndis_wlan_exit(void)
3194 usb_deregister(&rndis_wlan_driver);
3196 module_exit(rndis_wlan_exit);
3198 MODULE_AUTHOR("Bjorge Dijkstra");
3199 MODULE_AUTHOR("Jussi Kivilinna");
3200 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3201 MODULE_LICENSE("GPL");