scan.c 19 KB

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