blob: 54175b6fa86c2937342ee52c52bd3c47c99a1dcd [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_CURRENT_ADDRESS cpu_to_le32(0x01010102)
104#define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
105#define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200106
Harvey Harrison35c26c22009-02-14 22:56:56 -0800107#define OID_802_11_BSSID cpu_to_le32(0x0d010101)
108#define OID_802_11_SSID cpu_to_le32(0x0d010102)
109#define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
110#define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
111#define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
112#define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
113#define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
114#define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
115#define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
116#define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
117#define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
118#define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
119#define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
120#define OID_802_11_PMKID cpu_to_le32(0x0d010123)
121#define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
122#define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
123#define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
124#define OID_802_11_RSSI cpu_to_le32(0x0d010206)
125#define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
126#define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
127#define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
128#define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
129#define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
130#define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200131
132
133/* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
134#define WL_NOISE -96 /* typical noise level in dBm */
135#define WL_SIGMAX -32 /* typical maximum signal level in dBm */
136
137
138/* Assume that Broadcom 4320 (only chipset at time of writing known to be
139 * based on wireless rndis) has default txpower of 13dBm.
140 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300141 * 100% : 20 mW ~ 13dBm
142 * 75% : 15 mW ~ 12dBm
143 * 50% : 10 mW ~ 10dBm
144 * 25% : 5 mW ~ 7dBm
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200145 */
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300146#define BCM4320_DEFAULT_TXPOWER_DBM_100 13
147#define BCM4320_DEFAULT_TXPOWER_DBM_75 12
148#define BCM4320_DEFAULT_TXPOWER_DBM_50 10
149#define BCM4320_DEFAULT_TXPOWER_DBM_25 7
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200150
151
152/* codes for "status" field of completion messages */
Harvey Harrison35c26c22009-02-14 22:56:56 -0800153#define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
154#define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200155
156
157/* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
158 * slightly modified for datatype endianess, etc
159 */
160#define NDIS_802_11_LENGTH_SSID 32
161#define NDIS_802_11_LENGTH_RATES 8
162#define NDIS_802_11_LENGTH_RATES_EX 16
163
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200164enum ndis_80211_net_type {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300165 NDIS_80211_TYPE_FREQ_HOP,
166 NDIS_80211_TYPE_DIRECT_SEQ,
167 NDIS_80211_TYPE_OFDM_A,
168 NDIS_80211_TYPE_OFDM_G
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200169};
170
171enum ndis_80211_net_infra {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300172 NDIS_80211_INFRA_ADHOC,
173 NDIS_80211_INFRA_INFRA,
174 NDIS_80211_INFRA_AUTO_UNKNOWN
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200175};
176
177enum ndis_80211_auth_mode {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300178 NDIS_80211_AUTH_OPEN,
179 NDIS_80211_AUTH_SHARED,
180 NDIS_80211_AUTH_AUTO_SWITCH,
181 NDIS_80211_AUTH_WPA,
182 NDIS_80211_AUTH_WPA_PSK,
183 NDIS_80211_AUTH_WPA_NONE,
184 NDIS_80211_AUTH_WPA2,
185 NDIS_80211_AUTH_WPA2_PSK
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200186};
187
188enum ndis_80211_encr_status {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300189 NDIS_80211_ENCR_WEP_ENABLED,
190 NDIS_80211_ENCR_DISABLED,
191 NDIS_80211_ENCR_WEP_KEY_ABSENT,
192 NDIS_80211_ENCR_NOT_SUPPORTED,
193 NDIS_80211_ENCR_TKIP_ENABLED,
194 NDIS_80211_ENCR_TKIP_KEY_ABSENT,
195 NDIS_80211_ENCR_CCMP_ENABLED,
196 NDIS_80211_ENCR_CCMP_KEY_ABSENT
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200197};
198
199enum ndis_80211_priv_filter {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300200 NDIS_80211_PRIV_ACCEPT_ALL,
201 NDIS_80211_PRIV_8021X_WEP
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200202};
203
Jussi Kivilinna030645a2009-07-30 19:41:58 +0300204enum ndis_80211_status_type {
205 NDIS_80211_STATUSTYPE_AUTHENTICATION,
206 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE,
207 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST,
208 NDIS_80211_STATUSTYPE_RADIOSTATE,
209};
210
211enum ndis_80211_media_stream_mode {
212 NDIS_80211_MEDIA_STREAM_OFF,
213 NDIS_80211_MEDIA_STREAM_ON
214};
215
216enum ndis_80211_radio_status {
217 NDIS_80211_RADIO_STATUS_ON,
218 NDIS_80211_RADIO_STATUS_HARDWARE_OFF,
219 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF,
220};
221
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300222enum ndis_80211_addkey_bits {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300223 NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
224 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
225 NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
226 NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300227};
228
229enum ndis_80211_addwep_bits {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300230 NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
231 NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300232};
233
Jussi Kivilinna030645a2009-07-30 19:41:58 +0300234struct ndis_80211_auth_request {
235 __le32 length;
236 u8 bssid[6];
237 u8 padding[2];
238 __le32 flags;
239} __attribute__((packed));
240
241struct ndis_80211_pmkid_candidate {
242 u8 bssid[6];
243 u8 padding[2];
244 __le32 flags;
245} __attribute__((packed));
246
247struct ndis_80211_pmkid_cand_list {
248 __le32 version;
249 __le32 num_candidates;
250 struct ndis_80211_pmkid_candidate candidate_list[0];
251} __attribute__((packed));
252
253struct ndis_80211_status_indication {
254 __le32 status_type;
255 union {
Jussi Kivilinna53d27ea2009-09-01 15:33:06 +0300256 __le32 media_stream_mode;
257 __le32 radio_status;
Jussi Kivilinna030645a2009-07-30 19:41:58 +0300258 struct ndis_80211_auth_request auth_request[0];
259 struct ndis_80211_pmkid_cand_list cand_list;
260 } u;
261} __attribute__((packed));
262
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200263struct ndis_80211_ssid {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200264 __le32 length;
265 u8 essid[NDIS_802_11_LENGTH_SSID];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200266} __attribute__((packed));
267
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200268struct ndis_80211_conf_freq_hop {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200269 __le32 length;
270 __le32 hop_pattern;
271 __le32 hop_set;
272 __le32 dwell_time;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200273} __attribute__((packed));
274
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200275struct ndis_80211_conf {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200276 __le32 length;
277 __le32 beacon_period;
278 __le32 atim_window;
279 __le32 ds_config;
280 struct ndis_80211_conf_freq_hop fh_config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200281} __attribute__((packed));
282
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200283struct ndis_80211_bssid_ex {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200284 __le32 length;
285 u8 mac[6];
286 u8 padding[2];
287 struct ndis_80211_ssid ssid;
288 __le32 privacy;
289 __le32 rssi;
290 __le32 net_type;
291 struct ndis_80211_conf config;
292 __le32 net_infra;
293 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
294 __le32 ie_length;
295 u8 ies[0];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200296} __attribute__((packed));
297
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200298struct ndis_80211_bssid_list_ex {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200299 __le32 num_items;
300 struct ndis_80211_bssid_ex bssid[0];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200301} __attribute__((packed));
302
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200303struct ndis_80211_fixed_ies {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200304 u8 timestamp[8];
305 __le16 beacon_interval;
306 __le16 capabilities;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200307} __attribute__((packed));
308
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200309struct ndis_80211_wep_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200310 __le32 size;
311 __le32 index;
312 __le32 length;
313 u8 material[32];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200314} __attribute__((packed));
315
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200316struct ndis_80211_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200317 __le32 size;
318 __le32 index;
319 __le32 length;
320 u8 bssid[6];
321 u8 padding[6];
322 u8 rsc[8];
323 u8 material[32];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200324} __attribute__((packed));
325
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200326struct ndis_80211_remove_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200327 __le32 size;
328 __le32 index;
329 u8 bssid[6];
Jussi Kivilinna9d409342009-07-30 19:42:03 +0300330 u8 padding[2];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200331} __attribute__((packed));
332
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200333struct ndis_config_param {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200334 __le32 name_offs;
335 __le32 name_length;
336 __le32 type;
337 __le32 value_offs;
338 __le32 value_length;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200339} __attribute__((packed));
340
Scott Ashcroft43646232008-05-27 00:06:15 +0300341struct ndis_80211_assoc_info {
342 __le32 length;
343 __le16 req_ies;
344 struct req_ie {
345 __le16 capa;
346 __le16 listen_interval;
347 u8 cur_ap_address[6];
348 } req_ie;
349 __le32 req_ie_length;
350 __le32 offset_req_ies;
351 __le16 resp_ies;
352 struct resp_ie {
353 __le16 capa;
354 __le16 status_code;
355 __le16 assoc_id;
356 } resp_ie;
357 __le32 resp_ie_length;
358 __le32 offset_resp_ies;
359} __attribute__((packed));
360
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200361/*
362 * private data
363 */
364#define NET_TYPE_11FB 0
365
366#define CAP_MODE_80211A 1
367#define CAP_MODE_80211B 2
368#define CAP_MODE_80211G 4
369#define CAP_MODE_MASK 7
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200370
Jussi Kivilinna6010ce02008-06-02 18:35:21 +0300371#define WORK_LINK_UP (1<<0)
372#define WORK_LINK_DOWN (1<<1)
373#define WORK_SET_MULTICAST_LIST (1<<2)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200374
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300375#define RNDIS_WLAN_ALG_NONE 0
376#define RNDIS_WLAN_ALG_WEP (1<<0)
377#define RNDIS_WLAN_ALG_TKIP (1<<1)
378#define RNDIS_WLAN_ALG_CCMP (1<<2)
379
380#define RNDIS_WLAN_KEY_MGMT_NONE 0
381#define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
382#define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
383
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300384#define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
385
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200386static const struct ieee80211_channel rndis_channels[] = {
387 { .center_freq = 2412 },
388 { .center_freq = 2417 },
389 { .center_freq = 2422 },
390 { .center_freq = 2427 },
391 { .center_freq = 2432 },
392 { .center_freq = 2437 },
393 { .center_freq = 2442 },
394 { .center_freq = 2447 },
395 { .center_freq = 2452 },
396 { .center_freq = 2457 },
397 { .center_freq = 2462 },
398 { .center_freq = 2467 },
399 { .center_freq = 2472 },
400 { .center_freq = 2484 },
401};
402
403static const struct ieee80211_rate rndis_rates[] = {
404 { .bitrate = 10 },
405 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
406 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
407 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
408 { .bitrate = 60 },
409 { .bitrate = 90 },
410 { .bitrate = 120 },
411 { .bitrate = 180 },
412 { .bitrate = 240 },
413 { .bitrate = 360 },
414 { .bitrate = 480 },
415 { .bitrate = 540 }
416};
417
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +0300418static const u32 rndis_cipher_suites[] = {
419 WLAN_CIPHER_SUITE_WEP40,
420 WLAN_CIPHER_SUITE_WEP104,
421 WLAN_CIPHER_SUITE_TKIP,
422 WLAN_CIPHER_SUITE_CCMP,
423};
424
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300425struct rndis_wlan_encr_key {
426 int len;
Jussi Kivilinna84bf8402009-08-28 13:27:58 +0300427 u32 cipher;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300428 u8 material[32];
429 u8 bssid[ETH_ALEN];
430 bool pairwise;
431 bool tx_key;
432};
433
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200434/* RNDIS device private data */
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300435struct rndis_wlan_private {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200436 struct usbnet *usbdev;
437
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200438 struct wireless_dev wdev;
439
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200440 struct cfg80211_scan_request *scan_request;
441
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200442 struct workqueue_struct *workqueue;
Jussi Kivilinna305e2432009-08-28 13:28:14 +0300443 struct delayed_work dev_poller_work;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200444 struct delayed_work scan_work;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200445 struct work_struct work;
446 struct mutex command_lock;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200447 unsigned long work_pending;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +0300448 int last_qual;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200449
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200450 struct ieee80211_supported_band band;
451 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
452 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +0300453 u32 cipher_suites[ARRAY_SIZE(rndis_cipher_suites)];
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200454
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200455 int caps;
456 int multicast_size;
457
458 /* module parameters */
459 char param_country[4];
460 int param_frameburst;
461 int param_afterburner;
462 int param_power_save;
463 int param_power_output;
464 int param_roamtrigger;
465 int param_roamdelta;
466 u32 param_workaround_interval;
467
468 /* hardware state */
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +0300469 bool radio_on;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200470 int infra_mode;
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300471 bool connected;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +0300472 u8 bssid[ETH_ALEN];
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200473 struct ndis_80211_ssid essid;
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300474 __le32 current_command_oid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200475
476 /* encryption stuff */
477 int encr_tx_key_index;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300478 struct rndis_wlan_encr_key encr_keys[4];
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300479 enum nl80211_auth_type wpa_auth_type;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200480 int wpa_version;
481 int wpa_keymgmt;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200482 int wpa_ie_len;
483 u8 *wpa_ie;
484 int wpa_cipher_pair;
485 int wpa_cipher_group;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300486
487 u8 command_buffer[COMMAND_BUFFER_SIZE];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200488};
489
John W. Linville964c1d42009-03-26 23:40:01 +0200490/*
491 * cfg80211 ops
492 */
Johannes Berge36d56b2009-06-09 21:04:43 +0200493static int rndis_change_virtual_intf(struct wiphy *wiphy,
494 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +0200495 enum nl80211_iftype type, u32 *flags,
496 struct vif_params *params);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200497
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200498static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
499 struct cfg80211_scan_request *request);
500
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +0300501static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
502
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300503static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
504 int dbm);
505static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
506
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300507static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
508 struct cfg80211_connect_params *sme);
509
510static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
511 u16 reason_code);
512
513static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
514 struct cfg80211_ibss_params *params);
515
516static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev);
517
Jussi Kivilinna5554adb2009-08-28 13:27:53 +0300518static int rndis_set_channel(struct wiphy *wiphy,
519 struct ieee80211_channel *chan, enum nl80211_channel_type channel_type);
520
Jussi Kivilinna84bf8402009-08-28 13:27:58 +0300521static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
522 u8 key_index, const u8 *mac_addr,
523 struct key_params *params);
524
525static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
526 u8 key_index, const u8 *mac_addr);
527
528static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
529 u8 key_index);
530
Jussi Kivilinna8b89a282009-08-28 13:28:03 +0300531static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
532 u8 *mac, struct station_info *sinfo);
533
Jussi Kivilinnad695df92009-08-28 13:28:09 +0300534static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
535 int idx, u8 *mac, struct station_info *sinfo);
536
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200537static struct cfg80211_ops rndis_config_ops = {
John W. Linville964c1d42009-03-26 23:40:01 +0200538 .change_virtual_intf = rndis_change_virtual_intf,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200539 .scan = rndis_scan,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +0300540 .set_wiphy_params = rndis_set_wiphy_params,
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300541 .set_tx_power = rndis_set_tx_power,
542 .get_tx_power = rndis_get_tx_power,
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300543 .connect = rndis_connect,
544 .disconnect = rndis_disconnect,
545 .join_ibss = rndis_join_ibss,
546 .leave_ibss = rndis_leave_ibss,
Jussi Kivilinna5554adb2009-08-28 13:27:53 +0300547 .set_channel = rndis_set_channel,
Jussi Kivilinna84bf8402009-08-28 13:27:58 +0300548 .add_key = rndis_add_key,
549 .del_key = rndis_del_key,
550 .set_default_key = rndis_set_default_key,
Jussi Kivilinna8b89a282009-08-28 13:28:03 +0300551 .get_station = rndis_get_station,
Jussi Kivilinnad695df92009-08-28 13:28:09 +0300552 .dump_station = rndis_dump_station,
John W. Linville964c1d42009-03-26 23:40:01 +0200553};
554
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200555static void *rndis_wiphy_privid = &rndis_wiphy_privid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200556
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200557
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300558static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200559{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300560 return (struct rndis_wlan_private *)dev->driver_priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200561}
562
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300563static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200564{
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300565 switch (priv->param_power_output) {
566 default:
567 case 3:
568 return BCM4320_DEFAULT_TXPOWER_DBM_100;
569 case 2:
570 return BCM4320_DEFAULT_TXPOWER_DBM_75;
571 case 1:
572 return BCM4320_DEFAULT_TXPOWER_DBM_50;
573 case 0:
574 return BCM4320_DEFAULT_TXPOWER_DBM_25;
575 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200576}
577
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300578static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
579{
580 int cipher = priv->encr_keys[idx].cipher;
581
582 return (cipher == WLAN_CIPHER_SUITE_CCMP ||
583 cipher == WLAN_CIPHER_SUITE_TKIP);
584}
585
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300586static int rndis_cipher_to_alg(u32 cipher)
587{
588 switch (cipher) {
589 default:
590 return RNDIS_WLAN_ALG_NONE;
591 case WLAN_CIPHER_SUITE_WEP40:
592 case WLAN_CIPHER_SUITE_WEP104:
593 return RNDIS_WLAN_ALG_WEP;
594 case WLAN_CIPHER_SUITE_TKIP:
595 return RNDIS_WLAN_ALG_TKIP;
596 case WLAN_CIPHER_SUITE_CCMP:
597 return RNDIS_WLAN_ALG_CCMP;
598 }
599}
600
601static int rndis_akm_suite_to_key_mgmt(u32 akm_suite)
602{
603 switch (akm_suite) {
604 default:
605 return RNDIS_WLAN_KEY_MGMT_NONE;
606 case WLAN_AKM_SUITE_8021X:
607 return RNDIS_WLAN_KEY_MGMT_802_1X;
608 case WLAN_AKM_SUITE_PSK:
609 return RNDIS_WLAN_KEY_MGMT_PSK;
610 }
611}
612
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300613#ifdef DEBUG
614static const char *oid_to_string(__le32 oid)
615{
616 switch (oid) {
617#define OID_STR(oid) case oid: return(#oid)
618 /* from rndis_host.h */
619 OID_STR(OID_802_3_PERMANENT_ADDRESS);
620 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
621 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
622 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
623
624 /* from rndis_wlan.c */
625 OID_STR(OID_GEN_LINK_SPEED);
626 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
627
628 OID_STR(OID_GEN_XMIT_OK);
629 OID_STR(OID_GEN_RCV_OK);
630 OID_STR(OID_GEN_XMIT_ERROR);
631 OID_STR(OID_GEN_RCV_ERROR);
632 OID_STR(OID_GEN_RCV_NO_BUFFER);
633
634 OID_STR(OID_802_3_CURRENT_ADDRESS);
635 OID_STR(OID_802_3_MULTICAST_LIST);
636 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
637
638 OID_STR(OID_802_11_BSSID);
639 OID_STR(OID_802_11_SSID);
640 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
641 OID_STR(OID_802_11_ADD_WEP);
642 OID_STR(OID_802_11_REMOVE_WEP);
643 OID_STR(OID_802_11_DISASSOCIATE);
644 OID_STR(OID_802_11_AUTHENTICATION_MODE);
645 OID_STR(OID_802_11_PRIVACY_FILTER);
646 OID_STR(OID_802_11_BSSID_LIST_SCAN);
647 OID_STR(OID_802_11_ENCRYPTION_STATUS);
648 OID_STR(OID_802_11_ADD_KEY);
649 OID_STR(OID_802_11_REMOVE_KEY);
650 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
651 OID_STR(OID_802_11_PMKID);
652 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
653 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
654 OID_STR(OID_802_11_TX_POWER_LEVEL);
655 OID_STR(OID_802_11_RSSI);
656 OID_STR(OID_802_11_RSSI_TRIGGER);
657 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
658 OID_STR(OID_802_11_RTS_THRESHOLD);
659 OID_STR(OID_802_11_SUPPORTED_RATES);
660 OID_STR(OID_802_11_CONFIGURATION);
661 OID_STR(OID_802_11_BSSID_LIST);
662#undef OID_STR
663 }
664
665 return "?";
666}
667#else
668static const char *oid_to_string(__le32 oid)
669{
670 return "?";
671}
672#endif
673
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200674/* translate error code */
675static int rndis_error_status(__le32 rndis_status)
676{
677 int ret = -EINVAL;
678 switch (rndis_status) {
679 case RNDIS_STATUS_SUCCESS:
680 ret = 0;
681 break;
682 case RNDIS_STATUS_FAILURE:
683 case RNDIS_STATUS_INVALID_DATA:
684 ret = -EINVAL;
685 break;
686 case RNDIS_STATUS_NOT_SUPPORTED:
687 ret = -EOPNOTSUPP;
688 break;
689 case RNDIS_STATUS_ADAPTER_NOT_READY:
690 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
691 ret = -EBUSY;
692 break;
693 }
694 return ret;
695}
696
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200697static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
698{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300699 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200700 union {
701 void *buf;
702 struct rndis_msg_hdr *header;
703 struct rndis_query *get;
704 struct rndis_query_c *get_c;
705 } u;
706 int ret, buflen;
707
708 buflen = *len + sizeof(*u.get);
709 if (buflen < CONTROL_BUFFER_SIZE)
710 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300711
712 if (buflen > COMMAND_BUFFER_SIZE) {
713 u.buf = kmalloc(buflen, GFP_KERNEL);
714 if (!u.buf)
715 return -ENOMEM;
716 } else {
717 u.buf = priv->command_buffer;
718 }
719
720 mutex_lock(&priv->command_lock);
721
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200722 memset(u.get, 0, sizeof *u.get);
723 u.get->msg_type = RNDIS_MSG_QUERY;
Harvey Harrison35c26c22009-02-14 22:56:56 -0800724 u.get->msg_len = cpu_to_le32(sizeof *u.get);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200725 u.get->oid = oid;
726
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300727 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300728 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300729 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300730 if (ret < 0)
731 devdbg(dev, "rndis_query_oid(%s): rndis_command() failed, %d "
732 "(%08x)", oid_to_string(oid), ret,
733 le32_to_cpu(u.get_c->status));
734
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200735 if (ret == 0) {
736 ret = le32_to_cpu(u.get_c->len);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +0300737 if (ret > *len)
738 *len = ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200739 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
740 ret = rndis_error_status(u.get_c->status);
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300741
742 if (ret < 0)
743 devdbg(dev, "rndis_query_oid(%s): device returned "
744 "error, 0x%08x (%d)", oid_to_string(oid),
745 le32_to_cpu(u.get_c->status), ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200746 }
747
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300748 mutex_unlock(&priv->command_lock);
749
750 if (u.buf != priv->command_buffer)
751 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200752 return ret;
753}
754
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200755static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
756{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300757 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200758 union {
759 void *buf;
760 struct rndis_msg_hdr *header;
761 struct rndis_set *set;
762 struct rndis_set_c *set_c;
763 } u;
764 int ret, buflen;
765
766 buflen = len + sizeof(*u.set);
767 if (buflen < CONTROL_BUFFER_SIZE)
768 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300769
770 if (buflen > COMMAND_BUFFER_SIZE) {
771 u.buf = kmalloc(buflen, GFP_KERNEL);
772 if (!u.buf)
773 return -ENOMEM;
774 } else {
775 u.buf = priv->command_buffer;
776 }
777
778 mutex_lock(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200779
780 memset(u.set, 0, sizeof *u.set);
781 u.set->msg_type = RNDIS_MSG_SET;
782 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
783 u.set->oid = oid;
784 u.set->len = cpu_to_le32(len);
Harvey Harrison35c26c22009-02-14 22:56:56 -0800785 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
786 u.set->handle = cpu_to_le32(0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200787 memcpy(u.buf + sizeof(*u.set), data, len);
788
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300789 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300790 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300791 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300792 if (ret < 0)
793 devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
794 "(%08x)", oid_to_string(oid), ret,
795 le32_to_cpu(u.set_c->status));
796
797 if (ret == 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200798 ret = rndis_error_status(u.set_c->status);
799
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300800 if (ret < 0)
801 devdbg(dev, "rndis_set_oid(%s): device returned error, "
802 "0x%08x (%d)", oid_to_string(oid),
803 le32_to_cpu(u.set_c->status), ret);
804 }
805
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300806 mutex_unlock(&priv->command_lock);
807
808 if (u.buf != priv->command_buffer)
809 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200810 return ret;
811}
812
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300813static int rndis_reset(struct usbnet *usbdev)
814{
815 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
816 struct rndis_reset *reset;
817 int ret;
818
819 mutex_lock(&priv->command_lock);
820
821 reset = (void *)priv->command_buffer;
822 memset(reset, 0, sizeof(*reset));
823 reset->msg_type = RNDIS_MSG_RESET;
824 reset->msg_len = cpu_to_le32(sizeof(*reset));
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300825 priv->current_command_oid = 0;
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300826 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
827
828 mutex_unlock(&priv->command_lock);
829
830 if (ret < 0)
831 return ret;
832 return 0;
833}
834
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200835/*
836 * Specs say that we can only set config parameters only soon after device
837 * initialization.
838 * value_type: 0 = u32, 2 = unicode string
839 */
840static int rndis_set_config_parameter(struct usbnet *dev, char *param,
841 int value_type, void *value)
842{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200843 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200844 int value_len, info_len, param_len, ret, i;
845 __le16 *unibuf;
846 __le32 *dst_value;
847
848 if (value_type == 0)
849 value_len = sizeof(__le32);
850 else if (value_type == 2)
851 value_len = strlen(value) * sizeof(__le16);
852 else
853 return -EINVAL;
854
855 param_len = strlen(param) * sizeof(__le16);
856 info_len = sizeof(*infobuf) + param_len + value_len;
857
858#ifdef DEBUG
859 info_len += 12;
860#endif
861 infobuf = kmalloc(info_len, GFP_KERNEL);
862 if (!infobuf)
863 return -ENOMEM;
864
865#ifdef DEBUG
866 info_len -= 12;
867 /* extra 12 bytes are for padding (debug output) */
868 memset(infobuf, 0xCC, info_len + 12);
869#endif
870
871 if (value_type == 2)
872 devdbg(dev, "setting config parameter: %s, value: %s",
873 param, (u8 *)value);
874 else
875 devdbg(dev, "setting config parameter: %s, value: %d",
876 param, *(u32 *)value);
877
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200878 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
879 infobuf->name_length = cpu_to_le32(param_len);
880 infobuf->type = cpu_to_le32(value_type);
881 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
882 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200883
884 /* simple string to unicode string conversion */
885 unibuf = (void *)infobuf + sizeof(*infobuf);
886 for (i = 0; i < param_len / sizeof(__le16); i++)
887 unibuf[i] = cpu_to_le16(param[i]);
888
889 if (value_type == 2) {
890 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
891 for (i = 0; i < value_len / sizeof(__le16); i++)
892 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
893 } else {
894 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
895 *dst_value = cpu_to_le32(*(u32 *)value);
896 }
897
898#ifdef DEBUG
899 devdbg(dev, "info buffer (len: %d):", info_len);
900 for (i = 0; i < info_len; i += 12) {
901 u32 *tmp = (u32 *)((u8 *)infobuf + i);
902 devdbg(dev, "%08X:%08X:%08X",
903 cpu_to_be32(tmp[0]),
904 cpu_to_be32(tmp[1]),
905 cpu_to_be32(tmp[2]));
906 }
907#endif
908
909 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
910 infobuf, info_len);
911 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200912 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200913
914 kfree(infobuf);
915 return ret;
916}
917
918static int rndis_set_config_parameter_str(struct usbnet *dev,
919 char *param, char *value)
920{
Jussi Kivilinnac5c4fe92009-09-01 15:33:00 +0300921 return rndis_set_config_parameter(dev, param, 2, value);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200922}
923
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200924/*
925 * data conversion functions
926 */
927static int level_to_qual(int level)
928{
929 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
930 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
931}
932
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200933/*
934 * common functions
935 */
Jussi Kivilinna9f77cca2009-08-28 12:59:26 +0300936static int set_infra_mode(struct usbnet *usbdev, int mode);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300937static void restore_keys(struct usbnet *usbdev);
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +0300938static int rndis_check_bssid_list(struct usbnet *usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200939
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200940static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200941{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300942 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200943 int ret;
944
945 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300946 if (ret < 0) {
947 devwarn(usbdev, "setting SSID failed (%08X)", ret);
948 return ret;
949 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200950 if (ret == 0) {
951 memcpy(&priv->essid, ssid, sizeof(priv->essid));
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +0300952 priv->radio_on = true;
953 devdbg(usbdev, "set_essid: radio_on = true");
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200954 }
955
956 return ret;
957}
958
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300959static int set_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
960{
961 int ret;
962
963 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
964 if (ret < 0) {
965 devwarn(usbdev, "setting BSSID[%pM] failed (%08X)", bssid, ret);
966 return ret;
967 }
968
969 return ret;
970}
971
972static int clear_bssid(struct usbnet *usbdev)
973{
974 u8 broadcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
975
976 return set_bssid(usbdev, broadcast_mac);
977}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200978
979static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
980{
981 int ret, len;
982
983 len = ETH_ALEN;
984 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
985
986 if (ret != 0)
987 memset(bssid, 0, ETH_ALEN);
988
989 return ret;
990}
991
Scott Ashcroft43646232008-05-27 00:06:15 +0300992static int get_association_info(struct usbnet *usbdev,
993 struct ndis_80211_assoc_info *info, int len)
994{
995 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
996 info, &len);
997}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200998
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300999static bool is_associated(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001000{
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001001 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001002 u8 bssid[ETH_ALEN];
1003 int ret;
1004
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001005 if (!priv->radio_on)
1006 return false;
1007
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001008 ret = get_bssid(usbdev, bssid);
1009
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001010 return (ret == 0 && !is_zero_ether_addr(bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001011}
1012
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03001013static int disassociate(struct usbnet *usbdev, bool reset_ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001014{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001015 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001016 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001017 int i, ret = 0;
1018
1019 if (priv->radio_on) {
1020 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
1021 if (ret == 0) {
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03001022 priv->radio_on = false;
1023 devdbg(usbdev, "disassociate: radio_on = false");
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001024
1025 if (reset_ssid)
1026 msleep(100);
1027 }
1028 }
1029
1030 /* disassociate causes radio to be turned off; if reset_ssid
1031 * is given, set random ssid to enable radio */
1032 if (reset_ssid) {
Jussi Kivilinna9f77cca2009-08-28 12:59:26 +03001033 /* Set device to infrastructure mode so we don't get ad-hoc
1034 * 'media connect' indications with the random ssid.
1035 */
1036 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1037
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001038 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1039 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1040 ssid.essid[0] = 0x1;
1041 ssid.essid[1] = 0xff;
1042 for (i = 2; i < sizeof(ssid.essid); i++)
1043 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001044 ret = set_essid(usbdev, &ssid);
1045 }
1046 return ret;
1047}
1048
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001049static int set_auth_mode(struct usbnet *usbdev, u32 wpa_version,
1050 enum nl80211_auth_type auth_type, int keymgmt)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001051{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001052 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001053 __le32 tmp;
1054 int auth_mode, ret;
1055
1056 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001057 "keymgmt=0x%x", wpa_version, auth_type, keymgmt);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001058
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001059 if (wpa_version & NL80211_WPA_VERSION_2) {
1060 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001061 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001062 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001063 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001064 } else if (wpa_version & NL80211_WPA_VERSION_1) {
1065 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001066 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001067 else if (keymgmt & RNDIS_WLAN_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001068 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001069 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001070 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001071 } else if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
1072 auth_mode = NDIS_80211_AUTH_SHARED;
1073 else if (auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001074 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001075 else
1076 return -ENOTSUPP;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001077
1078 tmp = cpu_to_le32(auth_mode);
1079 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1080 sizeof(tmp));
1081 if (ret != 0) {
1082 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
1083 return ret;
1084 }
1085
1086 priv->wpa_version = wpa_version;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001087 priv->wpa_auth_type = auth_type;
1088 priv->wpa_keymgmt = keymgmt;
1089
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001090 return 0;
1091}
1092
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001093static int set_priv_filter(struct usbnet *usbdev)
1094{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001095 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001096 __le32 tmp;
1097
1098 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
1099
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001100 if (priv->wpa_version & NL80211_WPA_VERSION_2 ||
1101 priv->wpa_version & NL80211_WPA_VERSION_1)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001102 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001103 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001104 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001105
1106 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1107 sizeof(tmp));
1108}
1109
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001110static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1111{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001112 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001113 __le32 tmp;
1114 int encr_mode, ret;
1115
1116 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001117 pairwise, groupwise);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001118
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001119 if (pairwise & RNDIS_WLAN_ALG_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001120 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001121 else if (pairwise & RNDIS_WLAN_ALG_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001122 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001123 else if (pairwise & RNDIS_WLAN_ALG_WEP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001124 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001125 else if (groupwise & RNDIS_WLAN_ALG_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001126 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001127 else if (groupwise & RNDIS_WLAN_ALG_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001128 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001129 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001130 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001131
1132 tmp = cpu_to_le32(encr_mode);
1133 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1134 sizeof(tmp));
1135 if (ret != 0) {
1136 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
1137 return ret;
1138 }
1139
1140 priv->wpa_cipher_pair = pairwise;
1141 priv->wpa_cipher_group = groupwise;
1142 return 0;
1143}
1144
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001145static int set_infra_mode(struct usbnet *usbdev, int mode)
1146{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001147 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001148 __le32 tmp;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001149 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001150
1151 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
1152
1153 tmp = cpu_to_le32(mode);
1154 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1155 sizeof(tmp));
1156 if (ret != 0) {
1157 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
1158 return ret;
1159 }
1160
1161 /* NDIS drivers clear keys when infrastructure mode is
1162 * changed. But Linux tools assume otherwise. So set the
1163 * keys */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001164 restore_keys(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001165
1166 priv->infra_mode = mode;
1167 return 0;
1168}
1169
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001170static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1171{
1172 __le32 tmp;
1173
1174 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1175
1176 if (rts_threshold < 0 || rts_threshold > 2347)
1177 rts_threshold = 2347;
1178
1179 tmp = cpu_to_le32(rts_threshold);
1180 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1181 sizeof(tmp));
1182}
1183
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001184static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1185{
1186 __le32 tmp;
1187
1188 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1189
1190 if (frag_threshold < 256 || frag_threshold > 2346)
1191 frag_threshold = 2346;
1192
1193 tmp = cpu_to_le32(frag_threshold);
1194 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1195 sizeof(tmp));
1196}
1197
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001198static void set_default_iw_params(struct usbnet *usbdev)
1199{
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001200 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001201 set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
1202 RNDIS_WLAN_KEY_MGMT_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001203 set_priv_filter(usbdev);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001204 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001205}
1206
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001207static int deauthenticate(struct usbnet *usbdev)
1208{
1209 int ret;
1210
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03001211 ret = disassociate(usbdev, true);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001212 set_default_iw_params(usbdev);
1213 return ret;
1214}
1215
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001216static int set_channel(struct usbnet *usbdev, int channel)
1217{
1218 struct ndis_80211_conf config;
1219 unsigned int dsconfig;
1220 int len, ret;
1221
1222 devdbg(usbdev, "set_channel(%d)", channel);
1223
1224 /* this OID is valid only when not associated */
1225 if (is_associated(usbdev))
1226 return 0;
1227
1228 dsconfig = ieee80211_dsss_chan_to_freq(channel) * 1000;
1229
1230 len = sizeof(config);
1231 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1232 if (ret < 0) {
1233 devdbg(usbdev, "set_channel: querying configuration failed");
1234 return ret;
1235 }
1236
1237 config.ds_config = cpu_to_le32(dsconfig);
1238 ret = rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
1239 sizeof(config));
1240
1241 devdbg(usbdev, "set_channel: %d -> %d", channel, ret);
1242
1243 return ret;
1244}
1245
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001246/* index must be 0 - N, as per NDIS */
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001247static int add_wep_key(struct usbnet *usbdev, const u8 *key, int key_len,
1248 int index)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001249{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001250 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001251 struct ndis_80211_wep_key ndis_key;
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001252 u32 cipher;
1253 int ret;
1254
1255 devdbg(usbdev, "add_wep_key(idx: %d, len: %d)", index, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001256
Jussi Kivilinna40ba60d2009-08-20 21:00:34 +03001257 if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001258 return -EINVAL;
1259
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001260 if (key_len == 5)
1261 cipher = WLAN_CIPHER_SUITE_WEP40;
1262 else
1263 cipher = WLAN_CIPHER_SUITE_WEP104;
1264
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001265 memset(&ndis_key, 0, sizeof(ndis_key));
1266
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001267 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1268 ndis_key.length = cpu_to_le32(key_len);
1269 ndis_key.index = cpu_to_le32(index);
1270 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001271
1272 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001273 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001274 ret = set_encr_mode(usbdev, RNDIS_WLAN_ALG_WEP,
1275 RNDIS_WLAN_ALG_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001276 if (ret)
1277 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1278 ret);
1279 }
1280
1281 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1282 sizeof(ndis_key));
1283 if (ret != 0) {
1284 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1285 index+1, ret);
1286 return ret;
1287 }
1288
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001289 priv->encr_keys[index].len = key_len;
1290 priv->encr_keys[index].cipher = cipher;
1291 memcpy(&priv->encr_keys[index].material, key, key_len);
1292 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001293
1294 return 0;
1295}
1296
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001297static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001298 int index, const u8 *addr, const u8 *rx_seq,
Jussi Kivilinna53d27ea2009-09-01 15:33:06 +03001299 int seq_len, u32 cipher, __le32 flags)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001300{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001301 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001302 struct ndis_80211_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001303 bool is_addr_ok;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001304 int ret;
1305
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001306 if (index < 0 || index >= 4) {
1307 devdbg(usbdev, "add_wpa_key: index out of range (%i)", index);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001308 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001309 }
1310 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1311 devdbg(usbdev, "add_wpa_key: key length out of range (%i)",
1312 key_len);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001313 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001314 }
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001315 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) {
1316 if (!rx_seq || seq_len <= 0) {
1317 devdbg(usbdev, "add_wpa_key: recv seq flag without"
1318 "buffer");
1319 return -EINVAL;
1320 }
1321 if (rx_seq && seq_len > sizeof(ndis_key.rsc)) {
1322 devdbg(usbdev, "add_wpa_key: too big recv seq buffer");
1323 return -EINVAL;
1324 }
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001325 }
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001326
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001327 is_addr_ok = addr && !is_zero_ether_addr(addr) &&
1328 !is_broadcast_ether_addr(addr);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001329 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1330 devdbg(usbdev, "add_wpa_key: pairwise but bssid invalid (%pM)",
1331 addr);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001332 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001333 }
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001334
1335 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001336 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1337 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1338 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001339
1340 memset(&ndis_key, 0, sizeof(ndis_key));
1341
1342 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1343 sizeof(ndis_key.material) + key_len);
1344 ndis_key.length = cpu_to_le32(key_len);
1345 ndis_key.index = cpu_to_le32(index) | flags;
1346
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001347 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001348 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1349 * different order than NDIS spec, so swap the order here. */
1350 memcpy(ndis_key.material, key, 16);
1351 memcpy(ndis_key.material + 16, key + 24, 8);
1352 memcpy(ndis_key.material + 24, key + 16, 8);
1353 } else
1354 memcpy(ndis_key.material, key, key_len);
1355
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001356 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001357 memcpy(ndis_key.rsc, rx_seq, seq_len);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001358
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001359 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001360 /* pairwise key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001361 memcpy(ndis_key.bssid, addr, ETH_ALEN);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001362 } else {
1363 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001364 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001365 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1366 else
1367 get_bssid(usbdev, ndis_key.bssid);
1368 }
1369
1370 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1371 le32_to_cpu(ndis_key.size));
1372 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1373 if (ret != 0)
1374 return ret;
1375
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001376 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1377 priv->encr_keys[index].len = key_len;
1378 priv->encr_keys[index].cipher = cipher;
1379 memcpy(&priv->encr_keys[index].material, key, key_len);
1380 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1381 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1382 else
1383 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinna98391782009-05-22 17:40:34 +03001384
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001385 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001386 priv->encr_tx_key_index = index;
1387
1388 return 0;
1389}
1390
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001391static int restore_key(struct usbnet *usbdev, int key_idx)
1392{
1393 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1394 struct rndis_wlan_encr_key key;
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001395
1396 if (is_wpa_key(priv, key_idx))
1397 return 0;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001398
1399 key = priv->encr_keys[key_idx];
1400
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001401 devdbg(usbdev, "restore_key: %i:%i", key_idx, key.len);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001402
1403 if (key.len == 0)
1404 return 0;
1405
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001406 return add_wep_key(usbdev, key.material, key.len, key_idx);
1407}
1408
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001409static void restore_keys(struct usbnet *usbdev)
1410{
1411 int i;
1412
1413 for (i = 0; i < 4; i++)
1414 restore_key(usbdev, i);
1415}
1416
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001417static void clear_key(struct rndis_wlan_private *priv, int idx)
1418{
1419 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1420}
1421
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001422/* remove_key is for both wep and wpa */
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001423static int remove_key(struct usbnet *usbdev, int index, const u8 *bssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001424{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001425 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001426 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001427 __le32 keyindex;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001428 bool is_wpa;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001429 int ret;
1430
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001431 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001432 return 0;
1433
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001434 is_wpa = is_wpa_key(priv, index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001435
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001436 devdbg(usbdev, "remove_key: %i:%s:%i", index, is_wpa ? "wpa" : "wep",
1437 priv->encr_keys[index].len);
1438
1439 clear_key(priv, index);
1440
1441 if (is_wpa) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001442 remove_key.size = cpu_to_le32(sizeof(remove_key));
1443 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001444 if (bssid) {
1445 /* pairwise key */
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001446 if (!is_broadcast_ether_addr(bssid))
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001447 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001448 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001449 memcpy(remove_key.bssid, bssid,
1450 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001451 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001452 memset(remove_key.bssid, 0xff,
1453 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001454
1455 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1456 sizeof(remove_key));
1457 if (ret != 0)
1458 return ret;
1459 } else {
1460 keyindex = cpu_to_le32(index);
1461 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1462 sizeof(keyindex));
1463 if (ret != 0) {
1464 devwarn(usbdev,
1465 "removing encryption key %d failed (%08X)",
1466 index, ret);
1467 return ret;
1468 }
1469 }
1470
1471 /* if it is transmit key, disable encryption */
1472 if (index == priv->encr_tx_key_index)
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001473 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001474
1475 return 0;
1476}
1477
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001478static void set_multicast_list(struct usbnet *usbdev)
1479{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001480 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001481 struct dev_mc_list *mclist;
1482 __le32 filter;
1483 int ret, i, size;
1484 char *buf;
1485
1486 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1487
1488 if (usbdev->net->flags & IFF_PROMISC) {
1489 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1490 RNDIS_PACKET_TYPE_ALL_LOCAL;
1491 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1492 usbdev->net->mc_count > priv->multicast_size) {
1493 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1494 } else if (usbdev->net->mc_count > 0) {
1495 size = min(priv->multicast_size, usbdev->net->mc_count);
1496 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1497 if (!buf) {
1498 devwarn(usbdev,
1499 "couldn't alloc %d bytes of memory",
1500 size * ETH_ALEN);
1501 return;
1502 }
1503
1504 mclist = usbdev->net->mc_list;
1505 for (i = 0; i < size && mclist; mclist = mclist->next) {
1506 if (mclist->dmi_addrlen != ETH_ALEN)
1507 continue;
1508
1509 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1510 i++;
1511 }
1512
1513 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1514 i * ETH_ALEN);
1515 if (ret == 0 && i > 0)
1516 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1517 else
1518 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1519
1520 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1521 i, priv->multicast_size, ret);
1522
1523 kfree(buf);
1524 }
1525
1526 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1527 sizeof(filter));
1528 if (ret < 0) {
1529 devwarn(usbdev, "couldn't set packet filter: %08x",
1530 le32_to_cpu(filter));
1531 }
1532
1533 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1534 le32_to_cpu(filter), ret);
1535}
1536
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001537/*
John W. Linville964c1d42009-03-26 23:40:01 +02001538 * cfg80211 ops
1539 */
Johannes Berge36d56b2009-06-09 21:04:43 +02001540static int rndis_change_virtual_intf(struct wiphy *wiphy,
1541 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +02001542 enum nl80211_iftype type, u32 *flags,
1543 struct vif_params *params)
1544{
Jussi Kivilinna16139172009-08-28 12:59:21 +03001545 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1546 struct usbnet *usbdev = priv->usbdev;
John W. Linville964c1d42009-03-26 23:40:01 +02001547 int mode;
1548
John W. Linville964c1d42009-03-26 23:40:01 +02001549 switch (type) {
1550 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001551 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001552 break;
1553 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001554 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001555 break;
1556 default:
1557 return -EINVAL;
1558 }
1559
Jussi Kivilinna16139172009-08-28 12:59:21 +03001560 priv->wdev.iftype = type;
1561
John W. Linville964c1d42009-03-26 23:40:01 +02001562 return set_infra_mode(usbdev, mode);
1563}
1564
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001565static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1566{
1567 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1568 struct usbnet *usbdev = priv->usbdev;
1569 int err;
1570
1571 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1572 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1573 if (err < 0)
1574 return err;
1575 }
1576
1577 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1578 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1579 if (err < 0)
1580 return err;
1581 }
1582
1583 return 0;
1584}
1585
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001586static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1587 int dbm)
1588{
1589 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1590 struct usbnet *usbdev = priv->usbdev;
1591
1592 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1593
1594 /* Device doesn't support changing txpower after initialization, only
1595 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1596 * currently used.
1597 */
1598 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1599 if (!priv->radio_on)
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03001600 disassociate(usbdev, true); /* turn on radio */
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001601
1602 return 0;
1603 }
1604
1605 return -ENOTSUPP;
1606}
1607
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001608static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1609{
1610 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1611 struct usbnet *usbdev = priv->usbdev;
1612
1613 *dbm = get_bcm4320_power_dbm(priv);
1614
1615 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1616
1617 return 0;
1618}
1619
Jussi Kivilinnab1d25a62009-08-28 12:59:05 +03001620#define SCAN_DELAY_JIFFIES (6 * HZ)
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001621static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1622 struct cfg80211_scan_request *request)
1623{
1624 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001625 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001626 int ret;
1627 __le32 tmp;
1628
1629 devdbg(usbdev, "cfg80211.scan");
1630
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +03001631 /* Get current bssid list from device before new scan, as new scan
1632 * clears internal bssid list.
1633 */
1634 rndis_check_bssid_list(usbdev);
1635
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001636 if (!request)
1637 return -EINVAL;
1638
1639 if (priv->scan_request && priv->scan_request != request)
1640 return -EBUSY;
1641
1642 priv->scan_request = request;
1643
1644 tmp = cpu_to_le32(1);
1645 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1646 sizeof(tmp));
1647 if (ret == 0) {
1648 /* Wait before retrieving scan results from device */
1649 queue_delayed_work(priv->workqueue, &priv->scan_work,
1650 SCAN_DELAY_JIFFIES);
1651 }
1652
1653 return ret;
1654}
1655
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001656static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1657 struct ndis_80211_bssid_ex *bssid)
1658{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001659 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001660 struct ieee80211_channel *channel;
1661 s32 signal;
1662 u64 timestamp;
1663 u16 capability;
1664 u16 beacon_interval;
1665 struct ndis_80211_fixed_ies *fixed;
1666 int ie_len, bssid_len;
1667 u8 *ie;
1668
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001669 devdbg(usbdev, " found bssid: '%.32s' [%pM]", bssid->ssid.essid,
1670 bssid->mac);
1671
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001672 /* parse bssid structure */
1673 bssid_len = le32_to_cpu(bssid->length);
1674
1675 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1676 sizeof(struct ndis_80211_fixed_ies))
1677 return NULL;
1678
1679 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1680
1681 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1682 ie_len = min(bssid_len - (int)sizeof(*bssid),
1683 (int)le32_to_cpu(bssid->ie_length));
1684 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1685 if (ie_len < 0)
1686 return NULL;
1687
1688 /* extract data for cfg80211_inform_bss */
1689 channel = ieee80211_get_channel(priv->wdev.wiphy,
1690 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1691 if (!channel)
1692 return NULL;
1693
1694 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1695 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1696 capability = le16_to_cpu(fixed->capabilities);
1697 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1698
1699 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1700 timestamp, capability, beacon_interval, ie, ie_len, signal,
1701 GFP_KERNEL);
1702}
1703
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001704static int rndis_check_bssid_list(struct usbnet *usbdev)
1705{
1706 void *buf = NULL;
1707 struct ndis_80211_bssid_list_ex *bssid_list;
1708 struct ndis_80211_bssid_ex *bssid;
1709 int ret = -EINVAL, len, count, bssid_len;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001710 bool resized = false;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001711
1712 devdbg(usbdev, "check_bssid_list");
1713
1714 len = CONTROL_BUFFER_SIZE;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001715resize_buf:
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001716 buf = kmalloc(len, GFP_KERNEL);
1717 if (!buf) {
1718 ret = -ENOMEM;
1719 goto out;
1720 }
1721
1722 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1723 if (ret != 0)
1724 goto out;
1725
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001726 if (!resized && len > CONTROL_BUFFER_SIZE) {
1727 resized = true;
1728 kfree(buf);
1729 goto resize_buf;
1730 }
1731
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001732 bssid_list = buf;
1733 bssid = bssid_list->bssid;
1734 bssid_len = le32_to_cpu(bssid->length);
1735 count = le32_to_cpu(bssid_list->num_items);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001736 devdbg(usbdev, "check_bssid_list: %d BSSIDs found (buflen: %d)", count,
1737 len);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001738
1739 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1740 rndis_bss_info_update(usbdev, bssid);
1741
1742 bssid = (void *)bssid + bssid_len;
1743 bssid_len = le32_to_cpu(bssid->length);
1744 count--;
1745 }
1746
1747out:
1748 kfree(buf);
1749 return ret;
1750}
1751
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001752static void rndis_get_scan_results(struct work_struct *work)
1753{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001754 struct rndis_wlan_private *priv =
1755 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001756 struct usbnet *usbdev = priv->usbdev;
1757 int ret;
1758
1759 devdbg(usbdev, "get_scan_results");
1760
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03001761 if (!priv->scan_request)
1762 return;
1763
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001764 ret = rndis_check_bssid_list(usbdev);
1765
1766 cfg80211_scan_done(priv->scan_request, ret < 0);
1767
1768 priv->scan_request = NULL;
1769}
1770
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001771static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
1772 struct cfg80211_connect_params *sme)
1773{
1774 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1775 struct usbnet *usbdev = priv->usbdev;
1776 struct ieee80211_channel *channel = sme->channel;
1777 struct ndis_80211_ssid ssid;
1778 int pairwise = RNDIS_WLAN_ALG_NONE;
1779 int groupwise = RNDIS_WLAN_ALG_NONE;
1780 int keymgmt = RNDIS_WLAN_KEY_MGMT_NONE;
1781 int length, i, ret, chan = -1;
1782
1783 if (channel)
1784 chan = ieee80211_frequency_to_channel(channel->center_freq);
1785
1786 groupwise = rndis_cipher_to_alg(sme->crypto.cipher_group);
1787 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
1788 pairwise |=
1789 rndis_cipher_to_alg(sme->crypto.ciphers_pairwise[i]);
1790
1791 if (sme->crypto.n_ciphers_pairwise > 0 &&
1792 pairwise == RNDIS_WLAN_ALG_NONE) {
1793 deverr(usbdev, "Unsupported pairwise cipher");
1794 return -ENOTSUPP;
1795 }
1796
1797 for (i = 0; i < sme->crypto.n_akm_suites; i++)
1798 keymgmt |=
1799 rndis_akm_suite_to_key_mgmt(sme->crypto.akm_suites[i]);
1800
1801 if (sme->crypto.n_akm_suites > 0 &&
1802 keymgmt == RNDIS_WLAN_KEY_MGMT_NONE) {
1803 deverr(usbdev, "Invalid keymgmt");
1804 return -ENOTSUPP;
1805 }
1806
1807 devdbg(usbdev, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:"
1808 "0x%x]:0x%x)", sme->ssid, sme->bssid, chan,
1809 sme->privacy, sme->crypto.wpa_versions, sme->auth_type,
1810 groupwise, pairwise, keymgmt);
1811
1812 if (is_associated(usbdev))
1813 disassociate(usbdev, false);
1814
1815 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1816 if (ret < 0) {
1817 devdbg(usbdev, "connect: set_infra_mode failed, %d", ret);
1818 goto err_turn_radio_on;
1819 }
1820
1821 ret = set_auth_mode(usbdev, sme->crypto.wpa_versions, sme->auth_type,
1822 keymgmt);
1823 if (ret < 0) {
1824 devdbg(usbdev, "connect: set_auth_mode failed, %d", ret);
1825 goto err_turn_radio_on;
1826 }
1827
1828 set_priv_filter(usbdev);
1829
1830 ret = set_encr_mode(usbdev, pairwise, groupwise);
1831 if (ret < 0) {
1832 devdbg(usbdev, "connect: set_encr_mode failed, %d", ret);
1833 goto err_turn_radio_on;
1834 }
1835
1836 if (channel) {
1837 ret = set_channel(usbdev, chan);
1838 if (ret < 0) {
1839 devdbg(usbdev, "connect: set_channel failed, %d", ret);
1840 goto err_turn_radio_on;
1841 }
1842 }
1843
1844 if (sme->key && ((groupwise | pairwise) & RNDIS_WLAN_ALG_WEP)) {
1845 priv->encr_tx_key_index = sme->key_idx;
1846 ret = add_wep_key(usbdev, sme->key, sme->key_len, sme->key_idx);
1847 if (ret < 0) {
1848 devdbg(usbdev, "connect: add_wep_key failed, %d "
1849 "(%d, %d)", ret, sme->key_len, sme->key_idx);
1850 goto err_turn_radio_on;
1851 }
1852 }
1853
1854 if (sme->bssid && !is_zero_ether_addr(sme->bssid) &&
1855 !is_broadcast_ether_addr(sme->bssid)) {
1856 ret = set_bssid(usbdev, sme->bssid);
1857 if (ret < 0) {
1858 devdbg(usbdev, "connect: set_bssid failed, %d", ret);
1859 goto err_turn_radio_on;
1860 }
1861 } else
1862 clear_bssid(usbdev);
1863
1864 length = sme->ssid_len;
1865 if (length > NDIS_802_11_LENGTH_SSID)
1866 length = NDIS_802_11_LENGTH_SSID;
1867
1868 memset(&ssid, 0, sizeof(ssid));
1869 ssid.length = cpu_to_le32(length);
1870 memcpy(ssid.essid, sme->ssid, length);
1871
1872 /* Pause and purge rx queue, so we don't pass packets before
1873 * 'media connect'-indication.
1874 */
1875 usbnet_pause_rx(usbdev);
1876 usbnet_purge_paused_rxq(usbdev);
1877
1878 ret = set_essid(usbdev, &ssid);
1879 if (ret < 0)
1880 devdbg(usbdev, "connect: set_essid failed, %d", ret);
1881 return ret;
1882
1883err_turn_radio_on:
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03001884 disassociate(usbdev, true);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001885
1886 return ret;
1887}
1888
1889static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
1890 u16 reason_code)
1891{
1892 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1893 struct usbnet *usbdev = priv->usbdev;
1894
1895 devdbg(usbdev, "cfg80211.disconnect(%d)", reason_code);
1896
1897 priv->connected = false;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03001898 memset(priv->bssid, 0, ETH_ALEN);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001899
1900 return deauthenticate(usbdev);
1901}
1902
1903static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1904 struct cfg80211_ibss_params *params)
1905{
1906 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1907 struct usbnet *usbdev = priv->usbdev;
1908 struct ieee80211_channel *channel = params->channel;
1909 struct ndis_80211_ssid ssid;
1910 enum nl80211_auth_type auth_type;
1911 int ret, alg, length, chan = -1;
1912
1913 if (channel)
1914 chan = ieee80211_frequency_to_channel(channel->center_freq);
1915
1916 /* TODO: How to handle ad-hoc encryption?
1917 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
1918 * pre-shared for encryption (open/shared/wpa), is key set before
1919 * join_ibss? Which auth_type to use (not in params)? What about WPA?
1920 */
1921 if (params->privacy) {
1922 auth_type = NL80211_AUTHTYPE_SHARED_KEY;
1923 alg = RNDIS_WLAN_ALG_WEP;
1924 } else {
1925 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
1926 alg = RNDIS_WLAN_ALG_NONE;
1927 }
1928
1929 devdbg(usbdev, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)", params->ssid,
1930 params->bssid, chan, params->privacy);
1931
1932 if (is_associated(usbdev))
1933 disassociate(usbdev, false);
1934
1935 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_ADHOC);
1936 if (ret < 0) {
1937 devdbg(usbdev, "join_ibss: set_infra_mode failed, %d", ret);
1938 goto err_turn_radio_on;
1939 }
1940
1941 ret = set_auth_mode(usbdev, 0, auth_type, RNDIS_WLAN_KEY_MGMT_NONE);
1942 if (ret < 0) {
1943 devdbg(usbdev, "join_ibss: set_auth_mode failed, %d", ret);
1944 goto err_turn_radio_on;
1945 }
1946
1947 set_priv_filter(usbdev);
1948
1949 ret = set_encr_mode(usbdev, alg, RNDIS_WLAN_ALG_NONE);
1950 if (ret < 0) {
1951 devdbg(usbdev, "join_ibss: set_encr_mode failed, %d", ret);
1952 goto err_turn_radio_on;
1953 }
1954
1955 if (channel) {
1956 ret = set_channel(usbdev, chan);
1957 if (ret < 0) {
1958 devdbg(usbdev, "join_ibss: set_channel failed, %d",
1959 ret);
1960 goto err_turn_radio_on;
1961 }
1962 }
1963
1964 if (params->bssid && !is_zero_ether_addr(params->bssid) &&
1965 !is_broadcast_ether_addr(params->bssid)) {
1966 ret = set_bssid(usbdev, params->bssid);
1967 if (ret < 0) {
1968 devdbg(usbdev, "join_ibss: set_bssid failed, %d", ret);
1969 goto err_turn_radio_on;
1970 }
1971 } else
1972 clear_bssid(usbdev);
1973
1974 length = params->ssid_len;
1975 if (length > NDIS_802_11_LENGTH_SSID)
1976 length = NDIS_802_11_LENGTH_SSID;
1977
1978 memset(&ssid, 0, sizeof(ssid));
1979 ssid.length = cpu_to_le32(length);
1980 memcpy(ssid.essid, params->ssid, length);
1981
1982 /* Don't need to pause rx queue for ad-hoc. */
1983 usbnet_purge_paused_rxq(usbdev);
1984 usbnet_resume_rx(usbdev);
1985
1986 ret = set_essid(usbdev, &ssid);
1987 if (ret < 0)
1988 devdbg(usbdev, "join_ibss: set_essid failed, %d", ret);
1989 return ret;
1990
1991err_turn_radio_on:
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03001992 disassociate(usbdev, true);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001993
1994 return ret;
1995}
1996
1997static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1998{
1999 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2000 struct usbnet *usbdev = priv->usbdev;
2001
2002 devdbg(usbdev, "cfg80211.leave_ibss()");
2003
2004 priv->connected = false;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002005 memset(priv->bssid, 0, ETH_ALEN);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002006
2007 return deauthenticate(usbdev);
2008}
2009
Jussi Kivilinna5554adb2009-08-28 13:27:53 +03002010static int rndis_set_channel(struct wiphy *wiphy,
2011 struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
2012{
2013 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2014 struct usbnet *usbdev = priv->usbdev;
2015
2016 return set_channel(usbdev,
2017 ieee80211_frequency_to_channel(chan->center_freq));
2018}
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002019
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03002020static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
2021 u8 key_index, const u8 *mac_addr,
2022 struct key_params *params)
2023{
2024 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2025 struct usbnet *usbdev = priv->usbdev;
Jussi Kivilinna53d27ea2009-09-01 15:33:06 +03002026 __le32 flags;
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03002027
2028 devdbg(usbdev, "rndis_add_key(%i, %pM, %08x)", key_index, mac_addr,
2029 params->cipher);
2030
2031 switch (params->cipher) {
2032 case WLAN_CIPHER_SUITE_WEP40:
2033 case WLAN_CIPHER_SUITE_WEP104:
2034 return add_wep_key(usbdev, params->key, params->key_len,
2035 key_index);
2036 case WLAN_CIPHER_SUITE_TKIP:
2037 case WLAN_CIPHER_SUITE_CCMP:
2038 flags = 0;
2039
2040 if (params->seq && params->seq_len > 0)
2041 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
2042 if (mac_addr)
2043 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY |
2044 NDIS_80211_ADDKEY_TRANSMIT_KEY;
2045
2046 return add_wpa_key(usbdev, params->key, params->key_len,
2047 key_index, mac_addr, params->seq,
2048 params->seq_len, params->cipher, flags);
2049 default:
2050 devdbg(usbdev, "rndis_add_key: unsupported cipher %08x",
2051 params->cipher);
2052 return -ENOTSUPP;
2053 }
2054}
2055
2056static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
2057 u8 key_index, const u8 *mac_addr)
2058{
2059 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2060 struct usbnet *usbdev = priv->usbdev;
2061
2062 devdbg(usbdev, "rndis_del_key(%i, %pM)", key_index, mac_addr);
2063
2064 return remove_key(usbdev, key_index, mac_addr);
2065}
2066
2067static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
2068 u8 key_index)
2069{
2070 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2071 struct usbnet *usbdev = priv->usbdev;
2072 struct rndis_wlan_encr_key key;
2073
2074 devdbg(usbdev, "rndis_set_default_key(%i)", key_index);
2075
2076 priv->encr_tx_key_index = key_index;
2077
2078 key = priv->encr_keys[key_index];
2079
2080 return add_wep_key(usbdev, key.material, key.len, key_index);
2081}
2082
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002083static void rndis_fill_station_info(struct usbnet *usbdev,
2084 struct station_info *sinfo)
2085{
2086 __le32 linkspeed, rssi;
2087 int ret, len;
2088
2089 memset(sinfo, 0, sizeof(*sinfo));
2090
2091 len = sizeof(linkspeed);
2092 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &linkspeed, &len);
2093 if (ret == 0) {
2094 sinfo->txrate.legacy = le32_to_cpu(linkspeed) / 1000;
2095 sinfo->filled |= STATION_INFO_TX_BITRATE;
2096 }
2097
2098 len = sizeof(rssi);
2099 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2100 if (ret == 0) {
2101 sinfo->signal = level_to_qual(le32_to_cpu(rssi));
2102 sinfo->filled |= STATION_INFO_SIGNAL;
2103 }
2104}
2105
2106static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
2107 u8 *mac, struct station_info *sinfo)
2108{
2109 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2110 struct usbnet *usbdev = priv->usbdev;
2111
2112 if (compare_ether_addr(priv->bssid, mac))
2113 return -ENOENT;
2114
2115 rndis_fill_station_info(usbdev, sinfo);
2116
2117 return 0;
2118}
2119
Jussi Kivilinnad695df92009-08-28 13:28:09 +03002120static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
2121 int idx, u8 *mac, struct station_info *sinfo)
2122{
2123 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2124 struct usbnet *usbdev = priv->usbdev;
2125
2126 if (idx != 0)
2127 return -ENOENT;
2128
2129 memcpy(mac, priv->bssid, ETH_ALEN);
2130
2131 rndis_fill_station_info(usbdev, sinfo);
2132
2133 return 0;
2134}
2135
Jussi Kivilinnac5c4fe92009-09-01 15:33:00 +03002136/*
2137 * workers, indication handlers, device poller
2138 */
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002139static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002140{
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002141 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Scott Ashcroft43646232008-05-27 00:06:15 +03002142 struct ndis_80211_assoc_info *info;
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002143 u8 assoc_buf[sizeof(*info) + IW_CUSTOM_MAX + 32];
2144 u8 bssid[ETH_ALEN];
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002145 int resp_ie_len, req_ie_len;
2146 u8 *req_ie, *resp_ie;
Scott Ashcroft43646232008-05-27 00:06:15 +03002147 int ret, offset;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002148 bool roamed = false;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002149
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002150 if (priv->infra_mode == NDIS_80211_INFRA_INFRA && priv->connected) {
2151 /* received media connect indication while connected, either
2152 * device reassociated with same AP or roamed to new. */
2153 roamed = true;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002154 }
2155
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002156 req_ie_len = 0;
2157 resp_ie_len = 0;
2158 req_ie = NULL;
2159 resp_ie = NULL;
2160
2161 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2162 memset(assoc_buf, 0, sizeof(assoc_buf));
2163 info = (void *)assoc_buf;
2164
2165 /* Get association info IEs from device and send them back to
2166 * userspace. */
2167 ret = get_association_info(usbdev, info, sizeof(assoc_buf));
2168 if (!ret) {
2169 req_ie_len = le32_to_cpu(info->req_ie_length);
2170 if (req_ie_len > 0) {
2171 offset = le32_to_cpu(info->offset_req_ies);
2172 req_ie = (u8 *)info + offset;
2173 }
2174
2175 resp_ie_len = le32_to_cpu(info->resp_ie_length);
2176 if (resp_ie_len > 0) {
2177 offset = le32_to_cpu(info->offset_resp_ies);
2178 resp_ie = (u8 *)info + offset;
2179 }
2180 }
2181 } else if (WARN_ON(priv->infra_mode != NDIS_80211_INFRA_ADHOC))
2182 return;
2183
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002184 ret = get_bssid(usbdev, bssid);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002185 if (ret < 0)
2186 memset(bssid, 0, sizeof(bssid));
2187
2188 devdbg(usbdev, "link up work: [%pM] %s", bssid, roamed ? "roamed" : "");
2189
2190 /* Internal bss list in device always contains at least the currently
2191 * connected bss and we can get it to cfg80211 with
2192 * rndis_check_bssid_list().
2193 * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
2194 * spec.
2195 */
2196 rndis_check_bssid_list(usbdev);
2197
2198 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2199 if (!roamed)
2200 cfg80211_connect_result(usbdev->net, bssid, req_ie,
2201 req_ie_len, resp_ie,
2202 resp_ie_len, 0, GFP_KERNEL);
2203 else
2204 cfg80211_roamed(usbdev->net, bssid, req_ie, req_ie_len,
2205 resp_ie, resp_ie_len, GFP_KERNEL);
2206 } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
2207 cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
2208
2209 priv->connected = true;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002210 memcpy(priv->bssid, bssid, ETH_ALEN);
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002211
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002212 usbnet_resume_rx(usbdev);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002213 netif_carrier_on(usbdev->net);
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002214}
2215
2216static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
2217{
2218 union iwreq_data evt;
2219
2220 netif_carrier_off(usbdev->net);
2221
2222 evt.data.flags = 0;
2223 evt.data.length = 0;
2224 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2225 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2226}
2227
2228static void rndis_wlan_worker(struct work_struct *work)
2229{
2230 struct rndis_wlan_private *priv =
2231 container_of(work, struct rndis_wlan_private, work);
2232 struct usbnet *usbdev = priv->usbdev;
2233
2234 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
2235 rndis_wlan_do_link_up_work(usbdev);
2236
2237 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
2238 rndis_wlan_do_link_down_work(usbdev);
2239
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002240 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2241 set_multicast_list(usbdev);
2242}
2243
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002244static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002245{
Wang Chen524ad0a2008-11-12 23:39:10 -08002246 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002247 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002248
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002249 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2250 return;
2251
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002252 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2253 queue_work(priv->workqueue, &priv->work);
2254}
2255
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002256static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2257 struct ndis_80211_status_indication *indication,
2258 int len)
2259{
2260 u8 *buf;
2261 const char *type;
Jussi Kivilinnaa0f9ce22009-08-28 13:28:24 +03002262 int flags, buflen, key_id;
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002263 bool pairwise_error, group_error;
2264 struct ndis_80211_auth_request *auth_req;
Jussi Kivilinnaa0f9ce22009-08-28 13:28:24 +03002265 enum nl80211_key_type key_type;
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002266
2267 /* must have at least one array entry */
2268 if (len < offsetof(struct ndis_80211_status_indication, u) +
2269 sizeof(struct ndis_80211_auth_request)) {
2270 devinfo(usbdev, "authentication indication: "
2271 "too short message (%i)", len);
2272 return;
2273 }
2274
2275 buf = (void *)&indication->u.auth_request[0];
2276 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2277
2278 while (buflen >= sizeof(*auth_req)) {
2279 auth_req = (void *)buf;
2280 type = "unknown";
2281 flags = le32_to_cpu(auth_req->flags);
2282 pairwise_error = false;
2283 group_error = false;
2284
2285 if (flags & 0x1)
2286 type = "reauth request";
2287 if (flags & 0x2)
2288 type = "key update request";
2289 if (flags & 0x6) {
2290 pairwise_error = true;
2291 type = "pairwise_error";
2292 }
2293 if (flags & 0xe) {
2294 group_error = true;
2295 type = "group_error";
2296 }
2297
2298 devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
2299 le32_to_cpu(auth_req->flags));
2300
Jussi Kivilinnaa0f9ce22009-08-28 13:28:24 +03002301 if (pairwise_error) {
2302 key_type = NL80211_KEYTYPE_PAIRWISE;
2303 key_id = -1;
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002304
Jussi Kivilinnaa0f9ce22009-08-28 13:28:24 +03002305 cfg80211_michael_mic_failure(usbdev->net,
2306 auth_req->bssid,
2307 key_type, key_id, NULL,
2308 GFP_KERNEL);
2309 }
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002310
Jussi Kivilinnaa0f9ce22009-08-28 13:28:24 +03002311 if (group_error) {
2312 key_type = NL80211_KEYTYPE_GROUP;
2313 key_id = -1;
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002314
Jussi Kivilinnaa0f9ce22009-08-28 13:28:24 +03002315 cfg80211_michael_mic_failure(usbdev->net,
2316 auth_req->bssid,
2317 key_type, key_id, NULL,
2318 GFP_KERNEL);
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002319 }
2320
2321 buflen -= le32_to_cpu(auth_req->length);
2322 buf += le32_to_cpu(auth_req->length);
2323 }
2324}
2325
2326static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2327 struct ndis_80211_status_indication *indication,
2328 int len)
2329{
2330 struct ndis_80211_pmkid_cand_list *cand_list;
2331 int list_len, expected_len, i;
2332
2333 if (len < offsetof(struct ndis_80211_status_indication, u) +
2334 sizeof(struct ndis_80211_pmkid_cand_list)) {
2335 devinfo(usbdev, "pmkid candidate list indication: "
2336 "too short message (%i)", len);
2337 return;
2338 }
2339
2340 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2341 sizeof(struct ndis_80211_pmkid_candidate);
2342 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2343 offsetof(struct ndis_80211_status_indication, u);
2344
2345 if (len < expected_len) {
2346 devinfo(usbdev, "pmkid candidate list indication: "
2347 "list larger than buffer (%i < %i)",
2348 len, expected_len);
2349 return;
2350 }
2351
2352 cand_list = &indication->u.cand_list;
2353
2354 devinfo(usbdev, "pmkid candidate list indication: "
2355 "version %i, candidates %i",
2356 le32_to_cpu(cand_list->version),
2357 le32_to_cpu(cand_list->num_candidates));
2358
2359 if (le32_to_cpu(cand_list->version) != 1)
2360 return;
2361
2362 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002363 struct ndis_80211_pmkid_candidate *cand =
2364 &cand_list->candidate_list[i];
2365
2366 devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
2367 i, le32_to_cpu(cand->flags), cand->bssid);
2368
Jussi Kivilinna21ec2d82009-08-28 13:28:30 +03002369#if 0
2370 struct iw_pmkid_cand pcand;
2371 union iwreq_data wrqu;
2372
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002373 memset(&pcand, 0, sizeof(pcand));
2374 if (le32_to_cpu(cand->flags) & 0x01)
2375 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2376 pcand.index = i;
2377 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2378
2379 memset(&wrqu, 0, sizeof(wrqu));
2380 wrqu.data.length = sizeof(pcand);
2381 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2382 (u8 *)&pcand);
Jussi Kivilinna21ec2d82009-08-28 13:28:30 +03002383#endif
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002384 }
2385}
2386
2387static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2388 struct rndis_indicate *msg, int buflen)
2389{
2390 struct ndis_80211_status_indication *indication;
2391 int len, offset;
2392
2393 offset = offsetof(struct rndis_indicate, status) +
2394 le32_to_cpu(msg->offset);
2395 len = le32_to_cpu(msg->length);
2396
2397 if (len < 8) {
2398 devinfo(usbdev, "media specific indication, "
2399 "ignore too short message (%i < 8)", len);
2400 return;
2401 }
2402
2403 if (offset + len > buflen) {
2404 devinfo(usbdev, "media specific indication, "
2405 "too large to fit to buffer (%i > %i)",
2406 offset + len, buflen);
2407 return;
2408 }
2409
2410 indication = (void *)((u8 *)msg + offset);
2411
2412 switch (le32_to_cpu(indication->status_type)) {
2413 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2414 devinfo(usbdev, "radio state indication: %i",
2415 le32_to_cpu(indication->u.radio_status));
2416 return;
2417
2418 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2419 devinfo(usbdev, "media stream mode indication: %i",
2420 le32_to_cpu(indication->u.media_stream_mode));
2421 return;
2422
2423 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2424 rndis_wlan_auth_indication(usbdev, indication, len);
2425 return;
2426
2427 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2428 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2429 return;
2430
2431 default:
2432 devinfo(usbdev, "media specific indication: "
2433 "unknown status type 0x%08x",
2434 le32_to_cpu(indication->status_type));
2435 }
2436}
2437
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002438static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002439{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002440 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002441 struct rndis_indicate *msg = ind;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002442
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002443 switch (msg->status) {
2444 case RNDIS_STATUS_MEDIA_CONNECT:
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +03002445 if (priv->current_command_oid == OID_802_11_ADD_KEY) {
2446 /* OID_802_11_ADD_KEY causes sometimes extra
2447 * "media connect" indications which confuses driver
2448 * and userspace to think that device is
2449 * roaming/reassociating when it isn't.
2450 */
2451 devdbg(usbdev, "ignored OID_802_11_ADD_KEY triggered "
2452 "'media connect'");
2453 return;
2454 }
2455
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002456 usbnet_pause_rx(usbdev);
2457
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002458 devinfo(usbdev, "media connect");
2459
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002460 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002461 set_bit(WORK_LINK_UP, &priv->work_pending);
2462 queue_work(priv->workqueue, &priv->work);
2463 break;
2464
2465 case RNDIS_STATUS_MEDIA_DISCONNECT:
2466 devinfo(usbdev, "media disconnect");
2467
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002468 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002469 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2470 queue_work(priv->workqueue, &priv->work);
2471 break;
2472
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002473 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2474 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2475 break;
2476
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002477 default:
2478 devinfo(usbdev, "indication: 0x%08x",
2479 le32_to_cpu(msg->status));
2480 break;
2481 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002482}
2483
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002484static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002485{
2486 struct {
2487 __le32 num_items;
2488 __le32 items[8];
2489 } networks_supported;
2490 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002491 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002492
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002493 /* determine supported modes */
2494 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002495 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002496 &networks_supported, &len);
2497 if (retval >= 0) {
2498 n = le32_to_cpu(networks_supported.num_items);
2499 if (n > 8)
2500 n = 8;
2501 for (i = 0; i < n; i++) {
2502 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002503 case NDIS_80211_TYPE_FREQ_HOP:
2504 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002505 priv->caps |= CAP_MODE_80211B;
2506 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002507 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002508 priv->caps |= CAP_MODE_80211A;
2509 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002510 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002511 priv->caps |= CAP_MODE_80211G;
2512 break;
2513 }
2514 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002515 }
2516
2517 return retval;
2518}
2519
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002520#define DEVICE_POLLER_JIFFIES (HZ)
2521static void rndis_device_poller(struct work_struct *work)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002522{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002523 struct rndis_wlan_private *priv =
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002524 container_of(work, struct rndis_wlan_private,
2525 dev_poller_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002526 struct usbnet *usbdev = priv->usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002527 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002528 int len, ret, j;
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002529 int update_jiffies = DEVICE_POLLER_JIFFIES;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002530 void *buf;
2531
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002532 /* Only check/do workaround when connected. Calling is_associated()
2533 * also polls device with rndis_command() and catches for media link
2534 * indications.
2535 */
2536 if (!is_associated(usbdev))
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002537 goto end;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002538
2539 len = sizeof(rssi);
2540 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002541 if (ret == 0)
2542 priv->last_qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002543
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002544 devdbg(usbdev, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d",
2545 ret, le32_to_cpu(rssi), level_to_qual(le32_to_cpu(rssi)));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002546
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002547 /* Workaround transfer stalls on poor quality links.
2548 * TODO: find right way to fix these stalls (as stalls do not happen
2549 * with ndiswrapper/windows driver). */
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002550 if (priv->last_qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002551 /* Decrease stats worker interval to catch stalls.
2552 * faster. Faster than 400-500ms causes packet loss,
2553 * Slower doesn't catch stalls fast enough.
2554 */
2555 j = msecs_to_jiffies(priv->param_workaround_interval);
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002556 if (j > DEVICE_POLLER_JIFFIES)
2557 j = DEVICE_POLLER_JIFFIES;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002558 else if (j <= 0)
2559 j = 1;
2560 update_jiffies = j;
2561
2562 /* Send scan OID. Use of both OIDs is required to get device
2563 * working.
2564 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08002565 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002566 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2567 sizeof(tmp));
2568
2569 len = CONTROL_BUFFER_SIZE;
2570 buf = kmalloc(len, GFP_KERNEL);
2571 if (!buf)
2572 goto end;
2573
2574 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2575 kfree(buf);
2576 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002577
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002578end:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002579 if (update_jiffies >= HZ)
2580 update_jiffies = round_jiffies_relative(update_jiffies);
2581 else {
2582 j = round_jiffies_relative(update_jiffies);
2583 if (abs(j - update_jiffies) <= 10)
2584 update_jiffies = j;
2585 }
2586
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002587 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
2588 update_jiffies);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002589}
2590
Jussi Kivilinnac5c4fe92009-09-01 15:33:00 +03002591/*
2592 * driver/device initialization
2593 */
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002594static int bcm4320a_early_init(struct usbnet *usbdev)
2595{
2596 /* bcm4320a doesn't handle configuration parameters well. Try
2597 * set any and you get partially zeroed mac and broken device.
2598 */
2599
2600 return 0;
2601}
2602
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002603static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002604{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002605 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002606 char buf[8];
2607
2608 /* Early initialization settings, setting these won't have effect
2609 * if called after generic_rndis_bind().
2610 */
2611
2612 priv->param_country[0] = modparam_country[0];
2613 priv->param_country[1] = modparam_country[1];
2614 priv->param_country[2] = 0;
2615 priv->param_frameburst = modparam_frameburst;
2616 priv->param_afterburner = modparam_afterburner;
2617 priv->param_power_save = modparam_power_save;
2618 priv->param_power_output = modparam_power_output;
2619 priv->param_roamtrigger = modparam_roamtrigger;
2620 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002621
2622 priv->param_country[0] = toupper(priv->param_country[0]);
2623 priv->param_country[1] = toupper(priv->param_country[1]);
2624 /* doesn't support EU as country code, use FI instead */
2625 if (!strcmp(priv->param_country, "EU"))
2626 strcpy(priv->param_country, "FI");
2627
2628 if (priv->param_power_save < 0)
2629 priv->param_power_save = 0;
2630 else if (priv->param_power_save > 2)
2631 priv->param_power_save = 2;
2632
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03002633 if (priv->param_power_output < 0)
2634 priv->param_power_output = 0;
2635 else if (priv->param_power_output > 3)
2636 priv->param_power_output = 3;
2637
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002638 if (priv->param_roamtrigger < -80)
2639 priv->param_roamtrigger = -80;
2640 else if (priv->param_roamtrigger > -60)
2641 priv->param_roamtrigger = -60;
2642
2643 if (priv->param_roamdelta < 0)
2644 priv->param_roamdelta = 0;
2645 else if (priv->param_roamdelta > 2)
2646 priv->param_roamdelta = 2;
2647
Roel Kluin4d381ff2008-04-23 22:10:29 +02002648 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002649 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02002650 else
2651 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002652
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002653 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2654 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002655 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002656 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002657 priv->param_afterburner ? "1" : "0");
2658 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002659 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002660 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002661 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002662 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002663 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002664 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002665 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002666
2667 return 0;
2668}
2669
David S. Miller23d12e22009-03-25 00:03:16 -07002670/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002671static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07002672 .ndo_open = usbnet_open,
2673 .ndo_stop = usbnet_stop,
2674 .ndo_start_xmit = usbnet_start_xmit,
2675 .ndo_tx_timeout = usbnet_tx_timeout,
2676 .ndo_set_mac_address = eth_mac_addr,
2677 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002678 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07002679};
2680
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002681static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002682{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002683 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002684 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002685 int retval, len;
2686 __le32 tmp;
2687
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002688 /* allocate wiphy and rndis private data
2689 * NOTE: We only support a single virtual interface, so wiphy
2690 * and wireless_dev are somewhat synonymous for this device.
2691 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002692 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002693 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002694 return -ENOMEM;
2695
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002696 priv = wiphy_priv(wiphy);
2697 usbdev->net->ieee80211_ptr = &priv->wdev;
2698 priv->wdev.wiphy = wiphy;
2699 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2700
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002701 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002702 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002703 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002704 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002705 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002706
2707 mutex_init(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002708
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002709 /* because rndis_command() sleeps we need to use workqueue */
2710 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002711 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002712 INIT_DELAYED_WORK(&priv->dev_poller_work, rndis_device_poller);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002713 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2714
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002715 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002716 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002717 if (retval < 0)
2718 goto fail;
2719
2720 /* generic_rndis_bind set packet filter to multicast_all+
2721 * promisc mode which doesn't work well for our devices (device
2722 * picks up rssi to closest station instead of to access point).
2723 *
2724 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002725 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002726 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002727 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07002728
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002729 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002730 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002731 sizeof(tmp));
2732
2733 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002734 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2735 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002736 priv->multicast_size = le32_to_cpu(tmp);
2737 if (retval < 0 || priv->multicast_size < 0)
2738 priv->multicast_size = 0;
2739 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002740 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002741 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002742 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002743
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002744 /* fill-out wiphy structure and register w/ cfg80211 */
2745 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2746 wiphy->privid = rndis_wiphy_privid;
2747 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2748 | BIT(NL80211_IFTYPE_ADHOC);
2749 wiphy->max_scan_ssids = 1;
2750
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002751 /* TODO: fill-out band/encr information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002752 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002753
2754 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2755 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2756 priv->band.channels = priv->channels;
2757 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2758 priv->band.bitrates = priv->rates;
2759 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2760 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002761 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002762
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002763 memcpy(priv->cipher_suites, rndis_cipher_suites,
2764 sizeof(rndis_cipher_suites));
2765 wiphy->cipher_suites = priv->cipher_suites;
2766 wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
2767
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002768 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2769
2770 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002771 retval = -ENODEV;
2772 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002773 }
2774
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002775 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002776
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002777 /* set default rts/frag */
2778 rndis_set_wiphy_params(wiphy,
2779 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2780
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002781 /* turn radio on */
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03002782 priv->radio_on = true;
2783 disassociate(usbdev, true);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002784 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002785
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002786 return 0;
2787
2788fail:
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002789 cancel_delayed_work_sync(&priv->dev_poller_work);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002790 cancel_delayed_work_sync(&priv->scan_work);
2791 cancel_work_sync(&priv->work);
2792 flush_workqueue(priv->workqueue);
2793 destroy_workqueue(priv->workqueue);
2794
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002795 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002796 return retval;
2797}
2798
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002799static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002800{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002801 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002802
2803 /* turn radio off */
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03002804 disassociate(usbdev, false);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002805
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002806 cancel_delayed_work_sync(&priv->dev_poller_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002807 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002808 cancel_work_sync(&priv->work);
2809 flush_workqueue(priv->workqueue);
2810 destroy_workqueue(priv->workqueue);
2811
2812 if (priv && priv->wpa_ie_len)
2813 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002814
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002815 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002816
2817 wiphy_unregister(priv->wdev.wiphy);
2818 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002819}
2820
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002821static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002822{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002823 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002824 int retval;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002825
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002826 devdbg(usbdev, "rndis_wlan_reset");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002827
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002828 retval = rndis_reset(usbdev);
2829 if (retval)
2830 devwarn(usbdev, "rndis_reset() failed: %d", retval);
2831
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03002832 /* rndis_reset cleared multicast list, so restore here.
2833 (set_multicast_list() also turns on current packet filter) */
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002834 set_multicast_list(usbdev);
2835
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002836 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
2837 round_jiffies_relative(DEVICE_POLLER_JIFFIES));
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002838
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002839 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002840}
2841
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002842static int rndis_wlan_stop(struct usbnet *usbdev)
2843{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002844 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2845 int retval;
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03002846 __le32 filter;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002847
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002848 devdbg(usbdev, "rndis_wlan_stop");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002849
Jussi Kivilinna051ae0b2009-09-01 15:32:55 +03002850 retval = disassociate(usbdev, false);
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002851
2852 priv->work_pending = 0;
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002853 cancel_delayed_work_sync(&priv->dev_poller_work);
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002854 cancel_delayed_work_sync(&priv->scan_work);
2855 cancel_work_sync(&priv->work);
2856 flush_workqueue(priv->workqueue);
2857
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03002858 if (priv->scan_request) {
2859 cfg80211_scan_done(priv->scan_request, true);
2860 priv->scan_request = NULL;
2861 }
2862
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03002863 /* Set current packet filter zero to block receiving data packets from
2864 device. */
2865 filter = 0;
2866 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
2867 sizeof(filter));
2868
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002869 return retval;
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002870}
2871
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002872static const struct driver_info bcm4320b_info = {
2873 .description = "Wireless RNDIS device, BCM4320b based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002874 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2875 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002876 .bind = rndis_wlan_bind,
2877 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002878 .status = rndis_status,
2879 .rx_fixup = rndis_rx_fixup,
2880 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002881 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002882 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002883 .early_init = bcm4320b_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002884 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002885};
2886
2887static const struct driver_info bcm4320a_info = {
2888 .description = "Wireless RNDIS device, BCM4320a based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002889 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2890 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002891 .bind = rndis_wlan_bind,
2892 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002893 .status = rndis_status,
2894 .rx_fixup = rndis_rx_fixup,
2895 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002896 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002897 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002898 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002899 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002900};
2901
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002902static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002903 .description = "Wireless RNDIS device",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03002904 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2905 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002906 .bind = rndis_wlan_bind,
2907 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002908 .status = rndis_status,
2909 .rx_fixup = rndis_rx_fixup,
2910 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002911 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002912 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002913 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002914 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002915};
2916
2917/*-------------------------------------------------------------------------*/
2918
2919static const struct usb_device_id products [] = {
2920#define RNDIS_MASTER_INTERFACE \
2921 .bInterfaceClass = USB_CLASS_COMM, \
2922 .bInterfaceSubClass = 2 /* ACM */, \
2923 .bInterfaceProtocol = 0x0ff
2924
2925/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2926 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2927 */
2928{
2929 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2930 | USB_DEVICE_ID_MATCH_DEVICE,
2931 .idVendor = 0x0411,
2932 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
2933 RNDIS_MASTER_INTERFACE,
2934 .driver_info = (unsigned long) &bcm4320b_info,
2935}, {
2936 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2937 | USB_DEVICE_ID_MATCH_DEVICE,
2938 .idVendor = 0x0baf,
2939 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
2940 RNDIS_MASTER_INTERFACE,
2941 .driver_info = (unsigned long) &bcm4320b_info,
2942}, {
2943 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2944 | USB_DEVICE_ID_MATCH_DEVICE,
2945 .idVendor = 0x050d,
2946 .idProduct = 0x011b, /* Belkin F5D7051 */
2947 RNDIS_MASTER_INTERFACE,
2948 .driver_info = (unsigned long) &bcm4320b_info,
2949}, {
2950 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2951 | USB_DEVICE_ID_MATCH_DEVICE,
2952 .idVendor = 0x1799, /* Belkin has two vendor ids */
2953 .idProduct = 0x011b, /* Belkin F5D7051 */
2954 RNDIS_MASTER_INTERFACE,
2955 .driver_info = (unsigned long) &bcm4320b_info,
2956}, {
2957 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2958 | USB_DEVICE_ID_MATCH_DEVICE,
2959 .idVendor = 0x13b1,
2960 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
2961 RNDIS_MASTER_INTERFACE,
2962 .driver_info = (unsigned long) &bcm4320b_info,
2963}, {
2964 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2965 | USB_DEVICE_ID_MATCH_DEVICE,
2966 .idVendor = 0x13b1,
2967 .idProduct = 0x0026, /* Linksys WUSB54GSC */
2968 RNDIS_MASTER_INTERFACE,
2969 .driver_info = (unsigned long) &bcm4320b_info,
2970}, {
2971 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2972 | USB_DEVICE_ID_MATCH_DEVICE,
2973 .idVendor = 0x0b05,
2974 .idProduct = 0x1717, /* Asus WL169gE */
2975 RNDIS_MASTER_INTERFACE,
2976 .driver_info = (unsigned long) &bcm4320b_info,
2977}, {
2978 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2979 | USB_DEVICE_ID_MATCH_DEVICE,
2980 .idVendor = 0x0a5c,
2981 .idProduct = 0xd11b, /* Eminent EM4045 */
2982 RNDIS_MASTER_INTERFACE,
2983 .driver_info = (unsigned long) &bcm4320b_info,
2984}, {
2985 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2986 | USB_DEVICE_ID_MATCH_DEVICE,
2987 .idVendor = 0x1690,
2988 .idProduct = 0x0715, /* BT Voyager 1055 */
2989 RNDIS_MASTER_INTERFACE,
2990 .driver_info = (unsigned long) &bcm4320b_info,
2991},
2992/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
2993 * parameters available, hardware probably contain older firmware version with
2994 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
2995 */
2996{
2997 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2998 | USB_DEVICE_ID_MATCH_DEVICE,
2999 .idVendor = 0x13b1,
3000 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3001 RNDIS_MASTER_INTERFACE,
3002 .driver_info = (unsigned long) &bcm4320a_info,
3003}, {
3004 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3005 | USB_DEVICE_ID_MATCH_DEVICE,
3006 .idVendor = 0x0baf,
3007 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3008 RNDIS_MASTER_INTERFACE,
3009 .driver_info = (unsigned long) &bcm4320a_info,
3010}, {
3011 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3012 | USB_DEVICE_ID_MATCH_DEVICE,
3013 .idVendor = 0x0411,
3014 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3015 RNDIS_MASTER_INTERFACE,
3016 .driver_info = (unsigned long) &bcm4320a_info,
3017},
3018/* Generic Wireless RNDIS devices that we don't have exact
3019 * idVendor/idProduct/chip yet.
3020 */
3021{
3022 /* RNDIS is MSFT's un-official variant of CDC ACM */
3023 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003024 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003025}, {
3026 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3027 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003028 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003029},
3030 { }, // END
3031};
3032MODULE_DEVICE_TABLE(usb, products);
3033
3034static struct usb_driver rndis_wlan_driver = {
3035 .name = "rndis_wlan",
3036 .id_table = products,
3037 .probe = usbnet_probe,
3038 .disconnect = usbnet_disconnect,
3039 .suspend = usbnet_suspend,
3040 .resume = usbnet_resume,
3041};
3042
3043static int __init rndis_wlan_init(void)
3044{
3045 return usb_register(&rndis_wlan_driver);
3046}
3047module_init(rndis_wlan_init);
3048
3049static void __exit rndis_wlan_exit(void)
3050{
3051 usb_deregister(&rndis_wlan_driver);
3052}
3053module_exit(rndis_wlan_exit);
3054
3055MODULE_AUTHOR("Bjorge Dijkstra");
3056MODULE_AUTHOR("Jussi Kivilinna");
3057MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3058MODULE_LICENSE("GPL");
3059