Provide own_addr buffer in hapd_init() parameters

This reduces number of places in driver wrapper that would need to
dereference struct hostapd_data pointer directly.
This commit is contained in:
Jouni Malinen 2009-04-17 11:55:51 +03:00 committed by Jouni Malinen
parent 731723a5bd
commit 412036f5f0
10 changed files with 29 additions and 24 deletions

View File

@ -46,6 +46,9 @@ hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
if (bss->conf->bridge[0]) if (bss->conf->bridge[0])
params.bridge[i] = bss->conf->bridge; params.bridge[i] = bss->conf->bridge;
} }
params.own_addr = hapd->own_addr;
ret = hapd->driver->hapd_init(hapd, &params); ret = hapd->driver->hapd_init(hapd, &params);
os_free(params.bridge); os_free(params.bridge);

View File

@ -504,6 +504,8 @@ struct wpa_init_params {
int use_pae_group_addr; int use_pae_group_addr;
char **bridge; char **bridge;
size_t num_bridge; size_t num_bridge;
u8 *own_addr; /* buffer for writing own MAC address */
}; };

View File

@ -1203,7 +1203,7 @@ madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
handle_read, drv, 1); handle_read, drv, 1);
if (drv->sock_xmit == NULL) if (drv->sock_xmit == NULL)
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, params->own_addr))
goto bad; goto bad;
if (params->bridge[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.",

View File

@ -722,13 +722,13 @@ bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params)
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));
drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL, drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
handle_read, drv, 1); handle_read, drv, 1);
if (drv->sock_xmit == NULL) if (drv->sock_xmit == NULL)
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, params->own_addr))
goto bad; goto bad;
bsd_set_iface_flags(drv, 0); /* mark down during setup */ bsd_set_iface_flags(drv, 0); /* mark down during setup */

View File

@ -234,7 +234,7 @@ static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
} }
static int hostap_init_sockets(struct hostap_driver_data *drv) static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
{ {
struct ifreq ifr; struct ifreq ifr;
struct sockaddr_ll addr; struct sockaddr_ll addr;
@ -284,7 +284,7 @@ static int hostap_init_sockets(struct hostap_driver_data *drv)
ifr.ifr_hwaddr.sa_family); ifr.ifr_hwaddr.sa_family);
return -1; return -1;
} }
memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); os_memcpy(own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
return 0; return 0;
} }
@ -1098,7 +1098,8 @@ static void * hostap_init(struct hostapd_data *hapd,
return NULL; return NULL;
} }
if (hostap_init_sockets(drv) || hostap_wireless_event_init(drv)) { if (hostap_init_sockets(drv, params->own_addr) ||
hostap_wireless_event_init(drv)) {
close(drv->ioctl_sock); close(drv->ioctl_sock);
free(drv); free(drv);
return NULL; return NULL;

View File

@ -1266,7 +1266,7 @@ madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
handle_read, drv, 1); handle_read, drv, 1);
if (drv->sock_xmit == NULL) if (drv->sock_xmit == NULL)
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, params->own_addr))
goto bad; goto bad;
if (params->bridge[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.",

View File

@ -3987,7 +3987,7 @@ static void *i802_init(struct hostapd_data *hapd,
goto failed; goto failed;
} }
if (get_ifhwaddr(drv, drv->ifname, drv->hapd->own_addr)) if (get_ifhwaddr(drv, drv->ifname, params->own_addr))
goto failed; goto failed;
return drv; return drv;

View File

@ -941,9 +941,9 @@ static void handle_802_3(int sock, void *eloop_ctx, void *sock_ctx)
} }
static int prism54_init_sockets(struct prism54_driver_data *drv) static int prism54_init_sockets(struct prism54_driver_data *drv,
struct wpa_init_params *params)
{ {
struct hostapd_data *hapd = drv->hapd;
struct ifreq ifr; struct ifreq ifr;
struct sockaddr_ll addr; struct sockaddr_ll addr;
@ -960,9 +960,9 @@ static int prism54_init_sockets(struct prism54_driver_data *drv)
} }
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
if (hapd->conf->bridge[0] != '\0') { if (params->num_bridge && params->bridge[0]) {
printf("opening bridge: %s\n", hapd->conf->bridge); printf("opening bridge: %s\n", params->bridge[0]);
os_strlcpy(ifr.ifr_name, hapd->conf->bridge, os_strlcpy(ifr.ifr_name, params->bridge[0],
sizeof(ifr.ifr_name)); sizeof(ifr.ifr_name));
} else { } else {
os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name)); os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
@ -996,7 +996,7 @@ static int prism54_init_sockets(struct prism54_driver_data *drv)
ifr.ifr_hwaddr.sa_family); ifr.ifr_hwaddr.sa_family);
return -1; return -1;
} }
memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); memcpy(params->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
drv->pim_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); drv->pim_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (drv->pim_sock < 0) { if (drv->pim_sock < 0) {
@ -1048,7 +1048,7 @@ static void * prism54_driver_init(struct hostapd_data *hapd,
drv->pim_sock = drv->sock = -1; drv->pim_sock = drv->sock = -1;
memcpy(drv->iface, params->ifname, sizeof(drv->iface)); memcpy(drv->iface, params->ifname, sizeof(drv->iface));
if (prism54_init_sockets(drv)) { if (prism54_init_sockets(drv, params)) {
free(drv); free(drv);
return NULL; return NULL;
} }

View File

@ -1091,14 +1091,14 @@ static void * test_driver_init(struct hostapd_data *hapd,
drv->hapd = hapd; drv->hapd = 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 */ params->own_addr[0] = 0x02; /* locally administered */
sha1_prf((const u8 *) params->ifname, strlen(params->ifname), sha1_prf((const u8 *) params->ifname, strlen(params->ifname),
"hostapd test bssid generation", "hostapd test bssid generation",
params->ssid, params->ssid_len, params->ssid, params->ssid_len,
hapd->own_addr + 1, ETH_ALEN - 1); params->own_addr + 1, ETH_ALEN - 1);
os_strlcpy(drv->bss->ifname, params->ifname, IFNAMSIZ); os_strlcpy(drv->bss->ifname, params->ifname, IFNAMSIZ);
memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN); memcpy(drv->bss->bssid, params->own_addr, ETH_ALEN);
if (params->test_socket) { if (params->test_socket) {
if (os_strlen(params->test_socket) >= if (os_strlen(params->test_socket) >=
@ -1115,7 +1115,7 @@ static void * test_driver_init(struct hostapd_data *hapd,
snprintf(drv->own_socket_path, len, snprintf(drv->own_socket_path, len,
"%s/AP-" MACSTR, "%s/AP-" MACSTR,
params->test_socket + 4, params->test_socket + 4,
MAC2STR(hapd->own_addr)); MAC2STR(params->own_addr));
} }
} else if (strncmp(params->test_socket, "UDP:", 4) == 0) { } else if (strncmp(params->test_socket, "UDP:", 4) == 0) {
drv->udp_port = atoi(params->test_socket + 4); drv->udp_port = atoi(params->test_socket + 4);

View File

@ -30,9 +30,8 @@
#ifdef HOSTAPD #ifdef HOSTAPD
#include "eloop.h" #include "eloop.h"
#include "../../hostapd/hostapd.h" #include "../../hostapd/hostapd_defs.h"
#include "../../hostapd/sta_info.h" #include "../../hostapd/sta_info.h"
#include "../../hostapd/accounting.h"
#endif /* HOSTAPD */ #endif /* HOSTAPD */
static const u8 pae_group_addr[ETH_ALEN] = static const u8 pae_group_addr[ETH_ALEN] =
@ -185,7 +184,7 @@ static void handle_dhcp(int sock, void *eloop_ctx, void *sock_ctx)
} }
static int wired_init_sockets(struct wpa_driver_wired_data *drv) static int wired_init_sockets(struct wpa_driver_wired_data *drv, u8 *own_addr)
{ {
struct hostapd_data *hapd = drv->hapd; struct hostapd_data *hapd = drv->hapd;
struct ifreq ifr; struct ifreq ifr;
@ -248,7 +247,7 @@ static int wired_init_sockets(struct wpa_driver_wired_data *drv)
ifr.ifr_hwaddr.sa_family); ifr.ifr_hwaddr.sa_family);
return -1; return -1;
} }
memcpy(hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); memcpy(own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
/* setup dhcp listen socket for sta detection */ /* setup dhcp listen socket for sta detection */
if ((drv->dhcp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { if ((drv->dhcp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
@ -350,7 +349,7 @@ static void * wired_driver_hapd_init(struct hostapd_data *hapd,
os_strlcpy(drv->iface, params->ifname, sizeof(drv->iface)); os_strlcpy(drv->iface, params->ifname, sizeof(drv->iface));
drv->use_pae_group_addr = params->use_pae_group_addr; drv->use_pae_group_addr = params->use_pae_group_addr;
if (wired_init_sockets(drv)) { if (wired_init_sockets(drv, params->own_addr)) {
free(drv); free(drv);
return NULL; return NULL;
} }