/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2007-2008 Sam Leffler, Errno Consulting4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627/*28* IEEE 802.11 Monitor mode support.29*/30#include "opt_inet.h"31#include "opt_wlan.h"3233#include <sys/param.h>34#include <sys/systm.h>35#include <sys/mbuf.h>36#include <sys/malloc.h>37#include <sys/kernel.h>3839#include <sys/socket.h>40#include <sys/sockio.h>41#include <sys/endian.h>42#include <sys/errno.h>43#include <sys/proc.h>44#include <sys/sysctl.h>4546#include <net/if.h>47#include <net/if_var.h>48#include <net/if_media.h>49#include <net/if_llc.h>50#include <net/ethernet.h>5152#include <net/bpf.h>5354#include <net80211/ieee80211_var.h>55#include <net80211/ieee80211_monitor.h>5657static void monitor_vattach(struct ieee80211vap *);58static int monitor_newstate(struct ieee80211vap *, enum ieee80211_state, int);59static int monitor_input(struct ieee80211_node *ni, struct mbuf *m,60const struct ieee80211_rx_stats *rxs, int rssi, int nf);6162void63ieee80211_monitor_attach(struct ieee80211com *ic)64{65ic->ic_vattach[IEEE80211_M_MONITOR] = monitor_vattach;66}6768void69ieee80211_monitor_detach(struct ieee80211com *ic)70{71}7273static void74monitor_vdetach(struct ieee80211vap *vap)75{76}7778static void79monitor_vattach(struct ieee80211vap *vap)80{81vap->iv_newstate = monitor_newstate;82vap->iv_input = monitor_input;83vap->iv_opdetach = monitor_vdetach;84}8586/*87* IEEE80211_M_MONITOR vap state machine handler.88*/89static int90monitor_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)91{92struct ieee80211com *ic = vap->iv_ic;93enum ieee80211_state ostate;9495IEEE80211_LOCK_ASSERT(ic);9697ostate = vap->iv_state;98IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n",99__func__, ieee80211_state_name[ostate],100ieee80211_state_name[nstate], arg);101vap->iv_state = nstate; /* state transition */102if (nstate == IEEE80211_S_RUN) {103switch (ostate) {104case IEEE80211_S_INIT:105ieee80211_create_ibss(vap, ic->ic_curchan);106break;107default:108break;109}110/*111* NB: this shouldn't be here but many people use112* monitor mode for raw packets; once we switch113* them over to adhoc demo mode remove this.114*/115ieee80211_node_authorize(vap->iv_bss);116}117return 0;118}119120/*121* Process a received frame in monitor mode.122*/123static int124monitor_input(struct ieee80211_node *ni, struct mbuf *m,125const struct ieee80211_rx_stats *rxs, int rssi, int nf)126{127struct ieee80211vap *vap = ni->ni_vap;128struct ifnet *ifp = vap->iv_ifp;129130if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);131132if (ieee80211_radiotap_active_vap(vap))133ieee80211_radiotap_rx(vap, m);134m_freem(m);135return -1;136}137138139