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.
23 static unsigned int ath6kl_p2p;
25 module_param(ath6kl_p2p, uint, 0644);
27 #define RATETAB_ENT(_rate, _rateid, _flags) { \
30 .hw_value = (_rateid), \
33 #define CHAN2G(_channel, _freq, _flags) { \
34 .band = IEEE80211_BAND_2GHZ, \
35 .hw_value = (_channel), \
36 .center_freq = (_freq), \
38 .max_antenna_gain = 0, \
42 #define CHAN5G(_channel, _flags) { \
43 .band = IEEE80211_BAND_5GHZ, \
44 .hw_value = (_channel), \
45 .center_freq = 5000 + (5 * (_channel)), \
47 .max_antenna_gain = 0, \
51 static struct ieee80211_rate ath6kl_rates[] = {
52 RATETAB_ENT(10, 0x1, 0),
53 RATETAB_ENT(20, 0x2, 0),
54 RATETAB_ENT(55, 0x4, 0),
55 RATETAB_ENT(110, 0x8, 0),
56 RATETAB_ENT(60, 0x10, 0),
57 RATETAB_ENT(90, 0x20, 0),
58 RATETAB_ENT(120, 0x40, 0),
59 RATETAB_ENT(180, 0x80, 0),
60 RATETAB_ENT(240, 0x100, 0),
61 RATETAB_ENT(360, 0x200, 0),
62 RATETAB_ENT(480, 0x400, 0),
63 RATETAB_ENT(540, 0x800, 0),
66 #define ath6kl_a_rates (ath6kl_rates + 4)
67 #define ath6kl_a_rates_size 8
68 #define ath6kl_g_rates (ath6kl_rates + 0)
69 #define ath6kl_g_rates_size 12
71 static struct ieee80211_channel ath6kl_2ghz_channels[] = {
88 static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
89 CHAN5G(34, 0), CHAN5G(36, 0),
90 CHAN5G(38, 0), CHAN5G(40, 0),
91 CHAN5G(42, 0), CHAN5G(44, 0),
92 CHAN5G(46, 0), CHAN5G(48, 0),
93 CHAN5G(52, 0), CHAN5G(56, 0),
94 CHAN5G(60, 0), CHAN5G(64, 0),
95 CHAN5G(100, 0), CHAN5G(104, 0),
96 CHAN5G(108, 0), CHAN5G(112, 0),
97 CHAN5G(116, 0), CHAN5G(120, 0),
98 CHAN5G(124, 0), CHAN5G(128, 0),
99 CHAN5G(132, 0), CHAN5G(136, 0),
100 CHAN5G(140, 0), CHAN5G(149, 0),
101 CHAN5G(153, 0), CHAN5G(157, 0),
102 CHAN5G(161, 0), CHAN5G(165, 0),
103 CHAN5G(184, 0), CHAN5G(188, 0),
104 CHAN5G(192, 0), CHAN5G(196, 0),
105 CHAN5G(200, 0), CHAN5G(204, 0),
106 CHAN5G(208, 0), CHAN5G(212, 0),
110 static struct ieee80211_supported_band ath6kl_band_2ghz = {
111 .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
112 .channels = ath6kl_2ghz_channels,
113 .n_bitrates = ath6kl_g_rates_size,
114 .bitrates = ath6kl_g_rates,
117 static struct ieee80211_supported_band ath6kl_band_5ghz = {
118 .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
119 .channels = ath6kl_5ghz_a_channels,
120 .n_bitrates = ath6kl_a_rates_size,
121 .bitrates = ath6kl_a_rates,
124 static int ath6kl_set_wpa_version(struct ath6kl *ar,
125 enum nl80211_wpa_versions wpa_version)
127 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);
130 ar->auth_mode = NONE_AUTH;
131 } else if (wpa_version & NL80211_WPA_VERSION_2) {
132 ar->auth_mode = WPA2_AUTH;
133 } else if (wpa_version & NL80211_WPA_VERSION_1) {
134 ar->auth_mode = WPA_AUTH;
136 ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
143 static int ath6kl_set_auth_type(struct ath6kl *ar,
144 enum nl80211_auth_type auth_type)
147 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
150 case NL80211_AUTHTYPE_OPEN_SYSTEM:
151 ar->dot11_auth_mode = OPEN_AUTH;
153 case NL80211_AUTHTYPE_SHARED_KEY:
154 ar->dot11_auth_mode = SHARED_AUTH;
156 case NL80211_AUTHTYPE_NETWORK_EAP:
157 ar->dot11_auth_mode = LEAP_AUTH;
160 case NL80211_AUTHTYPE_AUTOMATIC:
161 ar->dot11_auth_mode = OPEN_AUTH;
162 ar->auto_auth_stage = AUTH_OPEN_IN_PROGRESS;
166 ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
173 static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast)
175 u8 *ar_cipher = ucast ? &ar->prwise_crypto : &ar->grp_crypto;
176 u8 *ar_cipher_len = ucast ? &ar->prwise_crypto_len :
179 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
180 __func__, cipher, ucast);
184 /* our own hack to use value 0 as no crypto used */
185 *ar_cipher = NONE_CRYPT;
188 case WLAN_CIPHER_SUITE_WEP40:
189 *ar_cipher = WEP_CRYPT;
192 case WLAN_CIPHER_SUITE_WEP104:
193 *ar_cipher = WEP_CRYPT;
196 case WLAN_CIPHER_SUITE_TKIP:
197 *ar_cipher = TKIP_CRYPT;
200 case WLAN_CIPHER_SUITE_CCMP:
201 *ar_cipher = AES_CRYPT;
205 ath6kl_err("cipher 0x%x not supported\n", cipher);
212 static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
214 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
216 if (key_mgmt == WLAN_AKM_SUITE_PSK) {
217 if (ar->auth_mode == WPA_AUTH)
218 ar->auth_mode = WPA_PSK_AUTH;
219 else if (ar->auth_mode == WPA2_AUTH)
220 ar->auth_mode = WPA2_PSK_AUTH;
221 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
222 ar->auth_mode = NONE_AUTH;
226 static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
228 if (!test_bit(WMI_READY, &ar->flag)) {
229 ath6kl_err("wmi is not ready\n");
233 if (!test_bit(WLAN_ENABLED, &ar->flag)) {
234 ath6kl_err("wlan disabled\n");
241 static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
242 struct cfg80211_connect_params *sme)
244 struct ath6kl *ar = ath6kl_priv(dev);
247 ar->sme_state = SME_CONNECTING;
249 if (!ath6kl_cfg80211_ready(ar))
252 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
253 ath6kl_err("destroy in progress\n");
257 if (test_bit(SKIP_SCAN, &ar->flag) &&
258 ((sme->channel && sme->channel->center_freq == 0) ||
259 (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
260 ath6kl_err("SkipScan: channel or bssid invalid\n");
264 if (down_interruptible(&ar->sem)) {
265 ath6kl_err("busy, couldn't get access\n");
269 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
270 ath6kl_err("busy, destroy in progress\n");
275 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
277 * sleep until the command queue drains
279 wait_event_interruptible_timeout(ar->event_wq,
280 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
282 if (signal_pending(current)) {
283 ath6kl_err("cmd queue drain timeout\n");
289 if (test_bit(CONNECTED, &ar->flag) &&
290 ar->ssid_len == sme->ssid_len &&
291 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
292 ar->reconnect_flag = true;
293 status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid,
298 ath6kl_err("wmi_reconnect_cmd failed\n");
302 } else if (ar->ssid_len == sme->ssid_len &&
303 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
304 ath6kl_disconnect(ar);
307 memset(ar->ssid, 0, sizeof(ar->ssid));
308 ar->ssid_len = sme->ssid_len;
309 memcpy(ar->ssid, sme->ssid, sme->ssid_len);
312 ar->ch_hint = sme->channel->center_freq;
314 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
315 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
316 memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid));
318 ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions);
320 status = ath6kl_set_auth_type(ar, sme->auth_type);
326 if (sme->crypto.n_ciphers_pairwise)
327 ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
329 ath6kl_set_cipher(ar, 0, true);
331 ath6kl_set_cipher(ar, sme->crypto.cipher_group, false);
333 if (sme->crypto.n_akm_suites)
334 ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
336 if ((sme->key_len) &&
337 (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) {
338 struct ath6kl_key *key = NULL;
340 if (sme->key_idx < WMI_MIN_KEY_INDEX ||
341 sme->key_idx > WMI_MAX_KEY_INDEX) {
342 ath6kl_err("key index %d out of bounds\n",
348 key = &ar->keys[sme->key_idx];
349 key->key_len = sme->key_len;
350 memcpy(key->key, sme->key, key->key_len);
351 key->cipher = ar->prwise_crypto;
352 ar->def_txkey_index = sme->key_idx;
354 ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx,
356 GROUP_USAGE | TX_USAGE,
359 key->key, KEY_OP_INIT_VAL, NULL,
363 if (!ar->usr_bss_filter) {
364 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) {
365 ath6kl_err("couldn't set bss filtering\n");
371 ar->nw_type = ar->next_mode;
373 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
374 "%s: connect called with authmode %d dot11 auth %d"
375 " PW crypto %d PW crypto len %d GRP crypto %d"
376 " GRP crypto len %d channel hint %u\n",
378 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
379 ar->prwise_crypto_len, ar->grp_crypto,
380 ar->grp_crypto_len, ar->ch_hint);
382 ar->reconnect_flag = 0;
383 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
384 ar->dot11_auth_mode, ar->auth_mode,
386 ar->prwise_crypto_len,
387 ar->grp_crypto, ar->grp_crypto_len,
388 ar->ssid_len, ar->ssid,
389 ar->req_bssid, ar->ch_hint,
390 ar->connect_ctrl_flags);
394 if (status == -EINVAL) {
395 memset(ar->ssid, 0, sizeof(ar->ssid));
397 ath6kl_err("invalid request\n");
400 ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
404 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
405 ((ar->auth_mode == WPA_PSK_AUTH)
406 || (ar->auth_mode == WPA2_PSK_AUTH))) {
407 mod_timer(&ar->disconnect_timer,
408 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
411 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
412 set_bit(CONNECT_PEND, &ar->flag);
417 void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel,
418 u8 *bssid, u16 listen_intvl,
420 enum network_type nw_type,
421 u8 beacon_ie_len, u8 assoc_req_len,
422 u8 assoc_resp_len, u8 *assoc_info)
426 struct cfg80211_bss *bss = NULL;
427 struct ieee80211_mgmt *mgmt = NULL;
428 struct ieee80211_channel *ibss_ch = NULL;
429 s32 signal = 50 * 100;
431 unsigned char ie_buf[256];
432 unsigned char *ptr_ie_buf = ie_buf;
433 unsigned char *ieeemgmtbuf = NULL;
434 u8 source_mac[ETH_ALEN];
436 /* capinfo + listen interval */
437 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
439 /* capinfo + status code + associd */
440 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
442 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
443 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
444 assoc_resp_ie_offset;
446 assoc_req_len -= assoc_req_ie_offset;
447 assoc_resp_len -= assoc_resp_ie_offset;
449 ar->auto_auth_stage = AUTH_IDLE;
451 if (nw_type & ADHOC_NETWORK) {
452 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
453 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
454 "%s: ath6k not in ibss mode\n", __func__);
459 if (nw_type & INFRA_NETWORK) {
460 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
461 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
462 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
463 "%s: ath6k not in station mode\n", __func__);
469 * Earlier we were updating the cfg about bss by making a beacon frame
470 * only if the entry for bss is not there. This can have some issue if
471 * ROAM event is generated and a heavy traffic is ongoing. The ROAM
472 * event is handled through a work queue and by the time it really gets
473 * handled, BSS would have been aged out. So it is better to update the
474 * cfg about BSS irrespective of its entry being present right now or
478 if (nw_type & ADHOC_NETWORK) {
479 /* construct 802.11 mgmt beacon */
481 *ptr_ie_buf++ = WLAN_EID_SSID;
482 *ptr_ie_buf++ = ar->ssid_len;
483 memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len);
484 ptr_ie_buf += ar->ssid_len;
486 *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
487 *ptr_ie_buf++ = 2; /* length */
488 *ptr_ie_buf++ = 0; /* ATIM window */
489 *ptr_ie_buf++ = 0; /* ATIM window */
491 /* TODO: update ibss params and include supported rates,
492 * DS param set, extened support rates, wmm. */
494 ie_buf_len = ptr_ie_buf - ie_buf;
497 capability |= WLAN_CAPABILITY_IBSS;
499 if (ar->prwise_crypto == WEP_CRYPT)
500 capability |= WLAN_CAPABILITY_PRIVACY;
502 memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN);
505 capability = *(u16 *) (&assoc_info[beacon_ie_len]);
506 memcpy(source_mac, bssid, ETH_ALEN);
507 ptr_ie_buf = assoc_req_ie;
508 ie_buf_len = assoc_req_len;
511 size = offsetof(struct ieee80211_mgmt, u)
512 + sizeof(mgmt->u.beacon)
515 ieeemgmtbuf = kzalloc(size, GFP_ATOMIC);
517 ath6kl_err("ieee mgmt buf alloc error\n");
521 mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
522 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
523 IEEE80211_STYPE_BEACON);
524 memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */
525 memcpy(mgmt->sa, source_mac, ETH_ALEN);
526 memcpy(mgmt->bssid, bssid, ETH_ALEN);
527 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl);
528 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
529 memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
531 ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
533 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
534 "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n",
535 __func__, mgmt->bssid, ibss_ch->hw_value,
536 beacon_intvl, capability);
538 bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
540 size, signal, GFP_KERNEL);
542 cfg80211_put_bss(bss);
544 if (nw_type & ADHOC_NETWORK) {
545 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
549 if (ar->sme_state == SME_CONNECTING) {
550 /* inform connect result to cfg80211 */
551 ar->sme_state = SME_CONNECTED;
552 cfg80211_connect_result(ar->net_dev, bssid,
553 assoc_req_ie, assoc_req_len,
554 assoc_resp_ie, assoc_resp_len,
555 WLAN_STATUS_SUCCESS, GFP_KERNEL);
556 } else if (ar->sme_state == SME_CONNECTED) {
557 /* inform roam event to cfg80211 */
558 cfg80211_roamed(ar->net_dev, ibss_ch, bssid,
559 assoc_req_ie, assoc_req_len,
560 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
564 static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
565 struct net_device *dev, u16 reason_code)
567 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
569 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
572 if (!ath6kl_cfg80211_ready(ar))
575 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
576 ath6kl_err("busy, destroy in progress\n");
580 if (down_interruptible(&ar->sem)) {
581 ath6kl_err("busy, couldn't get access\n");
585 ar->reconnect_flag = 0;
586 ath6kl_disconnect(ar);
587 memset(ar->ssid, 0, sizeof(ar->ssid));
590 if (!test_bit(SKIP_SCAN, &ar->flag))
591 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
598 void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
599 u8 *bssid, u8 assoc_resp_len,
600 u8 *assoc_info, u16 proto_reason)
602 struct ath6kl_key *key = NULL;
606 cfg80211_scan_done(ar->scan_req, true);
610 if (ar->nw_type & ADHOC_NETWORK) {
611 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
612 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
613 "%s: ath6k not in ibss mode\n", __func__);
616 memset(bssid, 0, ETH_ALEN);
617 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
621 if (ar->nw_type & INFRA_NETWORK) {
622 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
623 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
624 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
625 "%s: ath6k not in station mode\n", __func__);
630 if (!test_bit(CONNECT_PEND, &ar->flag)) {
631 if (reason != DISCONNECT_CMD)
632 ath6kl_wmi_disconnect_cmd(ar->wmi);
637 if (reason == NO_NETWORK_AVAIL) {
638 /* connect cmd failed */
639 ath6kl_wmi_disconnect_cmd(ar->wmi);
643 if (reason != DISCONNECT_CMD)
646 if (!ar->auto_auth_stage) {
647 clear_bit(CONNECT_PEND, &ar->flag);
649 if (ar->sme_state == SME_CONNECTING) {
650 cfg80211_connect_result(ar->net_dev,
653 WLAN_STATUS_UNSPECIFIED_FAILURE,
655 } else if (ar->sme_state == SME_CONNECTED) {
656 cfg80211_disconnected(ar->net_dev, reason,
657 NULL, 0, GFP_KERNEL);
660 ar->sme_state = SME_DISCONNECTED;
664 if (ar->dot11_auth_mode != OPEN_AUTH)
668 * If the current auth algorithm is open, try shared and
669 * make autoAuthStage idle. We do not make it leap for now
672 key = &ar->keys[ar->def_txkey_index];
673 if (down_interruptible(&ar->sem)) {
674 ath6kl_err("busy, couldn't get access\n");
678 ar->dot11_auth_mode = SHARED_AUTH;
679 ar->auto_auth_stage = AUTH_IDLE;
681 ath6kl_wmi_addkey_cmd(ar->wmi,
684 GROUP_USAGE | TX_USAGE,
687 KEY_OP_INIT_VAL, NULL,
690 status = ath6kl_wmi_connect_cmd(ar->wmi,
695 ar->prwise_crypto_len,
702 ar->connect_ctrl_flags);
706 static inline bool is_ch_11a(u16 ch)
708 return (!((ch >= 2412) && (ch <= 2484)));
711 /* struct ath6kl_node_table::nt_nodelock is locked when calling this */
712 void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni)
714 struct ieee80211_mgmt *mgmt;
715 struct ieee80211_channel *channel;
716 struct ieee80211_supported_band *band;
717 struct ath6kl_common_ie *cie;
723 if (is_ch_11a(cie->ie_chan))
724 band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */
725 else if ((cie->ie_erp) || (cie->ie_xrates))
726 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */
728 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */
731 channel = ieee80211_get_channel(wiphy, freq);
732 signal = ni->ni_snr * 100;
734 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
735 "%s: bssid %pM ch %d freq %d size %d\n", __func__,
736 ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen);
738 * Both Beacon and Probe Response frames have same payload structure,
739 * so it is fine to share the parser for both.
741 if (ni->ni_framelen < 8 + 2 + 2)
743 mgmt = (struct ieee80211_mgmt *) (ni->ni_buf -
744 offsetof(struct ieee80211_mgmt, u));
745 cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr,
746 le64_to_cpu(mgmt->u.beacon.timestamp),
747 le16_to_cpu(mgmt->u.beacon.capab_info),
748 le16_to_cpu(mgmt->u.beacon.beacon_int),
749 mgmt->u.beacon.variable,
750 ni->ni_buf + ni->ni_framelen -
751 mgmt->u.beacon.variable,
755 static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
756 struct cfg80211_scan_request *request)
758 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
760 u16 *channels = NULL;
763 if (!ath6kl_cfg80211_ready(ar))
766 if (!ar->usr_bss_filter) {
767 ret = ath6kl_wmi_bssfilter_cmd(
769 (test_bit(CONNECTED, &ar->flag) ?
770 ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0);
772 ath6kl_err("couldn't set bss filtering\n");
777 if (request->n_ssids && request->ssids[0].ssid_len) {
780 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
781 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
783 for (i = 0; i < request->n_ssids; i++)
784 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
786 request->ssids[i].ssid_len,
787 request->ssids[i].ssid);
791 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_REQ,
792 request->ie, request->ie_len);
794 ath6kl_err("failed to set Probe Request appie for "
801 * Scan only the requested channels if the request specifies a set of
802 * channels. If the list is longer than the target supports, do not
803 * configure the list and instead, scan all available channels.
805 if (request->n_channels > 0 &&
806 request->n_channels <= WMI_MAX_CHANNELS) {
809 n_channels = request->n_channels;
811 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
812 if (channels == NULL) {
813 ath6kl_warn("failed to set scan channels, "
814 "scan all channels");
818 for (i = 0; i < n_channels; i++)
819 channels[i] = request->channels[i]->center_freq;
822 ret = ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
823 false, 0, 0, n_channels, channels);
825 ath6kl_err("wmi_startscan_cmd failed\n");
827 ar->scan_req = request;
834 void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
838 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
843 if ((status == -ECANCELED) || (status == -EBUSY)) {
844 cfg80211_scan_done(ar->scan_req, true);
848 /* Translate data to cfg80211 mgmt format */
849 wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
851 cfg80211_scan_done(ar->scan_req, false);
853 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
854 for (i = 0; i < ar->scan_req->n_ssids; i++) {
855 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
865 static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
866 u8 key_index, bool pairwise,
868 struct key_params *params)
870 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
871 struct ath6kl_key *key = NULL;
876 if (!ath6kl_cfg80211_ready(ar))
879 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
880 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
881 "%s: key index %d out of bounds\n", __func__,
886 key = &ar->keys[key_index];
887 memset(key, 0, sizeof(struct ath6kl_key));
890 key_usage = PAIRWISE_USAGE;
892 key_usage = GROUP_USAGE;
895 if (params->key_len > WLAN_MAX_KEY_LEN ||
896 params->seq_len > sizeof(key->seq))
899 key->key_len = params->key_len;
900 memcpy(key->key, params->key, key->key_len);
901 key->seq_len = params->seq_len;
902 memcpy(key->seq, params->seq, key->seq_len);
903 key->cipher = params->cipher;
906 switch (key->cipher) {
907 case WLAN_CIPHER_SUITE_WEP40:
908 case WLAN_CIPHER_SUITE_WEP104:
909 key_type = WEP_CRYPT;
912 case WLAN_CIPHER_SUITE_TKIP:
913 key_type = TKIP_CRYPT;
916 case WLAN_CIPHER_SUITE_CCMP:
917 key_type = AES_CRYPT;
924 if (((ar->auth_mode == WPA_PSK_AUTH)
925 || (ar->auth_mode == WPA2_PSK_AUTH))
926 && (key_usage & GROUP_USAGE))
927 del_timer(&ar->disconnect_timer);
929 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
930 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
931 __func__, key_index, key->key_len, key_type,
932 key_usage, key->seq_len);
934 ar->def_txkey_index = key_index;
936 if (ar->nw_type == AP_NETWORK && !pairwise &&
937 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
938 ar->ap_mode_bkey.valid = true;
939 ar->ap_mode_bkey.key_index = key_index;
940 ar->ap_mode_bkey.key_type = key_type;
941 ar->ap_mode_bkey.key_len = key->key_len;
942 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
943 if (!test_bit(CONNECTED, &ar->flag)) {
944 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
945 "key configuration until AP mode has been "
948 * The key will be set in ath6kl_connect_ap_mode() once
949 * the connected event is received from the target.
955 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
956 key_type, key_usage, key->key_len,
957 key->seq, key->key, KEY_OP_INIT_VAL,
958 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
966 static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
967 u8 key_index, bool pairwise,
970 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
972 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
974 if (!ath6kl_cfg80211_ready(ar))
977 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
978 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
979 "%s: key index %d out of bounds\n", __func__,
984 if (!ar->keys[key_index].key_len) {
985 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
986 "%s: index %d is empty\n", __func__, key_index);
990 ar->keys[key_index].key_len = 0;
992 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
995 static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
996 u8 key_index, bool pairwise,
997 const u8 *mac_addr, void *cookie,
998 void (*callback) (void *cookie,
999 struct key_params *))
1001 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
1002 struct ath6kl_key *key = NULL;
1003 struct key_params params;
1005 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1007 if (!ath6kl_cfg80211_ready(ar))
1010 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1011 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1012 "%s: key index %d out of bounds\n", __func__,
1017 key = &ar->keys[key_index];
1018 memset(¶ms, 0, sizeof(params));
1019 params.cipher = key->cipher;
1020 params.key_len = key->key_len;
1021 params.seq_len = key->seq_len;
1022 params.seq = key->seq;
1023 params.key = key->key;
1025 callback(cookie, ¶ms);
1027 return key->key_len ? 0 : -ENOENT;
1030 static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1031 struct net_device *ndev,
1032 u8 key_index, bool unicast,
1035 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
1036 struct ath6kl_key *key = NULL;
1039 enum crypto_type key_type = NONE_CRYPT;
1041 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1043 if (!ath6kl_cfg80211_ready(ar))
1046 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1047 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1048 "%s: key index %d out of bounds\n",
1049 __func__, key_index);
1053 if (!ar->keys[key_index].key_len) {
1054 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1055 __func__, key_index);
1059 ar->def_txkey_index = key_index;
1060 key = &ar->keys[ar->def_txkey_index];
1061 key_usage = GROUP_USAGE;
1062 if (ar->prwise_crypto == WEP_CRYPT)
1063 key_usage |= TX_USAGE;
1065 key_type = ar->prwise_crypto;
1067 key_type = ar->grp_crypto;
1069 if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
1070 return 0; /* Delay until AP mode has been started */
1072 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
1073 key_type, key_usage,
1074 key->key_len, key->seq, key->key,
1075 KEY_OP_INIT_VAL, NULL,
1083 void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
1086 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1087 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1089 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
1090 (ismcast ? NL80211_KEYTYPE_GROUP :
1091 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1095 static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1097 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1100 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1103 if (!ath6kl_cfg80211_ready(ar))
1106 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1107 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1109 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1118 * The type nl80211_tx_power_setting replaces the following
1119 * data type from 2.6.36 onwards
1121 static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1122 enum nl80211_tx_power_setting type,
1125 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1128 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1131 if (!ath6kl_cfg80211_ready(ar))
1135 case NL80211_TX_POWER_AUTOMATIC:
1137 case NL80211_TX_POWER_LIMITED:
1138 ar->tx_pwr = ath6kl_dbm = dbm;
1141 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1146 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
1151 static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1153 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1155 if (!ath6kl_cfg80211_ready(ar))
1158 if (test_bit(CONNECTED, &ar->flag)) {
1161 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
1162 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1166 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1169 if (signal_pending(current)) {
1170 ath6kl_err("target did not respond\n");
1179 static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1180 struct net_device *dev,
1181 bool pmgmt, int timeout)
1183 struct ath6kl *ar = ath6kl_priv(dev);
1184 struct wmi_power_mode_cmd mode;
1186 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1187 __func__, pmgmt, timeout);
1189 if (!ath6kl_cfg80211_ready(ar))
1193 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1194 mode.pwr_mode = REC_POWER;
1196 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1197 mode.pwr_mode = MAX_PERF_POWER;
1200 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
1201 ath6kl_err("wmi_powermode_cmd failed\n");
1208 static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1209 struct net_device *ndev,
1210 enum nl80211_iftype type, u32 *flags,
1211 struct vif_params *params)
1213 struct ath6kl *ar = ath6kl_priv(ndev);
1214 struct wireless_dev *wdev = ar->wdev;
1216 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1218 if (!ath6kl_cfg80211_ready(ar))
1222 case NL80211_IFTYPE_STATION:
1223 ar->next_mode = INFRA_NETWORK;
1225 case NL80211_IFTYPE_ADHOC:
1226 ar->next_mode = ADHOC_NETWORK;
1228 case NL80211_IFTYPE_AP:
1229 ar->next_mode = AP_NETWORK;
1231 case NL80211_IFTYPE_P2P_CLIENT:
1232 ar->next_mode = INFRA_NETWORK;
1234 case NL80211_IFTYPE_P2P_GO:
1235 ar->next_mode = AP_NETWORK;
1238 ath6kl_err("invalid interface type %u\n", type);
1242 wdev->iftype = type;
1247 static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1248 struct net_device *dev,
1249 struct cfg80211_ibss_params *ibss_param)
1251 struct ath6kl *ar = ath6kl_priv(dev);
1254 if (!ath6kl_cfg80211_ready(ar))
1257 ar->ssid_len = ibss_param->ssid_len;
1258 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1260 if (ibss_param->channel)
1261 ar->ch_hint = ibss_param->channel->center_freq;
1263 if (ibss_param->channel_fixed) {
1265 * TODO: channel_fixed: The channel should be fixed, do not
1266 * search for IBSSs to join on other channels. Target
1267 * firmware does not support this feature, needs to be
1273 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1274 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1275 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1277 ath6kl_set_wpa_version(ar, 0);
1279 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1283 if (ibss_param->privacy) {
1284 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1285 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1287 ath6kl_set_cipher(ar, 0, true);
1288 ath6kl_set_cipher(ar, 0, false);
1291 ar->nw_type = ar->next_mode;
1293 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1294 "%s: connect called with authmode %d dot11 auth %d"
1295 " PW crypto %d PW crypto len %d GRP crypto %d"
1296 " GRP crypto len %d channel hint %u\n",
1298 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1299 ar->prwise_crypto_len, ar->grp_crypto,
1300 ar->grp_crypto_len, ar->ch_hint);
1302 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1303 ar->dot11_auth_mode, ar->auth_mode,
1305 ar->prwise_crypto_len,
1306 ar->grp_crypto, ar->grp_crypto_len,
1307 ar->ssid_len, ar->ssid,
1308 ar->req_bssid, ar->ch_hint,
1309 ar->connect_ctrl_flags);
1310 set_bit(CONNECT_PEND, &ar->flag);
1315 static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1316 struct net_device *dev)
1318 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1320 if (!ath6kl_cfg80211_ready(ar))
1323 ath6kl_disconnect(ar);
1324 memset(ar->ssid, 0, sizeof(ar->ssid));
1330 static const u32 cipher_suites[] = {
1331 WLAN_CIPHER_SUITE_WEP40,
1332 WLAN_CIPHER_SUITE_WEP104,
1333 WLAN_CIPHER_SUITE_TKIP,
1334 WLAN_CIPHER_SUITE_CCMP,
1337 static bool is_rate_legacy(s32 rate)
1339 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1340 6000, 9000, 12000, 18000, 24000,
1345 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1346 if (rate == legacy[i])
1352 static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1354 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1355 52000, 58500, 65000, 72200
1359 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1360 if (rate == ht20[i]) {
1361 if (i == ARRAY_SIZE(ht20) - 1)
1362 /* last rate uses sgi */
1374 static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1376 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1377 81000, 108000, 121500, 135000,
1382 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1383 if (rate == ht40[i]) {
1384 if (i == ARRAY_SIZE(ht40) - 1)
1385 /* last rate uses sgi */
1398 static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1399 u8 *mac, struct station_info *sinfo)
1401 struct ath6kl *ar = ath6kl_priv(dev);
1408 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1411 if (down_interruptible(&ar->sem))
1414 set_bit(STATS_UPDATE_PEND, &ar->flag);
1416 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1423 left = wait_event_interruptible_timeout(ar->event_wq,
1424 !test_bit(STATS_UPDATE_PEND,
1435 if (ar->target_stats.rx_byte) {
1436 sinfo->rx_bytes = ar->target_stats.rx_byte;
1437 sinfo->filled |= STATION_INFO_RX_BYTES;
1438 sinfo->rx_packets = ar->target_stats.rx_pkt;
1439 sinfo->filled |= STATION_INFO_RX_PACKETS;
1442 if (ar->target_stats.tx_byte) {
1443 sinfo->tx_bytes = ar->target_stats.tx_byte;
1444 sinfo->filled |= STATION_INFO_TX_BYTES;
1445 sinfo->tx_packets = ar->target_stats.tx_pkt;
1446 sinfo->filled |= STATION_INFO_TX_PACKETS;
1449 sinfo->signal = ar->target_stats.cs_rssi;
1450 sinfo->filled |= STATION_INFO_SIGNAL;
1452 rate = ar->target_stats.tx_ucast_rate;
1454 if (is_rate_legacy(rate)) {
1455 sinfo->txrate.legacy = rate / 100;
1456 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1458 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1459 sinfo->txrate.mcs = mcs - 1;
1461 sinfo->txrate.mcs = mcs;
1464 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1465 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1467 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1468 sinfo->txrate.mcs = mcs - 1;
1470 sinfo->txrate.mcs = mcs;
1473 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1474 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1476 ath6kl_warn("invalid rate: %d\n", rate);
1480 sinfo->filled |= STATION_INFO_TX_BITRATE;
1485 static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1486 struct cfg80211_pmksa *pmksa)
1488 struct ath6kl *ar = ath6kl_priv(netdev);
1489 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1490 pmksa->pmkid, true);
1493 static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1494 struct cfg80211_pmksa *pmksa)
1496 struct ath6kl *ar = ath6kl_priv(netdev);
1497 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1498 pmksa->pmkid, false);
1501 static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1503 struct ath6kl *ar = ath6kl_priv(netdev);
1504 if (test_bit(CONNECTED, &ar->flag))
1505 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1510 static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1511 struct cfg80211_wowlan *wow)
1513 struct ath6kl *ar = wiphy_priv(wiphy);
1515 return ath6kl_hif_suspend(ar);
1519 static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1520 struct ieee80211_channel *chan,
1521 enum nl80211_channel_type channel_type)
1523 struct ath6kl *ar = ath6kl_priv(dev);
1525 if (!ath6kl_cfg80211_ready(ar))
1528 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1529 __func__, chan->center_freq, chan->hw_value);
1530 ar->next_chan = chan->center_freq;
1535 static bool ath6kl_is_p2p_ie(const u8 *pos)
1537 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1538 pos[2] == 0x50 && pos[3] == 0x6f &&
1539 pos[4] == 0x9a && pos[5] == 0x09;
1542 static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
1551 * Filter out P2P IE(s) since they will be included depending on
1552 * the Probe Request frame in ath6kl_send_go_probe_resp().
1555 if (ies && ies_len) {
1556 buf = kmalloc(ies_len, GFP_KERNEL);
1560 while (pos + 1 < ies + ies_len) {
1561 if (pos + 2 + pos[1] > ies + ies_len)
1563 if (!ath6kl_is_p2p_ie(pos)) {
1564 memcpy(buf + len, pos, 2 + pos[1]);
1571 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1577 static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1578 struct beacon_parameters *info, bool add)
1580 struct ath6kl *ar = ath6kl_priv(dev);
1581 struct ieee80211_mgmt *mgmt;
1584 struct wmi_connect_cmd p;
1588 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1590 if (!ath6kl_cfg80211_ready(ar))
1593 if (ar->next_mode != AP_NETWORK)
1596 if (info->beacon_ies) {
1597 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1599 info->beacon_ies_len);
1603 if (info->proberesp_ies) {
1604 res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
1605 info->proberesp_ies_len);
1609 if (info->assocresp_ies) {
1610 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1611 info->assocresp_ies,
1612 info->assocresp_ies_len);
1620 ar->ap_mode_bkey.valid = false;
1627 if (info->head == NULL)
1629 mgmt = (struct ieee80211_mgmt *) info->head;
1630 ies = mgmt->u.beacon.variable;
1631 if (ies > info->head + info->head_len)
1633 ies_len = info->head + info->head_len - ies;
1635 if (info->ssid == NULL)
1637 memcpy(ar->ssid, info->ssid, info->ssid_len);
1638 ar->ssid_len = info->ssid_len;
1639 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1640 return -EOPNOTSUPP; /* TODO */
1642 ar->dot11_auth_mode = OPEN_AUTH;
1644 memset(&p, 0, sizeof(p));
1646 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1647 switch (info->crypto.akm_suites[i]) {
1648 case WLAN_AKM_SUITE_8021X:
1649 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1650 p.auth_mode |= WPA_AUTH;
1651 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1652 p.auth_mode |= WPA2_AUTH;
1654 case WLAN_AKM_SUITE_PSK:
1655 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1656 p.auth_mode |= WPA_PSK_AUTH;
1657 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1658 p.auth_mode |= WPA2_PSK_AUTH;
1662 if (p.auth_mode == 0)
1663 p.auth_mode = NONE_AUTH;
1664 ar->auth_mode = p.auth_mode;
1666 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1667 switch (info->crypto.ciphers_pairwise[i]) {
1668 case WLAN_CIPHER_SUITE_WEP40:
1669 case WLAN_CIPHER_SUITE_WEP104:
1670 p.prwise_crypto_type |= WEP_CRYPT;
1672 case WLAN_CIPHER_SUITE_TKIP:
1673 p.prwise_crypto_type |= TKIP_CRYPT;
1675 case WLAN_CIPHER_SUITE_CCMP:
1676 p.prwise_crypto_type |= AES_CRYPT;
1680 if (p.prwise_crypto_type == 0) {
1681 p.prwise_crypto_type = NONE_CRYPT;
1682 ath6kl_set_cipher(ar, 0, true);
1683 } else if (info->crypto.n_ciphers_pairwise == 1)
1684 ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
1686 switch (info->crypto.cipher_group) {
1687 case WLAN_CIPHER_SUITE_WEP40:
1688 case WLAN_CIPHER_SUITE_WEP104:
1689 p.grp_crypto_type = WEP_CRYPT;
1691 case WLAN_CIPHER_SUITE_TKIP:
1692 p.grp_crypto_type = TKIP_CRYPT;
1694 case WLAN_CIPHER_SUITE_CCMP:
1695 p.grp_crypto_type = AES_CRYPT;
1698 p.grp_crypto_type = NONE_CRYPT;
1701 ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
1703 p.nw_type = AP_NETWORK;
1704 ar->nw_type = ar->next_mode;
1706 p.ssid_len = ar->ssid_len;
1707 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1708 p.dot11_auth_mode = ar->dot11_auth_mode;
1709 p.ch = cpu_to_le16(ar->next_chan);
1711 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1718 static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1719 struct beacon_parameters *info)
1721 return ath6kl_ap_beacon(wiphy, dev, info, true);
1724 static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1725 struct beacon_parameters *info)
1727 return ath6kl_ap_beacon(wiphy, dev, info, false);
1730 static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1732 struct ath6kl *ar = ath6kl_priv(dev);
1734 if (ar->nw_type != AP_NETWORK)
1736 if (!test_bit(CONNECTED, &ar->flag))
1739 ath6kl_wmi_disconnect_cmd(ar->wmi);
1740 clear_bit(CONNECTED, &ar->flag);
1745 static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1746 u8 *mac, struct station_parameters *params)
1748 struct ath6kl *ar = ath6kl_priv(dev);
1750 if (ar->nw_type != AP_NETWORK)
1753 /* Use this only for authorizing/unauthorizing a station */
1754 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1757 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1758 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1760 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1764 static int ath6kl_remain_on_channel(struct wiphy *wiphy,
1765 struct net_device *dev,
1766 struct ieee80211_channel *chan,
1767 enum nl80211_channel_type channel_type,
1768 unsigned int duration,
1771 struct ath6kl *ar = ath6kl_priv(dev);
1773 /* TODO: if already pending or ongoing remain-on-channel,
1775 *cookie = 1; /* only a single pending request is supported */
1777 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
1781 static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
1782 struct net_device *dev,
1785 struct ath6kl *ar = ath6kl_priv(dev);
1790 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
1793 static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
1794 size_t len, unsigned int freq)
1800 const struct ieee80211_mgmt *mgmt;
1802 mgmt = (const struct ieee80211_mgmt *) buf;
1804 /* Include P2P IE(s) from the frame generated in user space. */
1806 p2p = kmalloc(len, GFP_KERNEL);
1811 pos = mgmt->u.probe_resp.variable;
1812 while (pos + 1 < buf + len) {
1813 if (pos + 2 + pos[1] > buf + len)
1815 if (ath6kl_is_p2p_ie(pos)) {
1816 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
1817 p2p_len += 2 + pos[1];
1822 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
1828 static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1829 struct ieee80211_channel *chan, bool offchan,
1830 enum nl80211_channel_type channel_type,
1831 bool channel_type_valid, unsigned int wait,
1832 const u8 *buf, size_t len, u64 *cookie)
1834 struct ath6kl *ar = ath6kl_priv(dev);
1836 const struct ieee80211_mgmt *mgmt;
1838 mgmt = (const struct ieee80211_mgmt *) buf;
1839 if (buf + len >= mgmt->u.probe_resp.variable &&
1840 ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
1841 ieee80211_is_probe_resp(mgmt->frame_control)) {
1843 * Send Probe Response frame in AP mode using a separate WMI
1844 * command to allow the target to fill in the generic IEs.
1846 *cookie = 0; /* TX status not supported */
1847 return ath6kl_send_go_probe_resp(ar, buf, len,
1851 id = ar->send_action_id++;
1854 * 0 is a reserved value in the WMI command and shall not be
1855 * used for the command.
1857 id = ar->send_action_id++;
1861 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
1865 static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
1866 struct net_device *dev,
1867 u16 frame_type, bool reg)
1869 struct ath6kl *ar = ath6kl_priv(dev);
1871 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
1872 __func__, frame_type, reg);
1873 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
1875 * Note: This notification callback is not allowed to sleep, so
1876 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
1877 * hardcode target to report Probe Request frames all the time.
1879 ar->probe_req_report = reg;
1883 static const struct ieee80211_txrx_stypes
1884 ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1885 [NL80211_IFTYPE_STATION] = {
1886 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1887 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1888 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1889 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1891 [NL80211_IFTYPE_P2P_CLIENT] = {
1892 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1893 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1894 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1895 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1897 [NL80211_IFTYPE_P2P_GO] = {
1898 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1899 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1900 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1901 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1905 static struct cfg80211_ops ath6kl_cfg80211_ops = {
1906 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1907 .scan = ath6kl_cfg80211_scan,
1908 .connect = ath6kl_cfg80211_connect,
1909 .disconnect = ath6kl_cfg80211_disconnect,
1910 .add_key = ath6kl_cfg80211_add_key,
1911 .get_key = ath6kl_cfg80211_get_key,
1912 .del_key = ath6kl_cfg80211_del_key,
1913 .set_default_key = ath6kl_cfg80211_set_default_key,
1914 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1915 .set_tx_power = ath6kl_cfg80211_set_txpower,
1916 .get_tx_power = ath6kl_cfg80211_get_txpower,
1917 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1918 .join_ibss = ath6kl_cfg80211_join_ibss,
1919 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1920 .get_station = ath6kl_get_station,
1921 .set_pmksa = ath6kl_set_pmksa,
1922 .del_pmksa = ath6kl_del_pmksa,
1923 .flush_pmksa = ath6kl_flush_pmksa,
1924 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd)
1926 .suspend = ar6k_cfg80211_suspend,
1928 .set_channel = ath6kl_set_channel,
1929 .add_beacon = ath6kl_add_beacon,
1930 .set_beacon = ath6kl_set_beacon,
1931 .del_beacon = ath6kl_del_beacon,
1932 .change_station = ath6kl_change_station,
1933 .remain_on_channel = ath6kl_remain_on_channel,
1934 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
1935 .mgmt_tx = ath6kl_mgmt_tx,
1936 .mgmt_frame_register = ath6kl_mgmt_frame_register,
1939 struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1942 struct wireless_dev *wdev;
1945 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1947 ath6kl_err("couldn't allocate wireless device\n");
1951 /* create a new wiphy for use with cfg80211 */
1952 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1954 ath6kl_err("couldn't allocate wiphy device\n");
1959 ar = wiphy_priv(wdev->wiphy);
1960 ar->p2p = !!ath6kl_p2p;
1962 wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
1964 wdev->wiphy->max_remain_on_channel_duration = 5000;
1966 /* set device pointer for wiphy */
1967 set_wiphy_dev(wdev->wiphy, dev);
1969 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1970 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1972 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) |
1973 BIT(NL80211_IFTYPE_P2P_CLIENT);
1975 /* max num of ssids that can be probed during scanning */
1976 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
1977 wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
1978 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1979 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1980 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1982 wdev->wiphy->cipher_suites = cipher_suites;
1983 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1985 ret = wiphy_register(wdev->wiphy);
1987 ath6kl_err("couldn't register wiphy device\n");
1988 wiphy_free(wdev->wiphy);
1996 void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1998 struct wireless_dev *wdev = ar->wdev;
2001 cfg80211_scan_done(ar->scan_req, true);
2002 ar->scan_req = NULL;
2008 wiphy_unregister(wdev->wiphy);
2009 wiphy_free(wdev->wiphy);