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 : &ar->grp_crpto_len;
173 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
174 __func__, cipher, ucast);
178 /* our own hack to use value 0 as no crypto used */
179 *ar_cipher = NONE_CRYPT;
182 case WLAN_CIPHER_SUITE_WEP40:
183 *ar_cipher = WEP_CRYPT;
186 case WLAN_CIPHER_SUITE_WEP104:
187 *ar_cipher = WEP_CRYPT;
190 case WLAN_CIPHER_SUITE_TKIP:
191 *ar_cipher = TKIP_CRYPT;
194 case WLAN_CIPHER_SUITE_CCMP:
195 *ar_cipher = AES_CRYPT;
199 ath6kl_err("cipher 0x%x not supported\n", cipher);
206 static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt)
208 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);
210 if (key_mgmt == WLAN_AKM_SUITE_PSK) {
211 if (ar->auth_mode == WPA_AUTH)
212 ar->auth_mode = WPA_PSK_AUTH;
213 else if (ar->auth_mode == WPA2_AUTH)
214 ar->auth_mode = WPA2_PSK_AUTH;
215 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
216 ar->auth_mode = NONE_AUTH;
220 static bool ath6kl_cfg80211_ready(struct ath6kl *ar)
222 if (!test_bit(WMI_READY, &ar->flag)) {
223 ath6kl_err("wmi is not ready\n");
227 if (!test_bit(WLAN_ENABLED, &ar->flag)) {
228 ath6kl_err("wlan disabled\n");
235 static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
236 struct cfg80211_connect_params *sme)
238 struct ath6kl *ar = ath6kl_priv(dev);
241 ar->sme_state = SME_CONNECTING;
243 if (!ath6kl_cfg80211_ready(ar))
246 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
247 ath6kl_err("destroy in progress\n");
251 if (test_bit(SKIP_SCAN, &ar->flag) &&
252 ((sme->channel && sme->channel->center_freq == 0) ||
253 (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
254 ath6kl_err("SkipScan: channel or bssid invalid\n");
258 if (down_interruptible(&ar->sem)) {
259 ath6kl_err("busy, couldn't get access\n");
263 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
264 ath6kl_err("busy, destroy in progress\n");
269 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
271 * sleep until the command queue drains
273 wait_event_interruptible_timeout(ar->event_wq,
274 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0,
276 if (signal_pending(current)) {
277 ath6kl_err("cmd queue drain timeout\n");
283 if (test_bit(CONNECTED, &ar->flag) &&
284 ar->ssid_len == sme->ssid_len &&
285 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
286 ar->reconnect_flag = true;
287 status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid,
292 ath6kl_err("wmi_reconnect_cmd failed\n");
296 } else if (ar->ssid_len == sme->ssid_len &&
297 !memcmp(ar->ssid, sme->ssid, ar->ssid_len)) {
298 ath6kl_disconnect(ar);
301 memset(ar->ssid, 0, sizeof(ar->ssid));
302 ar->ssid_len = sme->ssid_len;
303 memcpy(ar->ssid, sme->ssid, sme->ssid_len);
306 ar->ch_hint = sme->channel->center_freq;
308 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
309 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
310 memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid));
312 ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions);
314 status = ath6kl_set_auth_type(ar, sme->auth_type);
320 if (sme->crypto.n_ciphers_pairwise)
321 ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
323 ath6kl_set_cipher(ar, 0, true);
325 ath6kl_set_cipher(ar, sme->crypto.cipher_group, false);
327 if (sme->crypto.n_akm_suites)
328 ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
330 if ((sme->key_len) &&
331 (ar->auth_mode == NONE_AUTH) && (ar->prwise_crypto == WEP_CRYPT)) {
332 struct ath6kl_key *key = NULL;
334 if (sme->key_idx < WMI_MIN_KEY_INDEX ||
335 sme->key_idx > WMI_MAX_KEY_INDEX) {
336 ath6kl_err("key index %d out of bounds\n",
342 key = &ar->keys[sme->key_idx];
343 key->key_len = sme->key_len;
344 memcpy(key->key, sme->key, key->key_len);
345 key->cipher = ar->prwise_crypto;
346 ar->def_txkey_index = sme->key_idx;
348 ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx,
350 GROUP_USAGE | TX_USAGE,
353 key->key, KEY_OP_INIT_VAL, NULL,
357 if (!ar->usr_bss_filter) {
358 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) {
359 ath6kl_err("couldn't set bss filtering\n");
365 ar->nw_type = ar->next_mode;
367 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
368 "%s: connect called with authmode %d dot11 auth %d"
369 " PW crypto %d PW crypto len %d GRP crypto %d"
370 " GRP crypto len %d channel hint %u\n",
372 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
373 ar->prwise_crypto_len, ar->grp_crypto,
374 ar->grp_crpto_len, ar->ch_hint);
376 ar->reconnect_flag = 0;
377 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
378 ar->dot11_auth_mode, ar->auth_mode,
380 ar->prwise_crypto_len,
381 ar->grp_crypto, ar->grp_crpto_len,
382 ar->ssid_len, ar->ssid,
383 ar->req_bssid, ar->ch_hint,
384 ar->connect_ctrl_flags);
388 if (status == -EINVAL) {
389 memset(ar->ssid, 0, sizeof(ar->ssid));
391 ath6kl_err("invalid request\n");
394 ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
398 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
399 ((ar->auth_mode == WPA_PSK_AUTH)
400 || (ar->auth_mode == WPA2_PSK_AUTH))) {
401 mod_timer(&ar->disconnect_timer,
402 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
405 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
406 set_bit(CONNECT_PEND, &ar->flag);
411 void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel,
412 u8 *bssid, u16 listen_intvl,
414 enum network_type nw_type,
415 u8 beacon_ie_len, u8 assoc_req_len,
416 u8 assoc_resp_len, u8 *assoc_info)
420 struct cfg80211_bss *bss = NULL;
421 struct ieee80211_mgmt *mgmt = NULL;
422 struct ieee80211_channel *ibss_ch = NULL;
423 s32 signal = 50 * 100;
425 unsigned char ie_buf[256];
426 unsigned char *ptr_ie_buf = ie_buf;
427 unsigned char *ieeemgmtbuf = NULL;
428 u8 source_mac[ETH_ALEN];
430 /* capinfo + listen interval */
431 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);
433 /* capinfo + status code + associd */
434 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);
436 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
437 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
438 assoc_resp_ie_offset;
440 assoc_req_len -= assoc_req_ie_offset;
441 assoc_resp_len -= assoc_resp_ie_offset;
443 ar->auto_auth_stage = AUTH_IDLE;
445 if (nw_type & ADHOC_NETWORK) {
446 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
447 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
448 "%s: ath6k not in ibss mode\n", __func__);
453 if (nw_type & INFRA_NETWORK) {
454 if (ar->wdev->iftype != NL80211_IFTYPE_STATION) {
455 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
456 "%s: ath6k not in station mode\n", __func__);
462 * Earlier we were updating the cfg about bss by making a beacon frame
463 * only if the entry for bss is not there. This can have some issue if
464 * ROAM event is generated and a heavy traffic is ongoing. The ROAM
465 * event is handled through a work queue and by the time it really gets
466 * handled, BSS would have been aged out. So it is better to update the
467 * cfg about BSS irrespective of its entry being present right now or
471 if (nw_type & ADHOC_NETWORK) {
472 /* construct 802.11 mgmt beacon */
474 *ptr_ie_buf++ = WLAN_EID_SSID;
475 *ptr_ie_buf++ = ar->ssid_len;
476 memcpy(ptr_ie_buf, ar->ssid, ar->ssid_len);
477 ptr_ie_buf += ar->ssid_len;
479 *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
480 *ptr_ie_buf++ = 2; /* length */
481 *ptr_ie_buf++ = 0; /* ATIM window */
482 *ptr_ie_buf++ = 0; /* ATIM window */
484 /* TODO: update ibss params and include supported rates,
485 * DS param set, extened support rates, wmm. */
487 ie_buf_len = ptr_ie_buf - ie_buf;
490 capability |= WLAN_CAPABILITY_IBSS;
492 if (ar->prwise_crypto == WEP_CRYPT)
493 capability |= WLAN_CAPABILITY_PRIVACY;
495 memcpy(source_mac, ar->net_dev->dev_addr, ETH_ALEN);
498 capability = *(u16 *) (&assoc_info[beacon_ie_len]);
499 memcpy(source_mac, bssid, ETH_ALEN);
500 ptr_ie_buf = assoc_req_ie;
501 ie_buf_len = assoc_req_len;
504 size = offsetof(struct ieee80211_mgmt, u)
505 + sizeof(mgmt->u.beacon)
508 ieeemgmtbuf = kzalloc(size, GFP_ATOMIC);
510 ath6kl_err("ieee mgmt buf alloc error\n");
514 mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
515 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
516 IEEE80211_STYPE_BEACON);
517 memset(mgmt->da, 0xff, ETH_ALEN); /* broadcast addr */
518 memcpy(mgmt->sa, source_mac, ETH_ALEN);
519 memcpy(mgmt->bssid, bssid, ETH_ALEN);
520 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_intvl);
521 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
522 memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
524 ibss_ch = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
526 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
527 "%s: inform bss with bssid %pM channel %d beacon_intvl %d capability 0x%x\n",
528 __func__, mgmt->bssid, ibss_ch->hw_value,
529 beacon_intvl, capability);
531 bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
533 size, signal, GFP_KERNEL);
535 cfg80211_put_bss(bss);
537 if (nw_type & ADHOC_NETWORK) {
538 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
542 if (ar->sme_state == SME_CONNECTING) {
543 /* inform connect result to cfg80211 */
544 ar->sme_state = SME_CONNECTED;
545 cfg80211_connect_result(ar->net_dev, bssid,
546 assoc_req_ie, assoc_req_len,
547 assoc_resp_ie, assoc_resp_len,
548 WLAN_STATUS_SUCCESS, GFP_KERNEL);
549 } else if (ar->sme_state == SME_CONNECTED) {
550 /* inform roam event to cfg80211 */
551 cfg80211_roamed(ar->net_dev, ibss_ch, bssid,
552 assoc_req_ie, assoc_req_len,
553 assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
557 static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
558 struct net_device *dev, u16 reason_code)
560 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
562 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
565 if (!ath6kl_cfg80211_ready(ar))
568 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
569 ath6kl_err("busy, destroy in progress\n");
573 if (down_interruptible(&ar->sem)) {
574 ath6kl_err("busy, couldn't get access\n");
578 ar->reconnect_flag = 0;
579 ath6kl_disconnect(ar);
580 memset(ar->ssid, 0, sizeof(ar->ssid));
583 if (!test_bit(SKIP_SCAN, &ar->flag))
584 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
591 void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason,
592 u8 *bssid, u8 assoc_resp_len,
593 u8 *assoc_info, u16 proto_reason)
595 struct ath6kl_key *key = NULL;
599 cfg80211_scan_done(ar->scan_req, true);
603 if (ar->nw_type & ADHOC_NETWORK) {
604 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) {
605 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
606 "%s: ath6k not in ibss mode\n", __func__);
609 memset(bssid, 0, ETH_ALEN);
610 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL);
614 if (ar->nw_type & INFRA_NETWORK) {
615 if (ar->wdev->iftype != NL80211_IFTYPE_STATION) {
616 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
617 "%s: ath6k not in station mode\n", __func__);
622 if (!test_bit(CONNECT_PEND, &ar->flag)) {
623 if (reason != DISCONNECT_CMD)
624 ath6kl_wmi_disconnect_cmd(ar->wmi);
629 if (reason == NO_NETWORK_AVAIL) {
630 /* connect cmd failed */
631 ath6kl_wmi_disconnect_cmd(ar->wmi);
635 if (reason != DISCONNECT_CMD)
638 if (!ar->auto_auth_stage) {
639 clear_bit(CONNECT_PEND, &ar->flag);
641 if (ar->sme_state == SME_CONNECTING) {
642 cfg80211_connect_result(ar->net_dev,
645 WLAN_STATUS_UNSPECIFIED_FAILURE,
647 } else if (ar->sme_state == SME_CONNECTED) {
648 cfg80211_disconnected(ar->net_dev, reason,
649 NULL, 0, GFP_KERNEL);
652 ar->sme_state = SME_DISCONNECTED;
656 if (ar->dot11_auth_mode != OPEN_AUTH)
660 * If the current auth algorithm is open, try shared and
661 * make autoAuthStage idle. We do not make it leap for now
664 key = &ar->keys[ar->def_txkey_index];
665 if (down_interruptible(&ar->sem)) {
666 ath6kl_err("busy, couldn't get access\n");
670 ar->dot11_auth_mode = SHARED_AUTH;
671 ar->auto_auth_stage = AUTH_IDLE;
673 ath6kl_wmi_addkey_cmd(ar->wmi,
676 GROUP_USAGE | TX_USAGE,
679 KEY_OP_INIT_VAL, NULL,
682 status = ath6kl_wmi_connect_cmd(ar->wmi,
687 ar->prwise_crypto_len,
694 ar->connect_ctrl_flags);
698 static inline bool is_ch_11a(u16 ch)
700 return (!((ch >= 2412) && (ch <= 2484)));
703 /* struct ath6kl_node_table::nt_nodelock is locked when calling this */
704 void ath6kl_cfg80211_scan_node(struct wiphy *wiphy, struct bss *ni)
706 struct ieee80211_mgmt *mgmt;
707 struct ieee80211_channel *channel;
708 struct ieee80211_supported_band *band;
709 struct ath6kl_common_ie *cie;
715 if (is_ch_11a(cie->ie_chan))
716 band = wiphy->bands[IEEE80211_BAND_5GHZ]; /* 11a */
717 else if ((cie->ie_erp) || (cie->ie_xrates))
718 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11g */
720 band = wiphy->bands[IEEE80211_BAND_2GHZ]; /* 11b */
723 channel = ieee80211_get_channel(wiphy, freq);
724 signal = ni->ni_snr * 100;
726 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
727 "%s: bssid %pM ch %d freq %d size %d\n", __func__,
728 ni->ni_macaddr, channel->hw_value, freq, ni->ni_framelen);
730 * Both Beacon and Probe Response frames have same payload structure,
731 * so it is fine to share the parser for both.
733 if (ni->ni_framelen < 8 + 2 + 2)
735 mgmt = (struct ieee80211_mgmt *) (ni->ni_buf -
736 offsetof(struct ieee80211_mgmt, u));
737 cfg80211_inform_bss(wiphy, channel, ni->ni_macaddr,
738 le64_to_cpu(mgmt->u.beacon.timestamp),
739 le16_to_cpu(mgmt->u.beacon.capab_info),
740 le16_to_cpu(mgmt->u.beacon.beacon_int),
741 mgmt->u.beacon.variable,
742 ni->ni_buf + ni->ni_framelen -
743 mgmt->u.beacon.variable,
747 static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
748 struct cfg80211_scan_request *request)
750 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
753 if (!ath6kl_cfg80211_ready(ar))
756 if (!ar->usr_bss_filter) {
757 if (ath6kl_wmi_bssfilter_cmd(ar->wmi,
758 (test_bit(CONNECTED, &ar->flag) ?
760 ALL_BSS_FILTER), 0) != 0) {
761 ath6kl_err("couldn't set bss filtering\n");
766 if (request->n_ssids && request->ssids[0].ssid_len) {
769 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1))
770 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
772 for (i = 0; i < request->n_ssids; i++)
773 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
775 request->ssids[i].ssid_len,
776 request->ssids[i].ssid);
779 if (ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, 0,
780 false, 0, 0, 0, NULL) != 0) {
781 ath6kl_err("wmi_startscan_cmd failed\n");
785 ar->scan_req = request;
790 void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status)
794 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status);
799 if ((status == -ECANCELED) || (status == -EBUSY)) {
800 cfg80211_scan_done(ar->scan_req, true);
804 /* Translate data to cfg80211 mgmt format */
805 wlan_iterate_nodes(&ar->scan_table, ar->wdev->wiphy);
807 cfg80211_scan_done(ar->scan_req, false);
809 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) {
810 for (i = 0; i < ar->scan_req->n_ssids; i++) {
811 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1,
821 static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
822 u8 key_index, bool pairwise,
824 struct key_params *params)
826 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
827 struct ath6kl_key *key = NULL;
832 if (!ath6kl_cfg80211_ready(ar))
835 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
836 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
837 "%s: key index %d out of bounds\n", __func__,
842 key = &ar->keys[key_index];
843 memset(key, 0, sizeof(struct ath6kl_key));
846 key_usage = PAIRWISE_USAGE;
848 key_usage = GROUP_USAGE;
851 if (params->key_len > WLAN_MAX_KEY_LEN ||
852 params->seq_len > sizeof(key->seq))
855 key->key_len = params->key_len;
856 memcpy(key->key, params->key, key->key_len);
857 key->seq_len = params->seq_len;
858 memcpy(key->seq, params->seq, key->seq_len);
859 key->cipher = params->cipher;
862 switch (key->cipher) {
863 case WLAN_CIPHER_SUITE_WEP40:
864 case WLAN_CIPHER_SUITE_WEP104:
865 key_type = WEP_CRYPT;
868 case WLAN_CIPHER_SUITE_TKIP:
869 key_type = TKIP_CRYPT;
872 case WLAN_CIPHER_SUITE_CCMP:
873 key_type = AES_CRYPT;
880 if (((ar->auth_mode == WPA_PSK_AUTH)
881 || (ar->auth_mode == WPA2_PSK_AUTH))
882 && (key_usage & GROUP_USAGE))
883 del_timer(&ar->disconnect_timer);
885 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
886 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n",
887 __func__, key_index, key->key_len, key_type,
888 key_usage, key->seq_len);
890 ar->def_txkey_index = key_index;
892 if (ar->nw_type == AP_NETWORK && !pairwise &&
893 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) {
894 ar->ap_mode_bkey.valid = true;
895 ar->ap_mode_bkey.key_index = key_index;
896 ar->ap_mode_bkey.key_type = key_type;
897 ar->ap_mode_bkey.key_len = key->key_len;
898 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len);
899 if (!test_bit(CONNECTED, &ar->flag)) {
900 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group "
901 "key configuration until AP mode has been "
904 * The key will be set in ath6kl_connect_ap_mode() once
905 * the connected event is received from the target.
911 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
912 key_type, key_usage, key->key_len,
913 key->seq, key->key, KEY_OP_INIT_VAL,
914 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG);
922 static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
923 u8 key_index, bool pairwise,
926 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
928 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
930 if (!ath6kl_cfg80211_ready(ar))
933 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
934 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
935 "%s: key index %d out of bounds\n", __func__,
940 if (!ar->keys[key_index].key_len) {
941 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
942 "%s: index %d is empty\n", __func__, key_index);
946 ar->keys[key_index].key_len = 0;
948 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index);
951 static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
952 u8 key_index, bool pairwise,
953 const u8 *mac_addr, void *cookie,
954 void (*callback) (void *cookie,
955 struct key_params *))
957 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
958 struct ath6kl_key *key = NULL;
959 struct key_params params;
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 key = &ar->keys[key_index];
974 memset(¶ms, 0, sizeof(params));
975 params.cipher = key->cipher;
976 params.key_len = key->key_len;
977 params.seq_len = key->seq_len;
978 params.seq = key->seq;
979 params.key = key->key;
981 callback(cookie, ¶ms);
983 return key->key_len ? 0 : -ENOENT;
986 static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy,
987 struct net_device *ndev,
988 u8 key_index, bool unicast,
991 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev);
992 struct ath6kl_key *key = NULL;
996 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index);
998 if (!ath6kl_cfg80211_ready(ar))
1001 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1002 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1003 "%s: key index %d out of bounds\n",
1004 __func__, key_index);
1008 if (!ar->keys[key_index].key_len) {
1009 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n",
1010 __func__, key_index);
1014 ar->def_txkey_index = key_index;
1015 key = &ar->keys[ar->def_txkey_index];
1016 key_usage = GROUP_USAGE;
1017 if (ar->prwise_crypto == WEP_CRYPT)
1018 key_usage |= TX_USAGE;
1020 if (ar->nw_type == AP_NETWORK && !test_bit(CONNECTED, &ar->flag))
1021 return 0; /* Delay until AP mode has been started */
1023 status = ath6kl_wmi_addkey_cmd(ar->wmi, ar->def_txkey_index,
1024 ar->prwise_crypto, key_usage,
1025 key->key_len, key->seq, key->key,
1026 KEY_OP_INIT_VAL, NULL,
1034 void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid,
1037 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1038 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast);
1040 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid,
1041 (ismcast ? NL80211_KEYTYPE_GROUP :
1042 NL80211_KEYTYPE_PAIRWISE), keyid, NULL,
1046 static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1048 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1051 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__,
1054 if (!ath6kl_cfg80211_ready(ar))
1057 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1058 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold);
1060 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n");
1069 * The type nl80211_tx_power_setting replaces the following
1070 * data type from 2.6.36 onwards
1072 static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy,
1073 enum nl80211_tx_power_setting type,
1076 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1079 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__,
1082 if (!ath6kl_cfg80211_ready(ar))
1086 case NL80211_TX_POWER_AUTOMATIC:
1088 case NL80211_TX_POWER_LIMITED:
1089 ar->tx_pwr = ath6kl_dbm = dbm;
1092 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n",
1097 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm);
1102 static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1104 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy);
1106 if (!ath6kl_cfg80211_ready(ar))
1109 if (test_bit(CONNECTED, &ar->flag)) {
1112 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) {
1113 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n");
1117 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0,
1120 if (signal_pending(current)) {
1121 ath6kl_err("target did not respond\n");
1130 static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1131 struct net_device *dev,
1132 bool pmgmt, int timeout)
1134 struct ath6kl *ar = ath6kl_priv(dev);
1135 struct wmi_power_mode_cmd mode;
1137 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n",
1138 __func__, pmgmt, timeout);
1140 if (!ath6kl_cfg80211_ready(ar))
1144 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__);
1145 mode.pwr_mode = REC_POWER;
1147 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__);
1148 mode.pwr_mode = MAX_PERF_POWER;
1151 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) {
1152 ath6kl_err("wmi_powermode_cmd failed\n");
1159 static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
1160 struct net_device *ndev,
1161 enum nl80211_iftype type, u32 *flags,
1162 struct vif_params *params)
1164 struct ath6kl *ar = ath6kl_priv(ndev);
1165 struct wireless_dev *wdev = ar->wdev;
1167 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
1169 if (!ath6kl_cfg80211_ready(ar))
1173 case NL80211_IFTYPE_STATION:
1174 ar->next_mode = INFRA_NETWORK;
1176 case NL80211_IFTYPE_ADHOC:
1177 ar->next_mode = ADHOC_NETWORK;
1180 ath6kl_err("invalid interface type %u\n", type);
1184 wdev->iftype = type;
1189 static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy,
1190 struct net_device *dev,
1191 struct cfg80211_ibss_params *ibss_param)
1193 struct ath6kl *ar = ath6kl_priv(dev);
1196 if (!ath6kl_cfg80211_ready(ar))
1199 ar->ssid_len = ibss_param->ssid_len;
1200 memcpy(ar->ssid, ibss_param->ssid, ar->ssid_len);
1202 if (ibss_param->channel)
1203 ar->ch_hint = ibss_param->channel->center_freq;
1205 if (ibss_param->channel_fixed) {
1207 * TODO: channel_fixed: The channel should be fixed, do not
1208 * search for IBSSs to join on other channels. Target
1209 * firmware does not support this feature, needs to be
1215 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
1216 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid))
1217 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid));
1219 ath6kl_set_wpa_version(ar, 0);
1221 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1225 if (ibss_param->privacy) {
1226 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1227 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1229 ath6kl_set_cipher(ar, 0, true);
1230 ath6kl_set_cipher(ar, 0, false);
1233 ar->nw_type = ar->next_mode;
1235 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
1236 "%s: connect called with authmode %d dot11 auth %d"
1237 " PW crypto %d PW crypto len %d GRP crypto %d"
1238 " GRP crypto len %d channel hint %u\n",
1240 ar->auth_mode, ar->dot11_auth_mode, ar->prwise_crypto,
1241 ar->prwise_crypto_len, ar->grp_crypto,
1242 ar->grp_crpto_len, ar->ch_hint);
1244 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type,
1245 ar->dot11_auth_mode, ar->auth_mode,
1247 ar->prwise_crypto_len,
1248 ar->grp_crypto, ar->grp_crpto_len,
1249 ar->ssid_len, ar->ssid,
1250 ar->req_bssid, ar->ch_hint,
1251 ar->connect_ctrl_flags);
1252 set_bit(CONNECT_PEND, &ar->flag);
1257 static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy,
1258 struct net_device *dev)
1260 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev);
1262 if (!ath6kl_cfg80211_ready(ar))
1265 ath6kl_disconnect(ar);
1266 memset(ar->ssid, 0, sizeof(ar->ssid));
1272 static const u32 cipher_suites[] = {
1273 WLAN_CIPHER_SUITE_WEP40,
1274 WLAN_CIPHER_SUITE_WEP104,
1275 WLAN_CIPHER_SUITE_TKIP,
1276 WLAN_CIPHER_SUITE_CCMP,
1279 static bool is_rate_legacy(s32 rate)
1281 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1282 6000, 9000, 12000, 18000, 24000,
1287 for (i = 0; i < ARRAY_SIZE(legacy); i++)
1288 if (rate == legacy[i])
1294 static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1296 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1297 52000, 58500, 65000, 72200
1301 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1302 if (rate == ht20[i]) {
1303 if (i == ARRAY_SIZE(ht20) - 1)
1304 /* last rate uses sgi */
1316 static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1318 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1319 81000, 108000, 121500, 135000,
1324 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1325 if (rate == ht40[i]) {
1326 if (i == ARRAY_SIZE(ht40) - 1)
1327 /* last rate uses sgi */
1340 static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev,
1341 u8 *mac, struct station_info *sinfo)
1343 struct ath6kl *ar = ath6kl_priv(dev);
1350 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0)
1353 if (down_interruptible(&ar->sem))
1356 set_bit(STATS_UPDATE_PEND, &ar->flag);
1358 ret = ath6kl_wmi_get_stats_cmd(ar->wmi);
1365 left = wait_event_interruptible_timeout(ar->event_wq,
1366 !test_bit(STATS_UPDATE_PEND,
1377 if (ar->target_stats.rx_byte) {
1378 sinfo->rx_bytes = ar->target_stats.rx_byte;
1379 sinfo->filled |= STATION_INFO_RX_BYTES;
1380 sinfo->rx_packets = ar->target_stats.rx_pkt;
1381 sinfo->filled |= STATION_INFO_RX_PACKETS;
1384 if (ar->target_stats.tx_byte) {
1385 sinfo->tx_bytes = ar->target_stats.tx_byte;
1386 sinfo->filled |= STATION_INFO_TX_BYTES;
1387 sinfo->tx_packets = ar->target_stats.tx_pkt;
1388 sinfo->filled |= STATION_INFO_TX_PACKETS;
1391 sinfo->signal = ar->target_stats.cs_rssi;
1392 sinfo->filled |= STATION_INFO_SIGNAL;
1394 rate = ar->target_stats.tx_ucast_rate;
1396 if (is_rate_legacy(rate)) {
1397 sinfo->txrate.legacy = rate / 100;
1398 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1400 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1401 sinfo->txrate.mcs = mcs - 1;
1403 sinfo->txrate.mcs = mcs;
1406 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1407 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1409 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1410 sinfo->txrate.mcs = mcs - 1;
1412 sinfo->txrate.mcs = mcs;
1415 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1416 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1418 ath6kl_warn("invalid rate: %d\n", rate);
1422 sinfo->filled |= STATION_INFO_TX_BITRATE;
1427 static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1428 struct cfg80211_pmksa *pmksa)
1430 struct ath6kl *ar = ath6kl_priv(netdev);
1431 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1432 pmksa->pmkid, true);
1435 static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1436 struct cfg80211_pmksa *pmksa)
1438 struct ath6kl *ar = ath6kl_priv(netdev);
1439 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid,
1440 pmksa->pmkid, false);
1443 static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1445 struct ath6kl *ar = ath6kl_priv(netdev);
1446 if (test_bit(CONNECTED, &ar->flag))
1447 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false);
1452 static int ar6k_cfg80211_suspend(struct wiphy *wiphy,
1453 struct cfg80211_wowlan *wow)
1455 struct ath6kl *ar = wiphy_priv(wiphy);
1457 return ath6kl_hif_suspend(ar);
1461 static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
1462 struct ieee80211_channel *chan,
1463 enum nl80211_channel_type channel_type)
1465 struct ath6kl *ar = ath6kl_priv(dev);
1467 if (!ath6kl_cfg80211_ready(ar))
1470 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
1471 __func__, chan->center_freq, chan->hw_value);
1472 ar->next_chan = chan->center_freq;
1477 static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev,
1478 struct beacon_parameters *info, bool add)
1480 struct ath6kl *ar = ath6kl_priv(dev);
1481 struct ieee80211_mgmt *mgmt;
1484 struct wmi_connect_cmd p;
1488 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add);
1490 if (!ath6kl_cfg80211_ready(ar))
1493 if (ar->next_mode != AP_NETWORK)
1496 if (info->beacon_ies) {
1497 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON,
1499 info->beacon_ies_len);
1503 if (info->proberesp_ies) {
1504 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP,
1505 info->proberesp_ies,
1506 info->proberesp_ies_len);
1510 if (info->assocresp_ies) {
1511 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP,
1512 info->assocresp_ies,
1513 info->assocresp_ies_len);
1521 ar->ap_mode_bkey.valid = false;
1528 if (info->head == NULL)
1530 mgmt = (struct ieee80211_mgmt *) info->head;
1531 ies = mgmt->u.beacon.variable;
1532 if (ies > info->head + info->head_len)
1534 ies_len = info->head + info->head_len - ies;
1536 if (info->ssid == NULL)
1538 memcpy(ar->ssid, info->ssid, info->ssid_len);
1539 ar->ssid_len = info->ssid_len;
1540 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE)
1541 return -EOPNOTSUPP; /* TODO */
1543 ar->dot11_auth_mode = OPEN_AUTH;
1545 memset(&p, 0, sizeof(p));
1547 for (i = 0; i < info->crypto.n_akm_suites; i++) {
1548 switch (info->crypto.akm_suites[i]) {
1549 case WLAN_AKM_SUITE_8021X:
1550 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1551 p.auth_mode |= WPA_AUTH;
1552 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1553 p.auth_mode |= WPA2_AUTH;
1555 case WLAN_AKM_SUITE_PSK:
1556 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1)
1557 p.auth_mode |= WPA_PSK_AUTH;
1558 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2)
1559 p.auth_mode |= WPA2_PSK_AUTH;
1563 if (p.auth_mode == 0)
1564 p.auth_mode = NONE_AUTH;
1565 ar->auth_mode = p.auth_mode;
1567 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) {
1568 switch (info->crypto.ciphers_pairwise[i]) {
1569 case WLAN_CIPHER_SUITE_WEP40:
1570 case WLAN_CIPHER_SUITE_WEP104:
1571 p.prwise_crypto_type |= WEP_CRYPT;
1573 case WLAN_CIPHER_SUITE_TKIP:
1574 p.prwise_crypto_type |= TKIP_CRYPT;
1576 case WLAN_CIPHER_SUITE_CCMP:
1577 p.prwise_crypto_type |= AES_CRYPT;
1581 if (p.prwise_crypto_type == 0)
1582 p.prwise_crypto_type = NONE_CRYPT;
1584 switch (info->crypto.cipher_group) {
1585 case WLAN_CIPHER_SUITE_WEP40:
1586 case WLAN_CIPHER_SUITE_WEP104:
1587 p.grp_crypto_type = WEP_CRYPT;
1589 case WLAN_CIPHER_SUITE_TKIP:
1590 p.grp_crypto_type = TKIP_CRYPT;
1592 case WLAN_CIPHER_SUITE_CCMP:
1593 p.grp_crypto_type = AES_CRYPT;
1596 p.grp_crypto_type = NONE_CRYPT;
1600 p.nw_type = AP_NETWORK;
1601 ar->nw_type = ar->next_mode;
1603 p.ssid_len = ar->ssid_len;
1604 memcpy(p.ssid, ar->ssid, ar->ssid_len);
1605 p.dot11_auth_mode = ar->dot11_auth_mode;
1606 p.ch = cpu_to_le16(ar->next_chan);
1608 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p);
1615 static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev,
1616 struct beacon_parameters *info)
1618 return ath6kl_ap_beacon(wiphy, dev, info, true);
1621 static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev,
1622 struct beacon_parameters *info)
1624 return ath6kl_ap_beacon(wiphy, dev, info, false);
1627 static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev)
1629 struct ath6kl *ar = ath6kl_priv(dev);
1631 if (ar->nw_type != AP_NETWORK)
1633 if (!test_bit(CONNECTED, &ar->flag))
1636 ath6kl_wmi_disconnect_cmd(ar->wmi);
1637 clear_bit(CONNECTED, &ar->flag);
1642 static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev,
1643 u8 *mac, struct station_parameters *params)
1645 struct ath6kl *ar = ath6kl_priv(dev);
1647 if (ar->nw_type != AP_NETWORK)
1650 /* Use this only for authorizing/unauthorizing a station */
1651 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
1654 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1655 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE,
1657 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac,
1661 static struct cfg80211_ops ath6kl_cfg80211_ops = {
1662 .change_virtual_intf = ath6kl_cfg80211_change_iface,
1663 .scan = ath6kl_cfg80211_scan,
1664 .connect = ath6kl_cfg80211_connect,
1665 .disconnect = ath6kl_cfg80211_disconnect,
1666 .add_key = ath6kl_cfg80211_add_key,
1667 .get_key = ath6kl_cfg80211_get_key,
1668 .del_key = ath6kl_cfg80211_del_key,
1669 .set_default_key = ath6kl_cfg80211_set_default_key,
1670 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params,
1671 .set_tx_power = ath6kl_cfg80211_set_txpower,
1672 .get_tx_power = ath6kl_cfg80211_get_txpower,
1673 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt,
1674 .join_ibss = ath6kl_cfg80211_join_ibss,
1675 .leave_ibss = ath6kl_cfg80211_leave_ibss,
1676 .get_station = ath6kl_get_station,
1677 .set_pmksa = ath6kl_set_pmksa,
1678 .del_pmksa = ath6kl_del_pmksa,
1679 .flush_pmksa = ath6kl_flush_pmksa,
1681 .suspend = ar6k_cfg80211_suspend,
1683 .set_channel = ath6kl_set_channel,
1684 .add_beacon = ath6kl_add_beacon,
1685 .set_beacon = ath6kl_set_beacon,
1686 .del_beacon = ath6kl_del_beacon,
1687 .change_station = ath6kl_change_station,
1690 struct wireless_dev *ath6kl_cfg80211_init(struct device *dev)
1693 struct wireless_dev *wdev;
1695 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1697 ath6kl_err("couldn't allocate wireless device\n");
1701 /* create a new wiphy for use with cfg80211 */
1702 wdev->wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl));
1704 ath6kl_err("couldn't allocate wiphy device\n");
1709 /* set device pointer for wiphy */
1710 set_wiphy_dev(wdev->wiphy, dev);
1712 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1713 BIT(NL80211_IFTYPE_ADHOC);
1714 /* max num of ssids that can be probed during scanning */
1715 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
1716 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz;
1717 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz;
1718 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1720 wdev->wiphy->cipher_suites = cipher_suites;
1721 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1723 ret = wiphy_register(wdev->wiphy);
1725 ath6kl_err("couldn't register wiphy device\n");
1726 wiphy_free(wdev->wiphy);
1734 void ath6kl_cfg80211_deinit(struct ath6kl *ar)
1736 struct wireless_dev *wdev = ar->wdev;
1739 cfg80211_scan_done(ar->scan_req, true);
1740 ar->scan_req = NULL;
1746 wiphy_unregister(wdev->wiphy);
1747 wiphy_free(wdev->wiphy);