Move hostapd global callback functions into hapd_interfaces
These function pointers are going to be the same for each interface so there is no need to keep them in struct hostapd_iface. Moving them to struct hapd_interfaces makes it easier to add interfaces at run time. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
27b80b5b4c
commit
3776ac73b2
6 changed files with 53 additions and 39 deletions
|
@ -166,14 +166,9 @@ static struct hostapd_iface * hostapd_init(const char *config_file)
|
||||||
if (hapd_iface == NULL)
|
if (hapd_iface == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
hapd_iface->reload_config = hostapd_reload_config;
|
|
||||||
hapd_iface->config_read_cb = hostapd_config_read;
|
|
||||||
hapd_iface->config_fname = os_strdup(config_file);
|
hapd_iface->config_fname = os_strdup(config_file);
|
||||||
if (hapd_iface->config_fname == NULL)
|
if (hapd_iface->config_fname == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
hapd_iface->ctrl_iface_init = hostapd_ctrl_iface_init;
|
|
||||||
hapd_iface->ctrl_iface_deinit = hostapd_ctrl_iface_deinit;
|
|
||||||
hapd_iface->for_each_interface = hostapd_for_each_interface;
|
|
||||||
|
|
||||||
conf = hostapd_config_read(hapd_iface->config_fname);
|
conf = hostapd_config_read(hapd_iface->config_fname);
|
||||||
if (conf == NULL)
|
if (conf == NULL)
|
||||||
|
@ -540,6 +535,13 @@ int main(int argc, char *argv[])
|
||||||
if (os_program_init())
|
if (os_program_init())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
os_memset(&interfaces, 0, sizeof(interfaces));
|
||||||
|
interfaces.reload_config = hostapd_reload_config;
|
||||||
|
interfaces.config_read_cb = hostapd_config_read;
|
||||||
|
interfaces.for_each_interface = hostapd_for_each_interface;
|
||||||
|
interfaces.ctrl_iface_init = hostapd_ctrl_iface_init;
|
||||||
|
interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = getopt(argc, argv, "Bde:f:hKP:tv");
|
c = getopt(argc, argv, "Bde:f:hKP:tv");
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
|
|
|
@ -113,9 +113,10 @@ int hostapd_reload_config(struct hostapd_iface *iface)
|
||||||
struct hostapd_config *newconf, *oldconf;
|
struct hostapd_config *newconf, *oldconf;
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
if (iface->config_read_cb == NULL)
|
if (iface->interfaces == NULL ||
|
||||||
|
iface->interfaces->config_read_cb == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
newconf = iface->config_read_cb(iface->config_fname);
|
newconf = iface->interfaces->config_read_cb(iface->config_fname);
|
||||||
if (newconf == NULL)
|
if (newconf == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -286,8 +287,9 @@ static void hostapd_free_hapd_data(struct hostapd_data *hapd)
|
||||||
*/
|
*/
|
||||||
static void hostapd_cleanup(struct hostapd_data *hapd)
|
static void hostapd_cleanup(struct hostapd_data *hapd)
|
||||||
{
|
{
|
||||||
if (hapd->iface->ctrl_iface_deinit)
|
if (hapd->iface->interfaces &&
|
||||||
hapd->iface->ctrl_iface_deinit(hapd);
|
hapd->iface->interfaces->ctrl_iface_deinit)
|
||||||
|
hapd->iface->interfaces->ctrl_iface_deinit(hapd);
|
||||||
hostapd_free_hapd_data(hapd);
|
hostapd_free_hapd_data(hapd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,8 +772,9 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_INTERWORKING */
|
#endif /* CONFIG_INTERWORKING */
|
||||||
|
|
||||||
if (hapd->iface->ctrl_iface_init &&
|
if (hapd->iface->interfaces &&
|
||||||
hapd->iface->ctrl_iface_init(hapd)) {
|
hapd->iface->interfaces->ctrl_iface_init &&
|
||||||
|
hapd->iface->interfaces->ctrl_iface_init(hapd)) {
|
||||||
wpa_printf(MSG_ERROR, "Failed to setup control interface");
|
wpa_printf(MSG_ERROR, "Failed to setup control interface");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,17 @@ struct full_dynamic_vlan;
|
||||||
enum wps_event;
|
enum wps_event;
|
||||||
union wps_event_data;
|
union wps_event_data;
|
||||||
|
|
||||||
|
struct hostapd_iface;
|
||||||
|
|
||||||
struct hapd_interfaces {
|
struct hapd_interfaces {
|
||||||
|
int (*reload_config)(struct hostapd_iface *iface);
|
||||||
|
struct hostapd_config * (*config_read_cb)(const char *config_fname);
|
||||||
|
int (*ctrl_iface_init)(struct hostapd_data *hapd);
|
||||||
|
void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
|
||||||
|
int (*for_each_interface)(struct hapd_interfaces *interfaces,
|
||||||
|
int (*cb)(struct hostapd_iface *iface,
|
||||||
|
void *ctx), void *ctx);
|
||||||
|
|
||||||
size_t count;
|
size_t count;
|
||||||
struct hostapd_iface **iface;
|
struct hostapd_iface **iface;
|
||||||
};
|
};
|
||||||
|
@ -182,8 +192,6 @@ struct hostapd_data {
|
||||||
struct hostapd_iface {
|
struct hostapd_iface {
|
||||||
struct hapd_interfaces *interfaces;
|
struct hapd_interfaces *interfaces;
|
||||||
void *owner;
|
void *owner;
|
||||||
int (*reload_config)(struct hostapd_iface *iface);
|
|
||||||
struct hostapd_config * (*config_read_cb)(const char *config_fname);
|
|
||||||
char *config_fname;
|
char *config_fname;
|
||||||
struct hostapd_config *conf;
|
struct hostapd_config *conf;
|
||||||
|
|
||||||
|
@ -241,13 +249,6 @@ struct hostapd_iface {
|
||||||
|
|
||||||
u16 ht_op_mode;
|
u16 ht_op_mode;
|
||||||
void (*scan_cb)(struct hostapd_iface *iface);
|
void (*scan_cb)(struct hostapd_iface *iface);
|
||||||
|
|
||||||
int (*ctrl_iface_init)(struct hostapd_data *hapd);
|
|
||||||
void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
|
|
||||||
|
|
||||||
int (*for_each_interface)(struct hapd_interfaces *interfaces,
|
|
||||||
int (*cb)(struct hostapd_iface *iface,
|
|
||||||
void *ctx), void *ctx);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* hostapd.c */
|
/* hostapd.c */
|
||||||
|
|
|
@ -78,7 +78,8 @@ void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
|
||||||
struct prune_data data;
|
struct prune_data data;
|
||||||
data.hapd = hapd;
|
data.hapd = hapd;
|
||||||
data.addr = addr;
|
data.addr = addr;
|
||||||
if (hapd->iface->for_each_interface)
|
if (hapd->iface->interfaces &&
|
||||||
hapd->iface->for_each_interface(hapd->iface->interfaces,
|
hapd->iface->interfaces->for_each_interface)
|
||||||
prune_associations, &data);
|
hapd->iface->interfaces->for_each_interface(
|
||||||
|
hapd->iface->interfaces, prune_associations, &data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,12 +303,13 @@ static int hostapd_wpa_auth_for_each_auth(
|
||||||
{
|
{
|
||||||
struct hostapd_data *hapd = ctx;
|
struct hostapd_data *hapd = ctx;
|
||||||
struct wpa_auth_iface_iter_data data;
|
struct wpa_auth_iface_iter_data data;
|
||||||
if (hapd->iface->for_each_interface == NULL)
|
if (hapd->iface->interfaces == NULL ||
|
||||||
|
hapd->iface->interfaces->for_each_interface == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
data.cb = cb;
|
data.cb = cb;
|
||||||
data.cb_ctx = cb_ctx;
|
data.cb_ctx = cb_ctx;
|
||||||
return hapd->iface->for_each_interface(hapd->iface->interfaces,
|
return hapd->iface->interfaces->for_each_interface(
|
||||||
wpa_auth_iface_iter, &data);
|
hapd->iface->interfaces, wpa_auth_iface_iter, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -360,16 +361,17 @@ static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef CONFIG_IEEE80211R
|
#ifdef CONFIG_IEEE80211R
|
||||||
if (proto == ETH_P_RRB && hapd->iface->for_each_interface) {
|
if (proto == ETH_P_RRB && hapd->iface->interfaces &&
|
||||||
|
hapd->iface->interfaces->for_each_interface) {
|
||||||
int res;
|
int res;
|
||||||
struct wpa_auth_ft_iface_iter_data idata;
|
struct wpa_auth_ft_iface_iter_data idata;
|
||||||
idata.src_hapd = hapd;
|
idata.src_hapd = hapd;
|
||||||
idata.dst = dst;
|
idata.dst = dst;
|
||||||
idata.data = data;
|
idata.data = data;
|
||||||
idata.data_len = data_len;
|
idata.data_len = data_len;
|
||||||
res = hapd->iface->for_each_interface(hapd->iface->interfaces,
|
res = hapd->iface->interfaces->for_each_interface(
|
||||||
hostapd_wpa_auth_ft_iter,
|
hapd->iface->interfaces, hostapd_wpa_auth_ft_iter,
|
||||||
&idata);
|
&idata);
|
||||||
if (res == 1)
|
if (res == 1)
|
||||||
return data_len;
|
return data_len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,10 +76,11 @@ static int hostapd_wps_for_each(struct hostapd_data *hapd,
|
||||||
struct wps_for_each_data data;
|
struct wps_for_each_data data;
|
||||||
data.func = func;
|
data.func = func;
|
||||||
data.ctx = ctx;
|
data.ctx = ctx;
|
||||||
if (iface->for_each_interface == NULL)
|
if (iface->interfaces == NULL ||
|
||||||
|
iface->interfaces->for_each_interface == NULL)
|
||||||
return wps_for_each(iface, &data);
|
return wps_for_each(iface, &data);
|
||||||
return iface->for_each_interface(iface->interfaces, wps_for_each,
|
return iface->interfaces->for_each_interface(iface->interfaces,
|
||||||
&data);
|
wps_for_each, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -256,7 +257,8 @@ static void wps_reload_config(void *eloop_data, void *user_ctx)
|
||||||
struct hostapd_iface *iface = eloop_data;
|
struct hostapd_iface *iface = eloop_data;
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "WPS: Reload configuration data");
|
wpa_printf(MSG_DEBUG, "WPS: Reload configuration data");
|
||||||
if (iface->reload_config(iface) < 0) {
|
if (iface->interfaces == NULL ||
|
||||||
|
iface->interfaces->reload_config(iface) < 0) {
|
||||||
wpa_printf(MSG_WARNING, "WPS: Failed to reload the updated "
|
wpa_printf(MSG_WARNING, "WPS: Failed to reload the updated "
|
||||||
"configuration");
|
"configuration");
|
||||||
}
|
}
|
||||||
|
@ -717,10 +719,12 @@ static int get_uuid_cb(struct hostapd_iface *iface, void *ctx)
|
||||||
static const u8 * get_own_uuid(struct hostapd_iface *iface)
|
static const u8 * get_own_uuid(struct hostapd_iface *iface)
|
||||||
{
|
{
|
||||||
const u8 *uuid;
|
const u8 *uuid;
|
||||||
if (iface->for_each_interface == NULL)
|
if (iface->interfaces == NULL ||
|
||||||
|
iface->interfaces->for_each_interface == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
uuid = NULL;
|
uuid = NULL;
|
||||||
iface->for_each_interface(iface->interfaces, get_uuid_cb, &uuid);
|
iface->interfaces->for_each_interface(iface->interfaces, get_uuid_cb,
|
||||||
|
&uuid);
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,10 +740,11 @@ static int count_interface_cb(struct hostapd_iface *iface, void *ctx)
|
||||||
static int interface_count(struct hostapd_iface *iface)
|
static int interface_count(struct hostapd_iface *iface)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (iface->for_each_interface == NULL)
|
if (iface->interfaces == NULL ||
|
||||||
|
iface->interfaces->for_each_interface == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
iface->for_each_interface(iface->interfaces, count_interface_cb,
|
iface->interfaces->for_each_interface(iface->interfaces,
|
||||||
&count);
|
count_interface_cb, &count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue