scan.c 20 KB

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