scan.c 15.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * This file is part of wl1271
 *
 * Copyright (C) 2009-2010 Nokia Corporation
 *
 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <linux/ieee80211.h>

S
Shahar Levi 已提交
26 27 28 29
#include "wl12xx.h"
#include "cmd.h"
#include "scan.h"
#include "acx.h"
30
#include "ps.h"
31

32 33
void wl1271_scan_complete_work(struct work_struct *work)
{
34 35
	struct delayed_work *dwork;
	struct wl1271 *wl;
36
	int ret;
37 38 39

	dwork = container_of(work, struct delayed_work, work);
	wl = container_of(dwork, struct wl1271, scan_complete_work);
40 41 42 43

	wl1271_debug(DEBUG_SCAN, "Scanning complete");

	mutex_lock(&wl->mutex);
44

45 46 47 48 49
	if (wl->state == WL1271_STATE_OFF)
		goto out;

	if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
		goto out;
50

51
	wl->scan.state = WL1271_SCAN_STATE_IDLE;
52
	memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
53
	wl->scan.req = NULL;
54

55 56 57 58
	ret = wl1271_ps_elp_wakeup(wl);
	if (ret < 0)
		goto out;

59
	if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
60 61 62 63 64 65
		/* restore hardware connection monitoring template */
		wl1271_cmd_build_ap_probe_req(wl, wl->probereq);
	} else {
		/* restore remain on channel */
		wl12xx_cmd_role_start_dev(wl);
		wl12xx_roc(wl, wl->dev_role_id);
66
	}
67
	wl1271_ps_elp_sleep(wl);
68

69 70
	if (wl->scan.failed) {
		wl1271_info("Scan completed due to error.");
71
		wl12xx_queue_recovery_work(wl);
72
	}
73

74 75
	ieee80211_scan_completed(wl->hw, false);

76
out:
77 78
	mutex_unlock(&wl->mutex);

79 80 81
}


L
Luciano Coelho 已提交
82 83 84 85
static int wl1271_get_scan_channels(struct wl1271 *wl,
				    struct cfg80211_scan_request *req,
				    struct basic_scan_channel_params *channels,
				    enum ieee80211_band band, bool passive)
86
{
J
Juuso Oikarinen 已提交
87
	struct conf_scan_settings *c = &wl->conf.scan;
L
Luciano Coelho 已提交
88 89
	int i, j;
	u32 flags;
90

L
Luciano Coelho 已提交
91 92 93
	for (i = 0, j = 0;
	     i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
	     i++) {
94

L
Luciano Coelho 已提交
95
		flags = req->channels[i]->flags;
96

97
		if (!test_bit(i, wl->scan.scanned_ch) &&
L
Luciano Coelho 已提交
98 99 100
		    !(flags & IEEE80211_CHAN_DISABLED) &&
		    ((!!(flags & IEEE80211_CHAN_PASSIVE_SCAN)) == passive) &&
		    (req->channels[i]->band == band)) {
101

L
Luciano Coelho 已提交
102 103 104 105 106 107 108 109 110 111 112 113
			wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
				     req->channels[i]->band,
				     req->channels[i]->center_freq);
			wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
				     req->channels[i]->hw_value,
				     req->channels[i]->flags);
			wl1271_debug(DEBUG_SCAN,
				     "max_antenna_gain %d, max_power %d",
				     req->channels[i]->max_antenna_gain,
				     req->channels[i]->max_power);
			wl1271_debug(DEBUG_SCAN, "beacon_found %d",
				     req->channels[i]->beacon_found);
114

J
Juuso Oikarinen 已提交
115 116 117 118 119 120 121 122 123 124 125
			if (!passive) {
				channels[j].min_duration =
					cpu_to_le32(c->min_dwell_time_active);
				channels[j].max_duration =
					cpu_to_le32(c->max_dwell_time_active);
			} else {
				channels[j].min_duration =
					cpu_to_le32(c->min_dwell_time_passive);
				channels[j].max_duration =
					cpu_to_le32(c->max_dwell_time_passive);
			}
L
Luciano Coelho 已提交
126
			channels[j].early_termination = 0;
127
			channels[j].tx_power_att = req->channels[i]->max_power;
L
Luciano Coelho 已提交
128 129 130 131 132 133
			channels[j].channel = req->channels[i]->hw_value;

			memset(&channels[j].bssid_lsb, 0xff, 4);
			memset(&channels[j].bssid_msb, 0xff, 2);

			/* Mark the channels we already used */
134
			set_bit(i, wl->scan.scanned_ch);
L
Luciano Coelho 已提交
135

136 137 138 139
			j++;
		}
	}

L
Luciano Coelho 已提交
140 141
	return j;
}
142

L
Luciano Coelho 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
#define WL1271_NOTHING_TO_SCAN 1

static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
			     bool passive, u32 basic_rate)
{
	struct wl1271_cmd_scan *cmd;
	struct wl1271_cmd_trigger_scan_to *trigger;
	int ret;
	u16 scan_options = 0;

	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
	trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
	if (!cmd || !trigger) {
		ret = -ENOMEM;
		goto out;
158 159
	}

L
Luciano Coelho 已提交
160 161
	/* We always use high priority scans */
	scan_options = WL1271_SCAN_OPT_PRIORITY_HIGH;
L
Luciano Coelho 已提交
162 163 164

	/* No SSIDs means that we have a forced passive scan */
	if (passive || wl->scan.req->n_ssids == 0)
L
Luciano Coelho 已提交
165
		scan_options |= WL1271_SCAN_OPT_PASSIVE;
L
Luciano Coelho 已提交
166

E
Eliad Peller 已提交
167 168 169 170 171
	if (WARN_ON(wl->role_id == WL12XX_INVALID_ROLE_ID)) {
		ret = -EINVAL;
		goto out;
	}
	cmd->params.role_id = wl->role_id;
L
Luciano Coelho 已提交
172 173 174 175 176 177 178
	cmd->params.scan_options = cpu_to_le16(scan_options);

	cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
						    cmd->channels,
						    band, passive);
	if (cmd->params.n_ch == 0) {
		ret = WL1271_NOTHING_TO_SCAN;
179 180 181
		goto out;
	}

L
Luciano Coelho 已提交
182
	cmd->params.tx_rate = cpu_to_le32(basic_rate);
J
Juuso Oikarinen 已提交
183
	cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
L
Luciano Coelho 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197
	cmd->params.tx_rate = cpu_to_le32(basic_rate);
	cmd->params.tid_trigger = 0;
	cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;

	if (band == IEEE80211_BAND_2GHZ)
		cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
	else
		cmd->params.band = WL1271_SCAN_BAND_5_GHZ;

	if (wl->scan.ssid_len && wl->scan.ssid) {
		cmd->params.ssid_len = wl->scan.ssid_len;
		memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
	}

E
Eliad Peller 已提交
198 199
	memcpy(cmd->addr, wl->mac_addr, ETH_ALEN);

L
Luciano Coelho 已提交
200 201 202 203 204
	ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len,
					 wl->scan.req->ie, wl->scan.req->ie_len,
					 band);
	if (ret < 0) {
		wl1271_error("PROBE request template failed");
205 206 207 208 209 210 211 212 213 214 215 216
		goto out;
	}

	/* disable the timeout */
	trigger->timeout = 0;
	ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
			      sizeof(*trigger), 0);
	if (ret < 0) {
		wl1271_error("trigger scan to failed for hw scan");
		goto out;
	}

L
Luciano Coelho 已提交
217
	wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
218

L
Luciano Coelho 已提交
219
	ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
220 221 222 223 224 225
	if (ret < 0) {
		wl1271_error("SCAN failed");
		goto out;
	}

out:
L
Luciano Coelho 已提交
226
	kfree(cmd);
227 228 229 230
	kfree(trigger);
	return ret;
}

L
Luciano Coelho 已提交
231
void wl1271_scan_stm(struct wl1271 *wl)
232
{
233
	int ret = 0;
L
Luciano Coelho 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252

	switch (wl->scan.state) {
	case WL1271_SCAN_STATE_IDLE:
		break;

	case WL1271_SCAN_STATE_2GHZ_ACTIVE:
		ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false,
				       wl->conf.tx.basic_rate);
		if (ret == WL1271_NOTHING_TO_SCAN) {
			wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
			wl1271_scan_stm(wl);
		}

		break;

	case WL1271_SCAN_STATE_2GHZ_PASSIVE:
		ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true,
				       wl->conf.tx.basic_rate);
		if (ret == WL1271_NOTHING_TO_SCAN) {
253
			if (wl->enable_11a)
L
Luciano Coelho 已提交
254 255 256 257
				wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
			else
				wl->scan.state = WL1271_SCAN_STATE_DONE;
			wl1271_scan_stm(wl);
258
		}
L
Luciano Coelho 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282

		break;

	case WL1271_SCAN_STATE_5GHZ_ACTIVE:
		ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false,
				       wl->conf.tx.basic_rate_5);
		if (ret == WL1271_NOTHING_TO_SCAN) {
			wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
			wl1271_scan_stm(wl);
		}

		break;

	case WL1271_SCAN_STATE_5GHZ_PASSIVE:
		ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true,
				       wl->conf.tx.basic_rate_5);
		if (ret == WL1271_NOTHING_TO_SCAN) {
			wl->scan.state = WL1271_SCAN_STATE_DONE;
			wl1271_scan_stm(wl);
		}

		break;

	case WL1271_SCAN_STATE_DONE:
283 284 285 286
		wl->scan.failed = false;
		cancel_delayed_work(&wl->scan_complete_work);
		ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
					     msecs_to_jiffies(0));
L
Luciano Coelho 已提交
287 288 289 290 291
		break;

	default:
		wl1271_error("invalid scan state");
		break;
292
	}
293 294 295 296 297 298

	if (ret < 0) {
		cancel_delayed_work(&wl->scan_complete_work);
		ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
					     msecs_to_jiffies(0));
	}
L
Luciano Coelho 已提交
299 300 301 302 303
}

int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
		struct cfg80211_scan_request *req)
{
304 305 306 307 308 309
	/*
	 * cfg80211 should guarantee that we don't get more channels
	 * than what we have registered.
	 */
	BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);

L
Luciano Coelho 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322
	if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
		return -EBUSY;

	wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;

	if (ssid_len && ssid) {
		wl->scan.ssid_len = ssid_len;
		memcpy(wl->scan.ssid, ssid, ssid_len);
	} else {
		wl->scan.ssid_len = 0;
	}

	wl->scan.req = req;
323
	memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
L
Luciano Coelho 已提交
324

325 326 327 328 329
	/* we assume failure so that timeout scenarios are handled correctly */
	wl->scan.failed = true;
	ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
				     msecs_to_jiffies(WL1271_SCAN_TIMEOUT));

L
Luciano Coelho 已提交
330 331
	wl1271_scan_stm(wl);

332 333
	return 0;
}
334

E
Eliad Peller 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
int wl1271_scan_stop(struct wl1271 *wl)
{
	struct wl1271_cmd_header *cmd = NULL;
	int ret = 0;

	if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE))
		return -EINVAL;

	wl1271_debug(DEBUG_CMD, "cmd scan stop");

	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
	if (!cmd) {
		ret = -ENOMEM;
		goto out;
	}

	ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd,
			      sizeof(*cmd), 0);
	if (ret < 0) {
		wl1271_error("cmd stop_scan failed");
		goto out;
	}
out:
	kfree(cmd);
	return ret;
}

362 363 364 365 366
static int
wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
				    struct cfg80211_sched_scan_request *req,
				    struct conn_scan_ch_params *channels,
				    u32 band, bool radar, bool passive,
367
				    int start, int max_channels)
368 369 370 371
{
	struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
	int i, j;
	u32 flags;
372
	bool force_passive = !req->n_ssids;
373 374

	for (i = 0, j = start;
375
	     i < req->n_channels && j < max_channels;
376 377 378
	     i++) {
		flags = req->channels[i]->flags;

379 380 381
		if (force_passive)
			flags |= IEEE80211_CHAN_PASSIVE_SCAN;

382 383
		if ((req->channels[i]->band == band) &&
		    !(flags & IEEE80211_CHAN_DISABLED) &&
384
		    (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
385 386 387
		    /* if radar is set, we ignore the passive flag */
		    (radar ||
		     !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
388 389 390 391 392 393 394 395 396
			wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
				     req->channels[i]->band,
				     req->channels[i]->center_freq);
			wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
				     req->channels[i]->hw_value,
				     req->channels[i]->flags);
			wl1271_debug(DEBUG_SCAN, "max_power %d",
				     req->channels[i]->max_power);

397
			if (flags & IEEE80211_CHAN_RADAR) {
398
				channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
399 400 401 402
				channels[j].passive_duration =
					cpu_to_le16(c->dwell_time_dfs);
			}
			else if (flags & IEEE80211_CHAN_PASSIVE_SCAN) {
403 404 405 406 407 408 409 410
				channels[j].passive_duration =
					cpu_to_le16(c->dwell_time_passive);
			} else {
				channels[j].min_duration =
					cpu_to_le16(c->min_dwell_time_active);
				channels[j].max_duration =
					cpu_to_le16(c->max_dwell_time_active);
			}
411
			channels[j].tx_power_att = req->channels[i]->max_power;
412 413 414 415 416 417 418 419 420
			channels[j].channel = req->channels[i]->hw_value;

			j++;
		}
	}

	return j - start;
}

421
static bool
422 423 424 425 426
wl1271_scan_sched_scan_channels(struct wl1271 *wl,
				struct cfg80211_sched_scan_request *req,
				struct wl1271_cmd_sched_scan_config *cfg)
{
	cfg->passive[0] =
427
		wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
428
						    IEEE80211_BAND_2GHZ,
429 430
						    false, true, 0,
						    MAX_CHANNELS_2GHZ);
431
	cfg->active[0] =
432
		wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
433
						    IEEE80211_BAND_2GHZ,
434 435 436
						    false, false,
						    cfg->passive[0],
						    MAX_CHANNELS_2GHZ);
437
	cfg->passive[1] =
438
		wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
439
						    IEEE80211_BAND_5GHZ,
440 441
						    false, true, 0,
						    MAX_CHANNELS_5GHZ);
442
	cfg->dfs =
443
		wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
444
						    IEEE80211_BAND_5GHZ,
445 446 447
						    true, true,
						    cfg->passive[1],
						    MAX_CHANNELS_5GHZ);
448
	cfg->active[1] =
449
		wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
450
						    IEEE80211_BAND_5GHZ,
451 452 453 454 455 456
						    false, false,
						    cfg->passive[1] + cfg->dfs,
						    MAX_CHANNELS_5GHZ);
	/* 802.11j channels are not supported yet */
	cfg->passive[2] = 0;
	cfg->active[2] = 0;
457 458 459 460 461

	wl1271_debug(DEBUG_SCAN, "    2.4GHz: active %d passive %d",
		     cfg->active[0], cfg->passive[0]);
	wl1271_debug(DEBUG_SCAN, "    5GHz: active %d passive %d",
		     cfg->active[1], cfg->passive[1]);
462
	wl1271_debug(DEBUG_SCAN, "    DFS: %d", cfg->dfs);
463

464 465 466
	return  cfg->passive[0] || cfg->active[0] ||
		cfg->passive[1] || cfg->active[1] || cfg->dfs ||
		cfg->passive[2] || cfg->active[2];
467 468 469 470 471 472 473 474
}

int wl1271_scan_sched_scan_config(struct wl1271 *wl,
				  struct cfg80211_sched_scan_request *req,
				  struct ieee80211_sched_scan_ies *ies)
{
	struct wl1271_cmd_sched_scan_config *cfg = NULL;
	struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
475
	int i, ret;
476
	bool force_passive = !req->n_ssids;
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499

	wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");

	cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
	if (!cfg)
		return -ENOMEM;

	cfg->rssi_threshold = c->rssi_threshold;
	cfg->snr_threshold  = c->snr_threshold;
	cfg->n_probe_reqs = c->num_probe_reqs;
	/* cycles set to 0 it means infinite (until manually stopped) */
	cfg->cycles = 0;
	/* report APs when at least 1 is found */
	cfg->report_after = 1;
	/* don't stop scanning automatically when something is found */
	cfg->terminate = 0;
	cfg->tag = WL1271_SCAN_DEFAULT_TAG;
	/* don't filter on BSS type */
	cfg->bss_type = SCAN_BSS_TYPE_ANY;
	/* currently NL80211 supports only a single interval */
	for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++)
		cfg->intervals[i] = cpu_to_le32(req->interval);

500
	if (!force_passive && req->ssids[0].ssid_len && req->ssids[0].ssid) {
501 502 503 504 505 506 507 508 509
		cfg->filter_type = SCAN_SSID_FILTER_SPECIFIC;
		cfg->ssid_len = req->ssids[0].ssid_len;
		memcpy(cfg->ssid, req->ssids[0].ssid,
		       req->ssids[0].ssid_len);
	} else {
		cfg->filter_type = SCAN_SSID_FILTER_ANY;
		cfg->ssid_len = 0;
	}

510
	if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) {
511 512 513 514 515
		wl1271_error("scan channel list is empty");
		ret = -EINVAL;
		goto out;
	}

516
	if (!force_passive && cfg->active[0]) {
517 518 519 520 521 522 523 524 525 526 527
		ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid,
						 req->ssids[0].ssid_len,
						 ies->ie[IEEE80211_BAND_2GHZ],
						 ies->len[IEEE80211_BAND_2GHZ],
						 IEEE80211_BAND_2GHZ);
		if (ret < 0) {
			wl1271_error("2.4GHz PROBE request template failed");
			goto out;
		}
	}

528
	if (!force_passive && cfg->active[1]) {
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
		ret = wl1271_cmd_build_probe_req(wl,  req->ssids[0].ssid,
						 req->ssids[0].ssid_len,
						 ies->ie[IEEE80211_BAND_5GHZ],
						 ies->len[IEEE80211_BAND_5GHZ],
						 IEEE80211_BAND_5GHZ);
		if (ret < 0) {
			wl1271_error("5GHz PROBE request template failed");
			goto out;
		}
	}

	wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg));

	ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg,
			      sizeof(*cfg), 0);
	if (ret < 0) {
		wl1271_error("SCAN configuration failed");
		goto out;
	}
out:
	kfree(cfg);
	return ret;
}

int wl1271_scan_sched_scan_start(struct wl1271 *wl)
{
	struct wl1271_cmd_sched_scan_start *start;
	int ret = 0;

	wl1271_debug(DEBUG_CMD, "cmd periodic scan start");

560 561 562 563 564 565
	if (wl->bss_type != BSS_TYPE_STA_BSS)
		return -EOPNOTSUPP;

	if (!test_bit(WL1271_FLAG_IDLE, &wl->flags))
		return -EBUSY;

566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
	start = kzalloc(sizeof(*start), GFP_KERNEL);
	if (!start)
		return -ENOMEM;

	start->tag = WL1271_SCAN_DEFAULT_TAG;

	ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
			      sizeof(*start), 0);
	if (ret < 0) {
		wl1271_error("failed to send scan start command");
		goto out_free;
	}

out_free:
	kfree(start);
	return ret;
}

void wl1271_scan_sched_scan_results(struct wl1271 *wl)
{
	wl1271_debug(DEBUG_SCAN, "got periodic scan results");

	ieee80211_sched_scan_results(wl->hw);
}

void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
{
	struct wl1271_cmd_sched_scan_stop *stop;
	int ret = 0;

	wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");

	/* FIXME: what to do if alloc'ing to stop fails? */
	stop = kzalloc(sizeof(*stop), GFP_KERNEL);
	if (!stop) {
		wl1271_error("failed to alloc memory to send sched scan stop");
		return;
	}

	stop->tag = WL1271_SCAN_DEFAULT_TAG;

	ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
			      sizeof(*stop), 0);
609
	if (ret < 0) {
610
		wl1271_error("failed to send sched scan stop command");
611 612 613
		goto out_free;
	}
	wl->sched_scanning = false;
614

615
out_free:
616 617
	kfree(stop);
}