2 * Channel configuration utility for Cronyx serial adapters.
4 * Copyright (C) 1997-2002 Cronyx Engineering.
5 * Author: Serge Vakulenko, <vak@cronyx.ru>
7 * Copyright (C) 1999-2005 Cronyx Engineering.
8 * Author: Roman Kurakin, <rik@cronyx.ru>
10 * This software is distributed with NO WARRANTIES, not even the implied
11 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * Authors grant any other persons or organisations permission to use
14 * or modify this software as long as this message is kept with the software,
15 * all derivative works or modified versions.
17 * Cronyx Id: sconfig.c,v 1.4.2.2 2005/11/09 13:01:35 rik Exp $
27 #include <sys/ioctl.h>
28 #include <sys/types.h>
30 #include <sys/socket.h>
32 #include <machine/cserial.h>
36 int vflag, eflag, sflag, mflag, cflag, fflag, iflag, aflag, xflag;
39 int adapter_type; /* 0-sigma, 1-tau, 2-taupci, 3-tau32 */
49 "Serial Adapter Configuration Utility\n"
50 "Copyright (C) 1998-2005 Cronyx Engineering.\n"
51 "See also man sconfig (8)\n"
53 "\tsconfig [-aimsxeftuc] [device [parameters ...]]\n"
56 "\t<no options>\t\t -- print channel options\n"
57 "\t-a\t\t\t -- print all settings of the channel\n"
58 "\t-i\t\t\t -- print network interface status\n"
59 "\t-m\t\t\t -- print modem signal status\n"
60 "\t-s\t\t\t -- print channel statistics\n"
61 "\t-x\t\t\t -- print extended channel statistics\n"
62 "\t-e\t\t\t -- print short E1/G703 statistics\n"
63 "\t-f\t\t\t -- print full E1/G703 statistics\n"
64 "\t-t\t\t\t -- print short E3/T3/STS-1 statistics\n"
65 "\t-u\t\t\t -- print full E3/T3/STS-1 statistics\n"
66 "\t-c\t\t\t -- clear statistics\n"
68 "\t<number>\t\t -- baud rate, internal clock\n"
69 "\textclock\t\t -- external clock (default)\n"
70 "\nProtocol options:\n"
71 "\tasync\t\t\t -- asynchronous protocol\n"
73 "\tsync\t\t\t -- synchronous protocol\n"
75 "\tcisco\t\t\t -- Cisco/HDLC protocol\n"
76 "\tfr\t\t\t -- Frame Relay protocol\n"
78 "\t dlci<number>\t -- Add new DLCI\n"
80 "\tppp\t\t\t -- PPP protocol\n"
82 "\trbrg\t\t\t -- Remote bridge\n"
83 "\traw\t\t\t -- raw HDLC protocol\n"
84 "\tpacket\t\t\t -- packetized HDLC protocol\n"
85 "\tidle\t\t\t -- no protocol\n"
87 "\t keepalive={on,of}\t -- Enable/disable keepalive\n"
89 "\nInterface options:\n"
90 "\tport={rs232,v35,rs449}\t -- port type (for old models of Sigma)\n"
91 "\tcfg={A,B,C}\t\t -- adapter configuration\n"
92 "\tloop={on,off}\t\t -- internal loopback\n"
93 "\trloop={on,off}\t\t -- remote loopback\n"
94 "\tdpll={on,off}\t\t -- DPLL mode\n"
95 "\tnrzi={on,off}\t\t -- NRZI encoding\n"
96 "\tinvclk={on,off}\t\t -- invert receive and transmit clock\n"
97 "\tinvrclk={on,off}\t -- invert receive clock\n"
98 "\tinvtclk={on,off}\t -- invert transmit clock\n"
99 "\thigain={on,off}\t\t -- E1 high non linear input sensitivity \n\t\t\t\t (long line)\n"
100 "\tmonitor={on,off}\t -- E1 high linear input sensitivity \n\t\t\t\t (interception mode)\n"
101 "\tphony={on,off}\t\t -- E1 telepnony mode\n"
102 "\tunfram={on,off}\t\t -- E1 unframed mode\n"
103 "\tscrambler={on,off}\t -- G.703 scrambling mode\n"
104 "\tuse16={on,off}\t\t -- E1 timeslot 16 usage\n"
105 "\tcrc4={on,off}\t\t -- E1 CRC4 mode\n"
107 "\tami={on,off}\t\t -- E1 AMI or HDB3 line code\n"
108 "\tmtu={size}\t\t -- set MTU in bytes\n"
110 "\tsyn={int,rcv,rcvX}\t -- G.703 transmit clock\n"
111 "\tts=...\t\t\t -- E1 timeslots\n"
112 "\tpass=...\t\t -- E1 subchannel timeslots\n"
113 "\tdir=<num>\t\t -- connect channel to link<num>\n"
114 /*"\trqken={size}\t\t -- set receive queue length in packets\n"*/
115 /*"\tcablen={on,off}\t\t -- T3/STS-1 high transmitter output for long cable\n"*/
116 "\tdebug={0,1,2}\t\t -- enable/disable debug messages\n"
122 scan_timeslots (char *s)
127 unsigned long ts, lastv;
131 v = strtol (s, &e, 10);
143 for (i=lastv; i<v; ++i)
162 int ppp_disc = N_PPP;
165 * Open a socket for doing the ioctl operations.
167 s = socket (AF_INET, SOCK_DGRAM, 0);
169 fprintf (stderr, "Error opening socket.\n");
172 strncpy (ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
173 if (ioctl (s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0) {
180 /* open pseudo-tty and try to set PPP discipline */
181 sprintf (pttyname, "/dev/ptyXX");
184 for (i=0; i<16; i++) {
187 *p1 = "pqrstuvwxyzabcde"[i];
189 if (stat (pttyname, &stb) < 0)
191 for (j=0; j<16; j++) {
192 *p2 = "0123456789abcdef"[j];
193 p = open (pttyname, 2);
195 if (ioctl (p, TIOCSETD, &ppp_disc) < 0) {
196 fprintf (stderr, "No PPP discipline in kernel.\n");
205 fprintf (stderr, "Cannot get pseudo-tty.\n");
213 format_timeslots (unsigned long s)
215 static char buf [100];
221 int prev = (i > 1) & (s >> (i-1));
222 int next = (i < 31) & (s >> (i+1));
240 print_modems (int fd, int need_header)
244 if (ioctl (fd, TIOCMGET, &status) < 0) {
245 perror ("getting modem status");
249 printf ("Channel\tLE\tDTR\tDSR\tRTS\tCTS\tCD\n");
250 printf ("%s\t%s\t%s\t%s\t%s\t%s\t%s\n", chan_name,
251 status & TIOCM_LE ? "On" : "-",
252 status & TIOCM_DTR ? "On" : "-",
253 status & TIOCM_DSR ? "On" : "-",
254 status & TIOCM_RTS ? "On" : "-",
255 status & TIOCM_CTS ? "On" : "-",
256 status & TIOCM_CD ? "On" : "-");
260 print_ifconfig (int fd)
266 if (ioctl (fd, SERIAL_GETPROTO, &protocol) >= 0 &&
267 strcmp (protocol, "fr") == 0)
268 sprintf (buf, "ifconfig %sd16 2>/dev/null", chan_name);
271 sprintf (buf, "ifconfig %s 2>/dev/null", chan_name);
276 format_long (unsigned long val)
280 l = sprintf (s, "%lu", val);
286 sprintf (s + 5, "%02d", l-1);
292 print_stats (int fd, int need_header)
294 struct serial_statistics st;
295 unsigned long sarr [9];
298 if (ioctl (fd, SERIAL_GETSTAT, &st) < 0) {
299 perror ("getting statistics");
304 printf (" ------------Receive----------- "
305 "------------Transmit----------\n");
306 printf ("Channel Interrupts Packets Errors "
307 "Interrupts Packets Errors\n");
310 printf (" --------Receive--------------- "
311 "--------Transmit-------------- Modem\n");
312 printf ("Channel Intrs Bytes Packets Errors "
313 "Intrs Bytes Packets Errors Intrs\n");
318 sarr [1] = st.ibytes;
322 sarr [5] = st.obytes;
326 printf ("%s", chan_name);
328 printf ("\t%-12lu%-12lu%-12lu%-12lu%-12lu%-12lu", sarr[0],
329 sarr[2], sarr[3], sarr[4], sarr[6], sarr[7]);
331 for (i = 0; i < 9; i++)
332 printf ("\t%s", format_long (sarr [i]));
340 if (ioctl (fd, SERIAL_CLRSTAT, 0) < 0) {
341 perror ("clearing statistics");
347 format_e1_status (unsigned long status)
349 static char buf [80];
353 if (status & E1_NOALARM)
356 if (status & E1_LOS) strcat (buf, ",LOS");
357 if (status & E1_AIS) strcat (buf, ",AIS");
358 if (status & E1_LOF) strcat (buf, ",LOF");
359 if (status & E1_LOMF) strcat (buf, ",LOMF");
360 if (status & E1_CRC4E) strcat (buf, ",CRC4E");
361 if (status & E1_FARLOF) strcat (buf, ",FARLOF");
362 if (status & E1_AIS16) strcat (buf, ",AIS16");
363 if (status & E1_FARLOMF) strcat (buf, ",FARLOMF");
364 /* if (status & E1_TSTREQ) strcat (buf, ",TSTREQ");*/
365 /* if (status & E1_TSTERR) strcat (buf, ",TSTERR");*/
372 print_frac (int leftalign, unsigned long numerator, unsigned long divider)
376 if (numerator < 1 || divider < 1) {
377 printf (leftalign ? "/- " : " -");
380 n = (int) (0.5 + 1000.0 * numerator / divider);
382 printf (leftalign ? "/.%-3d" : " .%03d", n);
385 putchar (leftalign ? '/' : ' ');
387 if (n >= 1000000) n = (n+500) / 1000 * 1000;
388 else if (n >= 100000) n = (n+50) / 100 * 100;
389 else if (n >= 10000) n = (n+5) / 10 * 10;
392 case 1000: printf (".999"); return;
393 case 10000: n = 9990; break;
394 case 100000: n = 99900; break;
395 case 1000000: n = 999000; break;
397 if (n < 10000) printf ("%d.%d", n/1000, n/10%100);
398 else if (n < 100000) printf ("%d.%d", n/1000, n/100%10);
399 else if (n < 1000000) printf ("%d.", n/1000);
400 else printf ("%d", n/1000);
404 print_e1_stats (int fd, int need_header)
406 struct e1_statistics st;
410 printf ("Chan\t Unav/Degr Bpv/Fsyn CRC/RCRC Err/Lerr Sev/Bur Oof/Slp Status\n");
412 if (ioctl (fd, SERIAL_GETESTAT, &st) < 0)
414 printf ("%s\t", chan_name);
416 /* Unavailable seconds, degraded minutes */
417 print_frac (0, st.currnt.uas, st.cursec);
418 print_frac (1, 60 * st.currnt.dm, st.cursec);
420 /* Bipolar violations, frame sync errors */
421 print_frac (0, st.currnt.bpv, st.cursec);
422 print_frac (1, st.currnt.fse, st.cursec);
424 /* CRC errors, remote CRC errors (E-bit) */
425 print_frac (0, st.currnt.crce, st.cursec);
426 print_frac (1, st.currnt.rcrce, st.cursec);
428 /* Errored seconds, line errored seconds */
429 print_frac (0, st.currnt.es, st.cursec);
430 print_frac (1, st.currnt.les, st.cursec);
432 /* Severely errored seconds, bursty errored seconds */
433 print_frac (0, st.currnt.ses, st.cursec);
434 print_frac (1, st.currnt.bes, st.cursec);
436 /* Out of frame seconds, controlled slip seconds */
437 print_frac (0, st.currnt.oofs, st.cursec);
438 print_frac (1, st.currnt.css, st.cursec);
440 printf (" %s\n", format_e1_status (st.status));
443 /* Print total statistics. */
445 print_frac (0, st.total.uas, st.totsec);
446 print_frac (1, 60 * st.total.dm, st.totsec);
448 print_frac (0, st.total.bpv, st.totsec);
449 print_frac (1, st.total.fse, st.totsec);
451 print_frac (0, st.total.crce, st.totsec);
452 print_frac (1, st.total.rcrce, st.totsec);
454 print_frac (0, st.total.es, st.totsec);
455 print_frac (1, st.total.les, st.totsec);
457 print_frac (0, st.total.ses, st.totsec);
458 print_frac (1, st.total.bes, st.totsec);
460 print_frac (0, st.total.oofs, st.totsec);
461 print_frac (1, st.total.css, st.totsec);
463 printf (" -- Total\n");
465 /* Print 24-hour history. */
466 maxi = (st.totsec - st.cursec) / 900;
469 for (i=0; i<maxi; ++i) {
471 print_frac (0, st.interval[i].uas, 15*60);
472 print_frac (1, 60 * st.interval[i].dm, 15*60);
474 print_frac (0, st.interval[i].bpv, 15*60);
475 print_frac (1, st.interval[i].fse, 15*60);
477 print_frac (0, st.interval[i].crce, 15*60);
478 print_frac (1, st.interval[i].rcrce, 15*60);
480 print_frac (0, st.interval[i].es, 15*60);
481 print_frac (1, st.interval[i].les, 15*60);
483 print_frac (0, st.interval[i].ses, 15*60);
484 print_frac (1, st.interval[i].bes, 15*60);
486 print_frac (0, st.interval[i].oofs, 15*60);
487 print_frac (1, st.interval[i].css, 15*60);
490 printf (" -- %dm\n", (i+1)*15);
492 printf (" -- %dh %dm\n", (i+1)/4, (i+1)%4*15);
498 format_e3_status (unsigned long status)
500 static char buf [80];
503 if (status & E3_LOS) strcat (buf, ",LOS");
504 if (status & E3_TXE) strcat (buf, ",XMIT");
511 format_e3_cv (unsigned long cv, unsigned long baud, unsigned long time)
515 if (!cv || !baud || !time)
516 sprintf (buf, " - ");
518 sprintf (buf, "%10lu (%.1e)", cv, (double)cv/baud/time);
523 print_e3_stats (int fd, int need_header)
525 struct e3_statistics st;
530 printf ("Chan\t--Code Violations---\t\t\t\t\t ----Status----\n");
532 if (ioctl (fd, SERIAL_GETE3STAT, &st) < 0 ||
533 ioctl (fd, SERIAL_GETBAUD, &baud) < 0)
539 printf ("%s\t%s\t\t\t\t\t", chan_name,
540 format_e3_cv (st.ccv, baud, st.cursec));
542 printf (" %s\n", format_e3_status (st.status));
546 /* Print total statistics. */
547 printf ("\t%s\t\t\t\t\t",
548 format_e3_cv (st.tcv, baud, st.totsec));
549 printf (" -- Total\n");
551 /* Print 24-hour history. */
552 maxi = (st.totsec - st.cursec) / 900;
555 for (i=0; i<maxi; ++i) {
556 printf ("\t%s\t\t\t\t\t",
557 format_e3_cv (st.icv[i], baud, 15*60));
559 printf (" -- %2dm\n", (i+1)*15);
561 printf (" -- %2dh %2dm\n", (i+1)/4, (i+1)%4*15);
571 int loop, dpll, nrzi, invclk, clk, higain, phony, use16, crc4;
572 int level, keepalive, debug, port, invrclk, invtclk, unfram, monitor;
573 int cable, dir, scrambler, ami, mtu;
574 int cablen, rloop, rqlen;
575 long baud, timeslots, subchan;
576 int protocol_valid, baud_valid, loop_valid, use16_valid, crc4_valid;
577 int dpll_valid, nrzi_valid, invclk_valid, clk_valid, phony_valid;
578 int timeslots_valid, subchan_valid, higain_valid, level_valid;
579 int keepalive_valid, debug_valid, cfg_valid, port_valid;
580 int invrclk_valid, invtclk_valid, unfram_valid, monitor_valid;
581 int cable_valid, dir_valid, scrambler_valid, ami_valid, mtu_valid;
582 int cablen_valid, rloop_valid, rqlen_valid;
584 protocol_valid = ioctl (fd, SERIAL_GETPROTO, &protocol) >= 0;
585 cfg_valid = ioctl (fd, SERIAL_GETCFG, &cfg) >= 0;
586 baud_valid = ioctl (fd, SERIAL_GETBAUD, &baud) >= 0;
587 loop_valid = ioctl (fd, SERIAL_GETLOOP, &loop) >= 0;
588 dpll_valid = ioctl (fd, SERIAL_GETDPLL, &dpll) >= 0;
589 nrzi_valid = ioctl (fd, SERIAL_GETNRZI, &nrzi) >= 0;
590 invclk_valid = ioctl (fd, SERIAL_GETINVCLK, &invclk) >= 0;
591 invrclk_valid = ioctl (fd, SERIAL_GETINVRCLK, &invrclk) >= 0;
592 invtclk_valid = ioctl (fd, SERIAL_GETINVTCLK, &invtclk) >= 0;
593 clk_valid = ioctl (fd, SERIAL_GETCLK, &clk) >= 0;
594 timeslots_valid = ioctl (fd, SERIAL_GETTIMESLOTS, ×lots) >= 0;
595 subchan_valid = ioctl (fd, SERIAL_GETSUBCHAN, &subchan) >= 0;
596 higain_valid = ioctl (fd, SERIAL_GETHIGAIN, &higain) >= 0;
597 phony_valid = ioctl (fd, SERIAL_GETPHONY, &phony) >= 0;
598 unfram_valid = ioctl (fd, SERIAL_GETUNFRAM, &unfram) >= 0;
599 monitor_valid = ioctl (fd, SERIAL_GETMONITOR, &monitor) >= 0;
600 use16_valid = ioctl (fd, SERIAL_GETUSE16, &use16) >= 0;
601 crc4_valid = ioctl (fd, SERIAL_GETCRC4, &crc4) >= 0;
602 ami_valid = ioctl (fd, SERIAL_GETLCODE, &ami) >= 0;
603 level_valid = ioctl (fd, SERIAL_GETLEVEL, &level) >= 0;
604 keepalive_valid = ioctl (fd, SERIAL_GETKEEPALIVE, &keepalive) >= 0;
605 debug_valid = ioctl (fd, SERIAL_GETDEBUG, &debug) >= 0;
606 port_valid = ioctl (fd, SERIAL_GETPORT, &port) >= 0;
607 cable_valid = ioctl (fd, SERIAL_GETCABLE, &cable) >= 0;
608 dir_valid = ioctl (fd, SERIAL_GETDIR, &dir) >= 0;
609 scrambler_valid = ioctl (fd, SERIAL_GETSCRAMBLER, &scrambler) >= 0;
610 cablen_valid = ioctl (fd, SERIAL_GETCABLEN, &cablen) >= 0;
611 rloop_valid = ioctl (fd, SERIAL_GETRLOOP, &rloop) >= 0;
612 mtu_valid = ioctl (fd, SERIAL_GETMTU, &mtu) >= 0;
613 rqlen_valid = ioctl (fd, SERIAL_GETRQLEN, &rqlen) >= 0;
615 printf ("%s", chan_name);
618 case 0: printf (" (rs232)"); break;
619 case 1: printf (" (v35)"); break;
620 case 2: printf (" (rs530)"); break;
622 else if (cable_valid)
624 case 0: printf (" (rs232)"); break;
625 case 1: printf (" (v35)"); break;
626 case 2: printf (" (rs530)"); break;
627 case 3: printf (" (x21)"); break;
628 case 4: printf (" (rs485)"); break;
629 case 9: printf (" (no cable)"); break;
631 if (debug_valid && debug)
632 printf (" debug=%d", debug);
633 if (protocol_valid && *protocol)
634 printf (" %.8s", protocol);
638 printf (" cablen=%s", cablen ? "on" : "off");
640 printf (" keepalive=%s", keepalive ? "on" : "off");
644 case 'a' : printf (" cfg=A"); break;
645 case 'b' : printf (" cfg=B"); break;
646 case 'c' : printf (" cfg=C"); break;
647 case 'd' : printf (" cfg=D"); break;
648 default : printf (" cfg=unknown");
651 printf (" dir=%d", dir);
655 printf (" %ld", baud);
657 printf (" extclock");
660 printf (" mtu=%d", mtu);
662 if (aflag && rqlen_valid)
663 printf (" rqlen=%d", rqlen);
667 case E1CLK_INTERNAL: printf (" syn=int"); break;
668 case E1CLK_RECEIVE: printf (" syn=rcv"); break;
669 case E1CLK_RECEIVE_CHAN0: printf (" syn=rcv0"); break;
670 case E1CLK_RECEIVE_CHAN1: printf (" syn=rcv1"); break;
671 case E1CLK_RECEIVE_CHAN2: printf (" syn=rcv2"); break;
672 case E1CLK_RECEIVE_CHAN3: printf (" syn=rcv3"); break;
673 default: printf (" syn=%d", clk); break;
677 printf (" dpll=%s", dpll ? "on" : "off");
679 printf (" nrzi=%s", nrzi ? "on" : "off");
681 printf (" invclk=%s", invclk ? "on" : "off");
683 printf (" invrclk=%s", invrclk ? "on" : "off");
685 printf (" invtclk=%s", invtclk ? "on" : "off");
687 printf (" unfram=%s", unfram ? "on" : "off");
689 printf (" use16=%s", use16 ? "on" : "off");
692 printf (" crc4=%s", crc4 ? "on" : "off");
694 printf (" higain=%s", higain ? "on" : "off");
696 printf (" monitor=%s", monitor ? "on" : "off");
698 printf (" phony=%s", phony ? "on" : "off");
700 printf (" scrambler=%s", scrambler ? "on" : "off");
702 printf (" loop=%s", loop ? "on" : "off");
704 printf (" rloop=%s", rloop ? "on" : "off");
706 printf (" ami=%s", ami ? "on" : "off");
709 printf (" ts=%s", format_timeslots (timeslots));
711 printf (" pass=%s", format_timeslots (subchan));
713 printf (" (level=-%.1fdB)", level / 10.0);
718 setup_chan (int fd, int argc, char **argv)
720 int i, mode, loop, nrzi, dpll, invclk, phony, use16, crc4, unfram, ami;
721 int higain, clk, keepalive, debug, port, dlci, invrclk, invtclk;
722 int monitor, dir, scrambler, rloop, cablen;
723 long baud, timeslots, mtu, rqlen;
725 for (i=0; i<argc; ++i) {
726 if (argv[i][0] >= '0' && argv[i][0] <= '9') {
727 baud = strtol (argv[i], 0, 10);
728 ioctl (fd, SERIAL_SETBAUD, &baud);
729 } else if (strcasecmp ("extclock", argv[i]) == 0) {
731 ioctl (fd, SERIAL_SETBAUD, &baud);
732 } else if (strncasecmp ("cfg=", argv[i], 4) == 0) {
733 if (strncasecmp ("a", argv[i]+4, 1) == 0)
734 ioctl (fd, SERIAL_SETCFG, "a");
735 else if (strncasecmp ("b", argv[i]+4, 1) == 0)
736 ioctl (fd, SERIAL_SETCFG, "b");
737 else if (strncasecmp ("c", argv[i]+4, 1) == 0)
738 ioctl (fd, SERIAL_SETCFG, "c");
739 else if (strncasecmp ("d", argv[i]+4, 1) == 0)
740 ioctl (fd, SERIAL_SETCFG, "d");
742 fprintf (stderr, "invalid cfg\n");
745 } else if (strcasecmp ("idle", argv[i]) == 0)
746 ioctl (fd, SERIAL_SETPROTO, "\0\0\0\0\0\0\0");
747 else if (strcasecmp ("async", argv[i]) == 0) {
749 if (ioctl (fd, SERIAL_SETMODE, &mode) >= 0)
750 ioctl (fd, SERIAL_SETPROTO, "async\0\0");
751 } else if (strcasecmp ("sync", argv[i]) == 0) {
753 if (ioctl (fd, SERIAL_SETMODE, &mode) >= 0)
754 ioctl (fd, SERIAL_SETPROTO, "sync\0\0\0");
755 } else if (strcasecmp ("cisco", argv[i]) == 0) {
757 ioctl (fd, SERIAL_SETMODE, &mode);
758 ioctl (fd, SERIAL_SETPROTO, "cisco\0\0");
759 } else if (strcasecmp ("rbrg", argv[i]) == 0) {
761 ioctl (fd, SERIAL_SETMODE, &mode);
762 ioctl (fd, SERIAL_SETPROTO, "rbrg\0\0\0");
763 } else if (strcasecmp ("raw", argv[i]) == 0) {
765 ioctl (fd, SERIAL_SETMODE, &mode);
766 ioctl (fd, SERIAL_SETPROTO, "raw\0\0\0\0");
767 } else if (strcasecmp ("packet", argv[i]) == 0) {
769 ioctl (fd, SERIAL_SETMODE, &mode);
770 ioctl (fd, SERIAL_SETPROTO, "packet\0");
771 } else if (strcasecmp ("ppp", argv[i]) == 0) {
772 /* check that ppp line discipline is present */
775 ioctl (fd, SERIAL_SETMODE, &mode);
776 ioctl (fd, SERIAL_SETPROTO, "ppp\0\0\0\0");
778 } else if (strncasecmp ("keepalive=", argv[i], 10) == 0) {
779 keepalive = (strcasecmp ("on", argv[i] + 10) == 0);
780 ioctl (fd, SERIAL_SETKEEPALIVE, &keepalive);
781 } else if (strcasecmp ("fr", argv[i]) == 0) {
783 ioctl (fd, SERIAL_SETMODE, &mode);
784 ioctl (fd, SERIAL_SETPROTO, "fr\0\0\0\0\0");
785 } else if (strcasecmp ("zaptel", argv[i]) == 0) {
787 ioctl (fd, SERIAL_SETMODE, &mode);
788 ioctl (fd, SERIAL_SETPROTO, "zaptel\0");
789 } else if (strncasecmp ("debug=", argv[i], 6) == 0) {
790 debug = strtol (argv[i]+6, 0, 10);
791 ioctl (fd, SERIAL_SETDEBUG, &debug);
792 } else if (strncasecmp ("loop=", argv[i], 5) == 0) {
793 loop = (strcasecmp ("on", argv[i] + 5) == 0);
794 ioctl (fd, SERIAL_SETLOOP, &loop);
795 } else if (strncasecmp ("rloop=", argv[i], 6) == 0) {
796 rloop = (strcasecmp ("on", argv[i] + 6) == 0);
797 ioctl (fd, SERIAL_SETRLOOP, &rloop);
798 } else if (strncasecmp ("dpll=", argv[i], 5) == 0) {
799 dpll = (strcasecmp ("on", argv[i] + 5) == 0);
800 ioctl (fd, SERIAL_SETDPLL, &dpll);
801 } else if (strncasecmp ("nrzi=", argv[i], 5) == 0) {
802 nrzi = (strcasecmp ("on", argv[i] + 5) == 0);
803 ioctl (fd, SERIAL_SETNRZI, &nrzi);
804 } else if (strncasecmp ("invclk=", argv[i], 7) == 0) {
805 invclk = (strcasecmp ("on", argv[i] + 7) == 0);
806 ioctl (fd, SERIAL_SETINVCLK, &invclk);
807 } else if (strncasecmp ("invrclk=", argv[i], 8) == 0) {
808 invrclk = (strcasecmp ("on", argv[i] + 8) == 0);
809 ioctl (fd, SERIAL_SETINVRCLK, &invrclk);
810 } else if (strncasecmp ("invtclk=", argv[i], 8) == 0) {
811 invtclk = (strcasecmp ("on", argv[i] + 8) == 0);
812 ioctl (fd, SERIAL_SETINVTCLK, &invtclk);
813 } else if (strncasecmp ("higain=", argv[i], 7) == 0) {
814 higain = (strcasecmp ("on", argv[i] + 7) == 0);
815 ioctl (fd, SERIAL_SETHIGAIN, &higain);
816 } else if (strncasecmp ("phony=", argv[i], 6) == 0) {
817 phony = (strcasecmp ("on", argv[i] + 6) == 0);
818 ioctl (fd, SERIAL_SETPHONY, &phony);
819 } else if (strncasecmp ("unfram=", argv[i], 7) == 0) {
820 unfram = (strcasecmp ("on", argv[i] + 7) == 0);
821 ioctl (fd, SERIAL_SETUNFRAM, &unfram);
822 } else if (strncasecmp ("scrambler=", argv[i], 10) == 0) {
823 scrambler = (strcasecmp ("on", argv[i] + 10) == 0);
824 ioctl (fd, SERIAL_SETSCRAMBLER, &scrambler);
825 } else if (strncasecmp ("monitor=", argv[i], 8) == 0) {
826 monitor = (strcasecmp ("on", argv[i] + 8) == 0);
827 ioctl (fd, SERIAL_SETMONITOR, &monitor);
828 } else if (strncasecmp ("use16=", argv[i], 6) == 0) {
829 use16 = (strcasecmp ("on", argv[i] + 6) == 0);
830 ioctl (fd, SERIAL_SETUSE16, &use16);
831 } else if (strncasecmp ("crc4=", argv[i], 5) == 0) {
832 crc4 = (strcasecmp ("on", argv[i] + 5) == 0);
833 ioctl (fd, SERIAL_SETCRC4, &crc4);
834 } else if (strncasecmp ("ami=", argv[i], 4) == 0) {
835 ami = (strcasecmp ("on", argv[i] + 4) == 0);
836 ioctl (fd, SERIAL_SETLCODE, &ami);
837 } else if (strncasecmp ("mtu=", argv[i], 4) == 0) {
838 mtu = strtol (argv[i] + 4, 0, 10);
839 ioctl (fd, SERIAL_SETMTU, &mtu);
840 } else if (strncasecmp ("rqlen=", argv[i], 6) == 0) {
841 rqlen = strtol (argv[i] + 6, 0, 10);
842 ioctl (fd, SERIAL_SETRQLEN, &rqlen);
843 } else if (strcasecmp ("syn=int", argv[i]) == 0) {
844 clk = E1CLK_INTERNAL;
845 ioctl (fd, SERIAL_SETCLK, &clk);
846 } else if (strcasecmp ("syn=rcv", argv[i]) == 0) {
848 ioctl (fd, SERIAL_SETCLK, &clk);
849 } else if (strcasecmp ("syn=rcv0", argv[i]) == 0) {
850 clk = E1CLK_RECEIVE_CHAN0;
851 ioctl (fd, SERIAL_SETCLK, &clk);
852 } else if (strcasecmp ("syn=rcv1", argv[i]) == 0) {
853 clk = E1CLK_RECEIVE_CHAN1;
854 ioctl (fd, SERIAL_SETCLK, &clk);
855 } else if (strcasecmp ("syn=rcv2", argv[i]) == 0) {
856 clk = E1CLK_RECEIVE_CHAN2;
857 ioctl (fd, SERIAL_SETCLK, &clk);
858 } else if (strcasecmp ("syn=rcv3", argv[i]) == 0) {
859 clk = E1CLK_RECEIVE_CHAN3;
860 ioctl (fd, SERIAL_SETCLK, &clk);
861 } else if (strncasecmp ("ts=", argv[i], 3) == 0) {
862 timeslots = scan_timeslots (argv[i] + 3);
863 ioctl (fd, SERIAL_SETTIMESLOTS, ×lots);
864 } else if (strncasecmp ("pass=", argv[i], 5) == 0) {
865 timeslots = scan_timeslots (argv[i] + 5);
866 ioctl (fd, SERIAL_SETSUBCHAN, ×lots);
867 } else if (strncasecmp ("dlci", argv[i], 4) == 0) {
868 dlci = strtol (argv[i]+4, 0, 10);
869 ioctl (fd, SERIAL_ADDDLCI, &dlci);
870 } else if (strncasecmp ("dir=", argv[i], 4) == 0) {
871 dir = strtol (argv[i]+4, 0, 10);
872 ioctl (fd, SERIAL_SETDIR, &dir);
873 } else if (strncasecmp ("port=", argv[i], 5) == 0) {
874 if (strncasecmp ("rs232", argv[i]+5, 5) == 0) {
876 ioctl (fd, SERIAL_SETPORT, &port);
877 } else if (strncasecmp ("v35", argv[i]+5, 3) == 0) {
879 ioctl (fd, SERIAL_SETPORT, &port);
880 } else if (strncasecmp ("rs449", argv[i]+5, 5) == 0) {
882 ioctl (fd, SERIAL_SETPORT, &port);
884 fprintf (stderr, "invalid port type\n");
887 } else if (strcasecmp ("reset", argv[i]) == 0) {
888 ioctl (fd, SERIAL_RESET, 0);
889 } else if (strcasecmp ("hwreset", argv[i]) == 0) {
890 ioctl (fd, SERIAL_HARDRESET, 0);
892 } else if (strncasecmp ("cablen=", argv[i], 7) == 0) {
893 loop = (strcasecmp ("on", argv[i] + 7) == 0);
894 ioctl (fd, SERIAL_SETCABLEN, &cablen);
905 fd = open ("/dev/serial/ctl0", 0);
907 perror ("/dev/serial/ctl0");
910 if (ioctl (fd, SERIAL_GETREGISTERED, &mask) < 0) {
911 perror ("getting list of channels");
916 int fd, fd1, fd2, fd3, i;
919 for (i=0, fd=-1; i<12 && fd<0; i++) {
920 sprintf (buf, "/dev/cx%d", i*4);
924 for (i=0, fd1=-1; i<3 && fd1<0; i++) {
925 sprintf (buf, "/dev/ct%d", i*2);
929 for (i=0, fd2=-1; i<3 && fd2<0; i++) {
930 sprintf (buf, "/dev/cp%d", i*4);
935 for (i=0, fd3=-1; i<1 && fd3<0; i++) {
936 sprintf (buf, "/dev/ce%d", i*4);
940 if ((fd < 0) && (fd1 < 0) && (fd2 < 0) && (fd3 < 0)) {
941 fprintf (stderr, "No Cronyx adapters installed\n");
946 if (ioctl (fd, SERIAL_GETREGISTERED, &mask) < 0) {
947 perror ("getting list of channels");
954 if (ioctl (fd1, SERIAL_GETREGISTERED, (mask+16)) < 0) {
955 perror ("getting list of channels");
962 if (ioctl (fd2, SERIAL_GETREGISTERED, (mask+32)) < 0) {
963 perror ("getting list of channels");
970 if (ioctl (fd3, SERIAL_GETREGISTERED, (mask+48)) < 0) {
971 perror ("getting list of channels");
980 open_chan_ctl (int num)
986 sprintf (device, "/dev/serial/ctl%d", num);
988 switch (adapter_type) {
990 sprintf (device, "/dev/cx%d", num);
993 sprintf (device, "/dev/ct%d", num);
996 sprintf (device, "/dev/cp%d", num);
999 sprintf (device, "/dev/ce%d", num);
1003 fd = open (device, 0);
1005 if (errno == ENODEV)
1006 fprintf (stderr, "chan%d: not configured\n", num);
1012 if (ioctl (fd, SERIAL_GETNAME, &chan_name) < 0)
1013 sprintf (chan_name, "chan%d", num);
1015 switch (adapter_type) {
1016 case 0: sprintf (chan_name, "cx%d", num); break;
1017 case 1: sprintf (chan_name, "ct%d", num); break;
1018 case 2: sprintf (chan_name, "cp%d", num); break;
1019 case 3: sprintf (chan_name, "ce%d", num); break;
1026 main (int argc, char **argv)
1029 int fd, need_header, chan_num;
1031 if (argc > 1 && strcmp(argv[1], "help") == 0)
1035 switch (getopt (argc, argv, "mseftucviax")) {
1086 for (; adapter_type < 4; ++adapter_type)
1089 for (chan_num=0; chan_num<MAXCHAN; ++chan_num)
1090 if (mask[adapter_type*16+chan_num/8] & 1 << (chan_num & 7)) {
1091 fd = open_chan_ctl (chan_num);
1095 if (ioctl (fd, SERIAL_GETVERSIONSTRING, &buf) >= 0) {
1096 printf ("Version: %s\n", buf);
1104 print_ifconfig (fd);
1105 } else if (sflag||xflag)
1106 print_stats (fd, need_header);
1108 print_modems (fd, need_header);
1110 print_e1_stats (fd, need_header);
1112 print_e3_stats (fd, need_header);
1124 p = argv[0] + strlen (argv[0]);
1125 while (p > argv[0] && p[-1] >= '0' && p[-1] <= '9')
1127 chan_num = strtol (p, 0, 10);
1129 if (strncasecmp ("cx", argv[0], 2)==0)
1131 else if (strncasecmp ("ct", argv[0], 2)==0)
1133 else if (strncasecmp ("cp", argv[0], 2)==0)
1135 else if (strncasecmp ("ce", argv[0], 2)==0)
1138 fprintf (stderr, "Wrong channel name\n");
1145 fd = open_chan_ctl (chan_num);
1149 if (ioctl (fd, SERIAL_GETVERSIONSTRING, &buf) >= 0)
1150 printf ("Version: %s\n", buf);
1155 print_ifconfig (fd);
1160 print_stats (fd, 1);
1165 print_modems (fd, 1);
1170 print_e1_stats (fd, 1);
1175 print_e3_stats (fd, 1);
1185 setup_chan (fd, argc, argv);