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 !(llc->llc_snap.ether_type == htons(ETHERTYPE_IPX))) {
931 m_adj(m, hdrlen + sizeof(struct llc) - sizeof(*eh));
934 m_adj(m, hdrlen - sizeof(*eh));
936 eh = mtod(m, struct ether_header *);
937 ae = mc->mc_flags & 3;
938 if (WHDIR(wh) == IEEE80211_FC1_DIR_FROMDS) {
939 IEEE80211_ADDR_COPY(eh->ether_dhost, wh->i_addr1);
941 IEEE80211_ADDR_COPY(eh->ether_shost, wh->i_addr3);
942 } else if (ae == 1) {
943 IEEE80211_ADDR_COPY(eh->ether_shost, mc->mc_addr4);
945 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
946 (const struct ieee80211_frame *)wh, NULL,
948 vap->iv_stats.is_mesh_badae++;
954 IEEE80211_ADDR_COPY(eh->ether_dhost, wh->i_addr3);
955 IEEE80211_ADDR_COPY(eh->ether_shost, wh->i_addr4);
956 } else if (ae == 2) {
957 IEEE80211_ADDR_COPY(eh->ether_dhost, mc->mc_addr4);
958 IEEE80211_ADDR_COPY(eh->ether_shost, mc->mc_addr5);
960 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
961 (const struct ieee80211_frame *)wh, NULL,
963 vap->iv_stats.is_mesh_badae++;
968 #ifdef ALIGNED_POINTER
969 if (!ALIGNED_POINTER(mtod(m, caddr_t) + sizeof(*eh), uint32_t)) {
970 m = ieee80211_realign(vap, m, sizeof(*eh));
974 #endif /* ALIGNED_POINTER */
976 eh = mtod(m, struct ether_header *);
977 eh->ether_type = htons(m->m_pkthdr.len - sizeof(*eh));
984 * Return non-zero if the unicast mesh data frame should be processed
985 * locally. Frames that are not proxy'd have our address, otherwise
986 * we need to consult the routing table to look for a proxy entry.
989 mesh_isucastforme(struct ieee80211vap *vap, const struct ieee80211_frame *wh,
990 const struct ieee80211_meshcntl *mc)
992 int ae = mc->mc_flags & 3;
994 KASSERT((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS,
995 ("bad dir 0x%x:0x%x", wh->i_fc[0], wh->i_fc[1]));
996 KASSERT(ae == 0 || ae == 2, ("bad AE %d", ae));
997 if (ae == 2) { /* ucast w/ proxy */
998 const struct ieee80211_meshcntl_ae10 *mc10 =
999 (const struct ieee80211_meshcntl_ae10 *) mc;
1000 struct ieee80211_mesh_route *rt =
1001 ieee80211_mesh_rt_find(vap, mc10->mc_addr4);
1002 /* check for proxy route to ourself */
1003 return (rt != NULL &&
1004 (rt->rt_flags & IEEE80211_MESHRT_FLAGS_PROXY));
1005 } else /* ucast w/o proxy */
1006 return IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_myaddr);
1010 mesh_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf)
1012 #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
1013 #define HAS_SEQ(type) ((type & 0x4) == 0)
1014 struct ieee80211vap *vap = ni->ni_vap;
1015 struct ieee80211com *ic = ni->ni_ic;
1016 struct ifnet *ifp = vap->iv_ifp;
1017 struct ieee80211_frame *wh;
1018 const struct ieee80211_meshcntl *mc;
1019 int hdrspace, meshdrlen, need_tap;
1020 uint8_t dir, type, subtype, qos;
1023 ieee80211_seq rxseq;
1025 KASSERT(ni != NULL, ("null node"));
1026 ni->ni_inact = ni->ni_inact_reload;
1028 need_tap = 1; /* mbuf need to be tapped. */
1029 type = -1; /* undefined */
1031 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) {
1032 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1033 ni->ni_macaddr, NULL,
1034 "too short (1): len %u", m->m_pkthdr.len);
1035 vap->iv_stats.is_rx_tooshort++;
1039 * Bit of a cheat here, we use a pointer for a 3-address
1040 * frame format but don't reference fields past outside
1041 * ieee80211_frame_min w/o first validating the data is
1044 wh = mtod(m, struct ieee80211_frame *);
1046 if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
1047 IEEE80211_FC0_VERSION_0) {
1048 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1049 ni->ni_macaddr, NULL, "wrong version %x", wh->i_fc[0]);
1050 vap->iv_stats.is_rx_badversion++;
1053 dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
1054 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
1055 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
1056 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
1057 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
1059 if (HAS_SEQ(type)) {
1060 uint8_t tid = ieee80211_gettid(wh);
1062 if (IEEE80211_QOS_HAS_SEQ(wh) &&
1063 TID_TO_WME_AC(tid) >= WME_AC_VI)
1064 ic->ic_wme.wme_hipri_traffic++;
1065 rxseq = le16toh(*(uint16_t *)wh->i_seq);
1066 if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
1067 (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
1068 SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
1069 /* duplicate, discard */
1070 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
1071 wh->i_addr1, "duplicate",
1072 "seqno <%u,%u> fragno <%u,%u> tid %u",
1073 rxseq >> IEEE80211_SEQ_SEQ_SHIFT,
1074 ni->ni_rxseqs[tid] >>
1075 IEEE80211_SEQ_SEQ_SHIFT,
1076 rxseq & IEEE80211_SEQ_FRAG_MASK,
1077 ni->ni_rxseqs[tid] &
1078 IEEE80211_SEQ_FRAG_MASK,
1080 vap->iv_stats.is_rx_dup++;
1081 IEEE80211_NODE_STAT(ni, rx_dup);
1084 ni->ni_rxseqs[tid] = rxseq;
1087 #ifdef IEEE80211_DEBUG
1089 * It's easier, but too expensive, to simulate different mesh
1090 * topologies by consulting the ACL policy very early, so do this
1093 * NB: this check is also done upon peering link initiation.
1095 if (vap->iv_acl != NULL && !vap->iv_acl->iac_check(vap, wh->i_addr2)) {
1096 IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL,
1097 wh, NULL, "%s", "disallowed by ACL");
1098 vap->iv_stats.is_rx_acl++;
1103 case IEEE80211_FC0_TYPE_DATA:
1104 if (ni == vap->iv_bss)
1106 if (ni->ni_mlstate != IEEE80211_NODE_MESH_ESTABLISHED) {
1107 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_MESH,
1108 ni->ni_macaddr, NULL,
1109 "peer link not yet established (%d)",
1111 vap->iv_stats.is_mesh_nolink++;
1114 if (dir != IEEE80211_FC1_DIR_FROMDS &&
1115 dir != IEEE80211_FC1_DIR_DSTODS) {
1116 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1117 wh, "data", "incorrect dir 0x%x", dir);
1118 vap->iv_stats.is_rx_wrongdir++;
1121 /* pull up enough to get to the mesh control */
1122 hdrspace = ieee80211_hdrspace(ic, wh);
1123 if (m->m_len < hdrspace + sizeof(struct ieee80211_meshcntl) &&
1124 (m = m_pullup(m, hdrspace +
1125 sizeof(struct ieee80211_meshcntl))) == NULL) {
1126 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1127 ni->ni_macaddr, NULL,
1128 "data too short: expecting %u", hdrspace);
1129 vap->iv_stats.is_rx_tooshort++;
1133 * Now calculate the full extent of the headers. Note
1134 * mesh_decap will pull up anything we didn't get
1135 * above when it strips the 802.11 headers.
1137 mc = (const struct ieee80211_meshcntl *)
1138 (mtod(m, const uint8_t *) + hdrspace);
1139 meshdrlen = sizeof(struct ieee80211_meshcntl) +
1140 (mc->mc_flags & 3) * IEEE80211_ADDR_LEN;
1141 hdrspace += meshdrlen;
1142 seq = LE_READ_4(mc->mc_seq);
1143 if (IEEE80211_IS_MULTICAST(wh->i_addr1))
1146 addr = ((struct ieee80211_qosframe_addr4 *)wh)->i_addr4;
1147 if (IEEE80211_ADDR_EQ(vap->iv_myaddr, addr)) {
1148 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
1149 addr, "data", "%s", "not to me");
1150 vap->iv_stats.is_rx_wrongbss++; /* XXX kinda */
1153 if (mesh_checkpseq(vap, addr, seq) != 0) {
1154 vap->iv_stats.is_rx_dup++;
1159 * Potentially forward packet. See table s36 (p140)
1160 * for the rules. XXX tap fwd'd packets not for us?
1162 if (dir == IEEE80211_FC1_DIR_FROMDS ||
1163 !mesh_isucastforme(vap, wh, mc)) {
1164 mesh_forward(vap, m, mc);
1165 if (dir == IEEE80211_FC1_DIR_DSTODS)
1167 /* NB: fall thru to deliver mcast frames locally */
1171 * Save QoS bits for use below--before we strip the header.
1173 if (subtype == IEEE80211_FC0_SUBTYPE_QOS) {
1174 qos = (dir == IEEE80211_FC1_DIR_DSTODS) ?
1175 ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0] :
1176 ((struct ieee80211_qosframe *)wh)->i_qos[0];
1180 * Next up, any fragmentation.
1182 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1183 m = ieee80211_defrag(ni, m, hdrspace);
1185 /* Fragment dropped or frame not complete yet */
1189 wh = NULL; /* no longer valid, catch any uses */
1191 if (ieee80211_radiotap_active_vap(vap))
1192 ieee80211_radiotap_rx(vap, m);
1196 * Finally, strip the 802.11 header.
1198 m = mesh_decap(vap, m, hdrspace, meshdrlen);
1200 /* XXX mask bit to check for both */
1201 /* don't count Null data frames as errors */
1202 if (subtype == IEEE80211_FC0_SUBTYPE_NODATA ||
1203 subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL)
1205 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
1206 ni->ni_macaddr, "data", "%s", "decap error");
1207 vap->iv_stats.is_rx_decap++;
1208 IEEE80211_NODE_STAT(ni, rx_decap);
1211 if (qos & IEEE80211_QOS_AMSDU) {
1212 m = ieee80211_decap_amsdu(ni, m);
1214 return IEEE80211_FC0_TYPE_DATA;
1216 ieee80211_deliver_data(vap, ni, m);
1218 case IEEE80211_FC0_TYPE_MGT:
1219 vap->iv_stats.is_rx_mgmt++;
1220 IEEE80211_NODE_STAT(ni, rx_mgmt);
1221 if (dir != IEEE80211_FC1_DIR_NODS) {
1222 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1223 wh, "mgt", "incorrect dir 0x%x", dir);
1224 vap->iv_stats.is_rx_wrongdir++;
1227 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
1228 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
1229 ni->ni_macaddr, "mgt", "too short: len %u",
1231 vap->iv_stats.is_rx_tooshort++;
1234 #ifdef IEEE80211_DEBUG
1235 if ((ieee80211_msg_debug(vap) &&
1236 (vap->iv_ic->ic_flags & IEEE80211_F_SCAN)) ||
1237 ieee80211_msg_dumppkts(vap)) {
1238 if_printf(ifp, "received %s from %6D rssi %d\n",
1239 ieee80211_mgt_subtype_name[subtype >>
1240 IEEE80211_FC0_SUBTYPE_SHIFT],
1241 wh->i_addr2, ":", rssi);
1244 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
1245 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1246 wh, NULL, "%s", "WEP set but not permitted");
1247 vap->iv_stats.is_rx_mgtdiscard++; /* XXX */
1250 vap->iv_recv_mgmt(ni, m, subtype, rssi, nf);
1252 case IEEE80211_FC0_TYPE_CTL:
1253 vap->iv_stats.is_rx_ctl++;
1254 IEEE80211_NODE_STAT(ni, rx_ctrl);
1257 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1258 wh, "bad", "frame type 0x%x", type);
1259 /* should not come here */
1266 if (need_tap && ieee80211_radiotap_active_vap(vap))
1267 ieee80211_radiotap_rx(vap, m);
1274 mesh_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, int subtype,
1277 struct ieee80211vap *vap = ni->ni_vap;
1278 struct ieee80211_mesh_state *ms = vap->iv_mesh;
1279 struct ieee80211com *ic = ni->ni_ic;
1280 struct ieee80211_frame *wh;
1281 uint8_t *frm, *efrm;
1283 wh = mtod(m0, struct ieee80211_frame *);
1284 frm = (uint8_t *)&wh[1];
1285 efrm = mtod(m0, uint8_t *) + m0->m_len;
1287 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
1288 case IEEE80211_FC0_SUBTYPE_BEACON:
1290 struct ieee80211_scanparams scan;
1292 * We process beacon/probe response
1293 * frames to discover neighbors.
1295 if (ieee80211_parse_beacon(ni, m0, &scan) != 0)
1298 * Count frame now that we know it's to be processed.
1300 if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) {
1301 vap->iv_stats.is_rx_beacon++; /* XXX remove */
1302 IEEE80211_NODE_STAT(ni, rx_beacons);
1304 IEEE80211_NODE_STAT(ni, rx_proberesp);
1306 * If scanning, just pass information to the scan module.
1308 if (ic->ic_flags & IEEE80211_F_SCAN) {
1309 if (ic->ic_flags_ext & IEEE80211_FEXT_PROBECHAN) {
1311 * Actively scanning a channel marked passive;
1312 * send a probe request now that we know there
1313 * is 802.11 traffic present.
1315 * XXX check if the beacon we recv'd gives
1316 * us what we need and suppress the probe req
1318 ieee80211_probe_curchan(vap, 1);
1319 ic->ic_flags_ext &= ~IEEE80211_FEXT_PROBECHAN;
1321 ieee80211_add_scan(vap, &scan, wh,
1326 /* The rest of this code assumes we are running */
1327 if (vap->iv_state != IEEE80211_S_RUN)
1330 * Ignore non-mesh STAs.
1333 (IEEE80211_CAPINFO_ESS|IEEE80211_CAPINFO_IBSS)) ||
1334 scan.meshid == NULL || scan.meshconf == NULL) {
1335 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1336 wh, "beacon", "%s", "not a mesh sta");
1337 vap->iv_stats.is_mesh_wrongmesh++;
1341 * Ignore STAs for other mesh networks.
1343 if (memcmp(scan.meshid+2, ms->ms_id, ms->ms_idlen) != 0 ||
1344 mesh_verify_meshconf(vap, scan.meshconf)) {
1345 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1346 wh, "beacon", "%s", "not for our mesh");
1347 vap->iv_stats.is_mesh_wrongmesh++;
1351 * Peer only based on the current ACL policy.
1353 if (vap->iv_acl != NULL &&
1354 !vap->iv_acl->iac_check(vap, wh->i_addr2)) {
1355 IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL,
1356 wh, NULL, "%s", "disallowed by ACL");
1357 vap->iv_stats.is_rx_acl++;
1361 * Do neighbor discovery.
1363 if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) {
1365 * Create a new entry in the neighbor table.
1367 ni = ieee80211_add_neighbor(vap, wh, &scan);
1370 * Automatically peer with discovered nodes if possible.
1371 * XXX backoff on repeated failure
1373 if (ni != vap->iv_bss &&
1374 (ms->ms_flags & IEEE80211_MESHFLAGS_AP) &&
1375 ni->ni_mlstate == IEEE80211_NODE_MESH_IDLE) {
1378 ni->ni_mlpid = mesh_generateid(vap);
1379 if (ni->ni_mlpid == 0)
1381 mesh_linkchange(ni, IEEE80211_NODE_MESH_OPENSNT);
1382 args[0] = ni->ni_mlpid;
1383 ieee80211_send_action(ni,
1384 IEEE80211_ACTION_CAT_MESHPEERING,
1385 IEEE80211_ACTION_MESHPEERING_OPEN, args);
1387 mesh_peer_timeout_setup(ni);
1391 case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
1393 uint8_t *ssid, *meshid, *rates, *xrates;
1396 if (vap->iv_state != IEEE80211_S_RUN) {
1397 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1398 wh, NULL, "wrong state %s",
1399 ieee80211_state_name[vap->iv_state]);
1400 vap->iv_stats.is_rx_mgtdiscard++;
1403 if (IEEE80211_IS_MULTICAST(wh->i_addr2)) {
1404 /* frame must be directed */
1405 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1406 wh, NULL, "%s", "not unicast");
1407 vap->iv_stats.is_rx_mgtdiscard++; /* XXX stat */
1411 * prreq frame format
1413 * [tlv] supported rates
1414 * [tlv] extended supported rates
1417 ssid = meshid = rates = xrates = NULL;
1419 while (efrm - frm > 1) {
1420 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return);
1422 case IEEE80211_ELEMID_SSID:
1425 case IEEE80211_ELEMID_RATES:
1428 case IEEE80211_ELEMID_XRATES:
1431 case IEEE80211_ELEMID_MESHID:
1437 IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return);
1438 IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return);
1440 IEEE80211_VERIFY_ELEMENT(xrates,
1441 IEEE80211_RATE_MAXSIZE - rates[1], return);
1442 if (meshid != NULL) {
1443 IEEE80211_VERIFY_ELEMENT(meshid,
1444 IEEE80211_MESHID_LEN, return);
1445 /* NB: meshid, not ssid */
1446 IEEE80211_VERIFY_SSID(vap->iv_bss, meshid, return);
1449 /* XXX find a better class or define it's own */
1450 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2,
1451 "%s", "recv probe req");
1453 * Some legacy 11b clients cannot hack a complete
1454 * probe response frame. When the request includes
1455 * only a bare-bones rate set, communicate this to
1456 * the transmit side.
1458 ieee80211_send_proberesp(vap, wh->i_addr2, 0);
1461 case IEEE80211_FC0_SUBTYPE_ACTION:
1462 if (vap->iv_state != IEEE80211_S_RUN) {
1463 vap->iv_stats.is_rx_mgtdiscard++;
1467 * We received an action for an unknown neighbor.
1468 * XXX: wait for it to beacon or create ieee80211_node?
1470 if (ni == vap->iv_bss) {
1471 IEEE80211_DISCARD(vap, IEEE80211_MSG_MESH,
1472 wh, NULL, "%s", "unknown node");
1473 vap->iv_stats.is_rx_mgtdiscard++;
1477 * Discard if not for us.
1479 if (!IEEE80211_ADDR_EQ(vap->iv_myaddr, wh->i_addr1) &&
1480 !IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1481 IEEE80211_DISCARD(vap, IEEE80211_MSG_MESH,
1482 wh, NULL, "%s", "not for me");
1483 vap->iv_stats.is_rx_mgtdiscard++;
1486 /* XXX parse_action is a bit useless now */
1487 if (ieee80211_parse_action(ni, m0) == 0)
1488 ic->ic_recv_action(ni, wh, frm, efrm);
1490 case IEEE80211_FC0_SUBTYPE_AUTH:
1491 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
1492 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
1493 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
1494 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
1495 case IEEE80211_FC0_SUBTYPE_DEAUTH:
1496 case IEEE80211_FC0_SUBTYPE_DISASSOC:
1497 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1498 wh, NULL, "%s", "not handled");
1499 vap->iv_stats.is_rx_mgtdiscard++;
1502 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1503 wh, "mgt", "subtype 0x%x not handled", subtype);
1504 vap->iv_stats.is_rx_badsubtype++;
1510 * Parse meshpeering action ie's for open+confirm frames; the
1511 * important bits are returned in the supplied structure.
1513 static const struct ieee80211_meshpeer_ie *
1514 mesh_parse_meshpeering_action(struct ieee80211_node *ni,
1515 const struct ieee80211_frame *wh, /* XXX for VERIFY_LENGTH */
1516 const uint8_t *frm, const uint8_t *efrm,
1517 struct ieee80211_meshpeer_ie *mp, uint8_t subtype)
1519 struct ieee80211vap *vap = ni->ni_vap;
1520 const struct ieee80211_meshpeer_ie *mpie;
1521 const uint8_t *meshid, *meshconf, *meshpeer;
1523 meshid = meshconf = meshpeer = NULL;
1524 while (efrm - frm > 1) {
1525 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return NULL);
1527 case IEEE80211_ELEMID_MESHID:
1530 case IEEE80211_ELEMID_MESHCONF:
1533 case IEEE80211_ELEMID_MESHPEER:
1535 mpie = (const struct ieee80211_meshpeer_ie *) frm;
1536 memset(mp, 0, sizeof(*mp));
1537 mp->peer_llinkid = LE_READ_2(&mpie->peer_llinkid);
1538 /* NB: peer link ID is optional on these frames */
1539 if (subtype == IEEE80211_MESH_PEER_LINK_CLOSE &&
1540 mpie->peer_len == 8) {
1541 mp->peer_linkid = 0;
1542 mp->peer_rcode = LE_READ_2(&mpie->peer_linkid);
1544 mp->peer_linkid = LE_READ_2(&mpie->peer_linkid);
1545 mp->peer_rcode = LE_READ_2(&mpie->peer_rcode);
1553 * Verify the contents of the frame. Action frames with
1554 * close subtype don't have a Mesh Configuration IE.
1555 * If if fails validation, close the peer link.
1557 KASSERT(meshpeer != NULL &&
1558 subtype != IEEE80211_ACTION_MESHPEERING_CLOSE,
1559 ("parsing close action"));
1561 if (mesh_verify_meshid(vap, meshid) ||
1562 mesh_verify_meshpeer(vap, subtype, meshpeer) ||
1563 mesh_verify_meshconf(vap, meshconf)) {
1566 IEEE80211_DISCARD(vap,
1567 IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH,
1568 wh, NULL, "%s", "not for our mesh");
1569 vap->iv_stats.is_rx_mgtdiscard++;
1570 switch (ni->ni_mlstate) {
1571 case IEEE80211_NODE_MESH_IDLE:
1572 case IEEE80211_NODE_MESH_ESTABLISHED:
1573 case IEEE80211_NODE_MESH_HOLDING:
1576 case IEEE80211_NODE_MESH_OPENSNT:
1577 case IEEE80211_NODE_MESH_OPENRCV:
1578 case IEEE80211_NODE_MESH_CONFIRMRCV:
1579 args[0] = ni->ni_mlpid;
1580 args[1] = ni->ni_mllid;
1581 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1582 ieee80211_send_action(ni,
1583 IEEE80211_ACTION_CAT_MESHPEERING,
1584 IEEE80211_ACTION_MESHPEERING_CLOSE,
1586 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1587 mesh_peer_timeout_setup(ni);
1592 return (const struct ieee80211_meshpeer_ie *) mp;
1596 mesh_recv_action_meshpeering_open(struct ieee80211_node *ni,
1597 const struct ieee80211_frame *wh,
1598 const uint8_t *frm, const uint8_t *efrm)
1600 struct ieee80211vap *vap = ni->ni_vap;
1601 struct ieee80211_meshpeer_ie ie;
1602 const struct ieee80211_meshpeer_ie *meshpeer;
1605 /* +2+2 for action + code + capabilites */
1606 meshpeer = mesh_parse_meshpeering_action(ni, wh, frm+2+2, efrm, &ie,
1607 IEEE80211_ACTION_MESHPEERING_OPEN);
1608 if (meshpeer == NULL) {
1613 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1614 "recv PEER OPEN, lid 0x%x", meshpeer->peer_llinkid);
1616 switch (ni->ni_mlstate) {
1617 case IEEE80211_NODE_MESH_IDLE:
1618 mesh_linkchange(ni, IEEE80211_NODE_MESH_OPENRCV);
1619 ni->ni_mllid = meshpeer->peer_llinkid;
1620 ni->ni_mlpid = mesh_generateid(vap);
1621 if (ni->ni_mlpid == 0)
1623 args[0] = ni->ni_mlpid;
1624 /* Announce we're open too... */
1625 ieee80211_send_action(ni,
1626 IEEE80211_ACTION_CAT_MESHPEERING,
1627 IEEE80211_ACTION_MESHPEERING_OPEN, args);
1628 /* ...and confirm the link. */
1629 args[0] = ni->ni_mlpid;
1630 args[1] = ni->ni_mllid;
1631 ieee80211_send_action(ni,
1632 IEEE80211_ACTION_CAT_MESHPEERING,
1633 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1635 mesh_peer_timeout_setup(ni);
1637 case IEEE80211_NODE_MESH_OPENRCV:
1639 if (ni->ni_mllid != meshpeer->peer_llinkid) {
1640 args[0] = ni->ni_mllid;
1641 args[1] = ni->ni_mlpid;
1642 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1643 ieee80211_send_action(ni,
1644 IEEE80211_ACTION_CAT_MESHPEERING,
1645 IEEE80211_ACTION_MESHPEERING_CLOSE,
1647 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1648 mesh_peer_timeout_setup(ni);
1651 /* Duplicate open, confirm again. */
1652 args[0] = ni->ni_mlpid;
1653 args[1] = ni->ni_mllid;
1654 ieee80211_send_action(ni,
1655 IEEE80211_ACTION_CAT_MESHPEERING,
1656 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1659 case IEEE80211_NODE_MESH_OPENSNT:
1660 ni->ni_mllid = meshpeer->peer_llinkid;
1661 mesh_linkchange(ni, IEEE80211_NODE_MESH_OPENRCV);
1662 args[0] = ni->ni_mlpid;
1663 args[1] = ni->ni_mllid;
1664 ieee80211_send_action(ni,
1665 IEEE80211_ACTION_CAT_MESHPEERING,
1666 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1668 /* NB: don't setup/clear any timeout */
1670 case IEEE80211_NODE_MESH_CONFIRMRCV:
1671 if (ni->ni_mlpid != meshpeer->peer_linkid ||
1672 ni->ni_mllid != meshpeer->peer_llinkid) {
1673 args[0] = ni->ni_mlpid;
1674 args[1] = ni->ni_mllid;
1675 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1676 ieee80211_send_action(ni,
1677 IEEE80211_ACTION_CAT_MESHPEERING,
1678 IEEE80211_ACTION_MESHPEERING_CLOSE,
1681 IEEE80211_NODE_MESH_HOLDING);
1682 mesh_peer_timeout_setup(ni);
1685 mesh_linkchange(ni, IEEE80211_NODE_MESH_ESTABLISHED);
1686 ni->ni_mllid = meshpeer->peer_llinkid;
1687 args[0] = ni->ni_mlpid;
1688 args[1] = ni->ni_mllid;
1689 ieee80211_send_action(ni,
1690 IEEE80211_ACTION_CAT_MESHPEERING,
1691 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1693 mesh_peer_timeout_stop(ni);
1695 case IEEE80211_NODE_MESH_ESTABLISHED:
1696 if (ni->ni_mllid != meshpeer->peer_llinkid) {
1697 args[0] = ni->ni_mllid;
1698 args[1] = ni->ni_mlpid;
1699 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1700 ieee80211_send_action(ni,
1701 IEEE80211_ACTION_CAT_MESHPEERING,
1702 IEEE80211_ACTION_MESHPEERING_CLOSE,
1704 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1705 mesh_peer_timeout_setup(ni);
1708 args[0] = ni->ni_mlpid;
1709 args[1] = ni->ni_mllid;
1710 ieee80211_send_action(ni,
1711 IEEE80211_ACTION_CAT_MESHPEERING,
1712 IEEE80211_ACTION_MESHPEERING_CONFIRM,
1715 case IEEE80211_NODE_MESH_HOLDING:
1716 args[0] = ni->ni_mlpid;
1717 args[1] = meshpeer->peer_llinkid;
1718 args[2] = IEEE80211_REASON_MESH_MAX_RETRIES;
1719 ieee80211_send_action(ni,
1720 IEEE80211_ACTION_CAT_MESHPEERING,
1721 IEEE80211_ACTION_MESHPEERING_CLOSE,
1729 mesh_recv_action_meshpeering_confirm(struct ieee80211_node *ni,
1730 const struct ieee80211_frame *wh,
1731 const uint8_t *frm, const uint8_t *efrm)
1733 struct ieee80211vap *vap = ni->ni_vap;
1734 struct ieee80211_meshpeer_ie ie;
1735 const struct ieee80211_meshpeer_ie *meshpeer;
1738 /* +2+2+2+2 for action + code + capabilites + status code + AID */
1739 meshpeer = mesh_parse_meshpeering_action(ni, wh, frm+2+2+2+2, efrm, &ie,
1740 IEEE80211_ACTION_MESHPEERING_CONFIRM);
1741 if (meshpeer == NULL) {
1745 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1746 "recv PEER CONFIRM, local id 0x%x, peer id 0x%x",
1747 meshpeer->peer_llinkid, meshpeer->peer_linkid);
1749 switch (ni->ni_mlstate) {
1750 case IEEE80211_NODE_MESH_OPENRCV:
1751 mesh_linkchange(ni, IEEE80211_NODE_MESH_ESTABLISHED);
1752 mesh_peer_timeout_stop(ni);
1754 case IEEE80211_NODE_MESH_OPENSNT:
1755 mesh_linkchange(ni, IEEE80211_NODE_MESH_CONFIRMRCV);
1757 case IEEE80211_NODE_MESH_HOLDING:
1758 args[0] = ni->ni_mlpid;
1759 args[1] = meshpeer->peer_llinkid;
1760 args[2] = IEEE80211_REASON_MESH_MAX_RETRIES;
1761 ieee80211_send_action(ni,
1762 IEEE80211_ACTION_CAT_MESHPEERING,
1763 IEEE80211_ACTION_MESHPEERING_CLOSE,
1766 case IEEE80211_NODE_MESH_CONFIRMRCV:
1767 if (ni->ni_mllid != meshpeer->peer_llinkid) {
1768 args[0] = ni->ni_mlpid;
1769 args[1] = ni->ni_mllid;
1770 args[2] = IEEE80211_REASON_PEER_LINK_CANCELED;
1771 ieee80211_send_action(ni,
1772 IEEE80211_ACTION_CAT_MESHPEERING,
1773 IEEE80211_ACTION_MESHPEERING_CLOSE,
1775 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1776 mesh_peer_timeout_setup(ni);
1780 IEEE80211_DISCARD(vap,
1781 IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH,
1782 wh, NULL, "received confirm in invalid state %d",
1784 vap->iv_stats.is_rx_mgtdiscard++;
1791 mesh_recv_action_meshpeering_close(struct ieee80211_node *ni,
1792 const struct ieee80211_frame *wh,
1793 const uint8_t *frm, const uint8_t *efrm)
1797 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH,
1798 ni, "%s", "recv PEER CLOSE");
1800 switch (ni->ni_mlstate) {
1801 case IEEE80211_NODE_MESH_IDLE:
1804 case IEEE80211_NODE_MESH_OPENRCV:
1805 case IEEE80211_NODE_MESH_OPENSNT:
1806 case IEEE80211_NODE_MESH_CONFIRMRCV:
1807 case IEEE80211_NODE_MESH_ESTABLISHED:
1808 args[0] = ni->ni_mlpid;
1809 args[1] = ni->ni_mllid;
1810 args[2] = IEEE80211_REASON_MESH_CLOSE_RCVD;
1811 ieee80211_send_action(ni,
1812 IEEE80211_ACTION_CAT_MESHPEERING,
1813 IEEE80211_ACTION_MESHPEERING_CLOSE,
1815 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
1816 mesh_peer_timeout_setup(ni);
1818 case IEEE80211_NODE_MESH_HOLDING:
1819 mesh_linkchange(ni, IEEE80211_NODE_MESH_IDLE);
1820 mesh_peer_timeout_setup(ni);
1827 * Link Metric handling.
1830 mesh_recv_action_meshlmetric_req(struct ieee80211_node *ni,
1831 const struct ieee80211_frame *wh,
1832 const uint8_t *frm, const uint8_t *efrm)
1836 metric = mesh_airtime_calc(ni);
1837 ieee80211_send_action(ni,
1838 IEEE80211_ACTION_CAT_MESHLMETRIC,
1839 IEEE80211_ACTION_MESHLMETRIC_REP,
1845 mesh_recv_action_meshlmetric_rep(struct ieee80211_node *ni,
1846 const struct ieee80211_frame *wh,
1847 const uint8_t *frm, const uint8_t *efrm)
1853 mesh_send_action(struct ieee80211_node *ni, struct mbuf *m)
1855 struct ieee80211_bpf_params params;
1857 memset(¶ms, 0, sizeof(params));
1858 params.ibp_pri = WME_AC_VO;
1859 params.ibp_rate0 = ni->ni_txparms->mgmtrate;
1860 /* XXX ucast/mcast */
1861 params.ibp_try0 = ni->ni_txparms->maxretry;
1862 params.ibp_power = ni->ni_txpower;
1863 return ieee80211_mgmt_output(ni, m, IEEE80211_FC0_SUBTYPE_ACTION,
1867 #define ADDSHORT(frm, v) do { \
1868 frm[0] = (v) & 0xff; \
1869 frm[1] = (v) >> 8; \
1872 #define ADDWORD(frm, v) do { \
1873 frm[0] = (v) & 0xff; \
1874 frm[1] = ((v) >> 8) & 0xff; \
1875 frm[2] = ((v) >> 16) & 0xff; \
1876 frm[3] = ((v) >> 24) & 0xff; \
1881 mesh_send_action_meshpeering_open(struct ieee80211_node *ni,
1882 int category, int action, void *args0)
1884 struct ieee80211vap *vap = ni->ni_vap;
1885 struct ieee80211com *ic = ni->ni_ic;
1886 uint16_t *args = args0;
1887 const struct ieee80211_rateset *rs;
1891 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1892 "send PEER OPEN action: localid 0x%x", args[0]);
1894 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1895 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
1896 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
1897 ieee80211_ref_node(ni);
1899 m = ieee80211_getmgtframe(&frm,
1900 ic->ic_headroom + sizeof(struct ieee80211_frame),
1901 sizeof(uint16_t) /* action+category */
1902 + sizeof(uint16_t) /* capabilites */
1903 + 2 + IEEE80211_RATE_SIZE
1904 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
1905 + 2 + IEEE80211_MESHID_LEN
1906 + sizeof(struct ieee80211_meshconf_ie)
1907 + sizeof(struct ieee80211_meshpeer_ie)
1911 * mesh peer open action frame format:
1919 * [tlv] mesh peer link mgmt
1923 ADDSHORT(frm, ieee80211_getcapinfo(vap, ni->ni_chan));
1924 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
1925 frm = ieee80211_add_rates(frm, rs);
1926 frm = ieee80211_add_xrates(frm, rs);
1927 frm = ieee80211_add_meshid(frm, vap);
1928 frm = ieee80211_add_meshconf(frm, vap);
1929 frm = ieee80211_add_meshpeer(frm, IEEE80211_MESH_PEER_LINK_OPEN,
1931 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
1932 return mesh_send_action(ni, m);
1934 vap->iv_stats.is_tx_nobuf++;
1935 ieee80211_free_node(ni);
1941 mesh_send_action_meshpeering_confirm(struct ieee80211_node *ni,
1942 int category, int action, void *args0)
1944 struct ieee80211vap *vap = ni->ni_vap;
1945 struct ieee80211com *ic = ni->ni_ic;
1946 uint16_t *args = args0;
1947 const struct ieee80211_rateset *rs;
1951 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
1952 "send PEER CONFIRM action: localid 0x%x, peerid 0x%x",
1955 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1956 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
1957 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
1958 ieee80211_ref_node(ni);
1960 m = ieee80211_getmgtframe(&frm,
1961 ic->ic_headroom + sizeof(struct ieee80211_frame),
1962 sizeof(uint16_t) /* action+category */
1963 + sizeof(uint16_t) /* capabilites */
1964 + sizeof(uint16_t) /* status code */
1965 + sizeof(uint16_t) /* AID */
1966 + 2 + IEEE80211_RATE_SIZE
1967 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
1968 + 2 + IEEE80211_MESHID_LEN
1969 + sizeof(struct ieee80211_meshconf_ie)
1970 + sizeof(struct ieee80211_meshpeer_ie)
1974 * mesh peer confirm action frame format:
1979 * [2] association id (peer ID)
1984 * [tlv] mesh peer link mgmt
1988 ADDSHORT(frm, ieee80211_getcapinfo(vap, ni->ni_chan));
1989 ADDSHORT(frm, 0); /* status code */
1990 ADDSHORT(frm, args[1]); /* AID */
1991 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
1992 frm = ieee80211_add_rates(frm, rs);
1993 frm = ieee80211_add_xrates(frm, rs);
1994 frm = ieee80211_add_meshid(frm, vap);
1995 frm = ieee80211_add_meshconf(frm, vap);
1996 frm = ieee80211_add_meshpeer(frm,
1997 IEEE80211_MESH_PEER_LINK_CONFIRM,
1998 args[0], args[1], 0);
1999 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2000 return mesh_send_action(ni, m);
2002 vap->iv_stats.is_tx_nobuf++;
2003 ieee80211_free_node(ni);
2009 mesh_send_action_meshpeering_close(struct ieee80211_node *ni,
2010 int category, int action, void *args0)
2012 struct ieee80211vap *vap = ni->ni_vap;
2013 struct ieee80211com *ic = ni->ni_ic;
2014 uint16_t *args = args0;
2018 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
2019 "send PEER CLOSE action: localid 0x%x, peerid 0x%x reason %d",
2020 args[0], args[1], args[2]);
2022 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2023 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
2024 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
2025 ieee80211_ref_node(ni);
2027 m = ieee80211_getmgtframe(&frm,
2028 ic->ic_headroom + sizeof(struct ieee80211_frame),
2029 sizeof(uint16_t) /* action+category */
2030 + sizeof(uint16_t) /* reason code */
2031 + 2 + IEEE80211_MESHID_LEN
2032 + sizeof(struct ieee80211_meshpeer_ie)
2036 * mesh peer close action frame format:
2041 * [tlv] mesh peer link mgmt
2045 ADDSHORT(frm, args[2]); /* reason code */
2046 frm = ieee80211_add_meshid(frm, vap);
2047 frm = ieee80211_add_meshpeer(frm,
2048 IEEE80211_MESH_PEER_LINK_CLOSE,
2049 args[0], args[1], args[2]);
2050 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2051 return mesh_send_action(ni, m);
2053 vap->iv_stats.is_tx_nobuf++;
2054 ieee80211_free_node(ni);
2060 mesh_send_action_meshlink_request(struct ieee80211_node *ni,
2061 int category, int action, void *arg0)
2063 struct ieee80211vap *vap = ni->ni_vap;
2064 struct ieee80211com *ic = ni->ni_ic;
2068 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
2069 "%s", "send LINK METRIC REQUEST action");
2071 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2072 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
2073 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
2074 ieee80211_ref_node(ni);
2076 m = ieee80211_getmgtframe(&frm,
2077 ic->ic_headroom + sizeof(struct ieee80211_frame),
2078 sizeof(uint16_t) /* action+category */
2082 * mesh link metric request
2088 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2089 return mesh_send_action(ni, m);
2091 vap->iv_stats.is_tx_nobuf++;
2092 ieee80211_free_node(ni);
2098 mesh_send_action_meshlink_reply(struct ieee80211_node *ni,
2099 int category, int action, void *args0)
2101 struct ieee80211vap *vap = ni->ni_vap;
2102 struct ieee80211com *ic = ni->ni_ic;
2103 uint32_t *metric = args0;
2107 IEEE80211_NOTE(vap, IEEE80211_MSG_ACTION | IEEE80211_MSG_MESH, ni,
2108 "send LINK METRIC REPLY action: metric 0x%x", *metric);
2110 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2111 "ieee80211_ref_node (%s:%u) %p<%6D> refcnt %d\n", __func__, __LINE__,
2112 ni, ni->ni_macaddr, ":", ieee80211_node_refcnt(ni)+1);
2113 ieee80211_ref_node(ni);
2115 m = ieee80211_getmgtframe(&frm,
2116 ic->ic_headroom + sizeof(struct ieee80211_frame),
2117 sizeof(uint16_t) /* action+category */
2118 + sizeof(struct ieee80211_meshlmetric_ie)
2122 * mesh link metric reply
2125 * [tlv] mesh link metric
2129 frm = ieee80211_add_meshlmetric(frm, *metric);
2130 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2131 return mesh_send_action(ni, m);
2133 vap->iv_stats.is_tx_nobuf++;
2134 ieee80211_free_node(ni);
2140 mesh_peer_timeout_setup(struct ieee80211_node *ni)
2142 switch (ni->ni_mlstate) {
2143 case IEEE80211_NODE_MESH_HOLDING:
2144 ni->ni_mltval = ieee80211_mesh_holdingtimeout;
2146 case IEEE80211_NODE_MESH_CONFIRMRCV:
2147 ni->ni_mltval = ieee80211_mesh_confirmtimeout;
2149 case IEEE80211_NODE_MESH_IDLE:
2153 ni->ni_mltval = ieee80211_mesh_retrytimeout;
2156 if (ni->ni_mltval) {
2157 callout_reset(&ni->ni_mltimer, ni->ni_mltval,
2158 mesh_peer_timeout_callout, ni);
2163 * Same as above but backoffs timer statisically 50%.
2166 mesh_peer_timeout_backoff(struct ieee80211_node *ni)
2171 ni->ni_mltval += r % ni->ni_mltval;
2172 callout_reset(&ni->ni_mltimer, ni->ni_mltval,
2173 mesh_peer_timeout_callout, ni);
2176 static __inline void
2177 mesh_peer_timeout_stop(struct ieee80211_node *ni)
2179 callout_stop(&ni->ni_mltimer);
2183 * Mesh Peer Link Management FSM timeout handling.
2186 mesh_peer_timeout_callout(void *arg)
2188 struct ieee80211_node *ni = (struct ieee80211_node *)arg;
2191 wlan_serialize_enter();
2192 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_MESH,
2193 ni, "mesh link timeout, state %d, retry counter %d",
2194 ni->ni_mlstate, ni->ni_mlrcnt);
2196 switch (ni->ni_mlstate) {
2197 case IEEE80211_NODE_MESH_IDLE:
2198 case IEEE80211_NODE_MESH_ESTABLISHED:
2200 case IEEE80211_NODE_MESH_OPENSNT:
2201 case IEEE80211_NODE_MESH_OPENRCV:
2202 if (ni->ni_mlrcnt == ieee80211_mesh_maxretries) {
2203 args[0] = ni->ni_mlpid;
2204 args[2] = IEEE80211_REASON_MESH_MAX_RETRIES;
2205 ieee80211_send_action(ni,
2206 IEEE80211_ACTION_CAT_MESHPEERING,
2207 IEEE80211_ACTION_MESHPEERING_CLOSE, args);
2209 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
2210 mesh_peer_timeout_setup(ni);
2212 args[0] = ni->ni_mlpid;
2213 ieee80211_send_action(ni,
2214 IEEE80211_ACTION_CAT_MESHPEERING,
2215 IEEE80211_ACTION_MESHPEERING_OPEN, args);
2217 mesh_peer_timeout_backoff(ni);
2220 case IEEE80211_NODE_MESH_CONFIRMRCV:
2221 if (ni->ni_mlrcnt == ieee80211_mesh_maxretries) {
2222 args[0] = ni->ni_mlpid;
2223 args[2] = IEEE80211_REASON_MESH_CONFIRM_TIMEOUT;
2224 ieee80211_send_action(ni,
2225 IEEE80211_ACTION_CAT_MESHPEERING,
2226 IEEE80211_ACTION_MESHPEERING_CLOSE, args);
2228 mesh_linkchange(ni, IEEE80211_NODE_MESH_HOLDING);
2229 mesh_peer_timeout_setup(ni);
2232 mesh_peer_timeout_setup(ni);
2235 case IEEE80211_NODE_MESH_HOLDING:
2236 mesh_linkchange(ni, IEEE80211_NODE_MESH_IDLE);
2239 wlan_serialize_exit();
2243 mesh_verify_meshid(struct ieee80211vap *vap, const uint8_t *ie)
2245 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2247 if (ie == NULL || ie[1] != ms->ms_idlen)
2249 return memcmp(ms->ms_id, ie + 2, ms->ms_idlen);
2253 * Check if we are using the same algorithms for this mesh.
2256 mesh_verify_meshconf(struct ieee80211vap *vap, const uint8_t *ie)
2258 const struct ieee80211_meshconf_ie *meshconf =
2259 (const struct ieee80211_meshconf_ie *) ie;
2260 const struct ieee80211_mesh_state *ms = vap->iv_mesh;
2263 if (meshconf == NULL)
2265 if (meshconf->conf_pselid != ms->ms_ppath->mpp_ie) {
2266 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2267 "unknown path selection algorithm: 0x%x\n",
2268 meshconf->conf_pselid);
2271 if (meshconf->conf_pmetid != ms->ms_pmetric->mpm_ie) {
2272 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2273 "unknown path metric algorithm: 0x%x\n",
2274 meshconf->conf_pmetid);
2277 if (meshconf->conf_ccid != 0) {
2278 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2279 "unknown congestion control algorithm: 0x%x\n",
2280 meshconf->conf_ccid);
2283 if (meshconf->conf_syncid != IEEE80211_MESHCONF_SYNC_NEIGHOFF) {
2284 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2285 "unknown sync algorithm: 0x%x\n",
2286 meshconf->conf_syncid);
2289 if (meshconf->conf_authid != 0) {
2290 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2291 "unknown auth auth algorithm: 0x%x\n",
2292 meshconf->conf_pselid);
2295 /* NB: conf_cap is only read correctly here */
2296 cap = LE_READ_2(&meshconf->conf_cap);
2297 /* Not accepting peers */
2298 if (!(cap & IEEE80211_MESHCONF_CAP_AP)) {
2299 IEEE80211_DPRINTF(vap, IEEE80211_MSG_MESH,
2300 "not accepting peers: 0x%x\n", meshconf->conf_cap);
2307 mesh_verify_meshpeer(struct ieee80211vap *vap, uint8_t subtype,
2310 const struct ieee80211_meshpeer_ie *meshpeer =
2311 (const struct ieee80211_meshpeer_ie *) ie;
2313 if (meshpeer == NULL || meshpeer->peer_len < 6 ||
2314 meshpeer->peer_len > 10)
2317 case IEEE80211_MESH_PEER_LINK_OPEN:
2318 if (meshpeer->peer_len != 6)
2321 case IEEE80211_MESH_PEER_LINK_CONFIRM:
2322 if (meshpeer->peer_len != 8)
2325 case IEEE80211_MESH_PEER_LINK_CLOSE:
2326 if (meshpeer->peer_len < 8)
2328 if (meshpeer->peer_len == 8 && meshpeer->peer_linkid != 0)
2330 if (meshpeer->peer_rcode == 0)
2338 * Add a Mesh ID IE to a frame.
2341 ieee80211_add_meshid(uint8_t *frm, struct ieee80211vap *vap)
2343 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2345 KASSERT(vap->iv_opmode == IEEE80211_M_MBSS, ("not a mbss vap"));
2347 *frm++ = IEEE80211_ELEMID_MESHID;
2348 *frm++ = ms->ms_idlen;
2349 memcpy(frm, ms->ms_id, ms->ms_idlen);
2350 return frm + ms->ms_idlen;
2354 * Add a Mesh Configuration IE to a frame.
2355 * For now just use HWMP routing, Airtime link metric, Null Congestion
2356 * Signaling, Null Sync Protocol and Null Authentication.
2359 ieee80211_add_meshconf(uint8_t *frm, struct ieee80211vap *vap)
2361 const struct ieee80211_mesh_state *ms = vap->iv_mesh;
2364 KASSERT(vap->iv_opmode == IEEE80211_M_MBSS, ("not a MBSS vap"));
2366 *frm++ = IEEE80211_ELEMID_MESHCONF;
2367 *frm++ = sizeof(struct ieee80211_meshconf_ie) - 2;
2368 *frm++ = ms->ms_ppath->mpp_ie; /* path selection */
2369 *frm++ = ms->ms_pmetric->mpm_ie; /* link metric */
2370 *frm++ = IEEE80211_MESHCONF_CC_DISABLED;
2371 *frm++ = IEEE80211_MESHCONF_SYNC_NEIGHOFF;
2372 *frm++ = IEEE80211_MESHCONF_AUTH_DISABLED;
2373 /* NB: set the number of neighbors before the rest */
2374 *frm = (ms->ms_neighbors > 15 ? 15 : ms->ms_neighbors) << 1;
2375 if (ms->ms_flags & IEEE80211_MESHFLAGS_PORTAL)
2376 *frm |= IEEE80211_MESHCONF_FORM_MP;
2379 if (ms->ms_flags & IEEE80211_MESHFLAGS_AP)
2380 caps |= IEEE80211_MESHCONF_CAP_AP;
2381 if (ms->ms_flags & IEEE80211_MESHFLAGS_FWD)
2382 caps |= IEEE80211_MESHCONF_CAP_FWRD;
2383 ADDSHORT(frm, caps);
2388 * Add a Mesh Peer Management IE to a frame.
2391 ieee80211_add_meshpeer(uint8_t *frm, uint8_t subtype, uint16_t localid,
2392 uint16_t peerid, uint16_t reason)
2394 /* XXX change for AH */
2395 static const uint8_t meshpeerproto[4] = IEEE80211_MESH_PEER_PROTO;
2397 KASSERT(localid != 0, ("localid == 0"));
2399 *frm++ = IEEE80211_ELEMID_MESHPEER;
2401 case IEEE80211_MESH_PEER_LINK_OPEN:
2402 *frm++ = 6; /* length */
2403 memcpy(frm, meshpeerproto, 4);
2405 ADDSHORT(frm, localid); /* local ID */
2407 case IEEE80211_MESH_PEER_LINK_CONFIRM:
2408 KASSERT(peerid != 0, ("sending peer confirm without peer id"));
2409 *frm++ = 8; /* length */
2410 memcpy(frm, meshpeerproto, 4);
2412 ADDSHORT(frm, localid); /* local ID */
2413 ADDSHORT(frm, peerid); /* peer ID */
2415 case IEEE80211_MESH_PEER_LINK_CLOSE:
2417 *frm++ = 10; /* length */
2419 *frm++ = 8; /* length */
2420 memcpy(frm, meshpeerproto, 4);
2422 ADDSHORT(frm, localid); /* local ID */
2424 ADDSHORT(frm, peerid); /* peer ID */
2425 ADDSHORT(frm, reason);
2432 * Compute an Airtime Link Metric for the link with this node.
2434 * Based on Draft 3.0 spec (11B.10, p.149).
2437 * Max 802.11s overhead.
2439 #define IEEE80211_MESH_MAXOVERHEAD \
2440 (sizeof(struct ieee80211_qosframe_addr4) \
2441 + sizeof(struct ieee80211_meshcntl_ae11) \
2442 + sizeof(struct llc) \
2443 + IEEE80211_ADDR_LEN \
2444 + IEEE80211_WEP_IVLEN \
2445 + IEEE80211_WEP_KIDLEN \
2446 + IEEE80211_WEP_CRCLEN \
2447 + IEEE80211_WEP_MICLEN \
2448 + IEEE80211_CRC_LEN)
2450 mesh_airtime_calc(struct ieee80211_node *ni)
2453 #define S_FACTOR (2 * M_BITS)
2454 struct ieee80211com *ic = ni->ni_ic;
2455 struct ifnet *ifp = ni->ni_vap->iv_ifp;
2456 static const int nbits = 8192 << M_BITS;
2457 uint32_t overhead, rate, errrate;
2460 /* Time to transmit a frame */
2461 rate = ni->ni_txrate;
2462 overhead = ieee80211_compute_duration(ic->ic_rt,
2463 ifp->if_mtu + IEEE80211_MESH_MAXOVERHEAD, rate, 0) << M_BITS;
2464 /* Error rate in percentage */
2465 /* XXX assuming small failures are ok */
2466 errrate = (((ifp->if_oerrors +
2467 ifp->if_ierrors) / 100) << M_BITS) / 100;
2468 res = (overhead + (nbits / rate)) *
2469 ((1 << S_FACTOR) / ((1 << M_BITS) - errrate));
2471 return (uint32_t)(res >> S_FACTOR);
2477 * Add a Mesh Link Metric report IE to a frame.
2480 ieee80211_add_meshlmetric(uint8_t *frm, uint32_t metric)
2482 *frm++ = IEEE80211_ELEMID_MESHLINK;
2484 ADDWORD(frm, metric);
2491 * Initialize any mesh-specific node state.
2494 ieee80211_mesh_node_init(struct ieee80211vap *vap, struct ieee80211_node *ni)
2496 ni->ni_flags |= IEEE80211_NODE_QOS;
2497 callout_init_mp(&ni->ni_mltimer);
2501 * Cleanup any mesh-specific node state.
2504 ieee80211_mesh_node_cleanup(struct ieee80211_node *ni)
2506 struct ieee80211vap *vap = ni->ni_vap;
2507 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2509 callout_stop(&ni->ni_mltimer);
2510 /* NB: short-circuit callbacks after mesh_vdetach */
2511 if (vap->iv_mesh != NULL)
2512 ms->ms_ppath->mpp_peerdown(ni);
2516 ieee80211_parse_meshid(struct ieee80211_node *ni, const uint8_t *ie)
2518 ni->ni_meshidlen = ie[1];
2519 memcpy(ni->ni_meshid, ie + 2, ie[1]);
2523 * Setup mesh-specific node state on neighbor discovery.
2526 ieee80211_mesh_init_neighbor(struct ieee80211_node *ni,
2527 const struct ieee80211_frame *wh,
2528 const struct ieee80211_scanparams *sp)
2530 ieee80211_parse_meshid(ni, sp->meshid);
2534 ieee80211_mesh_update_beacon(struct ieee80211vap *vap,
2535 struct ieee80211_beacon_offsets *bo)
2537 KASSERT(vap->iv_opmode == IEEE80211_M_MBSS, ("not a MBSS vap"));
2539 if (isset(bo->bo_flags, IEEE80211_BEACON_MESHCONF)) {
2540 (void)ieee80211_add_meshconf(bo->bo_meshconf, vap);
2541 clrbit(bo->bo_flags, IEEE80211_BEACON_MESHCONF);
2546 mesh_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
2548 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2549 uint8_t tmpmeshid[IEEE80211_NWID_LEN];
2550 struct ieee80211_mesh_route *rt;
2551 struct ieee80211req_mesh_route *imr;
2556 if (vap->iv_opmode != IEEE80211_M_MBSS)
2560 switch (ireq->i_type) {
2561 case IEEE80211_IOC_MESH_ID:
2562 ireq->i_len = ms->ms_idlen;
2563 memcpy(tmpmeshid, ms->ms_id, ireq->i_len);
2564 error = copyout(tmpmeshid, ireq->i_data, ireq->i_len);
2566 case IEEE80211_IOC_MESH_AP:
2567 ireq->i_val = (ms->ms_flags & IEEE80211_MESHFLAGS_AP) != 0;
2569 case IEEE80211_IOC_MESH_FWRD:
2570 ireq->i_val = (ms->ms_flags & IEEE80211_MESHFLAGS_FWD) != 0;
2572 case IEEE80211_IOC_MESH_TTL:
2573 ireq->i_val = ms->ms_ttl;
2575 case IEEE80211_IOC_MESH_RTCMD:
2576 switch (ireq->i_val) {
2577 case IEEE80211_MESH_RTCMD_LIST:
2579 TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) {
2580 len += sizeof(*imr);
2582 if (len > ireq->i_len || ireq->i_len < sizeof(*imr)) {
2588 p = kmalloc(len, M_TEMP, M_INTWAIT | M_ZERO);
2592 TAILQ_FOREACH(rt, &ms->ms_routes, rt_next) {
2595 imr = (struct ieee80211req_mesh_route *)
2597 imr->imr_flags = rt->rt_flags;
2598 IEEE80211_ADDR_COPY(imr->imr_dest,
2600 IEEE80211_ADDR_COPY(imr->imr_nexthop,
2602 imr->imr_metric = rt->rt_metric;
2603 imr->imr_nhops = rt->rt_nhops;
2604 imr->imr_lifetime = rt->rt_lifetime;
2605 imr->imr_lastmseq = rt->rt_lastmseq;
2606 off += sizeof(*imr);
2608 error = copyout(p, (uint8_t *)ireq->i_data,
2612 case IEEE80211_MESH_RTCMD_FLUSH:
2613 case IEEE80211_MESH_RTCMD_ADD:
2614 case IEEE80211_MESH_RTCMD_DELETE:
2620 case IEEE80211_IOC_MESH_PR_METRIC:
2621 len = strlen(ms->ms_pmetric->mpm_descr);
2622 if (ireq->i_len < len)
2625 error = copyout(ms->ms_pmetric->mpm_descr,
2626 (uint8_t *)ireq->i_data, len);
2628 case IEEE80211_IOC_MESH_PR_PATH:
2629 len = strlen(ms->ms_ppath->mpp_descr);
2630 if (ireq->i_len < len)
2633 error = copyout(ms->ms_ppath->mpp_descr,
2634 (uint8_t *)ireq->i_data, len);
2642 IEEE80211_IOCTL_GET(mesh, mesh_ioctl_get80211);
2645 mesh_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
2647 struct ieee80211_mesh_state *ms = vap->iv_mesh;
2648 uint8_t tmpmeshid[IEEE80211_NWID_LEN];
2649 uint8_t tmpaddr[IEEE80211_ADDR_LEN];
2650 char tmpproto[IEEE80211_MESH_PROTO_DSZ];
2653 if (vap->iv_opmode != IEEE80211_M_MBSS)
2657 switch (ireq->i_type) {
2658 case IEEE80211_IOC_MESH_ID:
2659 if (ireq->i_val != 0 || ireq->i_len > IEEE80211_MESHID_LEN)
2661 error = copyin(ireq->i_data, tmpmeshid, ireq->i_len);
2664 memset(ms->ms_id, 0, IEEE80211_NWID_LEN);
2665 ms->ms_idlen = ireq->i_len;
2666 memcpy(ms->ms_id, tmpmeshid, ireq->i_len);
2669 case IEEE80211_IOC_MESH_AP:
2671 ms->ms_flags |= IEEE80211_MESHFLAGS_AP;
2673 ms->ms_flags &= ~IEEE80211_MESHFLAGS_AP;
2676 case IEEE80211_IOC_MESH_FWRD:
2678 ms->ms_flags |= IEEE80211_MESHFLAGS_FWD;
2680 ms->ms_flags &= ~IEEE80211_MESHFLAGS_FWD;
2682 case IEEE80211_IOC_MESH_TTL:
2683 ms->ms_ttl = (uint8_t) ireq->i_val;
2685 case IEEE80211_IOC_MESH_RTCMD:
2686 switch (ireq->i_val) {
2687 case IEEE80211_MESH_RTCMD_LIST:
2689 case IEEE80211_MESH_RTCMD_FLUSH:
2690 ieee80211_mesh_rt_flush(vap);
2692 case IEEE80211_MESH_RTCMD_ADD:
2693 if (IEEE80211_ADDR_EQ(vap->iv_myaddr, ireq->i_data) ||
2694 IEEE80211_ADDR_EQ(broadcastaddr, ireq->i_data))
2696 error = copyin(ireq->i_data, &tmpaddr,
2697 IEEE80211_ADDR_LEN);
2699 ieee80211_mesh_discover(vap, tmpaddr, NULL);
2701 case IEEE80211_MESH_RTCMD_DELETE:
2702 ieee80211_mesh_rt_del(vap, ireq->i_data);
2708 case IEEE80211_IOC_MESH_PR_METRIC:
2709 error = copyin(ireq->i_data, tmpproto, sizeof(tmpproto));
2711 error = mesh_select_proto_metric(vap, tmpproto);
2716 case IEEE80211_IOC_MESH_PR_PATH:
2717 error = copyin(ireq->i_data, tmpproto, sizeof(tmpproto));
2719 error = mesh_select_proto_path(vap, tmpproto);
2729 IEEE80211_IOCTL_SET(mesh, mesh_ioctl_set80211);