autoscan_exponential.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * WPA Supplicant - auto scan exponential module
  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 "wpa_supplicant_i.h"
  11. #include "autoscan.h"
  12. struct autoscan_exponential_data {
  13. struct wpa_supplicant *wpa_s;
  14. int base;
  15. int limit;
  16. int interval;
  17. };
  18. static int
  19. autoscan_exponential_get_params(struct autoscan_exponential_data *data,
  20. const char *params)
  21. {
  22. const char *pos;
  23. if (params == NULL)
  24. return -1;
  25. data->base = atoi(params);
  26. pos = os_strchr(params, ':');
  27. if (pos == NULL)
  28. return -1;
  29. pos++;
  30. data->limit = atoi(pos);
  31. return 0;
  32. }
  33. static void * autoscan_exponential_init(struct wpa_supplicant *wpa_s,
  34. const char *params)
  35. {
  36. struct autoscan_exponential_data *data;
  37. data = os_zalloc(sizeof(struct autoscan_exponential_data));
  38. if (data == NULL)
  39. return NULL;
  40. if (autoscan_exponential_get_params(data, params) < 0) {
  41. os_free(data);
  42. return NULL;
  43. }
  44. wpa_printf(MSG_DEBUG, "autoscan exponential: base exponential is %d "
  45. "and limit is %d", data->base, data->limit);
  46. data->wpa_s = wpa_s;
  47. return data;
  48. }
  49. static void autoscan_exponential_deinit(void *priv)
  50. {
  51. struct autoscan_exponential_data *data = priv;
  52. os_free(data);
  53. }
  54. static int autoscan_exponential_notify_scan(void *priv,
  55. struct wpa_scan_results *scan_res)
  56. {
  57. struct autoscan_exponential_data *data = priv;
  58. wpa_printf(MSG_DEBUG, "autoscan exponential: scan result "
  59. "notification");
  60. if (data->interval >= data->limit)
  61. return data->limit;
  62. if (data->interval <= 0)
  63. data->interval = data->base;
  64. else {
  65. data->interval = data->interval * data->base;
  66. if (data->interval > data->limit)
  67. return data->limit;
  68. }
  69. return data->interval;
  70. }
  71. const struct autoscan_ops autoscan_exponential_ops = {
  72. .name = "exponential",
  73. .init = autoscan_exponential_init,
  74. .deinit = autoscan_exponential_deinit,
  75. .notify_scan = autoscan_exponential_notify_scan,
  76. };