bgscan.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * WPA Supplicant - background scan and roaming interface
  3. * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
  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 "wpa_supplicant_i.h"
  11. #include "config_ssid.h"
  12. #include "bgscan.h"
  13. static const struct bgscan_ops * bgscan_modules[] = {
  14. #ifdef CONFIG_BGSCAN_SIMPLE
  15. &bgscan_simple_ops,
  16. #endif /* CONFIG_BGSCAN_SIMPLE */
  17. #ifdef CONFIG_BGSCAN_LEARN
  18. &bgscan_learn_ops,
  19. #endif /* CONFIG_BGSCAN_LEARN */
  20. NULL
  21. };
  22. int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  23. const char *name)
  24. {
  25. const char *params;
  26. size_t nlen;
  27. int i;
  28. const struct bgscan_ops *ops = NULL;
  29. bgscan_deinit(wpa_s);
  30. params = os_strchr(name, ':');
  31. if (params == NULL) {
  32. params = "";
  33. nlen = os_strlen(name);
  34. } else {
  35. nlen = params - name;
  36. params++;
  37. }
  38. for (i = 0; bgscan_modules[i]; i++) {
  39. if (os_strncmp(name, bgscan_modules[i]->name, nlen) == 0) {
  40. ops = bgscan_modules[i];
  41. break;
  42. }
  43. }
  44. if (ops == NULL) {
  45. wpa_printf(MSG_ERROR, "bgscan: Could not find module "
  46. "matching the parameter '%s'", name);
  47. return -1;
  48. }
  49. wpa_s->bgscan_priv = ops->init(wpa_s, params, ssid);
  50. if (wpa_s->bgscan_priv == NULL)
  51. return -1;
  52. wpa_s->bgscan = ops;
  53. wpa_printf(MSG_DEBUG, "bgscan: Initialized module '%s' with "
  54. "parameters '%s'", ops->name, params);
  55. return 0;
  56. }
  57. void bgscan_deinit(struct wpa_supplicant *wpa_s)
  58. {
  59. if (wpa_s->bgscan && wpa_s->bgscan_priv) {
  60. wpa_printf(MSG_DEBUG, "bgscan: Deinitializing module '%s'",
  61. wpa_s->bgscan->name);
  62. wpa_s->bgscan->deinit(wpa_s->bgscan_priv);
  63. wpa_s->bgscan = NULL;
  64. wpa_s->bgscan_priv = NULL;
  65. }
  66. }
  67. int bgscan_notify_scan(struct wpa_supplicant *wpa_s,
  68. struct wpa_scan_results *scan_res)
  69. {
  70. if (wpa_s->bgscan && wpa_s->bgscan_priv)
  71. return wpa_s->bgscan->notify_scan(wpa_s->bgscan_priv,
  72. scan_res);
  73. return 0;
  74. }
  75. void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s)
  76. {
  77. if (wpa_s->bgscan && wpa_s->bgscan_priv)
  78. wpa_s->bgscan->notify_beacon_loss(wpa_s->bgscan_priv);
  79. }
  80. void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above,
  81. int current_signal, int current_noise,
  82. int current_txrate)
  83. {
  84. if (wpa_s->bgscan && wpa_s->bgscan_priv)
  85. wpa_s->bgscan->notify_signal_change(wpa_s->bgscan_priv, above,
  86. current_signal,
  87. current_noise,
  88. current_txrate);
  89. }