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++;
}
} else if (os_strcmp(buf, "bssid") == 0) {
if (bss == conf->bss &&
(!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)) {
if (hwaddr_aton(pos, bss->bssid)) {
wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
"item", line);
errors++;

View file

@ -20,19 +20,37 @@
#include "config.h"
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)
return NULL;
return hapd->driver->hapd_init(hapd);
}
static inline void *
hostapd_driver_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
{
if (hapd->driver == NULL || hapd->driver->init_bssid == NULL)
os_memset(&params, 0, sizeof(params));
params.bssid = bssid;
params.ifname = hapd->conf->iface;
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 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

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
* configured with a pointer to this driver interface.
*/
if (b[0] | b[1] | b[2] | b[3] | b[4] | b[5]) {
hapd->drv_priv = hostapd_driver_init_bssid(hapd, b);
} else {
hapd->drv_priv = hostapd_driver_init(hapd);
}
if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
b = NULL;
hapd->drv_priv = hostapd_driver_init(hapd, b);
if (hapd->drv_priv == NULL) {
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 */
};
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
@ -1197,8 +1209,8 @@ struct wpa_driver_ops {
int (*set_beacon_int)(void *priv, int value);
void * (*hapd_init)(struct hostapd_data *hapd);
void * (*init_bssid)(struct hostapd_data *hapd, const u8 *bssid);
void * (*hapd_init)(struct hostapd_data *hapd,
struct wpa_init_params *params);
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 *
madwifi_init(struct hostapd_data *hapd)
madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
{
struct madwifi_driver_data *drv;
struct ifreq ifr;
@ -1185,7 +1185,7 @@ madwifi_init(struct hostapd_data *hapd)
perror("socket[PF_INET,SOCK_DGRAM]");
goto bad;
}
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
memcpy(drv->iface, params->ifname, sizeof(drv->iface));
memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
@ -1201,10 +1201,10 @@ madwifi_init(struct hostapd_data *hapd)
goto bad;
if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
goto bad;
if (hapd->conf->bridge[0] != '\0') {
if (params->bridge[0]) {
wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
hapd->conf->bridge);
drv->sock_recv = l2_packet_init(hapd->conf->bridge, NULL,
params->bridge[0]);
drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
ETH_P_EAPOL, handle_read, drv,
1);
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 *
bsd_init(struct hostapd_data *hapd)
bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params)
{
struct bsd_driver_data *drv;

View file

@ -31,7 +31,6 @@
#include "priv_netlink.h"
#include "ieee802_11_defs.h"
#include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/hw_features.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;
@ -1083,7 +1083,7 @@ static void * hostap_init(struct hostapd_data *hapd)
drv->hapd = hapd;
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);
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 *
madwifi_init(struct hostapd_data *hapd)
madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
{
struct madwifi_driver_data *drv;
struct ifreq ifr;
@ -1248,7 +1248,7 @@ madwifi_init(struct hostapd_data *hapd)
perror("socket[PF_INET,SOCK_DGRAM]");
goto bad;
}
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
memcpy(drv->iface, params->ifname, sizeof(drv->iface));
memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
@ -1264,10 +1264,10 @@ madwifi_init(struct hostapd_data *hapd)
goto bad;
if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
goto bad;
if (hapd->conf->bridge[0] != '\0') {
if (params->bridge[0]) {
wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
hapd->conf->bridge);
drv->sock_recv = l2_packet_init(hapd->conf->bridge, NULL,
params->bridge[0]);
drv->sock_recv = l2_packet_init(params->bridge[0], NULL,
ETH_P_EAPOL, handle_read, drv,
1);
if (drv->sock_recv == NULL)

View file

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

View file

@ -54,7 +54,6 @@
#include <net/if_arp.h>
#include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/sta_flags.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;
size_t i;
@ -4465,20 +4465,19 @@ static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
}
drv->hapd = hapd;
memcpy(drv->ifname, hapd->conf->iface, sizeof(drv->ifname));
memcpy(drv->bss.ifname, hapd->conf->iface, sizeof(drv->bss.ifname));
memcpy(drv->ifname, params->ifname, sizeof(drv->ifname));
memcpy(drv->bss.ifname, params->ifname, sizeof(drv->bss.ifname));
drv->ifindex = if_nametoindex(drv->ifname);
drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
drv->if_indices = drv->default_if_indices;
for (i = 0; i < hapd->iface->num_bss; i++) {
struct hostapd_data *bss = hapd->iface->bss[i];
if (bss->conf->bridge)
add_ifidx(drv, if_nametoindex(bss->conf->bridge));
for (i = 0; i < params->num_bridge; i++) {
if (params->bridge[i])
add_ifidx(drv, if_nametoindex(params->bridge[i]));
}
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;
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)
{
struct wpa_driver_nl80211_data *drv = priv;
@ -4577,7 +4570,6 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
#endif /* CONFIG_AP || HOSTAPD */
#ifdef HOSTAPD
.hapd_init = i802_init,
.init_bssid = i802_init_bssid,
.hapd_deinit = i802_deinit,
.hapd_set_key = i802_set_key,
.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;

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;
@ -1043,7 +1044,7 @@ static void * prism54_driver_init(struct hostapd_data *hapd)
drv->hapd = hapd;
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)) {
free(drv);

View file

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

View file

@ -38,7 +38,6 @@
#ifdef HOSTAPD
#include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/wpa.h"
#include "../../hostapd/hw_features.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 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 */
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",
(const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len,
params->ssid, params->ssid_len,
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);
if (hapd->conf->test_socket) {
if (strlen(hapd->conf->test_socket) >=
if (params->test_socket) {
if (os_strlen(params->test_socket) >=
sizeof(addr_un.sun_path)) {
printf("Too long test_socket path\n");
test_driver_free_priv(drv);
return NULL;
}
if (strncmp(hapd->conf->test_socket, "DIR:", 4) == 0) {
size_t len = strlen(hapd->conf->test_socket) + 30;
drv->socket_dir = strdup(hapd->conf->test_socket + 4);
if (strncmp(params->test_socket, "DIR:", 4) == 0) {
size_t len = strlen(params->test_socket) + 30;
drv->socket_dir = strdup(params->test_socket + 4);
drv->own_socket_path = malloc(len);
if (drv->own_socket_path) {
snprintf(drv->own_socket_path, len,
"%s/AP-" MACSTR,
hapd->conf->test_socket + 4,
params->test_socket + 4,
MAC2STR(hapd->own_addr));
}
} else if (strncmp(hapd->conf->test_socket, "UDP:", 4) == 0) {
drv->udp_port = atoi(hapd->conf->test_socket + 4);
} else if (strncmp(params->test_socket, "UDP:", 4) == 0) {
drv->udp_port = atoi(params->test_socket + 4);
} 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) {
test_driver_free_priv(drv);
@ -2520,7 +2520,6 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
NULL /* set_beacon */,
NULL /* set_beacon_int */,
NULL /* hapd_init */,
NULL /* init_bssid */,
NULL /* hapd_deinit */,
NULL /* set_ieee8021x */,
NULL /* set_privacy */,

View file

@ -31,7 +31,6 @@
#ifdef HOSTAPD
#include "eloop.h"
#include "../../hostapd/hostapd.h"
#include "../../hostapd/config.h"
#include "../../hostapd/sta_info.h"
#include "../../hostapd/accounting.h"
#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;
@ -347,8 +347,8 @@ static void * wired_driver_hapd_init(struct hostapd_data *hapd)
}
drv->hapd = hapd;
os_strlcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
drv->use_pae_group_addr = hapd->conf->use_pae_group_addr;
os_strlcpy(drv->iface, params->ifname, sizeof(drv->iface));
drv->use_pae_group_addr = params->use_pae_group_addr;
if (wired_init_sockets(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 wpa_supplicant *wpa_s = hapd->iface->owner;