rndis_wlan: copy only useful data from rndis_command respond
[deliverable/linux.git] / drivers / net / wireless / rndis_wlan.c
1 /*
2 * Driver for RNDIS based wireless USB devices.
3 *
4 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
5 * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
6 *
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>
40 #include <linux/ieee80211.h>
41 #include <linux/if_arp.h>
42 #include <linux/ctype.h>
43 #include <linux/spinlock.h>
44 #include <net/iw_handler.h>
45 #include <net/cfg80211.h>
46 #include <linux/usb/usbnet.h>
47 #include <linux/usb/rndis_host.h>
48
49
50 /* NOTE: All these are settings for Broadcom chipset */
51 static char modparam_country[4] = "EU";
52 module_param_string(country, modparam_country, 4, 0444);
53 MODULE_PARM_DESC(country, "Country code (ISO 3166-1 alpha-2), default: EU");
54
55 static int modparam_frameburst = 1;
56 module_param_named(frameburst, modparam_frameburst, int, 0444);
57 MODULE_PARM_DESC(frameburst, "enable frame bursting (default: on)");
58
59 static int modparam_afterburner = 0;
60 module_param_named(afterburner, modparam_afterburner, int, 0444);
61 MODULE_PARM_DESC(afterburner,
62 "enable afterburner aka '125 High Speed Mode' (default: off)");
63
64 static int modparam_power_save = 0;
65 module_param_named(power_save, modparam_power_save, int, 0444);
66 MODULE_PARM_DESC(power_save,
67 "set power save mode: 0=off, 1=on, 2=fast (default: off)");
68
69 static int modparam_power_output = 3;
70 module_param_named(power_output, modparam_power_output, int, 0444);
71 MODULE_PARM_DESC(power_output,
72 "set power output: 0=25%, 1=50%, 2=75%, 3=100% (default: 100%)");
73
74 static int modparam_roamtrigger = -70;
75 module_param_named(roamtrigger, modparam_roamtrigger, int, 0444);
76 MODULE_PARM_DESC(roamtrigger,
77 "set roaming dBm trigger: -80=optimize for distance, "
78 "-60=bandwidth (default: -70)");
79
80 static int modparam_roamdelta = 1;
81 module_param_named(roamdelta, modparam_roamdelta, int, 0444);
82 MODULE_PARM_DESC(roamdelta,
83 "set roaming tendency: 0=aggressive, 1=moderate, "
84 "2=conservative (default: moderate)");
85
86 static int modparam_workaround_interval;
87 module_param_named(workaround_interval, modparam_workaround_interval,
88 int, 0444);
89 MODULE_PARM_DESC(workaround_interval,
90 "set stall workaround interval in msecs (0=disabled) (default: 0)");
91
92
93 /* various RNDIS OID defs */
94 #define OID_GEN_LINK_SPEED cpu_to_le32(0x00010107)
95 #define OID_GEN_RNDIS_CONFIG_PARAMETER cpu_to_le32(0x0001021b)
96
97 #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)
102
103 #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102)
104 #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103)
105 #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104)
106
107 #define OID_802_11_BSSID cpu_to_le32(0x0d010101)
108 #define OID_802_11_SSID cpu_to_le32(0x0d010102)
109 #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108)
110 #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113)
111 #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114)
112 #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115)
113 #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118)
114 #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119)
115 #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a)
116 #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b)
117 #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d)
118 #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e)
119 #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f)
120 #define OID_802_11_PMKID cpu_to_le32(0x0d010123)
121 #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203)
122 #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204)
123 #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205)
124 #define OID_802_11_RSSI cpu_to_le32(0x0d010206)
125 #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207)
126 #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209)
127 #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a)
128 #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e)
129 #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211)
130 #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217)
131
132
133 /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */
134 #define WL_NOISE -96 /* typical noise level in dBm */
135 #define WL_SIGMAX -32 /* typical maximum signal level in dBm */
136
137
138 /* Assume that Broadcom 4320 (only chipset at time of writing known to be
139 * based on wireless rndis) has default txpower of 13dBm.
140 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
141 * 100% : 20 mW ~ 13dBm
142 * 75% : 15 mW ~ 12dBm
143 * 50% : 10 mW ~ 10dBm
144 * 25% : 5 mW ~ 7dBm
145 */
146 #define BCM4320_DEFAULT_TXPOWER_DBM_100 13
147 #define BCM4320_DEFAULT_TXPOWER_DBM_75 12
148 #define BCM4320_DEFAULT_TXPOWER_DBM_50 10
149 #define BCM4320_DEFAULT_TXPOWER_DBM_25 7
150
151
152 /* codes for "status" field of completion messages */
153 #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011)
154 #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012)
155
156
157 /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c
158 * slightly modified for datatype endianess, etc
159 */
160 #define NDIS_802_11_LENGTH_SSID 32
161 #define NDIS_802_11_LENGTH_RATES 8
162 #define NDIS_802_11_LENGTH_RATES_EX 16
163
164 enum ndis_80211_net_type {
165 NDIS_80211_TYPE_FREQ_HOP,
166 NDIS_80211_TYPE_DIRECT_SEQ,
167 NDIS_80211_TYPE_OFDM_A,
168 NDIS_80211_TYPE_OFDM_G
169 };
170
171 enum ndis_80211_net_infra {
172 NDIS_80211_INFRA_ADHOC,
173 NDIS_80211_INFRA_INFRA,
174 NDIS_80211_INFRA_AUTO_UNKNOWN
175 };
176
177 enum ndis_80211_auth_mode {
178 NDIS_80211_AUTH_OPEN,
179 NDIS_80211_AUTH_SHARED,
180 NDIS_80211_AUTH_AUTO_SWITCH,
181 NDIS_80211_AUTH_WPA,
182 NDIS_80211_AUTH_WPA_PSK,
183 NDIS_80211_AUTH_WPA_NONE,
184 NDIS_80211_AUTH_WPA2,
185 NDIS_80211_AUTH_WPA2_PSK
186 };
187
188 enum ndis_80211_encr_status {
189 NDIS_80211_ENCR_WEP_ENABLED,
190 NDIS_80211_ENCR_DISABLED,
191 NDIS_80211_ENCR_WEP_KEY_ABSENT,
192 NDIS_80211_ENCR_NOT_SUPPORTED,
193 NDIS_80211_ENCR_TKIP_ENABLED,
194 NDIS_80211_ENCR_TKIP_KEY_ABSENT,
195 NDIS_80211_ENCR_CCMP_ENABLED,
196 NDIS_80211_ENCR_CCMP_KEY_ABSENT
197 };
198
199 enum ndis_80211_priv_filter {
200 NDIS_80211_PRIV_ACCEPT_ALL,
201 NDIS_80211_PRIV_8021X_WEP
202 };
203
204 enum ndis_80211_status_type {
205 NDIS_80211_STATUSTYPE_AUTHENTICATION,
206 NDIS_80211_STATUSTYPE_MEDIASTREAMMODE,
207 NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST,
208 NDIS_80211_STATUSTYPE_RADIOSTATE,
209 };
210
211 enum ndis_80211_media_stream_mode {
212 NDIS_80211_MEDIA_STREAM_OFF,
213 NDIS_80211_MEDIA_STREAM_ON
214 };
215
216 enum ndis_80211_radio_status {
217 NDIS_80211_RADIO_STATUS_ON,
218 NDIS_80211_RADIO_STATUS_HARDWARE_OFF,
219 NDIS_80211_RADIO_STATUS_SOFTWARE_OFF,
220 };
221
222 enum ndis_80211_addkey_bits {
223 NDIS_80211_ADDKEY_8021X_AUTH = cpu_to_le32(1 << 28),
224 NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ = cpu_to_le32(1 << 29),
225 NDIS_80211_ADDKEY_PAIRWISE_KEY = cpu_to_le32(1 << 30),
226 NDIS_80211_ADDKEY_TRANSMIT_KEY = cpu_to_le32(1 << 31)
227 };
228
229 enum ndis_80211_addwep_bits {
230 NDIS_80211_ADDWEP_PERCLIENT_KEY = cpu_to_le32(1 << 30),
231 NDIS_80211_ADDWEP_TRANSMIT_KEY = cpu_to_le32(1 << 31)
232 };
233
234 struct ndis_80211_auth_request {
235 __le32 length;
236 u8 bssid[6];
237 u8 padding[2];
238 __le32 flags;
239 } __attribute__((packed));
240
241 struct ndis_80211_pmkid_candidate {
242 u8 bssid[6];
243 u8 padding[2];
244 __le32 flags;
245 } __attribute__((packed));
246
247 struct ndis_80211_pmkid_cand_list {
248 __le32 version;
249 __le32 num_candidates;
250 struct ndis_80211_pmkid_candidate candidate_list[0];
251 } __attribute__((packed));
252
253 struct ndis_80211_status_indication {
254 __le32 status_type;
255 union {
256 __le32 media_stream_mode;
257 __le32 radio_status;
258 struct ndis_80211_auth_request auth_request[0];
259 struct ndis_80211_pmkid_cand_list cand_list;
260 } u;
261 } __attribute__((packed));
262
263 struct ndis_80211_ssid {
264 __le32 length;
265 u8 essid[NDIS_802_11_LENGTH_SSID];
266 } __attribute__((packed));
267
268 struct ndis_80211_conf_freq_hop {
269 __le32 length;
270 __le32 hop_pattern;
271 __le32 hop_set;
272 __le32 dwell_time;
273 } __attribute__((packed));
274
275 struct ndis_80211_conf {
276 __le32 length;
277 __le32 beacon_period;
278 __le32 atim_window;
279 __le32 ds_config;
280 struct ndis_80211_conf_freq_hop fh_config;
281 } __attribute__((packed));
282
283 struct ndis_80211_bssid_ex {
284 __le32 length;
285 u8 mac[6];
286 u8 padding[2];
287 struct ndis_80211_ssid ssid;
288 __le32 privacy;
289 __le32 rssi;
290 __le32 net_type;
291 struct ndis_80211_conf config;
292 __le32 net_infra;
293 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
294 __le32 ie_length;
295 u8 ies[0];
296 } __attribute__((packed));
297
298 struct ndis_80211_bssid_list_ex {
299 __le32 num_items;
300 struct ndis_80211_bssid_ex bssid[0];
301 } __attribute__((packed));
302
303 struct ndis_80211_fixed_ies {
304 u8 timestamp[8];
305 __le16 beacon_interval;
306 __le16 capabilities;
307 } __attribute__((packed));
308
309 struct ndis_80211_wep_key {
310 __le32 size;
311 __le32 index;
312 __le32 length;
313 u8 material[32];
314 } __attribute__((packed));
315
316 struct ndis_80211_key {
317 __le32 size;
318 __le32 index;
319 __le32 length;
320 u8 bssid[6];
321 u8 padding[6];
322 u8 rsc[8];
323 u8 material[32];
324 } __attribute__((packed));
325
326 struct ndis_80211_remove_key {
327 __le32 size;
328 __le32 index;
329 u8 bssid[6];
330 u8 padding[2];
331 } __attribute__((packed));
332
333 struct ndis_config_param {
334 __le32 name_offs;
335 __le32 name_length;
336 __le32 type;
337 __le32 value_offs;
338 __le32 value_length;
339 } __attribute__((packed));
340
341 struct ndis_80211_assoc_info {
342 __le32 length;
343 __le16 req_ies;
344 struct req_ie {
345 __le16 capa;
346 __le16 listen_interval;
347 u8 cur_ap_address[6];
348 } req_ie;
349 __le32 req_ie_length;
350 __le32 offset_req_ies;
351 __le16 resp_ies;
352 struct resp_ie {
353 __le16 capa;
354 __le16 status_code;
355 __le16 assoc_id;
356 } resp_ie;
357 __le32 resp_ie_length;
358 __le32 offset_resp_ies;
359 } __attribute__((packed));
360
361 /*
362 * private data
363 */
364 #define NET_TYPE_11FB 0
365
366 #define CAP_MODE_80211A 1
367 #define CAP_MODE_80211B 2
368 #define CAP_MODE_80211G 4
369 #define CAP_MODE_MASK 7
370
371 #define WORK_LINK_UP (1<<0)
372 #define WORK_LINK_DOWN (1<<1)
373 #define WORK_SET_MULTICAST_LIST (1<<2)
374
375 #define RNDIS_WLAN_ALG_NONE 0
376 #define RNDIS_WLAN_ALG_WEP (1<<0)
377 #define RNDIS_WLAN_ALG_TKIP (1<<1)
378 #define RNDIS_WLAN_ALG_CCMP (1<<2)
379
380 #define RNDIS_WLAN_KEY_MGMT_NONE 0
381 #define RNDIS_WLAN_KEY_MGMT_802_1X (1<<0)
382 #define RNDIS_WLAN_KEY_MGMT_PSK (1<<1)
383
384 #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
385
386 static const struct ieee80211_channel rndis_channels[] = {
387 { .center_freq = 2412 },
388 { .center_freq = 2417 },
389 { .center_freq = 2422 },
390 { .center_freq = 2427 },
391 { .center_freq = 2432 },
392 { .center_freq = 2437 },
393 { .center_freq = 2442 },
394 { .center_freq = 2447 },
395 { .center_freq = 2452 },
396 { .center_freq = 2457 },
397 { .center_freq = 2462 },
398 { .center_freq = 2467 },
399 { .center_freq = 2472 },
400 { .center_freq = 2484 },
401 };
402
403 static const struct ieee80211_rate rndis_rates[] = {
404 { .bitrate = 10 },
405 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
406 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
407 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
408 { .bitrate = 60 },
409 { .bitrate = 90 },
410 { .bitrate = 120 },
411 { .bitrate = 180 },
412 { .bitrate = 240 },
413 { .bitrate = 360 },
414 { .bitrate = 480 },
415 { .bitrate = 540 }
416 };
417
418 static const u32 rndis_cipher_suites[] = {
419 WLAN_CIPHER_SUITE_WEP40,
420 WLAN_CIPHER_SUITE_WEP104,
421 WLAN_CIPHER_SUITE_TKIP,
422 WLAN_CIPHER_SUITE_CCMP,
423 };
424
425 struct rndis_wlan_encr_key {
426 int len;
427 u32 cipher;
428 u8 material[32];
429 u8 bssid[ETH_ALEN];
430 bool pairwise;
431 bool tx_key;
432 };
433
434 /* RNDIS device private data */
435 struct rndis_wlan_private {
436 struct usbnet *usbdev;
437
438 struct wireless_dev wdev;
439
440 struct cfg80211_scan_request *scan_request;
441
442 struct workqueue_struct *workqueue;
443 struct delayed_work dev_poller_work;
444 struct delayed_work scan_work;
445 struct work_struct work;
446 struct mutex command_lock;
447 unsigned long work_pending;
448 int last_qual;
449
450 struct ieee80211_supported_band band;
451 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
452 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
453 u32 cipher_suites[ARRAY_SIZE(rndis_cipher_suites)];
454
455 int caps;
456 int multicast_size;
457
458 /* module parameters */
459 char param_country[4];
460 int param_frameburst;
461 int param_afterburner;
462 int param_power_save;
463 int param_power_output;
464 int param_roamtrigger;
465 int param_roamdelta;
466 u32 param_workaround_interval;
467
468 /* hardware state */
469 bool radio_on;
470 int infra_mode;
471 bool connected;
472 u8 bssid[ETH_ALEN];
473 struct ndis_80211_ssid essid;
474 __le32 current_command_oid;
475
476 /* encryption stuff */
477 int encr_tx_key_index;
478 struct rndis_wlan_encr_key encr_keys[4];
479 enum nl80211_auth_type wpa_auth_type;
480 int wpa_version;
481 int wpa_keymgmt;
482 int wpa_ie_len;
483 u8 *wpa_ie;
484 int wpa_cipher_pair;
485 int wpa_cipher_group;
486
487 u8 command_buffer[COMMAND_BUFFER_SIZE];
488 };
489
490 /*
491 * cfg80211 ops
492 */
493 static int rndis_change_virtual_intf(struct wiphy *wiphy,
494 struct net_device *dev,
495 enum nl80211_iftype type, u32 *flags,
496 struct vif_params *params);
497
498 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
499 struct cfg80211_scan_request *request);
500
501 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
502
503 static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
504 int dbm);
505 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
506
507 static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
508 struct cfg80211_connect_params *sme);
509
510 static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
511 u16 reason_code);
512
513 static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
514 struct cfg80211_ibss_params *params);
515
516 static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev);
517
518 static int rndis_set_channel(struct wiphy *wiphy,
519 struct ieee80211_channel *chan, enum nl80211_channel_type channel_type);
520
521 static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
522 u8 key_index, const u8 *mac_addr,
523 struct key_params *params);
524
525 static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
526 u8 key_index, const u8 *mac_addr);
527
528 static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
529 u8 key_index);
530
531 static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
532 u8 *mac, struct station_info *sinfo);
533
534 static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
535 int idx, u8 *mac, struct station_info *sinfo);
536
537 static struct cfg80211_ops rndis_config_ops = {
538 .change_virtual_intf = rndis_change_virtual_intf,
539 .scan = rndis_scan,
540 .set_wiphy_params = rndis_set_wiphy_params,
541 .set_tx_power = rndis_set_tx_power,
542 .get_tx_power = rndis_get_tx_power,
543 .connect = rndis_connect,
544 .disconnect = rndis_disconnect,
545 .join_ibss = rndis_join_ibss,
546 .leave_ibss = rndis_leave_ibss,
547 .set_channel = rndis_set_channel,
548 .add_key = rndis_add_key,
549 .del_key = rndis_del_key,
550 .set_default_key = rndis_set_default_key,
551 .get_station = rndis_get_station,
552 .dump_station = rndis_dump_station,
553 };
554
555 static void *rndis_wiphy_privid = &rndis_wiphy_privid;
556
557
558 static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
559 {
560 return (struct rndis_wlan_private *)dev->driver_priv;
561 }
562
563 static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
564 {
565 switch (priv->param_power_output) {
566 default:
567 case 3:
568 return BCM4320_DEFAULT_TXPOWER_DBM_100;
569 case 2:
570 return BCM4320_DEFAULT_TXPOWER_DBM_75;
571 case 1:
572 return BCM4320_DEFAULT_TXPOWER_DBM_50;
573 case 0:
574 return BCM4320_DEFAULT_TXPOWER_DBM_25;
575 }
576 }
577
578 static bool is_wpa_key(struct rndis_wlan_private *priv, int idx)
579 {
580 int cipher = priv->encr_keys[idx].cipher;
581
582 return (cipher == WLAN_CIPHER_SUITE_CCMP ||
583 cipher == WLAN_CIPHER_SUITE_TKIP);
584 }
585
586 static int rndis_cipher_to_alg(u32 cipher)
587 {
588 switch (cipher) {
589 default:
590 return RNDIS_WLAN_ALG_NONE;
591 case WLAN_CIPHER_SUITE_WEP40:
592 case WLAN_CIPHER_SUITE_WEP104:
593 return RNDIS_WLAN_ALG_WEP;
594 case WLAN_CIPHER_SUITE_TKIP:
595 return RNDIS_WLAN_ALG_TKIP;
596 case WLAN_CIPHER_SUITE_CCMP:
597 return RNDIS_WLAN_ALG_CCMP;
598 }
599 }
600
601 static int rndis_akm_suite_to_key_mgmt(u32 akm_suite)
602 {
603 switch (akm_suite) {
604 default:
605 return RNDIS_WLAN_KEY_MGMT_NONE;
606 case WLAN_AKM_SUITE_8021X:
607 return RNDIS_WLAN_KEY_MGMT_802_1X;
608 case WLAN_AKM_SUITE_PSK:
609 return RNDIS_WLAN_KEY_MGMT_PSK;
610 }
611 }
612
613 #ifdef DEBUG
614 static const char *oid_to_string(__le32 oid)
615 {
616 switch (oid) {
617 #define OID_STR(oid) case oid: return(#oid)
618 /* from rndis_host.h */
619 OID_STR(OID_802_3_PERMANENT_ADDRESS);
620 OID_STR(OID_GEN_MAXIMUM_FRAME_SIZE);
621 OID_STR(OID_GEN_CURRENT_PACKET_FILTER);
622 OID_STR(OID_GEN_PHYSICAL_MEDIUM);
623
624 /* from rndis_wlan.c */
625 OID_STR(OID_GEN_LINK_SPEED);
626 OID_STR(OID_GEN_RNDIS_CONFIG_PARAMETER);
627
628 OID_STR(OID_GEN_XMIT_OK);
629 OID_STR(OID_GEN_RCV_OK);
630 OID_STR(OID_GEN_XMIT_ERROR);
631 OID_STR(OID_GEN_RCV_ERROR);
632 OID_STR(OID_GEN_RCV_NO_BUFFER);
633
634 OID_STR(OID_802_3_CURRENT_ADDRESS);
635 OID_STR(OID_802_3_MULTICAST_LIST);
636 OID_STR(OID_802_3_MAXIMUM_LIST_SIZE);
637
638 OID_STR(OID_802_11_BSSID);
639 OID_STR(OID_802_11_SSID);
640 OID_STR(OID_802_11_INFRASTRUCTURE_MODE);
641 OID_STR(OID_802_11_ADD_WEP);
642 OID_STR(OID_802_11_REMOVE_WEP);
643 OID_STR(OID_802_11_DISASSOCIATE);
644 OID_STR(OID_802_11_AUTHENTICATION_MODE);
645 OID_STR(OID_802_11_PRIVACY_FILTER);
646 OID_STR(OID_802_11_BSSID_LIST_SCAN);
647 OID_STR(OID_802_11_ENCRYPTION_STATUS);
648 OID_STR(OID_802_11_ADD_KEY);
649 OID_STR(OID_802_11_REMOVE_KEY);
650 OID_STR(OID_802_11_ASSOCIATION_INFORMATION);
651 OID_STR(OID_802_11_PMKID);
652 OID_STR(OID_802_11_NETWORK_TYPES_SUPPORTED);
653 OID_STR(OID_802_11_NETWORK_TYPE_IN_USE);
654 OID_STR(OID_802_11_TX_POWER_LEVEL);
655 OID_STR(OID_802_11_RSSI);
656 OID_STR(OID_802_11_RSSI_TRIGGER);
657 OID_STR(OID_802_11_FRAGMENTATION_THRESHOLD);
658 OID_STR(OID_802_11_RTS_THRESHOLD);
659 OID_STR(OID_802_11_SUPPORTED_RATES);
660 OID_STR(OID_802_11_CONFIGURATION);
661 OID_STR(OID_802_11_BSSID_LIST);
662 #undef OID_STR
663 }
664
665 return "?";
666 }
667 #else
668 static const char *oid_to_string(__le32 oid)
669 {
670 return "?";
671 }
672 #endif
673
674 /* translate error code */
675 static int rndis_error_status(__le32 rndis_status)
676 {
677 int ret = -EINVAL;
678 switch (rndis_status) {
679 case RNDIS_STATUS_SUCCESS:
680 ret = 0;
681 break;
682 case RNDIS_STATUS_FAILURE:
683 case RNDIS_STATUS_INVALID_DATA:
684 ret = -EINVAL;
685 break;
686 case RNDIS_STATUS_NOT_SUPPORTED:
687 ret = -EOPNOTSUPP;
688 break;
689 case RNDIS_STATUS_ADAPTER_NOT_READY:
690 case RNDIS_STATUS_ADAPTER_NOT_OPEN:
691 ret = -EBUSY;
692 break;
693 }
694 return ret;
695 }
696
697 static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len)
698 {
699 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
700 union {
701 void *buf;
702 struct rndis_msg_hdr *header;
703 struct rndis_query *get;
704 struct rndis_query_c *get_c;
705 } u;
706 int ret, buflen;
707 int resplen, respoffs, copylen;
708
709 buflen = *len + sizeof(*u.get);
710 if (buflen < CONTROL_BUFFER_SIZE)
711 buflen = CONTROL_BUFFER_SIZE;
712
713 if (buflen > COMMAND_BUFFER_SIZE) {
714 u.buf = kmalloc(buflen, GFP_KERNEL);
715 if (!u.buf)
716 return -ENOMEM;
717 } else {
718 u.buf = priv->command_buffer;
719 }
720
721 mutex_lock(&priv->command_lock);
722
723 memset(u.get, 0, sizeof *u.get);
724 u.get->msg_type = RNDIS_MSG_QUERY;
725 u.get->msg_len = cpu_to_le32(sizeof *u.get);
726 u.get->oid = oid;
727
728 priv->current_command_oid = oid;
729 ret = rndis_command(dev, u.header, buflen);
730 priv->current_command_oid = 0;
731 if (ret < 0)
732 netdev_dbg(dev->net, "%s(%s): rndis_command() failed, %d (%08x)\n",
733 __func__, oid_to_string(oid), ret,
734 le32_to_cpu(u.get_c->status));
735
736 if (ret == 0) {
737 resplen = le32_to_cpu(u.get_c->len);
738 respoffs = le32_to_cpu(u.get_c->offset) + 8;
739
740 if (respoffs > buflen) {
741 /* Device returned data offset outside buffer, error. */
742 netdev_dbg(dev->net, "%s(%s): received invalid "
743 "data offset: %d > %d\n", __func__,
744 oid_to_string(oid), respoffs, buflen);
745
746 ret = -EINVAL;
747 goto exit_unlock;
748 }
749
750 if ((resplen + respoffs) > buflen) {
751 /* Device would have returned more data if buffer would
752 * have been big enough. Copy just the bits that we got.
753 */
754 copylen = buflen - respoffs;
755 } else {
756 copylen = resplen;
757 }
758
759 if (copylen > *len)
760 copylen = *len;
761
762 memcpy(data, u.buf + respoffs, copylen);
763
764 *len = resplen;
765
766 ret = rndis_error_status(u.get_c->status);
767 if (ret < 0)
768 netdev_dbg(dev->net, "%s(%s): device returned error, 0x%08x (%d)\n",
769 __func__, oid_to_string(oid),
770 le32_to_cpu(u.get_c->status), ret);
771 }
772
773 exit_unlock:
774 mutex_unlock(&priv->command_lock);
775
776 if (u.buf != priv->command_buffer)
777 kfree(u.buf);
778 return ret;
779 }
780
781 static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len)
782 {
783 struct rndis_wlan_private *priv = get_rndis_wlan_priv(dev);
784 union {
785 void *buf;
786 struct rndis_msg_hdr *header;
787 struct rndis_set *set;
788 struct rndis_set_c *set_c;
789 } u;
790 int ret, buflen;
791
792 buflen = len + sizeof(*u.set);
793 if (buflen < CONTROL_BUFFER_SIZE)
794 buflen = CONTROL_BUFFER_SIZE;
795
796 if (buflen > COMMAND_BUFFER_SIZE) {
797 u.buf = kmalloc(buflen, GFP_KERNEL);
798 if (!u.buf)
799 return -ENOMEM;
800 } else {
801 u.buf = priv->command_buffer;
802 }
803
804 mutex_lock(&priv->command_lock);
805
806 memset(u.set, 0, sizeof *u.set);
807 u.set->msg_type = RNDIS_MSG_SET;
808 u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len);
809 u.set->oid = oid;
810 u.set->len = cpu_to_le32(len);
811 u.set->offset = cpu_to_le32(sizeof(*u.set) - 8);
812 u.set->handle = cpu_to_le32(0);
813 memcpy(u.buf + sizeof(*u.set), data, len);
814
815 priv->current_command_oid = oid;
816 ret = rndis_command(dev, u.header, buflen);
817 priv->current_command_oid = 0;
818 if (ret < 0)
819 netdev_dbg(dev->net, "%s(%s): rndis_command() failed, %d (%08x)\n",
820 __func__, oid_to_string(oid), ret,
821 le32_to_cpu(u.set_c->status));
822
823 if (ret == 0) {
824 ret = rndis_error_status(u.set_c->status);
825
826 if (ret < 0)
827 netdev_dbg(dev->net, "%s(%s): device returned error, 0x%08x (%d)\n",
828 __func__, oid_to_string(oid),
829 le32_to_cpu(u.set_c->status), ret);
830 }
831
832 mutex_unlock(&priv->command_lock);
833
834 if (u.buf != priv->command_buffer)
835 kfree(u.buf);
836 return ret;
837 }
838
839 static int rndis_reset(struct usbnet *usbdev)
840 {
841 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
842 struct rndis_reset *reset;
843 int ret;
844
845 mutex_lock(&priv->command_lock);
846
847 reset = (void *)priv->command_buffer;
848 memset(reset, 0, sizeof(*reset));
849 reset->msg_type = RNDIS_MSG_RESET;
850 reset->msg_len = cpu_to_le32(sizeof(*reset));
851 priv->current_command_oid = 0;
852 ret = rndis_command(usbdev, (void *)reset, CONTROL_BUFFER_SIZE);
853
854 mutex_unlock(&priv->command_lock);
855
856 if (ret < 0)
857 return ret;
858 return 0;
859 }
860
861 /*
862 * Specs say that we can only set config parameters only soon after device
863 * initialization.
864 * value_type: 0 = u32, 2 = unicode string
865 */
866 static int rndis_set_config_parameter(struct usbnet *dev, char *param,
867 int value_type, void *value)
868 {
869 struct ndis_config_param *infobuf;
870 int value_len, info_len, param_len, ret, i;
871 __le16 *unibuf;
872 __le32 *dst_value;
873
874 if (value_type == 0)
875 value_len = sizeof(__le32);
876 else if (value_type == 2)
877 value_len = strlen(value) * sizeof(__le16);
878 else
879 return -EINVAL;
880
881 param_len = strlen(param) * sizeof(__le16);
882 info_len = sizeof(*infobuf) + param_len + value_len;
883
884 #ifdef DEBUG
885 info_len += 12;
886 #endif
887 infobuf = kmalloc(info_len, GFP_KERNEL);
888 if (!infobuf)
889 return -ENOMEM;
890
891 #ifdef DEBUG
892 info_len -= 12;
893 /* extra 12 bytes are for padding (debug output) */
894 memset(infobuf, 0xCC, info_len + 12);
895 #endif
896
897 if (value_type == 2)
898 netdev_dbg(dev->net, "setting config parameter: %s, value: %s\n",
899 param, (u8 *)value);
900 else
901 netdev_dbg(dev->net, "setting config parameter: %s, value: %d\n",
902 param, *(u32 *)value);
903
904 infobuf->name_offs = cpu_to_le32(sizeof(*infobuf));
905 infobuf->name_length = cpu_to_le32(param_len);
906 infobuf->type = cpu_to_le32(value_type);
907 infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len);
908 infobuf->value_length = cpu_to_le32(value_len);
909
910 /* simple string to unicode string conversion */
911 unibuf = (void *)infobuf + sizeof(*infobuf);
912 for (i = 0; i < param_len / sizeof(__le16); i++)
913 unibuf[i] = cpu_to_le16(param[i]);
914
915 if (value_type == 2) {
916 unibuf = (void *)infobuf + sizeof(*infobuf) + param_len;
917 for (i = 0; i < value_len / sizeof(__le16); i++)
918 unibuf[i] = cpu_to_le16(((u8 *)value)[i]);
919 } else {
920 dst_value = (void *)infobuf + sizeof(*infobuf) + param_len;
921 *dst_value = cpu_to_le32(*(u32 *)value);
922 }
923
924 #ifdef DEBUG
925 netdev_dbg(dev->net, "info buffer (len: %d)\n", info_len);
926 for (i = 0; i < info_len; i += 12) {
927 u32 *tmp = (u32 *)((u8 *)infobuf + i);
928 netdev_dbg(dev->net, "%08X:%08X:%08X\n",
929 cpu_to_be32(tmp[0]),
930 cpu_to_be32(tmp[1]),
931 cpu_to_be32(tmp[2]));
932 }
933 #endif
934
935 ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER,
936 infobuf, info_len);
937 if (ret != 0)
938 netdev_dbg(dev->net, "setting rndis config parameter failed, %d\n",
939 ret);
940
941 kfree(infobuf);
942 return ret;
943 }
944
945 static int rndis_set_config_parameter_str(struct usbnet *dev,
946 char *param, char *value)
947 {
948 return rndis_set_config_parameter(dev, param, 2, value);
949 }
950
951 /*
952 * data conversion functions
953 */
954 static int level_to_qual(int level)
955 {
956 int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE);
957 return qual >= 0 ? (qual <= 100 ? qual : 100) : 0;
958 }
959
960 /*
961 * common functions
962 */
963 static int set_infra_mode(struct usbnet *usbdev, int mode);
964 static void restore_keys(struct usbnet *usbdev);
965 static int rndis_check_bssid_list(struct usbnet *usbdev);
966
967 static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid)
968 {
969 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
970 int ret;
971
972 ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid));
973 if (ret < 0) {
974 netdev_warn(usbdev->net, "setting SSID failed (%08X)\n", ret);
975 return ret;
976 }
977 if (ret == 0) {
978 memcpy(&priv->essid, ssid, sizeof(priv->essid));
979 priv->radio_on = true;
980 netdev_dbg(usbdev->net, "%s(): radio_on = true\n", __func__);
981 }
982
983 return ret;
984 }
985
986 static int set_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
987 {
988 int ret;
989
990 ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN);
991 if (ret < 0) {
992 netdev_warn(usbdev->net, "setting BSSID[%pM] failed (%08X)\n",
993 bssid, ret);
994 return ret;
995 }
996
997 return ret;
998 }
999
1000 static int clear_bssid(struct usbnet *usbdev)
1001 {
1002 u8 broadcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1003
1004 return set_bssid(usbdev, broadcast_mac);
1005 }
1006
1007 static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN])
1008 {
1009 int ret, len;
1010
1011 len = ETH_ALEN;
1012 ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len);
1013
1014 if (ret != 0)
1015 memset(bssid, 0, ETH_ALEN);
1016
1017 return ret;
1018 }
1019
1020 static int get_association_info(struct usbnet *usbdev,
1021 struct ndis_80211_assoc_info *info, int len)
1022 {
1023 return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION,
1024 info, &len);
1025 }
1026
1027 static bool is_associated(struct usbnet *usbdev)
1028 {
1029 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1030 u8 bssid[ETH_ALEN];
1031 int ret;
1032
1033 if (!priv->radio_on)
1034 return false;
1035
1036 ret = get_bssid(usbdev, bssid);
1037
1038 return (ret == 0 && !is_zero_ether_addr(bssid));
1039 }
1040
1041 static int disassociate(struct usbnet *usbdev, bool reset_ssid)
1042 {
1043 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1044 struct ndis_80211_ssid ssid;
1045 int i, ret = 0;
1046
1047 if (priv->radio_on) {
1048 ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0);
1049 if (ret == 0) {
1050 priv->radio_on = false;
1051 netdev_dbg(usbdev->net, "%s(): radio_on = false\n",
1052 __func__);
1053
1054 if (reset_ssid)
1055 msleep(100);
1056 }
1057 }
1058
1059 /* disassociate causes radio to be turned off; if reset_ssid
1060 * is given, set random ssid to enable radio */
1061 if (reset_ssid) {
1062 /* Set device to infrastructure mode so we don't get ad-hoc
1063 * 'media connect' indications with the random ssid.
1064 */
1065 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1066
1067 ssid.length = cpu_to_le32(sizeof(ssid.essid));
1068 get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2);
1069 ssid.essid[0] = 0x1;
1070 ssid.essid[1] = 0xff;
1071 for (i = 2; i < sizeof(ssid.essid); i++)
1072 ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff);
1073 ret = set_essid(usbdev, &ssid);
1074 }
1075 return ret;
1076 }
1077
1078 static int set_auth_mode(struct usbnet *usbdev, u32 wpa_version,
1079 enum nl80211_auth_type auth_type, int keymgmt)
1080 {
1081 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1082 __le32 tmp;
1083 int auth_mode, ret;
1084
1085 netdev_dbg(usbdev->net, "%s(): wpa_version=0x%x authalg=0x%x keymgmt=0x%x\n",
1086 __func__, wpa_version, auth_type, keymgmt);
1087
1088 if (wpa_version & NL80211_WPA_VERSION_2) {
1089 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
1090 auth_mode = NDIS_80211_AUTH_WPA2;
1091 else
1092 auth_mode = NDIS_80211_AUTH_WPA2_PSK;
1093 } else if (wpa_version & NL80211_WPA_VERSION_1) {
1094 if (keymgmt & RNDIS_WLAN_KEY_MGMT_802_1X)
1095 auth_mode = NDIS_80211_AUTH_WPA;
1096 else if (keymgmt & RNDIS_WLAN_KEY_MGMT_PSK)
1097 auth_mode = NDIS_80211_AUTH_WPA_PSK;
1098 else
1099 auth_mode = NDIS_80211_AUTH_WPA_NONE;
1100 } else if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
1101 auth_mode = NDIS_80211_AUTH_SHARED;
1102 else if (auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM)
1103 auth_mode = NDIS_80211_AUTH_OPEN;
1104 else if (auth_type == NL80211_AUTHTYPE_AUTOMATIC)
1105 auth_mode = NDIS_80211_AUTH_AUTO_SWITCH;
1106 else
1107 return -ENOTSUPP;
1108
1109 tmp = cpu_to_le32(auth_mode);
1110 ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp,
1111 sizeof(tmp));
1112 if (ret != 0) {
1113 netdev_warn(usbdev->net, "setting auth mode failed (%08X)\n",
1114 ret);
1115 return ret;
1116 }
1117
1118 priv->wpa_version = wpa_version;
1119 priv->wpa_auth_type = auth_type;
1120 priv->wpa_keymgmt = keymgmt;
1121
1122 return 0;
1123 }
1124
1125 static int set_priv_filter(struct usbnet *usbdev)
1126 {
1127 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1128 __le32 tmp;
1129
1130 netdev_dbg(usbdev->net, "%s(): wpa_version=0x%x\n",
1131 __func__, priv->wpa_version);
1132
1133 if (priv->wpa_version & NL80211_WPA_VERSION_2 ||
1134 priv->wpa_version & NL80211_WPA_VERSION_1)
1135 tmp = cpu_to_le32(NDIS_80211_PRIV_8021X_WEP);
1136 else
1137 tmp = cpu_to_le32(NDIS_80211_PRIV_ACCEPT_ALL);
1138
1139 return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp,
1140 sizeof(tmp));
1141 }
1142
1143 static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise)
1144 {
1145 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1146 __le32 tmp;
1147 int encr_mode, ret;
1148
1149 netdev_dbg(usbdev->net, "%s(): cipher_pair=0x%x cipher_group=0x%x\n",
1150 __func__, pairwise, groupwise);
1151
1152 if (pairwise & RNDIS_WLAN_ALG_CCMP)
1153 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1154 else if (pairwise & RNDIS_WLAN_ALG_TKIP)
1155 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1156 else if (pairwise & RNDIS_WLAN_ALG_WEP)
1157 encr_mode = NDIS_80211_ENCR_WEP_ENABLED;
1158 else if (groupwise & RNDIS_WLAN_ALG_CCMP)
1159 encr_mode = NDIS_80211_ENCR_CCMP_ENABLED;
1160 else if (groupwise & RNDIS_WLAN_ALG_TKIP)
1161 encr_mode = NDIS_80211_ENCR_TKIP_ENABLED;
1162 else
1163 encr_mode = NDIS_80211_ENCR_DISABLED;
1164
1165 tmp = cpu_to_le32(encr_mode);
1166 ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp,
1167 sizeof(tmp));
1168 if (ret != 0) {
1169 netdev_warn(usbdev->net, "setting encr mode failed (%08X)\n",
1170 ret);
1171 return ret;
1172 }
1173
1174 priv->wpa_cipher_pair = pairwise;
1175 priv->wpa_cipher_group = groupwise;
1176 return 0;
1177 }
1178
1179 static int set_infra_mode(struct usbnet *usbdev, int mode)
1180 {
1181 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1182 __le32 tmp;
1183 int ret;
1184
1185 netdev_dbg(usbdev->net, "%s(): infra_mode=0x%x\n",
1186 __func__, priv->infra_mode);
1187
1188 tmp = cpu_to_le32(mode);
1189 ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp,
1190 sizeof(tmp));
1191 if (ret != 0) {
1192 netdev_warn(usbdev->net, "setting infra mode failed (%08X)\n",
1193 ret);
1194 return ret;
1195 }
1196
1197 /* NDIS drivers clear keys when infrastructure mode is
1198 * changed. But Linux tools assume otherwise. So set the
1199 * keys */
1200 restore_keys(usbdev);
1201
1202 priv->infra_mode = mode;
1203 return 0;
1204 }
1205
1206 static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
1207 {
1208 __le32 tmp;
1209
1210 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
1211
1212 if (rts_threshold < 0 || rts_threshold > 2347)
1213 rts_threshold = 2347;
1214
1215 tmp = cpu_to_le32(rts_threshold);
1216 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1217 sizeof(tmp));
1218 }
1219
1220 static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1221 {
1222 __le32 tmp;
1223
1224 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, frag_threshold);
1225
1226 if (frag_threshold < 256 || frag_threshold > 2346)
1227 frag_threshold = 2346;
1228
1229 tmp = cpu_to_le32(frag_threshold);
1230 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1231 sizeof(tmp));
1232 }
1233
1234 static void set_default_iw_params(struct usbnet *usbdev)
1235 {
1236 set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1237 set_auth_mode(usbdev, 0, NL80211_AUTHTYPE_OPEN_SYSTEM,
1238 RNDIS_WLAN_KEY_MGMT_NONE);
1239 set_priv_filter(usbdev);
1240 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
1241 }
1242
1243 static int deauthenticate(struct usbnet *usbdev)
1244 {
1245 int ret;
1246
1247 ret = disassociate(usbdev, true);
1248 set_default_iw_params(usbdev);
1249 return ret;
1250 }
1251
1252 static int set_channel(struct usbnet *usbdev, int channel)
1253 {
1254 struct ndis_80211_conf config;
1255 unsigned int dsconfig;
1256 int len, ret;
1257
1258 netdev_dbg(usbdev->net, "%s(%d)\n", __func__, channel);
1259
1260 /* this OID is valid only when not associated */
1261 if (is_associated(usbdev))
1262 return 0;
1263
1264 dsconfig = ieee80211_dsss_chan_to_freq(channel) * 1000;
1265
1266 len = sizeof(config);
1267 ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len);
1268 if (ret < 0) {
1269 netdev_dbg(usbdev->net, "%s(): querying configuration failed\n",
1270 __func__);
1271 return ret;
1272 }
1273
1274 config.ds_config = cpu_to_le32(dsconfig);
1275 ret = rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config,
1276 sizeof(config));
1277
1278 netdev_dbg(usbdev->net, "%s(): %d -> %d\n", __func__, channel, ret);
1279
1280 return ret;
1281 }
1282
1283 /* index must be 0 - N, as per NDIS */
1284 static int add_wep_key(struct usbnet *usbdev, const u8 *key, int key_len,
1285 int index)
1286 {
1287 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1288 struct ndis_80211_wep_key ndis_key;
1289 u32 cipher;
1290 int ret;
1291
1292 netdev_dbg(usbdev->net, "%s(idx: %d, len: %d)\n",
1293 __func__, index, key_len);
1294
1295 if ((key_len != 5 && key_len != 13) || index < 0 || index > 3)
1296 return -EINVAL;
1297
1298 if (key_len == 5)
1299 cipher = WLAN_CIPHER_SUITE_WEP40;
1300 else
1301 cipher = WLAN_CIPHER_SUITE_WEP104;
1302
1303 memset(&ndis_key, 0, sizeof(ndis_key));
1304
1305 ndis_key.size = cpu_to_le32(sizeof(ndis_key));
1306 ndis_key.length = cpu_to_le32(key_len);
1307 ndis_key.index = cpu_to_le32(index);
1308 memcpy(&ndis_key.material, key, key_len);
1309
1310 if (index == priv->encr_tx_key_index) {
1311 ndis_key.index |= NDIS_80211_ADDWEP_TRANSMIT_KEY;
1312 ret = set_encr_mode(usbdev, RNDIS_WLAN_ALG_WEP,
1313 RNDIS_WLAN_ALG_NONE);
1314 if (ret)
1315 netdev_warn(usbdev->net, "encryption couldn't be enabled (%08X)\n",
1316 ret);
1317 }
1318
1319 ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key,
1320 sizeof(ndis_key));
1321 if (ret != 0) {
1322 netdev_warn(usbdev->net, "adding encryption key %d failed (%08X)\n",
1323 index + 1, ret);
1324 return ret;
1325 }
1326
1327 priv->encr_keys[index].len = key_len;
1328 priv->encr_keys[index].cipher = cipher;
1329 memcpy(&priv->encr_keys[index].material, key, key_len);
1330 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
1331
1332 return 0;
1333 }
1334
1335 static int add_wpa_key(struct usbnet *usbdev, const u8 *key, int key_len,
1336 int index, const u8 *addr, const u8 *rx_seq,
1337 int seq_len, u32 cipher, __le32 flags)
1338 {
1339 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1340 struct ndis_80211_key ndis_key;
1341 bool is_addr_ok;
1342 int ret;
1343
1344 if (index < 0 || index >= 4) {
1345 netdev_dbg(usbdev->net, "%s(): index out of range (%i)\n",
1346 __func__, index);
1347 return -EINVAL;
1348 }
1349 if (key_len > sizeof(ndis_key.material) || key_len < 0) {
1350 netdev_dbg(usbdev->net, "%s(): key length out of range (%i)\n",
1351 __func__, key_len);
1352 return -EINVAL;
1353 }
1354 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ) {
1355 if (!rx_seq || seq_len <= 0) {
1356 netdev_dbg(usbdev->net, "%s(): recv seq flag without buffer\n",
1357 __func__);
1358 return -EINVAL;
1359 }
1360 if (rx_seq && seq_len > sizeof(ndis_key.rsc)) {
1361 netdev_dbg(usbdev->net, "%s(): too big recv seq buffer\n", __func__);
1362 return -EINVAL;
1363 }
1364 }
1365
1366 is_addr_ok = addr && !is_zero_ether_addr(addr) &&
1367 !is_broadcast_ether_addr(addr);
1368 if ((flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) && !is_addr_ok) {
1369 netdev_dbg(usbdev->net, "%s(): pairwise but bssid invalid (%pM)\n",
1370 __func__, addr);
1371 return -EINVAL;
1372 }
1373
1374 netdev_dbg(usbdev->net, "%s(%i): flags:%i%i%i\n",
1375 __func__, index,
1376 !!(flags & NDIS_80211_ADDKEY_TRANSMIT_KEY),
1377 !!(flags & NDIS_80211_ADDKEY_PAIRWISE_KEY),
1378 !!(flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ));
1379
1380 memset(&ndis_key, 0, sizeof(ndis_key));
1381
1382 ndis_key.size = cpu_to_le32(sizeof(ndis_key) -
1383 sizeof(ndis_key.material) + key_len);
1384 ndis_key.length = cpu_to_le32(key_len);
1385 ndis_key.index = cpu_to_le32(index) | flags;
1386
1387 if (cipher == WLAN_CIPHER_SUITE_TKIP && key_len == 32) {
1388 /* wpa_supplicant gives us the Michael MIC RX/TX keys in
1389 * different order than NDIS spec, so swap the order here. */
1390 memcpy(ndis_key.material, key, 16);
1391 memcpy(ndis_key.material + 16, key + 24, 8);
1392 memcpy(ndis_key.material + 24, key + 16, 8);
1393 } else
1394 memcpy(ndis_key.material, key, key_len);
1395
1396 if (flags & NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ)
1397 memcpy(ndis_key.rsc, rx_seq, seq_len);
1398
1399 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY) {
1400 /* pairwise key */
1401 memcpy(ndis_key.bssid, addr, ETH_ALEN);
1402 } else {
1403 /* group key */
1404 if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
1405 memset(ndis_key.bssid, 0xff, ETH_ALEN);
1406 else
1407 get_bssid(usbdev, ndis_key.bssid);
1408 }
1409
1410 ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key,
1411 le32_to_cpu(ndis_key.size));
1412 netdev_dbg(usbdev->net, "%s(): OID_802_11_ADD_KEY -> %08X\n",
1413 __func__, ret);
1414 if (ret != 0)
1415 return ret;
1416
1417 memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index]));
1418 priv->encr_keys[index].len = key_len;
1419 priv->encr_keys[index].cipher = cipher;
1420 memcpy(&priv->encr_keys[index].material, key, key_len);
1421 if (flags & NDIS_80211_ADDKEY_PAIRWISE_KEY)
1422 memcpy(&priv->encr_keys[index].bssid, ndis_key.bssid, ETH_ALEN);
1423 else
1424 memset(&priv->encr_keys[index].bssid, 0xff, ETH_ALEN);
1425
1426 if (flags & NDIS_80211_ADDKEY_TRANSMIT_KEY)
1427 priv->encr_tx_key_index = index;
1428
1429 return 0;
1430 }
1431
1432 static int restore_key(struct usbnet *usbdev, int key_idx)
1433 {
1434 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1435 struct rndis_wlan_encr_key key;
1436
1437 if (is_wpa_key(priv, key_idx))
1438 return 0;
1439
1440 key = priv->encr_keys[key_idx];
1441
1442 netdev_dbg(usbdev->net, "%s(): %i:%i\n", __func__, key_idx, key.len);
1443
1444 if (key.len == 0)
1445 return 0;
1446
1447 return add_wep_key(usbdev, key.material, key.len, key_idx);
1448 }
1449
1450 static void restore_keys(struct usbnet *usbdev)
1451 {
1452 int i;
1453
1454 for (i = 0; i < 4; i++)
1455 restore_key(usbdev, i);
1456 }
1457
1458 static void clear_key(struct rndis_wlan_private *priv, int idx)
1459 {
1460 memset(&priv->encr_keys[idx], 0, sizeof(priv->encr_keys[idx]));
1461 }
1462
1463 /* remove_key is for both wep and wpa */
1464 static int remove_key(struct usbnet *usbdev, int index, const u8 *bssid)
1465 {
1466 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1467 struct ndis_80211_remove_key remove_key;
1468 __le32 keyindex;
1469 bool is_wpa;
1470 int ret;
1471
1472 if (priv->encr_keys[index].len == 0)
1473 return 0;
1474
1475 is_wpa = is_wpa_key(priv, index);
1476
1477 netdev_dbg(usbdev->net, "%s(): %i:%s:%i\n",
1478 __func__, index, is_wpa ? "wpa" : "wep",
1479 priv->encr_keys[index].len);
1480
1481 clear_key(priv, index);
1482
1483 if (is_wpa) {
1484 remove_key.size = cpu_to_le32(sizeof(remove_key));
1485 remove_key.index = cpu_to_le32(index);
1486 if (bssid) {
1487 /* pairwise key */
1488 if (!is_broadcast_ether_addr(bssid))
1489 remove_key.index |=
1490 NDIS_80211_ADDKEY_PAIRWISE_KEY;
1491 memcpy(remove_key.bssid, bssid,
1492 sizeof(remove_key.bssid));
1493 } else
1494 memset(remove_key.bssid, 0xff,
1495 sizeof(remove_key.bssid));
1496
1497 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key,
1498 sizeof(remove_key));
1499 if (ret != 0)
1500 return ret;
1501 } else {
1502 keyindex = cpu_to_le32(index);
1503 ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex,
1504 sizeof(keyindex));
1505 if (ret != 0) {
1506 netdev_warn(usbdev->net,
1507 "removing encryption key %d failed (%08X)\n",
1508 index, ret);
1509 return ret;
1510 }
1511 }
1512
1513 /* if it is transmit key, disable encryption */
1514 if (index == priv->encr_tx_key_index)
1515 set_encr_mode(usbdev, RNDIS_WLAN_ALG_NONE, RNDIS_WLAN_ALG_NONE);
1516
1517 return 0;
1518 }
1519
1520 static void set_multicast_list(struct usbnet *usbdev)
1521 {
1522 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1523 struct dev_mc_list *mclist;
1524 __le32 filter;
1525 int ret, i, size;
1526 char *buf;
1527
1528 filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
1529
1530 netif_addr_lock_bh(usbdev->net);
1531 if (usbdev->net->flags & IFF_PROMISC) {
1532 filter |= RNDIS_PACKET_TYPE_PROMISCUOUS |
1533 RNDIS_PACKET_TYPE_ALL_LOCAL;
1534 } else if (usbdev->net->flags & IFF_ALLMULTI ||
1535 netdev_mc_count(usbdev->net) > priv->multicast_size) {
1536 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1537 } else if (!netdev_mc_empty(usbdev->net)) {
1538 size = min(priv->multicast_size, netdev_mc_count(usbdev->net));
1539 buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
1540 if (!buf) {
1541 netdev_warn(usbdev->net,
1542 "couldn't alloc %d bytes of memory\n",
1543 size * ETH_ALEN);
1544 netif_addr_unlock_bh(usbdev->net);
1545 return;
1546 }
1547
1548 i = 0;
1549 netdev_for_each_mc_addr(mclist, usbdev->net) {
1550 if (i == size)
1551 break;
1552 memcpy(buf + i++ * ETH_ALEN, mclist->dmi_addr, ETH_ALEN);
1553 }
1554
1555 ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf,
1556 i * ETH_ALEN);
1557 if (ret == 0 && i > 0)
1558 filter |= RNDIS_PACKET_TYPE_MULTICAST;
1559 else
1560 filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
1561
1562 netdev_dbg(usbdev->net, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d\n",
1563 i, priv->multicast_size, ret);
1564
1565 kfree(buf);
1566 }
1567 netif_addr_unlock_bh(usbdev->net);
1568
1569 ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
1570 sizeof(filter));
1571 if (ret < 0) {
1572 netdev_warn(usbdev->net, "couldn't set packet filter: %08x\n",
1573 le32_to_cpu(filter));
1574 }
1575
1576 netdev_dbg(usbdev->net, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d\n",
1577 le32_to_cpu(filter), ret);
1578 }
1579
1580 /*
1581 * cfg80211 ops
1582 */
1583 static int rndis_change_virtual_intf(struct wiphy *wiphy,
1584 struct net_device *dev,
1585 enum nl80211_iftype type, u32 *flags,
1586 struct vif_params *params)
1587 {
1588 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1589 struct usbnet *usbdev = priv->usbdev;
1590 int mode;
1591
1592 switch (type) {
1593 case NL80211_IFTYPE_ADHOC:
1594 mode = NDIS_80211_INFRA_ADHOC;
1595 break;
1596 case NL80211_IFTYPE_STATION:
1597 mode = NDIS_80211_INFRA_INFRA;
1598 break;
1599 default:
1600 return -EINVAL;
1601 }
1602
1603 priv->wdev.iftype = type;
1604
1605 return set_infra_mode(usbdev, mode);
1606 }
1607
1608 static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1609 {
1610 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1611 struct usbnet *usbdev = priv->usbdev;
1612 int err;
1613
1614 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1615 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1616 if (err < 0)
1617 return err;
1618 }
1619
1620 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1621 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1622 if (err < 0)
1623 return err;
1624 }
1625
1626 return 0;
1627 }
1628
1629 static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1630 int dbm)
1631 {
1632 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1633 struct usbnet *usbdev = priv->usbdev;
1634
1635 netdev_dbg(usbdev->net, "%s(): type:0x%x dbm:%i\n",
1636 __func__, type, dbm);
1637
1638 /* Device doesn't support changing txpower after initialization, only
1639 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1640 * currently used.
1641 */
1642 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1643 if (!priv->radio_on)
1644 disassociate(usbdev, true); /* turn on radio */
1645
1646 return 0;
1647 }
1648
1649 return -ENOTSUPP;
1650 }
1651
1652 static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1653 {
1654 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1655 struct usbnet *usbdev = priv->usbdev;
1656
1657 *dbm = get_bcm4320_power_dbm(priv);
1658
1659 netdev_dbg(usbdev->net, "%s(): dbm:%i\n", __func__, *dbm);
1660
1661 return 0;
1662 }
1663
1664 #define SCAN_DELAY_JIFFIES (6 * HZ)
1665 static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1666 struct cfg80211_scan_request *request)
1667 {
1668 struct usbnet *usbdev = netdev_priv(dev);
1669 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1670 int ret;
1671 __le32 tmp;
1672
1673 netdev_dbg(usbdev->net, "cfg80211.scan\n");
1674
1675 /* Get current bssid list from device before new scan, as new scan
1676 * clears internal bssid list.
1677 */
1678 rndis_check_bssid_list(usbdev);
1679
1680 if (!request)
1681 return -EINVAL;
1682
1683 if (priv->scan_request && priv->scan_request != request)
1684 return -EBUSY;
1685
1686 priv->scan_request = request;
1687
1688 tmp = cpu_to_le32(1);
1689 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1690 sizeof(tmp));
1691 if (ret == 0) {
1692 /* Wait before retrieving scan results from device */
1693 queue_delayed_work(priv->workqueue, &priv->scan_work,
1694 SCAN_DELAY_JIFFIES);
1695 }
1696
1697 return ret;
1698 }
1699
1700 static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1701 struct ndis_80211_bssid_ex *bssid)
1702 {
1703 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1704 struct ieee80211_channel *channel;
1705 s32 signal;
1706 u64 timestamp;
1707 u16 capability;
1708 u16 beacon_interval;
1709 struct ndis_80211_fixed_ies *fixed;
1710 int ie_len, bssid_len;
1711 u8 *ie;
1712
1713 netdev_dbg(usbdev->net, " found bssid: '%.32s' [%pM]\n",
1714 bssid->ssid.essid, bssid->mac);
1715
1716 /* parse bssid structure */
1717 bssid_len = le32_to_cpu(bssid->length);
1718
1719 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1720 sizeof(struct ndis_80211_fixed_ies))
1721 return NULL;
1722
1723 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1724
1725 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1726 ie_len = min(bssid_len - (int)sizeof(*bssid),
1727 (int)le32_to_cpu(bssid->ie_length));
1728 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1729 if (ie_len < 0)
1730 return NULL;
1731
1732 /* extract data for cfg80211_inform_bss */
1733 channel = ieee80211_get_channel(priv->wdev.wiphy,
1734 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1735 if (!channel)
1736 return NULL;
1737
1738 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1739 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1740 capability = le16_to_cpu(fixed->capabilities);
1741 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1742
1743 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1744 timestamp, capability, beacon_interval, ie, ie_len, signal,
1745 GFP_KERNEL);
1746 }
1747
1748 static int rndis_check_bssid_list(struct usbnet *usbdev)
1749 {
1750 void *buf = NULL;
1751 struct ndis_80211_bssid_list_ex *bssid_list;
1752 struct ndis_80211_bssid_ex *bssid;
1753 int ret = -EINVAL, len, count, bssid_len;
1754 bool resized = false;
1755
1756 netdev_dbg(usbdev->net, "check_bssid_list\n");
1757
1758 len = CONTROL_BUFFER_SIZE;
1759 resize_buf:
1760 buf = kmalloc(len, GFP_KERNEL);
1761 if (!buf) {
1762 ret = -ENOMEM;
1763 goto out;
1764 }
1765
1766 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1767 if (ret != 0)
1768 goto out;
1769
1770 if (!resized && len > CONTROL_BUFFER_SIZE) {
1771 resized = true;
1772 kfree(buf);
1773 goto resize_buf;
1774 }
1775
1776 bssid_list = buf;
1777 bssid = bssid_list->bssid;
1778 bssid_len = le32_to_cpu(bssid->length);
1779 count = le32_to_cpu(bssid_list->num_items);
1780 netdev_dbg(usbdev->net, "check_bssid_list: %d BSSIDs found (buflen: %d)\n",
1781 count, len);
1782
1783 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1784 rndis_bss_info_update(usbdev, bssid);
1785
1786 bssid = (void *)bssid + bssid_len;
1787 bssid_len = le32_to_cpu(bssid->length);
1788 count--;
1789 }
1790
1791 out:
1792 kfree(buf);
1793 return ret;
1794 }
1795
1796 static void rndis_get_scan_results(struct work_struct *work)
1797 {
1798 struct rndis_wlan_private *priv =
1799 container_of(work, struct rndis_wlan_private, scan_work.work);
1800 struct usbnet *usbdev = priv->usbdev;
1801 int ret;
1802
1803 netdev_dbg(usbdev->net, "get_scan_results\n");
1804
1805 if (!priv->scan_request)
1806 return;
1807
1808 ret = rndis_check_bssid_list(usbdev);
1809
1810 cfg80211_scan_done(priv->scan_request, ret < 0);
1811
1812 priv->scan_request = NULL;
1813 }
1814
1815 static int rndis_connect(struct wiphy *wiphy, struct net_device *dev,
1816 struct cfg80211_connect_params *sme)
1817 {
1818 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1819 struct usbnet *usbdev = priv->usbdev;
1820 struct ieee80211_channel *channel = sme->channel;
1821 struct ndis_80211_ssid ssid;
1822 int pairwise = RNDIS_WLAN_ALG_NONE;
1823 int groupwise = RNDIS_WLAN_ALG_NONE;
1824 int keymgmt = RNDIS_WLAN_KEY_MGMT_NONE;
1825 int length, i, ret, chan = -1;
1826
1827 if (channel)
1828 chan = ieee80211_frequency_to_channel(channel->center_freq);
1829
1830 groupwise = rndis_cipher_to_alg(sme->crypto.cipher_group);
1831 for (i = 0; i < sme->crypto.n_ciphers_pairwise; i++)
1832 pairwise |=
1833 rndis_cipher_to_alg(sme->crypto.ciphers_pairwise[i]);
1834
1835 if (sme->crypto.n_ciphers_pairwise > 0 &&
1836 pairwise == RNDIS_WLAN_ALG_NONE) {
1837 netdev_err(usbdev->net, "Unsupported pairwise cipher\n");
1838 return -ENOTSUPP;
1839 }
1840
1841 for (i = 0; i < sme->crypto.n_akm_suites; i++)
1842 keymgmt |=
1843 rndis_akm_suite_to_key_mgmt(sme->crypto.akm_suites[i]);
1844
1845 if (sme->crypto.n_akm_suites > 0 &&
1846 keymgmt == RNDIS_WLAN_KEY_MGMT_NONE) {
1847 netdev_err(usbdev->net, "Invalid keymgmt\n");
1848 return -ENOTSUPP;
1849 }
1850
1851 netdev_dbg(usbdev->net, "cfg80211.connect('%.32s':[%pM]:%d:[%d,0x%x:0x%x]:[0x%x:0x%x]:0x%x)\n",
1852 sme->ssid, sme->bssid, chan,
1853 sme->privacy, sme->crypto.wpa_versions, sme->auth_type,
1854 groupwise, pairwise, keymgmt);
1855
1856 if (is_associated(usbdev))
1857 disassociate(usbdev, false);
1858
1859 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_INFRA);
1860 if (ret < 0) {
1861 netdev_dbg(usbdev->net, "connect: set_infra_mode failed, %d\n",
1862 ret);
1863 goto err_turn_radio_on;
1864 }
1865
1866 ret = set_auth_mode(usbdev, sme->crypto.wpa_versions, sme->auth_type,
1867 keymgmt);
1868 if (ret < 0) {
1869 netdev_dbg(usbdev->net, "connect: set_auth_mode failed, %d\n",
1870 ret);
1871 goto err_turn_radio_on;
1872 }
1873
1874 set_priv_filter(usbdev);
1875
1876 ret = set_encr_mode(usbdev, pairwise, groupwise);
1877 if (ret < 0) {
1878 netdev_dbg(usbdev->net, "connect: set_encr_mode failed, %d\n",
1879 ret);
1880 goto err_turn_radio_on;
1881 }
1882
1883 if (channel) {
1884 ret = set_channel(usbdev, chan);
1885 if (ret < 0) {
1886 netdev_dbg(usbdev->net, "connect: set_channel failed, %d\n",
1887 ret);
1888 goto err_turn_radio_on;
1889 }
1890 }
1891
1892 if (sme->key && ((groupwise | pairwise) & RNDIS_WLAN_ALG_WEP)) {
1893 priv->encr_tx_key_index = sme->key_idx;
1894 ret = add_wep_key(usbdev, sme->key, sme->key_len, sme->key_idx);
1895 if (ret < 0) {
1896 netdev_dbg(usbdev->net, "connect: add_wep_key failed, %d (%d, %d)\n",
1897 ret, sme->key_len, sme->key_idx);
1898 goto err_turn_radio_on;
1899 }
1900 }
1901
1902 if (sme->bssid && !is_zero_ether_addr(sme->bssid) &&
1903 !is_broadcast_ether_addr(sme->bssid)) {
1904 ret = set_bssid(usbdev, sme->bssid);
1905 if (ret < 0) {
1906 netdev_dbg(usbdev->net, "connect: set_bssid failed, %d\n",
1907 ret);
1908 goto err_turn_radio_on;
1909 }
1910 } else
1911 clear_bssid(usbdev);
1912
1913 length = sme->ssid_len;
1914 if (length > NDIS_802_11_LENGTH_SSID)
1915 length = NDIS_802_11_LENGTH_SSID;
1916
1917 memset(&ssid, 0, sizeof(ssid));
1918 ssid.length = cpu_to_le32(length);
1919 memcpy(ssid.essid, sme->ssid, length);
1920
1921 /* Pause and purge rx queue, so we don't pass packets before
1922 * 'media connect'-indication.
1923 */
1924 usbnet_pause_rx(usbdev);
1925 usbnet_purge_paused_rxq(usbdev);
1926
1927 ret = set_essid(usbdev, &ssid);
1928 if (ret < 0)
1929 netdev_dbg(usbdev->net, "connect: set_essid failed, %d\n", ret);
1930 return ret;
1931
1932 err_turn_radio_on:
1933 disassociate(usbdev, true);
1934
1935 return ret;
1936 }
1937
1938 static int rndis_disconnect(struct wiphy *wiphy, struct net_device *dev,
1939 u16 reason_code)
1940 {
1941 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1942 struct usbnet *usbdev = priv->usbdev;
1943
1944 netdev_dbg(usbdev->net, "cfg80211.disconnect(%d)\n", reason_code);
1945
1946 priv->connected = false;
1947 memset(priv->bssid, 0, ETH_ALEN);
1948
1949 return deauthenticate(usbdev);
1950 }
1951
1952 static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1953 struct cfg80211_ibss_params *params)
1954 {
1955 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1956 struct usbnet *usbdev = priv->usbdev;
1957 struct ieee80211_channel *channel = params->channel;
1958 struct ndis_80211_ssid ssid;
1959 enum nl80211_auth_type auth_type;
1960 int ret, alg, length, chan = -1;
1961
1962 if (channel)
1963 chan = ieee80211_frequency_to_channel(channel->center_freq);
1964
1965 /* TODO: How to handle ad-hoc encryption?
1966 * connect() has *key, join_ibss() doesn't. RNDIS requires key to be
1967 * pre-shared for encryption (open/shared/wpa), is key set before
1968 * join_ibss? Which auth_type to use (not in params)? What about WPA?
1969 */
1970 if (params->privacy) {
1971 auth_type = NL80211_AUTHTYPE_SHARED_KEY;
1972 alg = RNDIS_WLAN_ALG_WEP;
1973 } else {
1974 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
1975 alg = RNDIS_WLAN_ALG_NONE;
1976 }
1977
1978 netdev_dbg(usbdev->net, "cfg80211.join_ibss('%.32s':[%pM]:%d:%d)\n",
1979 params->ssid, params->bssid, chan, params->privacy);
1980
1981 if (is_associated(usbdev))
1982 disassociate(usbdev, false);
1983
1984 ret = set_infra_mode(usbdev, NDIS_80211_INFRA_ADHOC);
1985 if (ret < 0) {
1986 netdev_dbg(usbdev->net, "join_ibss: set_infra_mode failed, %d\n",
1987 ret);
1988 goto err_turn_radio_on;
1989 }
1990
1991 ret = set_auth_mode(usbdev, 0, auth_type, RNDIS_WLAN_KEY_MGMT_NONE);
1992 if (ret < 0) {
1993 netdev_dbg(usbdev->net, "join_ibss: set_auth_mode failed, %d\n",
1994 ret);
1995 goto err_turn_radio_on;
1996 }
1997
1998 set_priv_filter(usbdev);
1999
2000 ret = set_encr_mode(usbdev, alg, RNDIS_WLAN_ALG_NONE);
2001 if (ret < 0) {
2002 netdev_dbg(usbdev->net, "join_ibss: set_encr_mode failed, %d\n",
2003 ret);
2004 goto err_turn_radio_on;
2005 }
2006
2007 if (channel) {
2008 ret = set_channel(usbdev, chan);
2009 if (ret < 0) {
2010 netdev_dbg(usbdev->net, "join_ibss: set_channel failed, %d\n",
2011 ret);
2012 goto err_turn_radio_on;
2013 }
2014 }
2015
2016 if (params->bssid && !is_zero_ether_addr(params->bssid) &&
2017 !is_broadcast_ether_addr(params->bssid)) {
2018 ret = set_bssid(usbdev, params->bssid);
2019 if (ret < 0) {
2020 netdev_dbg(usbdev->net, "join_ibss: set_bssid failed, %d\n",
2021 ret);
2022 goto err_turn_radio_on;
2023 }
2024 } else
2025 clear_bssid(usbdev);
2026
2027 length = params->ssid_len;
2028 if (length > NDIS_802_11_LENGTH_SSID)
2029 length = NDIS_802_11_LENGTH_SSID;
2030
2031 memset(&ssid, 0, sizeof(ssid));
2032 ssid.length = cpu_to_le32(length);
2033 memcpy(ssid.essid, params->ssid, length);
2034
2035 /* Don't need to pause rx queue for ad-hoc. */
2036 usbnet_purge_paused_rxq(usbdev);
2037 usbnet_resume_rx(usbdev);
2038
2039 ret = set_essid(usbdev, &ssid);
2040 if (ret < 0)
2041 netdev_dbg(usbdev->net, "join_ibss: set_essid failed, %d\n",
2042 ret);
2043 return ret;
2044
2045 err_turn_radio_on:
2046 disassociate(usbdev, true);
2047
2048 return ret;
2049 }
2050
2051 static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2052 {
2053 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2054 struct usbnet *usbdev = priv->usbdev;
2055
2056 netdev_dbg(usbdev->net, "cfg80211.leave_ibss()\n");
2057
2058 priv->connected = false;
2059 memset(priv->bssid, 0, ETH_ALEN);
2060
2061 return deauthenticate(usbdev);
2062 }
2063
2064 static int rndis_set_channel(struct wiphy *wiphy,
2065 struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
2066 {
2067 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2068 struct usbnet *usbdev = priv->usbdev;
2069
2070 return set_channel(usbdev,
2071 ieee80211_frequency_to_channel(chan->center_freq));
2072 }
2073
2074 static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
2075 u8 key_index, const u8 *mac_addr,
2076 struct key_params *params)
2077 {
2078 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2079 struct usbnet *usbdev = priv->usbdev;
2080 __le32 flags;
2081
2082 netdev_dbg(usbdev->net, "%s(%i, %pM, %08x)\n",
2083 __func__, key_index, mac_addr, params->cipher);
2084
2085 switch (params->cipher) {
2086 case WLAN_CIPHER_SUITE_WEP40:
2087 case WLAN_CIPHER_SUITE_WEP104:
2088 return add_wep_key(usbdev, params->key, params->key_len,
2089 key_index);
2090 case WLAN_CIPHER_SUITE_TKIP:
2091 case WLAN_CIPHER_SUITE_CCMP:
2092 flags = 0;
2093
2094 if (params->seq && params->seq_len > 0)
2095 flags |= NDIS_80211_ADDKEY_SET_INIT_RECV_SEQ;
2096 if (mac_addr)
2097 flags |= NDIS_80211_ADDKEY_PAIRWISE_KEY |
2098 NDIS_80211_ADDKEY_TRANSMIT_KEY;
2099
2100 return add_wpa_key(usbdev, params->key, params->key_len,
2101 key_index, mac_addr, params->seq,
2102 params->seq_len, params->cipher, flags);
2103 default:
2104 netdev_dbg(usbdev->net, "%s(): unsupported cipher %08x\n",
2105 __func__, params->cipher);
2106 return -ENOTSUPP;
2107 }
2108 }
2109
2110 static int rndis_del_key(struct wiphy *wiphy, struct net_device *netdev,
2111 u8 key_index, const u8 *mac_addr)
2112 {
2113 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2114 struct usbnet *usbdev = priv->usbdev;
2115
2116 netdev_dbg(usbdev->net, "%s(%i, %pM)\n", __func__, key_index, mac_addr);
2117
2118 return remove_key(usbdev, key_index, mac_addr);
2119 }
2120
2121 static int rndis_set_default_key(struct wiphy *wiphy, struct net_device *netdev,
2122 u8 key_index)
2123 {
2124 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2125 struct usbnet *usbdev = priv->usbdev;
2126 struct rndis_wlan_encr_key key;
2127
2128 netdev_dbg(usbdev->net, "%s(%i)\n", __func__, key_index);
2129
2130 priv->encr_tx_key_index = key_index;
2131
2132 key = priv->encr_keys[key_index];
2133
2134 return add_wep_key(usbdev, key.material, key.len, key_index);
2135 }
2136
2137 static void rndis_fill_station_info(struct usbnet *usbdev,
2138 struct station_info *sinfo)
2139 {
2140 __le32 linkspeed, rssi;
2141 int ret, len;
2142
2143 memset(sinfo, 0, sizeof(*sinfo));
2144
2145 len = sizeof(linkspeed);
2146 ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &linkspeed, &len);
2147 if (ret == 0) {
2148 sinfo->txrate.legacy = le32_to_cpu(linkspeed) / 1000;
2149 sinfo->filled |= STATION_INFO_TX_BITRATE;
2150 }
2151
2152 len = sizeof(rssi);
2153 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2154 if (ret == 0) {
2155 sinfo->signal = level_to_qual(le32_to_cpu(rssi));
2156 sinfo->filled |= STATION_INFO_SIGNAL;
2157 }
2158 }
2159
2160 static int rndis_get_station(struct wiphy *wiphy, struct net_device *dev,
2161 u8 *mac, struct station_info *sinfo)
2162 {
2163 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2164 struct usbnet *usbdev = priv->usbdev;
2165
2166 if (compare_ether_addr(priv->bssid, mac))
2167 return -ENOENT;
2168
2169 rndis_fill_station_info(usbdev, sinfo);
2170
2171 return 0;
2172 }
2173
2174 static int rndis_dump_station(struct wiphy *wiphy, struct net_device *dev,
2175 int idx, u8 *mac, struct station_info *sinfo)
2176 {
2177 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
2178 struct usbnet *usbdev = priv->usbdev;
2179
2180 if (idx != 0)
2181 return -ENOENT;
2182
2183 memcpy(mac, priv->bssid, ETH_ALEN);
2184
2185 rndis_fill_station_info(usbdev, sinfo);
2186
2187 return 0;
2188 }
2189
2190 /*
2191 * workers, indication handlers, device poller
2192 */
2193 static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
2194 {
2195 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2196 struct ndis_80211_assoc_info *info;
2197 u8 assoc_buf[sizeof(*info) + IW_CUSTOM_MAX + 32];
2198 u8 bssid[ETH_ALEN];
2199 int resp_ie_len, req_ie_len;
2200 u8 *req_ie, *resp_ie;
2201 int ret, offset;
2202 bool roamed = false;
2203
2204 if (priv->infra_mode == NDIS_80211_INFRA_INFRA && priv->connected) {
2205 /* received media connect indication while connected, either
2206 * device reassociated with same AP or roamed to new. */
2207 roamed = true;
2208 }
2209
2210 req_ie_len = 0;
2211 resp_ie_len = 0;
2212 req_ie = NULL;
2213 resp_ie = NULL;
2214
2215 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2216 memset(assoc_buf, 0, sizeof(assoc_buf));
2217 info = (void *)assoc_buf;
2218
2219 /* Get association info IEs from device and send them back to
2220 * userspace. */
2221 ret = get_association_info(usbdev, info, sizeof(assoc_buf));
2222 if (!ret) {
2223 req_ie_len = le32_to_cpu(info->req_ie_length);
2224 if (req_ie_len > 0) {
2225 offset = le32_to_cpu(info->offset_req_ies);
2226 req_ie = (u8 *)info + offset;
2227 }
2228
2229 resp_ie_len = le32_to_cpu(info->resp_ie_length);
2230 if (resp_ie_len > 0) {
2231 offset = le32_to_cpu(info->offset_resp_ies);
2232 resp_ie = (u8 *)info + offset;
2233 }
2234 }
2235 } else if (WARN_ON(priv->infra_mode != NDIS_80211_INFRA_ADHOC))
2236 return;
2237
2238 ret = get_bssid(usbdev, bssid);
2239 if (ret < 0)
2240 memset(bssid, 0, sizeof(bssid));
2241
2242 netdev_dbg(usbdev->net, "link up work: [%pM]%s\n",
2243 bssid, roamed ? " roamed" : "");
2244
2245 /* Internal bss list in device always contains at least the currently
2246 * connected bss and we can get it to cfg80211 with
2247 * rndis_check_bssid_list().
2248 * NOTE: This is true for Broadcom chip, but not mentioned in RNDIS
2249 * spec.
2250 */
2251 rndis_check_bssid_list(usbdev);
2252
2253 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) {
2254 if (!roamed)
2255 cfg80211_connect_result(usbdev->net, bssid, req_ie,
2256 req_ie_len, resp_ie,
2257 resp_ie_len, 0, GFP_KERNEL);
2258 else
2259 cfg80211_roamed(usbdev->net, bssid, req_ie, req_ie_len,
2260 resp_ie, resp_ie_len, GFP_KERNEL);
2261 } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
2262 cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
2263
2264 priv->connected = true;
2265 memcpy(priv->bssid, bssid, ETH_ALEN);
2266
2267 usbnet_resume_rx(usbdev);
2268 netif_carrier_on(usbdev->net);
2269 }
2270
2271 static void rndis_wlan_do_link_down_work(struct usbnet *usbdev)
2272 {
2273 union iwreq_data evt;
2274
2275 netif_carrier_off(usbdev->net);
2276
2277 evt.data.flags = 0;
2278 evt.data.length = 0;
2279 memset(evt.ap_addr.sa_data, 0, ETH_ALEN);
2280 wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL);
2281 }
2282
2283 static void rndis_wlan_worker(struct work_struct *work)
2284 {
2285 struct rndis_wlan_private *priv =
2286 container_of(work, struct rndis_wlan_private, work);
2287 struct usbnet *usbdev = priv->usbdev;
2288
2289 if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending))
2290 rndis_wlan_do_link_up_work(usbdev);
2291
2292 if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending))
2293 rndis_wlan_do_link_down_work(usbdev);
2294
2295 if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2296 set_multicast_list(usbdev);
2297 }
2298
2299 static void rndis_wlan_set_multicast_list(struct net_device *dev)
2300 {
2301 struct usbnet *usbdev = netdev_priv(dev);
2302 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2303
2304 if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending))
2305 return;
2306
2307 set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending);
2308 queue_work(priv->workqueue, &priv->work);
2309 }
2310
2311 static void rndis_wlan_auth_indication(struct usbnet *usbdev,
2312 struct ndis_80211_status_indication *indication,
2313 int len)
2314 {
2315 u8 *buf;
2316 const char *type;
2317 int flags, buflen, key_id;
2318 bool pairwise_error, group_error;
2319 struct ndis_80211_auth_request *auth_req;
2320 enum nl80211_key_type key_type;
2321
2322 /* must have at least one array entry */
2323 if (len < offsetof(struct ndis_80211_status_indication, u) +
2324 sizeof(struct ndis_80211_auth_request)) {
2325 netdev_info(usbdev->net, "authentication indication: too short message (%i)\n",
2326 len);
2327 return;
2328 }
2329
2330 buf = (void *)&indication->u.auth_request[0];
2331 buflen = len - offsetof(struct ndis_80211_status_indication, u);
2332
2333 while (buflen >= sizeof(*auth_req)) {
2334 auth_req = (void *)buf;
2335 type = "unknown";
2336 flags = le32_to_cpu(auth_req->flags);
2337 pairwise_error = false;
2338 group_error = false;
2339
2340 if (flags & 0x1)
2341 type = "reauth request";
2342 if (flags & 0x2)
2343 type = "key update request";
2344 if (flags & 0x6) {
2345 pairwise_error = true;
2346 type = "pairwise_error";
2347 }
2348 if (flags & 0xe) {
2349 group_error = true;
2350 type = "group_error";
2351 }
2352
2353 netdev_info(usbdev->net, "authentication indication: %s (0x%08x)\n",
2354 type, le32_to_cpu(auth_req->flags));
2355
2356 if (pairwise_error) {
2357 key_type = NL80211_KEYTYPE_PAIRWISE;
2358 key_id = -1;
2359
2360 cfg80211_michael_mic_failure(usbdev->net,
2361 auth_req->bssid,
2362 key_type, key_id, NULL,
2363 GFP_KERNEL);
2364 }
2365
2366 if (group_error) {
2367 key_type = NL80211_KEYTYPE_GROUP;
2368 key_id = -1;
2369
2370 cfg80211_michael_mic_failure(usbdev->net,
2371 auth_req->bssid,
2372 key_type, key_id, NULL,
2373 GFP_KERNEL);
2374 }
2375
2376 buflen -= le32_to_cpu(auth_req->length);
2377 buf += le32_to_cpu(auth_req->length);
2378 }
2379 }
2380
2381 static void rndis_wlan_pmkid_cand_list_indication(struct usbnet *usbdev,
2382 struct ndis_80211_status_indication *indication,
2383 int len)
2384 {
2385 struct ndis_80211_pmkid_cand_list *cand_list;
2386 int list_len, expected_len, i;
2387
2388 if (len < offsetof(struct ndis_80211_status_indication, u) +
2389 sizeof(struct ndis_80211_pmkid_cand_list)) {
2390 netdev_info(usbdev->net, "pmkid candidate list indication: too short message (%i)\n",
2391 len);
2392 return;
2393 }
2394
2395 list_len = le32_to_cpu(indication->u.cand_list.num_candidates) *
2396 sizeof(struct ndis_80211_pmkid_candidate);
2397 expected_len = sizeof(struct ndis_80211_pmkid_cand_list) + list_len +
2398 offsetof(struct ndis_80211_status_indication, u);
2399
2400 if (len < expected_len) {
2401 netdev_info(usbdev->net, "pmkid candidate list indication: list larger than buffer (%i < %i)\n",
2402 len, expected_len);
2403 return;
2404 }
2405
2406 cand_list = &indication->u.cand_list;
2407
2408 netdev_info(usbdev->net, "pmkid candidate list indication: version %i, candidates %i\n",
2409 le32_to_cpu(cand_list->version),
2410 le32_to_cpu(cand_list->num_candidates));
2411
2412 if (le32_to_cpu(cand_list->version) != 1)
2413 return;
2414
2415 for (i = 0; i < le32_to_cpu(cand_list->num_candidates); i++) {
2416 struct ndis_80211_pmkid_candidate *cand =
2417 &cand_list->candidate_list[i];
2418
2419 netdev_dbg(usbdev->net, "cand[%i]: flags: 0x%08x, bssid: %pM\n",
2420 i, le32_to_cpu(cand->flags), cand->bssid);
2421
2422 #if 0
2423 struct iw_pmkid_cand pcand;
2424 union iwreq_data wrqu;
2425
2426 memset(&pcand, 0, sizeof(pcand));
2427 if (le32_to_cpu(cand->flags) & 0x01)
2428 pcand.flags |= IW_PMKID_CAND_PREAUTH;
2429 pcand.index = i;
2430 memcpy(pcand.bssid.sa_data, cand->bssid, ETH_ALEN);
2431
2432 memset(&wrqu, 0, sizeof(wrqu));
2433 wrqu.data.length = sizeof(pcand);
2434 wireless_send_event(usbdev->net, IWEVPMKIDCAND, &wrqu,
2435 (u8 *)&pcand);
2436 #endif
2437 }
2438 }
2439
2440 static void rndis_wlan_media_specific_indication(struct usbnet *usbdev,
2441 struct rndis_indicate *msg, int buflen)
2442 {
2443 struct ndis_80211_status_indication *indication;
2444 int len, offset;
2445
2446 offset = offsetof(struct rndis_indicate, status) +
2447 le32_to_cpu(msg->offset);
2448 len = le32_to_cpu(msg->length);
2449
2450 if (len < 8) {
2451 netdev_info(usbdev->net, "media specific indication, ignore too short message (%i < 8)\n",
2452 len);
2453 return;
2454 }
2455
2456 if (offset + len > buflen) {
2457 netdev_info(usbdev->net, "media specific indication, too large to fit to buffer (%i > %i)\n",
2458 offset + len, buflen);
2459 return;
2460 }
2461
2462 indication = (void *)((u8 *)msg + offset);
2463
2464 switch (le32_to_cpu(indication->status_type)) {
2465 case NDIS_80211_STATUSTYPE_RADIOSTATE:
2466 netdev_info(usbdev->net, "radio state indication: %i\n",
2467 le32_to_cpu(indication->u.radio_status));
2468 return;
2469
2470 case NDIS_80211_STATUSTYPE_MEDIASTREAMMODE:
2471 netdev_info(usbdev->net, "media stream mode indication: %i\n",
2472 le32_to_cpu(indication->u.media_stream_mode));
2473 return;
2474
2475 case NDIS_80211_STATUSTYPE_AUTHENTICATION:
2476 rndis_wlan_auth_indication(usbdev, indication, len);
2477 return;
2478
2479 case NDIS_80211_STATUSTYPE_PMKID_CANDIDATELIST:
2480 rndis_wlan_pmkid_cand_list_indication(usbdev, indication, len);
2481 return;
2482
2483 default:
2484 netdev_info(usbdev->net, "media specific indication: unknown status type 0x%08x\n",
2485 le32_to_cpu(indication->status_type));
2486 }
2487 }
2488
2489 static void rndis_wlan_indication(struct usbnet *usbdev, void *ind, int buflen)
2490 {
2491 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2492 struct rndis_indicate *msg = ind;
2493
2494 switch (msg->status) {
2495 case RNDIS_STATUS_MEDIA_CONNECT:
2496 if (priv->current_command_oid == OID_802_11_ADD_KEY) {
2497 /* OID_802_11_ADD_KEY causes sometimes extra
2498 * "media connect" indications which confuses driver
2499 * and userspace to think that device is
2500 * roaming/reassociating when it isn't.
2501 */
2502 netdev_dbg(usbdev->net, "ignored OID_802_11_ADD_KEY triggered 'media connect'\n");
2503 return;
2504 }
2505
2506 usbnet_pause_rx(usbdev);
2507
2508 netdev_info(usbdev->net, "media connect\n");
2509
2510 /* queue work to avoid recursive calls into rndis_command */
2511 set_bit(WORK_LINK_UP, &priv->work_pending);
2512 queue_work(priv->workqueue, &priv->work);
2513 break;
2514
2515 case RNDIS_STATUS_MEDIA_DISCONNECT:
2516 netdev_info(usbdev->net, "media disconnect\n");
2517
2518 /* queue work to avoid recursive calls into rndis_command */
2519 set_bit(WORK_LINK_DOWN, &priv->work_pending);
2520 queue_work(priv->workqueue, &priv->work);
2521 break;
2522
2523 case RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION:
2524 rndis_wlan_media_specific_indication(usbdev, msg, buflen);
2525 break;
2526
2527 default:
2528 netdev_info(usbdev->net, "indication: 0x%08x\n",
2529 le32_to_cpu(msg->status));
2530 break;
2531 }
2532 }
2533
2534 static int rndis_wlan_get_caps(struct usbnet *usbdev)
2535 {
2536 struct {
2537 __le32 num_items;
2538 __le32 items[8];
2539 } networks_supported;
2540 int len, retval, i, n;
2541 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2542
2543 /* determine supported modes */
2544 len = sizeof(networks_supported);
2545 retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED,
2546 &networks_supported, &len);
2547 if (retval >= 0) {
2548 n = le32_to_cpu(networks_supported.num_items);
2549 if (n > 8)
2550 n = 8;
2551 for (i = 0; i < n; i++) {
2552 switch (le32_to_cpu(networks_supported.items[i])) {
2553 case NDIS_80211_TYPE_FREQ_HOP:
2554 case NDIS_80211_TYPE_DIRECT_SEQ:
2555 priv->caps |= CAP_MODE_80211B;
2556 break;
2557 case NDIS_80211_TYPE_OFDM_A:
2558 priv->caps |= CAP_MODE_80211A;
2559 break;
2560 case NDIS_80211_TYPE_OFDM_G:
2561 priv->caps |= CAP_MODE_80211G;
2562 break;
2563 }
2564 }
2565 }
2566
2567 return retval;
2568 }
2569
2570 #define DEVICE_POLLER_JIFFIES (HZ)
2571 static void rndis_device_poller(struct work_struct *work)
2572 {
2573 struct rndis_wlan_private *priv =
2574 container_of(work, struct rndis_wlan_private,
2575 dev_poller_work.work);
2576 struct usbnet *usbdev = priv->usbdev;
2577 __le32 rssi, tmp;
2578 int len, ret, j;
2579 int update_jiffies = DEVICE_POLLER_JIFFIES;
2580 void *buf;
2581
2582 /* Only check/do workaround when connected. Calling is_associated()
2583 * also polls device with rndis_command() and catches for media link
2584 * indications.
2585 */
2586 if (!is_associated(usbdev))
2587 goto end;
2588
2589 len = sizeof(rssi);
2590 ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len);
2591 if (ret == 0)
2592 priv->last_qual = level_to_qual(le32_to_cpu(rssi));
2593
2594 netdev_dbg(usbdev->net, "dev-poller: OID_802_11_RSSI -> %d, rssi:%d, qual: %d\n",
2595 ret, le32_to_cpu(rssi), level_to_qual(le32_to_cpu(rssi)));
2596
2597 /* Workaround transfer stalls on poor quality links.
2598 * TODO: find right way to fix these stalls (as stalls do not happen
2599 * with ndiswrapper/windows driver). */
2600 if (priv->param_workaround_interval > 0 && priv->last_qual <= 25) {
2601 /* Decrease stats worker interval to catch stalls.
2602 * faster. Faster than 400-500ms causes packet loss,
2603 * Slower doesn't catch stalls fast enough.
2604 */
2605 j = msecs_to_jiffies(priv->param_workaround_interval);
2606 if (j > DEVICE_POLLER_JIFFIES)
2607 j = DEVICE_POLLER_JIFFIES;
2608 else if (j <= 0)
2609 j = 1;
2610 update_jiffies = j;
2611
2612 /* Send scan OID. Use of both OIDs is required to get device
2613 * working.
2614 */
2615 tmp = cpu_to_le32(1);
2616 rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
2617 sizeof(tmp));
2618
2619 len = CONTROL_BUFFER_SIZE;
2620 buf = kmalloc(len, GFP_KERNEL);
2621 if (!buf)
2622 goto end;
2623
2624 rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
2625 kfree(buf);
2626 }
2627
2628 end:
2629 if (update_jiffies >= HZ)
2630 update_jiffies = round_jiffies_relative(update_jiffies);
2631 else {
2632 j = round_jiffies_relative(update_jiffies);
2633 if (abs(j - update_jiffies) <= 10)
2634 update_jiffies = j;
2635 }
2636
2637 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
2638 update_jiffies);
2639 }
2640
2641 /*
2642 * driver/device initialization
2643 */
2644 static void rndis_copy_module_params(struct usbnet *usbdev)
2645 {
2646 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2647
2648 priv->param_country[0] = modparam_country[0];
2649 priv->param_country[1] = modparam_country[1];
2650 priv->param_country[2] = 0;
2651 priv->param_frameburst = modparam_frameburst;
2652 priv->param_afterburner = modparam_afterburner;
2653 priv->param_power_save = modparam_power_save;
2654 priv->param_power_output = modparam_power_output;
2655 priv->param_roamtrigger = modparam_roamtrigger;
2656 priv->param_roamdelta = modparam_roamdelta;
2657
2658 priv->param_country[0] = toupper(priv->param_country[0]);
2659 priv->param_country[1] = toupper(priv->param_country[1]);
2660 /* doesn't support EU as country code, use FI instead */
2661 if (!strcmp(priv->param_country, "EU"))
2662 strcpy(priv->param_country, "FI");
2663
2664 if (priv->param_power_save < 0)
2665 priv->param_power_save = 0;
2666 else if (priv->param_power_save > 2)
2667 priv->param_power_save = 2;
2668
2669 if (priv->param_power_output < 0)
2670 priv->param_power_output = 0;
2671 else if (priv->param_power_output > 3)
2672 priv->param_power_output = 3;
2673
2674 if (priv->param_roamtrigger < -80)
2675 priv->param_roamtrigger = -80;
2676 else if (priv->param_roamtrigger > -60)
2677 priv->param_roamtrigger = -60;
2678
2679 if (priv->param_roamdelta < 0)
2680 priv->param_roamdelta = 0;
2681 else if (priv->param_roamdelta > 2)
2682 priv->param_roamdelta = 2;
2683
2684 if (modparam_workaround_interval < 0)
2685 priv->param_workaround_interval = 500;
2686 else
2687 priv->param_workaround_interval = modparam_workaround_interval;
2688 }
2689
2690 static int bcm4320a_early_init(struct usbnet *usbdev)
2691 {
2692 /* copy module parameters for bcm4320a so that iwconfig reports txpower
2693 * and workaround parameter is copied to private structure correctly.
2694 */
2695 rndis_copy_module_params(usbdev);
2696
2697 /* bcm4320a doesn't handle configuration parameters well. Try
2698 * set any and you get partially zeroed mac and broken device.
2699 */
2700
2701 return 0;
2702 }
2703
2704 static int bcm4320b_early_init(struct usbnet *usbdev)
2705 {
2706 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2707 char buf[8];
2708
2709 rndis_copy_module_params(usbdev);
2710
2711 /* Early initialization settings, setting these won't have effect
2712 * if called after generic_rndis_bind().
2713 */
2714
2715 rndis_set_config_parameter_str(usbdev, "Country", priv->param_country);
2716 rndis_set_config_parameter_str(usbdev, "FrameBursting",
2717 priv->param_frameburst ? "1" : "0");
2718 rndis_set_config_parameter_str(usbdev, "Afterburner",
2719 priv->param_afterburner ? "1" : "0");
2720 sprintf(buf, "%d", priv->param_power_save);
2721 rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf);
2722 sprintf(buf, "%d", priv->param_power_output);
2723 rndis_set_config_parameter_str(usbdev, "PwrOut", buf);
2724 sprintf(buf, "%d", priv->param_roamtrigger);
2725 rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf);
2726 sprintf(buf, "%d", priv->param_roamdelta);
2727 rndis_set_config_parameter_str(usbdev, "RoamDelta", buf);
2728
2729 return 0;
2730 }
2731
2732 /* same as rndis_netdev_ops but with local multicast handler */
2733 static const struct net_device_ops rndis_wlan_netdev_ops = {
2734 .ndo_open = usbnet_open,
2735 .ndo_stop = usbnet_stop,
2736 .ndo_start_xmit = usbnet_start_xmit,
2737 .ndo_tx_timeout = usbnet_tx_timeout,
2738 .ndo_set_mac_address = eth_mac_addr,
2739 .ndo_validate_addr = eth_validate_addr,
2740 .ndo_set_multicast_list = rndis_wlan_set_multicast_list,
2741 };
2742
2743 static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
2744 {
2745 struct wiphy *wiphy;
2746 struct rndis_wlan_private *priv;
2747 int retval, len;
2748 __le32 tmp;
2749
2750 /* allocate wiphy and rndis private data
2751 * NOTE: We only support a single virtual interface, so wiphy
2752 * and wireless_dev are somewhat synonymous for this device.
2753 */
2754 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wlan_private));
2755 if (!wiphy)
2756 return -ENOMEM;
2757
2758 priv = wiphy_priv(wiphy);
2759 usbdev->net->ieee80211_ptr = &priv->wdev;
2760 priv->wdev.wiphy = wiphy;
2761 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2762
2763 /* These have to be initialized before calling generic_rndis_bind().
2764 * Otherwise we'll be in big trouble in rndis_wlan_early_init().
2765 */
2766 usbdev->driver_priv = priv;
2767 priv->usbdev = usbdev;
2768
2769 mutex_init(&priv->command_lock);
2770
2771 /* because rndis_command() sleeps we need to use workqueue */
2772 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
2773 INIT_WORK(&priv->work, rndis_wlan_worker);
2774 INIT_DELAYED_WORK(&priv->dev_poller_work, rndis_device_poller);
2775 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2776
2777 /* try bind rndis_host */
2778 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
2779 if (retval < 0)
2780 goto fail;
2781
2782 /* generic_rndis_bind set packet filter to multicast_all+
2783 * promisc mode which doesn't work well for our devices (device
2784 * picks up rssi to closest station instead of to access point).
2785 *
2786 * rndis_host wants to avoid all OID as much as possible
2787 * so do promisc/multicast handling in rndis_wlan.
2788 */
2789 usbdev->net->netdev_ops = &rndis_wlan_netdev_ops;
2790
2791 tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST;
2792 retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp,
2793 sizeof(tmp));
2794
2795 len = sizeof(tmp);
2796 retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp,
2797 &len);
2798 priv->multicast_size = le32_to_cpu(tmp);
2799 if (retval < 0 || priv->multicast_size < 0)
2800 priv->multicast_size = 0;
2801 if (priv->multicast_size > 0)
2802 usbdev->net->flags |= IFF_MULTICAST;
2803 else
2804 usbdev->net->flags &= ~IFF_MULTICAST;
2805
2806 /* fill-out wiphy structure and register w/ cfg80211 */
2807 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2808 wiphy->privid = rndis_wiphy_privid;
2809 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2810 | BIT(NL80211_IFTYPE_ADHOC);
2811 wiphy->max_scan_ssids = 1;
2812
2813 /* TODO: fill-out band/encr information based on priv->caps */
2814 rndis_wlan_get_caps(usbdev);
2815
2816 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2817 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2818 priv->band.channels = priv->channels;
2819 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2820 priv->band.bitrates = priv->rates;
2821 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2822 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
2823 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2824
2825 memcpy(priv->cipher_suites, rndis_cipher_suites,
2826 sizeof(rndis_cipher_suites));
2827 wiphy->cipher_suites = priv->cipher_suites;
2828 wiphy->n_cipher_suites = ARRAY_SIZE(rndis_cipher_suites);
2829
2830 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2831
2832 if (wiphy_register(wiphy)) {
2833 retval = -ENODEV;
2834 goto fail;
2835 }
2836
2837 set_default_iw_params(usbdev);
2838
2839 /* set default rts/frag */
2840 rndis_set_wiphy_params(wiphy,
2841 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2842
2843 /* turn radio on */
2844 priv->radio_on = true;
2845 disassociate(usbdev, true);
2846 netif_carrier_off(usbdev->net);
2847
2848 return 0;
2849
2850 fail:
2851 cancel_delayed_work_sync(&priv->dev_poller_work);
2852 cancel_delayed_work_sync(&priv->scan_work);
2853 cancel_work_sync(&priv->work);
2854 flush_workqueue(priv->workqueue);
2855 destroy_workqueue(priv->workqueue);
2856
2857 wiphy_free(wiphy);
2858 return retval;
2859 }
2860
2861 static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
2862 {
2863 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2864
2865 /* turn radio off */
2866 disassociate(usbdev, false);
2867
2868 cancel_delayed_work_sync(&priv->dev_poller_work);
2869 cancel_delayed_work_sync(&priv->scan_work);
2870 cancel_work_sync(&priv->work);
2871 flush_workqueue(priv->workqueue);
2872 destroy_workqueue(priv->workqueue);
2873
2874 if (priv && priv->wpa_ie_len)
2875 kfree(priv->wpa_ie);
2876
2877 rndis_unbind(usbdev, intf);
2878
2879 wiphy_unregister(priv->wdev.wiphy);
2880 wiphy_free(priv->wdev.wiphy);
2881 }
2882
2883 static int rndis_wlan_reset(struct usbnet *usbdev)
2884 {
2885 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2886 int retval;
2887
2888 netdev_dbg(usbdev->net, "%s()\n", __func__);
2889
2890 retval = rndis_reset(usbdev);
2891 if (retval)
2892 netdev_warn(usbdev->net, "rndis_reset failed: %d\n", retval);
2893
2894 /* rndis_reset cleared multicast list, so restore here.
2895 (set_multicast_list() also turns on current packet filter) */
2896 set_multicast_list(usbdev);
2897
2898 queue_delayed_work(priv->workqueue, &priv->dev_poller_work,
2899 round_jiffies_relative(DEVICE_POLLER_JIFFIES));
2900
2901 return deauthenticate(usbdev);
2902 }
2903
2904 static int rndis_wlan_stop(struct usbnet *usbdev)
2905 {
2906 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
2907 int retval;
2908 __le32 filter;
2909
2910 netdev_dbg(usbdev->net, "%s()\n", __func__);
2911
2912 retval = disassociate(usbdev, false);
2913
2914 priv->work_pending = 0;
2915 cancel_delayed_work_sync(&priv->dev_poller_work);
2916 cancel_delayed_work_sync(&priv->scan_work);
2917 cancel_work_sync(&priv->work);
2918 flush_workqueue(priv->workqueue);
2919
2920 if (priv->scan_request) {
2921 cfg80211_scan_done(priv->scan_request, true);
2922 priv->scan_request = NULL;
2923 }
2924
2925 /* Set current packet filter zero to block receiving data packets from
2926 device. */
2927 filter = 0;
2928 rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter,
2929 sizeof(filter));
2930
2931 return retval;
2932 }
2933
2934 static const struct driver_info bcm4320b_info = {
2935 .description = "Wireless RNDIS device, BCM4320b based",
2936 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2937 FLAG_AVOID_UNLINK_URBS,
2938 .bind = rndis_wlan_bind,
2939 .unbind = rndis_wlan_unbind,
2940 .status = rndis_status,
2941 .rx_fixup = rndis_rx_fixup,
2942 .tx_fixup = rndis_tx_fixup,
2943 .reset = rndis_wlan_reset,
2944 .stop = rndis_wlan_stop,
2945 .early_init = bcm4320b_early_init,
2946 .indication = rndis_wlan_indication,
2947 };
2948
2949 static const struct driver_info bcm4320a_info = {
2950 .description = "Wireless RNDIS device, BCM4320a based",
2951 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2952 FLAG_AVOID_UNLINK_URBS,
2953 .bind = rndis_wlan_bind,
2954 .unbind = rndis_wlan_unbind,
2955 .status = rndis_status,
2956 .rx_fixup = rndis_rx_fixup,
2957 .tx_fixup = rndis_tx_fixup,
2958 .reset = rndis_wlan_reset,
2959 .stop = rndis_wlan_stop,
2960 .early_init = bcm4320a_early_init,
2961 .indication = rndis_wlan_indication,
2962 };
2963
2964 static const struct driver_info rndis_wlan_info = {
2965 .description = "Wireless RNDIS device",
2966 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT |
2967 FLAG_AVOID_UNLINK_URBS,
2968 .bind = rndis_wlan_bind,
2969 .unbind = rndis_wlan_unbind,
2970 .status = rndis_status,
2971 .rx_fixup = rndis_rx_fixup,
2972 .tx_fixup = rndis_tx_fixup,
2973 .reset = rndis_wlan_reset,
2974 .stop = rndis_wlan_stop,
2975 .early_init = bcm4320a_early_init,
2976 .indication = rndis_wlan_indication,
2977 };
2978
2979 /*-------------------------------------------------------------------------*/
2980
2981 static const struct usb_device_id products [] = {
2982 #define RNDIS_MASTER_INTERFACE \
2983 .bInterfaceClass = USB_CLASS_COMM, \
2984 .bInterfaceSubClass = 2 /* ACM */, \
2985 .bInterfaceProtocol = 0x0ff
2986
2987 /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom
2988 * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki.
2989 */
2990 {
2991 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2992 | USB_DEVICE_ID_MATCH_DEVICE,
2993 .idVendor = 0x0411,
2994 .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */
2995 RNDIS_MASTER_INTERFACE,
2996 .driver_info = (unsigned long) &bcm4320b_info,
2997 }, {
2998 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2999 | USB_DEVICE_ID_MATCH_DEVICE,
3000 .idVendor = 0x0baf,
3001 .idProduct = 0x011b, /* U.S. Robotics USR5421 */
3002 RNDIS_MASTER_INTERFACE,
3003 .driver_info = (unsigned long) &bcm4320b_info,
3004 }, {
3005 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3006 | USB_DEVICE_ID_MATCH_DEVICE,
3007 .idVendor = 0x050d,
3008 .idProduct = 0x011b, /* Belkin F5D7051 */
3009 RNDIS_MASTER_INTERFACE,
3010 .driver_info = (unsigned long) &bcm4320b_info,
3011 }, {
3012 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3013 | USB_DEVICE_ID_MATCH_DEVICE,
3014 .idVendor = 0x1799, /* Belkin has two vendor ids */
3015 .idProduct = 0x011b, /* Belkin F5D7051 */
3016 RNDIS_MASTER_INTERFACE,
3017 .driver_info = (unsigned long) &bcm4320b_info,
3018 }, {
3019 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3020 | USB_DEVICE_ID_MATCH_DEVICE,
3021 .idVendor = 0x13b1,
3022 .idProduct = 0x0014, /* Linksys WUSB54GSv2 */
3023 RNDIS_MASTER_INTERFACE,
3024 .driver_info = (unsigned long) &bcm4320b_info,
3025 }, {
3026 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3027 | USB_DEVICE_ID_MATCH_DEVICE,
3028 .idVendor = 0x13b1,
3029 .idProduct = 0x0026, /* Linksys WUSB54GSC */
3030 RNDIS_MASTER_INTERFACE,
3031 .driver_info = (unsigned long) &bcm4320b_info,
3032 }, {
3033 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3034 | USB_DEVICE_ID_MATCH_DEVICE,
3035 .idVendor = 0x0b05,
3036 .idProduct = 0x1717, /* Asus WL169gE */
3037 RNDIS_MASTER_INTERFACE,
3038 .driver_info = (unsigned long) &bcm4320b_info,
3039 }, {
3040 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3041 | USB_DEVICE_ID_MATCH_DEVICE,
3042 .idVendor = 0x0a5c,
3043 .idProduct = 0xd11b, /* Eminent EM4045 */
3044 RNDIS_MASTER_INTERFACE,
3045 .driver_info = (unsigned long) &bcm4320b_info,
3046 }, {
3047 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3048 | USB_DEVICE_ID_MATCH_DEVICE,
3049 .idVendor = 0x1690,
3050 .idProduct = 0x0715, /* BT Voyager 1055 */
3051 RNDIS_MASTER_INTERFACE,
3052 .driver_info = (unsigned long) &bcm4320b_info,
3053 },
3054 /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom
3055 * parameters available, hardware probably contain older firmware version with
3056 * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki.
3057 */
3058 {
3059 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3060 | USB_DEVICE_ID_MATCH_DEVICE,
3061 .idVendor = 0x13b1,
3062 .idProduct = 0x000e, /* Linksys WUSB54GSv1 */
3063 RNDIS_MASTER_INTERFACE,
3064 .driver_info = (unsigned long) &bcm4320a_info,
3065 }, {
3066 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3067 | USB_DEVICE_ID_MATCH_DEVICE,
3068 .idVendor = 0x0baf,
3069 .idProduct = 0x0111, /* U.S. Robotics USR5420 */
3070 RNDIS_MASTER_INTERFACE,
3071 .driver_info = (unsigned long) &bcm4320a_info,
3072 }, {
3073 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
3074 | USB_DEVICE_ID_MATCH_DEVICE,
3075 .idVendor = 0x0411,
3076 .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */
3077 RNDIS_MASTER_INTERFACE,
3078 .driver_info = (unsigned long) &bcm4320a_info,
3079 },
3080 /* Generic Wireless RNDIS devices that we don't have exact
3081 * idVendor/idProduct/chip yet.
3082 */
3083 {
3084 /* RNDIS is MSFT's un-official variant of CDC ACM */
3085 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
3086 .driver_info = (unsigned long) &rndis_wlan_info,
3087 }, {
3088 /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */
3089 USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1),
3090 .driver_info = (unsigned long) &rndis_wlan_info,
3091 },
3092 { }, // END
3093 };
3094 MODULE_DEVICE_TABLE(usb, products);
3095
3096 static struct usb_driver rndis_wlan_driver = {
3097 .name = "rndis_wlan",
3098 .id_table = products,
3099 .probe = usbnet_probe,
3100 .disconnect = usbnet_disconnect,
3101 .suspend = usbnet_suspend,
3102 .resume = usbnet_resume,
3103 };
3104
3105 static int __init rndis_wlan_init(void)
3106 {
3107 return usb_register(&rndis_wlan_driver);
3108 }
3109 module_init(rndis_wlan_init);
3110
3111 static void __exit rndis_wlan_exit(void)
3112 {
3113 usb_deregister(&rndis_wlan_driver);
3114 }
3115 module_exit(rndis_wlan_exit);
3116
3117 MODULE_AUTHOR("Bjorge Dijkstra");
3118 MODULE_AUTHOR("Jussi Kivilinna");
3119 MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters");
3120 MODULE_LICENSE("GPL");
3121
This page took 0.0916 seconds and 6 git commands to generate.