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