cfg80211.c 97.1 KB
Newer Older
Kalle Valo's avatar
Kalle Valo committed
1 2
/*
 * Copyright (c) 2004-2011 Atheros Communications Inc.
3
 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
Kalle Valo's avatar
Kalle Valo committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

18 19
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

20
#include <linux/moduleparam.h>
21
#include <linux/inetdevice.h>
Kalle Valo's avatar
Kalle Valo committed
22
#include <linux/export.h>
23

Kalle Valo's avatar
Kalle Valo committed
24 25 26
#include "core.h"
#include "cfg80211.h"
#include "debug.h"
Kalle Valo's avatar
Kalle Valo committed
27
#include "hif-ops.h"
Kalle Valo's avatar
Kalle Valo committed
28
#include "testmode.h"
Kalle Valo's avatar
Kalle Valo committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

#define RATETAB_ENT(_rate, _rateid, _flags) {   \
	.bitrate    = (_rate),                  \
	.flags      = (_flags),                 \
	.hw_value   = (_rateid),                \
}

#define CHAN2G(_channel, _freq, _flags) {   \
	.band           = IEEE80211_BAND_2GHZ,  \
	.hw_value       = (_channel),           \
	.center_freq    = (_freq),              \
	.flags          = (_flags),             \
	.max_antenna_gain   = 0,                \
	.max_power      = 30,                   \
}

#define CHAN5G(_channel, _flags) {		    \
	.band           = IEEE80211_BAND_5GHZ,      \
	.hw_value       = (_channel),               \
	.center_freq    = 5000 + (5 * (_channel)),  \
	.flags          = (_flags),                 \
	.max_antenna_gain   = 0,                    \
	.max_power      = 30,                       \
}

54 55
#define DEFAULT_BG_SCAN_PERIOD 60

56 57 58 59 60
struct ath6kl_cfg80211_match_probe_ssid {
	struct cfg80211_ssid ssid;
	u8 flag;
};

Kalle Valo's avatar
Kalle Valo committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
static struct ieee80211_rate ath6kl_rates[] = {
	RATETAB_ENT(10, 0x1, 0),
	RATETAB_ENT(20, 0x2, 0),
	RATETAB_ENT(55, 0x4, 0),
	RATETAB_ENT(110, 0x8, 0),
	RATETAB_ENT(60, 0x10, 0),
	RATETAB_ENT(90, 0x20, 0),
	RATETAB_ENT(120, 0x40, 0),
	RATETAB_ENT(180, 0x80, 0),
	RATETAB_ENT(240, 0x100, 0),
	RATETAB_ENT(360, 0x200, 0),
	RATETAB_ENT(480, 0x400, 0),
	RATETAB_ENT(540, 0x800, 0),
};

#define ath6kl_a_rates     (ath6kl_rates + 4)
#define ath6kl_a_rates_size    8
#define ath6kl_g_rates     (ath6kl_rates + 0)
#define ath6kl_g_rates_size    12

81 82
#define ath6kl_g_htcap IEEE80211_HT_CAP_SGI_20
#define ath6kl_a_htcap (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
83 84 85
			IEEE80211_HT_CAP_SGI_20		 | \
			IEEE80211_HT_CAP_SGI_40)

Kalle Valo's avatar
Kalle Valo committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
static struct ieee80211_channel ath6kl_2ghz_channels[] = {
	CHAN2G(1, 2412, 0),
	CHAN2G(2, 2417, 0),
	CHAN2G(3, 2422, 0),
	CHAN2G(4, 2427, 0),
	CHAN2G(5, 2432, 0),
	CHAN2G(6, 2437, 0),
	CHAN2G(7, 2442, 0),
	CHAN2G(8, 2447, 0),
	CHAN2G(9, 2452, 0),
	CHAN2G(10, 2457, 0),
	CHAN2G(11, 2462, 0),
	CHAN2G(12, 2467, 0),
	CHAN2G(13, 2472, 0),
	CHAN2G(14, 2484, 0),
};

static struct ieee80211_channel ath6kl_5ghz_a_channels[] = {
	CHAN5G(34, 0), CHAN5G(36, 0),
	CHAN5G(38, 0), CHAN5G(40, 0),
	CHAN5G(42, 0), CHAN5G(44, 0),
	CHAN5G(46, 0), CHAN5G(48, 0),
	CHAN5G(52, 0), CHAN5G(56, 0),
	CHAN5G(60, 0), CHAN5G(64, 0),
	CHAN5G(100, 0), CHAN5G(104, 0),
	CHAN5G(108, 0), CHAN5G(112, 0),
	CHAN5G(116, 0), CHAN5G(120, 0),
	CHAN5G(124, 0), CHAN5G(128, 0),
	CHAN5G(132, 0), CHAN5G(136, 0),
	CHAN5G(140, 0), CHAN5G(149, 0),
	CHAN5G(153, 0), CHAN5G(157, 0),
	CHAN5G(161, 0), CHAN5G(165, 0),
	CHAN5G(184, 0), CHAN5G(188, 0),
	CHAN5G(192, 0), CHAN5G(196, 0),
	CHAN5G(200, 0), CHAN5G(204, 0),
	CHAN5G(208, 0), CHAN5G(212, 0),
	CHAN5G(216, 0),
};

static struct ieee80211_supported_band ath6kl_band_2ghz = {
	.n_channels = ARRAY_SIZE(ath6kl_2ghz_channels),
	.channels = ath6kl_2ghz_channels,
	.n_bitrates = ath6kl_g_rates_size,
	.bitrates = ath6kl_g_rates,
130 131
	.ht_cap.cap = ath6kl_g_htcap,
	.ht_cap.ht_supported = true,
Kalle Valo's avatar
Kalle Valo committed
132 133 134 135 136 137 138
};

static struct ieee80211_supported_band ath6kl_band_5ghz = {
	.n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels),
	.channels = ath6kl_5ghz_a_channels,
	.n_bitrates = ath6kl_a_rates_size,
	.bitrates = ath6kl_a_rates,
139
	.ht_cap.cap = ath6kl_a_htcap,
140
	.ht_cap.ht_supported = true,
Kalle Valo's avatar
Kalle Valo committed
141 142
};

143 144
#define CCKM_KRK_CIPHER_SUITE 0x004096ff /* use for KRK */

Kalle Valo's avatar
Kalle Valo committed
145 146 147 148 149
/* returns true if scheduled scan was stopped */
static bool __ath6kl_cfg80211_sscan_stop(struct ath6kl_vif *vif)
{
	struct ath6kl *ar = vif->ar;

150
	if (!test_and_clear_bit(SCHED_SCANNING, &vif->flags))
Kalle Valo's avatar
Kalle Valo committed
151 152 153 154
		return false;

	del_timer_sync(&vif->sched_scan_timer);

155 156
	if (ar->state == ATH6KL_STATE_RECOVERY)
		return true;
Kalle Valo's avatar
Kalle Valo committed
157

158
	ath6kl_wmi_enable_sched_scan_cmd(ar->wmi, vif->fw_vif_idx, false);
Kalle Valo's avatar
Kalle Valo committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

	return true;
}

static void ath6kl_cfg80211_sscan_disable(struct ath6kl_vif *vif)
{
	struct ath6kl *ar = vif->ar;
	bool stopped;

	stopped = __ath6kl_cfg80211_sscan_stop(vif);

	if (!stopped)
		return;

	cfg80211_sched_scan_stopped(ar->wiphy);
}

176
static int ath6kl_set_wpa_version(struct ath6kl_vif *vif,
Kalle Valo's avatar
Kalle Valo committed
177 178 179 180 181
				  enum nl80211_wpa_versions wpa_version)
{
	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version);

	if (!wpa_version) {
182
		vif->auth_mode = NONE_AUTH;
Kalle Valo's avatar
Kalle Valo committed
183
	} else if (wpa_version & NL80211_WPA_VERSION_2) {
184
		vif->auth_mode = WPA2_AUTH;
Kalle Valo's avatar
Kalle Valo committed
185
	} else if (wpa_version & NL80211_WPA_VERSION_1) {
186
		vif->auth_mode = WPA_AUTH;
Kalle Valo's avatar
Kalle Valo committed
187 188 189 190 191 192 193 194
	} else {
		ath6kl_err("%s: %u not supported\n", __func__, wpa_version);
		return -ENOTSUPP;
	}

	return 0;
}

195
static int ath6kl_set_auth_type(struct ath6kl_vif *vif,
Kalle Valo's avatar
Kalle Valo committed
196 197 198 199 200 201
				enum nl80211_auth_type auth_type)
{
	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type);

	switch (auth_type) {
	case NL80211_AUTHTYPE_OPEN_SYSTEM:
202
		vif->dot11_auth_mode = OPEN_AUTH;
Kalle Valo's avatar
Kalle Valo committed
203 204
		break;
	case NL80211_AUTHTYPE_SHARED_KEY:
205
		vif->dot11_auth_mode = SHARED_AUTH;
Kalle Valo's avatar
Kalle Valo committed
206 207
		break;
	case NL80211_AUTHTYPE_NETWORK_EAP:
208
		vif->dot11_auth_mode = LEAP_AUTH;
Kalle Valo's avatar
Kalle Valo committed
209 210 211
		break;

	case NL80211_AUTHTYPE_AUTOMATIC:
212
		vif->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH;
Kalle Valo's avatar
Kalle Valo committed
213 214 215
		break;

	default:
Masanari Iida's avatar
Masanari Iida committed
216
		ath6kl_err("%s: 0x%x not supported\n", __func__, auth_type);
Kalle Valo's avatar
Kalle Valo committed
217 218 219 220 221 222
		return -ENOTSUPP;
	}

	return 0;
}

223
static int ath6kl_set_cipher(struct ath6kl_vif *vif, u32 cipher, bool ucast)
Kalle Valo's avatar
Kalle Valo committed
224
{
225 226 227
	u8 *ar_cipher = ucast ? &vif->prwise_crypto : &vif->grp_crypto;
	u8 *ar_cipher_len = ucast ? &vif->prwise_crypto_len :
		&vif->grp_crypto_len;
Kalle Valo's avatar
Kalle Valo committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n",
		   __func__, cipher, ucast);

	switch (cipher) {
	case 0:
		/* our own hack to use value 0 as no crypto used */
		*ar_cipher = NONE_CRYPT;
		*ar_cipher_len = 0;
		break;
	case WLAN_CIPHER_SUITE_WEP40:
		*ar_cipher = WEP_CRYPT;
		*ar_cipher_len = 5;
		break;
	case WLAN_CIPHER_SUITE_WEP104:
		*ar_cipher = WEP_CRYPT;
		*ar_cipher_len = 13;
		break;
	case WLAN_CIPHER_SUITE_TKIP:
		*ar_cipher = TKIP_CRYPT;
		*ar_cipher_len = 0;
		break;
	case WLAN_CIPHER_SUITE_CCMP:
		*ar_cipher = AES_CRYPT;
		*ar_cipher_len = 0;
		break;
254 255 256 257
	case WLAN_CIPHER_SUITE_SMS4:
		*ar_cipher = WAPI_CRYPT;
		*ar_cipher_len = 0;
		break;
Kalle Valo's avatar
Kalle Valo committed
258 259 260 261 262 263 264 265
	default:
		ath6kl_err("cipher 0x%x not supported\n", cipher);
		return -ENOTSUPP;
	}

	return 0;
}

266
static void ath6kl_set_key_mgmt(struct ath6kl_vif *vif, u32 key_mgmt)
Kalle Valo's avatar
Kalle Valo committed
267 268 269 270
{
	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt);

	if (key_mgmt == WLAN_AKM_SUITE_PSK) {
271 272 273 274
		if (vif->auth_mode == WPA_AUTH)
			vif->auth_mode = WPA_PSK_AUTH;
		else if (vif->auth_mode == WPA2_AUTH)
			vif->auth_mode = WPA2_PSK_AUTH;
275
	} else if (key_mgmt == 0x00409600) {
276 277 278 279
		if (vif->auth_mode == WPA_AUTH)
			vif->auth_mode = WPA_AUTH_CCKM;
		else if (vif->auth_mode == WPA2_AUTH)
			vif->auth_mode = WPA2_AUTH_CCKM;
Kalle Valo's avatar
Kalle Valo committed
280
	} else if (key_mgmt != WLAN_AKM_SUITE_8021X) {
281
		vif->auth_mode = NONE_AUTH;
Kalle Valo's avatar
Kalle Valo committed
282 283 284
	}
}

285
static bool ath6kl_cfg80211_ready(struct ath6kl_vif *vif)
Kalle Valo's avatar
Kalle Valo committed
286
{
287
	struct ath6kl *ar = vif->ar;
288

Kalle Valo's avatar
Kalle Valo committed
289 290 291 292 293
	if (!test_bit(WMI_READY, &ar->flag)) {
		ath6kl_err("wmi is not ready\n");
		return false;
	}

294
	if (!test_bit(WLAN_ENABLED, &vif->flags)) {
Kalle Valo's avatar
Kalle Valo committed
295 296 297 298 299 300 301
		ath6kl_err("wlan disabled\n");
		return false;
	}

	return true;
}

302 303
static bool ath6kl_is_wpa_ie(const u8 *pos)
{
304
	return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
305 306 307 308 309 310 311 312 313
		pos[2] == 0x00 && pos[3] == 0x50 &&
		pos[4] == 0xf2 && pos[5] == 0x01;
}

static bool ath6kl_is_rsn_ie(const u8 *pos)
{
	return pos[0] == WLAN_EID_RSN;
}

314 315 316 317 318 319 320 321
static bool ath6kl_is_wps_ie(const u8 *pos)
{
	return (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
		pos[1] >= 4 &&
		pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2 &&
		pos[5] == 0x04);
}

322 323
static int ath6kl_set_assoc_req_ies(struct ath6kl_vif *vif, const u8 *ies,
				    size_t ies_len)
324
{
325
	struct ath6kl *ar = vif->ar;
326 327 328 329 330
	const u8 *pos;
	u8 *buf = NULL;
	size_t len = 0;
	int ret;

331 332 333 334 335 336
	/*
	 * Clear previously set flag
	 */

	ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;

337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
	/*
	 * Filter out RSN/WPA IE(s)
	 */

	if (ies && ies_len) {
		buf = kmalloc(ies_len, GFP_KERNEL);
		if (buf == NULL)
			return -ENOMEM;
		pos = ies;

		while (pos + 1 < ies + ies_len) {
			if (pos + 2 + pos[1] > ies + ies_len)
				break;
			if (!(ath6kl_is_wpa_ie(pos) || ath6kl_is_rsn_ie(pos))) {
				memcpy(buf + len, pos, 2 + pos[1]);
				len += 2 + pos[1];
			}
354 355 356 357

			if (ath6kl_is_wps_ie(pos))
				ar->connect_ctrl_flags |= CONNECT_WPS_FLAG;

358 359 360 361
			pos += 2 + pos[1];
		}
	}

362 363
	ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
				       WMI_FRAME_ASSOC_REQ, buf, len);
364 365 366 367
	kfree(buf);
	return ret;
}

368 369 370 371
static int ath6kl_nliftype_to_drv_iftype(enum nl80211_iftype type, u8 *nw_type)
{
	switch (type) {
	case NL80211_IFTYPE_STATION:
372
	case NL80211_IFTYPE_P2P_CLIENT:
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
		*nw_type = INFRA_NETWORK;
		break;
	case NL80211_IFTYPE_ADHOC:
		*nw_type = ADHOC_NETWORK;
		break;
	case NL80211_IFTYPE_AP:
	case NL80211_IFTYPE_P2P_GO:
		*nw_type = AP_NETWORK;
		break;
	default:
		ath6kl_err("invalid interface type %u\n", type);
		return -ENOTSUPP;
	}

	return 0;
}

static bool ath6kl_is_valid_iftype(struct ath6kl *ar, enum nl80211_iftype type,
				   u8 *if_idx, u8 *nw_type)
{
	int i;

	if (ath6kl_nliftype_to_drv_iftype(type, nw_type))
		return false;

	if (ar->ibss_if_active || ((type == NL80211_IFTYPE_ADHOC) &&
399
				   ar->num_vif))
400 401 402 403
		return false;

	if (type == NL80211_IFTYPE_STATION ||
	    type == NL80211_IFTYPE_AP || type == NL80211_IFTYPE_ADHOC) {
404
		for (i = 0; i < ar->vif_max; i++) {
405
			if ((ar->avail_idx_map) & BIT(i)) {
406 407 408 409 410 411
				*if_idx = i;
				return true;
			}
		}
	}

412 413
	if (type == NL80211_IFTYPE_P2P_CLIENT ||
	    type == NL80211_IFTYPE_P2P_GO) {
414
		for (i = ar->max_norm_iface; i < ar->vif_max; i++) {
415
			if ((ar->avail_idx_map) & BIT(i)) {
416 417 418 419 420 421
				*if_idx = i;
				return true;
			}
		}
	}

422 423 424
	return false;
}

425 426 427 428 429
static bool ath6kl_is_tx_pending(struct ath6kl *ar)
{
	return ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0;
}

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
static void ath6kl_cfg80211_sta_bmiss_enhance(struct ath6kl_vif *vif,
					      bool enable)
{
	int err;

	if (WARN_ON(!test_bit(WMI_READY, &vif->ar->flag)))
		return;

	if (vif->nw_type != INFRA_NETWORK)
		return;

	if (!test_bit(ATH6KL_FW_CAPABILITY_BMISS_ENHANCE,
		      vif->ar->fw_capabilities))
		return;

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s fw bmiss enhance\n",
		   enable ? "enable" : "disable");

	err = ath6kl_wmi_sta_bmiss_enhance_cmd(vif->ar->wmi,
					       vif->fw_vif_idx, enable);
	if (err)
		ath6kl_err("failed to %s enhanced bmiss detection: %d\n",
			   enable ? "enable" : "disable", err);
}
454

Kalle Valo's avatar
Kalle Valo committed
455 456 457 458
static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
				   struct cfg80211_connect_params *sme)
{
	struct ath6kl *ar = ath6kl_priv(dev);
459
	struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valo's avatar
Kalle Valo committed
460
	int status;
461
	u8 nw_subtype = (ar->p2p) ? SUBTYPE_P2PDEV : SUBTYPE_NONE;
462
	u16 interval;
Kalle Valo's avatar
Kalle Valo committed
463

Kalle Valo's avatar
Kalle Valo committed
464 465
	ath6kl_cfg80211_sscan_disable(vif);

466
	vif->sme_state = SME_CONNECTING;
Kalle Valo's avatar
Kalle Valo committed
467

468
	if (!ath6kl_cfg80211_ready(vif))
Kalle Valo's avatar
Kalle Valo committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
		return -EIO;

	if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
		ath6kl_err("destroy in progress\n");
		return -EBUSY;
	}

	if (test_bit(SKIP_SCAN, &ar->flag) &&
	    ((sme->channel && sme->channel->center_freq == 0) ||
	     (sme->bssid && is_zero_ether_addr(sme->bssid)))) {
		ath6kl_err("SkipScan: channel or bssid invalid\n");
		return -EINVAL;
	}

	if (down_interruptible(&ar->sem)) {
		ath6kl_err("busy, couldn't get access\n");
		return -ERESTARTSYS;
	}

	if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
		ath6kl_err("busy, destroy in progress\n");
		up(&ar->sem);
		return -EBUSY;
	}

	if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) {
		/*
		 * sleep until the command queue drains
		 */
		wait_event_interruptible_timeout(ar->event_wq,
499 500
						 ath6kl_is_tx_pending(ar),
						 WMI_TIMEOUT);
Kalle Valo's avatar
Kalle Valo committed
501 502 503 504 505 506 507
		if (signal_pending(current)) {
			ath6kl_err("cmd queue drain timeout\n");
			up(&ar->sem);
			return -EINTR;
		}
	}

508 509 510 511 512 513 514
	status = ath6kl_set_assoc_req_ies(vif, sme->ie, sme->ie_len);
	if (status) {
		up(&ar->sem);
		return status;
	}

	if (sme->ie == NULL || sme->ie_len == 0)
515
		ar->connect_ctrl_flags &= ~CONNECT_WPS_FLAG;
516

517
	if (test_bit(CONNECTED, &vif->flags) &&
518 519
	    vif->ssid_len == sme->ssid_len &&
	    !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
520
		vif->reconnect_flag = true;
521 522
		status = ath6kl_wmi_reconnect_cmd(ar->wmi, vif->fw_vif_idx,
						  vif->req_bssid,
523
						  vif->ch_hint);
Kalle Valo's avatar
Kalle Valo committed
524 525 526 527 528 529 530

		up(&ar->sem);
		if (status) {
			ath6kl_err("wmi_reconnect_cmd failed\n");
			return -EIO;
		}
		return 0;
531 532
	} else if (vif->ssid_len == sme->ssid_len &&
		   !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) {
533
		ath6kl_disconnect(vif);
Kalle Valo's avatar
Kalle Valo committed
534 535
	}

536 537 538
	memset(vif->ssid, 0, sizeof(vif->ssid));
	vif->ssid_len = sme->ssid_len;
	memcpy(vif->ssid, sme->ssid, sme->ssid_len);
Kalle Valo's avatar
Kalle Valo committed
539 540

	if (sme->channel)
541
		vif->ch_hint = sme->channel->center_freq;
Kalle Valo's avatar
Kalle Valo committed
542

543
	memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valo's avatar
Kalle Valo committed
544
	if (sme->bssid && !is_broadcast_ether_addr(sme->bssid))
545
		memcpy(vif->req_bssid, sme->bssid, sizeof(vif->req_bssid));
Kalle Valo's avatar
Kalle Valo committed
546

547
	ath6kl_set_wpa_version(vif, sme->crypto.wpa_versions);
Kalle Valo's avatar
Kalle Valo committed
548

549
	status = ath6kl_set_auth_type(vif, sme->auth_type);
Kalle Valo's avatar
Kalle Valo committed
550 551 552 553 554 555
	if (status) {
		up(&ar->sem);
		return status;
	}

	if (sme->crypto.n_ciphers_pairwise)
556
		ath6kl_set_cipher(vif, sme->crypto.ciphers_pairwise[0], true);
Kalle Valo's avatar
Kalle Valo committed
557
	else
558
		ath6kl_set_cipher(vif, 0, true);
Kalle Valo's avatar
Kalle Valo committed
559

560
	ath6kl_set_cipher(vif, sme->crypto.cipher_group, false);
Kalle Valo's avatar
Kalle Valo committed
561 562

	if (sme->crypto.n_akm_suites)
563
		ath6kl_set_key_mgmt(vif, sme->crypto.akm_suites[0]);
Kalle Valo's avatar
Kalle Valo committed
564 565

	if ((sme->key_len) &&
566 567
	    (vif->auth_mode == NONE_AUTH) &&
	    (vif->prwise_crypto == WEP_CRYPT)) {
Kalle Valo's avatar
Kalle Valo committed
568 569
		struct ath6kl_key *key = NULL;

570
		if (sme->key_idx > WMI_MAX_KEY_INDEX) {
Kalle Valo's avatar
Kalle Valo committed
571 572 573 574 575 576
			ath6kl_err("key index %d out of bounds\n",
				   sme->key_idx);
			up(&ar->sem);
			return -ENOENT;
		}

577
		key = &vif->keys[sme->key_idx];
Kalle Valo's avatar
Kalle Valo committed
578 579
		key->key_len = sme->key_len;
		memcpy(key->key, sme->key, key->key_len);
580 581
		key->cipher = vif->prwise_crypto;
		vif->def_txkey_index = sme->key_idx;
Kalle Valo's avatar
Kalle Valo committed
582

583
		ath6kl_wmi_addkey_cmd(ar->wmi, vif->fw_vif_idx, sme->key_idx,
584
				      vif->prwise_crypto,
Kalle Valo's avatar
Kalle Valo committed
585 586
				      GROUP_USAGE | TX_USAGE,
				      key->key_len,
587
				      NULL, 0,
Kalle Valo's avatar
Kalle Valo committed
588 589 590 591 592
				      key->key, KEY_OP_INIT_VAL, NULL,
				      NO_SYNC_WMIFLAG);
	}

	if (!ar->usr_bss_filter) {
593
		clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
594
		if (ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
595
					     ALL_BSS_FILTER, 0) != 0) {
Kalle Valo's avatar
Kalle Valo committed
596 597 598 599 600 601
			ath6kl_err("couldn't set bss filtering\n");
			up(&ar->sem);
			return -EIO;
		}
	}

602
	vif->nw_type = vif->next_mode;
Kalle Valo's avatar
Kalle Valo committed
603

604 605 606
	/* enable enhanced bmiss detection if applicable */
	ath6kl_cfg80211_sta_bmiss_enhance(vif, true);

607 608 609
	if (vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)
		nw_subtype = SUBTYPE_P2PCLIENT;

Kalle Valo's avatar
Kalle Valo committed
610 611 612 613 614
	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
		   "%s: connect called with authmode %d dot11 auth %d"
		   " PW crypto %d PW crypto len %d GRP crypto %d"
		   " GRP crypto len %d channel hint %u\n",
		   __func__,
615 616
		   vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto,
		   vif->prwise_crypto_len, vif->grp_crypto,
617
		   vif->grp_crypto_len, vif->ch_hint);
Kalle Valo's avatar
Kalle Valo committed
618

619
	vif->reconnect_flag = 0;
620 621

	if (vif->nw_type == INFRA_NETWORK) {
622 623
		interval = max_t(u16, vif->listen_intvl_t,
				 ATH6KL_MAX_WOW_LISTEN_INTL);
624 625 626 627 628 629 630 631 632 633
		status = ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
						       interval,
						       0);
		if (status) {
			ath6kl_err("couldn't set listen intervel\n");
			up(&ar->sem);
			return status;
		}
	}

634
	status = ath6kl_wmi_connect_cmd(ar->wmi, vif->fw_vif_idx, vif->nw_type,
635 636 637 638 639
					vif->dot11_auth_mode, vif->auth_mode,
					vif->prwise_crypto,
					vif->prwise_crypto_len,
					vif->grp_crypto, vif->grp_crypto_len,
					vif->ssid_len, vif->ssid,
640
					vif->req_bssid, vif->ch_hint,
641
					ar->connect_ctrl_flags, nw_subtype);
Kalle Valo's avatar
Kalle Valo committed
642

643 644
	if (sme->bg_scan_period == 0) {
		/* disable background scan if period is 0 */
645
		sme->bg_scan_period = 0xffff;
646 647
	} else if (sme->bg_scan_period == -1) {
		/* configure default value if not specified */
648
		sme->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
649
	}
650 651 652 653

	ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0, 0,
				  sme->bg_scan_period, 0, 0, 0, 3, 0, 0, 0);

Kalle Valo's avatar
Kalle Valo committed
654 655 656
	up(&ar->sem);

	if (status == -EINVAL) {
657 658
		memset(vif->ssid, 0, sizeof(vif->ssid));
		vif->ssid_len = 0;
Kalle Valo's avatar
Kalle Valo committed
659 660 661 662 663 664 665 666
		ath6kl_err("invalid request\n");
		return -ENOENT;
	} else if (status) {
		ath6kl_err("ath6kl_wmi_connect_cmd failed\n");
		return -EIO;
	}

	if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) &&
667 668
	    ((vif->auth_mode == WPA_PSK_AUTH) ||
	     (vif->auth_mode == WPA2_PSK_AUTH))) {
669
		mod_timer(&vif->disconnect_timer,
Kalle Valo's avatar
Kalle Valo committed
670 671 672 673
			  jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL));
	}

	ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD;
674
	set_bit(CONNECT_PEND, &vif->flags);
Kalle Valo's avatar
Kalle Valo committed
675 676 677 678

	return 0;
}

679 680 681 682 683 684 685
static struct cfg80211_bss *
ath6kl_add_bss_if_needed(struct ath6kl_vif *vif,
			 enum network_type nw_type,
			 const u8 *bssid,
			 struct ieee80211_channel *chan,
			 const u8 *beacon_ie,
			 size_t beacon_ie_len)
686
{
687
	struct ath6kl *ar = vif->ar;
688
	struct cfg80211_bss *bss;
689 690
	u16 cap_val;
	enum ieee80211_bss_type bss_type;
691 692
	u8 *ie;

693 694
	if (nw_type & ADHOC_NETWORK) {
		cap_val = WLAN_CAPABILITY_IBSS;
695
		bss_type = IEEE80211_BSS_TYPE_IBSS;
696 697
	} else {
		cap_val = WLAN_CAPABILITY_ESS;
698
		bss_type = IEEE80211_BSS_TYPE_ESS;
699 700
	}

701
	bss = cfg80211_get_bss(ar->wiphy, chan, bssid,
702
			       vif->ssid, vif->ssid_len,
703
			       bss_type, IEEE80211_PRIVACY_ANY);
704 705 706 707 708 709 710 711 712
	if (bss == NULL) {
		/*
		 * Since cfg80211 may not yet know about the BSS,
		 * generate a partial entry until the first BSS info
		 * event becomes available.
		 *
		 * Prepend SSID element since it is not included in the Beacon
		 * IEs from the target.
		 */
713
		ie = kmalloc(2 + vif->ssid_len + beacon_ie_len, GFP_KERNEL);
714
		if (ie == NULL)
715
			return NULL;
716
		ie[0] = WLAN_EID_SSID;
717 718 719
		ie[1] = vif->ssid_len;
		memcpy(ie + 2, vif->ssid, vif->ssid_len);
		memcpy(ie + 2 + vif->ssid_len, beacon_ie, beacon_ie_len);
720
		bss = cfg80211_inform_bss(ar->wiphy, chan,
721
					  CFG80211_BSS_FTYPE_UNKNOWN,
722
					  bssid, 0, cap_val, 100,
723
					  ie, 2 + vif->ssid_len + beacon_ie_len,
724 725
					  0, GFP_KERNEL);
		if (bss)
726 727
			ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
				   "added bss %pM to cfg80211\n", bssid);
728
		kfree(ie);
729
	} else {
730
		ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss\n");
731
	}
732

733
	return bss;
734 735
}

736
void ath6kl_cfg80211_connect_event(struct ath6kl_vif *vif, u16 channel,
Kalle Valo's avatar
Kalle Valo committed
737 738 739 740 741 742
				   u8 *bssid, u16 listen_intvl,
				   u16 beacon_intvl,
				   enum network_type nw_type,
				   u8 beacon_ie_len, u8 assoc_req_len,
				   u8 assoc_resp_len, u8 *assoc_info)
{
743
	struct ieee80211_channel *chan;
744
	struct ath6kl *ar = vif->ar;
745
	struct cfg80211_bss *bss;
Kalle Valo's avatar
Kalle Valo committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759

	/* capinfo + listen interval */
	u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16);

	/* capinfo + status code +  associd */
	u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16);

	u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset;
	u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len +
	    assoc_resp_ie_offset;

	assoc_req_len -= assoc_req_ie_offset;
	assoc_resp_len -= assoc_resp_ie_offset;

760 761 762 763
	/*
	 * Store Beacon interval here; DTIM period will be available only once
	 * a Beacon frame from the AP is seen.
	 */
764
	vif->assoc_bss_beacon_int = beacon_intvl;
765
	clear_bit(DTIM_PERIOD_AVAIL, &vif->flags);
766

Kalle Valo's avatar
Kalle Valo committed
767
	if (nw_type & ADHOC_NETWORK) {
768
		if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
Kalle Valo's avatar
Kalle Valo committed
769 770 771 772 773 774 775
			ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
				   "%s: ath6k not in ibss mode\n", __func__);
			return;
		}
	}

	if (nw_type & INFRA_NETWORK) {
776 777
		if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
		    vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valo's avatar
Kalle Valo committed
778 779 780 781 782 783
			ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
				   "%s: ath6k not in station mode\n", __func__);
			return;
		}
	}

784
	chan = ieee80211_get_channel(ar->wiphy, (int) channel);
Kalle Valo's avatar
Kalle Valo committed
785

786 787 788
	bss = ath6kl_add_bss_if_needed(vif, nw_type, bssid, chan,
				       assoc_info, beacon_ie_len);
	if (!bss) {
789
		ath6kl_err("could not add cfg80211 bss entry\n");
Kalle Valo's avatar
Kalle Valo committed
790 791 792
		return;
	}

793 794 795
	if (nw_type & ADHOC_NETWORK) {
		ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "ad-hoc %s selected\n",
			   nw_type & ADHOC_CREATOR ? "creator" : "joiner");
796
		cfg80211_ibss_joined(vif->ndev, bssid, chan, GFP_KERNEL);
797
		cfg80211_put_bss(ar->wiphy, bss);
Kalle Valo's avatar
Kalle Valo committed
798 799 800
		return;
	}

801
	if (vif->sme_state == SME_CONNECTING) {
Kalle Valo's avatar
Kalle Valo committed
802
		/* inform connect result to cfg80211 */
803
		vif->sme_state = SME_CONNECTED;
804
		cfg80211_connect_result(vif->ndev, bssid,
Kalle Valo's avatar
Kalle Valo committed
805 806 807
					assoc_req_ie, assoc_req_len,
					assoc_resp_ie, assoc_resp_len,
					WLAN_STATUS_SUCCESS, GFP_KERNEL);
808
		cfg80211_put_bss(ar->wiphy, bss);
809
	} else if (vif->sme_state == SME_CONNECTED) {
Kalle Valo's avatar
Kalle Valo committed
810
		/* inform roam event to cfg80211 */
811 812
		cfg80211_roamed_bss(vif->ndev, bss, assoc_req_ie, assoc_req_len,
				    assoc_resp_ie, assoc_resp_len, GFP_KERNEL);
Kalle Valo's avatar
Kalle Valo committed
813 814 815 816 817 818
	}
}

static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy,
				      struct net_device *dev, u16 reason_code)
{
Kalle Valo's avatar
Kalle Valo committed
819
	struct ath6kl *ar = ath6kl_priv(dev);
820
	struct ath6kl_vif *vif = netdev_priv(dev);
Kalle Valo's avatar
Kalle Valo committed
821 822 823 824

	ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__,
		   reason_code);

Kalle Valo's avatar
Kalle Valo committed
825 826
	ath6kl_cfg80211_sscan_disable(vif);

827
	if (!ath6kl_cfg80211_ready(vif))
Kalle Valo's avatar
Kalle Valo committed
828 829 830 831 832 833 834 835 836 837 838 839
		return -EIO;

	if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) {
		ath6kl_err("busy, destroy in progress\n");
		return -EBUSY;
	}

	if (down_interruptible(&ar->sem)) {
		ath6kl_err("busy, couldn't get access\n");
		return -ERESTARTSYS;
	}

840
	vif->reconnect_flag = 0;
841
	ath6kl_disconnect(vif);
842 843
	memset(vif->ssid, 0, sizeof(vif->ssid));
	vif->ssid_len = 0;
Kalle Valo's avatar
Kalle Valo committed
844 845

	if (!test_bit(SKIP_SCAN, &ar->flag))
846
		memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
Kalle Valo's avatar
Kalle Valo committed
847 848 849

	up(&ar->sem);

850
	vif->sme_state = SME_DISCONNECTED;
851

Kalle Valo's avatar
Kalle Valo committed
852 853 854
	return 0;
}

855
void ath6kl_cfg80211_disconnect_event(struct ath6kl_vif *vif, u8 reason,
Kalle Valo's avatar
Kalle Valo committed
856 857 858
				      u8 *bssid, u8 assoc_resp_len,
				      u8 *assoc_info, u16 proto_reason)
{
859
	struct ath6kl *ar = vif->ar;
860

861 862 863
	if (vif->scan_req) {
		cfg80211_scan_done(vif->scan_req, true);
		vif->scan_req = NULL;
Kalle Valo's avatar
Kalle Valo committed
864 865
	}

866
	if (vif->nw_type & ADHOC_NETWORK) {
867
		if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC)
Kalle Valo's avatar
Kalle Valo committed
868 869 870 871 872
			ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
				   "%s: ath6k not in ibss mode\n", __func__);
		return;
	}

873
	if (vif->nw_type & INFRA_NETWORK) {
874 875
		if (vif->wdev.iftype != NL80211_IFTYPE_STATION &&
		    vif->wdev.iftype != NL80211_IFTYPE_P2P_CLIENT) {
Kalle Valo's avatar
Kalle Valo committed
876 877 878 879 880 881
			ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
				   "%s: ath6k not in station mode\n", __func__);
			return;
		}
	}

882
	clear_bit(CONNECT_PEND, &vif->flags);
Kalle Valo's avatar
Kalle Valo committed
883

884
	if (vif->sme_state == SME_CONNECTING) {
885
		cfg80211_connect_result(vif->ndev,
886 887 888 889
					bssid, NULL, 0,
					NULL, 0,
					WLAN_STATUS_UNSPECIFIED_FAILURE,
					GFP_KERNEL);
890
	} else if (vif->sme_state == SME_CONNECTED) {
891
		cfg80211_disconnected(vif->ndev, proto_reason,
892
				      NULL, 0, GFP_KERNEL);
Kalle Valo's avatar
Kalle Valo committed
893 894
	}

895
	vif->sme_state = SME_DISCONNECTED;
896 897 898 899 900 901 902 903 904 905 906

	/*
	 * Send a disconnect command to target when a disconnect event is
	 * received with reason code other than 3 (DISCONNECT_CMD - disconnect
	 * request from host) to make the firmware stop trying to connect even
	 * after giving disconnect event. There will be one more disconnect
	 * event for this disconnect command with reason code DISCONNECT_CMD
	 * which won't be notified to cfg80211.
	 */
	if (reason != DISCONNECT_CMD)
		ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
Kalle Valo's avatar
Kalle Valo committed
907 908
}

909 910
static int ath6kl_set_probed_ssids(struct ath6kl *ar,
				   struct ath6kl_vif *vif,
911 912 913
				   struct cfg80211_ssid *ssids, int n_ssids,
				   struct cfg80211_match_set *match_set,
				   int n_match_ssid)
914
{
915 916 917 918
	u8 i, j, index_to_add, ssid_found = false;
	struct ath6kl_cfg80211_match_probe_ssid ssid_list[MAX_PROBED_SSIDS];

	memset(ssid_list, 0, sizeof(ssid_list));
919

920 921
	if (n_ssids > MAX_PROBED_SSIDS ||
	    n_match_ssid > MAX_PROBED_SSIDS)
922 923 924
		return -EINVAL;

	for (i = 0; i < n_ssids; i++) {
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
		memcpy(ssid_list[i].ssid.ssid,
		       ssids[i].ssid,
		       ssids[i].ssid_len);
		ssid_list[i].ssid.ssid_len = ssids[i].ssid_len;

		if (ssids[i].ssid_len)
			ssid_list[i].flag = SPECIFIC_SSID_FLAG;
		else
			ssid_list[i].flag = ANY_SSID_FLAG;

		if (n_match_ssid == 0)
			ssid_list[i].flag |= MATCH_SSID_FLAG;
	}

	index_to_add = i;

	for (i = 0; i < n_match_ssid; i++) {
		ssid_found = false;

		for (j = 0; j < n_ssids; j++) {
			if ((match_set[i].ssid.ssid_len ==
			     ssid_list[j].ssid.ssid_len) &&
			    (!memcmp(ssid_list[j].ssid.ssid,
				     match_set[i].ssid.ssid,
				     match_set[i].ssid.ssid_len))) {
				ssid_list[j].flag |= MATCH_SSID_FLAG;
				ssid_found = true;
				break;
			}
		}

		if (ssid_found)
			continue;

		if (index_to_add >= MAX_PROBED_SSIDS)
			continue;

		ssid_list[index_to_add].ssid.ssid_len =
			match_set[i].ssid.ssid_len;
		memcpy(ssid_list[index_to_add].ssid.ssid,
		       match_set[i].ssid.ssid,
		       match_set[i].ssid.ssid_len);
		ssid_list[index_to_add].flag |= MATCH_SSID_FLAG;
		index_to_add++;
	}

	for (i = 0; i < index_to_add; i++) {
972
		ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, i,
973 974 975
					  ssid_list[i].flag,
					  ssid_list[i].ssid.ssid_len,
					  ssid_list[i].ssid.ssid);
976 977 978
	}

	/* Make sure no old entries are left behind */
979
	for (i = index_to_add; i < MAX_PROBED_SSIDS; i++) {
980 981 982 983 984 985 986
		ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, i,
					  DISABLE_SSID_FLAG, 0, NULL);
	}

	return 0;
}

Johannes Berg's avatar
Johannes Berg committed
987
static int ath6kl_cfg80211_scan(struct wiphy *wiphy,
Kalle Valo's avatar
Kalle Valo committed
988 989
				struct cfg80211_scan_request *request)
{
Johannes Berg's avatar
Johannes Berg committed
990 991
	struct ath6kl_vif *vif = ath6kl_vif_from_wdev(request->wdev);
	struct ath6kl *ar = ath6kl_priv(vif->ndev);
992 993
	s8 n_channels = 0;
	u16 *channels = NULL;
Kalle Valo's avatar
Kalle Valo committed
994
	int ret = 0;
995
	u32 force_fg_scan = 0;
Kalle Valo's avatar
Kalle Valo committed
996

997
	if (!ath6kl_cfg80211_ready(vif))
Kalle Valo's avatar
Kalle Valo committed
998 999
		return -EIO;

Kalle Valo's avatar
Kalle Valo committed
1000 1001
	ath6kl_cfg80211_sscan_disable(vif);

Kalle Valo's avatar
Kalle Valo committed
1002
	if (!ar->usr_bss_filter) {
1003
		clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
1004 1005
		ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
					       ALL_BSS_FILTER, 0);
1006
		if (ret) {
Kalle Valo's avatar
Kalle Valo committed
1007
			ath6kl_err("couldn't set bss filtering\n");
1008
			return ret;
Kalle Valo's avatar
Kalle Valo committed
1009 1010 1011
		}
	}

1012
	ret = ath6kl_set_probed_ssids(ar, vif, request->ssids,
1013
				      request->n_ssids, NULL, 0);
1014 1015
	if (ret < 0)
		return ret;
Kalle Valo's avatar
Kalle Valo committed
1016

1017 1018 1019 1020 1021
	/* this also clears IE in fw if it's not set */
	ret = ath6kl_wmi_set_appie_cmd(ar->wmi, vif->fw_vif_idx,
				       WMI_FRAME_PROBE_REQ,
				       request->ie, request->ie_len);
	if (ret) {
1022
		ath6kl_err("failed to set Probe Request appie for scan\n");
1023
		return ret;
1024 1025
	}

1026 1027 1028 1029 1030 1031 1032
	/*
	 * Scan only the requested channels if the request specifies a set of
	 * channels. If the list is longer than the target supports, do not
	 * configure the list and instead, scan all available channels.
	 */
	if (request->n_channels > 0 &&
	    request->n_channels <= WMI_MAX_CHANNELS) {
1033 1034
		u8 i;

1035
		n_channels = request->n_channels;
1036 1037 1038

		channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL);
		if (channels == NULL) {
1039
			ath6kl_warn("failed to set scan channels, scan all channels");
1040 1041 1042 1043 1044 1045 1046
			n_channels = 0;
		}

		for (i = 0; i < n_channels; i++)
			channels[i] = request->channels[i]->center_freq;
	}