2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011 Adrian Chadd, Xenion Lty Ltd
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
34 * net80211 fast-logging support, primarily for debugging.
36 * This implements a single debugging queue which includes
37 * per-device enumeration where needed.
42 #include <sys/param.h>
43 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <sys/endian.h>
47 #include <sys/kernel.h>
48 #include <sys/sysctl.h>
51 #include <sys/ucred.h>
54 #include <sys/socket.h>
57 #include <net/if_var.h>
58 #include <net/if_media.h>
59 #include <net/ethernet.h>
61 #include <net80211/ieee80211_var.h>
62 #include <net80211/ieee80211_freebsd.h>
63 #include <net80211/ieee80211_alq.h>
65 static struct alq *ieee80211_alq;
66 static int ieee80211_alq_lost;
67 static int ieee80211_alq_logged;
68 static char ieee80211_alq_logfile[MAXPATHLEN] = "/tmp/net80211.log";
69 static unsigned int ieee80211_alq_qsize = 64*1024;
72 ieee80211_alq_setlogging(int enable)
78 alq_close(ieee80211_alq);
80 error = alq_open(&ieee80211_alq,
81 ieee80211_alq_logfile,
84 ieee80211_alq_qsize, 0);
85 ieee80211_alq_lost = 0;
86 ieee80211_alq_logged = 0;
87 printf("net80211: logging to %s enabled; "
88 "struct size %d bytes\n",
89 ieee80211_alq_logfile,
90 (int) sizeof(struct ieee80211_alq_rec));
93 alq_close(ieee80211_alq);
95 printf("net80211: logging disabled\n");
102 sysctl_ieee80211_alq_log(SYSCTL_HANDLER_ARGS)
106 enable = (ieee80211_alq != NULL);
107 error = sysctl_handle_int(oidp, &enable, 0, req);
108 if (error || !req->newptr)
111 return (ieee80211_alq_setlogging(enable));
114 SYSCTL_PROC(_net_wlan, OID_AUTO, alq,
115 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 0, 0,
116 sysctl_ieee80211_alq_log, "I",
117 "Enable net80211 alq logging");
118 SYSCTL_INT(_net_wlan, OID_AUTO, alq_size, CTLFLAG_RW,
119 &ieee80211_alq_qsize, 0, "In-memory log size (bytes)");
120 SYSCTL_INT(_net_wlan, OID_AUTO, alq_lost, CTLFLAG_RW,
121 &ieee80211_alq_lost, 0, "Debugging operations not logged");
122 SYSCTL_INT(_net_wlan, OID_AUTO, alq_logged, CTLFLAG_RW,
123 &ieee80211_alq_logged, 0, "Debugging operations logged");
126 ieee80211_alq_get(size_t len)
130 ale = alq_getn(ieee80211_alq, len + sizeof(struct ieee80211_alq_rec),
133 ieee80211_alq_lost++;
135 ieee80211_alq_logged++;
140 ieee80211_alq_log(struct ieee80211com *ic, struct ieee80211vap *vap,
141 uint32_t op, uint32_t flags, uint16_t srcid, const uint8_t *src,
145 struct ieee80211_alq_rec *r;
148 /* Don't log if we're disabled */
149 if (ieee80211_alq == NULL)
152 if (len > IEEE80211_ALQ_MAX_PAYLOAD)
155 ale = ieee80211_alq_get(len);
159 r = (struct ieee80211_alq_rec *) ale->ae_data;
160 dst = ((char *) r) + sizeof(struct ieee80211_alq_rec);
161 r->r_timestamp = htobe64(ticks);
163 r->r_wlan = htobe16(vap->iv_ifp->if_dunit);
167 r->r_src = htobe16(srcid);
168 r->r_flags = htobe32(flags);
169 r->r_op = htobe32(op);
170 r->r_len = htobe32(len + sizeof(struct ieee80211_alq_rec));
171 r->r_threadid = htobe32((uint32_t) curthread->td_tid);
174 memcpy(dst, src, len);
176 alq_post(ieee80211_alq, ale);