blob: 76c5ec6bbbc5c86b24928d40f383d45843ca25a3 [file] [log] [blame]
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001/*
2 * Driver for RNDIS based wireless USB devices.
3 *
4 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
Jussi Kivilinna9656e852009-05-22 17:40:12 +03005 * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02006 *
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.
11 *
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.
16 *
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
20 *
21 * Portions of this file are based on NDISwrapper project,
22 * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
23 * http://ndiswrapper.sourceforge.net/
24 */
25
26// #define DEBUG // error path messages, extra info
27// #define VERBOSE // more; success messages
28
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>
Johannes Berg2c7060022008-10-30 22:09:54 +010040#include <linux/ieee80211.h>
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +020041#include <linux/if_arp.h>
42#include <linux/ctype.h>
43#include <linux/spinlock.h>
44#include <net/iw_handler.h>
John W. Linville5c8fa4f2009-03-26 23:39:53 +020045#include <net/cfg80211.h>
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +020046#include <linux/usb/usbnet.h>
47#include <linux/usb/rndis_host.h>
48
49
50/* NOTE: All these are settings for Broadcom chipset */
51static char modparam_country[4] = "EU";
52module_param_string(country, modparam_country, 4, 0444);
53MODULE_PARM_DESC(country, "Country code (ISO 3166-1 alpha-2), default: EU");
54
55static int modparam_frameburst = 1;
56module_param_named(frameburst, modparam_frameburst, int, 0444);
57MODULE_PARM_DESC(frameburst, "enable frame bursting (default: on)");
58
59static int modparam_afterburner = 0;
60module_param_named(afterburner, modparam_afterburner, int, 0444);
61MODULE_PARM_DESC(afterburner,
62 "enable afterburner aka '125 High Speed Mode' (default: off)");
63
64static int modparam_power_save = 0;
65module_param_named(power_save, modparam_power_save, int, 0444);
66MODULE_PARM_DESC(power_save,
67 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
68
69static int modparam_power_output = 3;
70module_param_named(power_output, modparam_power_output, int, 0444);
71MODULE_PARM_DESC(power_output,
72 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
73
74static int modparam_roamtrigger = -70;
75module_param_named(roamtrigger, modparam_roamtrigger, int, 0444);
76MODULE_PARM_DESC(roamtrigger,
77 "set roaming dBm trigger: -80=optimize for distance, "
78 "-60=bandwidth (default: -70)");
79
80static int modparam_roamdelta = 1;
81module_param_named(roamdelta, modparam_roamdelta, int, 0444);
82MODULE_PARM_DESC(roamdelta,
83 "set roaming tendency: 0=aggressive, 1=moderate, "
84 "2=conservative (default: moderate)");
85
86static int modparam_workaround_interval = 500;
87module_param_named(workaround_interval, modparam_workaround_interval,
88 int, 0444);
89MODULE_PARM_DESC(workaround_interval,
90 "set stall workaround interval in msecs (default: 500)");
91
92
93/* various RNDIS OID defs */
Harvey Harrison35c26c22009-02-14 22:56:56 -080094#define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
95#define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +020096
Harvey Harrison35c26c22009-02-14 22:56:56 -080097#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)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200102
Harvey Harrison35c26c22009-02-14 22:56:56 -0800103#define OID_802_3_PERMANENT_ADDRESS cpu_to_le32(0x01010101)
104#define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
105#define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
106#define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200107
Harvey Harrison35c26c22009-02-14 22:56:56 -0800108#define OID_802_11_BSSID cpu_to_le32(0x0d010101)
109#define OID_802_11_SSID cpu_to_le32(0x0d010102)
110#define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
111#define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
112#define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
113#define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
114#define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
115#define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
116#define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
117#define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
118#define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
119#define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
120#define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
121#define OID_802_11_PMKID cpu_to_le32(0x0d010123)
122#define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
123#define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
124#define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
125#define OID_802_11_RSSI cpu_to_le32(0x0d010206)
126#define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
127#define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
128#define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
129#define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
130#define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
131#define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200132
133
134/* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
135#define WL_NOISE -96 /* typical noise level in dBm */
136#define WL_SIGMAX -32 /* typical maximum signal level in dBm */
137
138
139/* Assume that Broadcom 4320 (only chipset at time of writing known to be
140 * based on wireless rndis) has default txpower of 13dBm.
141 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300142 * 100% : 20 mW ~ 13dBm
143 * 75% : 15 mW ~ 12dBm
144 * 50% : 10 mW ~ 10dBm
145 * 25% : 5 mW ~ 7dBm
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200146 */
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300147#define BCM4320_DEFAULT_TXPOWER_DBM_100 13
148#define BCM4320_DEFAULT_TXPOWER_DBM_75 12
149#define BCM4320_DEFAULT_TXPOWER_DBM_50 10
150#define BCM4320_DEFAULT_TXPOWER_DBM_25 7
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200151
152
153/* codes for "status" field of completion messages */
Harvey Harrison35c26c22009-02-14 22:56:56 -0800154#define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
155#define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200156
157
158/* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
159 * slightly modified for datatype endianess, etc
160 */
161#define NDIS_802_11_LENGTH_SSID 32
162#define NDIS_802_11_LENGTH_RATES 8
163#define NDIS_802_11_LENGTH_RATES_EX 16
164
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200165enum ndis_80211_net_type {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300166 NDIS_80211_TYPE_FREQ_HOP,
167 NDIS_80211_TYPE_DIRECT_SEQ,
168 NDIS_80211_TYPE_OFDM_A,
169 NDIS_80211_TYPE_OFDM_G
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200170};
171
172enum ndis_80211_net_infra {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300173 NDIS_80211_INFRA_ADHOC,
174 NDIS_80211_INFRA_INFRA,
175 NDIS_80211_INFRA_AUTO_UNKNOWN
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200176};
177
178enum ndis_80211_auth_mode {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300179 NDIS_80211_AUTH_OPEN,
180 NDIS_80211_AUTH_SHARED,
181 NDIS_80211_AUTH_AUTO_SWITCH,
182 NDIS_80211_AUTH_WPA,
183 NDIS_80211_AUTH_WPA_PSK,
184 NDIS_80211_AUTH_WPA_NONE,
185 NDIS_80211_AUTH_WPA2,
186 NDIS_80211_AUTH_WPA2_PSK
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200187};
188
189enum ndis_80211_encr_status {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300190 NDIS_80211_ENCR_WEP_ENABLED,
191 NDIS_80211_ENCR_DISABLED,
192 NDIS_80211_ENCR_WEP_KEY_ABSENT,
193 NDIS_80211_ENCR_NOT_SUPPORTED,
194 NDIS_80211_ENCR_TKIP_ENABLED,
195 NDIS_80211_ENCR_TKIP_KEY_ABSENT,
196 NDIS_80211_ENCR_CCMP_ENABLED,
197 NDIS_80211_ENCR_CCMP_KEY_ABSENT
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200198};
199
200enum ndis_80211_priv_filter {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300201 NDIS_80211_PRIV_ACCEPT_ALL,
202 NDIS_80211_PRIV_8021X_WEP
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200203};
204
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300205enum ndis_80211_addkey_bits {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300206 NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
207 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
208 NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
209 NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300210};
211
212enum ndis_80211_addwep_bits {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300213 NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
214 NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300215};
216
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200217struct ndis_80211_ssid {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200218 __le32 length;
219 u8 essid[NDIS_802_11_LENGTH_SSID];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200220} __attribute__((packed));
221
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200222struct ndis_80211_conf_freq_hop {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200223 __le32 length;
224 __le32 hop_pattern;
225 __le32 hop_set;
226 __le32 dwell_time;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200227} __attribute__((packed));
228
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200229struct ndis_80211_conf {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200230 __le32 length;
231 __le32 beacon_period;
232 __le32 atim_window;
233 __le32 ds_config;
234 struct ndis_80211_conf_freq_hop fh_config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200235} __attribute__((packed));
236
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200237struct ndis_80211_bssid_ex {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200238 __le32 length;
239 u8 mac[6];
240 u8 padding[2];
241 struct ndis_80211_ssid ssid;
242 __le32 privacy;
243 __le32 rssi;
244 __le32 net_type;
245 struct ndis_80211_conf config;
246 __le32 net_infra;
247 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
248 __le32 ie_length;
249 u8 ies[0];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200250} __attribute__((packed));
251
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200252struct ndis_80211_bssid_list_ex {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200253 __le32 num_items;
254 struct ndis_80211_bssid_ex bssid[0];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200255} __attribute__((packed));
256
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200257struct ndis_80211_fixed_ies {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200258 u8 timestamp[8];
259 __le16 beacon_interval;
260 __le16 capabilities;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200261} __attribute__((packed));
262
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200263struct ndis_80211_wep_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200264 __le32 size;
265 __le32 index;
266 __le32 length;
267 u8 material[32];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200268} __attribute__((packed));
269
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200270struct ndis_80211_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200271 __le32 size;
272 __le32 index;
273 __le32 length;
274 u8 bssid[6];
275 u8 padding[6];
276 u8 rsc[8];
277 u8 material[32];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200278} __attribute__((packed));
279
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200280struct ndis_80211_remove_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200281 __le32 size;
282 __le32 index;
283 u8 bssid[6];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200284} __attribute__((packed));
285
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200286struct ndis_config_param {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200287 __le32 name_offs;
288 __le32 name_length;
289 __le32 type;
290 __le32 value_offs;
291 __le32 value_length;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200292} __attribute__((packed));
293
Scott Ashcroft43646232008-05-27 00:06:15 +0300294struct ndis_80211_assoc_info {
295 __le32 length;
296 __le16 req_ies;
297 struct req_ie {
298 __le16 capa;
299 __le16 listen_interval;
300 u8 cur_ap_address[6];
301 } req_ie;
302 __le32 req_ie_length;
303 __le32 offset_req_ies;
304 __le16 resp_ies;
305 struct resp_ie {
306 __le16 capa;
307 __le16 status_code;
308 __le16 assoc_id;
309 } resp_ie;
310 __le32 resp_ie_length;
311 __le32 offset_resp_ies;
312} __attribute__((packed));
313
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200314/* these have to match what is in wpa_supplicant */
Johannes Berg5b0acc62008-02-20 11:47:45 +0100315enum wpa_alg { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP };
316enum wpa_cipher { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
317 CIPHER_WEP104 };
318enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
319 KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE };
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200320
321/*
322 * private data
323 */
324#define NET_TYPE_11FB 0
325
326#define CAP_MODE_80211A 1
327#define CAP_MODE_80211B 2
328#define CAP_MODE_80211G 4
329#define CAP_MODE_MASK 7
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200330
Jussi Kivilinna6010ce02008-06-02 18:35:21 +0300331#define WORK_LINK_UP (1<<0)
332#define WORK_LINK_DOWN (1<<1)
333#define WORK_SET_MULTICAST_LIST (1<<2)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200334
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300335#define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
336
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200337static const struct ieee80211_channel rndis_channels[] = {
338 { .center_freq = 2412 },
339 { .center_freq = 2417 },
340 { .center_freq = 2422 },
341 { .center_freq = 2427 },
342 { .center_freq = 2432 },
343 { .center_freq = 2437 },
344 { .center_freq = 2442 },
345 { .center_freq = 2447 },
346 { .center_freq = 2452 },
347 { .center_freq = 2457 },
348 { .center_freq = 2462 },
349 { .center_freq = 2467 },
350 { .center_freq = 2472 },
351 { .center_freq = 2484 },
352};
353
354static const struct ieee80211_rate rndis_rates[] = {
355 { .bitrate = 10 },
356 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
357 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
358 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
359 { .bitrate = 60 },
360 { .bitrate = 90 },
361 { .bitrate = 120 },
362 { .bitrate = 180 },
363 { .bitrate = 240 },
364 { .bitrate = 360 },
365 { .bitrate = 480 },
366 { .bitrate = 540 }
367};
368
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200369/* RNDIS device private data */
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300370struct rndis_wlan_private {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200371 struct usbnet *usbdev;
372
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200373 struct wireless_dev wdev;
374
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200375 struct cfg80211_scan_request *scan_request;
376
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200377 struct workqueue_struct *workqueue;
378 struct delayed_work stats_work;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200379 struct delayed_work scan_work;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200380 struct work_struct work;
381 struct mutex command_lock;
382 spinlock_t stats_lock;
383 unsigned long work_pending;
384
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200385 struct ieee80211_supported_band band;
386 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
387 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
388
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200389 struct iw_statistics iwstats;
390 struct iw_statistics privstats;
391
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200392 int caps;
393 int multicast_size;
394
395 /* module parameters */
396 char param_country[4];
397 int param_frameburst;
398 int param_afterburner;
399 int param_power_save;
400 int param_power_output;
401 int param_roamtrigger;
402 int param_roamdelta;
403 u32 param_workaround_interval;
404
405 /* hardware state */
406 int radio_on;
407 int infra_mode;
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200408 struct ndis_80211_ssid essid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200409
410 /* encryption stuff */
411 int encr_tx_key_index;
412 char encr_keys[4][32];
413 int encr_key_len[4];
Jussi Kivilinna98391782009-05-22 17:40:34 +0300414 char encr_key_wpa[4];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200415 int wpa_version;
416 int wpa_keymgmt;
417 int wpa_authalg;
418 int wpa_ie_len;
419 u8 *wpa_ie;
420 int wpa_cipher_pair;
421 int wpa_cipher_group;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300422
423 u8 command_buffer[COMMAND_BUFFER_SIZE];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200424};
425
John W. Linville964c1d42009-03-26 23:40:01 +0200426/*
427 * cfg80211 ops
428 */
Johannes Berge36d56b2009-06-09 21:04:43 +0200429static int rndis_change_virtual_intf(struct wiphy *wiphy,
430 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +0200431 enum nl80211_iftype type, u32 *flags,
432 struct vif_params *params);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200433
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200434static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
435 struct cfg80211_scan_request *request);
436
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +0300437static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
438
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300439static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
440 int dbm);
441static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
442
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200443static struct cfg80211_ops rndis_config_ops = {
John W. Linville964c1d42009-03-26 23:40:01 +0200444 .change_virtual_intf = rndis_change_virtual_intf,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200445 .scan = rndis_scan,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +0300446 .set_wiphy_params = rndis_set_wiphy_params,
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300447 .set_tx_power = rndis_set_tx_power,
448 .get_tx_power = rndis_get_tx_power,
John W. Linville964c1d42009-03-26 23:40:01 +0200449};
450
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200451static void *rndis_wiphy_privid = &rndis_wiphy_privid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200452
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200453
454static const unsigned char zero_bssid[ETH_ALEN] = {0,};
455static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff,
456 0xff, 0xff, 0xff };
457
458
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300459static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200460{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300461 return (struct rndis_wlan_private *)dev->driver_priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200462}
463
464
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300465static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200466{
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300467 switch (priv->param_power_output) {
468 default:
469 case 3:
470 return BCM4320_DEFAULT_TXPOWER_DBM_100;
471 case 2:
472 return BCM4320_DEFAULT_TXPOWER_DBM_75;
473 case 1:
474 return BCM4320_DEFAULT_TXPOWER_DBM_50;
475 case 0:
476 return BCM4320_DEFAULT_TXPOWER_DBM_25;
477 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200478}
479
480
481/* translate error code */
482static int rndis_error_status(__le32 rndis_status)
483{
484 int ret = -EINVAL;
485 switch (rndis_status) {
486 case RNDIS_STATUS_SUCCESS:
487 ret = 0;
488 break;
489 case RNDIS_STATUS_FAILURE:
490 case RNDIS_STATUS_INVALID_DATA:
491 ret = -EINVAL;
492 break;
493 case RNDIS_STATUS_NOT_SUPPORTED:
494 ret = -EOPNOTSUPP;
495 break;
496 case RNDIS_STATUS_ADAPTER_NOT_READY:
497 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
498 ret = -EBUSY;
499 break;
500 }
501 return ret;
502}
503
504
505static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
506{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300507 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200508 union {
509 void *buf;
510 struct rndis_msg_hdr *header;
511 struct rndis_query *get;
512 struct rndis_query_c *get_c;
513 } u;
514 int ret, buflen;
515
516 buflen = *len + sizeof(*u.get);
517 if (buflen < CONTROL_BUFFER_SIZE)
518 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300519
520 if (buflen > COMMAND_BUFFER_SIZE) {
521 u.buf = kmalloc(buflen, GFP_KERNEL);
522 if (!u.buf)
523 return -ENOMEM;
524 } else {
525 u.buf = priv->command_buffer;
526 }
527
528 mutex_lock(&priv->command_lock);
529
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200530 memset(u.get, 0, sizeof *u.get);
531 u.get->msg_type = RNDIS_MSG_QUERY;
Harvey Harrison35c26c22009-02-14 22:56:56 -0800532 u.get->msg_len = cpu_to_le32(sizeof *u.get);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200533 u.get->oid = oid;
534
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300535 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200536 if (ret == 0) {
537 ret = le32_to_cpu(u.get_c->len);
538 *len = (*len > ret) ? ret : *len;
539 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
540 ret = rndis_error_status(u.get_c->status);
541 }
542
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300543 mutex_unlock(&priv->command_lock);
544
545 if (u.buf != priv->command_buffer)
546 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200547 return ret;
548}
549
550
551static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
552{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300553 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200554 union {
555 void *buf;
556 struct rndis_msg_hdr *header;
557 struct rndis_set *set;
558 struct rndis_set_c *set_c;
559 } u;
560 int ret, buflen;
561
562 buflen = len + sizeof(*u.set);
563 if (buflen < CONTROL_BUFFER_SIZE)
564 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300565
566 if (buflen > COMMAND_BUFFER_SIZE) {
567 u.buf = kmalloc(buflen, GFP_KERNEL);
568 if (!u.buf)
569 return -ENOMEM;
570 } else {
571 u.buf = priv->command_buffer;
572 }
573
574 mutex_lock(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200575
576 memset(u.set, 0, sizeof *u.set);
577 u.set->msg_type = RNDIS_MSG_SET;
578 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
579 u.set->oid = oid;
580 u.set->len = cpu_to_le32(len);
Harvey Harrison35c26c22009-02-14 22:56:56 -0800581 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
582 u.set->handle = cpu_to_le32(0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200583 memcpy(u.buf + sizeof(*u.set), data, len);
584
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300585 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200586 if (ret == 0)
587 ret = rndis_error_status(u.set_c->status);
588
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300589 mutex_unlock(&priv->command_lock);
590
591 if (u.buf != priv->command_buffer)
592 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200593 return ret;
594}
595
596
597/*
598 * Specs say that we can only set config parameters only soon after device
599 * initialization.
600 * value_type: 0 = u32, 2 = unicode string
601 */
602static int rndis_set_config_parameter(struct usbnet *dev, char *param,
603 int value_type, void *value)
604{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200605 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200606 int value_len, info_len, param_len, ret, i;
607 __le16 *unibuf;
608 __le32 *dst_value;
609
610 if (value_type == 0)
611 value_len = sizeof(__le32);
612 else if (value_type == 2)
613 value_len = strlen(value) * sizeof(__le16);
614 else
615 return -EINVAL;
616
617 param_len = strlen(param) * sizeof(__le16);
618 info_len = sizeof(*infobuf) + param_len + value_len;
619
620#ifdef DEBUG
621 info_len += 12;
622#endif
623 infobuf = kmalloc(info_len, GFP_KERNEL);
624 if (!infobuf)
625 return -ENOMEM;
626
627#ifdef DEBUG
628 info_len -= 12;
629 /* extra 12 bytes are for padding (debug output) */
630 memset(infobuf, 0xCC, info_len + 12);
631#endif
632
633 if (value_type == 2)
634 devdbg(dev, "setting config parameter: %s, value: %s",
635 param, (u8 *)value);
636 else
637 devdbg(dev, "setting config parameter: %s, value: %d",
638 param, *(u32 *)value);
639
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200640 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
641 infobuf->name_length = cpu_to_le32(param_len);
642 infobuf->type = cpu_to_le32(value_type);
643 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
644 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200645
646 /* simple string to unicode string conversion */
647 unibuf = (void *)infobuf + sizeof(*infobuf);
648 for (i = 0; i < param_len / sizeof(__le16); i++)
649 unibuf[i] = cpu_to_le16(param[i]);
650
651 if (value_type == 2) {
652 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
653 for (i = 0; i < value_len / sizeof(__le16); i++)
654 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
655 } else {
656 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
657 *dst_value = cpu_to_le32(*(u32 *)value);
658 }
659
660#ifdef DEBUG
661 devdbg(dev, "info buffer (len: %d):", info_len);
662 for (i = 0; i < info_len; i += 12) {
663 u32 *tmp = (u32 *)((u8 *)infobuf + i);
664 devdbg(dev, "%08X:%08X:%08X",
665 cpu_to_be32(tmp[0]),
666 cpu_to_be32(tmp[1]),
667 cpu_to_be32(tmp[2]));
668 }
669#endif
670
671 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
672 infobuf, info_len);
673 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200674 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200675
676 kfree(infobuf);
677 return ret;
678}
679
680static int rndis_set_config_parameter_str(struct usbnet *dev,
681 char *param, char *value)
682{
683 return(rndis_set_config_parameter(dev, param, 2, value));
684}
685
686/*static int rndis_set_config_parameter_u32(struct usbnet *dev,
687 char *param, u32 value)
688{
689 return(rndis_set_config_parameter(dev, param, 0, &value));
690}*/
691
692
693/*
694 * data conversion functions
695 */
696static int level_to_qual(int level)
697{
698 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
699 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
700}
701
702
703static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
704{
705 freq->e = 0;
706 freq->i = 0;
707 freq->flags = 0;
708
709 /* see comment in wireless.h above the "struct iw_freq"
710 * definition for an explanation of this if
711 * NOTE: 1000000 is due to the kHz
712 */
713 if (dsconfig > 1000000) {
714 freq->m = dsconfig / 10;
715 freq->e = 1;
716 } else
717 freq->m = dsconfig;
718
719 /* convert from kHz to Hz */
720 freq->e += 3;
721}
722
723
724static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
725{
726 if (freq->m < 1000 && freq->e == 0) {
David Kilroy9ee677c2008-12-23 14:03:38 +0000727 if (freq->m >= 1 && freq->m <= 14)
728 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200729 else
730 return -1;
731 } else {
732 int i;
733 *dsconfig = freq->m;
734 for (i = freq->e; i > 0; i--)
735 *dsconfig *= 10;
736 *dsconfig /= 1000;
737 }
738
739 return 0;
740}
741
742
743/*
744 * common functions
745 */
746static int
747add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index);
748
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200749static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200750{
751 int ret, len;
752
753 len = sizeof(*ssid);
754 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
755
756 if (ret != 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200757 ssid->length = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200758
759#ifdef DEBUG
760 {
761 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
762
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200763 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
764 tmp[le32_to_cpu(ssid->length)] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200765 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
766 }
767#endif
768 return ret;
769}
770
771
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200772static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200773{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300774 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200775 int ret;
776
777 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
778 if (ret == 0) {
779 memcpy(&priv->essid, ssid, sizeof(priv->essid));
780 priv->radio_on = 1;
781 devdbg(usbdev, "set_essid: radio_on = 1");
782 }
783
784 return ret;
785}
786
787
788static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
789{
790 int ret, len;
791
792 len = ETH_ALEN;
793 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
794
795 if (ret != 0)
796 memset(bssid, 0, ETH_ALEN);
797
798 return ret;
799}
800
Scott Ashcroft43646232008-05-27 00:06:15 +0300801static int get_association_info(struct usbnet *usbdev,
802 struct ndis_80211_assoc_info *info, int len)
803{
804 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
805 info, &len);
806}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200807
808static int is_associated(struct usbnet *usbdev)
809{
810 u8 bssid[ETH_ALEN];
811 int ret;
812
813 ret = get_bssid(usbdev, bssid);
814
815 return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0);
816}
817
818
819static int disassociate(struct usbnet *usbdev, int reset_ssid)
820{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300821 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200822 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200823 int i, ret = 0;
824
825 if (priv->radio_on) {
826 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
827 if (ret == 0) {
828 priv->radio_on = 0;
829 devdbg(usbdev, "disassociate: radio_on = 0");
830
831 if (reset_ssid)
832 msleep(100);
833 }
834 }
835
836 /* disassociate causes radio to be turned off; if reset_ssid
837 * is given, set random ssid to enable radio */
838 if (reset_ssid) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200839 ssid.length = cpu_to_le32(sizeof(ssid.essid));
840 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
841 ssid.essid[0] = 0x1;
842 ssid.essid[1] = 0xff;
843 for (i = 2; i < sizeof(ssid.essid); i++)
844 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200845 ret = set_essid(usbdev, &ssid);
846 }
847 return ret;
848}
849
850
851static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
852{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300853 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200854 __le32 tmp;
855 int auth_mode, ret;
856
857 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
858 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
859
860 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
861 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300862 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200863 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300864 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200865 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
866 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300867 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200868 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300869 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200870 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300871 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200872 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
873 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300874 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200875 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300876 auth_mode = NDIS_80211_AUTH_SHARED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200877 } else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300878 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200879
880 tmp = cpu_to_le32(auth_mode);
881 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
882 sizeof(tmp));
883 if (ret != 0) {
884 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
885 return ret;
886 }
887
888 priv->wpa_version = wpa_version;
889 priv->wpa_authalg = authalg;
890 return 0;
891}
892
893
894static int set_priv_filter(struct usbnet *usbdev)
895{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300896 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200897 __le32 tmp;
898
899 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
900
901 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
902 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300903 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200904 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300905 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200906
907 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
908 sizeof(tmp));
909}
910
911
912static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
913{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300914 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200915 __le32 tmp;
916 int encr_mode, ret;
917
918 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
919 pairwise,
920 groupwise);
921
922 if (pairwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300923 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200924 else if (pairwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300925 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200926 else if (pairwise &
927 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300928 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200929 else if (groupwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300930 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200931 else if (groupwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300932 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200933 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300934 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200935
936 tmp = cpu_to_le32(encr_mode);
937 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
938 sizeof(tmp));
939 if (ret != 0) {
940 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
941 return ret;
942 }
943
944 priv->wpa_cipher_pair = pairwise;
945 priv->wpa_cipher_group = groupwise;
946 return 0;
947}
948
949
950static int set_assoc_params(struct usbnet *usbdev)
951{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300952 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200953
954 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
955 set_priv_filter(usbdev);
956 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
957
958 return 0;
959}
960
961
962static int set_infra_mode(struct usbnet *usbdev, int mode)
963{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300964 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200965 __le32 tmp;
966 int ret, i;
967
968 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
969
970 tmp = cpu_to_le32(mode);
971 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
972 sizeof(tmp));
973 if (ret != 0) {
974 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
975 return ret;
976 }
977
978 /* NDIS drivers clear keys when infrastructure mode is
979 * changed. But Linux tools assume otherwise. So set the
980 * keys */
981 if (priv->wpa_keymgmt == 0 ||
982 priv->wpa_keymgmt == IW_AUTH_KEY_MGMT_802_1X) {
983 for (i = 0; i < 4; i++) {
Jussi Kivilinna98391782009-05-22 17:40:34 +0300984 if (priv->encr_key_len[i] > 0 && !priv->encr_key_wpa[i])
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200985 add_wep_key(usbdev, priv->encr_keys[i],
986 priv->encr_key_len[i], i);
987 }
988 }
989
990 priv->infra_mode = mode;
991 return 0;
992}
993
994
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +0300995static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
996{
997 __le32 tmp;
998
999 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1000
1001 if (rts_threshold < 0 || rts_threshold > 2347)
1002 rts_threshold = 2347;
1003
1004 tmp = cpu_to_le32(rts_threshold);
1005 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1006 sizeof(tmp));
1007}
1008
1009
1010static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1011{
1012 __le32 tmp;
1013
1014 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1015
1016 if (frag_threshold < 256 || frag_threshold > 2346)
1017 frag_threshold = 2346;
1018
1019 tmp = cpu_to_le32(frag_threshold);
1020 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1021 sizeof(tmp));
1022}
1023
1024
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001025static void set_default_iw_params(struct usbnet *usbdev)
1026{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001027 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001028
1029 priv->wpa_keymgmt = 0;
1030 priv->wpa_version = 0;
1031
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001032 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001033 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1034 IW_AUTH_ALG_OPEN_SYSTEM);
1035 set_priv_filter(usbdev);
1036 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1037}
1038
1039
1040static int deauthenticate(struct usbnet *usbdev)
1041{
1042 int ret;
1043
1044 ret = disassociate(usbdev, 1);
1045 set_default_iw_params(usbdev);
1046 return ret;
1047}
1048
1049
1050/* index must be 0 - N, as per NDIS */
1051static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
1052{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001053 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001054 struct ndis_80211_wep_key ndis_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001055 int ret;
1056
1057 if (key_len <= 0 || key_len > 32 || index < 0 || index >= 4)
1058 return -EINVAL;
1059
1060 memset(&ndis_key, 0, sizeof(ndis_key));
1061
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001062 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1063 ndis_key.length = cpu_to_le32(key_len);
1064 ndis_key.index = cpu_to_le32(index);
1065 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001066
1067 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001068 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001069 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1070 IW_AUTH_CIPHER_NONE);
1071 if (ret)
1072 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1073 ret);
1074 }
1075
1076 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1077 sizeof(ndis_key));
1078 if (ret != 0) {
1079 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1080 index+1, ret);
1081 return ret;
1082 }
1083
1084 priv->encr_key_len[index] = key_len;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001085 priv->encr_key_wpa[index] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001086 memcpy(&priv->encr_keys[index], key, key_len);
1087
1088 return 0;
1089}
1090
1091
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001092static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
1093 int index, const struct sockaddr *addr,
1094 const u8 *rx_seq, int alg, int flags)
1095{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001096 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001097 struct ndis_80211_key ndis_key;
1098 int ret;
1099
1100 if (index < 0 || index >= 4)
1101 return -EINVAL;
1102 if (key_len > sizeof(ndis_key.material) || key_len < 0)
1103 return -EINVAL;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001104 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001105 return -EINVAL;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001106 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !addr)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001107 return -EINVAL;
1108
1109 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001110 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1111 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1112 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001113
1114 memset(&ndis_key, 0, sizeof(ndis_key));
1115
1116 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1117 sizeof(ndis_key.material) + key_len);
1118 ndis_key.length = cpu_to_le32(key_len);
1119 ndis_key.index = cpu_to_le32(index) | flags;
1120
1121 if (alg == IW_ENCODE_ALG_TKIP && key_len == 32) {
1122 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1123 * different order than NDIS spec, so swap the order here. */
1124 memcpy(ndis_key.material, key, 16);
1125 memcpy(ndis_key.material + 16, key + 24, 8);
1126 memcpy(ndis_key.material + 24, key + 16, 8);
1127 } else
1128 memcpy(ndis_key.material, key, key_len);
1129
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001130 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001131 memcpy(ndis_key.rsc, rx_seq, 6);
1132
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001133 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001134 /* pairwise key */
1135 memcpy(ndis_key.bssid, addr->sa_data, ETH_ALEN);
1136 } else {
1137 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001138 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001139 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1140 else
1141 get_bssid(usbdev, ndis_key.bssid);
1142 }
1143
1144 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1145 le32_to_cpu(ndis_key.size));
1146 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1147 if (ret != 0)
1148 return ret;
1149
1150 priv->encr_key_len[index] = key_len;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001151 priv->encr_key_wpa[index] = 1;
1152
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001153 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001154 priv->encr_tx_key_index = index;
1155
1156 return 0;
1157}
1158
1159
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001160/* remove_key is for both wep and wpa */
1161static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1162{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001163 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001164 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001165 __le32 keyindex;
1166 int ret;
1167
1168 if (priv->encr_key_len[index] == 0)
1169 return 0;
1170
1171 priv->encr_key_len[index] = 0;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001172 priv->encr_key_wpa[index] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001173 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1174
1175 if (priv->wpa_cipher_pair == IW_AUTH_CIPHER_TKIP ||
1176 priv->wpa_cipher_pair == IW_AUTH_CIPHER_CCMP ||
1177 priv->wpa_cipher_group == IW_AUTH_CIPHER_TKIP ||
1178 priv->wpa_cipher_group == IW_AUTH_CIPHER_CCMP) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001179 remove_key.size = cpu_to_le32(sizeof(remove_key));
1180 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001181 if (bssid) {
1182 /* pairwise key */
1183 if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001184 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001185 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001186 memcpy(remove_key.bssid, bssid,
1187 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001188 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001189 memset(remove_key.bssid, 0xff,
1190 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001191
1192 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1193 sizeof(remove_key));
1194 if (ret != 0)
1195 return ret;
1196 } else {
1197 keyindex = cpu_to_le32(index);
1198 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1199 sizeof(keyindex));
1200 if (ret != 0) {
1201 devwarn(usbdev,
1202 "removing encryption key %d failed (%08X)",
1203 index, ret);
1204 return ret;
1205 }
1206 }
1207
1208 /* if it is transmit key, disable encryption */
1209 if (index == priv->encr_tx_key_index)
1210 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1211
1212 return 0;
1213}
1214
1215
1216static void set_multicast_list(struct usbnet *usbdev)
1217{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001218 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001219 struct dev_mc_list *mclist;
1220 __le32 filter;
1221 int ret, i, size;
1222 char *buf;
1223
1224 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1225
1226 if (usbdev->net->flags & IFF_PROMISC) {
1227 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1228 RNDIS_PACKET_TYPE_ALL_LOCAL;
1229 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1230 usbdev->net->mc_count > priv->multicast_size) {
1231 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1232 } else if (usbdev->net->mc_count > 0) {
1233 size = min(priv->multicast_size, usbdev->net->mc_count);
1234 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1235 if (!buf) {
1236 devwarn(usbdev,
1237 "couldn't alloc %d bytes of memory",
1238 size * ETH_ALEN);
1239 return;
1240 }
1241
1242 mclist = usbdev->net->mc_list;
1243 for (i = 0; i < size && mclist; mclist = mclist->next) {
1244 if (mclist->dmi_addrlen != ETH_ALEN)
1245 continue;
1246
1247 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1248 i++;
1249 }
1250
1251 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1252 i * ETH_ALEN);
1253 if (ret == 0 && i > 0)
1254 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1255 else
1256 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1257
1258 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1259 i, priv->multicast_size, ret);
1260
1261 kfree(buf);
1262 }
1263
1264 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1265 sizeof(filter));
1266 if (ret < 0) {
1267 devwarn(usbdev, "couldn't set packet filter: %08x",
1268 le32_to_cpu(filter));
1269 }
1270
1271 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1272 le32_to_cpu(filter), ret);
1273}
1274
1275
1276/*
John W. Linville964c1d42009-03-26 23:40:01 +02001277 * cfg80211 ops
1278 */
Johannes Berge36d56b2009-06-09 21:04:43 +02001279static int rndis_change_virtual_intf(struct wiphy *wiphy,
1280 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +02001281 enum nl80211_iftype type, u32 *flags,
1282 struct vif_params *params)
1283{
Johannes Berge36d56b2009-06-09 21:04:43 +02001284 struct usbnet *usbdev = netdev_priv(dev);
John W. Linville964c1d42009-03-26 23:40:01 +02001285 int mode;
1286
John W. Linville964c1d42009-03-26 23:40:01 +02001287 switch (type) {
1288 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001289 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001290 break;
1291 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001292 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001293 break;
1294 default:
1295 return -EINVAL;
1296 }
1297
1298 return set_infra_mode(usbdev, mode);
1299}
1300
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001301
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001302static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1303{
1304 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1305 struct usbnet *usbdev = priv->usbdev;
1306 int err;
1307
1308 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1309 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1310 if (err < 0)
1311 return err;
1312 }
1313
1314 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1315 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1316 if (err < 0)
1317 return err;
1318 }
1319
1320 return 0;
1321}
1322
1323
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001324static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1325 int dbm)
1326{
1327 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1328 struct usbnet *usbdev = priv->usbdev;
1329
1330 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1331
1332 /* Device doesn't support changing txpower after initialization, only
1333 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1334 * currently used.
1335 */
1336 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1337 if (!priv->radio_on)
1338 disassociate(usbdev, 1); /* turn on radio */
1339
1340 return 0;
1341 }
1342
1343 return -ENOTSUPP;
1344}
1345
1346
1347static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1348{
1349 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1350 struct usbnet *usbdev = priv->usbdev;
1351
1352 *dbm = get_bcm4320_power_dbm(priv);
1353
1354 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1355
1356 return 0;
1357}
1358
1359
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001360#define SCAN_DELAY_JIFFIES (HZ)
1361static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1362 struct cfg80211_scan_request *request)
1363{
1364 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001365 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001366 int ret;
1367 __le32 tmp;
1368
1369 devdbg(usbdev, "cfg80211.scan");
1370
1371 if (!request)
1372 return -EINVAL;
1373
1374 if (priv->scan_request && priv->scan_request != request)
1375 return -EBUSY;
1376
1377 priv->scan_request = request;
1378
1379 tmp = cpu_to_le32(1);
1380 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1381 sizeof(tmp));
1382 if (ret == 0) {
1383 /* Wait before retrieving scan results from device */
1384 queue_delayed_work(priv->workqueue, &priv->scan_work,
1385 SCAN_DELAY_JIFFIES);
1386 }
1387
1388 return ret;
1389}
1390
1391
1392static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1393 struct ndis_80211_bssid_ex *bssid)
1394{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001395 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001396 struct ieee80211_channel *channel;
1397 s32 signal;
1398 u64 timestamp;
1399 u16 capability;
1400 u16 beacon_interval;
1401 struct ndis_80211_fixed_ies *fixed;
1402 int ie_len, bssid_len;
1403 u8 *ie;
1404
1405 /* parse bssid structure */
1406 bssid_len = le32_to_cpu(bssid->length);
1407
1408 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1409 sizeof(struct ndis_80211_fixed_ies))
1410 return NULL;
1411
1412 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1413
1414 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1415 ie_len = min(bssid_len - (int)sizeof(*bssid),
1416 (int)le32_to_cpu(bssid->ie_length));
1417 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1418 if (ie_len < 0)
1419 return NULL;
1420
1421 /* extract data for cfg80211_inform_bss */
1422 channel = ieee80211_get_channel(priv->wdev.wiphy,
1423 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1424 if (!channel)
1425 return NULL;
1426
1427 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1428 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1429 capability = le16_to_cpu(fixed->capabilities);
1430 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1431
1432 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1433 timestamp, capability, beacon_interval, ie, ie_len, signal,
1434 GFP_KERNEL);
1435}
1436
1437
1438static int rndis_check_bssid_list(struct usbnet *usbdev)
1439{
1440 void *buf = NULL;
1441 struct ndis_80211_bssid_list_ex *bssid_list;
1442 struct ndis_80211_bssid_ex *bssid;
1443 int ret = -EINVAL, len, count, bssid_len;
1444
1445 devdbg(usbdev, "check_bssid_list");
1446
1447 len = CONTROL_BUFFER_SIZE;
1448 buf = kmalloc(len, GFP_KERNEL);
1449 if (!buf) {
1450 ret = -ENOMEM;
1451 goto out;
1452 }
1453
1454 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1455 if (ret != 0)
1456 goto out;
1457
1458 bssid_list = buf;
1459 bssid = bssid_list->bssid;
1460 bssid_len = le32_to_cpu(bssid->length);
1461 count = le32_to_cpu(bssid_list->num_items);
1462 devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count);
1463
1464 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1465 rndis_bss_info_update(usbdev, bssid);
1466
1467 bssid = (void *)bssid + bssid_len;
1468 bssid_len = le32_to_cpu(bssid->length);
1469 count--;
1470 }
1471
1472out:
1473 kfree(buf);
1474 return ret;
1475}
1476
1477
1478static void rndis_get_scan_results(struct work_struct *work)
1479{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001480 struct rndis_wlan_private *priv =
1481 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001482 struct usbnet *usbdev = priv->usbdev;
1483 int ret;
1484
1485 devdbg(usbdev, "get_scan_results");
1486
1487 ret = rndis_check_bssid_list(usbdev);
1488
1489 cfg80211_scan_done(priv->scan_request, ret < 0);
1490
1491 priv->scan_request = NULL;
1492}
1493
1494
John W. Linville964c1d42009-03-26 23:40:01 +02001495/*
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001496 * wireless extension handlers
1497 */
1498
1499static int rndis_iw_commit(struct net_device *dev,
1500 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1501{
1502 /* dummy op */
1503 return 0;
1504}
1505
1506
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001507static int rndis_iw_set_essid(struct net_device *dev,
1508 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1509{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001510 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001511 int length = wrqu->essid.length;
Wang Chen524ad0a2008-11-12 23:39:10 -08001512 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001513
1514 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1515 wrqu->essid.flags, wrqu->essid.length, essid);
1516
1517 if (length > NDIS_802_11_LENGTH_SSID)
1518 length = NDIS_802_11_LENGTH_SSID;
1519
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001520 ssid.length = cpu_to_le32(length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001521 if (length > 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001522 memcpy(ssid.essid, essid, length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001523 else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001524 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001525
1526 set_assoc_params(usbdev);
1527
1528 if (!wrqu->essid.flags || length == 0)
1529 return disassociate(usbdev, 1);
1530 else
1531 return set_essid(usbdev, &ssid);
1532}
1533
1534
1535static int rndis_iw_get_essid(struct net_device *dev,
1536 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1537{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001538 struct ndis_80211_ssid ssid;
Wang Chen524ad0a2008-11-12 23:39:10 -08001539 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001540 int ret;
1541
1542 ret = get_essid(usbdev, &ssid);
1543
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001544 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001545 wrqu->essid.flags = 1;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001546 wrqu->essid.length = le32_to_cpu(ssid.length);
1547 memcpy(essid, ssid.essid, wrqu->essid.length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001548 essid[wrqu->essid.length] = 0;
1549 } else {
1550 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1551 wrqu->essid.flags = 0;
1552 wrqu->essid.length = 0;
1553 }
1554 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1555 return ret;
1556}
1557
1558
1559static int rndis_iw_get_bssid(struct net_device *dev,
1560 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1561{
Wang Chen524ad0a2008-11-12 23:39:10 -08001562 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001563 unsigned char bssid[ETH_ALEN];
1564 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001565
1566 ret = get_bssid(usbdev, bssid);
1567
1568 if (ret == 0)
Johannes Berge1749612008-10-27 15:59:26 -07001569 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001570 else
1571 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1572
1573 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1574 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1575
1576 return ret;
1577}
1578
1579
1580static int rndis_iw_set_bssid(struct net_device *dev,
1581 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1582{
Wang Chen524ad0a2008-11-12 23:39:10 -08001583 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001584 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001585 int ret;
1586
Johannes Berge1749612008-10-27 15:59:26 -07001587 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001588
1589 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1590
1591 /* user apps may set ap's mac address, which is not required;
1592 * they may fail to work if this function fails, so return
1593 * success */
1594 if (ret)
1595 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1596
1597 return 0;
1598}
1599
1600
1601static int rndis_iw_set_auth(struct net_device *dev,
1602 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1603{
1604 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001605 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001606 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001607 int ret = -ENOTSUPP;
1608
1609 switch (p->flags & IW_AUTH_INDEX) {
1610 case IW_AUTH_WPA_VERSION:
1611 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1612 priv->wpa_version = p->value;
1613 ret = 0;
1614 break;
1615
1616 case IW_AUTH_CIPHER_PAIRWISE:
1617 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1618 priv->wpa_cipher_pair = p->value;
1619 ret = 0;
1620 break;
1621
1622 case IW_AUTH_CIPHER_GROUP:
1623 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1624 priv->wpa_cipher_group = p->value;
1625 ret = 0;
1626 break;
1627
1628 case IW_AUTH_KEY_MGMT:
1629 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1630 priv->wpa_keymgmt = p->value;
1631 ret = 0;
1632 break;
1633
1634 case IW_AUTH_TKIP_COUNTERMEASURES:
1635 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1636 p->value);
1637 ret = 0;
1638 break;
1639
1640 case IW_AUTH_DROP_UNENCRYPTED:
1641 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1642 ret = 0;
1643 break;
1644
1645 case IW_AUTH_80211_AUTH_ALG:
1646 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1647 priv->wpa_authalg = p->value;
1648 ret = 0;
1649 break;
1650
1651 case IW_AUTH_WPA_ENABLED:
1652 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1653 if (wrqu->param.value)
1654 deauthenticate(usbdev);
1655 ret = 0;
1656 break;
1657
1658 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1659 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1660 p->value);
1661 ret = 0;
1662 break;
1663
1664 case IW_AUTH_ROAMING_CONTROL:
1665 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1666 ret = 0;
1667 break;
1668
1669 case IW_AUTH_PRIVACY_INVOKED:
1670 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1671 wrqu->param.flags & IW_AUTH_INDEX);
1672 return -EOPNOTSUPP;
1673
1674 default:
1675 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1676 p->flags & IW_AUTH_INDEX, p->value);
1677 }
1678 return ret;
1679}
1680
1681
1682static int rndis_iw_get_auth(struct net_device *dev,
1683 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1684{
1685 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001686 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001687 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001688
1689 switch (p->flags & IW_AUTH_INDEX) {
1690 case IW_AUTH_WPA_VERSION:
1691 p->value = priv->wpa_version;
1692 break;
1693 case IW_AUTH_CIPHER_PAIRWISE:
1694 p->value = priv->wpa_cipher_pair;
1695 break;
1696 case IW_AUTH_CIPHER_GROUP:
1697 p->value = priv->wpa_cipher_group;
1698 break;
1699 case IW_AUTH_KEY_MGMT:
1700 p->value = priv->wpa_keymgmt;
1701 break;
1702 case IW_AUTH_80211_AUTH_ALG:
1703 p->value = priv->wpa_authalg;
1704 break;
1705 default:
1706 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1707 wrqu->param.flags & IW_AUTH_INDEX);
1708 return -EOPNOTSUPP;
1709 }
1710 return 0;
1711}
1712
1713
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001714static int rndis_iw_set_encode(struct net_device *dev,
1715 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1716{
Wang Chen524ad0a2008-11-12 23:39:10 -08001717 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001718 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001719 int ret, index, key_len;
1720 u8 *key;
1721
1722 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
1723
1724 /* iwconfig gives index as 1 - N */
1725 if (index > 0)
1726 index--;
1727 else
1728 index = priv->encr_tx_key_index;
1729
1730 if (index < 0 || index >= 4) {
1731 devwarn(usbdev, "encryption index out of range (%u)", index);
1732 return -EINVAL;
1733 }
1734
1735 /* remove key if disabled */
1736 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
1737 if (remove_key(usbdev, index, NULL))
1738 return -EINVAL;
1739 else
1740 return 0;
1741 }
1742
1743 /* global encryption state (for all keys) */
1744 if (wrqu->data.flags & IW_ENCODE_OPEN)
1745 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1746 IW_AUTH_ALG_OPEN_SYSTEM);
1747 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1748 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1749 IW_AUTH_ALG_SHARED_KEY);
1750 if (ret != 0)
1751 return ret;
1752
1753 if (wrqu->data.length > 0) {
1754 key_len = wrqu->data.length;
1755 key = extra;
1756 } else {
1757 /* must be set as tx key */
1758 if (priv->encr_key_len[index] == 0)
1759 return -EINVAL;
1760 key_len = priv->encr_key_len[index];
1761 key = priv->encr_keys[index];
1762 priv->encr_tx_key_index = index;
1763 }
1764
1765 if (add_wep_key(usbdev, key, key_len, index) != 0)
1766 return -EINVAL;
1767
1768 if (index == priv->encr_tx_key_index)
1769 /* ndis drivers want essid to be set after setting encr */
1770 set_essid(usbdev, &priv->essid);
1771
1772 return 0;
1773}
1774
1775
1776static int rndis_iw_set_encode_ext(struct net_device *dev,
1777 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1778{
1779 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
Wang Chen524ad0a2008-11-12 23:39:10 -08001780 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001781 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001782 int keyidx, flags;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001783
1784 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
1785
1786 /* iwconfig gives index as 1 - N */
1787 if (keyidx)
1788 keyidx--;
1789 else
1790 keyidx = priv->encr_tx_key_index;
1791
1792 if (keyidx < 0 || keyidx >= 4)
1793 return -EINVAL;
1794
1795 if (ext->alg == WPA_ALG_WEP) {
1796 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1797 priv->encr_tx_key_index = keyidx;
1798 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
1799 }
1800
1801 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
1802 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
1803 return remove_key(usbdev, keyidx, NULL);
1804
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001805 flags = 0;
1806 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001807 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001808 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001809 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001810 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001811 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001812
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001813 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx, &ext->addr,
1814 ext->rx_seq, ext->alg, flags);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001815}
1816
1817
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001818static int rndis_iw_set_genie(struct net_device *dev,
1819 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1820{
Wang Chen524ad0a2008-11-12 23:39:10 -08001821 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001822 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001823 int ret = 0;
1824
1825#ifdef DEBUG
1826 int j;
1827 u8 *gie = extra;
1828 for (j = 0; j < wrqu->data.length; j += 8)
1829 devdbg(usbdev,
1830 "SIOCSIWGENIE %04x - "
1831 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
1832 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
1833 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
1834#endif
1835 /* clear existing IEs */
1836 if (priv->wpa_ie_len) {
1837 kfree(priv->wpa_ie);
1838 priv->wpa_ie_len = 0;
1839 }
1840
1841 /* set new IEs */
1842 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
1843 if (priv->wpa_ie) {
1844 priv->wpa_ie_len = wrqu->data.length;
1845 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
1846 } else
1847 ret = -ENOMEM;
1848 return ret;
1849}
1850
1851
1852static int rndis_iw_get_genie(struct net_device *dev,
1853 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1854{
Wang Chen524ad0a2008-11-12 23:39:10 -08001855 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001856 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001857
1858 devdbg(usbdev, "SIOCGIWGENIE");
1859
1860 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
1861 wrqu->data.length = 0;
1862 return 0;
1863 }
1864
1865 if (wrqu->data.length < priv->wpa_ie_len)
1866 return -E2BIG;
1867
1868 wrqu->data.length = priv->wpa_ie_len;
1869 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
1870
1871 return 0;
1872}
1873
1874
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001875static int rndis_iw_set_freq(struct net_device *dev,
1876 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1877{
Wang Chen524ad0a2008-11-12 23:39:10 -08001878 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001879 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001880 unsigned int dsconfig;
1881 int len, ret;
1882
1883 /* this OID is valid only when not associated */
1884 if (is_associated(usbdev))
1885 return 0;
1886
1887 dsconfig = 0;
1888 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
1889 return -EINVAL;
1890
1891 len = sizeof(config);
1892 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1893 if (ret != 0) {
1894 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
1895 return 0;
1896 }
1897
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001898 config.ds_config = cpu_to_le32(dsconfig);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001899
1900 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
1901 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
1902 sizeof(config));
1903}
1904
1905
1906static int rndis_iw_get_freq(struct net_device *dev,
1907 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1908{
Wang Chen524ad0a2008-11-12 23:39:10 -08001909 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001910 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001911 int len, ret;
1912
1913 len = sizeof(config);
1914 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1915 if (ret == 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001916 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001917
1918 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
1919 return ret;
1920}
1921
1922
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001923static int rndis_iw_get_rate(struct net_device *dev,
1924 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1925{
Wang Chen524ad0a2008-11-12 23:39:10 -08001926 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001927 __le32 tmp;
1928 int ret, len;
1929
1930 len = sizeof(tmp);
1931 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
1932 if (ret == 0) {
1933 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
1934 wrqu->bitrate.disabled = 0;
1935 wrqu->bitrate.flags = 1;
1936 }
1937 return ret;
1938}
1939
1940
1941static int rndis_iw_set_mlme(struct net_device *dev,
1942 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1943{
Wang Chen524ad0a2008-11-12 23:39:10 -08001944 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001945 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001946 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1947 unsigned char bssid[ETH_ALEN];
1948
1949 get_bssid(usbdev, bssid);
1950
1951 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
1952 return -EINVAL;
1953
1954 switch (mlme->cmd) {
1955 case IW_MLME_DEAUTH:
1956 return deauthenticate(usbdev);
1957 case IW_MLME_DISASSOC:
1958 return disassociate(usbdev, priv->radio_on);
1959 default:
1960 return -EOPNOTSUPP;
1961 }
1962
1963 return 0;
1964}
1965
1966
1967static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
1968{
Wang Chen524ad0a2008-11-12 23:39:10 -08001969 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001970 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001971 unsigned long flags;
1972
1973 spin_lock_irqsave(&priv->stats_lock, flags);
1974 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
1975 spin_unlock_irqrestore(&priv->stats_lock, flags);
1976
1977 return &priv->iwstats;
1978}
1979
1980
1981#define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
1982static const iw_handler rndis_iw_handler[] =
1983{
1984 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
John W. Linville5c8fa4f2009-03-26 23:39:53 +02001985 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001986 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
1987 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
John W. Linville964c1d42009-03-26 23:40:01 +02001988 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
1989 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02001990 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001991 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
1992 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001993 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
1994 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001995 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
1996 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001997 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001998 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
1999 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2000 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2001 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002002 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2003 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002004 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2005 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2006 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2007 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2008 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2009 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2010 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2011};
2012
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002013static const iw_handler rndis_wlan_private_handler[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002014};
2015
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002016static const struct iw_priv_args rndis_wlan_private_args[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002017};
2018
2019
2020static const struct iw_handler_def rndis_iw_handlers = {
2021 .num_standard = ARRAY_SIZE(rndis_iw_handler),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002022 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2023 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002024 .standard = (iw_handler *)rndis_iw_handler,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002025 .private = (iw_handler *)rndis_wlan_private_handler,
2026 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002027 .get_wireless_stats = rndis_get_wireless_stats,
2028};
2029
2030
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002031static void rndis_wlan_worker(struct work_struct *work)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002032{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002033 struct rndis_wlan_private *priv =
2034 container_of(work, struct rndis_wlan_private, work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002035 struct usbnet *usbdev = priv->usbdev;
2036 union iwreq_data evt;
2037 unsigned char bssid[ETH_ALEN];
Scott Ashcroft43646232008-05-27 00:06:15 +03002038 struct ndis_80211_assoc_info *info;
2039 int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32;
2040 int ret, offset;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002041
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002042 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002043 netif_carrier_on(usbdev->net);
2044
Scott Ashcroft43646232008-05-27 00:06:15 +03002045 info = kzalloc(assoc_size, GFP_KERNEL);
2046 if (!info)
2047 goto get_bssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002048
Scott Ashcroft43646232008-05-27 00:06:15 +03002049 /* Get association info IEs from device and send them back to
2050 * userspace. */
2051 ret = get_association_info(usbdev, info, assoc_size);
2052 if (!ret) {
2053 evt.data.length = le32_to_cpu(info->req_ie_length);
2054 if (evt.data.length > 0) {
2055 offset = le32_to_cpu(info->offset_req_ies);
2056 wireless_send_event(usbdev->net,
2057 IWEVASSOCREQIE, &evt,
2058 (char *)info + offset);
2059 }
2060
2061 evt.data.length = le32_to_cpu(info->resp_ie_length);
2062 if (evt.data.length > 0) {
2063 offset = le32_to_cpu(info->offset_resp_ies);
2064 wireless_send_event(usbdev->net,
2065 IWEVASSOCRESPIE, &evt,
2066 (char *)info + offset);
2067 }
2068 }
2069
2070 kfree(info);
2071
2072get_bssid:
2073 ret = get_bssid(usbdev, bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002074 if (!ret) {
2075 evt.data.flags = 0;
2076 evt.data.length = 0;
2077 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
2078 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2079 }
2080 }
2081
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002082 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002083 netif_carrier_off(usbdev->net);
2084
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002085 evt.data.flags = 0;
2086 evt.data.length = 0;
2087 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2088 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2089 }
2090
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002091 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2092 set_multicast_list(usbdev);
2093}
2094
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002095static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002096{
Wang Chen524ad0a2008-11-12 23:39:10 -08002097 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002098 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002099
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002100 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2101 return;
2102
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002103 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2104 queue_work(priv->workqueue, &priv->work);
2105}
2106
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002107static void rndis_wlan_link_change(struct usbnet *usbdev, int state)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002108{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002109 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002110
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002111 /* queue work to avoid recursive calls into rndis_command */
2112 set_bit(state ? WORK_LINK_UP : WORK_LINK_DOWN, &priv->work_pending);
2113 queue_work(priv->workqueue, &priv->work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002114}
2115
2116
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002117static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002118{
2119 struct {
2120 __le32 num_items;
2121 __le32 items[8];
2122 } networks_supported;
2123 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002124 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002125
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002126 /* determine supported modes */
2127 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002128 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002129 &networks_supported, &len);
2130 if (retval >= 0) {
2131 n = le32_to_cpu(networks_supported.num_items);
2132 if (n > 8)
2133 n = 8;
2134 for (i = 0; i < n; i++) {
2135 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002136 case NDIS_80211_TYPE_FREQ_HOP:
2137 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002138 priv->caps |= CAP_MODE_80211B;
2139 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002140 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002141 priv->caps |= CAP_MODE_80211A;
2142 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002143 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002144 priv->caps |= CAP_MODE_80211G;
2145 break;
2146 }
2147 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002148 }
2149
2150 return retval;
2151}
2152
2153
2154#define STATS_UPDATE_JIFFIES (HZ)
2155static void rndis_update_wireless_stats(struct work_struct *work)
2156{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002157 struct rndis_wlan_private *priv =
2158 container_of(work, struct rndis_wlan_private, stats_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002159 struct usbnet *usbdev = priv->usbdev;
2160 struct iw_statistics iwstats;
2161 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002162 int len, ret, j;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002163 unsigned long flags;
2164 int update_jiffies = STATS_UPDATE_JIFFIES;
2165 void *buf;
2166
2167 spin_lock_irqsave(&priv->stats_lock, flags);
2168 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2169 spin_unlock_irqrestore(&priv->stats_lock, flags);
2170
2171 /* only update stats when connected */
2172 if (!is_associated(usbdev)) {
2173 iwstats.qual.qual = 0;
2174 iwstats.qual.level = 0;
2175 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2176 | IW_QUAL_LEVEL_UPDATED
2177 | IW_QUAL_NOISE_INVALID
2178 | IW_QUAL_QUAL_INVALID
2179 | IW_QUAL_LEVEL_INVALID;
2180 goto end;
2181 }
2182
2183 len = sizeof(rssi);
2184 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2185
2186 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2187 le32_to_cpu(rssi));
2188 if (ret == 0) {
2189 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2190 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinna4bd7f032009-03-26 23:40:16 +02002191 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002192 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2193 | IW_QUAL_LEVEL_UPDATED
2194 | IW_QUAL_NOISE_INVALID;
2195 }
2196
2197 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2198
2199 len = sizeof(tmp);
2200 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2201 if (ret == 0)
2202 iwstats.discard.misc += le32_to_cpu(tmp);
2203
2204 len = sizeof(tmp);
2205 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2206 if (ret == 0)
2207 iwstats.discard.misc += le32_to_cpu(tmp);
2208
2209 len = sizeof(tmp);
2210 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2211 if (ret == 0)
2212 iwstats.discard.misc += le32_to_cpu(tmp);
2213
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002214 /* Workaround transfer stalls on poor quality links.
2215 * TODO: find right way to fix these stalls (as stalls do not happen
2216 * with ndiswrapper/windows driver). */
2217 if (iwstats.qual.qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002218 /* Decrease stats worker interval to catch stalls.
2219 * faster. Faster than 400-500ms causes packet loss,
2220 * Slower doesn't catch stalls fast enough.
2221 */
2222 j = msecs_to_jiffies(priv->param_workaround_interval);
2223 if (j > STATS_UPDATE_JIFFIES)
2224 j = STATS_UPDATE_JIFFIES;
2225 else if (j <= 0)
2226 j = 1;
2227 update_jiffies = j;
2228
2229 /* Send scan OID. Use of both OIDs is required to get device
2230 * working.
2231 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08002232 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002233 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2234 sizeof(tmp));
2235
2236 len = CONTROL_BUFFER_SIZE;
2237 buf = kmalloc(len, GFP_KERNEL);
2238 if (!buf)
2239 goto end;
2240
2241 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2242 kfree(buf);
2243 }
2244end:
2245 spin_lock_irqsave(&priv->stats_lock, flags);
2246 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2247 spin_unlock_irqrestore(&priv->stats_lock, flags);
2248
2249 if (update_jiffies >= HZ)
2250 update_jiffies = round_jiffies_relative(update_jiffies);
2251 else {
2252 j = round_jiffies_relative(update_jiffies);
2253 if (abs(j - update_jiffies) <= 10)
2254 update_jiffies = j;
2255 }
2256
2257 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2258}
2259
2260
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002261static int bcm4320a_early_init(struct usbnet *usbdev)
2262{
2263 /* bcm4320a doesn't handle configuration parameters well. Try
2264 * set any and you get partially zeroed mac and broken device.
2265 */
2266
2267 return 0;
2268}
2269
2270
2271static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002272{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002273 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002274 char buf[8];
2275
2276 /* Early initialization settings, setting these won't have effect
2277 * if called after generic_rndis_bind().
2278 */
2279
2280 priv->param_country[0] = modparam_country[0];
2281 priv->param_country[1] = modparam_country[1];
2282 priv->param_country[2] = 0;
2283 priv->param_frameburst = modparam_frameburst;
2284 priv->param_afterburner = modparam_afterburner;
2285 priv->param_power_save = modparam_power_save;
2286 priv->param_power_output = modparam_power_output;
2287 priv->param_roamtrigger = modparam_roamtrigger;
2288 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002289
2290 priv->param_country[0] = toupper(priv->param_country[0]);
2291 priv->param_country[1] = toupper(priv->param_country[1]);
2292 /* doesn't support EU as country code, use FI instead */
2293 if (!strcmp(priv->param_country, "EU"))
2294 strcpy(priv->param_country, "FI");
2295
2296 if (priv->param_power_save < 0)
2297 priv->param_power_save = 0;
2298 else if (priv->param_power_save > 2)
2299 priv->param_power_save = 2;
2300
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03002301 if (priv->param_power_output < 0)
2302 priv->param_power_output = 0;
2303 else if (priv->param_power_output > 3)
2304 priv->param_power_output = 3;
2305
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002306 if (priv->param_roamtrigger < -80)
2307 priv->param_roamtrigger = -80;
2308 else if (priv->param_roamtrigger > -60)
2309 priv->param_roamtrigger = -60;
2310
2311 if (priv->param_roamdelta < 0)
2312 priv->param_roamdelta = 0;
2313 else if (priv->param_roamdelta > 2)
2314 priv->param_roamdelta = 2;
2315
Roel Kluin4d381ff2008-04-23 22:10:29 +02002316 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002317 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02002318 else
2319 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002320
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002321 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2322 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002323 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002324 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002325 priv->param_afterburner ? "1" : "0");
2326 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002327 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002328 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002329 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002330 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002331 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002332 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002333 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002334
2335 return 0;
2336}
2337
David S. Miller23d12e22009-03-25 00:03:16 -07002338/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002339static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07002340 .ndo_open = usbnet_open,
2341 .ndo_stop = usbnet_stop,
2342 .ndo_start_xmit = usbnet_start_xmit,
2343 .ndo_tx_timeout = usbnet_tx_timeout,
2344 .ndo_set_mac_address = eth_mac_addr,
2345 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002346 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07002347};
2348
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002349
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002350static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002351{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002352 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002353 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002354 int retval, len;
2355 __le32 tmp;
2356
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002357 /* allocate wiphy and rndis private data
2358 * NOTE: We only support a single virtual interface, so wiphy
2359 * and wireless_dev are somewhat synonymous for this device.
2360 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002361 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002362 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002363 return -ENOMEM;
2364
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002365 priv = wiphy_priv(wiphy);
2366 usbdev->net->ieee80211_ptr = &priv->wdev;
2367 priv->wdev.wiphy = wiphy;
2368 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2369
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002370 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002371 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002372 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002373 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002374 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2375 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002376
2377 mutex_init(&priv->command_lock);
2378 spin_lock_init(&priv->stats_lock);
2379
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002380 /* because rndis_command() sleeps we need to use workqueue */
2381 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002382 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002383 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2384 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2385
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002386 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002387 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002388 if (retval < 0)
2389 goto fail;
2390
2391 /* generic_rndis_bind set packet filter to multicast_all+
2392 * promisc mode which doesn't work well for our devices (device
2393 * picks up rssi to closest station instead of to access point).
2394 *
2395 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002396 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002397 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002398 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07002399
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002400 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002401 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002402 sizeof(tmp));
2403
2404 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002405 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2406 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002407 priv->multicast_size = le32_to_cpu(tmp);
2408 if (retval < 0 || priv->multicast_size < 0)
2409 priv->multicast_size = 0;
2410 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002411 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002412 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002413 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002414
2415 priv->iwstats.qual.qual = 0;
2416 priv->iwstats.qual.level = 0;
2417 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2418 | IW_QUAL_LEVEL_UPDATED
2419 | IW_QUAL_NOISE_INVALID
2420 | IW_QUAL_QUAL_INVALID
2421 | IW_QUAL_LEVEL_INVALID;
2422
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002423 /* fill-out wiphy structure and register w/ cfg80211 */
2424 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2425 wiphy->privid = rndis_wiphy_privid;
2426 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2427 | BIT(NL80211_IFTYPE_ADHOC);
2428 wiphy->max_scan_ssids = 1;
2429
2430 /* TODO: fill-out band information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002431 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002432
2433 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2434 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2435 priv->band.channels = priv->channels;
2436 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2437 priv->band.bitrates = priv->rates;
2438 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2439 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002440 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002441
2442 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2443
2444 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002445 retval = -ENODEV;
2446 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002447 }
2448
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002449 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002450
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002451 /* set default rts/frag */
2452 rndis_set_wiphy_params(wiphy,
2453 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2454
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002455 /* turn radio on */
2456 priv->radio_on = 1;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002457 disassociate(usbdev, 1);
2458 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002459
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002460 queue_delayed_work(priv->workqueue, &priv->stats_work,
2461 round_jiffies_relative(STATS_UPDATE_JIFFIES));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002462
2463 return 0;
2464
2465fail:
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002466 cancel_delayed_work_sync(&priv->stats_work);
2467 cancel_delayed_work_sync(&priv->scan_work);
2468 cancel_work_sync(&priv->work);
2469 flush_workqueue(priv->workqueue);
2470 destroy_workqueue(priv->workqueue);
2471
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002472 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002473 return retval;
2474}
2475
2476
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002477static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002478{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002479 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002480
2481 /* turn radio off */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002482 disassociate(usbdev, 0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002483
2484 cancel_delayed_work_sync(&priv->stats_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002485 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002486 cancel_work_sync(&priv->work);
2487 flush_workqueue(priv->workqueue);
2488 destroy_workqueue(priv->workqueue);
2489
2490 if (priv && priv->wpa_ie_len)
2491 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002492
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002493 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002494
2495 wiphy_unregister(priv->wdev.wiphy);
2496 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002497}
2498
2499
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002500static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002501{
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002502 devdbg(usbdev, "rndis_wlan_reset");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002503 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002504}
2505
2506
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002507static int rndis_wlan_stop(struct usbnet *usbdev)
2508{
2509 devdbg(usbdev, "rndis_wlan_stop");
2510 return disassociate(usbdev, 0);
2511}
2512
2513
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002514static const struct driver_info bcm4320b_info = {
2515 .description = "Wireless RNDIS device, BCM4320b based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002516 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2517 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002518 .bind = rndis_wlan_bind,
2519 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002520 .status = rndis_status,
2521 .rx_fixup = rndis_rx_fixup,
2522 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002523 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002524 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002525 .early_init = bcm4320b_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002526 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002527};
2528
2529static const struct driver_info bcm4320a_info = {
2530 .description = "Wireless RNDIS device, BCM4320a based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002531 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2532 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002533 .bind = rndis_wlan_bind,
2534 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002535 .status = rndis_status,
2536 .rx_fixup = rndis_rx_fixup,
2537 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002538 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002539 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002540 .early_init = bcm4320a_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002541 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002542};
2543
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002544static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002545 .description = "Wireless RNDIS device",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002546 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2547 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002548 .bind = rndis_wlan_bind,
2549 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002550 .status = rndis_status,
2551 .rx_fixup = rndis_rx_fixup,
2552 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002553 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002554 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002555 .early_init = bcm4320a_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002556 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002557};
2558
2559/*-------------------------------------------------------------------------*/
2560
2561static const struct usb_device_id products [] = {
2562#define RNDIS_MASTER_INTERFACE \
2563 .bInterfaceClass = USB_CLASS_COMM, \
2564 .bInterfaceSubClass = 2 /* ACM */, \
2565 .bInterfaceProtocol = 0x0ff
2566
2567/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2568 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2569 */
2570{
2571 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2572 | USB_DEVICE_ID_MATCH_DEVICE,
2573 .idVendor = 0x0411,
2574 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
2575 RNDIS_MASTER_INTERFACE,
2576 .driver_info = (unsigned long) &bcm4320b_info,
2577}, {
2578 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2579 | USB_DEVICE_ID_MATCH_DEVICE,
2580 .idVendor = 0x0baf,
2581 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
2582 RNDIS_MASTER_INTERFACE,
2583 .driver_info = (unsigned long) &bcm4320b_info,
2584}, {
2585 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2586 | USB_DEVICE_ID_MATCH_DEVICE,
2587 .idVendor = 0x050d,
2588 .idProduct = 0x011b, /* Belkin F5D7051 */
2589 RNDIS_MASTER_INTERFACE,
2590 .driver_info = (unsigned long) &bcm4320b_info,
2591}, {
2592 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2593 | USB_DEVICE_ID_MATCH_DEVICE,
2594 .idVendor = 0x1799, /* Belkin has two vendor ids */
2595 .idProduct = 0x011b, /* Belkin F5D7051 */
2596 RNDIS_MASTER_INTERFACE,
2597 .driver_info = (unsigned long) &bcm4320b_info,
2598}, {
2599 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2600 | USB_DEVICE_ID_MATCH_DEVICE,
2601 .idVendor = 0x13b1,
2602 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
2603 RNDIS_MASTER_INTERFACE,
2604 .driver_info = (unsigned long) &bcm4320b_info,
2605}, {
2606 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2607 | USB_DEVICE_ID_MATCH_DEVICE,
2608 .idVendor = 0x13b1,
2609 .idProduct = 0x0026, /* Linksys WUSB54GSC */
2610 RNDIS_MASTER_INTERFACE,
2611 .driver_info = (unsigned long) &bcm4320b_info,
2612}, {
2613 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2614 | USB_DEVICE_ID_MATCH_DEVICE,
2615 .idVendor = 0x0b05,
2616 .idProduct = 0x1717, /* Asus WL169gE */
2617 RNDIS_MASTER_INTERFACE,
2618 .driver_info = (unsigned long) &bcm4320b_info,
2619}, {
2620 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2621 | USB_DEVICE_ID_MATCH_DEVICE,
2622 .idVendor = 0x0a5c,
2623 .idProduct = 0xd11b, /* Eminent EM4045 */
2624 RNDIS_MASTER_INTERFACE,
2625 .driver_info = (unsigned long) &bcm4320b_info,
2626}, {
2627 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2628 | USB_DEVICE_ID_MATCH_DEVICE,
2629 .idVendor = 0x1690,
2630 .idProduct = 0x0715, /* BT Voyager 1055 */
2631 RNDIS_MASTER_INTERFACE,
2632 .driver_info = (unsigned long) &bcm4320b_info,
2633},
2634/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
2635 * parameters available, hardware probably contain older firmware version with
2636 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
2637 */
2638{
2639 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2640 | USB_DEVICE_ID_MATCH_DEVICE,
2641 .idVendor = 0x13b1,
2642 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
2643 RNDIS_MASTER_INTERFACE,
2644 .driver_info = (unsigned long) &bcm4320a_info,
2645}, {
2646 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2647 | USB_DEVICE_ID_MATCH_DEVICE,
2648 .idVendor = 0x0baf,
2649 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
2650 RNDIS_MASTER_INTERFACE,
2651 .driver_info = (unsigned long) &bcm4320a_info,
2652}, {
2653 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2654 | USB_DEVICE_ID_MATCH_DEVICE,
2655 .idVendor = 0x0411,
2656 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
2657 RNDIS_MASTER_INTERFACE,
2658 .driver_info = (unsigned long) &bcm4320a_info,
2659},
2660/* Generic Wireless RNDIS devices that we don't have exact
2661 * idVendor/idProduct/chip yet.
2662 */
2663{
2664 /* RNDIS is MSFT's un-official variant of CDC ACM */
2665 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002666 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002667}, {
2668 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
2669 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002670 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002671},
2672 { }, // END
2673};
2674MODULE_DEVICE_TABLE(usb, products);
2675
2676static struct usb_driver rndis_wlan_driver = {
2677 .name = "rndis_wlan",
2678 .id_table = products,
2679 .probe = usbnet_probe,
2680 .disconnect = usbnet_disconnect,
2681 .suspend = usbnet_suspend,
2682 .resume = usbnet_resume,
2683};
2684
2685static int __init rndis_wlan_init(void)
2686{
2687 return usb_register(&rndis_wlan_driver);
2688}
2689module_init(rndis_wlan_init);
2690
2691static void __exit rndis_wlan_exit(void)
2692{
2693 usb_deregister(&rndis_wlan_driver);
2694}
2695module_exit(rndis_wlan_exit);
2696
2697MODULE_AUTHOR("Bjorge Dijkstra");
2698MODULE_AUTHOR("Jussi Kivilinna");
2699MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
2700MODULE_LICENSE("GPL");
2701