Provide own_addr buffer in hapd_init() parameters
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 17 Apr 2009 08:55:51 +0000 (11:55 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 17 Apr 2009 08:55:51 +0000 (11:55 +0300)
This reduces number of places in driver wrapper that would need to
dereference struct hostapd_data pointer directly.

hostapd/driver_i.h
src/drivers/driver.h
src/drivers/driver_atheros.c
src/drivers/driver_bsd.c
src/drivers/driver_hostap.c
src/drivers/driver_madwifi.c
src/drivers/driver_nl80211.c
src/drivers/driver_prism54.c
src/drivers/driver_test.c
src/drivers/driver_wired.c

index dc2ea2b..3fe0594 100644 (file)
@@ -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);
 
index db87a58..e837ca3 100644 (file)
@@ -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 */
 };
 
 
index 96b7051..f1241f5 100644 (file)
@@ -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.",
index 24f1157..b6b6d8e 100644 (file)
@@ -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 */
index 7538b9a..d2d6af2 100644 (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 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;
index 336ce31..191fd31 100644 (file)
@@ -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.",
index 6e3a191..5dd42a4 100644 (file)
@@ -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;
index f2837cc..f2c6916 100644 (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 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;
        }
index 84c3836..ecc7487 100644 (file)
@@ -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);
index be8cc8f..a3657e5 100644 (file)
@@ -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;
        }