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/malloc.h>
41 #include <sys/systm.h>
43 #include <sys/socket.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>
55 send_inval(struct ieee80211_node
*ni
, int cat
, int act
, void *sa
)
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
,
83 ieee80211_send_action_register(int cat
, int act
, ieee80211_send_action_func
*f
)
86 case IEEE80211_ACTION_CAT_BA
:
87 if (act
>= nitems(ba_send_action
))
89 ba_send_action
[act
] = f
;
91 case IEEE80211_ACTION_CAT_HT
:
92 if (act
>= nitems(ht_send_action
))
94 ht_send_action
[act
] = f
;
96 case IEEE80211_ACTION_CAT_SELF_PROT
:
97 if (act
>= nitems(meshpl_send_action
))
99 meshpl_send_action
[act
] = f
;
101 case IEEE80211_ACTION_CAT_MESH
:
102 if (act
>= nitems(meshaction_send_action
))
104 meshaction_send_action
[act
] = f
;
107 case IEEE80211_ACTION_CAT_VENDOR
:
108 if (act
>= nitems(vendor_send_action
))
110 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 ieee80211_send_action_func
*f
= send_inval
;
128 case IEEE80211_ACTION_CAT_BA
:
129 if (act
< nitems(ba_send_action
))
130 f
= ba_send_action
[act
];
132 case IEEE80211_ACTION_CAT_HT
:
133 if (act
< nitems(ht_send_action
))
134 f
= ht_send_action
[act
];
136 case IEEE80211_ACTION_CAT_SELF_PROT
:
137 if (act
< nitems(meshpl_send_action
))
138 f
= meshpl_send_action
[act
];
140 case IEEE80211_ACTION_CAT_MESH
:
141 if (act
< nitems(meshaction_send_action
))
142 f
= meshaction_send_action
[act
];
144 case IEEE80211_ACTION_CAT_VENDOR
:
145 if (act
< nitems(vendor_send_action
))
146 f
= vendor_send_action
[act
];
149 return f(ni
, cat
, act
, sa
);
153 recv_inval(struct ieee80211_node
*ni
, const struct ieee80211_frame
*wh
,
154 const uint8_t *frm
, const uint8_t *efrm
)
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
)
185 case IEEE80211_ACTION_CAT_BA
:
186 if (act
>= nitems(ba_recv_action
))
188 ba_recv_action
[act
] = f
;
190 case IEEE80211_ACTION_CAT_HT
:
191 if (act
>= nitems(ht_recv_action
))
193 ht_recv_action
[act
] = f
;
195 case IEEE80211_ACTION_CAT_SELF_PROT
:
196 if (act
>= nitems(meshpl_recv_action
))
198 meshpl_recv_action
[act
] = f
;
200 case IEEE80211_ACTION_CAT_MESH
:
201 if (act
>= nitems(meshaction_recv_action
))
203 meshaction_recv_action
[act
] = f
;
205 case IEEE80211_ACTION_CAT_VENDOR
:
206 if (act
>= nitems(vendor_recv_action
))
208 vendor_recv_action
[act
] = f
;
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
];
235 case IEEE80211_ACTION_CAT_HT
:
236 if (ia
->ia_action
< nitems(ht_recv_action
))
237 f
= ht_recv_action
[ia
->ia_action
];
239 case IEEE80211_ACTION_CAT_SELF_PROT
:
240 if (ia
->ia_action
< nitems(meshpl_recv_action
))
241 f
= meshpl_recv_action
[ia
->ia_action
];
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
++;
253 if (ia
->ia_action
< nitems(meshaction_recv_action
))
254 f
= meshaction_recv_action
[ia
->ia_action
];
256 case IEEE80211_ACTION_CAT_VENDOR
:
257 if (ia
->ia_action
< nitems(vendor_recv_action
))
258 f
= vendor_recv_action
[ia
->ia_action
];
261 return f(ni
, wh
, frm
, efrm
);