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