ap.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * WPA Supplicant - Basic AP mode support routines
  3. * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2009, Atheros Communications
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Alternatively, this software may be distributed under the terms of BSD
  11. * license.
  12. *
  13. * See README and COPYING for more details.
  14. */
  15. #include "includes.h"
  16. #include "common.h"
  17. #include "../hostapd/hostapd.h"
  18. #include "../hostapd/config.h"
  19. #include "eap_common/eap_defs.h"
  20. #include "eap_server/eap_methods.h"
  21. #include "eap_common/eap_wsc_common.h"
  22. int hostapd_reload_config(struct hostapd_iface *iface)
  23. {
  24. /* TODO */
  25. return -1;
  26. }
  27. int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
  28. const u8 *addr, int *vlan_id)
  29. {
  30. int start, end, middle, res;
  31. start = 0;
  32. end = num_entries - 1;
  33. while (start <= end) {
  34. middle = (start + end) / 2;
  35. res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
  36. if (res == 0) {
  37. if (vlan_id)
  38. *vlan_id = list[middle].vlan_id;
  39. return 1;
  40. }
  41. if (res < 0)
  42. start = middle + 1;
  43. else
  44. end = middle - 1;
  45. }
  46. return 0;
  47. }
  48. int hostapd_rate_found(int *list, int rate)
  49. {
  50. int i;
  51. if (list == NULL)
  52. return 0;
  53. for (i = 0; list[i] >= 0; i++)
  54. if (list[i] == rate)
  55. return 1;
  56. return 0;
  57. }
  58. const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
  59. {
  60. return NULL;
  61. }
  62. int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface,
  63. void *ctx), void *ctx)
  64. {
  65. /* TODO */
  66. return 0;
  67. }
  68. const struct hostapd_eap_user *
  69. hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
  70. size_t identity_len, int phase2)
  71. {
  72. struct hostapd_eap_user *user = conf->eap_user;
  73. #ifdef CONFIG_WPS
  74. if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
  75. os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
  76. static struct hostapd_eap_user wsc_enrollee;
  77. os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
  78. wsc_enrollee.methods[0].method = eap_server_get_type(
  79. "WSC", &wsc_enrollee.methods[0].vendor);
  80. return &wsc_enrollee;
  81. }
  82. if (conf->wps_state && conf->ap_pin &&
  83. identity_len == WSC_ID_REGISTRAR_LEN &&
  84. os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
  85. static struct hostapd_eap_user wsc_registrar;
  86. os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
  87. wsc_registrar.methods[0].method = eap_server_get_type(
  88. "WSC", &wsc_registrar.methods[0].vendor);
  89. wsc_registrar.password = (u8 *) conf->ap_pin;
  90. wsc_registrar.password_len = os_strlen(conf->ap_pin);
  91. return &wsc_registrar;
  92. }
  93. #endif /* CONFIG_WPS */
  94. while (user) {
  95. if (!phase2 && user->identity == NULL) {
  96. /* Wildcard match */
  97. break;
  98. }
  99. if (user->phase2 == !!phase2 && user->wildcard_prefix &&
  100. identity_len >= user->identity_len &&
  101. os_memcmp(user->identity, identity, user->identity_len) ==
  102. 0) {
  103. /* Wildcard prefix match */
  104. break;
  105. }
  106. if (user->phase2 == !!phase2 &&
  107. user->identity_len == identity_len &&
  108. os_memcmp(user->identity, identity, identity_len) == 0)
  109. break;
  110. user = user->next;
  111. }
  112. return user;
  113. }