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