blob: 61a7693baf92f9ada6314cec43dcb4cd4433de33 [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 {
256 enum ndis_80211_media_stream_mode media_stream_mode;
257 enum ndis_80211_radio_status radio_status;
258 struct ndis_80211_auth_request auth_request[0];
259 struct ndis_80211_pmkid_cand_list cand_list;
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 */
469 int radio_on;
470 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
563
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300564static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200565{
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300566 switch (priv->param_power_output) {
567 default:
568 case 3:
569 return BCM4320_DEFAULT_TXPOWER_DBM_100;
570 case 2:
571 return BCM4320_DEFAULT_TXPOWER_DBM_75;
572 case 1:
573 return BCM4320_DEFAULT_TXPOWER_DBM_50;
574 case 0:
575 return BCM4320_DEFAULT_TXPOWER_DBM_25;
576 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200577}
578
579
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300580static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
581{
582 int cipher = priv->encr_keys[idx].cipher;
583
584 return (cipher == WLAN_CIPHER_SUITE_CCMP ||
585 cipher == WLAN_CIPHER_SUITE_TKIP);
586}
587
588
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300589static int rndis_cipher_to_alg(u32 cipher)
590{
591 switch (cipher) {
592 default:
593 return RNDIS_WLAN_ALG_NONE;
594 case WLAN_CIPHER_SUITE_WEP40:
595 case WLAN_CIPHER_SUITE_WEP104:
596 return RNDIS_WLAN_ALG_WEP;
597 case WLAN_CIPHER_SUITE_TKIP:
598 return RNDIS_WLAN_ALG_TKIP;
599 case WLAN_CIPHER_SUITE_CCMP:
600 return RNDIS_WLAN_ALG_CCMP;
601 }
602}
603
604static int rndis_akm_suite_to_key_mgmt(u32 akm_suite)
605{
606 switch (akm_suite) {
607 default:
608 return RNDIS_WLAN_KEY_MGMT_NONE;
609 case WLAN_AKM_SUITE_8021X:
610 return RNDIS_WLAN_KEY_MGMT_802_1X;
611 case WLAN_AKM_SUITE_PSK:
612 return RNDIS_WLAN_KEY_MGMT_PSK;
613 }
614}
615
616
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300617#ifdef DEBUG
618static const char *oid_to_string(__le32 oid)
619{
620 switch (oid) {
621#define OID_STR(oid) case oid: return(#oid)
622 /* from rndis_host.h */
623 OID_STR(OID_802_3_PERMANENT_ADDRESS);
624 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
625 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
626 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
627
628 /* from rndis_wlan.c */
629 OID_STR(OID_GEN_LINK_SPEED);
630 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
631
632 OID_STR(OID_GEN_XMIT_OK);
633 OID_STR(OID_GEN_RCV_OK);
634 OID_STR(OID_GEN_XMIT_ERROR);
635 OID_STR(OID_GEN_RCV_ERROR);
636 OID_STR(OID_GEN_RCV_NO_BUFFER);
637
638 OID_STR(OID_802_3_CURRENT_ADDRESS);
639 OID_STR(OID_802_3_MULTICAST_LIST);
640 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
641
642 OID_STR(OID_802_11_BSSID);
643 OID_STR(OID_802_11_SSID);
644 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
645 OID_STR(OID_802_11_ADD_WEP);
646 OID_STR(OID_802_11_REMOVE_WEP);
647 OID_STR(OID_802_11_DISASSOCIATE);
648 OID_STR(OID_802_11_AUTHENTICATION_MODE);
649 OID_STR(OID_802_11_PRIVACY_FILTER);
650 OID_STR(OID_802_11_BSSID_LIST_SCAN);
651 OID_STR(OID_802_11_ENCRYPTION_STATUS);
652 OID_STR(OID_802_11_ADD_KEY);
653 OID_STR(OID_802_11_REMOVE_KEY);
654 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
655 OID_STR(OID_802_11_PMKID);
656 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
657 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
658 OID_STR(OID_802_11_TX_POWER_LEVEL);
659 OID_STR(OID_802_11_RSSI);
660 OID_STR(OID_802_11_RSSI_TRIGGER);
661 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
662 OID_STR(OID_802_11_RTS_THRESHOLD);
663 OID_STR(OID_802_11_SUPPORTED_RATES);
664 OID_STR(OID_802_11_CONFIGURATION);
665 OID_STR(OID_802_11_BSSID_LIST);
666#undef OID_STR
667 }
668
669 return "?";
670}
671#else
672static const char *oid_to_string(__le32 oid)
673{
674 return "?";
675}
676#endif
677
678
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200679/* translate error code */
680static int rndis_error_status(__le32 rndis_status)
681{
682 int ret = -EINVAL;
683 switch (rndis_status) {
684 case RNDIS_STATUS_SUCCESS:
685 ret = 0;
686 break;
687 case RNDIS_STATUS_FAILURE:
688 case RNDIS_STATUS_INVALID_DATA:
689 ret = -EINVAL;
690 break;
691 case RNDIS_STATUS_NOT_SUPPORTED:
692 ret = -EOPNOTSUPP;
693 break;
694 case RNDIS_STATUS_ADAPTER_NOT_READY:
695 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
696 ret = -EBUSY;
697 break;
698 }
699 return ret;
700}
701
702
703static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
704{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300705 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200706 union {
707 void *buf;
708 struct rndis_msg_hdr *header;
709 struct rndis_query *get;
710 struct rndis_query_c *get_c;
711 } u;
712 int ret, buflen;
713
714 buflen = *len + sizeof(*u.get);
715 if (buflen < CONTROL_BUFFER_SIZE)
716 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300717
718 if (buflen > COMMAND_BUFFER_SIZE) {
719 u.buf = kmalloc(buflen, GFP_KERNEL);
720 if (!u.buf)
721 return -ENOMEM;
722 } else {
723 u.buf = priv->command_buffer;
724 }
725
726 mutex_lock(&priv->command_lock);
727
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200728 memset(u.get, 0, sizeof *u.get);
729 u.get->msg_type = RNDIS_MSG_QUERY;
Harvey Harrison35c26c22009-02-14 22:56:56 -0800730 u.get->msg_len = cpu_to_le32(sizeof *u.get);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200731 u.get->oid = oid;
732
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300733 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300734 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300735 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300736 if (ret < 0)
737 devdbg(dev, "rndis_query_oid(%s): rndis_command() failed, %d "
738 "(%08x)", oid_to_string(oid), ret,
739 le32_to_cpu(u.get_c->status));
740
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200741 if (ret == 0) {
742 ret = le32_to_cpu(u.get_c->len);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +0300743 if (ret > *len)
744 *len = ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200745 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
746 ret = rndis_error_status(u.get_c->status);
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300747
748 if (ret < 0)
749 devdbg(dev, "rndis_query_oid(%s): device returned "
750 "error, 0x%08x (%d)", oid_to_string(oid),
751 le32_to_cpu(u.get_c->status), ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200752 }
753
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300754 mutex_unlock(&priv->command_lock);
755
756 if (u.buf != priv->command_buffer)
757 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200758 return ret;
759}
760
761
762static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
763{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300764 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200765 union {
766 void *buf;
767 struct rndis_msg_hdr *header;
768 struct rndis_set *set;
769 struct rndis_set_c *set_c;
770 } u;
771 int ret, buflen;
772
773 buflen = len + sizeof(*u.set);
774 if (buflen < CONTROL_BUFFER_SIZE)
775 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300776
777 if (buflen > COMMAND_BUFFER_SIZE) {
778 u.buf = kmalloc(buflen, GFP_KERNEL);
779 if (!u.buf)
780 return -ENOMEM;
781 } else {
782 u.buf = priv->command_buffer;
783 }
784
785 mutex_lock(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200786
787 memset(u.set, 0, sizeof *u.set);
788 u.set->msg_type = RNDIS_MSG_SET;
789 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
790 u.set->oid = oid;
791 u.set->len = cpu_to_le32(len);
Harvey Harrison35c26c22009-02-14 22:56:56 -0800792 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
793 u.set->handle = cpu_to_le32(0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200794 memcpy(u.buf + sizeof(*u.set), data, len);
795
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300796 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300797 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300798 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300799 if (ret < 0)
800 devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
801 "(%08x)", oid_to_string(oid), ret,
802 le32_to_cpu(u.set_c->status));
803
804 if (ret == 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200805 ret = rndis_error_status(u.set_c->status);
806
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300807 if (ret < 0)
808 devdbg(dev, "rndis_set_oid(%s): device returned error, "
809 "0x%08x (%d)", oid_to_string(oid),
810 le32_to_cpu(u.set_c->status), ret);
811 }
812
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300813 mutex_unlock(&priv->command_lock);
814
815 if (u.buf != priv->command_buffer)
816 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200817 return ret;
818}
819
820
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300821static int rndis_reset(struct usbnet *usbdev)
822{
823 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
824 struct rndis_reset *reset;
825 int ret;
826
827 mutex_lock(&priv->command_lock);
828
829 reset = (void *)priv->command_buffer;
830 memset(reset, 0, sizeof(*reset));
831 reset->msg_type = RNDIS_MSG_RESET;
832 reset->msg_len = cpu_to_le32(sizeof(*reset));
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300833 priv->current_command_oid = 0;
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300834 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
835
836 mutex_unlock(&priv->command_lock);
837
838 if (ret < 0)
839 return ret;
840 return 0;
841}
842
843
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200844/*
845 * Specs say that we can only set config parameters only soon after device
846 * initialization.
847 * value_type: 0 = u32, 2 = unicode string
848 */
849static int rndis_set_config_parameter(struct usbnet *dev, char *param,
850 int value_type, void *value)
851{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200852 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200853 int value_len, info_len, param_len, ret, i;
854 __le16 *unibuf;
855 __le32 *dst_value;
856
857 if (value_type == 0)
858 value_len = sizeof(__le32);
859 else if (value_type == 2)
860 value_len = strlen(value) * sizeof(__le16);
861 else
862 return -EINVAL;
863
864 param_len = strlen(param) * sizeof(__le16);
865 info_len = sizeof(*infobuf) + param_len + value_len;
866
867#ifdef DEBUG
868 info_len += 12;
869#endif
870 infobuf = kmalloc(info_len, GFP_KERNEL);
871 if (!infobuf)
872 return -ENOMEM;
873
874#ifdef DEBUG
875 info_len -= 12;
876 /* extra 12 bytes are for padding (debug output) */
877 memset(infobuf, 0xCC, info_len + 12);
878#endif
879
880 if (value_type == 2)
881 devdbg(dev, "setting config parameter: %s, value: %s",
882 param, (u8 *)value);
883 else
884 devdbg(dev, "setting config parameter: %s, value: %d",
885 param, *(u32 *)value);
886
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200887 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
888 infobuf->name_length = cpu_to_le32(param_len);
889 infobuf->type = cpu_to_le32(value_type);
890 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
891 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200892
893 /* simple string to unicode string conversion */
894 unibuf = (void *)infobuf + sizeof(*infobuf);
895 for (i = 0; i < param_len / sizeof(__le16); i++)
896 unibuf[i] = cpu_to_le16(param[i]);
897
898 if (value_type == 2) {
899 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
900 for (i = 0; i < value_len / sizeof(__le16); i++)
901 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
902 } else {
903 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
904 *dst_value = cpu_to_le32(*(u32 *)value);
905 }
906
907#ifdef DEBUG
908 devdbg(dev, "info buffer (len: %d):", info_len);
909 for (i = 0; i < info_len; i += 12) {
910 u32 *tmp = (u32 *)((u8 *)infobuf + i);
911 devdbg(dev, "%08X:%08X:%08X",
912 cpu_to_be32(tmp[0]),
913 cpu_to_be32(tmp[1]),
914 cpu_to_be32(tmp[2]));
915 }
916#endif
917
918 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
919 infobuf, info_len);
920 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200921 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200922
923 kfree(infobuf);
924 return ret;
925}
926
927static int rndis_set_config_parameter_str(struct usbnet *dev,
928 char *param, char *value)
929{
930 return(rndis_set_config_parameter(dev, param, 2, value));
931}
932
933/*static int rndis_set_config_parameter_u32(struct usbnet *dev,
934 char *param, u32 value)
935{
936 return(rndis_set_config_parameter(dev, param, 0, &value));
937}*/
938
939
940/*
941 * data conversion functions
942 */
943static int level_to_qual(int level)
944{
945 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
946 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
947}
948
949
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200950/*
951 * common functions
952 */
Jussi Kivilinna9f77cca2009-08-28 12:59:26 +0300953static int set_infra_mode(struct usbnet *usbdev, int mode);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300954static void restore_keys(struct usbnet *usbdev);
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +0300955static int rndis_check_bssid_list(struct usbnet *usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200956
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200957static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200958{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300959 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200960 int ret;
961
962 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300963 if (ret < 0) {
964 devwarn(usbdev, "setting SSID failed (%08X)", ret);
965 return ret;
966 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200967 if (ret == 0) {
968 memcpy(&priv->essid, ssid, sizeof(priv->essid));
969 priv->radio_on = 1;
970 devdbg(usbdev, "set_essid: radio_on = 1");
971 }
972
973 return ret;
974}
975
Jussi Kivilinna5c523232009-08-28 13:27:47 +0300976static int set_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
977{
978 int ret;
979
980 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
981 if (ret < 0) {
982 devwarn(usbdev, "setting BSSID[%pM] failed (%08X)", bssid, ret);
983 return ret;
984 }
985
986 return ret;
987}
988
989static int clear_bssid(struct usbnet *usbdev)
990{
991 u8 broadcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
992
993 return set_bssid(usbdev, broadcast_mac);
994}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200995
996static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
997{
998 int ret, len;
999
1000 len = ETH_ALEN;
1001 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
1002
1003 if (ret != 0)
1004 memset(bssid, 0, ETH_ALEN);
1005
1006 return ret;
1007}
1008
Scott Ashcroft43646232008-05-27 00:06:15 +03001009static int get_association_info(struct usbnet *usbdev,
1010 struct ndis_80211_assoc_info *info, int len)
1011{
1012 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
1013 info, &len);
1014}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001015
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001016static bool is_associated(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001017{
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001018 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001019 u8 bssid[ETH_ALEN];
1020 int ret;
1021
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001022 if (!priv->radio_on)
1023 return false;
1024
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001025 ret = get_bssid(usbdev, bssid);
1026
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001027 return (ret == 0 && !is_zero_ether_addr(bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001028}
1029
1030
1031static int disassociate(struct usbnet *usbdev, int reset_ssid)
1032{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001033 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001034 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001035 int i, ret = 0;
1036
1037 if (priv->radio_on) {
1038 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
1039 if (ret == 0) {
1040 priv->radio_on = 0;
1041 devdbg(usbdev, "disassociate: radio_on = 0");
1042
1043 if (reset_ssid)
1044 msleep(100);
1045 }
1046 }
1047
1048 /* disassociate causes radio to be turned off; if reset_ssid
1049 * is given, set random ssid to enable radio */
1050 if (reset_ssid) {
Jussi Kivilinna9f77cca2009-08-28 12:59:26 +03001051 /* Set device to infrastructure mode so we don't get ad-hoc
1052 * 'media connect' indications with the random ssid.
1053 */
1054 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1055
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001056 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1057 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1058 ssid.essid[0] = 0x1;
1059 ssid.essid[1] = 0xff;
1060 for (i = 2; i < sizeof(ssid.essid); i++)
1061 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001062 ret = set_essid(usbdev, &ssid);
1063 }
1064 return ret;
1065}
1066
1067
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001068static int set_auth_mode(struct usbnet *usbdev, u32 wpa_version,
1069 enum nl80211_auth_type auth_type, int keymgmt)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001070{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001071 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001072 __le32 tmp;
1073 int auth_mode, ret;
1074
1075 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001076 "keymgmt=0x%x", wpa_version, auth_type, keymgmt);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001077
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001078 if (wpa_version & NL80211_WPA_VERSION_2) {
1079 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001080 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001081 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001082 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001083 } else if (wpa_version & NL80211_WPA_VERSION_1) {
1084 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001085 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001086 else if (keymgmt & RNDIS_WLAN_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001087 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001088 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001089 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001090 } else if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
1091 auth_mode = NDIS_80211_AUTH_SHARED;
1092 else if (auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001093 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001094 else
1095 return -ENOTSUPP;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001096
1097 tmp = cpu_to_le32(auth_mode);
1098 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1099 sizeof(tmp));
1100 if (ret != 0) {
1101 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
1102 return ret;
1103 }
1104
1105 priv->wpa_version = wpa_version;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001106 priv->wpa_auth_type = auth_type;
1107 priv->wpa_keymgmt = keymgmt;
1108
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001109 return 0;
1110}
1111
1112
1113static int set_priv_filter(struct usbnet *usbdev)
1114{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001115 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001116 __le32 tmp;
1117
1118 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
1119
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001120 if (priv->wpa_version & NL80211_WPA_VERSION_2 ||
1121 priv->wpa_version & NL80211_WPA_VERSION_1)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001122 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001123 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001124 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001125
1126 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1127 sizeof(tmp));
1128}
1129
1130
1131static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1132{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001133 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001134 __le32 tmp;
1135 int encr_mode, ret;
1136
1137 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001138 pairwise, groupwise);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001139
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001140 if (pairwise & RNDIS_WLAN_ALG_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001141 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001142 else if (pairwise & RNDIS_WLAN_ALG_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001143 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001144 else if (pairwise & RNDIS_WLAN_ALG_WEP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001145 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001146 else if (groupwise & RNDIS_WLAN_ALG_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001147 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001148 else if (groupwise & RNDIS_WLAN_ALG_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001149 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001150 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001151 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001152
1153 tmp = cpu_to_le32(encr_mode);
1154 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1155 sizeof(tmp));
1156 if (ret != 0) {
1157 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
1158 return ret;
1159 }
1160
1161 priv->wpa_cipher_pair = pairwise;
1162 priv->wpa_cipher_group = groupwise;
1163 return 0;
1164}
1165
1166
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001167static int set_infra_mode(struct usbnet *usbdev, int mode)
1168{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001169 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001170 __le32 tmp;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001171 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001172
1173 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
1174
1175 tmp = cpu_to_le32(mode);
1176 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1177 sizeof(tmp));
1178 if (ret != 0) {
1179 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
1180 return ret;
1181 }
1182
1183 /* NDIS drivers clear keys when infrastructure mode is
1184 * changed. But Linux tools assume otherwise. So set the
1185 * keys */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001186 restore_keys(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001187
1188 priv->infra_mode = mode;
1189 return 0;
1190}
1191
1192
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001193static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1194{
1195 __le32 tmp;
1196
1197 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1198
1199 if (rts_threshold < 0 || rts_threshold > 2347)
1200 rts_threshold = 2347;
1201
1202 tmp = cpu_to_le32(rts_threshold);
1203 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1204 sizeof(tmp));
1205}
1206
1207
1208static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1209{
1210 __le32 tmp;
1211
1212 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1213
1214 if (frag_threshold < 256 || frag_threshold > 2346)
1215 frag_threshold = 2346;
1216
1217 tmp = cpu_to_le32(frag_threshold);
1218 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1219 sizeof(tmp));
1220}
1221
1222
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001223static void set_default_iw_params(struct usbnet *usbdev)
1224{
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001225 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001226 set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
1227 RNDIS_WLAN_KEY_MGMT_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001228 set_priv_filter(usbdev);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001229 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001230}
1231
1232
1233static int deauthenticate(struct usbnet *usbdev)
1234{
1235 int ret;
1236
1237 ret = disassociate(usbdev, 1);
1238 set_default_iw_params(usbdev);
1239 return ret;
1240}
1241
1242
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001243static int set_channel(struct usbnet *usbdev, int channel)
1244{
1245 struct ndis_80211_conf config;
1246 unsigned int dsconfig;
1247 int len, ret;
1248
1249 devdbg(usbdev, "set_channel(%d)", channel);
1250
1251 /* this OID is valid only when not associated */
1252 if (is_associated(usbdev))
1253 return 0;
1254
1255 dsconfig = ieee80211_dsss_chan_to_freq(channel) * 1000;
1256
1257 len = sizeof(config);
1258 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1259 if (ret < 0) {
1260 devdbg(usbdev, "set_channel: querying configuration failed");
1261 return ret;
1262 }
1263
1264 config.ds_config = cpu_to_le32(dsconfig);
1265 ret = rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
1266 sizeof(config));
1267
1268 devdbg(usbdev, "set_channel: %d -> %d", channel, ret);
1269
1270 return ret;
1271}
1272
1273
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001274/* index must be 0 - N, as per NDIS */
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001275static int add_wep_key(struct usbnet *usbdev, const u8 *key, int key_len,
1276 int index)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001277{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001278 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001279 struct ndis_80211_wep_key ndis_key;
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001280 u32 cipher;
1281 int ret;
1282
1283 devdbg(usbdev, "add_wep_key(idx: %d, len: %d)", index, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001284
Jussi Kivilinna40ba60d2009-08-20 21:00:34 +03001285 if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001286 return -EINVAL;
1287
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001288 if (key_len == 5)
1289 cipher = WLAN_CIPHER_SUITE_WEP40;
1290 else
1291 cipher = WLAN_CIPHER_SUITE_WEP104;
1292
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001293 memset(&ndis_key, 0, sizeof(ndis_key));
1294
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001295 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1296 ndis_key.length = cpu_to_le32(key_len);
1297 ndis_key.index = cpu_to_le32(index);
1298 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001299
1300 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001301 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001302 ret = set_encr_mode(usbdev, RNDIS_WLAN_ALG_WEP,
1303 RNDIS_WLAN_ALG_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001304 if (ret)
1305 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1306 ret);
1307 }
1308
1309 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1310 sizeof(ndis_key));
1311 if (ret != 0) {
1312 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1313 index+1, ret);
1314 return ret;
1315 }
1316
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001317 priv->encr_keys[index].len = key_len;
1318 priv->encr_keys[index].cipher = cipher;
1319 memcpy(&priv->encr_keys[index].material, key, key_len);
1320 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001321
1322 return 0;
1323}
1324
1325
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001326static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001327 int index, const u8 *addr, const u8 *rx_seq,
1328 int seq_len, u32 cipher, int flags)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001329{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001330 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001331 struct ndis_80211_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001332 bool is_addr_ok;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001333 int ret;
1334
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001335 if (index < 0 || index >= 4) {
1336 devdbg(usbdev, "add_wpa_key: index out of range (%i)", index);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001337 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001338 }
1339 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1340 devdbg(usbdev, "add_wpa_key: key length out of range (%i)",
1341 key_len);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001342 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001343 }
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001344 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) {
1345 if (!rx_seq || seq_len <= 0) {
1346 devdbg(usbdev, "add_wpa_key: recv seq flag without"
1347 "buffer");
1348 return -EINVAL;
1349 }
1350 if (rx_seq && seq_len > sizeof(ndis_key.rsc)) {
1351 devdbg(usbdev, "add_wpa_key: too big recv seq buffer");
1352 return -EINVAL;
1353 }
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001354 }
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001355
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001356 is_addr_ok = addr && !is_zero_ether_addr(addr) &&
1357 !is_broadcast_ether_addr(addr);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001358 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1359 devdbg(usbdev, "add_wpa_key: pairwise but bssid invalid (%pM)",
1360 addr);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001361 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001362 }
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001363
1364 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001365 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1366 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1367 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001368
1369 memset(&ndis_key, 0, sizeof(ndis_key));
1370
1371 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1372 sizeof(ndis_key.material) + key_len);
1373 ndis_key.length = cpu_to_le32(key_len);
1374 ndis_key.index = cpu_to_le32(index) | flags;
1375
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001376 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001377 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1378 * different order than NDIS spec, so swap the order here. */
1379 memcpy(ndis_key.material, key, 16);
1380 memcpy(ndis_key.material + 16, key + 24, 8);
1381 memcpy(ndis_key.material + 24, key + 16, 8);
1382 } else
1383 memcpy(ndis_key.material, key, key_len);
1384
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001385 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001386 memcpy(ndis_key.rsc, rx_seq, seq_len);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001387
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001388 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001389 /* pairwise key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001390 memcpy(ndis_key.bssid, addr, ETH_ALEN);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001391 } else {
1392 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001393 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001394 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1395 else
1396 get_bssid(usbdev, ndis_key.bssid);
1397 }
1398
1399 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1400 le32_to_cpu(ndis_key.size));
1401 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1402 if (ret != 0)
1403 return ret;
1404
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001405 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1406 priv->encr_keys[index].len = key_len;
1407 priv->encr_keys[index].cipher = cipher;
1408 memcpy(&priv->encr_keys[index].material, key, key_len);
1409 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1410 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1411 else
1412 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinna98391782009-05-22 17:40:34 +03001413
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001414 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001415 priv->encr_tx_key_index = index;
1416
1417 return 0;
1418}
1419
1420
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001421static int restore_key(struct usbnet *usbdev, int key_idx)
1422{
1423 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1424 struct rndis_wlan_encr_key key;
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001425
1426 if (is_wpa_key(priv, key_idx))
1427 return 0;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001428
1429 key = priv->encr_keys[key_idx];
1430
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001431 devdbg(usbdev, "restore_key: %i:%i", key_idx, key.len);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001432
1433 if (key.len == 0)
1434 return 0;
1435
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001436 return add_wep_key(usbdev, key.material, key.len, key_idx);
1437}
1438
1439
1440static void restore_keys(struct usbnet *usbdev)
1441{
1442 int i;
1443
1444 for (i = 0; i < 4; i++)
1445 restore_key(usbdev, i);
1446}
1447
1448
1449static void clear_key(struct rndis_wlan_private *priv, int idx)
1450{
1451 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1452}
1453
1454
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001455/* remove_key is for both wep and wpa */
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03001456static int remove_key(struct usbnet *usbdev, int index, const u8 *bssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001457{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001458 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001459 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001460 __le32 keyindex;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001461 bool is_wpa;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001462 int ret;
1463
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001464 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001465 return 0;
1466
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001467 is_wpa = is_wpa_key(priv, index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001468
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001469 devdbg(usbdev, "remove_key: %i:%s:%i", index, is_wpa ? "wpa" : "wep",
1470 priv->encr_keys[index].len);
1471
1472 clear_key(priv, index);
1473
1474 if (is_wpa) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001475 remove_key.size = cpu_to_le32(sizeof(remove_key));
1476 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001477 if (bssid) {
1478 /* pairwise key */
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001479 if (!is_broadcast_ether_addr(bssid))
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001480 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001481 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001482 memcpy(remove_key.bssid, bssid,
1483 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001484 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001485 memset(remove_key.bssid, 0xff,
1486 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001487
1488 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1489 sizeof(remove_key));
1490 if (ret != 0)
1491 return ret;
1492 } else {
1493 keyindex = cpu_to_le32(index);
1494 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1495 sizeof(keyindex));
1496 if (ret != 0) {
1497 devwarn(usbdev,
1498 "removing encryption key %d failed (%08X)",
1499 index, ret);
1500 return ret;
1501 }
1502 }
1503
1504 /* if it is transmit key, disable encryption */
1505 if (index == priv->encr_tx_key_index)
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001506 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001507
1508 return 0;
1509}
1510
1511
1512static void set_multicast_list(struct usbnet *usbdev)
1513{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001514 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001515 struct dev_mc_list *mclist;
1516 __le32 filter;
1517 int ret, i, size;
1518 char *buf;
1519
1520 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1521
1522 if (usbdev->net->flags & IFF_PROMISC) {
1523 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1524 RNDIS_PACKET_TYPE_ALL_LOCAL;
1525 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1526 usbdev->net->mc_count > priv->multicast_size) {
1527 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1528 } else if (usbdev->net->mc_count > 0) {
1529 size = min(priv->multicast_size, usbdev->net->mc_count);
1530 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1531 if (!buf) {
1532 devwarn(usbdev,
1533 "couldn't alloc %d bytes of memory",
1534 size * ETH_ALEN);
1535 return;
1536 }
1537
1538 mclist = usbdev->net->mc_list;
1539 for (i = 0; i < size && mclist; mclist = mclist->next) {
1540 if (mclist->dmi_addrlen != ETH_ALEN)
1541 continue;
1542
1543 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1544 i++;
1545 }
1546
1547 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1548 i * ETH_ALEN);
1549 if (ret == 0 && i > 0)
1550 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1551 else
1552 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1553
1554 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1555 i, priv->multicast_size, ret);
1556
1557 kfree(buf);
1558 }
1559
1560 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1561 sizeof(filter));
1562 if (ret < 0) {
1563 devwarn(usbdev, "couldn't set packet filter: %08x",
1564 le32_to_cpu(filter));
1565 }
1566
1567 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1568 le32_to_cpu(filter), ret);
1569}
1570
1571
1572/*
John W. Linville964c1d42009-03-26 23:40:01 +02001573 * cfg80211 ops
1574 */
Johannes Berge36d56b2009-06-09 21:04:43 +02001575static int rndis_change_virtual_intf(struct wiphy *wiphy,
1576 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +02001577 enum nl80211_iftype type, u32 *flags,
1578 struct vif_params *params)
1579{
Jussi Kivilinna16139172009-08-28 12:59:21 +03001580 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1581 struct usbnet *usbdev = priv->usbdev;
John W. Linville964c1d42009-03-26 23:40:01 +02001582 int mode;
1583
John W. Linville964c1d42009-03-26 23:40:01 +02001584 switch (type) {
1585 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001586 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001587 break;
1588 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001589 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001590 break;
1591 default:
1592 return -EINVAL;
1593 }
1594
Jussi Kivilinna16139172009-08-28 12:59:21 +03001595 priv->wdev.iftype = type;
1596
John W. Linville964c1d42009-03-26 23:40:01 +02001597 return set_infra_mode(usbdev, mode);
1598}
1599
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001600
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001601static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1602{
1603 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1604 struct usbnet *usbdev = priv->usbdev;
1605 int err;
1606
1607 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1608 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1609 if (err < 0)
1610 return err;
1611 }
1612
1613 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1614 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1615 if (err < 0)
1616 return err;
1617 }
1618
1619 return 0;
1620}
1621
1622
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001623static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1624 int dbm)
1625{
1626 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1627 struct usbnet *usbdev = priv->usbdev;
1628
1629 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1630
1631 /* Device doesn't support changing txpower after initialization, only
1632 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1633 * currently used.
1634 */
1635 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1636 if (!priv->radio_on)
1637 disassociate(usbdev, 1); /* turn on radio */
1638
1639 return 0;
1640 }
1641
1642 return -ENOTSUPP;
1643}
1644
1645
1646static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1647{
1648 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1649 struct usbnet *usbdev = priv->usbdev;
1650
1651 *dbm = get_bcm4320_power_dbm(priv);
1652
1653 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1654
1655 return 0;
1656}
1657
1658
Jussi Kivilinnab1d25a62009-08-28 12:59:05 +03001659#define SCAN_DELAY_JIFFIES (6 * HZ)
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001660static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1661 struct cfg80211_scan_request *request)
1662{
1663 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001664 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001665 int ret;
1666 __le32 tmp;
1667
1668 devdbg(usbdev, "cfg80211.scan");
1669
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +03001670 /* Get current bssid list from device before new scan, as new scan
1671 * clears internal bssid list.
1672 */
1673 rndis_check_bssid_list(usbdev);
1674
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001675 if (!request)
1676 return -EINVAL;
1677
1678 if (priv->scan_request && priv->scan_request != request)
1679 return -EBUSY;
1680
1681 priv->scan_request = request;
1682
1683 tmp = cpu_to_le32(1);
1684 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1685 sizeof(tmp));
1686 if (ret == 0) {
1687 /* Wait before retrieving scan results from device */
1688 queue_delayed_work(priv->workqueue, &priv->scan_work,
1689 SCAN_DELAY_JIFFIES);
1690 }
1691
1692 return ret;
1693}
1694
1695
1696static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1697 struct ndis_80211_bssid_ex *bssid)
1698{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001699 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001700 struct ieee80211_channel *channel;
1701 s32 signal;
1702 u64 timestamp;
1703 u16 capability;
1704 u16 beacon_interval;
1705 struct ndis_80211_fixed_ies *fixed;
1706 int ie_len, bssid_len;
1707 u8 *ie;
1708
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001709 devdbg(usbdev, " found bssid: '%.32s' [%pM]", bssid->ssid.essid,
1710 bssid->mac);
1711
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001712 /* parse bssid structure */
1713 bssid_len = le32_to_cpu(bssid->length);
1714
1715 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1716 sizeof(struct ndis_80211_fixed_ies))
1717 return NULL;
1718
1719 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1720
1721 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1722 ie_len = min(bssid_len - (int)sizeof(*bssid),
1723 (int)le32_to_cpu(bssid->ie_length));
1724 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1725 if (ie_len < 0)
1726 return NULL;
1727
1728 /* extract data for cfg80211_inform_bss */
1729 channel = ieee80211_get_channel(priv->wdev.wiphy,
1730 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1731 if (!channel)
1732 return NULL;
1733
1734 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1735 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1736 capability = le16_to_cpu(fixed->capabilities);
1737 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1738
1739 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1740 timestamp, capability, beacon_interval, ie, ie_len, signal,
1741 GFP_KERNEL);
1742}
1743
1744
1745static int rndis_check_bssid_list(struct usbnet *usbdev)
1746{
1747 void *buf = NULL;
1748 struct ndis_80211_bssid_list_ex *bssid_list;
1749 struct ndis_80211_bssid_ex *bssid;
1750 int ret = -EINVAL, len, count, bssid_len;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001751 bool resized = false;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001752
1753 devdbg(usbdev, "check_bssid_list");
1754
1755 len = CONTROL_BUFFER_SIZE;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001756resize_buf:
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001757 buf = kmalloc(len, GFP_KERNEL);
1758 if (!buf) {
1759 ret = -ENOMEM;
1760 goto out;
1761 }
1762
1763 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1764 if (ret != 0)
1765 goto out;
1766
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001767 if (!resized && len > CONTROL_BUFFER_SIZE) {
1768 resized = true;
1769 kfree(buf);
1770 goto resize_buf;
1771 }
1772
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001773 bssid_list = buf;
1774 bssid = bssid_list->bssid;
1775 bssid_len = le32_to_cpu(bssid->length);
1776 count = le32_to_cpu(bssid_list->num_items);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001777 devdbg(usbdev, "check_bssid_list: %d BSSIDs found (buflen: %d)", count,
1778 len);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001779
1780 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1781 rndis_bss_info_update(usbdev, bssid);
1782
1783 bssid = (void *)bssid + bssid_len;
1784 bssid_len = le32_to_cpu(bssid->length);
1785 count--;
1786 }
1787
1788out:
1789 kfree(buf);
1790 return ret;
1791}
1792
1793
1794static void rndis_get_scan_results(struct work_struct *work)
1795{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001796 struct rndis_wlan_private *priv =
1797 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001798 struct usbnet *usbdev = priv->usbdev;
1799 int ret;
1800
1801 devdbg(usbdev, "get_scan_results");
1802
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03001803 if (!priv->scan_request)
1804 return;
1805
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001806 ret = rndis_check_bssid_list(usbdev);
1807
1808 cfg80211_scan_done(priv->scan_request, ret < 0);
1809
1810 priv->scan_request = NULL;
1811}
1812
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001813static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
1814 struct cfg80211_connect_params *sme)
1815{
1816 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1817 struct usbnet *usbdev = priv->usbdev;
1818 struct ieee80211_channel *channel = sme->channel;
1819 struct ndis_80211_ssid ssid;
1820 int pairwise = RNDIS_WLAN_ALG_NONE;
1821 int groupwise = RNDIS_WLAN_ALG_NONE;
1822 int keymgmt = RNDIS_WLAN_KEY_MGMT_NONE;
1823 int length, i, ret, chan = -1;
1824
1825 if (channel)
1826 chan = ieee80211_frequency_to_channel(channel->center_freq);
1827
1828 groupwise = rndis_cipher_to_alg(sme->crypto.cipher_group);
1829 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
1830 pairwise |=
1831 rndis_cipher_to_alg(sme->crypto.ciphers_pairwise[i]);
1832
1833 if (sme->crypto.n_ciphers_pairwise > 0 &&
1834 pairwise == RNDIS_WLAN_ALG_NONE) {
1835 deverr(usbdev, "Unsupported pairwise cipher");
1836 return -ENOTSUPP;
1837 }
1838
1839 for (i = 0; i < sme->crypto.n_akm_suites; i++)
1840 keymgmt |=
1841 rndis_akm_suite_to_key_mgmt(sme->crypto.akm_suites[i]);
1842
1843 if (sme->crypto.n_akm_suites > 0 &&
1844 keymgmt == RNDIS_WLAN_KEY_MGMT_NONE) {
1845 deverr(usbdev, "Invalid keymgmt");
1846 return -ENOTSUPP;
1847 }
1848
1849 devdbg(usbdev, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:"
1850 "0x%x]:0x%x)", sme->ssid, sme->bssid, chan,
1851 sme->privacy, sme->crypto.wpa_versions, sme->auth_type,
1852 groupwise, pairwise, keymgmt);
1853
1854 if (is_associated(usbdev))
1855 disassociate(usbdev, false);
1856
1857 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1858 if (ret < 0) {
1859 devdbg(usbdev, "connect: set_infra_mode failed, %d", ret);
1860 goto err_turn_radio_on;
1861 }
1862
1863 ret = set_auth_mode(usbdev, sme->crypto.wpa_versions, sme->auth_type,
1864 keymgmt);
1865 if (ret < 0) {
1866 devdbg(usbdev, "connect: set_auth_mode failed, %d", ret);
1867 goto err_turn_radio_on;
1868 }
1869
1870 set_priv_filter(usbdev);
1871
1872 ret = set_encr_mode(usbdev, pairwise, groupwise);
1873 if (ret < 0) {
1874 devdbg(usbdev, "connect: set_encr_mode failed, %d", ret);
1875 goto err_turn_radio_on;
1876 }
1877
1878 if (channel) {
1879 ret = set_channel(usbdev, chan);
1880 if (ret < 0) {
1881 devdbg(usbdev, "connect: set_channel failed, %d", ret);
1882 goto err_turn_radio_on;
1883 }
1884 }
1885
1886 if (sme->key && ((groupwise | pairwise) & RNDIS_WLAN_ALG_WEP)) {
1887 priv->encr_tx_key_index = sme->key_idx;
1888 ret = add_wep_key(usbdev, sme->key, sme->key_len, sme->key_idx);
1889 if (ret < 0) {
1890 devdbg(usbdev, "connect: add_wep_key failed, %d "
1891 "(%d, %d)", ret, sme->key_len, sme->key_idx);
1892 goto err_turn_radio_on;
1893 }
1894 }
1895
1896 if (sme->bssid && !is_zero_ether_addr(sme->bssid) &&
1897 !is_broadcast_ether_addr(sme->bssid)) {
1898 ret = set_bssid(usbdev, sme->bssid);
1899 if (ret < 0) {
1900 devdbg(usbdev, "connect: set_bssid failed, %d", ret);
1901 goto err_turn_radio_on;
1902 }
1903 } else
1904 clear_bssid(usbdev);
1905
1906 length = sme->ssid_len;
1907 if (length > NDIS_802_11_LENGTH_SSID)
1908 length = NDIS_802_11_LENGTH_SSID;
1909
1910 memset(&ssid, 0, sizeof(ssid));
1911 ssid.length = cpu_to_le32(length);
1912 memcpy(ssid.essid, sme->ssid, length);
1913
1914 /* Pause and purge rx queue, so we don't pass packets before
1915 * 'media connect'-indication.
1916 */
1917 usbnet_pause_rx(usbdev);
1918 usbnet_purge_paused_rxq(usbdev);
1919
1920 ret = set_essid(usbdev, &ssid);
1921 if (ret < 0)
1922 devdbg(usbdev, "connect: set_essid failed, %d", ret);
1923 return ret;
1924
1925err_turn_radio_on:
1926 disassociate(usbdev, 1);
1927
1928 return ret;
1929}
1930
1931static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
1932 u16 reason_code)
1933{
1934 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1935 struct usbnet *usbdev = priv->usbdev;
1936
1937 devdbg(usbdev, "cfg80211.disconnect(%d)", reason_code);
1938
1939 priv->connected = false;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03001940 memset(priv->bssid, 0, ETH_ALEN);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03001941
1942 return deauthenticate(usbdev);
1943}
1944
1945static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1946 struct cfg80211_ibss_params *params)
1947{
1948 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1949 struct usbnet *usbdev = priv->usbdev;
1950 struct ieee80211_channel *channel = params->channel;
1951 struct ndis_80211_ssid ssid;
1952 enum nl80211_auth_type auth_type;
1953 int ret, alg, length, chan = -1;
1954
1955 if (channel)
1956 chan = ieee80211_frequency_to_channel(channel->center_freq);
1957
1958 /* TODO: How to handle ad-hoc encryption?
1959 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
1960 * pre-shared for encryption (open/shared/wpa), is key set before
1961 * join_ibss? Which auth_type to use (not in params)? What about WPA?
1962 */
1963 if (params->privacy) {
1964 auth_type = NL80211_AUTHTYPE_SHARED_KEY;
1965 alg = RNDIS_WLAN_ALG_WEP;
1966 } else {
1967 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
1968 alg = RNDIS_WLAN_ALG_NONE;
1969 }
1970
1971 devdbg(usbdev, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)", params->ssid,
1972 params->bssid, chan, params->privacy);
1973
1974 if (is_associated(usbdev))
1975 disassociate(usbdev, false);
1976
1977 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_ADHOC);
1978 if (ret < 0) {
1979 devdbg(usbdev, "join_ibss: set_infra_mode failed, %d", ret);
1980 goto err_turn_radio_on;
1981 }
1982
1983 ret = set_auth_mode(usbdev, 0, auth_type, RNDIS_WLAN_KEY_MGMT_NONE);
1984 if (ret < 0) {
1985 devdbg(usbdev, "join_ibss: set_auth_mode failed, %d", ret);
1986 goto err_turn_radio_on;
1987 }
1988
1989 set_priv_filter(usbdev);
1990
1991 ret = set_encr_mode(usbdev, alg, RNDIS_WLAN_ALG_NONE);
1992 if (ret < 0) {
1993 devdbg(usbdev, "join_ibss: set_encr_mode failed, %d", ret);
1994 goto err_turn_radio_on;
1995 }
1996
1997 if (channel) {
1998 ret = set_channel(usbdev, chan);
1999 if (ret < 0) {
2000 devdbg(usbdev, "join_ibss: set_channel failed, %d",
2001 ret);
2002 goto err_turn_radio_on;
2003 }
2004 }
2005
2006 if (params->bssid && !is_zero_ether_addr(params->bssid) &&
2007 !is_broadcast_ether_addr(params->bssid)) {
2008 ret = set_bssid(usbdev, params->bssid);
2009 if (ret < 0) {
2010 devdbg(usbdev, "join_ibss: set_bssid failed, %d", ret);
2011 goto err_turn_radio_on;
2012 }
2013 } else
2014 clear_bssid(usbdev);
2015
2016 length = params->ssid_len;
2017 if (length > NDIS_802_11_LENGTH_SSID)
2018 length = NDIS_802_11_LENGTH_SSID;
2019
2020 memset(&ssid, 0, sizeof(ssid));
2021 ssid.length = cpu_to_le32(length);
2022 memcpy(ssid.essid, params->ssid, length);
2023
2024 /* Don't need to pause rx queue for ad-hoc. */
2025 usbnet_purge_paused_rxq(usbdev);
2026 usbnet_resume_rx(usbdev);
2027
2028 ret = set_essid(usbdev, &ssid);
2029 if (ret < 0)
2030 devdbg(usbdev, "join_ibss: set_essid failed, %d", ret);
2031 return ret;
2032
2033err_turn_radio_on:
2034 disassociate(usbdev, 1);
2035
2036 return ret;
2037}
2038
2039static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2040{
2041 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2042 struct usbnet *usbdev = priv->usbdev;
2043
2044 devdbg(usbdev, "cfg80211.leave_ibss()");
2045
2046 priv->connected = false;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002047 memset(priv->bssid, 0, ETH_ALEN);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002048
2049 return deauthenticate(usbdev);
2050}
2051
Jussi Kivilinna5554adb2009-08-28 13:27:53 +03002052static int rndis_set_channel(struct wiphy *wiphy,
2053 struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
2054{
2055 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2056 struct usbnet *usbdev = priv->usbdev;
2057
2058 return set_channel(usbdev,
2059 ieee80211_frequency_to_channel(chan->center_freq));
2060}
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002061
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03002062static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
2063 u8 key_index, const u8 *mac_addr,
2064 struct key_params *params)
2065{
2066 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2067 struct usbnet *usbdev = priv->usbdev;
2068 int flags;
2069
2070 devdbg(usbdev, "rndis_add_key(%i, %pM, %08x)", key_index, mac_addr,
2071 params->cipher);
2072
2073 switch (params->cipher) {
2074 case WLAN_CIPHER_SUITE_WEP40:
2075 case WLAN_CIPHER_SUITE_WEP104:
2076 return add_wep_key(usbdev, params->key, params->key_len,
2077 key_index);
2078 case WLAN_CIPHER_SUITE_TKIP:
2079 case WLAN_CIPHER_SUITE_CCMP:
2080 flags = 0;
2081
2082 if (params->seq && params->seq_len > 0)
2083 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
2084 if (mac_addr)
2085 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY |
2086 NDIS_80211_ADDKEY_TRANSMIT_KEY;
2087
2088 return add_wpa_key(usbdev, params->key, params->key_len,
2089 key_index, mac_addr, params->seq,
2090 params->seq_len, params->cipher, flags);
2091 default:
2092 devdbg(usbdev, "rndis_add_key: unsupported cipher %08x",
2093 params->cipher);
2094 return -ENOTSUPP;
2095 }
2096}
2097
2098static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
2099 u8 key_index, const u8 *mac_addr)
2100{
2101 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2102 struct usbnet *usbdev = priv->usbdev;
2103
2104 devdbg(usbdev, "rndis_del_key(%i, %pM)", key_index, mac_addr);
2105
2106 return remove_key(usbdev, key_index, mac_addr);
2107}
2108
2109static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
2110 u8 key_index)
2111{
2112 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2113 struct usbnet *usbdev = priv->usbdev;
2114 struct rndis_wlan_encr_key key;
2115
2116 devdbg(usbdev, "rndis_set_default_key(%i)", key_index);
2117
2118 priv->encr_tx_key_index = key_index;
2119
2120 key = priv->encr_keys[key_index];
2121
2122 return add_wep_key(usbdev, key.material, key.len, key_index);
2123}
2124
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002125static void rndis_fill_station_info(struct usbnet *usbdev,
2126 struct station_info *sinfo)
2127{
2128 __le32 linkspeed, rssi;
2129 int ret, len;
2130
2131 memset(sinfo, 0, sizeof(*sinfo));
2132
2133 len = sizeof(linkspeed);
2134 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &linkspeed, &len);
2135 if (ret == 0) {
2136 sinfo->txrate.legacy = le32_to_cpu(linkspeed) / 1000;
2137 sinfo->filled |= STATION_INFO_TX_BITRATE;
2138 }
2139
2140 len = sizeof(rssi);
2141 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2142 if (ret == 0) {
2143 sinfo->signal = level_to_qual(le32_to_cpu(rssi));
2144 sinfo->filled |= STATION_INFO_SIGNAL;
2145 }
2146}
2147
2148static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
2149 u8 *mac, struct station_info *sinfo)
2150{
2151 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2152 struct usbnet *usbdev = priv->usbdev;
2153
2154 if (compare_ether_addr(priv->bssid, mac))
2155 return -ENOENT;
2156
2157 rndis_fill_station_info(usbdev, sinfo);
2158
2159 return 0;
2160}
2161
Jussi Kivilinnad695df92009-08-28 13:28:09 +03002162static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
2163 int idx, u8 *mac, struct station_info *sinfo)
2164{
2165 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2166 struct usbnet *usbdev = priv->usbdev;
2167
2168 if (idx != 0)
2169 return -ENOENT;
2170
2171 memcpy(mac, priv->bssid, ETH_ALEN);
2172
2173 rndis_fill_station_info(usbdev, sinfo);
2174
2175 return 0;
2176}
2177
John W. Linville964c1d42009-03-26 23:40:01 +02002178/*
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002179 * wireless extension handlers
2180 */
2181
2182static int rndis_iw_commit(struct net_device *dev,
2183 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2184{
2185 /* dummy op */
2186 return 0;
2187}
2188
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002189#if 0
2190/* Commented code out instead of removing to have more sane patch for review.
2191 * Will be removed later in the set.
2192 */
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002193static int rndis_iw_set_essid(struct net_device *dev,
2194 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
2195{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002196 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002197 int length = wrqu->essid.length;
Wang Chen524ad0a2008-11-12 23:39:10 -08002198 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002199
2200 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
2201 wrqu->essid.flags, wrqu->essid.length, essid);
2202
2203 if (length > NDIS_802_11_LENGTH_SSID)
2204 length = NDIS_802_11_LENGTH_SSID;
2205
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002206 ssid.length = cpu_to_le32(length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002207 if (length > 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002208 memcpy(ssid.essid, essid, length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002209 else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002210 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002211
2212 set_assoc_params(usbdev);
2213
2214 if (!wrqu->essid.flags || length == 0)
2215 return disassociate(usbdev, 1);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002216 else {
2217 /* Pause and purge rx queue, so we don't pass packets before
2218 * 'media connect'-indication.
2219 */
2220 usbnet_pause_rx(usbdev);
2221 usbnet_purge_paused_rxq(usbdev);
2222
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002223 return set_essid(usbdev, &ssid);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002224 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002225}
2226
2227
2228static int rndis_iw_get_essid(struct net_device *dev,
2229 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
2230{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002231 struct ndis_80211_ssid ssid;
Wang Chen524ad0a2008-11-12 23:39:10 -08002232 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002233 int ret;
2234
2235 ret = get_essid(usbdev, &ssid);
2236
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002237 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002238 wrqu->essid.flags = 1;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002239 wrqu->essid.length = le32_to_cpu(ssid.length);
2240 memcpy(essid, ssid.essid, wrqu->essid.length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002241 essid[wrqu->essid.length] = 0;
2242 } else {
2243 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
2244 wrqu->essid.flags = 0;
2245 wrqu->essid.length = 0;
2246 }
2247 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
2248 return ret;
2249}
2250
2251
2252static int rndis_iw_get_bssid(struct net_device *dev,
2253 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2254{
Wang Chen524ad0a2008-11-12 23:39:10 -08002255 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002256 unsigned char bssid[ETH_ALEN];
2257 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002258
2259 ret = get_bssid(usbdev, bssid);
2260
2261 if (ret == 0)
Johannes Berge1749612008-10-27 15:59:26 -07002262 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002263 else
2264 devdbg(usbdev, "SIOCGIWAP: <not associated>");
2265
2266 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
2267 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
2268
2269 return ret;
2270}
2271
2272
2273static int rndis_iw_set_bssid(struct net_device *dev,
2274 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2275{
Wang Chen524ad0a2008-11-12 23:39:10 -08002276 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002277 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002278 int ret;
2279
Johannes Berge1749612008-10-27 15:59:26 -07002280 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002281
2282 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
2283
2284 /* user apps may set ap's mac address, which is not required;
2285 * they may fail to work if this function fails, so return
2286 * success */
2287 if (ret)
2288 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
2289
2290 return 0;
2291}
2292
2293
2294static int rndis_iw_set_auth(struct net_device *dev,
2295 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2296{
2297 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08002298 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002299 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002300 int ret = -ENOTSUPP;
2301
2302 switch (p->flags & IW_AUTH_INDEX) {
2303 case IW_AUTH_WPA_VERSION:
2304 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
2305 priv->wpa_version = p->value;
2306 ret = 0;
2307 break;
2308
2309 case IW_AUTH_CIPHER_PAIRWISE:
2310 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
2311 priv->wpa_cipher_pair = p->value;
2312 ret = 0;
2313 break;
2314
2315 case IW_AUTH_CIPHER_GROUP:
2316 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
2317 priv->wpa_cipher_group = p->value;
2318 ret = 0;
2319 break;
2320
2321 case IW_AUTH_KEY_MGMT:
2322 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
2323 priv->wpa_keymgmt = p->value;
2324 ret = 0;
2325 break;
2326
2327 case IW_AUTH_TKIP_COUNTERMEASURES:
2328 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
2329 p->value);
2330 ret = 0;
2331 break;
2332
2333 case IW_AUTH_DROP_UNENCRYPTED:
2334 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
2335 ret = 0;
2336 break;
2337
2338 case IW_AUTH_80211_AUTH_ALG:
2339 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
2340 priv->wpa_authalg = p->value;
2341 ret = 0;
2342 break;
2343
2344 case IW_AUTH_WPA_ENABLED:
2345 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
2346 if (wrqu->param.value)
2347 deauthenticate(usbdev);
2348 ret = 0;
2349 break;
2350
2351 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2352 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
2353 p->value);
2354 ret = 0;
2355 break;
2356
2357 case IW_AUTH_ROAMING_CONTROL:
2358 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
2359 ret = 0;
2360 break;
2361
2362 case IW_AUTH_PRIVACY_INVOKED:
2363 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
2364 wrqu->param.flags & IW_AUTH_INDEX);
2365 return -EOPNOTSUPP;
2366
2367 default:
2368 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
2369 p->flags & IW_AUTH_INDEX, p->value);
2370 }
2371 return ret;
2372}
2373
2374
2375static int rndis_iw_get_auth(struct net_device *dev,
2376 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2377{
2378 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08002379 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002380 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002381
2382 switch (p->flags & IW_AUTH_INDEX) {
2383 case IW_AUTH_WPA_VERSION:
2384 p->value = priv->wpa_version;
2385 break;
2386 case IW_AUTH_CIPHER_PAIRWISE:
2387 p->value = priv->wpa_cipher_pair;
2388 break;
2389 case IW_AUTH_CIPHER_GROUP:
2390 p->value = priv->wpa_cipher_group;
2391 break;
2392 case IW_AUTH_KEY_MGMT:
2393 p->value = priv->wpa_keymgmt;
2394 break;
2395 case IW_AUTH_80211_AUTH_ALG:
2396 p->value = priv->wpa_authalg;
2397 break;
2398 default:
2399 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
2400 wrqu->param.flags & IW_AUTH_INDEX);
2401 return -EOPNOTSUPP;
2402 }
2403 return 0;
2404}
2405
2406
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002407static int rndis_iw_set_encode(struct net_device *dev,
2408 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2409{
Wang Chen524ad0a2008-11-12 23:39:10 -08002410 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002411 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002412 struct rndis_wlan_encr_key key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002413 int ret, index, key_len;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002414 u8 *keybuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002415
2416 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
2417
2418 /* iwconfig gives index as 1 - N */
2419 if (index > 0)
2420 index--;
2421 else
2422 index = priv->encr_tx_key_index;
2423
2424 if (index < 0 || index >= 4) {
2425 devwarn(usbdev, "encryption index out of range (%u)", index);
2426 return -EINVAL;
2427 }
2428
2429 /* remove key if disabled */
2430 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
2431 if (remove_key(usbdev, index, NULL))
2432 return -EINVAL;
2433 else
2434 return 0;
2435 }
2436
2437 /* global encryption state (for all keys) */
2438 if (wrqu->data.flags & IW_ENCODE_OPEN)
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002439 ret = set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
2440 RNDIS_WLAN_KEY_MGMT_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002441 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002442 ret = set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_SHARED_KEY,
2443 RNDIS_WLAN_KEY_MGMT_NONE);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002444 if (ret != 0)
2445 return ret;
2446
2447 if (wrqu->data.length > 0) {
2448 key_len = wrqu->data.length;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002449 keybuf = extra;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002450 } else {
2451 /* must be set as tx key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002452 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002453 return -EINVAL;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002454 key = priv->encr_keys[index];
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002455 key_len = key.len;
2456 keybuf = key.material;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002457 priv->encr_tx_key_index = index;
2458 }
2459
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002460 if (add_wep_key(usbdev, keybuf, key_len, index) != 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002461 return -EINVAL;
2462
2463 if (index == priv->encr_tx_key_index)
2464 /* ndis drivers want essid to be set after setting encr */
2465 set_essid(usbdev, &priv->essid);
2466
2467 return 0;
2468}
2469
2470
2471static int rndis_iw_set_encode_ext(struct net_device *dev,
2472 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2473{
2474 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
Wang Chen524ad0a2008-11-12 23:39:10 -08002475 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002476 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002477 int keyidx, flags, cipher;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002478
2479 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
2480
2481 /* iwconfig gives index as 1 - N */
2482 if (keyidx)
2483 keyidx--;
2484 else
2485 keyidx = priv->encr_tx_key_index;
2486
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002487 if (keyidx < 0 || keyidx >= 4) {
2488 devwarn(usbdev, "encryption index out of range (%u)", keyidx);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002489 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002490 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002491
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002492 if (ext->alg == IW_ENCODE_ALG_WEP) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002493 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2494 priv->encr_tx_key_index = keyidx;
2495 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
2496 }
2497
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002498 cipher = -1;
2499 if (ext->alg == IW_ENCODE_ALG_TKIP)
2500 cipher = WLAN_CIPHER_SUITE_TKIP;
2501 else if (ext->alg == IW_ENCODE_ALG_CCMP)
2502 cipher = WLAN_CIPHER_SUITE_CCMP;
2503
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002504 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
2505 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
2506 return remove_key(usbdev, keyidx, NULL);
2507
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002508 if (cipher == -1)
2509 return -EOPNOTSUPP;
2510
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002511 flags = 0;
2512 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002513 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002514 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002515 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002516 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002517 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002518
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002519 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx,
2520 (u8 *)&ext->addr.sa_data, ext->rx_seq, cipher,
2521 flags);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002522}
2523
2524
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002525static int rndis_iw_get_rate(struct net_device *dev,
2526 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2527{
Wang Chen524ad0a2008-11-12 23:39:10 -08002528 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002529 __le32 tmp;
2530 int ret, len;
2531
2532 len = sizeof(tmp);
2533 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
2534 if (ret == 0) {
2535 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
2536 wrqu->bitrate.disabled = 0;
2537 wrqu->bitrate.flags = 1;
2538 }
2539 return ret;
2540}
2541
2542
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002543static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
2544{
Wang Chen524ad0a2008-11-12 23:39:10 -08002545 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002546 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002547 unsigned long flags;
2548
2549 spin_lock_irqsave(&priv->stats_lock, flags);
2550 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2551 spin_unlock_irqrestore(&priv->stats_lock, flags);
2552
2553 return &priv->iwstats;
2554}
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002555#endif
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002556
2557
2558#define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2559static const iw_handler rndis_iw_handler[] =
2560{
2561 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002562 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
Jussi Kivilinna5554adb2009-08-28 13:27:53 +03002563 IW_IOCTL(SIOCSIWFREQ) = (iw_handler) cfg80211_wext_siwfreq,
2564 IW_IOCTL(SIOCGIWFREQ) = (iw_handler) cfg80211_wext_giwfreq,
John W. Linville964c1d42009-03-26 23:40:01 +02002565 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2566 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002567 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002568 IW_IOCTL(SIOCSIWAP) = (iw_handler) cfg80211_wext_siwap,
2569 IW_IOCTL(SIOCGIWAP) = (iw_handler) cfg80211_wext_giwap,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002570 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2571 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002572 IW_IOCTL(SIOCSIWESSID) = (iw_handler) cfg80211_wext_siwessid,
2573 IW_IOCTL(SIOCGIWESSID) = (iw_handler) cfg80211_wext_giwessid,
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002574 IW_IOCTL(SIOCGIWRATE) = (iw_handler) cfg80211_wext_giwrate,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002575 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2576 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2577 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2578 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002579 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2580 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
Jussi Kivilinna84bf8402009-08-28 13:27:58 +03002581 IW_IOCTL(SIOCSIWENCODE) = (iw_handler) cfg80211_wext_siwencode,
2582 IW_IOCTL(SIOCSIWENCODEEXT) = (iw_handler) cfg80211_wext_siwencodeext,
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002583 IW_IOCTL(SIOCSIWAUTH) = (iw_handler) cfg80211_wext_siwauth,
2584 IW_IOCTL(SIOCGIWAUTH) = (iw_handler) cfg80211_wext_giwauth,
2585 IW_IOCTL(SIOCSIWGENIE) = (iw_handler) cfg80211_wext_siwgenie,
2586 IW_IOCTL(SIOCSIWMLME) = (iw_handler) cfg80211_wext_siwmlme,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002587};
2588
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002589static const iw_handler rndis_wlan_private_handler[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002590};
2591
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002592static const struct iw_priv_args rndis_wlan_private_args[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002593};
2594
2595
2596static const struct iw_handler_def rndis_iw_handlers = {
2597 .num_standard = ARRAY_SIZE(rndis_iw_handler),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002598 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2599 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002600 .standard = (iw_handler *)rndis_iw_handler,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002601 .private = (iw_handler *)rndis_wlan_private_handler,
2602 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002603 .get_wireless_stats = cfg80211_wireless_stats,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002604};
2605
2606
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002607static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002608{
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002609 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Scott Ashcroft43646232008-05-27 00:06:15 +03002610 struct ndis_80211_assoc_info *info;
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002611 u8 assoc_buf[sizeof(*info) + IW_CUSTOM_MAX + 32];
2612 u8 bssid[ETH_ALEN];
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002613 int resp_ie_len, req_ie_len;
2614 u8 *req_ie, *resp_ie;
Scott Ashcroft43646232008-05-27 00:06:15 +03002615 int ret, offset;
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002616 bool roamed = false;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002617
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002618 if (priv->infra_mode == NDIS_80211_INFRA_INFRA && priv->connected) {
2619 /* received media connect indication while connected, either
2620 * device reassociated with same AP or roamed to new. */
2621 roamed = true;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002622 }
2623
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002624 req_ie_len = 0;
2625 resp_ie_len = 0;
2626 req_ie = NULL;
2627 resp_ie = NULL;
2628
2629 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2630 memset(assoc_buf, 0, sizeof(assoc_buf));
2631 info = (void *)assoc_buf;
2632
2633 /* Get association info IEs from device and send them back to
2634 * userspace. */
2635 ret = get_association_info(usbdev, info, sizeof(assoc_buf));
2636 if (!ret) {
2637 req_ie_len = le32_to_cpu(info->req_ie_length);
2638 if (req_ie_len > 0) {
2639 offset = le32_to_cpu(info->offset_req_ies);
2640 req_ie = (u8 *)info + offset;
2641 }
2642
2643 resp_ie_len = le32_to_cpu(info->resp_ie_length);
2644 if (resp_ie_len > 0) {
2645 offset = le32_to_cpu(info->offset_resp_ies);
2646 resp_ie = (u8 *)info + offset;
2647 }
2648 }
2649 } else if (WARN_ON(priv->infra_mode != NDIS_80211_INFRA_ADHOC))
2650 return;
2651
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002652 ret = get_bssid(usbdev, bssid);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002653 if (ret < 0)
2654 memset(bssid, 0, sizeof(bssid));
2655
2656 devdbg(usbdev, "link up work: [%pM] %s", bssid, roamed ? "roamed" : "");
2657
2658 /* Internal bss list in device always contains at least the currently
2659 * connected bss and we can get it to cfg80211 with
2660 * rndis_check_bssid_list().
2661 * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
2662 * spec.
2663 */
2664 rndis_check_bssid_list(usbdev);
2665
2666 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2667 if (!roamed)
2668 cfg80211_connect_result(usbdev->net, bssid, req_ie,
2669 req_ie_len, resp_ie,
2670 resp_ie_len, 0, GFP_KERNEL);
2671 else
2672 cfg80211_roamed(usbdev->net, bssid, req_ie, req_ie_len,
2673 resp_ie, resp_ie_len, GFP_KERNEL);
2674 } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
2675 cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
2676
2677 priv->connected = true;
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002678 memcpy(priv->bssid, bssid, ETH_ALEN);
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002679
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002680 usbnet_resume_rx(usbdev);
Jussi Kivilinna5c523232009-08-28 13:27:47 +03002681 netif_carrier_on(usbdev->net);
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002682}
2683
2684static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
2685{
2686 union iwreq_data evt;
2687
2688 netif_carrier_off(usbdev->net);
2689
2690 evt.data.flags = 0;
2691 evt.data.length = 0;
2692 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2693 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2694}
2695
2696static void rndis_wlan_worker(struct work_struct *work)
2697{
2698 struct rndis_wlan_private *priv =
2699 container_of(work, struct rndis_wlan_private, work);
2700 struct usbnet *usbdev = priv->usbdev;
2701
2702 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
2703 rndis_wlan_do_link_up_work(usbdev);
2704
2705 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
2706 rndis_wlan_do_link_down_work(usbdev);
2707
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002708 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2709 set_multicast_list(usbdev);
2710}
2711
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002712static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002713{
Wang Chen524ad0a2008-11-12 23:39:10 -08002714 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002715 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002716
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002717 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2718 return;
2719
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002720 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2721 queue_work(priv->workqueue, &priv->work);
2722}
2723
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002724
2725static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2726 struct ndis_80211_status_indication *indication,
2727 int len)
2728{
2729 u8 *buf;
2730 const char *type;
2731 int flags, buflen;
2732 bool pairwise_error, group_error;
2733 struct ndis_80211_auth_request *auth_req;
2734
2735 /* must have at least one array entry */
2736 if (len < offsetof(struct ndis_80211_status_indication, u) +
2737 sizeof(struct ndis_80211_auth_request)) {
2738 devinfo(usbdev, "authentication indication: "
2739 "too short message (%i)", len);
2740 return;
2741 }
2742
2743 buf = (void *)&indication->u.auth_request[0];
2744 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2745
2746 while (buflen >= sizeof(*auth_req)) {
2747 auth_req = (void *)buf;
2748 type = "unknown";
2749 flags = le32_to_cpu(auth_req->flags);
2750 pairwise_error = false;
2751 group_error = false;
2752
2753 if (flags & 0x1)
2754 type = "reauth request";
2755 if (flags & 0x2)
2756 type = "key update request";
2757 if (flags & 0x6) {
2758 pairwise_error = true;
2759 type = "pairwise_error";
2760 }
2761 if (flags & 0xe) {
2762 group_error = true;
2763 type = "group_error";
2764 }
2765
2766 devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
2767 le32_to_cpu(auth_req->flags));
2768
2769 if (pairwise_error || group_error) {
2770 union iwreq_data wrqu;
2771 struct iw_michaelmicfailure micfailure;
2772
2773 memset(&micfailure, 0, sizeof(micfailure));
2774 if (pairwise_error)
2775 micfailure.flags |= IW_MICFAILURE_PAIRWISE;
2776 if (group_error)
2777 micfailure.flags |= IW_MICFAILURE_GROUP;
2778
2779 memcpy(micfailure.src_addr.sa_data, auth_req->bssid,
2780 ETH_ALEN);
2781
2782 memset(&wrqu, 0, sizeof(wrqu));
2783 wrqu.data.length = sizeof(micfailure);
2784 wireless_send_event(usbdev->net, IWEVMICHAELMICFAILURE,
2785 &wrqu, (u8 *)&micfailure);
2786 }
2787
2788 buflen -= le32_to_cpu(auth_req->length);
2789 buf += le32_to_cpu(auth_req->length);
2790 }
2791}
2792
2793static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2794 struct ndis_80211_status_indication *indication,
2795 int len)
2796{
2797 struct ndis_80211_pmkid_cand_list *cand_list;
2798 int list_len, expected_len, i;
2799
2800 if (len < offsetof(struct ndis_80211_status_indication, u) +
2801 sizeof(struct ndis_80211_pmkid_cand_list)) {
2802 devinfo(usbdev, "pmkid candidate list indication: "
2803 "too short message (%i)", len);
2804 return;
2805 }
2806
2807 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2808 sizeof(struct ndis_80211_pmkid_candidate);
2809 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2810 offsetof(struct ndis_80211_status_indication, u);
2811
2812 if (len < expected_len) {
2813 devinfo(usbdev, "pmkid candidate list indication: "
2814 "list larger than buffer (%i < %i)",
2815 len, expected_len);
2816 return;
2817 }
2818
2819 cand_list = &indication->u.cand_list;
2820
2821 devinfo(usbdev, "pmkid candidate list indication: "
2822 "version %i, candidates %i",
2823 le32_to_cpu(cand_list->version),
2824 le32_to_cpu(cand_list->num_candidates));
2825
2826 if (le32_to_cpu(cand_list->version) != 1)
2827 return;
2828
2829 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
2830 struct iw_pmkid_cand pcand;
2831 union iwreq_data wrqu;
2832 struct ndis_80211_pmkid_candidate *cand =
2833 &cand_list->candidate_list[i];
2834
2835 devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
2836 i, le32_to_cpu(cand->flags), cand->bssid);
2837
2838 memset(&pcand, 0, sizeof(pcand));
2839 if (le32_to_cpu(cand->flags) & 0x01)
2840 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2841 pcand.index = i;
2842 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2843
2844 memset(&wrqu, 0, sizeof(wrqu));
2845 wrqu.data.length = sizeof(pcand);
2846 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2847 (u8 *)&pcand);
2848 }
2849}
2850
2851static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2852 struct rndis_indicate *msg, int buflen)
2853{
2854 struct ndis_80211_status_indication *indication;
2855 int len, offset;
2856
2857 offset = offsetof(struct rndis_indicate, status) +
2858 le32_to_cpu(msg->offset);
2859 len = le32_to_cpu(msg->length);
2860
2861 if (len < 8) {
2862 devinfo(usbdev, "media specific indication, "
2863 "ignore too short message (%i < 8)", len);
2864 return;
2865 }
2866
2867 if (offset + len > buflen) {
2868 devinfo(usbdev, "media specific indication, "
2869 "too large to fit to buffer (%i > %i)",
2870 offset + len, buflen);
2871 return;
2872 }
2873
2874 indication = (void *)((u8 *)msg + offset);
2875
2876 switch (le32_to_cpu(indication->status_type)) {
2877 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2878 devinfo(usbdev, "radio state indication: %i",
2879 le32_to_cpu(indication->u.radio_status));
2880 return;
2881
2882 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2883 devinfo(usbdev, "media stream mode indication: %i",
2884 le32_to_cpu(indication->u.media_stream_mode));
2885 return;
2886
2887 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2888 rndis_wlan_auth_indication(usbdev, indication, len);
2889 return;
2890
2891 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2892 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2893 return;
2894
2895 default:
2896 devinfo(usbdev, "media specific indication: "
2897 "unknown status type 0x%08x",
2898 le32_to_cpu(indication->status_type));
2899 }
2900}
2901
2902
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002903static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002904{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002905 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002906 struct rndis_indicate *msg = ind;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002907
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002908 switch (msg->status) {
2909 case RNDIS_STATUS_MEDIA_CONNECT:
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +03002910 if (priv->current_command_oid == OID_802_11_ADD_KEY) {
2911 /* OID_802_11_ADD_KEY causes sometimes extra
2912 * "media connect" indications which confuses driver
2913 * and userspace to think that device is
2914 * roaming/reassociating when it isn't.
2915 */
2916 devdbg(usbdev, "ignored OID_802_11_ADD_KEY triggered "
2917 "'media connect'");
2918 return;
2919 }
2920
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002921 usbnet_pause_rx(usbdev);
2922
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002923 devinfo(usbdev, "media connect");
2924
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002925 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002926 set_bit(WORK_LINK_UP, &priv->work_pending);
2927 queue_work(priv->workqueue, &priv->work);
2928 break;
2929
2930 case RNDIS_STATUS_MEDIA_DISCONNECT:
2931 devinfo(usbdev, "media disconnect");
2932
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002933 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002934 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2935 queue_work(priv->workqueue, &priv->work);
2936 break;
2937
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002938 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2939 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2940 break;
2941
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002942 default:
2943 devinfo(usbdev, "indication: 0x%08x",
2944 le32_to_cpu(msg->status));
2945 break;
2946 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002947}
2948
2949
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002950static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002951{
2952 struct {
2953 __le32 num_items;
2954 __le32 items[8];
2955 } networks_supported;
2956 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002957 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002958
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002959 /* determine supported modes */
2960 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002961 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002962 &networks_supported, &len);
2963 if (retval >= 0) {
2964 n = le32_to_cpu(networks_supported.num_items);
2965 if (n > 8)
2966 n = 8;
2967 for (i = 0; i < n; i++) {
2968 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002969 case NDIS_80211_TYPE_FREQ_HOP:
2970 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002971 priv->caps |= CAP_MODE_80211B;
2972 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002973 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002974 priv->caps |= CAP_MODE_80211A;
2975 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002976 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002977 priv->caps |= CAP_MODE_80211G;
2978 break;
2979 }
2980 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002981 }
2982
2983 return retval;
2984}
2985
2986
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002987#define DEVICE_POLLER_JIFFIES (HZ)
2988static void rndis_device_poller(struct work_struct *work)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002989{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002990 struct rndis_wlan_private *priv =
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002991 container_of(work, struct rndis_wlan_private,
2992 dev_poller_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002993 struct usbnet *usbdev = priv->usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002994 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002995 int len, ret, j;
Jussi Kivilinna305e2432009-08-28 13:28:14 +03002996 int update_jiffies = DEVICE_POLLER_JIFFIES;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002997 void *buf;
2998
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03002999 /* Only check/do workaround when connected. Calling is_associated()
3000 * also polls device with rndis_command() and catches for media link
3001 * indications.
3002 */
3003 if (!is_associated(usbdev))
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003004 goto end;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003005
3006 len = sizeof(rssi);
3007 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03003008 if (ret == 0)
3009 priv->last_qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003010
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003011 devdbg(usbdev, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d",
3012 ret, le32_to_cpu(rssi), level_to_qual(le32_to_cpu(rssi)));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003013
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02003014 /* Workaround transfer stalls on poor quality links.
3015 * TODO: find right way to fix these stalls (as stalls do not happen
3016 * with ndiswrapper/windows driver). */
Jussi Kivilinna8b89a282009-08-28 13:28:03 +03003017 if (priv->last_qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003018 /* Decrease stats worker interval to catch stalls.
3019 * faster. Faster than 400-500ms causes packet loss,
3020 * Slower doesn't catch stalls fast enough.
3021 */
3022 j = msecs_to_jiffies(priv->param_workaround_interval);
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003023 if (j > DEVICE_POLLER_JIFFIES)
3024 j = DEVICE_POLLER_JIFFIES;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003025 else if (j <= 0)
3026 j = 1;
3027 update_jiffies = j;
3028
3029 /* Send scan OID. Use of both OIDs is required to get device
3030 * working.
3031 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08003032 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003033 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
3034 sizeof(tmp));
3035
3036 len = CONTROL_BUFFER_SIZE;
3037 buf = kmalloc(len, GFP_KERNEL);
3038 if (!buf)
3039 goto end;
3040
3041 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
3042 kfree(buf);
3043 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003044
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003045end:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003046 if (update_jiffies >= HZ)
3047 update_jiffies = round_jiffies_relative(update_jiffies);
3048 else {
3049 j = round_jiffies_relative(update_jiffies);
3050 if (abs(j - update_jiffies) <= 10)
3051 update_jiffies = j;
3052 }
3053
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003054 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
3055 update_jiffies);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003056}
3057
3058
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003059static int bcm4320a_early_init(struct usbnet *usbdev)
3060{
3061 /* bcm4320a doesn't handle configuration parameters well. Try
3062 * set any and you get partially zeroed mac and broken device.
3063 */
3064
3065 return 0;
3066}
3067
3068
3069static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003070{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003071 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003072 char buf[8];
3073
3074 /* Early initialization settings, setting these won't have effect
3075 * if called after generic_rndis_bind().
3076 */
3077
3078 priv->param_country[0] = modparam_country[0];
3079 priv->param_country[1] = modparam_country[1];
3080 priv->param_country[2] = 0;
3081 priv->param_frameburst = modparam_frameburst;
3082 priv->param_afterburner = modparam_afterburner;
3083 priv->param_power_save = modparam_power_save;
3084 priv->param_power_output = modparam_power_output;
3085 priv->param_roamtrigger = modparam_roamtrigger;
3086 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003087
3088 priv->param_country[0] = toupper(priv->param_country[0]);
3089 priv->param_country[1] = toupper(priv->param_country[1]);
3090 /* doesn't support EU as country code, use FI instead */
3091 if (!strcmp(priv->param_country, "EU"))
3092 strcpy(priv->param_country, "FI");
3093
3094 if (priv->param_power_save < 0)
3095 priv->param_power_save = 0;
3096 else if (priv->param_power_save > 2)
3097 priv->param_power_save = 2;
3098
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03003099 if (priv->param_power_output < 0)
3100 priv->param_power_output = 0;
3101 else if (priv->param_power_output > 3)
3102 priv->param_power_output = 3;
3103
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003104 if (priv->param_roamtrigger < -80)
3105 priv->param_roamtrigger = -80;
3106 else if (priv->param_roamtrigger > -60)
3107 priv->param_roamtrigger = -60;
3108
3109 if (priv->param_roamdelta < 0)
3110 priv->param_roamdelta = 0;
3111 else if (priv->param_roamdelta > 2)
3112 priv->param_roamdelta = 2;
3113
Roel Kluin4d381ff2008-04-23 22:10:29 +02003114 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003115 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02003116 else
3117 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003118
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003119 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
3120 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003121 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003122 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003123 priv->param_afterburner ? "1" : "0");
3124 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003125 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003126 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003127 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003128 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003129 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003130 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003131 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003132
3133 return 0;
3134}
3135
David S. Miller23d12e22009-03-25 00:03:16 -07003136/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003137static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07003138 .ndo_open = usbnet_open,
3139 .ndo_stop = usbnet_stop,
3140 .ndo_start_xmit = usbnet_start_xmit,
3141 .ndo_tx_timeout = usbnet_tx_timeout,
3142 .ndo_set_mac_address = eth_mac_addr,
3143 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003144 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07003145};
3146
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003147
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003148static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003149{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003150 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003151 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003152 int retval, len;
3153 __le32 tmp;
3154
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003155 /* allocate wiphy and rndis private data
3156 * NOTE: We only support a single virtual interface, so wiphy
3157 * and wireless_dev are somewhat synonymous for this device.
3158 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003159 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003160 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003161 return -ENOMEM;
3162
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003163 priv = wiphy_priv(wiphy);
3164 usbdev->net->ieee80211_ptr = &priv->wdev;
3165 priv->wdev.wiphy = wiphy;
3166 priv->wdev.iftype = NL80211_IFTYPE_STATION;
3167
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003168 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003169 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003170 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003171 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003172 usbdev->net->wireless_handlers = &rndis_iw_handlers;
3173 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003174
3175 mutex_init(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003176
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03003177 /* because rndis_command() sleeps we need to use workqueue */
3178 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003179 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003180 INIT_DELAYED_WORK(&priv->dev_poller_work, rndis_device_poller);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03003181 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
3182
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003183 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003184 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003185 if (retval < 0)
3186 goto fail;
3187
3188 /* generic_rndis_bind set packet filter to multicast_all+
3189 * promisc mode which doesn't work well for our devices (device
3190 * picks up rssi to closest station instead of to access point).
3191 *
3192 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003193 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003194 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003195 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07003196
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003197 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003198 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003199 sizeof(tmp));
3200
3201 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003202 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
3203 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003204 priv->multicast_size = le32_to_cpu(tmp);
3205 if (retval < 0 || priv->multicast_size < 0)
3206 priv->multicast_size = 0;
3207 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003208 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003209 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003210 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003211
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003212 /* fill-out wiphy structure and register w/ cfg80211 */
3213 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
3214 wiphy->privid = rndis_wiphy_privid;
3215 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
3216 | BIT(NL80211_IFTYPE_ADHOC);
3217 wiphy->max_scan_ssids = 1;
3218
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03003219 /* TODO: fill-out band/encr information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003220 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003221
3222 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
3223 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
3224 priv->band.channels = priv->channels;
3225 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
3226 priv->band.bitrates = priv->rates;
3227 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
3228 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02003229 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003230
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03003231 memcpy(priv->cipher_suites, rndis_cipher_suites,
3232 sizeof(rndis_cipher_suites));
3233 wiphy->cipher_suites = priv->cipher_suites;
3234 wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
3235
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003236 set_wiphy_dev(wiphy, &usbdev->udev->dev);
3237
3238 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03003239 retval = -ENODEV;
3240 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003241 }
3242
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003243 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003244
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03003245 /* set default rts/frag */
3246 rndis_set_wiphy_params(wiphy,
3247 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
3248
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003249 /* turn radio on */
3250 priv->radio_on = 1;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003251 disassociate(usbdev, 1);
3252 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003253
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003254 return 0;
3255
3256fail:
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003257 cancel_delayed_work_sync(&priv->dev_poller_work);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03003258 cancel_delayed_work_sync(&priv->scan_work);
3259 cancel_work_sync(&priv->work);
3260 flush_workqueue(priv->workqueue);
3261 destroy_workqueue(priv->workqueue);
3262
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03003263 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003264 return retval;
3265}
3266
3267
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003268static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003269{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003270 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003271
3272 /* turn radio off */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003273 disassociate(usbdev, 0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003274
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003275 cancel_delayed_work_sync(&priv->dev_poller_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02003276 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003277 cancel_work_sync(&priv->work);
3278 flush_workqueue(priv->workqueue);
3279 destroy_workqueue(priv->workqueue);
3280
3281 if (priv && priv->wpa_ie_len)
3282 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003283
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003284 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003285
3286 wiphy_unregister(priv->wdev.wiphy);
3287 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003288}
3289
3290
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003291static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003292{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003293 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003294 int retval;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003295
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003296 devdbg(usbdev, "rndis_wlan_reset");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003297
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003298 retval = rndis_reset(usbdev);
3299 if (retval)
3300 devwarn(usbdev, "rndis_reset() failed: %d", retval);
3301
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003302 /* rndis_reset cleared multicast list, so restore here.
3303 (set_multicast_list() also turns on current packet filter) */
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003304 set_multicast_list(usbdev);
3305
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003306 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
3307 round_jiffies_relative(DEVICE_POLLER_JIFFIES));
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003308
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003309 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003310}
3311
3312
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003313static int rndis_wlan_stop(struct usbnet *usbdev)
3314{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003315 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3316 int retval;
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003317 __le32 filter;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003318
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003319 devdbg(usbdev, "rndis_wlan_stop");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003320
3321 retval = disassociate(usbdev, 0);
3322
3323 priv->work_pending = 0;
Jussi Kivilinna305e2432009-08-28 13:28:14 +03003324 cancel_delayed_work_sync(&priv->dev_poller_work);
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003325 cancel_delayed_work_sync(&priv->scan_work);
3326 cancel_work_sync(&priv->work);
3327 flush_workqueue(priv->workqueue);
3328
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03003329 if (priv->scan_request) {
3330 cfg80211_scan_done(priv->scan_request, true);
3331 priv->scan_request = NULL;
3332 }
3333
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003334 /* Set current packet filter zero to block receiving data packets from
3335 device. */
3336 filter = 0;
3337 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
3338 sizeof(filter));
3339
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003340 return retval;
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003341}
3342
3343
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003344static const struct driver_info bcm4320b_info = {
3345 .description = "Wireless RNDIS device, BCM4320b based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003346 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3347 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003348 .bind = rndis_wlan_bind,
3349 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003350 .status = rndis_status,
3351 .rx_fixup = rndis_rx_fixup,
3352 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003353 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003354 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003355 .early_init = bcm4320b_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003356 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003357};
3358
3359static const struct driver_info bcm4320a_info = {
3360 .description = "Wireless RNDIS device, BCM4320a based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003361 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3362 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003363 .bind = rndis_wlan_bind,
3364 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003365 .status = rndis_status,
3366 .rx_fixup = rndis_rx_fixup,
3367 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003368 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003369 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003370 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003371 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003372};
3373
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003374static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003375 .description = "Wireless RNDIS device",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003376 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3377 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003378 .bind = rndis_wlan_bind,
3379 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003380 .status = rndis_status,
3381 .rx_fixup = rndis_rx_fixup,
3382 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003383 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003384 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003385 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003386 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003387};
3388
3389/*-------------------------------------------------------------------------*/
3390
3391static const struct usb_device_id products [] = {
3392#define RNDIS_MASTER_INTERFACE \
3393 .bInterfaceClass = USB_CLASS_COMM, \
3394 .bInterfaceSubClass = 2 /* ACM */, \
3395 .bInterfaceProtocol = 0x0ff
3396
3397/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3398 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3399 */
3400{
3401 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3402 | USB_DEVICE_ID_MATCH_DEVICE,
3403 .idVendor = 0x0411,
3404 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
3405 RNDIS_MASTER_INTERFACE,
3406 .driver_info = (unsigned long) &bcm4320b_info,
3407}, {
3408 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3409 | USB_DEVICE_ID_MATCH_DEVICE,
3410 .idVendor = 0x0baf,
3411 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
3412 RNDIS_MASTER_INTERFACE,
3413 .driver_info = (unsigned long) &bcm4320b_info,
3414}, {
3415 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3416 | USB_DEVICE_ID_MATCH_DEVICE,
3417 .idVendor = 0x050d,
3418 .idProduct = 0x011b, /* Belkin F5D7051 */
3419 RNDIS_MASTER_INTERFACE,
3420 .driver_info = (unsigned long) &bcm4320b_info,
3421}, {
3422 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3423 | USB_DEVICE_ID_MATCH_DEVICE,
3424 .idVendor = 0x1799, /* Belkin has two vendor ids */
3425 .idProduct = 0x011b, /* Belkin F5D7051 */
3426 RNDIS_MASTER_INTERFACE,
3427 .driver_info = (unsigned long) &bcm4320b_info,
3428}, {
3429 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3430 | USB_DEVICE_ID_MATCH_DEVICE,
3431 .idVendor = 0x13b1,
3432 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
3433 RNDIS_MASTER_INTERFACE,
3434 .driver_info = (unsigned long) &bcm4320b_info,
3435}, {
3436 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3437 | USB_DEVICE_ID_MATCH_DEVICE,
3438 .idVendor = 0x13b1,
3439 .idProduct = 0x0026, /* Linksys WUSB54GSC */
3440 RNDIS_MASTER_INTERFACE,
3441 .driver_info = (unsigned long) &bcm4320b_info,
3442}, {
3443 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3444 | USB_DEVICE_ID_MATCH_DEVICE,
3445 .idVendor = 0x0b05,
3446 .idProduct = 0x1717, /* Asus WL169gE */
3447 RNDIS_MASTER_INTERFACE,
3448 .driver_info = (unsigned long) &bcm4320b_info,
3449}, {
3450 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3451 | USB_DEVICE_ID_MATCH_DEVICE,
3452 .idVendor = 0x0a5c,
3453 .idProduct = 0xd11b, /* Eminent EM4045 */
3454 RNDIS_MASTER_INTERFACE,
3455 .driver_info = (unsigned long) &bcm4320b_info,
3456}, {
3457 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3458 | USB_DEVICE_ID_MATCH_DEVICE,
3459 .idVendor = 0x1690,
3460 .idProduct = 0x0715, /* BT Voyager 1055 */
3461 RNDIS_MASTER_INTERFACE,
3462 .driver_info = (unsigned long) &bcm4320b_info,
3463},
3464/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3465 * parameters available, hardware probably contain older firmware version with
3466 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3467 */
3468{
3469 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3470 | USB_DEVICE_ID_MATCH_DEVICE,
3471 .idVendor = 0x13b1,
3472 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3473 RNDIS_MASTER_INTERFACE,
3474 .driver_info = (unsigned long) &bcm4320a_info,
3475}, {
3476 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3477 | USB_DEVICE_ID_MATCH_DEVICE,
3478 .idVendor = 0x0baf,
3479 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3480 RNDIS_MASTER_INTERFACE,
3481 .driver_info = (unsigned long) &bcm4320a_info,
3482}, {
3483 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3484 | USB_DEVICE_ID_MATCH_DEVICE,
3485 .idVendor = 0x0411,
3486 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3487 RNDIS_MASTER_INTERFACE,
3488 .driver_info = (unsigned long) &bcm4320a_info,
3489},
3490/* Generic Wireless RNDIS devices that we don't have exact
3491 * idVendor/idProduct/chip yet.
3492 */
3493{
3494 /* RNDIS is MSFT's un-official variant of CDC ACM */
3495 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003496 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003497}, {
3498 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3499 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003500 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003501},
3502 { }, // END
3503};
3504MODULE_DEVICE_TABLE(usb, products);
3505
3506static struct usb_driver rndis_wlan_driver = {
3507 .name = "rndis_wlan",
3508 .id_table = products,
3509 .probe = usbnet_probe,
3510 .disconnect = usbnet_disconnect,
3511 .suspend = usbnet_suspend,
3512 .resume = usbnet_resume,
3513};
3514
3515static int __init rndis_wlan_init(void)
3516{
3517 return usb_register(&rndis_wlan_driver);
3518}
3519module_init(rndis_wlan_init);
3520
3521static void __exit rndis_wlan_exit(void)
3522{
3523 usb_deregister(&rndis_wlan_driver);
3524}
3525module_exit(rndis_wlan_exit);
3526
3527MODULE_AUTHOR("Bjorge Dijkstra");
3528MODULE_AUTHOR("Jussi Kivilinna");
3529MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3530MODULE_LICENSE("GPL");
3531