2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * main.c - i4b set debug options
28 * ------------------------------
30 * $FreeBSD: src/usr.sbin/i4b/isdndebug/main.c,v 1.8.2.1 2001/08/01 17:45:04 obrien Exp $
31 * $DragonFly: src/usr.sbin/i4b/isdndebug/main.c,v 1.3 2003/08/08 04:18:45 dillon Exp $
33 * last edit-date: [Mon May 21 10:09:23 2001]
35 *---------------------------------------------------------------------------*/
47 #include <sys/ioctl.h>
48 #include <sys/types.h>
51 #include <i4b_machine/i4b_debug.h>
52 #include <i4b_machine/i4b_ioctl.h>
54 char *bin_str(unsigned long val
, int length
);
56 static void usage ( void );
57 void printl1(unsigned long val
);
58 void printl2(unsigned long val
);
59 void printl3(unsigned long val
);
60 void printl4(unsigned long val
);
64 #define I4BCTLDEVICE "/dev/i4bctl"
79 /*---------------------------------------------------------------------------*
80 * usage display and exit
81 *---------------------------------------------------------------------------*/
85 fprintf(stderr
, "\n");
86 fprintf(stderr
, "isdndebug - i4b set debug level, version %d.%d.%d, compiled %s %s\n", VERSION
, REL
, STEP
, __DATE__
, __TIME__
);
87 fprintf(stderr
, "usage: isdndebug -c -e -g -l <layer> -m -q -r -s <value> -u <unit> -z -C -Q\n");
88 fprintf(stderr
, " -c get chipset statistics\n");
89 fprintf(stderr
, " -e set error only debugging output\n");
90 fprintf(stderr
, " -g get current debugging values\n");
91 fprintf(stderr
, " -l layer specify layer (1...4)\n");
92 fprintf(stderr
, " -m set maximum debugging output\n");
93 fprintf(stderr
, " -q get Q.921 statistics\n");
94 fprintf(stderr
, " -r reset values(s) to compiled in default\n");
95 fprintf(stderr
, " -s value set new debugging value for layer\n");
96 fprintf(stderr
, " -u unit unit number for -c, -q, -C and -Q commands\n");
97 fprintf(stderr
, " -z set zero (=no) debugging output\n");
98 fprintf(stderr
, " -C reset chipset statistics\n");
99 fprintf(stderr
, " -Q reset Q.921 statistics\n");
100 fprintf(stderr
, "\n");
104 /*---------------------------------------------------------------------------*
106 *---------------------------------------------------------------------------*/
108 main(int argc
, char **argv
)
114 while ((c
= getopt(argc
, argv
, "ceghl:mqrs:u:zCHQ")) != -1)
143 opt_layer
= atoi(optarg
);
144 if(opt_layer
< 1 || opt_layer
> 4)
149 if((sscanf(optarg
, "%i", &opt_setval
)) != 1)
155 opt_unit
= atoi(optarg
);
156 if(opt_unit
< 0 || opt_unit
> 9)
175 if(opt_get
== 0 && opt_set
== 0 && opt_reset
== 0 && opt_max
== 0 &&
176 opt_err
== 0 && opt_zero
== 0 && opt_lapd
== 0 && opt_rlapd
== 0 &&
182 if((opt_get
+ opt_set
+ opt_reset
+ opt_max
+ opt_err
+ opt_zero
+
183 opt_lapd
+ opt_rlapd
+ opt_chipstat
) > 1)
188 if((isdnfd
= open(I4BCTLDEVICE
, O_RDWR
)) < 0)
190 fprintf(stderr
, "i4bctl: cannot open %s: %s\n", I4BCTLDEVICE
, strerror(errno
));
199 cst
.driver_unit
= opt_unit
;
200 cst
.driver_bchannel
= 0;
202 if((ret
= ioctl(isdnfd
, I4B_CTL_GET_CHIPSTAT
, &cst
)) < 0)
204 fprintf(stderr
, "ioctl I4B_CTL_GET_CHIPSTAT failed: %s", strerror(errno
));
208 switch(cst
.driver_type
)
212 printf("\nisic-driver\nHSCX events: VFR RDO CRC RAB XDU RFO\n");
214 printf("unit %d chan %d: %6d %6d %6d %6d %6d %6d\n",
215 cst
.stats
.hscxstat
.unit
,
216 cst
.stats
.hscxstat
.chan
,
217 cst
.stats
.hscxstat
.vfr
,
218 cst
.stats
.hscxstat
.rdo
,
219 cst
.stats
.hscxstat
.crc
,
220 cst
.stats
.hscxstat
.rab
,
221 cst
.stats
.hscxstat
.xdu
,
222 cst
.stats
.hscxstat
.rfo
);
224 cst
.driver_unit
= opt_unit
;
225 cst
.driver_bchannel
= 1;
227 if((ret
= ioctl(isdnfd
, I4B_CTL_GET_CHIPSTAT
, &cst
)) < 0)
229 fprintf(stderr
, "ioctl I4B_CTL_GET_CHIPSTAT failed: %s", strerror(errno
));
233 printf("HSCX events: VFR RDO CRC RAB XDU RFO\n");
235 printf("unit %d chan %d: %6d %6d %6d %6d %6d %6d\n",
236 cst
.stats
.hscxstat
.unit
,
237 cst
.stats
.hscxstat
.chan
,
238 cst
.stats
.hscxstat
.vfr
,
239 cst
.stats
.hscxstat
.rdo
,
240 cst
.stats
.hscxstat
.crc
,
241 cst
.stats
.hscxstat
.rab
,
242 cst
.stats
.hscxstat
.xdu
,
243 cst
.stats
.hscxstat
.rfo
);
264 fprintf(stderr
, "ioctl I4B_CTL_GET_CHIPSTAT, unknown driver %d\n",cst
.driver_type
);
277 if((ret
= ioctl(isdnfd
, I4B_CTL_GET_LAPDSTAT
, &l2s
)) < 0)
279 fprintf(stderr
, "ioctl I4B_CTL_GET_LAPDSTAT failed: %s", strerror(errno
));
283 printf("unit %d Q.921 statistics: receive transmit\n", opt_unit
);
284 printf("---------------------------------------------\n");
285 printf("# of I-frames %12lu %12lu\n", l2s
.lapdstat
.rx_i
, l2s
.lapdstat
.tx_i
);
286 printf("# of RR-frames %12lu %12lu\n", l2s
.lapdstat
.rx_rr
, l2s
.lapdstat
.tx_rr
);
287 printf("# of RNR-frames %12lu %12lu\n", l2s
.lapdstat
.rx_rnr
, l2s
.lapdstat
.tx_rnr
);
288 printf("# of REJ-frames %12lu %12lu\n", l2s
.lapdstat
.rx_rej
, l2s
.lapdstat
.tx_rej
);
289 printf("# of SABME-frames %12lu %12lu\n", l2s
.lapdstat
.rx_sabme
, l2s
.lapdstat
.tx_sabme
);
290 printf("# of DM-frames %12lu %12lu\n", l2s
.lapdstat
.rx_dm
, l2s
.lapdstat
.tx_dm
);
291 printf("# of DISC-frames %12lu %12lu\n", l2s
.lapdstat
.rx_disc
, l2s
.lapdstat
.tx_disc
);
292 printf("# of UA-frames %12lu %12lu\n", l2s
.lapdstat
.rx_ua
, l2s
.lapdstat
.tx_ua
);
293 printf("# of FRMR-frames %12lu %12lu\n", l2s
.lapdstat
.rx_frmr
, l2s
.lapdstat
.tx_frmr
);
294 printf("# of TEI-frames %12lu %12lu\n", l2s
.lapdstat
.rx_tei
, l2s
.lapdstat
.tx_tei
);
295 printf("# of UI-frames %12lu \n", l2s
.lapdstat
.rx_ui
);
296 printf("# of XID-frames %12lu \n", l2s
.lapdstat
.rx_xid
);
298 printf("---------------------------------------------\n");
299 printf("# of frames with incorrect length%12lu\n", l2s
.lapdstat
.err_rx_len
);
300 printf("# of frames with bad frame type %12lu\n", l2s
.lapdstat
.err_rx_badf
);
301 printf("# of bad S frames %12lu\n", l2s
.lapdstat
.err_rx_bads
);
302 printf("# of bad U frames %12lu\n", l2s
.lapdstat
.err_rx_badu
);
303 printf("# of bad UI frames %12lu\n", l2s
.lapdstat
.err_rx_badui
);
314 if((ret
= ioctl(isdnfd
, I4B_CTL_CLR_LAPDSTAT
, &unit
)) < 0)
316 fprintf(stderr
, "ioctl I4B_CTL_CLR_LAPDSTAT failed: %s", strerror(errno
));
320 printf("Q.921 statistics counters unit %d reset to zero!\n", unit
);
324 if((ret
= ioctl(isdnfd
, I4B_CTL_GET_DEBUG
, &cdbg
)) < 0)
326 fprintf(stderr
, "ioctl I4B_CTL_GET_DEBUG failed: %s", strerror(errno
));
369 cdbg
.l1
= opt_setval
;
373 cdbg
.l2
= opt_setval
;
377 cdbg
.l3
= opt_setval
;
381 cdbg
.l4
= opt_setval
;
390 cdbg
.l1
= L1_DEBUG_DEFAULT
;
391 cdbg
.l2
= L2_DEBUG_DEFAULT
;
392 cdbg
.l3
= L3_DEBUG_DEFAULT
;
393 cdbg
.l4
= L4_DEBUG_DEFAULT
;
397 cdbg
.l1
= L1_DEBUG_DEFAULT
;
401 cdbg
.l2
= L2_DEBUG_DEFAULT
;
405 cdbg
.l3
= L3_DEBUG_DEFAULT
;
409 cdbg
.l4
= L4_DEBUG_DEFAULT
;
418 cdbg
.l1
= L1_DEBUG_MAX
;
419 cdbg
.l2
= L2_DEBUG_MAX
;
420 cdbg
.l3
= L3_DEBUG_MAX
;
421 cdbg
.l4
= L4_DEBUG_MAX
;
425 cdbg
.l1
= L1_DEBUG_MAX
;
429 cdbg
.l2
= L2_DEBUG_MAX
;
433 cdbg
.l3
= L3_DEBUG_MAX
;
437 cdbg
.l4
= L4_DEBUG_MAX
;
446 cdbg
.l1
= L1_DEBUG_ERR
;
447 cdbg
.l2
= L2_DEBUG_ERR
;
448 cdbg
.l3
= L3_DEBUG_ERR
;
449 cdbg
.l4
= L4_DEBUG_ERR
;
453 cdbg
.l1
= L1_DEBUG_ERR
;
457 cdbg
.l2
= L2_DEBUG_ERR
;
461 cdbg
.l3
= L3_DEBUG_ERR
;
465 cdbg
.l4
= L4_DEBUG_ERR
;
502 if((ret
= ioctl(isdnfd
, I4B_CTL_SET_DEBUG
, &cdbg
)) < 0)
504 fprintf(stderr
, "ioctl I4B_CTL_SET_DEBUG failed: %s", strerror(errno
));
510 /*---------------------------------------------------------------------------*
511 * return ptr to string of 1's and 0's for value
512 *---------------------------------------------------------------------------*/
514 bin_str(unsigned long val
, int length
)
516 static char buffer
[80];
522 val
= val
<< (32 - length
);
526 if (val
& 0x80000000)
530 if ((length
% 4) == 0 && length
)
537 /*---------------------------------------------------------------------------*
539 *---------------------------------------------------------------------------*/
541 printl1(unsigned long val
)
543 printf("\nLayer 1: %s = 0x%lX\n", bin_str(val
, 32), val
);
544 printf(" | |||| |||| |||| ||||\n"),
545 printf(" | |||| |||| |||| |||+- general error messages\n");
546 printf(" | |||| |||| |||| ||+-- PH primitives exchanged\n");
547 printf(" | |||| |||| |||| |+--- B channel actions\n");
548 printf(" | |||| |||| |||| +---- HSCX error messages\n");
549 printf(" | |||| |||| |||+------ HSCX IRQ messages\n");
550 printf(" | |||| |||| ||+------- ISAC error messages\n");
551 printf(" | |||| |||| |+-------- ISAC messages\n");
552 printf(" | |||| |||| +--------- ISAC setup messages\n");
553 printf(" | |||| |||+----------- FSM general messages\n");
554 printf(" | |||| ||+------------ FSM error messages\n");
555 printf(" | |||| |+------------- timer general messages\n");
556 printf(" | |||| +-------------- timer error messages\n");
557 printf(" | |||+---------------- HSCX data xfer errors msgs\n");
558 printf(" | ||+----------------- ISAC CICO messages\n");
559 printf(" | |+------------------ silent messages (soft-HDLC)\n");
560 printf(" | +------------------- error messages (soft-HDLC)\n");
561 printf(" +--------------------- HFC-S PCI debug messages\n");
562 printf(" ++++-++++-++++-+++---------------------- unassigned\n");
565 /*---------------------------------------------------------------------------*
567 *---------------------------------------------------------------------------*/
569 printl2(unsigned long val
)
571 printf("\nLayer 2: %s = 0x%lX\n", bin_str(val
, 32), val
);
572 printf(" || |||| |||| ||||\n"),
573 printf(" || |||| |||| |||+- general error messages\n");
574 printf(" || |||| |||| ||+-- DL primitives exchanged\n");
575 printf(" || |||| |||| |+--- U frame messages\n");
576 printf(" || |||| |||| +---- U frame error messages\n");
577 printf(" || |||| |||+------ S frame messages\n");
578 printf(" || |||| ||+------- S frame error messages\n");
579 printf(" || |||| |+-------- I frame messages\n");
580 printf(" || |||| +--------- I frame error messages\n");
581 printf(" || |||+----------- FSM general messages\n");
582 printf(" || ||+------------ FSM error messages\n");
583 printf(" || |+------------- timer general messages\n");
584 printf(" || +-------------- timer error messages\n");
585 printf(" |+---------------- TEI general messages\n");
586 printf(" +----------------- TEI error messages\n");
587 printf(" ++++-++++-++++-++++-++------------------ unassigned\n");
590 /*---------------------------------------------------------------------------*
592 *---------------------------------------------------------------------------*/
594 printl3(unsigned long val
)
596 printf("\nLayer 3: %s = 0x%lX\n", bin_str(val
, 32), val
);
597 printf(" ||| |||| ||||\n"),
598 printf(" ||| |||| |||+- general error messages\n");
599 printf(" ||| |||| ||+-- general messages\n");
600 printf(" ||| |||| |+--- FSM messages\n");
601 printf(" ||| |||| +---- FSM error messages\n");
602 printf(" ||| |||+------ timer messages\n");
603 printf(" ||| ||+------- timer error messages\n");
604 printf(" ||| |+-------- protocol messages\n");
605 printf(" ||| +--------- protocol error messages\n");
606 printf(" ||+----------- facility messages\n");
607 printf(" |+------------ facility error messages\n");
608 printf(" +------------- Q.931 messages exchanged\n");
609 printf(" ++++-++++-++++-++++-++++-+-------------- unassigned\n");
612 /*---------------------------------------------------------------------------*
614 *---------------------------------------------------------------------------*/
616 printl4(unsigned long val
)
618 printf("\nLayer 4: %s = 0x%lX\n", bin_str(val
, 32), val
);
619 printf(" ||| |||| ||||\n"),
620 printf(" ||| |||| |||+- general error messages\n");
621 printf(" ||| |||| ||+-- general messages\n");
622 printf(" ||| |||| |+--- B-ch timeout messages\n");
623 printf(" ||| |||| +---- network driver dial state\n");
624 printf(" ||| |||+------ ipr driver debug messages\n");
625 printf(" ||| ||+------- rbch driver debug messages\n");
626 printf(" ||| |+-------- isp driver debug messages\n");
627 printf(" ||| +--------- tel driver debug messages\n");
628 printf(" ||+----------- ing driver debug messages\n");
629 printf(" |+------------ iavc driver debug messages\n");
630 printf(" +------------- capi driver debug messages\n");
631 printf(" ++++-++++-++++-++++-++++---------------- unassigned\n");