Link in AP functionality from hostapd when CONFIG_AP=y
[wpasupplicant] / wpa_supplicant / ap.c
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
16 #include "includes.h"
17
18 #include "common.h"
19 #include "../hostapd/hostapd.h"
20 #include "eap_common/eap_defs.h"
21 #include "eap_server/eap_methods.h"
22 #include "eap_common/eap_wsc_common.h"
23
24
25 int hostapd_reload_config(struct hostapd_iface *iface)
26 {
27         /* TODO */
28         return -1;
29 }
30
31
32 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
33                           const u8 *addr, int *vlan_id)
34 {
35         int start, end, middle, res;
36
37         start = 0;
38         end = num_entries - 1;
39
40         while (start <= end) {
41                 middle = (start + end) / 2;
42                 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
43                 if (res == 0) {
44                         if (vlan_id)
45                                 *vlan_id = list[middle].vlan_id;
46                         return 1;
47                 }
48                 if (res < 0)
49                         start = middle + 1;
50                 else
51                         end = middle - 1;
52         }
53
54         return 0;
55 }
56
57
58 int hostapd_rate_found(int *list, int rate)
59 {
60         int i;
61
62         if (list == NULL)
63                 return 0;
64
65         for (i = 0; list[i] >= 0; i++)
66                 if (list[i] == rate)
67                         return 1;
68
69         return 0;
70 }
71
72
73 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
74 {
75         return NULL;
76 }
77
78
79 int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface,
80                                          void *ctx), void *ctx)
81 {
82         /* TODO */
83         return 0;
84 }
85
86
87 const struct hostapd_eap_user *
88 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
89                      size_t identity_len, int phase2)
90 {
91         struct hostapd_eap_user *user = conf->eap_user;
92
93 #ifdef CONFIG_WPS
94         if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
95             os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
96                 static struct hostapd_eap_user wsc_enrollee;
97                 os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
98                 wsc_enrollee.methods[0].method = eap_server_get_type(
99                         "WSC", &wsc_enrollee.methods[0].vendor);
100                 return &wsc_enrollee;
101         }
102
103         if (conf->wps_state && conf->ap_pin &&
104             identity_len == WSC_ID_REGISTRAR_LEN &&
105             os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
106                 static struct hostapd_eap_user wsc_registrar;
107                 os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
108                 wsc_registrar.methods[0].method = eap_server_get_type(
109                         "WSC", &wsc_registrar.methods[0].vendor);
110                 wsc_registrar.password = (u8 *) conf->ap_pin;
111                 wsc_registrar.password_len = os_strlen(conf->ap_pin);
112                 return &wsc_registrar;
113         }
114 #endif /* CONFIG_WPS */
115
116         while (user) {
117                 if (!phase2 && user->identity == NULL) {
118                         /* Wildcard match */
119                         break;
120                 }
121
122                 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
123                     identity_len >= user->identity_len &&
124                     os_memcmp(user->identity, identity, user->identity_len) ==
125                     0) {
126                         /* Wildcard prefix match */
127                         break;
128                 }
129
130                 if (user->phase2 == !!phase2 &&
131                     user->identity_len == identity_len &&
132                     os_memcmp(user->identity, identity, identity_len) == 0)
133                         break;
134                 user = user->next;
135         }
136
137         return user;
138 }