]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Remove support for use_monitor
authorJohannes Berg <johannes.berg@intel.com>
Mon, 3 Feb 2025 20:45:30 +0000 (21:45 +0100)
committerJouni Malinen <j@w1.fi>
Sat, 15 Feb 2025 09:45:22 +0000 (11:45 +0200)
Using nl80211 for management and EAPOL TX/RX has been available in the
kernel for over a decade, including TX status for data frames starting
from kernel 3.3. Remove support for (cooked) monitor TX/RX, leaving a
simple non-RX monitor for unencrypted TX testing.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
src/drivers/driver_nl80211.c
src/drivers/driver_nl80211.h
src/drivers/driver_nl80211_capa.c
src/drivers/driver_nl80211_monitor.c

index 966bbe39f48ddaec7023372dfa0f372bc856f119..3d5d62e1be4fe703f4f2ac0223a74f7d5a003307 100644 (file)
@@ -2349,8 +2349,6 @@ static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
        bss->ctx = ctx;
 
        os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
-       drv->monitor_ifidx = -1;
-       drv->monitor_sock = -1;
        drv->eapol_tx_sock = -1;
        drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
 
@@ -2379,9 +2377,7 @@ static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
                                   "nl80211: wifi status sockopt failed: %s",
                                   strerror(errno));
                        drv->data_tx_status = 0;
-                       if (!drv->use_monitor)
-                               drv->capa.flags &=
-                                       ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
+                       drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
                } else {
                        eloop_register_read_sock(
                                drv->eapol_tx_sock,
@@ -3242,8 +3238,6 @@ static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
                                   bss->brname, strerror(errno));
        }
 
-       nl80211_remove_monitor_interface(drv);
-
        if (is_ap_interface(drv->nlmode)) {
                wpa_driver_nl80211_del_beacon_all(bss);
                nl80211_remove_links(bss);
@@ -4383,7 +4377,6 @@ static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
 {
        struct wpa_driver_nl80211_data *drv = bss->drv;
        struct ieee80211_mgmt *mgmt;
-       int encrypt = !no_encrypt;
        u16 fc;
        int use_cookie = 1;
        int res;
@@ -4432,20 +4425,6 @@ static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
                goto send_frame_cmd;
        }
 
-       if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
-           WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
-               /*
-                * Only one of the authentication frame types is encrypted.
-                * In order for static WEP encryption to work properly (i.e.,
-                * to not encrypt the frame), we need to tell mac80211 about
-                * the frames that must not be encrypted.
-                */
-               u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
-               u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
-               if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
-                       encrypt = 0;
-       }
-
        if ((is_sta_interface(drv->nlmode) ||
             drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
            WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
@@ -4494,29 +4473,17 @@ static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
                freq = link->freq;
        }
 
-       if (drv->use_monitor && is_ap_interface(drv->nlmode)) {
-               wpa_printf(MSG_DEBUG,
-                          "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
-                          freq, link->freq);
-               return nl80211_send_monitor(drv, data, data_len, encrypt,
-                                           noack);
-       }
-
        if ((noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
             WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) &&
            link_id == NL80211_DRV_LINK_ID_NA)
                use_cookie = 0;
 send_frame_cmd:
 #ifdef CONFIG_TESTING_OPTIONS
-       if (no_encrypt && !encrypt && !drv->use_monitor) {
+       if (no_encrypt) {
                wpa_printf(MSG_DEBUG,
                           "nl80211: Request to send an unencrypted frame - use a monitor interface for this");
-               if (nl80211_create_monitor_interface(drv) < 0)
-                       return -1;
-               res = nl80211_send_monitor(drv, data, data_len, encrypt,
-                                          noack);
-               nl80211_remove_monitor_interface(drv);
-               return res;
+               return nl80211_send_monitor(drv, data, data_len, !no_encrypt,
+                                           noack);
        }
 #endif /* CONFIG_TESTING_OPTIONS */
 
@@ -5216,8 +5183,7 @@ static int wpa_driver_nl80211_set_ap(void *priv,
                   beacon_set);
        if (beacon_set)
                cmd = NL80211_CMD_SET_BEACON;
-       else if (!drv->device_ap_sme && !drv->use_monitor &&
-                !nl80211_get_wiphy_data_ap(bss))
+       else if (!drv->device_ap_sme && !nl80211_get_wiphy_data_ap(bss))
                return -ENOBUFS;
 
        wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
@@ -6209,19 +6175,8 @@ static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
            nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
                goto fail;
 
-       if (iftype == NL80211_IFTYPE_MONITOR) {
-               struct nlattr *flags;
-
-               flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
-               if (!flags ||
-                   nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
-                       goto fail;
-
-               nla_nest_end(msg, flags);
-       } else if (wds) {
-               if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
-                       goto fail;
-       }
+       if (wds && nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
+               goto fail;
 
        /*
         * Tell cfg80211 that the interface belongs to the socket that created
@@ -6329,8 +6284,8 @@ static int nl80211_setup_ap(struct i802_bss *bss)
 {
        struct wpa_driver_nl80211_data *drv = bss->drv;
 
-       wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
-                  bss->ifname, drv->device_ap_sme, drv->use_monitor);
+       wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d",
+                  bss->ifname, drv->device_ap_sme);
 
        /*
         * Disable Probe Request reporting unless we need it in this way for
@@ -6340,20 +6295,13 @@ static int nl80211_setup_ap(struct i802_bss *bss)
        if (!drv->device_ap_sme)
                wpa_driver_nl80211_probe_req_report(bss, 0);
 
-       if (!drv->device_ap_sme && !drv->use_monitor)
-               if (nl80211_mgmt_subscribe_ap(bss))
-                       return -1;
-
-       if (drv->device_ap_sme && !drv->use_monitor)
-               if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
-                       wpa_printf(MSG_DEBUG,
-                                  "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
-
-       if (!drv->device_ap_sme && drv->use_monitor &&
-           nl80211_create_monitor_interface(drv) &&
-           !drv->device_ap_sme)
+       if (!drv->device_ap_sme && nl80211_mgmt_subscribe_ap(bss))
                return -1;
 
+       if (drv->device_ap_sme && nl80211_mgmt_subscribe_ap_dev_sme(bss))
+               wpa_printf(MSG_DEBUG,
+                          "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
+
        if (drv->device_ap_sme &&
            wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
                wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
@@ -6369,16 +6317,14 @@ static void nl80211_teardown_ap(struct i802_bss *bss)
 {
        struct wpa_driver_nl80211_data *drv = bss->drv;
 
-       wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
-                  bss->ifname, drv->device_ap_sme, drv->use_monitor);
+       wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d",
+                  bss->ifname, drv->device_ap_sme);
        if (drv->device_ap_sme) {
                wpa_driver_nl80211_probe_req_report(bss, 0);
-               if (!drv->use_monitor)
-                       nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
-       } else if (drv->use_monitor)
-               nl80211_remove_monitor_interface(drv);
-       else
+               nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
+       } else {
                nl80211_mgmt_unsubscribe(bss, "AP teardown");
+       }
 
        nl80211_put_wiphy_data_ap(bss);
        if (bss->flink)
@@ -6464,8 +6410,6 @@ static int nl80211_send_eapol_data(struct i802_bss *bss,
 }
 
 
-static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
-
 static int wpa_driver_nl80211_hapd_send_eapol(
        void *priv, const u8 *addr, const u8 *data,
        size_t data_len, int encrypt, const u8 *own_addr, u32 flags,
@@ -6473,11 +6417,6 @@ static int wpa_driver_nl80211_hapd_send_eapol(
 {
        struct i802_bss *bss = priv;
        struct wpa_driver_nl80211_data *drv = bss->drv;
-       struct ieee80211_hdr *hdr;
-       size_t len;
-       u8 *pos;
-       int res;
-       int qos = flags & WPA_STA_WMM;
 
        /* For now, disable EAPOL TX over control port in AP mode by default
         * since it does not provide TX status notifications. */
@@ -6487,55 +6426,7 @@ static int wpa_driver_nl80211_hapd_send_eapol(
                                               data, data_len, !encrypt,
                                               link_id);
 
-       if (drv->device_ap_sme || !drv->use_monitor)
-               return nl80211_send_eapol_data(bss, addr, data, data_len);
-
-       len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
-               data_len;
-       hdr = os_zalloc(len);
-       if (hdr == NULL) {
-               wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
-                          (unsigned long) len);
-               return -1;
-       }
-
-       hdr->frame_control =
-               IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
-       hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
-       if (encrypt)
-               hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
-       if (qos) {
-               hdr->frame_control |=
-                       host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
-       }
-
-       memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
-       memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
-       memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
-       pos = (u8 *) (hdr + 1);
-
-       if (qos) {
-               /* Set highest priority in QoS header */
-               pos[0] = 7;
-               pos[1] = 0;
-               pos += 2;
-       }
-
-       memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
-       pos += sizeof(rfc1042_header);
-       WPA_PUT_BE16(pos, ETH_P_PAE);
-       pos += 2;
-       memcpy(pos, data, data_len);
-
-       res = nl80211_send_monitor(drv, hdr, len, encrypt, 0);
-       if (res < 0) {
-               wpa_printf(MSG_ERROR,
-                          "hapd_send_eapol - packet len: %lu - failed",
-                          (unsigned long) len);
-       }
-       os_free(hdr);
-
-       return res;
+       return nl80211_send_eapol_data(bss, addr, data, data_len);
 }
 
 
@@ -6633,16 +6524,13 @@ static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
                nlmode = NL80211_IFTYPE_AP;
 
        old_mode = drv->nlmode;
-       if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
-               nl80211_remove_monitor_interface(drv);
+       if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode))
                return -1;
-       }
 
        if (params->freq.freq &&
            nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
                if (old_mode != nlmode)
                        wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
-               nl80211_remove_monitor_interface(drv);
                return -1;
        }
 
@@ -9443,10 +9331,7 @@ static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
        }
 #endif /* CONFIG_MESH */
 
-       if (is_ap_interface(drv->nlmode) &&
-           (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
-            (int) freq == bss->flink->freq || drv->device_ap_sme ||
-            !drv->use_monitor))
+       if (is_ap_interface(drv->nlmode))
                ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
                                                   0, freq, no_cck, offchanok,
                                                   wait_time, NULL, 0, 0,
@@ -10126,9 +10011,6 @@ static int nl80211_set_param(void *priv, const char *param)
        }
 #endif /* CONFIG_P2P */
 
-       if (os_strstr(param, "use_monitor=1"))
-               drv->use_monitor = 1;
-
        if (os_strstr(param, "force_connect_cmd=1")) {
                drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
                drv->force_connect_cmd = 1;
@@ -11361,12 +11243,9 @@ static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
                          "prev_bssid=" MACSTR "\n"
                          "associated=%d\n"
                          "assoc_freq=%u\n"
-                         "monitor_sock=%d\n"
-                         "monitor_ifidx=%d\n"
-                         "monitor_refcount=%d\n"
                          "last_mgmt_freq=%u\n"
                          "eapol_tx_sock=%d\n"
-                         "%s%s%s%s%s%s%s%s%s%s%s%s%s",
+                         "%s%s%s%s%s%s%s%s%s%s%s%s",
                          drv->phyname,
                          MAC2STR(drv->perm_addr),
                          drv->ifindex,
@@ -11378,9 +11257,6 @@ static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
                          MAC2STR(drv->prev_bssid),
                          drv->associated,
                          drv->assoc_freq,
-                         drv->monitor_sock,
-                         drv->monitor_ifidx,
-                         drv->monitor_refcount,
                          drv->last_mgmt_freq,
                          drv->eapol_tx_sock,
                          drv->ignore_if_down_event ?
@@ -11398,7 +11274,6 @@ static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
                          drv->data_tx_status ? "data_tx_status=1\n" : "",
                          drv->scan_for_auth ? "scan_for_auth=1\n" : "",
                          drv->retry_auth ? "retry_auth=1\n" : "",
-                         drv->use_monitor ? "use_monitor=1\n" : "",
                          drv->ignore_next_local_disconnect ?
                          "ignore_next_local_disconnect\n" : "",
                          drv->ignore_next_local_deauth ?
index da6c2bfa0b8b36c518a5e63c3003b240c4307e4f..9c4aedd7acf094667caa65a4b3624a01c0fe80e7 100644 (file)
@@ -151,10 +151,6 @@ struct wpa_driver_nl80211_data {
        enum nl80211_iftype ap_scan_as_station;
        unsigned int assoc_freq;
 
-       int monitor_sock;
-       int monitor_ifidx;
-       int monitor_refcount;
-
        unsigned int disabled_11b_rates:1;
        unsigned int pending_remain_on_chan:1;
        unsigned int in_interface_list:1;
@@ -163,7 +159,6 @@ struct wpa_driver_nl80211_data {
        unsigned int data_tx_status:1;
        unsigned int scan_for_auth:1;
        unsigned int retry_auth:1;
-       unsigned int use_monitor:1;
        unsigned int hostapd:1;
        unsigned int start_mode_sta:1;
        unsigned int start_iface_up:1;
@@ -352,8 +347,6 @@ int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
                            int local_state_change,
                            struct i802_bss *bss);
 
-int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
-void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
 int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
                         const void *data, size_t len,
                         int encrypt, int noack);
index 72be7d103f97abae3a1f70793ab3505785abafb6..62b16696160c36fcbc38c8b6c48c40231f7a3915 100644 (file)
@@ -1580,18 +1580,10 @@ int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
        drv->have_low_prio_scan = info.have_low_prio_scan;
 
        /*
-        * If poll command and tx status are supported, mac80211 is new enough
-        * to have everything we need to not need monitor interfaces.
-        */
-       drv->use_monitor = !info.device_ap_sme &&
-               (!info.poll_command_supported || !info.data_tx_status);
-
-       /*
-        * If we aren't going to use monitor interfaces, but the
-        * driver doesn't support data TX status, we won't get TX
+        * If the driver doesn't support data TX status, we won't get TX
         * status for EAPOL frames.
         */
-       if (!drv->use_monitor && !info.data_tx_status)
+       if (!info.data_tx_status)
                drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
 
 #ifdef CONFIG_DRIVER_NL80211_QCA
index 7ff55f149a618ee45428616765ff2183cb0ea5ad..ca9bb1ec3cd59b12b449965a7e8cd547b4dba6ac 100644 (file)
 #include "driver_nl80211.h"
 
 
-static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok)
-{
-       struct ieee80211_hdr *hdr;
-       u16 fc;
-       union wpa_event_data event;
-
-       hdr = (struct ieee80211_hdr *) buf;
-       fc = le_to_host16(hdr->frame_control);
-
-       os_memset(&event, 0, sizeof(event));
-       event.tx_status.type = WLAN_FC_GET_TYPE(fc);
-       event.tx_status.stype = WLAN_FC_GET_STYPE(fc);
-       event.tx_status.dst = hdr->addr1;
-       event.tx_status.data = buf;
-       event.tx_status.data_len = len;
-       event.tx_status.ack = ok;
-       wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event);
-}
-
-
-static void from_unknown_sta(struct wpa_driver_nl80211_data *drv,
-                            u8 *buf, size_t len)
-{
-       struct ieee80211_hdr *hdr = (void *)buf;
-       u16 fc;
-       union wpa_event_data event;
-
-       if (len < sizeof(*hdr))
-               return;
-
-       fc = le_to_host16(hdr->frame_control);
-
-       os_memset(&event, 0, sizeof(event));
-       event.rx_from_unknown.bssid = get_hdr_bssid(hdr, len);
-       event.rx_from_unknown.addr = hdr->addr2;
-       event.rx_from_unknown.wds = (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) ==
-               (WLAN_FC_FROMDS | WLAN_FC_TODS);
-       wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event);
-}
-
-
-static void handle_frame(struct wpa_driver_nl80211_data *drv,
-                        u8 *buf, size_t len, int datarate, int ssi_signal)
-{
-       struct ieee80211_hdr *hdr;
-       u16 fc;
-       union wpa_event_data event;
-
-       if (!drv->use_monitor)
-               return;
-
-       hdr = (struct ieee80211_hdr *) buf;
-       fc = le_to_host16(hdr->frame_control);
-
-       switch (WLAN_FC_GET_TYPE(fc)) {
-       case WLAN_FC_TYPE_MGMT:
-               os_memset(&event, 0, sizeof(event));
-               event.rx_mgmt.frame = buf;
-               event.rx_mgmt.frame_len = len;
-               event.rx_mgmt.datarate = datarate;
-               event.rx_mgmt.ssi_signal = ssi_signal;
-               wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
-               break;
-       case WLAN_FC_TYPE_CTRL:
-               /* can only get here with PS-Poll frames */
-               wpa_printf(MSG_DEBUG, "CTRL");
-               from_unknown_sta(drv, buf, len);
-               break;
-       case WLAN_FC_TYPE_DATA:
-               from_unknown_sta(drv, buf, len);
-               break;
-       }
-}
-
-
-static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
-{
-       struct wpa_driver_nl80211_data *drv = eloop_ctx;
-       int len;
-       unsigned char buf[3000];
-       struct ieee80211_radiotap_iterator iter;
-       int ret;
-       int datarate = 0, ssi_signal = 0;
-       int injected = 0, failed = 0, rxflags = 0;
-
-       len = recv(sock, buf, sizeof(buf), 0);
-       if (len < 0) {
-               wpa_printf(MSG_ERROR, "nl80211: Monitor socket recv failed: %s",
-                          strerror(errno));
-               return;
-       }
-
-       if (ieee80211_radiotap_iterator_init(&iter, (void *) buf, len, NULL)) {
-               wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame");
-               return;
-       }
-
-       while (1) {
-               ret = ieee80211_radiotap_iterator_next(&iter);
-               if (ret == -ENOENT)
-                       break;
-               if (ret) {
-                       wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame (%d)",
-                                  ret);
-                       return;
-               }
-               switch (iter.this_arg_index) {
-               case IEEE80211_RADIOTAP_FLAGS:
-                       if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
-                               len -= 4;
-                       break;
-               case IEEE80211_RADIOTAP_RX_FLAGS:
-                       rxflags = 1;
-                       break;
-               case IEEE80211_RADIOTAP_TX_FLAGS:
-                       injected = 1;
-                       failed = le_to_host16((*(le16 *) iter.this_arg)) &
-                                       IEEE80211_RADIOTAP_F_TX_FAIL;
-                       break;
-               case IEEE80211_RADIOTAP_DATA_RETRIES:
-                       break;
-               case IEEE80211_RADIOTAP_CHANNEL:
-                       /* TODO: convert from freq/flags to channel number */
-                       break;
-               case IEEE80211_RADIOTAP_RATE:
-                       datarate = *iter.this_arg * 5;
-                       break;
-               case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
-                       ssi_signal = (s8) *iter.this_arg;
-                       break;
-               }
-       }
-
-       if (rxflags && injected)
-               return;
-
-       if (!injected)
-               handle_frame(drv, buf + iter._max_length,
-                            len - iter._max_length, datarate, ssi_signal);
-       else
-               handle_tx_callback(drv->ctx, buf + iter._max_length,
-                                  len - iter._max_length, !failed);
-}
-
-
-/*
- * we post-process the filter code later and rewrite
- * this to the offset to the last instruction
- */
-#define PASS   0xFF
-#define FAIL   0xFE
+#ifdef CONFIG_TESTING_OPTIONS
 
 static struct sock_filter msock_filter_insns[] = {
-       /*
-        * do a little-endian load of the radiotap length field
-        */
-       /* load lower byte into A */
-       BPF_STMT(BPF_LD  | BPF_B | BPF_ABS, 2),
-       /* put it into X (== index register) */
-       BPF_STMT(BPF_MISC| BPF_TAX, 0),
-       /* load upper byte into A */
-       BPF_STMT(BPF_LD  | BPF_B | BPF_ABS, 3),
-       /* left-shift it by 8 */
-       BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8),
-       /* or with X */
-       BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0),
-       /* put result into X */
-       BPF_STMT(BPF_MISC| BPF_TAX, 0),
-
-       /*
-        * Allow management frames through, this also gives us those
-        * management frames that we sent ourselves with status
-        */
-       /* load the lower byte of the IEEE 802.11 frame control field */
-       BPF_STMT(BPF_LD  | BPF_B | BPF_IND, 0),
-       /* mask off frame type and version */
-       BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF),
-       /* accept frame if it's both 0, fall through otherwise */
-       BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0),
-
-       /*
-        * TODO: add a bit to radiotap RX flags that indicates
-        * that the sending station is not associated, then
-        * add a filter here that filters on our DA and that flag
-        * to allow us to deauth frames to that bad station.
-        *
-        * For now allow all To DS data frames through.
-        */
-       /* load the IEEE 802.11 frame control field */
-       BPF_STMT(BPF_LD  | BPF_H | BPF_IND, 0),
-       /* mask off frame type, version and DS status */
-       BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0F03),
-       /* accept frame if version 0, type 2 and To DS, fall through otherwise
-        */
-       BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0801, PASS, 0),
-
-#if 0
-       /*
-        * drop non-data frames
-        */
-       /* load the lower byte of the frame control field */
-       BPF_STMT(BPF_LD   | BPF_B | BPF_IND, 0),
-       /* mask off QoS bit */
-       BPF_STMT(BPF_ALU  | BPF_AND | BPF_K, 0x0c),
-       /* drop non-data frames */
-       BPF_JUMP(BPF_JMP  | BPF_JEQ | BPF_K, 8, 0, FAIL),
-#endif
-       /* load the upper byte of the frame control field */
-       BPF_STMT(BPF_LD   | BPF_B | BPF_IND, 1),
-       /* mask off toDS/fromDS */
-       BPF_STMT(BPF_ALU  | BPF_AND | BPF_K, 0x03),
-       /* accept WDS frames */
-       BPF_JUMP(BPF_JMP  | BPF_JEQ | BPF_K, 3, PASS, 0),
-
-       /*
-        * add header length to index
-        */
-       /* load the lower byte of the frame control field */
-       BPF_STMT(BPF_LD   | BPF_B | BPF_IND, 0),
-       /* mask off QoS bit */
-       BPF_STMT(BPF_ALU  | BPF_AND | BPF_K, 0x80),
-       /* right shift it by 6 to give 0 or 2 */
-       BPF_STMT(BPF_ALU  | BPF_RSH | BPF_K, 6),
-       /* add data frame header length */
-       BPF_STMT(BPF_ALU  | BPF_ADD | BPF_K, 24),
-       /* add index, was start of 802.11 header */
-       BPF_STMT(BPF_ALU  | BPF_ADD | BPF_X, 0),
-       /* move to index, now start of LL header */
-       BPF_STMT(BPF_MISC | BPF_TAX, 0),
-
-       /*
-        * Accept empty data frames, we use those for
-        * polling activity.
-        */
-       BPF_STMT(BPF_LD  | BPF_W | BPF_LEN, 0),
-       BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0),
-
-       /*
-        * Accept EAPOL frames
-        */
-       BPF_STMT(BPF_LD  | BPF_W | BPF_IND, 0),
-       BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL),
-       BPF_STMT(BPF_LD  | BPF_W | BPF_IND, 4),
-       BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL),
-
-       /* keep these last two statements or change the code below */
-       /* return 0 == "DROP" */
+       /* return 0 == "DROP", we don't want RX */
        BPF_STMT(BPF_RET | BPF_K, 0),
-       /* return ~0 == "keep all" */
-       BPF_STMT(BPF_RET | BPF_K, ~0),
 };
 
-static struct sock_fprog msock_filter = {
+static const struct sock_fprog msock_filter = {
        .len = ARRAY_SIZE(msock_filter_insns),
        .filter = msock_filter_insns,
 };
@@ -283,32 +38,6 @@ static struct sock_fprog msock_filter = {
 
 static int add_monitor_filter(int s)
 {
-       int idx;
-
-       /* rewrite all PASS/FAIL jump offsets */
-       for (idx = 0; idx < msock_filter.len; idx++) {
-               struct sock_filter *insn = &msock_filter_insns[idx];
-
-               if (BPF_CLASS(insn->code) == BPF_JMP) {
-                       if (insn->code == (BPF_JMP|BPF_JA)) {
-                               if (insn->k == PASS)
-                                       insn->k = msock_filter.len - idx - 2;
-                               else if (insn->k == FAIL)
-                                       insn->k = msock_filter.len - idx - 3;
-                       }
-
-                       if (insn->jt == PASS)
-                               insn->jt = msock_filter.len - idx - 2;
-                       else if (insn->jt == FAIL)
-                               insn->jt = msock_filter.len - idx - 3;
-
-                       if (insn->jf == PASS)
-                               insn->jf = msock_filter.len - idx - 2;
-                       else if (insn->jf == FAIL)
-                               insn->jf = msock_filter.len - idx - 3;
-               }
-       }
-
        if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER,
                       &msock_filter, sizeof(msock_filter))) {
                wpa_printf(MSG_ERROR, "nl80211: setsockopt(SO_ATTACH_FILTER) failed: %s",
@@ -320,40 +49,29 @@ static int add_monitor_filter(int s)
 }
 
 
-void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv)
+static void
+nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv,
+                                int ifidx, int sock)
 {
-       if (drv->monitor_refcount > 0)
-               drv->monitor_refcount--;
-       wpa_printf(MSG_DEBUG, "nl80211: Remove monitor interface: refcount=%d",
-                  drv->monitor_refcount);
-       if (drv->monitor_refcount > 0)
-               return;
-
-       if (drv->monitor_ifidx >= 0) {
-               nl80211_remove_iface(drv, drv->monitor_ifidx);
-               drv->monitor_ifidx = -1;
-       }
-       if (drv->monitor_sock >= 0) {
-               eloop_unregister_read_sock(drv->monitor_sock);
-               close(drv->monitor_sock);
-               drv->monitor_sock = -1;
-       }
+       wpa_printf(MSG_DEBUG, "nl80211: Remove monitor interface");
+
+       if (ifidx >= 0)
+               nl80211_remove_iface(drv, ifidx);
+       if (sock >= 0)
+               close(sock);
 }
 
 
-int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv)
+static int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv,
+                                           int *ifidx, int *sock)
 {
        char buf[IFNAMSIZ];
        struct sockaddr_ll ll;
        int optval;
        socklen_t optlen;
 
-       if (drv->monitor_ifidx >= 0) {
-               drv->monitor_refcount++;
-               wpa_printf(MSG_DEBUG, "nl80211: Re-use existing monitor interface: refcount=%d",
-                          drv->monitor_refcount);
-               return 0;
-       }
+       *ifidx = -1;
+       *sock = -1;
 
        if (os_strncmp(drv->first_bss->ifname, "p2p-", 4) == 0) {
                /*
@@ -379,23 +97,10 @@ int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv)
 
        buf[IFNAMSIZ - 1] = '\0';
 
-       drv->monitor_ifidx =
-               nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL,
-                                    0, NULL, NULL, 0);
+       *ifidx = nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL,
+                                     0, NULL, NULL, 0);
 
-       if (drv->monitor_ifidx == -EOPNOTSUPP) {
-               /*
-                * This is backward compatibility for a few versions of
-                * the kernel only that didn't advertise the right
-                * attributes for the only driver that then supported
-                * AP mode w/o monitor -- ath6kl.
-                */
-               wpa_printf(MSG_DEBUG, "nl80211: Driver does not support "
-                          "monitor interface type - try to run without it");
-               drv->device_ap_sme = 1;
-       }
-
-       if (drv->monitor_ifidx < 0)
+       if (*ifidx < 0)
                return -1;
 
        if (linux_set_iface_flags(drv->global->ioctl_sock, buf, 1))
@@ -403,21 +108,21 @@ int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv)
 
        memset(&ll, 0, sizeof(ll));
        ll.sll_family = AF_PACKET;
-       ll.sll_ifindex = drv->monitor_ifidx;
-       drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
-       if (drv->monitor_sock < 0) {
+       ll.sll_ifindex = *ifidx;
+       *sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+       if (*sock < 0) {
                wpa_printf(MSG_ERROR, "nl80211: socket[PF_PACKET,SOCK_RAW] failed: %s",
                           strerror(errno));
                goto error;
        }
 
-       if (add_monitor_filter(drv->monitor_sock)) {
+       if (add_monitor_filter(*sock)) {
                wpa_printf(MSG_INFO, "Failed to set socket filter for monitor "
                           "interface; do filtering in user space");
                /* This works, but will cost in performance. */
        }
 
-       if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
+       if (bind(*sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
                wpa_printf(MSG_ERROR, "nl80211: monitor socket bind failed: %s",
                           strerror(errno));
                goto error;
@@ -425,30 +130,22 @@ int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv)
 
        optlen = sizeof(optval);
        optval = 20;
-       if (setsockopt
-           (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
+       if (setsockopt(*sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
                wpa_printf(MSG_ERROR, "nl80211: Failed to set socket priority: %s",
                           strerror(errno));
                goto error;
        }
 
-       if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
-                                    drv, NULL)) {
-               wpa_printf(MSG_INFO, "nl80211: Could not register monitor read socket");
-               goto error;
-       }
-
-       drv->monitor_refcount++;
        return 0;
  error:
-       nl80211_remove_monitor_interface(drv);
+       nl80211_remove_monitor_interface(drv, *ifidx, *sock);
        return -1;
 }
 
 
-int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
-                        const void *data, size_t len,
-                        int encrypt, int noack)
+static int _nl80211_send_monitor(int monitor_sock,
+                                const void *data, size_t len,
+                                int encrypt, int noack)
 {
        __u8 rtap_hdr[] = {
                0x00, 0x00, /* radiotap version */
@@ -484,20 +181,32 @@ int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
        if (encrypt)
                rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
 
-       if (drv->monitor_sock < 0) {
-               wpa_printf(MSG_DEBUG, "nl80211: No monitor socket available "
-                          "for %s", __func__);
-               return -1;
-       }
-
        if (noack)
                txflags |= IEEE80211_RADIOTAP_F_TX_NOACK;
        WPA_PUT_LE16(&rtap_hdr[12], txflags);
 
-       res = sendmsg(drv->monitor_sock, &msg, 0);
+       res = sendmsg(monitor_sock, &msg, 0);
        if (res < 0) {
                wpa_printf(MSG_INFO, "nl80211: sendmsg: %s", strerror(errno));
                return -1;
        }
        return 0;
 }
+
+
+int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
+                        const void *data, size_t len,
+                        int encrypt, int noack)
+{
+       int res, ifidx, sock;
+
+       res = nl80211_create_monitor_interface(drv, &ifidx, &sock);
+       if (res < 0)
+               return res;
+
+       res = _nl80211_send_monitor(sock, data, len, encrypt, noack);
+       nl80211_remove_monitor_interface(drv, ifidx, sock);
+       return res;
+}
+
+#endif /* CONFIG_TESTING_OPTIONS */