blob: 974f72497862d6e80863b0b755d219b792ecfc64 [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
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300597static int rndis_reset(struct usbnet *usbdev)
598{
599 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
600 struct rndis_reset *reset;
601 int ret;
602
603 mutex_lock(&priv->command_lock);
604
605 reset = (void *)priv->command_buffer;
606 memset(reset, 0, sizeof(*reset));
607 reset->msg_type = RNDIS_MSG_RESET;
608 reset->msg_len = cpu_to_le32(sizeof(*reset));
609 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
610
611 mutex_unlock(&priv->command_lock);
612
613 if (ret < 0)
614 return ret;
615 return 0;
616}
617
618
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200619/*
620 * Specs say that we can only set config parameters only soon after device
621 * initialization.
622 * value_type: 0 = u32, 2 = unicode string
623 */
624static int rndis_set_config_parameter(struct usbnet *dev, char *param,
625 int value_type, void *value)
626{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200627 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200628 int value_len, info_len, param_len, ret, i;
629 __le16 *unibuf;
630 __le32 *dst_value;
631
632 if (value_type == 0)
633 value_len = sizeof(__le32);
634 else if (value_type == 2)
635 value_len = strlen(value) * sizeof(__le16);
636 else
637 return -EINVAL;
638
639 param_len = strlen(param) * sizeof(__le16);
640 info_len = sizeof(*infobuf) + param_len + value_len;
641
642#ifdef DEBUG
643 info_len += 12;
644#endif
645 infobuf = kmalloc(info_len, GFP_KERNEL);
646 if (!infobuf)
647 return -ENOMEM;
648
649#ifdef DEBUG
650 info_len -= 12;
651 /* extra 12 bytes are for padding (debug output) */
652 memset(infobuf, 0xCC, info_len + 12);
653#endif
654
655 if (value_type == 2)
656 devdbg(dev, "setting config parameter: %s, value: %s",
657 param, (u8 *)value);
658 else
659 devdbg(dev, "setting config parameter: %s, value: %d",
660 param, *(u32 *)value);
661
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200662 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
663 infobuf->name_length = cpu_to_le32(param_len);
664 infobuf->type = cpu_to_le32(value_type);
665 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
666 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200667
668 /* simple string to unicode string conversion */
669 unibuf = (void *)infobuf + sizeof(*infobuf);
670 for (i = 0; i < param_len / sizeof(__le16); i++)
671 unibuf[i] = cpu_to_le16(param[i]);
672
673 if (value_type == 2) {
674 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
675 for (i = 0; i < value_len / sizeof(__le16); i++)
676 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
677 } else {
678 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
679 *dst_value = cpu_to_le32(*(u32 *)value);
680 }
681
682#ifdef DEBUG
683 devdbg(dev, "info buffer (len: %d):", info_len);
684 for (i = 0; i < info_len; i += 12) {
685 u32 *tmp = (u32 *)((u8 *)infobuf + i);
686 devdbg(dev, "%08X:%08X:%08X",
687 cpu_to_be32(tmp[0]),
688 cpu_to_be32(tmp[1]),
689 cpu_to_be32(tmp[2]));
690 }
691#endif
692
693 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
694 infobuf, info_len);
695 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200696 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200697
698 kfree(infobuf);
699 return ret;
700}
701
702static int rndis_set_config_parameter_str(struct usbnet *dev,
703 char *param, char *value)
704{
705 return(rndis_set_config_parameter(dev, param, 2, value));
706}
707
708/*static int rndis_set_config_parameter_u32(struct usbnet *dev,
709 char *param, u32 value)
710{
711 return(rndis_set_config_parameter(dev, param, 0, &value));
712}*/
713
714
715/*
716 * data conversion functions
717 */
718static int level_to_qual(int level)
719{
720 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
721 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
722}
723
724
725static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
726{
727 freq->e = 0;
728 freq->i = 0;
729 freq->flags = 0;
730
731 /* see comment in wireless.h above the "struct iw_freq"
732 * definition for an explanation of this if
733 * NOTE: 1000000 is due to the kHz
734 */
735 if (dsconfig > 1000000) {
736 freq->m = dsconfig / 10;
737 freq->e = 1;
738 } else
739 freq->m = dsconfig;
740
741 /* convert from kHz to Hz */
742 freq->e += 3;
743}
744
745
746static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
747{
748 if (freq->m < 1000 && freq->e == 0) {
David Kilroy9ee677c2008-12-23 14:03:38 +0000749 if (freq->m >= 1 && freq->m <= 14)
750 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200751 else
752 return -1;
753 } else {
754 int i;
755 *dsconfig = freq->m;
756 for (i = freq->e; i > 0; i--)
757 *dsconfig *= 10;
758 *dsconfig /= 1000;
759 }
760
761 return 0;
762}
763
764
765/*
766 * common functions
767 */
768static int
769add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index);
770
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200771static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200772{
773 int ret, len;
774
775 len = sizeof(*ssid);
776 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
777
778 if (ret != 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200779 ssid->length = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200780
781#ifdef DEBUG
782 {
783 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
784
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200785 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
786 tmp[le32_to_cpu(ssid->length)] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200787 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
788 }
789#endif
790 return ret;
791}
792
793
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200794static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200795{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300796 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200797 int ret;
798
799 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
800 if (ret == 0) {
801 memcpy(&priv->essid, ssid, sizeof(priv->essid));
802 priv->radio_on = 1;
803 devdbg(usbdev, "set_essid: radio_on = 1");
804 }
805
806 return ret;
807}
808
809
810static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
811{
812 int ret, len;
813
814 len = ETH_ALEN;
815 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
816
817 if (ret != 0)
818 memset(bssid, 0, ETH_ALEN);
819
820 return ret;
821}
822
Scott Ashcroft43646232008-05-27 00:06:15 +0300823static int get_association_info(struct usbnet *usbdev,
824 struct ndis_80211_assoc_info *info, int len)
825{
826 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
827 info, &len);
828}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200829
830static int is_associated(struct usbnet *usbdev)
831{
832 u8 bssid[ETH_ALEN];
833 int ret;
834
835 ret = get_bssid(usbdev, bssid);
836
837 return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0);
838}
839
840
841static int disassociate(struct usbnet *usbdev, int reset_ssid)
842{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300843 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200844 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200845 int i, ret = 0;
846
847 if (priv->radio_on) {
848 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
849 if (ret == 0) {
850 priv->radio_on = 0;
851 devdbg(usbdev, "disassociate: radio_on = 0");
852
853 if (reset_ssid)
854 msleep(100);
855 }
856 }
857
858 /* disassociate causes radio to be turned off; if reset_ssid
859 * is given, set random ssid to enable radio */
860 if (reset_ssid) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200861 ssid.length = cpu_to_le32(sizeof(ssid.essid));
862 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
863 ssid.essid[0] = 0x1;
864 ssid.essid[1] = 0xff;
865 for (i = 2; i < sizeof(ssid.essid); i++)
866 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200867 ret = set_essid(usbdev, &ssid);
868 }
869 return ret;
870}
871
872
873static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
874{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300875 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200876 __le32 tmp;
877 int auth_mode, ret;
878
879 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
880 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
881
882 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
883 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300884 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200885 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300886 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200887 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
888 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300889 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200890 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300891 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200892 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300893 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200894 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
895 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300896 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200897 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300898 auth_mode = NDIS_80211_AUTH_SHARED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200899 } else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300900 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200901
902 tmp = cpu_to_le32(auth_mode);
903 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
904 sizeof(tmp));
905 if (ret != 0) {
906 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
907 return ret;
908 }
909
910 priv->wpa_version = wpa_version;
911 priv->wpa_authalg = authalg;
912 return 0;
913}
914
915
916static int set_priv_filter(struct usbnet *usbdev)
917{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300918 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200919 __le32 tmp;
920
921 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
922
923 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
924 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300925 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200926 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300927 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200928
929 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
930 sizeof(tmp));
931}
932
933
934static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
935{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300936 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200937 __le32 tmp;
938 int encr_mode, ret;
939
940 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
941 pairwise,
942 groupwise);
943
944 if (pairwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300945 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200946 else if (pairwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300947 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200948 else if (pairwise &
949 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300950 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200951 else if (groupwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300952 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200953 else if (groupwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300954 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200955 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300956 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200957
958 tmp = cpu_to_le32(encr_mode);
959 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
960 sizeof(tmp));
961 if (ret != 0) {
962 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
963 return ret;
964 }
965
966 priv->wpa_cipher_pair = pairwise;
967 priv->wpa_cipher_group = groupwise;
968 return 0;
969}
970
971
972static int set_assoc_params(struct usbnet *usbdev)
973{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300974 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200975
976 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
977 set_priv_filter(usbdev);
978 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
979
980 return 0;
981}
982
983
984static int set_infra_mode(struct usbnet *usbdev, int mode)
985{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300986 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200987 __le32 tmp;
988 int ret, i;
989
990 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
991
992 tmp = cpu_to_le32(mode);
993 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
994 sizeof(tmp));
995 if (ret != 0) {
996 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
997 return ret;
998 }
999
1000 /* NDIS drivers clear keys when infrastructure mode is
1001 * changed. But Linux tools assume otherwise. So set the
1002 * keys */
1003 if (priv->wpa_keymgmt == 0 ||
1004 priv->wpa_keymgmt == IW_AUTH_KEY_MGMT_802_1X) {
1005 for (i = 0; i < 4; i++) {
Jussi Kivilinna98391782009-05-22 17:40:34 +03001006 if (priv->encr_key_len[i] > 0 && !priv->encr_key_wpa[i])
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001007 add_wep_key(usbdev, priv->encr_keys[i],
1008 priv->encr_key_len[i], i);
1009 }
1010 }
1011
1012 priv->infra_mode = mode;
1013 return 0;
1014}
1015
1016
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001017static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1018{
1019 __le32 tmp;
1020
1021 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1022
1023 if (rts_threshold < 0 || rts_threshold > 2347)
1024 rts_threshold = 2347;
1025
1026 tmp = cpu_to_le32(rts_threshold);
1027 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1028 sizeof(tmp));
1029}
1030
1031
1032static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1033{
1034 __le32 tmp;
1035
1036 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1037
1038 if (frag_threshold < 256 || frag_threshold > 2346)
1039 frag_threshold = 2346;
1040
1041 tmp = cpu_to_le32(frag_threshold);
1042 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1043 sizeof(tmp));
1044}
1045
1046
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001047static void set_default_iw_params(struct usbnet *usbdev)
1048{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001049 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001050
1051 priv->wpa_keymgmt = 0;
1052 priv->wpa_version = 0;
1053
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001054 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001055 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1056 IW_AUTH_ALG_OPEN_SYSTEM);
1057 set_priv_filter(usbdev);
1058 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1059}
1060
1061
1062static int deauthenticate(struct usbnet *usbdev)
1063{
1064 int ret;
1065
1066 ret = disassociate(usbdev, 1);
1067 set_default_iw_params(usbdev);
1068 return ret;
1069}
1070
1071
1072/* index must be 0 - N, as per NDIS */
1073static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
1074{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001075 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001076 struct ndis_80211_wep_key ndis_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001077 int ret;
1078
1079 if (key_len <= 0 || key_len > 32 || index < 0 || index >= 4)
1080 return -EINVAL;
1081
1082 memset(&ndis_key, 0, sizeof(ndis_key));
1083
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001084 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1085 ndis_key.length = cpu_to_le32(key_len);
1086 ndis_key.index = cpu_to_le32(index);
1087 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001088
1089 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001090 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001091 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1092 IW_AUTH_CIPHER_NONE);
1093 if (ret)
1094 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1095 ret);
1096 }
1097
1098 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1099 sizeof(ndis_key));
1100 if (ret != 0) {
1101 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1102 index+1, ret);
1103 return ret;
1104 }
1105
1106 priv->encr_key_len[index] = key_len;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001107 priv->encr_key_wpa[index] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001108 memcpy(&priv->encr_keys[index], key, key_len);
1109
1110 return 0;
1111}
1112
1113
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001114static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
1115 int index, const struct sockaddr *addr,
1116 const u8 *rx_seq, int alg, int flags)
1117{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001118 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001119 struct ndis_80211_key ndis_key;
1120 int ret;
1121
1122 if (index < 0 || index >= 4)
1123 return -EINVAL;
1124 if (key_len > sizeof(ndis_key.material) || key_len < 0)
1125 return -EINVAL;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001126 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001127 return -EINVAL;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001128 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !addr)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001129 return -EINVAL;
1130
1131 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001132 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1133 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1134 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001135
1136 memset(&ndis_key, 0, sizeof(ndis_key));
1137
1138 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1139 sizeof(ndis_key.material) + key_len);
1140 ndis_key.length = cpu_to_le32(key_len);
1141 ndis_key.index = cpu_to_le32(index) | flags;
1142
1143 if (alg == IW_ENCODE_ALG_TKIP && key_len == 32) {
1144 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1145 * different order than NDIS spec, so swap the order here. */
1146 memcpy(ndis_key.material, key, 16);
1147 memcpy(ndis_key.material + 16, key + 24, 8);
1148 memcpy(ndis_key.material + 24, key + 16, 8);
1149 } else
1150 memcpy(ndis_key.material, key, key_len);
1151
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001152 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001153 memcpy(ndis_key.rsc, rx_seq, 6);
1154
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001155 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001156 /* pairwise key */
1157 memcpy(ndis_key.bssid, addr->sa_data, ETH_ALEN);
1158 } else {
1159 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001160 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001161 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1162 else
1163 get_bssid(usbdev, ndis_key.bssid);
1164 }
1165
1166 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1167 le32_to_cpu(ndis_key.size));
1168 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1169 if (ret != 0)
1170 return ret;
1171
1172 priv->encr_key_len[index] = key_len;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001173 priv->encr_key_wpa[index] = 1;
1174
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001175 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001176 priv->encr_tx_key_index = index;
1177
1178 return 0;
1179}
1180
1181
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001182/* remove_key is for both wep and wpa */
1183static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1184{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001185 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001186 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001187 __le32 keyindex;
1188 int ret;
1189
1190 if (priv->encr_key_len[index] == 0)
1191 return 0;
1192
1193 priv->encr_key_len[index] = 0;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001194 priv->encr_key_wpa[index] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001195 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1196
1197 if (priv->wpa_cipher_pair == IW_AUTH_CIPHER_TKIP ||
1198 priv->wpa_cipher_pair == IW_AUTH_CIPHER_CCMP ||
1199 priv->wpa_cipher_group == IW_AUTH_CIPHER_TKIP ||
1200 priv->wpa_cipher_group == IW_AUTH_CIPHER_CCMP) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001201 remove_key.size = cpu_to_le32(sizeof(remove_key));
1202 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001203 if (bssid) {
1204 /* pairwise key */
1205 if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001206 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001207 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001208 memcpy(remove_key.bssid, bssid,
1209 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001210 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001211 memset(remove_key.bssid, 0xff,
1212 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001213
1214 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1215 sizeof(remove_key));
1216 if (ret != 0)
1217 return ret;
1218 } else {
1219 keyindex = cpu_to_le32(index);
1220 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1221 sizeof(keyindex));
1222 if (ret != 0) {
1223 devwarn(usbdev,
1224 "removing encryption key %d failed (%08X)",
1225 index, ret);
1226 return ret;
1227 }
1228 }
1229
1230 /* if it is transmit key, disable encryption */
1231 if (index == priv->encr_tx_key_index)
1232 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1233
1234 return 0;
1235}
1236
1237
1238static void set_multicast_list(struct usbnet *usbdev)
1239{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001240 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001241 struct dev_mc_list *mclist;
1242 __le32 filter;
1243 int ret, i, size;
1244 char *buf;
1245
1246 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1247
1248 if (usbdev->net->flags & IFF_PROMISC) {
1249 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1250 RNDIS_PACKET_TYPE_ALL_LOCAL;
1251 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1252 usbdev->net->mc_count > priv->multicast_size) {
1253 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1254 } else if (usbdev->net->mc_count > 0) {
1255 size = min(priv->multicast_size, usbdev->net->mc_count);
1256 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1257 if (!buf) {
1258 devwarn(usbdev,
1259 "couldn't alloc %d bytes of memory",
1260 size * ETH_ALEN);
1261 return;
1262 }
1263
1264 mclist = usbdev->net->mc_list;
1265 for (i = 0; i < size && mclist; mclist = mclist->next) {
1266 if (mclist->dmi_addrlen != ETH_ALEN)
1267 continue;
1268
1269 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1270 i++;
1271 }
1272
1273 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1274 i * ETH_ALEN);
1275 if (ret == 0 && i > 0)
1276 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1277 else
1278 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1279
1280 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1281 i, priv->multicast_size, ret);
1282
1283 kfree(buf);
1284 }
1285
1286 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1287 sizeof(filter));
1288 if (ret < 0) {
1289 devwarn(usbdev, "couldn't set packet filter: %08x",
1290 le32_to_cpu(filter));
1291 }
1292
1293 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1294 le32_to_cpu(filter), ret);
1295}
1296
1297
1298/*
John W. Linville964c1d42009-03-26 23:40:01 +02001299 * cfg80211 ops
1300 */
Johannes Berge36d56b2009-06-09 21:04:43 +02001301static int rndis_change_virtual_intf(struct wiphy *wiphy,
1302 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +02001303 enum nl80211_iftype type, u32 *flags,
1304 struct vif_params *params)
1305{
Johannes Berge36d56b2009-06-09 21:04:43 +02001306 struct usbnet *usbdev = netdev_priv(dev);
John W. Linville964c1d42009-03-26 23:40:01 +02001307 int mode;
1308
John W. Linville964c1d42009-03-26 23:40:01 +02001309 switch (type) {
1310 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001311 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001312 break;
1313 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001314 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001315 break;
1316 default:
1317 return -EINVAL;
1318 }
1319
1320 return set_infra_mode(usbdev, mode);
1321}
1322
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001323
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001324static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1325{
1326 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1327 struct usbnet *usbdev = priv->usbdev;
1328 int err;
1329
1330 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1331 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1332 if (err < 0)
1333 return err;
1334 }
1335
1336 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1337 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1338 if (err < 0)
1339 return err;
1340 }
1341
1342 return 0;
1343}
1344
1345
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001346static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1347 int dbm)
1348{
1349 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1350 struct usbnet *usbdev = priv->usbdev;
1351
1352 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1353
1354 /* Device doesn't support changing txpower after initialization, only
1355 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1356 * currently used.
1357 */
1358 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1359 if (!priv->radio_on)
1360 disassociate(usbdev, 1); /* turn on radio */
1361
1362 return 0;
1363 }
1364
1365 return -ENOTSUPP;
1366}
1367
1368
1369static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1370{
1371 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1372 struct usbnet *usbdev = priv->usbdev;
1373
1374 *dbm = get_bcm4320_power_dbm(priv);
1375
1376 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1377
1378 return 0;
1379}
1380
1381
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001382#define SCAN_DELAY_JIFFIES (HZ)
1383static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1384 struct cfg80211_scan_request *request)
1385{
1386 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001387 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001388 int ret;
1389 __le32 tmp;
1390
1391 devdbg(usbdev, "cfg80211.scan");
1392
1393 if (!request)
1394 return -EINVAL;
1395
1396 if (priv->scan_request && priv->scan_request != request)
1397 return -EBUSY;
1398
1399 priv->scan_request = request;
1400
1401 tmp = cpu_to_le32(1);
1402 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1403 sizeof(tmp));
1404 if (ret == 0) {
1405 /* Wait before retrieving scan results from device */
1406 queue_delayed_work(priv->workqueue, &priv->scan_work,
1407 SCAN_DELAY_JIFFIES);
1408 }
1409
1410 return ret;
1411}
1412
1413
1414static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1415 struct ndis_80211_bssid_ex *bssid)
1416{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001417 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001418 struct ieee80211_channel *channel;
1419 s32 signal;
1420 u64 timestamp;
1421 u16 capability;
1422 u16 beacon_interval;
1423 struct ndis_80211_fixed_ies *fixed;
1424 int ie_len, bssid_len;
1425 u8 *ie;
1426
1427 /* parse bssid structure */
1428 bssid_len = le32_to_cpu(bssid->length);
1429
1430 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1431 sizeof(struct ndis_80211_fixed_ies))
1432 return NULL;
1433
1434 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1435
1436 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1437 ie_len = min(bssid_len - (int)sizeof(*bssid),
1438 (int)le32_to_cpu(bssid->ie_length));
1439 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1440 if (ie_len < 0)
1441 return NULL;
1442
1443 /* extract data for cfg80211_inform_bss */
1444 channel = ieee80211_get_channel(priv->wdev.wiphy,
1445 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1446 if (!channel)
1447 return NULL;
1448
1449 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1450 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1451 capability = le16_to_cpu(fixed->capabilities);
1452 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1453
1454 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1455 timestamp, capability, beacon_interval, ie, ie_len, signal,
1456 GFP_KERNEL);
1457}
1458
1459
1460static int rndis_check_bssid_list(struct usbnet *usbdev)
1461{
1462 void *buf = NULL;
1463 struct ndis_80211_bssid_list_ex *bssid_list;
1464 struct ndis_80211_bssid_ex *bssid;
1465 int ret = -EINVAL, len, count, bssid_len;
1466
1467 devdbg(usbdev, "check_bssid_list");
1468
1469 len = CONTROL_BUFFER_SIZE;
1470 buf = kmalloc(len, GFP_KERNEL);
1471 if (!buf) {
1472 ret = -ENOMEM;
1473 goto out;
1474 }
1475
1476 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1477 if (ret != 0)
1478 goto out;
1479
1480 bssid_list = buf;
1481 bssid = bssid_list->bssid;
1482 bssid_len = le32_to_cpu(bssid->length);
1483 count = le32_to_cpu(bssid_list->num_items);
1484 devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count);
1485
1486 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1487 rndis_bss_info_update(usbdev, bssid);
1488
1489 bssid = (void *)bssid + bssid_len;
1490 bssid_len = le32_to_cpu(bssid->length);
1491 count--;
1492 }
1493
1494out:
1495 kfree(buf);
1496 return ret;
1497}
1498
1499
1500static void rndis_get_scan_results(struct work_struct *work)
1501{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001502 struct rndis_wlan_private *priv =
1503 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001504 struct usbnet *usbdev = priv->usbdev;
1505 int ret;
1506
1507 devdbg(usbdev, "get_scan_results");
1508
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03001509 if (!priv->scan_request)
1510 return;
1511
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001512 ret = rndis_check_bssid_list(usbdev);
1513
1514 cfg80211_scan_done(priv->scan_request, ret < 0);
1515
1516 priv->scan_request = NULL;
1517}
1518
1519
John W. Linville964c1d42009-03-26 23:40:01 +02001520/*
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001521 * wireless extension handlers
1522 */
1523
1524static int rndis_iw_commit(struct net_device *dev,
1525 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1526{
1527 /* dummy op */
1528 return 0;
1529}
1530
1531
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001532static int rndis_iw_set_essid(struct net_device *dev,
1533 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1534{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001535 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001536 int length = wrqu->essid.length;
Wang Chen524ad0a2008-11-12 23:39:10 -08001537 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001538
1539 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1540 wrqu->essid.flags, wrqu->essid.length, essid);
1541
1542 if (length > NDIS_802_11_LENGTH_SSID)
1543 length = NDIS_802_11_LENGTH_SSID;
1544
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001545 ssid.length = cpu_to_le32(length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001546 if (length > 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001547 memcpy(ssid.essid, essid, length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001548 else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001549 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001550
1551 set_assoc_params(usbdev);
1552
1553 if (!wrqu->essid.flags || length == 0)
1554 return disassociate(usbdev, 1);
1555 else
1556 return set_essid(usbdev, &ssid);
1557}
1558
1559
1560static int rndis_iw_get_essid(struct net_device *dev,
1561 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1562{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001563 struct ndis_80211_ssid ssid;
Wang Chen524ad0a2008-11-12 23:39:10 -08001564 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001565 int ret;
1566
1567 ret = get_essid(usbdev, &ssid);
1568
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001569 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001570 wrqu->essid.flags = 1;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001571 wrqu->essid.length = le32_to_cpu(ssid.length);
1572 memcpy(essid, ssid.essid, wrqu->essid.length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001573 essid[wrqu->essid.length] = 0;
1574 } else {
1575 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1576 wrqu->essid.flags = 0;
1577 wrqu->essid.length = 0;
1578 }
1579 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1580 return ret;
1581}
1582
1583
1584static int rndis_iw_get_bssid(struct net_device *dev,
1585 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1586{
Wang Chen524ad0a2008-11-12 23:39:10 -08001587 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001588 unsigned char bssid[ETH_ALEN];
1589 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001590
1591 ret = get_bssid(usbdev, bssid);
1592
1593 if (ret == 0)
Johannes Berge1749612008-10-27 15:59:26 -07001594 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001595 else
1596 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1597
1598 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1599 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1600
1601 return ret;
1602}
1603
1604
1605static int rndis_iw_set_bssid(struct net_device *dev,
1606 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1607{
Wang Chen524ad0a2008-11-12 23:39:10 -08001608 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001609 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001610 int ret;
1611
Johannes Berge1749612008-10-27 15:59:26 -07001612 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001613
1614 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1615
1616 /* user apps may set ap's mac address, which is not required;
1617 * they may fail to work if this function fails, so return
1618 * success */
1619 if (ret)
1620 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1621
1622 return 0;
1623}
1624
1625
1626static int rndis_iw_set_auth(struct net_device *dev,
1627 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1628{
1629 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001630 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001631 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001632 int ret = -ENOTSUPP;
1633
1634 switch (p->flags & IW_AUTH_INDEX) {
1635 case IW_AUTH_WPA_VERSION:
1636 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1637 priv->wpa_version = p->value;
1638 ret = 0;
1639 break;
1640
1641 case IW_AUTH_CIPHER_PAIRWISE:
1642 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1643 priv->wpa_cipher_pair = p->value;
1644 ret = 0;
1645 break;
1646
1647 case IW_AUTH_CIPHER_GROUP:
1648 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1649 priv->wpa_cipher_group = p->value;
1650 ret = 0;
1651 break;
1652
1653 case IW_AUTH_KEY_MGMT:
1654 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1655 priv->wpa_keymgmt = p->value;
1656 ret = 0;
1657 break;
1658
1659 case IW_AUTH_TKIP_COUNTERMEASURES:
1660 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1661 p->value);
1662 ret = 0;
1663 break;
1664
1665 case IW_AUTH_DROP_UNENCRYPTED:
1666 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1667 ret = 0;
1668 break;
1669
1670 case IW_AUTH_80211_AUTH_ALG:
1671 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1672 priv->wpa_authalg = p->value;
1673 ret = 0;
1674 break;
1675
1676 case IW_AUTH_WPA_ENABLED:
1677 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1678 if (wrqu->param.value)
1679 deauthenticate(usbdev);
1680 ret = 0;
1681 break;
1682
1683 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1684 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1685 p->value);
1686 ret = 0;
1687 break;
1688
1689 case IW_AUTH_ROAMING_CONTROL:
1690 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1691 ret = 0;
1692 break;
1693
1694 case IW_AUTH_PRIVACY_INVOKED:
1695 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1696 wrqu->param.flags & IW_AUTH_INDEX);
1697 return -EOPNOTSUPP;
1698
1699 default:
1700 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1701 p->flags & IW_AUTH_INDEX, p->value);
1702 }
1703 return ret;
1704}
1705
1706
1707static int rndis_iw_get_auth(struct net_device *dev,
1708 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1709{
1710 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001711 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001712 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001713
1714 switch (p->flags & IW_AUTH_INDEX) {
1715 case IW_AUTH_WPA_VERSION:
1716 p->value = priv->wpa_version;
1717 break;
1718 case IW_AUTH_CIPHER_PAIRWISE:
1719 p->value = priv->wpa_cipher_pair;
1720 break;
1721 case IW_AUTH_CIPHER_GROUP:
1722 p->value = priv->wpa_cipher_group;
1723 break;
1724 case IW_AUTH_KEY_MGMT:
1725 p->value = priv->wpa_keymgmt;
1726 break;
1727 case IW_AUTH_80211_AUTH_ALG:
1728 p->value = priv->wpa_authalg;
1729 break;
1730 default:
1731 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1732 wrqu->param.flags & IW_AUTH_INDEX);
1733 return -EOPNOTSUPP;
1734 }
1735 return 0;
1736}
1737
1738
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001739static int rndis_iw_set_encode(struct net_device *dev,
1740 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1741{
Wang Chen524ad0a2008-11-12 23:39:10 -08001742 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001743 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001744 int ret, index, key_len;
1745 u8 *key;
1746
1747 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
1748
1749 /* iwconfig gives index as 1 - N */
1750 if (index > 0)
1751 index--;
1752 else
1753 index = priv->encr_tx_key_index;
1754
1755 if (index < 0 || index >= 4) {
1756 devwarn(usbdev, "encryption index out of range (%u)", index);
1757 return -EINVAL;
1758 }
1759
1760 /* remove key if disabled */
1761 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
1762 if (remove_key(usbdev, index, NULL))
1763 return -EINVAL;
1764 else
1765 return 0;
1766 }
1767
1768 /* global encryption state (for all keys) */
1769 if (wrqu->data.flags & IW_ENCODE_OPEN)
1770 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1771 IW_AUTH_ALG_OPEN_SYSTEM);
1772 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1773 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1774 IW_AUTH_ALG_SHARED_KEY);
1775 if (ret != 0)
1776 return ret;
1777
1778 if (wrqu->data.length > 0) {
1779 key_len = wrqu->data.length;
1780 key = extra;
1781 } else {
1782 /* must be set as tx key */
1783 if (priv->encr_key_len[index] == 0)
1784 return -EINVAL;
1785 key_len = priv->encr_key_len[index];
1786 key = priv->encr_keys[index];
1787 priv->encr_tx_key_index = index;
1788 }
1789
1790 if (add_wep_key(usbdev, key, key_len, index) != 0)
1791 return -EINVAL;
1792
1793 if (index == priv->encr_tx_key_index)
1794 /* ndis drivers want essid to be set after setting encr */
1795 set_essid(usbdev, &priv->essid);
1796
1797 return 0;
1798}
1799
1800
1801static int rndis_iw_set_encode_ext(struct net_device *dev,
1802 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1803{
1804 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
Wang Chen524ad0a2008-11-12 23:39:10 -08001805 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001806 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001807 int keyidx, flags;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001808
1809 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
1810
1811 /* iwconfig gives index as 1 - N */
1812 if (keyidx)
1813 keyidx--;
1814 else
1815 keyidx = priv->encr_tx_key_index;
1816
1817 if (keyidx < 0 || keyidx >= 4)
1818 return -EINVAL;
1819
1820 if (ext->alg == WPA_ALG_WEP) {
1821 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1822 priv->encr_tx_key_index = keyidx;
1823 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
1824 }
1825
1826 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
1827 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
1828 return remove_key(usbdev, keyidx, NULL);
1829
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001830 flags = 0;
1831 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001832 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001833 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001834 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001835 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001836 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001837
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001838 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx, &ext->addr,
1839 ext->rx_seq, ext->alg, flags);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001840}
1841
1842
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001843static int rndis_iw_set_genie(struct net_device *dev,
1844 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1845{
Wang Chen524ad0a2008-11-12 23:39:10 -08001846 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001847 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001848 int ret = 0;
1849
1850#ifdef DEBUG
1851 int j;
1852 u8 *gie = extra;
1853 for (j = 0; j < wrqu->data.length; j += 8)
1854 devdbg(usbdev,
1855 "SIOCSIWGENIE %04x - "
1856 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
1857 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
1858 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
1859#endif
1860 /* clear existing IEs */
1861 if (priv->wpa_ie_len) {
1862 kfree(priv->wpa_ie);
1863 priv->wpa_ie_len = 0;
1864 }
1865
1866 /* set new IEs */
1867 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
1868 if (priv->wpa_ie) {
1869 priv->wpa_ie_len = wrqu->data.length;
1870 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
1871 } else
1872 ret = -ENOMEM;
1873 return ret;
1874}
1875
1876
1877static int rndis_iw_get_genie(struct net_device *dev,
1878 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1879{
Wang Chen524ad0a2008-11-12 23:39:10 -08001880 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001881 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001882
1883 devdbg(usbdev, "SIOCGIWGENIE");
1884
1885 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
1886 wrqu->data.length = 0;
1887 return 0;
1888 }
1889
1890 if (wrqu->data.length < priv->wpa_ie_len)
1891 return -E2BIG;
1892
1893 wrqu->data.length = priv->wpa_ie_len;
1894 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
1895
1896 return 0;
1897}
1898
1899
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001900static int rndis_iw_set_freq(struct net_device *dev,
1901 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1902{
Wang Chen524ad0a2008-11-12 23:39:10 -08001903 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001904 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001905 unsigned int dsconfig;
1906 int len, ret;
1907
1908 /* this OID is valid only when not associated */
1909 if (is_associated(usbdev))
1910 return 0;
1911
1912 dsconfig = 0;
1913 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
1914 return -EINVAL;
1915
1916 len = sizeof(config);
1917 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1918 if (ret != 0) {
1919 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
1920 return 0;
1921 }
1922
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001923 config.ds_config = cpu_to_le32(dsconfig);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001924
1925 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
1926 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
1927 sizeof(config));
1928}
1929
1930
1931static int rndis_iw_get_freq(struct net_device *dev,
1932 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1933{
Wang Chen524ad0a2008-11-12 23:39:10 -08001934 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001935 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001936 int len, ret;
1937
1938 len = sizeof(config);
1939 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1940 if (ret == 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001941 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001942
1943 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
1944 return ret;
1945}
1946
1947
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001948static int rndis_iw_get_rate(struct net_device *dev,
1949 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1950{
Wang Chen524ad0a2008-11-12 23:39:10 -08001951 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001952 __le32 tmp;
1953 int ret, len;
1954
1955 len = sizeof(tmp);
1956 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
1957 if (ret == 0) {
1958 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
1959 wrqu->bitrate.disabled = 0;
1960 wrqu->bitrate.flags = 1;
1961 }
1962 return ret;
1963}
1964
1965
1966static int rndis_iw_set_mlme(struct net_device *dev,
1967 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
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 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1972 unsigned char bssid[ETH_ALEN];
1973
1974 get_bssid(usbdev, bssid);
1975
1976 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
1977 return -EINVAL;
1978
1979 switch (mlme->cmd) {
1980 case IW_MLME_DEAUTH:
1981 return deauthenticate(usbdev);
1982 case IW_MLME_DISASSOC:
1983 return disassociate(usbdev, priv->radio_on);
1984 default:
1985 return -EOPNOTSUPP;
1986 }
1987
1988 return 0;
1989}
1990
1991
1992static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
1993{
Wang Chen524ad0a2008-11-12 23:39:10 -08001994 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001995 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001996 unsigned long flags;
1997
1998 spin_lock_irqsave(&priv->stats_lock, flags);
1999 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2000 spin_unlock_irqrestore(&priv->stats_lock, flags);
2001
2002 return &priv->iwstats;
2003}
2004
2005
2006#define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2007static const iw_handler rndis_iw_handler[] =
2008{
2009 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002010 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002011 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2012 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
John W. Linville964c1d42009-03-26 23:40:01 +02002013 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2014 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002015 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002016 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2017 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002018 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2019 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002020 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2021 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002022 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002023 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2024 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2025 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2026 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002027 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2028 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002029 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2030 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2031 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2032 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2033 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2034 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2035 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2036};
2037
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002038static const iw_handler rndis_wlan_private_handler[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002039};
2040
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002041static const struct iw_priv_args rndis_wlan_private_args[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002042};
2043
2044
2045static const struct iw_handler_def rndis_iw_handlers = {
2046 .num_standard = ARRAY_SIZE(rndis_iw_handler),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002047 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2048 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002049 .standard = (iw_handler *)rndis_iw_handler,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002050 .private = (iw_handler *)rndis_wlan_private_handler,
2051 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002052 .get_wireless_stats = rndis_get_wireless_stats,
2053};
2054
2055
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002056static void rndis_wlan_worker(struct work_struct *work)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002057{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002058 struct rndis_wlan_private *priv =
2059 container_of(work, struct rndis_wlan_private, work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002060 struct usbnet *usbdev = priv->usbdev;
2061 union iwreq_data evt;
2062 unsigned char bssid[ETH_ALEN];
Scott Ashcroft43646232008-05-27 00:06:15 +03002063 struct ndis_80211_assoc_info *info;
2064 int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32;
2065 int ret, offset;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002066
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002067 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002068 netif_carrier_on(usbdev->net);
2069
Scott Ashcroft43646232008-05-27 00:06:15 +03002070 info = kzalloc(assoc_size, GFP_KERNEL);
2071 if (!info)
2072 goto get_bssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002073
Scott Ashcroft43646232008-05-27 00:06:15 +03002074 /* Get association info IEs from device and send them back to
2075 * userspace. */
2076 ret = get_association_info(usbdev, info, assoc_size);
2077 if (!ret) {
2078 evt.data.length = le32_to_cpu(info->req_ie_length);
2079 if (evt.data.length > 0) {
2080 offset = le32_to_cpu(info->offset_req_ies);
2081 wireless_send_event(usbdev->net,
2082 IWEVASSOCREQIE, &evt,
2083 (char *)info + offset);
2084 }
2085
2086 evt.data.length = le32_to_cpu(info->resp_ie_length);
2087 if (evt.data.length > 0) {
2088 offset = le32_to_cpu(info->offset_resp_ies);
2089 wireless_send_event(usbdev->net,
2090 IWEVASSOCRESPIE, &evt,
2091 (char *)info + offset);
2092 }
2093 }
2094
2095 kfree(info);
2096
2097get_bssid:
2098 ret = get_bssid(usbdev, bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002099 if (!ret) {
2100 evt.data.flags = 0;
2101 evt.data.length = 0;
2102 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
2103 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2104 }
2105 }
2106
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002107 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002108 netif_carrier_off(usbdev->net);
2109
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002110 evt.data.flags = 0;
2111 evt.data.length = 0;
2112 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2113 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2114 }
2115
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002116 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2117 set_multicast_list(usbdev);
2118}
2119
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002120static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002121{
Wang Chen524ad0a2008-11-12 23:39:10 -08002122 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002123 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002124
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002125 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2126 return;
2127
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002128 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2129 queue_work(priv->workqueue, &priv->work);
2130}
2131
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002132static void rndis_wlan_link_change(struct usbnet *usbdev, int state)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002133{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002134 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002135
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002136 /* queue work to avoid recursive calls into rndis_command */
2137 set_bit(state ? WORK_LINK_UP : WORK_LINK_DOWN, &priv->work_pending);
2138 queue_work(priv->workqueue, &priv->work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002139}
2140
2141
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002142static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002143{
2144 struct {
2145 __le32 num_items;
2146 __le32 items[8];
2147 } networks_supported;
2148 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002149 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002150
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002151 /* determine supported modes */
2152 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002153 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002154 &networks_supported, &len);
2155 if (retval >= 0) {
2156 n = le32_to_cpu(networks_supported.num_items);
2157 if (n > 8)
2158 n = 8;
2159 for (i = 0; i < n; i++) {
2160 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002161 case NDIS_80211_TYPE_FREQ_HOP:
2162 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002163 priv->caps |= CAP_MODE_80211B;
2164 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002165 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002166 priv->caps |= CAP_MODE_80211A;
2167 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002168 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002169 priv->caps |= CAP_MODE_80211G;
2170 break;
2171 }
2172 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002173 }
2174
2175 return retval;
2176}
2177
2178
2179#define STATS_UPDATE_JIFFIES (HZ)
2180static void rndis_update_wireless_stats(struct work_struct *work)
2181{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002182 struct rndis_wlan_private *priv =
2183 container_of(work, struct rndis_wlan_private, stats_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002184 struct usbnet *usbdev = priv->usbdev;
2185 struct iw_statistics iwstats;
2186 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002187 int len, ret, j;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002188 unsigned long flags;
2189 int update_jiffies = STATS_UPDATE_JIFFIES;
2190 void *buf;
2191
2192 spin_lock_irqsave(&priv->stats_lock, flags);
2193 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2194 spin_unlock_irqrestore(&priv->stats_lock, flags);
2195
2196 /* only update stats when connected */
2197 if (!is_associated(usbdev)) {
2198 iwstats.qual.qual = 0;
2199 iwstats.qual.level = 0;
2200 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2201 | IW_QUAL_LEVEL_UPDATED
2202 | IW_QUAL_NOISE_INVALID
2203 | IW_QUAL_QUAL_INVALID
2204 | IW_QUAL_LEVEL_INVALID;
2205 goto end;
2206 }
2207
2208 len = sizeof(rssi);
2209 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2210
2211 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2212 le32_to_cpu(rssi));
2213 if (ret == 0) {
2214 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2215 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinna4bd7f032009-03-26 23:40:16 +02002216 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002217 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2218 | IW_QUAL_LEVEL_UPDATED
2219 | IW_QUAL_NOISE_INVALID;
2220 }
2221
2222 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2223
2224 len = sizeof(tmp);
2225 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2226 if (ret == 0)
2227 iwstats.discard.misc += le32_to_cpu(tmp);
2228
2229 len = sizeof(tmp);
2230 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2231 if (ret == 0)
2232 iwstats.discard.misc += le32_to_cpu(tmp);
2233
2234 len = sizeof(tmp);
2235 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2236 if (ret == 0)
2237 iwstats.discard.misc += le32_to_cpu(tmp);
2238
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002239 /* Workaround transfer stalls on poor quality links.
2240 * TODO: find right way to fix these stalls (as stalls do not happen
2241 * with ndiswrapper/windows driver). */
2242 if (iwstats.qual.qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002243 /* Decrease stats worker interval to catch stalls.
2244 * faster. Faster than 400-500ms causes packet loss,
2245 * Slower doesn't catch stalls fast enough.
2246 */
2247 j = msecs_to_jiffies(priv->param_workaround_interval);
2248 if (j > STATS_UPDATE_JIFFIES)
2249 j = STATS_UPDATE_JIFFIES;
2250 else if (j <= 0)
2251 j = 1;
2252 update_jiffies = j;
2253
2254 /* Send scan OID. Use of both OIDs is required to get device
2255 * working.
2256 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08002257 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002258 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2259 sizeof(tmp));
2260
2261 len = CONTROL_BUFFER_SIZE;
2262 buf = kmalloc(len, GFP_KERNEL);
2263 if (!buf)
2264 goto end;
2265
2266 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2267 kfree(buf);
2268 }
2269end:
2270 spin_lock_irqsave(&priv->stats_lock, flags);
2271 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2272 spin_unlock_irqrestore(&priv->stats_lock, flags);
2273
2274 if (update_jiffies >= HZ)
2275 update_jiffies = round_jiffies_relative(update_jiffies);
2276 else {
2277 j = round_jiffies_relative(update_jiffies);
2278 if (abs(j - update_jiffies) <= 10)
2279 update_jiffies = j;
2280 }
2281
2282 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2283}
2284
2285
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002286static int bcm4320a_early_init(struct usbnet *usbdev)
2287{
2288 /* bcm4320a doesn't handle configuration parameters well. Try
2289 * set any and you get partially zeroed mac and broken device.
2290 */
2291
2292 return 0;
2293}
2294
2295
2296static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002297{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002298 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002299 char buf[8];
2300
2301 /* Early initialization settings, setting these won't have effect
2302 * if called after generic_rndis_bind().
2303 */
2304
2305 priv->param_country[0] = modparam_country[0];
2306 priv->param_country[1] = modparam_country[1];
2307 priv->param_country[2] = 0;
2308 priv->param_frameburst = modparam_frameburst;
2309 priv->param_afterburner = modparam_afterburner;
2310 priv->param_power_save = modparam_power_save;
2311 priv->param_power_output = modparam_power_output;
2312 priv->param_roamtrigger = modparam_roamtrigger;
2313 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002314
2315 priv->param_country[0] = toupper(priv->param_country[0]);
2316 priv->param_country[1] = toupper(priv->param_country[1]);
2317 /* doesn't support EU as country code, use FI instead */
2318 if (!strcmp(priv->param_country, "EU"))
2319 strcpy(priv->param_country, "FI");
2320
2321 if (priv->param_power_save < 0)
2322 priv->param_power_save = 0;
2323 else if (priv->param_power_save > 2)
2324 priv->param_power_save = 2;
2325
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03002326 if (priv->param_power_output < 0)
2327 priv->param_power_output = 0;
2328 else if (priv->param_power_output > 3)
2329 priv->param_power_output = 3;
2330
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002331 if (priv->param_roamtrigger < -80)
2332 priv->param_roamtrigger = -80;
2333 else if (priv->param_roamtrigger > -60)
2334 priv->param_roamtrigger = -60;
2335
2336 if (priv->param_roamdelta < 0)
2337 priv->param_roamdelta = 0;
2338 else if (priv->param_roamdelta > 2)
2339 priv->param_roamdelta = 2;
2340
Roel Kluin4d381ff2008-04-23 22:10:29 +02002341 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002342 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02002343 else
2344 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002345
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002346 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2347 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002348 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002349 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002350 priv->param_afterburner ? "1" : "0");
2351 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002352 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002353 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002354 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002355 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002356 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002357 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002358 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002359
2360 return 0;
2361}
2362
David S. Miller23d12e22009-03-25 00:03:16 -07002363/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002364static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07002365 .ndo_open = usbnet_open,
2366 .ndo_stop = usbnet_stop,
2367 .ndo_start_xmit = usbnet_start_xmit,
2368 .ndo_tx_timeout = usbnet_tx_timeout,
2369 .ndo_set_mac_address = eth_mac_addr,
2370 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002371 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07002372};
2373
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002374
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002375static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002376{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002377 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002378 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002379 int retval, len;
2380 __le32 tmp;
2381
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002382 /* allocate wiphy and rndis private data
2383 * NOTE: We only support a single virtual interface, so wiphy
2384 * and wireless_dev are somewhat synonymous for this device.
2385 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002386 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002387 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002388 return -ENOMEM;
2389
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002390 priv = wiphy_priv(wiphy);
2391 usbdev->net->ieee80211_ptr = &priv->wdev;
2392 priv->wdev.wiphy = wiphy;
2393 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2394
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002395 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002396 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002397 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002398 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002399 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2400 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002401
2402 mutex_init(&priv->command_lock);
2403 spin_lock_init(&priv->stats_lock);
2404
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002405 /* because rndis_command() sleeps we need to use workqueue */
2406 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002407 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002408 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2409 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2410
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002411 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002412 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002413 if (retval < 0)
2414 goto fail;
2415
2416 /* generic_rndis_bind set packet filter to multicast_all+
2417 * promisc mode which doesn't work well for our devices (device
2418 * picks up rssi to closest station instead of to access point).
2419 *
2420 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002421 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002422 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002423 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07002424
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002425 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002426 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002427 sizeof(tmp));
2428
2429 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002430 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2431 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002432 priv->multicast_size = le32_to_cpu(tmp);
2433 if (retval < 0 || priv->multicast_size < 0)
2434 priv->multicast_size = 0;
2435 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002436 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002437 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002438 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002439
2440 priv->iwstats.qual.qual = 0;
2441 priv->iwstats.qual.level = 0;
2442 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2443 | IW_QUAL_LEVEL_UPDATED
2444 | IW_QUAL_NOISE_INVALID
2445 | IW_QUAL_QUAL_INVALID
2446 | IW_QUAL_LEVEL_INVALID;
2447
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002448 /* fill-out wiphy structure and register w/ cfg80211 */
2449 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2450 wiphy->privid = rndis_wiphy_privid;
2451 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2452 | BIT(NL80211_IFTYPE_ADHOC);
2453 wiphy->max_scan_ssids = 1;
2454
2455 /* TODO: fill-out band information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002456 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002457
2458 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2459 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2460 priv->band.channels = priv->channels;
2461 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2462 priv->band.bitrates = priv->rates;
2463 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2464 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002465 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002466
2467 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2468
2469 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002470 retval = -ENODEV;
2471 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002472 }
2473
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002474 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002475
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002476 /* set default rts/frag */
2477 rndis_set_wiphy_params(wiphy,
2478 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2479
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002480 /* turn radio on */
2481 priv->radio_on = 1;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002482 disassociate(usbdev, 1);
2483 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002484
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002485 return 0;
2486
2487fail:
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002488 cancel_delayed_work_sync(&priv->stats_work);
2489 cancel_delayed_work_sync(&priv->scan_work);
2490 cancel_work_sync(&priv->work);
2491 flush_workqueue(priv->workqueue);
2492 destroy_workqueue(priv->workqueue);
2493
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002494 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002495 return retval;
2496}
2497
2498
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002499static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002500{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002501 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002502
2503 /* turn radio off */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002504 disassociate(usbdev, 0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002505
2506 cancel_delayed_work_sync(&priv->stats_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002507 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002508 cancel_work_sync(&priv->work);
2509 flush_workqueue(priv->workqueue);
2510 destroy_workqueue(priv->workqueue);
2511
2512 if (priv && priv->wpa_ie_len)
2513 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002514
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002515 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002516
2517 wiphy_unregister(priv->wdev.wiphy);
2518 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002519}
2520
2521
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002522static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002523{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002524 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002525 int retval;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002526
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002527 devdbg(usbdev, "rndis_wlan_reset");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002528
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002529 retval = rndis_reset(usbdev);
2530 if (retval)
2531 devwarn(usbdev, "rndis_reset() failed: %d", retval);
2532
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03002533 /* rndis_reset cleared multicast list, so restore here.
2534 (set_multicast_list() also turns on current packet filter) */
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002535 set_multicast_list(usbdev);
2536
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002537 queue_delayed_work(priv->workqueue, &priv->stats_work,
2538 round_jiffies_relative(STATS_UPDATE_JIFFIES));
2539
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002540 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002541}
2542
2543
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002544static int rndis_wlan_stop(struct usbnet *usbdev)
2545{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002546 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2547 int retval;
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03002548 __le32 filter;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002549
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002550 devdbg(usbdev, "rndis_wlan_stop");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002551
2552 retval = disassociate(usbdev, 0);
2553
2554 priv->work_pending = 0;
2555 cancel_delayed_work_sync(&priv->stats_work);
2556 cancel_delayed_work_sync(&priv->scan_work);
2557 cancel_work_sync(&priv->work);
2558 flush_workqueue(priv->workqueue);
2559
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03002560 if (priv->scan_request) {
2561 cfg80211_scan_done(priv->scan_request, true);
2562 priv->scan_request = NULL;
2563 }
2564
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03002565 /* Set current packet filter zero to block receiving data packets from
2566 device. */
2567 filter = 0;
2568 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
2569 sizeof(filter));
2570
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002571 return retval;
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002572}
2573
2574
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002575static const struct driver_info bcm4320b_info = {
2576 .description = "Wireless RNDIS device, BCM4320b based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002577 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2578 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002579 .bind = rndis_wlan_bind,
2580 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002581 .status = rndis_status,
2582 .rx_fixup = rndis_rx_fixup,
2583 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002584 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002585 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002586 .early_init = bcm4320b_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002587 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002588};
2589
2590static const struct driver_info bcm4320a_info = {
2591 .description = "Wireless RNDIS device, BCM4320a based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002592 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2593 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002594 .bind = rndis_wlan_bind,
2595 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002596 .status = rndis_status,
2597 .rx_fixup = rndis_rx_fixup,
2598 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002599 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002600 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002601 .early_init = bcm4320a_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002602 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002603};
2604
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002605static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002606 .description = "Wireless RNDIS device",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002607 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2608 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002609 .bind = rndis_wlan_bind,
2610 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002611 .status = rndis_status,
2612 .rx_fixup = rndis_rx_fixup,
2613 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002614 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002615 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002616 .early_init = bcm4320a_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002617 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002618};
2619
2620/*-------------------------------------------------------------------------*/
2621
2622static const struct usb_device_id products [] = {
2623#define RNDIS_MASTER_INTERFACE \
2624 .bInterfaceClass = USB_CLASS_COMM, \
2625 .bInterfaceSubClass = 2 /* ACM */, \
2626 .bInterfaceProtocol = 0x0ff
2627
2628/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2629 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2630 */
2631{
2632 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2633 | USB_DEVICE_ID_MATCH_DEVICE,
2634 .idVendor = 0x0411,
2635 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
2636 RNDIS_MASTER_INTERFACE,
2637 .driver_info = (unsigned long) &bcm4320b_info,
2638}, {
2639 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2640 | USB_DEVICE_ID_MATCH_DEVICE,
2641 .idVendor = 0x0baf,
2642 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
2643 RNDIS_MASTER_INTERFACE,
2644 .driver_info = (unsigned long) &bcm4320b_info,
2645}, {
2646 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2647 | USB_DEVICE_ID_MATCH_DEVICE,
2648 .idVendor = 0x050d,
2649 .idProduct = 0x011b, /* Belkin F5D7051 */
2650 RNDIS_MASTER_INTERFACE,
2651 .driver_info = (unsigned long) &bcm4320b_info,
2652}, {
2653 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2654 | USB_DEVICE_ID_MATCH_DEVICE,
2655 .idVendor = 0x1799, /* Belkin has two vendor ids */
2656 .idProduct = 0x011b, /* Belkin F5D7051 */
2657 RNDIS_MASTER_INTERFACE,
2658 .driver_info = (unsigned long) &bcm4320b_info,
2659}, {
2660 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2661 | USB_DEVICE_ID_MATCH_DEVICE,
2662 .idVendor = 0x13b1,
2663 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
2664 RNDIS_MASTER_INTERFACE,
2665 .driver_info = (unsigned long) &bcm4320b_info,
2666}, {
2667 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2668 | USB_DEVICE_ID_MATCH_DEVICE,
2669 .idVendor = 0x13b1,
2670 .idProduct = 0x0026, /* Linksys WUSB54GSC */
2671 RNDIS_MASTER_INTERFACE,
2672 .driver_info = (unsigned long) &bcm4320b_info,
2673}, {
2674 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2675 | USB_DEVICE_ID_MATCH_DEVICE,
2676 .idVendor = 0x0b05,
2677 .idProduct = 0x1717, /* Asus WL169gE */
2678 RNDIS_MASTER_INTERFACE,
2679 .driver_info = (unsigned long) &bcm4320b_info,
2680}, {
2681 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2682 | USB_DEVICE_ID_MATCH_DEVICE,
2683 .idVendor = 0x0a5c,
2684 .idProduct = 0xd11b, /* Eminent EM4045 */
2685 RNDIS_MASTER_INTERFACE,
2686 .driver_info = (unsigned long) &bcm4320b_info,
2687}, {
2688 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2689 | USB_DEVICE_ID_MATCH_DEVICE,
2690 .idVendor = 0x1690,
2691 .idProduct = 0x0715, /* BT Voyager 1055 */
2692 RNDIS_MASTER_INTERFACE,
2693 .driver_info = (unsigned long) &bcm4320b_info,
2694},
2695/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
2696 * parameters available, hardware probably contain older firmware version with
2697 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
2698 */
2699{
2700 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2701 | USB_DEVICE_ID_MATCH_DEVICE,
2702 .idVendor = 0x13b1,
2703 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
2704 RNDIS_MASTER_INTERFACE,
2705 .driver_info = (unsigned long) &bcm4320a_info,
2706}, {
2707 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2708 | USB_DEVICE_ID_MATCH_DEVICE,
2709 .idVendor = 0x0baf,
2710 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
2711 RNDIS_MASTER_INTERFACE,
2712 .driver_info = (unsigned long) &bcm4320a_info,
2713}, {
2714 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2715 | USB_DEVICE_ID_MATCH_DEVICE,
2716 .idVendor = 0x0411,
2717 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
2718 RNDIS_MASTER_INTERFACE,
2719 .driver_info = (unsigned long) &bcm4320a_info,
2720},
2721/* Generic Wireless RNDIS devices that we don't have exact
2722 * idVendor/idProduct/chip yet.
2723 */
2724{
2725 /* RNDIS is MSFT's un-official variant of CDC ACM */
2726 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002727 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002728}, {
2729 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
2730 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002731 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002732},
2733 { }, // END
2734};
2735MODULE_DEVICE_TABLE(usb, products);
2736
2737static struct usb_driver rndis_wlan_driver = {
2738 .name = "rndis_wlan",
2739 .id_table = products,
2740 .probe = usbnet_probe,
2741 .disconnect = usbnet_disconnect,
2742 .suspend = usbnet_suspend,
2743 .resume = usbnet_resume,
2744};
2745
2746static int __init rndis_wlan_init(void)
2747{
2748 return usb_register(&rndis_wlan_driver);
2749}
2750module_init(rndis_wlan_init);
2751
2752static void __exit rndis_wlan_exit(void)
2753{
2754 usb_deregister(&rndis_wlan_driver);
2755}
2756module_exit(rndis_wlan_exit);
2757
2758MODULE_AUTHOR("Bjorge Dijkstra");
2759MODULE_AUTHOR("Jussi Kivilinna");
2760MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
2761MODULE_LICENSE("GPL");
2762