2 * Copyright (c) 2009 The FreeBSD Foundation
5 * This software was developed by Rui Paulo under sponsorship from the
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef _NET80211_IEEE80211_MESH_H_
32 #define _NET80211_IEEE80211_MESH_H_
34 #define IEEE80211_MESH_DEFAULT_TTL 31
37 * NB: all structures are __packed so sizeof works on arm, et. al.
40 * 802.11s Information Elements.
42 /* Mesh Configuration */
43 #define IEEE80211_MESH_CONF_SZ (7)
44 struct ieee80211_meshconf_ie {
45 uint8_t conf_ie; /* IEEE80211_ELEMID_MESHCONF */
47 uint8_t conf_pselid; /* Active Path Sel. Proto. ID */
48 uint8_t conf_pmetid; /* Active Metric Identifier */
49 uint8_t conf_ccid; /* Congestion Control Mode ID */
50 uint8_t conf_syncid; /* Sync. Protocol ID */
51 uint8_t conf_authid; /* Auth. Protocol ID */
52 uint8_t conf_form; /* Formation Information */
56 /* Hybrid Wireless Mesh Protocol */
59 IEEE80211_MESHCONF_PATH_HWMP = 1,
61 IEEE80211_MESHCONF_PATH_VENDOR = 255,
64 /* Airtime Link Metric */
67 IEEE80211_MESHCONF_METRIC_AIRTIME = 1,
69 IEEE80211_MESHCONF_METRIC_VENDOR = 255,
72 /* Congestion Control */
74 IEEE80211_MESHCONF_CC_DISABLED = 0,
75 IEEE80211_MESHCONF_CC_SIG = 1,
77 IEEE80211_MESHCONF_CC_VENDOR = 255,
80 /* Neighbour Offset */
83 IEEE80211_MESHCONF_SYNC_NEIGHOFF = 1,
85 IEEE80211_MESHCONF_SYNC_VENDOR = 255,
88 /* Authentication Protocol Identifier */
91 IEEE80211_MESHCONF_AUTH_DISABLED = 0,
92 /* Simultaneous Authenticaction of Equals */
93 IEEE80211_MESHCONF_AUTH_SEA = 1,
94 IEEE80211_MESHCONF_AUTH_8021X = 2, /* IEEE 802.1X */
96 IEEE80211_MESHCONF_AUTH_VENDOR = 255,
99 /* Mesh Formation Info */
100 #define IEEE80211_MESHCONF_FORM_MP 0x01 /* Connected to Portal */
101 #define IEEE80211_MESHCONF_FORM_NNEIGH_MASK 0x7E /* Number of Neighbours */
102 #define IEEE80211_MESHCONF_FORM_SA 0xF0 /* indicating 802.1X auth */
104 /* Mesh Capability */
105 #define IEEE80211_MESHCONF_CAP_AP 0x01 /* Accepting Peers */
106 #define IEEE80211_MESHCONF_CAP_MCCAS 0x02 /* MCCA supported */
107 #define IEEE80211_MESHCONF_CAP_MCCAE 0x04 /* MCCA enabled */
108 #define IEEE80211_MESHCONF_CAP_FWRD 0x08 /* forwarding enabled */
109 #define IEEE80211_MESHCONF_CAP_BTR 0x10 /* Beacon Timing Report Enab */
110 #define IEEE80211_MESHCONF_CAP_TBTT 0x20 /* TBTT Adjusting */
111 #define IEEE80211_MESHCONF_CAP_PSL 0x40 /* Power Save Level */
114 /* Mesh Identifier */
115 struct ieee80211_meshid_ie {
116 uint8_t id_ie; /* IEEE80211_ELEMID_MESHID */
120 /* Link Metric Report */
121 struct ieee80211_meshlmetric_ie {
122 uint8_t lm_ie; /* IEEE80211_ACTION_MESH_LMETRIC */
125 #define IEEE80211_MESH_LMETRIC_FLAGS_REQ 0x01 /* Request */
127 * XXX: this field should be variable in size and depend on
128 * the active active path selection metric identifier
131 #define IEEE80211_MESHLMETRIC_INITIALVAL 0
134 /* Congestion Notification */
135 struct ieee80211_meshcngst_ie {
136 uint8_t cngst_ie; /* IEEE80211_ELEMID_MESHCNGST */
138 uint16_t cngst_timer[4]; /* Expiration Timers: AC_BK,
139 AC_BE, AC_VI, AC_VO */
142 /* Peer Link Management */
143 #define IEEE80211_MPM_BASE_SZ (4)
144 #define IEEE80211_MPM_MAX_SZ (8)
145 struct ieee80211_meshpeer_ie {
146 uint8_t peer_ie; /* IEEE80211_ELEMID_MESHPEER */
148 uint16_t peer_proto; /* Peer Management Protocol */
149 uint16_t peer_llinkid; /* Local Link ID */
150 uint16_t peer_linkid; /* Peer Link ID */
154 /* Mesh Peering Protocol Identifier field value */
156 IEEE80211_MPPID_MPM = 0, /* Mesh peering management */
157 IEEE80211_MPPID_AUTH_MPM = 1, /* Auth. mesh peering exchange */
158 /* 2-65535 reserved */
162 /* Mesh Channel Switch Annoucement */
163 struct ieee80211_meshcsa_ie {
164 uint8_t csa_ie; /* IEEE80211_ELEMID_MESHCSA */
167 uint8_t csa_newclass; /* New Regulatory Class */
169 uint8_t csa_precvalue; /* Precedence Value */
174 /* Equal to the non Mesh version */
176 /* Mesh Awake Window */
177 struct ieee80211_meshawakew_ie {
178 uint8_t awakew_ie; /* IEEE80211_ELEMID_MESHAWAKEW */
180 uint8_t awakew_windowlen; /* in TUs */
183 /* Mesh Beacon Timing */
184 struct ieee80211_meshbeacont_ie {
185 uint8_t beacont_ie; /* IEEE80211_ELEMID_MESHBEACONT */
188 uint8_t mp_aid; /* Least Octet of AID */
189 uint16_t mp_btime; /* Beacon Time */
190 uint16_t mp_bint; /* Beacon Interval */
191 } __packed mp[1]; /* NB: variable size */
195 /* Portal (MP) Annoucement */
196 struct ieee80211_meshpann_ie {
197 uint8_t pann_ie; /* IEEE80211_ELEMID_MESHPANN */
200 uint8_t pann_hopcount;
202 uint8_t pann_addr[IEEE80211_ADDR_LEN];
203 uint8_t pann_seq; /* PANN Sequence Number */
206 /* Root (MP) Annoucement */
207 #define IEEE80211_MESHRANN_BASE_SZ (21)
208 struct ieee80211_meshrann_ie {
209 uint8_t rann_ie; /* IEEE80211_ELEMID_MESHRANN */
212 #define IEEE80211_MESHRANN_FLAGS_PR 0x01 /* Portal Role */
213 uint8_t rann_hopcount;
215 uint8_t rann_addr[IEEE80211_ADDR_LEN];
216 uint32_t rann_seq; /* HWMP Sequence Number */
217 uint32_t rann_interval;
218 uint32_t rann_metric;
221 /* Mesh Path Request */
222 #define IEEE80211_MESHPREQ_BASE_SZ (26)
223 #define IEEE80211_MESHPREQ_BASE_SZ_AE (32)
224 #define IEEE80211_MESHPREQ_TRGT_SZ (11)
225 #define IEEE80211_MESHPREQ_TCNT_OFFSET (27)
226 #define IEEE80211_MESHPREQ_TCNT_OFFSET_AE (33)
227 struct ieee80211_meshpreq_ie {
228 uint8_t preq_ie; /* IEEE80211_ELEMID_MESHPREQ */
231 #define IEEE80211_MESHPREQ_FLAGS_PR 0x01 /* Portal Role */
232 #define IEEE80211_MESHPREQ_FLAGS_AM 0x02 /* 0 = ucast / 1 = bcast */
233 #define IEEE80211_MESHPREQ_FLAGS_PP 0x04 /* Proactive PREP */
234 #define IEEE80211_MESHPREQ_FLAGS_AE 0x40 /* Address Extension */
235 uint8_t preq_hopcount;
238 uint8_t preq_origaddr[IEEE80211_ADDR_LEN];
239 uint32_t preq_origseq; /* HWMP Sequence Number */
240 /* NB: may have Originator External Address */
241 uint8_t preq_orig_ext_addr[IEEE80211_ADDR_LEN];
242 uint32_t preq_lifetime;
243 uint32_t preq_metric;
244 uint8_t preq_tcount; /* target count */
246 uint8_t target_flags;
247 #define IEEE80211_MESHPREQ_TFLAGS_TO 0x01 /* Target Only */
248 #define IEEE80211_MESHPREQ_TFLAGS_RF 0x02 /* Reply and Forward */
249 #define IEEE80211_MESHPREQ_TFLAGS_USN 0x04 /* Unknown HWMP seq number */
250 uint8_t target_addr[IEEE80211_ADDR_LEN];
251 uint32_t target_seq; /* HWMP Sequence Number */
252 } __packed preq_targets[1]; /* NB: variable size */
255 /* Mesh Path Reply */
256 #define IEEE80211_MESHPREP_BASE_SZ (31)
257 #define IEEE80211_MESHPREP_BASE_SZ_AE (37)
258 struct ieee80211_meshprep_ie {
259 uint8_t prep_ie; /* IEEE80211_ELEMID_MESHPREP */
262 #define IEEE80211_MESHPREP_FLAGS_AE 0x40 /* Address Extension */
263 uint8_t prep_hopcount;
265 uint8_t prep_targetaddr[IEEE80211_ADDR_LEN];
266 uint32_t prep_targetseq;
267 /* NB: May have Target External Address */
268 uint8_t prep_target_ext_addr[IEEE80211_ADDR_LEN];
269 uint32_t prep_lifetime;
270 uint32_t prep_metric;
271 uint8_t prep_origaddr[IEEE80211_ADDR_LEN];
272 uint32_t prep_origseq; /* HWMP Sequence Number */
275 /* Mesh Path Error */
276 #define IEEE80211_MESHPERR_MAXDEST (19)
277 #define IEEE80211_MESHPERR_NDEST_OFFSET (3)
278 #define IEEE80211_MESHPERR_BASE_SZ (2)
279 #define IEEE80211_MESHPERR_DEST_SZ (13)
280 #define IEEE80211_MESHPERR_DEST_SZ_AE (19)
281 struct ieee80211_meshperr_ie {
282 uint8_t perr_ie; /* IEEE80211_ELEMID_MESHPERR */
285 uint8_t perr_ndests; /* Number of Destinations */
288 #define IEEE80211_MESHPERR_DFLAGS_USN 0x01 /* XXX: not part of standard */
289 #define IEEE80211_MESHPERR_DFLAGS_RC 0x02 /* XXX: not part of standard */
290 #define IEEE80211_MESHPERR_FLAGS_AE 0x40 /* Address Extension */
291 uint8_t dest_addr[IEEE80211_ADDR_LEN];
292 uint32_t dest_seq; /* HWMP Sequence Number */
293 /* NB: May have Destination External Address */
294 uint8_t dest_ext_addr[IEEE80211_ADDR_LEN];
296 } __packed perr_dests[1]; /* NB: variable size */
300 /* Mesh Proxy Update */
301 struct ieee80211_meshpu_ie {
302 uint8_t pu_ie; /* IEEE80211_ELEMID_MESHPU */
305 #define IEEE80211_MESHPU_FLAGS_MASK 0x1
306 #define IEEE80211_MESHPU_FLAGS_DEL 0x0
307 #define IEEE80211_MESHPU_FLAGS_ADD 0x1
308 uint8_t pu_seq; /* PU Sequence Number */
309 uint8_t pu_addr[IEEE80211_ADDR_LEN];
310 uint8_t pu_naddr; /* Number of Proxied Addresses */
311 /* NB: proxied address follows */
314 /* Mesh Proxy Update Confirmation */
315 struct ieee80211_meshpuc_ie {
316 uint8_t puc_ie; /* IEEE80211_ELEMID_MESHPUC */
319 uint8_t puc_seq; /* PU Sequence Number */
320 uint8_t puc_daddr[IEEE80211_ADDR_LEN];
325 * 802.11s Action Frames
326 * XXX: these are wrong, and some of them should be
327 * under MESH category while PROXY is under MULTIHOP category.
329 #define IEEE80211_ACTION_CAT_INTERWORK 15
330 #define IEEE80211_ACTION_CAT_RESOURCE 16
331 #define IEEE80211_ACTION_CAT_PROXY 17
334 * Mesh Peering Action codes.
338 IEEE80211_ACTION_MESHPEERING_OPEN = 1,
339 IEEE80211_ACTION_MESHPEERING_CONFIRM = 2,
340 IEEE80211_ACTION_MESHPEERING_CLOSE = 3,
348 IEEE80211_ACTION_MESH_LMETRIC = 0, /* Mesh Link Metric Report */
349 IEEE80211_ACTION_MESH_HWMP = 1, /* HWMP Mesh Path Selection */
350 IEEE80211_ACTION_MESH_GANN = 2, /* Gate Announcement */
351 IEEE80211_ACTION_MESH_CC = 3, /* Congestion Control */
352 IEEE80211_ACTION_MESH_MCCA_SREQ = 4, /* MCCA Setup Request */
353 IEEE80211_ACTION_MESH_MCCA_SREP = 5, /* MCCA Setup Reply */
354 IEEE80211_ACTION_MESH_MCCA_AREQ = 6, /* MCCA Advertisement Req. */
355 IEEE80211_ACTION_MESH_MCCA_ADVER =7, /* MCCA Advertisement */
356 IEEE80211_ACTION_MESH_MCCA_TRDOWN = 8, /* MCCA Teardown */
357 IEEE80211_ACTION_MESH_TBTT_REQ = 9, /* TBTT Adjustment Request */
358 IEEE80211_ACTION_MESH_TBTT_RES = 10, /* TBTT Adjustment Response */
359 /* 11-255 reserved */
363 * Mesh Portal Annoucement Action codes.
366 IEEE80211_ACTION_MESHPANN = 0,
371 * Different mesh control structures based on the AE
372 * (Address Extension) bits.
374 struct ieee80211_meshcntl {
375 uint8_t mc_flags; /* Address Extension 00 */
376 uint8_t mc_ttl; /* TTL */
377 uint8_t mc_seq[4]; /* Sequence No. */
378 /* NB: more addresses may follow */
381 struct ieee80211_meshcntl_ae01 {
382 uint8_t mc_flags; /* Address Extension 01 */
383 uint8_t mc_ttl; /* TTL */
384 uint8_t mc_seq[4]; /* Sequence No. */
385 uint8_t mc_addr4[IEEE80211_ADDR_LEN];
388 struct ieee80211_meshcntl_ae10 {
389 uint8_t mc_flags; /* Address Extension 10 */
390 uint8_t mc_ttl; /* TTL */
391 uint8_t mc_seq[4]; /* Sequence No. */
392 uint8_t mc_addr4[IEEE80211_ADDR_LEN];
393 uint8_t mc_addr5[IEEE80211_ADDR_LEN];
396 struct ieee80211_meshcntl_ae11 {
397 uint8_t mc_flags; /* Address Extension 11 */
398 uint8_t mc_ttl; /* TTL */
399 uint8_t mc_seq[4]; /* Sequence No. */
400 uint8_t mc_addr4[IEEE80211_ADDR_LEN];
401 uint8_t mc_addr5[IEEE80211_ADDR_LEN];
402 uint8_t mc_addr6[IEEE80211_ADDR_LEN];
406 MALLOC_DECLARE(M_80211_MESH_PREQ);
407 MALLOC_DECLARE(M_80211_MESH_PREP);
408 MALLOC_DECLARE(M_80211_MESH_PERR);
410 MALLOC_DECLARE(M_80211_MESH_RT);
411 struct ieee80211_mesh_route {
412 TAILQ_ENTRY(ieee80211_mesh_route) rt_next;
413 int rt_crtime; /* creation time */
414 uint8_t rt_dest[IEEE80211_ADDR_LEN];
415 uint8_t rt_nexthop[IEEE80211_ADDR_LEN];
416 uint32_t rt_metric; /* path metric */
417 uint16_t rt_nhops; /* number of hops */
419 #define IEEE80211_MESHRT_FLAGS_VALID 0x01 /* patch discovery complete */
420 #define IEEE80211_MESHRT_FLAGS_PROXY 0x02 /* proxy entry */
421 uint32_t rt_lifetime;
422 uint32_t rt_lastmseq; /* last seq# seen dest */
423 void *rt_priv; /* private data */
425 #define IEEE80211_MESH_ROUTE_PRIV(rt, cast) ((cast *)rt->rt_priv)
427 #define IEEE80211_MESH_PROTO_DSZ 12 /* description size */
429 * Mesh Path Selection Protocol.
431 enum ieee80211_state;
432 struct ieee80211_mesh_proto_path {
434 char mpp_descr[IEEE80211_MESH_PROTO_DSZ];
436 struct ieee80211_node *
437 (*mpp_discover)(struct ieee80211vap *,
438 const uint8_t [IEEE80211_ADDR_LEN],
440 void (*mpp_peerdown)(struct ieee80211_node *);
441 void (*mpp_vattach)(struct ieee80211vap *);
442 void (*mpp_vdetach)(struct ieee80211vap *);
443 int (*mpp_newstate)(struct ieee80211vap *,
444 enum ieee80211_state, int);
445 const size_t mpp_privlen; /* size required in the routing table
447 int mpp_inact; /* inact. timeout for invalid routes
452 * Mesh Link Metric Report Protocol.
454 struct ieee80211_mesh_proto_metric {
456 char mpm_descr[IEEE80211_MESH_PROTO_DSZ];
458 uint32_t (*mpm_metric)(struct ieee80211_node *);
463 * Mesh Authentication Protocol.
465 struct ieee80211_mesh_proto_auth {
469 struct ieee80211_mesh_proto_congestion {
472 struct ieee80211_mesh_proto_sync {
476 typedef uint32_t ieee80211_mesh_seq;
477 #define IEEE80211_MESH_SEQ_LEQ(a, b) ((int32_t)((a)-(b)) <= 0)
478 #define IEEE80211_MESH_SEQ_GEQ(a, b) ((int32_t)((a)-(b)) >= 0)
480 struct ieee80211_mesh_state {
482 uint8_t ms_id[IEEE80211_MESHID_LEN];
483 ieee80211_mesh_seq ms_seq; /* seq no for meshcntl */
484 uint16_t ms_neighbors;
485 uint8_t ms_ttl; /* mesh ttl set in packets */
486 #define IEEE80211_MESHFLAGS_AP 0x01 /* accept peers */
487 #define IEEE80211_MESHFLAGS_PORTAL 0x02 /* mesh portal role */
488 #define IEEE80211_MESHFLAGS_FWD 0x04 /* forward packets */
490 struct mtx ms_rt_lock;
491 struct callout ms_cleantimer;
492 TAILQ_HEAD(, ieee80211_mesh_route) ms_routes;
493 struct ieee80211_mesh_proto_metric *ms_pmetric;
494 struct ieee80211_mesh_proto_path *ms_ppath;
496 void ieee80211_mesh_attach(struct ieee80211com *);
497 void ieee80211_mesh_detach(struct ieee80211com *);
499 struct ieee80211_mesh_route *
500 ieee80211_mesh_rt_find(struct ieee80211vap *,
501 const uint8_t [IEEE80211_ADDR_LEN]);
502 struct ieee80211_mesh_route *
503 ieee80211_mesh_rt_add(struct ieee80211vap *,
504 const uint8_t [IEEE80211_ADDR_LEN]);
505 void ieee80211_mesh_rt_del(struct ieee80211vap *,
506 const uint8_t [IEEE80211_ADDR_LEN]);
507 void ieee80211_mesh_rt_flush(struct ieee80211vap *);
508 void ieee80211_mesh_rt_flush_peer(struct ieee80211vap *,
509 const uint8_t [IEEE80211_ADDR_LEN]);
510 void ieee80211_mesh_proxy_check(struct ieee80211vap *,
511 const uint8_t [IEEE80211_ADDR_LEN]);
513 int ieee80211_mesh_register_proto_path(const
514 struct ieee80211_mesh_proto_path *);
515 int ieee80211_mesh_register_proto_metric(const
516 struct ieee80211_mesh_proto_metric *);
518 uint8_t * ieee80211_add_meshid(uint8_t *, struct ieee80211vap *);
519 uint8_t * ieee80211_add_meshconf(uint8_t *, struct ieee80211vap *);
520 uint8_t * ieee80211_add_meshpeer(uint8_t *, uint8_t, uint16_t, uint16_t,
522 uint8_t * ieee80211_add_meshlmetric(uint8_t *, uint8_t, uint32_t);
524 void ieee80211_mesh_node_init(struct ieee80211vap *,
525 struct ieee80211_node *);
526 void ieee80211_mesh_node_cleanup(struct ieee80211_node *);
527 void ieee80211_parse_meshid(struct ieee80211_node *,
529 struct ieee80211_scanparams;
530 void ieee80211_mesh_init_neighbor(struct ieee80211_node *,
531 const struct ieee80211_frame *,
532 const struct ieee80211_scanparams *);
533 void ieee80211_mesh_update_beacon(struct ieee80211vap *,
534 struct ieee80211_beacon_offsets *);
537 * Return non-zero if proxy operation is enabled.
540 ieee80211_mesh_isproxyena(struct ieee80211vap *vap)
542 struct ieee80211_mesh_state *ms = vap->iv_mesh;
543 return (ms->ms_flags &
544 (IEEE80211_MESHFLAGS_AP | IEEE80211_MESHFLAGS_PORTAL)) != 0;
548 * Process an outbound frame: if a path is known to the
549 * destination then return a reference to the next hop
550 * for immediate transmission. Otherwise initiate path
551 * discovery and, if possible queue the packet to be
552 * sent when path discovery completes.
554 static __inline struct ieee80211_node *
555 ieee80211_mesh_discover(struct ieee80211vap *vap,
556 const uint8_t dest[IEEE80211_ADDR_LEN], struct mbuf *m)
558 struct ieee80211_mesh_state *ms = vap->iv_mesh;
559 return ms->ms_ppath->mpp_discover(vap, dest, m);
563 #endif /* !_NET80211_IEEE80211_MESH_H_ */