Merge hostapd driver init functions into one

Use a parameter structure to pass in information that can be more easily
extended in the future. Include some of the parameters that were
previously read directly from hapd->conf in order to reduce need for
including hostapd/config.h into driver wrappers.
This commit is contained in:
Jouni Malinen 2009-04-09 23:28:21 +03:00 committed by Jouni Malinen
parent 989f52c639
commit 92f475b4d8
16 changed files with 96 additions and 76 deletions

View file

@ -2099,13 +2099,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
errors++; errors++;
} }
} else if (os_strcmp(buf, "bssid") == 0) { } else if (os_strcmp(buf, "bssid") == 0) {
if (bss == conf->bss && if (hwaddr_aton(pos, bss->bssid)) {
(!conf->driver || !conf->driver->init_bssid)) {
wpa_printf(MSG_ERROR, "Line %d: bssid item "
"not allowed for the default "
"interface and this driver", line);
errors++;
} else if (hwaddr_aton(pos, bss->bssid)) {
wpa_printf(MSG_ERROR, "Line %d: invalid bssid " wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
"item", line); "item", line);
errors++; errors++;

View file

@ -20,19 +20,37 @@
#include "config.h" #include "config.h"
static inline void * static inline void *
hostapd_driver_init(struct hostapd_data *hapd) hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
{ {
struct wpa_init_params params;
void *ret;
size_t i;
if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
return NULL; return NULL;
return hapd->driver->hapd_init(hapd);
}
static inline void * os_memset(&params, 0, sizeof(params));
hostapd_driver_init_bssid(struct hostapd_data *hapd, const u8 *bssid) params.bssid = bssid;
{ params.ifname = hapd->conf->iface;
if (hapd->driver == NULL || hapd->driver->init_bssid == NULL) params.ssid = (const u8 *) hapd->conf->ssid.ssid;
params.ssid_len = hapd->conf->ssid.ssid_len;
params.test_socket = hapd->conf->test_socket;
params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
params.ht_40mhz_scan = hapd->iconf->secondary_channel != 0;
params.num_bridge = hapd->iface->num_bss;
params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
if (params.bridge == NULL)
return NULL; return NULL;
return hapd->driver->init_bssid(hapd, bssid); for (i = 0; i < hapd->iface->num_bss; i++) {
struct hostapd_data *bss = hapd->iface->bss[i];
if (bss->conf->bridge[0])
params.bridge[i] = bss->conf->bridge;
}
ret = hapd->driver->hapd_init(hapd, &params);
os_free(params.bridge);
return ret;
} }
static inline void static inline void

View file

@ -1322,11 +1322,9 @@ static int setup_interface(struct hostapd_iface *iface)
* Initialize the driver interface and make sure that all BSSes get * Initialize the driver interface and make sure that all BSSes get
* configured with a pointer to this driver interface. * configured with a pointer to this driver interface.
*/ */
if (b[0] | b[1] | b[2] | b[3] | b[4] | b[5]) { if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
hapd->drv_priv = hostapd_driver_init_bssid(hapd, b); b = NULL;
} else { hapd->drv_priv = hostapd_driver_init(hapd, b);
hapd->drv_priv = hostapd_driver_init(hapd);
}
if (hapd->drv_priv == NULL) { if (hapd->drv_priv == NULL) {
wpa_printf(MSG_ERROR, "%s driver initialization failed.", wpa_printf(MSG_ERROR, "%s driver initialization failed.",

View file

@ -502,6 +502,18 @@ struct hostapd_neighbor_bss {
int sec_chan; /* 0 for 20 MHz channels */ int sec_chan; /* 0 for 20 MHz channels */
}; };
struct wpa_init_params {
const u8 *bssid;
const char *ifname;
const u8 *ssid;
size_t ssid_len;
const char *test_socket;
int use_pae_group_addr;
int ht_40mhz_scan;
char **bridge;
size_t num_bridge;
};
/** /**
* struct wpa_driver_ops - Driver interface API definition * struct wpa_driver_ops - Driver interface API definition
@ -1197,8 +1209,8 @@ struct wpa_driver_ops {
int (*set_beacon_int)(void *priv, int value); int (*set_beacon_int)(void *priv, int value);
void * (*hapd_init)(struct hostapd_data *hapd); void * (*hapd_init)(struct hostapd_data *hapd,
void * (*init_bssid)(struct hostapd_data *hapd, const u8 *bssid); struct wpa_init_params *params);
void (*hapd_deinit)(void *priv); void (*hapd_deinit)(void *priv);
/** /**

View file

@ -1167,7 +1167,7 @@ handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
} }
static void * static void *
madwifi_init(struct hostapd_data *hapd) madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
{ {
struct madwifi_driver_data *drv; struct madwifi_driver_data *drv;
struct ifreq ifr; struct ifreq ifr;
@ -1185,7 +1185,7 @@ madwifi_init(struct hostapd_data *hapd)
perror("socket[PF_INET,SOCK_DGRAM]"); perror("socket[PF_INET,SOCK_DGRAM]");
goto bad; goto bad;
} }
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface)); memcpy(drv->iface, params->ifname, sizeof(drv->iface));
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name)); os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
@ -1201,10 +1201,10 @@ madwifi_init(struct hostapd_data *hapd)
goto bad; goto bad;
if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr)) if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
goto bad; goto bad;
if (hapd->conf->bridge[0] != '\0') { if (params->bridge[0]) {
wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.", wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
hapd->conf->bridge); params->bridge[0]);
drv->sock_recv = l2_packet_init(hapd->conf->bridge, NULL, drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
ETH_P_EAPOL, handle_read, drv, ETH_P_EAPOL, handle_read, drv,
1); 1);
if (drv->sock_recv == NULL) if (drv->sock_recv == NULL)

View file

@ -704,7 +704,7 @@ bsd_set_ssid(const char *ifname, void *priv, const u8 *buf, int len)
} }
static void * static void *
bsd_init(struct hostapd_data *hapd) bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params)
{ {
struct bsd_driver_data *drv; struct bsd_driver_data *drv;

View file

@ -31,7 +31,6 @@
#include "priv_netlink.h" #include "priv_netlink.h"
#include "ieee802_11_defs.h" #include "ieee802_11_defs.h"
#include "../../hostapd/hostapd.h" #include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/hw_features.h" #include "../../hostapd/hw_features.h"
#include "../../hostapd/sta_flags.h" #include "../../hostapd/sta_flags.h"
@ -1071,7 +1070,8 @@ static void hostap_wireless_event_deinit(struct hostap_driver_data *drv)
} }
static void * hostap_init(struct hostapd_data *hapd) static void * hostap_init(struct hostapd_data *hapd,
struct wpa_init_params *params)
{ {
struct hostap_driver_data *drv; struct hostap_driver_data *drv;
@ -1083,7 +1083,7 @@ static void * hostap_init(struct hostapd_data *hapd)
drv->hapd = hapd; drv->hapd = hapd;
drv->ioctl_sock = drv->sock = -1; drv->ioctl_sock = drv->sock = -1;
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface)); memcpy(drv->iface, params->ifname, sizeof(drv->iface));
drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
if (drv->ioctl_sock < 0) { if (drv->ioctl_sock < 0) {

View file

@ -1230,7 +1230,7 @@ handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
} }
static void * static void *
madwifi_init(struct hostapd_data *hapd) madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
{ {
struct madwifi_driver_data *drv; struct madwifi_driver_data *drv;
struct ifreq ifr; struct ifreq ifr;
@ -1248,7 +1248,7 @@ madwifi_init(struct hostapd_data *hapd)
perror("socket[PF_INET,SOCK_DGRAM]"); perror("socket[PF_INET,SOCK_DGRAM]");
goto bad; goto bad;
} }
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface)); memcpy(drv->iface, params->ifname, sizeof(drv->iface));
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name)); os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
@ -1264,10 +1264,10 @@ madwifi_init(struct hostapd_data *hapd)
goto bad; goto bad;
if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr)) if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
goto bad; goto bad;
if (hapd->conf->bridge[0] != '\0') { if (params->bridge[0]) {
wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.", wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
hapd->conf->bridge); params->bridge[0]);
drv->sock_recv = l2_packet_init(hapd->conf->bridge, NULL, drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
ETH_P_EAPOL, handle_read, drv, ETH_P_EAPOL, handle_read, drv,
1); 1);
if (drv->sock_recv == NULL) if (drv->sock_recv == NULL)

View file

@ -3218,6 +3218,8 @@ const struct wpa_driver_ops wpa_driver_ndis_ops = {
NULL /* authenticate */, NULL /* authenticate */,
NULL /* set_beacon */, NULL /* set_beacon */,
NULL /* set_beacon_int */, NULL /* set_beacon_int */,
NULL /* hapd_init */,
NULL /* hapd_deinit */,
NULL /* set_ieee8021x */, NULL /* set_ieee8021x */,
NULL /* set_privacy */, NULL /* set_privacy */,
NULL /* hapd_set_key */, NULL /* hapd_set_key */,

View file

@ -54,7 +54,6 @@
#include <net/if_arp.h> #include <net/if_arp.h>
#include "../../hostapd/hostapd.h" #include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/sta_flags.h" #include "../../hostapd/sta_flags.h"
#include "ieee802_11_common.h" #include "ieee802_11_common.h"
@ -4453,7 +4452,8 @@ i802_get_neighbor_bss(void *priv, size_t *num)
} }
static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid) static void *i802_init(struct hostapd_data *hapd,
struct wpa_init_params *params)
{ {
struct wpa_driver_nl80211_data *drv; struct wpa_driver_nl80211_data *drv;
size_t i; size_t i;
@ -4465,20 +4465,19 @@ static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
} }
drv->hapd = hapd; drv->hapd = hapd;
memcpy(drv->ifname, hapd->conf->iface, sizeof(drv->ifname)); memcpy(drv->ifname, params->ifname, sizeof(drv->ifname));
memcpy(drv->bss.ifname, hapd->conf->iface, sizeof(drv->bss.ifname)); memcpy(drv->bss.ifname, params->ifname, sizeof(drv->bss.ifname));
drv->ifindex = if_nametoindex(drv->ifname); drv->ifindex = if_nametoindex(drv->ifname);
drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
drv->if_indices = drv->default_if_indices; drv->if_indices = drv->default_if_indices;
for (i = 0; i < hapd->iface->num_bss; i++) { for (i = 0; i < params->num_bridge; i++) {
struct hostapd_data *bss = hapd->iface->bss[i]; if (params->bridge[i])
if (bss->conf->bridge) add_ifidx(drv, if_nametoindex(params->bridge[i]));
add_ifidx(drv, if_nametoindex(bss->conf->bridge));
} }
drv->ht_40mhz_scan = hapd->iconf->secondary_channel != 0; drv->ht_40mhz_scan = params->ht_40mhz_scan;
if (i802_init_sockets(drv, bssid)) if (i802_init_sockets(drv, params->bssid))
goto failed; goto failed;
return drv; return drv;
@ -4489,12 +4488,6 @@ failed:
} }
static void *i802_init(struct hostapd_data *hapd)
{
return i802_init_bssid(hapd, NULL);
}
static void i802_deinit(void *priv) static void i802_deinit(void *priv)
{ {
struct wpa_driver_nl80211_data *drv = priv; struct wpa_driver_nl80211_data *drv = priv;
@ -4577,7 +4570,6 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
#endif /* CONFIG_AP || HOSTAPD */ #endif /* CONFIG_AP || HOSTAPD */
#ifdef HOSTAPD #ifdef HOSTAPD
.hapd_init = i802_init, .hapd_init = i802_init,
.init_bssid = i802_init_bssid,
.hapd_deinit = i802_deinit, .hapd_deinit = i802_deinit,
.hapd_set_key = i802_set_key, .hapd_set_key = i802_set_key,
.get_seqnum = i802_get_seqnum, .get_seqnum = i802_get_seqnum,

View file

@ -23,7 +23,8 @@ struct none_driver_data {
}; };
static void * none_driver_init(struct hostapd_data *hapd) static void * none_driver_init(struct hostapd_data *hapd,
struct wpa_init_params *params)
{ {
struct none_driver_data *drv; struct none_driver_data *drv;

View file

@ -1030,7 +1030,8 @@ static int prism54_init_sockets(struct prism54_driver_data *drv)
} }
static void * prism54_driver_init(struct hostapd_data *hapd) static void * prism54_driver_init(struct hostapd_data *hapd,
struct wpa_init_params *params)
{ {
struct prism54_driver_data *drv; struct prism54_driver_data *drv;
@ -1043,7 +1044,7 @@ static void * prism54_driver_init(struct hostapd_data *hapd)
drv->hapd = hapd; drv->hapd = hapd;
drv->pim_sock = drv->sock = -1; drv->pim_sock = drv->sock = -1;
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface)); memcpy(drv->iface, params->ifname, sizeof(drv->iface));
if (prism54_init_sockets(drv)) { if (prism54_init_sockets(drv)) {
free(drv); free(drv);

View file

@ -814,6 +814,8 @@ struct wpa_driver_ops wpa_driver_privsep_ops = {
NULL /* authenticate */, NULL /* authenticate */,
NULL /* set_beacon */, NULL /* set_beacon */,
NULL /* set_beacon_int */, NULL /* set_beacon_int */,
NULL /* hapd_init */,
NULL /* hapd_deinit */,
NULL /* set_ieee8021x */, NULL /* set_ieee8021x */,
NULL /* set_privacy */, NULL /* set_privacy */,
NULL /* hapd_set_key */, NULL /* hapd_set_key */,

View file

@ -38,7 +38,6 @@
#ifdef HOSTAPD #ifdef HOSTAPD
#include "../../hostapd/hostapd.h" #include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/wpa.h" #include "../../hostapd/wpa.h"
#include "../../hostapd/hw_features.h" #include "../../hostapd/hw_features.h"
#include "../../hostapd/wps_hostapd.h" #include "../../hostapd/wps_hostapd.h"
@ -1066,7 +1065,8 @@ static int test_driver_sta_add(const char *ifname, void *priv,
} }
static void * test_driver_init(struct hostapd_data *hapd) static void * test_driver_init(struct hostapd_data *hapd,
struct wpa_init_params *params)
{ {
struct test_driver_data *drv; struct test_driver_data *drv;
struct sockaddr_un addr_un; struct sockaddr_un addr_un;
@ -1090,35 +1090,35 @@ static void * test_driver_init(struct hostapd_data *hapd)
/* Generate a MAC address to help testing with multiple APs */ /* Generate a MAC address to help testing with multiple APs */
hapd->own_addr[0] = 0x02; /* locally administered */ hapd->own_addr[0] = 0x02; /* locally administered */
sha1_prf((const u8 *) hapd->conf->iface, strlen(hapd->conf->iface), sha1_prf((const u8 *) params->ifname, strlen(params->ifname),
"hostapd test bssid generation", "hostapd test bssid generation",
(const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len, params->ssid, params->ssid_len,
hapd->own_addr + 1, ETH_ALEN - 1); hapd->own_addr + 1, ETH_ALEN - 1);
os_strlcpy(drv->bss->ifname, hapd->conf->iface, IFNAMSIZ); os_strlcpy(drv->bss->ifname, params->ifname, IFNAMSIZ);
memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN); memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
if (hapd->conf->test_socket) { if (params->test_socket) {
if (strlen(hapd->conf->test_socket) >= if (os_strlen(params->test_socket) >=
sizeof(addr_un.sun_path)) { sizeof(addr_un.sun_path)) {
printf("Too long test_socket path\n"); printf("Too long test_socket path\n");
test_driver_free_priv(drv); test_driver_free_priv(drv);
return NULL; return NULL;
} }
if (strncmp(hapd->conf->test_socket, "DIR:", 4) == 0) { if (strncmp(params->test_socket, "DIR:", 4) == 0) {
size_t len = strlen(hapd->conf->test_socket) + 30; size_t len = strlen(params->test_socket) + 30;
drv->socket_dir = strdup(hapd->conf->test_socket + 4); drv->socket_dir = strdup(params->test_socket + 4);
drv->own_socket_path = malloc(len); drv->own_socket_path = malloc(len);
if (drv->own_socket_path) { if (drv->own_socket_path) {
snprintf(drv->own_socket_path, len, snprintf(drv->own_socket_path, len,
"%s/AP-" MACSTR, "%s/AP-" MACSTR,
hapd->conf->test_socket + 4, params->test_socket + 4,
MAC2STR(hapd->own_addr)); MAC2STR(hapd->own_addr));
} }
} else if (strncmp(hapd->conf->test_socket, "UDP:", 4) == 0) { } else if (strncmp(params->test_socket, "UDP:", 4) == 0) {
drv->udp_port = atoi(hapd->conf->test_socket + 4); drv->udp_port = atoi(params->test_socket + 4);
} else { } else {
drv->own_socket_path = strdup(hapd->conf->test_socket); drv->own_socket_path = strdup(params->test_socket);
} }
if (drv->own_socket_path == NULL && drv->udp_port == 0) { if (drv->own_socket_path == NULL && drv->udp_port == 0) {
test_driver_free_priv(drv); test_driver_free_priv(drv);
@ -2520,7 +2520,6 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
NULL /* set_beacon */, NULL /* set_beacon */,
NULL /* set_beacon_int */, NULL /* set_beacon_int */,
NULL /* hapd_init */, NULL /* hapd_init */,
NULL /* init_bssid */,
NULL /* hapd_deinit */, NULL /* hapd_deinit */,
NULL /* set_ieee8021x */, NULL /* set_ieee8021x */,
NULL /* set_privacy */, NULL /* set_privacy */,

View file

@ -31,7 +31,6 @@
#ifdef HOSTAPD #ifdef HOSTAPD
#include "eloop.h" #include "eloop.h"
#include "../../hostapd/hostapd.h" #include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/sta_info.h" #include "../../hostapd/sta_info.h"
#include "../../hostapd/accounting.h" #include "../../hostapd/accounting.h"
#endif /* HOSTAPD */ #endif /* HOSTAPD */
@ -336,7 +335,8 @@ static int wired_send_eapol(void *priv, const u8 *addr,
} }
static void * wired_driver_hapd_init(struct hostapd_data *hapd) static void * wired_driver_hapd_init(struct hostapd_data *hapd,
struct wpa_init_params *params)
{ {
struct wpa_driver_wired_data *drv; struct wpa_driver_wired_data *drv;
@ -347,8 +347,8 @@ static void * wired_driver_hapd_init(struct hostapd_data *hapd)
} }
drv->hapd = hapd; drv->hapd = hapd;
os_strlcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface)); os_strlcpy(drv->iface, params->ifname, sizeof(drv->iface));
drv->use_pae_group_addr = hapd->conf->use_pae_group_addr; drv->use_pae_group_addr = params->use_pae_group_addr;
if (wired_init_sockets(drv)) { if (wired_init_sockets(drv)) {
free(drv); free(drv);

View file

@ -54,7 +54,8 @@ struct ap_driver_data {
}; };
static void * ap_driver_init(struct hostapd_data *hapd) static void * ap_driver_init(struct hostapd_data *hapd,
struct wpa_init_params *params)
{ {
struct ap_driver_data *drv; struct ap_driver_data *drv;
struct wpa_supplicant *wpa_s = hapd->iface->owner; struct wpa_supplicant *wpa_s = hapd->iface->owner;