2 * Copyright (c) 2004-2011 Atheros Communications Inc.
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.
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.
17 #include <linux/moduleparam.h>
25 static unsigned int ath6kl_p2p;
27 module_param(ath6kl_p2p, uint, 0644);
29 #define RATETAB_ENT(_rate, _rateid, _flags) { \
32 .hw_value = (_rateid), \
35 #define CHAN2G(_channel, _freq, _flags) { \
36 .band = IEEE80211_BAND_2GHZ, \
37 .hw_value = (_channel), \
38 .center_freq = (_freq), \
40 .max_antenna_gain = 0, \
44 #define CHAN5G(_channel, _flags) { \
45 .band = IEEE80211_BAND_5GHZ, \
46 .hw_value = (_channel), \
47 .center_freq = 5000 + (5 * (_channel)), \
49 .max_antenna_gain = 0, \
53 static struct ieee80211_rate ath6kl_rates[] = {
54 RATETAB_ENT(10, 0x1, 0),
55 RATETAB_ENT(20, 0x2, 0),
56 RATETAB_ENT(55, 0x4, 0),
57 RATETAB_ENT(110, 0x8, 0),
58 RATETAB_ENT(60, 0x10, 0),
59 RATETAB_ENT(90, 0x20, 0),
60 RATETAB_ENT(120, 0x40, 0),
61 RATETAB_ENT(180, 0x80, 0),
62 RATETAB_ENT(240, 0x100, 0),
63 RATETAB_ENT(360, 0x200, 0),
64 RATETAB_ENT(480, 0x400, 0),
65 RATETAB_ENT(540, 0x800, 0),
68 #define ath6kl_a_rates (ath6kl_rates + 4)
69 #define ath6kl_a_rates_size 8
70 #define ath6kl_g_rates (ath6kl_rates + 0)
71 #define ath6kl_g_rates_size 12
73 static struct ieee80211_channel ath6kl_2ghz_channels[] = {
90 static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
91 CHAN5G(34, 0), CHAN5G(36, 0),
92 CHAN5G(38, 0), CHAN5G(40, 0),
93 CHAN5G(42, 0), CHAN5G(44, 0),
94 CHAN5G(46, 0), CHAN5G(48, 0),
95 CHAN5G(52, 0), CHAN5G(56, 0),
96 CHAN5G(60, 0), CHAN5G(64, 0),
97 CHAN5G(100, 0), CHAN5G(104, 0),
98 CHAN5G(108, 0), CHAN5G(112, 0),
99 CHAN5G(116, 0), CHAN5G(120, 0),
100 CHAN5G(124, 0), CHAN5G(128, 0),
101 CHAN5G(132, 0), CHAN5G(136, 0),
102 CHAN5G(140, 0), CHAN5G(149, 0),
103 CHAN5G(153, 0), CHAN5G(157, 0),
104 CHAN5G(161, 0), CHAN5G(165, 0),
105 CHAN5G(184, 0), CHAN5G(188, 0),
106 CHAN5G(192, 0), CHAN5G(196, 0),
107 CHAN5G(200, 0), CHAN5G(204, 0),
108 CHAN5G(208, 0), CHAN5G(212, 0),
112 static struct ieee80211_supported_band ath6kl_band_2ghz = {
113 .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
114 .channels = ath6kl_2ghz_channels,
115 .n_bitrates = ath6kl_g_rates_size,
116 .bitrates = ath6kl_g_rates,
119 static struct ieee80211_supported_band ath6kl_band_5ghz = {
120 .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
121 .channels = ath6kl_5ghz_a_channels,
122 .n_bitrates = ath6kl_a_rates_size,
123 .bitrates = ath6kl_a_rates,
126 static int ath6kl_set_wpa_version(struct ath6kl *ar,
127 enum nl80211_wpa_versions wpa_version)
129 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
132 ar->auth_mode = NONE_AUTH;
133 } else if (wpa_version & NL80211_WPA_VERSION_2) {
134 ar->auth_mode = WPA2_AUTH;
135 } else if (wpa_version & NL80211_WPA_VERSION_1) {
136 ar->auth_mode = WPA_AUTH;
138 ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
145 static int ath6kl_set_auth_type(struct ath6kl *ar,
146 enum nl80211_auth_type auth_type)
149 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
152 case NL80211_AUTHTYPE_OPEN_SYSTEM:
153 ar->dot11_auth_mode = OPEN_AUTH;
155 case NL80211_AUTHTYPE_SHARED_KEY:
156 ar->dot11_auth_mode = SHARED_AUTH;
158 case NL80211_AUTHTYPE_NETWORK_EAP:
159 ar->dot11_auth_mode = LEAP_AUTH;
162 case NL80211_AUTHTYPE_AUTOMATIC:
163 ar->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH;
167 ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
174 static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast)
176 u8 *ar_cipher = ucast ? &ar->prwise_crypto : &ar->grp_crypto;
177 u8 *ar_cipher_len = ucast ? &ar->prwise_crypto_len :
180 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
181 __func__, cipher, ucast);
185 /* our own hack to use value 0 as no crypto used */
186 *ar_cipher = NONE_CRYPT;
189 case WLAN_CIPHER_SUITE_WEP40:
190 *ar_cipher = WEP_CRYPT;
193 case WLAN_CIPHER_SUITE_WEP104:
194 *ar_cipher = WEP_CRYPT;
197 case WLAN_CIPHER_SUITE_TKIP:
198 *ar_cipher = TKIP_CRYPT;
201 case WLAN_CIPHER_SUITE_CCMP:
202 *ar_cipher = AES_CRYPT;
206 ath6kl_err("cipher 0x%x not supported\n", cipher);
213 static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
215 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
217 if (key_mgmt == WLAN_AKM_SUITE_PSK) {
218 if (ar->auth_mode == WPA_AUTH)
219 ar->auth_mode = WPA_PSK_AUTH;
220 else if (ar->auth_mode == WPA2_AUTH)
221 ar->auth_mode = WPA2_PSK_AUTH;
222 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
223 ar->auth_mode = NONE_AUTH;
227 static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
229 if (!test_bit(WMI_READY, &ar->flag)) {
230 ath6kl_err("wmi is not ready\n");
234 if (!test_bit(WLAN_ENABLED, &ar->flag)) {
235 ath6kl_err("wlan disabled\n");
242 static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
243 struct cfg80211_connect_params *sme)
245 struct ath6kl *ar = ath6kl_priv(dev);
248 ar->sme_state = SME_CONNECTING;
250 if (!ath6kl_cfg80211_ready(ar))
253 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
254 ath6kl_err("destroy in progress\n");
258 if (test_bit(SKIP_SCAN, &ar->flag) &&
259 ((sme->channel && sme->channel->center_freq == 0) ||
260 (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
261 ath6kl_err("SkipScan: channel or bssid invalid\n");
265 if (down_interruptible(&ar->sem)) {
266 ath6kl_err("busy, couldn't get access\n");
270 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
271 ath6kl_err("busy, destroy in progress\n");
276 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
278 * sleep until the command queue drains
280 wait_event_interruptible_timeout(ar->event_wq,
281 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
283 if (signal_pending(current)) {
284 ath6kl_err("cmd queue drain timeout\n");
290 if (test_bit(CONNECTED, &ar->flag) &&
291 ar->ssid_len == sme->ssid_len &&
292 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
293 ar->reconnect_flag = true;
294 status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid,
299 ath6kl_err("wmi_reconnect_cmd failed\n");
303 } else if (ar->ssid_len == sme->ssid_len &&
304 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
305 ath6kl_disconnect(ar);
308 memset(ar->ssid, 0, sizeof(ar->ssid));
309 ar->ssid_len = sme->ssid_len;
310 memcpy(ar->ssid, sme->ssid, sme->ssid_len);
313 ar->ch_hint = sme->channel->center_freq;
315 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
316 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
317 memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid));
319 ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions);
321 status = ath6kl_set_auth_type(ar, sme->auth_type);
327 if (sme->crypto.n_ciphers_pairwise)
328 ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
330 ath6kl_set_cipher(ar, 0, true);
332 ath6kl_set_cipher(ar, sme->crypto.cipher_group, false);
334 if (sme->crypto.n_akm_suites)
335 ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
337 if ((sme->key_len) &&
338 (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) {
339 struct ath6kl_key *key = NULL;
341 if (sme->key_idx < WMI_MIN_KEY_INDEX ||
342 sme->key_idx > WMI_MAX_KEY_INDEX) {
343 ath6kl_err("key index %d out of bounds\n",
349 key = &ar->keys[sme->key_idx];
350 key->key_len = sme->key_len;
351 memcpy(key->key, sme->key, key->key_len);
352 key->cipher = ar->prwise_crypto;
353 ar->def_txkey_index = sme->key_idx;
355 ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx,
357 GROUP_USAGE | TX_USAGE,
360 key->key, KEY_OP_INIT_VAL, NULL,
364 if (!ar->usr_bss_filter) {
365 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &ar->flag);
366 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) {
367 ath6kl_err("couldn't set bss filtering\n");
373 ar->nw_type = ar->next_mode;
375 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
376 "%s: connect called with authmode %d dot11 auth %d"
377 " PW crypto %d PW crypto len %d GRP crypto %d"
378 " GRP crypto len %d channel hint %u\n",
380 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
381 ar->prwise_crypto_len, ar->grp_crypto,
382 ar->grp_crypto_len, ar->ch_hint);
384 ar->reconnect_flag = 0;
385 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
386 ar->dot11_auth_mode, ar->auth_mode,
388 ar->prwise_crypto_len,
389 ar->grp_crypto, ar->grp_crypto_len,
390 ar->ssid_len, ar->ssid,
391 ar->req_bssid, ar->ch_hint,
392 ar->connect_ctrl_flags);
396 if (status == -EINVAL) {
397 memset(ar->ssid, 0, sizeof(ar->ssid));
399 ath6kl_err("invalid request\n");
402 ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
406 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
407 ((ar->auth_mode == WPA_PSK_AUTH)
408 || (ar->auth_mode == WPA2_PSK_AUTH))) {
409 mod_timer(&ar->disconnect_timer,
410 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
413 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
414 set_bit(CONNECT_PEND, &ar->flag);
419 static int ath6kl_add_bss_if_needed(struct ath6kl *ar, const u8 *bssid,
420 struct ieee80211_channel *chan,
421 const u8 *beacon_ie, size_t beacon_ie_len)
423 struct cfg80211_bss *bss;
426 bss = cfg80211_get_bss(ar->wdev->wiphy, chan, bssid,
427 ar->ssid, ar->ssid_len, WLAN_CAPABILITY_ESS,
428 WLAN_CAPABILITY_ESS);
431 * Since cfg80211 may not yet know about the BSS,
432 * generate a partial entry until the first BSS info
433 * event becomes available.
435 * Prepend SSID element since it is not included in the Beacon
436 * IEs from the target.
438 ie = kmalloc(2 + ar->ssid_len + beacon_ie_len, GFP_KERNEL);
441 ie[0] = WLAN_EID_SSID;
442 ie[1] = ar->ssid_len;
443 memcpy(ie + 2, ar->ssid, ar->ssid_len);
444 memcpy(ie + 2 + ar->ssid_len, beacon_ie, beacon_ie_len);
445 bss = cfg80211_inform_bss(ar->wdev->wiphy, chan,
446 bssid, 0, WLAN_CAPABILITY_ESS, 100,
447 ie, 2 + ar->ssid_len + beacon_ie_len,
450 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "added dummy bss for "
451 "%pM prior to indicating connect/roamed "
455 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss "
461 cfg80211_put_bss(bss);
466 void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel,
467 u8 *bssid, u16 listen_intvl,
469 enum network_type nw_type,
470 u8 beacon_ie_len, u8 assoc_req_len,
471 u8 assoc_resp_len, u8 *assoc_info)
473 struct ieee80211_channel *chan;
475 /* capinfo + listen interval */
476 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
478 /* capinfo + status code + associd */
479 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
481 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
482 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
483 assoc_resp_ie_offset;
485 assoc_req_len -= assoc_req_ie_offset;
486 assoc_resp_len -= assoc_resp_ie_offset;
489 * Store Beacon interval here; DTIM period will be available only once
490 * a Beacon frame from the AP is seen.
492 ar->assoc_bss_beacon_int = beacon_intvl;
493 clear_bit(DTIM_PERIOD_AVAIL, &ar->flag);
495 if (nw_type & ADHOC_NETWORK) {
496 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
497 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
498 "%s: ath6k not in ibss mode\n", __func__);
503 if (nw_type & INFRA_NETWORK) {
504 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
505 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
506 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
507 "%s: ath6k not in station mode\n", __func__);
512 chan = ieee80211_get_channel(ar->wdev->wiphy, (int) channel);
515 if (nw_type & ADHOC_NETWORK) {
516 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
520 if (ath6kl_add_bss_if_needed(ar, bssid, chan, assoc_info,
521 beacon_ie_len) < 0) {
522 ath6kl_err("could not add cfg80211 bss entry for "
523 "connect/roamed notification\n");
527 if (ar->sme_state == SME_CONNECTING) {
528 /* inform connect result to cfg80211 */
529 ar->sme_state = SME_CONNECTED;
530 cfg80211_connect_result(ar->net_dev, bssid,
531 assoc_req_ie, assoc_req_len,
532 assoc_resp_ie, assoc_resp_len,
533 WLAN_STATUS_SUCCESS, GFP_KERNEL);
534 } else if (ar->sme_state == SME_CONNECTED) {
535 /* inform roam event to cfg80211 */
536 cfg80211_roamed(ar->net_dev, chan, bssid,
537 assoc_req_ie, assoc_req_len,
538 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
542 static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
543 struct net_device *dev, u16 reason_code)
545 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
547 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
550 if (!ath6kl_cfg80211_ready(ar))
553 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
554 ath6kl_err("busy, destroy in progress\n");
558 if (down_interruptible(&ar->sem)) {
559 ath6kl_err("busy, couldn't get access\n");
563 ar->reconnect_flag = 0;
564 ath6kl_disconnect(ar);
565 memset(ar->ssid, 0, sizeof(ar->ssid));
568 if (!test_bit(SKIP_SCAN, &ar->flag))
569 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
573 ar->sme_state = SME_DISCONNECTED;
578 void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
579 u8 *bssid, u8 assoc_resp_len,
580 u8 *assoc_info, u16 proto_reason)
583 cfg80211_scan_done(ar->scan_req, true);
587 if (ar->nw_type & ADHOC_NETWORK) {
588 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
589 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
590 "%s: ath6k not in ibss mode\n", __func__);
593 memset(bssid, 0, ETH_ALEN);
594 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
598 if (ar->nw_type & INFRA_NETWORK) {
599 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
600 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
601 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
602 "%s: ath6k not in station mode\n", __func__);
608 * Send a disconnect command to target when a disconnect event is
609 * received with reason code other than 3 (DISCONNECT_CMD - disconnect
610 * request from host) to make the firmware stop trying to connect even
611 * after giving disconnect event. There will be one more disconnect
612 * event for this disconnect command with reason code DISCONNECT_CMD
613 * which will be notified to cfg80211.
616 if (reason != DISCONNECT_CMD) {
617 ath6kl_wmi_disconnect_cmd(ar->wmi);
621 clear_bit(CONNECT_PEND, &ar->flag);
623 if (ar->sme_state == SME_CONNECTING) {
624 cfg80211_connect_result(ar->net_dev,
627 WLAN_STATUS_UNSPECIFIED_FAILURE,
629 } else if (ar->sme_state == SME_CONNECTED) {
630 cfg80211_disconnected(ar->net_dev, reason,
631 NULL, 0, GFP_KERNEL);
634 ar->sme_state = SME_DISCONNECTED;
637 static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
638 struct cfg80211_scan_request *request)
640 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
642 u16 *channels = NULL;
645 if (!ath6kl_cfg80211_ready(ar))
648 if (!ar->usr_bss_filter) {
649 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &ar->flag);
650 ret = ath6kl_wmi_bssfilter_cmd(
652 (test_bit(CONNECTED, &ar->flag) ?
653 ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0);
655 ath6kl_err("couldn't set bss filtering\n");
660 if (request->n_ssids && request->ssids[0].ssid_len) {
663 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
664 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
666 for (i = 0; i < request->n_ssids; i++)
667 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
669 request->ssids[i].ssid_len,
670 request->ssids[i].ssid);
674 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_REQ,
675 request->ie, request->ie_len);
677 ath6kl_err("failed to set Probe Request appie for "
684 * Scan only the requested channels if the request specifies a set of
685 * channels. If the list is longer than the target supports, do not
686 * configure the list and instead, scan all available channels.
688 if (request->n_channels > 0 &&
689 request->n_channels <= WMI_MAX_CHANNELS) {
692 n_channels = request->n_channels;
694 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
695 if (channels == NULL) {
696 ath6kl_warn("failed to set scan channels, "
697 "scan all channels");
701 for (i = 0; i < n_channels; i++)
702 channels[i] = request->channels[i]->center_freq;
705 ret = ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
706 false, 0, 0, n_channels, channels);
708 ath6kl_err("wmi_startscan_cmd failed\n");
710 ar->scan_req = request;
717 void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
721 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
726 if ((status == -ECANCELED) || (status == -EBUSY)) {
727 cfg80211_scan_done(ar->scan_req, true);
731 cfg80211_scan_done(ar->scan_req, false);
733 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
734 for (i = 0; i < ar->scan_req->n_ssids; i++) {
735 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
745 static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
746 u8 key_index, bool pairwise,
748 struct key_params *params)
750 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
751 struct ath6kl_key *key = NULL;
756 if (!ath6kl_cfg80211_ready(ar))
759 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
760 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
761 "%s: key index %d out of bounds\n", __func__,
766 key = &ar->keys[key_index];
767 memset(key, 0, sizeof(struct ath6kl_key));
770 key_usage = PAIRWISE_USAGE;
772 key_usage = GROUP_USAGE;
775 if (params->key_len > WLAN_MAX_KEY_LEN ||
776 params->seq_len > sizeof(key->seq))
779 key->key_len = params->key_len;
780 memcpy(key->key, params->key, key->key_len);
781 key->seq_len = params->seq_len;
782 memcpy(key->seq, params->seq, key->seq_len);
783 key->cipher = params->cipher;
786 switch (key->cipher) {
787 case WLAN_CIPHER_SUITE_WEP40:
788 case WLAN_CIPHER_SUITE_WEP104:
789 key_type = WEP_CRYPT;
792 case WLAN_CIPHER_SUITE_TKIP:
793 key_type = TKIP_CRYPT;
796 case WLAN_CIPHER_SUITE_CCMP:
797 key_type = AES_CRYPT;
804 if (((ar->auth_mode == WPA_PSK_AUTH)
805 || (ar->auth_mode == WPA2_PSK_AUTH))
806 && (key_usage & GROUP_USAGE))
807 del_timer(&ar->disconnect_timer);
809 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
810 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
811 __func__, key_index, key->key_len, key_type,
812 key_usage, key->seq_len);
814 ar->def_txkey_index = key_index;
816 if (ar->nw_type == AP_NETWORK && !pairwise &&
817 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
818 ar->ap_mode_bkey.valid = true;
819 ar->ap_mode_bkey.key_index = key_index;
820 ar->ap_mode_bkey.key_type = key_type;
821 ar->ap_mode_bkey.key_len = key->key_len;
822 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
823 if (!test_bit(CONNECTED, &ar->flag)) {
824 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
825 "key configuration until AP mode has been "
828 * The key will be set in ath6kl_connect_ap_mode() once
829 * the connected event is received from the target.
835 if (ar->next_mode == AP_NETWORK && key_type == WEP_CRYPT &&
836 !test_bit(CONNECTED, &ar->flag)) {
838 * Store the key locally so that it can be re-configured after
839 * the AP mode has properly started
840 * (ath6kl_install_statioc_wep_keys).
842 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay WEP key configuration "
843 "until AP mode has been started\n");
844 ar->wep_key_list[key_index].key_len = key->key_len;
845 memcpy(ar->wep_key_list[key_index].key, key->key, key->key_len);
849 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
850 key_type, key_usage, key->key_len,
851 key->seq, key->key, KEY_OP_INIT_VAL,
852 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
860 static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
861 u8 key_index, bool pairwise,
864 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
866 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
868 if (!ath6kl_cfg80211_ready(ar))
871 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
872 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
873 "%s: key index %d out of bounds\n", __func__,
878 if (!ar->keys[key_index].key_len) {
879 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
880 "%s: index %d is empty\n", __func__, key_index);
884 ar->keys[key_index].key_len = 0;
886 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
889 static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
890 u8 key_index, bool pairwise,
891 const u8 *mac_addr, void *cookie,
892 void (*callback) (void *cookie,
893 struct key_params *))
895 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
896 struct ath6kl_key *key = NULL;
897 struct key_params params;
899 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
901 if (!ath6kl_cfg80211_ready(ar))
904 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
905 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
906 "%s: key index %d out of bounds\n", __func__,
911 key = &ar->keys[key_index];
912 memset(¶ms, 0, sizeof(params));
913 params.cipher = key->cipher;
914 params.key_len = key->key_len;
915 params.seq_len = key->seq_len;
916 params.seq = key->seq;
917 params.key = key->key;
919 callback(cookie, ¶ms);
921 return key->key_len ? 0 : -ENOENT;
924 static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
925 struct net_device *ndev,
926 u8 key_index, bool unicast,
929 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
930 struct ath6kl_key *key = NULL;
933 enum crypto_type key_type = NONE_CRYPT;
935 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
937 if (!ath6kl_cfg80211_ready(ar))
940 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
941 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
942 "%s: key index %d out of bounds\n",
943 __func__, key_index);
947 if (!ar->keys[key_index].key_len) {
948 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
949 __func__, key_index);
953 ar->def_txkey_index = key_index;
954 key = &ar->keys[ar->def_txkey_index];
955 key_usage = GROUP_USAGE;
956 if (ar->prwise_crypto == WEP_CRYPT)
957 key_usage |= TX_USAGE;
959 key_type = ar->prwise_crypto;
961 key_type = ar->grp_crypto;
963 if (ar->next_mode == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
964 return 0; /* Delay until AP mode has been started */
966 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
968 key->key_len, key->seq, key->key,
969 KEY_OP_INIT_VAL, NULL,
977 void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
980 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
981 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
983 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
984 (ismcast ? NL80211_KEYTYPE_GROUP :
985 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
989 static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
991 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
994 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
997 if (!ath6kl_cfg80211_ready(ar))
1000 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1001 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1003 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1012 * The type nl80211_tx_power_setting replaces the following
1013 * data type from 2.6.36 onwards
1015 static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1016 enum nl80211_tx_power_setting type,
1019 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1022 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1025 if (!ath6kl_cfg80211_ready(ar))
1029 case NL80211_TX_POWER_AUTOMATIC:
1031 case NL80211_TX_POWER_LIMITED:
1032 ar->tx_pwr = ath6kl_dbm = dbm;
1035 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1040 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
1045 static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1047 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1049 if (!ath6kl_cfg80211_ready(ar))
1052 if (test_bit(CONNECTED, &ar->flag)) {
1055 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
1056 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1060 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1063 if (signal_pending(current)) {
1064 ath6kl_err("target did not respond\n");
1073 static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1074 struct net_device *dev,
1075 bool pmgmt, int timeout)
1077 struct ath6kl *ar = ath6kl_priv(dev);
1078 struct wmi_power_mode_cmd mode;
1080 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1081 __func__, pmgmt, timeout);
1083 if (!ath6kl_cfg80211_ready(ar))
1087 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1088 mode.pwr_mode = REC_POWER;
1090 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1091 mode.pwr_mode = MAX_PERF_POWER;
1094 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
1095 ath6kl_err("wmi_powermode_cmd failed\n");
1102 static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1103 struct net_device *ndev,
1104 enum nl80211_iftype type, u32 *flags,
1105 struct vif_params *params)
1107 struct ath6kl *ar = ath6kl_priv(ndev);
1108 struct wireless_dev *wdev = ar->wdev;
1110 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1112 if (!ath6kl_cfg80211_ready(ar))
1116 case NL80211_IFTYPE_STATION:
1117 ar->next_mode = INFRA_NETWORK;
1119 case NL80211_IFTYPE_ADHOC:
1120 ar->next_mode = ADHOC_NETWORK;
1122 case NL80211_IFTYPE_AP:
1123 ar->next_mode = AP_NETWORK;
1125 case NL80211_IFTYPE_P2P_CLIENT:
1126 ar->next_mode = INFRA_NETWORK;
1128 case NL80211_IFTYPE_P2P_GO:
1129 ar->next_mode = AP_NETWORK;
1132 ath6kl_err("invalid interface type %u\n", type);
1136 wdev->iftype = type;
1141 static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1142 struct net_device *dev,
1143 struct cfg80211_ibss_params *ibss_param)
1145 struct ath6kl *ar = ath6kl_priv(dev);
1148 if (!ath6kl_cfg80211_ready(ar))
1151 ar->ssid_len = ibss_param->ssid_len;
1152 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1154 if (ibss_param->channel)
1155 ar->ch_hint = ibss_param->channel->center_freq;
1157 if (ibss_param->channel_fixed) {
1159 * TODO: channel_fixed: The channel should be fixed, do not
1160 * search for IBSSs to join on other channels. Target
1161 * firmware does not support this feature, needs to be
1167 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1168 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1169 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1171 ath6kl_set_wpa_version(ar, 0);
1173 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1177 if (ibss_param->privacy) {
1178 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1179 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1181 ath6kl_set_cipher(ar, 0, true);
1182 ath6kl_set_cipher(ar, 0, false);
1185 ar->nw_type = ar->next_mode;
1187 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1188 "%s: connect called with authmode %d dot11 auth %d"
1189 " PW crypto %d PW crypto len %d GRP crypto %d"
1190 " GRP crypto len %d channel hint %u\n",
1192 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1193 ar->prwise_crypto_len, ar->grp_crypto,
1194 ar->grp_crypto_len, ar->ch_hint);
1196 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1197 ar->dot11_auth_mode, ar->auth_mode,
1199 ar->prwise_crypto_len,
1200 ar->grp_crypto, ar->grp_crypto_len,
1201 ar->ssid_len, ar->ssid,
1202 ar->req_bssid, ar->ch_hint,
1203 ar->connect_ctrl_flags);
1204 set_bit(CONNECT_PEND, &ar->flag);
1209 static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1210 struct net_device *dev)
1212 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1214 if (!ath6kl_cfg80211_ready(ar))
1217 ath6kl_disconnect(ar);
1218 memset(ar->ssid, 0, sizeof(ar->ssid));
1224 static const u32 cipher_suites[] = {
1225 WLAN_CIPHER_SUITE_WEP40,
1226 WLAN_CIPHER_SUITE_WEP104,
1227 WLAN_CIPHER_SUITE_TKIP,
1228 WLAN_CIPHER_SUITE_CCMP,
1231 static bool is_rate_legacy(s32 rate)
1233 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1234 6000, 9000, 12000, 18000, 24000,
1239 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1240 if (rate == legacy[i])
1246 static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1248 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1249 52000, 58500, 65000, 72200
1253 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1254 if (rate == ht20[i]) {
1255 if (i == ARRAY_SIZE(ht20) - 1)
1256 /* last rate uses sgi */
1268 static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1270 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1271 81000, 108000, 121500, 135000,
1276 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1277 if (rate == ht40[i]) {
1278 if (i == ARRAY_SIZE(ht40) - 1)
1279 /* last rate uses sgi */
1292 static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1293 u8 *mac, struct station_info *sinfo)
1295 struct ath6kl *ar = ath6kl_priv(dev);
1302 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1305 if (down_interruptible(&ar->sem))
1308 set_bit(STATS_UPDATE_PEND, &ar->flag);
1310 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1317 left = wait_event_interruptible_timeout(ar->event_wq,
1318 !test_bit(STATS_UPDATE_PEND,
1329 if (ar->target_stats.rx_byte) {
1330 sinfo->rx_bytes = ar->target_stats.rx_byte;
1331 sinfo->filled |= STATION_INFO_RX_BYTES;
1332 sinfo->rx_packets = ar->target_stats.rx_pkt;
1333 sinfo->filled |= STATION_INFO_RX_PACKETS;
1336 if (ar->target_stats.tx_byte) {
1337 sinfo->tx_bytes = ar->target_stats.tx_byte;
1338 sinfo->filled |= STATION_INFO_TX_BYTES;
1339 sinfo->tx_packets = ar->target_stats.tx_pkt;
1340 sinfo->filled |= STATION_INFO_TX_PACKETS;
1343 sinfo->signal = ar->target_stats.cs_rssi;
1344 sinfo->filled |= STATION_INFO_SIGNAL;
1346 rate = ar->target_stats.tx_ucast_rate;
1348 if (is_rate_legacy(rate)) {
1349 sinfo->txrate.legacy = rate / 100;
1350 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1352 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1353 sinfo->txrate.mcs = mcs - 1;
1355 sinfo->txrate.mcs = mcs;
1358 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1359 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1361 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1362 sinfo->txrate.mcs = mcs - 1;
1364 sinfo->txrate.mcs = mcs;
1367 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1368 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1370 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1371 "invalid rate from stats: %d\n", rate);
1372 ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE);
1376 sinfo->filled |= STATION_INFO_TX_BITRATE;
1378 if (test_bit(CONNECTED, &ar->flag) &&
1379 test_bit(DTIM_PERIOD_AVAIL, &ar->flag) &&
1380 ar->nw_type == INFRA_NETWORK) {
1381 sinfo->filled |= STATION_INFO_BSS_PARAM;
1382 sinfo->bss_param.flags = 0;
1383 sinfo->bss_param.dtim_period = ar->assoc_bss_dtim_period;
1384 sinfo->bss_param.beacon_interval = ar->assoc_bss_beacon_int;
1390 static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1391 struct cfg80211_pmksa *pmksa)
1393 struct ath6kl *ar = ath6kl_priv(netdev);
1394 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1395 pmksa->pmkid, true);
1398 static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1399 struct cfg80211_pmksa *pmksa)
1401 struct ath6kl *ar = ath6kl_priv(netdev);
1402 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1403 pmksa->pmkid, false);
1406 static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1408 struct ath6kl *ar = ath6kl_priv(netdev);
1409 if (test_bit(CONNECTED, &ar->flag))
1410 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1415 static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1416 struct cfg80211_wowlan *wow)
1418 struct ath6kl *ar = wiphy_priv(wiphy);
1420 return ath6kl_hif_suspend(ar);
1424 static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1425 struct ieee80211_channel *chan,
1426 enum nl80211_channel_type channel_type)
1428 struct ath6kl *ar = ath6kl_priv(dev);
1430 if (!ath6kl_cfg80211_ready(ar))
1433 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1434 __func__, chan->center_freq, chan->hw_value);
1435 ar->next_chan = chan->center_freq;
1440 static bool ath6kl_is_p2p_ie(const u8 *pos)
1442 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1443 pos[2] == 0x50 && pos[3] == 0x6f &&
1444 pos[4] == 0x9a && pos[5] == 0x09;
1447 static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
1456 * Filter out P2P IE(s) since they will be included depending on
1457 * the Probe Request frame in ath6kl_send_go_probe_resp().
1460 if (ies && ies_len) {
1461 buf = kmalloc(ies_len, GFP_KERNEL);
1465 while (pos + 1 < ies + ies_len) {
1466 if (pos + 2 + pos[1] > ies + ies_len)
1468 if (!ath6kl_is_p2p_ie(pos)) {
1469 memcpy(buf + len, pos, 2 + pos[1]);
1476 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1482 static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1483 struct beacon_parameters *info, bool add)
1485 struct ath6kl *ar = ath6kl_priv(dev);
1486 struct ieee80211_mgmt *mgmt;
1489 struct wmi_connect_cmd p;
1493 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1495 if (!ath6kl_cfg80211_ready(ar))
1498 if (ar->next_mode != AP_NETWORK)
1501 if (info->beacon_ies) {
1502 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1504 info->beacon_ies_len);
1508 if (info->proberesp_ies) {
1509 res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
1510 info->proberesp_ies_len);
1514 if (info->assocresp_ies) {
1515 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1516 info->assocresp_ies,
1517 info->assocresp_ies_len);
1525 ar->ap_mode_bkey.valid = false;
1532 if (info->head == NULL)
1534 mgmt = (struct ieee80211_mgmt *) info->head;
1535 ies = mgmt->u.beacon.variable;
1536 if (ies > info->head + info->head_len)
1538 ies_len = info->head + info->head_len - ies;
1540 if (info->ssid == NULL)
1542 memcpy(ar->ssid, info->ssid, info->ssid_len);
1543 ar->ssid_len = info->ssid_len;
1544 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1545 return -EOPNOTSUPP; /* TODO */
1547 ar->dot11_auth_mode = OPEN_AUTH;
1549 memset(&p, 0, sizeof(p));
1551 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1552 switch (info->crypto.akm_suites[i]) {
1553 case WLAN_AKM_SUITE_8021X:
1554 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1555 p.auth_mode |= WPA_AUTH;
1556 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1557 p.auth_mode |= WPA2_AUTH;
1559 case WLAN_AKM_SUITE_PSK:
1560 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1561 p.auth_mode |= WPA_PSK_AUTH;
1562 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1563 p.auth_mode |= WPA2_PSK_AUTH;
1567 if (p.auth_mode == 0)
1568 p.auth_mode = NONE_AUTH;
1569 ar->auth_mode = p.auth_mode;
1571 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1572 switch (info->crypto.ciphers_pairwise[i]) {
1573 case WLAN_CIPHER_SUITE_WEP40:
1574 case WLAN_CIPHER_SUITE_WEP104:
1575 p.prwise_crypto_type |= WEP_CRYPT;
1577 case WLAN_CIPHER_SUITE_TKIP:
1578 p.prwise_crypto_type |= TKIP_CRYPT;
1580 case WLAN_CIPHER_SUITE_CCMP:
1581 p.prwise_crypto_type |= AES_CRYPT;
1585 if (p.prwise_crypto_type == 0) {
1586 p.prwise_crypto_type = NONE_CRYPT;
1587 ath6kl_set_cipher(ar, 0, true);
1588 } else if (info->crypto.n_ciphers_pairwise == 1)
1589 ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
1591 switch (info->crypto.cipher_group) {
1592 case WLAN_CIPHER_SUITE_WEP40:
1593 case WLAN_CIPHER_SUITE_WEP104:
1594 p.grp_crypto_type = WEP_CRYPT;
1596 case WLAN_CIPHER_SUITE_TKIP:
1597 p.grp_crypto_type = TKIP_CRYPT;
1599 case WLAN_CIPHER_SUITE_CCMP:
1600 p.grp_crypto_type = AES_CRYPT;
1603 p.grp_crypto_type = NONE_CRYPT;
1606 ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
1608 p.nw_type = AP_NETWORK;
1609 ar->nw_type = ar->next_mode;
1611 p.ssid_len = ar->ssid_len;
1612 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1613 p.dot11_auth_mode = ar->dot11_auth_mode;
1614 p.ch = cpu_to_le16(ar->next_chan);
1616 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1623 static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1624 struct beacon_parameters *info)
1626 return ath6kl_ap_beacon(wiphy, dev, info, true);
1629 static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1630 struct beacon_parameters *info)
1632 return ath6kl_ap_beacon(wiphy, dev, info, false);
1635 static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1637 struct ath6kl *ar = ath6kl_priv(dev);
1639 if (ar->nw_type != AP_NETWORK)
1641 if (!test_bit(CONNECTED, &ar->flag))
1644 ath6kl_wmi_disconnect_cmd(ar->wmi);
1645 clear_bit(CONNECTED, &ar->flag);
1650 static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1651 u8 *mac, struct station_parameters *params)
1653 struct ath6kl *ar = ath6kl_priv(dev);
1655 if (ar->nw_type != AP_NETWORK)
1658 /* Use this only for authorizing/unauthorizing a station */
1659 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1662 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1663 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1665 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1669 static int ath6kl_remain_on_channel(struct wiphy *wiphy,
1670 struct net_device *dev,
1671 struct ieee80211_channel *chan,
1672 enum nl80211_channel_type channel_type,
1673 unsigned int duration,
1676 struct ath6kl *ar = ath6kl_priv(dev);
1678 /* TODO: if already pending or ongoing remain-on-channel,
1680 *cookie = 1; /* only a single pending request is supported */
1682 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
1686 static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
1687 struct net_device *dev,
1690 struct ath6kl *ar = ath6kl_priv(dev);
1695 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
1698 static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
1699 size_t len, unsigned int freq)
1705 const struct ieee80211_mgmt *mgmt;
1707 mgmt = (const struct ieee80211_mgmt *) buf;
1709 /* Include P2P IE(s) from the frame generated in user space. */
1711 p2p = kmalloc(len, GFP_KERNEL);
1716 pos = mgmt->u.probe_resp.variable;
1717 while (pos + 1 < buf + len) {
1718 if (pos + 2 + pos[1] > buf + len)
1720 if (ath6kl_is_p2p_ie(pos)) {
1721 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
1722 p2p_len += 2 + pos[1];
1727 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
1733 static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1734 struct ieee80211_channel *chan, bool offchan,
1735 enum nl80211_channel_type channel_type,
1736 bool channel_type_valid, unsigned int wait,
1737 const u8 *buf, size_t len, bool no_cck, u64 *cookie)
1739 struct ath6kl *ar = ath6kl_priv(dev);
1741 const struct ieee80211_mgmt *mgmt;
1743 mgmt = (const struct ieee80211_mgmt *) buf;
1744 if (buf + len >= mgmt->u.probe_resp.variable &&
1745 ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
1746 ieee80211_is_probe_resp(mgmt->frame_control)) {
1748 * Send Probe Response frame in AP mode using a separate WMI
1749 * command to allow the target to fill in the generic IEs.
1751 *cookie = 0; /* TX status not supported */
1752 return ath6kl_send_go_probe_resp(ar, buf, len,
1756 id = ar->send_action_id++;
1759 * 0 is a reserved value in the WMI command and shall not be
1760 * used for the command.
1762 id = ar->send_action_id++;
1766 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
1770 static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
1771 struct net_device *dev,
1772 u16 frame_type, bool reg)
1774 struct ath6kl *ar = ath6kl_priv(dev);
1776 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
1777 __func__, frame_type, reg);
1778 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
1780 * Note: This notification callback is not allowed to sleep, so
1781 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
1782 * hardcode target to report Probe Request frames all the time.
1784 ar->probe_req_report = reg;
1788 static const struct ieee80211_txrx_stypes
1789 ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1790 [NL80211_IFTYPE_STATION] = {
1791 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1792 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1793 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1794 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1796 [NL80211_IFTYPE_P2P_CLIENT] = {
1797 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1798 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1799 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1800 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1802 [NL80211_IFTYPE_P2P_GO] = {
1803 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1804 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1805 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1806 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1810 static struct cfg80211_ops ath6kl_cfg80211_ops = {
1811 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1812 .scan = ath6kl_cfg80211_scan,
1813 .connect = ath6kl_cfg80211_connect,
1814 .disconnect = ath6kl_cfg80211_disconnect,
1815 .add_key = ath6kl_cfg80211_add_key,
1816 .get_key = ath6kl_cfg80211_get_key,
1817 .del_key = ath6kl_cfg80211_del_key,
1818 .set_default_key = ath6kl_cfg80211_set_default_key,
1819 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1820 .set_tx_power = ath6kl_cfg80211_set_txpower,
1821 .get_tx_power = ath6kl_cfg80211_get_txpower,
1822 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1823 .join_ibss = ath6kl_cfg80211_join_ibss,
1824 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1825 .get_station = ath6kl_get_station,
1826 .set_pmksa = ath6kl_set_pmksa,
1827 .del_pmksa = ath6kl_del_pmksa,
1828 .flush_pmksa = ath6kl_flush_pmksa,
1829 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
1831 .suspend = ar6k_cfg80211_suspend,
1833 .set_channel = ath6kl_set_channel,
1834 .add_beacon = ath6kl_add_beacon,
1835 .set_beacon = ath6kl_set_beacon,
1836 .del_beacon = ath6kl_del_beacon,
1837 .change_station = ath6kl_change_station,
1838 .remain_on_channel = ath6kl_remain_on_channel,
1839 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
1840 .mgmt_tx = ath6kl_mgmt_tx,
1841 .mgmt_frame_register = ath6kl_mgmt_frame_register,
1844 struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1847 struct wireless_dev *wdev;
1850 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1852 ath6kl_err("couldn't allocate wireless device\n");
1856 /* create a new wiphy for use with cfg80211 */
1857 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1859 ath6kl_err("couldn't allocate wiphy device\n");
1864 ar = wiphy_priv(wdev->wiphy);
1865 ar->p2p = !!ath6kl_p2p;
1867 wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
1869 wdev->wiphy->max_remain_on_channel_duration = 5000;
1871 /* set device pointer for wiphy */
1872 set_wiphy_dev(wdev->wiphy, dev);
1874 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1875 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1877 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
1878 BIT(NL80211_IFTYPE_P2P_CLIENT);
1880 /* max num of ssids that can be probed during scanning */
1881 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
1882 wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
1883 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1884 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1885 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1887 wdev->wiphy->cipher_suites = cipher_suites;
1888 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1890 ret = wiphy_register(wdev->wiphy);
1892 ath6kl_err("couldn't register wiphy device\n");
1893 wiphy_free(wdev->wiphy);
1901 void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1903 struct wireless_dev *wdev = ar->wdev;
1906 cfg80211_scan_done(ar->scan_req, true);
1907 ar->scan_req = NULL;
1913 wiphy_unregister(wdev->wiphy);
1914 wiphy_free(wdev->wiphy);