ieee80211_mesh.h revision 234884
1222322Sadrian/*-
2222322Sadrian * Copyright (c) 2009 The FreeBSD Foundation
3222322Sadrian * All rights reserved.
4222322Sadrian *
5222322Sadrian * This software was developed by Rui Paulo under sponsorship from the
6222322Sadrian * FreeBSD Foundation.
7222322Sadrian *
8222322Sadrian * Redistribution and use in source and binary forms, with or without
9222322Sadrian * modification, are permitted provided that the following conditions
10222322Sadrian * are met:
11222322Sadrian * 1. Redistributions of source code must retain the above copyright
12222322Sadrian *    notice, this list of conditions and the following disclaimer.
13222322Sadrian * 2. Redistributions in binary form must reproduce the above copyright
14222322Sadrian *    notice, this list of conditions and the following disclaimer in the
15222322Sadrian *    documentation and/or other materials provided with the distribution.
16222322Sadrian *
17222322Sadrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18222322Sadrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19222322Sadrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20222322Sadrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21222322Sadrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22222322Sadrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23222322Sadrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24222322Sadrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25222322Sadrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26222322Sadrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27222322Sadrian * SUCH DAMAGE.
28222322Sadrian *
29222322Sadrian * $FreeBSD: head/sys/net80211/ieee80211_mesh.h 234884 2012-05-01 16:06:20Z monthadar $
30222322Sadrian */
31222322Sadrian#ifndef _NET80211_IEEE80211_MESH_H_
32222322Sadrian#define _NET80211_IEEE80211_MESH_H_
33222322Sadrian
34222322Sadrian#define	IEEE80211_MESH_DEFAULT_TTL	31
35222322Sadrian#define	IEEE80211_MESH_MAX_NEIGHBORS	15
36222322Sadrian
37222322Sadrian/*
38222322Sadrian * NB: all structures are __packed  so sizeof works on arm, et. al.
39222322Sadrian */
40222322Sadrian/*
41222322Sadrian * 802.11s Information Elements.
42222322Sadrian*/
43222322Sadrian/* Mesh Configuration */
44222322Sadrian#define IEEE80211_MESH_CONF_SZ		(7)
45222322Sadrianstruct ieee80211_meshconf_ie {
46222322Sadrian	uint8_t		conf_ie;	/* IEEE80211_ELEMID_MESHCONF */
47222322Sadrian	uint8_t		conf_len;
48222322Sadrian	uint8_t		conf_pselid;	/* Active Path Sel. Proto. ID */
49222322Sadrian	uint8_t		conf_pmetid;	/* Active Metric Identifier */
50222322Sadrian	uint8_t		conf_ccid;	/* Congestion Control Mode ID  */
51222322Sadrian	uint8_t		conf_syncid;	/* Sync. Protocol ID */
52222322Sadrian	uint8_t		conf_authid;	/* Auth. Protocol ID */
53222322Sadrian	uint8_t		conf_form;	/* Formation Information */
54222322Sadrian	uint8_t		conf_cap;
55222322Sadrian} __packed;
56222322Sadrian
57222322Sadrian/* Hybrid Wireless Mesh Protocol */
58222322Sadrianenum {
59222322Sadrian	/* 0 reserved */
60222322Sadrian	IEEE80211_MESHCONF_PATH_HWMP		= 1,
61222322Sadrian	/* 2-254 reserved */
62222322Sadrian	IEEE80211_MESHCONF_PATH_VENDOR		= 255,
63222322Sadrian};
64222322Sadrian
65222322Sadrian/* Airtime Link Metric */
66222322Sadrianenum {
67222322Sadrian	/* 0 reserved */
68222322Sadrian	IEEE80211_MESHCONF_METRIC_AIRTIME	= 1,
69222322Sadrian	/* 2-254 reserved */
70222322Sadrian	IEEE80211_MESHCONF_METRIC_VENDOR	= 255,
71222322Sadrian};
72222322Sadrian
73222322Sadrian/* Congestion Control */
74222322Sadrianenum {
75222322Sadrian	IEEE80211_MESHCONF_CC_DISABLED		= 0,
76222322Sadrian	IEEE80211_MESHCONF_CC_SIG		= 1,
77222322Sadrian	/* 2-254 reserved */
78222322Sadrian	IEEE80211_MESHCONF_CC_VENDOR		= 255,
79222322Sadrian};
80222322Sadrian
81222322Sadrian/* Neighbour Offset */
82222322Sadrianenum {
83222322Sadrian	/* 0 reserved */
84222322Sadrian	IEEE80211_MESHCONF_SYNC_NEIGHOFF	= 1,
85222322Sadrian	/* 2-254 rserved */
86222322Sadrian	IEEE80211_MESHCONF_SYNC_VENDOR		= 255,
87222322Sadrian};
88222322Sadrian
89222322Sadrian/* Authentication Protocol Identifier */
90222322Sadrianenum {
91222322Sadrian
92222322Sadrian	IEEE80211_MESHCONF_AUTH_DISABLED	= 0,
93222322Sadrian	/* Simultaneous Authenticaction of Equals */
94222322Sadrian	IEEE80211_MESHCONF_AUTH_SEA		= 1,
95222322Sadrian	IEEE80211_MESHCONF_AUTH_8021X		= 2, /* IEEE 802.1X */
96222322Sadrian	/* 3-254 reserved */
97222322Sadrian	IEEE80211_MESHCONF_AUTH_VENDOR		= 255,
98222322Sadrian};
99222322Sadrian
100222322Sadrian/* Mesh Formation Info */
101222322Sadrian#define	IEEE80211_MESHCONF_FORM_MP	0x01 	/* Connected to Portal */
102222322Sadrian#define	IEEE80211_MESHCONF_FORM_NNEIGH_MASK 0x7E /* Number of Neighbours */
103222322Sadrian#define	IEEE80211_MESHCONF_FORM_SA	0xF0 	/* indicating 802.1X auth */
104222322Sadrian
105222322Sadrian/* Mesh Capability */
106222322Sadrian#define	IEEE80211_MESHCONF_CAP_AP	0x01	/* Accepting Peers */
107222322Sadrian#define	IEEE80211_MESHCONF_CAP_MCCAS	0x02	/* MCCA supported */
108222322Sadrian#define	IEEE80211_MESHCONF_CAP_MCCAE	0x04	/* MCCA enabled */
109222322Sadrian#define	IEEE80211_MESHCONF_CAP_FWRD 	0x08	/* forwarding enabled */
110222322Sadrian#define	IEEE80211_MESHCONF_CAP_BTR	0x10	/* Beacon Timing Report Enab */
111222322Sadrian#define	IEEE80211_MESHCONF_CAP_TBTT	0x20	/* TBTT Adjusting  */
112222322Sadrian#define	IEEE80211_MESHCONF_CAP_PSL	0x40	/* Power Save Level */
113222322Sadrian/* 0x80 reserved */
114222322Sadrian
115222322Sadrian/* Mesh Identifier */
116222322Sadrianstruct ieee80211_meshid_ie {
117222322Sadrian	uint8_t		id_ie;		/* IEEE80211_ELEMID_MESHID */
118222322Sadrian	uint8_t		id_len;
119222322Sadrian} __packed;
120222322Sadrian
121222322Sadrian/* Link Metric Report */
122222322Sadrianstruct ieee80211_meshlmetric_ie {
123222322Sadrian	uint8_t		lm_ie;	/* IEEE80211_ACTION_MESH_LMETRIC */
124222322Sadrian	uint8_t		lm_len;
125222322Sadrian	uint8_t		lm_flags;
126222322Sadrian#define	IEEE80211_MESH_LMETRIC_FLAGS_REQ	0x01	/* Request */
127222322Sadrian	/*
128222322Sadrian	 * XXX: this field should be variable in size and depend on
129222322Sadrian	 * the active active path selection metric identifier
130222322Sadrian	 */
131222322Sadrian	uint32_t	lm_metric;
132222322Sadrian#define	IEEE80211_MESHLMETRIC_INITIALVAL	0
133222322Sadrian} __packed;
134222322Sadrian
135222322Sadrian/* Congestion Notification */
136222322Sadrianstruct ieee80211_meshcngst_ie {
137222322Sadrian	uint8_t		cngst_ie;	/* IEEE80211_ELEMID_MESHCNGST */
138222322Sadrian	uint8_t		cngst_len;
139222322Sadrian	uint16_t	cngst_timer[4];	/* Expiration Timers: AC_BK,
140222322Sadrian					   AC_BE, AC_VI, AC_VO */
141222322Sadrian} __packed;
142222322Sadrian
143222322Sadrian/* Peer Link Management */
144222322Sadrian#define IEEE80211_MPM_BASE_SZ	(4)
145222322Sadrian#define IEEE80211_MPM_MAX_SZ	(8)
146222322Sadrianstruct ieee80211_meshpeer_ie {
147222322Sadrian	uint8_t		peer_ie;	/* IEEE80211_ELEMID_MESHPEER */
148222322Sadrian	uint8_t		peer_len;
149222322Sadrian	uint16_t	peer_proto;	/* Peer Management Protocol */
150222322Sadrian	uint16_t	peer_llinkid;	/* Local Link ID */
151222322Sadrian	uint16_t	peer_linkid;	/* Peer Link ID */
152222322Sadrian	uint16_t	peer_rcode;
153222322Sadrian} __packed;
154222322Sadrian
155222322Sadrian/* Mesh Peering Protocol Identifier field value */
156222322Sadrianenum {
157222322Sadrian	IEEE80211_MPPID_MPM		= 0,	/* Mesh peering management */
158222322Sadrian	IEEE80211_MPPID_AUTH_MPM	= 1,	/* Auth. mesh peering exchange */
159222322Sadrian	/* 2-65535 reserved */
160222322Sadrian};
161222322Sadrian
162222322Sadrian#ifdef notyet
163222322Sadrian/* Mesh Channel Switch Annoucement */
164222322Sadrianstruct ieee80211_meshcsa_ie {
165222322Sadrian	uint8_t		csa_ie;		/* IEEE80211_ELEMID_MESHCSA */
166222322Sadrian	uint8_t		csa_len;
167222322Sadrian	uint8_t		csa_mode;
168222322Sadrian	uint8_t		csa_newclass;	/* New Regulatory Class */
169222322Sadrian	uint8_t		csa_newchan;
170222322Sadrian	uint8_t		csa_precvalue;	/* Precedence Value */
171222322Sadrian	uint8_t		csa_count;
172222322Sadrian} __packed;
173222322Sadrian
174222322Sadrian/* Mesh TIM */
175222322Sadrian/* Equal to the non Mesh version */
176222322Sadrian
177222322Sadrian/* Mesh Awake Window */
178222322Sadrianstruct ieee80211_meshawakew_ie {
179222322Sadrian	uint8_t		awakew_ie;		/* IEEE80211_ELEMID_MESHAWAKEW */
180222322Sadrian	uint8_t		awakew_len;
181222322Sadrian	uint8_t		awakew_windowlen;	/* in TUs */
182222322Sadrian} __packed;
183222322Sadrian
184222322Sadrian/* Mesh Beacon Timing */
185222322Sadrianstruct ieee80211_meshbeacont_ie {
186222322Sadrian	uint8_t		beacont_ie;		/* IEEE80211_ELEMID_MESHBEACONT */
187222322Sadrian	uint8_t		beacont_len;
188222322Sadrian	struct {
189222322Sadrian		uint8_t		mp_aid;		/* Least Octet of AID */
190222322Sadrian		uint16_t	mp_btime;	/* Beacon Time */
191222322Sadrian		uint16_t	mp_bint;	/* Beacon Interval */
192222322Sadrian	} __packed mp[1];			/* NB: variable size */
193222322Sadrian} __packed;
194222322Sadrian#endif
195222322Sadrian
196222322Sadrian/* Portal (MP) Annoucement */
197222322Sadrianstruct ieee80211_meshpann_ie {
198222322Sadrian	uint8_t		pann_ie;		/* IEEE80211_ELEMID_MESHPANN */
199222322Sadrian	uint8_t		pann_len;
200222322Sadrian	uint8_t		pann_flags;
201222322Sadrian	uint8_t		pann_hopcount;
202222322Sadrian	uint8_t		pann_ttl;
203222322Sadrian	uint8_t		pann_addr[IEEE80211_ADDR_LEN];
204222322Sadrian	uint8_t		pann_seq;		/* PANN Sequence Number */
205222322Sadrian} __packed;
206222322Sadrian
207222322Sadrian/* Root (MP) Annoucement */
208222322Sadrian#define	IEEE80211_MESHRANN_BASE_SZ 	(21)
209222322Sadrianstruct ieee80211_meshrann_ie {
210222322Sadrian	uint8_t		rann_ie;		/* IEEE80211_ELEMID_MESHRANN */
211222322Sadrian	uint8_t		rann_len;
212222322Sadrian	uint8_t		rann_flags;
213222322Sadrian#define	IEEE80211_MESHRANN_FLAGS_PR	0x01	/* Portal Role */
214222322Sadrian	uint8_t		rann_hopcount;
215222322Sadrian	uint8_t		rann_ttl;
216222322Sadrian	uint8_t		rann_addr[IEEE80211_ADDR_LEN];
217222322Sadrian	uint32_t	rann_seq;		/* HWMP Sequence Number */
218222322Sadrian	uint32_t	rann_interval;
219222322Sadrian	uint32_t	rann_metric;
220222322Sadrian} __packed;
221222322Sadrian
222222322Sadrian/* Mesh Path Request */
223222322Sadrian#define	IEEE80211_MESHPREQ_BASE_SZ 		(26)
224222322Sadrian#define	IEEE80211_MESHPREQ_BASE_SZ_AE 		(32)
225222322Sadrian#define	IEEE80211_MESHPREQ_TRGT_SZ 		(11)
226222322Sadrian#define	IEEE80211_MESHPREQ_TCNT_OFFSET		(27)
227222322Sadrian#define	IEEE80211_MESHPREQ_TCNT_OFFSET_AE	(33)
228222322Sadrianstruct ieee80211_meshpreq_ie {
229222322Sadrian	uint8_t		preq_ie;	/* IEEE80211_ELEMID_MESHPREQ */
230222322Sadrian	uint8_t		preq_len;
231222322Sadrian	uint8_t		preq_flags;
232222322Sadrian#define	IEEE80211_MESHPREQ_FLAGS_PR	0x01	/* Portal Role */
233222322Sadrian#define	IEEE80211_MESHPREQ_FLAGS_AM	0x02	/* 0 = bcast / 1 = ucast */
234222322Sadrian#define	IEEE80211_MESHPREQ_FLAGS_PP	0x04	/* Proactive PREP */
235222322Sadrian#define	IEEE80211_MESHPREQ_FLAGS_AE	0x40	/* Address Extension */
236222322Sadrian	uint8_t		preq_hopcount;
237222322Sadrian	uint8_t		preq_ttl;
238222322Sadrian	uint32_t	preq_id;
239222322Sadrian	uint8_t		preq_origaddr[IEEE80211_ADDR_LEN];
240222322Sadrian	uint32_t	preq_origseq;	/* HWMP Sequence Number */
241222322Sadrian	/* NB: may have Originator External Address */
242222322Sadrian	uint8_t		preq_orig_ext_addr[IEEE80211_ADDR_LEN];
243222322Sadrian	uint32_t	preq_lifetime;
244222322Sadrian	uint32_t	preq_metric;
245222322Sadrian	uint8_t		preq_tcount;	/* target count */
246222322Sadrian	struct {
247222322Sadrian		uint8_t		target_flags;
248222322Sadrian#define	IEEE80211_MESHPREQ_TFLAGS_TO	0x01	/* Target Only */
249222322Sadrian#define	IEEE80211_MESHPREQ_TFLAGS_RF	0x02	/* Reply and Forward */
250222322Sadrian#define	IEEE80211_MESHPREQ_TFLAGS_USN	0x04	/* Unknown HWMP seq number */
251222322Sadrian		uint8_t		target_addr[IEEE80211_ADDR_LEN];
252222322Sadrian		uint32_t	target_seq;	/* HWMP Sequence Number */
253222322Sadrian	} __packed preq_targets[1];		/* NB: variable size */
254222322Sadrian} __packed;
255222322Sadrian
256222322Sadrian/* Mesh Path Reply */
257222322Sadrian#define	IEEE80211_MESHPREP_BASE_SZ 	(31)
258222322Sadrian#define	IEEE80211_MESHPREP_BASE_SZ_AE 	(37)
259222322Sadrianstruct ieee80211_meshprep_ie {
260222322Sadrian	uint8_t		prep_ie;	/* IEEE80211_ELEMID_MESHPREP */
261222322Sadrian	uint8_t		prep_len;
262222322Sadrian	uint8_t		prep_flags;
263222322Sadrian#define	IEEE80211_MESHPREP_FLAGS_AE	0x40	/* Address Extension */
264222322Sadrian	uint8_t		prep_hopcount;
265222322Sadrian	uint8_t		prep_ttl;
266222322Sadrian	uint8_t		prep_targetaddr[IEEE80211_ADDR_LEN];
267222322Sadrian	uint32_t	prep_targetseq;
268222322Sadrian	/* NB: May have Target External Address */
269222322Sadrian	uint8_t		prep_target_ext_addr[IEEE80211_ADDR_LEN];
270222322Sadrian	uint32_t	prep_lifetime;
271222322Sadrian	uint32_t	prep_metric;
272222322Sadrian	uint8_t		prep_origaddr[IEEE80211_ADDR_LEN];
273222322Sadrian	uint32_t	prep_origseq;	/* HWMP Sequence Number */
274222322Sadrian} __packed;
275222322Sadrian
276222322Sadrian/* Mesh Path Error */
277222322Sadrian#define	IEEE80211_MESHPERR_MAXDEST	(19)
278222322Sadrian#define	IEEE80211_MESHPERR_NDEST_OFFSET	(3)
279222322Sadrian#define	IEEE80211_MESHPERR_BASE_SZ 	(2)
280222322Sadrian#define	IEEE80211_MESHPERR_DEST_SZ 	(13)
281222322Sadrian#define	IEEE80211_MESHPERR_DEST_SZ_AE 	(19)
282222322Sadrianstruct ieee80211_meshperr_ie {
283222322Sadrian	uint8_t		perr_ie;	/* IEEE80211_ELEMID_MESHPERR */
284222322Sadrian	uint8_t		perr_len;
285222322Sadrian	uint8_t		perr_ttl;
286222322Sadrian	uint8_t		perr_ndests;	/* Number of Destinations */
287222322Sadrian	struct {
288222322Sadrian		uint8_t		dest_flags;
289222322Sadrian#define	IEEE80211_MESHPERR_DFLAGS_USN	0x01	/* XXX: not part of standard */
290222322Sadrian#define	IEEE80211_MESHPERR_DFLAGS_RC	0x02	/* XXX: not part of standard */
291222322Sadrian#define	IEEE80211_MESHPERR_FLAGS_AE	0x40	/* Address Extension */
292222322Sadrian		uint8_t		dest_addr[IEEE80211_ADDR_LEN];
293222322Sadrian		uint32_t	dest_seq;	/* HWMP Sequence Number */
294222322Sadrian		/* NB: May have Destination External Address */
295222322Sadrian		uint8_t		dest_ext_addr[IEEE80211_ADDR_LEN];
296222322Sadrian		uint16_t	dest_rcode;
297222322Sadrian	} __packed perr_dests[1];		/* NB: variable size */
298222322Sadrian} __packed;
299222322Sadrian
300222322Sadrian#ifdef notyet
301222322Sadrian/* Mesh Proxy Update */
302222322Sadrianstruct ieee80211_meshpu_ie {
303222322Sadrian	uint8_t		pu_ie;		/* IEEE80211_ELEMID_MESHPU */
304222322Sadrian	uint8_t		pu_len;
305222322Sadrian	uint8_t		pu_flags;
306222322Sadrian#define	IEEE80211_MESHPU_FLAGS_MASK		0x1
307222322Sadrian#define	IEEE80211_MESHPU_FLAGS_DEL		0x0
308222322Sadrian#define	IEEE80211_MESHPU_FLAGS_ADD		0x1
309222322Sadrian	uint8_t		pu_seq;		/* PU Sequence Number */
310222322Sadrian	uint8_t		pu_addr[IEEE80211_ADDR_LEN];
311222322Sadrian	uint8_t		pu_naddr;	/* Number of Proxied Addresses */
312222322Sadrian	/* NB: proxied address follows */
313222322Sadrian} __packed;
314222322Sadrian
315222322Sadrian/* Mesh Proxy Update Confirmation */
316222322Sadrianstruct ieee80211_meshpuc_ie {
317	uint8_t		puc_ie;		/* IEEE80211_ELEMID_MESHPUC */
318	uint8_t		puc_len;
319	uint8_t		puc_flags;
320	uint8_t		puc_seq;	/* PU Sequence Number */
321	uint8_t		puc_daddr[IEEE80211_ADDR_LEN];
322} __packed;
323#endif
324
325/*
326 * 802.11s Action Frames
327 * XXX: these are wrong, and some of them should be
328 * under MESH category while PROXY is under MULTIHOP category.
329 */
330#define	IEEE80211_ACTION_CAT_INTERWORK		15
331#define	IEEE80211_ACTION_CAT_RESOURCE		16
332#define	IEEE80211_ACTION_CAT_PROXY		17
333
334/*
335 * Mesh Peering Action codes.
336 */
337enum {
338	/* 0 reserved */
339	IEEE80211_ACTION_MESHPEERING_OPEN	= 1,
340	IEEE80211_ACTION_MESHPEERING_CONFIRM	= 2,
341	IEEE80211_ACTION_MESHPEERING_CLOSE	= 3,
342	/* 4-255 reserved */
343};
344
345/*
346 * Mesh Action code.
347 */
348enum {
349	IEEE80211_ACTION_MESH_LMETRIC	= 0,	/* Mesh Link Metric Report */
350	IEEE80211_ACTION_MESH_HWMP	= 1,	/* HWMP Mesh Path Selection */
351	IEEE80211_ACTION_MESH_GANN	= 2,	/* Gate Announcement */
352	IEEE80211_ACTION_MESH_CC	= 3,	/* Congestion Control */
353	IEEE80211_ACTION_MESH_MCCA_SREQ	= 4,	/* MCCA Setup Request */
354	IEEE80211_ACTION_MESH_MCCA_SREP	= 5,	/* MCCA Setup Reply */
355	IEEE80211_ACTION_MESH_MCCA_AREQ	= 6,	/* MCCA Advertisement Req. */
356	IEEE80211_ACTION_MESH_MCCA_ADVER =7,	/* MCCA Advertisement */
357	IEEE80211_ACTION_MESH_MCCA_TRDOWN = 8,	/* MCCA Teardown */
358	IEEE80211_ACTION_MESH_TBTT_REQ	= 9,	/* TBTT Adjustment Request */
359	IEEE80211_ACTION_MESH_TBTT_RES	= 10,	/* TBTT Adjustment Response */
360	/* 11-255 reserved */
361};
362
363/*
364 * Mesh Portal Annoucement Action codes.
365 */
366enum {
367	IEEE80211_ACTION_MESHPANN	= 0,
368	/* 1-255 reserved */
369};
370
371/*
372 * Different mesh control structures based on the AE
373 * (Address Extension) bits.
374 */
375struct ieee80211_meshcntl {
376	uint8_t		mc_flags;	/* Address Extension 00 */
377	uint8_t		mc_ttl;		/* TTL */
378	uint8_t		mc_seq[4];	/* Sequence No. */
379	/* NB: more addresses may follow */
380} __packed;
381
382struct ieee80211_meshcntl_ae01 {
383	uint8_t		mc_flags;	/* Address Extension 01 */
384	uint8_t		mc_ttl;		/* TTL */
385	uint8_t		mc_seq[4];	/* Sequence No. */
386	uint8_t		mc_addr4[IEEE80211_ADDR_LEN];
387} __packed;
388
389struct ieee80211_meshcntl_ae10 {
390	uint8_t		mc_flags;	/* Address Extension 10 */
391	uint8_t		mc_ttl;		/* TTL */
392	uint8_t		mc_seq[4];	/* Sequence No. */
393	uint8_t		mc_addr5[IEEE80211_ADDR_LEN];
394	uint8_t		mc_addr6[IEEE80211_ADDR_LEN];
395} __packed;
396
397#define IEEE80211_MESH_AE_MASK		0x03
398enum {
399	IEEE80211_MESH_AE_00		= 0,	/* MC has no AE subfield */
400	IEEE80211_MESH_AE_01		= 1,	/* MC contain addr4 */
401	IEEE80211_MESH_AE_10		= 2,	/* MC contain addr5 & addr6 */
402	IEEE80211_MESH_AE_11		= 3,	/* RESERVED */
403};
404
405#ifdef _KERNEL
406MALLOC_DECLARE(M_80211_MESH_PREQ);
407MALLOC_DECLARE(M_80211_MESH_PREP);
408MALLOC_DECLARE(M_80211_MESH_PERR);
409
410MALLOC_DECLARE(M_80211_MESH_RT);
411/*
412 * Basic forwarding information:
413 * o Destination MAC
414 * o Next-hop MAC
415 * o Precursor list (not implemented yet)
416 * o Path timeout
417 * The rest is part of the active Mesh path selection protocol.
418 * XXX: to be moved out later.
419 */
420struct ieee80211_mesh_route {
421	TAILQ_ENTRY(ieee80211_mesh_route)	rt_next;
422	struct mtx		rt_lock;	/* fine grained route lock */
423	int			rt_updtime;	/* last update time */
424	uint8_t			rt_dest[IEEE80211_ADDR_LEN];
425	uint8_t			rt_mesh_gate[IEEE80211_ADDR_LEN]; /* meshDA */
426	uint8_t			rt_nexthop[IEEE80211_ADDR_LEN];
427	uint32_t		rt_metric;	/* path metric */
428	uint16_t		rt_nhops;	/* number of hops */
429	uint16_t		rt_flags;
430#define	IEEE80211_MESHRT_FLAGS_VALID	0x01	/* patch discovery complete */
431#define	IEEE80211_MESHRT_FLAGS_PROXY	0x02	/* proxy entry */
432	uint32_t		rt_lifetime;	/* route timeout */
433	uint32_t		rt_lastmseq;	/* last seq# seen dest */
434	uint32_t		rt_ext_seq;	/* proxy seq number */
435	void			*rt_priv;	/* private data */
436};
437#define	IEEE80211_MESH_ROUTE_PRIV(rt, cast)	((cast *)rt->rt_priv)
438
439#define	IEEE80211_MESH_PROTO_DSZ	12	/* description size */
440/*
441 * Mesh Path Selection Protocol.
442 */
443enum ieee80211_state;
444struct ieee80211_mesh_proto_path {
445	uint8_t		mpp_active;
446	char 		mpp_descr[IEEE80211_MESH_PROTO_DSZ];
447	uint8_t		mpp_ie;
448	struct ieee80211_node *
449	    		(*mpp_discover)(struct ieee80211vap *,
450				const uint8_t [IEEE80211_ADDR_LEN],
451				struct mbuf *);
452	void		(*mpp_peerdown)(struct ieee80211_node *);
453	void		(*mpp_vattach)(struct ieee80211vap *);
454	void		(*mpp_vdetach)(struct ieee80211vap *);
455	int		(*mpp_newstate)(struct ieee80211vap *,
456			    enum ieee80211_state, int);
457	const size_t	mpp_privlen;	/* size required in the routing table
458					   for private data */
459	int		mpp_inact;	/* inact. timeout for invalid routes
460					   (ticks) */
461};
462
463/*
464 * Mesh Link Metric Report Protocol.
465 */
466struct ieee80211_mesh_proto_metric {
467	uint8_t		mpm_active;
468	char		mpm_descr[IEEE80211_MESH_PROTO_DSZ];
469	uint8_t		mpm_ie;
470	uint32_t	(*mpm_metric)(struct ieee80211_node *);
471};
472
473#ifdef notyet
474/*
475 * Mesh Authentication Protocol.
476 */
477struct ieee80211_mesh_proto_auth {
478	uint8_t		mpa_ie[4];
479};
480
481struct ieee80211_mesh_proto_congestion {
482};
483
484struct ieee80211_mesh_proto_sync {
485};
486#endif
487
488typedef uint32_t ieee80211_mesh_seq;
489#define	IEEE80211_MESH_SEQ_LEQ(a, b)	((int32_t)((a)-(b)) <= 0)
490#define	IEEE80211_MESH_SEQ_GEQ(a, b)	((int32_t)((a)-(b)) >= 0)
491
492struct ieee80211_mesh_state {
493	int				ms_idlen;
494	uint8_t				ms_id[IEEE80211_MESHID_LEN];
495	ieee80211_mesh_seq		ms_seq;	/* seq no for meshcntl */
496	uint16_t			ms_neighbors;
497	uint8_t				ms_ttl;	/* mesh ttl set in packets */
498#define IEEE80211_MESHFLAGS_AP		0x01	/* accept peers */
499#define IEEE80211_MESHFLAGS_PORTAL	0x02	/* mesh portal role */
500#define IEEE80211_MESHFLAGS_FWD		0x04	/* forward packets */
501	uint8_t				ms_flags;
502	struct mtx			ms_rt_lock;
503	struct callout			ms_cleantimer;
504	TAILQ_HEAD(, ieee80211_mesh_route)  ms_routes;
505	struct ieee80211_mesh_proto_metric *ms_pmetric;
506	struct ieee80211_mesh_proto_path   *ms_ppath;
507};
508void		ieee80211_mesh_attach(struct ieee80211com *);
509void		ieee80211_mesh_detach(struct ieee80211com *);
510
511struct ieee80211_mesh_route *
512		ieee80211_mesh_rt_find(struct ieee80211vap *,
513		    const uint8_t [IEEE80211_ADDR_LEN]);
514struct ieee80211_mesh_route *
515                ieee80211_mesh_rt_add(struct ieee80211vap *,
516		    const uint8_t [IEEE80211_ADDR_LEN]);
517void		ieee80211_mesh_rt_del(struct ieee80211vap *,
518		    const uint8_t [IEEE80211_ADDR_LEN]);
519void		ieee80211_mesh_rt_flush(struct ieee80211vap *);
520void		ieee80211_mesh_rt_flush_peer(struct ieee80211vap *,
521		    const uint8_t [IEEE80211_ADDR_LEN]);
522int		ieee80211_mesh_rt_update(struct ieee80211_mesh_route *rt, int);
523void		ieee80211_mesh_proxy_check(struct ieee80211vap *,
524		    const uint8_t [IEEE80211_ADDR_LEN]);
525
526int		ieee80211_mesh_register_proto_path(const
527		    struct ieee80211_mesh_proto_path *);
528int		ieee80211_mesh_register_proto_metric(const
529		    struct ieee80211_mesh_proto_metric *);
530
531uint8_t *	ieee80211_add_meshid(uint8_t *, struct ieee80211vap *);
532uint8_t *	ieee80211_add_meshconf(uint8_t *, struct ieee80211vap *);
533uint8_t *	ieee80211_add_meshpeer(uint8_t *, uint8_t, uint16_t, uint16_t,
534		    uint16_t);
535uint8_t *	ieee80211_add_meshlmetric(uint8_t *, uint8_t, uint32_t);
536
537void		ieee80211_mesh_node_init(struct ieee80211vap *,
538		    struct ieee80211_node *);
539void		ieee80211_mesh_node_cleanup(struct ieee80211_node *);
540void		ieee80211_parse_meshid(struct ieee80211_node *,
541		    const uint8_t *);
542struct ieee80211_scanparams;
543void		ieee80211_mesh_init_neighbor(struct ieee80211_node *,
544		   const struct ieee80211_frame *,
545		   const struct ieee80211_scanparams *);
546void		ieee80211_mesh_update_beacon(struct ieee80211vap *,
547		    struct ieee80211_beacon_offsets *);
548
549/*
550 * Return non-zero if proxy operation is enabled.
551 */
552static __inline int
553ieee80211_mesh_isproxyena(struct ieee80211vap *vap)
554{
555	struct ieee80211_mesh_state *ms = vap->iv_mesh;
556	return (ms->ms_flags &
557	    (IEEE80211_MESHFLAGS_AP | IEEE80211_MESHFLAGS_PORTAL)) != 0;
558}
559
560/*
561 * Process an outbound frame: if a path is known to the
562 * destination then return a reference to the next hop
563 * for immediate transmission.  Otherwise initiate path
564 * discovery and, if possible queue the packet to be
565 * sent when path discovery completes.
566 */
567static __inline struct ieee80211_node *
568ieee80211_mesh_discover(struct ieee80211vap *vap,
569    const uint8_t dest[IEEE80211_ADDR_LEN], struct mbuf *m)
570{
571	struct ieee80211_mesh_state *ms = vap->iv_mesh;
572	return ms->ms_ppath->mpp_discover(vap, dest, m);
573}
574
575#endif /* _KERNEL */
576#endif /* !_NET80211_IEEE80211_MESH_H_ */
577