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