blob: dc3083ba83800e318bc6c0e7e980c53087da6489 [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/* these have to match what is in wpa_supplicant */
Johannes Berg5b0acc62008-02-20 11:47:45 +0100362enum wpa_alg { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP };
363enum wpa_cipher { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
364 CIPHER_WEP104 };
365enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
366 KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE };
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200367
368/*
369 * private data
370 */
371#define NET_TYPE_11FB 0
372
373#define CAP_MODE_80211A 1
374#define CAP_MODE_80211B 2
375#define CAP_MODE_80211G 4
376#define CAP_MODE_MASK 7
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200377
Jussi Kivilinna6010ce02008-06-02 18:35:21 +0300378#define WORK_LINK_UP (1<<0)
379#define WORK_LINK_DOWN (1<<1)
380#define WORK_SET_MULTICAST_LIST (1<<2)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200381
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300382#define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
383
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200384static const struct ieee80211_channel rndis_channels[] = {
385 { .center_freq = 2412 },
386 { .center_freq = 2417 },
387 { .center_freq = 2422 },
388 { .center_freq = 2427 },
389 { .center_freq = 2432 },
390 { .center_freq = 2437 },
391 { .center_freq = 2442 },
392 { .center_freq = 2447 },
393 { .center_freq = 2452 },
394 { .center_freq = 2457 },
395 { .center_freq = 2462 },
396 { .center_freq = 2467 },
397 { .center_freq = 2472 },
398 { .center_freq = 2484 },
399};
400
401static const struct ieee80211_rate rndis_rates[] = {
402 { .bitrate = 10 },
403 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
404 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
405 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
406 { .bitrate = 60 },
407 { .bitrate = 90 },
408 { .bitrate = 120 },
409 { .bitrate = 180 },
410 { .bitrate = 240 },
411 { .bitrate = 360 },
412 { .bitrate = 480 },
413 { .bitrate = 540 }
414};
415
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +0300416static const u32 rndis_cipher_suites[] = {
417 WLAN_CIPHER_SUITE_WEP40,
418 WLAN_CIPHER_SUITE_WEP104,
419 WLAN_CIPHER_SUITE_TKIP,
420 WLAN_CIPHER_SUITE_CCMP,
421};
422
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300423struct rndis_wlan_encr_key {
424 int len;
425 int cipher;
426 u8 material[32];
427 u8 bssid[ETH_ALEN];
428 bool pairwise;
429 bool tx_key;
430};
431
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200432/* RNDIS device private data */
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300433struct rndis_wlan_private {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200434 struct usbnet *usbdev;
435
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200436 struct wireless_dev wdev;
437
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200438 struct cfg80211_scan_request *scan_request;
439
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200440 struct workqueue_struct *workqueue;
441 struct delayed_work stats_work;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200442 struct delayed_work scan_work;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200443 struct work_struct work;
444 struct mutex command_lock;
445 spinlock_t stats_lock;
446 unsigned long work_pending;
447
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200448 struct ieee80211_supported_band band;
449 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
450 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +0300451 u32 cipher_suites[ARRAY_SIZE(rndis_cipher_suites)];
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200452
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200453 struct iw_statistics iwstats;
454 struct iw_statistics privstats;
455
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200456 int caps;
457 int multicast_size;
458
459 /* module parameters */
460 char param_country[4];
461 int param_frameburst;
462 int param_afterburner;
463 int param_power_save;
464 int param_power_output;
465 int param_roamtrigger;
466 int param_roamdelta;
467 u32 param_workaround_interval;
468
469 /* hardware state */
470 int radio_on;
471 int infra_mode;
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200472 struct ndis_80211_ssid essid;
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300473 __le32 current_command_oid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200474
475 /* encryption stuff */
476 int encr_tx_key_index;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300477 struct rndis_wlan_encr_key encr_keys[4];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200478 int wpa_version;
479 int wpa_keymgmt;
480 int wpa_authalg;
481 int wpa_ie_len;
482 u8 *wpa_ie;
483 int wpa_cipher_pair;
484 int wpa_cipher_group;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300485
486 u8 command_buffer[COMMAND_BUFFER_SIZE];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200487};
488
John W. Linville964c1d42009-03-26 23:40:01 +0200489/*
490 * cfg80211 ops
491 */
Johannes Berge36d56b2009-06-09 21:04:43 +0200492static int rndis_change_virtual_intf(struct wiphy *wiphy,
493 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +0200494 enum nl80211_iftype type, u32 *flags,
495 struct vif_params *params);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200496
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200497static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
498 struct cfg80211_scan_request *request);
499
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +0300500static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
501
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300502static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
503 int dbm);
504static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
505
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200506static struct cfg80211_ops rndis_config_ops = {
John W. Linville964c1d42009-03-26 23:40:01 +0200507 .change_virtual_intf = rndis_change_virtual_intf,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200508 .scan = rndis_scan,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +0300509 .set_wiphy_params = rndis_set_wiphy_params,
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300510 .set_tx_power = rndis_set_tx_power,
511 .get_tx_power = rndis_get_tx_power,
John W. Linville964c1d42009-03-26 23:40:01 +0200512};
513
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200514static void *rndis_wiphy_privid = &rndis_wiphy_privid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200515
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200516
517static const unsigned char zero_bssid[ETH_ALEN] = {0,};
518static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff,
519 0xff, 0xff, 0xff };
520
521
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300522static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200523{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300524 return (struct rndis_wlan_private *)dev->driver_priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200525}
526
527
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300528static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200529{
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300530 switch (priv->param_power_output) {
531 default:
532 case 3:
533 return BCM4320_DEFAULT_TXPOWER_DBM_100;
534 case 2:
535 return BCM4320_DEFAULT_TXPOWER_DBM_75;
536 case 1:
537 return BCM4320_DEFAULT_TXPOWER_DBM_50;
538 case 0:
539 return BCM4320_DEFAULT_TXPOWER_DBM_25;
540 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200541}
542
543
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300544static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
545{
546 int cipher = priv->encr_keys[idx].cipher;
547
548 return (cipher == WLAN_CIPHER_SUITE_CCMP ||
549 cipher == WLAN_CIPHER_SUITE_TKIP);
550}
551
552
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300553#ifdef DEBUG
554static const char *oid_to_string(__le32 oid)
555{
556 switch (oid) {
557#define OID_STR(oid) case oid: return(#oid)
558 /* from rndis_host.h */
559 OID_STR(OID_802_3_PERMANENT_ADDRESS);
560 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
561 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
562 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
563
564 /* from rndis_wlan.c */
565 OID_STR(OID_GEN_LINK_SPEED);
566 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
567
568 OID_STR(OID_GEN_XMIT_OK);
569 OID_STR(OID_GEN_RCV_OK);
570 OID_STR(OID_GEN_XMIT_ERROR);
571 OID_STR(OID_GEN_RCV_ERROR);
572 OID_STR(OID_GEN_RCV_NO_BUFFER);
573
574 OID_STR(OID_802_3_CURRENT_ADDRESS);
575 OID_STR(OID_802_3_MULTICAST_LIST);
576 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
577
578 OID_STR(OID_802_11_BSSID);
579 OID_STR(OID_802_11_SSID);
580 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
581 OID_STR(OID_802_11_ADD_WEP);
582 OID_STR(OID_802_11_REMOVE_WEP);
583 OID_STR(OID_802_11_DISASSOCIATE);
584 OID_STR(OID_802_11_AUTHENTICATION_MODE);
585 OID_STR(OID_802_11_PRIVACY_FILTER);
586 OID_STR(OID_802_11_BSSID_LIST_SCAN);
587 OID_STR(OID_802_11_ENCRYPTION_STATUS);
588 OID_STR(OID_802_11_ADD_KEY);
589 OID_STR(OID_802_11_REMOVE_KEY);
590 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
591 OID_STR(OID_802_11_PMKID);
592 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
593 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
594 OID_STR(OID_802_11_TX_POWER_LEVEL);
595 OID_STR(OID_802_11_RSSI);
596 OID_STR(OID_802_11_RSSI_TRIGGER);
597 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
598 OID_STR(OID_802_11_RTS_THRESHOLD);
599 OID_STR(OID_802_11_SUPPORTED_RATES);
600 OID_STR(OID_802_11_CONFIGURATION);
601 OID_STR(OID_802_11_BSSID_LIST);
602#undef OID_STR
603 }
604
605 return "?";
606}
607#else
608static const char *oid_to_string(__le32 oid)
609{
610 return "?";
611}
612#endif
613
614
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200615/* translate error code */
616static int rndis_error_status(__le32 rndis_status)
617{
618 int ret = -EINVAL;
619 switch (rndis_status) {
620 case RNDIS_STATUS_SUCCESS:
621 ret = 0;
622 break;
623 case RNDIS_STATUS_FAILURE:
624 case RNDIS_STATUS_INVALID_DATA:
625 ret = -EINVAL;
626 break;
627 case RNDIS_STATUS_NOT_SUPPORTED:
628 ret = -EOPNOTSUPP;
629 break;
630 case RNDIS_STATUS_ADAPTER_NOT_READY:
631 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
632 ret = -EBUSY;
633 break;
634 }
635 return ret;
636}
637
638
639static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
640{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300641 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200642 union {
643 void *buf;
644 struct rndis_msg_hdr *header;
645 struct rndis_query *get;
646 struct rndis_query_c *get_c;
647 } u;
648 int ret, buflen;
649
650 buflen = *len + sizeof(*u.get);
651 if (buflen < CONTROL_BUFFER_SIZE)
652 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300653
654 if (buflen > COMMAND_BUFFER_SIZE) {
655 u.buf = kmalloc(buflen, GFP_KERNEL);
656 if (!u.buf)
657 return -ENOMEM;
658 } else {
659 u.buf = priv->command_buffer;
660 }
661
662 mutex_lock(&priv->command_lock);
663
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200664 memset(u.get, 0, sizeof *u.get);
665 u.get->msg_type = RNDIS_MSG_QUERY;
Harvey Harrison35c26c22009-02-14 22:56:56 -0800666 u.get->msg_len = cpu_to_le32(sizeof *u.get);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200667 u.get->oid = oid;
668
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300669 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300670 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300671 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300672 if (ret < 0)
673 devdbg(dev, "rndis_query_oid(%s): rndis_command() failed, %d "
674 "(%08x)", oid_to_string(oid), ret,
675 le32_to_cpu(u.get_c->status));
676
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200677 if (ret == 0) {
678 ret = le32_to_cpu(u.get_c->len);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +0300679 if (ret > *len)
680 *len = ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200681 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
682 ret = rndis_error_status(u.get_c->status);
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300683
684 if (ret < 0)
685 devdbg(dev, "rndis_query_oid(%s): device returned "
686 "error, 0x%08x (%d)", oid_to_string(oid),
687 le32_to_cpu(u.get_c->status), ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200688 }
689
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300690 mutex_unlock(&priv->command_lock);
691
692 if (u.buf != priv->command_buffer)
693 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200694 return ret;
695}
696
697
698static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
699{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300700 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200701 union {
702 void *buf;
703 struct rndis_msg_hdr *header;
704 struct rndis_set *set;
705 struct rndis_set_c *set_c;
706 } u;
707 int ret, buflen;
708
709 buflen = len + sizeof(*u.set);
710 if (buflen < CONTROL_BUFFER_SIZE)
711 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300712
713 if (buflen > COMMAND_BUFFER_SIZE) {
714 u.buf = kmalloc(buflen, GFP_KERNEL);
715 if (!u.buf)
716 return -ENOMEM;
717 } else {
718 u.buf = priv->command_buffer;
719 }
720
721 mutex_lock(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200722
723 memset(u.set, 0, sizeof *u.set);
724 u.set->msg_type = RNDIS_MSG_SET;
725 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
726 u.set->oid = oid;
727 u.set->len = cpu_to_le32(len);
Harvey Harrison35c26c22009-02-14 22:56:56 -0800728 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
729 u.set->handle = cpu_to_le32(0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200730 memcpy(u.buf + sizeof(*u.set), data, len);
731
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300732 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300733 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300734 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300735 if (ret < 0)
736 devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
737 "(%08x)", oid_to_string(oid), ret,
738 le32_to_cpu(u.set_c->status));
739
740 if (ret == 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200741 ret = rndis_error_status(u.set_c->status);
742
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300743 if (ret < 0)
744 devdbg(dev, "rndis_set_oid(%s): device returned error, "
745 "0x%08x (%d)", oid_to_string(oid),
746 le32_to_cpu(u.set_c->status), ret);
747 }
748
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300749 mutex_unlock(&priv->command_lock);
750
751 if (u.buf != priv->command_buffer)
752 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200753 return ret;
754}
755
756
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300757static int rndis_reset(struct usbnet *usbdev)
758{
759 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
760 struct rndis_reset *reset;
761 int ret;
762
763 mutex_lock(&priv->command_lock);
764
765 reset = (void *)priv->command_buffer;
766 memset(reset, 0, sizeof(*reset));
767 reset->msg_type = RNDIS_MSG_RESET;
768 reset->msg_len = cpu_to_le32(sizeof(*reset));
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300769 priv->current_command_oid = 0;
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300770 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
771
772 mutex_unlock(&priv->command_lock);
773
774 if (ret < 0)
775 return ret;
776 return 0;
777}
778
779
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200780/*
781 * Specs say that we can only set config parameters only soon after device
782 * initialization.
783 * value_type: 0 = u32, 2 = unicode string
784 */
785static int rndis_set_config_parameter(struct usbnet *dev, char *param,
786 int value_type, void *value)
787{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200788 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200789 int value_len, info_len, param_len, ret, i;
790 __le16 *unibuf;
791 __le32 *dst_value;
792
793 if (value_type == 0)
794 value_len = sizeof(__le32);
795 else if (value_type == 2)
796 value_len = strlen(value) * sizeof(__le16);
797 else
798 return -EINVAL;
799
800 param_len = strlen(param) * sizeof(__le16);
801 info_len = sizeof(*infobuf) + param_len + value_len;
802
803#ifdef DEBUG
804 info_len += 12;
805#endif
806 infobuf = kmalloc(info_len, GFP_KERNEL);
807 if (!infobuf)
808 return -ENOMEM;
809
810#ifdef DEBUG
811 info_len -= 12;
812 /* extra 12 bytes are for padding (debug output) */
813 memset(infobuf, 0xCC, info_len + 12);
814#endif
815
816 if (value_type == 2)
817 devdbg(dev, "setting config parameter: %s, value: %s",
818 param, (u8 *)value);
819 else
820 devdbg(dev, "setting config parameter: %s, value: %d",
821 param, *(u32 *)value);
822
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200823 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
824 infobuf->name_length = cpu_to_le32(param_len);
825 infobuf->type = cpu_to_le32(value_type);
826 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
827 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200828
829 /* simple string to unicode string conversion */
830 unibuf = (void *)infobuf + sizeof(*infobuf);
831 for (i = 0; i < param_len / sizeof(__le16); i++)
832 unibuf[i] = cpu_to_le16(param[i]);
833
834 if (value_type == 2) {
835 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
836 for (i = 0; i < value_len / sizeof(__le16); i++)
837 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
838 } else {
839 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
840 *dst_value = cpu_to_le32(*(u32 *)value);
841 }
842
843#ifdef DEBUG
844 devdbg(dev, "info buffer (len: %d):", info_len);
845 for (i = 0; i < info_len; i += 12) {
846 u32 *tmp = (u32 *)((u8 *)infobuf + i);
847 devdbg(dev, "%08X:%08X:%08X",
848 cpu_to_be32(tmp[0]),
849 cpu_to_be32(tmp[1]),
850 cpu_to_be32(tmp[2]));
851 }
852#endif
853
854 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
855 infobuf, info_len);
856 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200857 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200858
859 kfree(infobuf);
860 return ret;
861}
862
863static int rndis_set_config_parameter_str(struct usbnet *dev,
864 char *param, char *value)
865{
866 return(rndis_set_config_parameter(dev, param, 2, value));
867}
868
869/*static int rndis_set_config_parameter_u32(struct usbnet *dev,
870 char *param, u32 value)
871{
872 return(rndis_set_config_parameter(dev, param, 0, &value));
873}*/
874
875
876/*
877 * data conversion functions
878 */
879static int level_to_qual(int level)
880{
881 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
882 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
883}
884
885
886static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
887{
888 freq->e = 0;
889 freq->i = 0;
890 freq->flags = 0;
891
892 /* see comment in wireless.h above the "struct iw_freq"
893 * definition for an explanation of this if
894 * NOTE: 1000000 is due to the kHz
895 */
896 if (dsconfig > 1000000) {
897 freq->m = dsconfig / 10;
898 freq->e = 1;
899 } else
900 freq->m = dsconfig;
901
902 /* convert from kHz to Hz */
903 freq->e += 3;
904}
905
906
907static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
908{
909 if (freq->m < 1000 && freq->e == 0) {
David Kilroy9ee677c2008-12-23 14:03:38 +0000910 if (freq->m >= 1 && freq->m <= 14)
911 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200912 else
913 return -1;
914 } else {
915 int i;
916 *dsconfig = freq->m;
917 for (i = freq->e; i > 0; i--)
918 *dsconfig *= 10;
919 *dsconfig /= 1000;
920 }
921
922 return 0;
923}
924
925
926/*
927 * common functions
928 */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300929static void restore_keys(struct usbnet *usbdev);
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +0300930static int rndis_check_bssid_list(struct usbnet *usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200931
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200932static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200933{
934 int ret, len;
935
936 len = sizeof(*ssid);
937 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
938
939 if (ret != 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200940 ssid->length = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200941
942#ifdef DEBUG
943 {
944 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
945
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200946 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
947 tmp[le32_to_cpu(ssid->length)] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200948 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
949 }
950#endif
951 return ret;
952}
953
954
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200955static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200956{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300957 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200958 int ret;
959
960 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
961 if (ret == 0) {
962 memcpy(&priv->essid, ssid, sizeof(priv->essid));
963 priv->radio_on = 1;
964 devdbg(usbdev, "set_essid: radio_on = 1");
965 }
966
967 return ret;
968}
969
970
971static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
972{
973 int ret, len;
974
975 len = ETH_ALEN;
976 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
977
978 if (ret != 0)
979 memset(bssid, 0, ETH_ALEN);
980
981 return ret;
982}
983
Scott Ashcroft43646232008-05-27 00:06:15 +0300984static int get_association_info(struct usbnet *usbdev,
985 struct ndis_80211_assoc_info *info, int len)
986{
987 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
988 info, &len);
989}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200990
991static int is_associated(struct usbnet *usbdev)
992{
993 u8 bssid[ETH_ALEN];
994 int ret;
995
996 ret = get_bssid(usbdev, bssid);
997
998 return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0);
999}
1000
1001
1002static int disassociate(struct usbnet *usbdev, int reset_ssid)
1003{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001004 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001005 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001006 int i, ret = 0;
1007
1008 if (priv->radio_on) {
1009 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
1010 if (ret == 0) {
1011 priv->radio_on = 0;
1012 devdbg(usbdev, "disassociate: radio_on = 0");
1013
1014 if (reset_ssid)
1015 msleep(100);
1016 }
1017 }
1018
1019 /* disassociate causes radio to be turned off; if reset_ssid
1020 * is given, set random ssid to enable radio */
1021 if (reset_ssid) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001022 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1023 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1024 ssid.essid[0] = 0x1;
1025 ssid.essid[1] = 0xff;
1026 for (i = 2; i < sizeof(ssid.essid); i++)
1027 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001028 ret = set_essid(usbdev, &ssid);
1029 }
1030 return ret;
1031}
1032
1033
1034static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
1035{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001036 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001037 __le32 tmp;
1038 int auth_mode, ret;
1039
1040 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
1041 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
1042
1043 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
1044 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001045 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001046 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001047 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001048 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
1049 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001050 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001051 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001052 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001053 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001054 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001055 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
1056 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001057 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001058 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001059 auth_mode = NDIS_80211_AUTH_SHARED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001060 } else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001061 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001062
1063 tmp = cpu_to_le32(auth_mode);
1064 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1065 sizeof(tmp));
1066 if (ret != 0) {
1067 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
1068 return ret;
1069 }
1070
1071 priv->wpa_version = wpa_version;
1072 priv->wpa_authalg = authalg;
1073 return 0;
1074}
1075
1076
1077static int set_priv_filter(struct usbnet *usbdev)
1078{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001079 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001080 __le32 tmp;
1081
1082 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
1083
1084 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
1085 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001086 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001087 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001088 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001089
1090 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1091 sizeof(tmp));
1092}
1093
1094
1095static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1096{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001097 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001098 __le32 tmp;
1099 int encr_mode, ret;
1100
1101 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
1102 pairwise,
1103 groupwise);
1104
1105 if (pairwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001106 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001107 else if (pairwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001108 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001109 else if (pairwise &
1110 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001111 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001112 else if (groupwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001113 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001114 else if (groupwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001115 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001116 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001117 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001118
1119 tmp = cpu_to_le32(encr_mode);
1120 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1121 sizeof(tmp));
1122 if (ret != 0) {
1123 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
1124 return ret;
1125 }
1126
1127 priv->wpa_cipher_pair = pairwise;
1128 priv->wpa_cipher_group = groupwise;
1129 return 0;
1130}
1131
1132
1133static int set_assoc_params(struct usbnet *usbdev)
1134{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001135 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001136
1137 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
1138 set_priv_filter(usbdev);
1139 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
1140
1141 return 0;
1142}
1143
1144
1145static int set_infra_mode(struct usbnet *usbdev, int mode)
1146{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001147 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001148 __le32 tmp;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001149 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001150
1151 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
1152
1153 tmp = cpu_to_le32(mode);
1154 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1155 sizeof(tmp));
1156 if (ret != 0) {
1157 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
1158 return ret;
1159 }
1160
1161 /* NDIS drivers clear keys when infrastructure mode is
1162 * changed. But Linux tools assume otherwise. So set the
1163 * keys */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001164 restore_keys(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001165
1166 priv->infra_mode = mode;
1167 return 0;
1168}
1169
1170
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001171static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1172{
1173 __le32 tmp;
1174
1175 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1176
1177 if (rts_threshold < 0 || rts_threshold > 2347)
1178 rts_threshold = 2347;
1179
1180 tmp = cpu_to_le32(rts_threshold);
1181 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1182 sizeof(tmp));
1183}
1184
1185
1186static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1187{
1188 __le32 tmp;
1189
1190 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1191
1192 if (frag_threshold < 256 || frag_threshold > 2346)
1193 frag_threshold = 2346;
1194
1195 tmp = cpu_to_le32(frag_threshold);
1196 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1197 sizeof(tmp));
1198}
1199
1200
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001201static void set_default_iw_params(struct usbnet *usbdev)
1202{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001203 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001204
1205 priv->wpa_keymgmt = 0;
1206 priv->wpa_version = 0;
1207
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001208 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001209 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1210 IW_AUTH_ALG_OPEN_SYSTEM);
1211 set_priv_filter(usbdev);
1212 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1213}
1214
1215
1216static int deauthenticate(struct usbnet *usbdev)
1217{
1218 int ret;
1219
1220 ret = disassociate(usbdev, 1);
1221 set_default_iw_params(usbdev);
1222 return ret;
1223}
1224
1225
1226/* index must be 0 - N, as per NDIS */
1227static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
1228{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001229 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001230 struct ndis_80211_wep_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001231 int cipher, ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001232
Jussi Kivilinna40ba60d2009-08-20 21:00:34 +03001233 if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001234 return -EINVAL;
1235
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001236 if (key_len == 5)
1237 cipher = WLAN_CIPHER_SUITE_WEP40;
1238 else
1239 cipher = WLAN_CIPHER_SUITE_WEP104;
1240
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001241 memset(&ndis_key, 0, sizeof(ndis_key));
1242
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001243 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1244 ndis_key.length = cpu_to_le32(key_len);
1245 ndis_key.index = cpu_to_le32(index);
1246 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001247
1248 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001249 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001250 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1251 IW_AUTH_CIPHER_NONE);
1252 if (ret)
1253 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1254 ret);
1255 }
1256
1257 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1258 sizeof(ndis_key));
1259 if (ret != 0) {
1260 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1261 index+1, ret);
1262 return ret;
1263 }
1264
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001265 priv->encr_keys[index].len = key_len;
1266 priv->encr_keys[index].cipher = cipher;
1267 memcpy(&priv->encr_keys[index].material, key, key_len);
1268 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001269
1270 return 0;
1271}
1272
1273
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001274static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001275 int index, const u8 *addr, const u8 *rx_seq, int cipher,
1276 int flags)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001277{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001278 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001279 struct ndis_80211_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001280 bool is_addr_ok;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001281 int ret;
1282
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001283 if (index < 0 || index >= 4) {
1284 devdbg(usbdev, "add_wpa_key: index out of range (%i)", index);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001285 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001286 }
1287 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1288 devdbg(usbdev, "add_wpa_key: key length out of range (%i)",
1289 key_len);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001290 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001291 }
1292 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq) {
1293 devdbg(usbdev, "add_wpa_key: recv seq flag without buffer");
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001294 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001295 }
1296 is_addr_ok = addr && memcmp(addr, zero_bssid, ETH_ALEN) != 0 &&
1297 memcmp(addr, ffff_bssid, ETH_ALEN) != 0;
1298 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1299 devdbg(usbdev, "add_wpa_key: pairwise but bssid invalid (%pM)",
1300 addr);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001301 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001302 }
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001303
1304 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001305 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1306 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1307 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001308
1309 memset(&ndis_key, 0, sizeof(ndis_key));
1310
1311 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1312 sizeof(ndis_key.material) + key_len);
1313 ndis_key.length = cpu_to_le32(key_len);
1314 ndis_key.index = cpu_to_le32(index) | flags;
1315
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001316 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001317 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1318 * different order than NDIS spec, so swap the order here. */
1319 memcpy(ndis_key.material, key, 16);
1320 memcpy(ndis_key.material + 16, key + 24, 8);
1321 memcpy(ndis_key.material + 24, key + 16, 8);
1322 } else
1323 memcpy(ndis_key.material, key, key_len);
1324
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001325 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001326 memcpy(ndis_key.rsc, rx_seq, 6);
1327
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001328 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001329 /* pairwise key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001330 memcpy(ndis_key.bssid, addr, ETH_ALEN);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001331 } else {
1332 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001333 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001334 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1335 else
1336 get_bssid(usbdev, ndis_key.bssid);
1337 }
1338
1339 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1340 le32_to_cpu(ndis_key.size));
1341 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1342 if (ret != 0)
1343 return ret;
1344
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001345 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1346 priv->encr_keys[index].len = key_len;
1347 priv->encr_keys[index].cipher = cipher;
1348 memcpy(&priv->encr_keys[index].material, key, key_len);
1349 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1350 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1351 else
1352 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinna98391782009-05-22 17:40:34 +03001353
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001354 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001355 priv->encr_tx_key_index = index;
1356
1357 return 0;
1358}
1359
1360
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001361static int restore_key(struct usbnet *usbdev, int key_idx)
1362{
1363 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1364 struct rndis_wlan_encr_key key;
1365 int flags;
1366
1367 key = priv->encr_keys[key_idx];
1368
1369 devdbg(usbdev, "restore_key: %i:%s:%i", key_idx,
1370 is_wpa_key(priv, key_idx) ? "wpa" : "wep",
1371 key.len);
1372
1373 if (key.len == 0)
1374 return 0;
1375
1376 if (is_wpa_key(priv, key_idx)) {
1377 flags = 0;
1378
1379 /*if (priv->encr_tx_key_index == key_idx)
1380 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;*/
1381
1382 if (memcmp(key.bssid, zero_bssid, ETH_ALEN) != 0 &&
1383 memcmp(key.bssid, ffff_bssid, ETH_ALEN) != 0)
1384 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
1385
1386 return add_wpa_key(usbdev, key.material, key.len, key_idx,
1387 key.bssid, NULL, key.cipher, flags);
1388 }
1389
1390 return add_wep_key(usbdev, key.material, key.len, key_idx);
1391}
1392
1393
1394static void restore_keys(struct usbnet *usbdev)
1395{
1396 int i;
1397
1398 for (i = 0; i < 4; i++)
1399 restore_key(usbdev, i);
1400}
1401
1402
1403static void clear_key(struct rndis_wlan_private *priv, int idx)
1404{
1405 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1406}
1407
1408
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001409/* remove_key is for both wep and wpa */
1410static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1411{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001412 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001413 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001414 __le32 keyindex;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001415 bool is_wpa;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001416 int ret;
1417
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001418 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001419 return 0;
1420
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001421 is_wpa = is_wpa_key(priv, index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001422
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001423 devdbg(usbdev, "remove_key: %i:%s:%i", index, is_wpa ? "wpa" : "wep",
1424 priv->encr_keys[index].len);
1425
1426 clear_key(priv, index);
1427
1428 if (is_wpa) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001429 remove_key.size = cpu_to_le32(sizeof(remove_key));
1430 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001431 if (bssid) {
1432 /* pairwise key */
1433 if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001434 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001435 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001436 memcpy(remove_key.bssid, bssid,
1437 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001438 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001439 memset(remove_key.bssid, 0xff,
1440 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001441
1442 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1443 sizeof(remove_key));
1444 if (ret != 0)
1445 return ret;
1446 } else {
1447 keyindex = cpu_to_le32(index);
1448 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1449 sizeof(keyindex));
1450 if (ret != 0) {
1451 devwarn(usbdev,
1452 "removing encryption key %d failed (%08X)",
1453 index, ret);
1454 return ret;
1455 }
1456 }
1457
1458 /* if it is transmit key, disable encryption */
1459 if (index == priv->encr_tx_key_index)
1460 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1461
1462 return 0;
1463}
1464
1465
1466static void set_multicast_list(struct usbnet *usbdev)
1467{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001468 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001469 struct dev_mc_list *mclist;
1470 __le32 filter;
1471 int ret, i, size;
1472 char *buf;
1473
1474 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1475
1476 if (usbdev->net->flags & IFF_PROMISC) {
1477 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1478 RNDIS_PACKET_TYPE_ALL_LOCAL;
1479 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1480 usbdev->net->mc_count > priv->multicast_size) {
1481 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1482 } else if (usbdev->net->mc_count > 0) {
1483 size = min(priv->multicast_size, usbdev->net->mc_count);
1484 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1485 if (!buf) {
1486 devwarn(usbdev,
1487 "couldn't alloc %d bytes of memory",
1488 size * ETH_ALEN);
1489 return;
1490 }
1491
1492 mclist = usbdev->net->mc_list;
1493 for (i = 0; i < size && mclist; mclist = mclist->next) {
1494 if (mclist->dmi_addrlen != ETH_ALEN)
1495 continue;
1496
1497 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1498 i++;
1499 }
1500
1501 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1502 i * ETH_ALEN);
1503 if (ret == 0 && i > 0)
1504 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1505 else
1506 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1507
1508 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1509 i, priv->multicast_size, ret);
1510
1511 kfree(buf);
1512 }
1513
1514 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1515 sizeof(filter));
1516 if (ret < 0) {
1517 devwarn(usbdev, "couldn't set packet filter: %08x",
1518 le32_to_cpu(filter));
1519 }
1520
1521 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1522 le32_to_cpu(filter), ret);
1523}
1524
1525
1526/*
John W. Linville964c1d42009-03-26 23:40:01 +02001527 * cfg80211 ops
1528 */
Johannes Berge36d56b2009-06-09 21:04:43 +02001529static int rndis_change_virtual_intf(struct wiphy *wiphy,
1530 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +02001531 enum nl80211_iftype type, u32 *flags,
1532 struct vif_params *params)
1533{
Johannes Berge36d56b2009-06-09 21:04:43 +02001534 struct usbnet *usbdev = netdev_priv(dev);
John W. Linville964c1d42009-03-26 23:40:01 +02001535 int mode;
1536
John W. Linville964c1d42009-03-26 23:40:01 +02001537 switch (type) {
1538 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001539 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001540 break;
1541 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001542 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001543 break;
1544 default:
1545 return -EINVAL;
1546 }
1547
1548 return set_infra_mode(usbdev, mode);
1549}
1550
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001551
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001552static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1553{
1554 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1555 struct usbnet *usbdev = priv->usbdev;
1556 int err;
1557
1558 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1559 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1560 if (err < 0)
1561 return err;
1562 }
1563
1564 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1565 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1566 if (err < 0)
1567 return err;
1568 }
1569
1570 return 0;
1571}
1572
1573
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001574static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1575 int dbm)
1576{
1577 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1578 struct usbnet *usbdev = priv->usbdev;
1579
1580 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1581
1582 /* Device doesn't support changing txpower after initialization, only
1583 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1584 * currently used.
1585 */
1586 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1587 if (!priv->radio_on)
1588 disassociate(usbdev, 1); /* turn on radio */
1589
1590 return 0;
1591 }
1592
1593 return -ENOTSUPP;
1594}
1595
1596
1597static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1598{
1599 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1600 struct usbnet *usbdev = priv->usbdev;
1601
1602 *dbm = get_bcm4320_power_dbm(priv);
1603
1604 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1605
1606 return 0;
1607}
1608
1609
Jussi Kivilinnab1d25a62009-08-28 12:59:05 +03001610#define SCAN_DELAY_JIFFIES (6 * HZ)
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001611static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1612 struct cfg80211_scan_request *request)
1613{
1614 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001615 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001616 int ret;
1617 __le32 tmp;
1618
1619 devdbg(usbdev, "cfg80211.scan");
1620
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +03001621 /* Get current bssid list from device before new scan, as new scan
1622 * clears internal bssid list.
1623 */
1624 rndis_check_bssid_list(usbdev);
1625
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001626 if (!request)
1627 return -EINVAL;
1628
1629 if (priv->scan_request && priv->scan_request != request)
1630 return -EBUSY;
1631
1632 priv->scan_request = request;
1633
1634 tmp = cpu_to_le32(1);
1635 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1636 sizeof(tmp));
1637 if (ret == 0) {
1638 /* Wait before retrieving scan results from device */
1639 queue_delayed_work(priv->workqueue, &priv->scan_work,
1640 SCAN_DELAY_JIFFIES);
1641 }
1642
1643 return ret;
1644}
1645
1646
1647static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1648 struct ndis_80211_bssid_ex *bssid)
1649{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001650 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001651 struct ieee80211_channel *channel;
1652 s32 signal;
1653 u64 timestamp;
1654 u16 capability;
1655 u16 beacon_interval;
1656 struct ndis_80211_fixed_ies *fixed;
1657 int ie_len, bssid_len;
1658 u8 *ie;
1659
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001660 devdbg(usbdev, " found bssid: '%.32s' [%pM]", bssid->ssid.essid,
1661 bssid->mac);
1662
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001663 /* parse bssid structure */
1664 bssid_len = le32_to_cpu(bssid->length);
1665
1666 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1667 sizeof(struct ndis_80211_fixed_ies))
1668 return NULL;
1669
1670 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1671
1672 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1673 ie_len = min(bssid_len - (int)sizeof(*bssid),
1674 (int)le32_to_cpu(bssid->ie_length));
1675 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1676 if (ie_len < 0)
1677 return NULL;
1678
1679 /* extract data for cfg80211_inform_bss */
1680 channel = ieee80211_get_channel(priv->wdev.wiphy,
1681 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1682 if (!channel)
1683 return NULL;
1684
1685 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1686 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1687 capability = le16_to_cpu(fixed->capabilities);
1688 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1689
1690 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1691 timestamp, capability, beacon_interval, ie, ie_len, signal,
1692 GFP_KERNEL);
1693}
1694
1695
1696static int rndis_check_bssid_list(struct usbnet *usbdev)
1697{
1698 void *buf = NULL;
1699 struct ndis_80211_bssid_list_ex *bssid_list;
1700 struct ndis_80211_bssid_ex *bssid;
1701 int ret = -EINVAL, len, count, bssid_len;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001702 bool resized = false;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001703
1704 devdbg(usbdev, "check_bssid_list");
1705
1706 len = CONTROL_BUFFER_SIZE;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001707resize_buf:
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001708 buf = kmalloc(len, GFP_KERNEL);
1709 if (!buf) {
1710 ret = -ENOMEM;
1711 goto out;
1712 }
1713
1714 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1715 if (ret != 0)
1716 goto out;
1717
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001718 if (!resized && len > CONTROL_BUFFER_SIZE) {
1719 resized = true;
1720 kfree(buf);
1721 goto resize_buf;
1722 }
1723
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001724 bssid_list = buf;
1725 bssid = bssid_list->bssid;
1726 bssid_len = le32_to_cpu(bssid->length);
1727 count = le32_to_cpu(bssid_list->num_items);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001728 devdbg(usbdev, "check_bssid_list: %d BSSIDs found (buflen: %d)", count,
1729 len);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001730
1731 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1732 rndis_bss_info_update(usbdev, bssid);
1733
1734 bssid = (void *)bssid + bssid_len;
1735 bssid_len = le32_to_cpu(bssid->length);
1736 count--;
1737 }
1738
1739out:
1740 kfree(buf);
1741 return ret;
1742}
1743
1744
1745static void rndis_get_scan_results(struct work_struct *work)
1746{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001747 struct rndis_wlan_private *priv =
1748 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001749 struct usbnet *usbdev = priv->usbdev;
1750 int ret;
1751
1752 devdbg(usbdev, "get_scan_results");
1753
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03001754 if (!priv->scan_request)
1755 return;
1756
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001757 ret = rndis_check_bssid_list(usbdev);
1758
1759 cfg80211_scan_done(priv->scan_request, ret < 0);
1760
1761 priv->scan_request = NULL;
1762}
1763
1764
John W. Linville964c1d42009-03-26 23:40:01 +02001765/*
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001766 * wireless extension handlers
1767 */
1768
1769static int rndis_iw_commit(struct net_device *dev,
1770 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1771{
1772 /* dummy op */
1773 return 0;
1774}
1775
1776
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001777static int rndis_iw_set_essid(struct net_device *dev,
1778 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1779{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001780 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001781 int length = wrqu->essid.length;
Wang Chen524ad0a2008-11-12 23:39:10 -08001782 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001783
1784 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1785 wrqu->essid.flags, wrqu->essid.length, essid);
1786
1787 if (length > NDIS_802_11_LENGTH_SSID)
1788 length = NDIS_802_11_LENGTH_SSID;
1789
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001790 ssid.length = cpu_to_le32(length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001791 if (length > 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001792 memcpy(ssid.essid, essid, length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001793 else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001794 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001795
1796 set_assoc_params(usbdev);
1797
1798 if (!wrqu->essid.flags || length == 0)
1799 return disassociate(usbdev, 1);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001800 else {
1801 /* Pause and purge rx queue, so we don't pass packets before
1802 * 'media connect'-indication.
1803 */
1804 usbnet_pause_rx(usbdev);
1805 usbnet_purge_paused_rxq(usbdev);
1806
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001807 return set_essid(usbdev, &ssid);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001808 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001809}
1810
1811
1812static int rndis_iw_get_essid(struct net_device *dev,
1813 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1814{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001815 struct ndis_80211_ssid ssid;
Wang Chen524ad0a2008-11-12 23:39:10 -08001816 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001817 int ret;
1818
1819 ret = get_essid(usbdev, &ssid);
1820
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001821 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001822 wrqu->essid.flags = 1;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001823 wrqu->essid.length = le32_to_cpu(ssid.length);
1824 memcpy(essid, ssid.essid, wrqu->essid.length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001825 essid[wrqu->essid.length] = 0;
1826 } else {
1827 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1828 wrqu->essid.flags = 0;
1829 wrqu->essid.length = 0;
1830 }
1831 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1832 return ret;
1833}
1834
1835
1836static int rndis_iw_get_bssid(struct net_device *dev,
1837 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1838{
Wang Chen524ad0a2008-11-12 23:39:10 -08001839 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001840 unsigned char bssid[ETH_ALEN];
1841 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001842
1843 ret = get_bssid(usbdev, bssid);
1844
1845 if (ret == 0)
Johannes Berge1749612008-10-27 15:59:26 -07001846 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001847 else
1848 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1849
1850 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1851 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1852
1853 return ret;
1854}
1855
1856
1857static int rndis_iw_set_bssid(struct net_device *dev,
1858 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1859{
Wang Chen524ad0a2008-11-12 23:39:10 -08001860 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001861 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001862 int ret;
1863
Johannes Berge1749612008-10-27 15:59:26 -07001864 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001865
1866 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1867
1868 /* user apps may set ap's mac address, which is not required;
1869 * they may fail to work if this function fails, so return
1870 * success */
1871 if (ret)
1872 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1873
1874 return 0;
1875}
1876
1877
1878static int rndis_iw_set_auth(struct net_device *dev,
1879 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1880{
1881 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001882 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001883 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001884 int ret = -ENOTSUPP;
1885
1886 switch (p->flags & IW_AUTH_INDEX) {
1887 case IW_AUTH_WPA_VERSION:
1888 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1889 priv->wpa_version = p->value;
1890 ret = 0;
1891 break;
1892
1893 case IW_AUTH_CIPHER_PAIRWISE:
1894 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1895 priv->wpa_cipher_pair = p->value;
1896 ret = 0;
1897 break;
1898
1899 case IW_AUTH_CIPHER_GROUP:
1900 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1901 priv->wpa_cipher_group = p->value;
1902 ret = 0;
1903 break;
1904
1905 case IW_AUTH_KEY_MGMT:
1906 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1907 priv->wpa_keymgmt = p->value;
1908 ret = 0;
1909 break;
1910
1911 case IW_AUTH_TKIP_COUNTERMEASURES:
1912 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1913 p->value);
1914 ret = 0;
1915 break;
1916
1917 case IW_AUTH_DROP_UNENCRYPTED:
1918 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1919 ret = 0;
1920 break;
1921
1922 case IW_AUTH_80211_AUTH_ALG:
1923 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1924 priv->wpa_authalg = p->value;
1925 ret = 0;
1926 break;
1927
1928 case IW_AUTH_WPA_ENABLED:
1929 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1930 if (wrqu->param.value)
1931 deauthenticate(usbdev);
1932 ret = 0;
1933 break;
1934
1935 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1936 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1937 p->value);
1938 ret = 0;
1939 break;
1940
1941 case IW_AUTH_ROAMING_CONTROL:
1942 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1943 ret = 0;
1944 break;
1945
1946 case IW_AUTH_PRIVACY_INVOKED:
1947 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1948 wrqu->param.flags & IW_AUTH_INDEX);
1949 return -EOPNOTSUPP;
1950
1951 default:
1952 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1953 p->flags & IW_AUTH_INDEX, p->value);
1954 }
1955 return ret;
1956}
1957
1958
1959static int rndis_iw_get_auth(struct net_device *dev,
1960 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1961{
1962 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001963 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001964 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001965
1966 switch (p->flags & IW_AUTH_INDEX) {
1967 case IW_AUTH_WPA_VERSION:
1968 p->value = priv->wpa_version;
1969 break;
1970 case IW_AUTH_CIPHER_PAIRWISE:
1971 p->value = priv->wpa_cipher_pair;
1972 break;
1973 case IW_AUTH_CIPHER_GROUP:
1974 p->value = priv->wpa_cipher_group;
1975 break;
1976 case IW_AUTH_KEY_MGMT:
1977 p->value = priv->wpa_keymgmt;
1978 break;
1979 case IW_AUTH_80211_AUTH_ALG:
1980 p->value = priv->wpa_authalg;
1981 break;
1982 default:
1983 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1984 wrqu->param.flags & IW_AUTH_INDEX);
1985 return -EOPNOTSUPP;
1986 }
1987 return 0;
1988}
1989
1990
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001991static int rndis_iw_set_encode(struct net_device *dev,
1992 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1993{
Wang Chen524ad0a2008-11-12 23:39:10 -08001994 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001995 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001996 struct rndis_wlan_encr_key key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001997 int ret, index, key_len;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001998 u8 *keybuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001999
2000 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
2001
2002 /* iwconfig gives index as 1 - N */
2003 if (index > 0)
2004 index--;
2005 else
2006 index = priv->encr_tx_key_index;
2007
2008 if (index < 0 || index >= 4) {
2009 devwarn(usbdev, "encryption index out of range (%u)", index);
2010 return -EINVAL;
2011 }
2012
2013 /* remove key if disabled */
2014 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
2015 if (remove_key(usbdev, index, NULL))
2016 return -EINVAL;
2017 else
2018 return 0;
2019 }
2020
2021 /* global encryption state (for all keys) */
2022 if (wrqu->data.flags & IW_ENCODE_OPEN)
2023 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
2024 IW_AUTH_ALG_OPEN_SYSTEM);
2025 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
2026 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
2027 IW_AUTH_ALG_SHARED_KEY);
2028 if (ret != 0)
2029 return ret;
2030
2031 if (wrqu->data.length > 0) {
2032 key_len = wrqu->data.length;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002033 keybuf = extra;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002034 } else {
2035 /* must be set as tx key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002036 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002037 return -EINVAL;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002038 key = priv->encr_keys[index];
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002039 key_len = key.len;
2040 keybuf = key.material;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002041 priv->encr_tx_key_index = index;
2042 }
2043
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002044 if (add_wep_key(usbdev, keybuf, key_len, index) != 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002045 return -EINVAL;
2046
2047 if (index == priv->encr_tx_key_index)
2048 /* ndis drivers want essid to be set after setting encr */
2049 set_essid(usbdev, &priv->essid);
2050
2051 return 0;
2052}
2053
2054
2055static int rndis_iw_set_encode_ext(struct net_device *dev,
2056 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2057{
2058 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
Wang Chen524ad0a2008-11-12 23:39:10 -08002059 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002060 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002061 int keyidx, flags, cipher;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002062
2063 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
2064
2065 /* iwconfig gives index as 1 - N */
2066 if (keyidx)
2067 keyidx--;
2068 else
2069 keyidx = priv->encr_tx_key_index;
2070
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002071 if (keyidx < 0 || keyidx >= 4) {
2072 devwarn(usbdev, "encryption index out of range (%u)", keyidx);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002073 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002074 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002075
2076 if (ext->alg == WPA_ALG_WEP) {
2077 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2078 priv->encr_tx_key_index = keyidx;
2079 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
2080 }
2081
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002082 cipher = -1;
2083 if (ext->alg == IW_ENCODE_ALG_TKIP)
2084 cipher = WLAN_CIPHER_SUITE_TKIP;
2085 else if (ext->alg == IW_ENCODE_ALG_CCMP)
2086 cipher = WLAN_CIPHER_SUITE_CCMP;
2087
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002088 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
2089 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
2090 return remove_key(usbdev, keyidx, NULL);
2091
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002092 if (cipher == -1)
2093 return -EOPNOTSUPP;
2094
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002095 flags = 0;
2096 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002097 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002098 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002099 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002100 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002101 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002102
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002103 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx,
2104 (u8 *)&ext->addr.sa_data, ext->rx_seq, cipher,
2105 flags);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002106}
2107
2108
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002109static int rndis_iw_set_genie(struct net_device *dev,
2110 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2111{
Wang Chen524ad0a2008-11-12 23:39:10 -08002112 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002113 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002114 int ret = 0;
2115
2116#ifdef DEBUG
2117 int j;
2118 u8 *gie = extra;
2119 for (j = 0; j < wrqu->data.length; j += 8)
2120 devdbg(usbdev,
2121 "SIOCSIWGENIE %04x - "
2122 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
2123 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
2124 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
2125#endif
2126 /* clear existing IEs */
2127 if (priv->wpa_ie_len) {
2128 kfree(priv->wpa_ie);
2129 priv->wpa_ie_len = 0;
2130 }
2131
2132 /* set new IEs */
2133 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
2134 if (priv->wpa_ie) {
2135 priv->wpa_ie_len = wrqu->data.length;
2136 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
2137 } else
2138 ret = -ENOMEM;
2139 return ret;
2140}
2141
2142
2143static int rndis_iw_get_genie(struct net_device *dev,
2144 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2145{
Wang Chen524ad0a2008-11-12 23:39:10 -08002146 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002147 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002148
2149 devdbg(usbdev, "SIOCGIWGENIE");
2150
2151 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
2152 wrqu->data.length = 0;
2153 return 0;
2154 }
2155
2156 if (wrqu->data.length < priv->wpa_ie_len)
2157 return -E2BIG;
2158
2159 wrqu->data.length = priv->wpa_ie_len;
2160 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
2161
2162 return 0;
2163}
2164
2165
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002166static int rndis_iw_set_freq(struct net_device *dev,
2167 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2168{
Wang Chen524ad0a2008-11-12 23:39:10 -08002169 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002170 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002171 unsigned int dsconfig;
2172 int len, ret;
2173
2174 /* this OID is valid only when not associated */
2175 if (is_associated(usbdev))
2176 return 0;
2177
2178 dsconfig = 0;
2179 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
2180 return -EINVAL;
2181
2182 len = sizeof(config);
2183 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2184 if (ret != 0) {
2185 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
2186 return 0;
2187 }
2188
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002189 config.ds_config = cpu_to_le32(dsconfig);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002190
2191 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
2192 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
2193 sizeof(config));
2194}
2195
2196
2197static int rndis_iw_get_freq(struct net_device *dev,
2198 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2199{
Wang Chen524ad0a2008-11-12 23:39:10 -08002200 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002201 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002202 int len, ret;
2203
2204 len = sizeof(config);
2205 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2206 if (ret == 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002207 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002208
2209 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
2210 return ret;
2211}
2212
2213
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002214static int rndis_iw_get_rate(struct net_device *dev,
2215 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2216{
Wang Chen524ad0a2008-11-12 23:39:10 -08002217 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002218 __le32 tmp;
2219 int ret, len;
2220
2221 len = sizeof(tmp);
2222 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
2223 if (ret == 0) {
2224 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
2225 wrqu->bitrate.disabled = 0;
2226 wrqu->bitrate.flags = 1;
2227 }
2228 return ret;
2229}
2230
2231
2232static int rndis_iw_set_mlme(struct net_device *dev,
2233 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2234{
Wang Chen524ad0a2008-11-12 23:39:10 -08002235 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002236 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002237 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2238 unsigned char bssid[ETH_ALEN];
2239
2240 get_bssid(usbdev, bssid);
2241
2242 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
2243 return -EINVAL;
2244
2245 switch (mlme->cmd) {
2246 case IW_MLME_DEAUTH:
2247 return deauthenticate(usbdev);
2248 case IW_MLME_DISASSOC:
2249 return disassociate(usbdev, priv->radio_on);
2250 default:
2251 return -EOPNOTSUPP;
2252 }
2253
2254 return 0;
2255}
2256
2257
2258static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
2259{
Wang Chen524ad0a2008-11-12 23:39:10 -08002260 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002261 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002262 unsigned long flags;
2263
2264 spin_lock_irqsave(&priv->stats_lock, flags);
2265 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2266 spin_unlock_irqrestore(&priv->stats_lock, flags);
2267
2268 return &priv->iwstats;
2269}
2270
2271
2272#define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2273static const iw_handler rndis_iw_handler[] =
2274{
2275 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002276 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002277 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2278 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
John W. Linville964c1d42009-03-26 23:40:01 +02002279 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2280 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002281 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002282 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2283 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002284 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2285 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002286 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2287 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002288 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002289 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2290 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2291 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2292 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002293 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2294 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002295 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2296 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2297 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2298 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2299 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2300 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2301 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2302};
2303
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002304static const iw_handler rndis_wlan_private_handler[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002305};
2306
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002307static const struct iw_priv_args rndis_wlan_private_args[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002308};
2309
2310
2311static const struct iw_handler_def rndis_iw_handlers = {
2312 .num_standard = ARRAY_SIZE(rndis_iw_handler),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002313 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2314 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002315 .standard = (iw_handler *)rndis_iw_handler,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002316 .private = (iw_handler *)rndis_wlan_private_handler,
2317 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002318 .get_wireless_stats = rndis_get_wireless_stats,
2319};
2320
2321
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002322static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002323{
Scott Ashcroft43646232008-05-27 00:06:15 +03002324 struct ndis_80211_assoc_info *info;
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002325 union iwreq_data evt;
2326 u8 assoc_buf[sizeof(*info) + IW_CUSTOM_MAX + 32];
2327 u8 bssid[ETH_ALEN];
Scott Ashcroft43646232008-05-27 00:06:15 +03002328 int ret, offset;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002329
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002330 memset(assoc_buf, 0, sizeof(assoc_buf));
2331 info = (void *)assoc_buf;
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002332
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002333 netif_carrier_on(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002334
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002335 /* Get association info IEs from device and send them back to
2336 * userspace. */
2337 ret = get_association_info(usbdev, info, sizeof(assoc_buf));
2338 if (!ret) {
2339 evt.data.length = le32_to_cpu(info->req_ie_length);
2340 if (evt.data.length > 0) {
2341 offset = le32_to_cpu(info->offset_req_ies);
2342 wireless_send_event(usbdev->net,
2343 IWEVASSOCREQIE, &evt,
2344 (char *)info + offset);
Scott Ashcroft43646232008-05-27 00:06:15 +03002345 }
2346
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002347 evt.data.length = le32_to_cpu(info->resp_ie_length);
2348 if (evt.data.length > 0) {
2349 offset = le32_to_cpu(info->offset_resp_ies);
2350 wireless_send_event(usbdev->net,
2351 IWEVASSOCRESPIE, &evt,
2352 (char *)info + offset);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002353 }
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002354
2355 usbnet_resume_rx(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002356 }
2357
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002358 ret = get_bssid(usbdev, bssid);
2359 if (!ret) {
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002360 evt.data.flags = 0;
2361 evt.data.length = 0;
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002362 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002363 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2364 }
2365
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002366 usbnet_resume_rx(usbdev);
2367}
2368
2369static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
2370{
2371 union iwreq_data evt;
2372
2373 netif_carrier_off(usbdev->net);
2374
2375 evt.data.flags = 0;
2376 evt.data.length = 0;
2377 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2378 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2379}
2380
2381static void rndis_wlan_worker(struct work_struct *work)
2382{
2383 struct rndis_wlan_private *priv =
2384 container_of(work, struct rndis_wlan_private, work);
2385 struct usbnet *usbdev = priv->usbdev;
2386
2387 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
2388 rndis_wlan_do_link_up_work(usbdev);
2389
2390 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
2391 rndis_wlan_do_link_down_work(usbdev);
2392
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002393 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2394 set_multicast_list(usbdev);
2395}
2396
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002397static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002398{
Wang Chen524ad0a2008-11-12 23:39:10 -08002399 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002400 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002401
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002402 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2403 return;
2404
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002405 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2406 queue_work(priv->workqueue, &priv->work);
2407}
2408
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002409
2410static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2411 struct ndis_80211_status_indication *indication,
2412 int len)
2413{
2414 u8 *buf;
2415 const char *type;
2416 int flags, buflen;
2417 bool pairwise_error, group_error;
2418 struct ndis_80211_auth_request *auth_req;
2419
2420 /* must have at least one array entry */
2421 if (len < offsetof(struct ndis_80211_status_indication, u) +
2422 sizeof(struct ndis_80211_auth_request)) {
2423 devinfo(usbdev, "authentication indication: "
2424 "too short message (%i)", len);
2425 return;
2426 }
2427
2428 buf = (void *)&indication->u.auth_request[0];
2429 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2430
2431 while (buflen >= sizeof(*auth_req)) {
2432 auth_req = (void *)buf;
2433 type = "unknown";
2434 flags = le32_to_cpu(auth_req->flags);
2435 pairwise_error = false;
2436 group_error = false;
2437
2438 if (flags & 0x1)
2439 type = "reauth request";
2440 if (flags & 0x2)
2441 type = "key update request";
2442 if (flags & 0x6) {
2443 pairwise_error = true;
2444 type = "pairwise_error";
2445 }
2446 if (flags & 0xe) {
2447 group_error = true;
2448 type = "group_error";
2449 }
2450
2451 devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
2452 le32_to_cpu(auth_req->flags));
2453
2454 if (pairwise_error || group_error) {
2455 union iwreq_data wrqu;
2456 struct iw_michaelmicfailure micfailure;
2457
2458 memset(&micfailure, 0, sizeof(micfailure));
2459 if (pairwise_error)
2460 micfailure.flags |= IW_MICFAILURE_PAIRWISE;
2461 if (group_error)
2462 micfailure.flags |= IW_MICFAILURE_GROUP;
2463
2464 memcpy(micfailure.src_addr.sa_data, auth_req->bssid,
2465 ETH_ALEN);
2466
2467 memset(&wrqu, 0, sizeof(wrqu));
2468 wrqu.data.length = sizeof(micfailure);
2469 wireless_send_event(usbdev->net, IWEVMICHAELMICFAILURE,
2470 &wrqu, (u8 *)&micfailure);
2471 }
2472
2473 buflen -= le32_to_cpu(auth_req->length);
2474 buf += le32_to_cpu(auth_req->length);
2475 }
2476}
2477
2478static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2479 struct ndis_80211_status_indication *indication,
2480 int len)
2481{
2482 struct ndis_80211_pmkid_cand_list *cand_list;
2483 int list_len, expected_len, i;
2484
2485 if (len < offsetof(struct ndis_80211_status_indication, u) +
2486 sizeof(struct ndis_80211_pmkid_cand_list)) {
2487 devinfo(usbdev, "pmkid candidate list indication: "
2488 "too short message (%i)", len);
2489 return;
2490 }
2491
2492 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2493 sizeof(struct ndis_80211_pmkid_candidate);
2494 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2495 offsetof(struct ndis_80211_status_indication, u);
2496
2497 if (len < expected_len) {
2498 devinfo(usbdev, "pmkid candidate list indication: "
2499 "list larger than buffer (%i < %i)",
2500 len, expected_len);
2501 return;
2502 }
2503
2504 cand_list = &indication->u.cand_list;
2505
2506 devinfo(usbdev, "pmkid candidate list indication: "
2507 "version %i, candidates %i",
2508 le32_to_cpu(cand_list->version),
2509 le32_to_cpu(cand_list->num_candidates));
2510
2511 if (le32_to_cpu(cand_list->version) != 1)
2512 return;
2513
2514 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
2515 struct iw_pmkid_cand pcand;
2516 union iwreq_data wrqu;
2517 struct ndis_80211_pmkid_candidate *cand =
2518 &cand_list->candidate_list[i];
2519
2520 devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
2521 i, le32_to_cpu(cand->flags), cand->bssid);
2522
2523 memset(&pcand, 0, sizeof(pcand));
2524 if (le32_to_cpu(cand->flags) & 0x01)
2525 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2526 pcand.index = i;
2527 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2528
2529 memset(&wrqu, 0, sizeof(wrqu));
2530 wrqu.data.length = sizeof(pcand);
2531 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2532 (u8 *)&pcand);
2533 }
2534}
2535
2536static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2537 struct rndis_indicate *msg, int buflen)
2538{
2539 struct ndis_80211_status_indication *indication;
2540 int len, offset;
2541
2542 offset = offsetof(struct rndis_indicate, status) +
2543 le32_to_cpu(msg->offset);
2544 len = le32_to_cpu(msg->length);
2545
2546 if (len < 8) {
2547 devinfo(usbdev, "media specific indication, "
2548 "ignore too short message (%i < 8)", len);
2549 return;
2550 }
2551
2552 if (offset + len > buflen) {
2553 devinfo(usbdev, "media specific indication, "
2554 "too large to fit to buffer (%i > %i)",
2555 offset + len, buflen);
2556 return;
2557 }
2558
2559 indication = (void *)((u8 *)msg + offset);
2560
2561 switch (le32_to_cpu(indication->status_type)) {
2562 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2563 devinfo(usbdev, "radio state indication: %i",
2564 le32_to_cpu(indication->u.radio_status));
2565 return;
2566
2567 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2568 devinfo(usbdev, "media stream mode indication: %i",
2569 le32_to_cpu(indication->u.media_stream_mode));
2570 return;
2571
2572 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2573 rndis_wlan_auth_indication(usbdev, indication, len);
2574 return;
2575
2576 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2577 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2578 return;
2579
2580 default:
2581 devinfo(usbdev, "media specific indication: "
2582 "unknown status type 0x%08x",
2583 le32_to_cpu(indication->status_type));
2584 }
2585}
2586
2587
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002588static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002589{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002590 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002591 struct rndis_indicate *msg = ind;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002592
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002593 switch (msg->status) {
2594 case RNDIS_STATUS_MEDIA_CONNECT:
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +03002595 if (priv->current_command_oid == OID_802_11_ADD_KEY) {
2596 /* OID_802_11_ADD_KEY causes sometimes extra
2597 * "media connect" indications which confuses driver
2598 * and userspace to think that device is
2599 * roaming/reassociating when it isn't.
2600 */
2601 devdbg(usbdev, "ignored OID_802_11_ADD_KEY triggered "
2602 "'media connect'");
2603 return;
2604 }
2605
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002606 usbnet_pause_rx(usbdev);
2607
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002608 devinfo(usbdev, "media connect");
2609
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002610 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002611 set_bit(WORK_LINK_UP, &priv->work_pending);
2612 queue_work(priv->workqueue, &priv->work);
2613 break;
2614
2615 case RNDIS_STATUS_MEDIA_DISCONNECT:
2616 devinfo(usbdev, "media disconnect");
2617
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002618 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002619 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2620 queue_work(priv->workqueue, &priv->work);
2621 break;
2622
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002623 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2624 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2625 break;
2626
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002627 default:
2628 devinfo(usbdev, "indication: 0x%08x",
2629 le32_to_cpu(msg->status));
2630 break;
2631 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002632}
2633
2634
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002635static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002636{
2637 struct {
2638 __le32 num_items;
2639 __le32 items[8];
2640 } networks_supported;
2641 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002642 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002643
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002644 /* determine supported modes */
2645 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002646 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002647 &networks_supported, &len);
2648 if (retval >= 0) {
2649 n = le32_to_cpu(networks_supported.num_items);
2650 if (n > 8)
2651 n = 8;
2652 for (i = 0; i < n; i++) {
2653 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002654 case NDIS_80211_TYPE_FREQ_HOP:
2655 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002656 priv->caps |= CAP_MODE_80211B;
2657 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002658 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002659 priv->caps |= CAP_MODE_80211A;
2660 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002661 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002662 priv->caps |= CAP_MODE_80211G;
2663 break;
2664 }
2665 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002666 }
2667
2668 return retval;
2669}
2670
2671
2672#define STATS_UPDATE_JIFFIES (HZ)
2673static void rndis_update_wireless_stats(struct work_struct *work)
2674{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002675 struct rndis_wlan_private *priv =
2676 container_of(work, struct rndis_wlan_private, stats_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002677 struct usbnet *usbdev = priv->usbdev;
2678 struct iw_statistics iwstats;
2679 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002680 int len, ret, j;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002681 unsigned long flags;
2682 int update_jiffies = STATS_UPDATE_JIFFIES;
2683 void *buf;
2684
2685 spin_lock_irqsave(&priv->stats_lock, flags);
2686 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2687 spin_unlock_irqrestore(&priv->stats_lock, flags);
2688
2689 /* only update stats when connected */
2690 if (!is_associated(usbdev)) {
2691 iwstats.qual.qual = 0;
2692 iwstats.qual.level = 0;
2693 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2694 | IW_QUAL_LEVEL_UPDATED
2695 | IW_QUAL_NOISE_INVALID
2696 | IW_QUAL_QUAL_INVALID
2697 | IW_QUAL_LEVEL_INVALID;
2698 goto end;
2699 }
2700
2701 len = sizeof(rssi);
2702 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2703
2704 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2705 le32_to_cpu(rssi));
2706 if (ret == 0) {
2707 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2708 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinna4bd7f032009-03-26 23:40:16 +02002709 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002710 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2711 | IW_QUAL_LEVEL_UPDATED
2712 | IW_QUAL_NOISE_INVALID;
2713 }
2714
2715 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2716
2717 len = sizeof(tmp);
2718 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2719 if (ret == 0)
2720 iwstats.discard.misc += le32_to_cpu(tmp);
2721
2722 len = sizeof(tmp);
2723 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2724 if (ret == 0)
2725 iwstats.discard.misc += le32_to_cpu(tmp);
2726
2727 len = sizeof(tmp);
2728 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2729 if (ret == 0)
2730 iwstats.discard.misc += le32_to_cpu(tmp);
2731
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002732 /* Workaround transfer stalls on poor quality links.
2733 * TODO: find right way to fix these stalls (as stalls do not happen
2734 * with ndiswrapper/windows driver). */
2735 if (iwstats.qual.qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002736 /* Decrease stats worker interval to catch stalls.
2737 * faster. Faster than 400-500ms causes packet loss,
2738 * Slower doesn't catch stalls fast enough.
2739 */
2740 j = msecs_to_jiffies(priv->param_workaround_interval);
2741 if (j > STATS_UPDATE_JIFFIES)
2742 j = STATS_UPDATE_JIFFIES;
2743 else if (j <= 0)
2744 j = 1;
2745 update_jiffies = j;
2746
2747 /* Send scan OID. Use of both OIDs is required to get device
2748 * working.
2749 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08002750 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002751 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2752 sizeof(tmp));
2753
2754 len = CONTROL_BUFFER_SIZE;
2755 buf = kmalloc(len, GFP_KERNEL);
2756 if (!buf)
2757 goto end;
2758
2759 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2760 kfree(buf);
2761 }
2762end:
2763 spin_lock_irqsave(&priv->stats_lock, flags);
2764 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2765 spin_unlock_irqrestore(&priv->stats_lock, flags);
2766
2767 if (update_jiffies >= HZ)
2768 update_jiffies = round_jiffies_relative(update_jiffies);
2769 else {
2770 j = round_jiffies_relative(update_jiffies);
2771 if (abs(j - update_jiffies) <= 10)
2772 update_jiffies = j;
2773 }
2774
2775 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2776}
2777
2778
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002779static int bcm4320a_early_init(struct usbnet *usbdev)
2780{
2781 /* bcm4320a doesn't handle configuration parameters well. Try
2782 * set any and you get partially zeroed mac and broken device.
2783 */
2784
2785 return 0;
2786}
2787
2788
2789static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002790{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002791 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002792 char buf[8];
2793
2794 /* Early initialization settings, setting these won't have effect
2795 * if called after generic_rndis_bind().
2796 */
2797
2798 priv->param_country[0] = modparam_country[0];
2799 priv->param_country[1] = modparam_country[1];
2800 priv->param_country[2] = 0;
2801 priv->param_frameburst = modparam_frameburst;
2802 priv->param_afterburner = modparam_afterburner;
2803 priv->param_power_save = modparam_power_save;
2804 priv->param_power_output = modparam_power_output;
2805 priv->param_roamtrigger = modparam_roamtrigger;
2806 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002807
2808 priv->param_country[0] = toupper(priv->param_country[0]);
2809 priv->param_country[1] = toupper(priv->param_country[1]);
2810 /* doesn't support EU as country code, use FI instead */
2811 if (!strcmp(priv->param_country, "EU"))
2812 strcpy(priv->param_country, "FI");
2813
2814 if (priv->param_power_save < 0)
2815 priv->param_power_save = 0;
2816 else if (priv->param_power_save > 2)
2817 priv->param_power_save = 2;
2818
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03002819 if (priv->param_power_output < 0)
2820 priv->param_power_output = 0;
2821 else if (priv->param_power_output > 3)
2822 priv->param_power_output = 3;
2823
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002824 if (priv->param_roamtrigger < -80)
2825 priv->param_roamtrigger = -80;
2826 else if (priv->param_roamtrigger > -60)
2827 priv->param_roamtrigger = -60;
2828
2829 if (priv->param_roamdelta < 0)
2830 priv->param_roamdelta = 0;
2831 else if (priv->param_roamdelta > 2)
2832 priv->param_roamdelta = 2;
2833
Roel Kluin4d381ff2008-04-23 22:10:29 +02002834 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002835 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02002836 else
2837 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002838
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002839 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2840 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002841 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002842 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002843 priv->param_afterburner ? "1" : "0");
2844 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002845 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002846 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002847 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002848 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002849 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002850 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002851 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002852
2853 return 0;
2854}
2855
David S. Miller23d12e22009-03-25 00:03:16 -07002856/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002857static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07002858 .ndo_open = usbnet_open,
2859 .ndo_stop = usbnet_stop,
2860 .ndo_start_xmit = usbnet_start_xmit,
2861 .ndo_tx_timeout = usbnet_tx_timeout,
2862 .ndo_set_mac_address = eth_mac_addr,
2863 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002864 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07002865};
2866
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002867
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002868static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002869{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002870 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002871 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002872 int retval, len;
2873 __le32 tmp;
2874
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002875 /* allocate wiphy and rndis private data
2876 * NOTE: We only support a single virtual interface, so wiphy
2877 * and wireless_dev are somewhat synonymous for this device.
2878 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002879 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002880 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002881 return -ENOMEM;
2882
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002883 priv = wiphy_priv(wiphy);
2884 usbdev->net->ieee80211_ptr = &priv->wdev;
2885 priv->wdev.wiphy = wiphy;
2886 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2887
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002888 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002889 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002890 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002891 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002892 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2893 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002894
2895 mutex_init(&priv->command_lock);
2896 spin_lock_init(&priv->stats_lock);
2897
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002898 /* because rndis_command() sleeps we need to use workqueue */
2899 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002900 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002901 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2902 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2903
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002904 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002905 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002906 if (retval < 0)
2907 goto fail;
2908
2909 /* generic_rndis_bind set packet filter to multicast_all+
2910 * promisc mode which doesn't work well for our devices (device
2911 * picks up rssi to closest station instead of to access point).
2912 *
2913 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002914 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002915 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002916 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07002917
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002918 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002919 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002920 sizeof(tmp));
2921
2922 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002923 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2924 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002925 priv->multicast_size = le32_to_cpu(tmp);
2926 if (retval < 0 || priv->multicast_size < 0)
2927 priv->multicast_size = 0;
2928 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002929 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002930 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002931 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002932
2933 priv->iwstats.qual.qual = 0;
2934 priv->iwstats.qual.level = 0;
2935 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2936 | IW_QUAL_LEVEL_UPDATED
2937 | IW_QUAL_NOISE_INVALID
2938 | IW_QUAL_QUAL_INVALID
2939 | IW_QUAL_LEVEL_INVALID;
2940
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002941 /* fill-out wiphy structure and register w/ cfg80211 */
2942 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2943 wiphy->privid = rndis_wiphy_privid;
2944 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2945 | BIT(NL80211_IFTYPE_ADHOC);
2946 wiphy->max_scan_ssids = 1;
2947
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002948 /* TODO: fill-out band/encr information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002949 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002950
2951 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2952 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2953 priv->band.channels = priv->channels;
2954 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2955 priv->band.bitrates = priv->rates;
2956 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2957 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002958 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002959
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002960 memcpy(priv->cipher_suites, rndis_cipher_suites,
2961 sizeof(rndis_cipher_suites));
2962 wiphy->cipher_suites = priv->cipher_suites;
2963 wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
2964
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002965 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2966
2967 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002968 retval = -ENODEV;
2969 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002970 }
2971
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002972 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002973
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002974 /* set default rts/frag */
2975 rndis_set_wiphy_params(wiphy,
2976 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2977
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002978 /* turn radio on */
2979 priv->radio_on = 1;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002980 disassociate(usbdev, 1);
2981 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002982
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002983 return 0;
2984
2985fail:
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002986 cancel_delayed_work_sync(&priv->stats_work);
2987 cancel_delayed_work_sync(&priv->scan_work);
2988 cancel_work_sync(&priv->work);
2989 flush_workqueue(priv->workqueue);
2990 destroy_workqueue(priv->workqueue);
2991
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002992 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002993 return retval;
2994}
2995
2996
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002997static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002998{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002999 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003000
3001 /* turn radio off */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003002 disassociate(usbdev, 0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003003
3004 cancel_delayed_work_sync(&priv->stats_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02003005 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003006 cancel_work_sync(&priv->work);
3007 flush_workqueue(priv->workqueue);
3008 destroy_workqueue(priv->workqueue);
3009
3010 if (priv && priv->wpa_ie_len)
3011 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003012
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003013 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003014
3015 wiphy_unregister(priv->wdev.wiphy);
3016 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003017}
3018
3019
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003020static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003021{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003022 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003023 int retval;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003024
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003025 devdbg(usbdev, "rndis_wlan_reset");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003026
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003027 retval = rndis_reset(usbdev);
3028 if (retval)
3029 devwarn(usbdev, "rndis_reset() failed: %d", retval);
3030
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003031 /* rndis_reset cleared multicast list, so restore here.
3032 (set_multicast_list() also turns on current packet filter) */
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003033 set_multicast_list(usbdev);
3034
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003035 queue_delayed_work(priv->workqueue, &priv->stats_work,
3036 round_jiffies_relative(STATS_UPDATE_JIFFIES));
3037
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003038 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003039}
3040
3041
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003042static int rndis_wlan_stop(struct usbnet *usbdev)
3043{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003044 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3045 int retval;
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003046 __le32 filter;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003047
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003048 devdbg(usbdev, "rndis_wlan_stop");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003049
3050 retval = disassociate(usbdev, 0);
3051
3052 priv->work_pending = 0;
3053 cancel_delayed_work_sync(&priv->stats_work);
3054 cancel_delayed_work_sync(&priv->scan_work);
3055 cancel_work_sync(&priv->work);
3056 flush_workqueue(priv->workqueue);
3057
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03003058 if (priv->scan_request) {
3059 cfg80211_scan_done(priv->scan_request, true);
3060 priv->scan_request = NULL;
3061 }
3062
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003063 /* Set current packet filter zero to block receiving data packets from
3064 device. */
3065 filter = 0;
3066 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
3067 sizeof(filter));
3068
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003069 return retval;
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003070}
3071
3072
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003073static const struct driver_info bcm4320b_info = {
3074 .description = "Wireless RNDIS device, BCM4320b based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003075 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3076 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003077 .bind = rndis_wlan_bind,
3078 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003079 .status = rndis_status,
3080 .rx_fixup = rndis_rx_fixup,
3081 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003082 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003083 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003084 .early_init = bcm4320b_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003085 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003086};
3087
3088static const struct driver_info bcm4320a_info = {
3089 .description = "Wireless RNDIS device, BCM4320a based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003090 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3091 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003092 .bind = rndis_wlan_bind,
3093 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003094 .status = rndis_status,
3095 .rx_fixup = rndis_rx_fixup,
3096 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003097 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003098 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003099 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003100 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003101};
3102
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003103static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003104 .description = "Wireless RNDIS device",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003105 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3106 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003107 .bind = rndis_wlan_bind,
3108 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003109 .status = rndis_status,
3110 .rx_fixup = rndis_rx_fixup,
3111 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003112 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003113 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003114 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003115 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003116};
3117
3118/*-------------------------------------------------------------------------*/
3119
3120static const struct usb_device_id products [] = {
3121#define RNDIS_MASTER_INTERFACE \
3122 .bInterfaceClass = USB_CLASS_COMM, \
3123 .bInterfaceSubClass = 2 /* ACM */, \
3124 .bInterfaceProtocol = 0x0ff
3125
3126/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3127 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3128 */
3129{
3130 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3131 | USB_DEVICE_ID_MATCH_DEVICE,
3132 .idVendor = 0x0411,
3133 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
3134 RNDIS_MASTER_INTERFACE,
3135 .driver_info = (unsigned long) &bcm4320b_info,
3136}, {
3137 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3138 | USB_DEVICE_ID_MATCH_DEVICE,
3139 .idVendor = 0x0baf,
3140 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
3141 RNDIS_MASTER_INTERFACE,
3142 .driver_info = (unsigned long) &bcm4320b_info,
3143}, {
3144 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3145 | USB_DEVICE_ID_MATCH_DEVICE,
3146 .idVendor = 0x050d,
3147 .idProduct = 0x011b, /* Belkin F5D7051 */
3148 RNDIS_MASTER_INTERFACE,
3149 .driver_info = (unsigned long) &bcm4320b_info,
3150}, {
3151 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3152 | USB_DEVICE_ID_MATCH_DEVICE,
3153 .idVendor = 0x1799, /* Belkin has two vendor ids */
3154 .idProduct = 0x011b, /* Belkin F5D7051 */
3155 RNDIS_MASTER_INTERFACE,
3156 .driver_info = (unsigned long) &bcm4320b_info,
3157}, {
3158 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3159 | USB_DEVICE_ID_MATCH_DEVICE,
3160 .idVendor = 0x13b1,
3161 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
3162 RNDIS_MASTER_INTERFACE,
3163 .driver_info = (unsigned long) &bcm4320b_info,
3164}, {
3165 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3166 | USB_DEVICE_ID_MATCH_DEVICE,
3167 .idVendor = 0x13b1,
3168 .idProduct = 0x0026, /* Linksys WUSB54GSC */
3169 RNDIS_MASTER_INTERFACE,
3170 .driver_info = (unsigned long) &bcm4320b_info,
3171}, {
3172 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3173 | USB_DEVICE_ID_MATCH_DEVICE,
3174 .idVendor = 0x0b05,
3175 .idProduct = 0x1717, /* Asus WL169gE */
3176 RNDIS_MASTER_INTERFACE,
3177 .driver_info = (unsigned long) &bcm4320b_info,
3178}, {
3179 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3180 | USB_DEVICE_ID_MATCH_DEVICE,
3181 .idVendor = 0x0a5c,
3182 .idProduct = 0xd11b, /* Eminent EM4045 */
3183 RNDIS_MASTER_INTERFACE,
3184 .driver_info = (unsigned long) &bcm4320b_info,
3185}, {
3186 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3187 | USB_DEVICE_ID_MATCH_DEVICE,
3188 .idVendor = 0x1690,
3189 .idProduct = 0x0715, /* BT Voyager 1055 */
3190 RNDIS_MASTER_INTERFACE,
3191 .driver_info = (unsigned long) &bcm4320b_info,
3192},
3193/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3194 * parameters available, hardware probably contain older firmware version with
3195 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3196 */
3197{
3198 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3199 | USB_DEVICE_ID_MATCH_DEVICE,
3200 .idVendor = 0x13b1,
3201 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3202 RNDIS_MASTER_INTERFACE,
3203 .driver_info = (unsigned long) &bcm4320a_info,
3204}, {
3205 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3206 | USB_DEVICE_ID_MATCH_DEVICE,
3207 .idVendor = 0x0baf,
3208 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3209 RNDIS_MASTER_INTERFACE,
3210 .driver_info = (unsigned long) &bcm4320a_info,
3211}, {
3212 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3213 | USB_DEVICE_ID_MATCH_DEVICE,
3214 .idVendor = 0x0411,
3215 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3216 RNDIS_MASTER_INTERFACE,
3217 .driver_info = (unsigned long) &bcm4320a_info,
3218},
3219/* Generic Wireless RNDIS devices that we don't have exact
3220 * idVendor/idProduct/chip yet.
3221 */
3222{
3223 /* RNDIS is MSFT's un-official variant of CDC ACM */
3224 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003225 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003226}, {
3227 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3228 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003229 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003230},
3231 { }, // END
3232};
3233MODULE_DEVICE_TABLE(usb, products);
3234
3235static struct usb_driver rndis_wlan_driver = {
3236 .name = "rndis_wlan",
3237 .id_table = products,
3238 .probe = usbnet_probe,
3239 .disconnect = usbnet_disconnect,
3240 .suspend = usbnet_suspend,
3241 .resume = usbnet_resume,
3242};
3243
3244static int __init rndis_wlan_init(void)
3245{
3246 return usb_register(&rndis_wlan_driver);
3247}
3248module_init(rndis_wlan_init);
3249
3250static void __exit rndis_wlan_exit(void)
3251{
3252 usb_deregister(&rndis_wlan_driver);
3253}
3254module_exit(rndis_wlan_exit);
3255
3256MODULE_AUTHOR("Bjorge Dijkstra");
3257MODULE_AUTHOR("Jussi Kivilinna");
3258MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3259MODULE_LICENSE("GPL");
3260