1 /* $NetBSD: istat.c,v 1.5 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 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <sys/ioctl.h>
43 #include <netisdn/i4b_ioctl.h>
44 
45 #define LOG                     1
46 #define MEMR                    2
47 #define MEMW                    3
48 #define IOR                     4
49 #define IOW                     5
50 #define B1TEST                  6
51 #define B2TEST                  7
52 #define BTESTOFF                8
53 #define DSIG_STATS              9
54 #define B_CH_STATS              10
55 #define D_CH_STATS              11
56 #define BL1_STATS               12
57 #define BL1_STATS_C             13
58 #define DVERSION                14
59 
60 #define OK			0xff
61 #define MORE_EVENTS		0xfe
62 #define NO_EVENT		1
63 
64 struct DSigStruc
65 {
66   u_int8_t rc;
67   u_int8_t Id;
68   u_int8_t u;
69   u_int8_t listen;
70   u_int8_t active;
71   u_int8_t sin[3];
72   u_int8_t bc[6];
73   u_int8_t llc[6];
74   u_int8_t hlc[6];
75   u_int8_t oad[20];
76 };
77 
78 struct BL1Struc {
79   u_int8_t rc;
80   u_int32_t cx_b1;
81   u_int32_t cx_b2;
82   u_int32_t cr_b1;
83   u_int32_t cr_b2;
84   u_int32_t px_b1;
85   u_int32_t px_b2;
86   u_int32_t pr_b1;
87   u_int32_t pr_b2;
88   u_int16_t er_b1;
89   u_int16_t er_b2;
90 };
91 
92 struct L2Struc {
93   u_int8_t rc;
94   u_int32_t XTotal;
95   u_int32_t RTotal;
96   u_int16_t XError;
97   u_int16_t RError;
98 };
99 
100 static void printIE(u_int8_t *ie);
101 void istat(int fd, int controller);
102 void xversion(int fd, int controller);
103 
104 void
istat(int fd,int controller)105 istat(int fd, int controller)
106 {
107 	struct isdn_diagnostic_request req;
108 	printf("istat:\n");
109 	memset(&req, 0, sizeof(req));
110 
111 	req.controller = controller;
112 
113 	/* dump d-channel signaling tasks */
114 	{
115 		struct DSigStruc r;
116 		int ok = 1;
117 		req.cmd = DSIG_STATS;
118 		req.out_param_len = sizeof(r);
119 		req.out_param = &r;
120 
121 		printf("D-Channel Signaling Entities\n");
122 		printf("============================\n");
123 
124 		while (ok) {
125 			if (ioctl(fd, I4B_ACTIVE_DIAGNOSTIC, &req) == -1) {
126 				perror("ioctl(I4B_ACTIVE_DIAGNOSTIC)");
127 				return;
128 			}
129 			if (r.rc == OK)	/* last entry */
130 				ok = 0;
131 
132 			if (r.Id) {
133 				switch (r.sin[1]) {
134 				case 0:
135 					printf("Any Service Task");
136 					break;
137 				case 1:
138 					printf("Voice Task");
139 					break;
140 				case 2:
141 					printf("a/b Task");
142 					break;
143 				case 3:
144 					printf("X.21 Task");
145 					break;
146 				case 4:
147 					printf("Fax G4 Task");
148 					break;
149 				case 5:
150 					printf("Videotex Task");
151 					break;
152 				case 7:
153 					printf("Transparent Data Task");
154 					break;
155 				case 9:
156 					printf("Teletex 64 Task");
157 					break;
158 				}
159 				printf(", Id = %02X, State = %i\n",
160 				       r.Id,r.u);
161 				printf("\t");
162 				printf(" BC =");
163 				printIE(r.bc);
164 				printf(" LLC =");
165 				printIE(r.llc);
166 				printf(" HLC =");
167 				printIE(r.hlc);
168 				printf("\n");
169 			}
170 		}
171 	}
172 }
173 
174 static void
printIE(ie)175 printIE(ie)
176 	u_int8_t *ie;
177 {
178 	int i;
179 
180 	for (i = 0; i < ie[0]; i++)
181 		printf(" %02X", ie[i+1]);
182 }
183 
184 void
xversion(int fd,int controller)185 xversion(int fd, int controller)
186 {
187 	struct isdn_diagnostic_request req;
188 	char rcversion[50];
189 	memset(&req, 0, sizeof(req));
190 
191 	req.controller = controller;
192 	req.cmd = DVERSION;
193 	req.out_param_len = 49;
194 	req.out_param = &rcversion;
195 
196 	if (ioctl(fd, I4B_ACTIVE_DIAGNOSTIC, &req) == -1) {
197 		perror("");
198 		return;
199 	}
200 	rcversion[49] = '\0';
201 	printf("controller %d is running '%s'\n", controller, rcversion+1);
202 }
203