automake: xpp: man-pages and perl-scripts
[dahdi/tools.git] / dahdi_maint.c
index d3019d2..6777510 100644 (file)
@@ -53,10 +53,14 @@ void display_help(char *argv0, int exitcode)
        fprintf(stderr, "        -h, --help             display help\n");
        fprintf(stderr, "        -s, --span <span num>  specify the span\n");
        fprintf(stderr, "        -l, --loopback <localhost|networkline|"\
-                                               "networkpayload|off>\n"\
+                                               "networkpayload|loopup|"\
+                                               "loopdown|off>\n"\
                        "\t\tlocalhost - loop back towards host\n"\
                        "\t\tnetworkline - network line loopback\n"\
-                       "\t\tnetworkpayload - network payload loopback\n");
+                       "\t\tnetworkpayload - network payload loopback\n"\
+                       "\t\tloopup - transmit loopup signal\n"\
+                       "\t\tloopdown - transmit loopdown signal\n"\
+                       "\t\toff - end loopback mode\n");
        fprintf(stderr, "        -i, --insert <fas|multi|crc|cas|prbs|bipolar>"\
                        "\n\t\tinsert an error of a specific type\n");
        fprintf(stderr, "        -r, --reset            "\
@@ -77,7 +81,6 @@ int main(int argc, char *argv[])
 
        int doloopback = 0;
        char *larg = NULL;
-       int sflag = 0;
        int span = 1;
        int iflag = 0;
        char *iarg = NULL;
@@ -105,16 +108,15 @@ int main(int argc, char *argv[])
        while ((c = getopt_long(argc, argv, "hj:l:p:s:i:g:r",
                                long_options, &option_index)) != -1) {
                        switch (c) {
-                       case 'h': /* local host loopback */
+                       case 'h':
                                display_help(argv[0], 0);
                                break;
-                       case 'l': /* network line loopback */
+                       case 'l': /* loopback */
                                larg = optarg;
                                doloopback = 1;
                                break;
                        case 's': /* specify a span */
                                span = atoi(optarg);
-                               sflag = 1;
                                break;
                        case 'i': /* insert an error */
                                iarg = optarg;
@@ -138,7 +140,7 @@ int main(int argc, char *argv[])
        if (!(doloopback || iflag || gflag || rflag)) {
                s.spanno = span;
                res = ioctl(ctl, DAHDI_SPANSTAT, &s);
-               if (res)
+               if (res || ((__u32)-1 == s.fecount))
                        printf("Error counters not supported by the driver"\
                                        " for this span\n");
                printf("Span %d:\n", span);
@@ -163,6 +165,12 @@ int main(int argc, char *argv[])
                } else if (!strcasecmp(larg, "networkpayload")) {
                        printf("Span %d: network payload loopback ON\n", span);
                        m.command = DAHDI_MAINT_NETWORKPAYLOADLOOP;
+               } else if (!strcasecmp(larg, "loopup")) {
+                       printf("Span %d: transmitting loopup signal\n", span);
+                       m.command = DAHDI_MAINT_LOOPUP;
+               } else if (!strcasecmp(larg, "loopdown")) {
+                       printf("Span %d: transmitting loopdown signal\n", span);
+                       m.command = DAHDI_MAINT_LOOPDOWN;
                } else if (!strcasecmp(larg, "off")) {
                        printf("Span %d: loopback OFF\n", span);
                        m.command = DAHDI_MAINT_NONE;
@@ -171,9 +179,21 @@ int main(int argc, char *argv[])
                }
 
                res = ioctl(ctl, DAHDI_MAINT, &m);
-               if (res)
+               if (res) {
                        printf("This type of looping not supported by the"\
                                        " driver for this span\n");
+                       return 1;
+               }
+
+               /* Leave the loopup/loopdown signal on the line for
+                * five seconds according to AT&T TR 54016
+                */
+               if ((m.command == DAHDI_MAINT_LOOPUP) ||
+                  (m.command == DAHDI_MAINT_LOOPDOWN)) {
+                       sleep(5);
+                       m.command = DAHDI_MAINT_NONE;
+                       ioctl(ctl, DAHDI_MAINT, &m);
+               }
        }
 
        if (iflag) {