ap.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #include "config_ssid.h"
  23. #include "wpa_supplicant_i.h"
  24. int hostapd_reload_config(struct hostapd_iface *iface)
  25. {
  26. /* TODO */
  27. return -1;
  28. }
  29. int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
  30. const u8 *addr, int *vlan_id)
  31. {
  32. int start, end, middle, res;
  33. start = 0;
  34. end = num_entries - 1;
  35. while (start <= end) {
  36. middle = (start + end) / 2;
  37. res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
  38. if (res == 0) {
  39. if (vlan_id)
  40. *vlan_id = list[middle].vlan_id;
  41. return 1;
  42. }
  43. if (res < 0)
  44. start = middle + 1;
  45. else
  46. end = middle - 1;
  47. }
  48. return 0;
  49. }
  50. int hostapd_rate_found(int *list, int rate)
  51. {
  52. int i;
  53. if (list == NULL)
  54. return 0;
  55. for (i = 0; list[i] >= 0; i++)
  56. if (list[i] == rate)
  57. return 1;
  58. return 0;
  59. }
  60. const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
  61. {
  62. return NULL;
  63. }
  64. int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface,
  65. void *ctx), void *ctx)
  66. {
  67. /* TODO */
  68. return 0;
  69. }
  70. const struct hostapd_eap_user *
  71. hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
  72. size_t identity_len, int phase2)
  73. {
  74. struct hostapd_eap_user *user = conf->eap_user;
  75. #ifdef CONFIG_WPS
  76. if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
  77. os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
  78. static struct hostapd_eap_user wsc_enrollee;
  79. os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
  80. wsc_enrollee.methods[0].method = eap_server_get_type(
  81. "WSC", &wsc_enrollee.methods[0].vendor);
  82. return &wsc_enrollee;
  83. }
  84. if (conf->wps_state && conf->ap_pin &&
  85. identity_len == WSC_ID_REGISTRAR_LEN &&
  86. os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
  87. static struct hostapd_eap_user wsc_registrar;
  88. os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
  89. wsc_registrar.methods[0].method = eap_server_get_type(
  90. "WSC", &wsc_registrar.methods[0].vendor);
  91. wsc_registrar.password = (u8 *) conf->ap_pin;
  92. wsc_registrar.password_len = os_strlen(conf->ap_pin);
  93. return &wsc_registrar;
  94. }
  95. #endif /* CONFIG_WPS */
  96. while (user) {
  97. if (!phase2 && user->identity == NULL) {
  98. /* Wildcard match */
  99. break;
  100. }
  101. if (user->phase2 == !!phase2 && user->wildcard_prefix &&
  102. identity_len >= user->identity_len &&
  103. os_memcmp(user->identity, identity, user->identity_len) ==
  104. 0) {
  105. /* Wildcard prefix match */
  106. break;
  107. }
  108. if (user->phase2 == !!phase2 &&
  109. user->identity_len == identity_len &&
  110. os_memcmp(user->identity, identity, identity_len) == 0)
  111. break;
  112. user = user->next;
  113. }
  114. return user;
  115. }
  116. void wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
  117. struct wpa_ssid *ssid)
  118. {
  119. struct wpa_driver_associate_params params;
  120. if (ssid->ssid == NULL || ssid->ssid_len == 0) {
  121. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  122. return;
  123. }
  124. wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
  125. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  126. os_memset(&params, 0, sizeof(params));
  127. params.ssid = ssid->ssid;
  128. params.ssid_len = ssid->ssid_len;
  129. params.mode = ssid->mode;
  130. if (wpa_drv_associate(wpa_s, &params) < 0)
  131. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  132. }