2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2009 Sam Leffler, Errno Consulting
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
28 #include <sys/cdefs.h>
33 * IEEE 802.11 send/recv action frame support.
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/malloc.h>
42 #include <sys/systm.h>
44 #include <sys/socket.h>
47 #include <net/if_var.h>
48 #include <net/if_media.h>
49 #include <net/ethernet.h>
51 #include <net80211/ieee80211_var.h>
52 #include <net80211/ieee80211_action.h>
53 #include <net80211/ieee80211_mesh.h>
56 send_inval(struct ieee80211_node *ni, int cat, int act, void *sa)
61 static ieee80211_send_action_func *ba_send_action[8] = {
62 send_inval, send_inval, send_inval, send_inval,
63 send_inval, send_inval, send_inval, send_inval,
65 static ieee80211_send_action_func *ht_send_action[8] = {
66 send_inval, send_inval, send_inval, send_inval,
67 send_inval, send_inval, send_inval, send_inval,
69 static ieee80211_send_action_func *meshpl_send_action[8] = {
70 send_inval, send_inval, send_inval, send_inval,
71 send_inval, send_inval, send_inval, send_inval,
73 static ieee80211_send_action_func *meshaction_send_action[12] = {
74 send_inval, send_inval, send_inval, send_inval,
75 send_inval, send_inval, send_inval, send_inval,
76 send_inval, send_inval, send_inval, send_inval,
78 static ieee80211_send_action_func *vendor_send_action[8] = {
79 send_inval, send_inval, send_inval, send_inval,
80 send_inval, send_inval, send_inval, send_inval,
83 static ieee80211_send_action_func *vht_send_action[3] = {
84 send_inval, send_inval, send_inval,
88 ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f)
91 case IEEE80211_ACTION_CAT_BA:
92 if (act >= nitems(ba_send_action))
94 ba_send_action[act] = f;
96 case IEEE80211_ACTION_CAT_HT:
97 if (act >= nitems(ht_send_action))
99 ht_send_action[act] = f;
101 case IEEE80211_ACTION_CAT_SELF_PROT:
102 if (act >= nitems(meshpl_send_action))
104 meshpl_send_action[act] = f;
106 case IEEE80211_ACTION_CAT_MESH:
107 if (act >= nitems(meshaction_send_action))
109 meshaction_send_action[act] = f;
111 case IEEE80211_ACTION_CAT_VENDOR:
112 if (act >= nitems(vendor_send_action))
114 vendor_send_action[act] = f;
116 case IEEE80211_ACTION_CAT_VHT:
117 if (act >= nitems(vht_send_action))
119 vht_send_action[act] = f;
126 ieee80211_send_action_unregister(int cat, int act)
128 ieee80211_send_action_register(cat, act, send_inval);
132 ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
134 ieee80211_send_action_func *f = send_inval;
137 case IEEE80211_ACTION_CAT_BA:
138 if (act < nitems(ba_send_action))
139 f = ba_send_action[act];
141 case IEEE80211_ACTION_CAT_HT:
142 if (act < nitems(ht_send_action))
143 f = ht_send_action[act];
145 case IEEE80211_ACTION_CAT_SELF_PROT:
146 if (act < nitems(meshpl_send_action))
147 f = meshpl_send_action[act];
149 case IEEE80211_ACTION_CAT_MESH:
150 if (act < nitems(meshaction_send_action))
151 f = meshaction_send_action[act];
153 case IEEE80211_ACTION_CAT_VENDOR:
154 if (act < nitems(vendor_send_action))
155 f = vendor_send_action[act];
157 case IEEE80211_ACTION_CAT_VHT:
158 if (act < nitems(vht_send_action))
159 f = vht_send_action[act];
162 return f(ni, cat, act, sa);
166 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
167 const uint8_t *frm, const uint8_t *efrm)
172 static ieee80211_recv_action_func *ba_recv_action[8] = {
173 recv_inval, recv_inval, recv_inval, recv_inval,
174 recv_inval, recv_inval, recv_inval, recv_inval,
176 static ieee80211_recv_action_func *ht_recv_action[8] = {
177 recv_inval, recv_inval, recv_inval, recv_inval,
178 recv_inval, recv_inval, recv_inval, recv_inval,
180 static ieee80211_recv_action_func *meshpl_recv_action[8] = {
181 recv_inval, recv_inval, recv_inval, recv_inval,
182 recv_inval, recv_inval, recv_inval, recv_inval,
184 static ieee80211_recv_action_func *meshaction_recv_action[12] = {
185 recv_inval, recv_inval, recv_inval, recv_inval,
186 recv_inval, recv_inval, recv_inval, recv_inval,
187 recv_inval, recv_inval, recv_inval, recv_inval,
189 static ieee80211_recv_action_func *vendor_recv_action[8] = {
190 recv_inval, recv_inval, recv_inval, recv_inval,
191 recv_inval, recv_inval, recv_inval, recv_inval,
194 static ieee80211_recv_action_func *vht_recv_action[3] = {
195 recv_inval, recv_inval, recv_inval
199 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
202 case IEEE80211_ACTION_CAT_BA:
203 if (act >= nitems(ba_recv_action))
205 ba_recv_action[act] = f;
207 case IEEE80211_ACTION_CAT_HT:
208 if (act >= nitems(ht_recv_action))
210 ht_recv_action[act] = f;
212 case IEEE80211_ACTION_CAT_SELF_PROT:
213 if (act >= nitems(meshpl_recv_action))
215 meshpl_recv_action[act] = f;
217 case IEEE80211_ACTION_CAT_MESH:
218 if (act >= nitems(meshaction_recv_action))
220 meshaction_recv_action[act] = f;
222 case IEEE80211_ACTION_CAT_VENDOR:
223 if (act >= nitems(vendor_recv_action))
225 vendor_recv_action[act] = f;
227 case IEEE80211_ACTION_CAT_VHT:
228 if (act >= nitems(vht_recv_action))
230 vht_recv_action[act] = f;
237 ieee80211_recv_action_unregister(int cat, int act)
239 ieee80211_recv_action_register(cat, act, recv_inval);
243 ieee80211_recv_action(struct ieee80211_node *ni,
244 const struct ieee80211_frame *wh,
245 const uint8_t *frm, const uint8_t *efrm)
247 ieee80211_recv_action_func *f = recv_inval;
248 struct ieee80211vap *vap = ni->ni_vap;
249 const struct ieee80211_action *ia =
250 (const struct ieee80211_action *) frm;
252 switch (ia->ia_category) {
253 case IEEE80211_ACTION_CAT_BA:
254 if (ia->ia_action < nitems(ba_recv_action))
255 f = ba_recv_action[ia->ia_action];
257 case IEEE80211_ACTION_CAT_HT:
258 if (ia->ia_action < nitems(ht_recv_action))
259 f = ht_recv_action[ia->ia_action];
261 case IEEE80211_ACTION_CAT_SELF_PROT:
262 if (ia->ia_action < nitems(meshpl_recv_action))
263 f = meshpl_recv_action[ia->ia_action];
265 case IEEE80211_ACTION_CAT_MESH:
266 if (ni == vap->iv_bss ||
267 ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
268 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
269 ni->ni_macaddr, NULL,
270 "peer link not yet established (%d), cat %s act %u",
271 ni->ni_mlstate, "mesh action", ia->ia_action);
272 vap->iv_stats.is_mesh_nolink++;
275 if (ia->ia_action < nitems(meshaction_recv_action))
276 f = meshaction_recv_action[ia->ia_action];
278 case IEEE80211_ACTION_CAT_VENDOR:
279 if (ia->ia_action < nitems(vendor_recv_action))
280 f = vendor_recv_action[ia->ia_action];
282 case IEEE80211_ACTION_CAT_VHT:
283 if (ia->ia_action < nitems(vht_recv_action))
284 f = vht_recv_action[ia->ia_action];
287 return f(ni, wh, frm, efrm);