scan.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. wl18xx_adjust_channels(cmd, cmd_channels);
  74. /*
  75. * all the cycles params (except total cycles) should
  76. * remain 0 for normal scan
  77. */
  78. cmd->total_cycles = 1;
  79. if (req->no_cck)
  80. cmd->rate = WL18XX_SCAN_RATE_6;
  81. cmd->tag = WL1271_SCAN_DEFAULT_TAG;
  82. if (req->n_ssids) {
  83. cmd->ssid_len = req->ssids[0].ssid_len;
  84. memcpy(cmd->ssid, req->ssids[0].ssid, cmd->ssid_len);
  85. }
  86. /* TODO: per-band ies? */
  87. if (cmd->active[0]) {
  88. u8 band = IEEE80211_BAND_2GHZ;
  89. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  90. cmd->role_id, band,
  91. req->ssids[0].ssid,
  92. req->ssids[0].ssid_len,
  93. req->ie,
  94. req->ie_len,
  95. false);
  96. if (ret < 0) {
  97. wl1271_error("2.4GHz PROBE request template failed");
  98. goto out;
  99. }
  100. }
  101. if (cmd->active[1]) {
  102. u8 band = IEEE80211_BAND_5GHZ;
  103. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  104. cmd->role_id, band,
  105. req->ssids[0].ssid,
  106. req->ssids[0].ssid_len,
  107. req->ie,
  108. req->ie_len,
  109. false);
  110. if (ret < 0) {
  111. wl1271_error("5GHz PROBE request template failed");
  112. goto out;
  113. }
  114. }
  115. wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
  116. ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
  117. if (ret < 0) {
  118. wl1271_error("SCAN failed");
  119. goto out;
  120. }
  121. out:
  122. kfree(cmd_channels);
  123. kfree(cmd);
  124. return ret;
  125. }
  126. void wl18xx_scan_completed(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  127. {
  128. wl->scan.failed = false;
  129. cancel_delayed_work(&wl->scan_complete_work);
  130. ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
  131. msecs_to_jiffies(0));
  132. }
  133. static
  134. int wl18xx_scan_sched_scan_config(struct wl1271 *wl,
  135. struct wl12xx_vif *wlvif,
  136. struct cfg80211_sched_scan_request *req,
  137. struct ieee80211_sched_scan_ies *ies)
  138. {
  139. struct wl18xx_cmd_scan_params *cmd;
  140. struct wlcore_scan_channels *cmd_channels = NULL;
  141. struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
  142. int ret;
  143. int filter_type;
  144. wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
  145. filter_type = wlcore_scan_sched_scan_ssid_list(wl, wlvif, req);
  146. if (filter_type < 0)
  147. return filter_type;
  148. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  149. if (!cmd) {
  150. ret = -ENOMEM;
  151. goto out;
  152. }
  153. cmd->role_id = wlvif->role_id;
  154. if (WARN_ON(cmd->role_id == WL12XX_INVALID_ROLE_ID)) {
  155. ret = -EINVAL;
  156. goto out;
  157. }
  158. cmd->scan_type = SCAN_TYPE_PERIODIC;
  159. cmd->rssi_threshold = c->rssi_threshold;
  160. cmd->snr_threshold = c->snr_threshold;
  161. /* don't filter on BSS type */
  162. cmd->bss_type = SCAN_BSS_TYPE_ANY;
  163. cmd->ssid_from_list = 1;
  164. if (filter_type == SCAN_SSID_FILTER_LIST)
  165. cmd->filter = 1;
  166. cmd->add_broadcast = 0;
  167. cmd->urgency = 0;
  168. cmd->protect = 0;
  169. cmd->n_probe_reqs = c->num_probe_reqs;
  170. /* don't stop scanning automatically when something is found */
  171. cmd->terminate_after = 0;
  172. cmd_channels = kzalloc(sizeof(*cmd_channels), GFP_KERNEL);
  173. if (!cmd_channels) {
  174. ret = -ENOMEM;
  175. goto out;
  176. }
  177. /* configure channels */
  178. wlcore_set_scan_chan_params(wl, cmd_channels, req->channels,
  179. req->n_channels, req->n_ssids);
  180. wl18xx_adjust_channels(cmd, cmd_channels);
  181. cmd->short_cycles_sec = 0;
  182. cmd->long_cycles_sec = cpu_to_le16(req->interval);
  183. cmd->short_cycles_count = 0;
  184. cmd->total_cycles = 0;
  185. cmd->tag = WL1271_SCAN_DEFAULT_TAG;
  186. if (cmd->active[0]) {
  187. u8 band = IEEE80211_BAND_2GHZ;
  188. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  189. cmd->role_id, band,
  190. req->ssids[0].ssid,
  191. req->ssids[0].ssid_len,
  192. ies->ie[band],
  193. ies->len[band],
  194. true);
  195. if (ret < 0) {
  196. wl1271_error("2.4GHz PROBE request template failed");
  197. goto out;
  198. }
  199. }
  200. if (cmd->active[1]) {
  201. u8 band = IEEE80211_BAND_5GHZ;
  202. ret = wl12xx_cmd_build_probe_req(wl, wlvif,
  203. cmd->role_id, band,
  204. req->ssids[0].ssid,
  205. req->ssids[0].ssid_len,
  206. ies->ie[band],
  207. ies->len[band],
  208. true);
  209. if (ret < 0) {
  210. wl1271_error("5GHz PROBE request template failed");
  211. goto out;
  212. }
  213. }
  214. wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
  215. ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
  216. if (ret < 0) {
  217. wl1271_error("SCAN failed");
  218. goto out;
  219. }
  220. out:
  221. kfree(cmd_channels);
  222. kfree(cmd);
  223. return ret;
  224. }
  225. int wl18xx_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  226. struct cfg80211_sched_scan_request *req,
  227. struct ieee80211_sched_scan_ies *ies)
  228. {
  229. return wl18xx_scan_sched_scan_config(wl, wlvif, req, ies);
  230. }
  231. static int __wl18xx_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  232. u8 scan_type)
  233. {
  234. struct wl18xx_cmd_scan_stop *stop;
  235. int ret;
  236. wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
  237. stop = kzalloc(sizeof(*stop), GFP_KERNEL);
  238. if (!stop) {
  239. wl1271_error("failed to alloc memory to send sched scan stop");
  240. return -ENOMEM;
  241. }
  242. stop->role_id = wlvif->role_id;
  243. stop->scan_type = scan_type;
  244. ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, stop, sizeof(*stop), 0);
  245. if (ret < 0) {
  246. wl1271_error("failed to send sched scan stop command");
  247. goto out_free;
  248. }
  249. out_free:
  250. kfree(stop);
  251. return ret;
  252. }
  253. void wl18xx_scan_sched_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  254. {
  255. __wl18xx_scan_stop(wl, wlvif, SCAN_TYPE_PERIODIC);
  256. }
  257. int wl18xx_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  258. struct cfg80211_scan_request *req)
  259. {
  260. return wl18xx_scan_send(wl, wlvif, req);
  261. }
  262. int wl18xx_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  263. {
  264. return __wl18xx_scan_stop(wl, wlvif, SCAN_TYPE_SEARCH);
  265. }