1 //------------------------------------------------------------------------------
2 // Copyright (c) 2004-2010 Atheros Communications Inc.
3 // All rights reserved.
7 // Permission to use, copy, modify, and/or distribute this software for any
8 // purpose with or without fee is hereby granted, provided that the above
9 // copyright notice and this permission notice appear in all copies.
11 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 // Author(s): ="Atheros"
22 //------------------------------------------------------------------------------
24 #include <linux/wireless.h>
25 #include <linux/ieee80211.h>
26 #include <net/cfg80211.h>
27 #include <net/netlink.h>
29 #include "ar6000_drv.h"
32 extern A_WAITQUEUE_HEAD arEvent;
33 extern unsigned int wmitimeout;
34 extern int reconnect_flag;
37 #define RATETAB_ENT(_rate, _rateid, _flags) { \
40 .hw_value = (_rateid), \
43 #define CHAN2G(_channel, _freq, _flags) { \
44 .band = IEEE80211_BAND_2GHZ, \
45 .hw_value = (_channel), \
46 .center_freq = (_freq), \
48 .max_antenna_gain = 0, \
52 #define CHAN5G(_channel, _flags) { \
53 .band = IEEE80211_BAND_5GHZ, \
54 .hw_value = (_channel), \
55 .center_freq = 5000 + (5 * (_channel)), \
57 .max_antenna_gain = 0, \
62 ieee80211_rate ar6k_rates[] = {
63 RATETAB_ENT(10, 0x1, 0),
64 RATETAB_ENT(20, 0x2, 0),
65 RATETAB_ENT(55, 0x4, 0),
66 RATETAB_ENT(110, 0x8, 0),
67 RATETAB_ENT(60, 0x10, 0),
68 RATETAB_ENT(90, 0x20, 0),
69 RATETAB_ENT(120, 0x40, 0),
70 RATETAB_ENT(180, 0x80, 0),
71 RATETAB_ENT(240, 0x100, 0),
72 RATETAB_ENT(360, 0x200, 0),
73 RATETAB_ENT(480, 0x400, 0),
74 RATETAB_ENT(540, 0x800, 0),
77 #define ar6k_a_rates (ar6k_rates + 4)
78 #define ar6k_a_rates_size 8
79 #define ar6k_g_rates (ar6k_rates + 0)
80 #define ar6k_g_rates_size 12
83 ieee80211_channel ar6k_2ghz_channels[] = {
101 ieee80211_channel ar6k_5ghz_a_channels[] = {
102 CHAN5G(34, 0), CHAN5G(36, 0),
103 CHAN5G(38, 0), CHAN5G(40, 0),
104 CHAN5G(42, 0), CHAN5G(44, 0),
105 CHAN5G(46, 0), CHAN5G(48, 0),
106 CHAN5G(52, 0), CHAN5G(56, 0),
107 CHAN5G(60, 0), CHAN5G(64, 0),
108 CHAN5G(100, 0), CHAN5G(104, 0),
109 CHAN5G(108, 0), CHAN5G(112, 0),
110 CHAN5G(116, 0), CHAN5G(120, 0),
111 CHAN5G(124, 0), CHAN5G(128, 0),
112 CHAN5G(132, 0), CHAN5G(136, 0),
113 CHAN5G(140, 0), CHAN5G(149, 0),
114 CHAN5G(153, 0), CHAN5G(157, 0),
115 CHAN5G(161, 0), CHAN5G(165, 0),
116 CHAN5G(184, 0), CHAN5G(188, 0),
117 CHAN5G(192, 0), CHAN5G(196, 0),
118 CHAN5G(200, 0), CHAN5G(204, 0),
119 CHAN5G(208, 0), CHAN5G(212, 0),
124 ieee80211_supported_band ar6k_band_2ghz = {
125 .n_channels = ARRAY_SIZE(ar6k_2ghz_channels),
126 .channels = ar6k_2ghz_channels,
127 .n_bitrates = ar6k_g_rates_size,
128 .bitrates = ar6k_g_rates,
132 ieee80211_supported_band ar6k_band_5ghz = {
133 .n_channels = ARRAY_SIZE(ar6k_5ghz_a_channels),
134 .channels = ar6k_5ghz_a_channels,
135 .n_bitrates = ar6k_a_rates_size,
136 .bitrates = ar6k_a_rates,
140 ar6k_set_wpa_version(struct ar6_softc *ar, enum nl80211_wpa_versions wpa_version)
143 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: %u\n", __func__, wpa_version));
146 ar->arAuthMode = NONE_AUTH;
147 } else if (wpa_version & NL80211_WPA_VERSION_1) {
148 ar->arAuthMode = WPA_AUTH;
149 } else if (wpa_version & NL80211_WPA_VERSION_2) {
150 ar->arAuthMode = WPA2_AUTH;
152 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
153 ("%s: %u not spported\n", __func__, wpa_version));
161 ar6k_set_auth_type(struct ar6_softc *ar, enum nl80211_auth_type auth_type)
164 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: 0x%x\n", __func__, auth_type));
167 case NL80211_AUTHTYPE_OPEN_SYSTEM:
168 ar->arDot11AuthMode = OPEN_AUTH;
170 case NL80211_AUTHTYPE_SHARED_KEY:
171 ar->arDot11AuthMode = SHARED_AUTH;
173 case NL80211_AUTHTYPE_NETWORK_EAP:
174 ar->arDot11AuthMode = LEAP_AUTH;
177 case NL80211_AUTHTYPE_AUTOMATIC:
178 ar->arDot11AuthMode = OPEN_AUTH;
179 ar->arAutoAuthStage = AUTH_OPEN_IN_PROGRESS;
183 ar->arDot11AuthMode = OPEN_AUTH;
184 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
185 ("%s: 0x%x not spported\n", __func__, auth_type));
193 ar6k_set_cipher(struct ar6_softc *ar, u32 cipher, bool ucast)
195 u8 *ar_cipher = ucast ? &ar->arPairwiseCrypto :
197 u8 *ar_cipher_len = ucast ? &ar->arPairwiseCryptoLen :
198 &ar->arGroupCryptoLen;
200 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
201 ("%s: cipher 0x%x, ucast %u\n", __func__, cipher, ucast));
205 case IW_AUTH_CIPHER_NONE:
206 *ar_cipher = NONE_CRYPT;
209 case WLAN_CIPHER_SUITE_WEP40:
210 *ar_cipher = WEP_CRYPT;
213 case WLAN_CIPHER_SUITE_WEP104:
214 *ar_cipher = WEP_CRYPT;
217 case WLAN_CIPHER_SUITE_TKIP:
218 *ar_cipher = TKIP_CRYPT;
221 case WLAN_CIPHER_SUITE_CCMP:
222 *ar_cipher = AES_CRYPT;
226 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
227 ("%s: cipher 0x%x not supported\n", __func__, cipher));
235 ar6k_set_key_mgmt(struct ar6_softc *ar, u32 key_mgmt)
237 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: 0x%x\n", __func__, key_mgmt));
239 if (WLAN_AKM_SUITE_PSK == key_mgmt) {
240 if (WPA_AUTH == ar->arAuthMode) {
241 ar->arAuthMode = WPA_PSK_AUTH;
242 } else if (WPA2_AUTH == ar->arAuthMode) {
243 ar->arAuthMode = WPA2_PSK_AUTH;
245 } else if (WLAN_AKM_SUITE_8021X != key_mgmt) {
246 ar->arAuthMode = NONE_AUTH;
251 ar6k_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
252 struct cfg80211_connect_params *sme)
254 struct ar6_softc *ar = ar6k_priv(dev);
257 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
258 ar->smeState = SME_CONNECTING;
260 if(ar->arWmiReady == false) {
261 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready yet\n", __func__));
265 if(ar->arWlanState == WLAN_DISABLED) {
266 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
270 if(ar->bIsDestroyProgress) {
271 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: destroy in progress\n", __func__));
275 if(!sme->ssid_len || IEEE80211_MAX_SSID_LEN < sme->ssid_len) {
276 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ssid invalid\n", __func__));
280 if(ar->arSkipScan == true &&
281 ((sme->channel && sme->channel->center_freq == 0) ||
282 (sme->bssid && !sme->bssid[0] && !sme->bssid[1] && !sme->bssid[2] &&
283 !sme->bssid[3] && !sme->bssid[4] && !sme->bssid[5])))
285 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s:SkipScan: channel or bssid invalid\n", __func__));
289 if(down_interruptible(&ar->arSem)) {
290 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, couldn't get access\n", __func__));
294 if(ar->bIsDestroyProgress) {
295 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, destroy in progress\n", __func__));
300 if(ar->arTxPending[wmi_get_control_ep(ar->arWmi)]) {
302 * sleep until the command queue drains
304 wait_event_interruptible_timeout(arEvent,
305 ar->arTxPending[wmi_get_control_ep(ar->arWmi)] == 0, wmitimeout * HZ);
306 if (signal_pending(current)) {
307 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: cmd queue drain timeout\n", __func__));
313 if(ar->arConnected == true &&
314 ar->arSsidLen == sme->ssid_len &&
315 !memcmp(ar->arSsid, sme->ssid, ar->arSsidLen)) {
316 reconnect_flag = true;
317 status = wmi_reconnect_cmd(ar->arWmi,
323 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_reconnect_cmd failed\n", __func__));
327 } else if(ar->arSsidLen == sme->ssid_len &&
328 !memcmp(ar->arSsid, sme->ssid, ar->arSsidLen)) {
329 ar6000_disconnect(ar);
332 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
333 ar->arSsidLen = sme->ssid_len;
334 memcpy(ar->arSsid, sme->ssid, sme->ssid_len);
337 ar->arChannelHint = sme->channel->center_freq;
340 A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
342 if(memcmp(&sme->bssid, bcast_mac, AR6000_ETH_ADDR_LEN)) {
343 memcpy(ar->arReqBssid, sme->bssid, sizeof(ar->arReqBssid));
347 ar6k_set_wpa_version(ar, sme->crypto.wpa_versions);
348 ar6k_set_auth_type(ar, sme->auth_type);
350 if(sme->crypto.n_ciphers_pairwise) {
351 ar6k_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true);
353 ar6k_set_cipher(ar, IW_AUTH_CIPHER_NONE, true);
355 ar6k_set_cipher(ar, sme->crypto.cipher_group, false);
357 if(sme->crypto.n_akm_suites) {
358 ar6k_set_key_mgmt(ar, sme->crypto.akm_suites[0]);
362 (NONE_AUTH == ar->arAuthMode) &&
363 (WEP_CRYPT == ar->arPairwiseCrypto)) {
364 struct ar_key *key = NULL;
366 if(sme->key_idx < WMI_MIN_KEY_INDEX || sme->key_idx > WMI_MAX_KEY_INDEX) {
367 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
368 ("%s: key index %d out of bounds\n", __func__, sme->key_idx));
373 key = &ar->keys[sme->key_idx];
374 key->key_len = sme->key_len;
375 memcpy(key->key, sme->key, key->key_len);
376 key->cipher = ar->arPairwiseCrypto;
377 ar->arDefTxKeyIndex = sme->key_idx;
379 wmi_addKey_cmd(ar->arWmi, sme->key_idx,
380 ar->arPairwiseCrypto,
381 GROUP_USAGE | TX_USAGE,
384 key->key, KEY_OP_INIT_VAL, NULL,
388 if (!ar->arUserBssFilter) {
389 if (wmi_bssfilter_cmd(ar->arWmi, ALL_BSS_FILTER, 0) != 0) {
390 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Couldn't set bss filtering\n", __func__));
396 ar->arNetworkType = ar->arNextMode;
398 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Connect called with authmode %d dot11 auth %d"\
399 " PW crypto %d PW crypto Len %d GRP crypto %d"\
400 " GRP crypto Len %d channel hint %u\n",
401 __func__, ar->arAuthMode, ar->arDot11AuthMode,
402 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
403 ar->arGroupCrypto, ar->arGroupCryptoLen, ar->arChannelHint));
406 status = wmi_connect_cmd(ar->arWmi, ar->arNetworkType,
407 ar->arDot11AuthMode, ar->arAuthMode,
408 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
409 ar->arGroupCrypto,ar->arGroupCryptoLen,
410 ar->arSsidLen, ar->arSsid,
411 ar->arReqBssid, ar->arChannelHint,
412 ar->arConnectCtrlFlags);
416 if (A_EINVAL == status) {
417 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
419 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Invalid request\n", __func__));
422 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_connect_cmd failed\n", __func__));
426 if ((!(ar->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) &&
427 ((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)))
429 A_TIMEOUT_MS(&ar->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0);
432 ar->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD;
433 ar->arConnectPending = true;
439 ar6k_cfg80211_connect_event(struct ar6_softc *ar, u16 channel,
440 u8 *bssid, u16 listenInterval,
441 u16 beaconInterval,NETWORK_TYPE networkType,
442 u8 beaconIeLen, u8 assocReqLen,
443 u8 assocRespLen, u8 *assocInfo)
447 struct cfg80211_bss *bss = NULL;
448 struct ieee80211_mgmt *mgmt = NULL;
449 struct ieee80211_channel *ibss_channel = NULL;
450 s32 signal = 50 * 100;
452 unsigned char ie_buf[256];
453 unsigned char *ptr_ie_buf = ie_buf;
454 unsigned char *ieeemgmtbuf = NULL;
455 u8 source_mac[ATH_MAC_LEN];
457 u8 assocReqIeOffset = sizeof(u16) + /* capinfo*/
458 sizeof(u16); /* listen interval */
459 u8 assocRespIeOffset = sizeof(u16) + /* capinfo*/
460 sizeof(u16) + /* status Code */
461 sizeof(u16); /* associd */
462 u8 *assocReqIe = assocInfo + beaconIeLen + assocReqIeOffset;
463 u8 *assocRespIe = assocInfo + beaconIeLen + assocReqLen + assocRespIeOffset;
465 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
467 assocReqLen -= assocReqIeOffset;
468 assocRespLen -= assocRespIeOffset;
470 ar->arAutoAuthStage = AUTH_IDLE;
472 if((ADHOC_NETWORK & networkType)) {
473 if(NL80211_IFTYPE_ADHOC != ar->wdev->iftype) {
474 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
475 ("%s: ath6k not in ibss mode\n", __func__));
480 if((INFRA_NETWORK & networkType)) {
481 if(NL80211_IFTYPE_STATION != ar->wdev->iftype) {
482 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
483 ("%s: ath6k not in station mode\n", __func__));
488 /* Before informing the join/connect event, make sure that
489 * bss entry is present in scan list, if it not present
490 * construct and insert into scan list, otherwise that
491 * event will be dropped on the way by cfg80211, due to
492 * this keys will not be plumbed in case of WEP and
493 * application will not be aware of join/connect status. */
494 bss = cfg80211_get_bss(ar->wdev->wiphy, NULL, bssid,
495 ar->wdev->ssid, ar->wdev->ssid_len,
496 ((ADHOC_NETWORK & networkType) ? WLAN_CAPABILITY_IBSS : WLAN_CAPABILITY_ESS),
497 ((ADHOC_NETWORK & networkType) ? WLAN_CAPABILITY_IBSS : WLAN_CAPABILITY_ESS));
500 * Earlier we were updating the cfg about bss by making a beacon frame
501 * only if the entry for bss is not there. This can have some issue if
502 * ROAM event is generated and a heavy traffic is ongoing. The ROAM
503 * event is handled through a work queue and by the time it really gets
504 * handled, BSS would have been aged out. So it is better to update the
505 * cfg about BSS irrespective of its entry being present right now or
509 if (ADHOC_NETWORK & networkType) {
510 /* construct 802.11 mgmt beacon */
512 *ptr_ie_buf++ = WLAN_EID_SSID;
513 *ptr_ie_buf++ = ar->arSsidLen;
514 memcpy(ptr_ie_buf, ar->arSsid, ar->arSsidLen);
515 ptr_ie_buf +=ar->arSsidLen;
517 *ptr_ie_buf++ = WLAN_EID_IBSS_PARAMS;
518 *ptr_ie_buf++ = 2; /* length */
519 *ptr_ie_buf++ = 0; /* ATIM window */
520 *ptr_ie_buf++ = 0; /* ATIM window */
522 /* TODO: update ibss params and include supported rates,
523 * DS param set, extened support rates, wmm. */
525 ie_buf_len = ptr_ie_buf - ie_buf;
528 capability |= IEEE80211_CAPINFO_IBSS;
529 if(WEP_CRYPT == ar->arPairwiseCrypto) {
530 capability |= IEEE80211_CAPINFO_PRIVACY;
532 memcpy(source_mac, ar->arNetDev->dev_addr, ATH_MAC_LEN);
535 capability = *(u16 *)(&assocInfo[beaconIeLen]);
536 memcpy(source_mac, bssid, ATH_MAC_LEN);
537 ptr_ie_buf = assocReqIe;
538 ie_buf_len = assocReqLen;
541 size = offsetof(struct ieee80211_mgmt, u)
542 + sizeof(mgmt->u.beacon)
545 ieeemgmtbuf = A_MALLOC_NOWAIT(size);
547 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
548 ("%s: ieeeMgmtbuf alloc error\n", __func__));
549 cfg80211_put_bss(bss);
553 A_MEMZERO(ieeemgmtbuf, size);
554 mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
555 mgmt->frame_control = (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
556 memcpy(mgmt->da, bcast_mac, ATH_MAC_LEN);
557 memcpy(mgmt->sa, source_mac, ATH_MAC_LEN);
558 memcpy(mgmt->bssid, bssid, ATH_MAC_LEN);
559 mgmt->u.beacon.beacon_int = beaconInterval;
560 mgmt->u.beacon.capab_info = capability;
561 memcpy(mgmt->u.beacon.variable, ptr_ie_buf, ie_buf_len);
563 ibss_channel = ieee80211_get_channel(ar->wdev->wiphy, (int)channel);
565 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
566 ("%s: inform bss with bssid %pM channel %d beaconInterval %d "
567 "capability 0x%x\n", __func__, mgmt->bssid,
568 ibss_channel->hw_value, beaconInterval, capability));
570 bss = cfg80211_inform_bss_frame(ar->wdev->wiphy,
575 cfg80211_put_bss(bss);
577 if((ADHOC_NETWORK & networkType)) {
578 cfg80211_ibss_joined(ar->arNetDev, bssid, GFP_KERNEL);
582 if (false == ar->arConnected) {
583 /* inform connect result to cfg80211 */
584 ar->smeState = SME_DISCONNECTED;
585 cfg80211_connect_result(ar->arNetDev, bssid,
586 assocReqIe, assocReqLen,
587 assocRespIe, assocRespLen,
588 WLAN_STATUS_SUCCESS, GFP_KERNEL);
590 /* inform roam event to cfg80211 */
591 cfg80211_roamed(ar->arNetDev, ibss_channel, bssid,
592 assocReqIe, assocReqLen,
593 assocRespIe, assocRespLen,
599 ar6k_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
602 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
604 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: reason=%u\n", __func__, reason_code));
606 if(ar->arWmiReady == false) {
607 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
611 if(ar->arWlanState == WLAN_DISABLED) {
612 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
616 if(ar->bIsDestroyProgress) {
617 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, destroy in progress\n", __func__));
621 if(down_interruptible(&ar->arSem)) {
622 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, couldn't get access\n", __func__));
627 ar6000_disconnect(ar);
628 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
631 if (ar->arSkipScan == false) {
632 A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
641 ar6k_cfg80211_disconnect_event(struct ar6_softc *ar, u8 reason,
642 u8 *bssid, u8 assocRespLen,
643 u8 *assocInfo, u16 protocolReasonStatus)
648 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: reason=%u\n", __func__, reason));
650 if (ar->scan_request) {
651 cfg80211_scan_done(ar->scan_request, true);
652 ar->scan_request = NULL;
654 if((ADHOC_NETWORK & ar->arNetworkType)) {
655 if(NL80211_IFTYPE_ADHOC != ar->wdev->iftype) {
656 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
657 ("%s: ath6k not in ibss mode\n", __func__));
660 A_MEMZERO(bssid, ETH_ALEN);
661 cfg80211_ibss_joined(ar->arNetDev, bssid, GFP_KERNEL);
665 if((INFRA_NETWORK & ar->arNetworkType)) {
666 if(NL80211_IFTYPE_STATION != ar->wdev->iftype) {
667 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
668 ("%s: ath6k not in station mode\n", __func__));
673 if(true == ar->arConnectPending) {
674 if(NO_NETWORK_AVAIL == reason) {
675 /* connect cmd failed */
676 wmi_disconnect_cmd(ar->arWmi);
677 } else if (reason == DISCONNECT_CMD) {
678 if (ar->arAutoAuthStage) {
680 * If the current auth algorithm is open try shared
681 * and make autoAuthStage idle. We do not make it
682 * leap for now being.
684 if (ar->arDot11AuthMode == OPEN_AUTH) {
685 struct ar_key *key = NULL;
686 key = &ar->keys[ar->arDefTxKeyIndex];
687 if (down_interruptible(&ar->arSem)) {
688 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: busy, couldn't get access\n", __func__));
693 ar->arDot11AuthMode = SHARED_AUTH;
694 ar->arAutoAuthStage = AUTH_IDLE;
696 wmi_addKey_cmd(ar->arWmi, ar->arDefTxKeyIndex,
697 ar->arPairwiseCrypto,
698 GROUP_USAGE | TX_USAGE,
701 key->key, KEY_OP_INIT_VAL, NULL,
704 status = wmi_connect_cmd(ar->arWmi,
708 ar->arPairwiseCrypto,
709 ar->arPairwiseCryptoLen,
711 ar->arGroupCryptoLen,
716 ar->arConnectCtrlFlags);
719 } else if (ar->arDot11AuthMode == SHARED_AUTH) {
720 /* should not reach here */
723 ar->arConnectPending = false;
724 if (ar->smeState == SME_CONNECTING) {
725 cfg80211_connect_result(ar->arNetDev, bssid,
728 WLAN_STATUS_UNSPECIFIED_FAILURE,
731 cfg80211_disconnected(ar->arNetDev,
736 ar->smeState = SME_DISCONNECTED;
740 if (reason != DISCONNECT_CMD)
741 wmi_disconnect_cmd(ar->arWmi);
746 ar6k_cfg80211_scan_node(void *arg, bss_t *ni)
748 struct wiphy *wiphy = (struct wiphy *)arg;
750 unsigned char *ieeemgmtbuf = NULL;
751 struct ieee80211_mgmt *mgmt;
752 struct ieee80211_channel *channel;
753 struct ieee80211_supported_band *band;
754 struct ieee80211_common_ie *cie;
760 #define CHAN_IS_11A(x) (!((x >= 2412) && (x <= 2484)))
761 if(CHAN_IS_11A(cie->ie_chan)) {
763 band = wiphy->bands[IEEE80211_BAND_5GHZ];
764 } else if((cie->ie_erp) || (cie->ie_xrates)) {
766 band = wiphy->bands[IEEE80211_BAND_2GHZ];
769 band = wiphy->bands[IEEE80211_BAND_2GHZ];
772 size = ni->ni_framelen + offsetof(struct ieee80211_mgmt, u);
773 ieeemgmtbuf = A_MALLOC_NOWAIT(size);
776 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ieeeMgmtbuf alloc error\n", __func__));
781 TODO: Update target to include 802.11 mac header while sending bss info.
782 Target removes 802.11 mac header while sending the bss info to host,
783 cfg80211 needs it, for time being just filling the da, sa and bssid fields alone.
785 mgmt = (struct ieee80211_mgmt *)ieeemgmtbuf;
786 memcpy(mgmt->da, bcast_mac, ATH_MAC_LEN);
787 memcpy(mgmt->sa, ni->ni_macaddr, ATH_MAC_LEN);
788 memcpy(mgmt->bssid, ni->ni_macaddr, ATH_MAC_LEN);
789 memcpy(ieeemgmtbuf + offsetof(struct ieee80211_mgmt, u),
790 ni->ni_buf, ni->ni_framelen);
793 channel = ieee80211_get_channel(wiphy, freq);
794 signal = ni->ni_snr * 100;
796 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
797 ("%s: bssid %pM channel %d freq %d size %d\n", __func__,
798 mgmt->bssid, channel->hw_value, freq, size));
799 cfg80211_inform_bss_frame(wiphy, channel, mgmt,
807 ar6k_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
808 struct cfg80211_scan_request *request)
810 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(ndev);
814 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
816 if(ar->arWmiReady == false) {
817 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
821 if(ar->arWlanState == WLAN_DISABLED) {
822 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
826 if (!ar->arUserBssFilter) {
827 if (wmi_bssfilter_cmd(ar->arWmi,
828 (ar->arConnected ? ALL_BUT_BSS_FILTER : ALL_BSS_FILTER),
830 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Couldn't set bss filtering\n", __func__));
835 if(request->n_ssids &&
836 request->ssids[0].ssid_len) {
839 if(request->n_ssids > (MAX_PROBED_SSID_INDEX - 1)) {
840 request->n_ssids = MAX_PROBED_SSID_INDEX - 1;
843 for (i = 0; i < request->n_ssids; i++) {
844 wmi_probedSsid_cmd(ar->arWmi, i+1, SPECIFIC_SSID_FLAG,
845 request->ssids[i].ssid_len,
846 request->ssids[i].ssid);
850 if(ar->arConnected) {
854 if(wmi_startscan_cmd(ar->arWmi, WMI_LONG_SCAN, forceFgScan, false, \
855 0, 0, 0, NULL) != 0) {
856 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_startscan_cmd failed\n", __func__));
860 ar->scan_request = request;
866 ar6k_cfg80211_scanComplete_event(struct ar6_softc *ar, int status)
869 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: status %d\n", __func__, status));
871 if (!ar->scan_request)
874 if ((status == A_ECANCELED) || (status == A_EBUSY)) {
875 cfg80211_scan_done(ar->scan_request, true);
879 /* Translate data to cfg80211 mgmt format */
880 wmi_iterate_nodes(ar->arWmi, ar6k_cfg80211_scan_node, ar->wdev->wiphy);
882 cfg80211_scan_done(ar->scan_request, false);
884 if(ar->scan_request->n_ssids &&
885 ar->scan_request->ssids[0].ssid_len) {
888 for (i = 0; i < ar->scan_request->n_ssids; i++) {
889 wmi_probedSsid_cmd(ar->arWmi, i+1, DISABLE_SSID_FLAG,
895 ar->scan_request = NULL;
899 ar6k_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
900 u8 key_index, bool pairwise, const u8 *mac_addr,
901 struct key_params *params)
903 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(ndev);
904 struct ar_key *key = NULL;
909 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s:\n", __func__));
911 if(ar->arWmiReady == false) {
912 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
916 if(ar->arWlanState == WLAN_DISABLED) {
917 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
921 if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
922 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
923 ("%s: key index %d out of bounds\n", __func__, key_index));
927 key = &ar->keys[key_index];
928 A_MEMZERO(key, sizeof(struct ar_key));
930 if(!mac_addr || is_broadcast_ether_addr(mac_addr)) {
931 key_usage = GROUP_USAGE;
933 key_usage = PAIRWISE_USAGE;
937 if(params->key_len > WLAN_MAX_KEY_LEN ||
938 params->seq_len > IW_ENCODE_SEQ_MAX_SIZE)
941 key->key_len = params->key_len;
942 memcpy(key->key, params->key, key->key_len);
943 key->seq_len = params->seq_len;
944 memcpy(key->seq, params->seq, key->seq_len);
945 key->cipher = params->cipher;
948 switch (key->cipher) {
949 case WLAN_CIPHER_SUITE_WEP40:
950 case WLAN_CIPHER_SUITE_WEP104:
951 key_type = WEP_CRYPT;
954 case WLAN_CIPHER_SUITE_TKIP:
955 key_type = TKIP_CRYPT;
958 case WLAN_CIPHER_SUITE_CCMP:
959 key_type = AES_CRYPT;
966 if (((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)) &&
967 (GROUP_USAGE & key_usage))
969 A_UNTIMEOUT(&ar->disconnect_timer);
972 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
973 ("%s: index %d, key_len %d, key_type 0x%x,"\
974 " key_usage 0x%x, seq_len %d\n",
975 __func__, key_index, key->key_len, key_type,
976 key_usage, key->seq_len));
978 ar->arDefTxKeyIndex = key_index;
979 status = wmi_addKey_cmd(ar->arWmi, ar->arDefTxKeyIndex, key_type, key_usage,
980 key->key_len, key->seq, key->key, KEY_OP_INIT_VAL,
981 (u8 *)mac_addr, SYNC_BOTH_WMIFLAG);
992 ar6k_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
993 u8 key_index, bool pairwise, const u8 *mac_addr)
995 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(ndev);
997 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index));
999 if(ar->arWmiReady == false) {
1000 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1004 if(ar->arWlanState == WLAN_DISABLED) {
1005 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1009 if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1010 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
1011 ("%s: key index %d out of bounds\n", __func__, key_index));
1015 if(!ar->keys[key_index].key_len) {
1016 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d is empty\n", __func__, key_index));
1020 ar->keys[key_index].key_len = 0;
1022 return wmi_deleteKey_cmd(ar->arWmi, key_index);
1027 ar6k_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
1028 u8 key_index, bool pairwise, const u8 *mac_addr,
1030 void (*callback)(void *cookie, struct key_params*))
1032 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(ndev);
1033 struct ar_key *key = NULL;
1034 struct key_params params;
1036 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index));
1038 if(ar->arWmiReady == false) {
1039 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1043 if(ar->arWlanState == WLAN_DISABLED) {
1044 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1048 if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1049 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
1050 ("%s: key index %d out of bounds\n", __func__, key_index));
1054 key = &ar->keys[key_index];
1055 A_MEMZERO(¶ms, sizeof(params));
1056 params.cipher = key->cipher;
1057 params.key_len = key->key_len;
1058 params.seq_len = key->seq_len;
1059 params.seq = key->seq;
1060 params.key = key->key;
1062 callback(cookie, ¶ms);
1064 return key->key_len ? 0 : -ENOENT;
1069 ar6k_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *ndev,
1070 u8 key_index, bool unicast, bool multicast)
1072 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(ndev);
1073 struct ar_key *key = NULL;
1077 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index));
1079 if(ar->arWmiReady == false) {
1080 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1084 if(ar->arWlanState == WLAN_DISABLED) {
1085 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1089 if(key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) {
1090 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
1091 ("%s: key index %d out of bounds\n",
1092 __func__, key_index));
1096 if(!ar->keys[key_index].key_len) {
1097 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: invalid key index %d\n",
1098 __func__, key_index));
1102 ar->arDefTxKeyIndex = key_index;
1103 key = &ar->keys[ar->arDefTxKeyIndex];
1104 key_usage = GROUP_USAGE;
1105 if (WEP_CRYPT == ar->arPairwiseCrypto) {
1106 key_usage |= TX_USAGE;
1109 status = wmi_addKey_cmd(ar->arWmi, ar->arDefTxKeyIndex,
1110 ar->arPairwiseCrypto, key_usage,
1111 key->key_len, key->seq, key->key, KEY_OP_INIT_VAL,
1112 NULL, SYNC_BOTH_WMIFLAG);
1121 ar6k_cfg80211_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *ndev,
1124 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(ndev);
1126 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: index %d\n", __func__, key_index));
1128 if(ar->arWmiReady == false) {
1129 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1133 if(ar->arWlanState == WLAN_DISABLED) {
1134 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1138 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: not supported\n", __func__));
1143 ar6k_cfg80211_tkip_micerr_event(struct ar6_softc *ar, u8 keyid, bool ismcast)
1145 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
1146 ("%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast));
1148 cfg80211_michael_mic_failure(ar->arNetDev, ar->arBssid,
1149 (ismcast ? NL80211_KEYTYPE_GROUP : NL80211_KEYTYPE_PAIRWISE),
1150 keyid, NULL, GFP_KERNEL);
1154 ar6k_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1156 struct ar6_softc *ar = (struct ar6_softc *)wiphy_priv(wiphy);
1158 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: changed 0x%x\n", __func__, changed));
1160 if(ar->arWmiReady == false) {
1161 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1165 if(ar->arWlanState == WLAN_DISABLED) {
1166 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1170 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1171 if (wmi_set_rts_cmd(ar->arWmi,wiphy->rts_threshold) != 0){
1172 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_set_rts_cmd failed\n", __func__));
1181 ar6k_cfg80211_set_bitrate_mask(struct wiphy *wiphy, struct net_device *dev,
1183 const struct cfg80211_bitrate_mask *mask)
1185 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Setting rates: Not supported\n"));
1189 /* The type nl80211_tx_power_setting replaces the following data type from 2.6.36 onwards */
1191 ar6k_cfg80211_set_txpower(struct wiphy *wiphy, enum nl80211_tx_power_setting type, int dbm)
1193 struct ar6_softc *ar = (struct ar6_softc *)wiphy_priv(wiphy);
1196 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: type 0x%x, dbm %d\n", __func__, type, dbm));
1198 if(ar->arWmiReady == false) {
1199 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1203 if(ar->arWlanState == WLAN_DISABLED) {
1204 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1208 ar->arTxPwrSet = false;
1210 case NL80211_TX_POWER_AUTOMATIC:
1212 case NL80211_TX_POWER_LIMITED:
1213 ar->arTxPwr = ar_dbm = dbm;
1214 ar->arTxPwrSet = true;
1217 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: type 0x%x not supported\n", __func__, type));
1221 wmi_set_txPwr_cmd(ar->arWmi, ar_dbm);
1227 ar6k_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
1229 struct ar6_softc *ar = (struct ar6_softc *)wiphy_priv(wiphy);
1231 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
1233 if(ar->arWmiReady == false) {
1234 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1238 if(ar->arWlanState == WLAN_DISABLED) {
1239 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1243 if((ar->arConnected == true)) {
1246 if(wmi_get_txPwr_cmd(ar->arWmi) != 0) {
1247 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_get_txPwr_cmd failed\n", __func__));
1251 wait_event_interruptible_timeout(arEvent, ar->arTxPwr != 0, 5 * HZ);
1253 if(signal_pending(current)) {
1254 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Target did not respond\n", __func__));
1264 ar6k_cfg80211_set_power_mgmt(struct wiphy *wiphy,
1265 struct net_device *dev,
1266 bool pmgmt, int timeout)
1268 struct ar6_softc *ar = ar6k_priv(dev);
1269 WMI_POWER_MODE_CMD pwrMode;
1271 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: pmgmt %d, timeout %d\n", __func__, pmgmt, timeout));
1273 if(ar->arWmiReady == false) {
1274 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1278 if(ar->arWlanState == WLAN_DISABLED) {
1279 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1284 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Max Perf\n", __func__));
1285 pwrMode.powerMode = REC_POWER;
1287 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Rec Power\n", __func__));
1288 pwrMode.powerMode = MAX_PERF_POWER;
1291 if(wmi_powermode_cmd(ar->arWmi, pwrMode.powerMode) != 0) {
1292 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: wmi_powermode_cmd failed\n", __func__));
1299 static struct net_device *
1300 ar6k_cfg80211_add_virtual_intf(struct wiphy *wiphy, char *name,
1301 enum nl80211_iftype type, u32 *flags,
1302 struct vif_params *params)
1305 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: not supported\n", __func__));
1307 /* Multiple virtual interface is not supported.
1308 * The default interface supports STA and IBSS type
1310 return ERR_PTR(-EOPNOTSUPP);
1314 ar6k_cfg80211_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev)
1317 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: not supported\n", __func__));
1319 /* Multiple virtual interface is not supported.
1320 * The default interface supports STA and IBSS type
1326 ar6k_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
1327 enum nl80211_iftype type, u32 *flags,
1328 struct vif_params *params)
1330 struct ar6_softc *ar = ar6k_priv(ndev);
1331 struct wireless_dev *wdev = ar->wdev;
1333 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: type %u\n", __func__, type));
1335 if(ar->arWmiReady == false) {
1336 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1340 if(ar->arWlanState == WLAN_DISABLED) {
1341 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1346 case NL80211_IFTYPE_STATION:
1347 ar->arNextMode = INFRA_NETWORK;
1349 case NL80211_IFTYPE_ADHOC:
1350 ar->arNextMode = ADHOC_NETWORK;
1353 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: type %u\n", __func__, type));
1357 wdev->iftype = type;
1363 ar6k_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1364 struct cfg80211_ibss_params *ibss_param)
1366 struct ar6_softc *ar = ar6k_priv(dev);
1369 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
1371 if(ar->arWmiReady == false) {
1372 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1376 if(ar->arWlanState == WLAN_DISABLED) {
1377 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1381 if(!ibss_param->ssid_len || IEEE80211_MAX_SSID_LEN < ibss_param->ssid_len) {
1382 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ssid invalid\n", __func__));
1386 ar->arSsidLen = ibss_param->ssid_len;
1387 memcpy(ar->arSsid, ibss_param->ssid, ar->arSsidLen);
1389 if(ibss_param->channel) {
1390 ar->arChannelHint = ibss_param->channel->center_freq;
1393 if(ibss_param->channel_fixed) {
1394 /* TODO: channel_fixed: The channel should be fixed, do not search for
1395 * IBSSs to join on other channels. Target firmware does not support this
1396 * feature, needs to be updated.*/
1399 A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
1400 if(ibss_param->bssid) {
1401 if(memcmp(&ibss_param->bssid, bcast_mac, AR6000_ETH_ADDR_LEN)) {
1402 memcpy(ar->arReqBssid, ibss_param->bssid, sizeof(ar->arReqBssid));
1406 ar6k_set_wpa_version(ar, 0);
1407 ar6k_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM);
1409 if(ibss_param->privacy) {
1410 ar6k_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true);
1411 ar6k_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false);
1413 ar6k_set_cipher(ar, IW_AUTH_CIPHER_NONE, true);
1414 ar6k_set_cipher(ar, IW_AUTH_CIPHER_NONE, false);
1417 ar->arNetworkType = ar->arNextMode;
1419 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Connect called with authmode %d dot11 auth %d"\
1420 " PW crypto %d PW crypto Len %d GRP crypto %d"\
1421 " GRP crypto Len %d channel hint %u\n",
1422 __func__, ar->arAuthMode, ar->arDot11AuthMode,
1423 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
1424 ar->arGroupCrypto, ar->arGroupCryptoLen, ar->arChannelHint));
1426 status = wmi_connect_cmd(ar->arWmi, ar->arNetworkType,
1427 ar->arDot11AuthMode, ar->arAuthMode,
1428 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
1429 ar->arGroupCrypto,ar->arGroupCryptoLen,
1430 ar->arSsidLen, ar->arSsid,
1431 ar->arReqBssid, ar->arChannelHint,
1432 ar->arConnectCtrlFlags);
1433 ar->arConnectPending = true;
1439 ar6k_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1441 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
1443 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
1445 if(ar->arWmiReady == false) {
1446 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wmi not ready\n", __func__));
1450 if(ar->arWlanState == WLAN_DISABLED) {
1451 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Wlan disabled\n", __func__));
1455 ar6000_disconnect(ar);
1456 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
1462 #ifdef CONFIG_NL80211_TESTMODE
1463 enum ar6k_testmode_attr {
1464 __AR6K_TM_ATTR_INVALID = 0,
1465 AR6K_TM_ATTR_CMD = 1,
1466 AR6K_TM_ATTR_DATA = 2,
1469 __AR6K_TM_ATTR_AFTER_LAST,
1470 AR6K_TM_ATTR_MAX = __AR6K_TM_ATTR_AFTER_LAST - 1
1473 enum ar6k_testmode_cmd {
1474 AR6K_TM_CMD_TCMD = 0,
1475 AR6K_TM_CMD_RX_REPORT = 1,
1478 #define AR6K_TM_DATA_MAX_LEN 5000
1480 static const struct nla_policy ar6k_testmode_policy[AR6K_TM_ATTR_MAX + 1] = {
1481 [AR6K_TM_ATTR_CMD] = { .type = NLA_U32 },
1482 [AR6K_TM_ATTR_DATA] = { .type = NLA_BINARY,
1483 .len = AR6K_TM_DATA_MAX_LEN },
1486 void ar6000_testmode_rx_report_event(struct ar6_softc *ar, void *buf,
1489 if (down_interruptible(&ar->arSem))
1492 kfree(ar->tcmd_rx_report);
1494 ar->tcmd_rx_report = kmemdup(buf, buf_len, GFP_KERNEL);
1495 ar->tcmd_rx_report_len = buf_len;
1502 static int ar6000_testmode_rx_report(struct ar6_softc *ar, void *buf,
1503 int buf_len, struct sk_buff *skb)
1508 if (down_interruptible(&ar->arSem))
1509 return -ERESTARTSYS;
1511 if (ar->arWmiReady == false) {
1516 if (ar->bIsDestroyProgress) {
1521 WARN_ON(ar->tcmd_rx_report != NULL);
1522 WARN_ON(ar->tcmd_rx_report_len > 0);
1524 if (wmi_test_cmd(ar->arWmi, buf, buf_len) < 0) {
1529 left = wait_event_interruptible_timeout(arEvent,
1530 ar->tcmd_rx_report != NULL,
1536 } else if (left < 0) {
1541 if (ar->tcmd_rx_report == NULL || ar->tcmd_rx_report_len == 0) {
1546 NLA_PUT(skb, AR6K_TM_ATTR_DATA, ar->tcmd_rx_report_len,
1547 ar->tcmd_rx_report);
1549 kfree(ar->tcmd_rx_report);
1550 ar->tcmd_rx_report = NULL;
1562 static int ar6k_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1564 struct ar6_softc *ar = wiphy_priv(wiphy);
1565 struct nlattr *tb[AR6K_TM_ATTR_MAX + 1];
1566 int err, buf_len, reply_len;
1567 struct sk_buff *skb;
1570 err = nla_parse(tb, AR6K_TM_ATTR_MAX, data, len,
1571 ar6k_testmode_policy);
1575 if (!tb[AR6K_TM_ATTR_CMD])
1578 switch (nla_get_u32(tb[AR6K_TM_ATTR_CMD])) {
1579 case AR6K_TM_CMD_TCMD:
1580 if (!tb[AR6K_TM_ATTR_DATA])
1583 buf = nla_data(tb[AR6K_TM_ATTR_DATA]);
1584 buf_len = nla_len(tb[AR6K_TM_ATTR_DATA]);
1586 wmi_test_cmd(ar->arWmi, buf, buf_len);
1591 case AR6K_TM_CMD_RX_REPORT:
1592 if (!tb[AR6K_TM_ATTR_DATA])
1595 buf = nla_data(tb[AR6K_TM_ATTR_DATA]);
1596 buf_len = nla_len(tb[AR6K_TM_ATTR_DATA]);
1598 reply_len = nla_total_size(AR6K_TM_DATA_MAX_LEN);
1599 skb = cfg80211_testmode_alloc_reply_skb(wiphy, reply_len);
1603 err = ar6000_testmode_rx_report(ar, buf, buf_len, skb);
1609 return cfg80211_testmode_reply(skb);
1617 u32 cipher_suites[] = {
1618 WLAN_CIPHER_SUITE_WEP40,
1619 WLAN_CIPHER_SUITE_WEP104,
1620 WLAN_CIPHER_SUITE_TKIP,
1621 WLAN_CIPHER_SUITE_CCMP,
1624 bool is_rate_legacy(s32 rate)
1626 static const s32 legacy[] = { 1000, 2000, 5500, 11000,
1627 6000, 9000, 12000, 18000, 24000,
1628 36000, 48000, 54000 };
1631 for (i = 0; i < ARRAY_SIZE(legacy); i++) {
1632 if (rate == legacy[i])
1639 bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi)
1641 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000,
1642 52000, 58500, 65000, 72200 };
1645 for (i = 0; i < ARRAY_SIZE(ht20); i++) {
1646 if (rate == ht20[i]) {
1647 if (i == ARRAY_SIZE(ht20) - 1)
1648 /* last rate uses sgi */
1660 bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi)
1662 static const s32 ht40[] = { 13500, 27000, 40500, 54000,
1663 81000, 108000, 121500, 135000,
1667 for (i = 0; i < ARRAY_SIZE(ht40); i++) {
1668 if (rate == ht40[i]) {
1669 if (i == ARRAY_SIZE(ht40) - 1)
1670 /* last rate uses sgi */
1683 static int ar6k_get_station(struct wiphy *wiphy, struct net_device *dev,
1684 u8 *mac, struct station_info *sinfo)
1686 struct ar6_softc *ar = ar6k_priv(dev);
1693 if (memcmp(mac, ar->arBssid, ETH_ALEN) != 0)
1696 if (down_interruptible(&ar->arSem))
1699 ar->statsUpdatePending = true;
1701 ret = wmi_get_stats_cmd(ar->arWmi);
1708 left = wait_event_interruptible_timeout(arEvent,
1709 ar->statsUpdatePending == false,
1719 if (ar->arTargetStats.rx_bytes) {
1720 sinfo->rx_bytes = ar->arTargetStats.rx_bytes;
1721 sinfo->filled |= STATION_INFO_RX_BYTES;
1722 sinfo->rx_packets = ar->arTargetStats.rx_packets;
1723 sinfo->filled |= STATION_INFO_RX_PACKETS;
1726 if (ar->arTargetStats.tx_bytes) {
1727 sinfo->tx_bytes = ar->arTargetStats.tx_bytes;
1728 sinfo->filled |= STATION_INFO_TX_BYTES;
1729 sinfo->tx_packets = ar->arTargetStats.tx_packets;
1730 sinfo->filled |= STATION_INFO_TX_PACKETS;
1733 sinfo->signal = ar->arTargetStats.cs_rssi;
1734 sinfo->filled |= STATION_INFO_SIGNAL;
1736 rate = ar->arTargetStats.tx_unicast_rate;
1738 if (is_rate_legacy(rate)) {
1739 sinfo->txrate.legacy = rate / 100;
1740 } else if (is_rate_ht20(rate, &mcs, &sgi)) {
1742 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1743 sinfo->txrate.mcs = mcs - 1;
1745 sinfo->txrate.mcs = mcs;
1748 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1749 } else if (is_rate_ht40(rate, &mcs, &sgi)) {
1751 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
1752 sinfo->txrate.mcs = mcs - 1;
1754 sinfo->txrate.mcs = mcs;
1757 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
1758 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
1760 WARN(1, "invalid rate: %d", rate);
1764 sinfo->filled |= STATION_INFO_TX_BITRATE;
1769 static int ar6k_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1770 struct cfg80211_pmksa *pmksa)
1772 struct ar6_softc *ar = ar6k_priv(netdev);
1773 return wmi_setPmkid_cmd(ar->arWmi, pmksa->bssid, pmksa->pmkid, true);
1776 static int ar6k_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
1777 struct cfg80211_pmksa *pmksa)
1779 struct ar6_softc *ar = ar6k_priv(netdev);
1780 return wmi_setPmkid_cmd(ar->arWmi, pmksa->bssid, pmksa->pmkid, false);
1783 static int ar6k_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
1785 struct ar6_softc *ar = ar6k_priv(netdev);
1786 if (ar->arConnected)
1787 return wmi_setPmkid_cmd(ar->arWmi, ar->arBssid, NULL, false);
1792 cfg80211_ops ar6k_cfg80211_ops = {
1793 .change_virtual_intf = ar6k_cfg80211_change_iface,
1794 .add_virtual_intf = ar6k_cfg80211_add_virtual_intf,
1795 .del_virtual_intf = ar6k_cfg80211_del_virtual_intf,
1796 .scan = ar6k_cfg80211_scan,
1797 .connect = ar6k_cfg80211_connect,
1798 .disconnect = ar6k_cfg80211_disconnect,
1799 .add_key = ar6k_cfg80211_add_key,
1800 .get_key = ar6k_cfg80211_get_key,
1801 .del_key = ar6k_cfg80211_del_key,
1802 .set_default_key = ar6k_cfg80211_set_default_key,
1803 .set_default_mgmt_key = ar6k_cfg80211_set_default_mgmt_key,
1804 .set_wiphy_params = ar6k_cfg80211_set_wiphy_params,
1805 .set_bitrate_mask = ar6k_cfg80211_set_bitrate_mask,
1806 .set_tx_power = ar6k_cfg80211_set_txpower,
1807 .get_tx_power = ar6k_cfg80211_get_txpower,
1808 .set_power_mgmt = ar6k_cfg80211_set_power_mgmt,
1809 .join_ibss = ar6k_cfg80211_join_ibss,
1810 .leave_ibss = ar6k_cfg80211_leave_ibss,
1811 .get_station = ar6k_get_station,
1812 .set_pmksa = ar6k_set_pmksa,
1813 .del_pmksa = ar6k_del_pmksa,
1814 .flush_pmksa = ar6k_flush_pmksa,
1815 CFG80211_TESTMODE_CMD(ar6k_testmode_cmd)
1818 struct wireless_dev *
1819 ar6k_cfg80211_init(struct device *dev)
1822 struct wireless_dev *wdev;
1824 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
1826 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1828 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1829 ("%s: Couldn't allocate wireless device\n", __func__));
1830 return ERR_PTR(-ENOMEM);
1833 /* create a new wiphy for use with cfg80211 */
1834 wdev->wiphy = wiphy_new(&ar6k_cfg80211_ops, sizeof(struct ar6_softc));
1836 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1837 ("%s: Couldn't allocate wiphy device\n", __func__));
1839 return ERR_PTR(-ENOMEM);
1842 /* set device pointer for wiphy */
1843 set_wiphy_dev(wdev->wiphy, dev);
1845 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1846 BIT(NL80211_IFTYPE_ADHOC);
1847 /* max num of ssids that can be probed during scanning */
1848 wdev->wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX;
1849 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar6k_band_2ghz;
1850 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &ar6k_band_5ghz;
1851 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1853 wdev->wiphy->cipher_suites = cipher_suites;
1854 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1856 ret = wiphy_register(wdev->wiphy);
1858 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1859 ("%s: Couldn't register wiphy device\n", __func__));
1860 wiphy_free(wdev->wiphy);
1861 return ERR_PTR(ret);
1868 ar6k_cfg80211_deinit(struct ar6_softc *ar)
1870 struct wireless_dev *wdev = ar->wdev;
1872 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: \n", __func__));
1874 if(ar->scan_request) {
1875 cfg80211_scan_done(ar->scan_request, true);
1876 ar->scan_request = NULL;
1882 wiphy_unregister(wdev->wiphy);
1883 wiphy_free(wdev->wiphy);