scan.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * This file is part of wl18xx
  3. *
  4. * Copyright (C) 2012 Texas Instruments. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/ieee80211.h>
  22. #include "scan.h"
  23. #include "../wlcore/debug.h"
  24. static void wl18xx_adjust_channels(struct wl18xx_cmd_scan_params *cmd,
  25. struct wlcore_scan_channels *cmd_channels)
  26. {
  27. memcpy(cmd->passive, cmd_channels->passive, sizeof(cmd->passive));
  28. memcpy(cmd->active, cmd_channels->active, sizeof(cmd->active));
  29. cmd->dfs = cmd_channels->dfs;
  30. cmd->passive_active = cmd_channels->passive_active;
  31. memcpy(cmd->channels_2, cmd_channels->channels_2,
  32. sizeof(cmd->channels_2));
  33. memcpy(cmd->channels_5, cmd_channels->channels_5,
  34. sizeof(cmd->channels_2));
  35. /* channels_4 are not supported, so no need to copy them */
  36. }
  37. static int wl18xx_scan_send(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  38. struct cfg80211_scan_request *req)
  39. {
  40. struct wl18xx_cmd_scan_params *cmd;
  41. struct wlcore_scan_channels *cmd_channels = NULL;
  42. int ret;
  43. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  44. if (!cmd) {
  45. ret = -ENOMEM;
  46. goto out;
  47. }
  48. cmd->role_id = wlvif->role_id;
  49. if (WARN_ON(cmd->role_id == WL12XX_INVALID_ROLE_ID)) {
  50. ret = -EINVAL;
  51. goto out;
  52. }
  53. cmd->scan_type = SCAN_TYPE_SEARCH;
  54. cmd->rssi_threshold = -127;
  55. cmd->snr_threshold = 0;
  56. cmd->bss_type = SCAN_BSS_TYPE_ANY;
  57. cmd->ssid_from_list = 0;
  58. cmd->filter = 0;
  59. cmd->add_broadcast = 0;
  60. cmd->urgency = 0;
  61. cmd->protect = 0;
  62. cmd->n_probe_reqs = wl->conf.scan.num_probe_reqs;
  63. cmd->terminate_after = 0;
  64. /* configure channels */
  65. WARN_ON(req->n_ssids > 1);
  66. cmd_channels = kzalloc(sizeof(*cmd_channels), GFP_KERNEL);
  67. if (!cmd_channels) {
  68. ret = -ENOMEM;
  69. goto out;
  70. }
  71. wlcore_set_scan_chan_params(wl, cmd_channels, req->channels,
  72. req->n_channels, req->n_ssids,
  73. SCAN_TYPE_SEARCH);
  74. wl18xx_adjust_channels(cmd, cmd_channels);
  75. /*
  76. * all the cycles params (except total cycles) should
  77. * remain 0 for normal scan
  78. */
  79. cmd->total_cycles = 1;
  80. if (req->no_cck)
  81. cmd->rate = WL18XX_SCAN_RATE_6;
  82. cmd->tag = WL1271_SCAN_DEFAULT_TAG;
  83. if (req->n_ssids) {
  84. cmd->ssid_len = req->ssids[0].ssid_len;
  85. memcpy(cmd->ssid, req->ssids[0].ssid, cmd->ssid_len);
  86. }
  87. /* TODO: per-band ies? */
  88. if (cmd->active[0]) {
  89. u8 band = IEEE80211_BAND_2GHZ;
  90. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  91. cmd->role_id, band,
  92. req->ssids ? req->ssids[0].ssid : NULL,
  93. req->ssids ? req->ssids[0].ssid_len : 0,
  94. req->ie,
  95. req->ie_len,
  96. false);
  97. if (ret < 0) {
  98. wl1271_error("2.4GHz PROBE request template failed");
  99. goto out;
  100. }
  101. }
  102. if (cmd->active[1] || cmd->dfs) {
  103. u8 band = IEEE80211_BAND_5GHZ;
  104. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  105. cmd->role_id, band,
  106. req->ssids ? req->ssids[0].ssid : NULL,
  107. req->ssids ? req->ssids[0].ssid_len : 0,
  108. req->ie,
  109. req->ie_len,
  110. false);
  111. if (ret < 0) {
  112. wl1271_error("5GHz PROBE request template failed");
  113. goto out;
  114. }
  115. }
  116. wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
  117. ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
  118. if (ret < 0) {
  119. wl1271_error("SCAN failed");
  120. goto out;
  121. }
  122. out:
  123. kfree(cmd_channels);
  124. kfree(cmd);
  125. return ret;
  126. }
  127. void wl18xx_scan_completed(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  128. {
  129. wl->scan.failed = false;
  130. cancel_delayed_work(&wl->scan_complete_work);
  131. ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
  132. msecs_to_jiffies(0));
  133. }
  134. static
  135. int wl18xx_scan_sched_scan_config(struct wl1271 *wl,
  136. struct wl12xx_vif *wlvif,
  137. struct cfg80211_sched_scan_request *req,
  138. struct ieee80211_sched_scan_ies *ies)
  139. {
  140. struct wl18xx_cmd_scan_params *cmd;
  141. struct wlcore_scan_channels *cmd_channels = NULL;
  142. struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
  143. int ret;
  144. int filter_type;
  145. wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
  146. filter_type = wlcore_scan_sched_scan_ssid_list(wl, wlvif, req);
  147. if (filter_type < 0)
  148. return filter_type;
  149. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  150. if (!cmd) {
  151. ret = -ENOMEM;
  152. goto out;
  153. }
  154. cmd->role_id = wlvif->role_id;
  155. if (WARN_ON(cmd->role_id == WL12XX_INVALID_ROLE_ID)) {
  156. ret = -EINVAL;
  157. goto out;
  158. }
  159. cmd->scan_type = SCAN_TYPE_PERIODIC;
  160. cmd->rssi_threshold = c->rssi_threshold;
  161. cmd->snr_threshold = c->snr_threshold;
  162. /* don't filter on BSS type */
  163. cmd->bss_type = SCAN_BSS_TYPE_ANY;
  164. cmd->ssid_from_list = 1;
  165. if (filter_type == SCAN_SSID_FILTER_LIST)
  166. cmd->filter = 1;
  167. cmd->add_broadcast = 0;
  168. cmd->urgency = 0;
  169. cmd->protect = 0;
  170. cmd->n_probe_reqs = c->num_probe_reqs;
  171. /* don't stop scanning automatically when something is found */
  172. cmd->terminate_after = 0;
  173. cmd_channels = kzalloc(sizeof(*cmd_channels), GFP_KERNEL);
  174. if (!cmd_channels) {
  175. ret = -ENOMEM;
  176. goto out;
  177. }
  178. /* configure channels */
  179. wlcore_set_scan_chan_params(wl, cmd_channels, req->channels,
  180. req->n_channels, req->n_ssids,
  181. SCAN_TYPE_PERIODIC);
  182. wl18xx_adjust_channels(cmd, cmd_channels);
  183. cmd->short_cycles_sec = 0;
  184. cmd->long_cycles_sec = cpu_to_le16(req->interval);
  185. cmd->short_cycles_count = 0;
  186. cmd->total_cycles = 0;
  187. cmd->tag = WL1271_SCAN_DEFAULT_TAG;
  188. /* create a PERIODIC_SCAN_REPORT_EVENT whenever we've got a match */
  189. cmd->report_threshold = 1;
  190. cmd->terminate_on_report = 0;
  191. if (cmd->active[0]) {
  192. u8 band = IEEE80211_BAND_2GHZ;
  193. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  194. cmd->role_id, band,
  195. req->ssids ? req->ssids[0].ssid : NULL,
  196. req->ssids ? req->ssids[0].ssid_len : 0,
  197. ies->ie[band],
  198. ies->len[band],
  199. true);
  200. if (ret < 0) {
  201. wl1271_error("2.4GHz PROBE request template failed");
  202. goto out;
  203. }
  204. }
  205. if (cmd->active[1] || cmd->dfs) {
  206. u8 band = IEEE80211_BAND_5GHZ;
  207. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  208. cmd->role_id, band,
  209. req->ssids ? req->ssids[0].ssid : NULL,
  210. req->ssids ? req->ssids[0].ssid_len : 0,
  211. ies->ie[band],
  212. ies->len[band],
  213. true);
  214. if (ret < 0) {
  215. wl1271_error("5GHz PROBE request template failed");
  216. goto out;
  217. }
  218. }
  219. wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
  220. ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
  221. if (ret < 0) {
  222. wl1271_error("SCAN failed");
  223. goto out;
  224. }
  225. out:
  226. kfree(cmd_channels);
  227. kfree(cmd);
  228. return ret;
  229. }
  230. int wl18xx_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  231. struct cfg80211_sched_scan_request *req,
  232. struct ieee80211_sched_scan_ies *ies)
  233. {
  234. return wl18xx_scan_sched_scan_config(wl, wlvif, req, ies);
  235. }
  236. static int __wl18xx_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  237. u8 scan_type)
  238. {
  239. struct wl18xx_cmd_scan_stop *stop;
  240. int ret;
  241. wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
  242. stop = kzalloc(sizeof(*stop), GFP_KERNEL);
  243. if (!stop) {
  244. wl1271_error("failed to alloc memory to send sched scan stop");
  245. return -ENOMEM;
  246. }
  247. stop->role_id = wlvif->role_id;
  248. stop->scan_type = scan_type;
  249. ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, stop, sizeof(*stop), 0);
  250. if (ret < 0) {
  251. wl1271_error("failed to send sched scan stop command");
  252. goto out_free;
  253. }
  254. out_free:
  255. kfree(stop);
  256. return ret;
  257. }
  258. void wl18xx_scan_sched_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  259. {
  260. __wl18xx_scan_stop(wl, wlvif, SCAN_TYPE_PERIODIC);
  261. }
  262. int wl18xx_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  263. struct cfg80211_scan_request *req)
  264. {
  265. return wl18xx_scan_send(wl, wlvif, req);
  266. }
  267. int wl18xx_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  268. {
  269. return __wl18xx_scan_stop(wl, wlvif, SCAN_TYPE_SEARCH);
  270. }