Merge hostapd driver init functions into one
[wpasupplicant] / src / drivers / driver_test.c
index 700e98d..185a1c6 100644 (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"
@@ -77,6 +76,46 @@ struct test_driver_data {
        int udp_port;
 };
 
+#else /* HOSTAPD */
+
+struct wpa_driver_test_global {
+       int dummy;
+};
+
+struct wpa_driver_test_data {
+       struct wpa_driver_test_global *global;
+       void *ctx;
+       u8 own_addr[ETH_ALEN];
+       int test_socket;
+#ifdef DRIVER_TEST_UNIX
+       struct sockaddr_un hostapd_addr;
+#endif /* DRIVER_TEST_UNIX */
+       int hostapd_addr_set;
+       struct sockaddr_in hostapd_addr_udp;
+       int hostapd_addr_udp_set;
+       char *own_socket_path;
+       char *test_dir;
+       u8 bssid[ETH_ALEN];
+       u8 ssid[32];
+       size_t ssid_len;
+#define MAX_SCAN_RESULTS 30
+       struct wpa_scan_res *scanres[MAX_SCAN_RESULTS];
+       size_t num_scanres;
+       int use_associnfo;
+       u8 assoc_wpa_ie[80];
+       size_t assoc_wpa_ie_len;
+       int use_mlme;
+       int associated;
+       u8 *probe_req_ie;
+       size_t probe_req_ie_len;
+       int ibss;
+       int privacy;
+};
+
+#endif /* HOSTAPD */
+
+
+#ifdef HOSTAPD
 
 static void test_driver_free_bss(struct test_driver_bss *bss)
 {
@@ -257,8 +296,7 @@ static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
 }
 
 
-static int test_driver_send_mgmt_frame(void *priv, const void *buf,
-                                      size_t len, int flags)
+static int wpa_driver_test_send_mlme(void *priv, const u8 *buf, size_t len)
 {
        struct test_driver_data *drv = priv;
        struct msghdr msg;
@@ -821,68 +859,6 @@ static int test_driver_sta_disassoc(void *priv, const u8 *addr, int reason)
 }
 
 
-static struct hostapd_hw_modes *
-test_driver_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
-{
-       struct hostapd_hw_modes *modes;
-
-       *num_modes = 3;
-       *flags = 0;
-       modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
-       if (modes == NULL)
-               return NULL;
-       modes[0].mode = HOSTAPD_MODE_IEEE80211G;
-       modes[0].num_channels = 1;
-       modes[0].num_rates = 1;
-       modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-       modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
-       if (modes[0].channels == NULL || modes[0].rates == NULL) {
-               hostapd_free_hw_features(modes, *num_modes);
-               return NULL;
-       }
-       modes[0].channels[0].chan = 1;
-       modes[0].channels[0].freq = 2412;
-       modes[0].channels[0].flag = 0;
-       modes[0].rates[0].rate = 10;
-       modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
-               HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
-
-       modes[1].mode = HOSTAPD_MODE_IEEE80211B;
-       modes[1].num_channels = 1;
-       modes[1].num_rates = 1;
-       modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-       modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
-       if (modes[1].channels == NULL || modes[1].rates == NULL) {
-               hostapd_free_hw_features(modes, *num_modes);
-               return NULL;
-       }
-       modes[1].channels[0].chan = 1;
-       modes[1].channels[0].freq = 2412;
-       modes[1].channels[0].flag = 0;
-       modes[1].rates[0].rate = 10;
-       modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
-               HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
-
-       modes[2].mode = HOSTAPD_MODE_IEEE80211A;
-       modes[2].num_channels = 1;
-       modes[2].num_rates = 1;
-       modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-       modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
-       if (modes[2].channels == NULL || modes[2].rates == NULL) {
-               hostapd_free_hw_features(modes, *num_modes);
-               return NULL;
-       }
-       modes[2].channels[0].chan = 60;
-       modes[2].channels[0].freq = 5300;
-       modes[2].channels[0].flag = 0;
-       modes[2].rates[0].rate = 60;
-       modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
-               HOSTAPD_RATE_MANDATORY;
-
-       return modes;
-}
-
-
 static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
 {
        struct test_driver_data *drv = priv;
@@ -1089,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;
@@ -1113,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);
@@ -1215,70 +1192,8 @@ static void test_driver_deinit(void *priv)
        test_driver_free_priv(drv);
 }
 
-
-const struct wpa_driver_ops wpa_driver_test_ops = {
-       .name = "test",
-       .hapd_init = test_driver_init,
-       .hapd_deinit = test_driver_deinit,
-       .hapd_send_eapol = test_driver_send_eapol,
-       .send_mgmt_frame = test_driver_send_mgmt_frame,
-       .set_generic_elem = test_driver_set_generic_elem,
-       .sta_deauth = test_driver_sta_deauth,
-       .sta_disassoc = test_driver_sta_disassoc,
-       .get_hw_feature_data = test_driver_get_hw_feature_data,
-       .bss_add = test_driver_bss_add,
-       .bss_remove = test_driver_bss_remove,
-       .if_add = test_driver_if_add,
-       .if_update = test_driver_if_update,
-       .if_remove = test_driver_if_remove,
-       .valid_bss_mask = test_driver_valid_bss_mask,
-       .hapd_set_ssid = test_driver_set_ssid,
-       .set_privacy = test_driver_set_privacy,
-       .hapd_set_key = test_driver_set_key,
-       .set_sta_vlan = test_driver_set_sta_vlan,
-       .sta_add = test_driver_sta_add,
-       .send_ether = test_driver_send_ether,
-       .set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
-       .set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
-};
-
 #else /* HOSTAPD */
 
-struct wpa_driver_test_global {
-       int dummy;
-};
-
-struct wpa_driver_test_data {
-       struct wpa_driver_test_global *global;
-       void *ctx;
-       u8 own_addr[ETH_ALEN];
-       int test_socket;
-#ifdef DRIVER_TEST_UNIX
-       struct sockaddr_un hostapd_addr;
-#endif /* DRIVER_TEST_UNIX */
-       int hostapd_addr_set;
-       struct sockaddr_in hostapd_addr_udp;
-       int hostapd_addr_udp_set;
-       char *own_socket_path;
-       char *test_dir;
-       u8 bssid[ETH_ALEN];
-       u8 ssid[32];
-       size_t ssid_len;
-#define MAX_SCAN_RESULTS 30
-       struct wpa_scan_res *scanres[MAX_SCAN_RESULTS];
-       size_t num_scanres;
-       int use_associnfo;
-       u8 assoc_wpa_ie[80];
-       size_t assoc_wpa_ie_len;
-       int use_mlme;
-       int associated;
-       u8 *probe_req_ie;
-       size_t probe_req_ie_len;
-       int ibss;
-       int privacy;
-};
-
-
 static void wpa_driver_test_poll(void *eloop_ctx, void *timeout_ctx)
 {
        struct wpa_driver_test_data *drv = eloop_ctx;
@@ -2256,36 +2171,6 @@ static int wpa_driver_test_mlme_setprotection(void *priv, const u8 *addr,
 
 
 #ifdef CONFIG_CLIENT_MLME
-static struct hostapd_hw_modes *
-wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
-{
-       struct hostapd_hw_modes *modes;
-
-       *num_modes = 1;
-       *flags = 0;
-       modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
-       if (modes == NULL)
-               return NULL;
-       modes[0].mode = HOSTAPD_MODE_IEEE80211G;
-       modes[0].num_channels = 1;
-       modes[0].num_rates = 1;
-       modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-       modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
-       if (modes[0].channels == NULL || modes[0].rates == NULL) {
-               wpa_supplicant_sta_free_hw_features(modes, *num_modes);
-               return NULL;
-       }
-       modes[0].channels[0].chan = 1;
-       modes[0].channels[0].freq = 2412;
-       modes[0].channels[0].flag = 0;
-       modes[0].rates[0].rate = 10;
-       modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
-               HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
-
-       return modes;
-}
-
-
 static int wpa_driver_test_set_channel(void *priv, hostapd_hw_mode phymode,
                                       int chan, int freq)
 {
@@ -2479,10 +2364,105 @@ wpa_driver_test_get_interfaces(void *global_priv)
        return iface;
 }
 
+#endif /* HOSTAPD */
+
+
+#if defined(HOSTAPD) || defined(CONFIG_CLIENT_MLME)
+static struct hostapd_hw_modes *
+wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
+{
+       struct hostapd_hw_modes *modes;
+
+       *num_modes = 3;
+       *flags = 0;
+       modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
+       if (modes == NULL)
+               return NULL;
+       modes[0].mode = HOSTAPD_MODE_IEEE80211G;
+       modes[0].num_channels = 1;
+       modes[0].num_rates = 1;
+       modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
+       modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
+       if (modes[0].channels == NULL || modes[0].rates == NULL)
+               goto fail;
+       modes[0].channels[0].chan = 1;
+       modes[0].channels[0].freq = 2412;
+       modes[0].channels[0].flag = 0;
+       modes[0].rates[0].rate = 10;
+       modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
+               HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
+
+       modes[1].mode = HOSTAPD_MODE_IEEE80211B;
+       modes[1].num_channels = 1;
+       modes[1].num_rates = 1;
+       modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
+       modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
+       if (modes[1].channels == NULL || modes[1].rates == NULL)
+               goto fail;
+       modes[1].channels[0].chan = 1;
+       modes[1].channels[0].freq = 2412;
+       modes[1].channels[0].flag = 0;
+       modes[1].rates[0].rate = 10;
+       modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
+               HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
+
+       modes[2].mode = HOSTAPD_MODE_IEEE80211A;
+       modes[2].num_channels = 1;
+       modes[2].num_rates = 1;
+       modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
+       modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
+       if (modes[2].channels == NULL || modes[2].rates == NULL)
+               goto fail;
+       modes[2].channels[0].chan = 60;
+       modes[2].channels[0].freq = 5300;
+       modes[2].channels[0].flag = 0;
+       modes[2].rates[0].rate = 60;
+       modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
+               HOSTAPD_RATE_MANDATORY;
+
+       return modes;
+
+fail:
+       if (modes) {
+               size_t i;
+               for (i = 0; i < *num_modes; i++) {
+                       os_free(modes[i].channels);
+                       os_free(modes[i].rates);
+               }
+               os_free(modes);
+       }
+       return NULL;
+}
+#endif /* HOSTAPD || CONFIG_CLIENT_MLME */
+
 
 const struct wpa_driver_ops wpa_driver_test_ops = {
        "test",
        "wpa_supplicant test driver",
+#ifdef HOSTAPD
+       .hapd_init = test_driver_init,
+       .hapd_deinit = test_driver_deinit,
+       .hapd_send_eapol = test_driver_send_eapol,
+       .send_mlme = wpa_driver_test_send_mlme,
+       .set_generic_elem = test_driver_set_generic_elem,
+       .sta_deauth = test_driver_sta_deauth,
+       .sta_disassoc = test_driver_sta_disassoc,
+       .get_hw_feature_data = wpa_driver_test_get_hw_feature_data,
+       .bss_add = test_driver_bss_add,
+       .bss_remove = test_driver_bss_remove,
+       .if_add = test_driver_if_add,
+       .if_update = test_driver_if_update,
+       .if_remove = test_driver_if_remove,
+       .valid_bss_mask = test_driver_valid_bss_mask,
+       .hapd_set_ssid = test_driver_set_ssid,
+       .set_privacy = test_driver_set_privacy,
+       .hapd_set_key = test_driver_set_key,
+       .set_sta_vlan = test_driver_set_sta_vlan,
+       .sta_add = test_driver_sta_add,
+       .send_ether = test_driver_send_ether,
+       .set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
+       .set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
+#else /* HOSTAPD */
        wpa_driver_test_get_bssid,
        wpa_driver_test_get_ssid,
        wpa_driver_test_set_wpa,
@@ -2540,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 */,
@@ -2557,7 +2536,6 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
        NULL /* hapd_get_ssid */,
        NULL /* hapd_set_ssid */,
        NULL /* hapd_set_countermeasures */,
-       NULL /* send_mgmt_frame */,
        NULL /* sta_add */,
        NULL /* get_inact_sec */,
        NULL /* sta_clear_stats */,
@@ -2567,7 +2545,6 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
        NULL /* set_retry */,
        NULL /* sta_set_flags */,
        NULL /* set_rate_sets */,
-       NULL /* hapd_set_country */,
        NULL /* set_ieee80211d */,
        NULL /* hapd_set_beacon */,
        NULL /* set_internal_bridge */,
@@ -2581,7 +2558,6 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
        NULL /* bss_remove */,
        NULL /* valid_bss_mask */,
        NULL /* passive_scan */,
-       NULL /* hapd_get_hw_feature_data */,
        NULL /* if_add */,
        NULL /* if_update */,
        NULL /* if_remove */,
@@ -2594,6 +2570,5 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
        NULL /* set_wps_beacon_ie */,
        NULL /* set_wps_probe_resp_ie */,
        NULL /* get_neighbor_bss */
-};
-
 #endif /* HOSTAPD */
+};