2 * Copyright (c) 2009 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $FreeBSD: head/sys/net80211/ieee80211_action.c 199186 2009-11-11 14:58:48Z antoine $
30 * IEEE 802.11 send/recv action frame support.
36 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/systm.h>
40 #include <sys/socket.h>
43 #include <net/if_media.h>
44 #include <net/ethernet.h>
45 #include <net/route.h>
47 #include <netproto/802_11/ieee80211_var.h>
48 #include <netproto/802_11/ieee80211_action.h>
49 #include <netproto/802_11/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 *meshlm_send_action[4] = {
70 send_inval, send_inval, send_inval, send_inval,
72 static ieee80211_send_action_func *hwmp_send_action[8] = {
73 send_inval, send_inval, send_inval, send_inval,
74 send_inval, send_inval, send_inval, send_inval,
76 static ieee80211_send_action_func *vendor_send_action[8] = {
77 send_inval, send_inval, send_inval, send_inval,
78 send_inval, send_inval, send_inval, send_inval,
82 ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f)
85 case IEEE80211_ACTION_CAT_BA:
86 if (act >= NELEM(ba_send_action))
88 ba_send_action[act] = f;
90 case IEEE80211_ACTION_CAT_HT:
91 if (act >= NELEM(ht_send_action))
93 ht_send_action[act] = f;
95 case IEEE80211_ACTION_CAT_MESHPEERING:
96 if (act >= NELEM(meshpl_send_action))
98 meshpl_send_action[act] = f;
100 case IEEE80211_ACTION_CAT_MESHLMETRIC:
101 if (act >= NELEM(meshlm_send_action))
103 meshlm_send_action[act] = f;
105 case IEEE80211_ACTION_CAT_MESHPATH:
106 if (act >= NELEM(hwmp_send_action))
108 hwmp_send_action[act] = f;
110 case IEEE80211_ACTION_CAT_VENDOR:
111 if (act >= NELEM(vendor_send_action))
113 vendor_send_action[act] = f;
120 ieee80211_send_action_unregister(int cat, int act)
122 ieee80211_send_action_register(cat, act, send_inval);
126 ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
128 ieee80211_send_action_func *f = send_inval;
131 case IEEE80211_ACTION_CAT_BA:
132 if (act < NELEM(ba_send_action))
133 f = ba_send_action[act];
135 case IEEE80211_ACTION_CAT_HT:
136 if (act < NELEM(ht_send_action))
137 f = ht_send_action[act];
139 case IEEE80211_ACTION_CAT_MESHPEERING:
140 if (act < NELEM(meshpl_send_action))
141 f = meshpl_send_action[act];
143 case IEEE80211_ACTION_CAT_MESHLMETRIC:
144 if (act < NELEM(meshlm_send_action))
145 f = meshlm_send_action[act];
147 case IEEE80211_ACTION_CAT_MESHPATH:
148 if (act < NELEM(hwmp_send_action))
149 f = hwmp_send_action[act];
151 case IEEE80211_ACTION_CAT_VENDOR:
152 if (act < NELEM(vendor_send_action))
153 f = vendor_send_action[act];
156 return f(ni, cat, act, sa);
160 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
161 const uint8_t *frm, const uint8_t *efrm)
166 static ieee80211_recv_action_func *ba_recv_action[8] = {
167 recv_inval, recv_inval, recv_inval, recv_inval,
168 recv_inval, recv_inval, recv_inval, recv_inval,
170 static ieee80211_recv_action_func *ht_recv_action[8] = {
171 recv_inval, recv_inval, recv_inval, recv_inval,
172 recv_inval, recv_inval, recv_inval, recv_inval,
174 static ieee80211_recv_action_func *meshpl_recv_action[8] = {
175 recv_inval, recv_inval, recv_inval, recv_inval,
176 recv_inval, recv_inval, recv_inval, recv_inval,
178 static ieee80211_recv_action_func *meshlm_recv_action[4] = {
179 recv_inval, recv_inval, recv_inval, recv_inval,
181 static ieee80211_recv_action_func *hwmp_recv_action[8] = {
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,
191 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
194 case IEEE80211_ACTION_CAT_BA:
195 if (act >= NELEM(ba_recv_action))
197 ba_recv_action[act] = f;
199 case IEEE80211_ACTION_CAT_HT:
200 if (act >= NELEM(ht_recv_action))
202 ht_recv_action[act] = f;
204 case IEEE80211_ACTION_CAT_MESHPEERING:
205 if (act >= NELEM(meshpl_recv_action))
207 meshpl_recv_action[act] = f;
209 case IEEE80211_ACTION_CAT_MESHLMETRIC:
210 if (act >= NELEM(meshlm_recv_action))
212 meshlm_recv_action[act] = f;
214 case IEEE80211_ACTION_CAT_MESHPATH:
215 if (act >= NELEM(hwmp_recv_action))
217 hwmp_recv_action[act] = f;
219 case IEEE80211_ACTION_CAT_VENDOR:
220 if (act >= NELEM(vendor_recv_action))
222 vendor_recv_action[act] = f;
229 ieee80211_recv_action_unregister(int cat, int act)
231 ieee80211_recv_action_register(cat, act, recv_inval);
235 ieee80211_recv_action(struct ieee80211_node *ni,
236 const struct ieee80211_frame *wh,
237 const uint8_t *frm, const uint8_t *efrm)
239 ieee80211_recv_action_func *f = recv_inval;
240 const struct ieee80211_action *ia =
241 (const struct ieee80211_action *) frm;
243 switch (ia->ia_category) {
244 case IEEE80211_ACTION_CAT_BA:
245 if (ia->ia_action < NELEM(ba_recv_action))
246 f = ba_recv_action[ia->ia_action];
248 case IEEE80211_ACTION_CAT_HT:
249 if (ia->ia_action < NELEM(ht_recv_action))
250 f = ht_recv_action[ia->ia_action];
252 case IEEE80211_ACTION_CAT_MESHPEERING:
253 if (ia->ia_action < NELEM(meshpl_recv_action))
254 f = meshpl_recv_action[ia->ia_action];
256 case IEEE80211_ACTION_CAT_MESHLMETRIC:
257 if (ia->ia_action < NELEM(meshlm_recv_action))
258 f = meshlm_recv_action[ia->ia_action];
260 case IEEE80211_ACTION_CAT_MESHPATH:
261 if (ia->ia_action < NELEM(hwmp_recv_action))
262 f = hwmp_recv_action[ia->ia_action];
264 case IEEE80211_ACTION_CAT_VENDOR:
265 if (ia->ia_action < NELEM(vendor_recv_action))
266 f = vendor_recv_action[ia->ia_action];
269 return f(ni, wh, frm, efrm);