2 * WPA Supplicant - Basic AP mode support routines
3 * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2009, Atheros Communications
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.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
19 #include "../hostapd/hostapd.h"
20 #include "../hostapd/config.h"
21 #include "../hostapd/driver.h"
22 #include "eap_common/eap_defs.h"
23 #include "eap_server/eap_methods.h"
24 #include "eap_common/eap_wsc_common.h"
25 #include "config_ssid.h"
26 #include "wpa_supplicant_i.h"
31 int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface,
32 void *ctx), void *ctx)
39 int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
45 void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
50 struct ap_driver_data {
51 struct hostapd_data *hapd;
55 static void * ap_driver_init(struct hostapd_data *hapd)
57 struct ap_driver_data *drv;
59 drv = os_zalloc(sizeof(struct ap_driver_data));
61 wpa_printf(MSG_ERROR, "Could not allocate memory for AP "
71 static void ap_driver_deinit(void *priv)
73 struct ap_driver_data *drv = priv;
79 static int ap_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
80 u16 proto, const u8 *data, size_t data_len)
86 static struct hapd_driver_ops ap_driver_ops =
88 .name = "wpa_supplicant",
89 .init = ap_driver_init,
90 .deinit = ap_driver_deinit,
91 .send_ether = ap_driver_send_ether,
94 struct hapd_driver_ops *hostapd_drivers[] =
100 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
101 struct wpa_ssid *ssid)
103 struct wpa_driver_associate_params params;
104 struct hostapd_iface *hapd_iface;
105 struct hostapd_config *conf;
108 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
109 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
113 wpa_supplicant_ap_deinit(wpa_s);
114 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
115 if (hapd_iface == NULL)
118 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
120 wpa_supplicant_ap_deinit(wpa_s);
124 hapd_iface->num_bss = conf->num_bss;
125 hapd_iface->bss = os_zalloc(conf->num_bss *
126 sizeof(struct hostapd_data *));
127 if (hapd_iface->bss == NULL) {
128 wpa_supplicant_ap_deinit(wpa_s);
132 for (i = 0; i < conf->num_bss; i++) {
134 hostapd_alloc_bss_data(hapd_iface, conf,
136 if (hapd_iface->bss[i] == NULL) {
137 wpa_supplicant_ap_deinit(wpa_s);
142 if (hostapd_setup_interface(wpa_s->ap_iface)) {
143 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
144 wpa_supplicant_ap_deinit(wpa_s);
148 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
149 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
151 os_memset(¶ms, 0, sizeof(params));
152 params.ssid = ssid->ssid;
153 params.ssid_len = ssid->ssid_len;
154 params.mode = ssid->mode;
156 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
157 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
165 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
167 if (wpa_s->ap_iface == NULL)
170 hostapd_interface_deinit(wpa_s->ap_iface);
171 wpa_s->ap_iface = NULL;