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)
83 #define N(a) (sizeof(a) / sizeof(a[0]))
85 case IEEE80211_ACTION_CAT_BA:
86 if (act >= N(ba_send_action))
88 ba_send_action[act] = f;
90 case IEEE80211_ACTION_CAT_HT:
91 if (act >= N(ht_send_action))
93 ht_send_action[act] = f;
95 case IEEE80211_ACTION_CAT_SELF_PROT:
96 if (act >= N(meshpl_send_action))
98 meshpl_send_action[act] = f;
100 case IEEE80211_ACTION_CAT_MESH:
101 if (act >= N(meshaction_send_action))
103 meshaction_send_action[act] = f;
106 case IEEE80211_ACTION_CAT_VENDOR:
107 if (act >= N(vendor_send_action))
109 vendor_send_action[act] = f;
117 ieee80211_send_action_unregister(int cat, int act)
119 ieee80211_send_action_register(cat, act, send_inval);
123 ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
125 #define N(a) (sizeof(a) / sizeof(a[0]))
126 ieee80211_send_action_func *f = send_inval;
129 case IEEE80211_ACTION_CAT_BA:
130 if (act < N(ba_send_action))
131 f = ba_send_action[act];
133 case IEEE80211_ACTION_CAT_HT:
134 if (act < N(ht_send_action))
135 f = ht_send_action[act];
137 case IEEE80211_ACTION_CAT_SELF_PROT:
138 if (act < N(meshpl_send_action))
139 f = meshpl_send_action[act];
141 case IEEE80211_ACTION_CAT_MESH:
142 if (act < N(meshaction_send_action))
143 f = meshaction_send_action[act];
145 case IEEE80211_ACTION_CAT_VENDOR:
146 if (act < N(vendor_send_action))
147 f = vendor_send_action[act];
150 return f(ni, cat, act, sa);
155 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
156 const uint8_t *frm, const uint8_t *efrm)
161 static ieee80211_recv_action_func *ba_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 *ht_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 *meshpl_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 *meshaction_recv_action[12] = {
174 recv_inval, recv_inval, recv_inval, recv_inval,
175 recv_inval, recv_inval, recv_inval, recv_inval,
176 recv_inval, recv_inval, recv_inval, recv_inval,
178 static ieee80211_recv_action_func *vendor_recv_action[8] = {
179 recv_inval, recv_inval, recv_inval, recv_inval,
180 recv_inval, recv_inval, recv_inval, recv_inval,
184 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
186 #define N(a) (sizeof(a) / sizeof(a[0]))
188 case IEEE80211_ACTION_CAT_BA:
189 if (act >= N(ba_recv_action))
191 ba_recv_action[act] = f;
193 case IEEE80211_ACTION_CAT_HT:
194 if (act >= N(ht_recv_action))
196 ht_recv_action[act] = f;
198 case IEEE80211_ACTION_CAT_SELF_PROT:
199 if (act >= N(meshpl_recv_action))
201 meshpl_recv_action[act] = f;
203 case IEEE80211_ACTION_CAT_MESH:
204 if (act >= N(meshaction_recv_action))
206 meshaction_recv_action[act] = f;
208 case IEEE80211_ACTION_CAT_VENDOR:
209 if (act >= N(vendor_recv_action))
211 vendor_recv_action[act] = f;
219 ieee80211_recv_action_unregister(int cat, int act)
221 ieee80211_recv_action_register(cat, act, recv_inval);
225 ieee80211_recv_action(struct ieee80211_node *ni,
226 const struct ieee80211_frame *wh,
227 const uint8_t *frm, const uint8_t *efrm)
229 #define N(a) (sizeof(a) / sizeof(a[0]))
230 ieee80211_recv_action_func *f = recv_inval;
231 struct ieee80211vap *vap = ni->ni_vap;
232 const struct ieee80211_action *ia =
233 (const struct ieee80211_action *) frm;
235 switch (ia->ia_category) {
236 case IEEE80211_ACTION_CAT_BA:
237 if (ia->ia_action < N(ba_recv_action))
238 f = ba_recv_action[ia->ia_action];
240 case IEEE80211_ACTION_CAT_HT:
241 if (ia->ia_action < N(ht_recv_action))
242 f = ht_recv_action[ia->ia_action];
244 case IEEE80211_ACTION_CAT_SELF_PROT:
245 if (ia->ia_action < N(meshpl_recv_action))
246 f = meshpl_recv_action[ia->ia_action];
248 case IEEE80211_ACTION_CAT_MESH:
249 if (ni == vap->iv_bss ||
250 ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
251 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
252 ni->ni_macaddr, NULL,
253 "peer link not yet established (%d), cat %s act %u",
254 ni->ni_mlstate, "mesh action", ia->ia_action);
255 vap->iv_stats.is_mesh_nolink++;
258 if (ia->ia_action < N(meshaction_recv_action))
259 f = meshaction_recv_action[ia->ia_action];
261 case IEEE80211_ACTION_CAT_VENDOR:
262 if (ia->ia_action < N(vendor_recv_action))
263 f = vendor_recv_action[ia->ia_action];
266 return f(ni, wh, frm, efrm);