ieee80211_action.c revision 246503
1/*-
2 * Copyright (c) 2009 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
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.
13 *
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.
24 */
25
26#include <sys/cdefs.h>
27#ifdef __FreeBSD__
28__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_action.c 246503 2013-02-07 21:21:40Z monthadar $");
29#endif
30
31/*
32 * IEEE 802.11 send/recv action frame support.
33 */
34
35#include "opt_inet.h"
36#include "opt_wlan.h"
37
38#include <sys/param.h>
39#include <sys/kernel.h>
40#include <sys/systm.h>
41
42#include <sys/socket.h>
43
44#include <net/if.h>
45#include <net/if_media.h>
46#include <net/ethernet.h>
47
48#include <net80211/ieee80211_var.h>
49#include <net80211/ieee80211_action.h>
50#include <net80211/ieee80211_mesh.h>
51
52static int
53send_inval(struct ieee80211_node *ni, int cat, int act, void *sa)
54{
55	return EINVAL;
56}
57
58static 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,
61};
62static 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,
65};
66static 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,
69};
70static 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,
74};
75static 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,
78};
79
80int
81ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f)
82{
83#define	N(a)	(sizeof(a) / sizeof(a[0]))
84	switch (cat) {
85	case IEEE80211_ACTION_CAT_BA:
86		if (act >= N(ba_send_action))
87			break;
88		ba_send_action[act] = f;
89		return 0;
90	case IEEE80211_ACTION_CAT_HT:
91		if (act >= N(ht_send_action))
92			break;
93		ht_send_action[act] = f;
94		return 0;
95	case IEEE80211_ACTION_CAT_SELF_PROT:
96		if (act >= N(meshpl_send_action))
97			break;
98		meshpl_send_action[act] = f;
99		return 0;
100	case IEEE80211_ACTION_CAT_MESH:
101		if (act >= N(meshaction_send_action))
102			break;
103		meshaction_send_action[act] = f;
104		return 0;
105		break;
106	case IEEE80211_ACTION_CAT_VENDOR:
107		if (act >= N(vendor_send_action))
108			break;
109		vendor_send_action[act] = f;
110		return 0;
111	}
112	return EINVAL;
113#undef N
114}
115
116void
117ieee80211_send_action_unregister(int cat, int act)
118{
119	ieee80211_send_action_register(cat, act, send_inval);
120}
121
122int
123ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa)
124{
125#define	N(a)	(sizeof(a) / sizeof(a[0]))
126	ieee80211_send_action_func *f = send_inval;
127
128	switch (cat) {
129	case IEEE80211_ACTION_CAT_BA:
130		if (act < N(ba_send_action))
131			f = ba_send_action[act];
132		break;
133	case IEEE80211_ACTION_CAT_HT:
134		if (act < N(ht_send_action))
135			f = ht_send_action[act];
136		break;
137	case IEEE80211_ACTION_CAT_SELF_PROT:
138		if (act < N(meshpl_send_action))
139			f = meshpl_send_action[act];
140		break;
141	case IEEE80211_ACTION_CAT_MESH:
142		if (act < N(meshaction_send_action))
143			f = meshaction_send_action[act];
144		break;
145	case IEEE80211_ACTION_CAT_VENDOR:
146		if (act < N(vendor_send_action))
147			f = vendor_send_action[act];
148		break;
149	}
150	return f(ni, cat, act, sa);
151#undef N
152}
153
154static int
155recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
156	const uint8_t *frm, const uint8_t *efrm)
157{
158	return EINVAL;
159}
160
161static 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,
164};
165static 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,
168};
169static 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,
172};
173static 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,
177};
178static 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,
181};
182
183int
184ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f)
185{
186#define	N(a)	(sizeof(a) / sizeof(a[0]))
187	switch (cat) {
188	case IEEE80211_ACTION_CAT_BA:
189		if (act >= N(ba_recv_action))
190			break;
191		ba_recv_action[act] = f;
192		return 0;
193	case IEEE80211_ACTION_CAT_HT:
194		if (act >= N(ht_recv_action))
195			break;
196		ht_recv_action[act] = f;
197		return 0;
198	case IEEE80211_ACTION_CAT_SELF_PROT:
199		if (act >= N(meshpl_recv_action))
200			break;
201		meshpl_recv_action[act] = f;
202		return 0;
203	case IEEE80211_ACTION_CAT_MESH:
204		if (act >= N(meshaction_recv_action))
205			break;
206		meshaction_recv_action[act] = f;
207		return 0;
208	case IEEE80211_ACTION_CAT_VENDOR:
209		if (act >= N(vendor_recv_action))
210			break;
211		vendor_recv_action[act] = f;
212		return 0;
213	}
214	return EINVAL;
215#undef N
216}
217
218void
219ieee80211_recv_action_unregister(int cat, int act)
220{
221	ieee80211_recv_action_register(cat, act, recv_inval);
222}
223
224int
225ieee80211_recv_action(struct ieee80211_node *ni,
226	const struct ieee80211_frame *wh,
227	const uint8_t *frm, const uint8_t *efrm)
228{
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;
234
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];
239		break;
240	case IEEE80211_ACTION_CAT_HT:
241		if (ia->ia_action < N(ht_recv_action))
242			f = ht_recv_action[ia->ia_action];
243		break;
244	case IEEE80211_ACTION_CAT_SELF_PROT:
245		if (ia->ia_action < N(meshpl_recv_action))
246			f = meshpl_recv_action[ia->ia_action];
247		break;
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++;
256			break;
257		}
258		if (ia->ia_action < N(meshaction_recv_action))
259			f = meshaction_recv_action[ia->ia_action];
260		break;
261	case IEEE80211_ACTION_CAT_VENDOR:
262		if (ia->ia_action < N(vendor_recv_action))
263			f = vendor_recv_action[ia->ia_action];
264		break;
265	}
266	return f(ni, wh, frm, efrm);
267#undef N
268}
269