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.
26 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 * IEEE 802.11 send/recv action frame support.
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
42 #include <sys/socket.h>
45 #include <net/if_media.h>
46 #include <net/ethernet.h>
48 #include <net80211/ieee80211_var.h>
49 #include <net80211/ieee80211_action.h>
50 #include <net80211/ieee80211_mesh.h>
53 send_inval(struct ieee80211_node *ni, int cat, int act, void *sa)
58 static ieee80211_send_action_func *ba_send_action[8] = {
59 send_inval, send_inval, send_inval, send_inval,
60 send_inval, send_inval, send_inval, send_inval,
62 static ieee80211_send_action_func *ht_send_action[8] = {
63 send_inval, send_inval, send_inval, send_inval,
64 send_inval, send_inval, send_inval, send_inval,
66 static ieee80211_send_action_func *meshpl_send_action[8] = {
67 send_inval, send_inval, send_inval, send_inval,
68 send_inval, send_inval, send_inval, send_inval,
70 static ieee80211_send_action_func *meshaction_send_action[12] = {
71 send_inval, send_inval, send_inval, send_inval,
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 >= nitems(ba_send_action))
87 ba_send_action[act] = f;
89 case IEEE80211_ACTION_CAT_HT:
90 if (act >= nitems(ht_send_action))
92 ht_send_action[act] = f;
94 case IEEE80211_ACTION_CAT_SELF_PROT:
95 if (act >= nitems(meshpl_send_action))
97 meshpl_send_action[act] = f;
99 case IEEE80211_ACTION_CAT_MESH:
100 if (act >= nitems(meshaction_send_action))
102 meshaction_send_action[act] = f;
105 case IEEE80211_ACTION_CAT_VENDOR:
106 if (act >= nitems(vendor_send_action))
108 vendor_send_action[act] = f;
115 ieee80211_send_action_unregister(int cat, int act)
117 ieee80211_send_action_register(cat, act, send_inval);
121 ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
123 ieee80211_send_action_func *f = send_inval;
126 case IEEE80211_ACTION_CAT_BA:
127 if (act < nitems(ba_send_action))
128 f = ba_send_action[act];
130 case IEEE80211_ACTION_CAT_HT:
131 if (act < nitems(ht_send_action))
132 f = ht_send_action[act];
134 case IEEE80211_ACTION_CAT_SELF_PROT:
135 if (act < nitems(meshpl_send_action))
136 f = meshpl_send_action[act];
138 case IEEE80211_ACTION_CAT_MESH:
139 if (act < nitems(meshaction_send_action))
140 f = meshaction_send_action[act];
142 case IEEE80211_ACTION_CAT_VENDOR:
143 if (act < nitems(vendor_send_action))
144 f = vendor_send_action[act];
147 return f(ni, cat, act, sa);
151 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
152 const uint8_t *frm, const uint8_t *efrm)
157 static ieee80211_recv_action_func *ba_recv_action[8] = {
158 recv_inval, recv_inval, recv_inval, recv_inval,
159 recv_inval, recv_inval, recv_inval, recv_inval,
161 static ieee80211_recv_action_func *ht_recv_action[8] = {
162 recv_inval, recv_inval, recv_inval, recv_inval,
163 recv_inval, recv_inval, recv_inval, recv_inval,
165 static ieee80211_recv_action_func *meshpl_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 *meshaction_recv_action[12] = {
170 recv_inval, recv_inval, recv_inval, recv_inval,
171 recv_inval, recv_inval, recv_inval, recv_inval,
172 recv_inval, recv_inval, recv_inval, recv_inval,
174 static ieee80211_recv_action_func *vendor_recv_action[8] = {
175 recv_inval, recv_inval, recv_inval, recv_inval,
176 recv_inval, recv_inval, recv_inval, recv_inval,
180 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
183 case IEEE80211_ACTION_CAT_BA:
184 if (act >= nitems(ba_recv_action))
186 ba_recv_action[act] = f;
188 case IEEE80211_ACTION_CAT_HT:
189 if (act >= nitems(ht_recv_action))
191 ht_recv_action[act] = f;
193 case IEEE80211_ACTION_CAT_SELF_PROT:
194 if (act >= nitems(meshpl_recv_action))
196 meshpl_recv_action[act] = f;
198 case IEEE80211_ACTION_CAT_MESH:
199 if (act >= nitems(meshaction_recv_action))
201 meshaction_recv_action[act] = f;
203 case IEEE80211_ACTION_CAT_VENDOR:
204 if (act >= nitems(vendor_recv_action))
206 vendor_recv_action[act] = f;
213 ieee80211_recv_action_unregister(int cat, int act)
215 ieee80211_recv_action_register(cat, act, recv_inval);
219 ieee80211_recv_action(struct ieee80211_node *ni,
220 const struct ieee80211_frame *wh,
221 const uint8_t *frm, const uint8_t *efrm)
223 ieee80211_recv_action_func *f = recv_inval;
224 struct ieee80211vap *vap = ni->ni_vap;
225 const struct ieee80211_action *ia =
226 (const struct ieee80211_action *) frm;
228 switch (ia->ia_category) {
229 case IEEE80211_ACTION_CAT_BA:
230 if (ia->ia_action < nitems(ba_recv_action))
231 f = ba_recv_action[ia->ia_action];
233 case IEEE80211_ACTION_CAT_HT:
234 if (ia->ia_action < nitems(ht_recv_action))
235 f = ht_recv_action[ia->ia_action];
237 case IEEE80211_ACTION_CAT_SELF_PROT:
238 if (ia->ia_action < nitems(meshpl_recv_action))
239 f = meshpl_recv_action[ia->ia_action];
241 case IEEE80211_ACTION_CAT_MESH:
242 if (ni == vap->iv_bss ||
243 ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
244 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
245 ni->ni_macaddr, NULL,
246 "peer link not yet established (%d), cat %s act %u",
247 ni->ni_mlstate, "mesh action", ia->ia_action);
248 vap->iv_stats.is_mesh_nolink++;
251 if (ia->ia_action < nitems(meshaction_recv_action))
252 f = meshaction_recv_action[ia->ia_action];
254 case IEEE80211_ACTION_CAT_VENDOR:
255 if (ia->ia_action < nitems(vendor_recv_action))
256 f = vendor_recv_action[ia->ia_action];
259 return f(ni, wh, frm, efrm);