Commit | Line | Data |
---|---|---|
bdcd8170 KV |
1 | /* |
2 | * Copyright (c) 2004-2011 Atheros Communications Inc. | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include "core.h" | |
18 | #include "cfg80211.h" | |
19 | #include "debug.h" | |
abcb344b | 20 | #include "hif-ops.h" |
bdcd8170 KV |
21 | |
22 | #define RATETAB_ENT(_rate, _rateid, _flags) { \ | |
23 | .bitrate = (_rate), \ | |
24 | .flags = (_flags), \ | |
25 | .hw_value = (_rateid), \ | |
26 | } | |
27 | ||
28 | #define CHAN2G(_channel, _freq, _flags) { \ | |
29 | .band = IEEE80211_BAND_2GHZ, \ | |
30 | .hw_value = (_channel), \ | |
31 | .center_freq = (_freq), \ | |
32 | .flags = (_flags), \ | |
33 | .max_antenna_gain = 0, \ | |
34 | .max_power = 30, \ | |
35 | } | |
36 | ||
37 | #define CHAN5G(_channel, _flags) { \ | |
38 | .band = IEEE80211_BAND_5GHZ, \ | |
39 | .hw_value = (_channel), \ | |
40 | .center_freq = 5000 + (5 * (_channel)), \ | |
41 | .flags = (_flags), \ | |
42 | .max_antenna_gain = 0, \ | |
43 | .max_power = 30, \ | |
44 | } | |
45 | ||
46 | static struct ieee80211_rate ath6kl_rates[] = { | |
47 | RATETAB_ENT(10, 0x1, 0), | |
48 | RATETAB_ENT(20, 0x2, 0), | |
49 | RATETAB_ENT(55, 0x4, 0), | |
50 | RATETAB_ENT(110, 0x8, 0), | |
51 | RATETAB_ENT(60, 0x10, 0), | |
52 | RATETAB_ENT(90, 0x20, 0), | |
53 | RATETAB_ENT(120, 0x40, 0), | |
54 | RATETAB_ENT(180, 0x80, 0), | |
55 | RATETAB_ENT(240, 0x100, 0), | |
56 | RATETAB_ENT(360, 0x200, 0), | |
57 | RATETAB_ENT(480, 0x400, 0), | |
58 | RATETAB_ENT(540, 0x800, 0), | |
59 | }; | |
60 | ||
61 | #define ath6kl_a_rates (ath6kl_rates + 4) | |
62 | #define ath6kl_a_rates_size 8 | |
63 | #define ath6kl_g_rates (ath6kl_rates + 0) | |
64 | #define ath6kl_g_rates_size 12 | |
65 | ||
66 | static struct ieee80211_channel ath6kl_2ghz_channels[] = { | |
67 | CHAN2G(1, 2412, 0), | |
68 | CHAN2G(2, 2417, 0), | |
69 | CHAN2G(3, 2422, 0), | |
70 | CHAN2G(4, 2427, 0), | |
71 | CHAN2G(5, 2432, 0), | |
72 | CHAN2G(6, 2437, 0), | |
73 | CHAN2G(7, 2442, 0), | |
74 | CHAN2G(8, 2447, 0), | |
75 | CHAN2G(9, 2452, 0), | |
76 | CHAN2G(10, 2457, 0), | |
77 | CHAN2G(11, 2462, 0), | |
78 | CHAN2G(12, 2467, 0), | |
79 | CHAN2G(13, 2472, 0), | |
80 | CHAN2G(14, 2484, 0), | |
81 | }; | |
82 | ||
83 | static struct ieee80211_channel ath6kl_5ghz_a_channels[] = { | |
84 | CHAN5G(34, 0), CHAN5G(36, 0), | |
85 | CHAN5G(38, 0), CHAN5G(40, 0), | |
86 | CHAN5G(42, 0), CHAN5G(44, 0), | |
87 | CHAN5G(46, 0), CHAN5G(48, 0), | |
88 | CHAN5G(52, 0), CHAN5G(56, 0), | |
89 | CHAN5G(60, 0), CHAN5G(64, 0), | |
90 | CHAN5G(100, 0), CHAN5G(104, 0), | |
91 | CHAN5G(108, 0), CHAN5G(112, 0), | |
92 | CHAN5G(116, 0), CHAN5G(120, 0), | |
93 | CHAN5G(124, 0), CHAN5G(128, 0), | |
94 | CHAN5G(132, 0), CHAN5G(136, 0), | |
95 | CHAN5G(140, 0), CHAN5G(149, 0), | |
96 | CHAN5G(153, 0), CHAN5G(157, 0), | |
97 | CHAN5G(161, 0), CHAN5G(165, 0), | |
98 | CHAN5G(184, 0), CHAN5G(188, 0), | |
99 | CHAN5G(192, 0), CHAN5G(196, 0), | |
100 | CHAN5G(200, 0), CHAN5G(204, 0), | |
101 | CHAN5G(208, 0), CHAN5G(212, 0), | |
102 | CHAN5G(216, 0), | |
103 | }; | |
104 | ||
105 | static struct ieee80211_supported_band ath6kl_band_2ghz = { | |
106 | .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels), | |
107 | .channels = ath6kl_2ghz_channels, | |
108 | .n_bitrates = ath6kl_g_rates_size, | |
109 | .bitrates = ath6kl_g_rates, | |
110 | }; | |
111 | ||
112 | static struct ieee80211_supported_band ath6kl_band_5ghz = { | |
113 | .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels), | |
114 | .channels = ath6kl_5ghz_a_channels, | |
115 | .n_bitrates = ath6kl_a_rates_size, | |
116 | .bitrates = ath6kl_a_rates, | |
117 | }; | |
118 | ||
119 | static int ath6kl_set_wpa_version(struct ath6kl *ar, | |
120 | enum nl80211_wpa_versions wpa_version) | |
121 | { | |
122 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version); | |
123 | ||
124 | if (!wpa_version) { | |
125 | ar->auth_mode = NONE_AUTH; | |
126 | } else if (wpa_version & NL80211_WPA_VERSION_2) { | |
127 | ar->auth_mode = WPA2_AUTH; | |
128 | } else if (wpa_version & NL80211_WPA_VERSION_1) { | |
129 | ar->auth_mode = WPA_AUTH; | |
130 | } else { | |
131 | ath6kl_err("%s: %u not supported\n", __func__, wpa_version); | |
132 | return -ENOTSUPP; | |
133 | } | |
134 | ||
135 | return 0; | |
136 | } | |
137 | ||
138 | static int ath6kl_set_auth_type(struct ath6kl *ar, | |
139 | enum nl80211_auth_type auth_type) | |
140 | { | |
141 | ||
142 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type); | |
143 | ||
144 | switch (auth_type) { | |
145 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
146 | ar->dot11_auth_mode = OPEN_AUTH; | |
147 | break; | |
148 | case NL80211_AUTHTYPE_SHARED_KEY: | |
149 | ar->dot11_auth_mode = SHARED_AUTH; | |
150 | break; | |
151 | case NL80211_AUTHTYPE_NETWORK_EAP: | |
152 | ar->dot11_auth_mode = LEAP_AUTH; | |
153 | break; | |
154 | ||
155 | case NL80211_AUTHTYPE_AUTOMATIC: | |
156 | ar->dot11_auth_mode = OPEN_AUTH; | |
157 | ar->auto_auth_stage = AUTH_OPEN_IN_PROGRESS; | |
158 | break; | |
159 | ||
160 | default: | |
161 | ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type); | |
162 | return -ENOTSUPP; | |
163 | } | |
164 | ||
165 | return 0; | |
166 | } | |
167 | ||
168 | static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast) | |
169 | { | |
170 | u8 *ar_cipher = ucast ? &ar->prwise_crypto : &ar->grp_crypto; | |
171 | u8 *ar_cipher_len = ucast ? &ar->prwise_crypto_len : &ar->grp_crpto_len; | |
172 | ||
173 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n", | |
174 | __func__, cipher, ucast); | |
175 | ||
176 | switch (cipher) { | |
177 | case 0: | |
178 | /* our own hack to use value 0 as no crypto used */ | |
179 | *ar_cipher = NONE_CRYPT; | |
180 | *ar_cipher_len = 0; | |
181 | break; | |
182 | case WLAN_CIPHER_SUITE_WEP40: | |
183 | *ar_cipher = WEP_CRYPT; | |
184 | *ar_cipher_len = 5; | |
185 | break; | |
186 | case WLAN_CIPHER_SUITE_WEP104: | |
187 | *ar_cipher = WEP_CRYPT; | |
188 | *ar_cipher_len = 13; | |
189 | break; | |
190 | case WLAN_CIPHER_SUITE_TKIP: | |
191 | *ar_cipher = TKIP_CRYPT; | |
192 | *ar_cipher_len = 0; | |
193 | break; | |
194 | case WLAN_CIPHER_SUITE_CCMP: | |
195 | *ar_cipher = AES_CRYPT; | |
196 | *ar_cipher_len = 0; | |
197 | break; | |
198 | default: | |
199 | ath6kl_err("cipher 0x%x not supported\n", cipher); | |
200 | return -ENOTSUPP; | |
201 | } | |
202 | ||
203 | return 0; | |
204 | } | |
205 | ||
206 | static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt) | |
207 | { | |
208 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt); | |
209 | ||
210 | if (key_mgmt == WLAN_AKM_SUITE_PSK) { | |
211 | if (ar->auth_mode == WPA_AUTH) | |
212 | ar->auth_mode = WPA_PSK_AUTH; | |
213 | else if (ar->auth_mode == WPA2_AUTH) | |
214 | ar->auth_mode = WPA2_PSK_AUTH; | |
215 | } else if (key_mgmt != WLAN_AKM_SUITE_8021X) { | |
216 | ar->auth_mode = NONE_AUTH; | |
217 | } | |
218 | } | |
219 | ||
220 | static bool ath6kl_cfg80211_ready(struct ath6kl *ar) | |
221 | { | |
222 | if (!test_bit(WMI_READY, &ar->flag)) { | |
223 | ath6kl_err("wmi is not ready\n"); | |
224 | return false; | |
225 | } | |
226 | ||
575b5f34 | 227 | if (!test_bit(WLAN_ENABLED, &ar->flag)) { |
bdcd8170 KV |
228 | ath6kl_err("wlan disabled\n"); |
229 | return false; | |
230 | } | |
231 | ||
232 | return true; | |
233 | } | |
234 | ||
235 | static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev, | |
236 | struct cfg80211_connect_params *sme) | |
237 | { | |
238 | struct ath6kl *ar = ath6kl_priv(dev); | |
239 | int status; | |
240 | ||
241 | ar->sme_state = SME_CONNECTING; | |
242 | ||
243 | if (!ath6kl_cfg80211_ready(ar)) | |
244 | return -EIO; | |
245 | ||
246 | if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { | |
247 | ath6kl_err("destroy in progress\n"); | |
248 | return -EBUSY; | |
249 | } | |
250 | ||
251 | if (test_bit(SKIP_SCAN, &ar->flag) && | |
252 | ((sme->channel && sme->channel->center_freq == 0) || | |
253 | (sme->bssid && is_zero_ether_addr(sme->bssid)))) { | |
254 | ath6kl_err("SkipScan: channel or bssid invalid\n"); | |
255 | return -EINVAL; | |
256 | } | |
257 | ||
258 | if (down_interruptible(&ar->sem)) { | |
259 | ath6kl_err("busy, couldn't get access\n"); | |
260 | return -ERESTARTSYS; | |
261 | } | |
262 | ||
263 | if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { | |
264 | ath6kl_err("busy, destroy in progress\n"); | |
265 | up(&ar->sem); | |
266 | return -EBUSY; | |
267 | } | |
268 | ||
269 | if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) { | |
270 | /* | |
271 | * sleep until the command queue drains | |
272 | */ | |
273 | wait_event_interruptible_timeout(ar->event_wq, | |
274 | ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0, | |
275 | WMI_TIMEOUT); | |
276 | if (signal_pending(current)) { | |
277 | ath6kl_err("cmd queue drain timeout\n"); | |
278 | up(&ar->sem); | |
279 | return -EINTR; | |
280 | } | |
281 | } | |
282 | ||
283 | if (test_bit(CONNECTED, &ar->flag) && | |
284 | ar->ssid_len == sme->ssid_len && | |
285 | !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) { | |
286 | ar->reconnect_flag = true; | |
287 | status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid, | |
288 | ar->ch_hint); | |
289 | ||
290 | up(&ar->sem); | |
291 | if (status) { | |
292 | ath6kl_err("wmi_reconnect_cmd failed\n"); | |
293 | return -EIO; | |
294 | } | |
295 | return 0; | |
296 | } else if (ar->ssid_len == sme->ssid_len && | |
297 | !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) { | |
298 | ath6kl_disconnect(ar); | |
299 | } | |
300 | ||
301 | memset(ar->ssid, 0, sizeof(ar->ssid)); | |
302 | ar->ssid_len = sme->ssid_len; | |
303 | memcpy(ar->ssid, sme->ssid, sme->ssid_len); | |
304 | ||
305 | if (sme->channel) | |
306 | ar->ch_hint = sme->channel->center_freq; | |
307 | ||
308 | memset(ar->req_bssid, 0, sizeof(ar->req_bssid)); | |
309 | if (sme->bssid && !is_broadcast_ether_addr(sme->bssid)) | |
310 | memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid)); | |
311 | ||
312 | ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions); | |
313 | ||
314 | status = ath6kl_set_auth_type(ar, sme->auth_type); | |
315 | if (status) { | |
316 | up(&ar->sem); | |
317 | return status; | |
318 | } | |
319 | ||
320 | if (sme->crypto.n_ciphers_pairwise) | |
321 | ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true); | |
322 | else | |
323 | ath6kl_set_cipher(ar, 0, true); | |
324 | ||
325 | ath6kl_set_cipher(ar, sme->crypto.cipher_group, false); | |
326 | ||
327 | if (sme->crypto.n_akm_suites) | |
328 | ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]); | |
329 | ||
330 | if ((sme->key_len) && | |
331 | (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) { | |
332 | struct ath6kl_key *key = NULL; | |
333 | ||
334 | if (sme->key_idx < WMI_MIN_KEY_INDEX || | |
335 | sme->key_idx > WMI_MAX_KEY_INDEX) { | |
336 | ath6kl_err("key index %d out of bounds\n", | |
337 | sme->key_idx); | |
338 | up(&ar->sem); | |
339 | return -ENOENT; | |
340 | } | |
341 | ||
342 | key = &ar->keys[sme->key_idx]; | |
343 | key->key_len = sme->key_len; | |
344 | memcpy(key->key, sme->key, key->key_len); | |
345 | key->cipher = ar->prwise_crypto; | |
346 | ar->def_txkey_index = sme->key_idx; | |
347 | ||
348 | ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx, | |
349 | ar->prwise_crypto, | |
350 | GROUP_USAGE | TX_USAGE, | |
351 | key->key_len, | |
352 | NULL, | |
353 | key->key, KEY_OP_INIT_VAL, NULL, | |
354 | NO_SYNC_WMIFLAG); | |
355 | } | |
356 | ||
357 | if (!ar->usr_bss_filter) { | |
358 | if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) { | |
359 | ath6kl_err("couldn't set bss filtering\n"); | |
360 | up(&ar->sem); | |
361 | return -EIO; | |
362 | } | |
363 | } | |
364 | ||
365 | ar->nw_type = ar->next_mode; | |
366 | ||
367 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
368 | "%s: connect called with authmode %d dot11 auth %d" | |
369 | " PW crypto %d PW crypto len %d GRP crypto %d" | |
370 | " GRP crypto len %d channel hint %u\n", | |
371 | __func__, | |
372 | ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto, | |
373 | ar->prwise_crypto_len, ar->grp_crypto, | |
374 | ar->grp_crpto_len, ar->ch_hint); | |
375 | ||
376 | ar->reconnect_flag = 0; | |
377 | status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type, | |
378 | ar->dot11_auth_mode, ar->auth_mode, | |
379 | ar->prwise_crypto, | |
380 | ar->prwise_crypto_len, | |
381 | ar->grp_crypto, ar->grp_crpto_len, | |
382 | ar->ssid_len, ar->ssid, | |
383 | ar->req_bssid, ar->ch_hint, | |
384 | ar->connect_ctrl_flags); | |
385 | ||
386 | up(&ar->sem); | |
387 | ||
388 | if (status == -EINVAL) { | |
389 | memset(ar->ssid, 0, sizeof(ar->ssid)); | |
390 | ar->ssid_len = 0; | |
391 | ath6kl_err("invalid request\n"); | |
392 | return -ENOENT; | |
393 | } else if (status) { | |
394 | ath6kl_err("ath6kl_wmi_connect_cmd failed\n"); | |
395 | return -EIO; | |
396 | } | |
397 | ||
398 | if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) && | |
399 | ((ar->auth_mode == WPA_PSK_AUTH) | |
400 | || (ar->auth_mode == WPA2_PSK_AUTH))) { | |
401 | mod_timer(&ar->disconnect_timer, | |
402 | jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL)); | |
403 | } | |
404 | ||
405 | ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD; | |
406 | set_bit(CONNECT_PEND, &ar->flag); | |
407 | ||
408 | return 0; | |
409 | } | |
410 | ||
411 | void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel, | |
412 | u8 *bssid, u16 listen_intvl, | |
413 | u16 beacon_intvl, | |
414 | enum network_type nw_type, | |
415 | u8 beacon_ie_len, u8 assoc_req_len, | |
416 | u8 assoc_resp_len, u8 *assoc_info) | |
417 | { | |
418 | u16 size = 0; | |
419 | u16 capability = 0; | |
420 | struct cfg80211_bss *bss = NULL; | |
421 | struct ieee80211_mgmt *mgmt = NULL; | |
422 | struct ieee80211_channel *ibss_ch = NULL; | |
423 | s32 signal = 50 * 100; | |
424 | u8 ie_buf_len = 0; | |
425 | unsigned char ie_buf[256]; | |
426 | unsigned char *ptr_ie_buf = ie_buf; | |
427 | unsigned char *ieeemgmtbuf = NULL; | |
428 | u8 source_mac[ETH_ALEN]; | |
bdcd8170 KV |
429 | |
430 | /* capinfo + listen interval */ | |
431 | u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16); | |
432 | ||
433 | /* capinfo + status code + associd */ | |
434 | u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16); | |
435 | ||
436 | u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset; | |
437 | u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len + | |
438 | assoc_resp_ie_offset; | |
439 | ||
440 | assoc_req_len -= assoc_req_ie_offset; | |
441 | assoc_resp_len -= assoc_resp_ie_offset; | |
442 | ||
443 | ar->auto_auth_stage = AUTH_IDLE; | |
444 | ||
445 | if (nw_type & ADHOC_NETWORK) { | |
446 | if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) { | |
447 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
448 | "%s: ath6k not in ibss mode\n", __func__); | |
449 | return; | |
450 | } | |
451 | } | |
452 | ||
453 | if (nw_type & INFRA_NETWORK) { | |
454 | if (ar->wdev->iftype != NL80211_IFTYPE_STATION) { | |
455 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
456 | "%s: ath6k not in station mode\n", __func__); | |
457 | return; | |
458 | } | |
459 | } | |
460 | ||
bdcd8170 KV |
461 | /* |
462 | * Earlier we were updating the cfg about bss by making a beacon frame | |
463 | * only if the entry for bss is not there. This can have some issue if | |
464 | * ROAM event is generated and a heavy traffic is ongoing. The ROAM | |
465 | * event is handled through a work queue and by the time it really gets | |
466 | * handled, BSS would have been aged out. So it is better to update the | |
467 | * cfg about BSS irrespective of its entry being present right now or | |
468 | * not. | |
469 | */ | |
470 | ||
471 | if (nw_type & ADHOC_NETWORK) { | |
472 | /* construct 802.11 mgmt beacon */ | |
473 | if (ptr_ie_buf) { | |
474 | *ptr_ie_buf++ = WLAN_EID_SSID; | |
475 | *ptr_ie_buf++ = ar->ssid_len; | |
476 | memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len); | |
477 | ptr_ie_buf += ar->ssid_len; | |
478 | ||
479 | *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS; | |
480 | *ptr_ie_buf++ = 2; /* length */ | |
481 | *ptr_ie_buf++ = 0; /* ATIM window */ | |
482 | *ptr_ie_buf++ = 0; /* ATIM window */ | |
483 | ||
484 | /* TODO: update ibss params and include supported rates, | |
485 | * DS param set, extened support rates, wmm. */ | |
486 | ||
487 | ie_buf_len = ptr_ie_buf - ie_buf; | |
488 | } | |
489 | ||
490 | capability |= WLAN_CAPABILITY_IBSS; | |
491 | ||
492 | if (ar->prwise_crypto == WEP_CRYPT) | |
493 | capability |= WLAN_CAPABILITY_PRIVACY; | |
494 | ||
495 | memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN); | |
496 | ptr_ie_buf = ie_buf; | |
497 | } else { | |
498 | capability = *(u16 *) (&assoc_info[beacon_ie_len]); | |
499 | memcpy(source_mac, bssid, ETH_ALEN); | |
500 | ptr_ie_buf = assoc_req_ie; | |
501 | ie_buf_len = assoc_req_len; | |
502 | } | |
503 | ||
504 | size = offsetof(struct ieee80211_mgmt, u) | |
505 | + sizeof(mgmt->u.beacon) | |
506 | + ie_buf_len; | |
507 | ||
508 | ieeemgmtbuf = kzalloc(size, GFP_ATOMIC); | |
509 | if (!ieeemgmtbuf) { | |
510 | ath6kl_err("ieee mgmt buf alloc error\n"); | |
bdcd8170 KV |
511 | return; |
512 | } | |
513 | ||
514 | mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf; | |
515 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
516 | IEEE80211_STYPE_BEACON); | |
517 | memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */ | |
518 | memcpy(mgmt->sa, source_mac, ETH_ALEN); | |
519 | memcpy(mgmt->bssid, bssid, ETH_ALEN); | |
520 | mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl); | |
521 | mgmt->u.beacon.capab_info = cpu_to_le16(capability); | |
522 | memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len); | |
523 | ||
524 | ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel); | |
525 | ||
526 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
527 | "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n", | |
528 | __func__, mgmt->bssid, ibss_ch->hw_value, | |
529 | beacon_intvl, capability); | |
530 | ||
531 | bss = cfg80211_inform_bss_frame(ar->wdev->wiphy, | |
532 | ibss_ch, mgmt, | |
533 | size, signal, GFP_KERNEL); | |
534 | kfree(ieeemgmtbuf); | |
535 | cfg80211_put_bss(bss); | |
536 | ||
537 | if (nw_type & ADHOC_NETWORK) { | |
538 | cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL); | |
539 | return; | |
540 | } | |
541 | ||
9aa60357 | 542 | if (ar->sme_state == SME_CONNECTING) { |
bdcd8170 | 543 | /* inform connect result to cfg80211 */ |
9aa60357 | 544 | ar->sme_state = SME_CONNECTED; |
bdcd8170 KV |
545 | cfg80211_connect_result(ar->net_dev, bssid, |
546 | assoc_req_ie, assoc_req_len, | |
547 | assoc_resp_ie, assoc_resp_len, | |
548 | WLAN_STATUS_SUCCESS, GFP_KERNEL); | |
9aa60357 | 549 | } else if (ar->sme_state == SME_CONNECTED) { |
bdcd8170 KV |
550 | /* inform roam event to cfg80211 */ |
551 | cfg80211_roamed(ar->net_dev, ibss_ch, bssid, | |
552 | assoc_req_ie, assoc_req_len, | |
553 | assoc_resp_ie, assoc_resp_len, GFP_KERNEL); | |
554 | } | |
555 | } | |
556 | ||
557 | static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy, | |
558 | struct net_device *dev, u16 reason_code) | |
559 | { | |
560 | struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev); | |
561 | ||
562 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__, | |
563 | reason_code); | |
564 | ||
565 | if (!ath6kl_cfg80211_ready(ar)) | |
566 | return -EIO; | |
567 | ||
568 | if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { | |
569 | ath6kl_err("busy, destroy in progress\n"); | |
570 | return -EBUSY; | |
571 | } | |
572 | ||
573 | if (down_interruptible(&ar->sem)) { | |
574 | ath6kl_err("busy, couldn't get access\n"); | |
575 | return -ERESTARTSYS; | |
576 | } | |
577 | ||
578 | ar->reconnect_flag = 0; | |
579 | ath6kl_disconnect(ar); | |
580 | memset(ar->ssid, 0, sizeof(ar->ssid)); | |
581 | ar->ssid_len = 0; | |
582 | ||
583 | if (!test_bit(SKIP_SCAN, &ar->flag)) | |
584 | memset(ar->req_bssid, 0, sizeof(ar->req_bssid)); | |
585 | ||
586 | up(&ar->sem); | |
587 | ||
588 | return 0; | |
589 | } | |
590 | ||
591 | void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason, | |
592 | u8 *bssid, u8 assoc_resp_len, | |
593 | u8 *assoc_info, u16 proto_reason) | |
594 | { | |
595 | struct ath6kl_key *key = NULL; | |
596 | u16 status; | |
597 | ||
598 | if (ar->scan_req) { | |
599 | cfg80211_scan_done(ar->scan_req, true); | |
600 | ar->scan_req = NULL; | |
601 | } | |
602 | ||
603 | if (ar->nw_type & ADHOC_NETWORK) { | |
604 | if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) { | |
605 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
606 | "%s: ath6k not in ibss mode\n", __func__); | |
607 | return; | |
608 | } | |
609 | memset(bssid, 0, ETH_ALEN); | |
610 | cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL); | |
611 | return; | |
612 | } | |
613 | ||
614 | if (ar->nw_type & INFRA_NETWORK) { | |
615 | if (ar->wdev->iftype != NL80211_IFTYPE_STATION) { | |
616 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
617 | "%s: ath6k not in station mode\n", __func__); | |
618 | return; | |
619 | } | |
620 | } | |
621 | ||
622 | if (!test_bit(CONNECT_PEND, &ar->flag)) { | |
623 | if (reason != DISCONNECT_CMD) | |
624 | ath6kl_wmi_disconnect_cmd(ar->wmi); | |
625 | ||
626 | return; | |
627 | } | |
628 | ||
629 | if (reason == NO_NETWORK_AVAIL) { | |
630 | /* connect cmd failed */ | |
631 | ath6kl_wmi_disconnect_cmd(ar->wmi); | |
632 | return; | |
633 | } | |
634 | ||
635 | if (reason != DISCONNECT_CMD) | |
636 | return; | |
637 | ||
638 | if (!ar->auto_auth_stage) { | |
639 | clear_bit(CONNECT_PEND, &ar->flag); | |
640 | ||
641 | if (ar->sme_state == SME_CONNECTING) { | |
642 | cfg80211_connect_result(ar->net_dev, | |
643 | bssid, NULL, 0, | |
644 | NULL, 0, | |
645 | WLAN_STATUS_UNSPECIFIED_FAILURE, | |
646 | GFP_KERNEL); | |
0e5cc8e6 | 647 | } else if (ar->sme_state == SME_CONNECTED) { |
bdcd8170 KV |
648 | cfg80211_disconnected(ar->net_dev, reason, |
649 | NULL, 0, GFP_KERNEL); | |
650 | } | |
651 | ||
652 | ar->sme_state = SME_DISCONNECTED; | |
653 | return; | |
654 | } | |
655 | ||
656 | if (ar->dot11_auth_mode != OPEN_AUTH) | |
657 | return; | |
658 | ||
659 | /* | |
660 | * If the current auth algorithm is open, try shared and | |
661 | * make autoAuthStage idle. We do not make it leap for now | |
662 | * being. | |
663 | */ | |
664 | key = &ar->keys[ar->def_txkey_index]; | |
665 | if (down_interruptible(&ar->sem)) { | |
666 | ath6kl_err("busy, couldn't get access\n"); | |
667 | return; | |
668 | } | |
669 | ||
670 | ar->dot11_auth_mode = SHARED_AUTH; | |
671 | ar->auto_auth_stage = AUTH_IDLE; | |
672 | ||
673 | ath6kl_wmi_addkey_cmd(ar->wmi, | |
674 | ar->def_txkey_index, | |
675 | ar->prwise_crypto, | |
676 | GROUP_USAGE | TX_USAGE, | |
677 | key->key_len, NULL, | |
678 | key->key, | |
679 | KEY_OP_INIT_VAL, NULL, | |
680 | NO_SYNC_WMIFLAG); | |
681 | ||
682 | status = ath6kl_wmi_connect_cmd(ar->wmi, | |
683 | ar->nw_type, | |
684 | ar->dot11_auth_mode, | |
685 | ar->auth_mode, | |
686 | ar->prwise_crypto, | |
687 | ar->prwise_crypto_len, | |
688 | ar->grp_crypto, | |
689 | ar->grp_crpto_len, | |
690 | ar->ssid_len, | |
691 | ar->ssid, | |
692 | ar->req_bssid, | |
693 | ar->ch_hint, | |
694 | ar->connect_ctrl_flags); | |
695 | up(&ar->sem); | |
696 | } | |
697 | ||
698 | static inline bool is_ch_11a(u16 ch) | |
699 | { | |
700 | return (!((ch >= 2412) && (ch <= 2484))); | |
701 | } | |
702 | ||
cf104c2a | 703 | /* struct ath6kl_node_table::nt_nodelock is locked when calling this */ |
91db35da | 704 | void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni) |
bdcd8170 | 705 | { |
bdcd8170 KV |
706 | struct ieee80211_mgmt *mgmt; |
707 | struct ieee80211_channel *channel; | |
708 | struct ieee80211_supported_band *band; | |
709 | struct ath6kl_common_ie *cie; | |
710 | s32 signal; | |
711 | int freq; | |
712 | ||
713 | cie = &ni->ni_cie; | |
714 | ||
715 | if (is_ch_11a(cie->ie_chan)) | |
716 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */ | |
717 | else if ((cie->ie_erp) || (cie->ie_xrates)) | |
718 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */ | |
719 | else | |
720 | band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */ | |
721 | ||
bdcd8170 KV |
722 | freq = cie->ie_chan; |
723 | channel = ieee80211_get_channel(wiphy, freq); | |
724 | signal = ni->ni_snr * 100; | |
725 | ||
726 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
727 | "%s: bssid %pM ch %d freq %d size %d\n", __func__, | |
0ce77920 JM |
728 | ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen); |
729 | /* | |
730 | * Both Beacon and Probe Response frames have same payload structure, | |
731 | * so it is fine to share the parser for both. | |
732 | */ | |
733 | if (ni->ni_framelen < 8 + 2 + 2) | |
734 | return; | |
735 | mgmt = (struct ieee80211_mgmt *) (ni->ni_buf - | |
736 | offsetof(struct ieee80211_mgmt, u)); | |
737 | cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr, | |
738 | le64_to_cpu(mgmt->u.beacon.timestamp), | |
739 | le16_to_cpu(mgmt->u.beacon.capab_info), | |
740 | le16_to_cpu(mgmt->u.beacon.beacon_int), | |
741 | mgmt->u.beacon.variable, | |
742 | ni->ni_buf + ni->ni_framelen - | |
743 | mgmt->u.beacon.variable, | |
744 | signal, GFP_ATOMIC); | |
bdcd8170 KV |
745 | } |
746 | ||
747 | static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev, | |
748 | struct cfg80211_scan_request *request) | |
749 | { | |
750 | struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); | |
751 | int ret = 0; | |
bdcd8170 KV |
752 | |
753 | if (!ath6kl_cfg80211_ready(ar)) | |
754 | return -EIO; | |
755 | ||
756 | if (!ar->usr_bss_filter) { | |
757 | if (ath6kl_wmi_bssfilter_cmd(ar->wmi, | |
758 | (test_bit(CONNECTED, &ar->flag) ? | |
759 | ALL_BUT_BSS_FILTER : | |
760 | ALL_BSS_FILTER), 0) != 0) { | |
761 | ath6kl_err("couldn't set bss filtering\n"); | |
762 | return -EIO; | |
763 | } | |
764 | } | |
765 | ||
766 | if (request->n_ssids && request->ssids[0].ssid_len) { | |
767 | u8 i; | |
768 | ||
769 | if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1)) | |
770 | request->n_ssids = MAX_PROBED_SSID_INDEX - 1; | |
771 | ||
772 | for (i = 0; i < request->n_ssids; i++) | |
773 | ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1, | |
774 | SPECIFIC_SSID_FLAG, | |
775 | request->ssids[i].ssid_len, | |
776 | request->ssids[i].ssid); | |
777 | } | |
778 | ||
b2c76bbe | 779 | if (ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0, |
bdcd8170 KV |
780 | false, 0, 0, 0, NULL) != 0) { |
781 | ath6kl_err("wmi_startscan_cmd failed\n"); | |
782 | ret = -EIO; | |
783 | } | |
784 | ||
785 | ar->scan_req = request; | |
786 | ||
787 | return ret; | |
788 | } | |
789 | ||
790 | void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status) | |
791 | { | |
6fd1eace | 792 | int i; |
bdcd8170 KV |
793 | |
794 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status); | |
795 | ||
6fd1eace KV |
796 | if (!ar->scan_req) |
797 | return; | |
798 | ||
799 | if ((status == -ECANCELED) || (status == -EBUSY)) { | |
800 | cfg80211_scan_done(ar->scan_req, true); | |
801 | goto out; | |
802 | } | |
803 | ||
804 | /* Translate data to cfg80211 mgmt format */ | |
8a8bc5a4 | 805 | wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy); |
6fd1eace KV |
806 | |
807 | cfg80211_scan_done(ar->scan_req, false); | |
808 | ||
809 | if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) { | |
810 | for (i = 0; i < ar->scan_req->n_ssids; i++) { | |
811 | ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1, | |
812 | DISABLE_SSID_FLAG, | |
813 | 0, NULL); | |
bdcd8170 | 814 | } |
bdcd8170 | 815 | } |
6fd1eace KV |
816 | |
817 | out: | |
818 | ar->scan_req = NULL; | |
bdcd8170 KV |
819 | } |
820 | ||
821 | static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, | |
822 | u8 key_index, bool pairwise, | |
823 | const u8 *mac_addr, | |
824 | struct key_params *params) | |
825 | { | |
826 | struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); | |
827 | struct ath6kl_key *key = NULL; | |
828 | u8 key_usage; | |
829 | u8 key_type; | |
830 | int status = 0; | |
831 | ||
832 | if (!ath6kl_cfg80211_ready(ar)) | |
833 | return -EIO; | |
834 | ||
835 | if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { | |
836 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
837 | "%s: key index %d out of bounds\n", __func__, | |
838 | key_index); | |
839 | return -ENOENT; | |
840 | } | |
841 | ||
842 | key = &ar->keys[key_index]; | |
843 | memset(key, 0, sizeof(struct ath6kl_key)); | |
844 | ||
845 | if (pairwise) | |
846 | key_usage = PAIRWISE_USAGE; | |
847 | else | |
848 | key_usage = GROUP_USAGE; | |
849 | ||
850 | if (params) { | |
851 | if (params->key_len > WLAN_MAX_KEY_LEN || | |
852 | params->seq_len > sizeof(key->seq)) | |
853 | return -EINVAL; | |
854 | ||
855 | key->key_len = params->key_len; | |
856 | memcpy(key->key, params->key, key->key_len); | |
857 | key->seq_len = params->seq_len; | |
858 | memcpy(key->seq, params->seq, key->seq_len); | |
859 | key->cipher = params->cipher; | |
860 | } | |
861 | ||
862 | switch (key->cipher) { | |
863 | case WLAN_CIPHER_SUITE_WEP40: | |
864 | case WLAN_CIPHER_SUITE_WEP104: | |
865 | key_type = WEP_CRYPT; | |
866 | break; | |
867 | ||
868 | case WLAN_CIPHER_SUITE_TKIP: | |
869 | key_type = TKIP_CRYPT; | |
870 | break; | |
871 | ||
872 | case WLAN_CIPHER_SUITE_CCMP: | |
873 | key_type = AES_CRYPT; | |
874 | break; | |
875 | ||
876 | default: | |
877 | return -ENOTSUPP; | |
878 | } | |
879 | ||
880 | if (((ar->auth_mode == WPA_PSK_AUTH) | |
881 | || (ar->auth_mode == WPA2_PSK_AUTH)) | |
882 | && (key_usage & GROUP_USAGE)) | |
883 | del_timer(&ar->disconnect_timer); | |
884 | ||
885 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
886 | "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n", | |
887 | __func__, key_index, key->key_len, key_type, | |
888 | key_usage, key->seq_len); | |
889 | ||
890 | ar->def_txkey_index = key_index; | |
891 | status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index, | |
892 | key_type, key_usage, key->key_len, | |
893 | key->seq, key->key, KEY_OP_INIT_VAL, | |
894 | (u8 *) mac_addr, SYNC_BOTH_WMIFLAG); | |
895 | ||
896 | if (status) | |
897 | return -EIO; | |
898 | ||
899 | return 0; | |
900 | } | |
901 | ||
902 | static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, | |
903 | u8 key_index, bool pairwise, | |
904 | const u8 *mac_addr) | |
905 | { | |
906 | struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); | |
907 | ||
908 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); | |
909 | ||
910 | if (!ath6kl_cfg80211_ready(ar)) | |
911 | return -EIO; | |
912 | ||
913 | if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { | |
914 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
915 | "%s: key index %d out of bounds\n", __func__, | |
916 | key_index); | |
917 | return -ENOENT; | |
918 | } | |
919 | ||
920 | if (!ar->keys[key_index].key_len) { | |
921 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
922 | "%s: index %d is empty\n", __func__, key_index); | |
923 | return 0; | |
924 | } | |
925 | ||
926 | ar->keys[key_index].key_len = 0; | |
927 | ||
928 | return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index); | |
929 | } | |
930 | ||
931 | static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, | |
932 | u8 key_index, bool pairwise, | |
933 | const u8 *mac_addr, void *cookie, | |
934 | void (*callback) (void *cookie, | |
935 | struct key_params *)) | |
936 | { | |
937 | struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); | |
938 | struct ath6kl_key *key = NULL; | |
939 | struct key_params params; | |
940 | ||
941 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); | |
942 | ||
943 | if (!ath6kl_cfg80211_ready(ar)) | |
944 | return -EIO; | |
945 | ||
946 | if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { | |
947 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
948 | "%s: key index %d out of bounds\n", __func__, | |
949 | key_index); | |
950 | return -ENOENT; | |
951 | } | |
952 | ||
953 | key = &ar->keys[key_index]; | |
954 | memset(¶ms, 0, sizeof(params)); | |
955 | params.cipher = key->cipher; | |
956 | params.key_len = key->key_len; | |
957 | params.seq_len = key->seq_len; | |
958 | params.seq = key->seq; | |
959 | params.key = key->key; | |
960 | ||
961 | callback(cookie, ¶ms); | |
962 | ||
963 | return key->key_len ? 0 : -ENOENT; | |
964 | } | |
965 | ||
966 | static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy, | |
967 | struct net_device *ndev, | |
968 | u8 key_index, bool unicast, | |
969 | bool multicast) | |
970 | { | |
971 | struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); | |
972 | struct ath6kl_key *key = NULL; | |
973 | int status = 0; | |
974 | u8 key_usage; | |
975 | ||
976 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); | |
977 | ||
978 | if (!ath6kl_cfg80211_ready(ar)) | |
979 | return -EIO; | |
980 | ||
981 | if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { | |
982 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
983 | "%s: key index %d out of bounds\n", | |
984 | __func__, key_index); | |
985 | return -ENOENT; | |
986 | } | |
987 | ||
988 | if (!ar->keys[key_index].key_len) { | |
989 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n", | |
990 | __func__, key_index); | |
991 | return -EINVAL; | |
992 | } | |
993 | ||
994 | ar->def_txkey_index = key_index; | |
995 | key = &ar->keys[ar->def_txkey_index]; | |
996 | key_usage = GROUP_USAGE; | |
997 | if (ar->prwise_crypto == WEP_CRYPT) | |
998 | key_usage |= TX_USAGE; | |
999 | ||
1000 | status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index, | |
1001 | ar->prwise_crypto, key_usage, | |
1002 | key->key_len, key->seq, key->key, | |
1003 | KEY_OP_INIT_VAL, NULL, | |
1004 | SYNC_BOTH_WMIFLAG); | |
1005 | if (status) | |
1006 | return -EIO; | |
1007 | ||
1008 | return 0; | |
1009 | } | |
1010 | ||
1011 | void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid, | |
1012 | bool ismcast) | |
1013 | { | |
1014 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
1015 | "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast); | |
1016 | ||
1017 | cfg80211_michael_mic_failure(ar->net_dev, ar->bssid, | |
1018 | (ismcast ? NL80211_KEYTYPE_GROUP : | |
1019 | NL80211_KEYTYPE_PAIRWISE), keyid, NULL, | |
1020 | GFP_KERNEL); | |
1021 | } | |
1022 | ||
1023 | static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) | |
1024 | { | |
1025 | struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); | |
1026 | int ret; | |
1027 | ||
1028 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__, | |
1029 | changed); | |
1030 | ||
1031 | if (!ath6kl_cfg80211_ready(ar)) | |
1032 | return -EIO; | |
1033 | ||
1034 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { | |
1035 | ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold); | |
1036 | if (ret != 0) { | |
1037 | ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n"); | |
1038 | return -EIO; | |
1039 | } | |
1040 | } | |
1041 | ||
1042 | return 0; | |
1043 | } | |
1044 | ||
1045 | /* | |
1046 | * The type nl80211_tx_power_setting replaces the following | |
1047 | * data type from 2.6.36 onwards | |
1048 | */ | |
1049 | static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy, | |
1050 | enum nl80211_tx_power_setting type, | |
1051 | int dbm) | |
1052 | { | |
1053 | struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); | |
1054 | u8 ath6kl_dbm; | |
1055 | ||
1056 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__, | |
1057 | type, dbm); | |
1058 | ||
1059 | if (!ath6kl_cfg80211_ready(ar)) | |
1060 | return -EIO; | |
1061 | ||
1062 | switch (type) { | |
1063 | case NL80211_TX_POWER_AUTOMATIC: | |
1064 | return 0; | |
1065 | case NL80211_TX_POWER_LIMITED: | |
1066 | ar->tx_pwr = ath6kl_dbm = dbm; | |
1067 | break; | |
1068 | default: | |
1069 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n", | |
1070 | __func__, type); | |
1071 | return -EOPNOTSUPP; | |
1072 | } | |
1073 | ||
1074 | ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm); | |
1075 | ||
1076 | return 0; | |
1077 | } | |
1078 | ||
1079 | static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm) | |
1080 | { | |
1081 | struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); | |
1082 | ||
1083 | if (!ath6kl_cfg80211_ready(ar)) | |
1084 | return -EIO; | |
1085 | ||
1086 | if (test_bit(CONNECTED, &ar->flag)) { | |
1087 | ar->tx_pwr = 0; | |
1088 | ||
1089 | if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) { | |
1090 | ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n"); | |
1091 | return -EIO; | |
1092 | } | |
1093 | ||
1094 | wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0, | |
1095 | 5 * HZ); | |
1096 | ||
1097 | if (signal_pending(current)) { | |
1098 | ath6kl_err("target did not respond\n"); | |
1099 | return -EINTR; | |
1100 | } | |
1101 | } | |
1102 | ||
1103 | *dbm = ar->tx_pwr; | |
1104 | return 0; | |
1105 | } | |
1106 | ||
1107 | static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy, | |
1108 | struct net_device *dev, | |
1109 | bool pmgmt, int timeout) | |
1110 | { | |
1111 | struct ath6kl *ar = ath6kl_priv(dev); | |
1112 | struct wmi_power_mode_cmd mode; | |
1113 | ||
1114 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n", | |
1115 | __func__, pmgmt, timeout); | |
1116 | ||
1117 | if (!ath6kl_cfg80211_ready(ar)) | |
1118 | return -EIO; | |
1119 | ||
1120 | if (pmgmt) { | |
1121 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__); | |
1122 | mode.pwr_mode = REC_POWER; | |
1123 | } else { | |
1124 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__); | |
1125 | mode.pwr_mode = MAX_PERF_POWER; | |
1126 | } | |
1127 | ||
1128 | if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) { | |
1129 | ath6kl_err("wmi_powermode_cmd failed\n"); | |
1130 | return -EIO; | |
1131 | } | |
1132 | ||
1133 | return 0; | |
1134 | } | |
1135 | ||
1136 | static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy, | |
1137 | struct net_device *ndev, | |
1138 | enum nl80211_iftype type, u32 *flags, | |
1139 | struct vif_params *params) | |
1140 | { | |
1141 | struct ath6kl *ar = ath6kl_priv(ndev); | |
1142 | struct wireless_dev *wdev = ar->wdev; | |
1143 | ||
1144 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type); | |
1145 | ||
1146 | if (!ath6kl_cfg80211_ready(ar)) | |
1147 | return -EIO; | |
1148 | ||
1149 | switch (type) { | |
1150 | case NL80211_IFTYPE_STATION: | |
1151 | ar->next_mode = INFRA_NETWORK; | |
1152 | break; | |
1153 | case NL80211_IFTYPE_ADHOC: | |
1154 | ar->next_mode = ADHOC_NETWORK; | |
1155 | break; | |
1156 | default: | |
1157 | ath6kl_err("invalid interface type %u\n", type); | |
1158 | return -EOPNOTSUPP; | |
1159 | } | |
1160 | ||
1161 | wdev->iftype = type; | |
1162 | ||
1163 | return 0; | |
1164 | } | |
1165 | ||
1166 | static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy, | |
1167 | struct net_device *dev, | |
1168 | struct cfg80211_ibss_params *ibss_param) | |
1169 | { | |
1170 | struct ath6kl *ar = ath6kl_priv(dev); | |
1171 | int status; | |
1172 | ||
1173 | if (!ath6kl_cfg80211_ready(ar)) | |
1174 | return -EIO; | |
1175 | ||
1176 | ar->ssid_len = ibss_param->ssid_len; | |
1177 | memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len); | |
1178 | ||
1179 | if (ibss_param->channel) | |
1180 | ar->ch_hint = ibss_param->channel->center_freq; | |
1181 | ||
1182 | if (ibss_param->channel_fixed) { | |
1183 | /* | |
1184 | * TODO: channel_fixed: The channel should be fixed, do not | |
1185 | * search for IBSSs to join on other channels. Target | |
1186 | * firmware does not support this feature, needs to be | |
1187 | * updated. | |
1188 | */ | |
1189 | return -EOPNOTSUPP; | |
1190 | } | |
1191 | ||
1192 | memset(ar->req_bssid, 0, sizeof(ar->req_bssid)); | |
1193 | if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid)) | |
1194 | memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid)); | |
1195 | ||
1196 | ath6kl_set_wpa_version(ar, 0); | |
1197 | ||
1198 | status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM); | |
1199 | if (status) | |
1200 | return status; | |
1201 | ||
1202 | if (ibss_param->privacy) { | |
1203 | ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true); | |
1204 | ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false); | |
1205 | } else { | |
1206 | ath6kl_set_cipher(ar, 0, true); | |
1207 | ath6kl_set_cipher(ar, 0, false); | |
1208 | } | |
1209 | ||
1210 | ar->nw_type = ar->next_mode; | |
1211 | ||
1212 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, | |
1213 | "%s: connect called with authmode %d dot11 auth %d" | |
1214 | " PW crypto %d PW crypto len %d GRP crypto %d" | |
1215 | " GRP crypto len %d channel hint %u\n", | |
1216 | __func__, | |
1217 | ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto, | |
1218 | ar->prwise_crypto_len, ar->grp_crypto, | |
1219 | ar->grp_crpto_len, ar->ch_hint); | |
1220 | ||
1221 | status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type, | |
1222 | ar->dot11_auth_mode, ar->auth_mode, | |
1223 | ar->prwise_crypto, | |
1224 | ar->prwise_crypto_len, | |
1225 | ar->grp_crypto, ar->grp_crpto_len, | |
1226 | ar->ssid_len, ar->ssid, | |
1227 | ar->req_bssid, ar->ch_hint, | |
1228 | ar->connect_ctrl_flags); | |
1229 | set_bit(CONNECT_PEND, &ar->flag); | |
1230 | ||
1231 | return 0; | |
1232 | } | |
1233 | ||
1234 | static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy, | |
1235 | struct net_device *dev) | |
1236 | { | |
1237 | struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev); | |
1238 | ||
1239 | if (!ath6kl_cfg80211_ready(ar)) | |
1240 | return -EIO; | |
1241 | ||
1242 | ath6kl_disconnect(ar); | |
1243 | memset(ar->ssid, 0, sizeof(ar->ssid)); | |
1244 | ar->ssid_len = 0; | |
1245 | ||
1246 | return 0; | |
1247 | } | |
1248 | ||
1249 | static const u32 cipher_suites[] = { | |
1250 | WLAN_CIPHER_SUITE_WEP40, | |
1251 | WLAN_CIPHER_SUITE_WEP104, | |
1252 | WLAN_CIPHER_SUITE_TKIP, | |
1253 | WLAN_CIPHER_SUITE_CCMP, | |
1254 | }; | |
1255 | ||
1256 | static bool is_rate_legacy(s32 rate) | |
1257 | { | |
1258 | static const s32 legacy[] = { 1000, 2000, 5500, 11000, | |
1259 | 6000, 9000, 12000, 18000, 24000, | |
1260 | 36000, 48000, 54000 | |
1261 | }; | |
1262 | u8 i; | |
1263 | ||
1264 | for (i = 0; i < ARRAY_SIZE(legacy); i++) | |
1265 | if (rate == legacy[i]) | |
1266 | return true; | |
1267 | ||
1268 | return false; | |
1269 | } | |
1270 | ||
1271 | static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi) | |
1272 | { | |
1273 | static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000, | |
1274 | 52000, 58500, 65000, 72200 | |
1275 | }; | |
1276 | u8 i; | |
1277 | ||
1278 | for (i = 0; i < ARRAY_SIZE(ht20); i++) { | |
1279 | if (rate == ht20[i]) { | |
1280 | if (i == ARRAY_SIZE(ht20) - 1) | |
1281 | /* last rate uses sgi */ | |
1282 | *sgi = true; | |
1283 | else | |
1284 | *sgi = false; | |
1285 | ||
1286 | *mcs = i; | |
1287 | return true; | |
1288 | } | |
1289 | } | |
1290 | return false; | |
1291 | } | |
1292 | ||
1293 | static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi) | |
1294 | { | |
1295 | static const s32 ht40[] = { 13500, 27000, 40500, 54000, | |
1296 | 81000, 108000, 121500, 135000, | |
1297 | 150000 | |
1298 | }; | |
1299 | u8 i; | |
1300 | ||
1301 | for (i = 0; i < ARRAY_SIZE(ht40); i++) { | |
1302 | if (rate == ht40[i]) { | |
1303 | if (i == ARRAY_SIZE(ht40) - 1) | |
1304 | /* last rate uses sgi */ | |
1305 | *sgi = true; | |
1306 | else | |
1307 | *sgi = false; | |
1308 | ||
1309 | *mcs = i; | |
1310 | return true; | |
1311 | } | |
1312 | } | |
1313 | ||
1314 | return false; | |
1315 | } | |
1316 | ||
1317 | static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev, | |
1318 | u8 *mac, struct station_info *sinfo) | |
1319 | { | |
1320 | struct ath6kl *ar = ath6kl_priv(dev); | |
1321 | long left; | |
1322 | bool sgi; | |
1323 | s32 rate; | |
1324 | int ret; | |
1325 | u8 mcs; | |
1326 | ||
1327 | if (memcmp(mac, ar->bssid, ETH_ALEN) != 0) | |
1328 | return -ENOENT; | |
1329 | ||
1330 | if (down_interruptible(&ar->sem)) | |
1331 | return -EBUSY; | |
1332 | ||
1333 | set_bit(STATS_UPDATE_PEND, &ar->flag); | |
1334 | ||
1335 | ret = ath6kl_wmi_get_stats_cmd(ar->wmi); | |
1336 | ||
1337 | if (ret != 0) { | |
1338 | up(&ar->sem); | |
1339 | return -EIO; | |
1340 | } | |
1341 | ||
1342 | left = wait_event_interruptible_timeout(ar->event_wq, | |
1343 | !test_bit(STATS_UPDATE_PEND, | |
1344 | &ar->flag), | |
1345 | WMI_TIMEOUT); | |
1346 | ||
1347 | up(&ar->sem); | |
1348 | ||
1349 | if (left == 0) | |
1350 | return -ETIMEDOUT; | |
1351 | else if (left < 0) | |
1352 | return left; | |
1353 | ||
1354 | if (ar->target_stats.rx_byte) { | |
1355 | sinfo->rx_bytes = ar->target_stats.rx_byte; | |
1356 | sinfo->filled |= STATION_INFO_RX_BYTES; | |
1357 | sinfo->rx_packets = ar->target_stats.rx_pkt; | |
1358 | sinfo->filled |= STATION_INFO_RX_PACKETS; | |
1359 | } | |
1360 | ||
1361 | if (ar->target_stats.tx_byte) { | |
1362 | sinfo->tx_bytes = ar->target_stats.tx_byte; | |
1363 | sinfo->filled |= STATION_INFO_TX_BYTES; | |
1364 | sinfo->tx_packets = ar->target_stats.tx_pkt; | |
1365 | sinfo->filled |= STATION_INFO_TX_PACKETS; | |
1366 | } | |
1367 | ||
1368 | sinfo->signal = ar->target_stats.cs_rssi; | |
1369 | sinfo->filled |= STATION_INFO_SIGNAL; | |
1370 | ||
1371 | rate = ar->target_stats.tx_ucast_rate; | |
1372 | ||
1373 | if (is_rate_legacy(rate)) { | |
1374 | sinfo->txrate.legacy = rate / 100; | |
1375 | } else if (is_rate_ht20(rate, &mcs, &sgi)) { | |
1376 | if (sgi) { | |
1377 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; | |
1378 | sinfo->txrate.mcs = mcs - 1; | |
1379 | } else { | |
1380 | sinfo->txrate.mcs = mcs; | |
1381 | } | |
1382 | ||
1383 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; | |
1384 | } else if (is_rate_ht40(rate, &mcs, &sgi)) { | |
1385 | if (sgi) { | |
1386 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; | |
1387 | sinfo->txrate.mcs = mcs - 1; | |
1388 | } else { | |
1389 | sinfo->txrate.mcs = mcs; | |
1390 | } | |
1391 | ||
1392 | sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; | |
1393 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; | |
1394 | } else { | |
1395 | ath6kl_warn("invalid rate: %d\n", rate); | |
1396 | return 0; | |
1397 | } | |
1398 | ||
1399 | sinfo->filled |= STATION_INFO_TX_BITRATE; | |
1400 | ||
1401 | return 0; | |
1402 | } | |
1403 | ||
1404 | static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev, | |
1405 | struct cfg80211_pmksa *pmksa) | |
1406 | { | |
1407 | struct ath6kl *ar = ath6kl_priv(netdev); | |
1408 | return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid, | |
1409 | pmksa->pmkid, true); | |
1410 | } | |
1411 | ||
1412 | static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev, | |
1413 | struct cfg80211_pmksa *pmksa) | |
1414 | { | |
1415 | struct ath6kl *ar = ath6kl_priv(netdev); | |
1416 | return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid, | |
1417 | pmksa->pmkid, false); | |
1418 | } | |
1419 | ||
1420 | static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev) | |
1421 | { | |
1422 | struct ath6kl *ar = ath6kl_priv(netdev); | |
1423 | if (test_bit(CONNECTED, &ar->flag)) | |
1424 | return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false); | |
1425 | return 0; | |
1426 | } | |
1427 | ||
abcb344b KV |
1428 | #ifdef CONFIG_PM |
1429 | static int ar6k_cfg80211_suspend(struct wiphy *wiphy, | |
1430 | struct cfg80211_wowlan *wow) | |
1431 | { | |
1432 | struct ath6kl *ar = wiphy_priv(wiphy); | |
1433 | ||
1434 | return ath6kl_hif_suspend(ar); | |
1435 | } | |
1436 | #endif | |
1437 | ||
6a7c9bad JM |
1438 | static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev, |
1439 | struct ieee80211_channel *chan, | |
1440 | enum nl80211_channel_type channel_type) | |
1441 | { | |
1442 | struct ath6kl *ar = ath6kl_priv(dev); | |
1443 | ||
1444 | if (!ath6kl_cfg80211_ready(ar)) | |
1445 | return -EIO; | |
1446 | ||
1447 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n", | |
1448 | __func__, chan->center_freq, chan->hw_value); | |
1449 | ar->next_chan = chan->center_freq; | |
1450 | ||
1451 | return 0; | |
1452 | } | |
1453 | ||
1454 | static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev, | |
1455 | struct beacon_parameters *info, bool add) | |
1456 | { | |
1457 | struct ath6kl *ar = ath6kl_priv(dev); | |
1458 | struct ieee80211_mgmt *mgmt; | |
1459 | u8 *ies; | |
1460 | int ies_len; | |
1461 | struct wmi_connect_cmd p; | |
1462 | int res; | |
1463 | int i; | |
1464 | ||
1465 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add); | |
1466 | ||
1467 | if (!ath6kl_cfg80211_ready(ar)) | |
1468 | return -EIO; | |
1469 | ||
1470 | if (ar->next_mode != AP_NETWORK) | |
1471 | return -EOPNOTSUPP; | |
1472 | ||
1473 | if (info->beacon_ies) { | |
1474 | res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON, | |
1475 | info->beacon_ies, | |
1476 | info->beacon_ies_len); | |
1477 | if (res) | |
1478 | return res; | |
1479 | } | |
1480 | if (info->proberesp_ies) { | |
1481 | res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP, | |
1482 | info->proberesp_ies, | |
1483 | info->proberesp_ies_len); | |
1484 | if (res) | |
1485 | return res; | |
1486 | } | |
1487 | if (info->assocresp_ies) { | |
1488 | res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP, | |
1489 | info->assocresp_ies, | |
1490 | info->assocresp_ies_len); | |
1491 | if (res) | |
1492 | return res; | |
1493 | } | |
1494 | ||
1495 | if (!add) | |
1496 | return 0; | |
1497 | ||
1498 | /* TODO: | |
1499 | * info->interval | |
1500 | * info->dtim_period | |
1501 | */ | |
1502 | ||
1503 | if (info->head == NULL) | |
1504 | return -EINVAL; | |
1505 | mgmt = (struct ieee80211_mgmt *) info->head; | |
1506 | ies = mgmt->u.beacon.variable; | |
1507 | if (ies > info->head + info->head_len) | |
1508 | return -EINVAL; | |
1509 | ies_len = info->head + info->head_len - ies; | |
1510 | ||
1511 | if (info->ssid == NULL) | |
1512 | return -EINVAL; | |
1513 | memcpy(ar->ssid, info->ssid, info->ssid_len); | |
1514 | ar->ssid_len = info->ssid_len; | |
1515 | if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE) | |
1516 | return -EOPNOTSUPP; /* TODO */ | |
1517 | ||
1518 | ar->dot11_auth_mode = OPEN_AUTH; | |
1519 | ||
1520 | memset(&p, 0, sizeof(p)); | |
1521 | ||
1522 | for (i = 0; i < info->crypto.n_akm_suites; i++) { | |
1523 | switch (info->crypto.akm_suites[i]) { | |
1524 | case WLAN_AKM_SUITE_8021X: | |
1525 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1) | |
1526 | p.auth_mode |= WPA_AUTH; | |
1527 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2) | |
1528 | p.auth_mode |= WPA2_AUTH; | |
1529 | break; | |
1530 | case WLAN_AKM_SUITE_PSK: | |
1531 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1) | |
1532 | p.auth_mode |= WPA_PSK_AUTH; | |
1533 | if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2) | |
1534 | p.auth_mode |= WPA2_PSK_AUTH; | |
1535 | break; | |
1536 | } | |
1537 | } | |
1538 | if (p.auth_mode == 0) | |
1539 | p.auth_mode = NONE_AUTH; | |
1540 | ar->auth_mode = p.auth_mode; | |
1541 | ||
1542 | for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) { | |
1543 | switch (info->crypto.ciphers_pairwise[i]) { | |
1544 | case WLAN_CIPHER_SUITE_WEP40: | |
1545 | case WLAN_CIPHER_SUITE_WEP104: | |
1546 | p.prwise_crypto_type |= WEP_CRYPT; | |
1547 | break; | |
1548 | case WLAN_CIPHER_SUITE_TKIP: | |
1549 | p.prwise_crypto_type |= TKIP_CRYPT; | |
1550 | break; | |
1551 | case WLAN_CIPHER_SUITE_CCMP: | |
1552 | p.prwise_crypto_type |= AES_CRYPT; | |
1553 | break; | |
1554 | } | |
1555 | } | |
1556 | if (p.prwise_crypto_type == 0) | |
1557 | p.prwise_crypto_type = NONE_CRYPT; | |
1558 | ||
1559 | switch (info->crypto.cipher_group) { | |
1560 | case WLAN_CIPHER_SUITE_WEP40: | |
1561 | case WLAN_CIPHER_SUITE_WEP104: | |
1562 | p.grp_crypto_type = WEP_CRYPT; | |
1563 | break; | |
1564 | case WLAN_CIPHER_SUITE_TKIP: | |
1565 | p.grp_crypto_type = TKIP_CRYPT; | |
1566 | break; | |
1567 | case WLAN_CIPHER_SUITE_CCMP: | |
1568 | p.grp_crypto_type = AES_CRYPT; | |
1569 | break; | |
1570 | default: | |
1571 | p.grp_crypto_type = NONE_CRYPT; | |
1572 | break; | |
1573 | } | |
1574 | ||
1575 | p.nw_type = AP_NETWORK; | |
1576 | ar->nw_type = ar->next_mode; | |
1577 | ||
1578 | p.ssid_len = ar->ssid_len; | |
1579 | memcpy(p.ssid, ar->ssid, ar->ssid_len); | |
1580 | p.dot11_auth_mode = ar->dot11_auth_mode; | |
1581 | p.ch = cpu_to_le16(ar->next_chan); | |
1582 | ||
1583 | return ath6kl_wmi_ap_profile_commit(ar->wmi, &p); | |
1584 | } | |
1585 | ||
1586 | static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev, | |
1587 | struct beacon_parameters *info) | |
1588 | { | |
1589 | return ath6kl_ap_beacon(wiphy, dev, info, true); | |
1590 | } | |
1591 | ||
1592 | static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev, | |
1593 | struct beacon_parameters *info) | |
1594 | { | |
1595 | return ath6kl_ap_beacon(wiphy, dev, info, false); | |
1596 | } | |
1597 | ||
1598 | static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev) | |
1599 | { | |
1600 | struct ath6kl *ar = ath6kl_priv(dev); | |
1601 | ||
1602 | if (ar->nw_type != AP_NETWORK) | |
1603 | return -EOPNOTSUPP; | |
1604 | if (!test_bit(CONNECTED, &ar->flag)) | |
1605 | return -ENOTCONN; | |
1606 | ||
1607 | ath6kl_wmi_disconnect_cmd(ar->wmi); | |
1608 | clear_bit(CONNECTED, &ar->flag); | |
1609 | ||
1610 | return 0; | |
1611 | } | |
1612 | ||
bdcd8170 KV |
1613 | static struct cfg80211_ops ath6kl_cfg80211_ops = { |
1614 | .change_virtual_intf = ath6kl_cfg80211_change_iface, | |
1615 | .scan = ath6kl_cfg80211_scan, | |
1616 | .connect = ath6kl_cfg80211_connect, | |
1617 | .disconnect = ath6kl_cfg80211_disconnect, | |
1618 | .add_key = ath6kl_cfg80211_add_key, | |
1619 | .get_key = ath6kl_cfg80211_get_key, | |
1620 | .del_key = ath6kl_cfg80211_del_key, | |
1621 | .set_default_key = ath6kl_cfg80211_set_default_key, | |
1622 | .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params, | |
1623 | .set_tx_power = ath6kl_cfg80211_set_txpower, | |
1624 | .get_tx_power = ath6kl_cfg80211_get_txpower, | |
1625 | .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt, | |
1626 | .join_ibss = ath6kl_cfg80211_join_ibss, | |
1627 | .leave_ibss = ath6kl_cfg80211_leave_ibss, | |
1628 | .get_station = ath6kl_get_station, | |
1629 | .set_pmksa = ath6kl_set_pmksa, | |
1630 | .del_pmksa = ath6kl_del_pmksa, | |
1631 | .flush_pmksa = ath6kl_flush_pmksa, | |
abcb344b KV |
1632 | #ifdef CONFIG_PM |
1633 | .suspend = ar6k_cfg80211_suspend, | |
1634 | #endif | |
6a7c9bad JM |
1635 | .set_channel = ath6kl_set_channel, |
1636 | .add_beacon = ath6kl_add_beacon, | |
1637 | .set_beacon = ath6kl_set_beacon, | |
1638 | .del_beacon = ath6kl_del_beacon, | |
bdcd8170 KV |
1639 | }; |
1640 | ||
1641 | struct wireless_dev *ath6kl_cfg80211_init(struct device *dev) | |
1642 | { | |
1643 | int ret = 0; | |
1644 | struct wireless_dev *wdev; | |
1645 | ||
1646 | wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); | |
1647 | if (!wdev) { | |
1648 | ath6kl_err("couldn't allocate wireless device\n"); | |
1649 | return NULL; | |
1650 | } | |
1651 | ||
1652 | /* create a new wiphy for use with cfg80211 */ | |
1653 | wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl)); | |
1654 | if (!wdev->wiphy) { | |
1655 | ath6kl_err("couldn't allocate wiphy device\n"); | |
1656 | kfree(wdev); | |
1657 | return NULL; | |
1658 | } | |
1659 | ||
1660 | /* set device pointer for wiphy */ | |
1661 | set_wiphy_dev(wdev->wiphy, dev); | |
1662 | ||
1663 | wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
1664 | BIT(NL80211_IFTYPE_ADHOC); | |
1665 | /* max num of ssids that can be probed during scanning */ | |
1666 | wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX; | |
1667 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz; | |
1668 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz; | |
1669 | wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; | |
1670 | ||
1671 | wdev->wiphy->cipher_suites = cipher_suites; | |
1672 | wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
1673 | ||
1674 | ret = wiphy_register(wdev->wiphy); | |
1675 | if (ret < 0) { | |
1676 | ath6kl_err("couldn't register wiphy device\n"); | |
1677 | wiphy_free(wdev->wiphy); | |
1678 | kfree(wdev); | |
1679 | return NULL; | |
1680 | } | |
1681 | ||
1682 | return wdev; | |
1683 | } | |
1684 | ||
1685 | void ath6kl_cfg80211_deinit(struct ath6kl *ar) | |
1686 | { | |
1687 | struct wireless_dev *wdev = ar->wdev; | |
1688 | ||
1689 | if (ar->scan_req) { | |
1690 | cfg80211_scan_done(ar->scan_req, true); | |
1691 | ar->scan_req = NULL; | |
1692 | } | |
1693 | ||
1694 | if (!wdev) | |
1695 | return; | |
1696 | ||
1697 | wiphy_unregister(wdev->wiphy); | |
1698 | wiphy_free(wdev->wiphy); | |
1699 | kfree(wdev); | |
1700 | } |