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
29 * $FreeBSD: head/sys/net80211/ieee80211_mesh.c 203423 2010-02-03 10:12:49Z rpaulo $
34 * IEEE 802.11s Mesh Point (MBSS) support.
36 * Based on March 2009, D3.0 802.11s draft spec.
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
47 #include <sys/socket.h>
48 #include <sys/sockio.h>
49 #include <sys/endian.h>
50 #include <sys/errno.h>
52 #include <sys/sysctl.h>
55 #include <net/if_media.h>
56 #include <net/if_llc.h>
57 #include <net/ethernet.h>
58 #include <net/route.h>
60 #include <netproto/802_11/ieee80211_var.h>
61 #include <netproto/802_11/ieee80211_action.h>
62 #include <netproto/802_11/ieee80211_input.h>
63 #include <netproto/802_11/ieee80211_mesh.h>
65 static void mesh_rt_flush_invalid(struct ieee80211vap *);
66 static int mesh_select_proto_path(struct ieee80211vap *, const char *);
67 static int mesh_select_proto_metric(struct ieee80211vap *, const char *);
68 static void mesh_vattach(struct ieee80211vap *);
69 static int mesh_newstate(struct ieee80211vap *, enum ieee80211_state, int);
70 static void mesh_rt_cleanup_callout(void *);
71 static void mesh_linkchange(struct ieee80211_node *,
72 enum ieee80211_mesh_mlstate);
73 static void mesh_checkid(void *, struct ieee80211_node *);
74 static uint32_t mesh_generateid(struct ieee80211vap *);
75 static int mesh_checkpseq(struct ieee80211vap *,
76 const uint8_t [IEEE80211_ADDR_LEN], uint32_t);
77 static struct ieee80211_node *
78 mesh_find_txnode(struct ieee80211vap *,
79 const uint8_t [IEEE80211_ADDR_LEN]);
80 static void mesh_forward(struct ieee80211vap *, struct mbuf *,
81 const struct ieee80211_meshcntl *);
82 static int mesh_input(struct ieee80211_node *, struct mbuf *, int, int);
83 static void mesh_recv_mgmt(struct ieee80211_node *, struct mbuf *, int,
85 static void mesh_peer_timeout_setup(struct ieee80211_node *);
86 static void mesh_peer_timeout_backoff(struct ieee80211_node *);
87 static void mesh_peer_timeout_callout(void *);
89 mesh_peer_timeout_stop(struct ieee80211_node *);
90 static int mesh_verify_meshid(struct ieee80211vap *, const uint8_t *);
91 static int mesh_verify_meshconf(struct ieee80211vap *, const uint8_t *);
92 static int mesh_verify_meshpeer(struct ieee80211vap *, uint8_t,
94 uint32_t mesh_airtime_calc(struct ieee80211_node *);
97 * Timeout values come from the specification and are in milliseconds.
99 SYSCTL_NODE(_net_wlan, OID_AUTO, mesh, CTLFLAG_RD, 0,
100 "IEEE 802.11s parameters");
101 static int ieee80211_mesh_retrytimeout = -1;
102 SYSCTL_PROC(_net_wlan_mesh, OID_AUTO, retrytimeout, CTLTYPE_INT | CTLFLAG_RW,
103 &ieee80211_mesh_retrytimeout, 0, ieee80211_sysctl_msecs_ticks, "I",
104 "Retry timeout (msec)");
105 static int ieee80211_mesh_holdingtimeout = -1;
106 SYSCTL_PROC(_net_wlan_mesh, OID_AUTO, holdingtimeout, CTLTYPE_INT | CTLFLAG_RW,
107 &ieee80211_mesh_holdingtimeout, 0, ieee80211_sysctl_msecs_ticks, "I",
108 "Holding state timeout (msec)");
109 static int ieee80211_mesh_confirmtimeout = -1;
110 SYSCTL_PROC(_net_wlan_mesh, OID_AUTO, confirmtimeout, CTLTYPE_INT | CTLFLAG_RW,
111 &ieee80211_mesh_confirmtimeout, 0, ieee80211_sysctl_msecs_ticks, "I",
112 "Confirm state timeout (msec)");
113 static int ieee80211_mesh_maxretries = 2;
114 SYSCTL_INT(_net_wlan_mesh, OID_AUTO, maxretries, CTLTYPE_INT | CTLFLAG_RW,
115 &ieee80211_mesh_maxretries, 0,
116 "Maximum retries during peer link establishment");
118 static const uint8_t broadcastaddr[IEEE80211_ADDR_LEN] =
119 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
121 static ieee80211_recv_action_func mesh_recv_action_meshpeering_open;
122 static ieee80211_recv_action_func mesh_recv_action_meshpeering_confirm;
123 static ieee80211_recv_action_func mesh_recv_action_meshpeering_close;
124 static ieee80211_recv_action_func mesh_recv_action_meshlmetric_req;
125 static ieee80211_recv_action_func mesh_recv_action_meshlmetric_rep;
127 static ieee80211_send_action_func mesh_send_action_meshpeering_open;
128 static ieee80211_send_action_func mesh_send_action_meshpeering_confirm;
129 static ieee80211_send_action_func mesh_send_action_meshpeering_close;
130 static ieee80211_send_action_func mesh_send_action_meshlink_request;
131 static ieee80211_send_action_func mesh_send_action_meshlink_reply;
133 static const struct ieee80211_mesh_proto_metric mesh_metric_airtime = {
134 .mpm_descr = "AIRTIME",
135 .mpm_ie = IEEE80211_MESHCONF_METRIC_AIRTIME,
136 .mpm_metric = mesh_airtime_calc,
139 static struct ieee80211_mesh_proto_path mesh_proto_paths[4];
140 static struct ieee80211_mesh_proto_metric mesh_proto_metrics[4];
142 MALLOC_DEFINE(M_80211_MESH_RT, "80211mesh", "802.11s routing table");
145 * Helper functions to manipulate the Mesh routing table.
148 static struct ieee80211_mesh_route *
149 mesh_rt_find_locked(struct ieee80211_mesh_state *ms,
150 const uint8_t dest[IEEE80211_ADDR_LEN])
152 struct ieee80211_mesh_route *rt;
154 TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) {
155 if (IEEE80211_ADDR_EQ(dest, rt->rt_dest))
161 static struct ieee80211_mesh_route *
162 mesh_rt_add_locked(struct ieee80211_mesh_state *ms,
163 const uint8_t dest[IEEE80211_ADDR_LEN])
165 struct ieee80211_mesh_route *rt;
167 KASSERT(!IEEE80211_ADDR_EQ(broadcastaddr, dest),
168 ("%s: adding broadcast to the routing table", __func__));
170 rt = kmalloc(ALIGN(sizeof(struct ieee80211_mesh_route)) +
171 ms->ms_ppath->mpp_privlen, M_80211_MESH_RT, M_INTWAIT | M_ZERO);
173 IEEE80211_ADDR_COPY(rt->rt_dest, dest);
174 rt->rt_priv = (void *)ALIGN(&rt[1]);
175 rt->rt_crtime = ticks;
176 TAILQ_INSERT_TAIL(&ms->ms_routes, rt, rt_next);
181 struct ieee80211_mesh_route *
182 ieee80211_mesh_rt_find(struct ieee80211vap *vap,
183 const uint8_t dest[IEEE80211_ADDR_LEN])
185 struct ieee80211_mesh_state *ms = vap->iv_mesh;
186 struct ieee80211_mesh_route *rt;
188 rt = mesh_rt_find_locked(ms, dest);
192 struct ieee80211_mesh_route *
193 ieee80211_mesh_rt_add(struct ieee80211vap *vap,
194 const uint8_t dest[IEEE80211_ADDR_LEN])
196 struct ieee80211_mesh_state *ms = vap->iv_mesh;
197 struct ieee80211_mesh_route *rt;
199 KASSERT(ieee80211_mesh_rt_find(vap, dest) == NULL,
200 ("%s: duplicate entry in the routing table", __func__));
201 KASSERT(!IEEE80211_ADDR_EQ(vap->iv_myaddr, dest),
202 ("%s: adding self to the routing table", __func__));
204 rt = mesh_rt_add_locked(ms, dest);
209 * Add a proxy route (as needed) for the specified destination.
212 ieee80211_mesh_proxy_check(struct ieee80211vap *vap,
213 const uint8_t dest[IEEE80211_ADDR_LEN])
215 struct ieee80211_mesh_state *ms = vap->iv_mesh;
216 struct ieee80211_mesh_route *rt;
218 rt = mesh_rt_find_locked(ms, dest);
220 rt = mesh_rt_add_locked(ms, dest);
222 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_MESH, dest,
223 "%s", "unable to add proxy entry");
224 vap->iv_stats.is_mesh_rtaddfailed++;
226 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_MESH, dest,
227 "%s", "add proxy entry");
228 IEEE80211_ADDR_COPY(rt->rt_nexthop, vap->iv_myaddr);
229 rt->rt_flags |= IEEE80211_MESHRT_FLAGS_VALID
230 | IEEE80211_MESHRT_FLAGS_PROXY;
232 /* XXX assert PROXY? */
233 } else if ((rt->rt_flags & IEEE80211_MESHRT_FLAGS_VALID) == 0) {
234 struct ieee80211com *ic = vap->iv_ic;
236 * Fix existing entry created by received frames from
237 * stations that have some memory of dest. We also
238 * flush any frames held on the staging queue; delivering
239 * them is too much trouble right now.
241 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_MESH, dest,
242 "%s", "fix proxy entry");
243 IEEE80211_ADDR_COPY(rt->rt_nexthop, vap->iv_myaddr);
244 rt->rt_flags |= IEEE80211_MESHRT_FLAGS_VALID
245 | IEEE80211_MESHRT_FLAGS_PROXY;
246 /* XXX belongs in hwmp */
247 ieee80211_ageq_drain_node(&ic->ic_stageq,
248 (void *)(uintptr_t) ieee80211_mac_hash(ic, dest));
254 mesh_rt_del(struct ieee80211_mesh_state *ms, struct ieee80211_mesh_route *rt)
256 TAILQ_REMOVE(&ms->ms_routes, rt, rt_next);
257 kfree(rt, M_80211_MESH_RT);
261 ieee80211_mesh_rt_del(struct ieee80211vap *vap,
262 const uint8_t dest[IEEE80211_ADDR_LEN])
264 struct ieee80211_mesh_state *ms = vap->iv_mesh;
265 struct ieee80211_mesh_route *rt, *next;
267 TAILQ_FOREACH_MUTABLE(rt, &ms->ms_routes, rt_next, next) {
268 if (IEEE80211_ADDR_EQ(rt->rt_dest, dest)) {
276 ieee80211_mesh_rt_flush(struct ieee80211vap *vap)
278 struct ieee80211_mesh_state *ms = vap->iv_mesh;
279 struct ieee80211_mesh_route *rt, *next;
283 TAILQ_FOREACH_MUTABLE(rt, &ms->ms_routes, rt_next, next)
288 ieee80211_mesh_rt_flush_peer(struct ieee80211vap *vap,
289 const uint8_t peer[IEEE80211_ADDR_LEN])
291 struct ieee80211_mesh_state *ms = vap->iv_mesh;
292 struct ieee80211_mesh_route *rt, *next;
294 TAILQ_FOREACH_MUTABLE(rt, &ms->ms_routes, rt_next, next) {
295 if (IEEE80211_ADDR_EQ(rt->rt_nexthop, peer))
301 * Flush expired routing entries, i.e. those in invalid state for
305 mesh_rt_flush_invalid(struct ieee80211vap *vap)
307 struct ieee80211_mesh_state *ms = vap->iv_mesh;
308 struct ieee80211_mesh_route *rt, *next;
312 TAILQ_FOREACH_MUTABLE(rt, &ms->ms_routes, rt_next, next) {
313 if ((rt->rt_flags & IEEE80211_MESHRT_FLAGS_VALID) == 0 &&
314 ticks - rt->rt_crtime >= ms->ms_ppath->mpp_inact)
320 ieee80211_mesh_register_proto_path(const struct ieee80211_mesh_proto_path *mpp)
322 int i, firstempty = -1;
324 for (i = 0; i < NELEM(mesh_proto_paths); i++) {
325 if (strncmp(mpp->mpp_descr, mesh_proto_paths[i].mpp_descr,
326 IEEE80211_MESH_PROTO_DSZ) == 0)
328 if (!mesh_proto_paths[i].mpp_active && firstempty == -1)
333 memcpy(&mesh_proto_paths[firstempty], mpp, sizeof(*mpp));
334 mesh_proto_paths[firstempty].mpp_active = 1;
339 ieee80211_mesh_register_proto_metric(const struct
340 ieee80211_mesh_proto_metric *mpm)
342 int i, firstempty = -1;
344 for (i = 0; i < NELEM(mesh_proto_metrics); i++) {
345 if (strncmp(mpm->mpm_descr, mesh_proto_metrics[i].mpm_descr,
346 IEEE80211_MESH_PROTO_DSZ) == 0)
348 if (!mesh_proto_metrics[i].mpm_active && firstempty == -1)
353 memcpy(&mesh_proto_metrics[firstempty], mpm, sizeof(*mpm));
354 mesh_proto_metrics[firstempty].mpm_active = 1;
359 mesh_select_proto_path(struct ieee80211vap *vap, const char *name)
361 struct ieee80211_mesh_state *ms = vap->iv_mesh;
364 for (i = 0; i < NELEM(mesh_proto_paths); i++) {
365 if (strcasecmp(mesh_proto_paths[i].mpp_descr, name) == 0) {
366 ms->ms_ppath = &mesh_proto_paths[i];
374 mesh_select_proto_metric(struct ieee80211vap *vap, const char *name)
376 struct ieee80211_mesh_state *ms = vap->iv_mesh;
379 for (i = 0; i < NELEM(mesh_proto_metrics); i++) {
380 if (strcasecmp(mesh_proto_metrics[i].mpm_descr, name) == 0) {
381 ms->ms_pmetric = &mesh_proto_metrics[i];
389 ieee80211_mesh_init(void)
392 memset(mesh_proto_paths, 0, sizeof(mesh_proto_paths));
393 memset(mesh_proto_metrics, 0, sizeof(mesh_proto_metrics));
396 * Setup mesh parameters that depends on the clock frequency.
398 ieee80211_mesh_retrytimeout = msecs_to_ticks(40);
399 ieee80211_mesh_holdingtimeout = msecs_to_ticks(40);
400 ieee80211_mesh_confirmtimeout = msecs_to_ticks(40);
403 * Register action frame handlers.
405 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_MESHPEERING,
406 IEEE80211_ACTION_MESHPEERING_OPEN,
407 mesh_recv_action_meshpeering_open);
408 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_MESHPEERING,
409 IEEE80211_ACTION_MESHPEERING_CONFIRM,
410 mesh_recv_action_meshpeering_confirm);
411 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_MESHPEERING,
412 IEEE80211_ACTION_MESHPEERING_CLOSE,
413 mesh_recv_action_meshpeering_close);
414 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_MESHLMETRIC,
415 IEEE80211_ACTION_MESHLMETRIC_REQ, mesh_recv_action_meshlmetric_req);
416 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_MESHLMETRIC,
417 IEEE80211_ACTION_MESHLMETRIC_REP, mesh_recv_action_meshlmetric_rep);
419 ieee80211_send_action_register(IEEE80211_ACTION_CAT_MESHPEERING,
420 IEEE80211_ACTION_MESHPEERING_OPEN,
421 mesh_send_action_meshpeering_open);
422 ieee80211_send_action_register(IEEE80211_ACTION_CAT_MESHPEERING,
423 IEEE80211_ACTION_MESHPEERING_CONFIRM,
424 mesh_send_action_meshpeering_confirm);
425 ieee80211_send_action_register(IEEE80211_ACTION_CAT_MESHPEERING,
426 IEEE80211_ACTION_MESHPEERING_CLOSE,
427 mesh_send_action_meshpeering_close);
428 ieee80211_send_action_register(IEEE80211_ACTION_CAT_MESHLMETRIC,
429 IEEE80211_ACTION_MESHLMETRIC_REQ,
430 mesh_send_action_meshlink_request);
431 ieee80211_send_action_register(IEEE80211_ACTION_CAT_MESHLMETRIC,
432 IEEE80211_ACTION_MESHLMETRIC_REP,
433 mesh_send_action_meshlink_reply);
436 * Register Airtime Link Metric.
438 ieee80211_mesh_register_proto_metric(&mesh_metric_airtime);
441 SYSINIT(wlan_mesh, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_mesh_init, NULL);
444 ieee80211_mesh_attach(struct ieee80211com *ic)
446 ic->ic_vattach[IEEE80211_M_MBSS] = mesh_vattach;
450 ieee80211_mesh_detach(struct ieee80211com *ic)
455 mesh_vdetach_peers(void *arg, struct ieee80211_node *ni)
457 struct ieee80211com *ic = ni->ni_ic;
460 if (ni->ni_mlstate == IEEE80211_NODE_MESH_ESTABLISHED) {
461 args[0] = ni->ni_mlpid;
462 args[1] = ni->ni_mllid;
463 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
464 ieee80211_send_action(ni,
465 IEEE80211_ACTION_CAT_MESHPEERING,
466 IEEE80211_ACTION_MESHPEERING_CLOSE,
469 callout_stop(&ni->ni_mltimer);
470 /* XXX belongs in hwmp */
471 ieee80211_ageq_drain_node(&ic->ic_stageq,
472 (void *)(uintptr_t) ieee80211_mac_hash(ic, ni->ni_macaddr));
476 mesh_vdetach(struct ieee80211vap *vap)
478 struct ieee80211_mesh_state *ms = vap->iv_mesh;
480 callout_stop(&ms->ms_cleantimer);
481 ieee80211_iterate_nodes(&vap->iv_ic->ic_sta, mesh_vdetach_peers,
483 ieee80211_mesh_rt_flush(vap);
484 ms->ms_ppath->mpp_vdetach(vap);
485 kfree(vap->iv_mesh, M_80211_VAP);
490 mesh_vattach(struct ieee80211vap *vap)
492 struct ieee80211_mesh_state *ms;
493 vap->iv_newstate = mesh_newstate;
494 vap->iv_input = mesh_input;
495 vap->iv_opdetach = mesh_vdetach;
496 vap->iv_recv_mgmt = mesh_recv_mgmt;
497 ms = kmalloc(sizeof(struct ieee80211_mesh_state), M_80211_VAP,
500 kprintf("%s: couldn't alloc MBSS state\n", __func__);
505 ms->ms_flags = (IEEE80211_MESHFLAGS_AP | IEEE80211_MESHFLAGS_FWD);
506 ms->ms_ttl = IEEE80211_MESH_DEFAULT_TTL;
507 TAILQ_INIT(&ms->ms_routes);
508 callout_init_mp(&ms->ms_cleantimer);
509 mesh_select_proto_metric(vap, "AIRTIME");
510 KASSERT(ms->ms_pmetric, ("ms_pmetric == NULL"));
511 mesh_select_proto_path(vap, "HWMP");
512 KASSERT(ms->ms_ppath, ("ms_ppath == NULL"));
513 ms->ms_ppath->mpp_vattach(vap);
517 * IEEE80211_M_MBSS vap state machine handler.
520 mesh_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
522 struct ieee80211_mesh_state *ms = vap->iv_mesh;
523 struct ieee80211com *ic = vap->iv_ic;
524 struct ieee80211_node *ni;
525 enum ieee80211_state ostate;
527 ostate = vap->iv_state;
528 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n",
529 __func__, ieee80211_state_name[ostate],
530 ieee80211_state_name[nstate], arg);
531 vap->iv_state = nstate; /* state transition */
532 if (ostate != IEEE80211_S_SCAN)
533 ieee80211_cancel_scan(vap); /* background scan */
534 ni = vap->iv_bss; /* NB: no reference held */
535 if (nstate != IEEE80211_S_RUN && ostate == IEEE80211_S_RUN)
536 callout_stop(&ms->ms_cleantimer);
538 case IEEE80211_S_INIT:
540 case IEEE80211_S_SCAN:
541 ieee80211_cancel_scan(vap);
543 case IEEE80211_S_CAC:
544 ieee80211_dfs_cac_stop(vap);
546 case IEEE80211_S_RUN:
547 ieee80211_iterate_nodes(&ic->ic_sta,
548 mesh_vdetach_peers, NULL);
553 if (ostate != IEEE80211_S_INIT) {
554 /* NB: optimize INIT -> INIT case */
555 ieee80211_reset_bss(vap);
556 ieee80211_mesh_rt_flush(vap);
559 case IEEE80211_S_SCAN:
561 case IEEE80211_S_INIT:
562 if (vap->iv_des_chan != IEEE80211_CHAN_ANYC &&
563 !IEEE80211_IS_CHAN_RADAR(vap->iv_des_chan) &&
566 * Already have a channel and a mesh ID; bypass
567 * the scan and startup immediately.
569 ieee80211_create_ibss(vap, vap->iv_des_chan);
573 * Initiate a scan. We can come here as a result
574 * of an IEEE80211_IOC_SCAN_REQ too in which case
575 * the vap will be marked with IEEE80211_FEXT_SCANREQ
576 * and the scan request parameters will be present
577 * in iv_scanreq. Otherwise we do the default.
579 if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) {
580 ieee80211_check_scan(vap,
581 vap->iv_scanreq_flags,
582 vap->iv_scanreq_duration,
583 vap->iv_scanreq_mindwell,
584 vap->iv_scanreq_maxdwell,
585 vap->iv_scanreq_nssid, vap->iv_scanreq_ssid);
586 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ;
588 ieee80211_check_scan_current(vap);
594 case IEEE80211_S_CAC:
596 * Start CAC on a DFS channel. We come here when starting
597 * a bss on a DFS channel (see ieee80211_create_ibss).
599 ieee80211_dfs_cac_start(vap);
601 case IEEE80211_S_RUN:
603 case IEEE80211_S_INIT:
605 * Already have a channel; bypass the
606 * scan and startup immediately.
607 * Note that ieee80211_create_ibss will call
608 * back to do a RUN->RUN state change.
610 ieee80211_create_ibss(vap,
611 ieee80211_ht_adjust_channel(ic,
612 ic->ic_curchan, vap->iv_flags_ht));
613 /* NB: iv_bss is changed on return */
615 case IEEE80211_S_CAC:
617 * NB: This is the normal state change when CAC
618 * expires and no radar was detected; no need to
619 * clear the CAC timer as it's already expired.
622 case IEEE80211_S_CSA:
625 * Shorten inactivity timer of associated stations
626 * to weed out sta's that don't follow a CSA.
628 ieee80211_iterate_nodes(&ic->ic_sta, sta_csa, vap);
631 * Update bss node channel to reflect where
632 * we landed after CSA.
634 ieee80211_node_set_chan(vap->iv_bss,
635 ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
636 ieee80211_htchanflags(vap->iv_bss->ni_chan)));
637 /* XXX bypass debug msgs */
639 case IEEE80211_S_SCAN:
640 case IEEE80211_S_RUN:
641 #ifdef IEEE80211_DEBUG
642 if (ieee80211_msg_debug(vap)) {
643 struct ieee80211_node *ni = vap->iv_bss;
645 "synchronized with %6D meshid ",
647 ieee80211_print_essid(ni->ni_meshid,
650 kprintf(" channel %d\n",
651 ieee80211_chan2ieee(ic, ic->ic_curchan));
658 ieee80211_node_authorize(vap->iv_bss);
659 callout_reset(&ms->ms_cleantimer, ms->ms_ppath->mpp_inact,
660 mesh_rt_cleanup_callout, vap);
665 /* NB: ostate not nstate */
666 ms->ms_ppath->mpp_newstate(vap, ostate, arg);
671 mesh_rt_cleanup_callout(void *arg)
673 struct ieee80211vap *vap = arg;
674 struct ieee80211_mesh_state *ms = vap->iv_mesh;
676 wlan_serialize_enter();
677 mesh_rt_flush_invalid(vap);
678 callout_reset(&ms->ms_cleantimer, ms->ms_ppath->mpp_inact,
679 mesh_rt_cleanup_callout, vap);
680 wlan_serialize_exit();
685 * Helper function to note the Mesh Peer Link FSM change.
688 mesh_linkchange(struct ieee80211_node *ni, enum ieee80211_mesh_mlstate state)
690 struct ieee80211vap *vap = ni->ni_vap;
691 struct ieee80211_mesh_state *ms = vap->iv_mesh;
692 #ifdef IEEE80211_DEBUG
693 static const char *meshlinkstates[] = {
694 [IEEE80211_NODE_MESH_IDLE] = "IDLE",
695 [IEEE80211_NODE_MESH_OPENSNT] = "OPEN SENT",
696 [IEEE80211_NODE_MESH_OPENRCV] = "OPEN RECEIVED",
697 [IEEE80211_NODE_MESH_CONFIRMRCV] = "CONFIRM RECEIVED",
698 [IEEE80211_NODE_MESH_ESTABLISHED] = "ESTABLISHED",
699 [IEEE80211_NODE_MESH_HOLDING] = "HOLDING"
702 IEEE80211_NOTE(vap, IEEE80211_MSG_MESH,
703 ni, "peer link: %s -> %s",
704 meshlinkstates[ni->ni_mlstate], meshlinkstates[state]);
706 /* track neighbor count */
707 if (state == IEEE80211_NODE_MESH_ESTABLISHED &&
708 ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
709 KASSERT(ms->ms_neighbors < 65535, ("neighbor count overflow"));
711 ieee80211_beacon_notify(vap, IEEE80211_BEACON_MESHCONF);
712 } else if (ni->ni_mlstate == IEEE80211_NODE_MESH_ESTABLISHED &&
713 state != IEEE80211_NODE_MESH_ESTABLISHED) {
714 KASSERT(ms->ms_neighbors > 0, ("neighbor count 0"));
716 ieee80211_beacon_notify(vap, IEEE80211_BEACON_MESHCONF);
718 ni->ni_mlstate = state;
720 case IEEE80211_NODE_MESH_HOLDING:
721 ms->ms_ppath->mpp_peerdown(ni);
723 case IEEE80211_NODE_MESH_ESTABLISHED:
724 ieee80211_mesh_discover(vap, ni->ni_macaddr, NULL);
732 * Helper function to generate a unique local ID required for mesh
733 * peer establishment.
736 mesh_checkid(void *arg, struct ieee80211_node *ni)
740 if (*r == ni->ni_mllid)
741 *(uint16_t *)arg = 0;
745 mesh_generateid(struct ieee80211vap *vap)
751 get_random_bytes(&r, 2);
752 ieee80211_iterate_nodes(&vap->iv_ic->ic_sta, mesh_checkid, &r);
754 } while (r == 0 && maxiter > 0);
759 * Verifies if we already received this packet by checking its
761 * Returns 0 if the frame is to be accepted, 1 otherwise.
764 mesh_checkpseq(struct ieee80211vap *vap,
765 const uint8_t source[IEEE80211_ADDR_LEN], uint32_t seq)
767 struct ieee80211_mesh_route *rt;
769 rt = ieee80211_mesh_rt_find(vap, source);
771 rt = ieee80211_mesh_rt_add(vap, source);
773 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_MESH, source,
774 "%s", "add mcast route failed");
775 vap->iv_stats.is_mesh_rtaddfailed++;
778 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_MESH, source,
779 "add mcast route, mesh seqno %d", seq);
780 rt->rt_lastmseq = seq;
783 if (IEEE80211_MESH_SEQ_GEQ(rt->rt_lastmseq, seq)) {
786 rt->rt_lastmseq = seq;
792 * Iterate the routing table and locate the next hop.
794 static struct ieee80211_node *
795 mesh_find_txnode(struct ieee80211vap *vap,
796 const uint8_t dest[IEEE80211_ADDR_LEN])
798 struct ieee80211_mesh_route *rt;
800 rt = ieee80211_mesh_rt_find(vap, dest);
803 if ((rt->rt_flags & IEEE80211_MESHRT_FLAGS_VALID) == 0 ||
804 (rt->rt_flags & IEEE80211_MESHRT_FLAGS_PROXY)) {
805 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_MESH, dest,
806 "%s: !valid or proxy, flags 0x%x", __func__, rt->rt_flags);
810 return ieee80211_find_txnode(vap, rt->rt_nexthop);
814 * Forward the specified frame.
815 * Decrement the TTL and set TA to our MAC address.
818 mesh_forward(struct ieee80211vap *vap, struct mbuf *m,
819 const struct ieee80211_meshcntl *mc)
821 struct ieee80211com *ic = vap->iv_ic;
822 struct ieee80211_mesh_state *ms = vap->iv_mesh;
823 struct ifnet *ifp = vap->iv_ifp;
824 struct ifnet *parent = ic->ic_ifp;
825 const struct ieee80211_frame *wh =
826 mtod(m, const struct ieee80211_frame *);
828 struct ieee80211_meshcntl *mccopy;
829 struct ieee80211_frame *whcopy;
830 struct ieee80211_node *ni;
833 if (mc->mc_ttl == 0) {
834 IEEE80211_NOTE_FRAME(vap, IEEE80211_MSG_MESH, wh,
835 "%s", "frame not fwd'd, ttl 0");
836 vap->iv_stats.is_mesh_fwd_ttl++;
839 if (!(ms->ms_flags & IEEE80211_MESHFLAGS_FWD)) {
840 IEEE80211_NOTE_FRAME(vap, IEEE80211_MSG_MESH, wh,
841 "%s", "frame not fwd'd, fwding disabled");
842 vap->iv_stats.is_mesh_fwd_disabled++;
845 mcopy = m_dup(m, MB_DONTWAIT);
847 IEEE80211_NOTE_FRAME(vap, IEEE80211_MSG_MESH, wh,
848 "%s", "frame not fwd'd, cannot dup");
849 vap->iv_stats.is_mesh_fwd_nobuf++;
853 mcopy = m_pullup(mcopy, ieee80211_hdrspace(ic, wh) +
854 sizeof(struct ieee80211_meshcntl));
856 IEEE80211_NOTE_FRAME(vap, IEEE80211_MSG_MESH, wh,
857 "%s", "frame not fwd'd, too short");
858 vap->iv_stats.is_mesh_fwd_tooshort++;
863 whcopy = mtod(mcopy, struct ieee80211_frame *);
864 mccopy = (struct ieee80211_meshcntl *)
865 (mtod(mcopy, uint8_t *) + ieee80211_hdrspace(ic, wh));
866 /* XXX clear other bits? */
867 whcopy->i_fc[1] &= ~IEEE80211_FC1_RETRY;
868 IEEE80211_ADDR_COPY(whcopy->i_addr2, vap->iv_myaddr);
869 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
870 ni = ieee80211_ref_node(vap->iv_bss);
871 mcopy->m_flags |= M_MCAST;
873 ni = mesh_find_txnode(vap, whcopy->i_addr3);
875 IEEE80211_NOTE_FRAME(vap, IEEE80211_MSG_MESH, wh,
876 "%s", "frame not fwd'd, no path");
877 vap->iv_stats.is_mesh_fwd_nopath++;
881 IEEE80211_ADDR_COPY(whcopy->i_addr1, ni->ni_macaddr);
883 KASSERT(mccopy->mc_ttl > 0, ("%s called with wrong ttl", __func__));
886 /* XXX calculate priority so drivers can find the tx queue */
887 M_WME_SETAC(mcopy, WME_AC_BE);
889 /* XXX do we know m_nextpkt is NULL? */
890 mcopy->m_pkthdr.rcvif = (void *) ni;
891 err = ieee80211_handoff(parent, mcopy);
893 /* NB: IFQ_HANDOFF reclaims mbuf */
894 ieee80211_free_node(ni);
901 mesh_decap(struct ieee80211vap *vap, struct mbuf *m, int hdrlen, int meshdrlen)
903 #define WHDIR(wh) ((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK)
904 uint8_t b[sizeof(struct ieee80211_qosframe_addr4) +
905 sizeof(struct ieee80211_meshcntl_ae11)];
906 const struct ieee80211_qosframe_addr4 *wh;
907 const struct ieee80211_meshcntl_ae10 *mc;
908 struct ether_header *eh;
912 if (m->m_len < hdrlen + sizeof(*llc) &&
913 (m = m_pullup(m, hdrlen + sizeof(*llc))) == NULL) {
914 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ANY,
915 "discard data frame: %s", "m_pullup failed");
916 vap->iv_stats.is_rx_tooshort++;
919 memcpy(b, mtod(m, caddr_t), hdrlen);
920 wh = (const struct ieee80211_qosframe_addr4 *)&b[0];
921 mc = (const struct ieee80211_meshcntl_ae10 *)&b[hdrlen - meshdrlen];
922 KASSERT(WHDIR(wh) == IEEE80211_FC1_DIR_FROMDS ||
923 WHDIR(wh) == IEEE80211_FC1_DIR_DSTODS,
924 ("bogus dir, fc 0x%x:0x%x", wh->i_fc[0], wh->i_fc[1]));
926 llc = (struct llc *)(mtod(m, caddr_t) + hdrlen);
927 if (llc->llc_dsap == LLC_SNAP_LSAP && llc->llc_ssap == LLC_SNAP_LSAP &&
928 llc->llc_control == LLC_UI && llc->llc_snap.org_code[0] == 0 &&
929 llc->llc_snap.org_code[1] == 0 && llc->llc_snap.org_code[2] == 0 &&
930 /* NB: preserve AppleTalk frames that have a native SNAP hdr */
931 !(llc->llc_snap.ether_type == htons(ETHERTYPE_AARP) ||
932 llc->llc_snap.ether_type == htons(ETHERTYPE_IPX))) {
933 m_adj(m, hdrlen + sizeof(struct llc) - sizeof(*eh));
936 m_adj(m, hdrlen - sizeof(*eh));
938 eh = mtod(m, struct ether_header *);
939 ae = mc->mc_flags & 3;
940 if (WHDIR(wh) == IEEE80211_FC1_DIR_FROMDS) {
941 IEEE80211_ADDR_COPY(eh->ether_dhost, wh->i_addr1);
943 IEEE80211_ADDR_COPY(eh->ether_shost, wh->i_addr3);
944 } else if (ae == 1) {
945 IEEE80211_ADDR_COPY(eh->ether_shost, mc->mc_addr4);
947 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
948 (const struct ieee80211_frame *)wh, NULL,
950 vap->iv_stats.is_mesh_badae++;
956 IEEE80211_ADDR_COPY(eh->ether_dhost, wh->i_addr3);
957 IEEE80211_ADDR_COPY(eh->ether_shost, wh->i_addr4);
958 } else if (ae == 2) {
959 IEEE80211_ADDR_COPY(eh->ether_dhost, mc->mc_addr4);
960 IEEE80211_ADDR_COPY(eh->ether_shost, mc->mc_addr5);
962 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
963 (const struct ieee80211_frame *)wh, NULL,
965 vap->iv_stats.is_mesh_badae++;
970 #ifdef ALIGNED_POINTER
971 if (!ALIGNED_POINTER(mtod(m, caddr_t) + sizeof(*eh), uint32_t)) {
972 m = ieee80211_realign(vap, m, sizeof(*eh));
976 #endif /* ALIGNED_POINTER */
978 eh = mtod(m, struct ether_header *);
979 eh->ether_type = htons(m->m_pkthdr.len - sizeof(*eh));
986 * Return non-zero if the unicast mesh data frame should be processed
987 * locally. Frames that are not proxy'd have our address, otherwise
988 * we need to consult the routing table to look for a proxy entry.
991 mesh_isucastforme(struct ieee80211vap *vap, const struct ieee80211_frame *wh,
992 const struct ieee80211_meshcntl *mc)
994 int ae = mc->mc_flags & 3;
996 KASSERT((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS,
997 ("bad dir 0x%x:0x%x", wh->i_fc[0], wh->i_fc[1]));
998 KASSERT(ae == 0 || ae == 2, ("bad AE %d", ae));
999 if (ae == 2) { /* ucast w/ proxy */
1000 const struct ieee80211_meshcntl_ae10 *mc10 =
1001 (const struct ieee80211_meshcntl_ae10 *) mc;
1002 struct ieee80211_mesh_route *rt =
1003 ieee80211_mesh_rt_find(vap, mc10->mc_addr4);
1004 /* check for proxy route to ourself */
1005 return (rt != NULL &&
1006 (rt->rt_flags & IEEE80211_MESHRT_FLAGS_PROXY));
1007 } else /* ucast w/o proxy */
1008 return IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_myaddr);
1012 mesh_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
1014 #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
1015 #define HAS_SEQ(type) ((type & 0x4) == 0)
1016 struct ieee80211vap *vap = ni->ni_vap;
1017 struct ieee80211com *ic = ni->ni_ic;
1018 struct ifnet *ifp = vap->iv_ifp;
1019 struct ieee80211_frame *wh;
1020 const struct ieee80211_meshcntl *mc;
1021 int hdrspace, meshdrlen, need_tap;
1022 uint8_t dir, type, subtype, qos;
1025 ieee80211_seq rxseq;
1027 KASSERT(ni != NULL, ("null node"));
1028 ni->ni_inact = ni->ni_inact_reload;
1030 need_tap = 1; /* mbuf need to be tapped. */
1031 type = -1; /* undefined */
1033 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) {
1034 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1035 ni->ni_macaddr, NULL,
1036 "too short (1): len %u", m->m_pkthdr.len);
1037 vap->iv_stats.is_rx_tooshort++;
1041 * Bit of a cheat here, we use a pointer for a 3-address
1042 * frame format but don't reference fields past outside
1043 * ieee80211_frame_min w/o first validating the data is
1046 wh = mtod(m, struct ieee80211_frame *);
1048 if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
1049 IEEE80211_FC0_VERSION_0) {
1050 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1051 ni->ni_macaddr, NULL, "wrong version %x", wh->i_fc[0]);
1052 vap->iv_stats.is_rx_badversion++;
1055 dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
1056 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
1057 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
1058 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
1059 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
1061 if (HAS_SEQ(type)) {
1062 uint8_t tid = ieee80211_gettid(wh);
1064 if (IEEE80211_QOS_HAS_SEQ(wh) &&
1065 TID_TO_WME_AC(tid) >= WME_AC_VI)
1066 ic->ic_wme.wme_hipri_traffic++;
1067 rxseq = le16toh(*(uint16_t *)wh->i_seq);
1068 if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
1069 (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
1070 SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
1071 /* duplicate, discard */
1072 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
1073 wh->i_addr1, "duplicate",
1074 "seqno <%u,%u> fragno <%u,%u> tid %u",
1075 rxseq >> IEEE80211_SEQ_SEQ_SHIFT,
1076 ni->ni_rxseqs[tid] >>
1077 IEEE80211_SEQ_SEQ_SHIFT,
1078 rxseq & IEEE80211_SEQ_FRAG_MASK,
1079 ni->ni_rxseqs[tid] &
1080 IEEE80211_SEQ_FRAG_MASK,
1082 vap->iv_stats.is_rx_dup++;
1083 IEEE80211_NODE_STAT(ni, rx_dup);
1086 ni->ni_rxseqs[tid] = rxseq;
1089 #ifdef IEEE80211_DEBUG
1091 * It's easier, but too expensive, to simulate different mesh
1092 * topologies by consulting the ACL policy very early, so do this
1095 * NB: this check is also done upon peering link initiation.
1097 if (vap->iv_acl != NULL && !vap->iv_acl->iac_check(vap, wh->i_addr2)) {
1098 IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL,
1099 wh, NULL, "%s", "disallowed by ACL");
1100 vap->iv_stats.is_rx_acl++;
1105 case IEEE80211_FC0_TYPE_DATA:
1106 if (ni == vap->iv_bss)
1108 if (ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
1109 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
1110 ni->ni_macaddr, NULL,
1111 "peer link not yet established (%d)",
1113 vap->iv_stats.is_mesh_nolink++;
1116 if (dir != IEEE80211_FC1_DIR_FROMDS &&
1117 dir != IEEE80211_FC1_DIR_DSTODS) {
1118 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1119 wh, "data", "incorrect dir 0x%x", dir);
1120 vap->iv_stats.is_rx_wrongdir++;
1123 /* pull up enough to get to the mesh control */
1124 hdrspace = ieee80211_hdrspace(ic, wh);
1125 if (m->m_len < hdrspace + sizeof(struct ieee80211_meshcntl) &&
1126 (m = m_pullup(m, hdrspace +
1127 sizeof(struct ieee80211_meshcntl))) == NULL) {
1128 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1129 ni->ni_macaddr, NULL,
1130 "data too short: expecting %u", hdrspace);
1131 vap->iv_stats.is_rx_tooshort++;
1135 * Now calculate the full extent of the headers. Note
1136 * mesh_decap will pull up anything we didn't get
1137 * above when it strips the 802.11 headers.
1139 mc = (const struct ieee80211_meshcntl *)
1140 (mtod(m, const uint8_t *) + hdrspace);
1141 meshdrlen = sizeof(struct ieee80211_meshcntl) +
1142 (mc->mc_flags & 3) * IEEE80211_ADDR_LEN;
1143 hdrspace += meshdrlen;
1144 seq = LE_READ_4(mc->mc_seq);
1145 if (IEEE80211_IS_MULTICAST(wh->i_addr1))
1148 addr = ((struct ieee80211_qosframe_addr4 *)wh)->i_addr4;
1149 if (IEEE80211_ADDR_EQ(vap->iv_myaddr, addr)) {
1150 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
1151 addr, "data", "%s", "not to me");
1152 vap->iv_stats.is_rx_wrongbss++; /* XXX kinda */
1155 if (mesh_checkpseq(vap, addr, seq) != 0) {
1156 vap->iv_stats.is_rx_dup++;
1161 * Potentially forward packet. See table s36 (p140)
1162 * for the rules. XXX tap fwd'd packets not for us?
1164 if (dir == IEEE80211_FC1_DIR_FROMDS ||
1165 !mesh_isucastforme(vap, wh, mc)) {
1166 mesh_forward(vap, m, mc);
1167 if (dir == IEEE80211_FC1_DIR_DSTODS)
1169 /* NB: fall thru to deliver mcast frames locally */
1173 * Save QoS bits for use below--before we strip the header.
1175 if (subtype == IEEE80211_FC0_SUBTYPE_QOS) {
1176 qos = (dir == IEEE80211_FC1_DIR_DSTODS) ?
1177 ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0] :
1178 ((struct ieee80211_qosframe *)wh)->i_qos[0];
1182 * Next up, any fragmentation.
1184 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1185 m = ieee80211_defrag(ni, m, hdrspace);
1187 /* Fragment dropped or frame not complete yet */
1191 wh = NULL; /* no longer valid, catch any uses */
1193 if (ieee80211_radiotap_active_vap(vap))
1194 ieee80211_radiotap_rx(vap, m);
1198 * Finally, strip the 802.11 header.
1200 m = mesh_decap(vap, m, hdrspace, meshdrlen);
1202 /* XXX mask bit to check for both */
1203 /* don't count Null data frames as errors */
1204 if (subtype == IEEE80211_FC0_SUBTYPE_NODATA ||
1205 subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL)
1207 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
1208 ni->ni_macaddr, "data", "%s", "decap error");
1209 vap->iv_stats.is_rx_decap++;
1210 IEEE80211_NODE_STAT(ni, rx_decap);
1213 if (qos & IEEE80211_QOS_AMSDU) {
1214 m = ieee80211_decap_amsdu(ni, m);
1216 return IEEE80211_FC0_TYPE_DATA;
1218 ieee80211_deliver_data(vap, ni, m);
1220 case IEEE80211_FC0_TYPE_MGT:
1221 vap->iv_stats.is_rx_mgmt++;
1222 IEEE80211_NODE_STAT(ni, rx_mgmt);
1223 if (dir != IEEE80211_FC1_DIR_NODS) {
1224 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1225 wh, "mgt", "incorrect dir 0x%x", dir);
1226 vap->iv_stats.is_rx_wrongdir++;
1229 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
1230 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1231 ni->ni_macaddr, "mgt", "too short: len %u",
1233 vap->iv_stats.is_rx_tooshort++;
1236 #ifdef IEEE80211_DEBUG
1237 if ((ieee80211_msg_debug(vap) &&
1238 (vap->iv_ic->ic_flags & IEEE80211_F_SCAN)) ||
1239 ieee80211_msg_dumppkts(vap)) {
1240 if_printf(ifp, "received %s from %6D rssi %d\n",
1241 ieee80211_mgt_subtype_name[subtype >>
1242 IEEE80211_FC0_SUBTYPE_SHIFT],
1243 wh->i_addr2, ":", rssi);
1246 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
1247 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1248 wh, NULL, "%s", "WEP set but not permitted");
1249 vap->iv_stats.is_rx_mgtdiscard++; /* XXX */
1252 vap->iv_recv_mgmt(ni, m, subtype, rssi, nf);
1254 case IEEE80211_FC0_TYPE_CTL:
1255 vap->iv_stats.is_rx_ctl++;
1256 IEEE80211_NODE_STAT(ni, rx_ctrl);
1259 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1260 wh, "bad", "frame type 0x%x", type);
1261 /* should not come here */
1268 if (need_tap && ieee80211_radiotap_active_vap(vap))
1269 ieee80211_radiotap_rx(vap, m);
1276 mesh_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, int subtype,
1279 struct ieee80211vap *vap = ni->ni_vap;
1280 struct ieee80211_mesh_state *ms = vap->iv_mesh;
1281 struct ieee80211com *ic = ni->ni_ic;
1282 struct ieee80211_frame *wh;
1283 uint8_t *frm, *efrm;
1285 wh = mtod(m0, struct ieee80211_frame *);
1286 frm = (uint8_t *)&wh[1];
1287 efrm = mtod(m0, uint8_t *) + m0->m_len;
1289 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
1290 case IEEE80211_FC0_SUBTYPE_BEACON:
1292 struct ieee80211_scanparams scan;
1294 * We process beacon/probe response
1295 * frames to discover neighbors.
1297 if (ieee80211_parse_beacon(ni, m0, &scan) != 0)
1300 * Count frame now that we know it's to be processed.
1302 if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) {
1303 vap->iv_stats.is_rx_beacon++; /* XXX remove */
1304 IEEE80211_NODE_STAT(ni, rx_beacons);
1306 IEEE80211_NODE_STAT(ni, rx_proberesp);
1308 * If scanning, just pass information to the scan module.
1310 if (ic->ic_flags & IEEE80211_F_SCAN) {
1311 if (ic->ic_flags_ext & IEEE80211_FEXT_PROBECHAN) {
1313 * Actively scanning a channel marked passive;
1314 * send a probe request now that we know there
1315 * is 802.11 traffic present.
1317 * XXX check if the beacon we recv'd gives
1318 * us what we need and suppress the probe req
1320 ieee80211_probe_curchan(vap, 1);
1321 ic->ic_flags_ext &= ~IEEE80211_FEXT_PROBECHAN;
1323 ieee80211_add_scan(vap, &scan, wh,
1328 /* The rest of this code assumes we are running */
1329 if (vap->iv_state != IEEE80211_S_RUN)
1332 * Ignore non-mesh STAs.
1335 (IEEE80211_CAPINFO_ESS|IEEE80211_CAPINFO_IBSS)) ||
1336 scan.meshid == NULL || scan.meshconf == NULL) {
1337 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1338 wh, "beacon", "%s", "not a mesh sta");
1339 vap->iv_stats.is_mesh_wrongmesh++;
1343 * Ignore STAs for other mesh networks.
1345 if (memcmp(scan.meshid+2, ms->ms_id, ms->ms_idlen) != 0 ||
1346 mesh_verify_meshconf(vap, scan.meshconf)) {
1347 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1348 wh, "beacon", "%s", "not for our mesh");
1349 vap->iv_stats.is_mesh_wrongmesh++;
1353 * Peer only based on the current ACL policy.
1355 if (vap->iv_acl != NULL &&
1356 !vap->iv_acl->iac_check(vap, wh->i_addr2)) {
1357 IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL,
1358 wh, NULL, "%s", "disallowed by ACL");
1359 vap->iv_stats.is_rx_acl++;
1363 * Do neighbor discovery.
1365 if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) {
1367 * Create a new entry in the neighbor table.
1369 ni = ieee80211_add_neighbor(vap, wh, &scan);
1372 * Automatically peer with discovered nodes if possible.
1373 * XXX backoff on repeated failure
1375 if (ni != vap->iv_bss &&
1376 (ms->ms_flags & IEEE80211_MESHFLAGS_AP) &&
1377 ni->ni_mlstate == IEEE80211_NODE_MESH_IDLE) {
1380 ni->ni_mlpid = mesh_generateid(vap);
1381 if (ni->ni_mlpid == 0)
1383 mesh_linkchange(ni, IEEE80211_NODE_MESH_OPENSNT);
1384 args[0] = ni->ni_mlpid;
1385 ieee80211_send_action(ni,
1386 IEEE80211_ACTION_CAT_MESHPEERING,
1387 IEEE80211_ACTION_MESHPEERING_OPEN, args);
1389 mesh_peer_timeout_setup(ni);
1393 case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
1395 uint8_t *ssid, *meshid, *rates, *xrates;
1398 if (vap->iv_state != IEEE80211_S_RUN) {
1399 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1400 wh, NULL, "wrong state %s",
1401 ieee80211_state_name[vap->iv_state]);
1402 vap->iv_stats.is_rx_mgtdiscard++;
1405 if (IEEE80211_IS_MULTICAST(wh->i_addr2)) {
1406 /* frame must be directed */
1407 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1408 wh, NULL, "%s", "not unicast");
1409 vap->iv_stats.is_rx_mgtdiscard++; /* XXX stat */
1413 * prreq frame format
1415 * [tlv] supported rates
1416 * [tlv] extended supported rates
1419 ssid = meshid = rates = xrates = NULL;
1421 while (efrm - frm > 1) {
1422 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return);
1424 case IEEE80211_ELEMID_SSID:
1427 case IEEE80211_ELEMID_RATES:
1430 case IEEE80211_ELEMID_XRATES:
1433 case IEEE80211_ELEMID_MESHID:
1439 IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return);
1440 IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return);
1442 IEEE80211_VERIFY_ELEMENT(xrates,
1443 IEEE80211_RATE_MAXSIZE - rates[1], return);
1444 if (meshid != NULL) {
1445 IEEE80211_VERIFY_ELEMENT(meshid,
1446 IEEE80211_MESHID_LEN, return);
1447 /* NB: meshid, not ssid */
1448 IEEE80211_VERIFY_SSID(vap->iv_bss, meshid, return);
1451 /* XXX find a better class or define it's own */
1452 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2,
1453 "%s", "recv probe req");
1455 * Some legacy 11b clients cannot hack a complete
1456 * probe response frame. When the request includes
1457 * only a bare-bones rate set, communicate this to
1458 * the transmit side.
1460 ieee80211_send_proberesp(vap, wh->i_addr2, 0);
1463 case IEEE80211_FC0_SUBTYPE_ACTION:
1464 if (vap->iv_state != IEEE80211_S_RUN) {
1465 vap->iv_stats.is_rx_mgtdiscard++;
1469 * We received an action for an unknown neighbor.
1470 * XXX: wait for it to beacon or create ieee80211_node?
1472 if (ni == vap->iv_bss) {
1473 IEEE80211_DISCARD(vap, IEEE80211_MSG_MESH,
1474 wh, NULL, "%s", "unknown node");
1475 vap->iv_stats.is_rx_mgtdiscard++;
1479 * Discard if not for us.
1481 if (!IEEE80211_ADDR_EQ(vap->iv_myaddr, wh->i_addr1) &&
1482 !IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1483 IEEE80211_DISCARD(vap, IEEE80211_MSG_MESH,
1484 wh, NULL, "%s", "not for me");
1485 vap->iv_stats.is_rx_mgtdiscard++;
1488 /* XXX parse_action is a bit useless now */
1489 if (ieee80211_parse_action(ni, m0) == 0)
1490 ic->ic_recv_action(ni, wh, frm, efrm);
1492 case IEEE80211_FC0_SUBTYPE_AUTH:
1493 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
1494 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
1495 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
1496 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
1497 case IEEE80211_FC0_SUBTYPE_DEAUTH:
1498 case IEEE80211_FC0_SUBTYPE_DISASSOC:
1499 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1500 wh, NULL, "%s", "not handled");
1501 vap->iv_stats.is_rx_mgtdiscard++;
1504 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1505 wh, "mgt", "subtype 0x%x not handled", subtype);
1506 vap->iv_stats.is_rx_badsubtype++;
1512 * Parse meshpeering action ie's for open+confirm frames; the
1513 * important bits are returned in the supplied structure.
1515 static const struct ieee80211_meshpeer_ie *
1516 mesh_parse_meshpeering_action(struct ieee80211_node *ni,
1517 const struct ieee80211_frame *wh, /* XXX for VERIFY_LENGTH */
1518 const uint8_t *frm, const uint8_t *efrm,
1519 struct ieee80211_meshpeer_ie *mp, uint8_t subtype)
1521 struct ieee80211vap *vap = ni->ni_vap;
1522 const struct ieee80211_meshpeer_ie *mpie;
1523 const uint8_t *meshid, *meshconf, *meshpeer;
1525 meshid = meshconf = meshpeer = NULL;
1526 while (efrm - frm > 1) {
1527 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return NULL);
1529 case IEEE80211_ELEMID_MESHID:
1532 case IEEE80211_ELEMID_MESHCONF:
1535 case IEEE80211_ELEMID_MESHPEER:
1537 mpie = (const struct ieee80211_meshpeer_ie *) frm;
1538 memset(mp, 0, sizeof(*mp));
1539 mp->peer_llinkid = LE_READ_2(&mpie->peer_llinkid);
1540 /* NB: peer link ID is optional on these frames */
1541 if (subtype == IEEE80211_MESH_PEER_LINK_CLOSE &&
1542 mpie->peer_len == 8) {
1543 mp->peer_linkid = 0;
1544 mp->peer_rcode = LE_READ_2(&mpie->peer_linkid);
1546 mp->peer_linkid = LE_READ_2(&mpie->peer_linkid);
1547 mp->peer_rcode = LE_READ_2(&mpie->peer_rcode);
1555 * Verify the contents of the frame. Action frames with
1556 * close subtype don't have a Mesh Configuration IE.
1557 * If if fails validation, close the peer link.
1559 KASSERT(meshpeer != NULL &&
1560 subtype != IEEE80211_ACTION_MESHPEERING_CLOSE,
1561 ("parsing close action"));
1563 if (mesh_verify_meshid(vap, meshid) ||
1564 mesh_verify_meshpeer(vap, subtype, meshpeer) ||
1565 mesh_verify_meshconf(vap, meshconf)) {
1568 IEEE80211_DISCARD(vap,
1569 IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH,
1570 wh, NULL, "%s", "not for our mesh");
1571 vap->iv_stats.is_rx_mgtdiscard++;
1572 switch (ni->ni_mlstate) {
1573 case IEEE80211_NODE_MESH_IDLE:
1574 case IEEE80211_NODE_MESH_ESTABLISHED:
1575 case IEEE80211_NODE_MESH_HOLDING:
1578 case IEEE80211_NODE_MESH_OPENSNT:
1579 case IEEE80211_NODE_MESH_OPENRCV:
1580 case IEEE80211_NODE_MESH_CONFIRMRCV:
1581 args[0] = ni->ni_mlpid;
1582 args[1] = ni->ni_mllid;
1583 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1584 ieee80211_send_action(ni,
1585 IEEE80211_ACTION_CAT_MESHPEERING,
1586 IEEE80211_ACTION_MESHPEERING_CLOSE,
1588 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1589 mesh_peer_timeout_setup(ni);
1594 return (const struct ieee80211_meshpeer_ie *) mp;
1598 mesh_recv_action_meshpeering_open(struct ieee80211_node *ni,
1599 const struct ieee80211_frame *wh,
1600 const uint8_t *frm, const uint8_t *efrm)
1602 struct ieee80211vap *vap = ni->ni_vap;
1603 struct ieee80211_meshpeer_ie ie;
1604 const struct ieee80211_meshpeer_ie *meshpeer;
1607 /* +2+2 for action + code + capabilites */
1608 meshpeer = mesh_parse_meshpeering_action(ni, wh, frm+2+2, efrm, &ie,
1609 IEEE80211_ACTION_MESHPEERING_OPEN);
1610 if (meshpeer == NULL) {
1615 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1616 "recv PEER OPEN, lid 0x%x", meshpeer->peer_llinkid);
1618 switch (ni->ni_mlstate) {
1619 case IEEE80211_NODE_MESH_IDLE:
1620 mesh_linkchange(ni, IEEE80211_NODE_MESH_OPENRCV);
1621 ni->ni_mllid = meshpeer->peer_llinkid;
1622 ni->ni_mlpid = mesh_generateid(vap);
1623 if (ni->ni_mlpid == 0)
1625 args[0] = ni->ni_mlpid;
1626 /* Announce we're open too... */
1627 ieee80211_send_action(ni,
1628 IEEE80211_ACTION_CAT_MESHPEERING,
1629 IEEE80211_ACTION_MESHPEERING_OPEN, args);
1630 /* ...and confirm the link. */
1631 args[0] = ni->ni_mlpid;
1632 args[1] = ni->ni_mllid;
1633 ieee80211_send_action(ni,
1634 IEEE80211_ACTION_CAT_MESHPEERING,
1635 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1637 mesh_peer_timeout_setup(ni);
1639 case IEEE80211_NODE_MESH_OPENRCV:
1641 if (ni->ni_mllid != meshpeer->peer_llinkid) {
1642 args[0] = ni->ni_mllid;
1643 args[1] = ni->ni_mlpid;
1644 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1645 ieee80211_send_action(ni,
1646 IEEE80211_ACTION_CAT_MESHPEERING,
1647 IEEE80211_ACTION_MESHPEERING_CLOSE,
1649 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1650 mesh_peer_timeout_setup(ni);
1653 /* Duplicate open, confirm again. */
1654 args[0] = ni->ni_mlpid;
1655 args[1] = ni->ni_mllid;
1656 ieee80211_send_action(ni,
1657 IEEE80211_ACTION_CAT_MESHPEERING,
1658 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1661 case IEEE80211_NODE_MESH_OPENSNT:
1662 ni->ni_mllid = meshpeer->peer_llinkid;
1663 mesh_linkchange(ni, IEEE80211_NODE_MESH_OPENRCV);
1664 args[0] = ni->ni_mlpid;
1665 args[1] = ni->ni_mllid;
1666 ieee80211_send_action(ni,
1667 IEEE80211_ACTION_CAT_MESHPEERING,
1668 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1670 /* NB: don't setup/clear any timeout */
1672 case IEEE80211_NODE_MESH_CONFIRMRCV:
1673 if (ni->ni_mlpid != meshpeer->peer_linkid ||
1674 ni->ni_mllid != meshpeer->peer_llinkid) {
1675 args[0] = ni->ni_mlpid;
1676 args[1] = ni->ni_mllid;
1677 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1678 ieee80211_send_action(ni,
1679 IEEE80211_ACTION_CAT_MESHPEERING,
1680 IEEE80211_ACTION_MESHPEERING_CLOSE,
1683 IEEE80211_NODE_MESH_HOLDING);
1684 mesh_peer_timeout_setup(ni);
1687 mesh_linkchange(ni, IEEE80211_NODE_MESH_ESTABLISHED);
1688 ni->ni_mllid = meshpeer->peer_llinkid;
1689 args[0] = ni->ni_mlpid;
1690 args[1] = ni->ni_mllid;
1691 ieee80211_send_action(ni,
1692 IEEE80211_ACTION_CAT_MESHPEERING,
1693 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1695 mesh_peer_timeout_stop(ni);
1697 case IEEE80211_NODE_MESH_ESTABLISHED:
1698 if (ni->ni_mllid != meshpeer->peer_llinkid) {
1699 args[0] = ni->ni_mllid;
1700 args[1] = ni->ni_mlpid;
1701 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1702 ieee80211_send_action(ni,
1703 IEEE80211_ACTION_CAT_MESHPEERING,
1704 IEEE80211_ACTION_MESHPEERING_CLOSE,
1706 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1707 mesh_peer_timeout_setup(ni);
1710 args[0] = ni->ni_mlpid;
1711 args[1] = ni->ni_mllid;
1712 ieee80211_send_action(ni,
1713 IEEE80211_ACTION_CAT_MESHPEERING,
1714 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1717 case IEEE80211_NODE_MESH_HOLDING:
1718 args[0] = ni->ni_mlpid;
1719 args[1] = meshpeer->peer_llinkid;
1720 args[2] = IEEE80211_REASON_MESH_MAX_RETRIES;
1721 ieee80211_send_action(ni,
1722 IEEE80211_ACTION_CAT_MESHPEERING,
1723 IEEE80211_ACTION_MESHPEERING_CLOSE,
1731 mesh_recv_action_meshpeering_confirm(struct ieee80211_node *ni,
1732 const struct ieee80211_frame *wh,
1733 const uint8_t *frm, const uint8_t *efrm)
1735 struct ieee80211vap *vap = ni->ni_vap;
1736 struct ieee80211_meshpeer_ie ie;
1737 const struct ieee80211_meshpeer_ie *meshpeer;
1740 /* +2+2+2+2 for action + code + capabilites + status code + AID */
1741 meshpeer = mesh_parse_meshpeering_action(ni, wh, frm+2+2+2+2, efrm, &ie,
1742 IEEE80211_ACTION_MESHPEERING_CONFIRM);
1743 if (meshpeer == NULL) {
1747 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1748 "recv PEER CONFIRM, local id 0x%x, peer id 0x%x",
1749 meshpeer->peer_llinkid, meshpeer->peer_linkid);
1751 switch (ni->ni_mlstate) {
1752 case IEEE80211_NODE_MESH_OPENRCV:
1753 mesh_linkchange(ni, IEEE80211_NODE_MESH_ESTABLISHED);
1754 mesh_peer_timeout_stop(ni);
1756 case IEEE80211_NODE_MESH_OPENSNT:
1757 mesh_linkchange(ni, IEEE80211_NODE_MESH_CONFIRMRCV);
1759 case IEEE80211_NODE_MESH_HOLDING:
1760 args[0] = ni->ni_mlpid;
1761 args[1] = meshpeer->peer_llinkid;
1762 args[2] = IEEE80211_REASON_MESH_MAX_RETRIES;
1763 ieee80211_send_action(ni,
1764 IEEE80211_ACTION_CAT_MESHPEERING,
1765 IEEE80211_ACTION_MESHPEERING_CLOSE,
1768 case IEEE80211_NODE_MESH_CONFIRMRCV:
1769 if (ni->ni_mllid != meshpeer->peer_llinkid) {
1770 args[0] = ni->ni_mlpid;
1771 args[1] = ni->ni_mllid;
1772 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1773 ieee80211_send_action(ni,
1774 IEEE80211_ACTION_CAT_MESHPEERING,
1775 IEEE80211_ACTION_MESHPEERING_CLOSE,
1777 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1778 mesh_peer_timeout_setup(ni);
1782 IEEE80211_DISCARD(vap,
1783 IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH,
1784 wh, NULL, "received confirm in invalid state %d",
1786 vap->iv_stats.is_rx_mgtdiscard++;
1793 mesh_recv_action_meshpeering_close(struct ieee80211_node *ni,
1794 const struct ieee80211_frame *wh,
1795 const uint8_t *frm, const uint8_t *efrm)
1799 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH,
1800 ni, "%s", "recv PEER CLOSE");
1802 switch (ni->ni_mlstate) {
1803 case IEEE80211_NODE_MESH_IDLE:
1806 case IEEE80211_NODE_MESH_OPENRCV:
1807 case IEEE80211_NODE_MESH_OPENSNT:
1808 case IEEE80211_NODE_MESH_CONFIRMRCV:
1809 case IEEE80211_NODE_MESH_ESTABLISHED:
1810 args[0] = ni->ni_mlpid;
1811 args[1] = ni->ni_mllid;
1812 args[2] = IEEE80211_REASON_MESH_CLOSE_RCVD;
1813 ieee80211_send_action(ni,
1814 IEEE80211_ACTION_CAT_MESHPEERING,
1815 IEEE80211_ACTION_MESHPEERING_CLOSE,
1817 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1818 mesh_peer_timeout_setup(ni);
1820 case IEEE80211_NODE_MESH_HOLDING:
1821 mesh_linkchange(ni, IEEE80211_NODE_MESH_IDLE);
1822 mesh_peer_timeout_setup(ni);
1829 * Link Metric handling.
1832 mesh_recv_action_meshlmetric_req(struct ieee80211_node *ni,
1833 const struct ieee80211_frame *wh,
1834 const uint8_t *frm, const uint8_t *efrm)
1838 metric = mesh_airtime_calc(ni);
1839 ieee80211_send_action(ni,
1840 IEEE80211_ACTION_CAT_MESHLMETRIC,
1841 IEEE80211_ACTION_MESHLMETRIC_REP,
1847 mesh_recv_action_meshlmetric_rep(struct ieee80211_node *ni,
1848 const struct ieee80211_frame *wh,
1849 const uint8_t *frm, const uint8_t *efrm)
1855 mesh_send_action(struct ieee80211_node *ni, struct mbuf *m)
1857 struct ieee80211_bpf_params params;
1859 memset(¶ms, 0, sizeof(params));
1860 params.ibp_pri = WME_AC_VO;
1861 params.ibp_rate0 = ni->ni_txparms->mgmtrate;
1862 /* XXX ucast/mcast */
1863 params.ibp_try0 = ni->ni_txparms->maxretry;
1864 params.ibp_power = ni->ni_txpower;
1865 return ieee80211_mgmt_output(ni, m, IEEE80211_FC0_SUBTYPE_ACTION,
1869 #define ADDSHORT(frm, v) do { \
1870 frm[0] = (v) & 0xff; \
1871 frm[1] = (v) >> 8; \
1874 #define ADDWORD(frm, v) do { \
1875 frm[0] = (v) & 0xff; \
1876 frm[1] = ((v) >> 8) & 0xff; \
1877 frm[2] = ((v) >> 16) & 0xff; \
1878 frm[3] = ((v) >> 24) & 0xff; \
1883 mesh_send_action_meshpeering_open(struct ieee80211_node *ni,
1884 int category, int action, void *args0)
1886 struct ieee80211vap *vap = ni->ni_vap;
1887 struct ieee80211com *ic = ni->ni_ic;
1888 uint16_t *args = args0;
1889 const struct ieee80211_rateset *rs;
1893 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1894 "send PEER OPEN action: localid 0x%x", args[0]);
1896 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1897 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
1898 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
1899 ieee80211_ref_node(ni);
1901 m = ieee80211_getmgtframe(&frm,
1902 ic->ic_headroom + sizeof(struct ieee80211_frame),
1903 sizeof(uint16_t) /* action+category */
1904 + sizeof(uint16_t) /* capabilites */
1905 + 2 + IEEE80211_RATE_SIZE
1906 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
1907 + 2 + IEEE80211_MESHID_LEN
1908 + sizeof(struct ieee80211_meshconf_ie)
1909 + sizeof(struct ieee80211_meshpeer_ie)
1913 * mesh peer open action frame format:
1921 * [tlv] mesh peer link mgmt
1925 ADDSHORT(frm, ieee80211_getcapinfo(vap, ni->ni_chan));
1926 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
1927 frm = ieee80211_add_rates(frm, rs);
1928 frm = ieee80211_add_xrates(frm, rs);
1929 frm = ieee80211_add_meshid(frm, vap);
1930 frm = ieee80211_add_meshconf(frm, vap);
1931 frm = ieee80211_add_meshpeer(frm, IEEE80211_MESH_PEER_LINK_OPEN,
1933 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
1934 return mesh_send_action(ni, m);
1936 vap->iv_stats.is_tx_nobuf++;
1937 ieee80211_free_node(ni);
1943 mesh_send_action_meshpeering_confirm(struct ieee80211_node *ni,
1944 int category, int action, void *args0)
1946 struct ieee80211vap *vap = ni->ni_vap;
1947 struct ieee80211com *ic = ni->ni_ic;
1948 uint16_t *args = args0;
1949 const struct ieee80211_rateset *rs;
1953 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1954 "send PEER CONFIRM action: localid 0x%x, peerid 0x%x",
1957 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1958 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
1959 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
1960 ieee80211_ref_node(ni);
1962 m = ieee80211_getmgtframe(&frm,
1963 ic->ic_headroom + sizeof(struct ieee80211_frame),
1964 sizeof(uint16_t) /* action+category */
1965 + sizeof(uint16_t) /* capabilites */
1966 + sizeof(uint16_t) /* status code */
1967 + sizeof(uint16_t) /* AID */
1968 + 2 + IEEE80211_RATE_SIZE
1969 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
1970 + 2 + IEEE80211_MESHID_LEN
1971 + sizeof(struct ieee80211_meshconf_ie)
1972 + sizeof(struct ieee80211_meshpeer_ie)
1976 * mesh peer confirm action frame format:
1981 * [2] association id (peer ID)
1986 * [tlv] mesh peer link mgmt
1990 ADDSHORT(frm, ieee80211_getcapinfo(vap, ni->ni_chan));
1991 ADDSHORT(frm, 0); /* status code */
1992 ADDSHORT(frm, args[1]); /* AID */
1993 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
1994 frm = ieee80211_add_rates(frm, rs);
1995 frm = ieee80211_add_xrates(frm, rs);
1996 frm = ieee80211_add_meshid(frm, vap);
1997 frm = ieee80211_add_meshconf(frm, vap);
1998 frm = ieee80211_add_meshpeer(frm,
1999 IEEE80211_MESH_PEER_LINK_CONFIRM,
2000 args[0], args[1], 0);
2001 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2002 return mesh_send_action(ni, m);
2004 vap->iv_stats.is_tx_nobuf++;
2005 ieee80211_free_node(ni);
2011 mesh_send_action_meshpeering_close(struct ieee80211_node *ni,
2012 int category, int action, void *args0)
2014 struct ieee80211vap *vap = ni->ni_vap;
2015 struct ieee80211com *ic = ni->ni_ic;
2016 uint16_t *args = args0;
2020 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
2021 "send PEER CLOSE action: localid 0x%x, peerid 0x%x reason %d",
2022 args[0], args[1], args[2]);
2024 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2025 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
2026 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
2027 ieee80211_ref_node(ni);
2029 m = ieee80211_getmgtframe(&frm,
2030 ic->ic_headroom + sizeof(struct ieee80211_frame),
2031 sizeof(uint16_t) /* action+category */
2032 + sizeof(uint16_t) /* reason code */
2033 + 2 + IEEE80211_MESHID_LEN
2034 + sizeof(struct ieee80211_meshpeer_ie)
2038 * mesh peer close action frame format:
2043 * [tlv] mesh peer link mgmt
2047 ADDSHORT(frm, args[2]); /* reason code */
2048 frm = ieee80211_add_meshid(frm, vap);
2049 frm = ieee80211_add_meshpeer(frm,
2050 IEEE80211_MESH_PEER_LINK_CLOSE,
2051 args[0], args[1], args[2]);
2052 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2053 return mesh_send_action(ni, m);
2055 vap->iv_stats.is_tx_nobuf++;
2056 ieee80211_free_node(ni);
2062 mesh_send_action_meshlink_request(struct ieee80211_node *ni,
2063 int category, int action, void *arg0)
2065 struct ieee80211vap *vap = ni->ni_vap;
2066 struct ieee80211com *ic = ni->ni_ic;
2070 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
2071 "%s", "send LINK METRIC REQUEST action");
2073 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2074 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
2075 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
2076 ieee80211_ref_node(ni);
2078 m = ieee80211_getmgtframe(&frm,
2079 ic->ic_headroom + sizeof(struct ieee80211_frame),
2080 sizeof(uint16_t) /* action+category */
2084 * mesh link metric request
2090 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2091 return mesh_send_action(ni, m);
2093 vap->iv_stats.is_tx_nobuf++;
2094 ieee80211_free_node(ni);
2100 mesh_send_action_meshlink_reply(struct ieee80211_node *ni,
2101 int category, int action, void *args0)
2103 struct ieee80211vap *vap = ni->ni_vap;
2104 struct ieee80211com *ic = ni->ni_ic;
2105 uint32_t *metric = args0;
2109 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
2110 "send LINK METRIC REPLY action: metric 0x%x", *metric);
2112 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2113 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
2114 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
2115 ieee80211_ref_node(ni);
2117 m = ieee80211_getmgtframe(&frm,
2118 ic->ic_headroom + sizeof(struct ieee80211_frame),
2119 sizeof(uint16_t) /* action+category */
2120 + sizeof(struct ieee80211_meshlmetric_ie)
2124 * mesh link metric reply
2127 * [tlv] mesh link metric
2131 frm = ieee80211_add_meshlmetric(frm, *metric);
2132 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2133 return mesh_send_action(ni, m);
2135 vap->iv_stats.is_tx_nobuf++;
2136 ieee80211_free_node(ni);
2142 mesh_peer_timeout_setup(struct ieee80211_node *ni)
2144 switch (ni->ni_mlstate) {
2145 case IEEE80211_NODE_MESH_HOLDING:
2146 ni->ni_mltval = ieee80211_mesh_holdingtimeout;
2148 case IEEE80211_NODE_MESH_CONFIRMRCV:
2149 ni->ni_mltval = ieee80211_mesh_confirmtimeout;
2151 case IEEE80211_NODE_MESH_IDLE:
2155 ni->ni_mltval = ieee80211_mesh_retrytimeout;
2158 if (ni->ni_mltval) {
2159 callout_reset(&ni->ni_mltimer, ni->ni_mltval,
2160 mesh_peer_timeout_callout, ni);
2165 * Same as above but backoffs timer statisically 50%.
2168 mesh_peer_timeout_backoff(struct ieee80211_node *ni)
2173 ni->ni_mltval += r % ni->ni_mltval;
2174 callout_reset(&ni->ni_mltimer, ni->ni_mltval,
2175 mesh_peer_timeout_callout, ni);
2178 static __inline void
2179 mesh_peer_timeout_stop(struct ieee80211_node *ni)
2181 callout_stop(&ni->ni_mltimer);
2185 * Mesh Peer Link Management FSM timeout handling.
2188 mesh_peer_timeout_callout(void *arg)
2190 struct ieee80211_node *ni = (struct ieee80211_node *)arg;
2193 wlan_serialize_enter();
2194 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_MESH,
2195 ni, "mesh link timeout, state %d, retry counter %d",
2196 ni->ni_mlstate, ni->ni_mlrcnt);
2198 switch (ni->ni_mlstate) {
2199 case IEEE80211_NODE_MESH_IDLE:
2200 case IEEE80211_NODE_MESH_ESTABLISHED:
2202 case IEEE80211_NODE_MESH_OPENSNT:
2203 case IEEE80211_NODE_MESH_OPENRCV:
2204 if (ni->ni_mlrcnt == ieee80211_mesh_maxretries) {
2205 args[0] = ni->ni_mlpid;
2206 args[2] = IEEE80211_REASON_MESH_MAX_RETRIES;
2207 ieee80211_send_action(ni,
2208 IEEE80211_ACTION_CAT_MESHPEERING,
2209 IEEE80211_ACTION_MESHPEERING_CLOSE, args);
2211 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
2212 mesh_peer_timeout_setup(ni);
2214 args[0] = ni->ni_mlpid;
2215 ieee80211_send_action(ni,
2216 IEEE80211_ACTION_CAT_MESHPEERING,
2217 IEEE80211_ACTION_MESHPEERING_OPEN, args);
2219 mesh_peer_timeout_backoff(ni);
2222 case IEEE80211_NODE_MESH_CONFIRMRCV:
2223 if (ni->ni_mlrcnt == ieee80211_mesh_maxretries) {
2224 args[0] = ni->ni_mlpid;
2225 args[2] = IEEE80211_REASON_MESH_CONFIRM_TIMEOUT;
2226 ieee80211_send_action(ni,
2227 IEEE80211_ACTION_CAT_MESHPEERING,
2228 IEEE80211_ACTION_MESHPEERING_CLOSE, args);
2230 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
2231 mesh_peer_timeout_setup(ni);
2234 mesh_peer_timeout_setup(ni);
2237 case IEEE80211_NODE_MESH_HOLDING:
2238 mesh_linkchange(ni, IEEE80211_NODE_MESH_IDLE);
2241 wlan_serialize_exit();
2245 mesh_verify_meshid(struct ieee80211vap *vap, const uint8_t *ie)
2247 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2249 if (ie == NULL || ie[1] != ms->ms_idlen)
2251 return memcmp(ms->ms_id, ie + 2, ms->ms_idlen);
2255 * Check if we are using the same algorithms for this mesh.
2258 mesh_verify_meshconf(struct ieee80211vap *vap, const uint8_t *ie)
2260 const struct ieee80211_meshconf_ie *meshconf =
2261 (const struct ieee80211_meshconf_ie *) ie;
2262 const struct ieee80211_mesh_state *ms = vap->iv_mesh;
2265 if (meshconf == NULL)
2267 if (meshconf->conf_pselid != ms->ms_ppath->mpp_ie) {
2268 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2269 "unknown path selection algorithm: 0x%x\n",
2270 meshconf->conf_pselid);
2273 if (meshconf->conf_pmetid != ms->ms_pmetric->mpm_ie) {
2274 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2275 "unknown path metric algorithm: 0x%x\n",
2276 meshconf->conf_pmetid);
2279 if (meshconf->conf_ccid != 0) {
2280 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2281 "unknown congestion control algorithm: 0x%x\n",
2282 meshconf->conf_ccid);
2285 if (meshconf->conf_syncid != IEEE80211_MESHCONF_SYNC_NEIGHOFF) {
2286 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2287 "unknown sync algorithm: 0x%x\n",
2288 meshconf->conf_syncid);
2291 if (meshconf->conf_authid != 0) {
2292 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2293 "unknown auth auth algorithm: 0x%x\n",
2294 meshconf->conf_pselid);
2297 /* NB: conf_cap is only read correctly here */
2298 cap = LE_READ_2(&meshconf->conf_cap);
2299 /* Not accepting peers */
2300 if (!(cap & IEEE80211_MESHCONF_CAP_AP)) {
2301 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2302 "not accepting peers: 0x%x\n", meshconf->conf_cap);
2309 mesh_verify_meshpeer(struct ieee80211vap *vap, uint8_t subtype,
2312 const struct ieee80211_meshpeer_ie *meshpeer =
2313 (const struct ieee80211_meshpeer_ie *) ie;
2315 if (meshpeer == NULL || meshpeer->peer_len < 6 ||
2316 meshpeer->peer_len > 10)
2319 case IEEE80211_MESH_PEER_LINK_OPEN:
2320 if (meshpeer->peer_len != 6)
2323 case IEEE80211_MESH_PEER_LINK_CONFIRM:
2324 if (meshpeer->peer_len != 8)
2327 case IEEE80211_MESH_PEER_LINK_CLOSE:
2328 if (meshpeer->peer_len < 8)
2330 if (meshpeer->peer_len == 8 && meshpeer->peer_linkid != 0)
2332 if (meshpeer->peer_rcode == 0)
2340 * Add a Mesh ID IE to a frame.
2343 ieee80211_add_meshid(uint8_t *frm, struct ieee80211vap *vap)
2345 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2347 KASSERT(vap->iv_opmode == IEEE80211_M_MBSS, ("not a mbss vap"));
2349 *frm++ = IEEE80211_ELEMID_MESHID;
2350 *frm++ = ms->ms_idlen;
2351 memcpy(frm, ms->ms_id, ms->ms_idlen);
2352 return frm + ms->ms_idlen;
2356 * Add a Mesh Configuration IE to a frame.
2357 * For now just use HWMP routing, Airtime link metric, Null Congestion
2358 * Signaling, Null Sync Protocol and Null Authentication.
2361 ieee80211_add_meshconf(uint8_t *frm, struct ieee80211vap *vap)
2363 const struct ieee80211_mesh_state *ms = vap->iv_mesh;
2366 KASSERT(vap->iv_opmode == IEEE80211_M_MBSS, ("not a MBSS vap"));
2368 *frm++ = IEEE80211_ELEMID_MESHCONF;
2369 *frm++ = sizeof(struct ieee80211_meshconf_ie) - 2;
2370 *frm++ = ms->ms_ppath->mpp_ie; /* path selection */
2371 *frm++ = ms->ms_pmetric->mpm_ie; /* link metric */
2372 *frm++ = IEEE80211_MESHCONF_CC_DISABLED;
2373 *frm++ = IEEE80211_MESHCONF_SYNC_NEIGHOFF;
2374 *frm++ = IEEE80211_MESHCONF_AUTH_DISABLED;
2375 /* NB: set the number of neighbors before the rest */
2376 *frm = (ms->ms_neighbors > 15 ? 15 : ms->ms_neighbors) << 1;
2377 if (ms->ms_flags & IEEE80211_MESHFLAGS_PORTAL)
2378 *frm |= IEEE80211_MESHCONF_FORM_MP;
2381 if (ms->ms_flags & IEEE80211_MESHFLAGS_AP)
2382 caps |= IEEE80211_MESHCONF_CAP_AP;
2383 if (ms->ms_flags & IEEE80211_MESHFLAGS_FWD)
2384 caps |= IEEE80211_MESHCONF_CAP_FWRD;
2385 ADDSHORT(frm, caps);
2390 * Add a Mesh Peer Management IE to a frame.
2393 ieee80211_add_meshpeer(uint8_t *frm, uint8_t subtype, uint16_t localid,
2394 uint16_t peerid, uint16_t reason)
2396 /* XXX change for AH */
2397 static const uint8_t meshpeerproto[4] = IEEE80211_MESH_PEER_PROTO;
2399 KASSERT(localid != 0, ("localid == 0"));
2401 *frm++ = IEEE80211_ELEMID_MESHPEER;
2403 case IEEE80211_MESH_PEER_LINK_OPEN:
2404 *frm++ = 6; /* length */
2405 memcpy(frm, meshpeerproto, 4);
2407 ADDSHORT(frm, localid); /* local ID */
2409 case IEEE80211_MESH_PEER_LINK_CONFIRM:
2410 KASSERT(peerid != 0, ("sending peer confirm without peer id"));
2411 *frm++ = 8; /* length */
2412 memcpy(frm, meshpeerproto, 4);
2414 ADDSHORT(frm, localid); /* local ID */
2415 ADDSHORT(frm, peerid); /* peer ID */
2417 case IEEE80211_MESH_PEER_LINK_CLOSE:
2419 *frm++ = 10; /* length */
2421 *frm++ = 8; /* length */
2422 memcpy(frm, meshpeerproto, 4);
2424 ADDSHORT(frm, localid); /* local ID */
2426 ADDSHORT(frm, peerid); /* peer ID */
2427 ADDSHORT(frm, reason);
2434 * Compute an Airtime Link Metric for the link with this node.
2436 * Based on Draft 3.0 spec (11B.10, p.149).
2439 * Max 802.11s overhead.
2441 #define IEEE80211_MESH_MAXOVERHEAD \
2442 (sizeof(struct ieee80211_qosframe_addr4) \
2443 + sizeof(struct ieee80211_meshcntl_ae11) \
2444 + sizeof(struct llc) \
2445 + IEEE80211_ADDR_LEN \
2446 + IEEE80211_WEP_IVLEN \
2447 + IEEE80211_WEP_KIDLEN \
2448 + IEEE80211_WEP_CRCLEN \
2449 + IEEE80211_WEP_MICLEN \
2450 + IEEE80211_CRC_LEN)
2452 mesh_airtime_calc(struct ieee80211_node *ni)
2455 #define S_FACTOR (2 * M_BITS)
2456 struct ieee80211com *ic = ni->ni_ic;
2457 struct ifnet *ifp = ni->ni_vap->iv_ifp;
2458 const static int nbits = 8192 << M_BITS;
2459 uint32_t overhead, rate, errrate;
2462 /* Time to transmit a frame */
2463 rate = ni->ni_txrate;
2464 overhead = ieee80211_compute_duration(ic->ic_rt,
2465 ifp->if_mtu + IEEE80211_MESH_MAXOVERHEAD, rate, 0) << M_BITS;
2466 /* Error rate in percentage */
2467 /* XXX assuming small failures are ok */
2468 errrate = (((ifp->if_oerrors +
2469 ifp->if_ierrors) / 100) << M_BITS) / 100;
2470 res = (overhead + (nbits / rate)) *
2471 ((1 << S_FACTOR) / ((1 << M_BITS) - errrate));
2473 return (uint32_t)(res >> S_FACTOR);
2479 * Add a Mesh Link Metric report IE to a frame.
2482 ieee80211_add_meshlmetric(uint8_t *frm, uint32_t metric)
2484 *frm++ = IEEE80211_ELEMID_MESHLINK;
2486 ADDWORD(frm, metric);
2493 * Initialize any mesh-specific node state.
2496 ieee80211_mesh_node_init(struct ieee80211vap *vap, struct ieee80211_node *ni)
2498 ni->ni_flags |= IEEE80211_NODE_QOS;
2499 callout_init_mp(&ni->ni_mltimer);
2503 * Cleanup any mesh-specific node state.
2506 ieee80211_mesh_node_cleanup(struct ieee80211_node *ni)
2508 struct ieee80211vap *vap = ni->ni_vap;
2509 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2511 callout_stop(&ni->ni_mltimer);
2512 /* NB: short-circuit callbacks after mesh_vdetach */
2513 if (vap->iv_mesh != NULL)
2514 ms->ms_ppath->mpp_peerdown(ni);
2518 ieee80211_parse_meshid(struct ieee80211_node *ni, const uint8_t *ie)
2520 ni->ni_meshidlen = ie[1];
2521 memcpy(ni->ni_meshid, ie + 2, ie[1]);
2525 * Setup mesh-specific node state on neighbor discovery.
2528 ieee80211_mesh_init_neighbor(struct ieee80211_node *ni,
2529 const struct ieee80211_frame *wh,
2530 const struct ieee80211_scanparams *sp)
2532 ieee80211_parse_meshid(ni, sp->meshid);
2536 ieee80211_mesh_update_beacon(struct ieee80211vap *vap,
2537 struct ieee80211_beacon_offsets *bo)
2539 KASSERT(vap->iv_opmode == IEEE80211_M_MBSS, ("not a MBSS vap"));
2541 if (isset(bo->bo_flags, IEEE80211_BEACON_MESHCONF)) {
2542 (void)ieee80211_add_meshconf(bo->bo_meshconf, vap);
2543 clrbit(bo->bo_flags, IEEE80211_BEACON_MESHCONF);
2548 mesh_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
2550 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2551 uint8_t tmpmeshid[IEEE80211_NWID_LEN];
2552 struct ieee80211_mesh_route *rt;
2553 struct ieee80211req_mesh_route *imr;
2558 if (vap->iv_opmode != IEEE80211_M_MBSS)
2562 switch (ireq->i_type) {
2563 case IEEE80211_IOC_MESH_ID:
2564 ireq->i_len = ms->ms_idlen;
2565 memcpy(tmpmeshid, ms->ms_id, ireq->i_len);
2566 error = copyout(tmpmeshid, ireq->i_data, ireq->i_len);
2568 case IEEE80211_IOC_MESH_AP:
2569 ireq->i_val = (ms->ms_flags & IEEE80211_MESHFLAGS_AP) != 0;
2571 case IEEE80211_IOC_MESH_FWRD:
2572 ireq->i_val = (ms->ms_flags & IEEE80211_MESHFLAGS_FWD) != 0;
2574 case IEEE80211_IOC_MESH_TTL:
2575 ireq->i_val = ms->ms_ttl;
2577 case IEEE80211_IOC_MESH_RTCMD:
2578 switch (ireq->i_val) {
2579 case IEEE80211_MESH_RTCMD_LIST:
2581 TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) {
2582 len += sizeof(*imr);
2584 if (len > ireq->i_len || ireq->i_len < sizeof(*imr)) {
2590 p = kmalloc(len, M_TEMP, M_INTWAIT | M_ZERO);
2594 TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) {
2597 imr = (struct ieee80211req_mesh_route *)
2599 imr->imr_flags = rt->rt_flags;
2600 IEEE80211_ADDR_COPY(imr->imr_dest,
2602 IEEE80211_ADDR_COPY(imr->imr_nexthop,
2604 imr->imr_metric = rt->rt_metric;
2605 imr->imr_nhops = rt->rt_nhops;
2606 imr->imr_lifetime = rt->rt_lifetime;
2607 imr->imr_lastmseq = rt->rt_lastmseq;
2608 off += sizeof(*imr);
2610 error = copyout(p, (uint8_t *)ireq->i_data,
2614 case IEEE80211_MESH_RTCMD_FLUSH:
2615 case IEEE80211_MESH_RTCMD_ADD:
2616 case IEEE80211_MESH_RTCMD_DELETE:
2622 case IEEE80211_IOC_MESH_PR_METRIC:
2623 len = strlen(ms->ms_pmetric->mpm_descr);
2624 if (ireq->i_len < len)
2627 error = copyout(ms->ms_pmetric->mpm_descr,
2628 (uint8_t *)ireq->i_data, len);
2630 case IEEE80211_IOC_MESH_PR_PATH:
2631 len = strlen(ms->ms_ppath->mpp_descr);
2632 if (ireq->i_len < len)
2635 error = copyout(ms->ms_ppath->mpp_descr,
2636 (uint8_t *)ireq->i_data, len);
2644 IEEE80211_IOCTL_GET(mesh, mesh_ioctl_get80211);
2647 mesh_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
2649 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2650 uint8_t tmpmeshid[IEEE80211_NWID_LEN];
2651 uint8_t tmpaddr[IEEE80211_ADDR_LEN];
2652 char tmpproto[IEEE80211_MESH_PROTO_DSZ];
2655 if (vap->iv_opmode != IEEE80211_M_MBSS)
2659 switch (ireq->i_type) {
2660 case IEEE80211_IOC_MESH_ID:
2661 if (ireq->i_val != 0 || ireq->i_len > IEEE80211_MESHID_LEN)
2663 error = copyin(ireq->i_data, tmpmeshid, ireq->i_len);
2666 memset(ms->ms_id, 0, IEEE80211_NWID_LEN);
2667 ms->ms_idlen = ireq->i_len;
2668 memcpy(ms->ms_id, tmpmeshid, ireq->i_len);
2671 case IEEE80211_IOC_MESH_AP:
2673 ms->ms_flags |= IEEE80211_MESHFLAGS_AP;
2675 ms->ms_flags &= ~IEEE80211_MESHFLAGS_AP;
2678 case IEEE80211_IOC_MESH_FWRD:
2680 ms->ms_flags |= IEEE80211_MESHFLAGS_FWD;
2682 ms->ms_flags &= ~IEEE80211_MESHFLAGS_FWD;
2684 case IEEE80211_IOC_MESH_TTL:
2685 ms->ms_ttl = (uint8_t) ireq->i_val;
2687 case IEEE80211_IOC_MESH_RTCMD:
2688 switch (ireq->i_val) {
2689 case IEEE80211_MESH_RTCMD_LIST:
2691 case IEEE80211_MESH_RTCMD_FLUSH:
2692 ieee80211_mesh_rt_flush(vap);
2694 case IEEE80211_MESH_RTCMD_ADD:
2695 if (IEEE80211_ADDR_EQ(vap->iv_myaddr, ireq->i_data) ||
2696 IEEE80211_ADDR_EQ(broadcastaddr, ireq->i_data))
2698 error = copyin(ireq->i_data, &tmpaddr,
2699 IEEE80211_ADDR_LEN);
2701 ieee80211_mesh_discover(vap, tmpaddr, NULL);
2703 case IEEE80211_MESH_RTCMD_DELETE:
2704 ieee80211_mesh_rt_del(vap, ireq->i_data);
2710 case IEEE80211_IOC_MESH_PR_METRIC:
2711 error = copyin(ireq->i_data, tmpproto, sizeof(tmpproto));
2713 error = mesh_select_proto_metric(vap, tmpproto);
2718 case IEEE80211_IOC_MESH_PR_PATH:
2719 error = copyin(ireq->i_data, tmpproto, sizeof(tmpproto));
2721 error = mesh_select_proto_path(vap, tmpproto);
2731 IEEE80211_IOCTL_SET(mesh, mesh_ioctl_set80211);