Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / usr.sbin / isdn / isdnmonitor / monitor.h
blob32757e00968f258ab77aa3d6e3df19644958a0c4
1 /* $NetBSD: monitor.h,v 1.3 2003/11/12 13:31:07 grant Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin@NetBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _MONITOR_H_
33 #define _MONITOR_H_
35 #define DEF_MONPORT 451 /* default monitor TCP port */
37 #ifdef __hpux
38 #define u_int8_t ubit8
39 #define u_int32_t ubit32
40 #endif
41 #ifdef WIN32
42 #define u_int8_t BYTE
43 #define u_int32_t DWORD
44 #endif
47 * The monitor client connects to the isdnd daemon process via a tcp/ip
48 * connection from a remote machine or via a local (unix domain) socket.
49 * The daemon accepts multiple connections and verifies access rights.
50 * On connection establishment the daemon sends initial data telling
51 * the client the current configuration: number and type of available
52 * controllers, current connections, channel and interface states
53 * and the clients access privileges. The client sends an event mask
54 * telling the daemon which events it is interested in. If the client
55 * has appropriate rights he may send commands to the daemon.
57 * All multi-byte values are in network byte order!
60 /* All data packets transfered are declared as arrays of u_int8_t */
62 /* max stringlength used in this protocol */
63 #define I4B_MAX_MON_STRING 256
65 /* max command size from client to server */
66 #define I4B_MAX_MON_CLIENT_CMD 16
68 /* Version of the monitor protocol described here */
69 #define MPROT_VERSION 0 /* major version no */
70 #define MPROT_REL 5 /* release no */
73 * Client access rights
75 #define I4B_CA_COMMAND_FULL 1 /* may send any command */
76 #define I4B_CA_COMMAND_RESTRICTED 2 /* may send 'harmless' commands */
77 #define I4B_CA_EVNT_CHANSTATE 16 /* may watch b-channel states */
78 #define I4B_CA_EVNT_CALLIN 32 /* may watch incoming calls */
79 #define I4B_CA_EVNT_CALLOUT 64 /* may watch outgoing calls */
80 #define I4B_CA_EVNT_I4B 128 /* may watch isdnd actions */
83 * General layout of a command packet. All commands have this common
84 * prefix. It is prepared by the macro I4B_PREP_CMD (s.b.)
86 #define I4B_MON_CMD 0 /* 2 byte: command code */
87 #define I4B_MON_CMD_LEN 2 /* 2 byte: packet length */
88 #define I4B_MON_CMD_HDR 4 /* size of header */
91 * Currently events look the same as commands. We do not make
92 * any guarantee this will remain the same, so a different set
93 * of macros is used when describing events. Events are prepared
94 * by I4B_PREP_EVNT (s.b.)
96 #define I4B_MON_EVNT 0 /* 2 byte: event code */
97 #define I4B_MON_EVNT_LEN 2 /* 2 byte: packet length */
98 #define I4B_MON_EVNT_HDR 4 /* size of header */
100 /* Initial data send by daemon after connection is established */
101 #define I4B_MON_IDATA_SIZE I4B_MON_EVNT_HDR+12
102 #define I4B_MON_IDATA_CODE 0 /* event code */
103 #define I4B_MON_IDATA_VERSMAJOR I4B_MON_EVNT_HDR+0 /* 2 byte: isdnd major version */
104 #define I4B_MON_IDATA_VERSMINOR I4B_MON_EVNT_HDR+2 /* 2 byte: isdnd minor version */
105 #define I4B_MON_IDATA_NUMCTRL I4B_MON_EVNT_HDR+4 /* 2 byte: number of controllers */
106 #define I4B_MON_IDATA_NUMENTR I4B_MON_EVNT_HDR+6 /* 2 byte: number of controllers */
107 #define I4B_MON_IDATA_CLACCESS I4B_MON_EVNT_HDR+8 /* 4 byte: client rights */
109 /* followed by this for every controller */
110 #define I4B_MON_ICTRL_SIZE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+8
111 #define I4B_MON_ICTRL_CODE 1 /* event code */
112 #define I4B_MON_ICTRL_NAME I4B_MON_EVNT_HDR+0 /* string: name of controller */
113 #define I4B_MON_ICTRL_BUSID I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+0 /* 2 byte: isdn bus id (reservered) */
114 #define I4B_MON_ICTRL_FLAGS I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+2 /* 4 byte: controller flags (not yet defined) */
115 #define I4B_MON_ICTRL_NCHAN I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+6 /* 2 byte: number of b channels on this controller */
117 /* followed by this for every entry */
118 #define I4B_MON_IDEV_SIZE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+2
119 #define I4B_MON_IDEV_CODE 2 /* event code */
120 #define I4B_MON_IDEV_NAME I4B_MON_EVNT_HDR+0 /* string: name of device */
121 #define I4B_MON_IDEV_STATE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+0 /* 2 byte: state of device */
124 * The client sets it's protocol version and event mask (usually once after
125 * connection establishement)
127 #define I4B_MON_CCMD_SETMASK 0x7e /* command code */
128 #define I4B_MON_ICLIENT_SIZE I4B_MON_CMD_HDR+8
129 #define I4B_MON_ICLIENT_VERMAJOR I4B_MON_CMD_HDR+0 /* 2 byte: protocol major version (always 0 for now) */
130 #define I4B_MON_ICLIENT_VERMINOR I4B_MON_CMD_HDR+2 /* 2 byte: protocol minor version (always 0 for now) */
131 #define I4B_MON_ICLIENT_EVENTS I4B_MON_CMD_HDR+4 /* 4 byte: client event mask */
133 /* The client requests a list of monitor rights */
134 #define I4B_MON_DUMPRIGHTS_CODE 1
135 #define I4B_MON_DUMPRIGHTS_SIZE I4B_MON_CMD_HDR /* no parameters */
138 * in response to a I4B_MON_DUMPRIGHTS_CODE command, the daemon sends
139 * this event:
141 #define I4B_MON_DRINI_CODE 2 /* event code */
142 #define I4B_MON_DRINI_SIZE I4B_MON_EVNT_HDR+2 /* size of packet */
143 #define I4B_MON_DRINI_COUNT I4B_MON_EVNT_HDR+0 /* 2 byte: number of records */
145 /* followed by this for each record anounced above */
146 #define I4B_MON_DR_CODE 3
147 #define I4B_MON_DR_SIZE I4B_MON_EVNT_HDR+13
148 #define I4B_MON_DR_RIGHTS I4B_MON_EVNT_HDR+0 /* 4 byte: rights mask */
149 #define I4B_MON_DR_NET I4B_MON_EVNT_HDR+4 /* 4 byte: network address */
150 #define I4B_MON_DR_MASK I4B_MON_EVNT_HDR+8 /* 4 byte: network mask */
151 #define I4B_MON_DR_LOCAL I4B_MON_EVNT_HDR+12 /* 1 byte: non-zero if local socket */
153 /* The client requests a list of monitor connections */
154 #define I4B_MON_DUMPMCONS_CODE 2
155 #define I4B_MON_DUMPMCONS_SIZE I4B_MON_CMD_HDR /* no parameters */
158 * in response to a I4B_MON_DUMPMCONS_CODE command, the daemon sends
159 * this event:
161 #define I4B_MON_DCINI_CODE 4 /* event code */
162 #define I4B_MON_DCINI_SIZE I4B_MON_EVNT_HDR+2 /* size of packet */
163 #define I4B_MON_DCINI_COUNT I4B_MON_EVNT_HDR+0 /* 2 byte: number of records */
165 /* followed by this for each record anounced above */
166 #define I4B_MON_DC_CODE 5
167 #define I4B_MON_DC_SIZE I4B_MON_EVNT_HDR+8
168 #define I4B_MON_DC_RIGHTS I4B_MON_EVNT_HDR+0 /* 4 byte: rights mask */
169 #define I4B_MON_DC_WHO I4B_MON_EVNT_HDR+4 /* 4 byte: network address */
171 /* The client requests a config file rescan */
172 #define I4B_MON_CFGREREAD_CODE 3
173 #define I4B_MON_CFGREREAD_SIZE I4B_MON_CMD_HDR /* no parameters */
175 /* The client requests to hangup a connection */
176 #define I4B_MON_HANGUP_CODE 4
177 #define I4B_MON_HANGUP_SIZE I4B_MON_CMD_HDR+8
178 #define I4B_MON_HANGUP_CTRL I4B_MON_CMD_HDR+0 /* controller */
179 #define I4B_MON_HANGUP_CHANNEL I4B_MON_CMD_HDR+4 /* channel */
181 /* The daemon sends a logfile event */
182 #define I4B_MON_LOGEVNT_CODE 6
183 #define I4B_MON_LOGEVNT_SIZE I4B_MON_EVNT_HDR+8+2*I4B_MAX_MON_STRING
184 #define I4B_MON_LOGEVNT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: timestamp */
185 #define I4B_MON_LOGEVNT_PRIO I4B_MON_EVNT_HDR+4 /* 4 byte: syslog priority */
186 #define I4B_MON_LOGEVNT_WHAT I4B_MON_EVNT_HDR+8 /* followed by 2 strings: 'what' and 'message' */
187 #define I4B_MON_LOGEVNT_MSG I4B_MON_EVNT_HDR+8+I4B_MAX_MON_STRING
189 /* The daemon sends a charge event */
190 #define I4B_MON_CHRG_CODE 7
191 #define I4B_MON_CHRG_SIZE I4B_MON_EVNT_HDR+20
192 #define I4B_MON_CHRG_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: timestamp */
193 #define I4B_MON_CHRG_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel charged */
194 #define I4B_MON_CHRG_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel charged */
195 #define I4B_MON_CHRG_UNITS I4B_MON_EVNT_HDR+12 /* 4 byte: new charge value */
196 #define I4B_MON_CHRG_ESTIMATED I4B_MON_EVNT_HDR+16 /* 4 byte: 0 = charge by network, 1 = calculated estimate */
198 /* The daemon sends a connect event */
199 #define I4B_MON_CONNECT_CODE 8
200 #define I4B_MON_CONNECT_SIZE I4B_MON_EVNT_HDR+16+4*I4B_MAX_MON_STRING
201 #define I4B_MON_CONNECT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
202 #define I4B_MON_CONNECT_DIR I4B_MON_EVNT_HDR+4 /* 4 byte: direction (0 = incoming, 1 = outgoing) */
203 #define I4B_MON_CONNECT_CTRL I4B_MON_EVNT_HDR+8 /* 4 byte: channel connected */
204 #define I4B_MON_CONNECT_CHANNEL I4B_MON_EVNT_HDR+12 /* 4 byte: channel connected */
205 #define I4B_MON_CONNECT_CFGNAME I4B_MON_EVNT_HDR+16 /* name of config entry */
206 #define I4B_MON_CONNECT_DEVNAME I4B_MON_EVNT_HDR+16+I4B_MAX_MON_STRING /* name of device used for connection */
207 #define I4B_MON_CONNECT_REMPHONE I4B_MON_EVNT_HDR+16+2*I4B_MAX_MON_STRING /* remote phone no. */
208 #define I4B_MON_CONNECT_LOCPHONE I4B_MON_EVNT_HDR+16+3*I4B_MAX_MON_STRING /* local phone no. */
210 /* The daemon sends a disconnect event */
211 #define I4B_MON_DISCONNECT_CODE 9
212 #define I4B_MON_DISCONNECT_SIZE I4B_MON_EVNT_HDR+12
213 #define I4B_MON_DISCONNECT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
214 #define I4B_MON_DISCONNECT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel disconnected */
215 #define I4B_MON_DISCONNECT_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel disconnected */
217 /* The daemon sends an up/down event */
218 #define I4B_MON_UPDOWN_CODE 10
219 #define I4B_MON_UPDOWN_SIZE I4B_MON_EVNT_HDR+16
220 #define I4B_MON_UPDOWN_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
221 #define I4B_MON_UPDOWN_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel disconnected */
222 #define I4B_MON_UPDOWN_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel disconnected */
223 #define I4B_MON_UPDOWN_ISUP I4B_MON_EVNT_HDR+12 /* 4 byte: interface is up */
225 /* The daemon sends a L1/L2 status change event */
226 #define I4B_MON_L12STAT_CODE 11
227 #define I4B_MON_L12STAT_SIZE I4B_MON_EVNT_HDR+16
228 #define I4B_MON_L12STAT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
229 #define I4B_MON_L12STAT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */
230 #define I4B_MON_L12STAT_LAYER I4B_MON_EVNT_HDR+8 /* 4 byte: layer */
231 #define I4B_MON_L12STAT_STATE I4B_MON_EVNT_HDR+12 /* 4 byte: state */
233 /* The daemon sends a TEI change event */
234 #define I4B_MON_TEI_CODE 12
235 #define I4B_MON_TEI_SIZE I4B_MON_EVNT_HDR+12
236 #define I4B_MON_TEI_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
237 #define I4B_MON_TEI_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */
238 #define I4B_MON_TEI_TEI I4B_MON_EVNT_HDR+8 /* 4 byte: tei */
240 /* The daemon sends an accounting message event */
241 #define I4B_MON_ACCT_CODE 13
242 #define I4B_MON_ACCT_SIZE I4B_MON_EVNT_HDR+28
243 #define I4B_MON_ACCT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */
244 #define I4B_MON_ACCT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */
245 #define I4B_MON_ACCT_CHAN I4B_MON_EVNT_HDR+8 /* 4 byte: channel */
246 #define I4B_MON_ACCT_OBYTES I4B_MON_EVNT_HDR+12 /* 4 byte: outbytes */
247 #define I4B_MON_ACCT_OBPS I4B_MON_EVNT_HDR+16 /* 4 byte: outbps */
248 #define I4B_MON_ACCT_IBYTES I4B_MON_EVNT_HDR+20 /* 4 byte: inbytes */
249 #define I4B_MON_ACCT_IBPS I4B_MON_EVNT_HDR+24 /* 4 byte: inbps */
251 /* macros for setup/decoding of protocol packets */
253 /* clear a record */
254 #define I4B_CLEAR(r) memset(&(r), 0, sizeof(r));
256 /* prepare a record as event or command */
257 #define I4B_PREP_EVNT(r, e) { \
258 I4B_CLEAR(r); \
259 I4B_PUT_2B(r, I4B_MON_EVNT, e); \
260 I4B_PUT_2B(r, I4B_MON_EVNT_LEN, sizeof(r)); \
262 #define I4B_PREP_CMD(r, c) { \
263 I4B_CLEAR(r); \
264 I4B_PUT_2B(r, I4B_MON_CMD, c); \
265 I4B_PUT_2B(r, I4B_MON_CMD_LEN, sizeof(r)); \
268 /* put 1, 2 or 4 bytes in network byte order into a record at offset off */
269 #define I4B_PUT_1B(r, off, val) { ((u_int8_t*)(r))[off] = (val) & 0x00ff; }
270 #define I4B_PUT_2B(r, off, val) { I4B_PUT_1B(r, off, val >> 8); I4B_PUT_1B(r, off+1, val); }
271 #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); }
273 /* get 1, 2 or 4 bytes in network byte order from a record at offset off */
274 #define I4B_GET_1B(r, off) (((u_int8_t*)(r))[off])
275 #define I4B_GET_2B(r, off) ((((u_int8_t*)(r))[off]) << 8) | (((u_int8_t*)(r))[off+1])
276 #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])
279 * put a string into record r at offset off, make sure it's not to long
280 * and proper terminate it
282 #define I4B_PUT_STR(r, off, str) { \
283 strncpy((r)+(off), (str), I4B_MAX_MON_STRING); \
284 (r)[(off)+I4B_MAX_MON_STRING-1] = (u_int8_t)0; }
286 #endif /* _MONITOR_H_ */