scan.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009-2010 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/ieee80211.h>
  24. #include "wl12xx.h"
  25. #include "cmd.h"
  26. #include "scan.h"
  27. #include "acx.h"
  28. #include "ps.h"
  29. void wl1271_scan_complete_work(struct work_struct *work)
  30. {
  31. struct delayed_work *dwork;
  32. struct wl1271 *wl;
  33. int ret;
  34. bool is_sta, is_ibss;
  35. dwork = container_of(work, struct delayed_work, work);
  36. wl = container_of(dwork, struct wl1271, scan_complete_work);
  37. wl1271_debug(DEBUG_SCAN, "Scanning complete");
  38. mutex_lock(&wl->mutex);
  39. if (wl->state == WL1271_STATE_OFF)
  40. goto out;
  41. if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
  42. goto out;
  43. wl->scan.state = WL1271_SCAN_STATE_IDLE;
  44. memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
  45. wl->scan.req = NULL;
  46. ret = wl1271_ps_elp_wakeup(wl);
  47. if (ret < 0)
  48. goto out;
  49. if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
  50. /* restore hardware connection monitoring template */
  51. wl1271_cmd_build_ap_probe_req(wl, wl->probereq);
  52. }
  53. /* return to ROC if needed */
  54. is_sta = (wl->bss_type == BSS_TYPE_STA_BSS);
  55. is_ibss = (wl->bss_type == BSS_TYPE_IBSS);
  56. if (((is_sta && !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) ||
  57. (is_ibss && !test_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags))) &&
  58. !test_bit(wl->dev_role_id, wl->roc_map)) {
  59. /* restore remain on channel */
  60. wl12xx_cmd_role_start_dev(wl);
  61. wl12xx_roc(wl, wl->dev_role_id);
  62. }
  63. wl1271_ps_elp_sleep(wl);
  64. if (wl->scan.failed) {
  65. wl1271_info("Scan completed due to error.");
  66. wl12xx_queue_recovery_work(wl);
  67. }
  68. ieee80211_scan_completed(wl->hw, false);
  69. out:
  70. mutex_unlock(&wl->mutex);
  71. }
  72. static int wl1271_get_scan_channels(struct wl1271 *wl,
  73. struct cfg80211_scan_request *req,
  74. struct basic_scan_channel_params *channels,
  75. enum ieee80211_band band, bool passive)
  76. {
  77. struct conf_scan_settings *c = &wl->conf.scan;
  78. int i, j;
  79. u32 flags;
  80. for (i = 0, j = 0;
  81. i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
  82. i++) {
  83. flags = req->channels[i]->flags;
  84. if (!test_bit(i, wl->scan.scanned_ch) &&
  85. !(flags & IEEE80211_CHAN_DISABLED) &&
  86. (req->channels[i]->band == band) &&
  87. /*
  88. * In passive scans, we scan all remaining
  89. * channels, even if not marked as such.
  90. * In active scans, we only scan channels not
  91. * marked as passive.
  92. */
  93. (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) {
  94. wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
  95. req->channels[i]->band,
  96. req->channels[i]->center_freq);
  97. wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
  98. req->channels[i]->hw_value,
  99. req->channels[i]->flags);
  100. wl1271_debug(DEBUG_SCAN,
  101. "max_antenna_gain %d, max_power %d",
  102. req->channels[i]->max_antenna_gain,
  103. req->channels[i]->max_power);
  104. wl1271_debug(DEBUG_SCAN, "beacon_found %d",
  105. req->channels[i]->beacon_found);
  106. if (!passive) {
  107. channels[j].min_duration =
  108. cpu_to_le32(c->min_dwell_time_active);
  109. channels[j].max_duration =
  110. cpu_to_le32(c->max_dwell_time_active);
  111. } else {
  112. channels[j].min_duration =
  113. cpu_to_le32(c->min_dwell_time_passive);
  114. channels[j].max_duration =
  115. cpu_to_le32(c->max_dwell_time_passive);
  116. }
  117. channels[j].early_termination = 0;
  118. channels[j].tx_power_att = req->channels[i]->max_power;
  119. channels[j].channel = req->channels[i]->hw_value;
  120. memset(&channels[j].bssid_lsb, 0xff, 4);
  121. memset(&channels[j].bssid_msb, 0xff, 2);
  122. /* Mark the channels we already used */
  123. set_bit(i, wl->scan.scanned_ch);
  124. j++;
  125. }
  126. }
  127. return j;
  128. }
  129. #define WL1271_NOTHING_TO_SCAN 1
  130. static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
  131. bool passive, u32 basic_rate)
  132. {
  133. struct wl1271_cmd_scan *cmd;
  134. struct wl1271_cmd_trigger_scan_to *trigger;
  135. int ret;
  136. u16 scan_options = 0;
  137. /* skip active scans if we don't have SSIDs */
  138. if (!passive && wl->scan.req->n_ssids == 0)
  139. return WL1271_NOTHING_TO_SCAN;
  140. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  141. trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
  142. if (!cmd || !trigger) {
  143. ret = -ENOMEM;
  144. goto out;
  145. }
  146. if (passive)
  147. scan_options |= WL1271_SCAN_OPT_PASSIVE;
  148. if (WARN_ON(wl->role_id == WL12XX_INVALID_ROLE_ID)) {
  149. ret = -EINVAL;
  150. goto out;
  151. }
  152. cmd->params.role_id = wl->role_id;
  153. cmd->params.scan_options = cpu_to_le16(scan_options);
  154. cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
  155. cmd->channels,
  156. band, passive);
  157. if (cmd->params.n_ch == 0) {
  158. ret = WL1271_NOTHING_TO_SCAN;
  159. goto out;
  160. }
  161. cmd->params.tx_rate = cpu_to_le32(basic_rate);
  162. cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
  163. cmd->params.tx_rate = cpu_to_le32(basic_rate);
  164. cmd->params.tid_trigger = 0;
  165. cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
  166. if (band == IEEE80211_BAND_2GHZ)
  167. cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
  168. else
  169. cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
  170. if (wl->scan.ssid_len && wl->scan.ssid) {
  171. cmd->params.ssid_len = wl->scan.ssid_len;
  172. memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
  173. }
  174. memcpy(cmd->addr, wl->mac_addr, ETH_ALEN);
  175. ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len,
  176. wl->scan.req->ie, wl->scan.req->ie_len,
  177. band);
  178. if (ret < 0) {
  179. wl1271_error("PROBE request template failed");
  180. goto out;
  181. }
  182. /* disable the timeout */
  183. trigger->timeout = 0;
  184. ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
  185. sizeof(*trigger), 0);
  186. if (ret < 0) {
  187. wl1271_error("trigger scan to failed for hw scan");
  188. goto out;
  189. }
  190. wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
  191. ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
  192. if (ret < 0) {
  193. wl1271_error("SCAN failed");
  194. goto out;
  195. }
  196. out:
  197. kfree(cmd);
  198. kfree(trigger);
  199. return ret;
  200. }
  201. void wl1271_scan_stm(struct wl1271 *wl)
  202. {
  203. int ret = 0;
  204. switch (wl->scan.state) {
  205. case WL1271_SCAN_STATE_IDLE:
  206. break;
  207. case WL1271_SCAN_STATE_2GHZ_ACTIVE:
  208. ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false,
  209. wl->conf.tx.basic_rate);
  210. if (ret == WL1271_NOTHING_TO_SCAN) {
  211. wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
  212. wl1271_scan_stm(wl);
  213. }
  214. break;
  215. case WL1271_SCAN_STATE_2GHZ_PASSIVE:
  216. ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true,
  217. wl->conf.tx.basic_rate);
  218. if (ret == WL1271_NOTHING_TO_SCAN) {
  219. if (wl->enable_11a)
  220. wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
  221. else
  222. wl->scan.state = WL1271_SCAN_STATE_DONE;
  223. wl1271_scan_stm(wl);
  224. }
  225. break;
  226. case WL1271_SCAN_STATE_5GHZ_ACTIVE:
  227. ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false,
  228. wl->conf.tx.basic_rate_5);
  229. if (ret == WL1271_NOTHING_TO_SCAN) {
  230. wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
  231. wl1271_scan_stm(wl);
  232. }
  233. break;
  234. case WL1271_SCAN_STATE_5GHZ_PASSIVE:
  235. ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true,
  236. wl->conf.tx.basic_rate_5);
  237. if (ret == WL1271_NOTHING_TO_SCAN) {
  238. wl->scan.state = WL1271_SCAN_STATE_DONE;
  239. wl1271_scan_stm(wl);
  240. }
  241. break;
  242. case WL1271_SCAN_STATE_DONE:
  243. wl->scan.failed = false;
  244. cancel_delayed_work(&wl->scan_complete_work);
  245. ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
  246. msecs_to_jiffies(0));
  247. break;
  248. default:
  249. wl1271_error("invalid scan state");
  250. break;
  251. }
  252. if (ret < 0) {
  253. cancel_delayed_work(&wl->scan_complete_work);
  254. ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
  255. msecs_to_jiffies(0));
  256. }
  257. }
  258. int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
  259. struct cfg80211_scan_request *req)
  260. {
  261. /*
  262. * cfg80211 should guarantee that we don't get more channels
  263. * than what we have registered.
  264. */
  265. BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);
  266. if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
  267. return -EBUSY;
  268. wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
  269. if (ssid_len && ssid) {
  270. wl->scan.ssid_len = ssid_len;
  271. memcpy(wl->scan.ssid, ssid, ssid_len);
  272. } else {
  273. wl->scan.ssid_len = 0;
  274. }
  275. wl->scan.req = req;
  276. memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
  277. /* we assume failure so that timeout scenarios are handled correctly */
  278. wl->scan.failed = true;
  279. ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
  280. msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
  281. wl1271_scan_stm(wl);
  282. return 0;
  283. }
  284. int wl1271_scan_stop(struct wl1271 *wl)
  285. {
  286. struct wl1271_cmd_header *cmd = NULL;
  287. int ret = 0;
  288. if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE))
  289. return -EINVAL;
  290. wl1271_debug(DEBUG_CMD, "cmd scan stop");
  291. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  292. if (!cmd) {
  293. ret = -ENOMEM;
  294. goto out;
  295. }
  296. ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd,
  297. sizeof(*cmd), 0);
  298. if (ret < 0) {
  299. wl1271_error("cmd stop_scan failed");
  300. goto out;
  301. }
  302. out:
  303. kfree(cmd);
  304. return ret;
  305. }
  306. static int
  307. wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
  308. struct cfg80211_sched_scan_request *req,
  309. struct conn_scan_ch_params *channels,
  310. u32 band, bool radar, bool passive,
  311. int start, int max_channels)
  312. {
  313. struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
  314. int i, j;
  315. u32 flags;
  316. bool force_passive = !req->n_ssids;
  317. for (i = 0, j = start;
  318. i < req->n_channels && j < max_channels;
  319. i++) {
  320. flags = req->channels[i]->flags;
  321. if (force_passive)
  322. flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  323. if ((req->channels[i]->band == band) &&
  324. !(flags & IEEE80211_CHAN_DISABLED) &&
  325. (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
  326. /* if radar is set, we ignore the passive flag */
  327. (radar ||
  328. !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
  329. wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
  330. req->channels[i]->band,
  331. req->channels[i]->center_freq);
  332. wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
  333. req->channels[i]->hw_value,
  334. req->channels[i]->flags);
  335. wl1271_debug(DEBUG_SCAN, "max_power %d",
  336. req->channels[i]->max_power);
  337. if (flags & IEEE80211_CHAN_RADAR) {
  338. channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
  339. channels[j].passive_duration =
  340. cpu_to_le16(c->dwell_time_dfs);
  341. }
  342. else if (flags & IEEE80211_CHAN_PASSIVE_SCAN) {
  343. channels[j].passive_duration =
  344. cpu_to_le16(c->dwell_time_passive);
  345. } else {
  346. channels[j].min_duration =
  347. cpu_to_le16(c->min_dwell_time_active);
  348. channels[j].max_duration =
  349. cpu_to_le16(c->max_dwell_time_active);
  350. }
  351. channels[j].tx_power_att = req->channels[i]->max_power;
  352. channels[j].channel = req->channels[i]->hw_value;
  353. j++;
  354. }
  355. }
  356. return j - start;
  357. }
  358. static bool
  359. wl1271_scan_sched_scan_channels(struct wl1271 *wl,
  360. struct cfg80211_sched_scan_request *req,
  361. struct wl1271_cmd_sched_scan_config *cfg)
  362. {
  363. cfg->passive[0] =
  364. wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
  365. IEEE80211_BAND_2GHZ,
  366. false, true, 0,
  367. MAX_CHANNELS_2GHZ);
  368. cfg->active[0] =
  369. wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
  370. IEEE80211_BAND_2GHZ,
  371. false, false,
  372. cfg->passive[0],
  373. MAX_CHANNELS_2GHZ);
  374. cfg->passive[1] =
  375. wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
  376. IEEE80211_BAND_5GHZ,
  377. false, true, 0,
  378. MAX_CHANNELS_5GHZ);
  379. cfg->dfs =
  380. wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
  381. IEEE80211_BAND_5GHZ,
  382. true, true,
  383. cfg->passive[1],
  384. MAX_CHANNELS_5GHZ);
  385. cfg->active[1] =
  386. wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
  387. IEEE80211_BAND_5GHZ,
  388. false, false,
  389. cfg->passive[1] + cfg->dfs,
  390. MAX_CHANNELS_5GHZ);
  391. /* 802.11j channels are not supported yet */
  392. cfg->passive[2] = 0;
  393. cfg->active[2] = 0;
  394. wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d",
  395. cfg->active[0], cfg->passive[0]);
  396. wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d",
  397. cfg->active[1], cfg->passive[1]);
  398. wl1271_debug(DEBUG_SCAN, " DFS: %d", cfg->dfs);
  399. return cfg->passive[0] || cfg->active[0] ||
  400. cfg->passive[1] || cfg->active[1] || cfg->dfs ||
  401. cfg->passive[2] || cfg->active[2];
  402. }
  403. /* Returns the scan type to be used or a negative value on error */
  404. static int
  405. wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
  406. struct cfg80211_sched_scan_request *req)
  407. {
  408. struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL;
  409. struct cfg80211_match_set *sets = req->match_sets;
  410. struct cfg80211_ssid *ssids = req->ssids;
  411. int ret = 0, type, i, j, n_match_ssids = 0;
  412. wl1271_debug(DEBUG_CMD, "cmd sched scan ssid list");
  413. /* count the match sets that contain SSIDs */
  414. for (i = 0; i < req->n_match_sets; i++)
  415. if (sets[i].ssid.ssid_len > 0)
  416. n_match_ssids++;
  417. /* No filter, no ssids or only bcast ssid */
  418. if (!n_match_ssids &&
  419. (!req->n_ssids ||
  420. (req->n_ssids == 1 && req->ssids[0].ssid_len == 0))) {
  421. type = SCAN_SSID_FILTER_ANY;
  422. goto out;
  423. }
  424. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  425. if (!cmd) {
  426. ret = -ENOMEM;
  427. goto out;
  428. }
  429. if (!n_match_ssids) {
  430. /* No filter, with ssids */
  431. type = SCAN_SSID_FILTER_DISABLED;
  432. for (i = 0; i < req->n_ssids; i++) {
  433. cmd->ssids[cmd->n_ssids].type = (ssids[i].ssid_len) ?
  434. SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC;
  435. cmd->ssids[cmd->n_ssids].len = ssids[i].ssid_len;
  436. memcpy(cmd->ssids[cmd->n_ssids].ssid, ssids[i].ssid,
  437. ssids[i].ssid_len);
  438. cmd->n_ssids++;
  439. }
  440. } else {
  441. type = SCAN_SSID_FILTER_LIST;
  442. /* Add all SSIDs from the filters */
  443. for (i = 0; i < req->n_match_sets; i++) {
  444. /* ignore sets without SSIDs */
  445. if (!sets[i].ssid.ssid_len)
  446. continue;
  447. cmd->ssids[cmd->n_ssids].type = SCAN_SSID_TYPE_PUBLIC;
  448. cmd->ssids[cmd->n_ssids].len = sets[i].ssid.ssid_len;
  449. memcpy(cmd->ssids[cmd->n_ssids].ssid,
  450. sets[i].ssid.ssid, sets[i].ssid.ssid_len);
  451. cmd->n_ssids++;
  452. }
  453. if ((req->n_ssids > 1) ||
  454. (req->n_ssids == 1 && req->ssids[0].ssid_len > 0)) {
  455. /*
  456. * Mark all the SSIDs passed in the SSID list as HIDDEN,
  457. * so they're used in probe requests.
  458. */
  459. for (i = 0; i < req->n_ssids; i++) {
  460. for (j = 0; j < cmd->n_ssids; j++)
  461. if (!memcmp(req->ssids[i].ssid,
  462. cmd->ssids[j].ssid,
  463. req->ssids[i].ssid_len)) {
  464. cmd->ssids[j].type =
  465. SCAN_SSID_TYPE_HIDDEN;
  466. break;
  467. }
  468. /* Fail if SSID isn't present in the filters */
  469. if (j == req->n_ssids) {
  470. ret = -EINVAL;
  471. goto out_free;
  472. }
  473. }
  474. }
  475. }
  476. wl1271_dump(DEBUG_SCAN, "SSID_LIST: ", cmd, sizeof(*cmd));
  477. ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd,
  478. sizeof(*cmd), 0);
  479. if (ret < 0) {
  480. wl1271_error("cmd sched scan ssid list failed");
  481. goto out_free;
  482. }
  483. out_free:
  484. kfree(cmd);
  485. out:
  486. if (ret < 0)
  487. return ret;
  488. return type;
  489. }
  490. int wl1271_scan_sched_scan_config(struct wl1271 *wl,
  491. struct cfg80211_sched_scan_request *req,
  492. struct ieee80211_sched_scan_ies *ies)
  493. {
  494. struct wl1271_cmd_sched_scan_config *cfg = NULL;
  495. struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
  496. int i, ret;
  497. bool force_passive = !req->n_ssids;
  498. wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
  499. cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
  500. if (!cfg)
  501. return -ENOMEM;
  502. cfg->rssi_threshold = c->rssi_threshold;
  503. cfg->snr_threshold = c->snr_threshold;
  504. cfg->n_probe_reqs = c->num_probe_reqs;
  505. /* cycles set to 0 it means infinite (until manually stopped) */
  506. cfg->cycles = 0;
  507. /* report APs when at least 1 is found */
  508. cfg->report_after = 1;
  509. /* don't stop scanning automatically when something is found */
  510. cfg->terminate = 0;
  511. cfg->tag = WL1271_SCAN_DEFAULT_TAG;
  512. /* don't filter on BSS type */
  513. cfg->bss_type = SCAN_BSS_TYPE_ANY;
  514. /* currently NL80211 supports only a single interval */
  515. for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++)
  516. cfg->intervals[i] = cpu_to_le32(req->interval);
  517. cfg->ssid_len = 0;
  518. ret = wl12xx_scan_sched_scan_ssid_list(wl, req);
  519. if (ret < 0)
  520. goto out;
  521. cfg->filter_type = ret;
  522. wl1271_debug(DEBUG_SCAN, "filter_type = %d", cfg->filter_type);
  523. if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) {
  524. wl1271_error("scan channel list is empty");
  525. ret = -EINVAL;
  526. goto out;
  527. }
  528. if (!force_passive && cfg->active[0]) {
  529. ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid,
  530. req->ssids[0].ssid_len,
  531. ies->ie[IEEE80211_BAND_2GHZ],
  532. ies->len[IEEE80211_BAND_2GHZ],
  533. IEEE80211_BAND_2GHZ);
  534. if (ret < 0) {
  535. wl1271_error("2.4GHz PROBE request template failed");
  536. goto out;
  537. }
  538. }
  539. if (!force_passive && cfg->active[1]) {
  540. ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid,
  541. req->ssids[0].ssid_len,
  542. ies->ie[IEEE80211_BAND_5GHZ],
  543. ies->len[IEEE80211_BAND_5GHZ],
  544. IEEE80211_BAND_5GHZ);
  545. if (ret < 0) {
  546. wl1271_error("5GHz PROBE request template failed");
  547. goto out;
  548. }
  549. }
  550. wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg));
  551. ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg,
  552. sizeof(*cfg), 0);
  553. if (ret < 0) {
  554. wl1271_error("SCAN configuration failed");
  555. goto out;
  556. }
  557. out:
  558. kfree(cfg);
  559. return ret;
  560. }
  561. int wl1271_scan_sched_scan_start(struct wl1271 *wl)
  562. {
  563. struct wl1271_cmd_sched_scan_start *start;
  564. int ret = 0;
  565. wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
  566. if (wl->bss_type != BSS_TYPE_STA_BSS)
  567. return -EOPNOTSUPP;
  568. if (!test_bit(WL1271_FLAG_IDLE, &wl->flags))
  569. return -EBUSY;
  570. start = kzalloc(sizeof(*start), GFP_KERNEL);
  571. if (!start)
  572. return -ENOMEM;
  573. start->tag = WL1271_SCAN_DEFAULT_TAG;
  574. ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
  575. sizeof(*start), 0);
  576. if (ret < 0) {
  577. wl1271_error("failed to send scan start command");
  578. goto out_free;
  579. }
  580. out_free:
  581. kfree(start);
  582. return ret;
  583. }
  584. void wl1271_scan_sched_scan_results(struct wl1271 *wl)
  585. {
  586. wl1271_debug(DEBUG_SCAN, "got periodic scan results");
  587. ieee80211_sched_scan_results(wl->hw);
  588. }
  589. void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
  590. {
  591. struct wl1271_cmd_sched_scan_stop *stop;
  592. int ret = 0;
  593. wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
  594. /* FIXME: what to do if alloc'ing to stop fails? */
  595. stop = kzalloc(sizeof(*stop), GFP_KERNEL);
  596. if (!stop) {
  597. wl1271_error("failed to alloc memory to send sched scan stop");
  598. return;
  599. }
  600. stop->tag = WL1271_SCAN_DEFAULT_TAG;
  601. ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
  602. sizeof(*stop), 0);
  603. if (ret < 0) {
  604. wl1271_error("failed to send sched scan stop command");
  605. goto out_free;
  606. }
  607. wl->sched_scanning = false;
  608. out_free:
  609. kfree(stop);
  610. }