Fix couple of forgotten wpa_hw_modes -> hostapd_hw_modes
[wpasupplicant] / hostapd / driver_test.c
index bb4224b..94da5d0 100644 (file)
 #include <dirent.h>
 
 #include "hostapd.h"
+#include "config.h"
 #include "driver.h"
 #include "sha1.h"
 #include "eloop.h"
-#include "ieee802_1x.h"
-#include "sta_info.h"
 #include "wpa.h"
-#include "accounting.h"
-#include "radius/radius.h"
 #include "l2_packet/l2_packet.h"
-#include "ieee802_11.h"
 #include "hw_features.h"
 #include "wps_hostapd.h"
+#include "ieee802_11_defs.h"
 
 
 struct test_client_socket {
@@ -139,7 +136,7 @@ static int test_driver_send_eapol(void *priv, const u8 *addr, const u8 *data,
 
        memcpy(eth.h_dest, addr, ETH_ALEN);
        memcpy(eth.h_source, own_addr, ETH_ALEN);
-       eth.h_proto = htons(ETH_P_EAPOL);
+       eth.h_proto = host_to_be16(ETH_P_EAPOL);
 
        io[0].iov_base = "EAPOL ";
        io[0].iov_len = 6;
@@ -182,7 +179,7 @@ static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
 
        memcpy(eth.h_dest, dst, ETH_ALEN);
        memcpy(eth.h_source, src, ETH_ALEN);
-       eth.h_proto = htons(proto);
+       eth.h_proto = host_to_be16(proto);
 
        io[0].iov_base = "ETHER ";
        io[0].iov_len = 6;
@@ -321,7 +318,7 @@ static int test_driver_send_mgmt_frame(void *priv, const void *buf,
 
        hdr = (struct ieee80211_hdr *) buf;
        fc = le_to_host16(hdr->frame_control);
-       ieee802_11_mgmt_cb(drv->hapd, (u8 *) buf, len, WLAN_FC_GET_STYPE(fc),
+       hostapd_mgmt_tx_cb(drv->hapd, (u8 *) buf, len, WLAN_FC_GET_STYPE(fc),
                           ret >= 0);
 
        return ret;
@@ -432,63 +429,12 @@ static int test_driver_new_sta(struct test_driver_data *drv,
                               const u8 *ie, size_t ielen)
 {
        struct hostapd_data *hapd;
-       struct sta_info *sta;
-       int new_assoc, res;
 
        hapd = test_driver_get_hapd(drv, bss);
        if (hapd == NULL)
                return -1;
 
-       hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
-               HOSTAPD_LEVEL_INFO, "associated");
-
-       sta = ap_get_sta(hapd, addr);
-       if (sta) {
-               accounting_sta_stop(hapd, sta);
-       } else {
-               sta = ap_sta_add(hapd, addr);
-               if (sta == NULL)
-                       return -1;
-       }
-       sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
-
-       if (hapd->conf->wpa) {
-               if (ie == NULL || ielen == 0) {
-                       if (hapd->conf->wps_state) {
-                               sta->flags |= WLAN_STA_WPS;
-                               goto skip_wpa_check;
-                       }
-
-                       printf("test_driver: no IE from STA\n");
-                       return -1;
-               }
-               if (sta->wpa_sm == NULL)
-                       sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
-                                                       sta->addr);
-               if (sta->wpa_sm == NULL) {
-                       printf("test_driver: Failed to initialize WPA state "
-                              "machine\n");
-                       return -1;
-               }
-               res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
-                                         ie, ielen, NULL, 0);
-               if (res != WPA_IE_OK) {
-                       printf("WPA/RSN information element rejected? "
-                              "(res %u)\n", res);
-                       return -1;
-               }
-       }
-skip_wpa_check:
-
-       new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
-       sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
-       wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
-
-       hostapd_new_assoc_sta(hapd, sta, !new_assoc);
-
-       ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
-
-       return 0;
+       return hostapd_notif_assoc(hapd, addr, ie, ielen);
 }
 
 
@@ -573,24 +519,12 @@ static void test_driver_disassoc(struct test_driver_data *drv,
                                 struct sockaddr_un *from, socklen_t fromlen)
 {
        struct test_client_socket *cli;
-       struct sta_info *sta;
 
        cli = test_driver_get_cli(drv, from, fromlen);
        if (!cli)
                return;
 
-       hostapd_logger(drv->hapd, cli->addr, HOSTAPD_MODULE_IEEE80211,
-                      HOSTAPD_LEVEL_INFO, "disassociated");
-
-       sta = ap_get_sta(drv->hapd, cli->addr);
-       if (sta != NULL) {
-               sta->flags &= ~WLAN_STA_ASSOC;
-               wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
-               sta->acct_terminate_cause =
-                       RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
-               ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
-               ap_free_sta(drv->hapd, sta);
-       }
+       hostapd_notif_disassoc(drv->hapd, cli->addr);
 }
 
 
@@ -600,12 +534,11 @@ static void test_driver_eapol(struct test_driver_data *drv,
 {
        struct test_client_socket *cli;
        if (datalen > 14) {
-               u8 *proto = data + 2 * ETH_ALEN;
                /* Skip Ethernet header */
                wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
                           MACSTR " proto=%04x",
                           MAC2STR(data), MAC2STR(data + ETH_ALEN),
-                          WPA_GET_BE16(proto));
+                          WPA_GET_BE16(data + 2 * ETH_ALEN));
                data += 14;
                datalen -= 14;
        }
@@ -615,7 +548,7 @@ static void test_driver_eapol(struct test_driver_data *drv,
                hapd = test_driver_get_hapd(drv, cli->bss);
                if (hapd == NULL)
                        return;
-               ieee802_1x_receive(hapd, cli->addr, data, datalen);
+               hostapd_eapol_receive(hapd, cli->addr, data, datalen);
        } else {
                wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
                           "client");
@@ -678,7 +611,7 @@ static void test_driver_mlme(struct test_driver_data *drv,
                           __func__);
                return;
        }
-       ieee802_11_mgmt(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
+       hostapd_mgmt_rx(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
 }
 
 
@@ -1073,12 +1006,13 @@ static int test_driver_set_privacy(const char *ifname, void *priv, int enabled)
 }
 
 
-static int test_driver_set_encryption(const char *iface, void *priv,
-                                     const char *alg, const u8 *addr, int idx,
-                                     const u8 *key, size_t key_len, int txkey)
+static int test_driver_set_key(const char *iface, void *priv, wpa_alg alg,
+                              const u8 *addr, int key_idx, int set_tx,
+                              const u8 *seq, size_t seq_len,
+                              const u8 *key, size_t key_len)
 {
-       wpa_printf(MSG_DEBUG, "%s(iface=%s alg=%s idx=%d txkey=%d)",
-                  __func__, iface, alg, idx, txkey);
+       wpa_printf(MSG_DEBUG, "%s(iface=%s alg=%d idx=%d set_tx=%d)",
+                  __func__, iface, alg, key_idx, set_tx);
        if (addr)
                wpa_printf(MSG_DEBUG, "   addr=" MACSTR, MAC2STR(addr));
        if (key)
@@ -1096,10 +1030,8 @@ static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
 }
 
 
-static int test_driver_sta_add(const char *ifname, void *priv, const u8 *addr,
-                              u16 aid, u16 capability, u8 *supp_rates,
-                              size_t supp_rates_len, int flags,
-                              u16 listen_interval)
+static int test_driver_sta_add(const char *ifname, void *priv,
+                              struct hostapd_sta_add_params *params)
 {
        struct test_driver_data *drv = priv;
        struct test_client_socket *cli;
@@ -1107,14 +1039,15 @@ static int test_driver_sta_add(const char *ifname, void *priv, const u8 *addr,
 
        wpa_printf(MSG_DEBUG, "%s(ifname=%s addr=" MACSTR " aid=%d "
                   "capability=0x%x flags=0x%x listen_interval=%d)",
-                  __func__, ifname, MAC2STR(addr), aid, capability, flags,
-                  listen_interval);
+                  __func__, ifname, MAC2STR(params->addr), params->aid,
+                  params->capability, params->flags,
+                  params->listen_interval);
        wpa_hexdump(MSG_DEBUG, "test_driver_sta_add - supp_rates",
-                   supp_rates, supp_rates_len);
+                   params->supp_rates, params->supp_rates_len);
 
        cli = drv->cli;
        while (cli) {
-               if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
+               if (os_memcmp(cli->addr, params->addr, ETH_ALEN) == 0)
                        break;
                cli = cli->next;
        }
@@ -1267,7 +1200,7 @@ static void test_driver_deinit(void *priv)
 }
 
 
-const struct wpa_driver_ops wpa_driver_test_ops = {
+const struct hapd_driver_ops wpa_driver_test_ops = {
        .name = "test",
        .init = test_driver_init,
        .deinit = test_driver_deinit,
@@ -1285,7 +1218,7 @@ const struct wpa_driver_ops wpa_driver_test_ops = {
        .valid_bss_mask = test_driver_valid_bss_mask,
        .set_ssid = test_driver_set_ssid,
        .set_privacy = test_driver_set_privacy,
-       .set_encryption = test_driver_set_encryption,
+       .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,