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_var.h>
46 #include <net/if_media.h>
47 #include <net/ethernet.h>
49 #include <netproto/802_11/ieee80211_var.h>
50 #include <netproto/802_11/ieee80211_action.h>
51 #include <netproto/802_11/ieee80211_mesh.h>
54 send_inval(struct ieee80211_node *ni, int cat, int act, void *sa)
59 static ieee80211_send_action_func *ba_send_action[8] = {
60 send_inval, send_inval, send_inval, send_inval,
61 send_inval, send_inval, send_inval, send_inval,
63 static ieee80211_send_action_func *ht_send_action[8] = {
64 send_inval, send_inval, send_inval, send_inval,
65 send_inval, send_inval, send_inval, send_inval,
67 static ieee80211_send_action_func *meshpl_send_action[8] = {
68 send_inval, send_inval, send_inval, send_inval,
69 send_inval, send_inval, send_inval, send_inval,
71 static ieee80211_send_action_func *meshaction_send_action[12] = {
72 send_inval, send_inval, send_inval, send_inval,
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 >= nitems(ba_send_action))
88 ba_send_action[act] = f;
90 case IEEE80211_ACTION_CAT_HT:
91 if (act >= nitems(ht_send_action))
93 ht_send_action[act] = f;
95 case IEEE80211_ACTION_CAT_SELF_PROT:
96 if (act >= nitems(meshpl_send_action))
98 meshpl_send_action[act] = f;
100 case IEEE80211_ACTION_CAT_MESH:
101 if (act >= nitems(meshaction_send_action))
103 meshaction_send_action[act] = f;
106 case IEEE80211_ACTION_CAT_VENDOR:
107 if (act >= nitems(vendor_send_action))
109 vendor_send_action[act] = f;
116 ieee80211_send_action_unregister(int cat, int act)
118 ieee80211_send_action_register(cat, act, send_inval);
122 ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
124 ieee80211_send_action_func *f = send_inval;
127 case IEEE80211_ACTION_CAT_BA:
128 if (act < nitems(ba_send_action))
129 f = ba_send_action[act];
131 case IEEE80211_ACTION_CAT_HT:
132 if (act < nitems(ht_send_action))
133 f = ht_send_action[act];
135 case IEEE80211_ACTION_CAT_SELF_PROT:
136 if (act < nitems(meshpl_send_action))
137 f = meshpl_send_action[act];
139 case IEEE80211_ACTION_CAT_MESH:
140 if (act < nitems(meshaction_send_action))
141 f = meshaction_send_action[act];
143 case IEEE80211_ACTION_CAT_VENDOR:
144 if (act < nitems(vendor_send_action))
145 f = vendor_send_action[act];
148 return f(ni, cat, act, sa);
152 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
153 const uint8_t *frm, const uint8_t *efrm)
158 static ieee80211_recv_action_func *ba_recv_action[8] = {
159 recv_inval, recv_inval, recv_inval, recv_inval,
160 recv_inval, recv_inval, recv_inval, recv_inval,
162 static ieee80211_recv_action_func *ht_recv_action[8] = {
163 recv_inval, recv_inval, recv_inval, recv_inval,
164 recv_inval, recv_inval, recv_inval, recv_inval,
166 static ieee80211_recv_action_func *meshpl_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 *meshaction_recv_action[12] = {
171 recv_inval, recv_inval, recv_inval, recv_inval,
172 recv_inval, recv_inval, recv_inval, recv_inval,
173 recv_inval, recv_inval, recv_inval, recv_inval,
175 static ieee80211_recv_action_func *vendor_recv_action[8] = {
176 recv_inval, recv_inval, recv_inval, recv_inval,
177 recv_inval, recv_inval, recv_inval, recv_inval,
181 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
184 case IEEE80211_ACTION_CAT_BA:
185 if (act >= nitems(ba_recv_action))
187 ba_recv_action[act] = f;
189 case IEEE80211_ACTION_CAT_HT:
190 if (act >= nitems(ht_recv_action))
192 ht_recv_action[act] = f;
194 case IEEE80211_ACTION_CAT_SELF_PROT:
195 if (act >= nitems(meshpl_recv_action))
197 meshpl_recv_action[act] = f;
199 case IEEE80211_ACTION_CAT_MESH:
200 if (act >= nitems(meshaction_recv_action))
202 meshaction_recv_action[act] = f;
204 case IEEE80211_ACTION_CAT_VENDOR:
205 if (act >= nitems(vendor_recv_action))
207 vendor_recv_action[act] = f;
214 ieee80211_recv_action_unregister(int cat, int act)
216 ieee80211_recv_action_register(cat, act, recv_inval);
220 ieee80211_recv_action(struct ieee80211_node *ni,
221 const struct ieee80211_frame *wh,
222 const uint8_t *frm, const uint8_t *efrm)
224 ieee80211_recv_action_func *f = recv_inval;
225 struct ieee80211vap *vap = ni->ni_vap;
226 const struct ieee80211_action *ia =
227 (const struct ieee80211_action *) frm;
229 switch (ia->ia_category) {
230 case IEEE80211_ACTION_CAT_BA:
231 if (ia->ia_action < nitems(ba_recv_action))
232 f = ba_recv_action[ia->ia_action];
234 case IEEE80211_ACTION_CAT_HT:
235 if (ia->ia_action < nitems(ht_recv_action))
236 f = ht_recv_action[ia->ia_action];
238 case IEEE80211_ACTION_CAT_SELF_PROT:
239 if (ia->ia_action < nitems(meshpl_recv_action))
240 f = meshpl_recv_action[ia->ia_action];
242 case IEEE80211_ACTION_CAT_MESH:
243 if (ni == vap->iv_bss ||
244 ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
245 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
246 ni->ni_macaddr, NULL,
247 "peer link not yet established (%d), cat %s act %u",
248 ni->ni_mlstate, "mesh action", ia->ia_action);
249 vap->iv_stats.is_mesh_nolink++;
252 if (ia->ia_action < nitems(meshaction_recv_action))
253 f = meshaction_recv_action[ia->ia_action];
255 case IEEE80211_ACTION_CAT_VENDOR:
256 if (ia->ia_action < nitems(vendor_recv_action))
257 f = vendor_recv_action[ia->ia_action];
260 return f(ni, wh, frm, efrm);