]>
Commit | Line | Data |
---|---|---|
f1a48710 JM |
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" | |
089757c6 | 20 | #include "../hostapd/config.h" |
fe6bdb77 | 21 | #ifdef NEED_AP_MLME |
0915d02c | 22 | #include "../hostapd/ieee802_11.h" |
fe6bdb77 | 23 | #endif /* NEED_AP_MLME */ |
3ec97afe | 24 | #include "../hostapd/wps_hostapd.h" |
e653b622 | 25 | #include "../hostapd/ctrl_iface_ap.h" |
f1a48710 JM |
26 | #include "eap_common/eap_defs.h" |
27 | #include "eap_server/eap_methods.h" | |
28 | #include "eap_common/eap_wsc_common.h" | |
3ec97afe | 29 | #include "wps/wps.h" |
1f1b62a0 JM |
30 | #include "config_ssid.h" |
31 | #include "wpa_supplicant_i.h" | |
2d5b792d JM |
32 | #include "driver_i.h" |
33 | #include "ap.h" | |
f1a48710 JM |
34 | |
35 | ||
2d5b792d JM |
36 | int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface, |
37 | void *ctx), void *ctx) | |
f1a48710 JM |
38 | { |
39 | /* TODO */ | |
2d5b792d | 40 | return 0; |
f1a48710 JM |
41 | } |
42 | ||
43 | ||
2d5b792d | 44 | int hostapd_ctrl_iface_init(struct hostapd_data *hapd) |
f1a48710 | 45 | { |
f1a48710 JM |
46 | return 0; |
47 | } | |
48 | ||
49 | ||
2d5b792d | 50 | void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd) |
f1a48710 | 51 | { |
2d5b792d | 52 | } |
f1a48710 | 53 | |
f1a48710 | 54 | |
2d5b792d JM |
55 | struct ap_driver_data { |
56 | struct hostapd_data *hapd; | |
57 | }; | |
f1a48710 | 58 | |
2d5b792d | 59 | |
92f475b4 JM |
60 | static void * ap_driver_init(struct hostapd_data *hapd, |
61 | struct wpa_init_params *params) | |
2d5b792d JM |
62 | { |
63 | struct ap_driver_data *drv; | |
0892aaaf | 64 | struct wpa_supplicant *wpa_s = hapd->iface->owner; |
2d5b792d JM |
65 | |
66 | drv = os_zalloc(sizeof(struct ap_driver_data)); | |
67 | if (drv == NULL) { | |
68 | wpa_printf(MSG_ERROR, "Could not allocate memory for AP " | |
69 | "driver data"); | |
70 | return NULL; | |
71 | } | |
72 | drv->hapd = hapd; | |
0892aaaf | 73 | os_memcpy(hapd->own_addr, wpa_s->own_addr, ETH_ALEN); |
2d5b792d JM |
74 | |
75 | return drv; | |
f1a48710 JM |
76 | } |
77 | ||
78 | ||
2d5b792d | 79 | static void ap_driver_deinit(void *priv) |
f1a48710 | 80 | { |
2d5b792d JM |
81 | struct ap_driver_data *drv = priv; |
82 | ||
83 | os_free(drv); | |
f1a48710 JM |
84 | } |
85 | ||
86 | ||
2d5b792d JM |
87 | static int ap_driver_send_ether(void *priv, const u8 *dst, const u8 *src, |
88 | u16 proto, const u8 *data, size_t data_len) | |
f1a48710 | 89 | { |
0f2b2c19 JM |
90 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); |
91 | return -1; | |
92 | } | |
93 | ||
94 | ||
95 | static int ap_driver_set_key(const char *iface, void *priv, wpa_alg alg, | |
96 | const u8 *addr, int key_idx, int set_tx, | |
97 | const u8 *seq, size_t seq_len, const u8 *key, | |
98 | size_t key_len) | |
99 | { | |
100 | struct ap_driver_data *drv = priv; | |
101 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
102 | return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len, | |
103 | key, key_len); | |
104 | } | |
105 | ||
106 | ||
107 | static int ap_driver_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
108 | int idx, u8 *seq) | |
109 | { | |
110 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
111 | return -1; | |
112 | } | |
113 | ||
114 | ||
115 | static int ap_driver_flush(void *priv) | |
116 | { | |
117 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
118 | return -1; | |
119 | } | |
120 | ||
121 | ||
122 | static int ap_driver_read_sta_data(void *priv, | |
123 | struct hostap_sta_driver_data *data, | |
124 | const u8 *addr) | |
125 | { | |
126 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
127 | return -1; | |
128 | } | |
129 | ||
130 | ||
131 | static int ap_driver_sta_set_flags(void *priv, const u8 *addr, int total_flags, | |
132 | int flags_or, int flags_and) | |
133 | { | |
a8d6ffa4 JM |
134 | struct ap_driver_data *drv = priv; |
135 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
136 | return wpa_drv_sta_set_flags(wpa_s, addr, total_flags, flags_or, | |
137 | flags_and); | |
0f2b2c19 JM |
138 | } |
139 | ||
140 | ||
be301e56 JM |
141 | static int ap_driver_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
142 | int reason) | |
0f2b2c19 JM |
143 | { |
144 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
145 | return -1; | |
146 | } | |
147 | ||
148 | ||
be301e56 JM |
149 | static int ap_driver_sta_disassoc(void *priv, const u8 *own_addr, |
150 | const u8 *addr, int reason) | |
0f2b2c19 JM |
151 | { |
152 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
153 | return -1; | |
154 | } | |
155 | ||
156 | ||
157 | static int ap_driver_sta_remove(void *priv, const u8 *addr) | |
158 | { | |
0f4e8b4f JM |
159 | struct ap_driver_data *drv = priv; |
160 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
161 | return wpa_drv_sta_remove(wpa_s, addr); | |
0f2b2c19 JM |
162 | } |
163 | ||
164 | ||
be301e56 | 165 | static int ap_driver_send_mlme(void *priv, const u8 *data, size_t len) |
0f2b2c19 | 166 | { |
2c2010ac JM |
167 | struct ap_driver_data *drv = priv; |
168 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
169 | return wpa_drv_send_mlme(wpa_s, data, len); | |
0f2b2c19 JM |
170 | } |
171 | ||
172 | ||
173 | static int ap_driver_sta_add(const char *ifname, void *priv, | |
174 | struct hostapd_sta_add_params *params) | |
175 | { | |
0f4e8b4f JM |
176 | struct ap_driver_data *drv = priv; |
177 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
178 | return wpa_drv_sta_add(wpa_s, params); | |
0f2b2c19 JM |
179 | } |
180 | ||
181 | ||
182 | static int ap_driver_get_inact_sec(void *priv, const u8 *addr) | |
183 | { | |
184 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
185 | return -1; | |
186 | } | |
187 | ||
188 | ||
189 | static int ap_driver_set_freq(void *priv, struct hostapd_freq_params *freq) | |
190 | { | |
191 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
f1a48710 JM |
192 | return 0; |
193 | } | |
194 | ||
195 | ||
0f2b2c19 | 196 | static int ap_driver_set_beacon(const char *iface, void *priv, |
d2440ba0 JM |
197 | const u8 *head, size_t head_len, |
198 | const u8 *tail, size_t tail_len, | |
199 | int dtim_period) | |
0f2b2c19 | 200 | { |
d2440ba0 JM |
201 | struct ap_driver_data *drv = priv; |
202 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
203 | return wpa_drv_set_beacon(wpa_s, head, head_len, tail, tail_len, | |
204 | dtim_period); | |
0f2b2c19 JM |
205 | } |
206 | ||
207 | ||
208 | static int ap_driver_set_beacon_int(void *priv, int value) | |
209 | { | |
d2440ba0 JM |
210 | struct ap_driver_data *drv = priv; |
211 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
212 | return wpa_drv_set_beacon_int(wpa_s, value); | |
0f2b2c19 JM |
213 | } |
214 | ||
215 | ||
216 | static int ap_driver_set_cts_protect(void *priv, int value) | |
217 | { | |
218 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
219 | return -1; | |
220 | } | |
221 | ||
222 | ||
223 | static int ap_driver_set_preamble(void *priv, int value) | |
224 | { | |
225 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
226 | return -1; | |
227 | } | |
228 | ||
229 | ||
230 | static int ap_driver_set_short_slot_time(void *priv, int value) | |
231 | { | |
232 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
233 | return -1; | |
234 | } | |
235 | ||
236 | ||
237 | static int ap_driver_set_tx_queue_params(void *priv, int queue, int aifs, | |
238 | int cw_min, int cw_max, | |
239 | int burst_time) | |
240 | { | |
241 | wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__); | |
242 | return -1; | |
243 | } | |
244 | ||
245 | ||
246 | static struct hostapd_hw_modes *ap_driver_get_hw_feature_data(void *priv, | |
247 | u16 *num_modes, | |
248 | u16 *flags) | |
249 | { | |
282d5590 JM |
250 | struct ap_driver_data *drv = priv; |
251 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
252 | return wpa_drv_get_hw_feature_data(wpa_s, num_modes, flags); | |
0f2b2c19 JM |
253 | } |
254 | ||
255 | ||
db149ac9 JM |
256 | static int ap_driver_hapd_send_eapol(void *priv, const u8 *addr, |
257 | const u8 *data, size_t data_len, | |
258 | int encrypt, const u8 *own_addr) | |
259 | { | |
260 | struct ap_driver_data *drv = priv; | |
261 | struct wpa_supplicant *wpa_s = drv->hapd->iface->owner; | |
262 | return wpa_drv_hapd_send_eapol(wpa_s, addr, data, data_len, encrypt, | |
263 | own_addr); | |
264 | } | |
265 | ||
266 | ||
c5121837 | 267 | struct wpa_driver_ops ap_driver_ops = |
f1a48710 | 268 | { |
2d5b792d | 269 | .name = "wpa_supplicant", |
c5121837 JM |
270 | .hapd_init = ap_driver_init, |
271 | .hapd_deinit = ap_driver_deinit, | |
2d5b792d | 272 | .send_ether = ap_driver_send_ether, |
c5121837 | 273 | .hapd_set_key = ap_driver_set_key, |
0f2b2c19 JM |
274 | .get_seqnum = ap_driver_get_seqnum, |
275 | .flush = ap_driver_flush, | |
276 | .read_sta_data = ap_driver_read_sta_data, | |
277 | .sta_set_flags = ap_driver_sta_set_flags, | |
278 | .sta_deauth = ap_driver_sta_deauth, | |
279 | .sta_disassoc = ap_driver_sta_disassoc, | |
280 | .sta_remove = ap_driver_sta_remove, | |
be301e56 | 281 | .send_mlme = ap_driver_send_mlme, |
0f2b2c19 JM |
282 | .sta_add = ap_driver_sta_add, |
283 | .get_inact_sec = ap_driver_get_inact_sec, | |
284 | .set_freq = ap_driver_set_freq, | |
c5121837 | 285 | .hapd_set_beacon = ap_driver_set_beacon, |
be301e56 | 286 | .set_beacon_int = ap_driver_set_beacon_int, |
0f2b2c19 JM |
287 | .set_cts_protect = ap_driver_set_cts_protect, |
288 | .set_preamble = ap_driver_set_preamble, | |
289 | .set_short_slot_time = ap_driver_set_short_slot_time, | |
290 | .set_tx_queue_params = ap_driver_set_tx_queue_params, | |
c3965310 | 291 | .get_hw_feature_data = ap_driver_get_hw_feature_data, |
db149ac9 | 292 | .hapd_send_eapol = ap_driver_hapd_send_eapol, |
2d5b792d | 293 | }; |
f1a48710 | 294 | |
f1a48710 | 295 | |
c5121837 | 296 | extern struct wpa_driver_ops *wpa_drivers[]; |
07f117ed JM |
297 | |
298 | static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s, | |
299 | struct wpa_ssid *ssid, | |
300 | struct hostapd_config *conf) | |
301 | { | |
302 | struct hostapd_bss_config *bss = &conf->bss[0]; | |
07d9a552 | 303 | int j, pairwise; |
c5121837 JM |
304 | |
305 | for (j = 0; wpa_drivers[j]; j++) { | |
306 | if (os_strcmp("wpa_supplicant", wpa_drivers[j]->name) == 0) { | |
307 | conf->driver = wpa_drivers[j]; | |
308 | break; | |
309 | } | |
310 | } | |
311 | if (conf->driver == NULL) { | |
312 | wpa_printf(MSG_ERROR, "No AP driver ops found"); | |
313 | return -1; | |
314 | } | |
07f117ed JM |
315 | |
316 | os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface)); | |
317 | ||
318 | if (ssid->frequency == 0) { | |
319 | /* default channel 11 */ | |
320 | conf->hw_mode = HOSTAPD_MODE_IEEE80211G; | |
321 | conf->channel = 11; | |
322 | } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) { | |
323 | conf->hw_mode = HOSTAPD_MODE_IEEE80211G; | |
324 | conf->channel = (ssid->frequency - 2407) / 5; | |
325 | } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) || | |
326 | (ssid->frequency >= 5745 && ssid->frequency <= 5825)) { | |
b615a25e | 327 | conf->hw_mode = HOSTAPD_MODE_IEEE80211A; |
07f117ed JM |
328 | conf->channel = (ssid->frequency - 5000) / 5; |
329 | } else { | |
330 | wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz", | |
331 | ssid->frequency); | |
332 | return -1; | |
333 | } | |
334 | ||
335 | /* TODO: enable HT if driver supports it; | |
336 | * drop to 11b if driver does not support 11g */ | |
337 | ||
338 | if (ssid->ssid_len == 0) { | |
339 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); | |
340 | return -1; | |
341 | } | |
342 | os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len); | |
343 | bss->ssid.ssid[ssid->ssid_len] = '\0'; | |
344 | bss->ssid.ssid_len = ssid->ssid_len; | |
345 | bss->ssid.ssid_set = 1; | |
346 | ||
347 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) | |
348 | bss->wpa = ssid->proto; | |
349 | bss->wpa_key_mgmt = ssid->key_mgmt; | |
350 | bss->wpa_pairwise = ssid->pairwise_cipher; | |
351 | if (ssid->passphrase) { | |
352 | bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase); | |
07f117ed JM |
353 | } else if (ssid->psk_set) { |
354 | os_free(bss->ssid.wpa_psk); | |
355 | bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); | |
356 | if (bss->ssid.wpa_psk == NULL) | |
357 | return -1; | |
358 | os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN); | |
359 | bss->ssid.wpa_psk->group = 1; | |
360 | } | |
361 | ||
07d9a552 JM |
362 | /* Select group cipher based on the enabled pairwise cipher suites */ |
363 | pairwise = 0; | |
364 | if (bss->wpa & 1) | |
365 | pairwise |= bss->wpa_pairwise; | |
366 | if (bss->wpa & 2) { | |
367 | if (bss->rsn_pairwise == 0) | |
368 | bss->rsn_pairwise = bss->wpa_pairwise; | |
369 | pairwise |= bss->rsn_pairwise; | |
370 | } | |
371 | if (pairwise & WPA_CIPHER_TKIP) | |
372 | bss->wpa_group = WPA_CIPHER_TKIP; | |
373 | else | |
374 | bss->wpa_group = WPA_CIPHER_CCMP; | |
375 | ||
376 | if (bss->wpa && bss->ieee802_1x) | |
377 | bss->ssid.security_policy = SECURITY_WPA; | |
378 | else if (bss->wpa) | |
379 | bss->ssid.security_policy = SECURITY_WPA_PSK; | |
380 | else if (bss->ieee802_1x) { | |
381 | bss->ssid.security_policy = SECURITY_IEEE_802_1X; | |
382 | bss->ssid.wep.default_len = bss->default_wep_key_len; | |
383 | } else if (bss->ssid.wep.keys_set) | |
384 | bss->ssid.security_policy = SECURITY_STATIC_WEP; | |
385 | else | |
386 | bss->ssid.security_policy = SECURITY_PLAINTEXT; | |
387 | ||
3ec97afe JM |
388 | #ifdef CONFIG_WPS |
389 | /* | |
390 | * Enable WPS by default, but require user interaction to actually use | |
391 | * it. Only the internal Registrar is supported. | |
392 | */ | |
393 | bss->eap_server = 1; | |
394 | bss->wps_state = 2; | |
395 | bss->ap_setup_locked = 1; | |
396 | bss->config_methods = os_strdup("display push_button"); | |
397 | #endif /* CONFIG_WPS */ | |
398 | ||
07f117ed JM |
399 | return 0; |
400 | } | |
401 | ||
402 | ||
2d5b792d JM |
403 | int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s, |
404 | struct wpa_ssid *ssid) | |
405 | { | |
406 | struct wpa_driver_associate_params params; | |
407 | struct hostapd_iface *hapd_iface; | |
408 | struct hostapd_config *conf; | |
409 | size_t i; | |
f1a48710 | 410 | |
2d5b792d JM |
411 | if (ssid->ssid == NULL || ssid->ssid_len == 0) { |
412 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); | |
413 | return -1; | |
f1a48710 JM |
414 | } |
415 | ||
2d5b792d | 416 | wpa_supplicant_ap_deinit(wpa_s); |
d2440ba0 JM |
417 | |
418 | wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')", | |
419 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
420 | ||
421 | os_memset(¶ms, 0, sizeof(params)); | |
422 | params.ssid = ssid->ssid; | |
423 | params.ssid_len = ssid->ssid_len; | |
424 | params.mode = ssid->mode; | |
425 | params.freq = ssid->frequency; | |
426 | ||
427 | if (wpa_drv_associate(wpa_s, ¶ms) < 0) { | |
428 | wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality"); | |
429 | return -1; | |
430 | } | |
431 | ||
2d5b792d JM |
432 | wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface)); |
433 | if (hapd_iface == NULL) | |
434 | return -1; | |
0f2b2c19 | 435 | hapd_iface->owner = wpa_s; |
1f1b62a0 | 436 | |
2d5b792d JM |
437 | wpa_s->ap_iface->conf = conf = hostapd_config_defaults(); |
438 | if (conf == NULL) { | |
439 | wpa_supplicant_ap_deinit(wpa_s); | |
440 | return -1; | |
441 | } | |
1f1b62a0 | 442 | |
07f117ed JM |
443 | if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) { |
444 | wpa_printf(MSG_ERROR, "Failed to create AP configuration"); | |
445 | wpa_supplicant_ap_deinit(wpa_s); | |
446 | return -1; | |
447 | } | |
448 | ||
2d5b792d JM |
449 | hapd_iface->num_bss = conf->num_bss; |
450 | hapd_iface->bss = os_zalloc(conf->num_bss * | |
451 | sizeof(struct hostapd_data *)); | |
452 | if (hapd_iface->bss == NULL) { | |
453 | wpa_supplicant_ap_deinit(wpa_s); | |
454 | return -1; | |
455 | } | |
1f1b62a0 | 456 | |
2d5b792d JM |
457 | for (i = 0; i < conf->num_bss; i++) { |
458 | hapd_iface->bss[i] = | |
459 | hostapd_alloc_bss_data(hapd_iface, conf, | |
460 | &conf->bss[i]); | |
461 | if (hapd_iface->bss[i] == NULL) { | |
462 | wpa_supplicant_ap_deinit(wpa_s); | |
463 | return -1; | |
464 | } | |
4f760fcc JM |
465 | |
466 | hapd_iface->bss[i]->msg_ctx = wpa_s; | |
2d5b792d JM |
467 | } |
468 | ||
469 | if (hostapd_setup_interface(wpa_s->ap_iface)) { | |
470 | wpa_printf(MSG_ERROR, "Failed to initialize AP interface"); | |
471 | wpa_supplicant_ap_deinit(wpa_s); | |
472 | return -1; | |
1f1b62a0 JM |
473 | } |
474 | ||
b2cc8056 | 475 | wpa_s->current_ssid = ssid; |
137fb724 WS |
476 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
477 | ||
2d5b792d JM |
478 | return 0; |
479 | } | |
480 | ||
481 | ||
482 | void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s) | |
483 | { | |
484 | if (wpa_s->ap_iface == NULL) | |
485 | return; | |
486 | ||
487 | hostapd_interface_deinit(wpa_s->ap_iface); | |
488 | wpa_s->ap_iface = NULL; | |
1f1b62a0 | 489 | } |
0915d02c JM |
490 | |
491 | ||
492 | void ap_tx_status(void *ctx, const u8 *addr, | |
493 | const u8 *buf, size_t len, int ack) | |
494 | { | |
495 | struct wpa_supplicant *wpa_s = ctx; | |
496 | hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack); | |
497 | } | |
498 | ||
499 | ||
3a57305f | 500 | void ap_rx_from_unknown_sta(void *ctx, struct ieee80211_hdr *hdr, size_t len) |
0915d02c JM |
501 | { |
502 | struct wpa_supplicant *wpa_s = ctx; | |
3a57305f | 503 | hostapd_rx_from_unknown_sta(wpa_s->ap_iface->bss[0], hdr, len); |
0915d02c JM |
504 | } |
505 | ||
506 | ||
fe6bdb77 | 507 | #ifdef NEED_AP_MLME |
0915d02c JM |
508 | void ap_mgmt_rx(void *ctx, u8 *buf, size_t len, u16 stype, |
509 | struct hostapd_frame_info *fi) | |
510 | { | |
511 | struct wpa_supplicant *wpa_s = ctx; | |
512 | ieee802_11_mgmt(wpa_s->ap_iface->bss[0], buf, len, stype, fi); | |
513 | } | |
514 | ||
515 | ||
516 | void ap_mgmt_tx_cb(void *ctx, u8 *buf, size_t len, u16 stype, int ok) | |
517 | { | |
518 | struct wpa_supplicant *wpa_s = ctx; | |
519 | ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok); | |
520 | } | |
fe6bdb77 | 521 | #endif /* NEED_AP_MLME */ |
db149ac9 JM |
522 | |
523 | ||
524 | void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s, | |
525 | const u8 *src_addr, const u8 *buf, size_t len) | |
526 | { | |
527 | hostapd_eapol_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len); | |
528 | } | |
3ec97afe JM |
529 | |
530 | ||
531 | #ifdef CONFIG_WPS | |
532 | ||
533 | int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid) | |
534 | { | |
535 | return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]); | |
536 | } | |
537 | ||
538 | ||
539 | int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, | |
540 | const char *pin, char *buf, size_t buflen) | |
541 | { | |
542 | int ret, ret_len = 0; | |
543 | ||
544 | if (pin == NULL) { | |
545 | unsigned int rpin = wps_generate_pin(); | |
546 | ret_len = os_snprintf(buf, buflen, "%d", rpin); | |
547 | pin = buf; | |
548 | } | |
549 | ||
077a781f | 550 | ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], "any", pin, 0); |
3ec97afe JM |
551 | if (ret) |
552 | return -1; | |
553 | return ret_len; | |
554 | } | |
555 | ||
556 | #endif /* CONFIG_WPS */ | |
e653b622 JM |
557 | |
558 | ||
35deb646 JM |
559 | #ifdef CONFIG_CTRL_IFACE |
560 | ||
e653b622 JM |
561 | int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s, |
562 | char *buf, size_t buflen) | |
563 | { | |
564 | if (wpa_s->ap_iface == NULL) | |
565 | return -1; | |
566 | return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0], | |
567 | buf, buflen); | |
568 | } | |
569 | ||
570 | ||
571 | int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr, | |
572 | char *buf, size_t buflen) | |
573 | { | |
574 | if (wpa_s->ap_iface == NULL) | |
575 | return -1; | |
576 | return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr, | |
577 | buf, buflen); | |
578 | } | |
579 | ||
580 | ||
581 | int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr, | |
582 | char *buf, size_t buflen) | |
583 | { | |
584 | if (wpa_s->ap_iface == NULL) | |
585 | return -1; | |
586 | return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr, | |
587 | buf, buflen); | |
588 | } | |
35deb646 JM |
589 | |
590 | #endif /* CONFIG_CTRL_IFACE */ |