scan.c 19 KB

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