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.
29 * IEEE 802.11 send/recv action frame support.
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/systm.h>
40 #include <sys/socket.h>
43 #include <net/if_var.h>
44 #include <net/if_media.h>
45 #include <net/ethernet.h>
47 #include <net80211/ieee80211_var.h>
48 #include <net80211/ieee80211_action.h>
49 #include <net80211/ieee80211_mesh.h>
52 send_inval(struct ieee80211_node *ni, int cat, int act, void *sa)
57 static ieee80211_send_action_func *ba_send_action[8] = {
58 send_inval, send_inval, send_inval, send_inval,
59 send_inval, send_inval, send_inval, send_inval,
61 static ieee80211_send_action_func *ht_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 *meshpl_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 *meshaction_send_action[12] = {
70 send_inval, send_inval, send_inval, send_inval,
71 send_inval, send_inval, send_inval, send_inval,
72 send_inval, send_inval, send_inval, send_inval,
74 static ieee80211_send_action_func *vendor_send_action[8] = {
75 send_inval, send_inval, send_inval, send_inval,
76 send_inval, send_inval, send_inval, send_inval,
79 static ieee80211_send_action_func *vht_send_action[3] = {
80 send_inval, send_inval, send_inval,
84 ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f)
87 case IEEE80211_ACTION_CAT_BA:
88 if (act >= nitems(ba_send_action))
90 ba_send_action[act] = f;
92 case IEEE80211_ACTION_CAT_HT:
93 if (act >= nitems(ht_send_action))
95 ht_send_action[act] = f;
97 case IEEE80211_ACTION_CAT_SELF_PROT:
98 if (act >= nitems(meshpl_send_action))
100 meshpl_send_action[act] = f;
102 case IEEE80211_ACTION_CAT_MESH:
103 if (act >= nitems(meshaction_send_action))
105 meshaction_send_action[act] = f;
107 case IEEE80211_ACTION_CAT_VENDOR:
108 if (act >= nitems(vendor_send_action))
110 vendor_send_action[act] = f;
112 case IEEE80211_ACTION_CAT_VHT:
113 if (act >= nitems(vht_send_action))
115 vht_send_action[act] = f;
122 ieee80211_send_action_unregister(int cat, int act)
124 ieee80211_send_action_register(cat, act, send_inval);
128 ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
130 ieee80211_send_action_func *f = send_inval;
133 case IEEE80211_ACTION_CAT_BA:
134 if (act < nitems(ba_send_action))
135 f = ba_send_action[act];
137 case IEEE80211_ACTION_CAT_HT:
138 if (act < nitems(ht_send_action))
139 f = ht_send_action[act];
141 case IEEE80211_ACTION_CAT_SELF_PROT:
142 if (act < nitems(meshpl_send_action))
143 f = meshpl_send_action[act];
145 case IEEE80211_ACTION_CAT_MESH:
146 if (act < nitems(meshaction_send_action))
147 f = meshaction_send_action[act];
149 case IEEE80211_ACTION_CAT_VENDOR:
150 if (act < nitems(vendor_send_action))
151 f = vendor_send_action[act];
153 case IEEE80211_ACTION_CAT_VHT:
154 if (act < nitems(vht_send_action))
155 f = vht_send_action[act];
158 return f(ni, cat, act, sa);
162 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
163 const uint8_t *frm, const uint8_t *efrm)
168 static ieee80211_recv_action_func *ba_recv_action[8] = {
169 recv_inval, recv_inval, recv_inval, recv_inval,
170 recv_inval, recv_inval, recv_inval, recv_inval,
172 static ieee80211_recv_action_func *ht_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 *meshpl_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 *meshaction_recv_action[12] = {
181 recv_inval, recv_inval, recv_inval, recv_inval,
182 recv_inval, recv_inval, recv_inval, recv_inval,
183 recv_inval, recv_inval, recv_inval, recv_inval,
185 static ieee80211_recv_action_func *vendor_recv_action[8] = {
186 recv_inval, recv_inval, recv_inval, recv_inval,
187 recv_inval, recv_inval, recv_inval, recv_inval,
190 static ieee80211_recv_action_func *vht_recv_action[3] = {
191 recv_inval, recv_inval, recv_inval
195 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
198 case IEEE80211_ACTION_CAT_BA:
199 if (act >= nitems(ba_recv_action))
201 ba_recv_action[act] = f;
203 case IEEE80211_ACTION_CAT_HT:
204 if (act >= nitems(ht_recv_action))
206 ht_recv_action[act] = f;
208 case IEEE80211_ACTION_CAT_SELF_PROT:
209 if (act >= nitems(meshpl_recv_action))
211 meshpl_recv_action[act] = f;
213 case IEEE80211_ACTION_CAT_MESH:
214 if (act >= nitems(meshaction_recv_action))
216 meshaction_recv_action[act] = f;
218 case IEEE80211_ACTION_CAT_VENDOR:
219 if (act >= nitems(vendor_recv_action))
221 vendor_recv_action[act] = f;
223 case IEEE80211_ACTION_CAT_VHT:
224 if (act >= nitems(vht_recv_action))
226 vht_recv_action[act] = f;
233 ieee80211_recv_action_unregister(int cat, int act)
235 ieee80211_recv_action_register(cat, act, recv_inval);
239 ieee80211_recv_action(struct ieee80211_node *ni,
240 const struct ieee80211_frame *wh,
241 const uint8_t *frm, const uint8_t *efrm)
243 ieee80211_recv_action_func *f = recv_inval;
244 struct ieee80211vap *vap = ni->ni_vap;
245 const struct ieee80211_action *ia =
246 (const struct ieee80211_action *) frm;
248 switch (ia->ia_category) {
249 case IEEE80211_ACTION_CAT_BA:
250 if (ia->ia_action < nitems(ba_recv_action))
251 f = ba_recv_action[ia->ia_action];
253 case IEEE80211_ACTION_CAT_HT:
254 if (ia->ia_action < nitems(ht_recv_action))
255 f = ht_recv_action[ia->ia_action];
257 case IEEE80211_ACTION_CAT_SELF_PROT:
258 if (ia->ia_action < nitems(meshpl_recv_action))
259 f = meshpl_recv_action[ia->ia_action];
261 case IEEE80211_ACTION_CAT_MESH:
262 if (ni == vap->iv_bss ||
263 ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
264 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
265 ni->ni_macaddr, NULL,
266 "peer link not yet established (%d), cat %s act %u",
267 ni->ni_mlstate, "mesh action", ia->ia_action);
268 vap->iv_stats.is_mesh_nolink++;
271 if (ia->ia_action < nitems(meshaction_recv_action))
272 f = meshaction_recv_action[ia->ia_action];
274 case IEEE80211_ACTION_CAT_VENDOR:
275 if (ia->ia_action < nitems(vendor_recv_action))
276 f = vendor_recv_action[ia->ia_action];
278 case IEEE80211_ACTION_CAT_VHT:
279 if (ia->ia_action < nitems(vht_recv_action))
280 f = vht_recv_action[ia->ia_action];
283 return f(ni, wh, frm, efrm);