You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bgscan.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * WPA Supplicant - background scan and roaming interface
  3. * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "wpa_supplicant_i.h"
  17. #include "config_ssid.h"
  18. #include "bgscan.h"
  19. #ifdef CONFIG_BGSCAN_SIMPLE
  20. extern const struct bgscan_ops bgscan_simple_ops;
  21. #endif /* CONFIG_BGSCAN_SIMPLE */
  22. #ifdef CONFIG_BGSCAN_LEARN
  23. extern const struct bgscan_ops bgscan_learn_ops;
  24. #endif /* CONFIG_BGSCAN_LEARN */
  25. static const struct bgscan_ops * bgscan_modules[] = {
  26. #ifdef CONFIG_BGSCAN_SIMPLE
  27. &bgscan_simple_ops,
  28. #endif /* CONFIG_BGSCAN_SIMPLE */
  29. #ifdef CONFIG_BGSCAN_LEARN
  30. &bgscan_learn_ops,
  31. #endif /* CONFIG_BGSCAN_LEARN */
  32. NULL
  33. };
  34. int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
  35. {
  36. const char *name = ssid->bgscan;
  37. const char *params;
  38. size_t nlen;
  39. int i;
  40. const struct bgscan_ops *ops = NULL;
  41. bgscan_deinit(wpa_s);
  42. if (name == NULL)
  43. return 0;
  44. params = os_strchr(name, ':');
  45. if (params == NULL) {
  46. params = "";
  47. nlen = os_strlen(name);
  48. } else {
  49. nlen = params - name;
  50. params++;
  51. }
  52. for (i = 0; bgscan_modules[i]; i++) {
  53. if (os_strncmp(name, bgscan_modules[i]->name, nlen) == 0) {
  54. ops = bgscan_modules[i];
  55. break;
  56. }
  57. }
  58. if (ops == NULL) {
  59. wpa_printf(MSG_ERROR, "bgscan: Could not find module "
  60. "matching the parameter '%s'", name);
  61. return -1;
  62. }
  63. wpa_s->bgscan_priv = ops->init(wpa_s, params, ssid);
  64. if (wpa_s->bgscan_priv == NULL)
  65. return -1;
  66. wpa_s->bgscan = ops;
  67. wpa_printf(MSG_DEBUG, "bgscan: Initialized module '%s' with "
  68. "parameters '%s'", ops->name, params);
  69. return 0;
  70. }
  71. void bgscan_deinit(struct wpa_supplicant *wpa_s)
  72. {
  73. if (wpa_s->bgscan && wpa_s->bgscan_priv) {
  74. wpa_printf(MSG_DEBUG, "bgscan: Deinitializing module '%s'",
  75. wpa_s->bgscan->name);
  76. wpa_s->bgscan->deinit(wpa_s->bgscan_priv);
  77. wpa_s->bgscan = NULL;
  78. wpa_s->bgscan_priv = NULL;
  79. }
  80. }
  81. int bgscan_notify_scan(struct wpa_supplicant *wpa_s,
  82. struct wpa_scan_results *scan_res)
  83. {
  84. if (wpa_s->bgscan && wpa_s->bgscan_priv)
  85. return wpa_s->bgscan->notify_scan(wpa_s->bgscan_priv,
  86. scan_res);
  87. return 0;
  88. }
  89. void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s)
  90. {
  91. if (wpa_s->bgscan && wpa_s->bgscan_priv)
  92. wpa_s->bgscan->notify_beacon_loss(wpa_s->bgscan_priv);
  93. }
  94. void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above,
  95. int current_signal, int current_noise,
  96. int current_txrate)
  97. {
  98. if (wpa_s->bgscan && wpa_s->bgscan_priv)
  99. wpa_s->bgscan->notify_signal_change(wpa_s->bgscan_priv, above,
  100. current_signal,
  101. current_noise,
  102. current_txrate);
  103. }