FreeBSD kernel WLAN code
ieee80211_monitor.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29#ifdef __FreeBSD__
30__FBSDID("$FreeBSD$");
31#endif
32
33/*
34 * IEEE 802.11 Monitor mode support.
35 */
36#include "opt_inet.h"
37#include "opt_wlan.h"
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/mbuf.h>
42#include <sys/malloc.h>
43#include <sys/kernel.h>
44
45#include <sys/socket.h>
46#include <sys/sockio.h>
47#include <sys/endian.h>
48#include <sys/errno.h>
49#include <sys/proc.h>
50#include <sys/sysctl.h>
51
52#include <net/if.h>
53#include <net/if_var.h>
54#include <net/if_media.h>
55#include <net/if_llc.h>
56#include <net/ethernet.h>
57
58#include <net/bpf.h>
59
62
63static void monitor_vattach(struct ieee80211vap *);
64static int monitor_newstate(struct ieee80211vap *, enum ieee80211_state, int);
65static int monitor_input(struct ieee80211_node *ni, struct mbuf *m,
66 const struct ieee80211_rx_stats *rxs, int rssi, int nf);
67
68void
70{
72}
73
74void
76{
77}
78
79static void
81{
82}
83
84static void
86{
90}
91
92/*
93 * IEEE80211_M_MONITOR vap state machine handler.
94 */
95static int
96monitor_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
97{
98 struct ieee80211com *ic = vap->iv_ic;
99 enum ieee80211_state ostate;
100
102
103 ostate = vap->iv_state;
104 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n",
105 __func__, ieee80211_state_name[ostate],
106 ieee80211_state_name[nstate], arg);
107 vap->iv_state = nstate; /* state transition */
108 if (nstate == IEEE80211_S_RUN) {
109 switch (ostate) {
110 case IEEE80211_S_INIT:
112 break;
113 default:
114 break;
115 }
116 /*
117 * NB: this shouldn't be here but many people use
118 * monitor mode for raw packets; once we switch
119 * them over to adhoc demo mode remove this.
120 */
122 }
123 return 0;
124}
125
126/*
127 * Process a received frame in monitor mode.
128 */
129static int
130monitor_input(struct ieee80211_node *ni, struct mbuf *m,
131 const struct ieee80211_rx_stats *rxs, int rssi, int nf)
132{
133 struct ieee80211vap *vap = ni->ni_vap;
134 struct ifnet *ifp = vap->iv_ifp;
135
136 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
137
139 ieee80211_radiotap_rx(vap, m);
140 m_freem(m);
141 return -1;
142}
@ IEEE80211_M_MONITOR
Definition: _ieee80211.h:91
#define IEEE80211_LOCK_ASSERT(_ic)
static void monitor_vattach(struct ieee80211vap *)
static int monitor_input(struct ieee80211_node *ni, struct mbuf *m, const struct ieee80211_rx_stats *rxs, int rssi, int nf)
static void monitor_vdetach(struct ieee80211vap *vap)
__FBSDID("$FreeBSD$")
static int monitor_newstate(struct ieee80211vap *, enum ieee80211_state, int)
void ieee80211_monitor_detach(struct ieee80211com *ic)
void ieee80211_monitor_attach(struct ieee80211com *ic)
void ieee80211_node_authorize(struct ieee80211_node *ni)
void ieee80211_create_ibss(struct ieee80211vap *vap, struct ieee80211_channel *chan)
const char * ieee80211_state_name[IEEE80211_S_MAX]
ieee80211_state
@ IEEE80211_S_RUN
@ IEEE80211_S_INIT
void ieee80211_radiotap_rx(struct ieee80211vap *vap0, struct mbuf *m)
static __inline int ieee80211_radiotap_active_vap(const struct ieee80211vap *vap)
#define IEEE80211_MSG_STATE
#define IEEE80211_DPRINTF(_vap, _m, _fmt,...)
struct ieee80211vap * ni_vap
ieee80211vap_attach ic_vattach[IEEE80211_OPMODE_MAX]
struct ieee80211_channel * ic_curchan
struct ieee80211com * iv_ic
struct ieee80211_node * iv_bss
enum ieee80211_state iv_state
void(* iv_opdetach)(struct ieee80211vap *)
int(* iv_input)(struct ieee80211_node *, struct mbuf *, const struct ieee80211_rx_stats *, int, int)
struct ifnet * iv_ifp
int(* iv_newstate)(struct ieee80211vap *, enum ieee80211_state, int)