blob: c28fde59c32bf05c73e8a7e40963445f7e9a8b5d [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
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300517static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200518{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300519 return (struct rndis_wlan_private *)dev->driver_priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200520}
521
522
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300523static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200524{
Jussi Kivilinna222ec502009-06-16 17:17:32 +0300525 switch (priv->param_power_output) {
526 default:
527 case 3:
528 return BCM4320_DEFAULT_TXPOWER_DBM_100;
529 case 2:
530 return BCM4320_DEFAULT_TXPOWER_DBM_75;
531 case 1:
532 return BCM4320_DEFAULT_TXPOWER_DBM_50;
533 case 0:
534 return BCM4320_DEFAULT_TXPOWER_DBM_25;
535 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200536}
537
538
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300539static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
540{
541 int cipher = priv->encr_keys[idx].cipher;
542
543 return (cipher == WLAN_CIPHER_SUITE_CCMP ||
544 cipher == WLAN_CIPHER_SUITE_TKIP);
545}
546
547
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300548#ifdef DEBUG
549static const char *oid_to_string(__le32 oid)
550{
551 switch (oid) {
552#define OID_STR(oid) case oid: return(#oid)
553 /* from rndis_host.h */
554 OID_STR(OID_802_3_PERMANENT_ADDRESS);
555 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
556 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
557 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
558
559 /* from rndis_wlan.c */
560 OID_STR(OID_GEN_LINK_SPEED);
561 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
562
563 OID_STR(OID_GEN_XMIT_OK);
564 OID_STR(OID_GEN_RCV_OK);
565 OID_STR(OID_GEN_XMIT_ERROR);
566 OID_STR(OID_GEN_RCV_ERROR);
567 OID_STR(OID_GEN_RCV_NO_BUFFER);
568
569 OID_STR(OID_802_3_CURRENT_ADDRESS);
570 OID_STR(OID_802_3_MULTICAST_LIST);
571 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
572
573 OID_STR(OID_802_11_BSSID);
574 OID_STR(OID_802_11_SSID);
575 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
576 OID_STR(OID_802_11_ADD_WEP);
577 OID_STR(OID_802_11_REMOVE_WEP);
578 OID_STR(OID_802_11_DISASSOCIATE);
579 OID_STR(OID_802_11_AUTHENTICATION_MODE);
580 OID_STR(OID_802_11_PRIVACY_FILTER);
581 OID_STR(OID_802_11_BSSID_LIST_SCAN);
582 OID_STR(OID_802_11_ENCRYPTION_STATUS);
583 OID_STR(OID_802_11_ADD_KEY);
584 OID_STR(OID_802_11_REMOVE_KEY);
585 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
586 OID_STR(OID_802_11_PMKID);
587 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
588 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
589 OID_STR(OID_802_11_TX_POWER_LEVEL);
590 OID_STR(OID_802_11_RSSI);
591 OID_STR(OID_802_11_RSSI_TRIGGER);
592 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
593 OID_STR(OID_802_11_RTS_THRESHOLD);
594 OID_STR(OID_802_11_SUPPORTED_RATES);
595 OID_STR(OID_802_11_CONFIGURATION);
596 OID_STR(OID_802_11_BSSID_LIST);
597#undef OID_STR
598 }
599
600 return "?";
601}
602#else
603static const char *oid_to_string(__le32 oid)
604{
605 return "?";
606}
607#endif
608
609
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200610/* translate error code */
611static int rndis_error_status(__le32 rndis_status)
612{
613 int ret = -EINVAL;
614 switch (rndis_status) {
615 case RNDIS_STATUS_SUCCESS:
616 ret = 0;
617 break;
618 case RNDIS_STATUS_FAILURE:
619 case RNDIS_STATUS_INVALID_DATA:
620 ret = -EINVAL;
621 break;
622 case RNDIS_STATUS_NOT_SUPPORTED:
623 ret = -EOPNOTSUPP;
624 break;
625 case RNDIS_STATUS_ADAPTER_NOT_READY:
626 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
627 ret = -EBUSY;
628 break;
629 }
630 return ret;
631}
632
633
634static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
635{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300636 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200637 union {
638 void *buf;
639 struct rndis_msg_hdr *header;
640 struct rndis_query *get;
641 struct rndis_query_c *get_c;
642 } u;
643 int ret, buflen;
644
645 buflen = *len + sizeof(*u.get);
646 if (buflen < CONTROL_BUFFER_SIZE)
647 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300648
649 if (buflen > COMMAND_BUFFER_SIZE) {
650 u.buf = kmalloc(buflen, GFP_KERNEL);
651 if (!u.buf)
652 return -ENOMEM;
653 } else {
654 u.buf = priv->command_buffer;
655 }
656
657 mutex_lock(&priv->command_lock);
658
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200659 memset(u.get, 0, sizeof *u.get);
660 u.get->msg_type = RNDIS_MSG_QUERY;
Harvey Harrison35c26c22009-02-14 22:56:56 -0800661 u.get->msg_len = cpu_to_le32(sizeof *u.get);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200662 u.get->oid = oid;
663
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300664 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300665 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300666 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300667 if (ret < 0)
668 devdbg(dev, "rndis_query_oid(%s): rndis_command() failed, %d "
669 "(%08x)", oid_to_string(oid), ret,
670 le32_to_cpu(u.get_c->status));
671
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200672 if (ret == 0) {
673 ret = le32_to_cpu(u.get_c->len);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +0300674 if (ret > *len)
675 *len = ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200676 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
677 ret = rndis_error_status(u.get_c->status);
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300678
679 if (ret < 0)
680 devdbg(dev, "rndis_query_oid(%s): device returned "
681 "error, 0x%08x (%d)", oid_to_string(oid),
682 le32_to_cpu(u.get_c->status), ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200683 }
684
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300685 mutex_unlock(&priv->command_lock);
686
687 if (u.buf != priv->command_buffer)
688 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200689 return ret;
690}
691
692
693static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
694{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300695 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200696 union {
697 void *buf;
698 struct rndis_msg_hdr *header;
699 struct rndis_set *set;
700 struct rndis_set_c *set_c;
701 } u;
702 int ret, buflen;
703
704 buflen = len + sizeof(*u.set);
705 if (buflen < CONTROL_BUFFER_SIZE)
706 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300707
708 if (buflen > COMMAND_BUFFER_SIZE) {
709 u.buf = kmalloc(buflen, GFP_KERNEL);
710 if (!u.buf)
711 return -ENOMEM;
712 } else {
713 u.buf = priv->command_buffer;
714 }
715
716 mutex_lock(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200717
718 memset(u.set, 0, sizeof *u.set);
719 u.set->msg_type = RNDIS_MSG_SET;
720 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
721 u.set->oid = oid;
722 u.set->len = cpu_to_le32(len);
Harvey Harrison35c26c22009-02-14 22:56:56 -0800723 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
724 u.set->handle = cpu_to_le32(0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200725 memcpy(u.buf + sizeof(*u.set), data, len);
726
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300727 priv->current_command_oid = oid;
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300728 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300729 priv->current_command_oid = 0;
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300730 if (ret < 0)
731 devdbg(dev, "rndis_set_oid(%s): rndis_command() failed, %d "
732 "(%08x)", oid_to_string(oid), ret,
733 le32_to_cpu(u.set_c->status));
734
735 if (ret == 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200736 ret = rndis_error_status(u.set_c->status);
737
Jussi Kivilinna27b7b5c2009-07-30 19:41:47 +0300738 if (ret < 0)
739 devdbg(dev, "rndis_set_oid(%s): device returned error, "
740 "0x%08x (%d)", oid_to_string(oid),
741 le32_to_cpu(u.set_c->status), ret);
742 }
743
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300744 mutex_unlock(&priv->command_lock);
745
746 if (u.buf != priv->command_buffer)
747 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200748 return ret;
749}
750
751
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300752static int rndis_reset(struct usbnet *usbdev)
753{
754 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
755 struct rndis_reset *reset;
756 int ret;
757
758 mutex_lock(&priv->command_lock);
759
760 reset = (void *)priv->command_buffer;
761 memset(reset, 0, sizeof(*reset));
762 reset->msg_type = RNDIS_MSG_RESET;
763 reset->msg_len = cpu_to_le32(sizeof(*reset));
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +0300764 priv->current_command_oid = 0;
Jussi Kivilinna7eaab702009-07-30 19:41:37 +0300765 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
766
767 mutex_unlock(&priv->command_lock);
768
769 if (ret < 0)
770 return ret;
771 return 0;
772}
773
774
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200775/*
776 * Specs say that we can only set config parameters only soon after device
777 * initialization.
778 * value_type: 0 = u32, 2 = unicode string
779 */
780static int rndis_set_config_parameter(struct usbnet *dev, char *param,
781 int value_type, void *value)
782{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200783 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200784 int value_len, info_len, param_len, ret, i;
785 __le16 *unibuf;
786 __le32 *dst_value;
787
788 if (value_type == 0)
789 value_len = sizeof(__le32);
790 else if (value_type == 2)
791 value_len = strlen(value) * sizeof(__le16);
792 else
793 return -EINVAL;
794
795 param_len = strlen(param) * sizeof(__le16);
796 info_len = sizeof(*infobuf) + param_len + value_len;
797
798#ifdef DEBUG
799 info_len += 12;
800#endif
801 infobuf = kmalloc(info_len, GFP_KERNEL);
802 if (!infobuf)
803 return -ENOMEM;
804
805#ifdef DEBUG
806 info_len -= 12;
807 /* extra 12 bytes are for padding (debug output) */
808 memset(infobuf, 0xCC, info_len + 12);
809#endif
810
811 if (value_type == 2)
812 devdbg(dev, "setting config parameter: %s, value: %s",
813 param, (u8 *)value);
814 else
815 devdbg(dev, "setting config parameter: %s, value: %d",
816 param, *(u32 *)value);
817
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200818 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
819 infobuf->name_length = cpu_to_le32(param_len);
820 infobuf->type = cpu_to_le32(value_type);
821 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
822 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200823
824 /* simple string to unicode string conversion */
825 unibuf = (void *)infobuf + sizeof(*infobuf);
826 for (i = 0; i < param_len / sizeof(__le16); i++)
827 unibuf[i] = cpu_to_le16(param[i]);
828
829 if (value_type == 2) {
830 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
831 for (i = 0; i < value_len / sizeof(__le16); i++)
832 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
833 } else {
834 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
835 *dst_value = cpu_to_le32(*(u32 *)value);
836 }
837
838#ifdef DEBUG
839 devdbg(dev, "info buffer (len: %d):", info_len);
840 for (i = 0; i < info_len; i += 12) {
841 u32 *tmp = (u32 *)((u8 *)infobuf + i);
842 devdbg(dev, "%08X:%08X:%08X",
843 cpu_to_be32(tmp[0]),
844 cpu_to_be32(tmp[1]),
845 cpu_to_be32(tmp[2]));
846 }
847#endif
848
849 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
850 infobuf, info_len);
851 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200852 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200853
854 kfree(infobuf);
855 return ret;
856}
857
858static int rndis_set_config_parameter_str(struct usbnet *dev,
859 char *param, char *value)
860{
861 return(rndis_set_config_parameter(dev, param, 2, value));
862}
863
864/*static int rndis_set_config_parameter_u32(struct usbnet *dev,
865 char *param, u32 value)
866{
867 return(rndis_set_config_parameter(dev, param, 0, &value));
868}*/
869
870
871/*
872 * data conversion functions
873 */
874static int level_to_qual(int level)
875{
876 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
877 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
878}
879
880
881static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
882{
883 freq->e = 0;
884 freq->i = 0;
885 freq->flags = 0;
886
887 /* see comment in wireless.h above the "struct iw_freq"
888 * definition for an explanation of this if
889 * NOTE: 1000000 is due to the kHz
890 */
891 if (dsconfig > 1000000) {
892 freq->m = dsconfig / 10;
893 freq->e = 1;
894 } else
895 freq->m = dsconfig;
896
897 /* convert from kHz to Hz */
898 freq->e += 3;
899}
900
901
902static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
903{
904 if (freq->m < 1000 && freq->e == 0) {
David Kilroy9ee677c2008-12-23 14:03:38 +0000905 if (freq->m >= 1 && freq->m <= 14)
906 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200907 else
908 return -1;
909 } else {
910 int i;
911 *dsconfig = freq->m;
912 for (i = freq->e; i > 0; i--)
913 *dsconfig *= 10;
914 *dsconfig /= 1000;
915 }
916
917 return 0;
918}
919
920
921/*
922 * common functions
923 */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +0300924static void restore_keys(struct usbnet *usbdev);
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +0300925static int rndis_check_bssid_list(struct usbnet *usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200926
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200927static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200928{
929 int ret, len;
930
931 len = sizeof(*ssid);
932 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
933
934 if (ret != 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200935 ssid->length = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200936
937#ifdef DEBUG
938 {
939 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
940
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200941 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
942 tmp[le32_to_cpu(ssid->length)] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200943 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
944 }
945#endif
946 return ret;
947}
948
949
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200950static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200951{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300952 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200953 int ret;
954
955 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
956 if (ret == 0) {
957 memcpy(&priv->essid, ssid, sizeof(priv->essid));
958 priv->radio_on = 1;
959 devdbg(usbdev, "set_essid: radio_on = 1");
960 }
961
962 return ret;
963}
964
965
966static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
967{
968 int ret, len;
969
970 len = ETH_ALEN;
971 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
972
973 if (ret != 0)
974 memset(bssid, 0, ETH_ALEN);
975
976 return ret;
977}
978
Scott Ashcroft43646232008-05-27 00:06:15 +0300979static int get_association_info(struct usbnet *usbdev,
980 struct ndis_80211_assoc_info *info, int len)
981{
982 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
983 info, &len);
984}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200985
986static int is_associated(struct usbnet *usbdev)
987{
988 u8 bssid[ETH_ALEN];
989 int ret;
990
991 ret = get_bssid(usbdev, bssid);
992
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +0300993 return (ret == 0 && !is_zero_ether_addr(bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200994}
995
996
997static int disassociate(struct usbnet *usbdev, int reset_ssid)
998{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300999 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001000 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001001 int i, ret = 0;
1002
1003 if (priv->radio_on) {
1004 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
1005 if (ret == 0) {
1006 priv->radio_on = 0;
1007 devdbg(usbdev, "disassociate: radio_on = 0");
1008
1009 if (reset_ssid)
1010 msleep(100);
1011 }
1012 }
1013
1014 /* disassociate causes radio to be turned off; if reset_ssid
1015 * is given, set random ssid to enable radio */
1016 if (reset_ssid) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001017 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1018 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1019 ssid.essid[0] = 0x1;
1020 ssid.essid[1] = 0xff;
1021 for (i = 2; i < sizeof(ssid.essid); i++)
1022 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001023 ret = set_essid(usbdev, &ssid);
1024 }
1025 return ret;
1026}
1027
1028
1029static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
1030{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001031 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001032 __le32 tmp;
1033 int auth_mode, ret;
1034
1035 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
1036 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
1037
1038 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
1039 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001040 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001041 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001042 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001043 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
1044 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001045 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001046 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001047 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001048 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001049 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001050 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
1051 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001052 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001053 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001054 auth_mode = NDIS_80211_AUTH_SHARED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001055 } else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001056 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001057
1058 tmp = cpu_to_le32(auth_mode);
1059 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1060 sizeof(tmp));
1061 if (ret != 0) {
1062 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
1063 return ret;
1064 }
1065
1066 priv->wpa_version = wpa_version;
1067 priv->wpa_authalg = authalg;
1068 return 0;
1069}
1070
1071
1072static int set_priv_filter(struct usbnet *usbdev)
1073{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001074 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001075 __le32 tmp;
1076
1077 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
1078
1079 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
1080 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001081 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001082 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001083 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001084
1085 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1086 sizeof(tmp));
1087}
1088
1089
1090static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1091{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001092 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001093 __le32 tmp;
1094 int encr_mode, ret;
1095
1096 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
1097 pairwise,
1098 groupwise);
1099
1100 if (pairwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001101 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001102 else if (pairwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001103 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001104 else if (pairwise &
1105 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001106 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001107 else if (groupwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001108 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001109 else if (groupwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001110 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001111 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001112 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001113
1114 tmp = cpu_to_le32(encr_mode);
1115 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1116 sizeof(tmp));
1117 if (ret != 0) {
1118 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
1119 return ret;
1120 }
1121
1122 priv->wpa_cipher_pair = pairwise;
1123 priv->wpa_cipher_group = groupwise;
1124 return 0;
1125}
1126
1127
1128static int set_assoc_params(struct usbnet *usbdev)
1129{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001130 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001131
1132 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
1133 set_priv_filter(usbdev);
1134 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
1135
1136 return 0;
1137}
1138
1139
1140static int set_infra_mode(struct usbnet *usbdev, int mode)
1141{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001142 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001143 __le32 tmp;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001144 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001145
1146 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
1147
1148 tmp = cpu_to_le32(mode);
1149 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1150 sizeof(tmp));
1151 if (ret != 0) {
1152 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
1153 return ret;
1154 }
1155
1156 /* NDIS drivers clear keys when infrastructure mode is
1157 * changed. But Linux tools assume otherwise. So set the
1158 * keys */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001159 restore_keys(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001160
1161 priv->infra_mode = mode;
1162 return 0;
1163}
1164
1165
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001166static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1167{
1168 __le32 tmp;
1169
1170 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1171
1172 if (rts_threshold < 0 || rts_threshold > 2347)
1173 rts_threshold = 2347;
1174
1175 tmp = cpu_to_le32(rts_threshold);
1176 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1177 sizeof(tmp));
1178}
1179
1180
1181static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1182{
1183 __le32 tmp;
1184
1185 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1186
1187 if (frag_threshold < 256 || frag_threshold > 2346)
1188 frag_threshold = 2346;
1189
1190 tmp = cpu_to_le32(frag_threshold);
1191 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1192 sizeof(tmp));
1193}
1194
1195
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001196static void set_default_iw_params(struct usbnet *usbdev)
1197{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001198 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001199
1200 priv->wpa_keymgmt = 0;
1201 priv->wpa_version = 0;
1202
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001203 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001204 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1205 IW_AUTH_ALG_OPEN_SYSTEM);
1206 set_priv_filter(usbdev);
1207 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1208}
1209
1210
1211static int deauthenticate(struct usbnet *usbdev)
1212{
1213 int ret;
1214
1215 ret = disassociate(usbdev, 1);
1216 set_default_iw_params(usbdev);
1217 return ret;
1218}
1219
1220
1221/* index must be 0 - N, as per NDIS */
1222static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
1223{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001224 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001225 struct ndis_80211_wep_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001226 int cipher, ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001227
Jussi Kivilinna40ba60d2009-08-20 21:00:34 +03001228 if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001229 return -EINVAL;
1230
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001231 if (key_len == 5)
1232 cipher = WLAN_CIPHER_SUITE_WEP40;
1233 else
1234 cipher = WLAN_CIPHER_SUITE_WEP104;
1235
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001236 memset(&ndis_key, 0, sizeof(ndis_key));
1237
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001238 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1239 ndis_key.length = cpu_to_le32(key_len);
1240 ndis_key.index = cpu_to_le32(index);
1241 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001242
1243 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001244 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001245 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1246 IW_AUTH_CIPHER_NONE);
1247 if (ret)
1248 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1249 ret);
1250 }
1251
1252 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1253 sizeof(ndis_key));
1254 if (ret != 0) {
1255 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1256 index+1, ret);
1257 return ret;
1258 }
1259
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001260 priv->encr_keys[index].len = key_len;
1261 priv->encr_keys[index].cipher = cipher;
1262 memcpy(&priv->encr_keys[index].material, key, key_len);
1263 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001264
1265 return 0;
1266}
1267
1268
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001269static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001270 int index, const u8 *addr, const u8 *rx_seq, int cipher,
1271 int flags)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001272{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001273 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001274 struct ndis_80211_key ndis_key;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001275 bool is_addr_ok;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001276 int ret;
1277
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001278 if (index < 0 || index >= 4) {
1279 devdbg(usbdev, "add_wpa_key: index out of range (%i)", index);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001280 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001281 }
1282 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1283 devdbg(usbdev, "add_wpa_key: key length out of range (%i)",
1284 key_len);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001285 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001286 }
1287 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq) {
1288 devdbg(usbdev, "add_wpa_key: recv seq flag without buffer");
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001289 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001290 }
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001291 is_addr_ok = addr && !is_zero_ether_addr(addr) &&
1292 !is_broadcast_ether_addr(addr);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001293 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1294 devdbg(usbdev, "add_wpa_key: pairwise but bssid invalid (%pM)",
1295 addr);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001296 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001297 }
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001298
1299 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001300 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1301 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1302 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001303
1304 memset(&ndis_key, 0, sizeof(ndis_key));
1305
1306 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1307 sizeof(ndis_key.material) + key_len);
1308 ndis_key.length = cpu_to_le32(key_len);
1309 ndis_key.index = cpu_to_le32(index) | flags;
1310
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001311 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001312 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1313 * different order than NDIS spec, so swap the order here. */
1314 memcpy(ndis_key.material, key, 16);
1315 memcpy(ndis_key.material + 16, key + 24, 8);
1316 memcpy(ndis_key.material + 24, key + 16, 8);
1317 } else
1318 memcpy(ndis_key.material, key, key_len);
1319
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001320 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001321 memcpy(ndis_key.rsc, rx_seq, 6);
1322
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001323 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001324 /* pairwise key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001325 memcpy(ndis_key.bssid, addr, ETH_ALEN);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001326 } else {
1327 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001328 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001329 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1330 else
1331 get_bssid(usbdev, ndis_key.bssid);
1332 }
1333
1334 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1335 le32_to_cpu(ndis_key.size));
1336 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1337 if (ret != 0)
1338 return ret;
1339
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001340 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1341 priv->encr_keys[index].len = key_len;
1342 priv->encr_keys[index].cipher = cipher;
1343 memcpy(&priv->encr_keys[index].material, key, key_len);
1344 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1345 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1346 else
1347 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
Jussi Kivilinna98391782009-05-22 17:40:34 +03001348
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001349 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001350 priv->encr_tx_key_index = index;
1351
1352 return 0;
1353}
1354
1355
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001356static int restore_key(struct usbnet *usbdev, int key_idx)
1357{
1358 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1359 struct rndis_wlan_encr_key key;
1360 int flags;
1361
1362 key = priv->encr_keys[key_idx];
1363
1364 devdbg(usbdev, "restore_key: %i:%s:%i", key_idx,
1365 is_wpa_key(priv, key_idx) ? "wpa" : "wep",
1366 key.len);
1367
1368 if (key.len == 0)
1369 return 0;
1370
1371 if (is_wpa_key(priv, key_idx)) {
1372 flags = 0;
1373
1374 /*if (priv->encr_tx_key_index == key_idx)
1375 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;*/
1376
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001377 if (!is_zero_ether_addr(key.bssid) &&
1378 !is_broadcast_ether_addr(key.bssid))
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001379 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
1380
1381 return add_wpa_key(usbdev, key.material, key.len, key_idx,
1382 key.bssid, NULL, key.cipher, flags);
1383 }
1384
1385 return add_wep_key(usbdev, key.material, key.len, key_idx);
1386}
1387
1388
1389static void restore_keys(struct usbnet *usbdev)
1390{
1391 int i;
1392
1393 for (i = 0; i < 4; i++)
1394 restore_key(usbdev, i);
1395}
1396
1397
1398static void clear_key(struct rndis_wlan_private *priv, int idx)
1399{
1400 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1401}
1402
1403
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001404/* remove_key is for both wep and wpa */
1405static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1406{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001407 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001408 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001409 __le32 keyindex;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001410 bool is_wpa;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001411 int ret;
1412
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001413 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001414 return 0;
1415
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001416 is_wpa = is_wpa_key(priv, index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001417
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001418 devdbg(usbdev, "remove_key: %i:%s:%i", index, is_wpa ? "wpa" : "wep",
1419 priv->encr_keys[index].len);
1420
1421 clear_key(priv, index);
1422
1423 if (is_wpa) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001424 remove_key.size = cpu_to_le32(sizeof(remove_key));
1425 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001426 if (bssid) {
1427 /* pairwise key */
Jussi Kivilinna7b1fff92009-08-28 12:59:15 +03001428 if (!is_broadcast_ether_addr(bssid))
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001429 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001430 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001431 memcpy(remove_key.bssid, bssid,
1432 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001433 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001434 memset(remove_key.bssid, 0xff,
1435 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001436
1437 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1438 sizeof(remove_key));
1439 if (ret != 0)
1440 return ret;
1441 } else {
1442 keyindex = cpu_to_le32(index);
1443 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1444 sizeof(keyindex));
1445 if (ret != 0) {
1446 devwarn(usbdev,
1447 "removing encryption key %d failed (%08X)",
1448 index, ret);
1449 return ret;
1450 }
1451 }
1452
1453 /* if it is transmit key, disable encryption */
1454 if (index == priv->encr_tx_key_index)
1455 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1456
1457 return 0;
1458}
1459
1460
1461static void set_multicast_list(struct usbnet *usbdev)
1462{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001463 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001464 struct dev_mc_list *mclist;
1465 __le32 filter;
1466 int ret, i, size;
1467 char *buf;
1468
1469 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1470
1471 if (usbdev->net->flags & IFF_PROMISC) {
1472 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1473 RNDIS_PACKET_TYPE_ALL_LOCAL;
1474 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1475 usbdev->net->mc_count > priv->multicast_size) {
1476 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1477 } else if (usbdev->net->mc_count > 0) {
1478 size = min(priv->multicast_size, usbdev->net->mc_count);
1479 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1480 if (!buf) {
1481 devwarn(usbdev,
1482 "couldn't alloc %d bytes of memory",
1483 size * ETH_ALEN);
1484 return;
1485 }
1486
1487 mclist = usbdev->net->mc_list;
1488 for (i = 0; i < size && mclist; mclist = mclist->next) {
1489 if (mclist->dmi_addrlen != ETH_ALEN)
1490 continue;
1491
1492 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1493 i++;
1494 }
1495
1496 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1497 i * ETH_ALEN);
1498 if (ret == 0 && i > 0)
1499 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1500 else
1501 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1502
1503 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1504 i, priv->multicast_size, ret);
1505
1506 kfree(buf);
1507 }
1508
1509 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1510 sizeof(filter));
1511 if (ret < 0) {
1512 devwarn(usbdev, "couldn't set packet filter: %08x",
1513 le32_to_cpu(filter));
1514 }
1515
1516 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1517 le32_to_cpu(filter), ret);
1518}
1519
1520
1521/*
John W. Linville964c1d42009-03-26 23:40:01 +02001522 * cfg80211 ops
1523 */
Johannes Berge36d56b2009-06-09 21:04:43 +02001524static int rndis_change_virtual_intf(struct wiphy *wiphy,
1525 struct net_device *dev,
John W. Linville964c1d42009-03-26 23:40:01 +02001526 enum nl80211_iftype type, u32 *flags,
1527 struct vif_params *params)
1528{
Johannes Berge36d56b2009-06-09 21:04:43 +02001529 struct usbnet *usbdev = netdev_priv(dev);
John W. Linville964c1d42009-03-26 23:40:01 +02001530 int mode;
1531
John W. Linville964c1d42009-03-26 23:40:01 +02001532 switch (type) {
1533 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001534 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001535 break;
1536 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001537 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001538 break;
1539 default:
1540 return -EINVAL;
1541 }
1542
1543 return set_infra_mode(usbdev, mode);
1544}
1545
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001546
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03001547static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1548{
1549 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1550 struct usbnet *usbdev = priv->usbdev;
1551 int err;
1552
1553 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1554 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1555 if (err < 0)
1556 return err;
1557 }
1558
1559 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1560 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1561 if (err < 0)
1562 return err;
1563 }
1564
1565 return 0;
1566}
1567
1568
Jussi Kivilinna222ec502009-06-16 17:17:32 +03001569static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1570 int dbm)
1571{
1572 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1573 struct usbnet *usbdev = priv->usbdev;
1574
1575 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1576
1577 /* Device doesn't support changing txpower after initialization, only
1578 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1579 * currently used.
1580 */
1581 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1582 if (!priv->radio_on)
1583 disassociate(usbdev, 1); /* turn on radio */
1584
1585 return 0;
1586 }
1587
1588 return -ENOTSUPP;
1589}
1590
1591
1592static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1593{
1594 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1595 struct usbnet *usbdev = priv->usbdev;
1596
1597 *dbm = get_bcm4320_power_dbm(priv);
1598
1599 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1600
1601 return 0;
1602}
1603
1604
Jussi Kivilinnab1d25a62009-08-28 12:59:05 +03001605#define SCAN_DELAY_JIFFIES (6 * HZ)
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001606static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1607 struct cfg80211_scan_request *request)
1608{
1609 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001610 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001611 int ret;
1612 __le32 tmp;
1613
1614 devdbg(usbdev, "cfg80211.scan");
1615
Jussi Kivilinnadb0dd392009-08-28 12:58:55 +03001616 /* Get current bssid list from device before new scan, as new scan
1617 * clears internal bssid list.
1618 */
1619 rndis_check_bssid_list(usbdev);
1620
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001621 if (!request)
1622 return -EINVAL;
1623
1624 if (priv->scan_request && priv->scan_request != request)
1625 return -EBUSY;
1626
1627 priv->scan_request = request;
1628
1629 tmp = cpu_to_le32(1);
1630 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1631 sizeof(tmp));
1632 if (ret == 0) {
1633 /* Wait before retrieving scan results from device */
1634 queue_delayed_work(priv->workqueue, &priv->scan_work,
1635 SCAN_DELAY_JIFFIES);
1636 }
1637
1638 return ret;
1639}
1640
1641
1642static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1643 struct ndis_80211_bssid_ex *bssid)
1644{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001645 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001646 struct ieee80211_channel *channel;
1647 s32 signal;
1648 u64 timestamp;
1649 u16 capability;
1650 u16 beacon_interval;
1651 struct ndis_80211_fixed_ies *fixed;
1652 int ie_len, bssid_len;
1653 u8 *ie;
1654
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001655 devdbg(usbdev, " found bssid: '%.32s' [%pM]", bssid->ssid.essid,
1656 bssid->mac);
1657
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001658 /* parse bssid structure */
1659 bssid_len = le32_to_cpu(bssid->length);
1660
1661 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1662 sizeof(struct ndis_80211_fixed_ies))
1663 return NULL;
1664
1665 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1666
1667 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1668 ie_len = min(bssid_len - (int)sizeof(*bssid),
1669 (int)le32_to_cpu(bssid->ie_length));
1670 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1671 if (ie_len < 0)
1672 return NULL;
1673
1674 /* extract data for cfg80211_inform_bss */
1675 channel = ieee80211_get_channel(priv->wdev.wiphy,
1676 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1677 if (!channel)
1678 return NULL;
1679
1680 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1681 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1682 capability = le16_to_cpu(fixed->capabilities);
1683 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1684
1685 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1686 timestamp, capability, beacon_interval, ie, ie_len, signal,
1687 GFP_KERNEL);
1688}
1689
1690
1691static int rndis_check_bssid_list(struct usbnet *usbdev)
1692{
1693 void *buf = NULL;
1694 struct ndis_80211_bssid_list_ex *bssid_list;
1695 struct ndis_80211_bssid_ex *bssid;
1696 int ret = -EINVAL, len, count, bssid_len;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001697 bool resized = false;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001698
1699 devdbg(usbdev, "check_bssid_list");
1700
1701 len = CONTROL_BUFFER_SIZE;
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001702resize_buf:
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001703 buf = kmalloc(len, GFP_KERNEL);
1704 if (!buf) {
1705 ret = -ENOMEM;
1706 goto out;
1707 }
1708
1709 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1710 if (ret != 0)
1711 goto out;
1712
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001713 if (!resized && len > CONTROL_BUFFER_SIZE) {
1714 resized = true;
1715 kfree(buf);
1716 goto resize_buf;
1717 }
1718
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001719 bssid_list = buf;
1720 bssid = bssid_list->bssid;
1721 bssid_len = le32_to_cpu(bssid->length);
1722 count = le32_to_cpu(bssid_list->num_items);
Jussi Kivilinna5fd8f252009-08-28 12:59:00 +03001723 devdbg(usbdev, "check_bssid_list: %d BSSIDs found (buflen: %d)", count,
1724 len);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001725
1726 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1727 rndis_bss_info_update(usbdev, bssid);
1728
1729 bssid = (void *)bssid + bssid_len;
1730 bssid_len = le32_to_cpu(bssid->length);
1731 count--;
1732 }
1733
1734out:
1735 kfree(buf);
1736 return ret;
1737}
1738
1739
1740static void rndis_get_scan_results(struct work_struct *work)
1741{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001742 struct rndis_wlan_private *priv =
1743 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001744 struct usbnet *usbdev = priv->usbdev;
1745 int ret;
1746
1747 devdbg(usbdev, "get_scan_results");
1748
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03001749 if (!priv->scan_request)
1750 return;
1751
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001752 ret = rndis_check_bssid_list(usbdev);
1753
1754 cfg80211_scan_done(priv->scan_request, ret < 0);
1755
1756 priv->scan_request = NULL;
1757}
1758
1759
John W. Linville964c1d42009-03-26 23:40:01 +02001760/*
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001761 * wireless extension handlers
1762 */
1763
1764static int rndis_iw_commit(struct net_device *dev,
1765 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1766{
1767 /* dummy op */
1768 return 0;
1769}
1770
1771
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001772static int rndis_iw_set_essid(struct net_device *dev,
1773 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1774{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001775 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001776 int length = wrqu->essid.length;
Wang Chen524ad0a2008-11-12 23:39:10 -08001777 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001778
1779 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1780 wrqu->essid.flags, wrqu->essid.length, essid);
1781
1782 if (length > NDIS_802_11_LENGTH_SSID)
1783 length = NDIS_802_11_LENGTH_SSID;
1784
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001785 ssid.length = cpu_to_le32(length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001786 if (length > 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001787 memcpy(ssid.essid, essid, length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001788 else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001789 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001790
1791 set_assoc_params(usbdev);
1792
1793 if (!wrqu->essid.flags || length == 0)
1794 return disassociate(usbdev, 1);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001795 else {
1796 /* Pause and purge rx queue, so we don't pass packets before
1797 * 'media connect'-indication.
1798 */
1799 usbnet_pause_rx(usbdev);
1800 usbnet_purge_paused_rxq(usbdev);
1801
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001802 return set_essid(usbdev, &ssid);
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03001803 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001804}
1805
1806
1807static int rndis_iw_get_essid(struct net_device *dev,
1808 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1809{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001810 struct ndis_80211_ssid ssid;
Wang Chen524ad0a2008-11-12 23:39:10 -08001811 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001812 int ret;
1813
1814 ret = get_essid(usbdev, &ssid);
1815
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001816 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001817 wrqu->essid.flags = 1;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001818 wrqu->essid.length = le32_to_cpu(ssid.length);
1819 memcpy(essid, ssid.essid, wrqu->essid.length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001820 essid[wrqu->essid.length] = 0;
1821 } else {
1822 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1823 wrqu->essid.flags = 0;
1824 wrqu->essid.length = 0;
1825 }
1826 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1827 return ret;
1828}
1829
1830
1831static int rndis_iw_get_bssid(struct net_device *dev,
1832 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1833{
Wang Chen524ad0a2008-11-12 23:39:10 -08001834 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001835 unsigned char bssid[ETH_ALEN];
1836 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001837
1838 ret = get_bssid(usbdev, bssid);
1839
1840 if (ret == 0)
Johannes Berge1749612008-10-27 15:59:26 -07001841 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001842 else
1843 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1844
1845 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1846 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1847
1848 return ret;
1849}
1850
1851
1852static int rndis_iw_set_bssid(struct net_device *dev,
1853 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1854{
Wang Chen524ad0a2008-11-12 23:39:10 -08001855 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001856 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001857 int ret;
1858
Johannes Berge1749612008-10-27 15:59:26 -07001859 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001860
1861 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1862
1863 /* user apps may set ap's mac address, which is not required;
1864 * they may fail to work if this function fails, so return
1865 * success */
1866 if (ret)
1867 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1868
1869 return 0;
1870}
1871
1872
1873static int rndis_iw_set_auth(struct net_device *dev,
1874 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1875{
1876 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001877 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001878 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001879 int ret = -ENOTSUPP;
1880
1881 switch (p->flags & IW_AUTH_INDEX) {
1882 case IW_AUTH_WPA_VERSION:
1883 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1884 priv->wpa_version = p->value;
1885 ret = 0;
1886 break;
1887
1888 case IW_AUTH_CIPHER_PAIRWISE:
1889 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1890 priv->wpa_cipher_pair = p->value;
1891 ret = 0;
1892 break;
1893
1894 case IW_AUTH_CIPHER_GROUP:
1895 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1896 priv->wpa_cipher_group = p->value;
1897 ret = 0;
1898 break;
1899
1900 case IW_AUTH_KEY_MGMT:
1901 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1902 priv->wpa_keymgmt = p->value;
1903 ret = 0;
1904 break;
1905
1906 case IW_AUTH_TKIP_COUNTERMEASURES:
1907 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1908 p->value);
1909 ret = 0;
1910 break;
1911
1912 case IW_AUTH_DROP_UNENCRYPTED:
1913 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1914 ret = 0;
1915 break;
1916
1917 case IW_AUTH_80211_AUTH_ALG:
1918 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1919 priv->wpa_authalg = p->value;
1920 ret = 0;
1921 break;
1922
1923 case IW_AUTH_WPA_ENABLED:
1924 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1925 if (wrqu->param.value)
1926 deauthenticate(usbdev);
1927 ret = 0;
1928 break;
1929
1930 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1931 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1932 p->value);
1933 ret = 0;
1934 break;
1935
1936 case IW_AUTH_ROAMING_CONTROL:
1937 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1938 ret = 0;
1939 break;
1940
1941 case IW_AUTH_PRIVACY_INVOKED:
1942 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1943 wrqu->param.flags & IW_AUTH_INDEX);
1944 return -EOPNOTSUPP;
1945
1946 default:
1947 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1948 p->flags & IW_AUTH_INDEX, p->value);
1949 }
1950 return ret;
1951}
1952
1953
1954static int rndis_iw_get_auth(struct net_device *dev,
1955 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1956{
1957 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001958 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001959 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001960
1961 switch (p->flags & IW_AUTH_INDEX) {
1962 case IW_AUTH_WPA_VERSION:
1963 p->value = priv->wpa_version;
1964 break;
1965 case IW_AUTH_CIPHER_PAIRWISE:
1966 p->value = priv->wpa_cipher_pair;
1967 break;
1968 case IW_AUTH_CIPHER_GROUP:
1969 p->value = priv->wpa_cipher_group;
1970 break;
1971 case IW_AUTH_KEY_MGMT:
1972 p->value = priv->wpa_keymgmt;
1973 break;
1974 case IW_AUTH_80211_AUTH_ALG:
1975 p->value = priv->wpa_authalg;
1976 break;
1977 default:
1978 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1979 wrqu->param.flags & IW_AUTH_INDEX);
1980 return -EOPNOTSUPP;
1981 }
1982 return 0;
1983}
1984
1985
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001986static int rndis_iw_set_encode(struct net_device *dev,
1987 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1988{
Wang Chen524ad0a2008-11-12 23:39:10 -08001989 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001990 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001991 struct rndis_wlan_encr_key key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001992 int ret, index, key_len;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03001993 u8 *keybuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001994
1995 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
1996
1997 /* iwconfig gives index as 1 - N */
1998 if (index > 0)
1999 index--;
2000 else
2001 index = priv->encr_tx_key_index;
2002
2003 if (index < 0 || index >= 4) {
2004 devwarn(usbdev, "encryption index out of range (%u)", index);
2005 return -EINVAL;
2006 }
2007
2008 /* remove key if disabled */
2009 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
2010 if (remove_key(usbdev, index, NULL))
2011 return -EINVAL;
2012 else
2013 return 0;
2014 }
2015
2016 /* global encryption state (for all keys) */
2017 if (wrqu->data.flags & IW_ENCODE_OPEN)
2018 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
2019 IW_AUTH_ALG_OPEN_SYSTEM);
2020 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
2021 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
2022 IW_AUTH_ALG_SHARED_KEY);
2023 if (ret != 0)
2024 return ret;
2025
2026 if (wrqu->data.length > 0) {
2027 key_len = wrqu->data.length;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002028 keybuf = extra;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002029 } else {
2030 /* must be set as tx key */
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002031 if (priv->encr_keys[index].len == 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002032 return -EINVAL;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002033 key = priv->encr_keys[index];
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002034 key_len = key.len;
2035 keybuf = key.material;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002036 priv->encr_tx_key_index = index;
2037 }
2038
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002039 if (add_wep_key(usbdev, keybuf, key_len, index) != 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002040 return -EINVAL;
2041
2042 if (index == priv->encr_tx_key_index)
2043 /* ndis drivers want essid to be set after setting encr */
2044 set_essid(usbdev, &priv->essid);
2045
2046 return 0;
2047}
2048
2049
2050static int rndis_iw_set_encode_ext(struct net_device *dev,
2051 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2052{
2053 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
Wang Chen524ad0a2008-11-12 23:39:10 -08002054 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002055 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002056 int keyidx, flags, cipher;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002057
2058 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
2059
2060 /* iwconfig gives index as 1 - N */
2061 if (keyidx)
2062 keyidx--;
2063 else
2064 keyidx = priv->encr_tx_key_index;
2065
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002066 if (keyidx < 0 || keyidx >= 4) {
2067 devwarn(usbdev, "encryption index out of range (%u)", keyidx);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002068 return -EINVAL;
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002069 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002070
2071 if (ext->alg == WPA_ALG_WEP) {
2072 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2073 priv->encr_tx_key_index = keyidx;
2074 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
2075 }
2076
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002077 cipher = -1;
2078 if (ext->alg == IW_ENCODE_ALG_TKIP)
2079 cipher = WLAN_CIPHER_SUITE_TKIP;
2080 else if (ext->alg == IW_ENCODE_ALG_CCMP)
2081 cipher = WLAN_CIPHER_SUITE_CCMP;
2082
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002083 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
2084 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
2085 return remove_key(usbdev, keyidx, NULL);
2086
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002087 if (cipher == -1)
2088 return -EOPNOTSUPP;
2089
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002090 flags = 0;
2091 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002092 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03002093 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002094 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002095 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002096 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002097
Jussi Kivilinnab7cfc5b2009-07-30 19:42:08 +03002098 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx,
2099 (u8 *)&ext->addr.sa_data, ext->rx_seq, cipher,
2100 flags);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002101}
2102
2103
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002104static int rndis_iw_set_genie(struct net_device *dev,
2105 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2106{
Wang Chen524ad0a2008-11-12 23:39:10 -08002107 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002108 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002109 int ret = 0;
2110
2111#ifdef DEBUG
2112 int j;
2113 u8 *gie = extra;
2114 for (j = 0; j < wrqu->data.length; j += 8)
2115 devdbg(usbdev,
2116 "SIOCSIWGENIE %04x - "
2117 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
2118 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
2119 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
2120#endif
2121 /* clear existing IEs */
2122 if (priv->wpa_ie_len) {
2123 kfree(priv->wpa_ie);
2124 priv->wpa_ie_len = 0;
2125 }
2126
2127 /* set new IEs */
2128 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
2129 if (priv->wpa_ie) {
2130 priv->wpa_ie_len = wrqu->data.length;
2131 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
2132 } else
2133 ret = -ENOMEM;
2134 return ret;
2135}
2136
2137
2138static int rndis_iw_get_genie(struct net_device *dev,
2139 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2140{
Wang Chen524ad0a2008-11-12 23:39:10 -08002141 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002142 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002143
2144 devdbg(usbdev, "SIOCGIWGENIE");
2145
2146 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
2147 wrqu->data.length = 0;
2148 return 0;
2149 }
2150
2151 if (wrqu->data.length < priv->wpa_ie_len)
2152 return -E2BIG;
2153
2154 wrqu->data.length = priv->wpa_ie_len;
2155 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
2156
2157 return 0;
2158}
2159
2160
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002161static int rndis_iw_set_freq(struct net_device *dev,
2162 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2163{
Wang Chen524ad0a2008-11-12 23:39:10 -08002164 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002165 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002166 unsigned int dsconfig;
2167 int len, ret;
2168
2169 /* this OID is valid only when not associated */
2170 if (is_associated(usbdev))
2171 return 0;
2172
2173 dsconfig = 0;
2174 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
2175 return -EINVAL;
2176
2177 len = sizeof(config);
2178 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2179 if (ret != 0) {
2180 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
2181 return 0;
2182 }
2183
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002184 config.ds_config = cpu_to_le32(dsconfig);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002185
2186 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
2187 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
2188 sizeof(config));
2189}
2190
2191
2192static int rndis_iw_get_freq(struct net_device *dev,
2193 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2194{
Wang Chen524ad0a2008-11-12 23:39:10 -08002195 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02002196 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002197 int len, ret;
2198
2199 len = sizeof(config);
2200 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
2201 if (ret == 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02002202 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002203
2204 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
2205 return ret;
2206}
2207
2208
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002209static int rndis_iw_get_rate(struct net_device *dev,
2210 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2211{
Wang Chen524ad0a2008-11-12 23:39:10 -08002212 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002213 __le32 tmp;
2214 int ret, len;
2215
2216 len = sizeof(tmp);
2217 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
2218 if (ret == 0) {
2219 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
2220 wrqu->bitrate.disabled = 0;
2221 wrqu->bitrate.flags = 1;
2222 }
2223 return ret;
2224}
2225
2226
2227static int rndis_iw_set_mlme(struct net_device *dev,
2228 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
2229{
Wang Chen524ad0a2008-11-12 23:39:10 -08002230 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002231 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002232 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2233 unsigned char bssid[ETH_ALEN];
2234
2235 get_bssid(usbdev, bssid);
2236
2237 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
2238 return -EINVAL;
2239
2240 switch (mlme->cmd) {
2241 case IW_MLME_DEAUTH:
2242 return deauthenticate(usbdev);
2243 case IW_MLME_DISASSOC:
2244 return disassociate(usbdev, priv->radio_on);
2245 default:
2246 return -EOPNOTSUPP;
2247 }
2248
2249 return 0;
2250}
2251
2252
2253static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
2254{
Wang Chen524ad0a2008-11-12 23:39:10 -08002255 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002256 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002257 unsigned long flags;
2258
2259 spin_lock_irqsave(&priv->stats_lock, flags);
2260 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2261 spin_unlock_irqrestore(&priv->stats_lock, flags);
2262
2263 return &priv->iwstats;
2264}
2265
2266
2267#define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2268static const iw_handler rndis_iw_handler[] =
2269{
2270 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002271 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002272 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2273 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
John W. Linville964c1d42009-03-26 23:40:01 +02002274 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2275 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002276 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002277 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2278 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002279 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2280 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002281 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2282 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002283 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002284 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2285 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2286 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2287 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03002288 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2289 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002290 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2291 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2292 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2293 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2294 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2295 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2296 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2297};
2298
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002299static const iw_handler rndis_wlan_private_handler[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002300};
2301
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002302static const struct iw_priv_args rndis_wlan_private_args[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002303};
2304
2305
2306static const struct iw_handler_def rndis_iw_handlers = {
2307 .num_standard = ARRAY_SIZE(rndis_iw_handler),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002308 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2309 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002310 .standard = (iw_handler *)rndis_iw_handler,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002311 .private = (iw_handler *)rndis_wlan_private_handler,
2312 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002313 .get_wireless_stats = rndis_get_wireless_stats,
2314};
2315
2316
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002317static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002318{
Scott Ashcroft43646232008-05-27 00:06:15 +03002319 struct ndis_80211_assoc_info *info;
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002320 union iwreq_data evt;
2321 u8 assoc_buf[sizeof(*info) + IW_CUSTOM_MAX + 32];
2322 u8 bssid[ETH_ALEN];
Scott Ashcroft43646232008-05-27 00:06:15 +03002323 int ret, offset;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002324
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002325 memset(assoc_buf, 0, sizeof(assoc_buf));
2326 info = (void *)assoc_buf;
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002327
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002328 netif_carrier_on(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002329
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002330 /* Get association info IEs from device and send them back to
2331 * userspace. */
2332 ret = get_association_info(usbdev, info, sizeof(assoc_buf));
2333 if (!ret) {
2334 evt.data.length = le32_to_cpu(info->req_ie_length);
2335 if (evt.data.length > 0) {
2336 offset = le32_to_cpu(info->offset_req_ies);
2337 wireless_send_event(usbdev->net,
2338 IWEVASSOCREQIE, &evt,
2339 (char *)info + offset);
Scott Ashcroft43646232008-05-27 00:06:15 +03002340 }
2341
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002342 evt.data.length = le32_to_cpu(info->resp_ie_length);
2343 if (evt.data.length > 0) {
2344 offset = le32_to_cpu(info->offset_resp_ies);
2345 wireless_send_event(usbdev->net,
2346 IWEVASSOCRESPIE, &evt,
2347 (char *)info + offset);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002348 }
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002349
2350 usbnet_resume_rx(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002351 }
2352
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002353 ret = get_bssid(usbdev, bssid);
2354 if (!ret) {
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002355 evt.data.flags = 0;
2356 evt.data.length = 0;
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002357 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002358 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2359 }
2360
Jussi Kivilinna0848e6c2009-08-28 12:59:10 +03002361 usbnet_resume_rx(usbdev);
2362}
2363
2364static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
2365{
2366 union iwreq_data evt;
2367
2368 netif_carrier_off(usbdev->net);
2369
2370 evt.data.flags = 0;
2371 evt.data.length = 0;
2372 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2373 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2374}
2375
2376static void rndis_wlan_worker(struct work_struct *work)
2377{
2378 struct rndis_wlan_private *priv =
2379 container_of(work, struct rndis_wlan_private, work);
2380 struct usbnet *usbdev = priv->usbdev;
2381
2382 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
2383 rndis_wlan_do_link_up_work(usbdev);
2384
2385 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
2386 rndis_wlan_do_link_down_work(usbdev);
2387
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002388 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2389 set_multicast_list(usbdev);
2390}
2391
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002392static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002393{
Wang Chen524ad0a2008-11-12 23:39:10 -08002394 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002395 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002396
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002397 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2398 return;
2399
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002400 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2401 queue_work(priv->workqueue, &priv->work);
2402}
2403
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002404
2405static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2406 struct ndis_80211_status_indication *indication,
2407 int len)
2408{
2409 u8 *buf;
2410 const char *type;
2411 int flags, buflen;
2412 bool pairwise_error, group_error;
2413 struct ndis_80211_auth_request *auth_req;
2414
2415 /* must have at least one array entry */
2416 if (len < offsetof(struct ndis_80211_status_indication, u) +
2417 sizeof(struct ndis_80211_auth_request)) {
2418 devinfo(usbdev, "authentication indication: "
2419 "too short message (%i)", len);
2420 return;
2421 }
2422
2423 buf = (void *)&indication->u.auth_request[0];
2424 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2425
2426 while (buflen >= sizeof(*auth_req)) {
2427 auth_req = (void *)buf;
2428 type = "unknown";
2429 flags = le32_to_cpu(auth_req->flags);
2430 pairwise_error = false;
2431 group_error = false;
2432
2433 if (flags & 0x1)
2434 type = "reauth request";
2435 if (flags & 0x2)
2436 type = "key update request";
2437 if (flags & 0x6) {
2438 pairwise_error = true;
2439 type = "pairwise_error";
2440 }
2441 if (flags & 0xe) {
2442 group_error = true;
2443 type = "group_error";
2444 }
2445
2446 devinfo(usbdev, "authentication indication: %s (0x%08x)", type,
2447 le32_to_cpu(auth_req->flags));
2448
2449 if (pairwise_error || group_error) {
2450 union iwreq_data wrqu;
2451 struct iw_michaelmicfailure micfailure;
2452
2453 memset(&micfailure, 0, sizeof(micfailure));
2454 if (pairwise_error)
2455 micfailure.flags |= IW_MICFAILURE_PAIRWISE;
2456 if (group_error)
2457 micfailure.flags |= IW_MICFAILURE_GROUP;
2458
2459 memcpy(micfailure.src_addr.sa_data, auth_req->bssid,
2460 ETH_ALEN);
2461
2462 memset(&wrqu, 0, sizeof(wrqu));
2463 wrqu.data.length = sizeof(micfailure);
2464 wireless_send_event(usbdev->net, IWEVMICHAELMICFAILURE,
2465 &wrqu, (u8 *)&micfailure);
2466 }
2467
2468 buflen -= le32_to_cpu(auth_req->length);
2469 buf += le32_to_cpu(auth_req->length);
2470 }
2471}
2472
2473static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2474 struct ndis_80211_status_indication *indication,
2475 int len)
2476{
2477 struct ndis_80211_pmkid_cand_list *cand_list;
2478 int list_len, expected_len, i;
2479
2480 if (len < offsetof(struct ndis_80211_status_indication, u) +
2481 sizeof(struct ndis_80211_pmkid_cand_list)) {
2482 devinfo(usbdev, "pmkid candidate list indication: "
2483 "too short message (%i)", len);
2484 return;
2485 }
2486
2487 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2488 sizeof(struct ndis_80211_pmkid_candidate);
2489 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2490 offsetof(struct ndis_80211_status_indication, u);
2491
2492 if (len < expected_len) {
2493 devinfo(usbdev, "pmkid candidate list indication: "
2494 "list larger than buffer (%i < %i)",
2495 len, expected_len);
2496 return;
2497 }
2498
2499 cand_list = &indication->u.cand_list;
2500
2501 devinfo(usbdev, "pmkid candidate list indication: "
2502 "version %i, candidates %i",
2503 le32_to_cpu(cand_list->version),
2504 le32_to_cpu(cand_list->num_candidates));
2505
2506 if (le32_to_cpu(cand_list->version) != 1)
2507 return;
2508
2509 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
2510 struct iw_pmkid_cand pcand;
2511 union iwreq_data wrqu;
2512 struct ndis_80211_pmkid_candidate *cand =
2513 &cand_list->candidate_list[i];
2514
2515 devdbg(usbdev, "cand[%i]: flags: 0x%08x, bssid: %pM",
2516 i, le32_to_cpu(cand->flags), cand->bssid);
2517
2518 memset(&pcand, 0, sizeof(pcand));
2519 if (le32_to_cpu(cand->flags) & 0x01)
2520 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2521 pcand.index = i;
2522 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2523
2524 memset(&wrqu, 0, sizeof(wrqu));
2525 wrqu.data.length = sizeof(pcand);
2526 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2527 (u8 *)&pcand);
2528 }
2529}
2530
2531static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2532 struct rndis_indicate *msg, int buflen)
2533{
2534 struct ndis_80211_status_indication *indication;
2535 int len, offset;
2536
2537 offset = offsetof(struct rndis_indicate, status) +
2538 le32_to_cpu(msg->offset);
2539 len = le32_to_cpu(msg->length);
2540
2541 if (len < 8) {
2542 devinfo(usbdev, "media specific indication, "
2543 "ignore too short message (%i < 8)", len);
2544 return;
2545 }
2546
2547 if (offset + len > buflen) {
2548 devinfo(usbdev, "media specific indication, "
2549 "too large to fit to buffer (%i > %i)",
2550 offset + len, buflen);
2551 return;
2552 }
2553
2554 indication = (void *)((u8 *)msg + offset);
2555
2556 switch (le32_to_cpu(indication->status_type)) {
2557 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2558 devinfo(usbdev, "radio state indication: %i",
2559 le32_to_cpu(indication->u.radio_status));
2560 return;
2561
2562 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2563 devinfo(usbdev, "media stream mode indication: %i",
2564 le32_to_cpu(indication->u.media_stream_mode));
2565 return;
2566
2567 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2568 rndis_wlan_auth_indication(usbdev, indication, len);
2569 return;
2570
2571 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2572 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2573 return;
2574
2575 default:
2576 devinfo(usbdev, "media specific indication: "
2577 "unknown status type 0x%08x",
2578 le32_to_cpu(indication->status_type));
2579 }
2580}
2581
2582
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002583static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002584{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002585 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002586 struct rndis_indicate *msg = ind;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002587
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002588 switch (msg->status) {
2589 case RNDIS_STATUS_MEDIA_CONNECT:
Jussi Kivilinna5f81ff52009-08-28 12:58:49 +03002590 if (priv->current_command_oid == OID_802_11_ADD_KEY) {
2591 /* OID_802_11_ADD_KEY causes sometimes extra
2592 * "media connect" indications which confuses driver
2593 * and userspace to think that device is
2594 * roaming/reassociating when it isn't.
2595 */
2596 devdbg(usbdev, "ignored OID_802_11_ADD_KEY triggered "
2597 "'media connect'");
2598 return;
2599 }
2600
Jussi Kivilinna7834ddb2009-08-11 22:57:16 +03002601 usbnet_pause_rx(usbdev);
2602
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002603 devinfo(usbdev, "media connect");
2604
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002605 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002606 set_bit(WORK_LINK_UP, &priv->work_pending);
2607 queue_work(priv->workqueue, &priv->work);
2608 break;
2609
2610 case RNDIS_STATUS_MEDIA_DISCONNECT:
2611 devinfo(usbdev, "media disconnect");
2612
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002613 /* queue work to avoid recursive calls into rndis_command */
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002614 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2615 queue_work(priv->workqueue, &priv->work);
2616 break;
2617
Jussi Kivilinna030645a2009-07-30 19:41:58 +03002618 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2619 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2620 break;
2621
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03002622 default:
2623 devinfo(usbdev, "indication: 0x%08x",
2624 le32_to_cpu(msg->status));
2625 break;
2626 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002627}
2628
2629
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002630static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002631{
2632 struct {
2633 __le32 num_items;
2634 __le32 items[8];
2635 } networks_supported;
2636 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002637 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002638
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002639 /* determine supported modes */
2640 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002641 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002642 &networks_supported, &len);
2643 if (retval >= 0) {
2644 n = le32_to_cpu(networks_supported.num_items);
2645 if (n > 8)
2646 n = 8;
2647 for (i = 0; i < n; i++) {
2648 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002649 case NDIS_80211_TYPE_FREQ_HOP:
2650 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002651 priv->caps |= CAP_MODE_80211B;
2652 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002653 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002654 priv->caps |= CAP_MODE_80211A;
2655 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002656 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002657 priv->caps |= CAP_MODE_80211G;
2658 break;
2659 }
2660 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002661 }
2662
2663 return retval;
2664}
2665
2666
2667#define STATS_UPDATE_JIFFIES (HZ)
2668static void rndis_update_wireless_stats(struct work_struct *work)
2669{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002670 struct rndis_wlan_private *priv =
2671 container_of(work, struct rndis_wlan_private, stats_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002672 struct usbnet *usbdev = priv->usbdev;
2673 struct iw_statistics iwstats;
2674 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002675 int len, ret, j;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002676 unsigned long flags;
2677 int update_jiffies = STATS_UPDATE_JIFFIES;
2678 void *buf;
2679
2680 spin_lock_irqsave(&priv->stats_lock, flags);
2681 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2682 spin_unlock_irqrestore(&priv->stats_lock, flags);
2683
2684 /* only update stats when connected */
2685 if (!is_associated(usbdev)) {
2686 iwstats.qual.qual = 0;
2687 iwstats.qual.level = 0;
2688 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2689 | IW_QUAL_LEVEL_UPDATED
2690 | IW_QUAL_NOISE_INVALID
2691 | IW_QUAL_QUAL_INVALID
2692 | IW_QUAL_LEVEL_INVALID;
2693 goto end;
2694 }
2695
2696 len = sizeof(rssi);
2697 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2698
2699 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2700 le32_to_cpu(rssi));
2701 if (ret == 0) {
2702 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2703 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinna4bd7f032009-03-26 23:40:16 +02002704 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002705 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2706 | IW_QUAL_LEVEL_UPDATED
2707 | IW_QUAL_NOISE_INVALID;
2708 }
2709
2710 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2711
2712 len = sizeof(tmp);
2713 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2714 if (ret == 0)
2715 iwstats.discard.misc += le32_to_cpu(tmp);
2716
2717 len = sizeof(tmp);
2718 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2719 if (ret == 0)
2720 iwstats.discard.misc += le32_to_cpu(tmp);
2721
2722 len = sizeof(tmp);
2723 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2724 if (ret == 0)
2725 iwstats.discard.misc += le32_to_cpu(tmp);
2726
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002727 /* Workaround transfer stalls on poor quality links.
2728 * TODO: find right way to fix these stalls (as stalls do not happen
2729 * with ndiswrapper/windows driver). */
2730 if (iwstats.qual.qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002731 /* Decrease stats worker interval to catch stalls.
2732 * faster. Faster than 400-500ms causes packet loss,
2733 * Slower doesn't catch stalls fast enough.
2734 */
2735 j = msecs_to_jiffies(priv->param_workaround_interval);
2736 if (j > STATS_UPDATE_JIFFIES)
2737 j = STATS_UPDATE_JIFFIES;
2738 else if (j <= 0)
2739 j = 1;
2740 update_jiffies = j;
2741
2742 /* Send scan OID. Use of both OIDs is required to get device
2743 * working.
2744 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08002745 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002746 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2747 sizeof(tmp));
2748
2749 len = CONTROL_BUFFER_SIZE;
2750 buf = kmalloc(len, GFP_KERNEL);
2751 if (!buf)
2752 goto end;
2753
2754 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2755 kfree(buf);
2756 }
2757end:
2758 spin_lock_irqsave(&priv->stats_lock, flags);
2759 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2760 spin_unlock_irqrestore(&priv->stats_lock, flags);
2761
2762 if (update_jiffies >= HZ)
2763 update_jiffies = round_jiffies_relative(update_jiffies);
2764 else {
2765 j = round_jiffies_relative(update_jiffies);
2766 if (abs(j - update_jiffies) <= 10)
2767 update_jiffies = j;
2768 }
2769
2770 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2771}
2772
2773
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002774static int bcm4320a_early_init(struct usbnet *usbdev)
2775{
2776 /* bcm4320a doesn't handle configuration parameters well. Try
2777 * set any and you get partially zeroed mac and broken device.
2778 */
2779
2780 return 0;
2781}
2782
2783
2784static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002785{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002786 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002787 char buf[8];
2788
2789 /* Early initialization settings, setting these won't have effect
2790 * if called after generic_rndis_bind().
2791 */
2792
2793 priv->param_country[0] = modparam_country[0];
2794 priv->param_country[1] = modparam_country[1];
2795 priv->param_country[2] = 0;
2796 priv->param_frameburst = modparam_frameburst;
2797 priv->param_afterburner = modparam_afterburner;
2798 priv->param_power_save = modparam_power_save;
2799 priv->param_power_output = modparam_power_output;
2800 priv->param_roamtrigger = modparam_roamtrigger;
2801 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002802
2803 priv->param_country[0] = toupper(priv->param_country[0]);
2804 priv->param_country[1] = toupper(priv->param_country[1]);
2805 /* doesn't support EU as country code, use FI instead */
2806 if (!strcmp(priv->param_country, "EU"))
2807 strcpy(priv->param_country, "FI");
2808
2809 if (priv->param_power_save < 0)
2810 priv->param_power_save = 0;
2811 else if (priv->param_power_save > 2)
2812 priv->param_power_save = 2;
2813
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03002814 if (priv->param_power_output < 0)
2815 priv->param_power_output = 0;
2816 else if (priv->param_power_output > 3)
2817 priv->param_power_output = 3;
2818
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002819 if (priv->param_roamtrigger < -80)
2820 priv->param_roamtrigger = -80;
2821 else if (priv->param_roamtrigger > -60)
2822 priv->param_roamtrigger = -60;
2823
2824 if (priv->param_roamdelta < 0)
2825 priv->param_roamdelta = 0;
2826 else if (priv->param_roamdelta > 2)
2827 priv->param_roamdelta = 2;
2828
Roel Kluin4d381ff2008-04-23 22:10:29 +02002829 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002830 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02002831 else
2832 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002833
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002834 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2835 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002836 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002837 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002838 priv->param_afterburner ? "1" : "0");
2839 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002840 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002841 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002842 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002843 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002844 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002845 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002846 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002847
2848 return 0;
2849}
2850
David S. Miller23d12e22009-03-25 00:03:16 -07002851/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002852static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07002853 .ndo_open = usbnet_open,
2854 .ndo_stop = usbnet_stop,
2855 .ndo_start_xmit = usbnet_start_xmit,
2856 .ndo_tx_timeout = usbnet_tx_timeout,
2857 .ndo_set_mac_address = eth_mac_addr,
2858 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002859 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07002860};
2861
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002862
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002863static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002864{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002865 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002866 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002867 int retval, len;
2868 __le32 tmp;
2869
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002870 /* allocate wiphy and rndis private data
2871 * NOTE: We only support a single virtual interface, so wiphy
2872 * and wireless_dev are somewhat synonymous for this device.
2873 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002874 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002875 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002876 return -ENOMEM;
2877
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002878 priv = wiphy_priv(wiphy);
2879 usbdev->net->ieee80211_ptr = &priv->wdev;
2880 priv->wdev.wiphy = wiphy;
2881 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2882
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002883 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002884 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002885 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002886 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002887 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2888 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002889
2890 mutex_init(&priv->command_lock);
2891 spin_lock_init(&priv->stats_lock);
2892
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002893 /* because rndis_command() sleeps we need to use workqueue */
2894 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002895 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002896 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2897 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2898
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002899 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002900 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002901 if (retval < 0)
2902 goto fail;
2903
2904 /* generic_rndis_bind set packet filter to multicast_all+
2905 * promisc mode which doesn't work well for our devices (device
2906 * picks up rssi to closest station instead of to access point).
2907 *
2908 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002909 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002910 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002911 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07002912
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002913 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002914 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002915 sizeof(tmp));
2916
2917 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002918 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2919 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002920 priv->multicast_size = le32_to_cpu(tmp);
2921 if (retval < 0 || priv->multicast_size < 0)
2922 priv->multicast_size = 0;
2923 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002924 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002925 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002926 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002927
2928 priv->iwstats.qual.qual = 0;
2929 priv->iwstats.qual.level = 0;
2930 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2931 | IW_QUAL_LEVEL_UPDATED
2932 | IW_QUAL_NOISE_INVALID
2933 | IW_QUAL_QUAL_INVALID
2934 | IW_QUAL_LEVEL_INVALID;
2935
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002936 /* fill-out wiphy structure and register w/ cfg80211 */
2937 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2938 wiphy->privid = rndis_wiphy_privid;
2939 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2940 | BIT(NL80211_IFTYPE_ADHOC);
2941 wiphy->max_scan_ssids = 1;
2942
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002943 /* TODO: fill-out band/encr information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002944 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002945
2946 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2947 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2948 priv->band.channels = priv->channels;
2949 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2950 priv->band.bitrates = priv->rates;
2951 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2952 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002953 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002954
Jussi Kivilinna4a7f13e2009-08-26 15:53:02 +03002955 memcpy(priv->cipher_suites, rndis_cipher_suites,
2956 sizeof(rndis_cipher_suites));
2957 wiphy->cipher_suites = priv->cipher_suites;
2958 wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
2959
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002960 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2961
2962 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002963 retval = -ENODEV;
2964 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002965 }
2966
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002967 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002968
Jussi Kivilinnad75ec2b2009-06-16 17:17:21 +03002969 /* set default rts/frag */
2970 rndis_set_wiphy_params(wiphy,
2971 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2972
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002973 /* turn radio on */
2974 priv->radio_on = 1;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002975 disassociate(usbdev, 1);
2976 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002977
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002978 return 0;
2979
2980fail:
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002981 cancel_delayed_work_sync(&priv->stats_work);
2982 cancel_delayed_work_sync(&priv->scan_work);
2983 cancel_work_sync(&priv->work);
2984 flush_workqueue(priv->workqueue);
2985 destroy_workqueue(priv->workqueue);
2986
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002987 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002988 return retval;
2989}
2990
2991
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002992static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002993{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002994 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002995
2996 /* turn radio off */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002997 disassociate(usbdev, 0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002998
2999 cancel_delayed_work_sync(&priv->stats_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02003000 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003001 cancel_work_sync(&priv->work);
3002 flush_workqueue(priv->workqueue);
3003 destroy_workqueue(priv->workqueue);
3004
3005 if (priv && priv->wpa_ie_len)
3006 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003007
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003008 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02003009
3010 wiphy_unregister(priv->wdev.wiphy);
3011 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003012}
3013
3014
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003015static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003016{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003017 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003018 int retval;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003019
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003020 devdbg(usbdev, "rndis_wlan_reset");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003021
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003022 retval = rndis_reset(usbdev);
3023 if (retval)
3024 devwarn(usbdev, "rndis_reset() failed: %d", retval);
3025
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003026 /* rndis_reset cleared multicast list, so restore here.
3027 (set_multicast_list() also turns on current packet filter) */
Jussi Kivilinna7eaab702009-07-30 19:41:37 +03003028 set_multicast_list(usbdev);
3029
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003030 queue_delayed_work(priv->workqueue, &priv->stats_work,
3031 round_jiffies_relative(STATS_UPDATE_JIFFIES));
3032
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03003033 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003034}
3035
3036
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003037static int rndis_wlan_stop(struct usbnet *usbdev)
3038{
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003039 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
3040 int retval;
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003041 __le32 filter;
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003042
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003043 devdbg(usbdev, "rndis_wlan_stop");
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003044
3045 retval = disassociate(usbdev, 0);
3046
3047 priv->work_pending = 0;
3048 cancel_delayed_work_sync(&priv->stats_work);
3049 cancel_delayed_work_sync(&priv->scan_work);
3050 cancel_work_sync(&priv->work);
3051 flush_workqueue(priv->workqueue);
3052
Jussi Kivilinna005ba2f2009-07-30 19:41:31 +03003053 if (priv->scan_request) {
3054 cfg80211_scan_done(priv->scan_request, true);
3055 priv->scan_request = NULL;
3056 }
3057
Jussi Kivilinnae5a11a82009-07-30 19:41:42 +03003058 /* Set current packet filter zero to block receiving data packets from
3059 device. */
3060 filter = 0;
3061 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
3062 sizeof(filter));
3063
Jussi Kivilinna110736d2009-07-30 19:41:26 +03003064 return retval;
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003065}
3066
3067
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003068static const struct driver_info bcm4320b_info = {
3069 .description = "Wireless RNDIS device, BCM4320b based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003070 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3071 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003072 .bind = rndis_wlan_bind,
3073 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003074 .status = rndis_status,
3075 .rx_fixup = rndis_rx_fixup,
3076 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003077 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003078 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003079 .early_init = bcm4320b_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003080 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003081};
3082
3083static const struct driver_info bcm4320a_info = {
3084 .description = "Wireless RNDIS device, BCM4320a based",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003085 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3086 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003087 .bind = rndis_wlan_bind,
3088 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003089 .status = rndis_status,
3090 .rx_fixup = rndis_rx_fixup,
3091 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003092 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003093 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003094 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003095 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003096};
3097
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003098static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003099 .description = "Wireless RNDIS device",
Jussi Kivilinna1487cd52009-07-30 19:41:20 +03003100 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
3101 FLAG_AVOID_UNLINK_URBS,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003102 .bind = rndis_wlan_bind,
3103 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003104 .status = rndis_status,
3105 .rx_fixup = rndis_rx_fixup,
3106 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003107 .reset = rndis_wlan_reset,
Jussi Kivilinna222ec502009-06-16 17:17:32 +03003108 .stop = rndis_wlan_stop,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03003109 .early_init = bcm4320a_early_init,
Jussi Kivilinna2a4901b2009-07-30 19:41:52 +03003110 .indication = rndis_wlan_indication,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003111};
3112
3113/*-------------------------------------------------------------------------*/
3114
3115static const struct usb_device_id products [] = {
3116#define RNDIS_MASTER_INTERFACE \
3117 .bInterfaceClass = USB_CLASS_COMM, \
3118 .bInterfaceSubClass = 2 /* ACM */, \
3119 .bInterfaceProtocol = 0x0ff
3120
3121/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
3122 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
3123 */
3124{
3125 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3126 | USB_DEVICE_ID_MATCH_DEVICE,
3127 .idVendor = 0x0411,
3128 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
3129 RNDIS_MASTER_INTERFACE,
3130 .driver_info = (unsigned long) &bcm4320b_info,
3131}, {
3132 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3133 | USB_DEVICE_ID_MATCH_DEVICE,
3134 .idVendor = 0x0baf,
3135 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
3136 RNDIS_MASTER_INTERFACE,
3137 .driver_info = (unsigned long) &bcm4320b_info,
3138}, {
3139 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3140 | USB_DEVICE_ID_MATCH_DEVICE,
3141 .idVendor = 0x050d,
3142 .idProduct = 0x011b, /* Belkin F5D7051 */
3143 RNDIS_MASTER_INTERFACE,
3144 .driver_info = (unsigned long) &bcm4320b_info,
3145}, {
3146 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3147 | USB_DEVICE_ID_MATCH_DEVICE,
3148 .idVendor = 0x1799, /* Belkin has two vendor ids */
3149 .idProduct = 0x011b, /* Belkin F5D7051 */
3150 RNDIS_MASTER_INTERFACE,
3151 .driver_info = (unsigned long) &bcm4320b_info,
3152}, {
3153 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3154 | USB_DEVICE_ID_MATCH_DEVICE,
3155 .idVendor = 0x13b1,
3156 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
3157 RNDIS_MASTER_INTERFACE,
3158 .driver_info = (unsigned long) &bcm4320b_info,
3159}, {
3160 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3161 | USB_DEVICE_ID_MATCH_DEVICE,
3162 .idVendor = 0x13b1,
3163 .idProduct = 0x0026, /* Linksys WUSB54GSC */
3164 RNDIS_MASTER_INTERFACE,
3165 .driver_info = (unsigned long) &bcm4320b_info,
3166}, {
3167 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3168 | USB_DEVICE_ID_MATCH_DEVICE,
3169 .idVendor = 0x0b05,
3170 .idProduct = 0x1717, /* Asus WL169gE */
3171 RNDIS_MASTER_INTERFACE,
3172 .driver_info = (unsigned long) &bcm4320b_info,
3173}, {
3174 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3175 | USB_DEVICE_ID_MATCH_DEVICE,
3176 .idVendor = 0x0a5c,
3177 .idProduct = 0xd11b, /* Eminent EM4045 */
3178 RNDIS_MASTER_INTERFACE,
3179 .driver_info = (unsigned long) &bcm4320b_info,
3180}, {
3181 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3182 | USB_DEVICE_ID_MATCH_DEVICE,
3183 .idVendor = 0x1690,
3184 .idProduct = 0x0715, /* BT Voyager 1055 */
3185 RNDIS_MASTER_INTERFACE,
3186 .driver_info = (unsigned long) &bcm4320b_info,
3187},
3188/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3189 * parameters available, hardware probably contain older firmware version with
3190 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3191 */
3192{
3193 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3194 | USB_DEVICE_ID_MATCH_DEVICE,
3195 .idVendor = 0x13b1,
3196 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3197 RNDIS_MASTER_INTERFACE,
3198 .driver_info = (unsigned long) &bcm4320a_info,
3199}, {
3200 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3201 | USB_DEVICE_ID_MATCH_DEVICE,
3202 .idVendor = 0x0baf,
3203 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3204 RNDIS_MASTER_INTERFACE,
3205 .driver_info = (unsigned long) &bcm4320a_info,
3206}, {
3207 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3208 | USB_DEVICE_ID_MATCH_DEVICE,
3209 .idVendor = 0x0411,
3210 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3211 RNDIS_MASTER_INTERFACE,
3212 .driver_info = (unsigned long) &bcm4320a_info,
3213},
3214/* Generic Wireless RNDIS devices that we don't have exact
3215 * idVendor/idProduct/chip yet.
3216 */
3217{
3218 /* RNDIS is MSFT's un-official variant of CDC ACM */
3219 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003220 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003221}, {
3222 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3223 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03003224 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02003225},
3226 { }, // END
3227};
3228MODULE_DEVICE_TABLE(usb, products);
3229
3230static struct usb_driver rndis_wlan_driver = {
3231 .name = "rndis_wlan",
3232 .id_table = products,
3233 .probe = usbnet_probe,
3234 .disconnect = usbnet_disconnect,
3235 .suspend = usbnet_suspend,
3236 .resume = usbnet_resume,
3237};
3238
3239static int __init rndis_wlan_init(void)
3240{
3241 return usb_register(&rndis_wlan_driver);
3242}
3243module_init(rndis_wlan_init);
3244
3245static void __exit rndis_wlan_exit(void)
3246{
3247 usb_deregister(&rndis_wlan_driver);
3248}
3249module_exit(rndis_wlan_exit);
3250
3251MODULE_AUTHOR("Bjorge Dijkstra");
3252MODULE_AUTHOR("Jussi Kivilinna");
3253MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3254MODULE_LICENSE("GPL");
3255