autoscan.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * WPA Supplicant - auto scan
  3. * Copyright (c) 2012, Intel Corporation. All rights reserved.
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "config.h"
  11. #include "wpa_supplicant_i.h"
  12. #include "bss.h"
  13. #include "scan.h"
  14. #include "autoscan.h"
  15. static const struct autoscan_ops * autoscan_modules[] = {
  16. NULL
  17. };
  18. static void request_scan(struct wpa_supplicant *wpa_s)
  19. {
  20. wpa_s->scan_req = 2;
  21. if (wpa_supplicant_req_sched_scan(wpa_s))
  22. wpa_supplicant_req_scan(wpa_s, wpa_s->scan_interval, 0);
  23. }
  24. int autoscan_init(struct wpa_supplicant *wpa_s)
  25. {
  26. const char *name = wpa_s->conf->autoscan;
  27. const char *params;
  28. size_t nlen;
  29. int i;
  30. const struct autoscan_ops *ops = NULL;
  31. if (wpa_s->autoscan && wpa_s->autoscan_priv)
  32. return 0;
  33. if (name == NULL)
  34. return 0;
  35. params = os_strchr(name, ':');
  36. if (params == NULL) {
  37. params = "";
  38. nlen = os_strlen(name);
  39. } else {
  40. nlen = params - name;
  41. params++;
  42. }
  43. for (i = 0; autoscan_modules[i]; i++) {
  44. if (os_strncmp(name, autoscan_modules[i]->name, nlen) == 0) {
  45. ops = autoscan_modules[i];
  46. break;
  47. }
  48. }
  49. if (ops == NULL) {
  50. wpa_printf(MSG_ERROR, "autoscan: Could not find module "
  51. "matching the parameter '%s'", name);
  52. return -1;
  53. }
  54. wpa_s->autoscan_params = NULL;
  55. wpa_s->autoscan_priv = ops->init(wpa_s, params);
  56. if (wpa_s->autoscan_priv == NULL)
  57. return -1;
  58. wpa_s->autoscan = ops;
  59. wpa_printf(MSG_DEBUG, "autoscan: Initialized module '%s' with "
  60. "parameters '%s'", ops->name, params);
  61. /*
  62. * Cancelling existing scan requests, if any.
  63. */
  64. wpa_supplicant_cancel_sched_scan(wpa_s);
  65. wpa_supplicant_cancel_scan(wpa_s);
  66. /*
  67. * Firing first scan, which will lead to call autoscan_notify_scan.
  68. */
  69. request_scan(wpa_s);
  70. return 0;
  71. }
  72. void autoscan_deinit(struct wpa_supplicant *wpa_s)
  73. {
  74. if (wpa_s->autoscan && wpa_s->autoscan_priv) {
  75. wpa_printf(MSG_DEBUG, "autoscan: Deinitializing module '%s'",
  76. wpa_s->autoscan->name);
  77. wpa_s->autoscan->deinit(wpa_s->autoscan_priv);
  78. wpa_s->autoscan = NULL;
  79. wpa_s->autoscan_priv = NULL;
  80. wpa_s->scan_interval = 5;
  81. wpa_s->sched_scan_interval = 0;
  82. }
  83. }
  84. int autoscan_notify_scan(struct wpa_supplicant *wpa_s,
  85. struct wpa_scan_results *scan_res)
  86. {
  87. int interval;
  88. if (wpa_s->autoscan && wpa_s->autoscan_priv) {
  89. interval = wpa_s->autoscan->notify_scan(wpa_s->autoscan_priv,
  90. scan_res);
  91. if (interval <= 0)
  92. return -1;
  93. wpa_s->scan_interval = interval;
  94. wpa_s->sched_scan_interval = interval;
  95. request_scan(wpa_s);
  96. }
  97. return 0;
  98. }