acpi: Narrow workaround for broken interrupt settings
[dragonfly.git] / sys / netproto / 802_11 / wlan / ieee80211_action.c
blobd3f9fbf3e5484412772d43b47f03be90ecddd05e
1 /*-
2 * Copyright (c) 2009 Sam Leffler, Errno Consulting
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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>
27 #ifdef __FreeBSD__
28 __FBSDID("$FreeBSD$");
29 #endif
32 * IEEE 802.11 send/recv action frame support.
35 #include "opt_inet.h"
36 #include "opt_wlan.h"
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/systm.h>
43 #include <sys/socket.h>
45 #include <net/if.h>
46 #include <net/if_var.h>
47 #include <net/if_media.h>
48 #include <net/ethernet.h>
50 #include <netproto/802_11/ieee80211_var.h>
51 #include <netproto/802_11/ieee80211_action.h>
52 #include <netproto/802_11/ieee80211_mesh.h>
54 static int
55 send_inval(struct ieee80211_node *ni, int cat, int act, void *sa)
57 return EINVAL;
60 static ieee80211_send_action_func *ba_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 *ht_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 *meshpl_send_action[8] = {
69 send_inval, send_inval, send_inval, send_inval,
70 send_inval, send_inval, send_inval, send_inval,
72 static ieee80211_send_action_func *meshaction_send_action[12] = {
73 send_inval, send_inval, send_inval, send_inval,
74 send_inval, send_inval, send_inval, send_inval,
75 send_inval, send_inval, send_inval, send_inval,
77 static ieee80211_send_action_func *vendor_send_action[8] = {
78 send_inval, send_inval, send_inval, send_inval,
79 send_inval, send_inval, send_inval, send_inval,
82 int
83 ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f)
85 switch (cat) {
86 case IEEE80211_ACTION_CAT_BA:
87 if (act >= nitems(ba_send_action))
88 break;
89 ba_send_action[act] = f;
90 return 0;
91 case IEEE80211_ACTION_CAT_HT:
92 if (act >= nitems(ht_send_action))
93 break;
94 ht_send_action[act] = f;
95 return 0;
96 case IEEE80211_ACTION_CAT_SELF_PROT:
97 if (act >= nitems(meshpl_send_action))
98 break;
99 meshpl_send_action[act] = f;
100 return 0;
101 case IEEE80211_ACTION_CAT_MESH:
102 if (act >= nitems(meshaction_send_action))
103 break;
104 meshaction_send_action[act] = f;
105 return 0;
106 break;
107 case IEEE80211_ACTION_CAT_VENDOR:
108 if (act >= nitems(vendor_send_action))
109 break;
110 vendor_send_action[act] = f;
111 return 0;
113 return EINVAL;
116 void
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 ieee80211_send_action_func *f = send_inval;
127 switch (cat) {
128 case IEEE80211_ACTION_CAT_BA:
129 if (act < nitems(ba_send_action))
130 f = ba_send_action[act];
131 break;
132 case IEEE80211_ACTION_CAT_HT:
133 if (act < nitems(ht_send_action))
134 f = ht_send_action[act];
135 break;
136 case IEEE80211_ACTION_CAT_SELF_PROT:
137 if (act < nitems(meshpl_send_action))
138 f = meshpl_send_action[act];
139 break;
140 case IEEE80211_ACTION_CAT_MESH:
141 if (act < nitems(meshaction_send_action))
142 f = meshaction_send_action[act];
143 break;
144 case IEEE80211_ACTION_CAT_VENDOR:
145 if (act < nitems(vendor_send_action))
146 f = vendor_send_action[act];
147 break;
149 return f(ni, cat, act, sa);
152 static int
153 recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
154 const uint8_t *frm, const uint8_t *efrm)
156 return EINVAL;
159 static ieee80211_recv_action_func *ba_recv_action[8] = {
160 recv_inval, recv_inval, recv_inval, recv_inval,
161 recv_inval, recv_inval, recv_inval, recv_inval,
163 static ieee80211_recv_action_func *ht_recv_action[8] = {
164 recv_inval, recv_inval, recv_inval, recv_inval,
165 recv_inval, recv_inval, recv_inval, recv_inval,
167 static ieee80211_recv_action_func *meshpl_recv_action[8] = {
168 recv_inval, recv_inval, recv_inval, recv_inval,
169 recv_inval, recv_inval, recv_inval, recv_inval,
171 static ieee80211_recv_action_func *meshaction_recv_action[12] = {
172 recv_inval, recv_inval, recv_inval, recv_inval,
173 recv_inval, recv_inval, recv_inval, recv_inval,
174 recv_inval, recv_inval, recv_inval, recv_inval,
176 static ieee80211_recv_action_func *vendor_recv_action[8] = {
177 recv_inval, recv_inval, recv_inval, recv_inval,
178 recv_inval, recv_inval, recv_inval, recv_inval,
182 ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
184 switch (cat) {
185 case IEEE80211_ACTION_CAT_BA:
186 if (act >= nitems(ba_recv_action))
187 break;
188 ba_recv_action[act] = f;
189 return 0;
190 case IEEE80211_ACTION_CAT_HT:
191 if (act >= nitems(ht_recv_action))
192 break;
193 ht_recv_action[act] = f;
194 return 0;
195 case IEEE80211_ACTION_CAT_SELF_PROT:
196 if (act >= nitems(meshpl_recv_action))
197 break;
198 meshpl_recv_action[act] = f;
199 return 0;
200 case IEEE80211_ACTION_CAT_MESH:
201 if (act >= nitems(meshaction_recv_action))
202 break;
203 meshaction_recv_action[act] = f;
204 return 0;
205 case IEEE80211_ACTION_CAT_VENDOR:
206 if (act >= nitems(vendor_recv_action))
207 break;
208 vendor_recv_action[act] = f;
209 return 0;
211 return EINVAL;
214 void
215 ieee80211_recv_action_unregister(int cat, int act)
217 ieee80211_recv_action_register(cat, act, recv_inval);
221 ieee80211_recv_action(struct ieee80211_node *ni,
222 const struct ieee80211_frame *wh,
223 const uint8_t *frm, const uint8_t *efrm)
225 ieee80211_recv_action_func *f = recv_inval;
226 struct ieee80211vap *vap = ni->ni_vap;
227 const struct ieee80211_action *ia =
228 (const struct ieee80211_action *) frm;
230 switch (ia->ia_category) {
231 case IEEE80211_ACTION_CAT_BA:
232 if (ia->ia_action < nitems(ba_recv_action))
233 f = ba_recv_action[ia->ia_action];
234 break;
235 case IEEE80211_ACTION_CAT_HT:
236 if (ia->ia_action < nitems(ht_recv_action))
237 f = ht_recv_action[ia->ia_action];
238 break;
239 case IEEE80211_ACTION_CAT_SELF_PROT:
240 if (ia->ia_action < nitems(meshpl_recv_action))
241 f = meshpl_recv_action[ia->ia_action];
242 break;
243 case IEEE80211_ACTION_CAT_MESH:
244 if (ni == vap->iv_bss ||
245 ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
246 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
247 ni->ni_macaddr, NULL,
248 "peer link not yet established (%d), cat %s act %u",
249 ni->ni_mlstate, "mesh action", ia->ia_action);
250 vap->iv_stats.is_mesh_nolink++;
251 break;
253 if (ia->ia_action < nitems(meshaction_recv_action))
254 f = meshaction_recv_action[ia->ia_action];
255 break;
256 case IEEE80211_ACTION_CAT_VENDOR:
257 if (ia->ia_action < nitems(vendor_recv_action))
258 f = vendor_recv_action[ia->ia_action];
259 break;
261 return f(ni, wh, frm, efrm);