1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
|
/*
* Copyright (c) 1997, 1998 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*---------------------------------------------------------------------------
*
* main.c - i4b set debug options
* ------------------------------
*
* $Id: main.c,v 1.13 1998/12/05 18:03:49 hm Exp $
*
* last edit-date: [Sat Dec 5 18:13:55 1998]
*
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <machine/i4b_debug.h>
#include <machine/i4b_ioctl.h>
char *bin_str(unsigned long val, int length);
static void usage ( void );
void printl1(unsigned long val);
void printl2(unsigned long val);
void printl3(unsigned long val);
void printl4(unsigned long val);
static int isdnfd;
#define I4BCTLDEVICE "/dev/i4bctl"
int opt_get = 0;
int opt_layer = -1;
int opt_set = 0;
int opt_setval;
int opt_reset = 0;
int opt_max = 0;
int opt_err = 0;
int opt_zero = 0;
int opt_unit = 0;
int opt_hscx = 0;
int opt_rhscx = 0;
/*---------------------------------------------------------------------------*
* program entry
*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
int c;
ctl_debug_t cdbg;
int ret;
while ((c = getopt(argc, argv, "eghl:mrs:u:zH?")) != EOF)
{
switch(c)
{
case 'e':
opt_err = 1;
break;
case 'g':
opt_get = 1;
break;
case 'h':
opt_hscx = 1;
break;
case 'r':
opt_reset = 1;
break;
case 'm':
opt_max = 1;
break;
case 'l':
opt_layer = atoi(optarg);
if(opt_layer < 1 || opt_layer > 4)
usage();
break;
case 's':
if((sscanf(optarg, "%i", &opt_setval)) != 1)
usage();
opt_set = 1;
break;
case 'u':
opt_unit = atoi(optarg);
if(opt_unit < 0 || opt_unit > 9)
usage();
break;
case 'z':
opt_zero = 1;
break;
case 'H':
opt_rhscx = 1;
break;
case '?':
default:
usage();
break;
}
}
if(opt_get == 0 && opt_set == 0 && opt_reset == 0 && opt_max == 0 &&
opt_err == 0 && opt_zero == 0 && opt_hscx == 0 && opt_rhscx == 0)
{
usage();
}
if((opt_get + opt_set + opt_reset + opt_max + opt_err + opt_zero +
opt_hscx + opt_rhscx) > 1)
{
usage();
}
if((isdnfd = open(I4BCTLDEVICE, O_RDWR)) < 0)
{
fprintf(stderr, "i4bctl: cannot open %s: %s\n", I4BCTLDEVICE, strerror(errno));
exit(1);
}
if(opt_hscx)
{
hscxstat_t hst;
hst.unit = opt_unit;
hst.chan = 0;
if((ret = ioctl(isdnfd, I4B_CTL_GET_HSCXSTAT, &hst)) < 0)
{
fprintf(stderr, "ioctl I4B_CTL_GET_HSCXSTAT failed: %s", strerror(errno));
exit(1);
}
printf("\nHSCX events: VFR RDO CRC RAB XDU RFO\n");
printf("unit %d chan %d: %6d %6d %6d %6d %6d %6d\n",
hst.unit, hst.chan,
hst.vfr, hst.rdo, hst.crc, hst.rab, hst.xdu, hst.rfo);
hst.unit = opt_unit;
hst.chan = 1;
if((ret = ioctl(isdnfd, I4B_CTL_GET_HSCXSTAT, &hst)) < 0)
{
fprintf(stderr, "ioctl I4B_CTL_GET_HSCXSTAT failed: %s", strerror(errno));
exit(1);
}
printf("unit %d chan %d: %6d %6d %6d %6d %6d %6d\n",
hst.unit, hst.chan,
hst.vfr, hst.rdo, hst.crc, hst.rab, hst.xdu, hst.rfo);
exit(0);
}
if(opt_rhscx)
{
hscxstat_t hst;
hst.unit = opt_unit;
hst.chan = 0;
if((ret = ioctl(isdnfd, I4B_CTL_CLR_HSCXSTAT, &hst)) < 0)
{
fprintf(stderr, "ioctl I4B_CTL_CLR_HSCXSTAT failed: %s", strerror(errno));
exit(1);
}
printf("HSCX event counters unit %d chan %d reset to zero!\n",
hst.unit, hst.chan);
hst.unit = opt_unit;
hst.chan = 1;
if((ret = ioctl(isdnfd, I4B_CTL_CLR_HSCXSTAT, &hst)) < 0)
{
fprintf(stderr, "ioctl I4B_CTL_CLR_HSCXSTAT failed: %s", strerror(errno));
exit(1);
}
printf("HSCX event counters unit %d chan %d reset to zero!\n",
hst.unit, hst.chan);
exit(0);
}
if((ret = ioctl(isdnfd, I4B_CTL_GET_DEBUG, &cdbg)) < 0)
{
fprintf(stderr, "ioctl I4B_CTL_GET_DEBUG failed: %s", strerror(errno));
exit(1);
}
if(opt_get)
{
switch(opt_layer)
{
case -1:
printl1(cdbg.l1);
printl2(cdbg.l2);
printl3(cdbg.l3);
printl4(cdbg.l4);
break;
case 1:
printl1(cdbg.l1);
break;
case 2:
printl2(cdbg.l2);
break;
case 3:
printl3(cdbg.l3);
break;
case 4:
printl4(cdbg.l4);
break;
}
printf("\n");
return(0);
}
else if(opt_set)
{
switch(opt_layer)
{
case -1:
usage();
break;
case 1:
cdbg.l1 = opt_setval;
break;
case 2:
cdbg.l2 = opt_setval;
break;
case 3:
cdbg.l3 = opt_setval;
break;
case 4:
cdbg.l4 = opt_setval;
break;
}
}
else if(opt_reset)
{
switch(opt_layer)
{
case -1:
cdbg.l1 = L1_DEBUG_DEFAULT;
cdbg.l2 = L2_DEBUG_DEFAULT;
cdbg.l3 = L3_DEBUG_DEFAULT;
cdbg.l4 = L4_DEBUG_DEFAULT;
break;
case 1:
cdbg.l1 = L1_DEBUG_DEFAULT;
break;
case 2:
cdbg.l2 = L2_DEBUG_DEFAULT;
break;
case 3:
cdbg.l3 = L3_DEBUG_DEFAULT;
break;
case 4:
cdbg.l4 = L4_DEBUG_DEFAULT;
break;
}
}
else if(opt_max)
{
switch(opt_layer)
{
case -1:
cdbg.l1 = L1_DEBUG_MAX;
cdbg.l2 = L2_DEBUG_MAX;
cdbg.l3 = L3_DEBUG_MAX;
cdbg.l4 = L4_DEBUG_MAX;
break;
case 1:
cdbg.l1 = L1_DEBUG_MAX;
break;
case 2:
cdbg.l2 = L2_DEBUG_MAX;
break;
case 3:
cdbg.l3 = L3_DEBUG_MAX;
break;
case 4:
cdbg.l4 = L4_DEBUG_MAX;
break;
}
}
else if(opt_err)
{
switch(opt_layer)
{
case -1:
cdbg.l1 = L1_DEBUG_ERR;
cdbg.l2 = L2_DEBUG_ERR;
cdbg.l3 = L3_DEBUG_ERR;
cdbg.l4 = L4_DEBUG_ERR;
break;
case 1:
cdbg.l1 = L1_DEBUG_ERR;
break;
case 2:
cdbg.l2 = L2_DEBUG_ERR;
break;
case 3:
cdbg.l3 = L3_DEBUG_ERR;
break;
case 4:
cdbg.l4 = L4_DEBUG_ERR;
break;
}
}
else if(opt_zero)
{
switch(opt_layer)
{
case -1:
cdbg.l1 = 0;
cdbg.l2 = 0;
cdbg.l3 = 0;
cdbg.l4 = 0;
break;
case 1:
cdbg.l1 = 0;
break;
case 2:
cdbg.l2 = 0;
break;
case 3:
cdbg.l3 = 0;
break;
case 4:
cdbg.l4 = 0;
break;
}
}
else
{
exit(1);
}
if((ret = ioctl(isdnfd, I4B_CTL_SET_DEBUG, &cdbg)) < 0)
{
fprintf(stderr, "ioctl I4B_CTL_SET_DEBUG failed: %s", strerror(errno));
exit(1);
}
return(0);
}
/*---------------------------------------------------------------------------*
* return ptr to string of 1's and 0's for value
*---------------------------------------------------------------------------*/
char *
bin_str(unsigned long val, int length)
{
static char buffer[80];
int i = 0;
if (length > 32)
length = 32;
val = val << (32 - length);
while (length--)
{
if (val & 0x80000000)
buffer[i++] = '1';
else
buffer[i++] = '0';
if ((length % 4) == 0 && length)
buffer[i++] = '.';
val = val << 1;
}
return (buffer);
}
/*---------------------------------------------------------------------------*
* print l1 info
*---------------------------------------------------------------------------*/
void
printl1(unsigned long val)
{
printf("\nLayer 1: %s = 0x%lX\n", bin_str(val, 32), val);
printf(" || |||| |||| ||||\n"),
printf(" || |||| |||| |||+- general error messages\n");
printf(" || |||| |||| ||+-- PH primitives exchanged\n");
printf(" || |||| |||| |+--- B channel actions\n");
printf(" || |||| |||| +---- HSCX error messages\n");
printf(" || |||| |||+------ HSCX IRQ messages\n");
printf(" || |||| ||+------- ISAC error messages\n");
printf(" || |||| |+-------- ISAC messages\n");
printf(" || |||| +--------- ISAC setup messages\n");
printf(" || |||+----------- FSM general messages\n");
printf(" || ||+------------ FSM error messages\n");
printf(" || |+------------- timer general messages\n");
printf(" || +-------------- timer error messages\n");
printf(" |+---------------- HSCX data xfer errors msgs\n");
printf(" +----------------- ISAC CICO messages\n");
printf(" ++++-++++-++++-++++-++------------------ unassigned\n");
}
/*---------------------------------------------------------------------------*
* print l2 info
*---------------------------------------------------------------------------*/
void
printl2(unsigned long val)
{
printf("\nLayer 2: %s = 0x%lX\n", bin_str(val, 32), val);
printf(" || |||| |||| ||||\n"),
printf(" || |||| |||| |||+- general error messages\n");
printf(" || |||| |||| ||+-- DL primitives exchanged\n");
printf(" || |||| |||| |+--- U frame messages\n");
printf(" || |||| |||| +---- U frame error messages\n");
printf(" || |||| |||+------ S frame messages\n");
printf(" || |||| ||+------- S frame error messages\n");
printf(" || |||| |+-------- I frame messages\n");
printf(" || |||| +--------- I frame error messages\n");
printf(" || |||+----------- FSM general messages\n");
printf(" || ||+------------ FSM error messages\n");
printf(" || |+------------- timer general messages\n");
printf(" || +-------------- timer error messages\n");
printf(" |+---------------- TEI general messages\n");
printf(" +----------------- TEI error messages\n");
printf(" ++++-++++-++++-++++-++------------------ unassigned\n");
}
/*---------------------------------------------------------------------------*
* print l3 info
*---------------------------------------------------------------------------*/
void
printl3(unsigned long val)
{
printf("\nLayer 3: %s = 0x%lX\n", bin_str(val, 32), val);
printf(" ||| |||| ||||\n"),
printf(" ||| |||| |||+- general error messages\n");
printf(" ||| |||| ||+-- general messages\n");
printf(" ||| |||| |+--- FSM messages\n");
printf(" ||| |||| +---- FSM error messages\n");
printf(" ||| |||+------ timer messages\n");
printf(" ||| ||+------- timer error messages\n");
printf(" ||| |+-------- protocol messages\n");
printf(" ||| +--------- protocol error messages\n");
printf(" ||+----------- facility messages\n");
printf(" |+------------ facility error messages\n");
printf(" +------------- Q.931 messages exchanged\n");
printf(" ++++-++++-++++-++++-++++-++------------- unassigned\n");
}
/*---------------------------------------------------------------------------*
* print l4 info
*---------------------------------------------------------------------------*/
void
printl4(unsigned long val)
{
printf("\nLayer 4: %s = 0x%lX\n", bin_str(val, 32), val);
printf(" || ||||\n"),
printf(" || |||+- general error messages\n");
printf(" || ||+-- general messages\n");
printf(" || |+--- B-ch timeout messages\n");
printf(" || +---- network driver dial state\n");
printf(" |+------ ipr driver debug messages\n");
printf(" +------- rbch driver debug messages\n");
printf(" ++++-++++-++++-++++-++++-++++-++-------- unassigned\n");
}
/*---------------------------------------------------------------------------*
* usage display and exit
*---------------------------------------------------------------------------*/
static void
usage(void)
{
fprintf(stderr, "\n");
fprintf(stderr, "isdndebug - i4b set debug level, version %02d.%02d, compiled %s %s\n", VERSION, REL, __DATE__, __TIME__);
fprintf(stderr, "usage: isdndebug -e -h -g -l <layer> -m -r -s <value> -u <unit> -z -H\n");
fprintf(stderr, " -e set error only debugging output\n");
fprintf(stderr, " -g get current debugging values\n");
fprintf(stderr, " -h get HSCX event counters\n");
fprintf(stderr, " -l layer specify layer (1...4)\n");
fprintf(stderr, " -m set maximum debugging output\n");
fprintf(stderr, " -r reset values(s) to compiled in default\n");
fprintf(stderr, " -s value set new debugging value for layer\n");
fprintf(stderr, " -u unit unit number for -h and -H commands\n");
fprintf(stderr, " -z set zero (=no) debugging output\n");
fprintf(stderr, " -H reset HSCX event counters to zero\n");
fprintf(stderr, "\n");
exit(1);
}
/* EOF */
|