bgscan.c 2.5 KB

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