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 * ------------------------------
32 * last edit-date: [Mon May 21 10:09:23 2001]
34 *---------------------------------------------------------------------------*/
46 #include <sys/ioctl.h>
47 #include <sys/types.h>
50 #include <i4b/i4b_debug.h>
51 #include <i4b/i4b_ioctl.h>
53 char *bin_str(unsigned long val, int length);
55 static void usage ( void );
56 void printl1(unsigned long val);
57 void printl2(unsigned long val);
58 void printl3(unsigned long val);
59 void printl4(unsigned long val);
63 #define I4BCTLDEVICE "/dev/i4bctl"
78 /*---------------------------------------------------------------------------*
79 * usage display and exit
80 *---------------------------------------------------------------------------*/
84 fprintf(stderr, "\n");
85 fprintf(stderr, "isdndebug - i4b set debug level, version %d.%d.%d\n", VERSION, REL, STEP);
86 fprintf(stderr, "usage: isdndebug -c -e -g -l <layer> -m -q -r -s <value> -u <unit> -z -C -Q\n");
87 fprintf(stderr, " -c get chipset statistics\n");
88 fprintf(stderr, " -e set error only debugging output\n");
89 fprintf(stderr, " -g get current debugging values\n");
90 fprintf(stderr, " -l layer specify layer (1...4)\n");
91 fprintf(stderr, " -m set maximum debugging output\n");
92 fprintf(stderr, " -q get Q.921 statistics\n");
93 fprintf(stderr, " -r reset values(s) to compiled in default\n");
94 fprintf(stderr, " -s value set new debugging value for layer\n");
95 fprintf(stderr, " -u unit unit number for -c, -q, -C and -Q commands\n");
96 fprintf(stderr, " -z set zero (=no) debugging output\n");
97 fprintf(stderr, " -C reset chipset statistics\n");
98 fprintf(stderr, " -Q reset Q.921 statistics\n");
99 fprintf(stderr, "\n");
103 /*---------------------------------------------------------------------------*
105 *---------------------------------------------------------------------------*/
107 main(int argc, char **argv)
113 while ((c = getopt(argc, argv, "ceghl:mqrs:u:zCHQ")) != -1)
142 opt_layer = atoi(optarg);
143 if(opt_layer < 1 || opt_layer > 4)
148 if((sscanf(optarg, "%i", &opt_setval)) != 1)
154 opt_unit = atoi(optarg);
155 if(opt_unit < 0 || opt_unit > 9)
174 if(opt_get == 0 && opt_set == 0 && opt_reset == 0 && opt_max == 0 &&
175 opt_err == 0 && opt_zero == 0 && opt_lapd == 0 && opt_rlapd == 0 &&
181 if((opt_get + opt_set + opt_reset + opt_max + opt_err + opt_zero +
182 opt_lapd + opt_rlapd + opt_chipstat) > 1)
187 if((isdnfd = open(I4BCTLDEVICE, O_RDWR)) < 0)
189 fprintf(stderr, "i4bctl: cannot open %s: %s\n", I4BCTLDEVICE, strerror(errno));
198 cst.driver_unit = opt_unit;
199 cst.driver_bchannel = 0;
201 if((ret = ioctl(isdnfd, I4B_CTL_GET_CHIPSTAT, &cst)) < 0)
203 fprintf(stderr, "ioctl I4B_CTL_GET_CHIPSTAT failed: %s", strerror(errno));
207 switch(cst.driver_type)
211 printf("\nisic-driver\nHSCX events: VFR RDO CRC RAB XDU RFO\n");
213 printf("unit %d chan %d: %6d %6d %6d %6d %6d %6d\n",
214 cst.stats.hscxstat.unit,
215 cst.stats.hscxstat.chan,
216 cst.stats.hscxstat.vfr,
217 cst.stats.hscxstat.rdo,
218 cst.stats.hscxstat.crc,
219 cst.stats.hscxstat.rab,
220 cst.stats.hscxstat.xdu,
221 cst.stats.hscxstat.rfo);
223 cst.driver_unit = opt_unit;
224 cst.driver_bchannel = 1;
226 if((ret = ioctl(isdnfd, I4B_CTL_GET_CHIPSTAT, &cst)) < 0)
228 fprintf(stderr, "ioctl I4B_CTL_GET_CHIPSTAT failed: %s", strerror(errno));
232 printf("HSCX events: VFR RDO CRC RAB XDU RFO\n");
234 printf("unit %d chan %d: %6d %6d %6d %6d %6d %6d\n",
235 cst.stats.hscxstat.unit,
236 cst.stats.hscxstat.chan,
237 cst.stats.hscxstat.vfr,
238 cst.stats.hscxstat.rdo,
239 cst.stats.hscxstat.crc,
240 cst.stats.hscxstat.rab,
241 cst.stats.hscxstat.xdu,
242 cst.stats.hscxstat.rfo);
263 fprintf(stderr, "ioctl I4B_CTL_GET_CHIPSTAT, unknown driver %d\n",cst.driver_type);
276 if((ret = ioctl(isdnfd, I4B_CTL_GET_LAPDSTAT, &l2s)) < 0)
278 fprintf(stderr, "ioctl I4B_CTL_GET_LAPDSTAT failed: %s", strerror(errno));
282 printf("unit %d Q.921 statistics: receive transmit\n", opt_unit);
283 printf("---------------------------------------------\n");
284 printf("# of I-frames %12lu %12lu\n", l2s.lapdstat.rx_i, l2s.lapdstat.tx_i);
285 printf("# of RR-frames %12lu %12lu\n", l2s.lapdstat.rx_rr, l2s.lapdstat.tx_rr);
286 printf("# of RNR-frames %12lu %12lu\n", l2s.lapdstat.rx_rnr, l2s.lapdstat.tx_rnr);
287 printf("# of REJ-frames %12lu %12lu\n", l2s.lapdstat.rx_rej, l2s.lapdstat.tx_rej);
288 printf("# of SABME-frames %12lu %12lu\n", l2s.lapdstat.rx_sabme, l2s.lapdstat.tx_sabme);
289 printf("# of DM-frames %12lu %12lu\n", l2s.lapdstat.rx_dm, l2s.lapdstat.tx_dm);
290 printf("# of DISC-frames %12lu %12lu\n", l2s.lapdstat.rx_disc, l2s.lapdstat.tx_disc);
291 printf("# of UA-frames %12lu %12lu\n", l2s.lapdstat.rx_ua, l2s.lapdstat.tx_ua);
292 printf("# of FRMR-frames %12lu %12lu\n", l2s.lapdstat.rx_frmr, l2s.lapdstat.tx_frmr);
293 printf("# of TEI-frames %12lu %12lu\n", l2s.lapdstat.rx_tei, l2s.lapdstat.tx_tei);
294 printf("# of UI-frames %12lu \n", l2s.lapdstat.rx_ui);
295 printf("# of XID-frames %12lu \n", l2s.lapdstat.rx_xid);
297 printf("---------------------------------------------\n");
298 printf("# of frames with incorrect length%12lu\n", l2s.lapdstat.err_rx_len);
299 printf("# of frames with bad frame type %12lu\n", l2s.lapdstat.err_rx_badf);
300 printf("# of bad S frames %12lu\n", l2s.lapdstat.err_rx_bads);
301 printf("# of bad U frames %12lu\n", l2s.lapdstat.err_rx_badu);
302 printf("# of bad UI frames %12lu\n", l2s.lapdstat.err_rx_badui);
313 if((ret = ioctl(isdnfd, I4B_CTL_CLR_LAPDSTAT, &unit)) < 0)
315 fprintf(stderr, "ioctl I4B_CTL_CLR_LAPDSTAT failed: %s", strerror(errno));
319 printf("Q.921 statistics counters unit %d reset to zero!\n", unit);
323 if((ret = ioctl(isdnfd, I4B_CTL_GET_DEBUG, &cdbg)) < 0)
325 fprintf(stderr, "ioctl I4B_CTL_GET_DEBUG failed: %s", strerror(errno));
368 cdbg.l1 = opt_setval;
372 cdbg.l2 = opt_setval;
376 cdbg.l3 = opt_setval;
380 cdbg.l4 = opt_setval;
389 cdbg.l1 = L1_DEBUG_DEFAULT;
390 cdbg.l2 = L2_DEBUG_DEFAULT;
391 cdbg.l3 = L3_DEBUG_DEFAULT;
392 cdbg.l4 = L4_DEBUG_DEFAULT;
396 cdbg.l1 = L1_DEBUG_DEFAULT;
400 cdbg.l2 = L2_DEBUG_DEFAULT;
404 cdbg.l3 = L3_DEBUG_DEFAULT;
408 cdbg.l4 = L4_DEBUG_DEFAULT;
417 cdbg.l1 = L1_DEBUG_MAX;
418 cdbg.l2 = L2_DEBUG_MAX;
419 cdbg.l3 = L3_DEBUG_MAX;
420 cdbg.l4 = L4_DEBUG_MAX;
424 cdbg.l1 = L1_DEBUG_MAX;
428 cdbg.l2 = L2_DEBUG_MAX;
432 cdbg.l3 = L3_DEBUG_MAX;
436 cdbg.l4 = L4_DEBUG_MAX;
445 cdbg.l1 = L1_DEBUG_ERR;
446 cdbg.l2 = L2_DEBUG_ERR;
447 cdbg.l3 = L3_DEBUG_ERR;
448 cdbg.l4 = L4_DEBUG_ERR;
452 cdbg.l1 = L1_DEBUG_ERR;
456 cdbg.l2 = L2_DEBUG_ERR;
460 cdbg.l3 = L3_DEBUG_ERR;
464 cdbg.l4 = L4_DEBUG_ERR;
501 if((ret = ioctl(isdnfd, I4B_CTL_SET_DEBUG, &cdbg)) < 0)
503 fprintf(stderr, "ioctl I4B_CTL_SET_DEBUG failed: %s", strerror(errno));
509 /*---------------------------------------------------------------------------*
510 * return ptr to string of 1's and 0's for value
511 *---------------------------------------------------------------------------*/
513 bin_str(unsigned long val, int length)
515 static char buffer[80];
521 val = val << (32 - length);
525 if (val & 0x80000000)
529 if ((length % 4) == 0 && length)
536 /*---------------------------------------------------------------------------*
538 *---------------------------------------------------------------------------*/
540 printl1(unsigned long val)
542 printf("\nLayer 1: %s = 0x%lX\n", bin_str(val, 32), val);
543 printf(" | |||| |||| |||| ||||\n"),
544 printf(" | |||| |||| |||| |||+- general error messages\n");
545 printf(" | |||| |||| |||| ||+-- PH primitives exchanged\n");
546 printf(" | |||| |||| |||| |+--- B channel actions\n");
547 printf(" | |||| |||| |||| +---- HSCX error messages\n");
548 printf(" | |||| |||| |||+------ HSCX IRQ messages\n");
549 printf(" | |||| |||| ||+------- ISAC error messages\n");
550 printf(" | |||| |||| |+-------- ISAC messages\n");
551 printf(" | |||| |||| +--------- ISAC setup messages\n");
552 printf(" | |||| |||+----------- FSM general messages\n");
553 printf(" | |||| ||+------------ FSM error messages\n");
554 printf(" | |||| |+------------- timer general messages\n");
555 printf(" | |||| +-------------- timer error messages\n");
556 printf(" | |||+---------------- HSCX data xfer errors msgs\n");
557 printf(" | ||+----------------- ISAC CICO messages\n");
558 printf(" | |+------------------ silent messages (soft-HDLC)\n");
559 printf(" | +------------------- error messages (soft-HDLC)\n");
560 printf(" +--------------------- HFC-S PCI debug messages\n");
561 printf(" ++++-++++-++++-+++---------------------- unassigned\n");
564 /*---------------------------------------------------------------------------*
566 *---------------------------------------------------------------------------*/
568 printl2(unsigned long val)
570 printf("\nLayer 2: %s = 0x%lX\n", bin_str(val, 32), val);
571 printf(" || |||| |||| ||||\n"),
572 printf(" || |||| |||| |||+- general error messages\n");
573 printf(" || |||| |||| ||+-- DL primitives exchanged\n");
574 printf(" || |||| |||| |+--- U frame messages\n");
575 printf(" || |||| |||| +---- U frame error messages\n");
576 printf(" || |||| |||+------ S frame messages\n");
577 printf(" || |||| ||+------- S frame error messages\n");
578 printf(" || |||| |+-------- I frame messages\n");
579 printf(" || |||| +--------- I frame error messages\n");
580 printf(" || |||+----------- FSM general messages\n");
581 printf(" || ||+------------ FSM error messages\n");
582 printf(" || |+------------- timer general messages\n");
583 printf(" || +-------------- timer error messages\n");
584 printf(" |+---------------- TEI general messages\n");
585 printf(" +----------------- TEI error messages\n");
586 printf(" ++++-++++-++++-++++-++------------------ unassigned\n");
589 /*---------------------------------------------------------------------------*
591 *---------------------------------------------------------------------------*/
593 printl3(unsigned long val)
595 printf("\nLayer 3: %s = 0x%lX\n", bin_str(val, 32), val);
596 printf(" ||| |||| ||||\n"),
597 printf(" ||| |||| |||+- general error messages\n");
598 printf(" ||| |||| ||+-- general messages\n");
599 printf(" ||| |||| |+--- FSM messages\n");
600 printf(" ||| |||| +---- FSM error messages\n");
601 printf(" ||| |||+------ timer messages\n");
602 printf(" ||| ||+------- timer error messages\n");
603 printf(" ||| |+-------- protocol messages\n");
604 printf(" ||| +--------- protocol error messages\n");
605 printf(" ||+----------- facility messages\n");
606 printf(" |+------------ facility error messages\n");
607 printf(" +------------- Q.931 messages exchanged\n");
608 printf(" ++++-++++-++++-++++-++++-+-------------- unassigned\n");
611 /*---------------------------------------------------------------------------*
613 *---------------------------------------------------------------------------*/
615 printl4(unsigned long val)
617 printf("\nLayer 4: %s = 0x%lX\n", bin_str(val, 32), val);
618 printf(" ||| |||| ||||\n"),
619 printf(" ||| |||| |||+- general error messages\n");
620 printf(" ||| |||| ||+-- general messages\n");
621 printf(" ||| |||| |+--- B-ch timeout messages\n");
622 printf(" ||| |||| +---- network driver dial state\n");
623 printf(" ||| |||+------ ipr driver debug messages\n");
624 printf(" ||| ||+------- rbch driver debug messages\n");
625 printf(" ||| |+-------- isp driver debug messages\n");
626 printf(" ||| +--------- tel driver debug messages\n");
627 printf(" ||+----------- ing driver debug messages\n");
628 printf(" |+------------ iavc driver debug messages\n");
629 printf(" +------------- capi driver debug messages\n");
630 printf(" ++++-++++-++++-++++-++++---------------- unassigned\n");