MFC: following 4 commits:
[dragonfly.git] / usr.sbin / i4b / isdnmonitor / monitor.h
blob4d7d876b1a0e5db781eaaa2853a9686b8dfc09b8
1 /*
2 * Copyright (c) 1998,1999 Martin Husemann. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 * 4. Altered versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software and/or documentation.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
31 *---------------------------------------------------------------------------
33 * i4b daemon - network monitor protocol definition
34 * ------------------------------------------------
36 * $Id: monitor.h,v 1.16 1999/12/13 21:25:26 hm Exp $
38 * $FreeBSD: src/usr.sbin/i4b/isdnmonitor/monitor.h,v 1.6.2.1 2001/08/01 17:45:06 obrien Exp $
39 * $DragonFly: src/usr.sbin/i4b/isdnmonitor/monitor.h,v 1.2 2003/06/17 04:29:55 dillon Exp $
41 * last edit-date: [Mon Dec 13 21:52:18 1999]
43 *---------------------------------------------------------------------------*/
45 #ifndef _MONITOR_H_
46 #define _MONITOR_H_
48 #define DEF_MONPORT 451 /* default monitor TCP port */
50 #ifdef __hpux
51 #define u_int8_t ubit8
52 #define u_int32_t ubit32
53 #endif
54 #ifdef WIN32
55 #define u_int8_t BYTE
56 #define u_int32_t DWORD
57 #endif
60 * The monitor client connects to the isdnd daemon process via a tcp/ip
61 * connection from a remote machine or via a local (unix domain) socket.
62 * The daemon accepts multiple connections and verifies access rights.
63 * On connection establishment the daemon sends initial data telling
64 * the client the current configuration: number and type of available
65 * controllers, current connections, channel and interface states
66 * and the clients access privileges. The client sends an event mask
67 * telling the daemon which events it is interested in. If the client
68 * has appropriate rights he may send commands to the daemon.
70 * All multi-byte values are in network byte order!
73 /* All data packets transfered are declared as arrays of u_int8_t */
75 /* max stringlength used in this protocol */
76 #define I4B_MAX_MON_STRING 256
78 /* max command size from client to server */
79 #define I4B_MAX_MON_CLIENT_CMD 16
81 /* Version of the monitor protocol described here */
82 #define MPROT_VERSION 0 /* major version no */
83 #define MPROT_REL 5 /* release no */
86 * Client access rights
88 #define I4B_CA_COMMAND_FULL 1 /* may send any command */
89 #define I4B_CA_COMMAND_RESTRICTED 2 /* may send 'harmless' commands */
90 #define I4B_CA_EVNT_CHANSTATE 16 /* may watch b-channel states */
91 #define I4B_CA_EVNT_CALLIN 32 /* may watch incoming calls */
92 #define I4B_CA_EVNT_CALLOUT 64 /* may watch outgoing calls */
93 #define I4B_CA_EVNT_I4B 128 /* may watch isdnd actions */
96 * General layout of a command packet. All commands have this common
97 * prefix. It is prepared by the macro I4B_PREP_CMD (s.b.)
99 #define I4B_MON_CMD 0 /* 2 byte: command code */
100 #define I4B_MON_CMD_LEN 2 /* 2 byte: packet length */
101 #define I4B_MON_CMD_HDR 4 /* size of header */
104 * Currently events look the same as commands. We do not make
105 * any guarantee this will remain the same, so a different set
106 * of macros is used when describing events. Events are prepared
107 * by I4B_PREP_EVNT (s.b.)
109 #define I4B_MON_EVNT 0 /* 2 byte: event code */
110 #define I4B_MON_EVNT_LEN 2 /* 2 byte: packet length */
111 #define I4B_MON_EVNT_HDR 4 /* size of header */
113 /* Initial data send by daemon after connection is established */
114 #define I4B_MON_IDATA_SIZE I4B_MON_EVNT_HDR+12
115 #define I4B_MON_IDATA_CODE 0 /* event code */
116 #define I4B_MON_IDATA_VERSMAJOR I4B_MON_EVNT_HDR+0 /* 2 byte: isdnd major version */
117 #define I4B_MON_IDATA_VERSMINOR I4B_MON_EVNT_HDR+2 /* 2 byte: isdnd minor version */
118 #define I4B_MON_IDATA_NUMCTRL I4B_MON_EVNT_HDR+4 /* 2 byte: number of controllers */
119 #define I4B_MON_IDATA_NUMENTR I4B_MON_EVNT_HDR+6 /* 2 byte: number of controllers */
120 #define I4B_MON_IDATA_CLACCESS I4B_MON_EVNT_HDR+8 /* 4 byte: client rights */
122 /* followed by this for every controller */
123 #define I4B_MON_ICTRL_SIZE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+8
124 #define I4B_MON_ICTRL_CODE 1 /* event code */
125 #define I4B_MON_ICTRL_NAME I4B_MON_EVNT_HDR+0 /* string: name of controller */
126 #define I4B_MON_ICTRL_BUSID I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+0 /* 2 byte: isdn bus id (reservered) */
127 #define I4B_MON_ICTRL_FLAGS I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+2 /* 4 byte: controller flags (not yet defined) */
128 #define I4B_MON_ICTRL_NCHAN I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+6 /* 2 byte: number of b channels on this controller */
130 /* followed by this for every entry */
131 #define I4B_MON_IDEV_SIZE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+2
132 #define I4B_MON_IDEV_CODE 2 /* event code */
133 #define I4B_MON_IDEV_NAME I4B_MON_EVNT_HDR+0 /* string: name of device */
134 #define I4B_MON_IDEV_STATE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+0 /* 2 byte: state of device */
137 * The client sets it's protocol version and event mask (usually once after
138 * connection establishement)
140 #define I4B_MON_CCMD_SETMASK 0x7e /* command code */
141 #define I4B_MON_ICLIENT_SIZE I4B_MON_CMD_HDR+8
142 #define I4B_MON_ICLIENT_VERMAJOR I4B_MON_CMD_HDR+0 /* 2 byte: protocol major version (always 0 for now) */
143 #define I4B_MON_ICLIENT_VERMINOR I4B_MON_CMD_HDR+2 /* 2 byte: protocol minor version (always 0 for now) */
144 #define I4B_MON_ICLIENT_EVENTS I4B_MON_CMD_HDR+4 /* 4 byte: client event mask */
146 /* The client requests a list of monitor rights */
147 #define I4B_MON_DUMPRIGHTS_CODE 1
148 #define I4B_MON_DUMPRIGHTS_SIZE I4B_MON_CMD_HDR /* no parameters */
151 * in response to a I4B_MON_DUMPRIGHTS_CODE command, the daemon sends
152 * this event:
154 #define I4B_MON_DRINI_CODE 2 /* event code */
155 #define I4B_MON_DRINI_SIZE I4B_MON_EVNT_HDR+2 /* size of packet */
156 #define I4B_MON_DRINI_COUNT I4B_MON_EVNT_HDR+0 /* 2 byte: number of records */
158 /* followed by this for each record anounced above */
159 #define I4B_MON_DR_CODE 3
160 #define I4B_MON_DR_SIZE I4B_MON_EVNT_HDR+13
161 #define I4B_MON_DR_RIGHTS I4B_MON_EVNT_HDR+0 /* 4 byte: rights mask */
162 #define I4B_MON_DR_NET I4B_MON_EVNT_HDR+4 /* 4 byte: network address */
163 #define I4B_MON_DR_MASK I4B_MON_EVNT_HDR+8 /* 4 byte: network mask */
164 #define I4B_MON_DR_LOCAL I4B_MON_EVNT_HDR+12 /* 1 byte: non-zero if local socket */
166 /* The client requests a list of monitor connections */
167 #define I4B_MON_DUMPMCONS_CODE 2
168 #define I4B_MON_DUMPMCONS_SIZE I4B_MON_CMD_HDR /* no parameters */
171 * in response to a I4B_MON_DUMPMCONS_CODE command, the daemon sends
172 * this event:
174 #define I4B_MON_DCINI_CODE 4 /* event code */
175 #define I4B_MON_DCINI_SIZE I4B_MON_EVNT_HDR+2 /* size of packet */
176 #define I4B_MON_DCINI_COUNT I4B_MON_EVNT_HDR+0 /* 2 byte: number of records */
178 /* followed by this for each record anounced above */
179 #define I4B_MON_DC_CODE 5
180 #define I4B_MON_DC_SIZE I4B_MON_EVNT_HDR+8
181 #define I4B_MON_DC_RIGHTS I4B_MON_EVNT_HDR+0 /* 4 byte: rights mask */
182 #define I4B_MON_DC_WHO I4B_MON_EVNT_HDR+4 /* 4 byte: network address */
184 /* The client requests a config file rescan */
185 #define I4B_MON_CFGREREAD_CODE 3
186 #define I4B_MON_CFGREREAD_SIZE I4B_MON_CMD_HDR /* no parameters */
188 /* The client requests to hangup a connection */
189 #define I4B_MON_HANGUP_CODE 4
190 #define I4B_MON_HANGUP_SIZE I4B_MON_CMD_HDR+8
191 #define I4B_MON_HANGUP_CTRL I4B_MON_CMD_HDR+0 /* controller */
192 #define I4B_MON_HANGUP_CHANNEL I4B_MON_CMD_HDR+4 /* channel */
194 /* The daemon sends a logfile event */
195 #define I4B_MON_LOGEVNT_CODE 6
196 #define I4B_MON_LOGEVNT_SIZE I4B_MON_EVNT_HDR+8+2*I4B_MAX_MON_STRING
197 #define I4B_MON_LOGEVNT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: timestamp */
198 #define I4B_MON_LOGEVNT_PRIO I4B_MON_EVNT_HDR+4 /* 4 byte: syslog priority */
199 #define I4B_MON_LOGEVNT_WHAT I4B_MON_EVNT_HDR+8 /* followed by 2 strings: 'what' and 'message' */
200 #define I4B_MON_LOGEVNT_MSG I4B_MON_EVNT_HDR+8+I4B_MAX_MON_STRING
202 /* The daemon sends a charge event */
203 #define I4B_MON_CHRG_CODE 7
204 #define I4B_MON_CHRG_SIZE I4B_MON_EVNT_HDR+20
205 #define I4B_MON_CHRG_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: timestamp */
206 #define I4B_MON_CHRG_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel charged */
207 #define I4B_MON_CHRG_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel charged */
208 #define I4B_MON_CHRG_UNITS I4B_MON_EVNT_HDR+12 /* 4 byte: new charge value */
209 #define I4B_MON_CHRG_ESTIMATED I4B_MON_EVNT_HDR+16 /* 4 byte: 0 = charge by network, 1 = calculated estimate */
211 /* The daemon sends a connect event */
212 #define I4B_MON_CONNECT_CODE 8
213 #define I4B_MON_CONNECT_SIZE I4B_MON_EVNT_HDR+16+4*I4B_MAX_MON_STRING
214 #define I4B_MON_CONNECT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
215 #define I4B_MON_CONNECT_DIR I4B_MON_EVNT_HDR+4 /* 4 byte: direction (0 = incoming, 1 = outgoing) */
216 #define I4B_MON_CONNECT_CTRL I4B_MON_EVNT_HDR+8 /* 4 byte: channel connected */
217 #define I4B_MON_CONNECT_CHANNEL I4B_MON_EVNT_HDR+12 /* 4 byte: channel connected */
218 #define I4B_MON_CONNECT_CFGNAME I4B_MON_EVNT_HDR+16 /* name of config entry */
219 #define I4B_MON_CONNECT_DEVNAME I4B_MON_EVNT_HDR+16+I4B_MAX_MON_STRING /* name of device used for connection */
220 #define I4B_MON_CONNECT_REMPHONE I4B_MON_EVNT_HDR+16+2*I4B_MAX_MON_STRING /* remote phone no. */
221 #define I4B_MON_CONNECT_LOCPHONE I4B_MON_EVNT_HDR+16+3*I4B_MAX_MON_STRING /* local phone no. */
223 /* The daemon sends a disconnect event */
224 #define I4B_MON_DISCONNECT_CODE 9
225 #define I4B_MON_DISCONNECT_SIZE I4B_MON_EVNT_HDR+12
226 #define I4B_MON_DISCONNECT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
227 #define I4B_MON_DISCONNECT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel disconnected */
228 #define I4B_MON_DISCONNECT_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel disconnected */
230 /* The daemon sends an up/down event */
231 #define I4B_MON_UPDOWN_CODE 10
232 #define I4B_MON_UPDOWN_SIZE I4B_MON_EVNT_HDR+16
233 #define I4B_MON_UPDOWN_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
234 #define I4B_MON_UPDOWN_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel disconnected */
235 #define I4B_MON_UPDOWN_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel disconnected */
236 #define I4B_MON_UPDOWN_ISUP I4B_MON_EVNT_HDR+12 /* 4 byte: interface is up */
238 /* The daemon sends a L1/L2 status change event */
239 #define I4B_MON_L12STAT_CODE 11
240 #define I4B_MON_L12STAT_SIZE I4B_MON_EVNT_HDR+16
241 #define I4B_MON_L12STAT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
242 #define I4B_MON_L12STAT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */
243 #define I4B_MON_L12STAT_LAYER I4B_MON_EVNT_HDR+8 /* 4 byte: layer */
244 #define I4B_MON_L12STAT_STATE I4B_MON_EVNT_HDR+12 /* 4 byte: state */
246 /* The daemon sends a TEI change event */
247 #define I4B_MON_TEI_CODE 12
248 #define I4B_MON_TEI_SIZE I4B_MON_EVNT_HDR+12
249 #define I4B_MON_TEI_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
250 #define I4B_MON_TEI_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */
251 #define I4B_MON_TEI_TEI I4B_MON_EVNT_HDR+8 /* 4 byte: tei */
253 /* The daemon sends an accounting message event */
254 #define I4B_MON_ACCT_CODE 13
255 #define I4B_MON_ACCT_SIZE I4B_MON_EVNT_HDR+28
256 #define I4B_MON_ACCT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
257 #define I4B_MON_ACCT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */
258 #define I4B_MON_ACCT_CHAN I4B_MON_EVNT_HDR+8 /* 4 byte: channel */
259 #define I4B_MON_ACCT_OBYTES I4B_MON_EVNT_HDR+12 /* 4 byte: outbytes */
260 #define I4B_MON_ACCT_OBPS I4B_MON_EVNT_HDR+16 /* 4 byte: outbps */
261 #define I4B_MON_ACCT_IBYTES I4B_MON_EVNT_HDR+20 /* 4 byte: inbytes */
262 #define I4B_MON_ACCT_IBPS I4B_MON_EVNT_HDR+24 /* 4 byte: inbps */
264 /* macros for setup/decoding of protocol packets */
266 /* clear a record */
267 #define I4B_CLEAR(r) memset(&(r), 0, sizeof(r));
269 /* prepare a record as event or command */
270 #define I4B_PREP_EVNT(r, e) { \
271 I4B_CLEAR(r); \
272 I4B_PUT_2B(r, I4B_MON_EVNT, e); \
273 I4B_PUT_2B(r, I4B_MON_EVNT_LEN, sizeof(r)); \
275 #define I4B_PREP_CMD(r, c) { \
276 I4B_CLEAR(r); \
277 I4B_PUT_2B(r, I4B_MON_CMD, c); \
278 I4B_PUT_2B(r, I4B_MON_CMD_LEN, sizeof(r)); \
281 /* put 1, 2 or 4 bytes in network byte order into a record at offset off */
282 #define I4B_PUT_1B(r, off, val) { ((u_int8_t*)(r))[off] = (val) & 0x00ff; }
283 #define I4B_PUT_2B(r, off, val) { I4B_PUT_1B(r, off, val >> 8); I4B_PUT_1B(r, off+1, val); }
284 #define I4B_PUT_4B(r, off, val) { I4B_PUT_1B(r, off, val >> 24); I4B_PUT_1B(r, off+1, val >> 16); I4B_PUT_1B(r, off+2, val >> 8); I4B_PUT_1B(r, off+3, val); }
286 /* get 1, 2 or 4 bytes in network byte order from a record at offset off */
287 #define I4B_GET_1B(r, off) (((u_int8_t*)(r))[off])
288 #define I4B_GET_2B(r, off) ((((u_int8_t*)(r))[off]) << 8) | (((u_int8_t*)(r))[off+1])
289 #define I4B_GET_4B(r, off) ((((u_int8_t*)(r))[off]) << 24) | ((((u_int8_t*)(r))[off+1]) << 16) | ((((u_int8_t*)(r))[off+2]) << 8) | (((u_int8_t*)(r))[off+3])
292 * put a string into record r at offset off, make sure it's not to long
293 * and proper terminate it
295 #define I4B_PUT_STR(r, off, str) { \
296 strncpy((r)+(off), (str), I4B_MAX_MON_STRING); \
297 (r)[(off)+I4B_MAX_MON_STRING-1] = (u_int8_t)0; }
299 #endif /* _MONITOR_H_ */