scan.c 18 KB

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