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 $
29 * IEEE 802.11 send/recv action frame support.
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
39 #include <sys/socket.h>
42 #include <net/if_media.h>
43 #include <net/ethernet.h>
44 #include <net/route.h>
46 #include <netproto/802_11/ieee80211_var.h>
47 #include <netproto/802_11/ieee80211_action.h>
48 #include <netproto/802_11/ieee80211_mesh.h>
51 send_inval(struct ieee80211_node *ni, int cat, int act, void *sa)
56 static ieee80211_send_action_func *ba_send_action[8] = {
57 send_inval, send_inval, send_inval, send_inval,
58 send_inval, send_inval, send_inval, send_inval,
60 static ieee80211_send_action_func *ht_send_action[8] = {
61 send_inval, send_inval, send_inval, send_inval,
62 send_inval, send_inval, send_inval, send_inval,
64 static ieee80211_send_action_func *meshpl_send_action[8] = {
65 send_inval, send_inval, send_inval, send_inval,
66 send_inval, send_inval, send_inval, send_inval,
68 static ieee80211_send_action_func *meshlm_send_action[4] = {
69 send_inval, send_inval, send_inval, send_inval,
71 static ieee80211_send_action_func *hwmp_send_action[8] = {
72 send_inval, send_inval, send_inval, send_inval,
73 send_inval, send_inval, send_inval, send_inval,
75 static ieee80211_send_action_func *vendor_send_action[8] = {
76 send_inval, send_inval, send_inval, send_inval,
77 send_inval, send_inval, send_inval, send_inval,
81 ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f)
84 case IEEE80211_ACTION_CAT_BA:
85 if (act >= NELEM(ba_send_action))
87 ba_send_action[act] = f;
89 case IEEE80211_ACTION_CAT_HT:
90 if (act >= NELEM(ht_send_action))
92 ht_send_action[act] = f;
94 case IEEE80211_ACTION_CAT_MESHPEERING:
95 if (act >= NELEM(meshpl_send_action))
97 meshpl_send_action[act] = f;
99 case IEEE80211_ACTION_CAT_MESHLMETRIC:
100 if (act >= NELEM(meshlm_send_action))
102 meshlm_send_action[act] = f;
104 case IEEE80211_ACTION_CAT_MESHPATH:
105 if (act >= NELEM(hwmp_send_action))
107 hwmp_send_action[act] = f;
109 case IEEE80211_ACTION_CAT_VENDOR:
110 if (act >= NELEM(vendor_send_action))
112 vendor_send_action[act] = f;
119 ieee80211_send_action_unregister(int cat, int act)
121 ieee80211_send_action_register(cat, act, send_inval);
125 ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
127 ieee80211_send_action_func *f = send_inval;
130 case IEEE80211_ACTION_CAT_BA:
131 if (act < NELEM(ba_send_action))
132 f = ba_send_action[act];
134 case IEEE80211_ACTION_CAT_HT:
135 if (act < NELEM(ht_send_action))
136 f = ht_send_action[act];
138 case IEEE80211_ACTION_CAT_MESHPEERING:
139 if (act < NELEM(meshpl_send_action))
140 f = meshpl_send_action[act];
142 case IEEE80211_ACTION_CAT_MESHLMETRIC:
143 if (act < NELEM(meshlm_send_action))
144 f = meshlm_send_action[act];
146 case IEEE80211_ACTION_CAT_MESHPATH:
147 if (act < NELEM(hwmp_send_action))
148 f = hwmp_send_action[act];
150 case IEEE80211_ACTION_CAT_VENDOR:
151 if (act < NELEM(vendor_send_action))
152 f = vendor_send_action[act];
155 return f(ni, cat, act, sa);
159 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
160 const uint8_t *frm, const uint8_t *efrm)
165 static ieee80211_recv_action_func *ba_recv_action[8] = {
166 recv_inval, recv_inval, recv_inval, recv_inval,
167 recv_inval, recv_inval, recv_inval, recv_inval,
169 static ieee80211_recv_action_func *ht_recv_action[8] = {
170 recv_inval, recv_inval, recv_inval, recv_inval,
171 recv_inval, recv_inval, recv_inval, recv_inval,
173 static ieee80211_recv_action_func *meshpl_recv_action[8] = {
174 recv_inval, recv_inval, recv_inval, recv_inval,
175 recv_inval, recv_inval, recv_inval, recv_inval,
177 static ieee80211_recv_action_func *meshlm_recv_action[4] = {
178 recv_inval, recv_inval, recv_inval, recv_inval,
180 static ieee80211_recv_action_func *hwmp_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 *vendor_recv_action[8] = {
185 recv_inval, recv_inval, recv_inval, recv_inval,
186 recv_inval, recv_inval, recv_inval, recv_inval,
190 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
193 case IEEE80211_ACTION_CAT_BA:
194 if (act >= NELEM(ba_recv_action))
196 ba_recv_action[act] = f;
198 case IEEE80211_ACTION_CAT_HT:
199 if (act >= NELEM(ht_recv_action))
201 ht_recv_action[act] = f;
203 case IEEE80211_ACTION_CAT_MESHPEERING:
204 if (act >= NELEM(meshpl_recv_action))
206 meshpl_recv_action[act] = f;
208 case IEEE80211_ACTION_CAT_MESHLMETRIC:
209 if (act >= NELEM(meshlm_recv_action))
211 meshlm_recv_action[act] = f;
213 case IEEE80211_ACTION_CAT_MESHPATH:
214 if (act >= NELEM(hwmp_recv_action))
216 hwmp_recv_action[act] = f;
218 case IEEE80211_ACTION_CAT_VENDOR:
219 if (act >= NELEM(vendor_recv_action))
221 vendor_recv_action[act] = f;
228 ieee80211_recv_action_unregister(int cat, int act)
230 ieee80211_recv_action_register(cat, act, recv_inval);
234 ieee80211_recv_action(struct ieee80211_node *ni,
235 const struct ieee80211_frame *wh,
236 const uint8_t *frm, const uint8_t *efrm)
238 ieee80211_recv_action_func *f = recv_inval;
239 const struct ieee80211_action *ia =
240 (const struct ieee80211_action *) frm;
242 switch (ia->ia_category) {
243 case IEEE80211_ACTION_CAT_BA:
244 if (ia->ia_action < NELEM(ba_recv_action))
245 f = ba_recv_action[ia->ia_action];
247 case IEEE80211_ACTION_CAT_HT:
248 if (ia->ia_action < NELEM(ht_recv_action))
249 f = ht_recv_action[ia->ia_action];
251 case IEEE80211_ACTION_CAT_MESHPEERING:
252 if (ia->ia_action < NELEM(meshpl_recv_action))
253 f = meshpl_recv_action[ia->ia_action];
255 case IEEE80211_ACTION_CAT_MESHLMETRIC:
256 if (ia->ia_action < NELEM(meshlm_recv_action))
257 f = meshlm_recv_action[ia->ia_action];
259 case IEEE80211_ACTION_CAT_MESHPATH:
260 if (ia->ia_action < NELEM(hwmp_recv_action))
261 f = hwmp_recv_action[ia->ia_action];
263 case IEEE80211_ACTION_CAT_VENDOR:
264 if (ia->ia_action < NELEM(vendor_recv_action))
265 f = vendor_recv_action[ia->ia_action];
268 return f(ni, wh, frm, efrm);