Add BSS ctx to if_add() driver op

This remove the need from driver_test.c to go through internal hostapd
structures to find the appropriate BSS when reporting events on secondary
BSSes.
This commit is contained in:
Jouni Malinen 2009-12-13 18:54:11 +02:00
parent 9b5d2b8b9c
commit 8043e72589
6 changed files with 23 additions and 71 deletions

View file

@ -362,12 +362,12 @@ hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
static inline int
hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
const char *ifname, const u8 *addr)
const char *ifname, const u8 *addr, void *bss_ctx)
{
if (hapd->driver == NULL || hapd->driver->if_add == NULL)
return -1;
return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
ifname, addr);
ifname, addr, bss_ctx);
}
static inline int

View file

@ -1040,7 +1040,7 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
hapd->interface_added = 1;
if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
hapd->conf->iface, hapd->own_addr)) {
hapd->conf->iface, hapd->own_addr, hapd)) {
wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
MACSTR ")", MAC2STR(hapd->own_addr));
return -1;

View file

@ -680,7 +680,8 @@ static int vlan_dynamic_add(struct hostapd_data *hapd,
{
while (vlan) {
if (vlan->vlan_id != VLAN_ID_WILDCARD &&
hostapd_if_add(hapd, WPA_IF_AP_VLAN, vlan->ifname, NULL)) {
hostapd_if_add(hapd, WPA_IF_AP_VLAN, vlan->ifname, NULL,
NULL)) {
if (errno != EEXIST) {
printf("Could not add VLAN iface: %s: %s\n",
vlan->ifname, strerror(errno));
@ -775,7 +776,7 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
pos);
os_free(ifname);
if (hostapd_if_add(hapd, WPA_IF_AP_VLAN, n->ifname, NULL)) {
if (hostapd_if_add(hapd, WPA_IF_AP_VLAN, n->ifname, NULL, NULL)) {
os_free(n);
return NULL;
}

View file

@ -1398,11 +1398,12 @@ struct wpa_driver_ops {
* @ifname: Interface name for the new virtual interface
* @addr: Local address to use for the interface or %NULL to use the
* parent interface address
* @bss_ctx: BSS context for %WPA_IF_AP_BSS interfaces
* Returns: 0 on success, -1 on failure
*/
int (*if_add)(const char *iface, void *priv,
enum wpa_driver_if_type type, const char *ifname,
const u8 *addr);
const u8 *addr, void *bss_ctx);
/**
* if_remove - Remove a virtual interface

View file

@ -4506,7 +4506,8 @@ static enum nl80211_iftype wpa_driver_nl80211_if_type(
static int wpa_driver_nl80211_if_add(const char *iface, void *priv,
enum wpa_driver_if_type type,
const char *ifname, const u8 *addr)
const char *ifname, const u8 *addr,
void *bss_ctx)
{
struct wpa_driver_nl80211_data *drv = priv;
int ifidx;

View file

@ -34,8 +34,6 @@
#include "crypto/sha1.h"
#include "common/ieee802_11_defs.h"
#include "../../hostapd/hostapd.h"
struct test_client_socket {
struct test_client_socket *next;
@ -47,6 +45,7 @@ struct test_client_socket {
struct test_driver_bss {
struct test_driver_bss *next;
void *bss_ctx;
char ifname[IFNAMSIZ + 1];
u8 bssid[ETH_ALEN];
u8 *ie;
@ -546,56 +545,6 @@ static void test_driver_scan(struct wpa_driver_test_data *drv,
}
static struct hostapd_data *
test_driver_get_hapd(struct wpa_driver_test_data *drv,
struct test_driver_bss *bss)
{
#ifdef HOSTAPD
struct hostapd_iface *iface = drv->hapd->iface;
struct hostapd_data *hapd = NULL;
size_t i;
if (bss == NULL) {
wpa_printf(MSG_DEBUG, "%s: bss == NULL", __func__);
return NULL;
}
for (i = 0; i < iface->num_bss; i++) {
hapd = iface->bss[i];
if (memcmp(hapd->own_addr, bss->bssid, ETH_ALEN) == 0)
break;
}
if (i == iface->num_bss) {
wpa_printf(MSG_DEBUG, "%s: no matching interface entry found "
"for BSSID " MACSTR, __func__, MAC2STR(bss->bssid));
return NULL;
}
return hapd;
#else /* HOSTAPD */
return NULL;
#endif /* HOSTAPD */
}
static int test_driver_new_sta(struct wpa_driver_test_data *drv,
struct test_driver_bss *bss, const u8 *addr,
const u8 *ie, size_t ielen)
{
struct hostapd_data *hapd;
hapd = test_driver_get_hapd(drv, bss);
if (hapd == NULL)
return -1;
#ifdef HOSTAPD
return hostapd_notif_assoc(hapd, addr, ie, ielen);
#else /* HOSTAPD */
return -1;
#endif /* HOSTAPD */
}
static void test_driver_assoc(struct wpa_driver_test_data *drv,
struct sockaddr_un *from, socklen_t fromlen,
char *data)
@ -667,9 +616,10 @@ static void test_driver_assoc(struct wpa_driver_test_data *drv,
sendto(drv->test_socket, cmd, strlen(cmd), 0,
(struct sockaddr *) from, fromlen);
if (test_driver_new_sta(drv, bss, cli->addr, ie, ielen) < 0) {
#ifdef HOSTAPD
if (hostapd_notif_assoc(bss->bss_ctx, cli->addr, ie, ielen) < 0)
wpa_printf(MSG_DEBUG, "test_driver: failed to add new STA");
}
#endif /* HOSTAPD */
}
@ -710,11 +660,8 @@ static void test_driver_eapol(struct wpa_driver_test_data *drv,
#ifdef HOSTAPD
cli = test_driver_get_cli(drv, from, fromlen);
if (cli) {
struct hostapd_data *hapd;
hapd = test_driver_get_hapd(drv, cli->bss);
if (hapd == NULL)
return;
hostapd_eapol_receive(hapd, cli->addr, data, datalen);
hostapd_eapol_receive(cli->bss->bss_ctx, cli->addr, data,
datalen);
} else {
wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
"client");
@ -984,7 +931,8 @@ static int test_driver_sta_disassoc(void *priv, const u8 *own_addr,
}
static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid,
void *bss_ctx)
{
struct wpa_driver_test_data *drv = priv;
struct test_driver_bss *bss;
@ -996,6 +944,7 @@ static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
if (bss == NULL)
return -1;
bss->bss_ctx = bss_ctx;
os_strlcpy(bss->ifname, ifname, IFNAMSIZ);
memcpy(bss->bssid, bssid, ETH_ALEN);
@ -1045,12 +994,12 @@ static int test_driver_bss_remove(void *priv, const char *ifname)
static int test_driver_if_add(const char *iface, void *priv,
enum wpa_driver_if_type type, const char *ifname,
const u8 *addr)
const u8 *addr, void *bss_ctx)
{
wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s)",
__func__, iface, type, ifname);
wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s bss_ctx=%p)",
__func__, iface, type, ifname, bss_ctx);
if (type == WPA_IF_AP_BSS)
return test_driver_bss_add(priv, ifname, addr);
return test_driver_bss_add(priv, ifname, addr, bss_ctx);
return 0;
}