scan.c 20 KB

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