Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * wpa_supplicant - Temporary BSSID blacklist
  3. * Copyright (c) 2003-2007, 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 "blacklist.h"
  18. /**
  19. * wpa_blacklist_get - Get the blacklist entry for a BSSID
  20. * @wpa_s: Pointer to wpa_supplicant data
  21. * @bssid: BSSID
  22. * Returns: Matching blacklist entry for the BSSID or %NULL if not found
  23. */
  24. struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
  25. const u8 *bssid)
  26. {
  27. struct wpa_blacklist *e;
  28. e = wpa_s->blacklist;
  29. while (e) {
  30. if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0)
  31. return e;
  32. e = e->next;
  33. }
  34. return NULL;
  35. }
  36. /**
  37. * wpa_blacklist_add - Add an BSSID to the blacklist
  38. * @wpa_s: Pointer to wpa_supplicant data
  39. * @bssid: BSSID to be added to the blacklist
  40. * Returns: Current blacklist count on success, -1 on failure
  41. *
  42. * This function adds the specified BSSID to the blacklist or increases the
  43. * blacklist count if the BSSID was already listed. It should be called when
  44. * an association attempt fails either due to the selected BSS rejecting
  45. * association or due to timeout.
  46. *
  47. * This blacklist is used to force %wpa_supplicant to go through all available
  48. * BSSes before retrying to associate with an BSS that rejected or timed out
  49. * association. It does not prevent the listed BSS from being used; it only
  50. * changes the order in which they are tried.
  51. */
  52. int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
  53. {
  54. struct wpa_blacklist *e;
  55. e = wpa_blacklist_get(wpa_s, bssid);
  56. if (e) {
  57. e->count++;
  58. wpa_printf(MSG_DEBUG, "BSSID " MACSTR " blacklist count "
  59. "incremented to %d",
  60. MAC2STR(bssid), e->count);
  61. return e->count;
  62. }
  63. e = os_zalloc(sizeof(*e));
  64. if (e == NULL)
  65. return -1;
  66. os_memcpy(e->bssid, bssid, ETH_ALEN);
  67. e->count = 1;
  68. e->next = wpa_s->blacklist;
  69. wpa_s->blacklist = e;
  70. wpa_printf(MSG_DEBUG, "Added BSSID " MACSTR " into blacklist",
  71. MAC2STR(bssid));
  72. return e->count;
  73. }
  74. /**
  75. * wpa_blacklist_del - Remove an BSSID from the blacklist
  76. * @wpa_s: Pointer to wpa_supplicant data
  77. * @bssid: BSSID to be removed from the blacklist
  78. * Returns: 0 on success, -1 on failure
  79. */
  80. int wpa_blacklist_del(struct wpa_supplicant *wpa_s, const u8 *bssid)
  81. {
  82. struct wpa_blacklist *e, *prev = NULL;
  83. e = wpa_s->blacklist;
  84. while (e) {
  85. if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0) {
  86. if (prev == NULL) {
  87. wpa_s->blacklist = e->next;
  88. } else {
  89. prev->next = e->next;
  90. }
  91. wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
  92. "blacklist", MAC2STR(bssid));
  93. os_free(e);
  94. return 0;
  95. }
  96. prev = e;
  97. e = e->next;
  98. }
  99. return -1;
  100. }
  101. /**
  102. * wpa_blacklist_clear - Clear the blacklist of all entries
  103. * @wpa_s: Pointer to wpa_supplicant data
  104. */
  105. void wpa_blacklist_clear(struct wpa_supplicant *wpa_s)
  106. {
  107. struct wpa_blacklist *e, *prev;
  108. e = wpa_s->blacklist;
  109. wpa_s->blacklist = NULL;
  110. while (e) {
  111. prev = e;
  112. e = e->next;
  113. wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
  114. "blacklist (clear)", MAC2STR(prev->bssid));
  115. os_free(prev);
  116. }
  117. }