]>
Commit | Line | Data |
---|---|---|
bf164cc0 JK |
1 | /* |
2 | * Driver for RNDIS based wireless USB devices. | |
3 | * | |
4 | * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net> | |
9656e85b | 5 | * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@mbnet.fi> |
bf164cc0 JK |
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> | |
2c706002 | 40 | #include <linux/ieee80211.h> |
bf164cc0 JK |
41 | #include <linux/if_arp.h> |
42 | #include <linux/ctype.h> | |
43 | #include <linux/spinlock.h> | |
44 | #include <net/iw_handler.h> | |
5c8fa4f7 | 45 | #include <net/cfg80211.h> |
bf164cc0 JK |
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 = 500; | |
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 (default: 500)"); | |
91 | ||
92 | ||
93 | /* various RNDIS OID defs */ | |
35c26c2c HH |
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_PERMANENT_ADDRESS cpu_to_le32(0x01010101) | |
104 | #define OID_802_3_CURRENT_ADDRESS cpu_to_le32(0x01010102) | |
105 | #define OID_802_3_MULTICAST_LIST cpu_to_le32(0x01010103) | |
106 | #define OID_802_3_MAXIMUM_LIST_SIZE cpu_to_le32(0x01010104) | |
107 | ||
108 | #define OID_802_11_BSSID cpu_to_le32(0x0d010101) | |
109 | #define OID_802_11_SSID cpu_to_le32(0x0d010102) | |
110 | #define OID_802_11_INFRASTRUCTURE_MODE cpu_to_le32(0x0d010108) | |
111 | #define OID_802_11_ADD_WEP cpu_to_le32(0x0d010113) | |
112 | #define OID_802_11_REMOVE_WEP cpu_to_le32(0x0d010114) | |
113 | #define OID_802_11_DISASSOCIATE cpu_to_le32(0x0d010115) | |
114 | #define OID_802_11_AUTHENTICATION_MODE cpu_to_le32(0x0d010118) | |
115 | #define OID_802_11_PRIVACY_FILTER cpu_to_le32(0x0d010119) | |
116 | #define OID_802_11_BSSID_LIST_SCAN cpu_to_le32(0x0d01011a) | |
117 | #define OID_802_11_ENCRYPTION_STATUS cpu_to_le32(0x0d01011b) | |
118 | #define OID_802_11_ADD_KEY cpu_to_le32(0x0d01011d) | |
119 | #define OID_802_11_REMOVE_KEY cpu_to_le32(0x0d01011e) | |
120 | #define OID_802_11_ASSOCIATION_INFORMATION cpu_to_le32(0x0d01011f) | |
121 | #define OID_802_11_PMKID cpu_to_le32(0x0d010123) | |
122 | #define OID_802_11_NETWORK_TYPES_SUPPORTED cpu_to_le32(0x0d010203) | |
123 | #define OID_802_11_NETWORK_TYPE_IN_USE cpu_to_le32(0x0d010204) | |
124 | #define OID_802_11_TX_POWER_LEVEL cpu_to_le32(0x0d010205) | |
125 | #define OID_802_11_RSSI cpu_to_le32(0x0d010206) | |
126 | #define OID_802_11_RSSI_TRIGGER cpu_to_le32(0x0d010207) | |
127 | #define OID_802_11_FRAGMENTATION_THRESHOLD cpu_to_le32(0x0d010209) | |
128 | #define OID_802_11_RTS_THRESHOLD cpu_to_le32(0x0d01020a) | |
129 | #define OID_802_11_SUPPORTED_RATES cpu_to_le32(0x0d01020e) | |
130 | #define OID_802_11_CONFIGURATION cpu_to_le32(0x0d010211) | |
131 | #define OID_802_11_BSSID_LIST cpu_to_le32(0x0d010217) | |
bf164cc0 JK |
132 | |
133 | ||
134 | /* Typical noise/maximum signal level values taken from ndiswrapper iw_ndis.h */ | |
135 | #define WL_NOISE -96 /* typical noise level in dBm */ | |
136 | #define WL_SIGMAX -32 /* typical maximum signal level in dBm */ | |
137 | ||
138 | ||
139 | /* Assume that Broadcom 4320 (only chipset at time of writing known to be | |
140 | * based on wireless rndis) has default txpower of 13dBm. | |
141 | * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications. | |
142 | * 13dBm == 19.9mW | |
143 | */ | |
144 | #define BCM4320_DEFAULT_TXPOWER 20 | |
145 | ||
146 | ||
147 | /* codes for "status" field of completion messages */ | |
35c26c2c HH |
148 | #define RNDIS_STATUS_ADAPTER_NOT_READY cpu_to_le32(0xc0010011) |
149 | #define RNDIS_STATUS_ADAPTER_NOT_OPEN cpu_to_le32(0xc0010012) | |
bf164cc0 JK |
150 | |
151 | ||
152 | /* NDIS data structures. Taken from wpa_supplicant driver_ndis.c | |
153 | * slightly modified for datatype endianess, etc | |
154 | */ | |
155 | #define NDIS_802_11_LENGTH_SSID 32 | |
156 | #define NDIS_802_11_LENGTH_RATES 8 | |
157 | #define NDIS_802_11_LENGTH_RATES_EX 16 | |
158 | ||
1e41e1d2 JK |
159 | enum ndis_80211_net_type { |
160 | ndis_80211_type_freq_hop, | |
161 | ndis_80211_type_direct_seq, | |
162 | ndis_80211_type_ofdm_a, | |
163 | ndis_80211_type_ofdm_g | |
164 | }; | |
165 | ||
166 | enum ndis_80211_net_infra { | |
167 | ndis_80211_infra_adhoc, | |
168 | ndis_80211_infra_infra, | |
169 | ndis_80211_infra_auto_unknown | |
170 | }; | |
171 | ||
172 | enum ndis_80211_auth_mode { | |
173 | ndis_80211_auth_open, | |
174 | ndis_80211_auth_shared, | |
175 | ndis_80211_auth_auto_switch, | |
176 | ndis_80211_auth_wpa, | |
177 | ndis_80211_auth_wpa_psk, | |
178 | ndis_80211_auth_wpa_none, | |
179 | ndis_80211_auth_wpa2, | |
180 | ndis_80211_auth_wpa2_psk | |
181 | }; | |
182 | ||
183 | enum ndis_80211_encr_status { | |
184 | ndis_80211_encr_wep_enabled, | |
185 | ndis_80211_encr_disabled, | |
186 | ndis_80211_encr_wep_key_absent, | |
187 | ndis_80211_encr_not_supported, | |
188 | ndis_80211_encr_tkip_enabled, | |
189 | ndis_80211_encr_tkip_key_absent, | |
190 | ndis_80211_encr_ccmp_enabled, | |
191 | ndis_80211_encr_ccmp_key_absent | |
192 | }; | |
193 | ||
194 | enum ndis_80211_priv_filter { | |
195 | ndis_80211_priv_accept_all, | |
196 | ndis_80211_priv_8021x_wep | |
197 | }; | |
198 | ||
b4703a2e JK |
199 | enum ndis_80211_addkey_bits { |
200 | ndis_80211_addkey_8021x_auth = cpu_to_le32(1 << 28), | |
201 | ndis_80211_addkey_set_init_recv_seq = cpu_to_le32(1 << 29), | |
202 | ndis_80211_addkey_pairwise_key = cpu_to_le32(1 << 30), | |
203 | ndis_80211_addkey_transmit_key = cpu_to_le32(1 << 31), | |
204 | }; | |
205 | ||
206 | enum ndis_80211_addwep_bits { | |
207 | ndis_80211_addwep_perclient_key = cpu_to_le32(1 << 30), | |
208 | ndis_80211_addwep_transmit_key = cpu_to_le32(1 << 31), | |
209 | }; | |
210 | ||
1e41e1d2 | 211 | struct ndis_80211_ssid { |
461b3f2a JK |
212 | __le32 length; |
213 | u8 essid[NDIS_802_11_LENGTH_SSID]; | |
bf164cc0 JK |
214 | } __attribute__((packed)); |
215 | ||
1e41e1d2 | 216 | struct ndis_80211_conf_freq_hop { |
461b3f2a JK |
217 | __le32 length; |
218 | __le32 hop_pattern; | |
219 | __le32 hop_set; | |
220 | __le32 dwell_time; | |
bf164cc0 JK |
221 | } __attribute__((packed)); |
222 | ||
1e41e1d2 | 223 | struct ndis_80211_conf { |
461b3f2a JK |
224 | __le32 length; |
225 | __le32 beacon_period; | |
226 | __le32 atim_window; | |
227 | __le32 ds_config; | |
228 | struct ndis_80211_conf_freq_hop fh_config; | |
bf164cc0 JK |
229 | } __attribute__((packed)); |
230 | ||
1e41e1d2 | 231 | struct ndis_80211_bssid_ex { |
461b3f2a JK |
232 | __le32 length; |
233 | u8 mac[6]; | |
234 | u8 padding[2]; | |
235 | struct ndis_80211_ssid ssid; | |
236 | __le32 privacy; | |
237 | __le32 rssi; | |
238 | __le32 net_type; | |
239 | struct ndis_80211_conf config; | |
240 | __le32 net_infra; | |
241 | u8 rates[NDIS_802_11_LENGTH_RATES_EX]; | |
242 | __le32 ie_length; | |
243 | u8 ies[0]; | |
bf164cc0 JK |
244 | } __attribute__((packed)); |
245 | ||
1e41e1d2 | 246 | struct ndis_80211_bssid_list_ex { |
461b3f2a JK |
247 | __le32 num_items; |
248 | struct ndis_80211_bssid_ex bssid[0]; | |
bf164cc0 JK |
249 | } __attribute__((packed)); |
250 | ||
1e41e1d2 | 251 | struct ndis_80211_fixed_ies { |
461b3f2a JK |
252 | u8 timestamp[8]; |
253 | __le16 beacon_interval; | |
254 | __le16 capabilities; | |
bf164cc0 JK |
255 | } __attribute__((packed)); |
256 | ||
1e41e1d2 | 257 | struct ndis_80211_wep_key { |
461b3f2a JK |
258 | __le32 size; |
259 | __le32 index; | |
260 | __le32 length; | |
261 | u8 material[32]; | |
bf164cc0 JK |
262 | } __attribute__((packed)); |
263 | ||
1e41e1d2 | 264 | struct ndis_80211_key { |
461b3f2a JK |
265 | __le32 size; |
266 | __le32 index; | |
267 | __le32 length; | |
268 | u8 bssid[6]; | |
269 | u8 padding[6]; | |
270 | u8 rsc[8]; | |
271 | u8 material[32]; | |
bf164cc0 JK |
272 | } __attribute__((packed)); |
273 | ||
1e41e1d2 | 274 | struct ndis_80211_remove_key { |
461b3f2a JK |
275 | __le32 size; |
276 | __le32 index; | |
277 | u8 bssid[6]; | |
bf164cc0 JK |
278 | } __attribute__((packed)); |
279 | ||
1e41e1d2 | 280 | struct ndis_config_param { |
461b3f2a JK |
281 | __le32 name_offs; |
282 | __le32 name_length; | |
283 | __le32 type; | |
284 | __le32 value_offs; | |
285 | __le32 value_length; | |
bf164cc0 JK |
286 | } __attribute__((packed)); |
287 | ||
4364623c SA |
288 | struct ndis_80211_assoc_info { |
289 | __le32 length; | |
290 | __le16 req_ies; | |
291 | struct req_ie { | |
292 | __le16 capa; | |
293 | __le16 listen_interval; | |
294 | u8 cur_ap_address[6]; | |
295 | } req_ie; | |
296 | __le32 req_ie_length; | |
297 | __le32 offset_req_ies; | |
298 | __le16 resp_ies; | |
299 | struct resp_ie { | |
300 | __le16 capa; | |
301 | __le16 status_code; | |
302 | __le16 assoc_id; | |
303 | } resp_ie; | |
304 | __le32 resp_ie_length; | |
305 | __le32 offset_resp_ies; | |
306 | } __attribute__((packed)); | |
307 | ||
bf164cc0 | 308 | /* these have to match what is in wpa_supplicant */ |
5b0acc64 JB |
309 | enum wpa_alg { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP }; |
310 | enum wpa_cipher { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP, | |
311 | CIPHER_WEP104 }; | |
312 | enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE, | |
313 | KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE }; | |
bf164cc0 JK |
314 | |
315 | /* | |
316 | * private data | |
317 | */ | |
318 | #define NET_TYPE_11FB 0 | |
319 | ||
320 | #define CAP_MODE_80211A 1 | |
321 | #define CAP_MODE_80211B 2 | |
322 | #define CAP_MODE_80211G 4 | |
323 | #define CAP_MODE_MASK 7 | |
bf164cc0 | 324 | |
6010ce07 JK |
325 | #define WORK_LINK_UP (1<<0) |
326 | #define WORK_LINK_DOWN (1<<1) | |
327 | #define WORK_SET_MULTICAST_LIST (1<<2) | |
bf164cc0 | 328 | |
90d07349 JK |
329 | #define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set)) |
330 | ||
5c8fa4f7 JL |
331 | static const struct ieee80211_channel rndis_channels[] = { |
332 | { .center_freq = 2412 }, | |
333 | { .center_freq = 2417 }, | |
334 | { .center_freq = 2422 }, | |
335 | { .center_freq = 2427 }, | |
336 | { .center_freq = 2432 }, | |
337 | { .center_freq = 2437 }, | |
338 | { .center_freq = 2442 }, | |
339 | { .center_freq = 2447 }, | |
340 | { .center_freq = 2452 }, | |
341 | { .center_freq = 2457 }, | |
342 | { .center_freq = 2462 }, | |
343 | { .center_freq = 2467 }, | |
344 | { .center_freq = 2472 }, | |
345 | { .center_freq = 2484 }, | |
346 | }; | |
347 | ||
348 | static const struct ieee80211_rate rndis_rates[] = { | |
349 | { .bitrate = 10 }, | |
350 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
351 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
352 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
353 | { .bitrate = 60 }, | |
354 | { .bitrate = 90 }, | |
355 | { .bitrate = 120 }, | |
356 | { .bitrate = 180 }, | |
357 | { .bitrate = 240 }, | |
358 | { .bitrate = 360 }, | |
359 | { .bitrate = 480 }, | |
360 | { .bitrate = 540 } | |
361 | }; | |
362 | ||
bf164cc0 JK |
363 | /* RNDIS device private data */ |
364 | struct rndis_wext_private { | |
bf164cc0 JK |
365 | struct usbnet *usbdev; |
366 | ||
5c8fa4f7 JL |
367 | struct wireless_dev wdev; |
368 | ||
71a7b26d JK |
369 | struct cfg80211_scan_request *scan_request; |
370 | ||
bf164cc0 JK |
371 | struct workqueue_struct *workqueue; |
372 | struct delayed_work stats_work; | |
71a7b26d | 373 | struct delayed_work scan_work; |
bf164cc0 JK |
374 | struct work_struct work; |
375 | struct mutex command_lock; | |
376 | spinlock_t stats_lock; | |
377 | unsigned long work_pending; | |
378 | ||
5c8fa4f7 JL |
379 | struct ieee80211_supported_band band; |
380 | struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)]; | |
381 | struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)]; | |
382 | ||
bf164cc0 JK |
383 | struct iw_statistics iwstats; |
384 | struct iw_statistics privstats; | |
385 | ||
bf164cc0 JK |
386 | int caps; |
387 | int multicast_size; | |
388 | ||
389 | /* module parameters */ | |
390 | char param_country[4]; | |
391 | int param_frameburst; | |
392 | int param_afterburner; | |
393 | int param_power_save; | |
394 | int param_power_output; | |
395 | int param_roamtrigger; | |
396 | int param_roamdelta; | |
397 | u32 param_workaround_interval; | |
398 | ||
399 | /* hardware state */ | |
400 | int radio_on; | |
401 | int infra_mode; | |
1e41e1d2 | 402 | struct ndis_80211_ssid essid; |
bf164cc0 JK |
403 | |
404 | /* encryption stuff */ | |
405 | int encr_tx_key_index; | |
406 | char encr_keys[4][32]; | |
407 | int encr_key_len[4]; | |
408 | int wpa_version; | |
409 | int wpa_keymgmt; | |
410 | int wpa_authalg; | |
411 | int wpa_ie_len; | |
412 | u8 *wpa_ie; | |
413 | int wpa_cipher_pair; | |
414 | int wpa_cipher_group; | |
90d07349 JK |
415 | |
416 | u8 command_buffer[COMMAND_BUFFER_SIZE]; | |
bf164cc0 JK |
417 | }; |
418 | ||
964c1d41 JL |
419 | /* |
420 | * cfg80211 ops | |
421 | */ | |
422 | static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex, | |
423 | enum nl80211_iftype type, u32 *flags, | |
424 | struct vif_params *params); | |
425 | ||
71a7b26d JK |
426 | static int rndis_scan(struct wiphy *wiphy, struct net_device *dev, |
427 | struct cfg80211_scan_request *request); | |
428 | ||
caa6dfad | 429 | static struct cfg80211_ops rndis_config_ops = { |
964c1d41 | 430 | .change_virtual_intf = rndis_change_virtual_intf, |
71a7b26d | 431 | .scan = rndis_scan, |
964c1d41 | 432 | }; |
bf164cc0 | 433 | |
caa6dfad | 434 | static void *rndis_wiphy_privid = &rndis_wiphy_privid; |
bf164cc0 JK |
435 | |
436 | static const int bcm4320_power_output[4] = { 25, 50, 75, 100 }; | |
437 | ||
438 | static const unsigned char zero_bssid[ETH_ALEN] = {0,}; | |
439 | static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff, | |
440 | 0xff, 0xff, 0xff }; | |
441 | ||
442 | ||
443 | static struct rndis_wext_private *get_rndis_wext_priv(struct usbnet *dev) | |
444 | { | |
445 | return (struct rndis_wext_private *)dev->driver_priv; | |
446 | } | |
447 | ||
448 | ||
449 | static u32 get_bcm4320_power(struct rndis_wext_private *priv) | |
450 | { | |
451 | return BCM4320_DEFAULT_TXPOWER * | |
452 | bcm4320_power_output[priv->param_power_output] / 100; | |
453 | } | |
454 | ||
455 | ||
456 | /* translate error code */ | |
457 | static int rndis_error_status(__le32 rndis_status) | |
458 | { | |
459 | int ret = -EINVAL; | |
460 | switch (rndis_status) { | |
461 | case RNDIS_STATUS_SUCCESS: | |
462 | ret = 0; | |
463 | break; | |
464 | case RNDIS_STATUS_FAILURE: | |
465 | case RNDIS_STATUS_INVALID_DATA: | |
466 | ret = -EINVAL; | |
467 | break; | |
468 | case RNDIS_STATUS_NOT_SUPPORTED: | |
469 | ret = -EOPNOTSUPP; | |
470 | break; | |
471 | case RNDIS_STATUS_ADAPTER_NOT_READY: | |
472 | case RNDIS_STATUS_ADAPTER_NOT_OPEN: | |
473 | ret = -EBUSY; | |
474 | break; | |
475 | } | |
476 | return ret; | |
477 | } | |
478 | ||
479 | ||
480 | static int rndis_query_oid(struct usbnet *dev, __le32 oid, void *data, int *len) | |
481 | { | |
482 | struct rndis_wext_private *priv = get_rndis_wext_priv(dev); | |
483 | union { | |
484 | void *buf; | |
485 | struct rndis_msg_hdr *header; | |
486 | struct rndis_query *get; | |
487 | struct rndis_query_c *get_c; | |
488 | } u; | |
489 | int ret, buflen; | |
490 | ||
491 | buflen = *len + sizeof(*u.get); | |
492 | if (buflen < CONTROL_BUFFER_SIZE) | |
493 | buflen = CONTROL_BUFFER_SIZE; | |
90d07349 JK |
494 | |
495 | if (buflen > COMMAND_BUFFER_SIZE) { | |
496 | u.buf = kmalloc(buflen, GFP_KERNEL); | |
497 | if (!u.buf) | |
498 | return -ENOMEM; | |
499 | } else { | |
500 | u.buf = priv->command_buffer; | |
501 | } | |
502 | ||
503 | mutex_lock(&priv->command_lock); | |
504 | ||
bf164cc0 JK |
505 | memset(u.get, 0, sizeof *u.get); |
506 | u.get->msg_type = RNDIS_MSG_QUERY; | |
35c26c2c | 507 | u.get->msg_len = cpu_to_le32(sizeof *u.get); |
bf164cc0 JK |
508 | u.get->oid = oid; |
509 | ||
818727ba | 510 | ret = rndis_command(dev, u.header, buflen); |
bf164cc0 JK |
511 | if (ret == 0) { |
512 | ret = le32_to_cpu(u.get_c->len); | |
513 | *len = (*len > ret) ? ret : *len; | |
514 | memcpy(data, u.buf + le32_to_cpu(u.get_c->offset) + 8, *len); | |
515 | ret = rndis_error_status(u.get_c->status); | |
516 | } | |
517 | ||
90d07349 JK |
518 | mutex_unlock(&priv->command_lock); |
519 | ||
520 | if (u.buf != priv->command_buffer) | |
521 | kfree(u.buf); | |
bf164cc0 JK |
522 | return ret; |
523 | } | |
524 | ||
525 | ||
526 | static int rndis_set_oid(struct usbnet *dev, __le32 oid, void *data, int len) | |
527 | { | |
528 | struct rndis_wext_private *priv = get_rndis_wext_priv(dev); | |
529 | union { | |
530 | void *buf; | |
531 | struct rndis_msg_hdr *header; | |
532 | struct rndis_set *set; | |
533 | struct rndis_set_c *set_c; | |
534 | } u; | |
535 | int ret, buflen; | |
536 | ||
537 | buflen = len + sizeof(*u.set); | |
538 | if (buflen < CONTROL_BUFFER_SIZE) | |
539 | buflen = CONTROL_BUFFER_SIZE; | |
90d07349 JK |
540 | |
541 | if (buflen > COMMAND_BUFFER_SIZE) { | |
542 | u.buf = kmalloc(buflen, GFP_KERNEL); | |
543 | if (!u.buf) | |
544 | return -ENOMEM; | |
545 | } else { | |
546 | u.buf = priv->command_buffer; | |
547 | } | |
548 | ||
549 | mutex_lock(&priv->command_lock); | |
bf164cc0 JK |
550 | |
551 | memset(u.set, 0, sizeof *u.set); | |
552 | u.set->msg_type = RNDIS_MSG_SET; | |
553 | u.set->msg_len = cpu_to_le32(sizeof(*u.set) + len); | |
554 | u.set->oid = oid; | |
555 | u.set->len = cpu_to_le32(len); | |
35c26c2c HH |
556 | u.set->offset = cpu_to_le32(sizeof(*u.set) - 8); |
557 | u.set->handle = cpu_to_le32(0); | |
bf164cc0 JK |
558 | memcpy(u.buf + sizeof(*u.set), data, len); |
559 | ||
818727ba | 560 | ret = rndis_command(dev, u.header, buflen); |
bf164cc0 JK |
561 | if (ret == 0) |
562 | ret = rndis_error_status(u.set_c->status); | |
563 | ||
90d07349 JK |
564 | mutex_unlock(&priv->command_lock); |
565 | ||
566 | if (u.buf != priv->command_buffer) | |
567 | kfree(u.buf); | |
bf164cc0 JK |
568 | return ret; |
569 | } | |
570 | ||
571 | ||
572 | /* | |
573 | * Specs say that we can only set config parameters only soon after device | |
574 | * initialization. | |
575 | * value_type: 0 = u32, 2 = unicode string | |
576 | */ | |
577 | static int rndis_set_config_parameter(struct usbnet *dev, char *param, | |
578 | int value_type, void *value) | |
579 | { | |
1e41e1d2 | 580 | struct ndis_config_param *infobuf; |
bf164cc0 JK |
581 | int value_len, info_len, param_len, ret, i; |
582 | __le16 *unibuf; | |
583 | __le32 *dst_value; | |
584 | ||
585 | if (value_type == 0) | |
586 | value_len = sizeof(__le32); | |
587 | else if (value_type == 2) | |
588 | value_len = strlen(value) * sizeof(__le16); | |
589 | else | |
590 | return -EINVAL; | |
591 | ||
592 | param_len = strlen(param) * sizeof(__le16); | |
593 | info_len = sizeof(*infobuf) + param_len + value_len; | |
594 | ||
595 | #ifdef DEBUG | |
596 | info_len += 12; | |
597 | #endif | |
598 | infobuf = kmalloc(info_len, GFP_KERNEL); | |
599 | if (!infobuf) | |
600 | return -ENOMEM; | |
601 | ||
602 | #ifdef DEBUG | |
603 | info_len -= 12; | |
604 | /* extra 12 bytes are for padding (debug output) */ | |
605 | memset(infobuf, 0xCC, info_len + 12); | |
606 | #endif | |
607 | ||
608 | if (value_type == 2) | |
609 | devdbg(dev, "setting config parameter: %s, value: %s", | |
610 | param, (u8 *)value); | |
611 | else | |
612 | devdbg(dev, "setting config parameter: %s, value: %d", | |
613 | param, *(u32 *)value); | |
614 | ||
461b3f2a JK |
615 | infobuf->name_offs = cpu_to_le32(sizeof(*infobuf)); |
616 | infobuf->name_length = cpu_to_le32(param_len); | |
617 | infobuf->type = cpu_to_le32(value_type); | |
618 | infobuf->value_offs = cpu_to_le32(sizeof(*infobuf) + param_len); | |
619 | infobuf->value_length = cpu_to_le32(value_len); | |
bf164cc0 JK |
620 | |
621 | /* simple string to unicode string conversion */ | |
622 | unibuf = (void *)infobuf + sizeof(*infobuf); | |
623 | for (i = 0; i < param_len / sizeof(__le16); i++) | |
624 | unibuf[i] = cpu_to_le16(param[i]); | |
625 | ||
626 | if (value_type == 2) { | |
627 | unibuf = (void *)infobuf + sizeof(*infobuf) + param_len; | |
628 | for (i = 0; i < value_len / sizeof(__le16); i++) | |
629 | unibuf[i] = cpu_to_le16(((u8 *)value)[i]); | |
630 | } else { | |
631 | dst_value = (void *)infobuf + sizeof(*infobuf) + param_len; | |
632 | *dst_value = cpu_to_le32(*(u32 *)value); | |
633 | } | |
634 | ||
635 | #ifdef DEBUG | |
636 | devdbg(dev, "info buffer (len: %d):", info_len); | |
637 | for (i = 0; i < info_len; i += 12) { | |
638 | u32 *tmp = (u32 *)((u8 *)infobuf + i); | |
639 | devdbg(dev, "%08X:%08X:%08X", | |
640 | cpu_to_be32(tmp[0]), | |
641 | cpu_to_be32(tmp[1]), | |
642 | cpu_to_be32(tmp[2])); | |
643 | } | |
644 | #endif | |
645 | ||
646 | ret = rndis_set_oid(dev, OID_GEN_RNDIS_CONFIG_PARAMETER, | |
647 | infobuf, info_len); | |
648 | if (ret != 0) | |
649 | devdbg(dev, "setting rndis config paramater failed, %d.", ret); | |
650 | ||
651 | kfree(infobuf); | |
652 | return ret; | |
653 | } | |
654 | ||
655 | static int rndis_set_config_parameter_str(struct usbnet *dev, | |
656 | char *param, char *value) | |
657 | { | |
658 | return(rndis_set_config_parameter(dev, param, 2, value)); | |
659 | } | |
660 | ||
661 | /*static int rndis_set_config_parameter_u32(struct usbnet *dev, | |
662 | char *param, u32 value) | |
663 | { | |
664 | return(rndis_set_config_parameter(dev, param, 0, &value)); | |
665 | }*/ | |
666 | ||
667 | ||
668 | /* | |
669 | * data conversion functions | |
670 | */ | |
671 | static int level_to_qual(int level) | |
672 | { | |
673 | int qual = 100 * (level - WL_NOISE) / (WL_SIGMAX - WL_NOISE); | |
674 | return qual >= 0 ? (qual <= 100 ? qual : 100) : 0; | |
675 | } | |
676 | ||
677 | ||
678 | static void dsconfig_to_freq(unsigned int dsconfig, struct iw_freq *freq) | |
679 | { | |
680 | freq->e = 0; | |
681 | freq->i = 0; | |
682 | freq->flags = 0; | |
683 | ||
684 | /* see comment in wireless.h above the "struct iw_freq" | |
685 | * definition for an explanation of this if | |
686 | * NOTE: 1000000 is due to the kHz | |
687 | */ | |
688 | if (dsconfig > 1000000) { | |
689 | freq->m = dsconfig / 10; | |
690 | freq->e = 1; | |
691 | } else | |
692 | freq->m = dsconfig; | |
693 | ||
694 | /* convert from kHz to Hz */ | |
695 | freq->e += 3; | |
696 | } | |
697 | ||
698 | ||
699 | static int freq_to_dsconfig(struct iw_freq *freq, unsigned int *dsconfig) | |
700 | { | |
701 | if (freq->m < 1000 && freq->e == 0) { | |
9ee677c2 DK |
702 | if (freq->m >= 1 && freq->m <= 14) |
703 | *dsconfig = ieee80211_dsss_chan_to_freq(freq->m) * 1000; | |
bf164cc0 JK |
704 | else |
705 | return -1; | |
706 | } else { | |
707 | int i; | |
708 | *dsconfig = freq->m; | |
709 | for (i = freq->e; i > 0; i--) | |
710 | *dsconfig *= 10; | |
711 | *dsconfig /= 1000; | |
712 | } | |
713 | ||
714 | return 0; | |
715 | } | |
716 | ||
717 | ||
718 | /* | |
719 | * common functions | |
720 | */ | |
721 | static int | |
722 | add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index); | |
723 | ||
1e41e1d2 | 724 | static int get_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid) |
bf164cc0 JK |
725 | { |
726 | int ret, len; | |
727 | ||
728 | len = sizeof(*ssid); | |
729 | ret = rndis_query_oid(usbdev, OID_802_11_SSID, ssid, &len); | |
730 | ||
731 | if (ret != 0) | |
461b3f2a | 732 | ssid->length = 0; |
bf164cc0 JK |
733 | |
734 | #ifdef DEBUG | |
735 | { | |
736 | unsigned char tmp[NDIS_802_11_LENGTH_SSID + 1]; | |
737 | ||
461b3f2a JK |
738 | memcpy(tmp, ssid->essid, le32_to_cpu(ssid->length)); |
739 | tmp[le32_to_cpu(ssid->length)] = 0; | |
bf164cc0 JK |
740 | devdbg(usbdev, "get_essid: '%s', ret: %d", tmp, ret); |
741 | } | |
742 | #endif | |
743 | return ret; | |
744 | } | |
745 | ||
746 | ||
1e41e1d2 | 747 | static int set_essid(struct usbnet *usbdev, struct ndis_80211_ssid *ssid) |
bf164cc0 JK |
748 | { |
749 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
750 | int ret; | |
751 | ||
752 | ret = rndis_set_oid(usbdev, OID_802_11_SSID, ssid, sizeof(*ssid)); | |
753 | if (ret == 0) { | |
754 | memcpy(&priv->essid, ssid, sizeof(priv->essid)); | |
755 | priv->radio_on = 1; | |
756 | devdbg(usbdev, "set_essid: radio_on = 1"); | |
757 | } | |
758 | ||
759 | return ret; | |
760 | } | |
761 | ||
762 | ||
763 | static int get_bssid(struct usbnet *usbdev, u8 bssid[ETH_ALEN]) | |
764 | { | |
765 | int ret, len; | |
766 | ||
767 | len = ETH_ALEN; | |
768 | ret = rndis_query_oid(usbdev, OID_802_11_BSSID, bssid, &len); | |
769 | ||
770 | if (ret != 0) | |
771 | memset(bssid, 0, ETH_ALEN); | |
772 | ||
773 | return ret; | |
774 | } | |
775 | ||
4364623c SA |
776 | static int get_association_info(struct usbnet *usbdev, |
777 | struct ndis_80211_assoc_info *info, int len) | |
778 | { | |
779 | return rndis_query_oid(usbdev, OID_802_11_ASSOCIATION_INFORMATION, | |
780 | info, &len); | |
781 | } | |
bf164cc0 JK |
782 | |
783 | static int is_associated(struct usbnet *usbdev) | |
784 | { | |
785 | u8 bssid[ETH_ALEN]; | |
786 | int ret; | |
787 | ||
788 | ret = get_bssid(usbdev, bssid); | |
789 | ||
790 | return(ret == 0 && memcmp(bssid, zero_bssid, ETH_ALEN) != 0); | |
791 | } | |
792 | ||
793 | ||
794 | static int disassociate(struct usbnet *usbdev, int reset_ssid) | |
795 | { | |
796 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
1e41e1d2 | 797 | struct ndis_80211_ssid ssid; |
bf164cc0 JK |
798 | int i, ret = 0; |
799 | ||
800 | if (priv->radio_on) { | |
801 | ret = rndis_set_oid(usbdev, OID_802_11_DISASSOCIATE, NULL, 0); | |
802 | if (ret == 0) { | |
803 | priv->radio_on = 0; | |
804 | devdbg(usbdev, "disassociate: radio_on = 0"); | |
805 | ||
806 | if (reset_ssid) | |
807 | msleep(100); | |
808 | } | |
809 | } | |
810 | ||
811 | /* disassociate causes radio to be turned off; if reset_ssid | |
812 | * is given, set random ssid to enable radio */ | |
813 | if (reset_ssid) { | |
461b3f2a JK |
814 | ssid.length = cpu_to_le32(sizeof(ssid.essid)); |
815 | get_random_bytes(&ssid.essid[2], sizeof(ssid.essid)-2); | |
816 | ssid.essid[0] = 0x1; | |
817 | ssid.essid[1] = 0xff; | |
818 | for (i = 2; i < sizeof(ssid.essid); i++) | |
819 | ssid.essid[i] = 0x1 + (ssid.essid[i] * 0xfe / 0xff); | |
bf164cc0 JK |
820 | ret = set_essid(usbdev, &ssid); |
821 | } | |
822 | return ret; | |
823 | } | |
824 | ||
825 | ||
826 | static int set_auth_mode(struct usbnet *usbdev, int wpa_version, int authalg) | |
827 | { | |
828 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
829 | __le32 tmp; | |
830 | int auth_mode, ret; | |
831 | ||
832 | devdbg(usbdev, "set_auth_mode: wpa_version=0x%x authalg=0x%x " | |
833 | "keymgmt=0x%x", wpa_version, authalg, priv->wpa_keymgmt); | |
834 | ||
835 | if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) { | |
836 | if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X) | |
1e41e1d2 | 837 | auth_mode = ndis_80211_auth_wpa2; |
bf164cc0 | 838 | else |
1e41e1d2 | 839 | auth_mode = ndis_80211_auth_wpa2_psk; |
bf164cc0 JK |
840 | } else if (wpa_version & IW_AUTH_WPA_VERSION_WPA) { |
841 | if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_802_1X) | |
1e41e1d2 | 842 | auth_mode = ndis_80211_auth_wpa; |
bf164cc0 | 843 | else if (priv->wpa_keymgmt & IW_AUTH_KEY_MGMT_PSK) |
1e41e1d2 | 844 | auth_mode = ndis_80211_auth_wpa_psk; |
bf164cc0 | 845 | else |
1e41e1d2 | 846 | auth_mode = ndis_80211_auth_wpa_none; |
bf164cc0 JK |
847 | } else if (authalg & IW_AUTH_ALG_SHARED_KEY) { |
848 | if (authalg & IW_AUTH_ALG_OPEN_SYSTEM) | |
1e41e1d2 | 849 | auth_mode = ndis_80211_auth_auto_switch; |
bf164cc0 | 850 | else |
1e41e1d2 | 851 | auth_mode = ndis_80211_auth_shared; |
bf164cc0 | 852 | } else |
1e41e1d2 | 853 | auth_mode = ndis_80211_auth_open; |
bf164cc0 JK |
854 | |
855 | tmp = cpu_to_le32(auth_mode); | |
856 | ret = rndis_set_oid(usbdev, OID_802_11_AUTHENTICATION_MODE, &tmp, | |
857 | sizeof(tmp)); | |
858 | if (ret != 0) { | |
859 | devwarn(usbdev, "setting auth mode failed (%08X)", ret); | |
860 | return ret; | |
861 | } | |
862 | ||
863 | priv->wpa_version = wpa_version; | |
864 | priv->wpa_authalg = authalg; | |
865 | return 0; | |
866 | } | |
867 | ||
868 | ||
869 | static int set_priv_filter(struct usbnet *usbdev) | |
870 | { | |
871 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
872 | __le32 tmp; | |
873 | ||
874 | devdbg(usbdev, "set_priv_filter: wpa_version=0x%x", priv->wpa_version); | |
875 | ||
876 | if (priv->wpa_version & IW_AUTH_WPA_VERSION_WPA2 || | |
877 | priv->wpa_version & IW_AUTH_WPA_VERSION_WPA) | |
1e41e1d2 | 878 | tmp = cpu_to_le32(ndis_80211_priv_8021x_wep); |
bf164cc0 | 879 | else |
1e41e1d2 | 880 | tmp = cpu_to_le32(ndis_80211_priv_accept_all); |
bf164cc0 JK |
881 | |
882 | return rndis_set_oid(usbdev, OID_802_11_PRIVACY_FILTER, &tmp, | |
883 | sizeof(tmp)); | |
884 | } | |
885 | ||
886 | ||
887 | static int set_encr_mode(struct usbnet *usbdev, int pairwise, int groupwise) | |
888 | { | |
889 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
890 | __le32 tmp; | |
891 | int encr_mode, ret; | |
892 | ||
893 | devdbg(usbdev, "set_encr_mode: cipher_pair=0x%x cipher_group=0x%x", | |
894 | pairwise, | |
895 | groupwise); | |
896 | ||
897 | if (pairwise & IW_AUTH_CIPHER_CCMP) | |
1e41e1d2 | 898 | encr_mode = ndis_80211_encr_ccmp_enabled; |
bf164cc0 | 899 | else if (pairwise & IW_AUTH_CIPHER_TKIP) |
1e41e1d2 | 900 | encr_mode = ndis_80211_encr_tkip_enabled; |
bf164cc0 JK |
901 | else if (pairwise & |
902 | (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104)) | |
1e41e1d2 | 903 | encr_mode = ndis_80211_encr_wep_enabled; |
bf164cc0 | 904 | else if (groupwise & IW_AUTH_CIPHER_CCMP) |
1e41e1d2 | 905 | encr_mode = ndis_80211_encr_ccmp_enabled; |
bf164cc0 | 906 | else if (groupwise & IW_AUTH_CIPHER_TKIP) |
1e41e1d2 | 907 | encr_mode = ndis_80211_encr_tkip_enabled; |
bf164cc0 | 908 | else |
1e41e1d2 | 909 | encr_mode = ndis_80211_encr_disabled; |
bf164cc0 JK |
910 | |
911 | tmp = cpu_to_le32(encr_mode); | |
912 | ret = rndis_set_oid(usbdev, OID_802_11_ENCRYPTION_STATUS, &tmp, | |
913 | sizeof(tmp)); | |
914 | if (ret != 0) { | |
915 | devwarn(usbdev, "setting encr mode failed (%08X)", ret); | |
916 | return ret; | |
917 | } | |
918 | ||
919 | priv->wpa_cipher_pair = pairwise; | |
920 | priv->wpa_cipher_group = groupwise; | |
921 | return 0; | |
922 | } | |
923 | ||
924 | ||
925 | static int set_assoc_params(struct usbnet *usbdev) | |
926 | { | |
927 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
928 | ||
929 | set_auth_mode(usbdev, priv->wpa_version, priv->wpa_authalg); | |
930 | set_priv_filter(usbdev); | |
931 | set_encr_mode(usbdev, priv->wpa_cipher_pair, priv->wpa_cipher_group); | |
932 | ||
933 | return 0; | |
934 | } | |
935 | ||
936 | ||
937 | static int set_infra_mode(struct usbnet *usbdev, int mode) | |
938 | { | |
939 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
940 | __le32 tmp; | |
941 | int ret, i; | |
942 | ||
943 | devdbg(usbdev, "set_infra_mode: infra_mode=0x%x", priv->infra_mode); | |
944 | ||
945 | tmp = cpu_to_le32(mode); | |
946 | ret = rndis_set_oid(usbdev, OID_802_11_INFRASTRUCTURE_MODE, &tmp, | |
947 | sizeof(tmp)); | |
948 | if (ret != 0) { | |
949 | devwarn(usbdev, "setting infra mode failed (%08X)", ret); | |
950 | return ret; | |
951 | } | |
952 | ||
953 | /* NDIS drivers clear keys when infrastructure mode is | |
954 | * changed. But Linux tools assume otherwise. So set the | |
955 | * keys */ | |
956 | if (priv->wpa_keymgmt == 0 || | |
957 | priv->wpa_keymgmt == IW_AUTH_KEY_MGMT_802_1X) { | |
958 | for (i = 0; i < 4; i++) { | |
959 | if (priv->encr_key_len[i] > 0) | |
960 | add_wep_key(usbdev, priv->encr_keys[i], | |
961 | priv->encr_key_len[i], i); | |
962 | } | |
963 | } | |
964 | ||
965 | priv->infra_mode = mode; | |
966 | return 0; | |
967 | } | |
968 | ||
969 | ||
970 | static void set_default_iw_params(struct usbnet *usbdev) | |
971 | { | |
972 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
973 | ||
974 | priv->wpa_keymgmt = 0; | |
975 | priv->wpa_version = 0; | |
976 | ||
1e41e1d2 | 977 | set_infra_mode(usbdev, ndis_80211_infra_infra); |
bf164cc0 JK |
978 | set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED, |
979 | IW_AUTH_ALG_OPEN_SYSTEM); | |
980 | set_priv_filter(usbdev); | |
981 | set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE); | |
982 | } | |
983 | ||
984 | ||
985 | static int deauthenticate(struct usbnet *usbdev) | |
986 | { | |
987 | int ret; | |
988 | ||
989 | ret = disassociate(usbdev, 1); | |
990 | set_default_iw_params(usbdev); | |
991 | return ret; | |
992 | } | |
993 | ||
994 | ||
995 | /* index must be 0 - N, as per NDIS */ | |
996 | static int add_wep_key(struct usbnet *usbdev, char *key, int key_len, int index) | |
997 | { | |
998 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
1e41e1d2 | 999 | struct ndis_80211_wep_key ndis_key; |
bf164cc0 JK |
1000 | int ret; |
1001 | ||
1002 | if (key_len <= 0 || key_len > 32 || index < 0 || index >= 4) | |
1003 | return -EINVAL; | |
1004 | ||
1005 | memset(&ndis_key, 0, sizeof(ndis_key)); | |
1006 | ||
461b3f2a JK |
1007 | ndis_key.size = cpu_to_le32(sizeof(ndis_key)); |
1008 | ndis_key.length = cpu_to_le32(key_len); | |
1009 | ndis_key.index = cpu_to_le32(index); | |
1010 | memcpy(&ndis_key.material, key, key_len); | |
bf164cc0 JK |
1011 | |
1012 | if (index == priv->encr_tx_key_index) { | |
b4703a2e | 1013 | ndis_key.index |= ndis_80211_addwep_transmit_key; |
bf164cc0 JK |
1014 | ret = set_encr_mode(usbdev, IW_AUTH_CIPHER_WEP104, |
1015 | IW_AUTH_CIPHER_NONE); | |
1016 | if (ret) | |
1017 | devwarn(usbdev, "encryption couldn't be enabled (%08X)", | |
1018 | ret); | |
1019 | } | |
1020 | ||
1021 | ret = rndis_set_oid(usbdev, OID_802_11_ADD_WEP, &ndis_key, | |
1022 | sizeof(ndis_key)); | |
1023 | if (ret != 0) { | |
1024 | devwarn(usbdev, "adding encryption key %d failed (%08X)", | |
1025 | index+1, ret); | |
1026 | return ret; | |
1027 | } | |
1028 | ||
1029 | priv->encr_key_len[index] = key_len; | |
1030 | memcpy(&priv->encr_keys[index], key, key_len); | |
1031 | ||
1032 | return 0; | |
1033 | } | |
1034 | ||
1035 | ||
1036 | /* remove_key is for both wep and wpa */ | |
1037 | static int remove_key(struct usbnet *usbdev, int index, u8 bssid[ETH_ALEN]) | |
1038 | { | |
1039 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
1e41e1d2 | 1040 | struct ndis_80211_remove_key remove_key; |
bf164cc0 JK |
1041 | __le32 keyindex; |
1042 | int ret; | |
1043 | ||
1044 | if (priv->encr_key_len[index] == 0) | |
1045 | return 0; | |
1046 | ||
1047 | priv->encr_key_len[index] = 0; | |
1048 | memset(&priv->encr_keys[index], 0, sizeof(priv->encr_keys[index])); | |
1049 | ||
1050 | if (priv->wpa_cipher_pair == IW_AUTH_CIPHER_TKIP || | |
1051 | priv->wpa_cipher_pair == IW_AUTH_CIPHER_CCMP || | |
1052 | priv->wpa_cipher_group == IW_AUTH_CIPHER_TKIP || | |
1053 | priv->wpa_cipher_group == IW_AUTH_CIPHER_CCMP) { | |
461b3f2a JK |
1054 | remove_key.size = cpu_to_le32(sizeof(remove_key)); |
1055 | remove_key.index = cpu_to_le32(index); | |
bf164cc0 JK |
1056 | if (bssid) { |
1057 | /* pairwise key */ | |
1058 | if (memcmp(bssid, ffff_bssid, ETH_ALEN) != 0) | |
b4703a2e JK |
1059 | remove_key.index |= |
1060 | ndis_80211_addkey_pairwise_key; | |
461b3f2a JK |
1061 | memcpy(remove_key.bssid, bssid, |
1062 | sizeof(remove_key.bssid)); | |
bf164cc0 | 1063 | } else |
461b3f2a JK |
1064 | memset(remove_key.bssid, 0xff, |
1065 | sizeof(remove_key.bssid)); | |
bf164cc0 JK |
1066 | |
1067 | ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_KEY, &remove_key, | |
1068 | sizeof(remove_key)); | |
1069 | if (ret != 0) | |
1070 | return ret; | |
1071 | } else { | |
1072 | keyindex = cpu_to_le32(index); | |
1073 | ret = rndis_set_oid(usbdev, OID_802_11_REMOVE_WEP, &keyindex, | |
1074 | sizeof(keyindex)); | |
1075 | if (ret != 0) { | |
1076 | devwarn(usbdev, | |
1077 | "removing encryption key %d failed (%08X)", | |
1078 | index, ret); | |
1079 | return ret; | |
1080 | } | |
1081 | } | |
1082 | ||
1083 | /* if it is transmit key, disable encryption */ | |
1084 | if (index == priv->encr_tx_key_index) | |
1085 | set_encr_mode(usbdev, IW_AUTH_CIPHER_NONE, IW_AUTH_CIPHER_NONE); | |
1086 | ||
1087 | return 0; | |
1088 | } | |
1089 | ||
1090 | ||
1091 | static void set_multicast_list(struct usbnet *usbdev) | |
1092 | { | |
1093 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
1094 | struct dev_mc_list *mclist; | |
1095 | __le32 filter; | |
1096 | int ret, i, size; | |
1097 | char *buf; | |
1098 | ||
1099 | filter = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST; | |
1100 | ||
1101 | if (usbdev->net->flags & IFF_PROMISC) { | |
1102 | filter |= RNDIS_PACKET_TYPE_PROMISCUOUS | | |
1103 | RNDIS_PACKET_TYPE_ALL_LOCAL; | |
1104 | } else if (usbdev->net->flags & IFF_ALLMULTI || | |
1105 | usbdev->net->mc_count > priv->multicast_size) { | |
1106 | filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST; | |
1107 | } else if (usbdev->net->mc_count > 0) { | |
1108 | size = min(priv->multicast_size, usbdev->net->mc_count); | |
1109 | buf = kmalloc(size * ETH_ALEN, GFP_KERNEL); | |
1110 | if (!buf) { | |
1111 | devwarn(usbdev, | |
1112 | "couldn't alloc %d bytes of memory", | |
1113 | size * ETH_ALEN); | |
1114 | return; | |
1115 | } | |
1116 | ||
1117 | mclist = usbdev->net->mc_list; | |
1118 | for (i = 0; i < size && mclist; mclist = mclist->next) { | |
1119 | if (mclist->dmi_addrlen != ETH_ALEN) | |
1120 | continue; | |
1121 | ||
1122 | memcpy(buf + i * ETH_ALEN, mclist->dmi_addr, ETH_ALEN); | |
1123 | i++; | |
1124 | } | |
1125 | ||
1126 | ret = rndis_set_oid(usbdev, OID_802_3_MULTICAST_LIST, buf, | |
1127 | i * ETH_ALEN); | |
1128 | if (ret == 0 && i > 0) | |
1129 | filter |= RNDIS_PACKET_TYPE_MULTICAST; | |
1130 | else | |
1131 | filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST; | |
1132 | ||
1133 | devdbg(usbdev, "OID_802_3_MULTICAST_LIST(%d, max: %d) -> %d", | |
1134 | i, priv->multicast_size, ret); | |
1135 | ||
1136 | kfree(buf); | |
1137 | } | |
1138 | ||
1139 | ret = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &filter, | |
1140 | sizeof(filter)); | |
1141 | if (ret < 0) { | |
1142 | devwarn(usbdev, "couldn't set packet filter: %08x", | |
1143 | le32_to_cpu(filter)); | |
1144 | } | |
1145 | ||
1146 | devdbg(usbdev, "OID_GEN_CURRENT_PACKET_FILTER(%08x) -> %d", | |
1147 | le32_to_cpu(filter), ret); | |
1148 | } | |
1149 | ||
1150 | ||
964c1d41 JL |
1151 | /* |
1152 | * cfg80211 ops | |
1153 | */ | |
1154 | static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex, | |
1155 | enum nl80211_iftype type, u32 *flags, | |
1156 | struct vif_params *params) | |
1157 | { | |
1158 | struct net_device *dev; | |
1159 | struct usbnet *usbdev; | |
1160 | int mode; | |
1161 | ||
1162 | /* we're under RTNL */ | |
1163 | dev = __dev_get_by_index(&init_net, ifindex); | |
1164 | if (!dev) | |
1165 | return -ENODEV; | |
1166 | usbdev = netdev_priv(dev); | |
1167 | ||
1168 | switch (type) { | |
1169 | case NL80211_IFTYPE_ADHOC: | |
1170 | mode = ndis_80211_infra_adhoc; | |
1171 | break; | |
1172 | case NL80211_IFTYPE_STATION: | |
1173 | mode = ndis_80211_infra_infra; | |
1174 | break; | |
1175 | default: | |
1176 | return -EINVAL; | |
1177 | } | |
1178 | ||
1179 | return set_infra_mode(usbdev, mode); | |
1180 | } | |
1181 | ||
71a7b26d JK |
1182 | |
1183 | #define SCAN_DELAY_JIFFIES (HZ) | |
1184 | static int rndis_scan(struct wiphy *wiphy, struct net_device *dev, | |
1185 | struct cfg80211_scan_request *request) | |
1186 | { | |
1187 | struct usbnet *usbdev = netdev_priv(dev); | |
1188 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
1189 | int ret; | |
1190 | __le32 tmp; | |
1191 | ||
1192 | devdbg(usbdev, "cfg80211.scan"); | |
1193 | ||
1194 | if (!request) | |
1195 | return -EINVAL; | |
1196 | ||
1197 | if (priv->scan_request && priv->scan_request != request) | |
1198 | return -EBUSY; | |
1199 | ||
1200 | priv->scan_request = request; | |
1201 | ||
1202 | tmp = cpu_to_le32(1); | |
1203 | ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp, | |
1204 | sizeof(tmp)); | |
1205 | if (ret == 0) { | |
1206 | /* Wait before retrieving scan results from device */ | |
1207 | queue_delayed_work(priv->workqueue, &priv->scan_work, | |
1208 | SCAN_DELAY_JIFFIES); | |
1209 | } | |
1210 | ||
1211 | return ret; | |
1212 | } | |
1213 | ||
1214 | ||
1215 | static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev, | |
1216 | struct ndis_80211_bssid_ex *bssid) | |
1217 | { | |
1218 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); | |
1219 | struct ieee80211_channel *channel; | |
1220 | s32 signal; | |
1221 | u64 timestamp; | |
1222 | u16 capability; | |
1223 | u16 beacon_interval; | |
1224 | struct ndis_80211_fixed_ies *fixed; | |
1225 | int ie_len, bssid_len; | |
1226 | u8 *ie; | |
1227 | ||
1228 | /* parse bssid structure */ | |
1229 | bssid_len = le32_to_cpu(bssid->length); | |
1230 | ||
1231 | if (bssid_len < sizeof(struct ndis_80211_bssid_ex) + | |
1232 | sizeof(struct ndis_80211_fixed_ies)) | |
1233 | return NULL; | |
1234 | ||
1235 | fixed = (struct ndis_80211_fixed_ies *)bssid->ies; | |
1236 | ||
1237 | ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies)); | |
1238 | ie_len = min(bssid_len - (int)sizeof(*bssid), | |
1239 | (int)le32_to_cpu(bssid->ie_length)); | |
1240 | ie_len -= sizeof(struct ndis_80211_fixed_ies); | |
1241 | if (ie_len < 0) | |
1242 | return NULL; | |
1243 | ||
1244 | /* extract data for cfg80211_inform_bss */ | |
1245 | channel = ieee80211_get_channel(priv->wdev.wiphy, | |
1246 | KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config))); | |
1247 | if (!channel) | |
1248 | return NULL; | |
1249 | ||
1250 | signal = level_to_qual(le32_to_cpu(bssid->rssi)); | |
1251 | timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp); | |
1252 | capability = le16_to_cpu(fixed->capabilities); | |
1253 | beacon_interval = le16_to_cpu(fixed->beacon_interval); | |
1254 | ||
1255 | return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac, | |
1256 | timestamp, capability, beacon_interval, ie, ie_len, signal, | |
1257 | GFP_KERNEL); | |
1258 | } | |
1259 | ||
1260 | ||
1261 | static int rndis_check_bssid_list(struct usbnet *usbdev) | |
1262 | { | |
1263 | void *buf = NULL; | |
1264 | struct ndis_80211_bssid_list_ex *bssid_list; | |
1265 | struct ndis_80211_bssid_ex *bssid; | |
1266 | int ret = -EINVAL, len, count, bssid_len; | |
1267 | ||
1268 | devdbg(usbdev, "check_bssid_list"); | |
1269 | ||
1270 | len = CONTROL_BUFFER_SIZE; | |
1271 | buf = kmalloc(len, GFP_KERNEL); | |
1272 | if (!buf) { | |
1273 | ret = -ENOMEM; | |
1274 | goto out; | |
1275 | } | |
1276 | ||
1277 | ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len); | |
1278 | if (ret != 0) | |
1279 | goto out; | |
1280 | ||
1281 | bssid_list = buf; | |
1282 | bssid = bssid_list->bssid; | |
1283 | bssid_len = le32_to_cpu(bssid->length); | |
1284 | count = le32_to_cpu(bssid_list->num_items); | |
1285 | devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count); | |
1286 | ||
1287 | while (count && ((void *)bssid + bssid_len) <= (buf + len)) { | |
1288 | rndis_bss_info_update(usbdev, bssid); | |
1289 | ||
1290 | bssid = (void *)bssid + bssid_len; | |
1291 | bssid_len = le32_to_cpu(bssid->length); | |
1292 | count--; | |
1293 | } | |
1294 | ||
1295 | out: | |
1296 | kfree(buf); | |
1297 | return ret; | |
1298 | } | |
1299 | ||
1300 | ||
1301 | static void rndis_get_scan_results(struct work_struct *work) | |
1302 | { | |
1303 | struct rndis_wext_private *priv = | |
1304 | container_of(work, struct rndis_wext_private, scan_work.work); | |
1305 | struct usbnet *usbdev = priv->usbdev; | |
1306 | int ret; | |
1307 | ||
1308 | devdbg(usbdev, "get_scan_results"); | |
1309 | ||
1310 | ret = rndis_check_bssid_list(usbdev); | |
1311 | ||
1312 | cfg80211_scan_done(priv->scan_request, ret < 0); | |
1313 | ||
1314 | priv->scan_request = NULL; | |
1315 | } | |
1316 | ||
1317 | ||
bf164cc0 JK |
1318 | /* |
1319 | * wireless extension handlers | |
1320 | */ | |
1321 | ||
1322 | static int rndis_iw_commit(struct net_device *dev, | |
1323 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1324 | { | |
1325 | /* dummy op */ | |
1326 | return 0; | |
1327 | } | |
1328 | ||
1329 | ||
bf164cc0 JK |
1330 | static int rndis_iw_set_essid(struct net_device *dev, |
1331 | struct iw_request_info *info, union iwreq_data *wrqu, char *essid) | |
1332 | { | |
1e41e1d2 | 1333 | struct ndis_80211_ssid ssid; |
bf164cc0 | 1334 | int length = wrqu->essid.length; |
524ad0a7 | 1335 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1336 | |
1337 | devdbg(usbdev, "SIOCSIWESSID: [flags:%d,len:%d] '%.32s'", | |
1338 | wrqu->essid.flags, wrqu->essid.length, essid); | |
1339 | ||
1340 | if (length > NDIS_802_11_LENGTH_SSID) | |
1341 | length = NDIS_802_11_LENGTH_SSID; | |
1342 | ||
461b3f2a | 1343 | ssid.length = cpu_to_le32(length); |
bf164cc0 | 1344 | if (length > 0) |
461b3f2a | 1345 | memcpy(ssid.essid, essid, length); |
bf164cc0 | 1346 | else |
461b3f2a | 1347 | memset(ssid.essid, 0, NDIS_802_11_LENGTH_SSID); |
bf164cc0 JK |
1348 | |
1349 | set_assoc_params(usbdev); | |
1350 | ||
1351 | if (!wrqu->essid.flags || length == 0) | |
1352 | return disassociate(usbdev, 1); | |
1353 | else | |
1354 | return set_essid(usbdev, &ssid); | |
1355 | } | |
1356 | ||
1357 | ||
1358 | static int rndis_iw_get_essid(struct net_device *dev, | |
1359 | struct iw_request_info *info, union iwreq_data *wrqu, char *essid) | |
1360 | { | |
1e41e1d2 | 1361 | struct ndis_80211_ssid ssid; |
524ad0a7 | 1362 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1363 | int ret; |
1364 | ||
1365 | ret = get_essid(usbdev, &ssid); | |
1366 | ||
461b3f2a | 1367 | if (ret == 0 && le32_to_cpu(ssid.length) > 0) { |
bf164cc0 | 1368 | wrqu->essid.flags = 1; |
461b3f2a JK |
1369 | wrqu->essid.length = le32_to_cpu(ssid.length); |
1370 | memcpy(essid, ssid.essid, wrqu->essid.length); | |
bf164cc0 JK |
1371 | essid[wrqu->essid.length] = 0; |
1372 | } else { | |
1373 | memset(essid, 0, sizeof(NDIS_802_11_LENGTH_SSID)); | |
1374 | wrqu->essid.flags = 0; | |
1375 | wrqu->essid.length = 0; | |
1376 | } | |
1377 | devdbg(usbdev, "SIOCGIWESSID: %s", essid); | |
1378 | return ret; | |
1379 | } | |
1380 | ||
1381 | ||
1382 | static int rndis_iw_get_bssid(struct net_device *dev, | |
1383 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1384 | { | |
524ad0a7 | 1385 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1386 | unsigned char bssid[ETH_ALEN]; |
1387 | int ret; | |
bf164cc0 JK |
1388 | |
1389 | ret = get_bssid(usbdev, bssid); | |
1390 | ||
1391 | if (ret == 0) | |
e174961c | 1392 | devdbg(usbdev, "SIOCGIWAP: %pM", bssid); |
bf164cc0 JK |
1393 | else |
1394 | devdbg(usbdev, "SIOCGIWAP: <not associated>"); | |
1395 | ||
1396 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | |
1397 | memcpy(wrqu->ap_addr.sa_data, bssid, ETH_ALEN); | |
1398 | ||
1399 | return ret; | |
1400 | } | |
1401 | ||
1402 | ||
1403 | static int rndis_iw_set_bssid(struct net_device *dev, | |
1404 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1405 | { | |
524ad0a7 | 1406 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 | 1407 | u8 *bssid = (u8 *)wrqu->ap_addr.sa_data; |
bf164cc0 JK |
1408 | int ret; |
1409 | ||
e174961c | 1410 | devdbg(usbdev, "SIOCSIWAP: %pM", bssid); |
bf164cc0 JK |
1411 | |
1412 | ret = rndis_set_oid(usbdev, OID_802_11_BSSID, bssid, ETH_ALEN); | |
1413 | ||
1414 | /* user apps may set ap's mac address, which is not required; | |
1415 | * they may fail to work if this function fails, so return | |
1416 | * success */ | |
1417 | if (ret) | |
1418 | devwarn(usbdev, "setting AP mac address failed (%08X)", ret); | |
1419 | ||
1420 | return 0; | |
1421 | } | |
1422 | ||
1423 | ||
1424 | static int rndis_iw_set_auth(struct net_device *dev, | |
1425 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1426 | { | |
1427 | struct iw_param *p = &wrqu->param; | |
524ad0a7 | 1428 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1429 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1430 | int ret = -ENOTSUPP; | |
1431 | ||
1432 | switch (p->flags & IW_AUTH_INDEX) { | |
1433 | case IW_AUTH_WPA_VERSION: | |
1434 | devdbg(usbdev, "SIOCSIWAUTH: WPA_VERSION, %08x", p->value); | |
1435 | priv->wpa_version = p->value; | |
1436 | ret = 0; | |
1437 | break; | |
1438 | ||
1439 | case IW_AUTH_CIPHER_PAIRWISE: | |
1440 | devdbg(usbdev, "SIOCSIWAUTH: CIPHER_PAIRWISE, %08x", p->value); | |
1441 | priv->wpa_cipher_pair = p->value; | |
1442 | ret = 0; | |
1443 | break; | |
1444 | ||
1445 | case IW_AUTH_CIPHER_GROUP: | |
1446 | devdbg(usbdev, "SIOCSIWAUTH: CIPHER_GROUP, %08x", p->value); | |
1447 | priv->wpa_cipher_group = p->value; | |
1448 | ret = 0; | |
1449 | break; | |
1450 | ||
1451 | case IW_AUTH_KEY_MGMT: | |
1452 | devdbg(usbdev, "SIOCSIWAUTH: KEY_MGMT, %08x", p->value); | |
1453 | priv->wpa_keymgmt = p->value; | |
1454 | ret = 0; | |
1455 | break; | |
1456 | ||
1457 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
1458 | devdbg(usbdev, "SIOCSIWAUTH: TKIP_COUNTERMEASURES, %08x", | |
1459 | p->value); | |
1460 | ret = 0; | |
1461 | break; | |
1462 | ||
1463 | case IW_AUTH_DROP_UNENCRYPTED: | |
1464 | devdbg(usbdev, "SIOCSIWAUTH: DROP_UNENCRYPTED, %08x", p->value); | |
1465 | ret = 0; | |
1466 | break; | |
1467 | ||
1468 | case IW_AUTH_80211_AUTH_ALG: | |
1469 | devdbg(usbdev, "SIOCSIWAUTH: 80211_AUTH_ALG, %08x", p->value); | |
1470 | priv->wpa_authalg = p->value; | |
1471 | ret = 0; | |
1472 | break; | |
1473 | ||
1474 | case IW_AUTH_WPA_ENABLED: | |
1475 | devdbg(usbdev, "SIOCSIWAUTH: WPA_ENABLED, %08x", p->value); | |
1476 | if (wrqu->param.value) | |
1477 | deauthenticate(usbdev); | |
1478 | ret = 0; | |
1479 | break; | |
1480 | ||
1481 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
1482 | devdbg(usbdev, "SIOCSIWAUTH: RX_UNENCRYPTED_EAPOL, %08x", | |
1483 | p->value); | |
1484 | ret = 0; | |
1485 | break; | |
1486 | ||
1487 | case IW_AUTH_ROAMING_CONTROL: | |
1488 | devdbg(usbdev, "SIOCSIWAUTH: ROAMING_CONTROL, %08x", p->value); | |
1489 | ret = 0; | |
1490 | break; | |
1491 | ||
1492 | case IW_AUTH_PRIVACY_INVOKED: | |
1493 | devdbg(usbdev, "SIOCSIWAUTH: invalid cmd %d", | |
1494 | wrqu->param.flags & IW_AUTH_INDEX); | |
1495 | return -EOPNOTSUPP; | |
1496 | ||
1497 | default: | |
1498 | devdbg(usbdev, "SIOCSIWAUTH: UNKNOWN %08x, %08x", | |
1499 | p->flags & IW_AUTH_INDEX, p->value); | |
1500 | } | |
1501 | return ret; | |
1502 | } | |
1503 | ||
1504 | ||
1505 | static int rndis_iw_get_auth(struct net_device *dev, | |
1506 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1507 | { | |
1508 | struct iw_param *p = &wrqu->param; | |
524ad0a7 | 1509 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1510 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1511 | ||
1512 | switch (p->flags & IW_AUTH_INDEX) { | |
1513 | case IW_AUTH_WPA_VERSION: | |
1514 | p->value = priv->wpa_version; | |
1515 | break; | |
1516 | case IW_AUTH_CIPHER_PAIRWISE: | |
1517 | p->value = priv->wpa_cipher_pair; | |
1518 | break; | |
1519 | case IW_AUTH_CIPHER_GROUP: | |
1520 | p->value = priv->wpa_cipher_group; | |
1521 | break; | |
1522 | case IW_AUTH_KEY_MGMT: | |
1523 | p->value = priv->wpa_keymgmt; | |
1524 | break; | |
1525 | case IW_AUTH_80211_AUTH_ALG: | |
1526 | p->value = priv->wpa_authalg; | |
1527 | break; | |
1528 | default: | |
1529 | devdbg(usbdev, "SIOCGIWAUTH: invalid cmd %d", | |
1530 | wrqu->param.flags & IW_AUTH_INDEX); | |
1531 | return -EOPNOTSUPP; | |
1532 | } | |
1533 | return 0; | |
1534 | } | |
1535 | ||
1536 | ||
bf164cc0 JK |
1537 | static int rndis_iw_set_encode(struct net_device *dev, |
1538 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1539 | { | |
524ad0a7 | 1540 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1541 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1542 | int ret, index, key_len; | |
1543 | u8 *key; | |
1544 | ||
1545 | index = (wrqu->encoding.flags & IW_ENCODE_INDEX); | |
1546 | ||
1547 | /* iwconfig gives index as 1 - N */ | |
1548 | if (index > 0) | |
1549 | index--; | |
1550 | else | |
1551 | index = priv->encr_tx_key_index; | |
1552 | ||
1553 | if (index < 0 || index >= 4) { | |
1554 | devwarn(usbdev, "encryption index out of range (%u)", index); | |
1555 | return -EINVAL; | |
1556 | } | |
1557 | ||
1558 | /* remove key if disabled */ | |
1559 | if (wrqu->data.flags & IW_ENCODE_DISABLED) { | |
1560 | if (remove_key(usbdev, index, NULL)) | |
1561 | return -EINVAL; | |
1562 | else | |
1563 | return 0; | |
1564 | } | |
1565 | ||
1566 | /* global encryption state (for all keys) */ | |
1567 | if (wrqu->data.flags & IW_ENCODE_OPEN) | |
1568 | ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED, | |
1569 | IW_AUTH_ALG_OPEN_SYSTEM); | |
1570 | else /*if (wrqu->data.flags & IW_ENCODE_RESTRICTED)*/ | |
1571 | ret = set_auth_mode(usbdev, IW_AUTH_WPA_VERSION_DISABLED, | |
1572 | IW_AUTH_ALG_SHARED_KEY); | |
1573 | if (ret != 0) | |
1574 | return ret; | |
1575 | ||
1576 | if (wrqu->data.length > 0) { | |
1577 | key_len = wrqu->data.length; | |
1578 | key = extra; | |
1579 | } else { | |
1580 | /* must be set as tx key */ | |
1581 | if (priv->encr_key_len[index] == 0) | |
1582 | return -EINVAL; | |
1583 | key_len = priv->encr_key_len[index]; | |
1584 | key = priv->encr_keys[index]; | |
1585 | priv->encr_tx_key_index = index; | |
1586 | } | |
1587 | ||
1588 | if (add_wep_key(usbdev, key, key_len, index) != 0) | |
1589 | return -EINVAL; | |
1590 | ||
1591 | if (index == priv->encr_tx_key_index) | |
1592 | /* ndis drivers want essid to be set after setting encr */ | |
1593 | set_essid(usbdev, &priv->essid); | |
1594 | ||
1595 | return 0; | |
1596 | } | |
1597 | ||
1598 | ||
1599 | static int rndis_iw_set_encode_ext(struct net_device *dev, | |
1600 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1601 | { | |
1602 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
524ad0a7 | 1603 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 | 1604 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1e41e1d2 | 1605 | struct ndis_80211_key ndis_key; |
cdb2a9fe | 1606 | int keyidx, ret; |
bf164cc0 JK |
1607 | u8 *addr; |
1608 | ||
1609 | keyidx = wrqu->encoding.flags & IW_ENCODE_INDEX; | |
1610 | ||
1611 | /* iwconfig gives index as 1 - N */ | |
1612 | if (keyidx) | |
1613 | keyidx--; | |
1614 | else | |
1615 | keyidx = priv->encr_tx_key_index; | |
1616 | ||
1617 | if (keyidx < 0 || keyidx >= 4) | |
1618 | return -EINVAL; | |
1619 | ||
1620 | if (ext->alg == WPA_ALG_WEP) { | |
1621 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) | |
1622 | priv->encr_tx_key_index = keyidx; | |
1623 | return add_wep_key(usbdev, ext->key, ext->key_len, keyidx); | |
1624 | } | |
1625 | ||
1626 | if ((wrqu->encoding.flags & IW_ENCODE_DISABLED) || | |
1627 | ext->alg == IW_ENCODE_ALG_NONE || ext->key_len == 0) | |
1628 | return remove_key(usbdev, keyidx, NULL); | |
1629 | ||
461b3f2a | 1630 | if (ext->key_len > sizeof(ndis_key.material)) |
bf164cc0 JK |
1631 | return -1; |
1632 | ||
1633 | memset(&ndis_key, 0, sizeof(ndis_key)); | |
1634 | ||
461b3f2a JK |
1635 | ndis_key.size = cpu_to_le32(sizeof(ndis_key) - |
1636 | sizeof(ndis_key.material) + ext->key_len); | |
1637 | ndis_key.length = cpu_to_le32(ext->key_len); | |
1638 | ndis_key.index = cpu_to_le32(keyidx); | |
bf164cc0 JK |
1639 | |
1640 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { | |
461b3f2a | 1641 | memcpy(ndis_key.rsc, ext->rx_seq, 6); |
b4703a2e | 1642 | ndis_key.index |= ndis_80211_addkey_set_init_recv_seq; |
bf164cc0 JK |
1643 | } |
1644 | ||
1645 | addr = ext->addr.sa_data; | |
1646 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { | |
1647 | /* group key */ | |
1e41e1d2 | 1648 | if (priv->infra_mode == ndis_80211_infra_adhoc) |
461b3f2a | 1649 | memset(ndis_key.bssid, 0xff, ETH_ALEN); |
bf164cc0 | 1650 | else |
461b3f2a | 1651 | get_bssid(usbdev, ndis_key.bssid); |
bf164cc0 JK |
1652 | } else { |
1653 | /* pairwise key */ | |
b4703a2e | 1654 | ndis_key.index |= ndis_80211_addkey_pairwise_key; |
461b3f2a | 1655 | memcpy(ndis_key.bssid, addr, ETH_ALEN); |
bf164cc0 JK |
1656 | } |
1657 | ||
1658 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) | |
b4703a2e | 1659 | ndis_key.index |= ndis_80211_addkey_transmit_key; |
bf164cc0 JK |
1660 | |
1661 | if (ext->alg == IW_ENCODE_ALG_TKIP && ext->key_len == 32) { | |
1662 | /* wpa_supplicant gives us the Michael MIC RX/TX keys in | |
1663 | * different order than NDIS spec, so swap the order here. */ | |
461b3f2a JK |
1664 | memcpy(ndis_key.material, ext->key, 16); |
1665 | memcpy(ndis_key.material + 16, ext->key + 24, 8); | |
1666 | memcpy(ndis_key.material + 24, ext->key + 16, 8); | |
bf164cc0 | 1667 | } else |
461b3f2a | 1668 | memcpy(ndis_key.material, ext->key, ext->key_len); |
bf164cc0 JK |
1669 | |
1670 | ret = rndis_set_oid(usbdev, OID_802_11_ADD_KEY, &ndis_key, | |
461b3f2a | 1671 | le32_to_cpu(ndis_key.size)); |
bf164cc0 JK |
1672 | devdbg(usbdev, "SIOCSIWENCODEEXT: OID_802_11_ADD_KEY -> %08X", ret); |
1673 | if (ret != 0) | |
1674 | return ret; | |
1675 | ||
1676 | priv->encr_key_len[keyidx] = ext->key_len; | |
461b3f2a | 1677 | memcpy(&priv->encr_keys[keyidx], ndis_key.material, ext->key_len); |
bf164cc0 JK |
1678 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) |
1679 | priv->encr_tx_key_index = keyidx; | |
1680 | ||
1681 | return 0; | |
1682 | } | |
1683 | ||
1684 | ||
bf164cc0 JK |
1685 | static int rndis_iw_set_genie(struct net_device *dev, |
1686 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1687 | { | |
524ad0a7 | 1688 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1689 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1690 | int ret = 0; | |
1691 | ||
1692 | #ifdef DEBUG | |
1693 | int j; | |
1694 | u8 *gie = extra; | |
1695 | for (j = 0; j < wrqu->data.length; j += 8) | |
1696 | devdbg(usbdev, | |
1697 | "SIOCSIWGENIE %04x - " | |
1698 | "%02x %02x %02x %02x %02x %02x %02x %02x", j, | |
1699 | gie[j + 0], gie[j + 1], gie[j + 2], gie[j + 3], | |
1700 | gie[j + 4], gie[j + 5], gie[j + 6], gie[j + 7]); | |
1701 | #endif | |
1702 | /* clear existing IEs */ | |
1703 | if (priv->wpa_ie_len) { | |
1704 | kfree(priv->wpa_ie); | |
1705 | priv->wpa_ie_len = 0; | |
1706 | } | |
1707 | ||
1708 | /* set new IEs */ | |
1709 | priv->wpa_ie = kmalloc(wrqu->data.length, GFP_KERNEL); | |
1710 | if (priv->wpa_ie) { | |
1711 | priv->wpa_ie_len = wrqu->data.length; | |
1712 | memcpy(priv->wpa_ie, extra, priv->wpa_ie_len); | |
1713 | } else | |
1714 | ret = -ENOMEM; | |
1715 | return ret; | |
1716 | } | |
1717 | ||
1718 | ||
1719 | static int rndis_iw_get_genie(struct net_device *dev, | |
1720 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1721 | { | |
524ad0a7 | 1722 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1723 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1724 | ||
1725 | devdbg(usbdev, "SIOCGIWGENIE"); | |
1726 | ||
1727 | if (priv->wpa_ie_len == 0 || priv->wpa_ie == NULL) { | |
1728 | wrqu->data.length = 0; | |
1729 | return 0; | |
1730 | } | |
1731 | ||
1732 | if (wrqu->data.length < priv->wpa_ie_len) | |
1733 | return -E2BIG; | |
1734 | ||
1735 | wrqu->data.length = priv->wpa_ie_len; | |
1736 | memcpy(extra, priv->wpa_ie, priv->wpa_ie_len); | |
1737 | ||
1738 | return 0; | |
1739 | } | |
1740 | ||
1741 | ||
1742 | static int rndis_iw_set_rts(struct net_device *dev, | |
1743 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1744 | { | |
524ad0a7 | 1745 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1746 | __le32 tmp; |
1747 | devdbg(usbdev, "SIOCSIWRTS"); | |
1748 | ||
1749 | tmp = cpu_to_le32(wrqu->rts.value); | |
1750 | return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp, | |
1751 | sizeof(tmp)); | |
1752 | } | |
1753 | ||
1754 | ||
1755 | static int rndis_iw_get_rts(struct net_device *dev, | |
1756 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1757 | { | |
524ad0a7 | 1758 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1759 | __le32 tmp; |
1760 | int len, ret; | |
1761 | ||
1762 | len = sizeof(tmp); | |
1763 | ret = rndis_query_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp, &len); | |
1764 | if (ret == 0) { | |
1765 | wrqu->rts.value = le32_to_cpu(tmp); | |
1766 | wrqu->rts.flags = 1; | |
1767 | wrqu->rts.disabled = 0; | |
1768 | } | |
1769 | ||
1770 | devdbg(usbdev, "SIOCGIWRTS: %d", wrqu->rts.value); | |
1771 | ||
1772 | return ret; | |
1773 | } | |
1774 | ||
1775 | ||
1776 | static int rndis_iw_set_frag(struct net_device *dev, | |
1777 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1778 | { | |
524ad0a7 | 1779 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1780 | __le32 tmp; |
1781 | ||
1782 | devdbg(usbdev, "SIOCSIWFRAG"); | |
1783 | ||
1784 | tmp = cpu_to_le32(wrqu->frag.value); | |
1785 | return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp, | |
1786 | sizeof(tmp)); | |
1787 | } | |
1788 | ||
1789 | ||
1790 | static int rndis_iw_get_frag(struct net_device *dev, | |
1791 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1792 | { | |
524ad0a7 | 1793 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1794 | __le32 tmp; |
1795 | int len, ret; | |
1796 | ||
1797 | len = sizeof(tmp); | |
1798 | ret = rndis_query_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp, | |
1799 | &len); | |
1800 | if (ret == 0) { | |
1801 | wrqu->frag.value = le32_to_cpu(tmp); | |
1802 | wrqu->frag.flags = 1; | |
1803 | wrqu->frag.disabled = 0; | |
1804 | } | |
1805 | devdbg(usbdev, "SIOCGIWFRAG: %d", wrqu->frag.value); | |
1806 | return ret; | |
1807 | } | |
1808 | ||
1809 | ||
bf164cc0 JK |
1810 | static int rndis_iw_set_freq(struct net_device *dev, |
1811 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1812 | { | |
524ad0a7 | 1813 | struct usbnet *usbdev = netdev_priv(dev); |
1e41e1d2 | 1814 | struct ndis_80211_conf config; |
bf164cc0 JK |
1815 | unsigned int dsconfig; |
1816 | int len, ret; | |
1817 | ||
1818 | /* this OID is valid only when not associated */ | |
1819 | if (is_associated(usbdev)) | |
1820 | return 0; | |
1821 | ||
1822 | dsconfig = 0; | |
1823 | if (freq_to_dsconfig(&wrqu->freq, &dsconfig)) | |
1824 | return -EINVAL; | |
1825 | ||
1826 | len = sizeof(config); | |
1827 | ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len); | |
1828 | if (ret != 0) { | |
1829 | devdbg(usbdev, "SIOCSIWFREQ: querying configuration failed"); | |
1830 | return 0; | |
1831 | } | |
1832 | ||
461b3f2a | 1833 | config.ds_config = cpu_to_le32(dsconfig); |
bf164cc0 JK |
1834 | |
1835 | devdbg(usbdev, "SIOCSIWFREQ: %d * 10^%d", wrqu->freq.m, wrqu->freq.e); | |
1836 | return rndis_set_oid(usbdev, OID_802_11_CONFIGURATION, &config, | |
1837 | sizeof(config)); | |
1838 | } | |
1839 | ||
1840 | ||
1841 | static int rndis_iw_get_freq(struct net_device *dev, | |
1842 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1843 | { | |
524ad0a7 | 1844 | struct usbnet *usbdev = netdev_priv(dev); |
1e41e1d2 | 1845 | struct ndis_80211_conf config; |
bf164cc0 JK |
1846 | int len, ret; |
1847 | ||
1848 | len = sizeof(config); | |
1849 | ret = rndis_query_oid(usbdev, OID_802_11_CONFIGURATION, &config, &len); | |
1850 | if (ret == 0) | |
461b3f2a | 1851 | dsconfig_to_freq(le32_to_cpu(config.ds_config), &wrqu->freq); |
bf164cc0 JK |
1852 | |
1853 | devdbg(usbdev, "SIOCGIWFREQ: %d", wrqu->freq.m); | |
1854 | return ret; | |
1855 | } | |
1856 | ||
1857 | ||
1858 | static int rndis_iw_get_txpower(struct net_device *dev, | |
1859 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1860 | { | |
524ad0a7 | 1861 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1862 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1863 | __le32 tx_power; | |
bf164cc0 JK |
1864 | |
1865 | if (priv->radio_on) { | |
9656e85b JK |
1866 | /* fake since changing tx_power (by userlevel) not supported */ |
1867 | tx_power = cpu_to_le32(get_bcm4320_power(priv)); | |
bf164cc0 JK |
1868 | |
1869 | wrqu->txpower.flags = IW_TXPOW_MWATT; | |
1870 | wrqu->txpower.value = le32_to_cpu(tx_power); | |
1871 | wrqu->txpower.disabled = 0; | |
1872 | } else { | |
1873 | wrqu->txpower.flags = IW_TXPOW_MWATT; | |
1874 | wrqu->txpower.value = 0; | |
1875 | wrqu->txpower.disabled = 1; | |
1876 | } | |
1877 | ||
1878 | devdbg(usbdev, "SIOCGIWTXPOW: %d", wrqu->txpower.value); | |
1879 | ||
9656e85b | 1880 | return 0; |
bf164cc0 JK |
1881 | } |
1882 | ||
1883 | ||
1884 | static int rndis_iw_set_txpower(struct net_device *dev, | |
1885 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1886 | { | |
524ad0a7 | 1887 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1888 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1889 | __le32 tx_power = 0; | |
bf164cc0 JK |
1890 | |
1891 | if (!wrqu->txpower.disabled) { | |
1892 | if (wrqu->txpower.flags == IW_TXPOW_MWATT) | |
1893 | tx_power = cpu_to_le32(wrqu->txpower.value); | |
1894 | else { /* wrqu->txpower.flags == IW_TXPOW_DBM */ | |
1895 | if (wrqu->txpower.value > 20) | |
1896 | tx_power = cpu_to_le32(128); | |
1897 | else if (wrqu->txpower.value < -43) | |
1898 | tx_power = cpu_to_le32(127); | |
1899 | else { | |
1900 | signed char tmp; | |
1901 | tmp = wrqu->txpower.value; | |
1902 | tmp = -12 - tmp; | |
1903 | tmp <<= 2; | |
1904 | tx_power = cpu_to_le32((unsigned char)tmp); | |
1905 | } | |
1906 | } | |
1907 | } | |
1908 | ||
1909 | devdbg(usbdev, "SIOCSIWTXPOW: %d", le32_to_cpu(tx_power)); | |
1910 | ||
1911 | if (le32_to_cpu(tx_power) != 0) { | |
9656e85b JK |
1912 | /* txpower unsupported, just turn radio on */ |
1913 | if (!priv->radio_on) | |
1914 | return disassociate(usbdev, 1); | |
1915 | return 0; /* all ready on */ | |
bf164cc0 JK |
1916 | } |
1917 | ||
1918 | /* tx_power == 0, turn off radio */ | |
1919 | return disassociate(usbdev, 0); | |
1920 | } | |
1921 | ||
1922 | ||
1923 | static int rndis_iw_get_rate(struct net_device *dev, | |
1924 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1925 | { | |
524ad0a7 | 1926 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1927 | __le32 tmp; |
1928 | int ret, len; | |
1929 | ||
1930 | len = sizeof(tmp); | |
1931 | ret = rndis_query_oid(usbdev, OID_GEN_LINK_SPEED, &tmp, &len); | |
1932 | if (ret == 0) { | |
1933 | wrqu->bitrate.value = le32_to_cpu(tmp) * 100; | |
1934 | wrqu->bitrate.disabled = 0; | |
1935 | wrqu->bitrate.flags = 1; | |
1936 | } | |
1937 | return ret; | |
1938 | } | |
1939 | ||
1940 | ||
1941 | static int rndis_iw_set_mlme(struct net_device *dev, | |
1942 | struct iw_request_info *info, union iwreq_data *wrqu, char *extra) | |
1943 | { | |
524ad0a7 | 1944 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1945 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1946 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | |
1947 | unsigned char bssid[ETH_ALEN]; | |
1948 | ||
1949 | get_bssid(usbdev, bssid); | |
1950 | ||
1951 | if (memcmp(bssid, mlme->addr.sa_data, ETH_ALEN)) | |
1952 | return -EINVAL; | |
1953 | ||
1954 | switch (mlme->cmd) { | |
1955 | case IW_MLME_DEAUTH: | |
1956 | return deauthenticate(usbdev); | |
1957 | case IW_MLME_DISASSOC: | |
1958 | return disassociate(usbdev, priv->radio_on); | |
1959 | default: | |
1960 | return -EOPNOTSUPP; | |
1961 | } | |
1962 | ||
1963 | return 0; | |
1964 | } | |
1965 | ||
1966 | ||
1967 | static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev) | |
1968 | { | |
524ad0a7 | 1969 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
1970 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
1971 | unsigned long flags; | |
1972 | ||
1973 | spin_lock_irqsave(&priv->stats_lock, flags); | |
1974 | memcpy(&priv->iwstats, &priv->privstats, sizeof(priv->iwstats)); | |
1975 | spin_unlock_irqrestore(&priv->stats_lock, flags); | |
1976 | ||
1977 | return &priv->iwstats; | |
1978 | } | |
1979 | ||
1980 | ||
1981 | #define IW_IOCTL(x) [(x) - SIOCSIWCOMMIT] | |
1982 | static const iw_handler rndis_iw_handler[] = | |
1983 | { | |
1984 | IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit, | |
5c8fa4f7 | 1985 | IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname, |
bf164cc0 JK |
1986 | IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq, |
1987 | IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq, | |
964c1d41 JL |
1988 | IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode, |
1989 | IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode, | |
4d2a369e | 1990 | IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange, |
bf164cc0 JK |
1991 | IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid, |
1992 | IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid, | |
71a7b26d JK |
1993 | IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan, |
1994 | IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan, | |
bf164cc0 JK |
1995 | IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid, |
1996 | IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid, | |
bf164cc0 JK |
1997 | IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate, |
1998 | IW_IOCTL(SIOCSIWRTS) = rndis_iw_set_rts, | |
1999 | IW_IOCTL(SIOCGIWRTS) = rndis_iw_get_rts, | |
2000 | IW_IOCTL(SIOCSIWFRAG) = rndis_iw_set_frag, | |
2001 | IW_IOCTL(SIOCGIWFRAG) = rndis_iw_get_frag, | |
2002 | IW_IOCTL(SIOCSIWTXPOW) = rndis_iw_set_txpower, | |
2003 | IW_IOCTL(SIOCGIWTXPOW) = rndis_iw_get_txpower, | |
2004 | IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode, | |
2005 | IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext, | |
2006 | IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth, | |
2007 | IW_IOCTL(SIOCGIWAUTH) = rndis_iw_get_auth, | |
2008 | IW_IOCTL(SIOCSIWGENIE) = rndis_iw_set_genie, | |
2009 | IW_IOCTL(SIOCGIWGENIE) = rndis_iw_get_genie, | |
2010 | IW_IOCTL(SIOCSIWMLME) = rndis_iw_set_mlme, | |
2011 | }; | |
2012 | ||
2013 | static const iw_handler rndis_wext_private_handler[] = { | |
2014 | }; | |
2015 | ||
2016 | static const struct iw_priv_args rndis_wext_private_args[] = { | |
2017 | }; | |
2018 | ||
2019 | ||
2020 | static const struct iw_handler_def rndis_iw_handlers = { | |
2021 | .num_standard = ARRAY_SIZE(rndis_iw_handler), | |
2022 | .num_private = ARRAY_SIZE(rndis_wext_private_handler), | |
2023 | .num_private_args = ARRAY_SIZE(rndis_wext_private_args), | |
2024 | .standard = (iw_handler *)rndis_iw_handler, | |
2025 | .private = (iw_handler *)rndis_wext_private_handler, | |
2026 | .private_args = (struct iw_priv_args *)rndis_wext_private_args, | |
2027 | .get_wireless_stats = rndis_get_wireless_stats, | |
2028 | }; | |
2029 | ||
2030 | ||
2031 | static void rndis_wext_worker(struct work_struct *work) | |
2032 | { | |
2033 | struct rndis_wext_private *priv = | |
2034 | container_of(work, struct rndis_wext_private, work); | |
2035 | struct usbnet *usbdev = priv->usbdev; | |
2036 | union iwreq_data evt; | |
2037 | unsigned char bssid[ETH_ALEN]; | |
4364623c SA |
2038 | struct ndis_80211_assoc_info *info; |
2039 | int assoc_size = sizeof(*info) + IW_CUSTOM_MAX + 32; | |
2040 | int ret, offset; | |
bf164cc0 | 2041 | |
6010ce07 | 2042 | if (test_and_clear_bit(WORK_LINK_UP, &priv->work_pending)) { |
5331b96c JK |
2043 | netif_carrier_on(usbdev->net); |
2044 | ||
4364623c SA |
2045 | info = kzalloc(assoc_size, GFP_KERNEL); |
2046 | if (!info) | |
2047 | goto get_bssid; | |
bf164cc0 | 2048 | |
4364623c SA |
2049 | /* Get association info IEs from device and send them back to |
2050 | * userspace. */ | |
2051 | ret = get_association_info(usbdev, info, assoc_size); | |
2052 | if (!ret) { | |
2053 | evt.data.length = le32_to_cpu(info->req_ie_length); | |
2054 | if (evt.data.length > 0) { | |
2055 | offset = le32_to_cpu(info->offset_req_ies); | |
2056 | wireless_send_event(usbdev->net, | |
2057 | IWEVASSOCREQIE, &evt, | |
2058 | (char *)info + offset); | |
2059 | } | |
2060 | ||
2061 | evt.data.length = le32_to_cpu(info->resp_ie_length); | |
2062 | if (evt.data.length > 0) { | |
2063 | offset = le32_to_cpu(info->offset_resp_ies); | |
2064 | wireless_send_event(usbdev->net, | |
2065 | IWEVASSOCRESPIE, &evt, | |
2066 | (char *)info + offset); | |
2067 | } | |
2068 | } | |
2069 | ||
2070 | kfree(info); | |
bf164cc0 | 2071 | |
4364623c SA |
2072 | get_bssid: |
2073 | ret = get_bssid(usbdev, bssid); | |
bf164cc0 JK |
2074 | if (!ret) { |
2075 | evt.data.flags = 0; | |
2076 | evt.data.length = 0; | |
2077 | memcpy(evt.ap_addr.sa_data, bssid, ETH_ALEN); | |
2078 | wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL); | |
2079 | } | |
2080 | } | |
2081 | ||
6010ce07 | 2082 | if (test_and_clear_bit(WORK_LINK_DOWN, &priv->work_pending)) { |
5331b96c JK |
2083 | netif_carrier_off(usbdev->net); |
2084 | ||
6010ce07 JK |
2085 | evt.data.flags = 0; |
2086 | evt.data.length = 0; | |
2087 | memset(evt.ap_addr.sa_data, 0, ETH_ALEN); | |
2088 | wireless_send_event(usbdev->net, SIOCGIWAP, &evt, NULL); | |
2089 | } | |
2090 | ||
bf164cc0 JK |
2091 | if (test_and_clear_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending)) |
2092 | set_multicast_list(usbdev); | |
2093 | } | |
2094 | ||
2095 | static void rndis_wext_set_multicast_list(struct net_device *dev) | |
2096 | { | |
524ad0a7 | 2097 | struct usbnet *usbdev = netdev_priv(dev); |
bf164cc0 JK |
2098 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
2099 | ||
a67edb9e JK |
2100 | if (test_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending)) |
2101 | return; | |
2102 | ||
bf164cc0 JK |
2103 | set_bit(WORK_SET_MULTICAST_LIST, &priv->work_pending); |
2104 | queue_work(priv->workqueue, &priv->work); | |
2105 | } | |
2106 | ||
a19d7292 | 2107 | static void rndis_wext_link_change(struct usbnet *usbdev, int state) |
bf164cc0 | 2108 | { |
a19d7292 | 2109 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
bf164cc0 | 2110 | |
6010ce07 JK |
2111 | /* queue work to avoid recursive calls into rndis_command */ |
2112 | set_bit(state ? WORK_LINK_UP : WORK_LINK_DOWN, &priv->work_pending); | |
2113 | queue_work(priv->workqueue, &priv->work); | |
bf164cc0 JK |
2114 | } |
2115 | ||
2116 | ||
a19d7292 | 2117 | static int rndis_wext_get_caps(struct usbnet *usbdev) |
bf164cc0 JK |
2118 | { |
2119 | struct { | |
2120 | __le32 num_items; | |
2121 | __le32 items[8]; | |
2122 | } networks_supported; | |
2123 | int len, retval, i, n; | |
a19d7292 | 2124 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
bf164cc0 | 2125 | |
bf164cc0 JK |
2126 | /* determine supported modes */ |
2127 | len = sizeof(networks_supported); | |
a19d7292 | 2128 | retval = rndis_query_oid(usbdev, OID_802_11_NETWORK_TYPES_SUPPORTED, |
bf164cc0 JK |
2129 | &networks_supported, &len); |
2130 | if (retval >= 0) { | |
2131 | n = le32_to_cpu(networks_supported.num_items); | |
2132 | if (n > 8) | |
2133 | n = 8; | |
2134 | for (i = 0; i < n; i++) { | |
2135 | switch (le32_to_cpu(networks_supported.items[i])) { | |
1e41e1d2 JK |
2136 | case ndis_80211_type_freq_hop: |
2137 | case ndis_80211_type_direct_seq: | |
bf164cc0 JK |
2138 | priv->caps |= CAP_MODE_80211B; |
2139 | break; | |
1e41e1d2 | 2140 | case ndis_80211_type_ofdm_a: |
bf164cc0 JK |
2141 | priv->caps |= CAP_MODE_80211A; |
2142 | break; | |
1e41e1d2 | 2143 | case ndis_80211_type_ofdm_g: |
bf164cc0 JK |
2144 | priv->caps |= CAP_MODE_80211G; |
2145 | break; | |
2146 | } | |
2147 | } | |
bf164cc0 JK |
2148 | } |
2149 | ||
2150 | return retval; | |
2151 | } | |
2152 | ||
2153 | ||
2154 | #define STATS_UPDATE_JIFFIES (HZ) | |
2155 | static void rndis_update_wireless_stats(struct work_struct *work) | |
2156 | { | |
2157 | struct rndis_wext_private *priv = | |
2158 | container_of(work, struct rndis_wext_private, stats_work.work); | |
2159 | struct usbnet *usbdev = priv->usbdev; | |
2160 | struct iw_statistics iwstats; | |
2161 | __le32 rssi, tmp; | |
a97b1f3d | 2162 | int len, ret, j; |
bf164cc0 JK |
2163 | unsigned long flags; |
2164 | int update_jiffies = STATS_UPDATE_JIFFIES; | |
2165 | void *buf; | |
2166 | ||
2167 | spin_lock_irqsave(&priv->stats_lock, flags); | |
2168 | memcpy(&iwstats, &priv->privstats, sizeof(iwstats)); | |
2169 | spin_unlock_irqrestore(&priv->stats_lock, flags); | |
2170 | ||
2171 | /* only update stats when connected */ | |
2172 | if (!is_associated(usbdev)) { | |
2173 | iwstats.qual.qual = 0; | |
2174 | iwstats.qual.level = 0; | |
2175 | iwstats.qual.updated = IW_QUAL_QUAL_UPDATED | |
2176 | | IW_QUAL_LEVEL_UPDATED | |
2177 | | IW_QUAL_NOISE_INVALID | |
2178 | | IW_QUAL_QUAL_INVALID | |
2179 | | IW_QUAL_LEVEL_INVALID; | |
2180 | goto end; | |
2181 | } | |
2182 | ||
2183 | len = sizeof(rssi); | |
2184 | ret = rndis_query_oid(usbdev, OID_802_11_RSSI, &rssi, &len); | |
2185 | ||
2186 | devdbg(usbdev, "stats: OID_802_11_RSSI -> %d, rssi:%d", ret, | |
2187 | le32_to_cpu(rssi)); | |
2188 | if (ret == 0) { | |
2189 | memset(&iwstats.qual, 0, sizeof(iwstats.qual)); | |
2190 | iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi)); | |
4bd7f03e | 2191 | iwstats.qual.level = level_to_qual(le32_to_cpu(rssi)); |
bf164cc0 JK |
2192 | iwstats.qual.updated = IW_QUAL_QUAL_UPDATED |
2193 | | IW_QUAL_LEVEL_UPDATED | |
2194 | | IW_QUAL_NOISE_INVALID; | |
2195 | } | |
2196 | ||
2197 | memset(&iwstats.discard, 0, sizeof(iwstats.discard)); | |
2198 | ||
2199 | len = sizeof(tmp); | |
2200 | ret = rndis_query_oid(usbdev, OID_GEN_XMIT_ERROR, &tmp, &len); | |
2201 | if (ret == 0) | |
2202 | iwstats.discard.misc += le32_to_cpu(tmp); | |
2203 | ||
2204 | len = sizeof(tmp); | |
2205 | ret = rndis_query_oid(usbdev, OID_GEN_RCV_ERROR, &tmp, &len); | |
2206 | if (ret == 0) | |
2207 | iwstats.discard.misc += le32_to_cpu(tmp); | |
2208 | ||
2209 | len = sizeof(tmp); | |
2210 | ret = rndis_query_oid(usbdev, OID_GEN_RCV_NO_BUFFER, &tmp, &len); | |
2211 | if (ret == 0) | |
2212 | iwstats.discard.misc += le32_to_cpu(tmp); | |
2213 | ||
a97b1f3d JK |
2214 | /* Workaround transfer stalls on poor quality links. |
2215 | * TODO: find right way to fix these stalls (as stalls do not happen | |
2216 | * with ndiswrapper/windows driver). */ | |
2217 | if (iwstats.qual.qual <= 25) { | |
bf164cc0 JK |
2218 | /* Decrease stats worker interval to catch stalls. |
2219 | * faster. Faster than 400-500ms causes packet loss, | |
2220 | * Slower doesn't catch stalls fast enough. | |
2221 | */ | |
2222 | j = msecs_to_jiffies(priv->param_workaround_interval); | |
2223 | if (j > STATS_UPDATE_JIFFIES) | |
2224 | j = STATS_UPDATE_JIFFIES; | |
2225 | else if (j <= 0) | |
2226 | j = 1; | |
2227 | update_jiffies = j; | |
2228 | ||
2229 | /* Send scan OID. Use of both OIDs is required to get device | |
2230 | * working. | |
2231 | */ | |
35c26c2c | 2232 | tmp = cpu_to_le32(1); |
bf164cc0 JK |
2233 | rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp, |
2234 | sizeof(tmp)); | |
2235 | ||
2236 | len = CONTROL_BUFFER_SIZE; | |
2237 | buf = kmalloc(len, GFP_KERNEL); | |
2238 | if (!buf) | |
2239 | goto end; | |
2240 | ||
2241 | rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len); | |
2242 | kfree(buf); | |
2243 | } | |
2244 | end: | |
2245 | spin_lock_irqsave(&priv->stats_lock, flags); | |
2246 | memcpy(&priv->privstats, &iwstats, sizeof(iwstats)); | |
2247 | spin_unlock_irqrestore(&priv->stats_lock, flags); | |
2248 | ||
2249 | if (update_jiffies >= HZ) | |
2250 | update_jiffies = round_jiffies_relative(update_jiffies); | |
2251 | else { | |
2252 | j = round_jiffies_relative(update_jiffies); | |
2253 | if (abs(j - update_jiffies) <= 10) | |
2254 | update_jiffies = j; | |
2255 | } | |
2256 | ||
2257 | queue_delayed_work(priv->workqueue, &priv->stats_work, update_jiffies); | |
2258 | } | |
2259 | ||
2260 | ||
59620e9f JK |
2261 | static int bcm4320a_early_init(struct usbnet *usbdev) |
2262 | { | |
2263 | /* bcm4320a doesn't handle configuration parameters well. Try | |
2264 | * set any and you get partially zeroed mac and broken device. | |
2265 | */ | |
2266 | ||
2267 | return 0; | |
2268 | } | |
2269 | ||
2270 | ||
2271 | static int bcm4320b_early_init(struct usbnet *usbdev) | |
bf164cc0 | 2272 | { |
a19d7292 | 2273 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
bf164cc0 JK |
2274 | char buf[8]; |
2275 | ||
2276 | /* Early initialization settings, setting these won't have effect | |
2277 | * if called after generic_rndis_bind(). | |
2278 | */ | |
2279 | ||
2280 | priv->param_country[0] = modparam_country[0]; | |
2281 | priv->param_country[1] = modparam_country[1]; | |
2282 | priv->param_country[2] = 0; | |
2283 | priv->param_frameburst = modparam_frameburst; | |
2284 | priv->param_afterburner = modparam_afterburner; | |
2285 | priv->param_power_save = modparam_power_save; | |
2286 | priv->param_power_output = modparam_power_output; | |
2287 | priv->param_roamtrigger = modparam_roamtrigger; | |
2288 | priv->param_roamdelta = modparam_roamdelta; | |
bf164cc0 JK |
2289 | |
2290 | priv->param_country[0] = toupper(priv->param_country[0]); | |
2291 | priv->param_country[1] = toupper(priv->param_country[1]); | |
2292 | /* doesn't support EU as country code, use FI instead */ | |
2293 | if (!strcmp(priv->param_country, "EU")) | |
2294 | strcpy(priv->param_country, "FI"); | |
2295 | ||
2296 | if (priv->param_power_save < 0) | |
2297 | priv->param_power_save = 0; | |
2298 | else if (priv->param_power_save > 2) | |
2299 | priv->param_power_save = 2; | |
2300 | ||
a7624837 JK |
2301 | if (priv->param_power_output < 0) |
2302 | priv->param_power_output = 0; | |
2303 | else if (priv->param_power_output > 3) | |
2304 | priv->param_power_output = 3; | |
2305 | ||
bf164cc0 JK |
2306 | if (priv->param_roamtrigger < -80) |
2307 | priv->param_roamtrigger = -80; | |
2308 | else if (priv->param_roamtrigger > -60) | |
2309 | priv->param_roamtrigger = -60; | |
2310 | ||
2311 | if (priv->param_roamdelta < 0) | |
2312 | priv->param_roamdelta = 0; | |
2313 | else if (priv->param_roamdelta > 2) | |
2314 | priv->param_roamdelta = 2; | |
2315 | ||
4d381ffb | 2316 | if (modparam_workaround_interval < 0) |
bf164cc0 | 2317 | priv->param_workaround_interval = 500; |
4d381ffb RK |
2318 | else |
2319 | priv->param_workaround_interval = modparam_workaround_interval; | |
bf164cc0 | 2320 | |
a19d7292 JK |
2321 | rndis_set_config_parameter_str(usbdev, "Country", priv->param_country); |
2322 | rndis_set_config_parameter_str(usbdev, "FrameBursting", | |
bf164cc0 | 2323 | priv->param_frameburst ? "1" : "0"); |
a19d7292 | 2324 | rndis_set_config_parameter_str(usbdev, "Afterburner", |
bf164cc0 JK |
2325 | priv->param_afterburner ? "1" : "0"); |
2326 | sprintf(buf, "%d", priv->param_power_save); | |
a19d7292 | 2327 | rndis_set_config_parameter_str(usbdev, "PowerSaveMode", buf); |
bf164cc0 | 2328 | sprintf(buf, "%d", priv->param_power_output); |
a19d7292 | 2329 | rndis_set_config_parameter_str(usbdev, "PwrOut", buf); |
bf164cc0 | 2330 | sprintf(buf, "%d", priv->param_roamtrigger); |
a19d7292 | 2331 | rndis_set_config_parameter_str(usbdev, "RoamTrigger", buf); |
bf164cc0 | 2332 | sprintf(buf, "%d", priv->param_roamdelta); |
a19d7292 | 2333 | rndis_set_config_parameter_str(usbdev, "RoamDelta", buf); |
bf164cc0 JK |
2334 | |
2335 | return 0; | |
2336 | } | |
2337 | ||
23d12e2b DM |
2338 | /* same as rndis_netdev_ops but with local multicast handler */ |
2339 | static const struct net_device_ops rndis_wext_netdev_ops = { | |
2340 | .ndo_open = usbnet_open, | |
2341 | .ndo_stop = usbnet_stop, | |
2342 | .ndo_start_xmit = usbnet_start_xmit, | |
2343 | .ndo_tx_timeout = usbnet_tx_timeout, | |
2344 | .ndo_set_mac_address = eth_mac_addr, | |
2345 | .ndo_validate_addr = eth_validate_addr, | |
2346 | .ndo_set_multicast_list = rndis_wext_set_multicast_list, | |
2347 | }; | |
2348 | ||
bf164cc0 | 2349 | |
a19d7292 | 2350 | static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf) |
bf164cc0 | 2351 | { |
5c8fa4f7 | 2352 | struct wiphy *wiphy; |
bf164cc0 JK |
2353 | struct rndis_wext_private *priv; |
2354 | int retval, len; | |
2355 | __le32 tmp; | |
2356 | ||
5c8fa4f7 JL |
2357 | /* allocate wiphy and rndis private data |
2358 | * NOTE: We only support a single virtual interface, so wiphy | |
2359 | * and wireless_dev are somewhat synonymous for this device. | |
2360 | */ | |
2361 | wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wext_private)); | |
2362 | if (!wiphy) | |
bf164cc0 JK |
2363 | return -ENOMEM; |
2364 | ||
5c8fa4f7 JL |
2365 | priv = wiphy_priv(wiphy); |
2366 | usbdev->net->ieee80211_ptr = &priv->wdev; | |
2367 | priv->wdev.wiphy = wiphy; | |
2368 | priv->wdev.iftype = NL80211_IFTYPE_STATION; | |
2369 | ||
bf164cc0 JK |
2370 | /* These have to be initialized before calling generic_rndis_bind(). |
2371 | * Otherwise we'll be in big trouble in rndis_wext_early_init(). | |
2372 | */ | |
a19d7292 | 2373 | usbdev->driver_priv = priv; |
a19d7292 JK |
2374 | usbdev->net->wireless_handlers = &rndis_iw_handlers; |
2375 | priv->usbdev = usbdev; | |
bf164cc0 JK |
2376 | |
2377 | mutex_init(&priv->command_lock); | |
2378 | spin_lock_init(&priv->stats_lock); | |
2379 | ||
8d4d99ae JK |
2380 | /* because rndis_command() sleeps we need to use workqueue */ |
2381 | priv->workqueue = create_singlethread_workqueue("rndis_wlan"); | |
2382 | INIT_WORK(&priv->work, rndis_wext_worker); | |
2383 | INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats); | |
2384 | INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results); | |
2385 | ||
bf164cc0 | 2386 | /* try bind rndis_host */ |
a19d7292 | 2387 | retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS); |
bf164cc0 JK |
2388 | if (retval < 0) |
2389 | goto fail; | |
2390 | ||
2391 | /* generic_rndis_bind set packet filter to multicast_all+ | |
2392 | * promisc mode which doesn't work well for our devices (device | |
2393 | * picks up rssi to closest station instead of to access point). | |
2394 | * | |
2395 | * rndis_host wants to avoid all OID as much as possible | |
2396 | * so do promisc/multicast handling in rndis_wext. | |
2397 | */ | |
23d12e2b DM |
2398 | usbdev->net->netdev_ops = &rndis_wext_netdev_ops; |
2399 | ||
bf164cc0 | 2400 | tmp = RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_BROADCAST; |
a19d7292 | 2401 | retval = rndis_set_oid(usbdev, OID_GEN_CURRENT_PACKET_FILTER, &tmp, |
bf164cc0 JK |
2402 | sizeof(tmp)); |
2403 | ||
2404 | len = sizeof(tmp); | |
a19d7292 JK |
2405 | retval = rndis_query_oid(usbdev, OID_802_3_MAXIMUM_LIST_SIZE, &tmp, |
2406 | &len); | |
bf164cc0 JK |
2407 | priv->multicast_size = le32_to_cpu(tmp); |
2408 | if (retval < 0 || priv->multicast_size < 0) | |
2409 | priv->multicast_size = 0; | |
2410 | if (priv->multicast_size > 0) | |
a19d7292 | 2411 | usbdev->net->flags |= IFF_MULTICAST; |
bf164cc0 | 2412 | else |
a19d7292 | 2413 | usbdev->net->flags &= ~IFF_MULTICAST; |
bf164cc0 JK |
2414 | |
2415 | priv->iwstats.qual.qual = 0; | |
2416 | priv->iwstats.qual.level = 0; | |
2417 | priv->iwstats.qual.updated = IW_QUAL_QUAL_UPDATED | |
2418 | | IW_QUAL_LEVEL_UPDATED | |
2419 | | IW_QUAL_NOISE_INVALID | |
2420 | | IW_QUAL_QUAL_INVALID | |
2421 | | IW_QUAL_LEVEL_INVALID; | |
2422 | ||
5c8fa4f7 JL |
2423 | /* fill-out wiphy structure and register w/ cfg80211 */ |
2424 | memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN); | |
2425 | wiphy->privid = rndis_wiphy_privid; | |
2426 | wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
2427 | | BIT(NL80211_IFTYPE_ADHOC); | |
2428 | wiphy->max_scan_ssids = 1; | |
2429 | ||
2430 | /* TODO: fill-out band information based on priv->caps */ | |
a19d7292 | 2431 | rndis_wext_get_caps(usbdev); |
5c8fa4f7 JL |
2432 | |
2433 | memcpy(priv->channels, rndis_channels, sizeof(rndis_channels)); | |
2434 | memcpy(priv->rates, rndis_rates, sizeof(rndis_rates)); | |
2435 | priv->band.channels = priv->channels; | |
2436 | priv->band.n_channels = ARRAY_SIZE(rndis_channels); | |
2437 | priv->band.bitrates = priv->rates; | |
2438 | priv->band.n_bitrates = ARRAY_SIZE(rndis_rates); | |
2439 | wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band; | |
4d2a369e | 2440 | wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; |
5c8fa4f7 JL |
2441 | |
2442 | set_wiphy_dev(wiphy, &usbdev->udev->dev); | |
2443 | ||
2444 | if (wiphy_register(wiphy)) { | |
eb1a685e JK |
2445 | retval = -ENODEV; |
2446 | goto fail; | |
5c8fa4f7 JL |
2447 | } |
2448 | ||
a19d7292 | 2449 | set_default_iw_params(usbdev); |
bf164cc0 JK |
2450 | |
2451 | /* turn radio on */ | |
2452 | priv->radio_on = 1; | |
a19d7292 JK |
2453 | disassociate(usbdev, 1); |
2454 | netif_carrier_off(usbdev->net); | |
bf164cc0 | 2455 | |
bf164cc0 JK |
2456 | queue_delayed_work(priv->workqueue, &priv->stats_work, |
2457 | round_jiffies_relative(STATS_UPDATE_JIFFIES)); | |
bf164cc0 JK |
2458 | |
2459 | return 0; | |
2460 | ||
2461 | fail: | |
8d4d99ae JK |
2462 | cancel_delayed_work_sync(&priv->stats_work); |
2463 | cancel_delayed_work_sync(&priv->scan_work); | |
2464 | cancel_work_sync(&priv->work); | |
2465 | flush_workqueue(priv->workqueue); | |
2466 | destroy_workqueue(priv->workqueue); | |
2467 | ||
eb1a685e | 2468 | wiphy_free(wiphy); |
bf164cc0 JK |
2469 | return retval; |
2470 | } | |
2471 | ||
2472 | ||
a19d7292 | 2473 | static void rndis_wext_unbind(struct usbnet *usbdev, struct usb_interface *intf) |
bf164cc0 | 2474 | { |
a19d7292 | 2475 | struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); |
bf164cc0 JK |
2476 | |
2477 | /* turn radio off */ | |
a19d7292 | 2478 | disassociate(usbdev, 0); |
bf164cc0 JK |
2479 | |
2480 | cancel_delayed_work_sync(&priv->stats_work); | |
71a7b26d | 2481 | cancel_delayed_work_sync(&priv->scan_work); |
bf164cc0 JK |
2482 | cancel_work_sync(&priv->work); |
2483 | flush_workqueue(priv->workqueue); | |
2484 | destroy_workqueue(priv->workqueue); | |
2485 | ||
2486 | if (priv && priv->wpa_ie_len) | |
2487 | kfree(priv->wpa_ie); | |
bf164cc0 | 2488 | |
a19d7292 | 2489 | rndis_unbind(usbdev, intf); |
5c8fa4f7 JL |
2490 | |
2491 | wiphy_unregister(priv->wdev.wiphy); | |
2492 | wiphy_free(priv->wdev.wiphy); | |
bf164cc0 JK |
2493 | } |
2494 | ||
2495 | ||
a19d7292 | 2496 | static int rndis_wext_reset(struct usbnet *usbdev) |
bf164cc0 | 2497 | { |
a19d7292 | 2498 | return deauthenticate(usbdev); |
bf164cc0 JK |
2499 | } |
2500 | ||
2501 | ||
2502 | static const struct driver_info bcm4320b_info = { | |
2503 | .description = "Wireless RNDIS device, BCM4320b based", | |
2504 | .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT, | |
2505 | .bind = rndis_wext_bind, | |
2506 | .unbind = rndis_wext_unbind, | |
2507 | .status = rndis_status, | |
2508 | .rx_fixup = rndis_rx_fixup, | |
2509 | .tx_fixup = rndis_tx_fixup, | |
2510 | .reset = rndis_wext_reset, | |
59620e9f | 2511 | .early_init = bcm4320b_early_init, |
bf164cc0 JK |
2512 | .link_change = rndis_wext_link_change, |
2513 | }; | |
2514 | ||
2515 | static const struct driver_info bcm4320a_info = { | |
2516 | .description = "Wireless RNDIS device, BCM4320a based", | |
2517 | .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT, | |
2518 | .bind = rndis_wext_bind, | |
2519 | .unbind = rndis_wext_unbind, | |
2520 | .status = rndis_status, | |
2521 | .rx_fixup = rndis_rx_fixup, | |
2522 | .tx_fixup = rndis_tx_fixup, | |
2523 | .reset = rndis_wext_reset, | |
59620e9f | 2524 | .early_init = bcm4320a_early_init, |
bf164cc0 JK |
2525 | .link_change = rndis_wext_link_change, |
2526 | }; | |
2527 | ||
2528 | static const struct driver_info rndis_wext_info = { | |
2529 | .description = "Wireless RNDIS device", | |
2530 | .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT, | |
2531 | .bind = rndis_wext_bind, | |
2532 | .unbind = rndis_wext_unbind, | |
2533 | .status = rndis_status, | |
2534 | .rx_fixup = rndis_rx_fixup, | |
2535 | .tx_fixup = rndis_tx_fixup, | |
2536 | .reset = rndis_wext_reset, | |
59620e9f | 2537 | .early_init = bcm4320a_early_init, |
bf164cc0 JK |
2538 | .link_change = rndis_wext_link_change, |
2539 | }; | |
2540 | ||
2541 | /*-------------------------------------------------------------------------*/ | |
2542 | ||
2543 | static const struct usb_device_id products [] = { | |
2544 | #define RNDIS_MASTER_INTERFACE \ | |
2545 | .bInterfaceClass = USB_CLASS_COMM, \ | |
2546 | .bInterfaceSubClass = 2 /* ACM */, \ | |
2547 | .bInterfaceProtocol = 0x0ff | |
2548 | ||
2549 | /* INF driver for these devices have DriverVer >= 4.xx.xx.xx and many custom | |
2550 | * parameters available. Chipset marked as 'BCM4320SKFBG' in NDISwrapper-wiki. | |
2551 | */ | |
2552 | { | |
2553 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2554 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2555 | .idVendor = 0x0411, | |
2556 | .idProduct = 0x00bc, /* Buffalo WLI-U2-KG125S */ | |
2557 | RNDIS_MASTER_INTERFACE, | |
2558 | .driver_info = (unsigned long) &bcm4320b_info, | |
2559 | }, { | |
2560 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2561 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2562 | .idVendor = 0x0baf, | |
2563 | .idProduct = 0x011b, /* U.S. Robotics USR5421 */ | |
2564 | RNDIS_MASTER_INTERFACE, | |
2565 | .driver_info = (unsigned long) &bcm4320b_info, | |
2566 | }, { | |
2567 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2568 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2569 | .idVendor = 0x050d, | |
2570 | .idProduct = 0x011b, /* Belkin F5D7051 */ | |
2571 | RNDIS_MASTER_INTERFACE, | |
2572 | .driver_info = (unsigned long) &bcm4320b_info, | |
2573 | }, { | |
2574 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2575 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2576 | .idVendor = 0x1799, /* Belkin has two vendor ids */ | |
2577 | .idProduct = 0x011b, /* Belkin F5D7051 */ | |
2578 | RNDIS_MASTER_INTERFACE, | |
2579 | .driver_info = (unsigned long) &bcm4320b_info, | |
2580 | }, { | |
2581 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2582 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2583 | .idVendor = 0x13b1, | |
2584 | .idProduct = 0x0014, /* Linksys WUSB54GSv2 */ | |
2585 | RNDIS_MASTER_INTERFACE, | |
2586 | .driver_info = (unsigned long) &bcm4320b_info, | |
2587 | }, { | |
2588 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2589 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2590 | .idVendor = 0x13b1, | |
2591 | .idProduct = 0x0026, /* Linksys WUSB54GSC */ | |
2592 | RNDIS_MASTER_INTERFACE, | |
2593 | .driver_info = (unsigned long) &bcm4320b_info, | |
2594 | }, { | |
2595 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2596 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2597 | .idVendor = 0x0b05, | |
2598 | .idProduct = 0x1717, /* Asus WL169gE */ | |
2599 | RNDIS_MASTER_INTERFACE, | |
2600 | .driver_info = (unsigned long) &bcm4320b_info, | |
2601 | }, { | |
2602 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2603 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2604 | .idVendor = 0x0a5c, | |
2605 | .idProduct = 0xd11b, /* Eminent EM4045 */ | |
2606 | RNDIS_MASTER_INTERFACE, | |
2607 | .driver_info = (unsigned long) &bcm4320b_info, | |
2608 | }, { | |
2609 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2610 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2611 | .idVendor = 0x1690, | |
2612 | .idProduct = 0x0715, /* BT Voyager 1055 */ | |
2613 | RNDIS_MASTER_INTERFACE, | |
2614 | .driver_info = (unsigned long) &bcm4320b_info, | |
2615 | }, | |
2616 | /* These devices have DriverVer < 4.xx.xx.xx and do not have any custom | |
2617 | * parameters available, hardware probably contain older firmware version with | |
2618 | * no way of updating. Chipset marked as 'BCM4320????' in NDISwrapper-wiki. | |
2619 | */ | |
2620 | { | |
2621 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2622 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2623 | .idVendor = 0x13b1, | |
2624 | .idProduct = 0x000e, /* Linksys WUSB54GSv1 */ | |
2625 | RNDIS_MASTER_INTERFACE, | |
2626 | .driver_info = (unsigned long) &bcm4320a_info, | |
2627 | }, { | |
2628 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2629 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2630 | .idVendor = 0x0baf, | |
2631 | .idProduct = 0x0111, /* U.S. Robotics USR5420 */ | |
2632 | RNDIS_MASTER_INTERFACE, | |
2633 | .driver_info = (unsigned long) &bcm4320a_info, | |
2634 | }, { | |
2635 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | |
2636 | | USB_DEVICE_ID_MATCH_DEVICE, | |
2637 | .idVendor = 0x0411, | |
2638 | .idProduct = 0x004b, /* BUFFALO WLI-USB-G54 */ | |
2639 | RNDIS_MASTER_INTERFACE, | |
2640 | .driver_info = (unsigned long) &bcm4320a_info, | |
2641 | }, | |
2642 | /* Generic Wireless RNDIS devices that we don't have exact | |
2643 | * idVendor/idProduct/chip yet. | |
2644 | */ | |
2645 | { | |
2646 | /* RNDIS is MSFT's un-official variant of CDC ACM */ | |
2647 | USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff), | |
2648 | .driver_info = (unsigned long) &rndis_wext_info, | |
2649 | }, { | |
2650 | /* "ActiveSync" is an undocumented variant of RNDIS, used in WM5 */ | |
2651 | USB_INTERFACE_INFO(USB_CLASS_MISC, 1, 1), | |
2652 | .driver_info = (unsigned long) &rndis_wext_info, | |
2653 | }, | |
2654 | { }, // END | |
2655 | }; | |
2656 | MODULE_DEVICE_TABLE(usb, products); | |
2657 | ||
2658 | static struct usb_driver rndis_wlan_driver = { | |
2659 | .name = "rndis_wlan", | |
2660 | .id_table = products, | |
2661 | .probe = usbnet_probe, | |
2662 | .disconnect = usbnet_disconnect, | |
2663 | .suspend = usbnet_suspend, | |
2664 | .resume = usbnet_resume, | |
2665 | }; | |
2666 | ||
2667 | static int __init rndis_wlan_init(void) | |
2668 | { | |
2669 | return usb_register(&rndis_wlan_driver); | |
2670 | } | |
2671 | module_init(rndis_wlan_init); | |
2672 | ||
2673 | static void __exit rndis_wlan_exit(void) | |
2674 | { | |
2675 | usb_deregister(&rndis_wlan_driver); | |
2676 | } | |
2677 | module_exit(rndis_wlan_exit); | |
2678 | ||
2679 | MODULE_AUTHOR("Bjorge Dijkstra"); | |
2680 | MODULE_AUTHOR("Jussi Kivilinna"); | |
2681 | MODULE_DESCRIPTION("Driver for RNDIS based USB Wireless adapters"); | |
2682 | MODULE_LICENSE("GPL"); | |
2683 |