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.
22 #define RATETAB_ENT(_rate, _rateid, _flags) { \
25 .hw_value = (_rateid), \
28 #define CHAN2G(_channel, _freq, _flags) { \
29 .band = IEEE80211_BAND_2GHZ, \
30 .hw_value = (_channel), \
31 .center_freq = (_freq), \
33 .max_antenna_gain = 0, \
37 #define CHAN5G(_channel, _flags) { \
38 .band = IEEE80211_BAND_5GHZ, \
39 .hw_value = (_channel), \
40 .center_freq = 5000 + (5 * (_channel)), \
42 .max_antenna_gain = 0, \
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),
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
66 static struct ieee80211_channel ath6kl_2ghz_channels[] = {
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),
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,
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,
119 static int ath6kl_set_wpa_version(struct ath6kl *ar,
120 enum nl80211_wpa_versions wpa_version)
122 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, 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;
131 ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
138 static int ath6kl_set_auth_type(struct ath6kl *ar,
139 enum nl80211_auth_type auth_type)
142 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);
145 case NL80211_AUTHTYPE_OPEN_SYSTEM:
146 ar->dot11_auth_mode = OPEN_AUTH;
148 case NL80211_AUTHTYPE_SHARED_KEY:
149 ar->dot11_auth_mode = SHARED_AUTH;
151 case NL80211_AUTHTYPE_NETWORK_EAP:
152 ar->dot11_auth_mode = LEAP_AUTH;
155 case NL80211_AUTHTYPE_AUTOMATIC:
156 ar->dot11_auth_mode = OPEN_AUTH;
157 ar->auto_auth_stage = AUTH_OPEN_IN_PROGRESS;
161 ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type);
168 static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast)
170 u8 *ar_cipher = ucast ? &ar->prwise_crypto : &ar->grp_crypto;
171 u8 *ar_cipher_len = ucast ? &ar->prwise_crypto_len :
174 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
175 __func__, cipher, ucast);
179 /* our own hack to use value 0 as no crypto used */
180 *ar_cipher = NONE_CRYPT;
183 case WLAN_CIPHER_SUITE_WEP40:
184 *ar_cipher = WEP_CRYPT;
187 case WLAN_CIPHER_SUITE_WEP104:
188 *ar_cipher = WEP_CRYPT;
191 case WLAN_CIPHER_SUITE_TKIP:
192 *ar_cipher = TKIP_CRYPT;
195 case WLAN_CIPHER_SUITE_CCMP:
196 *ar_cipher = AES_CRYPT;
200 ath6kl_err("cipher 0x%x not supported\n", cipher);
207 static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
209 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
211 if (key_mgmt == WLAN_AKM_SUITE_PSK) {
212 if (ar->auth_mode == WPA_AUTH)
213 ar->auth_mode = WPA_PSK_AUTH;
214 else if (ar->auth_mode == WPA2_AUTH)
215 ar->auth_mode = WPA2_PSK_AUTH;
216 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
217 ar->auth_mode = NONE_AUTH;
221 static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
223 if (!test_bit(WMI_READY, &ar->flag)) {
224 ath6kl_err("wmi is not ready\n");
228 if (!test_bit(WLAN_ENABLED, &ar->flag)) {
229 ath6kl_err("wlan disabled\n");
236 static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
237 struct cfg80211_connect_params *sme)
239 struct ath6kl *ar = ath6kl_priv(dev);
242 ar->sme_state = SME_CONNECTING;
244 if (!ath6kl_cfg80211_ready(ar))
247 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
248 ath6kl_err("destroy in progress\n");
252 if (test_bit(SKIP_SCAN, &ar->flag) &&
253 ((sme->channel && sme->channel->center_freq == 0) ||
254 (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
255 ath6kl_err("SkipScan: channel or bssid invalid\n");
259 if (down_interruptible(&ar->sem)) {
260 ath6kl_err("busy, couldn't get access\n");
264 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
265 ath6kl_err("busy, destroy in progress\n");
270 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
272 * sleep until the command queue drains
274 wait_event_interruptible_timeout(ar->event_wq,
275 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
277 if (signal_pending(current)) {
278 ath6kl_err("cmd queue drain timeout\n");
284 if (test_bit(CONNECTED, &ar->flag) &&
285 ar->ssid_len == sme->ssid_len &&
286 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
287 ar->reconnect_flag = true;
288 status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid,
293 ath6kl_err("wmi_reconnect_cmd failed\n");
297 } else if (ar->ssid_len == sme->ssid_len &&
298 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
299 ath6kl_disconnect(ar);
302 memset(ar->ssid, 0, sizeof(ar->ssid));
303 ar->ssid_len = sme->ssid_len;
304 memcpy(ar->ssid, sme->ssid, sme->ssid_len);
307 ar->ch_hint = sme->channel->center_freq;
309 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
310 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
311 memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid));
313 ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions);
315 status = ath6kl_set_auth_type(ar, sme->auth_type);
321 if (sme->crypto.n_ciphers_pairwise)
322 ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
324 ath6kl_set_cipher(ar, 0, true);
326 ath6kl_set_cipher(ar, sme->crypto.cipher_group, false);
328 if (sme->crypto.n_akm_suites)
329 ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
331 if ((sme->key_len) &&
332 (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) {
333 struct ath6kl_key *key = NULL;
335 if (sme->key_idx < WMI_MIN_KEY_INDEX ||
336 sme->key_idx > WMI_MAX_KEY_INDEX) {
337 ath6kl_err("key index %d out of bounds\n",
343 key = &ar->keys[sme->key_idx];
344 key->key_len = sme->key_len;
345 memcpy(key->key, sme->key, key->key_len);
346 key->cipher = ar->prwise_crypto;
347 ar->def_txkey_index = sme->key_idx;
349 ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx,
351 GROUP_USAGE | TX_USAGE,
354 key->key, KEY_OP_INIT_VAL, NULL,
358 if (!ar->usr_bss_filter) {
359 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) {
360 ath6kl_err("couldn't set bss filtering\n");
366 ar->nw_type = ar->next_mode;
368 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
369 "%s: connect called with authmode %d dot11 auth %d"
370 " PW crypto %d PW crypto len %d GRP crypto %d"
371 " GRP crypto len %d channel hint %u\n",
373 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
374 ar->prwise_crypto_len, ar->grp_crypto,
375 ar->grp_crypto_len, ar->ch_hint);
377 ar->reconnect_flag = 0;
378 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
379 ar->dot11_auth_mode, ar->auth_mode,
381 ar->prwise_crypto_len,
382 ar->grp_crypto, ar->grp_crypto_len,
383 ar->ssid_len, ar->ssid,
384 ar->req_bssid, ar->ch_hint,
385 ar->connect_ctrl_flags);
389 if (status == -EINVAL) {
390 memset(ar->ssid, 0, sizeof(ar->ssid));
392 ath6kl_err("invalid request\n");
395 ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
399 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
400 ((ar->auth_mode == WPA_PSK_AUTH)
401 || (ar->auth_mode == WPA2_PSK_AUTH))) {
402 mod_timer(&ar->disconnect_timer,
403 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
406 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
407 set_bit(CONNECT_PEND, &ar->flag);
412 void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel,
413 u8 *bssid, u16 listen_intvl,
415 enum network_type nw_type,
416 u8 beacon_ie_len, u8 assoc_req_len,
417 u8 assoc_resp_len, u8 *assoc_info)
421 struct cfg80211_bss *bss = NULL;
422 struct ieee80211_mgmt *mgmt = NULL;
423 struct ieee80211_channel *ibss_ch = NULL;
424 s32 signal = 50 * 100;
426 unsigned char ie_buf[256];
427 unsigned char *ptr_ie_buf = ie_buf;
428 unsigned char *ieeemgmtbuf = NULL;
429 u8 source_mac[ETH_ALEN];
431 /* capinfo + listen interval */
432 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
434 /* capinfo + status code + associd */
435 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
437 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
438 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
439 assoc_resp_ie_offset;
441 assoc_req_len -= assoc_req_ie_offset;
442 assoc_resp_len -= assoc_resp_ie_offset;
444 ar->auto_auth_stage = AUTH_IDLE;
446 if (nw_type & ADHOC_NETWORK) {
447 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
448 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
449 "%s: ath6k not in ibss mode\n", __func__);
454 if (nw_type & INFRA_NETWORK) {
455 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
456 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
457 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
458 "%s: ath6k not in station mode\n", __func__);
464 * Earlier we were updating the cfg about bss by making a beacon frame
465 * only if the entry for bss is not there. This can have some issue if
466 * ROAM event is generated and a heavy traffic is ongoing. The ROAM
467 * event is handled through a work queue and by the time it really gets
468 * handled, BSS would have been aged out. So it is better to update the
469 * cfg about BSS irrespective of its entry being present right now or
473 if (nw_type & ADHOC_NETWORK) {
474 /* construct 802.11 mgmt beacon */
476 *ptr_ie_buf++ = WLAN_EID_SSID;
477 *ptr_ie_buf++ = ar->ssid_len;
478 memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len);
479 ptr_ie_buf += ar->ssid_len;
481 *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
482 *ptr_ie_buf++ = 2; /* length */
483 *ptr_ie_buf++ = 0; /* ATIM window */
484 *ptr_ie_buf++ = 0; /* ATIM window */
486 /* TODO: update ibss params and include supported rates,
487 * DS param set, extened support rates, wmm. */
489 ie_buf_len = ptr_ie_buf - ie_buf;
492 capability |= WLAN_CAPABILITY_IBSS;
494 if (ar->prwise_crypto == WEP_CRYPT)
495 capability |= WLAN_CAPABILITY_PRIVACY;
497 memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN);
500 capability = *(u16 *) (&assoc_info[beacon_ie_len]);
501 memcpy(source_mac, bssid, ETH_ALEN);
502 ptr_ie_buf = assoc_req_ie;
503 ie_buf_len = assoc_req_len;
506 size = offsetof(struct ieee80211_mgmt, u)
507 + sizeof(mgmt->u.beacon)
510 ieeemgmtbuf = kzalloc(size, GFP_ATOMIC);
512 ath6kl_err("ieee mgmt buf alloc error\n");
516 mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
517 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
518 IEEE80211_STYPE_BEACON);
519 memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */
520 memcpy(mgmt->sa, source_mac, ETH_ALEN);
521 memcpy(mgmt->bssid, bssid, ETH_ALEN);
522 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl);
523 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
524 memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
526 ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
528 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
529 "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n",
530 __func__, mgmt->bssid, ibss_ch->hw_value,
531 beacon_intvl, capability);
533 bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
535 size, signal, GFP_KERNEL);
537 cfg80211_put_bss(bss);
539 if (nw_type & ADHOC_NETWORK) {
540 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
544 if (ar->sme_state == SME_CONNECTING) {
545 /* inform connect result to cfg80211 */
546 ar->sme_state = SME_CONNECTED;
547 cfg80211_connect_result(ar->net_dev, bssid,
548 assoc_req_ie, assoc_req_len,
549 assoc_resp_ie, assoc_resp_len,
550 WLAN_STATUS_SUCCESS, GFP_KERNEL);
551 } else if (ar->sme_state == SME_CONNECTED) {
552 /* inform roam event to cfg80211 */
553 cfg80211_roamed(ar->net_dev, ibss_ch, bssid,
554 assoc_req_ie, assoc_req_len,
555 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
559 static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
560 struct net_device *dev, u16 reason_code)
562 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
564 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
567 if (!ath6kl_cfg80211_ready(ar))
570 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
571 ath6kl_err("busy, destroy in progress\n");
575 if (down_interruptible(&ar->sem)) {
576 ath6kl_err("busy, couldn't get access\n");
580 ar->reconnect_flag = 0;
581 ath6kl_disconnect(ar);
582 memset(ar->ssid, 0, sizeof(ar->ssid));
585 if (!test_bit(SKIP_SCAN, &ar->flag))
586 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
593 void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
594 u8 *bssid, u8 assoc_resp_len,
595 u8 *assoc_info, u16 proto_reason)
597 struct ath6kl_key *key = NULL;
601 cfg80211_scan_done(ar->scan_req, true);
605 if (ar->nw_type & ADHOC_NETWORK) {
606 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
607 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
608 "%s: ath6k not in ibss mode\n", __func__);
611 memset(bssid, 0, ETH_ALEN);
612 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
616 if (ar->nw_type & INFRA_NETWORK) {
617 if (ar->wdev->iftype != NL80211_IFTYPE_STATION &&
618 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) {
619 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
620 "%s: ath6k not in station mode\n", __func__);
625 if (!test_bit(CONNECT_PEND, &ar->flag)) {
626 if (reason != DISCONNECT_CMD)
627 ath6kl_wmi_disconnect_cmd(ar->wmi);
632 if (reason == NO_NETWORK_AVAIL) {
633 /* connect cmd failed */
634 ath6kl_wmi_disconnect_cmd(ar->wmi);
638 if (reason != DISCONNECT_CMD)
641 if (!ar->auto_auth_stage) {
642 clear_bit(CONNECT_PEND, &ar->flag);
644 if (ar->sme_state == SME_CONNECTING) {
645 cfg80211_connect_result(ar->net_dev,
648 WLAN_STATUS_UNSPECIFIED_FAILURE,
650 } else if (ar->sme_state == SME_CONNECTED) {
651 cfg80211_disconnected(ar->net_dev, reason,
652 NULL, 0, GFP_KERNEL);
655 ar->sme_state = SME_DISCONNECTED;
659 if (ar->dot11_auth_mode != OPEN_AUTH)
663 * If the current auth algorithm is open, try shared and
664 * make autoAuthStage idle. We do not make it leap for now
667 key = &ar->keys[ar->def_txkey_index];
668 if (down_interruptible(&ar->sem)) {
669 ath6kl_err("busy, couldn't get access\n");
673 ar->dot11_auth_mode = SHARED_AUTH;
674 ar->auto_auth_stage = AUTH_IDLE;
676 ath6kl_wmi_addkey_cmd(ar->wmi,
679 GROUP_USAGE | TX_USAGE,
682 KEY_OP_INIT_VAL, NULL,
685 status = ath6kl_wmi_connect_cmd(ar->wmi,
690 ar->prwise_crypto_len,
697 ar->connect_ctrl_flags);
701 static inline bool is_ch_11a(u16 ch)
703 return (!((ch >= 2412) && (ch <= 2484)));
706 /* struct ath6kl_node_table::nt_nodelock is locked when calling this */
707 void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni)
709 struct ieee80211_mgmt *mgmt;
710 struct ieee80211_channel *channel;
711 struct ieee80211_supported_band *band;
712 struct ath6kl_common_ie *cie;
718 if (is_ch_11a(cie->ie_chan))
719 band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */
720 else if ((cie->ie_erp) || (cie->ie_xrates))
721 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */
723 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */
726 channel = ieee80211_get_channel(wiphy, freq);
727 signal = ni->ni_snr * 100;
729 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
730 "%s: bssid %pM ch %d freq %d size %d\n", __func__,
731 ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen);
733 * Both Beacon and Probe Response frames have same payload structure,
734 * so it is fine to share the parser for both.
736 if (ni->ni_framelen < 8 + 2 + 2)
738 mgmt = (struct ieee80211_mgmt *) (ni->ni_buf -
739 offsetof(struct ieee80211_mgmt, u));
740 cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr,
741 le64_to_cpu(mgmt->u.beacon.timestamp),
742 le16_to_cpu(mgmt->u.beacon.capab_info),
743 le16_to_cpu(mgmt->u.beacon.beacon_int),
744 mgmt->u.beacon.variable,
745 ni->ni_buf + ni->ni_framelen -
746 mgmt->u.beacon.variable,
750 static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
751 struct cfg80211_scan_request *request)
753 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
755 u16 *channels = NULL;
758 if (!ath6kl_cfg80211_ready(ar))
761 if (!ar->usr_bss_filter) {
762 if (ath6kl_wmi_bssfilter_cmd(ar->wmi,
763 (test_bit(CONNECTED, &ar->flag) ?
765 ALL_BSS_FILTER), 0) != 0) {
766 ath6kl_err("couldn't set bss filtering\n");
771 if (request->n_ssids && request->ssids[0].ssid_len) {
774 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
775 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
777 for (i = 0; i < request->n_ssids; i++)
778 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
780 request->ssids[i].ssid_len,
781 request->ssids[i].ssid);
785 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_REQ,
786 request->ie, request->ie_len);
788 ath6kl_err("failed to set Probe Request appie for "
794 if (request->n_channels > 0) {
797 n_channels = min(127U, request->n_channels);
799 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
800 if (channels == NULL) {
801 ath6kl_warn("failed to set scan channels, "
802 "scan all channels");
806 for (i = 0; i < n_channels; i++)
807 channels[i] = request->channels[i]->center_freq;
810 if (ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
811 false, 0, 0, n_channels, channels) != 0) {
812 ath6kl_err("wmi_startscan_cmd failed\n");
816 ar->scan_req = request;
823 void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
827 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
832 if ((status == -ECANCELED) || (status == -EBUSY)) {
833 cfg80211_scan_done(ar->scan_req, true);
837 /* Translate data to cfg80211 mgmt format */
838 wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
840 cfg80211_scan_done(ar->scan_req, false);
842 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
843 for (i = 0; i < ar->scan_req->n_ssids; i++) {
844 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
854 static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
855 u8 key_index, bool pairwise,
857 struct key_params *params)
859 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
860 struct ath6kl_key *key = NULL;
865 if (!ath6kl_cfg80211_ready(ar))
868 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
869 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
870 "%s: key index %d out of bounds\n", __func__,
875 key = &ar->keys[key_index];
876 memset(key, 0, sizeof(struct ath6kl_key));
879 key_usage = PAIRWISE_USAGE;
881 key_usage = GROUP_USAGE;
884 if (params->key_len > WLAN_MAX_KEY_LEN ||
885 params->seq_len > sizeof(key->seq))
888 key->key_len = params->key_len;
889 memcpy(key->key, params->key, key->key_len);
890 key->seq_len = params->seq_len;
891 memcpy(key->seq, params->seq, key->seq_len);
892 key->cipher = params->cipher;
895 switch (key->cipher) {
896 case WLAN_CIPHER_SUITE_WEP40:
897 case WLAN_CIPHER_SUITE_WEP104:
898 key_type = WEP_CRYPT;
901 case WLAN_CIPHER_SUITE_TKIP:
902 key_type = TKIP_CRYPT;
905 case WLAN_CIPHER_SUITE_CCMP:
906 key_type = AES_CRYPT;
913 if (((ar->auth_mode == WPA_PSK_AUTH)
914 || (ar->auth_mode == WPA2_PSK_AUTH))
915 && (key_usage & GROUP_USAGE))
916 del_timer(&ar->disconnect_timer);
918 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
919 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
920 __func__, key_index, key->key_len, key_type,
921 key_usage, key->seq_len);
923 ar->def_txkey_index = key_index;
925 if (ar->nw_type == AP_NETWORK && !pairwise &&
926 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
927 ar->ap_mode_bkey.valid = true;
928 ar->ap_mode_bkey.key_index = key_index;
929 ar->ap_mode_bkey.key_type = key_type;
930 ar->ap_mode_bkey.key_len = key->key_len;
931 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
932 if (!test_bit(CONNECTED, &ar->flag)) {
933 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
934 "key configuration until AP mode has been "
937 * The key will be set in ath6kl_connect_ap_mode() once
938 * the connected event is received from the target.
944 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
945 key_type, key_usage, key->key_len,
946 key->seq, key->key, KEY_OP_INIT_VAL,
947 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
955 static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
956 u8 key_index, bool pairwise,
959 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
961 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
963 if (!ath6kl_cfg80211_ready(ar))
966 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
967 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
968 "%s: key index %d out of bounds\n", __func__,
973 if (!ar->keys[key_index].key_len) {
974 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
975 "%s: index %d is empty\n", __func__, key_index);
979 ar->keys[key_index].key_len = 0;
981 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
984 static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
985 u8 key_index, bool pairwise,
986 const u8 *mac_addr, void *cookie,
987 void (*callback) (void *cookie,
988 struct key_params *))
990 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
991 struct ath6kl_key *key = NULL;
992 struct key_params params;
994 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
996 if (!ath6kl_cfg80211_ready(ar))
999 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1000 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1001 "%s: key index %d out of bounds\n", __func__,
1006 key = &ar->keys[key_index];
1007 memset(¶ms, 0, sizeof(params));
1008 params.cipher = key->cipher;
1009 params.key_len = key->key_len;
1010 params.seq_len = key->seq_len;
1011 params.seq = key->seq;
1012 params.key = key->key;
1014 callback(cookie, ¶ms);
1016 return key->key_len ? 0 : -ENOENT;
1019 static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
1020 struct net_device *ndev,
1021 u8 key_index, bool unicast,
1024 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
1025 struct ath6kl_key *key = NULL;
1028 enum crypto_type key_type = NONE_CRYPT;
1030 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
1032 if (!ath6kl_cfg80211_ready(ar))
1035 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1036 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1037 "%s: key index %d out of bounds\n",
1038 __func__, key_index);
1042 if (!ar->keys[key_index].key_len) {
1043 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1044 __func__, key_index);
1048 ar->def_txkey_index = key_index;
1049 key = &ar->keys[ar->def_txkey_index];
1050 key_usage = GROUP_USAGE;
1051 if (ar->prwise_crypto == WEP_CRYPT)
1052 key_usage |= TX_USAGE;
1054 key_type = ar->prwise_crypto;
1056 key_type = ar->grp_crypto;
1058 if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
1059 return 0; /* Delay until AP mode has been started */
1061 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
1062 key_type, key_usage,
1063 key->key_len, key->seq, key->key,
1064 KEY_OP_INIT_VAL, NULL,
1072 void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
1075 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1076 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1078 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
1079 (ismcast ? NL80211_KEYTYPE_GROUP :
1080 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1084 static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1086 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1089 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1092 if (!ath6kl_cfg80211_ready(ar))
1095 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1096 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1098 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1107 * The type nl80211_tx_power_setting replaces the following
1108 * data type from 2.6.36 onwards
1110 static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1111 enum nl80211_tx_power_setting type,
1114 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1117 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1120 if (!ath6kl_cfg80211_ready(ar))
1124 case NL80211_TX_POWER_AUTOMATIC:
1126 case NL80211_TX_POWER_LIMITED:
1127 ar->tx_pwr = ath6kl_dbm = dbm;
1130 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1135 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
1140 static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1142 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1144 if (!ath6kl_cfg80211_ready(ar))
1147 if (test_bit(CONNECTED, &ar->flag)) {
1150 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
1151 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1155 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1158 if (signal_pending(current)) {
1159 ath6kl_err("target did not respond\n");
1168 static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1169 struct net_device *dev,
1170 bool pmgmt, int timeout)
1172 struct ath6kl *ar = ath6kl_priv(dev);
1173 struct wmi_power_mode_cmd mode;
1175 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1176 __func__, pmgmt, timeout);
1178 if (!ath6kl_cfg80211_ready(ar))
1182 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1183 mode.pwr_mode = REC_POWER;
1185 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1186 mode.pwr_mode = MAX_PERF_POWER;
1189 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
1190 ath6kl_err("wmi_powermode_cmd failed\n");
1197 static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1198 struct net_device *ndev,
1199 enum nl80211_iftype type, u32 *flags,
1200 struct vif_params *params)
1202 struct ath6kl *ar = ath6kl_priv(ndev);
1203 struct wireless_dev *wdev = ar->wdev;
1205 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1207 if (!ath6kl_cfg80211_ready(ar))
1211 case NL80211_IFTYPE_STATION:
1212 ar->next_mode = INFRA_NETWORK;
1214 case NL80211_IFTYPE_ADHOC:
1215 ar->next_mode = ADHOC_NETWORK;
1217 case NL80211_IFTYPE_P2P_CLIENT:
1218 ar->next_mode = INFRA_NETWORK;
1220 case NL80211_IFTYPE_P2P_GO:
1221 ar->next_mode = AP_NETWORK;
1224 ath6kl_err("invalid interface type %u\n", type);
1228 wdev->iftype = type;
1233 static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1234 struct net_device *dev,
1235 struct cfg80211_ibss_params *ibss_param)
1237 struct ath6kl *ar = ath6kl_priv(dev);
1240 if (!ath6kl_cfg80211_ready(ar))
1243 ar->ssid_len = ibss_param->ssid_len;
1244 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1246 if (ibss_param->channel)
1247 ar->ch_hint = ibss_param->channel->center_freq;
1249 if (ibss_param->channel_fixed) {
1251 * TODO: channel_fixed: The channel should be fixed, do not
1252 * search for IBSSs to join on other channels. Target
1253 * firmware does not support this feature, needs to be
1259 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1260 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1261 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1263 ath6kl_set_wpa_version(ar, 0);
1265 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1269 if (ibss_param->privacy) {
1270 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1271 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1273 ath6kl_set_cipher(ar, 0, true);
1274 ath6kl_set_cipher(ar, 0, false);
1277 ar->nw_type = ar->next_mode;
1279 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1280 "%s: connect called with authmode %d dot11 auth %d"
1281 " PW crypto %d PW crypto len %d GRP crypto %d"
1282 " GRP crypto len %d channel hint %u\n",
1284 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1285 ar->prwise_crypto_len, ar->grp_crypto,
1286 ar->grp_crypto_len, ar->ch_hint);
1288 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1289 ar->dot11_auth_mode, ar->auth_mode,
1291 ar->prwise_crypto_len,
1292 ar->grp_crypto, ar->grp_crypto_len,
1293 ar->ssid_len, ar->ssid,
1294 ar->req_bssid, ar->ch_hint,
1295 ar->connect_ctrl_flags);
1296 set_bit(CONNECT_PEND, &ar->flag);
1301 static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1302 struct net_device *dev)
1304 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1306 if (!ath6kl_cfg80211_ready(ar))
1309 ath6kl_disconnect(ar);
1310 memset(ar->ssid, 0, sizeof(ar->ssid));
1316 static const u32 cipher_suites[] = {
1317 WLAN_CIPHER_SUITE_WEP40,
1318 WLAN_CIPHER_SUITE_WEP104,
1319 WLAN_CIPHER_SUITE_TKIP,
1320 WLAN_CIPHER_SUITE_CCMP,
1323 static bool is_rate_legacy(s32 rate)
1325 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1326 6000, 9000, 12000, 18000, 24000,
1331 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1332 if (rate == legacy[i])
1338 static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1340 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1341 52000, 58500, 65000, 72200
1345 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1346 if (rate == ht20[i]) {
1347 if (i == ARRAY_SIZE(ht20) - 1)
1348 /* last rate uses sgi */
1360 static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1362 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1363 81000, 108000, 121500, 135000,
1368 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1369 if (rate == ht40[i]) {
1370 if (i == ARRAY_SIZE(ht40) - 1)
1371 /* last rate uses sgi */
1384 static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1385 u8 *mac, struct station_info *sinfo)
1387 struct ath6kl *ar = ath6kl_priv(dev);
1394 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1397 if (down_interruptible(&ar->sem))
1400 set_bit(STATS_UPDATE_PEND, &ar->flag);
1402 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1409 left = wait_event_interruptible_timeout(ar->event_wq,
1410 !test_bit(STATS_UPDATE_PEND,
1421 if (ar->target_stats.rx_byte) {
1422 sinfo->rx_bytes = ar->target_stats.rx_byte;
1423 sinfo->filled |= STATION_INFO_RX_BYTES;
1424 sinfo->rx_packets = ar->target_stats.rx_pkt;
1425 sinfo->filled |= STATION_INFO_RX_PACKETS;
1428 if (ar->target_stats.tx_byte) {
1429 sinfo->tx_bytes = ar->target_stats.tx_byte;
1430 sinfo->filled |= STATION_INFO_TX_BYTES;
1431 sinfo->tx_packets = ar->target_stats.tx_pkt;
1432 sinfo->filled |= STATION_INFO_TX_PACKETS;
1435 sinfo->signal = ar->target_stats.cs_rssi;
1436 sinfo->filled |= STATION_INFO_SIGNAL;
1438 rate = ar->target_stats.tx_ucast_rate;
1440 if (is_rate_legacy(rate)) {
1441 sinfo->txrate.legacy = rate / 100;
1442 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1444 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1445 sinfo->txrate.mcs = mcs - 1;
1447 sinfo->txrate.mcs = mcs;
1450 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1451 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1453 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1454 sinfo->txrate.mcs = mcs - 1;
1456 sinfo->txrate.mcs = mcs;
1459 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1460 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1462 ath6kl_warn("invalid rate: %d\n", rate);
1466 sinfo->filled |= STATION_INFO_TX_BITRATE;
1471 static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1472 struct cfg80211_pmksa *pmksa)
1474 struct ath6kl *ar = ath6kl_priv(netdev);
1475 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1476 pmksa->pmkid, true);
1479 static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1480 struct cfg80211_pmksa *pmksa)
1482 struct ath6kl *ar = ath6kl_priv(netdev);
1483 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1484 pmksa->pmkid, false);
1487 static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1489 struct ath6kl *ar = ath6kl_priv(netdev);
1490 if (test_bit(CONNECTED, &ar->flag))
1491 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1496 static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1497 struct cfg80211_wowlan *wow)
1499 struct ath6kl *ar = wiphy_priv(wiphy);
1501 return ath6kl_hif_suspend(ar);
1505 static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1506 struct ieee80211_channel *chan,
1507 enum nl80211_channel_type channel_type)
1509 struct ath6kl *ar = ath6kl_priv(dev);
1511 if (!ath6kl_cfg80211_ready(ar))
1514 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1515 __func__, chan->center_freq, chan->hw_value);
1516 ar->next_chan = chan->center_freq;
1521 static bool ath6kl_is_p2p_ie(const u8 *pos)
1523 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
1524 pos[2] == 0x50 && pos[3] == 0x6f &&
1525 pos[4] == 0x9a && pos[5] == 0x09;
1528 static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies,
1537 * Filter out P2P IE(s) since they will be included depending on
1538 * the Probe Request frame in ath6kl_send_go_probe_resp().
1541 if (ies && ies_len) {
1542 buf = kmalloc(ies_len, GFP_KERNEL);
1546 while (pos + 1 < ies + ies_len) {
1547 if (pos + 2 + pos[1] > ies + ies_len)
1549 if (!ath6kl_is_p2p_ie(pos)) {
1550 memcpy(buf + len, pos, 2 + pos[1]);
1557 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1563 static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1564 struct beacon_parameters *info, bool add)
1566 struct ath6kl *ar = ath6kl_priv(dev);
1567 struct ieee80211_mgmt *mgmt;
1570 struct wmi_connect_cmd p;
1574 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1576 if (!ath6kl_cfg80211_ready(ar))
1579 if (ar->next_mode != AP_NETWORK)
1582 if (info->beacon_ies) {
1583 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1585 info->beacon_ies_len);
1589 if (info->proberesp_ies) {
1590 res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies,
1591 info->proberesp_ies_len);
1595 if (info->assocresp_ies) {
1596 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1597 info->assocresp_ies,
1598 info->assocresp_ies_len);
1606 ar->ap_mode_bkey.valid = false;
1613 if (info->head == NULL)
1615 mgmt = (struct ieee80211_mgmt *) info->head;
1616 ies = mgmt->u.beacon.variable;
1617 if (ies > info->head + info->head_len)
1619 ies_len = info->head + info->head_len - ies;
1621 if (info->ssid == NULL)
1623 memcpy(ar->ssid, info->ssid, info->ssid_len);
1624 ar->ssid_len = info->ssid_len;
1625 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1626 return -EOPNOTSUPP; /* TODO */
1628 ar->dot11_auth_mode = OPEN_AUTH;
1630 memset(&p, 0, sizeof(p));
1632 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1633 switch (info->crypto.akm_suites[i]) {
1634 case WLAN_AKM_SUITE_8021X:
1635 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1636 p.auth_mode |= WPA_AUTH;
1637 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1638 p.auth_mode |= WPA2_AUTH;
1640 case WLAN_AKM_SUITE_PSK:
1641 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1642 p.auth_mode |= WPA_PSK_AUTH;
1643 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1644 p.auth_mode |= WPA2_PSK_AUTH;
1648 if (p.auth_mode == 0)
1649 p.auth_mode = NONE_AUTH;
1650 ar->auth_mode = p.auth_mode;
1652 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1653 switch (info->crypto.ciphers_pairwise[i]) {
1654 case WLAN_CIPHER_SUITE_WEP40:
1655 case WLAN_CIPHER_SUITE_WEP104:
1656 p.prwise_crypto_type |= WEP_CRYPT;
1658 case WLAN_CIPHER_SUITE_TKIP:
1659 p.prwise_crypto_type |= TKIP_CRYPT;
1661 case WLAN_CIPHER_SUITE_CCMP:
1662 p.prwise_crypto_type |= AES_CRYPT;
1666 if (p.prwise_crypto_type == 0) {
1667 p.prwise_crypto_type = NONE_CRYPT;
1668 ath6kl_set_cipher(ar, 0, true);
1669 } else if (info->crypto.n_ciphers_pairwise == 1)
1670 ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true);
1672 switch (info->crypto.cipher_group) {
1673 case WLAN_CIPHER_SUITE_WEP40:
1674 case WLAN_CIPHER_SUITE_WEP104:
1675 p.grp_crypto_type = WEP_CRYPT;
1677 case WLAN_CIPHER_SUITE_TKIP:
1678 p.grp_crypto_type = TKIP_CRYPT;
1680 case WLAN_CIPHER_SUITE_CCMP:
1681 p.grp_crypto_type = AES_CRYPT;
1684 p.grp_crypto_type = NONE_CRYPT;
1687 ath6kl_set_cipher(ar, info->crypto.cipher_group, false);
1689 p.nw_type = AP_NETWORK;
1690 ar->nw_type = ar->next_mode;
1692 p.ssid_len = ar->ssid_len;
1693 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1694 p.dot11_auth_mode = ar->dot11_auth_mode;
1695 p.ch = cpu_to_le16(ar->next_chan);
1697 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1704 static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1705 struct beacon_parameters *info)
1707 return ath6kl_ap_beacon(wiphy, dev, info, true);
1710 static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1711 struct beacon_parameters *info)
1713 return ath6kl_ap_beacon(wiphy, dev, info, false);
1716 static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1718 struct ath6kl *ar = ath6kl_priv(dev);
1720 if (ar->nw_type != AP_NETWORK)
1722 if (!test_bit(CONNECTED, &ar->flag))
1725 ath6kl_wmi_disconnect_cmd(ar->wmi);
1726 clear_bit(CONNECTED, &ar->flag);
1731 static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1732 u8 *mac, struct station_parameters *params)
1734 struct ath6kl *ar = ath6kl_priv(dev);
1736 if (ar->nw_type != AP_NETWORK)
1739 /* Use this only for authorizing/unauthorizing a station */
1740 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1743 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1744 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1746 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1750 static int ath6kl_remain_on_channel(struct wiphy *wiphy,
1751 struct net_device *dev,
1752 struct ieee80211_channel *chan,
1753 enum nl80211_channel_type channel_type,
1754 unsigned int duration,
1757 struct ath6kl *ar = ath6kl_priv(dev);
1759 /* TODO: if already pending or ongoing remain-on-channel,
1761 *cookie = 1; /* only a single pending request is supported */
1763 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq,
1767 static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy,
1768 struct net_device *dev,
1771 struct ath6kl *ar = ath6kl_priv(dev);
1776 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi);
1779 static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf,
1780 size_t len, unsigned int freq)
1786 const struct ieee80211_mgmt *mgmt;
1788 mgmt = (const struct ieee80211_mgmt *) buf;
1790 /* Include P2P IE(s) from the frame generated in user space. */
1792 p2p = kmalloc(len, GFP_KERNEL);
1797 pos = mgmt->u.probe_resp.variable;
1798 while (pos + 1 < buf + len) {
1799 if (pos + 2 + pos[1] > buf + len)
1801 if (ath6kl_is_p2p_ie(pos)) {
1802 memcpy(p2p + p2p_len, pos, 2 + pos[1]);
1803 p2p_len += 2 + pos[1];
1808 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da,
1814 static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1815 struct ieee80211_channel *chan, bool offchan,
1816 enum nl80211_channel_type channel_type,
1817 bool channel_type_valid, unsigned int wait,
1818 const u8 *buf, size_t len, u64 *cookie)
1820 struct ath6kl *ar = ath6kl_priv(dev);
1822 const struct ieee80211_mgmt *mgmt;
1824 mgmt = (const struct ieee80211_mgmt *) buf;
1825 if (buf + len >= mgmt->u.probe_resp.variable &&
1826 ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &ar->flag) &&
1827 ieee80211_is_probe_resp(mgmt->frame_control)) {
1829 * Send Probe Response frame in AP mode using a separate WMI
1830 * command to allow the target to fill in the generic IEs.
1832 *cookie = 0; /* TX status not supported */
1833 return ath6kl_send_go_probe_resp(ar, buf, len,
1837 id = ar->send_action_id++;
1840 * 0 is a reserved value in the WMI command and shall not be
1841 * used for the command.
1843 id = ar->send_action_id++;
1847 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait,
1851 static void ath6kl_mgmt_frame_register(struct wiphy *wiphy,
1852 struct net_device *dev,
1853 u16 frame_type, bool reg)
1855 struct ath6kl *ar = ath6kl_priv(dev);
1857 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n",
1858 __func__, frame_type, reg);
1859 if (frame_type == IEEE80211_STYPE_PROBE_REQ) {
1861 * Note: This notification callback is not allowed to sleep, so
1862 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we
1863 * hardcode target to report Probe Request frames all the time.
1865 ar->probe_req_report = reg;
1869 static const struct ieee80211_txrx_stypes
1870 ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = {
1871 [NL80211_IFTYPE_STATION] = {
1872 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1873 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1874 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1875 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1877 [NL80211_IFTYPE_P2P_CLIENT] = {
1878 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1879 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1880 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1881 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1883 [NL80211_IFTYPE_P2P_GO] = {
1884 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1885 BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
1886 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
1887 BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
1891 static struct cfg80211_ops ath6kl_cfg80211_ops = {
1892 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1893 .scan = ath6kl_cfg80211_scan,
1894 .connect = ath6kl_cfg80211_connect,
1895 .disconnect = ath6kl_cfg80211_disconnect,
1896 .add_key = ath6kl_cfg80211_add_key,
1897 .get_key = ath6kl_cfg80211_get_key,
1898 .del_key = ath6kl_cfg80211_del_key,
1899 .set_default_key = ath6kl_cfg80211_set_default_key,
1900 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1901 .set_tx_power = ath6kl_cfg80211_set_txpower,
1902 .get_tx_power = ath6kl_cfg80211_get_txpower,
1903 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1904 .join_ibss = ath6kl_cfg80211_join_ibss,
1905 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1906 .get_station = ath6kl_get_station,
1907 .set_pmksa = ath6kl_set_pmksa,
1908 .del_pmksa = ath6kl_del_pmksa,
1909 .flush_pmksa = ath6kl_flush_pmksa,
1911 .suspend = ar6k_cfg80211_suspend,
1913 .set_channel = ath6kl_set_channel,
1914 .add_beacon = ath6kl_add_beacon,
1915 .set_beacon = ath6kl_set_beacon,
1916 .del_beacon = ath6kl_del_beacon,
1917 .change_station = ath6kl_change_station,
1918 .remain_on_channel = ath6kl_remain_on_channel,
1919 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel,
1920 .mgmt_tx = ath6kl_mgmt_tx,
1921 .mgmt_frame_register = ath6kl_mgmt_frame_register,
1924 struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1927 struct wireless_dev *wdev;
1929 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1931 ath6kl_err("couldn't allocate wireless device\n");
1935 /* create a new wiphy for use with cfg80211 */
1936 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1938 ath6kl_err("couldn't allocate wiphy device\n");
1943 wdev->wiphy->mgmt_stypes = ath6kl_mgmt_stypes;
1945 wdev->wiphy->max_remain_on_channel_duration = 5000;
1947 /* set device pointer for wiphy */
1948 set_wiphy_dev(wdev->wiphy, dev);
1950 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1951 BIT(NL80211_IFTYPE_ADHOC);
1952 /* max num of ssids that can be probed during scanning */
1953 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
1954 wdev->wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */
1955 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1956 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1957 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1959 wdev->wiphy->cipher_suites = cipher_suites;
1960 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1962 ret = wiphy_register(wdev->wiphy);
1964 ath6kl_err("couldn't register wiphy device\n");
1965 wiphy_free(wdev->wiphy);
1973 void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1975 struct wireless_dev *wdev = ar->wdev;
1978 cfg80211_scan_done(ar->scan_req, true);
1979 ar->scan_req = NULL;
1985 wiphy_unregister(wdev->wiphy);
1986 wiphy_free(wdev->wiphy);