blob: 612c2c75a9977d78725e1c0610780eeca2813c4d [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);
679 *len = (*len > ret) ? ret : *len;
680 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
681 ret = rndis_error_status(u.get_c->status);
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300682
683 if (ret < 0)
684 devdbg(dev, "rndis_query_oid(%s): device returned "
685 "error, 0x%08x (%d)", oid_to_string(oid),
686 le32_to_cpu(u.get_c->status), ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200687 }
688
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300689 mutex_unlock(&priv->command_lock);
690
691 if (u.buf != priv->command_buffer)
692 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200693 return ret;
694}
695
696
697static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
698{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300699 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200700 union {
701 void *buf;
702 struct rndis_msg_hdr *header;
703 struct rndis_set *set;
704 struct rndis_set_c *set_c;
705 } u;
706 int ret, buflen;
707
708 buflen = len + sizeof(*u.set);
709 if (buflen < CONTROL_BUFFER_SIZE)
710 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300711
712 if (buflen > COMMAND_BUFFER_SIZE) {
713 u.buf = kmalloc(buflen, GFP_KERNEL);
714 if (!u.buf)
715 return -ENOMEM;
716 } else {
717 u.buf = priv->command_buffer;
718 }
719
720 mutex_lock(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200721
722 memset(u.set, 0, sizeof *u.set);
723 u.set->msg_type = RNDIS_MSG_SET;
724 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
725 u.set->oid = oid;
726 u.set->len = cpu_to_le32(len);
Harvey Harrison35c26c22009-02-14 22:56:56 -0800727 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
728 u.set->handle = cpu_to_le32(0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200729 memcpy(u.buf + sizeof(*u.set), data, len);
730
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300731 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300732 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300733 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300734 if (ret < 0)
735 devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
736 "(%08x)", oid_to_string(oid), ret,
737 le32_to_cpu(u.set_c->status));
738
739 if (ret == 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200740 ret = rndis_error_status(u.set_c->status);
741
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300742 if (ret < 0)
743 devdbg(dev, "rndis_set_oid(%s): device returned error, "
744 "0x%08x (%d)", oid_to_string(oid),
745 le32_to_cpu(u.set_c->status), ret);
746 }
747
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300748 mutex_unlock(&priv->command_lock);
749
750 if (u.buf != priv->command_buffer)
751 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200752 return ret;
753}
754
755
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300756static int rndis_reset(struct usbnet *usbdev)
757{
758 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
759 struct rndis_reset *reset;
760 int ret;
761
762 mutex_lock(&priv->command_lock);
763
764 reset = (void *)priv->command_buffer;
765 memset(reset, 0, sizeof(*reset));
766 reset->msg_type = RNDIS_MSG_RESET;
767 reset->msg_len = cpu_to_le32(sizeof(*reset));
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300768 priv->current_command_oid = 0;
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300769 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
770
771 mutex_unlock(&priv->command_lock);
772
773 if (ret < 0)
774 return ret;
775 return 0;
776}
777
778
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200779/*
780 * Specs say that we can only set config parameters only soon after device
781 * initialization.
782 * value_type: 0 = u32, 2 = unicode string
783 */
784static int rndis_set_config_parameter(struct usbnet *dev, char *param,
785 int value_type, void *value)
786{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200787 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200788 int value_len, info_len, param_len, ret, i;
789 __le16 *unibuf;
790 __le32 *dst_value;
791
792 if (value_type == 0)
793 value_len = sizeof(__le32);
794 else if (value_type == 2)
795 value_len = strlen(value) * sizeof(__le16);
796 else
797 return -EINVAL;
798
799 param_len = strlen(param) * sizeof(__le16);
800 info_len = sizeof(*infobuf) + param_len + value_len;
801
802#ifdef DEBUG
803 info_len += 12;
804#endif
805 infobuf = kmalloc(info_len, GFP_KERNEL);
806 if (!infobuf)
807 return -ENOMEM;
808
809#ifdef DEBUG
810 info_len -= 12;
811 /* extra 12 bytes are for padding (debug output) */
812 memset(infobuf, 0xCC, info_len + 12);
813#endif
814
815 if (value_type == 2)
816 devdbg(dev, "setting config parameter: %s, value: %s",
817 param, (u8 *)value);
818 else
819 devdbg(dev, "setting config parameter: %s, value: %d",
820 param, *(u32 *)value);
821
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200822 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
823 infobuf->name_length = cpu_to_le32(param_len);
824 infobuf->type = cpu_to_le32(value_type);
825 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
826 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200827
828 /* simple string to unicode string conversion */
829 unibuf = (void *)infobuf + sizeof(*infobuf);
830 for (i = 0; i < param_len / sizeof(__le16); i++)
831 unibuf[i] = cpu_to_le16(param[i]);
832
833 if (value_type == 2) {
834 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
835 for (i = 0; i < value_len / sizeof(__le16); i++)
836 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
837 } else {
838 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
839 *dst_value = cpu_to_le32(*(u32 *)value);
840 }
841
842#ifdef DEBUG
843 devdbg(dev, "info buffer (len: %d):", info_len);
844 for (i = 0; i < info_len; i += 12) {
845 u32 *tmp = (u32 *)((u8 *)infobuf + i);
846 devdbg(dev, "%08X:%08X:%08X",
847 cpu_to_be32(tmp[0]),
848 cpu_to_be32(tmp[1]),
849 cpu_to_be32(tmp[2]));
850 }
851#endif
852
853 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
854 infobuf, info_len);
855 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200856 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200857
858 kfree(infobuf);
859 return ret;
860}
861
862static int rndis_set_config_parameter_str(struct usbnet *dev,
863 char *param, char *value)
864{
865 return(rndis_set_config_parameter(dev, param, 2, value));
866}
867
868/*static int rndis_set_config_parameter_u32(struct usbnet *dev,
869 char *param, u32 value)
870{
871 return(rndis_set_config_parameter(dev, param, 0, &value));
872}*/
873
874
875/*
876 * data conversion functions
877 */
878static int level_to_qual(int level)
879{
880 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
881 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
882}
883
884
885static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
886{
887 freq->e = 0;
888 freq->i = 0;
889 freq->flags = 0;
890
891 /* see comment in wireless.h above the "struct iw_freq"
892 * definition for an explanation of this if
893 * NOTE: 1000000 is due to the kHz
894 */
895 if (dsconfig > 1000000) {
896 freq->m = dsconfig / 10;
897 freq->e = 1;
898 } else
899 freq->m = dsconfig;
900
901 /* convert from kHz to Hz */
902 freq->e += 3;
903}
904
905
906static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
907{
908 if (freq->m < 1000 && freq->e == 0) {
David Kilroy9ee677c2008-12-23 14:03:38 +0000909 if (freq->m >= 1 && freq->m <= 14)
910 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200911 else
912 return -1;
913 } else {
914 int i;
915 *dsconfig = freq->m;
916 for (i = freq->e; i > 0; i--)
917 *dsconfig *= 10;
918 *dsconfig /= 1000;
919 }
920
921 return 0;
922}
923
924
925/*
926 * common functions
927 */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300928static void restore_keys(struct usbnet *usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200929
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200930static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200931{
932 int ret, len;
933
934 len = sizeof(*ssid);
935 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
936
937 if (ret != 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200938 ssid->length = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200939
940#ifdef DEBUG
941 {
942 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
943
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200944 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
945 tmp[le32_to_cpu(ssid->length)] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200946 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
947 }
948#endif
949 return ret;
950}
951
952
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200953static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200954{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300955 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200956 int ret;
957
958 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
959 if (ret == 0) {
960 memcpy(&priv->essid, ssid, sizeof(priv->essid));
961 priv->radio_on = 1;
962 devdbg(usbdev, "set_essid: radio_on = 1");
963 }
964
965 return ret;
966}
967
968
969static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
970{
971 int ret, len;
972
973 len = ETH_ALEN;
974 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
975
976 if (ret != 0)
977 memset(bssid, 0, ETH_ALEN);
978
979 return ret;
980}
981
Scott Ashcroft43646232008-05-27 00:06:15 +0300982static int get_association_info(struct usbnet *usbdev,
983 struct ndis_80211_assoc_info *info, int len)
984{
985 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
986 info, &len);
987}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200988
989static int is_associated(struct usbnet *usbdev)
990{
991 u8 bssid[ETH_ALEN];
992 int ret;
993
994 ret = get_bssid(usbdev, bssid);
995
996 return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0);
997}
998
999
1000static int disassociate(struct usbnet *usbdev, int reset_ssid)
1001{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001002 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001003 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001004 int i, ret = 0;
1005
1006 if (priv->radio_on) {
1007 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
1008 if (ret == 0) {
1009 priv->radio_on = 0;
1010 devdbg(usbdev, "disassociate: radio_on = 0");
1011
1012 if (reset_ssid)
1013 msleep(100);
1014 }
1015 }
1016
1017 /* disassociate causes radio to be turned off; if reset_ssid
1018 * is given, set random ssid to enable radio */
1019 if (reset_ssid) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001020 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1021 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1022 ssid.essid[0] = 0x1;
1023 ssid.essid[1] = 0xff;
1024 for (i = 2; i < sizeof(ssid.essid); i++)
1025 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001026 ret = set_essid(usbdev, &ssid);
1027 }
1028 return ret;
1029}
1030
1031
1032static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
1033{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001034 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001035 __le32 tmp;
1036 int auth_mode, ret;
1037
1038 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
1039 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
1040
1041 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
1042 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001043 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001044 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001045 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001046 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
1047 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001048 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001049 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001050 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001051 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001052 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001053 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
1054 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001055 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001056 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001057 auth_mode = NDIS_80211_AUTH_SHARED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001058 } else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001059 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001060
1061 tmp = cpu_to_le32(auth_mode);
1062 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1063 sizeof(tmp));
1064 if (ret != 0) {
1065 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
1066 return ret;
1067 }
1068
1069 priv->wpa_version = wpa_version;
1070 priv->wpa_authalg = authalg;
1071 return 0;
1072}
1073
1074
1075static int set_priv_filter(struct usbnet *usbdev)
1076{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001077 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001078 __le32 tmp;
1079
1080 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
1081
1082 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
1083 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001084 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001085 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001086 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001087
1088 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1089 sizeof(tmp));
1090}
1091
1092
1093static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1094{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001095 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001096 __le32 tmp;
1097 int encr_mode, ret;
1098
1099 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
1100 pairwise,
1101 groupwise);
1102
1103 if (pairwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001104 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001105 else if (pairwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001106 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001107 else if (pairwise &
1108 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001109 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001110 else if (groupwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001111 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001112 else if (groupwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001113 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001114 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001115 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001116
1117 tmp = cpu_to_le32(encr_mode);
1118 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1119 sizeof(tmp));
1120 if (ret != 0) {
1121 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
1122 return ret;
1123 }
1124
1125 priv->wpa_cipher_pair = pairwise;
1126 priv->wpa_cipher_group = groupwise;
1127 return 0;
1128}
1129
1130
1131static int set_assoc_params(struct usbnet *usbdev)
1132{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001133 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001134
1135 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
1136 set_priv_filter(usbdev);
1137 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
1138
1139 return 0;
1140}
1141
1142
1143static int set_infra_mode(struct usbnet *usbdev, int mode)
1144{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001145 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001146 __le32 tmp;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001147 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001148
1149 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
1150
1151 tmp = cpu_to_le32(mode);
1152 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1153 sizeof(tmp));
1154 if (ret != 0) {
1155 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
1156 return ret;
1157 }
1158
1159 /* NDIS drivers clear keys when infrastructure mode is
1160 * changed. But Linux tools assume otherwise. So set the
1161 * keys */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001162 restore_keys(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001163
1164 priv->infra_mode = mode;
1165 return 0;
1166}
1167
1168
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001169static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1170{
1171 __le32 tmp;
1172
1173 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1174
1175 if (rts_threshold < 0 || rts_threshold > 2347)
1176 rts_threshold = 2347;
1177
1178 tmp = cpu_to_le32(rts_threshold);
1179 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1180 sizeof(tmp));
1181}
1182
1183
1184static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1185{
1186 __le32 tmp;
1187
1188 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1189
1190 if (frag_threshold < 256 || frag_threshold > 2346)
1191 frag_threshold = 2346;
1192
1193 tmp = cpu_to_le32(frag_threshold);
1194 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1195 sizeof(tmp));
1196}
1197
1198
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001199static void set_default_iw_params(struct usbnet *usbdev)
1200{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001201 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001202
1203 priv->wpa_keymgmt = 0;
1204 priv->wpa_version = 0;
1205
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001206 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001207 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1208 IW_AUTH_ALG_OPEN_SYSTEM);
1209 set_priv_filter(usbdev);
1210 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1211}
1212
1213
1214static int deauthenticate(struct usbnet *usbdev)
1215{
1216 int ret;
1217
1218 ret = disassociate(usbdev, 1);
1219 set_default_iw_params(usbdev);
1220 return ret;
1221}
1222
1223
1224/* index must be 0 - N, as per NDIS */
1225static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
1226{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001227 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001228 struct ndis_80211_wep_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001229 int cipher, ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001230
Jussi Kivilinna40ba60d2009-08-20 21:00:34 +03001231 if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001232 return -EINVAL;
1233
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001234 if (key_len == 5)
1235 cipher = WLAN_CIPHER_SUITE_WEP40;
1236 else
1237 cipher = WLAN_CIPHER_SUITE_WEP104;
1238
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001239 memset(&ndis_key, 0, sizeof(ndis_key));
1240
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001241 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1242 ndis_key.length = cpu_to_le32(key_len);
1243 ndis_key.index = cpu_to_le32(index);
1244 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001245
1246 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001247 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001248 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1249 IW_AUTH_CIPHER_NONE);
1250 if (ret)
1251 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1252 ret);
1253 }
1254
1255 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1256 sizeof(ndis_key));
1257 if (ret != 0) {
1258 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1259 index+1, ret);
1260 return ret;
1261 }
1262
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001263 priv->encr_keys[index].len = key_len;
1264 priv->encr_keys[index].cipher = cipher;
1265 memcpy(&priv->encr_keys[index].material, key, key_len);
1266 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001267
1268 return 0;
1269}
1270
1271
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001272static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001273 int index, const u8 *addr, const u8 *rx_seq, int cipher,
1274 int flags)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001275{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001276 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001277 struct ndis_80211_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001278 bool is_addr_ok;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001279 int ret;
1280
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001281 if (index < 0 || index >= 4) {
1282 devdbg(usbdev, "add_wpa_key: index out of range (%i)", index);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001283 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001284 }
1285 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1286 devdbg(usbdev, "add_wpa_key: key length out of range (%i)",
1287 key_len);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001288 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001289 }
1290 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq) {
1291 devdbg(usbdev, "add_wpa_key: recv seq flag without buffer");
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001292 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001293 }
1294 is_addr_ok = addr && memcmp(addr, zero_bssid, ETH_ALEN) != 0 &&
1295 memcmp(addr, ffff_bssid, ETH_ALEN) != 0;
1296 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1297 devdbg(usbdev, "add_wpa_key: pairwise but bssid invalid (%pM)",
1298 addr);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001299 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001300 }
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001301
1302 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001303 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1304 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1305 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001306
1307 memset(&ndis_key, 0, sizeof(ndis_key));
1308
1309 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1310 sizeof(ndis_key.material) + key_len);
1311 ndis_key.length = cpu_to_le32(key_len);
1312 ndis_key.index = cpu_to_le32(index) | flags;
1313
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001314 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001315 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1316 * different order than NDIS spec, so swap the order here. */
1317 memcpy(ndis_key.material, key, 16);
1318 memcpy(ndis_key.material + 16, key + 24, 8);
1319 memcpy(ndis_key.material + 24, key + 16, 8);
1320 } else
1321 memcpy(ndis_key.material, key, key_len);
1322
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001323 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001324 memcpy(ndis_key.rsc, rx_seq, 6);
1325
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001326 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001327 /* pairwise key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001328 memcpy(ndis_key.bssid, addr, ETH_ALEN);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001329 } else {
1330 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001331 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001332 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1333 else
1334 get_bssid(usbdev, ndis_key.bssid);
1335 }
1336
1337 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1338 le32_to_cpu(ndis_key.size));
1339 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1340 if (ret != 0)
1341 return ret;
1342
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001343 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1344 priv->encr_keys[index].len = key_len;
1345 priv->encr_keys[index].cipher = cipher;
1346 memcpy(&priv->encr_keys[index].material, key, key_len);
1347 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1348 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1349 else
1350 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinna98391782009-05-22 17:40:34 +03001351
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001352 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001353 priv->encr_tx_key_index = index;
1354
1355 return 0;
1356}
1357
1358
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001359static int restore_key(struct usbnet *usbdev, int key_idx)
1360{
1361 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1362 struct rndis_wlan_encr_key key;
1363 int flags;
1364
1365 key = priv->encr_keys[key_idx];
1366
1367 devdbg(usbdev, "restore_key: %i:%s:%i", key_idx,
1368 is_wpa_key(priv, key_idx) ? "wpa" : "wep",
1369 key.len);
1370
1371 if (key.len == 0)
1372 return 0;
1373
1374 if (is_wpa_key(priv, key_idx)) {
1375 flags = 0;
1376
1377 /*if (priv->encr_tx_key_index == key_idx)
1378 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;*/
1379
1380 if (memcmp(key.bssid, zero_bssid, ETH_ALEN) != 0 &&
1381 memcmp(key.bssid, ffff_bssid, ETH_ALEN) != 0)
1382 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
1383
1384 return add_wpa_key(usbdev, key.material, key.len, key_idx,
1385 key.bssid, NULL, key.cipher, flags);
1386 }
1387
1388 return add_wep_key(usbdev, key.material, key.len, key_idx);
1389}
1390
1391
1392static void restore_keys(struct usbnet *usbdev)
1393{
1394 int i;
1395
1396 for (i = 0; i < 4; i++)
1397 restore_key(usbdev, i);
1398}
1399
1400
1401static void clear_key(struct rndis_wlan_private *priv, int idx)
1402{
1403 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1404}
1405
1406
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001407/* remove_key is for both wep and wpa */
1408static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1409{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001410 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001411 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001412 __le32 keyindex;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001413 bool is_wpa;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001414 int ret;
1415
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001416 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001417 return 0;
1418
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001419 is_wpa = is_wpa_key(priv, index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001420
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001421 devdbg(usbdev, "remove_key: %i:%s:%i", index, is_wpa ? "wpa" : "wep",
1422 priv->encr_keys[index].len);
1423
1424 clear_key(priv, index);
1425
1426 if (is_wpa) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001427 remove_key.size = cpu_to_le32(sizeof(remove_key));
1428 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001429 if (bssid) {
1430 /* pairwise key */
1431 if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001432 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001433 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001434 memcpy(remove_key.bssid, bssid,
1435 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001436 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001437 memset(remove_key.bssid, 0xff,
1438 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001439
1440 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1441 sizeof(remove_key));
1442 if (ret != 0)
1443 return ret;
1444 } else {
1445 keyindex = cpu_to_le32(index);
1446 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1447 sizeof(keyindex));
1448 if (ret != 0) {
1449 devwarn(usbdev,
1450 "removing encryption key %d failed (%08X)",
1451 index, ret);
1452 return ret;
1453 }
1454 }
1455
1456 /* if it is transmit key, disable encryption */
1457 if (index == priv->encr_tx_key_index)
1458 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1459
1460 return 0;
1461}
1462
1463
1464static void set_multicast_list(struct usbnet *usbdev)
1465{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001466 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001467 struct dev_mc_list *mclist;
1468 __le32 filter;
1469 int ret, i, size;
1470 char *buf;
1471
1472 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1473
1474 if (usbdev->net->flags & IFF_PROMISC) {
1475 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1476 RNDIS_PACKET_TYPE_ALL_LOCAL;
1477 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1478 usbdev->net->mc_count > priv->multicast_size) {
1479 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1480 } else if (usbdev->net->mc_count > 0) {
1481 size = min(priv->multicast_size, usbdev->net->mc_count);
1482 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1483 if (!buf) {
1484 devwarn(usbdev,
1485 "couldn't alloc %d bytes of memory",
1486 size * ETH_ALEN);
1487 return;
1488 }
1489
1490 mclist = usbdev->net->mc_list;
1491 for (i = 0; i < size && mclist; mclist = mclist->next) {
1492 if (mclist->dmi_addrlen != ETH_ALEN)
1493 continue;
1494
1495 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1496 i++;
1497 }
1498
1499 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1500 i * ETH_ALEN);
1501 if (ret == 0 && i > 0)
1502 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1503 else
1504 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1505
1506 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1507 i, priv->multicast_size, ret);
1508
1509 kfree(buf);
1510 }
1511
1512 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1513 sizeof(filter));
1514 if (ret < 0) {
1515 devwarn(usbdev, "couldn't set packet filter: %08x",
1516 le32_to_cpu(filter));
1517 }
1518
1519 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1520 le32_to_cpu(filter), ret);
1521}
1522
1523
1524/*
John W. Linville964c1d42009-03-26 23:40:01 +02001525 * cfg80211 ops
1526 */
Johannes Berge36d56b2009-06-09 21:04:43 +02001527static int rndis_change_virtual_intf(struct wiphy *wiphy,
1528 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +02001529 enum nl80211_iftype type, u32 *flags,
1530 struct vif_params *params)
1531{
Johannes Berge36d56b2009-06-09 21:04:43 +02001532 struct usbnet *usbdev = netdev_priv(dev);
John W. Linville964c1d42009-03-26 23:40:01 +02001533 int mode;
1534
John W. Linville964c1d42009-03-26 23:40:01 +02001535 switch (type) {
1536 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001537 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001538 break;
1539 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001540 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001541 break;
1542 default:
1543 return -EINVAL;
1544 }
1545
1546 return set_infra_mode(usbdev, mode);
1547}
1548
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001549
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001550static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1551{
1552 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1553 struct usbnet *usbdev = priv->usbdev;
1554 int err;
1555
1556 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1557 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1558 if (err < 0)
1559 return err;
1560 }
1561
1562 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1563 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1564 if (err < 0)
1565 return err;
1566 }
1567
1568 return 0;
1569}
1570
1571
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001572static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1573 int dbm)
1574{
1575 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1576 struct usbnet *usbdev = priv->usbdev;
1577
1578 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1579
1580 /* Device doesn't support changing txpower after initialization, only
1581 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1582 * currently used.
1583 */
1584 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1585 if (!priv->radio_on)
1586 disassociate(usbdev, 1); /* turn on radio */
1587
1588 return 0;
1589 }
1590
1591 return -ENOTSUPP;
1592}
1593
1594
1595static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1596{
1597 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1598 struct usbnet *usbdev = priv->usbdev;
1599
1600 *dbm = get_bcm4320_power_dbm(priv);
1601
1602 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1603
1604 return 0;
1605}
1606
1607
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001608#define SCAN_DELAY_JIFFIES (HZ)
1609static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1610 struct cfg80211_scan_request *request)
1611{
1612 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001613 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001614 int ret;
1615 __le32 tmp;
1616
1617 devdbg(usbdev, "cfg80211.scan");
1618
1619 if (!request)
1620 return -EINVAL;
1621
1622 if (priv->scan_request && priv->scan_request != request)
1623 return -EBUSY;
1624
1625 priv->scan_request = request;
1626
1627 tmp = cpu_to_le32(1);
1628 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1629 sizeof(tmp));
1630 if (ret == 0) {
1631 /* Wait before retrieving scan results from device */
1632 queue_delayed_work(priv->workqueue, &priv->scan_work,
1633 SCAN_DELAY_JIFFIES);
1634 }
1635
1636 return ret;
1637}
1638
1639
1640static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1641 struct ndis_80211_bssid_ex *bssid)
1642{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001643 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001644 struct ieee80211_channel *channel;
1645 s32 signal;
1646 u64 timestamp;
1647 u16 capability;
1648 u16 beacon_interval;
1649 struct ndis_80211_fixed_ies *fixed;
1650 int ie_len, bssid_len;
1651 u8 *ie;
1652
1653 /* parse bssid structure */
1654 bssid_len = le32_to_cpu(bssid->length);
1655
1656 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1657 sizeof(struct ndis_80211_fixed_ies))
1658 return NULL;
1659
1660 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1661
1662 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1663 ie_len = min(bssid_len - (int)sizeof(*bssid),
1664 (int)le32_to_cpu(bssid->ie_length));
1665 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1666 if (ie_len < 0)
1667 return NULL;
1668
1669 /* extract data for cfg80211_inform_bss */
1670 channel = ieee80211_get_channel(priv->wdev.wiphy,
1671 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1672 if (!channel)
1673 return NULL;
1674
1675 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1676 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1677 capability = le16_to_cpu(fixed->capabilities);
1678 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1679
1680 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1681 timestamp, capability, beacon_interval, ie, ie_len, signal,
1682 GFP_KERNEL);
1683}
1684
1685
1686static int rndis_check_bssid_list(struct usbnet *usbdev)
1687{
1688 void *buf = NULL;
1689 struct ndis_80211_bssid_list_ex *bssid_list;
1690 struct ndis_80211_bssid_ex *bssid;
1691 int ret = -EINVAL, len, count, bssid_len;
1692
1693 devdbg(usbdev, "check_bssid_list");
1694
1695 len = CONTROL_BUFFER_SIZE;
1696 buf = kmalloc(len, GFP_KERNEL);
1697 if (!buf) {
1698 ret = -ENOMEM;
1699 goto out;
1700 }
1701
1702 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1703 if (ret != 0)
1704 goto out;
1705
1706 bssid_list = buf;
1707 bssid = bssid_list->bssid;
1708 bssid_len = le32_to_cpu(bssid->length);
1709 count = le32_to_cpu(bssid_list->num_items);
1710 devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count);
1711
1712 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1713 rndis_bss_info_update(usbdev, bssid);
1714
1715 bssid = (void *)bssid + bssid_len;
1716 bssid_len = le32_to_cpu(bssid->length);
1717 count--;
1718 }
1719
1720out:
1721 kfree(buf);
1722 return ret;
1723}
1724
1725
1726static void rndis_get_scan_results(struct work_struct *work)
1727{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001728 struct rndis_wlan_private *priv =
1729 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001730 struct usbnet *usbdev = priv->usbdev;
1731 int ret;
1732
1733 devdbg(usbdev, "get_scan_results");
1734
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03001735 if (!priv->scan_request)
1736 return;
1737
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001738 ret = rndis_check_bssid_list(usbdev);
1739
1740 cfg80211_scan_done(priv->scan_request, ret < 0);
1741
1742 priv->scan_request = NULL;
1743}
1744
1745
John W. Linville964c1d42009-03-26 23:40:01 +02001746/*
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001747 * wireless extension handlers
1748 */
1749
1750static int rndis_iw_commit(struct net_device *dev,
1751 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1752{
1753 /* dummy op */
1754 return 0;
1755}
1756
1757
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001758static int rndis_iw_set_essid(struct net_device *dev,
1759 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1760{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001761 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001762 int length = wrqu->essid.length;
Wang Chen524ad0a2008-11-12 23:39:10 -08001763 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001764
1765 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1766 wrqu->essid.flags, wrqu->essid.length, essid);
1767
1768 if (length > NDIS_802_11_LENGTH_SSID)
1769 length = NDIS_802_11_LENGTH_SSID;
1770
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001771 ssid.length = cpu_to_le32(length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001772 if (length > 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001773 memcpy(ssid.essid, essid, length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001774 else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001775 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001776
1777 set_assoc_params(usbdev);
1778
1779 if (!wrqu->essid.flags || length == 0)
1780 return disassociate(usbdev, 1);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001781 else {
1782 /* Pause and purge rx queue, so we don't pass packets before
1783 * 'media connect'-indication.
1784 */
1785 usbnet_pause_rx(usbdev);
1786 usbnet_purge_paused_rxq(usbdev);
1787
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001788 return set_essid(usbdev, &ssid);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001789 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001790}
1791
1792
1793static int rndis_iw_get_essid(struct net_device *dev,
1794 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1795{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001796 struct ndis_80211_ssid ssid;
Wang Chen524ad0a2008-11-12 23:39:10 -08001797 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001798 int ret;
1799
1800 ret = get_essid(usbdev, &ssid);
1801
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001802 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001803 wrqu->essid.flags = 1;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001804 wrqu->essid.length = le32_to_cpu(ssid.length);
1805 memcpy(essid, ssid.essid, wrqu->essid.length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001806 essid[wrqu->essid.length] = 0;
1807 } else {
1808 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1809 wrqu->essid.flags = 0;
1810 wrqu->essid.length = 0;
1811 }
1812 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1813 return ret;
1814}
1815
1816
1817static int rndis_iw_get_bssid(struct net_device *dev,
1818 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1819{
Wang Chen524ad0a2008-11-12 23:39:10 -08001820 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001821 unsigned char bssid[ETH_ALEN];
1822 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001823
1824 ret = get_bssid(usbdev, bssid);
1825
1826 if (ret == 0)
Johannes Berge1749612008-10-27 15:59:26 -07001827 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001828 else
1829 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1830
1831 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1832 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1833
1834 return ret;
1835}
1836
1837
1838static int rndis_iw_set_bssid(struct net_device *dev,
1839 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1840{
Wang Chen524ad0a2008-11-12 23:39:10 -08001841 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001842 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001843 int ret;
1844
Johannes Berge1749612008-10-27 15:59:26 -07001845 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001846
1847 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1848
1849 /* user apps may set ap's mac address, which is not required;
1850 * they may fail to work if this function fails, so return
1851 * success */
1852 if (ret)
1853 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1854
1855 return 0;
1856}
1857
1858
1859static int rndis_iw_set_auth(struct net_device *dev,
1860 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1861{
1862 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001863 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001864 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001865 int ret = -ENOTSUPP;
1866
1867 switch (p->flags & IW_AUTH_INDEX) {
1868 case IW_AUTH_WPA_VERSION:
1869 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1870 priv->wpa_version = p->value;
1871 ret = 0;
1872 break;
1873
1874 case IW_AUTH_CIPHER_PAIRWISE:
1875 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1876 priv->wpa_cipher_pair = p->value;
1877 ret = 0;
1878 break;
1879
1880 case IW_AUTH_CIPHER_GROUP:
1881 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1882 priv->wpa_cipher_group = p->value;
1883 ret = 0;
1884 break;
1885
1886 case IW_AUTH_KEY_MGMT:
1887 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1888 priv->wpa_keymgmt = p->value;
1889 ret = 0;
1890 break;
1891
1892 case IW_AUTH_TKIP_COUNTERMEASURES:
1893 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1894 p->value);
1895 ret = 0;
1896 break;
1897
1898 case IW_AUTH_DROP_UNENCRYPTED:
1899 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1900 ret = 0;
1901 break;
1902
1903 case IW_AUTH_80211_AUTH_ALG:
1904 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1905 priv->wpa_authalg = p->value;
1906 ret = 0;
1907 break;
1908
1909 case IW_AUTH_WPA_ENABLED:
1910 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1911 if (wrqu->param.value)
1912 deauthenticate(usbdev);
1913 ret = 0;
1914 break;
1915
1916 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1917 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1918 p->value);
1919 ret = 0;
1920 break;
1921
1922 case IW_AUTH_ROAMING_CONTROL:
1923 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1924 ret = 0;
1925 break;
1926
1927 case IW_AUTH_PRIVACY_INVOKED:
1928 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1929 wrqu->param.flags & IW_AUTH_INDEX);
1930 return -EOPNOTSUPP;
1931
1932 default:
1933 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1934 p->flags & IW_AUTH_INDEX, p->value);
1935 }
1936 return ret;
1937}
1938
1939
1940static int rndis_iw_get_auth(struct net_device *dev,
1941 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1942{
1943 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001944 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001945 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001946
1947 switch (p->flags & IW_AUTH_INDEX) {
1948 case IW_AUTH_WPA_VERSION:
1949 p->value = priv->wpa_version;
1950 break;
1951 case IW_AUTH_CIPHER_PAIRWISE:
1952 p->value = priv->wpa_cipher_pair;
1953 break;
1954 case IW_AUTH_CIPHER_GROUP:
1955 p->value = priv->wpa_cipher_group;
1956 break;
1957 case IW_AUTH_KEY_MGMT:
1958 p->value = priv->wpa_keymgmt;
1959 break;
1960 case IW_AUTH_80211_AUTH_ALG:
1961 p->value = priv->wpa_authalg;
1962 break;
1963 default:
1964 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1965 wrqu->param.flags & IW_AUTH_INDEX);
1966 return -EOPNOTSUPP;
1967 }
1968 return 0;
1969}
1970
1971
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001972static int rndis_iw_set_encode(struct net_device *dev,
1973 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1974{
Wang Chen524ad0a2008-11-12 23:39:10 -08001975 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001976 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001977 struct rndis_wlan_encr_key key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001978 int ret, index, key_len;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001979 u8 *keybuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001980
1981 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
1982
1983 /* iwconfig gives index as 1 - N */
1984 if (index > 0)
1985 index--;
1986 else
1987 index = priv->encr_tx_key_index;
1988
1989 if (index < 0 || index >= 4) {
1990 devwarn(usbdev, "encryption index out of range (%u)", index);
1991 return -EINVAL;
1992 }
1993
1994 /* remove key if disabled */
1995 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
1996 if (remove_key(usbdev, index, NULL))
1997 return -EINVAL;
1998 else
1999 return 0;
2000 }
2001
2002 /* global encryption state (for all keys) */
2003 if (wrqu->data.flags & IW_ENCODE_OPEN)
2004 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
2005 IW_AUTH_ALG_OPEN_SYSTEM);
2006 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
2007 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
2008 IW_AUTH_ALG_SHARED_KEY);
2009 if (ret != 0)
2010 return ret;
2011
2012 if (wrqu->data.length > 0) {
2013 key_len = wrqu->data.length;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002014 keybuf = extra;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002015 } else {
2016 /* must be set as tx key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002017 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002018 return -EINVAL;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002019 key = priv->encr_keys[index];
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002020 key_len = key.len;
2021 keybuf = key.material;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002022 priv->encr_tx_key_index = index;
2023 }
2024
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002025 if (add_wep_key(usbdev, keybuf, key_len, index) != 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002026 return -EINVAL;
2027
2028 if (index == priv->encr_tx_key_index)
2029 /* ndis drivers want essid to be set after setting encr */
2030 set_essid(usbdev, &priv->essid);
2031
2032 return 0;
2033}
2034
2035
2036static int rndis_iw_set_encode_ext(struct net_device *dev,
2037 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2038{
2039 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
Wang Chen524ad0a2008-11-12 23:39:10 -08002040 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002041 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002042 int keyidx, flags, cipher;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002043
2044 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
2045
2046 /* iwconfig gives index as 1 - N */
2047 if (keyidx)
2048 keyidx--;
2049 else
2050 keyidx = priv->encr_tx_key_index;
2051
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002052 if (keyidx < 0 || keyidx >= 4) {
2053 devwarn(usbdev, "encryption index out of range (%u)", keyidx);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002054 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002055 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002056
2057 if (ext->alg == WPA_ALG_WEP) {
2058 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2059 priv->encr_tx_key_index = keyidx;
2060 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
2061 }
2062
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002063 cipher = -1;
2064 if (ext->alg == IW_ENCODE_ALG_TKIP)
2065 cipher = WLAN_CIPHER_SUITE_TKIP;
2066 else if (ext->alg == IW_ENCODE_ALG_CCMP)
2067 cipher = WLAN_CIPHER_SUITE_CCMP;
2068
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002069 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
2070 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
2071 return remove_key(usbdev, keyidx, NULL);
2072
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002073 if (cipher == -1)
2074 return -EOPNOTSUPP;
2075
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002076 flags = 0;
2077 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002078 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002079 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002080 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002081 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002082 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002083
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002084 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx,
2085 (u8 *)&ext->addr.sa_data, ext->rx_seq, cipher,
2086 flags);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002087}
2088
2089
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002090static int rndis_iw_set_genie(struct net_device *dev,
2091 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2092{
Wang Chen524ad0a2008-11-12 23:39:10 -08002093 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002094 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002095 int ret = 0;
2096
2097#ifdef DEBUG
2098 int j;
2099 u8 *gie = extra;
2100 for (j = 0; j < wrqu->data.length; j += 8)
2101 devdbg(usbdev,
2102 "SIOCSIWGENIE %04x - "
2103 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
2104 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
2105 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
2106#endif
2107 /* clear existing IEs */
2108 if (priv->wpa_ie_len) {
2109 kfree(priv->wpa_ie);
2110 priv->wpa_ie_len = 0;
2111 }
2112
2113 /* set new IEs */
2114 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
2115 if (priv->wpa_ie) {
2116 priv->wpa_ie_len = wrqu->data.length;
2117 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
2118 } else
2119 ret = -ENOMEM;
2120 return ret;
2121}
2122
2123
2124static int rndis_iw_get_genie(struct net_device *dev,
2125 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2126{
Wang Chen524ad0a2008-11-12 23:39:10 -08002127 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002128 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002129
2130 devdbg(usbdev, "SIOCGIWGENIE");
2131
2132 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
2133 wrqu->data.length = 0;
2134 return 0;
2135 }
2136
2137 if (wrqu->data.length < priv->wpa_ie_len)
2138 return -E2BIG;
2139
2140 wrqu->data.length = priv->wpa_ie_len;
2141 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
2142
2143 return 0;
2144}
2145
2146
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002147static int rndis_iw_set_freq(struct net_device *dev,
2148 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2149{
Wang Chen524ad0a2008-11-12 23:39:10 -08002150 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002151 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002152 unsigned int dsconfig;
2153 int len, ret;
2154
2155 /* this OID is valid only when not associated */
2156 if (is_associated(usbdev))
2157 return 0;
2158
2159 dsconfig = 0;
2160 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
2161 return -EINVAL;
2162
2163 len = sizeof(config);
2164 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2165 if (ret != 0) {
2166 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
2167 return 0;
2168 }
2169
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002170 config.ds_config = cpu_to_le32(dsconfig);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002171
2172 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
2173 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
2174 sizeof(config));
2175}
2176
2177
2178static int rndis_iw_get_freq(struct net_device *dev,
2179 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2180{
Wang Chen524ad0a2008-11-12 23:39:10 -08002181 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002182 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002183 int len, ret;
2184
2185 len = sizeof(config);
2186 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2187 if (ret == 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002188 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002189
2190 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
2191 return ret;
2192}
2193
2194
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002195static int rndis_iw_get_rate(struct net_device *dev,
2196 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2197{
Wang Chen524ad0a2008-11-12 23:39:10 -08002198 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002199 __le32 tmp;
2200 int ret, len;
2201
2202 len = sizeof(tmp);
2203 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
2204 if (ret == 0) {
2205 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
2206 wrqu->bitrate.disabled = 0;
2207 wrqu->bitrate.flags = 1;
2208 }
2209 return ret;
2210}
2211
2212
2213static int rndis_iw_set_mlme(struct net_device *dev,
2214 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2215{
Wang Chen524ad0a2008-11-12 23:39:10 -08002216 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002217 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002218 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2219 unsigned char bssid[ETH_ALEN];
2220
2221 get_bssid(usbdev, bssid);
2222
2223 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
2224 return -EINVAL;
2225
2226 switch (mlme->cmd) {
2227 case IW_MLME_DEAUTH:
2228 return deauthenticate(usbdev);
2229 case IW_MLME_DISASSOC:
2230 return disassociate(usbdev, priv->radio_on);
2231 default:
2232 return -EOPNOTSUPP;
2233 }
2234
2235 return 0;
2236}
2237
2238
2239static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
2240{
Wang Chen524ad0a2008-11-12 23:39:10 -08002241 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002242 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002243 unsigned long flags;
2244
2245 spin_lock_irqsave(&priv->stats_lock, flags);
2246 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2247 spin_unlock_irqrestore(&priv->stats_lock, flags);
2248
2249 return &priv->iwstats;
2250}
2251
2252
2253#define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2254static const iw_handler rndis_iw_handler[] =
2255{
2256 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002257 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002258 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2259 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
John W. Linville964c1d42009-03-26 23:40:01 +02002260 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2261 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002262 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002263 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2264 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002265 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2266 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002267 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2268 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002269 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002270 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2271 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2272 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2273 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002274 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2275 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002276 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2277 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2278 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2279 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2280 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2281 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2282 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2283};
2284
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002285static const iw_handler rndis_wlan_private_handler[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002286};
2287
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002288static const struct iw_priv_args rndis_wlan_private_args[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002289};
2290
2291
2292static const struct iw_handler_def rndis_iw_handlers = {
2293 .num_standard = ARRAY_SIZE(rndis_iw_handler),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002294 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2295 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002296 .standard = (iw_handler *)rndis_iw_handler,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002297 .private = (iw_handler *)rndis_wlan_private_handler,
2298 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002299 .get_wireless_stats = rndis_get_wireless_stats,
2300};
2301
2302
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002303static void rndis_wlan_worker(struct work_struct *work)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002304{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002305 struct rndis_wlan_private *priv =
2306 container_of(work, struct rndis_wlan_private, work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002307 struct usbnet *usbdev = priv->usbdev;
2308 union iwreq_data evt;
2309 unsigned char bssid[ETH_ALEN];
Scott Ashcroft43646232008-05-27 00:06:15 +03002310 struct ndis_80211_assoc_info *info;
2311 int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32;
2312 int ret, offset;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002313
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002314 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002315 netif_carrier_on(usbdev->net);
2316
Scott Ashcroft43646232008-05-27 00:06:15 +03002317 info = kzalloc(assoc_size, GFP_KERNEL);
2318 if (!info)
2319 goto get_bssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002320
Scott Ashcroft43646232008-05-27 00:06:15 +03002321 /* Get association info IEs from device and send them back to
2322 * userspace. */
2323 ret = get_association_info(usbdev, info, assoc_size);
2324 if (!ret) {
2325 evt.data.length = le32_to_cpu(info->req_ie_length);
2326 if (evt.data.length > 0) {
2327 offset = le32_to_cpu(info->offset_req_ies);
2328 wireless_send_event(usbdev->net,
2329 IWEVASSOCREQIE, &evt,
2330 (char *)info + offset);
2331 }
2332
2333 evt.data.length = le32_to_cpu(info->resp_ie_length);
2334 if (evt.data.length > 0) {
2335 offset = le32_to_cpu(info->offset_resp_ies);
2336 wireless_send_event(usbdev->net,
2337 IWEVASSOCRESPIE, &evt,
2338 (char *)info + offset);
2339 }
2340 }
2341
2342 kfree(info);
2343
2344get_bssid:
2345 ret = get_bssid(usbdev, bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002346 if (!ret) {
2347 evt.data.flags = 0;
2348 evt.data.length = 0;
2349 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
2350 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2351 }
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002352
2353 usbnet_resume_rx(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002354 }
2355
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002356 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002357 netif_carrier_off(usbdev->net);
2358
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002359 evt.data.flags = 0;
2360 evt.data.length = 0;
2361 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2362 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2363 }
2364
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002365 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2366 set_multicast_list(usbdev);
2367}
2368
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002369static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002370{
Wang Chen524ad0a2008-11-12 23:39:10 -08002371 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002372 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002373
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002374 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2375 return;
2376
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002377 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2378 queue_work(priv->workqueue, &priv->work);
2379}
2380
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002381
2382static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2383 struct ndis_80211_status_indication *indication,
2384 int len)
2385{
2386 u8 *buf;
2387 const char *type;
2388 int flags, buflen;
2389 bool pairwise_error, group_error;
2390 struct ndis_80211_auth_request *auth_req;
2391
2392 /* must have at least one array entry */
2393 if (len < offsetof(struct ndis_80211_status_indication, u) +
2394 sizeof(struct ndis_80211_auth_request)) {
2395 devinfo(usbdev, "authentication indication: "
2396 "too short message (%i)", len);
2397 return;
2398 }
2399
2400 buf = (void *)&indication->u.auth_request[0];
2401 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2402
2403 while (buflen >= sizeof(*auth_req)) {
2404 auth_req = (void *)buf;
2405 type = "unknown";
2406 flags = le32_to_cpu(auth_req->flags);
2407 pairwise_error = false;
2408 group_error = false;
2409
2410 if (flags & 0x1)
2411 type = "reauth request";
2412 if (flags & 0x2)
2413 type = "key update request";
2414 if (flags & 0x6) {
2415 pairwise_error = true;
2416 type = "pairwise_error";
2417 }
2418 if (flags & 0xe) {
2419 group_error = true;
2420 type = "group_error";
2421 }
2422
2423 devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
2424 le32_to_cpu(auth_req->flags));
2425
2426 if (pairwise_error || group_error) {
2427 union iwreq_data wrqu;
2428 struct iw_michaelmicfailure micfailure;
2429
2430 memset(&micfailure, 0, sizeof(micfailure));
2431 if (pairwise_error)
2432 micfailure.flags |= IW_MICFAILURE_PAIRWISE;
2433 if (group_error)
2434 micfailure.flags |= IW_MICFAILURE_GROUP;
2435
2436 memcpy(micfailure.src_addr.sa_data, auth_req->bssid,
2437 ETH_ALEN);
2438
2439 memset(&wrqu, 0, sizeof(wrqu));
2440 wrqu.data.length = sizeof(micfailure);
2441 wireless_send_event(usbdev->net, IWEVMICHAELMICFAILURE,
2442 &wrqu, (u8 *)&micfailure);
2443 }
2444
2445 buflen -= le32_to_cpu(auth_req->length);
2446 buf += le32_to_cpu(auth_req->length);
2447 }
2448}
2449
2450static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2451 struct ndis_80211_status_indication *indication,
2452 int len)
2453{
2454 struct ndis_80211_pmkid_cand_list *cand_list;
2455 int list_len, expected_len, i;
2456
2457 if (len < offsetof(struct ndis_80211_status_indication, u) +
2458 sizeof(struct ndis_80211_pmkid_cand_list)) {
2459 devinfo(usbdev, "pmkid candidate list indication: "
2460 "too short message (%i)", len);
2461 return;
2462 }
2463
2464 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2465 sizeof(struct ndis_80211_pmkid_candidate);
2466 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2467 offsetof(struct ndis_80211_status_indication, u);
2468
2469 if (len < expected_len) {
2470 devinfo(usbdev, "pmkid candidate list indication: "
2471 "list larger than buffer (%i < %i)",
2472 len, expected_len);
2473 return;
2474 }
2475
2476 cand_list = &indication->u.cand_list;
2477
2478 devinfo(usbdev, "pmkid candidate list indication: "
2479 "version %i, candidates %i",
2480 le32_to_cpu(cand_list->version),
2481 le32_to_cpu(cand_list->num_candidates));
2482
2483 if (le32_to_cpu(cand_list->version) != 1)
2484 return;
2485
2486 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
2487 struct iw_pmkid_cand pcand;
2488 union iwreq_data wrqu;
2489 struct ndis_80211_pmkid_candidate *cand =
2490 &cand_list->candidate_list[i];
2491
2492 devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
2493 i, le32_to_cpu(cand->flags), cand->bssid);
2494
2495 memset(&pcand, 0, sizeof(pcand));
2496 if (le32_to_cpu(cand->flags) & 0x01)
2497 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2498 pcand.index = i;
2499 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2500
2501 memset(&wrqu, 0, sizeof(wrqu));
2502 wrqu.data.length = sizeof(pcand);
2503 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2504 (u8 *)&pcand);
2505 }
2506}
2507
2508static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2509 struct rndis_indicate *msg, int buflen)
2510{
2511 struct ndis_80211_status_indication *indication;
2512 int len, offset;
2513
2514 offset = offsetof(struct rndis_indicate, status) +
2515 le32_to_cpu(msg->offset);
2516 len = le32_to_cpu(msg->length);
2517
2518 if (len < 8) {
2519 devinfo(usbdev, "media specific indication, "
2520 "ignore too short message (%i < 8)", len);
2521 return;
2522 }
2523
2524 if (offset + len > buflen) {
2525 devinfo(usbdev, "media specific indication, "
2526 "too large to fit to buffer (%i > %i)",
2527 offset + len, buflen);
2528 return;
2529 }
2530
2531 indication = (void *)((u8 *)msg + offset);
2532
2533 switch (le32_to_cpu(indication->status_type)) {
2534 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2535 devinfo(usbdev, "radio state indication: %i",
2536 le32_to_cpu(indication->u.radio_status));
2537 return;
2538
2539 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2540 devinfo(usbdev, "media stream mode indication: %i",
2541 le32_to_cpu(indication->u.media_stream_mode));
2542 return;
2543
2544 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2545 rndis_wlan_auth_indication(usbdev, indication, len);
2546 return;
2547
2548 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2549 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2550 return;
2551
2552 default:
2553 devinfo(usbdev, "media specific indication: "
2554 "unknown status type 0x%08x",
2555 le32_to_cpu(indication->status_type));
2556 }
2557}
2558
2559
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002560static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002561{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002562 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002563 struct rndis_indicate *msg = ind;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002564
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002565 switch (msg->status) {
2566 case RNDIS_STATUS_MEDIA_CONNECT:
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +03002567 if (priv->current_command_oid == OID_802_11_ADD_KEY) {
2568 /* OID_802_11_ADD_KEY causes sometimes extra
2569 * "media connect" indications which confuses driver
2570 * and userspace to think that device is
2571 * roaming/reassociating when it isn't.
2572 */
2573 devdbg(usbdev, "ignored OID_802_11_ADD_KEY triggered "
2574 "'media connect'");
2575 return;
2576 }
2577
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002578 usbnet_pause_rx(usbdev);
2579
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002580 devinfo(usbdev, "media connect");
2581
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002582 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002583 set_bit(WORK_LINK_UP, &priv->work_pending);
2584 queue_work(priv->workqueue, &priv->work);
2585 break;
2586
2587 case RNDIS_STATUS_MEDIA_DISCONNECT:
2588 devinfo(usbdev, "media disconnect");
2589
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002590 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002591 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2592 queue_work(priv->workqueue, &priv->work);
2593 break;
2594
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002595 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2596 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2597 break;
2598
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002599 default:
2600 devinfo(usbdev, "indication: 0x%08x",
2601 le32_to_cpu(msg->status));
2602 break;
2603 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002604}
2605
2606
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002607static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002608{
2609 struct {
2610 __le32 num_items;
2611 __le32 items[8];
2612 } networks_supported;
2613 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002614 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002615
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002616 /* determine supported modes */
2617 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002618 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002619 &networks_supported, &len);
2620 if (retval >= 0) {
2621 n = le32_to_cpu(networks_supported.num_items);
2622 if (n > 8)
2623 n = 8;
2624 for (i = 0; i < n; i++) {
2625 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002626 case NDIS_80211_TYPE_FREQ_HOP:
2627 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002628 priv->caps |= CAP_MODE_80211B;
2629 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002630 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002631 priv->caps |= CAP_MODE_80211A;
2632 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002633 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002634 priv->caps |= CAP_MODE_80211G;
2635 break;
2636 }
2637 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002638 }
2639
2640 return retval;
2641}
2642
2643
2644#define STATS_UPDATE_JIFFIES (HZ)
2645static void rndis_update_wireless_stats(struct work_struct *work)
2646{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002647 struct rndis_wlan_private *priv =
2648 container_of(work, struct rndis_wlan_private, stats_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002649 struct usbnet *usbdev = priv->usbdev;
2650 struct iw_statistics iwstats;
2651 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002652 int len, ret, j;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002653 unsigned long flags;
2654 int update_jiffies = STATS_UPDATE_JIFFIES;
2655 void *buf;
2656
2657 spin_lock_irqsave(&priv->stats_lock, flags);
2658 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2659 spin_unlock_irqrestore(&priv->stats_lock, flags);
2660
2661 /* only update stats when connected */
2662 if (!is_associated(usbdev)) {
2663 iwstats.qual.qual = 0;
2664 iwstats.qual.level = 0;
2665 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2666 | IW_QUAL_LEVEL_UPDATED
2667 | IW_QUAL_NOISE_INVALID
2668 | IW_QUAL_QUAL_INVALID
2669 | IW_QUAL_LEVEL_INVALID;
2670 goto end;
2671 }
2672
2673 len = sizeof(rssi);
2674 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2675
2676 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2677 le32_to_cpu(rssi));
2678 if (ret == 0) {
2679 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2680 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinna4bd7f032009-03-26 23:40:16 +02002681 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002682 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2683 | IW_QUAL_LEVEL_UPDATED
2684 | IW_QUAL_NOISE_INVALID;
2685 }
2686
2687 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2688
2689 len = sizeof(tmp);
2690 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2691 if (ret == 0)
2692 iwstats.discard.misc += le32_to_cpu(tmp);
2693
2694 len = sizeof(tmp);
2695 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2696 if (ret == 0)
2697 iwstats.discard.misc += le32_to_cpu(tmp);
2698
2699 len = sizeof(tmp);
2700 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2701 if (ret == 0)
2702 iwstats.discard.misc += le32_to_cpu(tmp);
2703
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002704 /* Workaround transfer stalls on poor quality links.
2705 * TODO: find right way to fix these stalls (as stalls do not happen
2706 * with ndiswrapper/windows driver). */
2707 if (iwstats.qual.qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002708 /* Decrease stats worker interval to catch stalls.
2709 * faster. Faster than 400-500ms causes packet loss,
2710 * Slower doesn't catch stalls fast enough.
2711 */
2712 j = msecs_to_jiffies(priv->param_workaround_interval);
2713 if (j > STATS_UPDATE_JIFFIES)
2714 j = STATS_UPDATE_JIFFIES;
2715 else if (j <= 0)
2716 j = 1;
2717 update_jiffies = j;
2718
2719 /* Send scan OID. Use of both OIDs is required to get device
2720 * working.
2721 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08002722 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002723 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2724 sizeof(tmp));
2725
2726 len = CONTROL_BUFFER_SIZE;
2727 buf = kmalloc(len, GFP_KERNEL);
2728 if (!buf)
2729 goto end;
2730
2731 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2732 kfree(buf);
2733 }
2734end:
2735 spin_lock_irqsave(&priv->stats_lock, flags);
2736 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2737 spin_unlock_irqrestore(&priv->stats_lock, flags);
2738
2739 if (update_jiffies >= HZ)
2740 update_jiffies = round_jiffies_relative(update_jiffies);
2741 else {
2742 j = round_jiffies_relative(update_jiffies);
2743 if (abs(j - update_jiffies) <= 10)
2744 update_jiffies = j;
2745 }
2746
2747 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2748}
2749
2750
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002751static int bcm4320a_early_init(struct usbnet *usbdev)
2752{
2753 /* bcm4320a doesn't handle configuration parameters well. Try
2754 * set any and you get partially zeroed mac and broken device.
2755 */
2756
2757 return 0;
2758}
2759
2760
2761static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002762{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002763 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002764 char buf[8];
2765
2766 /* Early initialization settings, setting these won't have effect
2767 * if called after generic_rndis_bind().
2768 */
2769
2770 priv->param_country[0] = modparam_country[0];
2771 priv->param_country[1] = modparam_country[1];
2772 priv->param_country[2] = 0;
2773 priv->param_frameburst = modparam_frameburst;
2774 priv->param_afterburner = modparam_afterburner;
2775 priv->param_power_save = modparam_power_save;
2776 priv->param_power_output = modparam_power_output;
2777 priv->param_roamtrigger = modparam_roamtrigger;
2778 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002779
2780 priv->param_country[0] = toupper(priv->param_country[0]);
2781 priv->param_country[1] = toupper(priv->param_country[1]);
2782 /* doesn't support EU as country code, use FI instead */
2783 if (!strcmp(priv->param_country, "EU"))
2784 strcpy(priv->param_country, "FI");
2785
2786 if (priv->param_power_save < 0)
2787 priv->param_power_save = 0;
2788 else if (priv->param_power_save > 2)
2789 priv->param_power_save = 2;
2790
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03002791 if (priv->param_power_output < 0)
2792 priv->param_power_output = 0;
2793 else if (priv->param_power_output > 3)
2794 priv->param_power_output = 3;
2795
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002796 if (priv->param_roamtrigger < -80)
2797 priv->param_roamtrigger = -80;
2798 else if (priv->param_roamtrigger > -60)
2799 priv->param_roamtrigger = -60;
2800
2801 if (priv->param_roamdelta < 0)
2802 priv->param_roamdelta = 0;
2803 else if (priv->param_roamdelta > 2)
2804 priv->param_roamdelta = 2;
2805
Roel Kluin4d381ff2008-04-23 22:10:29 +02002806 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002807 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02002808 else
2809 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002810
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002811 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2812 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002813 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002814 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002815 priv->param_afterburner ? "1" : "0");
2816 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002817 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002818 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002819 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002820 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002821 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002822 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002823 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002824
2825 return 0;
2826}
2827
David S. Miller23d12e22009-03-25 00:03:16 -07002828/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002829static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07002830 .ndo_open = usbnet_open,
2831 .ndo_stop = usbnet_stop,
2832 .ndo_start_xmit = usbnet_start_xmit,
2833 .ndo_tx_timeout = usbnet_tx_timeout,
2834 .ndo_set_mac_address = eth_mac_addr,
2835 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002836 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07002837};
2838
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002839
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002840static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002841{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002842 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002843 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002844 int retval, len;
2845 __le32 tmp;
2846
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002847 /* allocate wiphy and rndis private data
2848 * NOTE: We only support a single virtual interface, so wiphy
2849 * and wireless_dev are somewhat synonymous for this device.
2850 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002851 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002852 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002853 return -ENOMEM;
2854
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002855 priv = wiphy_priv(wiphy);
2856 usbdev->net->ieee80211_ptr = &priv->wdev;
2857 priv->wdev.wiphy = wiphy;
2858 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2859
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002860 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002861 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002862 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002863 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002864 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2865 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002866
2867 mutex_init(&priv->command_lock);
2868 spin_lock_init(&priv->stats_lock);
2869
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002870 /* because rndis_command() sleeps we need to use workqueue */
2871 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002872 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002873 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2874 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2875
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002876 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002877 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002878 if (retval < 0)
2879 goto fail;
2880
2881 /* generic_rndis_bind set packet filter to multicast_all+
2882 * promisc mode which doesn't work well for our devices (device
2883 * picks up rssi to closest station instead of to access point).
2884 *
2885 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002886 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002887 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002888 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07002889
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002890 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002891 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002892 sizeof(tmp));
2893
2894 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002895 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2896 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002897 priv->multicast_size = le32_to_cpu(tmp);
2898 if (retval < 0 || priv->multicast_size < 0)
2899 priv->multicast_size = 0;
2900 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002901 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002902 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002903 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002904
2905 priv->iwstats.qual.qual = 0;
2906 priv->iwstats.qual.level = 0;
2907 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2908 | IW_QUAL_LEVEL_UPDATED
2909 | IW_QUAL_NOISE_INVALID
2910 | IW_QUAL_QUAL_INVALID
2911 | IW_QUAL_LEVEL_INVALID;
2912
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002913 /* fill-out wiphy structure and register w/ cfg80211 */
2914 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2915 wiphy->privid = rndis_wiphy_privid;
2916 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2917 | BIT(NL80211_IFTYPE_ADHOC);
2918 wiphy->max_scan_ssids = 1;
2919
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002920 /* TODO: fill-out band/encr information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002921 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002922
2923 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2924 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2925 priv->band.channels = priv->channels;
2926 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2927 priv->band.bitrates = priv->rates;
2928 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2929 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002930 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002931
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002932 memcpy(priv->cipher_suites, rndis_cipher_suites,
2933 sizeof(rndis_cipher_suites));
2934 wiphy->cipher_suites = priv->cipher_suites;
2935 wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
2936
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002937 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2938
2939 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002940 retval = -ENODEV;
2941 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002942 }
2943
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002944 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002945
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002946 /* set default rts/frag */
2947 rndis_set_wiphy_params(wiphy,
2948 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2949
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002950 /* turn radio on */
2951 priv->radio_on = 1;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002952 disassociate(usbdev, 1);
2953 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002954
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002955 return 0;
2956
2957fail:
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002958 cancel_delayed_work_sync(&priv->stats_work);
2959 cancel_delayed_work_sync(&priv->scan_work);
2960 cancel_work_sync(&priv->work);
2961 flush_workqueue(priv->workqueue);
2962 destroy_workqueue(priv->workqueue);
2963
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002964 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002965 return retval;
2966}
2967
2968
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002969static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002970{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002971 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002972
2973 /* turn radio off */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002974 disassociate(usbdev, 0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002975
2976 cancel_delayed_work_sync(&priv->stats_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002977 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002978 cancel_work_sync(&priv->work);
2979 flush_workqueue(priv->workqueue);
2980 destroy_workqueue(priv->workqueue);
2981
2982 if (priv && priv->wpa_ie_len)
2983 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002984
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002985 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002986
2987 wiphy_unregister(priv->wdev.wiphy);
2988 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002989}
2990
2991
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002992static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002993{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002994 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002995 int retval;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002996
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002997 devdbg(usbdev, "rndis_wlan_reset");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03002998
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03002999 retval = rndis_reset(usbdev);
3000 if (retval)
3001 devwarn(usbdev, "rndis_reset() failed: %d", retval);
3002
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003003 /* rndis_reset cleared multicast list, so restore here.
3004 (set_multicast_list() also turns on current packet filter) */
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003005 set_multicast_list(usbdev);
3006
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003007 queue_delayed_work(priv->workqueue, &priv->stats_work,
3008 round_jiffies_relative(STATS_UPDATE_JIFFIES));
3009
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003010 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003011}
3012
3013
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003014static int rndis_wlan_stop(struct usbnet *usbdev)
3015{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003016 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3017 int retval;
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003018 __le32 filter;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003019
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003020 devdbg(usbdev, "rndis_wlan_stop");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003021
3022 retval = disassociate(usbdev, 0);
3023
3024 priv->work_pending = 0;
3025 cancel_delayed_work_sync(&priv->stats_work);
3026 cancel_delayed_work_sync(&priv->scan_work);
3027 cancel_work_sync(&priv->work);
3028 flush_workqueue(priv->workqueue);
3029
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03003030 if (priv->scan_request) {
3031 cfg80211_scan_done(priv->scan_request, true);
3032 priv->scan_request = NULL;
3033 }
3034
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003035 /* Set current packet filter zero to block receiving data packets from
3036 device. */
3037 filter = 0;
3038 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
3039 sizeof(filter));
3040
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003041 return retval;
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003042}
3043
3044
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003045static const struct driver_info bcm4320b_info = {
3046 .description = "Wireless RNDIS device, BCM4320b based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003047 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3048 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003049 .bind = rndis_wlan_bind,
3050 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003051 .status = rndis_status,
3052 .rx_fixup = rndis_rx_fixup,
3053 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003054 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003055 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003056 .early_init = bcm4320b_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003057 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003058};
3059
3060static const struct driver_info bcm4320a_info = {
3061 .description = "Wireless RNDIS device, BCM4320a based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003062 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3063 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003064 .bind = rndis_wlan_bind,
3065 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003066 .status = rndis_status,
3067 .rx_fixup = rndis_rx_fixup,
3068 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003069 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003070 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003071 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003072 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003073};
3074
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003075static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003076 .description = "Wireless RNDIS device",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003077 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3078 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003079 .bind = rndis_wlan_bind,
3080 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003081 .status = rndis_status,
3082 .rx_fixup = rndis_rx_fixup,
3083 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003084 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003085 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003086 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003087 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003088};
3089
3090/*-------------------------------------------------------------------------*/
3091
3092static const struct usb_device_id products [] = {
3093#define RNDIS_MASTER_INTERFACE \
3094 .bInterfaceClass = USB_CLASS_COMM, \
3095 .bInterfaceSubClass = 2 /* ACM */, \
3096 .bInterfaceProtocol = 0x0ff
3097
3098/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3099 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3100 */
3101{
3102 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3103 | USB_DEVICE_ID_MATCH_DEVICE,
3104 .idVendor = 0x0411,
3105 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
3106 RNDIS_MASTER_INTERFACE,
3107 .driver_info = (unsigned long) &bcm4320b_info,
3108}, {
3109 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3110 | USB_DEVICE_ID_MATCH_DEVICE,
3111 .idVendor = 0x0baf,
3112 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
3113 RNDIS_MASTER_INTERFACE,
3114 .driver_info = (unsigned long) &bcm4320b_info,
3115}, {
3116 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3117 | USB_DEVICE_ID_MATCH_DEVICE,
3118 .idVendor = 0x050d,
3119 .idProduct = 0x011b, /* Belkin F5D7051 */
3120 RNDIS_MASTER_INTERFACE,
3121 .driver_info = (unsigned long) &bcm4320b_info,
3122}, {
3123 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3124 | USB_DEVICE_ID_MATCH_DEVICE,
3125 .idVendor = 0x1799, /* Belkin has two vendor ids */
3126 .idProduct = 0x011b, /* Belkin F5D7051 */
3127 RNDIS_MASTER_INTERFACE,
3128 .driver_info = (unsigned long) &bcm4320b_info,
3129}, {
3130 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3131 | USB_DEVICE_ID_MATCH_DEVICE,
3132 .idVendor = 0x13b1,
3133 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
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 = 0x13b1,
3140 .idProduct = 0x0026, /* Linksys WUSB54GSC */
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 = 0x0b05,
3147 .idProduct = 0x1717, /* Asus WL169gE */
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 = 0x0a5c,
3154 .idProduct = 0xd11b, /* Eminent EM4045 */
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 = 0x1690,
3161 .idProduct = 0x0715, /* BT Voyager 1055 */
3162 RNDIS_MASTER_INTERFACE,
3163 .driver_info = (unsigned long) &bcm4320b_info,
3164},
3165/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3166 * parameters available, hardware probably contain older firmware version with
3167 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3168 */
3169{
3170 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3171 | USB_DEVICE_ID_MATCH_DEVICE,
3172 .idVendor = 0x13b1,
3173 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3174 RNDIS_MASTER_INTERFACE,
3175 .driver_info = (unsigned long) &bcm4320a_info,
3176}, {
3177 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3178 | USB_DEVICE_ID_MATCH_DEVICE,
3179 .idVendor = 0x0baf,
3180 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3181 RNDIS_MASTER_INTERFACE,
3182 .driver_info = (unsigned long) &bcm4320a_info,
3183}, {
3184 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3185 | USB_DEVICE_ID_MATCH_DEVICE,
3186 .idVendor = 0x0411,
3187 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3188 RNDIS_MASTER_INTERFACE,
3189 .driver_info = (unsigned long) &bcm4320a_info,
3190},
3191/* Generic Wireless RNDIS devices that we don't have exact
3192 * idVendor/idProduct/chip yet.
3193 */
3194{
3195 /* RNDIS is MSFT's un-official variant of CDC ACM */
3196 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003197 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003198}, {
3199 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3200 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003201 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003202},
3203 { }, // END
3204};
3205MODULE_DEVICE_TABLE(usb, products);
3206
3207static struct usb_driver rndis_wlan_driver = {
3208 .name = "rndis_wlan",
3209 .id_table = products,
3210 .probe = usbnet_probe,
3211 .disconnect = usbnet_disconnect,
3212 .suspend = usbnet_suspend,
3213 .resume = usbnet_resume,
3214};
3215
3216static int __init rndis_wlan_init(void)
3217{
3218 return usb_register(&rndis_wlan_driver);
3219}
3220module_init(rndis_wlan_init);
3221
3222static void __exit rndis_wlan_exit(void)
3223{
3224 usb_deregister(&rndis_wlan_driver);
3225}
3226module_exit(rndis_wlan_exit);
3227
3228MODULE_AUTHOR("Bjorge Dijkstra");
3229MODULE_AUTHOR("Jussi Kivilinna");
3230MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3231MODULE_LICENSE("GPL");
3232