Browse Source

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.
Jouni Malinen 16 years ago
parent
commit
412036f5f0

+ 3 - 0
hostapd/driver_i.h

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

+ 2 - 0
src/drivers/driver.h

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

+ 1 - 1
src/drivers/driver_atheros.c

@@ -1203,7 +1203,7 @@ madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
 					handle_read, drv, 1);
 	if (drv->sock_xmit == NULL)
 		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;
 	if (params->bridge[0]) {
 		wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",

+ 2 - 2
src/drivers/driver_bsd.c

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

+ 4 - 3
src/drivers/driver_hostap.c

@@ -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 sockaddr_ll addr;
@@ -284,7 +284,7 @@ static int hostap_init_sockets(struct hostap_driver_data *drv)
 		       ifr.ifr_hwaddr.sa_family);
 		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;
 }
@@ -1098,7 +1098,8 @@ static void * hostap_init(struct hostapd_data *hapd,
 		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);
 		free(drv);
 		return NULL;

+ 1 - 1
src/drivers/driver_madwifi.c

@@ -1266,7 +1266,7 @@ madwifi_init(struct hostapd_data *hapd, struct wpa_init_params *params)
 					handle_read, drv, 1);
 	if (drv->sock_xmit == NULL)
 		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;
 	if (params->bridge[0]) {
 		wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",

+ 1 - 1
src/drivers/driver_nl80211.c

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

+ 7 - 7
src/drivers/driver_prism54.c

@@ -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 sockaddr_ll addr;
 
@@ -960,9 +960,9 @@ static int prism54_init_sockets(struct prism54_driver_data *drv)
 	}
 
         memset(&ifr, 0, sizeof(ifr));
-	if (hapd->conf->bridge[0] != '\0') {
-		printf("opening bridge: %s\n", hapd->conf->bridge);
-		os_strlcpy(ifr.ifr_name, hapd->conf->bridge,
+	if (params->num_bridge && params->bridge[0]) {
+		printf("opening bridge: %s\n", params->bridge[0]);
+		os_strlcpy(ifr.ifr_name, params->bridge[0],
 			   sizeof(ifr.ifr_name));
 	} else {
 		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);
 		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));
 	if (drv->pim_sock < 0) {
@@ -1048,7 +1048,7 @@ static void * prism54_driver_init(struct hostapd_data *hapd,
 	drv->pim_sock = drv->sock = -1;
 	memcpy(drv->iface, params->ifname, sizeof(drv->iface));
 
-	if (prism54_init_sockets(drv)) {
+	if (prism54_init_sockets(drv, params)) {
 		free(drv);
 		return NULL;
 	}

+ 4 - 4
src/drivers/driver_test.c

@@ -1091,14 +1091,14 @@ static void * test_driver_init(struct hostapd_data *hapd,
 	drv->hapd = hapd;
 
 	/* 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),
 		 "hostapd test bssid generation",
 		 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);
-	memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
+	memcpy(drv->bss->bssid, params->own_addr, ETH_ALEN);
 
 	if (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,
 					 "%s/AP-" MACSTR,
 					 params->test_socket + 4,
-					 MAC2STR(hapd->own_addr));
+					 MAC2STR(params->own_addr));
 			}
 		} else if (strncmp(params->test_socket, "UDP:", 4) == 0) {
 			drv->udp_port = atoi(params->test_socket + 4);

+ 4 - 5
src/drivers/driver_wired.c

@@ -30,9 +30,8 @@
 
 #ifdef HOSTAPD
 #include "eloop.h"
-#include "../../hostapd/hostapd.h"
+#include "../../hostapd/hostapd_defs.h"
 #include "../../hostapd/sta_info.h"
-#include "../../hostapd/accounting.h"
 #endif /* HOSTAPD */
 
 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 ifreq ifr;
@@ -248,7 +247,7 @@ static int wired_init_sockets(struct wpa_driver_wired_data *drv)
 		       ifr.ifr_hwaddr.sa_family);
 		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 */
 	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));
 	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);
 		return NULL;
 	}