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