blob: 3bec3dbd3450cf105e91fbc72c062da7b16e21e7 [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_PERMANENT_ADDRESS cpu_to_le32(0x01010101)
104#define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
105#define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
106#define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200107
Harvey Harrison35c26c22009-02-14 22:56:56 -0800108#define OID_802_11_BSSID cpu_to_le32(0x0d010101)
109#define OID_802_11_SSID cpu_to_le32(0x0d010102)
110#define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
111#define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
112#define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
113#define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
114#define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
115#define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
116#define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
117#define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
118#define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
119#define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
120#define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
121#define OID_802_11_PMKID cpu_to_le32(0x0d010123)
122#define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
123#define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
124#define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
125#define OID_802_11_RSSI cpu_to_le32(0x0d010206)
126#define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
127#define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
128#define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
129#define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
130#define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
131#define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200132
133
134/* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
135#define WL_NOISE -96 /* typical noise level in dBm */
136#define WL_SIGMAX -32 /* typical maximum signal level in dBm */
137
138
139/* Assume that Broadcom 4320 (only chipset at time of writing known to be
140 * based on wireless rndis) has default txpower of 13dBm.
141 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
142 * 13dBm == 19.9mW
143 */
144#define BCM4320_DEFAULT_TXPOWER 20
145
146
147/* codes for "status" field of completion messages */
Harvey Harrison35c26c22009-02-14 22:56:56 -0800148#define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
149#define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200150
151
152/* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
153 * slightly modified for datatype endianess, etc
154 */
155#define NDIS_802_11_LENGTH_SSID 32
156#define NDIS_802_11_LENGTH_RATES 8
157#define NDIS_802_11_LENGTH_RATES_EX 16
158
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200159enum ndis_80211_net_type {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300160 NDIS_80211_TYPE_FREQ_HOP,
161 NDIS_80211_TYPE_DIRECT_SEQ,
162 NDIS_80211_TYPE_OFDM_A,
163 NDIS_80211_TYPE_OFDM_G
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200164};
165
166enum ndis_80211_net_infra {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300167 NDIS_80211_INFRA_ADHOC,
168 NDIS_80211_INFRA_INFRA,
169 NDIS_80211_INFRA_AUTO_UNKNOWN
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200170};
171
172enum ndis_80211_auth_mode {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300173 NDIS_80211_AUTH_OPEN,
174 NDIS_80211_AUTH_SHARED,
175 NDIS_80211_AUTH_AUTO_SWITCH,
176 NDIS_80211_AUTH_WPA,
177 NDIS_80211_AUTH_WPA_PSK,
178 NDIS_80211_AUTH_WPA_NONE,
179 NDIS_80211_AUTH_WPA2,
180 NDIS_80211_AUTH_WPA2_PSK
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200181};
182
183enum ndis_80211_encr_status {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300184 NDIS_80211_ENCR_WEP_ENABLED,
185 NDIS_80211_ENCR_DISABLED,
186 NDIS_80211_ENCR_WEP_KEY_ABSENT,
187 NDIS_80211_ENCR_NOT_SUPPORTED,
188 NDIS_80211_ENCR_TKIP_ENABLED,
189 NDIS_80211_ENCR_TKIP_KEY_ABSENT,
190 NDIS_80211_ENCR_CCMP_ENABLED,
191 NDIS_80211_ENCR_CCMP_KEY_ABSENT
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200192};
193
194enum ndis_80211_priv_filter {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300195 NDIS_80211_PRIV_ACCEPT_ALL,
196 NDIS_80211_PRIV_8021X_WEP
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200197};
198
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300199enum ndis_80211_addkey_bits {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300200 NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
201 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
202 NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
203 NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300204};
205
206enum ndis_80211_addwep_bits {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300207 NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
208 NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +0300209};
210
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200211struct ndis_80211_ssid {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200212 __le32 length;
213 u8 essid[NDIS_802_11_LENGTH_SSID];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200214} __attribute__((packed));
215
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200216struct ndis_80211_conf_freq_hop {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200217 __le32 length;
218 __le32 hop_pattern;
219 __le32 hop_set;
220 __le32 dwell_time;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200221} __attribute__((packed));
222
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200223struct ndis_80211_conf {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200224 __le32 length;
225 __le32 beacon_period;
226 __le32 atim_window;
227 __le32 ds_config;
228 struct ndis_80211_conf_freq_hop fh_config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200229} __attribute__((packed));
230
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200231struct ndis_80211_bssid_ex {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200232 __le32 length;
233 u8 mac[6];
234 u8 padding[2];
235 struct ndis_80211_ssid ssid;
236 __le32 privacy;
237 __le32 rssi;
238 __le32 net_type;
239 struct ndis_80211_conf config;
240 __le32 net_infra;
241 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
242 __le32 ie_length;
243 u8 ies[0];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200244} __attribute__((packed));
245
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200246struct ndis_80211_bssid_list_ex {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200247 __le32 num_items;
248 struct ndis_80211_bssid_ex bssid[0];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200249} __attribute__((packed));
250
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200251struct ndis_80211_fixed_ies {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200252 u8 timestamp[8];
253 __le16 beacon_interval;
254 __le16 capabilities;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200255} __attribute__((packed));
256
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200257struct ndis_80211_wep_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200258 __le32 size;
259 __le32 index;
260 __le32 length;
261 u8 material[32];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200262} __attribute__((packed));
263
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200264struct ndis_80211_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200265 __le32 size;
266 __le32 index;
267 __le32 length;
268 u8 bssid[6];
269 u8 padding[6];
270 u8 rsc[8];
271 u8 material[32];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200272} __attribute__((packed));
273
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200274struct ndis_80211_remove_key {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200275 __le32 size;
276 __le32 index;
277 u8 bssid[6];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200278} __attribute__((packed));
279
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200280struct ndis_config_param {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200281 __le32 name_offs;
282 __le32 name_length;
283 __le32 type;
284 __le32 value_offs;
285 __le32 value_length;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200286} __attribute__((packed));
287
Scott Ashcroft43646232008-05-27 00:06:15 +0300288struct ndis_80211_assoc_info {
289 __le32 length;
290 __le16 req_ies;
291 struct req_ie {
292 __le16 capa;
293 __le16 listen_interval;
294 u8 cur_ap_address[6];
295 } req_ie;
296 __le32 req_ie_length;
297 __le32 offset_req_ies;
298 __le16 resp_ies;
299 struct resp_ie {
300 __le16 capa;
301 __le16 status_code;
302 __le16 assoc_id;
303 } resp_ie;
304 __le32 resp_ie_length;
305 __le32 offset_resp_ies;
306} __attribute__((packed));
307
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200308/* these have to match what is in wpa_supplicant */
Johannes Berg5b0acc62008-02-20 11:47:45 +0100309enum wpa_alg { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP };
310enum wpa_cipher { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
311 CIPHER_WEP104 };
312enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
313 KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE };
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200314
315/*
316 * private data
317 */
318#define NET_TYPE_11FB 0
319
320#define CAP_MODE_80211A 1
321#define CAP_MODE_80211B 2
322#define CAP_MODE_80211G 4
323#define CAP_MODE_MASK 7
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200324
Jussi Kivilinna6010ce02008-06-02 18:35:21 +0300325#define WORK_LINK_UP (1<<0)
326#define WORK_LINK_DOWN (1<<1)
327#define WORK_SET_MULTICAST_LIST (1<<2)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200328
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300329#define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
330
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200331static const struct ieee80211_channel rndis_channels[] = {
332 { .center_freq = 2412 },
333 { .center_freq = 2417 },
334 { .center_freq = 2422 },
335 { .center_freq = 2427 },
336 { .center_freq = 2432 },
337 { .center_freq = 2437 },
338 { .center_freq = 2442 },
339 { .center_freq = 2447 },
340 { .center_freq = 2452 },
341 { .center_freq = 2457 },
342 { .center_freq = 2462 },
343 { .center_freq = 2467 },
344 { .center_freq = 2472 },
345 { .center_freq = 2484 },
346};
347
348static const struct ieee80211_rate rndis_rates[] = {
349 { .bitrate = 10 },
350 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
351 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
352 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
353 { .bitrate = 60 },
354 { .bitrate = 90 },
355 { .bitrate = 120 },
356 { .bitrate = 180 },
357 { .bitrate = 240 },
358 { .bitrate = 360 },
359 { .bitrate = 480 },
360 { .bitrate = 540 }
361};
362
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200363/* RNDIS device private data */
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300364struct rndis_wlan_private {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200365 struct usbnet *usbdev;
366
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200367 struct wireless_dev wdev;
368
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200369 struct cfg80211_scan_request *scan_request;
370
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200371 struct workqueue_struct *workqueue;
372 struct delayed_work stats_work;
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200373 struct delayed_work scan_work;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200374 struct work_struct work;
375 struct mutex command_lock;
376 spinlock_t stats_lock;
377 unsigned long work_pending;
378
John W. Linville5c8fa4f2009-03-26 23:39:53 +0200379 struct ieee80211_supported_band band;
380 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
381 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
382
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200383 struct iw_statistics iwstats;
384 struct iw_statistics privstats;
385
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200386 int caps;
387 int multicast_size;
388
389 /* module parameters */
390 char param_country[4];
391 int param_frameburst;
392 int param_afterburner;
393 int param_power_save;
394 int param_power_output;
395 int param_roamtrigger;
396 int param_roamdelta;
397 u32 param_workaround_interval;
398
399 /* hardware state */
400 int radio_on;
401 int infra_mode;
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200402 struct ndis_80211_ssid essid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200403
404 /* encryption stuff */
405 int encr_tx_key_index;
406 char encr_keys[4][32];
407 int encr_key_len[4];
Jussi Kivilinna98391782009-05-22 17:40:34 +0300408 char encr_key_wpa[4];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200409 int wpa_version;
410 int wpa_keymgmt;
411 int wpa_authalg;
412 int wpa_ie_len;
413 u8 *wpa_ie;
414 int wpa_cipher_pair;
415 int wpa_cipher_group;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300416
417 u8 command_buffer[COMMAND_BUFFER_SIZE];
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200418};
419
John W. Linville964c1d42009-03-26 23:40:01 +0200420/*
421 * cfg80211 ops
422 */
423static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex,
424 enum nl80211_iftype type, u32 *flags,
425 struct vif_params *params);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200426
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200427static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
428 struct cfg80211_scan_request *request);
429
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200430static struct cfg80211_ops rndis_config_ops = {
John W. Linville964c1d42009-03-26 23:40:01 +0200431 .change_virtual_intf = rndis_change_virtual_intf,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +0200432 .scan = rndis_scan,
John W. Linville964c1d42009-03-26 23:40:01 +0200433};
434
Johannes Bergcaa6dfa2009-04-21 10:55:10 +0200435static void *rndis_wiphy_privid = &rndis_wiphy_privid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200436
437static const int bcm4320_power_output[4] = { 25, 50, 75, 100 };
438
439static const unsigned char zero_bssid[ETH_ALEN] = {0,};
440static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff,
441 0xff, 0xff, 0xff };
442
443
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300444static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200445{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300446 return (struct rndis_wlan_private *)dev->driver_priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200447}
448
449
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300450static u32 get_bcm4320_power(struct rndis_wlan_private *priv)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200451{
452 return BCM4320_DEFAULT_TXPOWER *
453 bcm4320_power_output[priv->param_power_output] / 100;
454}
455
456
457/* translate error code */
458static int rndis_error_status(__le32 rndis_status)
459{
460 int ret = -EINVAL;
461 switch (rndis_status) {
462 case RNDIS_STATUS_SUCCESS:
463 ret = 0;
464 break;
465 case RNDIS_STATUS_FAILURE:
466 case RNDIS_STATUS_INVALID_DATA:
467 ret = -EINVAL;
468 break;
469 case RNDIS_STATUS_NOT_SUPPORTED:
470 ret = -EOPNOTSUPP;
471 break;
472 case RNDIS_STATUS_ADAPTER_NOT_READY:
473 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
474 ret = -EBUSY;
475 break;
476 }
477 return ret;
478}
479
480
481static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
482{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300483 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200484 union {
485 void *buf;
486 struct rndis_msg_hdr *header;
487 struct rndis_query *get;
488 struct rndis_query_c *get_c;
489 } u;
490 int ret, buflen;
491
492 buflen = *len + sizeof(*u.get);
493 if (buflen < CONTROL_BUFFER_SIZE)
494 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300495
496 if (buflen > COMMAND_BUFFER_SIZE) {
497 u.buf = kmalloc(buflen, GFP_KERNEL);
498 if (!u.buf)
499 return -ENOMEM;
500 } else {
501 u.buf = priv->command_buffer;
502 }
503
504 mutex_lock(&priv->command_lock);
505
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200506 memset(u.get, 0, sizeof *u.get);
507 u.get->msg_type = RNDIS_MSG_QUERY;
Harvey Harrison35c26c22009-02-14 22:56:56 -0800508 u.get->msg_len = cpu_to_le32(sizeof *u.get);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200509 u.get->oid = oid;
510
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300511 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200512 if (ret == 0) {
513 ret = le32_to_cpu(u.get_c->len);
514 *len = (*len > ret) ? ret : *len;
515 memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len);
516 ret = rndis_error_status(u.get_c->status);
517 }
518
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300519 mutex_unlock(&priv->command_lock);
520
521 if (u.buf != priv->command_buffer)
522 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200523 return ret;
524}
525
526
527static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
528{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300529 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200530 union {
531 void *buf;
532 struct rndis_msg_hdr *header;
533 struct rndis_set *set;
534 struct rndis_set_c *set_c;
535 } u;
536 int ret, buflen;
537
538 buflen = len + sizeof(*u.set);
539 if (buflen < CONTROL_BUFFER_SIZE)
540 buflen = CONTROL_BUFFER_SIZE;
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300541
542 if (buflen > COMMAND_BUFFER_SIZE) {
543 u.buf = kmalloc(buflen, GFP_KERNEL);
544 if (!u.buf)
545 return -ENOMEM;
546 } else {
547 u.buf = priv->command_buffer;
548 }
549
550 mutex_lock(&priv->command_lock);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200551
552 memset(u.set, 0, sizeof *u.set);
553 u.set->msg_type = RNDIS_MSG_SET;
554 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
555 u.set->oid = oid;
556 u.set->len = cpu_to_le32(len);
Harvey Harrison35c26c22009-02-14 22:56:56 -0800557 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
558 u.set->handle = cpu_to_le32(0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200559 memcpy(u.buf + sizeof(*u.set), data, len);
560
Jussi Kivilinna818727b2008-06-18 15:40:12 +0300561 ret = rndis_command(dev, u.header, buflen);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200562 if (ret == 0)
563 ret = rndis_error_status(u.set_c->status);
564
Jussi Kivilinna90d07342008-06-12 20:19:19 +0300565 mutex_unlock(&priv->command_lock);
566
567 if (u.buf != priv->command_buffer)
568 kfree(u.buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200569 return ret;
570}
571
572
573/*
574 * Specs say that we can only set config parameters only soon after device
575 * initialization.
576 * value_type: 0 = u32, 2 = unicode string
577 */
578static int rndis_set_config_parameter(struct usbnet *dev, char *param,
579 int value_type, void *value)
580{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200581 struct ndis_config_param *infobuf;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200582 int value_len, info_len, param_len, ret, i;
583 __le16 *unibuf;
584 __le32 *dst_value;
585
586 if (value_type == 0)
587 value_len = sizeof(__le32);
588 else if (value_type == 2)
589 value_len = strlen(value) * sizeof(__le16);
590 else
591 return -EINVAL;
592
593 param_len = strlen(param) * sizeof(__le16);
594 info_len = sizeof(*infobuf) + param_len + value_len;
595
596#ifdef DEBUG
597 info_len += 12;
598#endif
599 infobuf = kmalloc(info_len, GFP_KERNEL);
600 if (!infobuf)
601 return -ENOMEM;
602
603#ifdef DEBUG
604 info_len -= 12;
605 /* extra 12 bytes are for padding (debug output) */
606 memset(infobuf, 0xCC, info_len + 12);
607#endif
608
609 if (value_type == 2)
610 devdbg(dev, "setting config parameter: %s, value: %s",
611 param, (u8 *)value);
612 else
613 devdbg(dev, "setting config parameter: %s, value: %d",
614 param, *(u32 *)value);
615
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200616 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
617 infobuf->name_length = cpu_to_le32(param_len);
618 infobuf->type = cpu_to_le32(value_type);
619 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
620 infobuf->value_length = cpu_to_le32(value_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200621
622 /* simple string to unicode string conversion */
623 unibuf = (void *)infobuf + sizeof(*infobuf);
624 for (i = 0; i < param_len / sizeof(__le16); i++)
625 unibuf[i] = cpu_to_le16(param[i]);
626
627 if (value_type == 2) {
628 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
629 for (i = 0; i < value_len / sizeof(__le16); i++)
630 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
631 } else {
632 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
633 *dst_value = cpu_to_le32(*(u32 *)value);
634 }
635
636#ifdef DEBUG
637 devdbg(dev, "info buffer (len: %d):", info_len);
638 for (i = 0; i < info_len; i += 12) {
639 u32 *tmp = (u32 *)((u8 *)infobuf + i);
640 devdbg(dev, "%08X:%08X:%08X",
641 cpu_to_be32(tmp[0]),
642 cpu_to_be32(tmp[1]),
643 cpu_to_be32(tmp[2]));
644 }
645#endif
646
647 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
648 infobuf, info_len);
649 if (ret != 0)
Martin Olsson6d60f9df2009-04-07 10:30:24 +0200650 devdbg(dev, "setting rndis config parameter failed, %d.", ret);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200651
652 kfree(infobuf);
653 return ret;
654}
655
656static int rndis_set_config_parameter_str(struct usbnet *dev,
657 char *param, char *value)
658{
659 return(rndis_set_config_parameter(dev, param, 2, value));
660}
661
662/*static int rndis_set_config_parameter_u32(struct usbnet *dev,
663 char *param, u32 value)
664{
665 return(rndis_set_config_parameter(dev, param, 0, &value));
666}*/
667
668
669/*
670 * data conversion functions
671 */
672static int level_to_qual(int level)
673{
674 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
675 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
676}
677
678
679static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq)
680{
681 freq->e = 0;
682 freq->i = 0;
683 freq->flags = 0;
684
685 /* see comment in wireless.h above the "struct iw_freq"
686 * definition for an explanation of this if
687 * NOTE: 1000000 is due to the kHz
688 */
689 if (dsconfig > 1000000) {
690 freq->m = dsconfig / 10;
691 freq->e = 1;
692 } else
693 freq->m = dsconfig;
694
695 /* convert from kHz to Hz */
696 freq->e += 3;
697}
698
699
700static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig)
701{
702 if (freq->m < 1000 && freq->e == 0) {
David Kilroy9ee677c2008-12-23 14:03:38 +0000703 if (freq->m >= 1 && freq->m <= 14)
704 *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200705 else
706 return -1;
707 } else {
708 int i;
709 *dsconfig = freq->m;
710 for (i = freq->e; i > 0; i--)
711 *dsconfig *= 10;
712 *dsconfig /= 1000;
713 }
714
715 return 0;
716}
717
718
719/*
720 * common functions
721 */
722static int
723add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index);
724
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200725static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200726{
727 int ret, len;
728
729 len = sizeof(*ssid);
730 ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len);
731
732 if (ret != 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200733 ssid->length = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200734
735#ifdef DEBUG
736 {
737 unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1];
738
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200739 memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length));
740 tmp[le32_to_cpu(ssid->length)] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200741 devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret);
742 }
743#endif
744 return ret;
745}
746
747
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200748static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200749{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300750 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200751 int ret;
752
753 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
754 if (ret == 0) {
755 memcpy(&priv->essid, ssid, sizeof(priv->essid));
756 priv->radio_on = 1;
757 devdbg(usbdev, "set_essid: radio_on = 1");
758 }
759
760 return ret;
761}
762
763
764static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
765{
766 int ret, len;
767
768 len = ETH_ALEN;
769 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
770
771 if (ret != 0)
772 memset(bssid, 0, ETH_ALEN);
773
774 return ret;
775}
776
Scott Ashcroft43646232008-05-27 00:06:15 +0300777static int get_association_info(struct usbnet *usbdev,
778 struct ndis_80211_assoc_info *info, int len)
779{
780 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
781 info, &len);
782}
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200783
784static int is_associated(struct usbnet *usbdev)
785{
786 u8 bssid[ETH_ALEN];
787 int ret;
788
789 ret = get_bssid(usbdev, bssid);
790
791 return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0);
792}
793
794
795static int disassociate(struct usbnet *usbdev, int reset_ssid)
796{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300797 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +0200798 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200799 int i, ret = 0;
800
801 if (priv->radio_on) {
802 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
803 if (ret == 0) {
804 priv->radio_on = 0;
805 devdbg(usbdev, "disassociate: radio_on = 0");
806
807 if (reset_ssid)
808 msleep(100);
809 }
810 }
811
812 /* disassociate causes radio to be turned off; if reset_ssid
813 * is given, set random ssid to enable radio */
814 if (reset_ssid) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +0200815 ssid.length = cpu_to_le32(sizeof(ssid.essid));
816 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
817 ssid.essid[0] = 0x1;
818 ssid.essid[1] = 0xff;
819 for (i = 2; i < sizeof(ssid.essid); i++)
820 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200821 ret = set_essid(usbdev, &ssid);
822 }
823 return ret;
824}
825
826
827static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg)
828{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300829 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200830 __le32 tmp;
831 int auth_mode, ret;
832
833 devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x "
834 "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt);
835
836 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) {
837 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300838 auth_mode = NDIS_80211_AUTH_WPA2;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200839 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300840 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200841 } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) {
842 if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300843 auth_mode = NDIS_80211_AUTH_WPA;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200844 else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300845 auth_mode = NDIS_80211_AUTH_WPA_PSK;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200846 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300847 auth_mode = NDIS_80211_AUTH_WPA_NONE;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200848 } else if (authalg & IW_AUTH_ALG_SHARED_KEY) {
849 if (authalg & IW_AUTH_ALG_OPEN_SYSTEM)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300850 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200851 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300852 auth_mode = NDIS_80211_AUTH_SHARED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200853 } else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300854 auth_mode = NDIS_80211_AUTH_OPEN;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200855
856 tmp = cpu_to_le32(auth_mode);
857 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
858 sizeof(tmp));
859 if (ret != 0) {
860 devwarn(usbdev, "setting auth mode failed (%08X)", ret);
861 return ret;
862 }
863
864 priv->wpa_version = wpa_version;
865 priv->wpa_authalg = authalg;
866 return 0;
867}
868
869
870static int set_priv_filter(struct usbnet *usbdev)
871{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300872 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200873 __le32 tmp;
874
875 devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version);
876
877 if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 ||
878 priv->wpa_version & IW_AUTH_WPA_VERSION_WPA)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300879 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200880 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300881 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200882
883 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
884 sizeof(tmp));
885}
886
887
888static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
889{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300890 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200891 __le32 tmp;
892 int encr_mode, ret;
893
894 devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x",
895 pairwise,
896 groupwise);
897
898 if (pairwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300899 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200900 else if (pairwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300901 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200902 else if (pairwise &
903 (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300904 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200905 else if (groupwise & IW_AUTH_CIPHER_CCMP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300906 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200907 else if (groupwise & IW_AUTH_CIPHER_TKIP)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300908 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200909 else
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300910 encr_mode = NDIS_80211_ENCR_DISABLED;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200911
912 tmp = cpu_to_le32(encr_mode);
913 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
914 sizeof(tmp));
915 if (ret != 0) {
916 devwarn(usbdev, "setting encr mode failed (%08X)", ret);
917 return ret;
918 }
919
920 priv->wpa_cipher_pair = pairwise;
921 priv->wpa_cipher_group = groupwise;
922 return 0;
923}
924
925
926static int set_assoc_params(struct usbnet *usbdev)
927{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300928 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200929
930 set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg);
931 set_priv_filter(usbdev);
932 set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group);
933
934 return 0;
935}
936
937
938static int set_infra_mode(struct usbnet *usbdev, int mode)
939{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300940 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200941 __le32 tmp;
942 int ret, i;
943
944 devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode);
945
946 tmp = cpu_to_le32(mode);
947 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
948 sizeof(tmp));
949 if (ret != 0) {
950 devwarn(usbdev, "setting infra mode failed (%08X)", ret);
951 return ret;
952 }
953
954 /* NDIS drivers clear keys when infrastructure mode is
955 * changed. But Linux tools assume otherwise. So set the
956 * keys */
957 if (priv->wpa_keymgmt == 0 ||
958 priv->wpa_keymgmt == IW_AUTH_KEY_MGMT_802_1X) {
959 for (i = 0; i < 4; i++) {
Jussi Kivilinna98391782009-05-22 17:40:34 +0300960 if (priv->encr_key_len[i] > 0 && !priv->encr_key_wpa[i])
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200961 add_wep_key(usbdev, priv->encr_keys[i],
962 priv->encr_key_len[i], i);
963 }
964 }
965
966 priv->infra_mode = mode;
967 return 0;
968}
969
970
971static void set_default_iw_params(struct usbnet *usbdev)
972{
Jussi Kivilinna582241a02009-06-04 20:13:25 +0300973 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200974
975 priv->wpa_keymgmt = 0;
976 priv->wpa_version = 0;
977
Jussi Kivilinnaaa182942009-06-04 20:13:19 +0300978 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +0200979 set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
980 IW_AUTH_ALG_OPEN_SYSTEM);
981 set_priv_filter(usbdev);
982 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
983}
984
985
986static int deauthenticate(struct usbnet *usbdev)
987{
988 int ret;
989
990 ret = disassociate(usbdev, 1);
991 set_default_iw_params(usbdev);
992 return ret;
993}
994
995
996/* index must be 0 - N, as per NDIS */
997static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index)
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_wep_key ndis_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001001 int ret;
1002
1003 if (key_len <= 0 || key_len > 32 || index < 0 || index >= 4)
1004 return -EINVAL;
1005
1006 memset(&ndis_key, 0, sizeof(ndis_key));
1007
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001008 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1009 ndis_key.length = cpu_to_le32(key_len);
1010 ndis_key.index = cpu_to_le32(index);
1011 memcpy(&ndis_key.material, key, key_len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001012
1013 if (index == priv->encr_tx_key_index) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001014 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001015 ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104,
1016 IW_AUTH_CIPHER_NONE);
1017 if (ret)
1018 devwarn(usbdev, "encryption couldn't be enabled (%08X)",
1019 ret);
1020 }
1021
1022 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1023 sizeof(ndis_key));
1024 if (ret != 0) {
1025 devwarn(usbdev, "adding encryption key %d failed (%08X)",
1026 index+1, ret);
1027 return ret;
1028 }
1029
1030 priv->encr_key_len[index] = key_len;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001031 priv->encr_key_wpa[index] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001032 memcpy(&priv->encr_keys[index], key, key_len);
1033
1034 return 0;
1035}
1036
1037
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001038static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
1039 int index, const struct sockaddr *addr,
1040 const u8 *rx_seq, int alg, int flags)
1041{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001042 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001043 struct ndis_80211_key ndis_key;
1044 int ret;
1045
1046 if (index < 0 || index >= 4)
1047 return -EINVAL;
1048 if (key_len > sizeof(ndis_key.material) || key_len < 0)
1049 return -EINVAL;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001050 if ((flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) && !rx_seq)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001051 return -EINVAL;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001052 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !addr)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001053 return -EINVAL;
1054
1055 devdbg(usbdev, "add_wpa_key(%i): flags:%i%i%i", index,
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001056 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1057 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1058 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001059
1060 memset(&ndis_key, 0, sizeof(ndis_key));
1061
1062 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1063 sizeof(ndis_key.material) + key_len);
1064 ndis_key.length = cpu_to_le32(key_len);
1065 ndis_key.index = cpu_to_le32(index) | flags;
1066
1067 if (alg == IW_ENCODE_ALG_TKIP && key_len == 32) {
1068 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1069 * different order than NDIS spec, so swap the order here. */
1070 memcpy(ndis_key.material, key, 16);
1071 memcpy(ndis_key.material + 16, key + 24, 8);
1072 memcpy(ndis_key.material + 24, key + 16, 8);
1073 } else
1074 memcpy(ndis_key.material, key, key_len);
1075
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001076 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001077 memcpy(ndis_key.rsc, rx_seq, 6);
1078
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001079 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001080 /* pairwise key */
1081 memcpy(ndis_key.bssid, addr->sa_data, ETH_ALEN);
1082 } else {
1083 /* group key */
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001084 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001085 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1086 else
1087 get_bssid(usbdev, ndis_key.bssid);
1088 }
1089
1090 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1091 le32_to_cpu(ndis_key.size));
1092 devdbg(usbdev, "add_wpa_key: OID_802_11_ADD_KEY -> %08X", ret);
1093 if (ret != 0)
1094 return ret;
1095
1096 priv->encr_key_len[index] = key_len;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001097 priv->encr_key_wpa[index] = 1;
1098
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001099 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001100 priv->encr_tx_key_index = index;
1101
1102 return 0;
1103}
1104
1105
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001106/* remove_key is for both wep and wpa */
1107static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN])
1108{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001109 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001110 struct ndis_80211_remove_key remove_key;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001111 __le32 keyindex;
1112 int ret;
1113
1114 if (priv->encr_key_len[index] == 0)
1115 return 0;
1116
1117 priv->encr_key_len[index] = 0;
Jussi Kivilinna98391782009-05-22 17:40:34 +03001118 priv->encr_key_wpa[index] = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001119 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1120
1121 if (priv->wpa_cipher_pair == IW_AUTH_CIPHER_TKIP ||
1122 priv->wpa_cipher_pair == IW_AUTH_CIPHER_CCMP ||
1123 priv->wpa_cipher_group == IW_AUTH_CIPHER_TKIP ||
1124 priv->wpa_cipher_group == IW_AUTH_CIPHER_CCMP) {
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001125 remove_key.size = cpu_to_le32(sizeof(remove_key));
1126 remove_key.index = cpu_to_le32(index);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001127 if (bssid) {
1128 /* pairwise key */
1129 if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0)
Jussi Kivilinnab4703a22009-05-22 17:40:20 +03001130 remove_key.index |=
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001131 NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001132 memcpy(remove_key.bssid, bssid,
1133 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001134 } else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001135 memset(remove_key.bssid, 0xff,
1136 sizeof(remove_key.bssid));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001137
1138 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1139 sizeof(remove_key));
1140 if (ret != 0)
1141 return ret;
1142 } else {
1143 keyindex = cpu_to_le32(index);
1144 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1145 sizeof(keyindex));
1146 if (ret != 0) {
1147 devwarn(usbdev,
1148 "removing encryption key %d failed (%08X)",
1149 index, ret);
1150 return ret;
1151 }
1152 }
1153
1154 /* if it is transmit key, disable encryption */
1155 if (index == priv->encr_tx_key_index)
1156 set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE);
1157
1158 return 0;
1159}
1160
1161
1162static void set_multicast_list(struct usbnet *usbdev)
1163{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001164 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001165 struct dev_mc_list *mclist;
1166 __le32 filter;
1167 int ret, i, size;
1168 char *buf;
1169
1170 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1171
1172 if (usbdev->net->flags & IFF_PROMISC) {
1173 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1174 RNDIS_PACKET_TYPE_ALL_LOCAL;
1175 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1176 usbdev->net->mc_count > priv->multicast_size) {
1177 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1178 } else if (usbdev->net->mc_count > 0) {
1179 size = min(priv->multicast_size, usbdev->net->mc_count);
1180 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1181 if (!buf) {
1182 devwarn(usbdev,
1183 "couldn't alloc %d bytes of memory",
1184 size * ETH_ALEN);
1185 return;
1186 }
1187
1188 mclist = usbdev->net->mc_list;
1189 for (i = 0; i < size && mclist; mclist = mclist->next) {
1190 if (mclist->dmi_addrlen != ETH_ALEN)
1191 continue;
1192
1193 memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1194 i++;
1195 }
1196
1197 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1198 i * ETH_ALEN);
1199 if (ret == 0 && i > 0)
1200 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1201 else
1202 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1203
1204 devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d",
1205 i, priv->multicast_size, ret);
1206
1207 kfree(buf);
1208 }
1209
1210 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1211 sizeof(filter));
1212 if (ret < 0) {
1213 devwarn(usbdev, "couldn't set packet filter: %08x",
1214 le32_to_cpu(filter));
1215 }
1216
1217 devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d",
1218 le32_to_cpu(filter), ret);
1219}
1220
1221
1222/*
John W. Linville964c1d42009-03-26 23:40:01 +02001223 * cfg80211 ops
1224 */
1225static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex,
1226 enum nl80211_iftype type, u32 *flags,
1227 struct vif_params *params)
1228{
1229 struct net_device *dev;
1230 struct usbnet *usbdev;
1231 int mode;
1232
1233 /* we're under RTNL */
1234 dev = __dev_get_by_index(&init_net, ifindex);
1235 if (!dev)
1236 return -ENODEV;
1237 usbdev = netdev_priv(dev);
1238
1239 switch (type) {
1240 case NL80211_IFTYPE_ADHOC:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001241 mode = NDIS_80211_INFRA_ADHOC;
John W. Linville964c1d42009-03-26 23:40:01 +02001242 break;
1243 case NL80211_IFTYPE_STATION:
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001244 mode = NDIS_80211_INFRA_INFRA;
John W. Linville964c1d42009-03-26 23:40:01 +02001245 break;
1246 default:
1247 return -EINVAL;
1248 }
1249
1250 return set_infra_mode(usbdev, mode);
1251}
1252
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001253
1254#define SCAN_DELAY_JIFFIES (HZ)
1255static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1256 struct cfg80211_scan_request *request)
1257{
1258 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001259 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001260 int ret;
1261 __le32 tmp;
1262
1263 devdbg(usbdev, "cfg80211.scan");
1264
1265 if (!request)
1266 return -EINVAL;
1267
1268 if (priv->scan_request && priv->scan_request != request)
1269 return -EBUSY;
1270
1271 priv->scan_request = request;
1272
1273 tmp = cpu_to_le32(1);
1274 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1275 sizeof(tmp));
1276 if (ret == 0) {
1277 /* Wait before retrieving scan results from device */
1278 queue_delayed_work(priv->workqueue, &priv->scan_work,
1279 SCAN_DELAY_JIFFIES);
1280 }
1281
1282 return ret;
1283}
1284
1285
1286static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1287 struct ndis_80211_bssid_ex *bssid)
1288{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001289 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001290 struct ieee80211_channel *channel;
1291 s32 signal;
1292 u64 timestamp;
1293 u16 capability;
1294 u16 beacon_interval;
1295 struct ndis_80211_fixed_ies *fixed;
1296 int ie_len, bssid_len;
1297 u8 *ie;
1298
1299 /* parse bssid structure */
1300 bssid_len = le32_to_cpu(bssid->length);
1301
1302 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1303 sizeof(struct ndis_80211_fixed_ies))
1304 return NULL;
1305
1306 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1307
1308 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1309 ie_len = min(bssid_len - (int)sizeof(*bssid),
1310 (int)le32_to_cpu(bssid->ie_length));
1311 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1312 if (ie_len < 0)
1313 return NULL;
1314
1315 /* extract data for cfg80211_inform_bss */
1316 channel = ieee80211_get_channel(priv->wdev.wiphy,
1317 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1318 if (!channel)
1319 return NULL;
1320
1321 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1322 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1323 capability = le16_to_cpu(fixed->capabilities);
1324 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1325
1326 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1327 timestamp, capability, beacon_interval, ie, ie_len, signal,
1328 GFP_KERNEL);
1329}
1330
1331
1332static int rndis_check_bssid_list(struct usbnet *usbdev)
1333{
1334 void *buf = NULL;
1335 struct ndis_80211_bssid_list_ex *bssid_list;
1336 struct ndis_80211_bssid_ex *bssid;
1337 int ret = -EINVAL, len, count, bssid_len;
1338
1339 devdbg(usbdev, "check_bssid_list");
1340
1341 len = CONTROL_BUFFER_SIZE;
1342 buf = kmalloc(len, GFP_KERNEL);
1343 if (!buf) {
1344 ret = -ENOMEM;
1345 goto out;
1346 }
1347
1348 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1349 if (ret != 0)
1350 goto out;
1351
1352 bssid_list = buf;
1353 bssid = bssid_list->bssid;
1354 bssid_len = le32_to_cpu(bssid->length);
1355 count = le32_to_cpu(bssid_list->num_items);
1356 devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count);
1357
1358 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1359 rndis_bss_info_update(usbdev, bssid);
1360
1361 bssid = (void *)bssid + bssid_len;
1362 bssid_len = le32_to_cpu(bssid->length);
1363 count--;
1364 }
1365
1366out:
1367 kfree(buf);
1368 return ret;
1369}
1370
1371
1372static void rndis_get_scan_results(struct work_struct *work)
1373{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001374 struct rndis_wlan_private *priv =
1375 container_of(work, struct rndis_wlan_private, scan_work.work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02001376 struct usbnet *usbdev = priv->usbdev;
1377 int ret;
1378
1379 devdbg(usbdev, "get_scan_results");
1380
1381 ret = rndis_check_bssid_list(usbdev);
1382
1383 cfg80211_scan_done(priv->scan_request, ret < 0);
1384
1385 priv->scan_request = NULL;
1386}
1387
1388
John W. Linville964c1d42009-03-26 23:40:01 +02001389/*
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001390 * wireless extension handlers
1391 */
1392
1393static int rndis_iw_commit(struct net_device *dev,
1394 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1395{
1396 /* dummy op */
1397 return 0;
1398}
1399
1400
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001401static int rndis_iw_set_essid(struct net_device *dev,
1402 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1403{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001404 struct ndis_80211_ssid ssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001405 int length = wrqu->essid.length;
Wang Chen524ad0a2008-11-12 23:39:10 -08001406 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001407
1408 devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'",
1409 wrqu->essid.flags, wrqu->essid.length, essid);
1410
1411 if (length > NDIS_802_11_LENGTH_SSID)
1412 length = NDIS_802_11_LENGTH_SSID;
1413
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001414 ssid.length = cpu_to_le32(length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001415 if (length > 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001416 memcpy(ssid.essid, essid, length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001417 else
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001418 memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001419
1420 set_assoc_params(usbdev);
1421
1422 if (!wrqu->essid.flags || length == 0)
1423 return disassociate(usbdev, 1);
1424 else
1425 return set_essid(usbdev, &ssid);
1426}
1427
1428
1429static int rndis_iw_get_essid(struct net_device *dev,
1430 struct iw_request_info *info, union iwreq_data *wrqu, char *essid)
1431{
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001432 struct ndis_80211_ssid ssid;
Wang Chen524ad0a2008-11-12 23:39:10 -08001433 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001434 int ret;
1435
1436 ret = get_essid(usbdev, &ssid);
1437
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001438 if (ret == 0 && le32_to_cpu(ssid.length) > 0) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001439 wrqu->essid.flags = 1;
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001440 wrqu->essid.length = le32_to_cpu(ssid.length);
1441 memcpy(essid, ssid.essid, wrqu->essid.length);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001442 essid[wrqu->essid.length] = 0;
1443 } else {
1444 memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID));
1445 wrqu->essid.flags = 0;
1446 wrqu->essid.length = 0;
1447 }
1448 devdbg(usbdev, "SIOCGIWESSID: %s", essid);
1449 return ret;
1450}
1451
1452
1453static int rndis_iw_get_bssid(struct net_device *dev,
1454 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1455{
Wang Chen524ad0a2008-11-12 23:39:10 -08001456 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001457 unsigned char bssid[ETH_ALEN];
1458 int ret;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001459
1460 ret = get_bssid(usbdev, bssid);
1461
1462 if (ret == 0)
Johannes Berge1749612008-10-27 15:59:26 -07001463 devdbg(usbdev, "SIOCGIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001464 else
1465 devdbg(usbdev, "SIOCGIWAP: <not associated>");
1466
1467 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1468 memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN);
1469
1470 return ret;
1471}
1472
1473
1474static int rndis_iw_set_bssid(struct net_device *dev,
1475 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1476{
Wang Chen524ad0a2008-11-12 23:39:10 -08001477 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001478 u8 *bssid = (u8 *)wrqu->ap_addr.sa_data;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001479 int ret;
1480
Johannes Berge1749612008-10-27 15:59:26 -07001481 devdbg(usbdev, "SIOCSIWAP: %pM", bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001482
1483 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
1484
1485 /* user apps may set ap's mac address, which is not required;
1486 * they may fail to work if this function fails, so return
1487 * success */
1488 if (ret)
1489 devwarn(usbdev, "setting AP mac address failed (%08X)", ret);
1490
1491 return 0;
1492}
1493
1494
1495static int rndis_iw_set_auth(struct net_device *dev,
1496 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1497{
1498 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001499 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001500 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001501 int ret = -ENOTSUPP;
1502
1503 switch (p->flags & IW_AUTH_INDEX) {
1504 case IW_AUTH_WPA_VERSION:
1505 devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value);
1506 priv->wpa_version = p->value;
1507 ret = 0;
1508 break;
1509
1510 case IW_AUTH_CIPHER_PAIRWISE:
1511 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value);
1512 priv->wpa_cipher_pair = p->value;
1513 ret = 0;
1514 break;
1515
1516 case IW_AUTH_CIPHER_GROUP:
1517 devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value);
1518 priv->wpa_cipher_group = p->value;
1519 ret = 0;
1520 break;
1521
1522 case IW_AUTH_KEY_MGMT:
1523 devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value);
1524 priv->wpa_keymgmt = p->value;
1525 ret = 0;
1526 break;
1527
1528 case IW_AUTH_TKIP_COUNTERMEASURES:
1529 devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x",
1530 p->value);
1531 ret = 0;
1532 break;
1533
1534 case IW_AUTH_DROP_UNENCRYPTED:
1535 devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value);
1536 ret = 0;
1537 break;
1538
1539 case IW_AUTH_80211_AUTH_ALG:
1540 devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value);
1541 priv->wpa_authalg = p->value;
1542 ret = 0;
1543 break;
1544
1545 case IW_AUTH_WPA_ENABLED:
1546 devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value);
1547 if (wrqu->param.value)
1548 deauthenticate(usbdev);
1549 ret = 0;
1550 break;
1551
1552 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1553 devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x",
1554 p->value);
1555 ret = 0;
1556 break;
1557
1558 case IW_AUTH_ROAMING_CONTROL:
1559 devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value);
1560 ret = 0;
1561 break;
1562
1563 case IW_AUTH_PRIVACY_INVOKED:
1564 devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d",
1565 wrqu->param.flags & IW_AUTH_INDEX);
1566 return -EOPNOTSUPP;
1567
1568 default:
1569 devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x",
1570 p->flags & IW_AUTH_INDEX, p->value);
1571 }
1572 return ret;
1573}
1574
1575
1576static int rndis_iw_get_auth(struct net_device *dev,
1577 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1578{
1579 struct iw_param *p = &wrqu->param;
Wang Chen524ad0a2008-11-12 23:39:10 -08001580 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001581 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001582
1583 switch (p->flags & IW_AUTH_INDEX) {
1584 case IW_AUTH_WPA_VERSION:
1585 p->value = priv->wpa_version;
1586 break;
1587 case IW_AUTH_CIPHER_PAIRWISE:
1588 p->value = priv->wpa_cipher_pair;
1589 break;
1590 case IW_AUTH_CIPHER_GROUP:
1591 p->value = priv->wpa_cipher_group;
1592 break;
1593 case IW_AUTH_KEY_MGMT:
1594 p->value = priv->wpa_keymgmt;
1595 break;
1596 case IW_AUTH_80211_AUTH_ALG:
1597 p->value = priv->wpa_authalg;
1598 break;
1599 default:
1600 devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d",
1601 wrqu->param.flags & IW_AUTH_INDEX);
1602 return -EOPNOTSUPP;
1603 }
1604 return 0;
1605}
1606
1607
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001608static int rndis_iw_set_encode(struct net_device *dev,
1609 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1610{
Wang Chen524ad0a2008-11-12 23:39:10 -08001611 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001612 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001613 int ret, index, key_len;
1614 u8 *key;
1615
1616 index = (wrqu->encoding.flags & IW_ENCODE_INDEX);
1617
1618 /* iwconfig gives index as 1 - N */
1619 if (index > 0)
1620 index--;
1621 else
1622 index = priv->encr_tx_key_index;
1623
1624 if (index < 0 || index >= 4) {
1625 devwarn(usbdev, "encryption index out of range (%u)", index);
1626 return -EINVAL;
1627 }
1628
1629 /* remove key if disabled */
1630 if (wrqu->data.flags & IW_ENCODE_DISABLED) {
1631 if (remove_key(usbdev, index, NULL))
1632 return -EINVAL;
1633 else
1634 return 0;
1635 }
1636
1637 /* global encryption state (for all keys) */
1638 if (wrqu->data.flags & IW_ENCODE_OPEN)
1639 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1640 IW_AUTH_ALG_OPEN_SYSTEM);
1641 else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/
1642 ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED,
1643 IW_AUTH_ALG_SHARED_KEY);
1644 if (ret != 0)
1645 return ret;
1646
1647 if (wrqu->data.length > 0) {
1648 key_len = wrqu->data.length;
1649 key = extra;
1650 } else {
1651 /* must be set as tx key */
1652 if (priv->encr_key_len[index] == 0)
1653 return -EINVAL;
1654 key_len = priv->encr_key_len[index];
1655 key = priv->encr_keys[index];
1656 priv->encr_tx_key_index = index;
1657 }
1658
1659 if (add_wep_key(usbdev, key, key_len, index) != 0)
1660 return -EINVAL;
1661
1662 if (index == priv->encr_tx_key_index)
1663 /* ndis drivers want essid to be set after setting encr */
1664 set_essid(usbdev, &priv->essid);
1665
1666 return 0;
1667}
1668
1669
1670static int rndis_iw_set_encode_ext(struct net_device *dev,
1671 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1672{
1673 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
Wang Chen524ad0a2008-11-12 23:39:10 -08001674 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001675 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001676 int keyidx, flags;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001677
1678 keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX;
1679
1680 /* iwconfig gives index as 1 - N */
1681 if (keyidx)
1682 keyidx--;
1683 else
1684 keyidx = priv->encr_tx_key_index;
1685
1686 if (keyidx < 0 || keyidx >= 4)
1687 return -EINVAL;
1688
1689 if (ext->alg == WPA_ALG_WEP) {
1690 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1691 priv->encr_tx_key_index = keyidx;
1692 return add_wep_key(usbdev, ext->key, ext->key_len, keyidx);
1693 }
1694
1695 if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) ||
1696 ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0)
1697 return remove_key(usbdev, keyidx, NULL);
1698
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001699 flags = 0;
1700 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001701 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001702 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001703 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001704 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03001705 flags |= NDIS_80211_ADDKEY_TRANSMIT_KEY;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001706
Jussi Kivilinnab145ee02009-05-22 17:40:27 +03001707 return add_wpa_key(usbdev, ext->key, ext->key_len, keyidx, &ext->addr,
1708 ext->rx_seq, ext->alg, flags);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001709}
1710
1711
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001712static int rndis_iw_set_genie(struct net_device *dev,
1713 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1714{
Wang Chen524ad0a2008-11-12 23:39:10 -08001715 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001716 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001717 int ret = 0;
1718
1719#ifdef DEBUG
1720 int j;
1721 u8 *gie = extra;
1722 for (j = 0; j < wrqu->data.length; j += 8)
1723 devdbg(usbdev,
1724 "SIOCSIWGENIE %04x - "
1725 "%02x %02x %02x %02x %02x %02x %02x %02x", j,
1726 gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3],
1727 gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]);
1728#endif
1729 /* clear existing IEs */
1730 if (priv->wpa_ie_len) {
1731 kfree(priv->wpa_ie);
1732 priv->wpa_ie_len = 0;
1733 }
1734
1735 /* set new IEs */
1736 priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL);
1737 if (priv->wpa_ie) {
1738 priv->wpa_ie_len = wrqu->data.length;
1739 memcpy(priv->wpa_ie, extra, priv->wpa_ie_len);
1740 } else
1741 ret = -ENOMEM;
1742 return ret;
1743}
1744
1745
1746static int rndis_iw_get_genie(struct net_device *dev,
1747 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1748{
Wang Chen524ad0a2008-11-12 23:39:10 -08001749 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001750 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001751
1752 devdbg(usbdev, "SIOCGIWGENIE");
1753
1754 if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) {
1755 wrqu->data.length = 0;
1756 return 0;
1757 }
1758
1759 if (wrqu->data.length < priv->wpa_ie_len)
1760 return -E2BIG;
1761
1762 wrqu->data.length = priv->wpa_ie_len;
1763 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
1764
1765 return 0;
1766}
1767
1768
1769static int rndis_iw_set_rts(struct net_device *dev,
1770 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1771{
Wang Chen524ad0a2008-11-12 23:39:10 -08001772 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001773 __le32 tmp;
1774 devdbg(usbdev, "SIOCSIWRTS");
1775
1776 tmp = cpu_to_le32(wrqu->rts.value);
1777 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1778 sizeof(tmp));
1779}
1780
1781
1782static int rndis_iw_get_rts(struct net_device *dev,
1783 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1784{
Wang Chen524ad0a2008-11-12 23:39:10 -08001785 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001786 __le32 tmp;
1787 int len, ret;
1788
1789 len = sizeof(tmp);
1790 ret = rndis_query_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp, &len);
1791 if (ret == 0) {
1792 wrqu->rts.value = le32_to_cpu(tmp);
1793 wrqu->rts.flags = 1;
1794 wrqu->rts.disabled = 0;
1795 }
1796
1797 devdbg(usbdev, "SIOCGIWRTS: %d", wrqu->rts.value);
1798
1799 return ret;
1800}
1801
1802
1803static int rndis_iw_set_frag(struct net_device *dev,
1804 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1805{
Wang Chen524ad0a2008-11-12 23:39:10 -08001806 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001807 __le32 tmp;
1808
1809 devdbg(usbdev, "SIOCSIWFRAG");
1810
1811 tmp = cpu_to_le32(wrqu->frag.value);
1812 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1813 sizeof(tmp));
1814}
1815
1816
1817static int rndis_iw_get_frag(struct net_device *dev,
1818 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1819{
Wang Chen524ad0a2008-11-12 23:39:10 -08001820 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001821 __le32 tmp;
1822 int len, ret;
1823
1824 len = sizeof(tmp);
1825 ret = rndis_query_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1826 &len);
1827 if (ret == 0) {
1828 wrqu->frag.value = le32_to_cpu(tmp);
1829 wrqu->frag.flags = 1;
1830 wrqu->frag.disabled = 0;
1831 }
1832 devdbg(usbdev, "SIOCGIWFRAG: %d", wrqu->frag.value);
1833 return ret;
1834}
1835
1836
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001837static int rndis_iw_set_freq(struct net_device *dev,
1838 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1839{
Wang Chen524ad0a2008-11-12 23:39:10 -08001840 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001841 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001842 unsigned int dsconfig;
1843 int len, ret;
1844
1845 /* this OID is valid only when not associated */
1846 if (is_associated(usbdev))
1847 return 0;
1848
1849 dsconfig = 0;
1850 if (freq_to_dsconfig(&wrqu->freq, &dsconfig))
1851 return -EINVAL;
1852
1853 len = sizeof(config);
1854 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1855 if (ret != 0) {
1856 devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed");
1857 return 0;
1858 }
1859
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001860 config.ds_config = cpu_to_le32(dsconfig);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001861
1862 devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e);
1863 return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
1864 sizeof(config));
1865}
1866
1867
1868static int rndis_iw_get_freq(struct net_device *dev,
1869 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1870{
Wang Chen524ad0a2008-11-12 23:39:10 -08001871 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna1e41e1d2008-03-08 01:23:17 +02001872 struct ndis_80211_conf config;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001873 int len, ret;
1874
1875 len = sizeof(config);
1876 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1877 if (ret == 0)
Jussi Kivilinna461b3f22008-03-08 01:23:25 +02001878 dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001879
1880 devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m);
1881 return ret;
1882}
1883
1884
1885static int rndis_iw_get_txpower(struct net_device *dev,
1886 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1887{
Wang Chen524ad0a2008-11-12 23:39:10 -08001888 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001889 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001890 __le32 tx_power;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001891
1892 if (priv->radio_on) {
Jussi Kivilinna9656e852009-05-22 17:40:12 +03001893 /* fake since changing tx_power (by userlevel) not supported */
1894 tx_power = cpu_to_le32(get_bcm4320_power(priv));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001895
1896 wrqu->txpower.flags = IW_TXPOW_MWATT;
1897 wrqu->txpower.value = le32_to_cpu(tx_power);
1898 wrqu->txpower.disabled = 0;
1899 } else {
1900 wrqu->txpower.flags = IW_TXPOW_MWATT;
1901 wrqu->txpower.value = 0;
1902 wrqu->txpower.disabled = 1;
1903 }
1904
1905 devdbg(usbdev, "SIOCGIWTXPOW: %d", wrqu->txpower.value);
1906
Jussi Kivilinna9656e852009-05-22 17:40:12 +03001907 return 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001908}
1909
1910
1911static int rndis_iw_set_txpower(struct net_device *dev,
1912 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1913{
Wang Chen524ad0a2008-11-12 23:39:10 -08001914 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001915 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001916 __le32 tx_power = 0;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001917
1918 if (!wrqu->txpower.disabled) {
1919 if (wrqu->txpower.flags == IW_TXPOW_MWATT)
1920 tx_power = cpu_to_le32(wrqu->txpower.value);
1921 else { /* wrqu->txpower.flags == IW_TXPOW_DBM */
1922 if (wrqu->txpower.value > 20)
1923 tx_power = cpu_to_le32(128);
1924 else if (wrqu->txpower.value < -43)
1925 tx_power = cpu_to_le32(127);
1926 else {
1927 signed char tmp;
1928 tmp = wrqu->txpower.value;
1929 tmp = -12 - tmp;
1930 tmp <<= 2;
1931 tx_power = cpu_to_le32((unsigned char)tmp);
1932 }
1933 }
1934 }
1935
1936 devdbg(usbdev, "SIOCSIWTXPOW: %d", le32_to_cpu(tx_power));
1937
1938 if (le32_to_cpu(tx_power) != 0) {
Jussi Kivilinna9656e852009-05-22 17:40:12 +03001939 /* txpower unsupported, just turn radio on */
1940 if (!priv->radio_on)
1941 return disassociate(usbdev, 1);
1942 return 0; /* all ready on */
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001943 }
1944
1945 /* tx_power == 0, turn off radio */
1946 return disassociate(usbdev, 0);
1947}
1948
1949
1950static int rndis_iw_get_rate(struct net_device *dev,
1951 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1952{
Wang Chen524ad0a2008-11-12 23:39:10 -08001953 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001954 __le32 tmp;
1955 int ret, len;
1956
1957 len = sizeof(tmp);
1958 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len);
1959 if (ret == 0) {
1960 wrqu->bitrate.value = le32_to_cpu(tmp) * 100;
1961 wrqu->bitrate.disabled = 0;
1962 wrqu->bitrate.flags = 1;
1963 }
1964 return ret;
1965}
1966
1967
1968static int rndis_iw_set_mlme(struct net_device *dev,
1969 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1970{
Wang Chen524ad0a2008-11-12 23:39:10 -08001971 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001972 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001973 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1974 unsigned char bssid[ETH_ALEN];
1975
1976 get_bssid(usbdev, bssid);
1977
1978 if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN))
1979 return -EINVAL;
1980
1981 switch (mlme->cmd) {
1982 case IW_MLME_DEAUTH:
1983 return deauthenticate(usbdev);
1984 case IW_MLME_DISASSOC:
1985 return disassociate(usbdev, priv->radio_on);
1986 default:
1987 return -EOPNOTSUPP;
1988 }
1989
1990 return 0;
1991}
1992
1993
1994static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
1995{
Wang Chen524ad0a2008-11-12 23:39:10 -08001996 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03001997 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02001998 unsigned long flags;
1999
2000 spin_lock_irqsave(&priv->stats_lock, flags);
2001 memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats));
2002 spin_unlock_irqrestore(&priv->stats_lock, flags);
2003
2004 return &priv->iwstats;
2005}
2006
2007
2008#define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT]
2009static const iw_handler rndis_iw_handler[] =
2010{
2011 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002012 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002013 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2014 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
John W. Linville964c1d42009-03-26 23:40:01 +02002015 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2016 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002017 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002018 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2019 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002020 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2021 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002022 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2023 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002024 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
2025 IW_IOCTL(SIOCSIWRTS) = rndis_iw_set_rts,
2026 IW_IOCTL(SIOCGIWRTS) = rndis_iw_get_rts,
2027 IW_IOCTL(SIOCSIWFRAG) = rndis_iw_set_frag,
2028 IW_IOCTL(SIOCGIWFRAG) = rndis_iw_get_frag,
2029 IW_IOCTL(SIOCSIWTXPOW) = rndis_iw_set_txpower,
2030 IW_IOCTL(SIOCGIWTXPOW) = rndis_iw_get_txpower,
2031 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2032 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2033 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
2034 IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth,
2035 IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie,
2036 IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie,
2037 IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme,
2038};
2039
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002040static const iw_handler rndis_wlan_private_handler[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002041};
2042
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002043static const struct iw_priv_args rndis_wlan_private_args[] = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002044};
2045
2046
2047static const struct iw_handler_def rndis_iw_handlers = {
2048 .num_standard = ARRAY_SIZE(rndis_iw_handler),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002049 .num_private = ARRAY_SIZE(rndis_wlan_private_handler),
2050 .num_private_args = ARRAY_SIZE(rndis_wlan_private_args),
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002051 .standard = (iw_handler *)rndis_iw_handler,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002052 .private = (iw_handler *)rndis_wlan_private_handler,
2053 .private_args = (struct iw_priv_args *)rndis_wlan_private_args,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002054 .get_wireless_stats = rndis_get_wireless_stats,
2055};
2056
2057
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002058static void rndis_wlan_worker(struct work_struct *work)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002059{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002060 struct rndis_wlan_private *priv =
2061 container_of(work, struct rndis_wlan_private, work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002062 struct usbnet *usbdev = priv->usbdev;
2063 union iwreq_data evt;
2064 unsigned char bssid[ETH_ALEN];
Scott Ashcroft43646232008-05-27 00:06:15 +03002065 struct ndis_80211_assoc_info *info;
2066 int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32;
2067 int ret, offset;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002068
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002069 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002070 netif_carrier_on(usbdev->net);
2071
Scott Ashcroft43646232008-05-27 00:06:15 +03002072 info = kzalloc(assoc_size, GFP_KERNEL);
2073 if (!info)
2074 goto get_bssid;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002075
Scott Ashcroft43646232008-05-27 00:06:15 +03002076 /* Get association info IEs from device and send them back to
2077 * userspace. */
2078 ret = get_association_info(usbdev, info, assoc_size);
2079 if (!ret) {
2080 evt.data.length = le32_to_cpu(info->req_ie_length);
2081 if (evt.data.length > 0) {
2082 offset = le32_to_cpu(info->offset_req_ies);
2083 wireless_send_event(usbdev->net,
2084 IWEVASSOCREQIE, &evt,
2085 (char *)info + offset);
2086 }
2087
2088 evt.data.length = le32_to_cpu(info->resp_ie_length);
2089 if (evt.data.length > 0) {
2090 offset = le32_to_cpu(info->offset_resp_ies);
2091 wireless_send_event(usbdev->net,
2092 IWEVASSOCRESPIE, &evt,
2093 (char *)info + offset);
2094 }
2095 }
2096
2097 kfree(info);
2098
2099get_bssid:
2100 ret = get_bssid(usbdev, bssid);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002101 if (!ret) {
2102 evt.data.flags = 0;
2103 evt.data.length = 0;
2104 memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN);
2105 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2106 }
2107 }
2108
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002109 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) {
Jussi Kivilinna5331b962008-06-02 18:35:29 +03002110 netif_carrier_off(usbdev->net);
2111
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002112 evt.data.flags = 0;
2113 evt.data.length = 0;
2114 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2115 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2116 }
2117
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002118 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2119 set_multicast_list(usbdev);
2120}
2121
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002122static void rndis_wlan_set_multicast_list(struct net_device *dev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002123{
Wang Chen524ad0a2008-11-12 23:39:10 -08002124 struct usbnet *usbdev = netdev_priv(dev);
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002125 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002126
Jussi Kivilinnaa67edb92008-06-02 18:35:36 +03002127 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2128 return;
2129
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002130 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2131 queue_work(priv->workqueue, &priv->work);
2132}
2133
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002134static void rndis_wlan_link_change(struct usbnet *usbdev, int state)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002135{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002136 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002137
Jussi Kivilinna6010ce02008-06-02 18:35:21 +03002138 /* queue work to avoid recursive calls into rndis_command */
2139 set_bit(state ? WORK_LINK_UP : WORK_LINK_DOWN, &priv->work_pending);
2140 queue_work(priv->workqueue, &priv->work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002141}
2142
2143
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002144static int rndis_wlan_get_caps(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002145{
2146 struct {
2147 __le32 num_items;
2148 __le32 items[8];
2149 } networks_supported;
2150 int len, retval, i, n;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002151 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002152
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002153 /* determine supported modes */
2154 len = sizeof(networks_supported);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002155 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002156 &networks_supported, &len);
2157 if (retval >= 0) {
2158 n = le32_to_cpu(networks_supported.num_items);
2159 if (n > 8)
2160 n = 8;
2161 for (i = 0; i < n; i++) {
2162 switch (le32_to_cpu(networks_supported.items[i])) {
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002163 case NDIS_80211_TYPE_FREQ_HOP:
2164 case NDIS_80211_TYPE_DIRECT_SEQ:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002165 priv->caps |= CAP_MODE_80211B;
2166 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002167 case NDIS_80211_TYPE_OFDM_A:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002168 priv->caps |= CAP_MODE_80211A;
2169 break;
Jussi Kivilinnaaa182942009-06-04 20:13:19 +03002170 case NDIS_80211_TYPE_OFDM_G:
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002171 priv->caps |= CAP_MODE_80211G;
2172 break;
2173 }
2174 }
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002175 }
2176
2177 return retval;
2178}
2179
2180
2181#define STATS_UPDATE_JIFFIES (HZ)
2182static void rndis_update_wireless_stats(struct work_struct *work)
2183{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002184 struct rndis_wlan_private *priv =
2185 container_of(work, struct rndis_wlan_private, stats_work.work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002186 struct usbnet *usbdev = priv->usbdev;
2187 struct iw_statistics iwstats;
2188 __le32 rssi, tmp;
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002189 int len, ret, j;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002190 unsigned long flags;
2191 int update_jiffies = STATS_UPDATE_JIFFIES;
2192 void *buf;
2193
2194 spin_lock_irqsave(&priv->stats_lock, flags);
2195 memcpy(&iwstats, &priv->privstats, sizeof(iwstats));
2196 spin_unlock_irqrestore(&priv->stats_lock, flags);
2197
2198 /* only update stats when connected */
2199 if (!is_associated(usbdev)) {
2200 iwstats.qual.qual = 0;
2201 iwstats.qual.level = 0;
2202 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2203 | IW_QUAL_LEVEL_UPDATED
2204 | IW_QUAL_NOISE_INVALID
2205 | IW_QUAL_QUAL_INVALID
2206 | IW_QUAL_LEVEL_INVALID;
2207 goto end;
2208 }
2209
2210 len = sizeof(rssi);
2211 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2212
2213 devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret,
2214 le32_to_cpu(rssi));
2215 if (ret == 0) {
2216 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2217 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinna4bd7f032009-03-26 23:40:16 +02002218 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002219 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2220 | IW_QUAL_LEVEL_UPDATED
2221 | IW_QUAL_NOISE_INVALID;
2222 }
2223
2224 memset(&iwstats.discard, 0, sizeof(iwstats.discard));
2225
2226 len = sizeof(tmp);
2227 ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len);
2228 if (ret == 0)
2229 iwstats.discard.misc += le32_to_cpu(tmp);
2230
2231 len = sizeof(tmp);
2232 ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len);
2233 if (ret == 0)
2234 iwstats.discard.misc += le32_to_cpu(tmp);
2235
2236 len = sizeof(tmp);
2237 ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len);
2238 if (ret == 0)
2239 iwstats.discard.misc += le32_to_cpu(tmp);
2240
Jussi Kivilinnaa97b1f32008-02-06 15:36:10 +02002241 /* Workaround transfer stalls on poor quality links.
2242 * TODO: find right way to fix these stalls (as stalls do not happen
2243 * with ndiswrapper/windows driver). */
2244 if (iwstats.qual.qual <= 25) {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002245 /* Decrease stats worker interval to catch stalls.
2246 * faster. Faster than 400-500ms causes packet loss,
2247 * Slower doesn't catch stalls fast enough.
2248 */
2249 j = msecs_to_jiffies(priv->param_workaround_interval);
2250 if (j > STATS_UPDATE_JIFFIES)
2251 j = STATS_UPDATE_JIFFIES;
2252 else if (j <= 0)
2253 j = 1;
2254 update_jiffies = j;
2255
2256 /* Send scan OID. Use of both OIDs is required to get device
2257 * working.
2258 */
Harvey Harrison35c26c22009-02-14 22:56:56 -08002259 tmp = cpu_to_le32(1);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002260 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2261 sizeof(tmp));
2262
2263 len = CONTROL_BUFFER_SIZE;
2264 buf = kmalloc(len, GFP_KERNEL);
2265 if (!buf)
2266 goto end;
2267
2268 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2269 kfree(buf);
2270 }
2271end:
2272 spin_lock_irqsave(&priv->stats_lock, flags);
2273 memcpy(&priv->privstats, &iwstats, sizeof(iwstats));
2274 spin_unlock_irqrestore(&priv->stats_lock, flags);
2275
2276 if (update_jiffies >= HZ)
2277 update_jiffies = round_jiffies_relative(update_jiffies);
2278 else {
2279 j = round_jiffies_relative(update_jiffies);
2280 if (abs(j - update_jiffies) <= 10)
2281 update_jiffies = j;
2282 }
2283
2284 queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies);
2285}
2286
2287
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002288static int bcm4320a_early_init(struct usbnet *usbdev)
2289{
2290 /* bcm4320a doesn't handle configuration parameters well. Try
2291 * set any and you get partially zeroed mac and broken device.
2292 */
2293
2294 return 0;
2295}
2296
2297
2298static int bcm4320b_early_init(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002299{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002300 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002301 char buf[8];
2302
2303 /* Early initialization settings, setting these won't have effect
2304 * if called after generic_rndis_bind().
2305 */
2306
2307 priv->param_country[0] = modparam_country[0];
2308 priv->param_country[1] = modparam_country[1];
2309 priv->param_country[2] = 0;
2310 priv->param_frameburst = modparam_frameburst;
2311 priv->param_afterburner = modparam_afterburner;
2312 priv->param_power_save = modparam_power_save;
2313 priv->param_power_output = modparam_power_output;
2314 priv->param_roamtrigger = modparam_roamtrigger;
2315 priv->param_roamdelta = modparam_roamdelta;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002316
2317 priv->param_country[0] = toupper(priv->param_country[0]);
2318 priv->param_country[1] = toupper(priv->param_country[1]);
2319 /* doesn't support EU as country code, use FI instead */
2320 if (!strcmp(priv->param_country, "EU"))
2321 strcpy(priv->param_country, "FI");
2322
2323 if (priv->param_power_save < 0)
2324 priv->param_power_save = 0;
2325 else if (priv->param_power_save > 2)
2326 priv->param_power_save = 2;
2327
Jussi Kivilinnaa7624832008-05-27 11:15:08 +03002328 if (priv->param_power_output < 0)
2329 priv->param_power_output = 0;
2330 else if (priv->param_power_output > 3)
2331 priv->param_power_output = 3;
2332
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002333 if (priv->param_roamtrigger < -80)
2334 priv->param_roamtrigger = -80;
2335 else if (priv->param_roamtrigger > -60)
2336 priv->param_roamtrigger = -60;
2337
2338 if (priv->param_roamdelta < 0)
2339 priv->param_roamdelta = 0;
2340 else if (priv->param_roamdelta > 2)
2341 priv->param_roamdelta = 2;
2342
Roel Kluin4d381ff2008-04-23 22:10:29 +02002343 if (modparam_workaround_interval < 0)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002344 priv->param_workaround_interval = 500;
Roel Kluin4d381ff2008-04-23 22:10:29 +02002345 else
2346 priv->param_workaround_interval = modparam_workaround_interval;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002347
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002348 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2349 rndis_set_config_parameter_str(usbdev, "FrameBursting",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002350 priv->param_frameburst ? "1" : "0");
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002351 rndis_set_config_parameter_str(usbdev, "Afterburner",
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002352 priv->param_afterburner ? "1" : "0");
2353 sprintf(buf, "%d", priv->param_power_save);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002354 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002355 sprintf(buf, "%d", priv->param_power_output);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002356 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002357 sprintf(buf, "%d", priv->param_roamtrigger);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002358 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002359 sprintf(buf, "%d", priv->param_roamdelta);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002360 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002361
2362 return 0;
2363}
2364
David S. Miller23d12e22009-03-25 00:03:16 -07002365/* same as rndis_netdev_ops but with local multicast handler */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002366static const struct net_device_ops rndis_wlan_netdev_ops = {
David S. Miller23d12e22009-03-25 00:03:16 -07002367 .ndo_open = usbnet_open,
2368 .ndo_stop = usbnet_stop,
2369 .ndo_start_xmit = usbnet_start_xmit,
2370 .ndo_tx_timeout = usbnet_tx_timeout,
2371 .ndo_set_mac_address = eth_mac_addr,
2372 .ndo_validate_addr = eth_validate_addr,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002373 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
David S. Miller23d12e22009-03-25 00:03:16 -07002374};
2375
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002376
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002377static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002378{
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002379 struct wiphy *wiphy;
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002380 struct rndis_wlan_private *priv;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002381 int retval, len;
2382 __le32 tmp;
2383
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002384 /* allocate wiphy and rndis private data
2385 * NOTE: We only support a single virtual interface, so wiphy
2386 * and wireless_dev are somewhat synonymous for this device.
2387 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002388 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002389 if (!wiphy)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002390 return -ENOMEM;
2391
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002392 priv = wiphy_priv(wiphy);
2393 usbdev->net->ieee80211_ptr = &priv->wdev;
2394 priv->wdev.wiphy = wiphy;
2395 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2396
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002397 /* These have to be initialized before calling generic_rndis_bind().
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002398 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002399 */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002400 usbdev->driver_priv = priv;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002401 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2402 priv->usbdev = usbdev;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002403
2404 mutex_init(&priv->command_lock);
2405 spin_lock_init(&priv->stats_lock);
2406
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002407 /* because rndis_command() sleeps we need to use workqueue */
2408 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002409 INIT_WORK(&priv->work, rndis_wlan_worker);
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002410 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2411 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2412
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002413 /* try bind rndis_host */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002414 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002415 if (retval < 0)
2416 goto fail;
2417
2418 /* generic_rndis_bind set packet filter to multicast_all+
2419 * promisc mode which doesn't work well for our devices (device
2420 * picks up rssi to closest station instead of to access point).
2421 *
2422 * rndis_host wants to avoid all OID as much as possible
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002423 * so do promisc/multicast handling in rndis_wlan.
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002424 */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002425 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
David S. Miller23d12e22009-03-25 00:03:16 -07002426
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002427 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002428 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002429 sizeof(tmp));
2430
2431 len = sizeof(tmp);
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002432 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2433 &len);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002434 priv->multicast_size = le32_to_cpu(tmp);
2435 if (retval < 0 || priv->multicast_size < 0)
2436 priv->multicast_size = 0;
2437 if (priv->multicast_size > 0)
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002438 usbdev->net->flags |= IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002439 else
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002440 usbdev->net->flags &= ~IFF_MULTICAST;
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002441
2442 priv->iwstats.qual.qual = 0;
2443 priv->iwstats.qual.level = 0;
2444 priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2445 | IW_QUAL_LEVEL_UPDATED
2446 | IW_QUAL_NOISE_INVALID
2447 | IW_QUAL_QUAL_INVALID
2448 | IW_QUAL_LEVEL_INVALID;
2449
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002450 /* fill-out wiphy structure and register w/ cfg80211 */
2451 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2452 wiphy->privid = rndis_wiphy_privid;
2453 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2454 | BIT(NL80211_IFTYPE_ADHOC);
2455 wiphy->max_scan_ssids = 1;
2456
2457 /* TODO: fill-out band information based on priv->caps */
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002458 rndis_wlan_get_caps(usbdev);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002459
2460 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2461 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2462 priv->band.channels = priv->channels;
2463 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2464 priv->band.bitrates = priv->rates;
2465 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2466 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
Jussi Kivilinna4d2a3692009-03-26 23:40:23 +02002467 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002468
2469 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2470
2471 if (wiphy_register(wiphy)) {
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002472 retval = -ENODEV;
2473 goto fail;
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002474 }
2475
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002476 set_default_iw_params(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002477
2478 /* turn radio on */
2479 priv->radio_on = 1;
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002480 disassociate(usbdev, 1);
2481 netif_carrier_off(usbdev->net);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002482
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002483 queue_delayed_work(priv->workqueue, &priv->stats_work,
2484 round_jiffies_relative(STATS_UPDATE_JIFFIES));
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002485
2486 return 0;
2487
2488fail:
Jussi Kivilinna8d4d99a2009-04-21 19:48:07 +03002489 cancel_delayed_work_sync(&priv->stats_work);
2490 cancel_delayed_work_sync(&priv->scan_work);
2491 cancel_work_sync(&priv->work);
2492 flush_workqueue(priv->workqueue);
2493 destroy_workqueue(priv->workqueue);
2494
Jussi Kivilinnaeb1a6852009-04-21 19:48:15 +03002495 wiphy_free(wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002496 return retval;
2497}
2498
2499
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002500static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002501{
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002502 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002503
2504 /* turn radio off */
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002505 disassociate(usbdev, 0);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002506
2507 cancel_delayed_work_sync(&priv->stats_work);
Jussi Kivilinna71a7b262009-03-26 23:40:31 +02002508 cancel_delayed_work_sync(&priv->scan_work);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002509 cancel_work_sync(&priv->work);
2510 flush_workqueue(priv->workqueue);
2511 destroy_workqueue(priv->workqueue);
2512
2513 if (priv && priv->wpa_ie_len)
2514 kfree(priv->wpa_ie);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002515
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002516 rndis_unbind(usbdev, intf);
John W. Linville5c8fa4f2009-03-26 23:39:53 +02002517
2518 wiphy_unregister(priv->wdev.wiphy);
2519 wiphy_free(priv->wdev.wiphy);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002520}
2521
2522
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002523static int rndis_wlan_reset(struct usbnet *usbdev)
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002524{
Jussi Kivilinnaa19d7292008-06-02 18:35:44 +03002525 return deauthenticate(usbdev);
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002526}
2527
2528
2529static const struct driver_info bcm4320b_info = {
2530 .description = "Wireless RNDIS device, BCM4320b based",
2531 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002532 .bind = rndis_wlan_bind,
2533 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002534 .status = rndis_status,
2535 .rx_fixup = rndis_rx_fixup,
2536 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002537 .reset = rndis_wlan_reset,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002538 .early_init = bcm4320b_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002539 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002540};
2541
2542static const struct driver_info bcm4320a_info = {
2543 .description = "Wireless RNDIS device, BCM4320a based",
2544 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002545 .bind = rndis_wlan_bind,
2546 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002547 .status = rndis_status,
2548 .rx_fixup = rndis_rx_fixup,
2549 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002550 .reset = rndis_wlan_reset,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002551 .early_init = bcm4320a_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002552 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002553};
2554
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002555static const struct driver_info rndis_wlan_info = {
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002556 .description = "Wireless RNDIS device",
2557 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002558 .bind = rndis_wlan_bind,
2559 .unbind = rndis_wlan_unbind,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002560 .status = rndis_status,
2561 .rx_fixup = rndis_rx_fixup,
2562 .tx_fixup = rndis_tx_fixup,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002563 .reset = rndis_wlan_reset,
Jussi Kivilinna59620e92009-05-22 11:58:36 +03002564 .early_init = bcm4320a_early_init,
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002565 .link_change = rndis_wlan_link_change,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002566};
2567
2568/*-------------------------------------------------------------------------*/
2569
2570static const struct usb_device_id products [] = {
2571#define RNDIS_MASTER_INTERFACE \
2572 .bInterfaceClass = USB_CLASS_COMM, \
2573 .bInterfaceSubClass = 2 /* ACM */, \
2574 .bInterfaceProtocol = 0x0ff
2575
2576/* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2577 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2578 */
2579{
2580 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2581 | USB_DEVICE_ID_MATCH_DEVICE,
2582 .idVendor = 0x0411,
2583 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
2584 RNDIS_MASTER_INTERFACE,
2585 .driver_info = (unsigned long) &bcm4320b_info,
2586}, {
2587 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2588 | USB_DEVICE_ID_MATCH_DEVICE,
2589 .idVendor = 0x0baf,
2590 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
2591 RNDIS_MASTER_INTERFACE,
2592 .driver_info = (unsigned long) &bcm4320b_info,
2593}, {
2594 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2595 | USB_DEVICE_ID_MATCH_DEVICE,
2596 .idVendor = 0x050d,
2597 .idProduct = 0x011b, /* Belkin F5D7051 */
2598 RNDIS_MASTER_INTERFACE,
2599 .driver_info = (unsigned long) &bcm4320b_info,
2600}, {
2601 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2602 | USB_DEVICE_ID_MATCH_DEVICE,
2603 .idVendor = 0x1799, /* Belkin has two vendor ids */
2604 .idProduct = 0x011b, /* Belkin F5D7051 */
2605 RNDIS_MASTER_INTERFACE,
2606 .driver_info = (unsigned long) &bcm4320b_info,
2607}, {
2608 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2609 | USB_DEVICE_ID_MATCH_DEVICE,
2610 .idVendor = 0x13b1,
2611 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
2612 RNDIS_MASTER_INTERFACE,
2613 .driver_info = (unsigned long) &bcm4320b_info,
2614}, {
2615 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2616 | USB_DEVICE_ID_MATCH_DEVICE,
2617 .idVendor = 0x13b1,
2618 .idProduct = 0x0026, /* Linksys WUSB54GSC */
2619 RNDIS_MASTER_INTERFACE,
2620 .driver_info = (unsigned long) &bcm4320b_info,
2621}, {
2622 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2623 | USB_DEVICE_ID_MATCH_DEVICE,
2624 .idVendor = 0x0b05,
2625 .idProduct = 0x1717, /* Asus WL169gE */
2626 RNDIS_MASTER_INTERFACE,
2627 .driver_info = (unsigned long) &bcm4320b_info,
2628}, {
2629 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2630 | USB_DEVICE_ID_MATCH_DEVICE,
2631 .idVendor = 0x0a5c,
2632 .idProduct = 0xd11b, /* Eminent EM4045 */
2633 RNDIS_MASTER_INTERFACE,
2634 .driver_info = (unsigned long) &bcm4320b_info,
2635}, {
2636 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2637 | USB_DEVICE_ID_MATCH_DEVICE,
2638 .idVendor = 0x1690,
2639 .idProduct = 0x0715, /* BT Voyager 1055 */
2640 RNDIS_MASTER_INTERFACE,
2641 .driver_info = (unsigned long) &bcm4320b_info,
2642},
2643/* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
2644 * parameters available, hardware probably contain older firmware version with
2645 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
2646 */
2647{
2648 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2649 | USB_DEVICE_ID_MATCH_DEVICE,
2650 .idVendor = 0x13b1,
2651 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
2652 RNDIS_MASTER_INTERFACE,
2653 .driver_info = (unsigned long) &bcm4320a_info,
2654}, {
2655 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2656 | USB_DEVICE_ID_MATCH_DEVICE,
2657 .idVendor = 0x0baf,
2658 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
2659 RNDIS_MASTER_INTERFACE,
2660 .driver_info = (unsigned long) &bcm4320a_info,
2661}, {
2662 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2663 | USB_DEVICE_ID_MATCH_DEVICE,
2664 .idVendor = 0x0411,
2665 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
2666 RNDIS_MASTER_INTERFACE,
2667 .driver_info = (unsigned long) &bcm4320a_info,
2668},
2669/* Generic Wireless RNDIS devices that we don't have exact
2670 * idVendor/idProduct/chip yet.
2671 */
2672{
2673 /* RNDIS is MSFT's un-official variant of CDC ACM */
2674 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002675 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002676}, {
2677 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
2678 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
Jussi Kivilinna582241a02009-06-04 20:13:25 +03002679 .driver_info = (unsigned long) &rndis_wlan_info,
Jussi Kivilinnabf164cc2008-01-26 00:51:51 +02002680},
2681 { }, // END
2682};
2683MODULE_DEVICE_TABLE(usb, products);
2684
2685static struct usb_driver rndis_wlan_driver = {
2686 .name = "rndis_wlan",
2687 .id_table = products,
2688 .probe = usbnet_probe,
2689 .disconnect = usbnet_disconnect,
2690 .suspend = usbnet_suspend,
2691 .resume = usbnet_resume,
2692};
2693
2694static int __init rndis_wlan_init(void)
2695{
2696 return usb_register(&rndis_wlan_driver);
2697}
2698module_init(rndis_wlan_init);
2699
2700static void __exit rndis_wlan_exit(void)
2701{
2702 usb_deregister(&rndis_wlan_driver);
2703}
2704module_exit(rndis_wlan_exit);
2705
2706MODULE_AUTHOR("Bjorge Dijkstra");
2707MODULE_AUTHOR("Jussi Kivilinna");
2708MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
2709MODULE_LICENSE("GPL");
2710