summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/modem.c
blob: 67aa08ec4f0d333549ced4b8b1654b6b9d6732ce (plain)
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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
/*
 *		PPP Modem handling module
 *
 *	    Written by Toshiharu OHNO (tony-o@iij.ad.jp)
 *
 *   Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the Internet Initiative Japan, Inc.  The name of the
 * IIJ may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * $Id: modem.c,v 1.26 1996/12/22 17:29:32 jkh Exp $
 *
 *  TODO:
 */
#include "fsm.h"
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <errno.h>
#include <time.h>
#include "hdlc.h"
#include "lcp.h"
#include "ip.h"
#include "modem.h"
#include "vars.h"

#ifndef O_NONBLOCK
#ifdef O_NDELAY
#define O_NONBLOCK O_NDELAY
#endif
#endif

extern int DoChat();

static int mbits;			/* Current DCD status */
static int connect_time;		/* connection time */
static int connect_count;
static struct pppTimer ModemTimer;
static char uucplock[10];

extern int uu_lock(), uu_unlock();
extern void PacketMode(), TtyTermMode(), TtyCommandMode();
extern int TermMode;

#define	Online	(mbits & TIOCM_CD)

static struct mbuf *modemout;
static struct mqueue OutputQueues[PRI_LINK+1];
static int dev_is_modem;

#undef QDEBUG

void
Enqueue(queue, bp)
struct mqueue *queue;
struct mbuf *bp;
{
  if (queue->last) {
    queue->last->pnext = bp;
    queue->last = bp;
  } else
    queue->last = queue->top = bp;
  queue->qlen++;
#ifdef QDEBUG
  logprintf("Enqueue: len = %d\n", queue->qlen);
#endif
}

struct mbuf *
Dequeue(queue)
struct mqueue *queue;
{
  struct mbuf *bp;

#ifdef QDEBUG
  logprintf("Dequeue: len = %d\n", queue->qlen);
#endif
  bp = queue->top;
  if (bp) {
    queue->top = queue->top->pnext;
    queue->qlen--;
    if (queue->top == NULL) {
      queue->last = queue->top;
#ifdef QDEBUG
      if (queue->qlen)
	logprintf("!!! not zero (%d)!!!\n", queue->qlen);
#endif
    }
  }
  return(bp);
}

static struct speeds{
  int nspeed;
  speed_t speed;
} speeds[] = {
#ifdef B50
  { 50, B50, },
#endif
#ifdef B75
  { 75, B75, },
#endif
#ifdef B110
  { 110, B110, },
#endif
#ifdef B134
  { 134, B134, },
#endif
#ifdef B150
  { 150, B150, },
#endif
#ifdef B200
  { 200, B200, },
#endif
#ifdef B300
  { 300, B300, },
#endif
#ifdef B600
  { 600, B600, },
#endif
#ifdef B1200
  { 1200, B1200, },
#endif
#ifdef B1800
  { 1800, B1800, },
#endif
#ifdef B2400
  { 2400, B2400, },
#endif
#ifdef B4800
  { 4800, B4800, },
#endif
#ifdef B9600
  { 9600, B9600, },
#endif
#ifdef B19200
  { 19200, B19200, },
#endif
#ifdef B38400
  { 38400, B38400, },
#endif
#ifndef _POSIX_SOURCE
#ifdef B7200
  { 7200, B7200, },
#endif
#ifdef B14400
  { 14400, B14400, },
#endif
#ifdef B28800
  { 28800, B28800, },
#endif
#ifdef B57600
  { 57600, B57600, },
#endif
#ifdef B76800
  { 76800, B76800, },
#endif
#ifdef B115200
  { 115200, B115200, },
#endif
#ifdef B230400
  { 230400, B230400, },
#endif
#ifdef EXTA
  { 19200, EXTA, },
#endif
#ifdef EXTB
  { 38400, EXTB, },
#endif
#endif  /*_POSIX_SOURCE */
  { 0, 0 }
};

int SpeedToInt(speed)
speed_t speed;
{
  struct speeds *sp;

  for (sp = speeds; sp->nspeed; sp++) {
    if (sp->speed == speed) {
      return(sp->nspeed);
    }
  }
  return 0;
}

speed_t IntToSpeed(nspeed)
int nspeed;
{
  struct speeds *sp;

  for (sp = speeds; sp->nspeed; sp++) {
    if (sp->nspeed == nspeed) {
      return(sp->speed);
    }
  }
  return B0;
}

static time_t uptime;

void
DownConnection()
{
  LogPrintf(LOG_PHASE_BIT, "Disconnected!\n");
  LogPrintf(LOG_PHASE_BIT, "Connect time: %d secs\n", time(NULL) - uptime);
  if (!TermMode) {
    CloseModem();
    LcpDown();
  }
  connect_time = 0;
}

/*
 *  ModemTimeout() watches DCD signal and notifies if it's status is changed.
 *
 */
void
ModemTimeout()
{
  int ombits = mbits;
  int change;

  StopTimer(&ModemTimer);
  if (Online)
    connect_time++;
  StartTimer(&ModemTimer);

  if (dev_is_modem) {
    ioctl(modem, TIOCMGET, &mbits);
    change = ombits ^ mbits;
    if (change & TIOCM_CD) {
      if (Online) {
        time(&uptime);
        LogPrintf(LOG_PHASE_BIT, "*Connected!\n");
        connect_count++;
        /*
         * In dedicated mode, start packet mode immediate
         * after we detected carrier.
         */
        if (mode & MODE_DEDICATED)
	  PacketMode();
      } else {
	DownConnection();
      }
    }
  } else {
    if (!Online) {
      time(&uptime);
      LogPrintf(LOG_PHASE_BIT, "Connected!\n");
      mbits = TIOCM_CD;
      connect_count++;
      connect_time = 0;
    } else if (uptime == 0) {
      time(&uptime);
    }
  }
}

void
StartModemTimer()
{
  connect_time = 0;
  StopTimer(&ModemTimer);
  ModemTimer.state = TIMER_STOPPED;
  ModemTimer.load = SECTICKS;
  ModemTimer.func = ModemTimeout;
  StartTimer(&ModemTimer);
}

struct parity {
  char *name;
  char *name1;
  int  set;
} validparity[] = {
  { "even", "P_EVEN", CS7 | PARENB }, { "odd", "P_ODD", CS7 | PARENB | PARODD },
  { "none", "P_ZERO", CS8 },          { NULL,  0 },
};

int
GetParityValue(str)
char *str;
{
  struct parity *pp;

  for (pp = validparity; pp->name; pp++) {
    if (strcasecmp(pp->name, str) == 0 ||
	strcasecmp(pp->name1, str) == 0) {
      VarParity = pp->set;
      return(pp->set);
    }
  }
  return(-1);
}

int
ChangeParity(str)
char *str;
{
  struct termios rstio;
  int val;

  val = GetParityValue(str);
  if (val > 0) {
    VarParity = val;
    tcgetattr(modem, &rstio);
    rstio.c_cflag &= ~(CSIZE|PARODD|PARENB);
    rstio.c_cflag |= val;
    tcsetattr(modem, TCSADRAIN, &rstio);
  }
  return(val);
}

#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>

int
OpenConnection(host, port)
char *host, *port;
{
  struct sockaddr_in dest;
  int sock;
  struct hostent *hp;
  struct servent *sp;

  dest.sin_family = AF_INET;
  dest.sin_addr.s_addr = inet_addr(host);
  if (dest.sin_addr.s_addr == INADDR_NONE) {
    hp = gethostbyname(host);
    if (hp) {
      bcopy(hp->h_addr_list[0], &dest.sin_addr.s_addr, 4);
    } else {
      printf("unknown host: %s\n", host);
      return(-1);
    }
  }
  dest.sin_port = htons(atoi(port));
  if (dest.sin_port == 0) {
    sp = getservbyname(port, "tcp");
    if (sp) {
      dest.sin_port = sp->s_port;
    } else {
      printf("unknown service: %s\n", port);
      return(-1);
    }
  }
  LogPrintf(LOG_PHASE_BIT, "Connected to %s:%s\n", host, port);

  sock = socket(PF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    return(sock);
  }
  if (connect(sock, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
    printf("connection failed.\n");
    return(-1);
  }
  return(sock);
}

static struct termios modemios;

int
OpenModem(mode)
int mode;
{
  struct termios rstio;
  int oldflag;
  char *host, *cp, *port;

  mbits = 0;
  if (mode & MODE_DIRECT) {
    if (isatty(0))
      modem = open(ctermid(NULL), O_RDWR|O_NONBLOCK);
  } else if (modem == 0) {
    if (strncmp(VarDevice, "/dev", 4) == 0) {
      strncpy(uucplock, rindex(VarDevice, '/')+1,sizeof(uucplock)-1);
      uucplock[sizeof(uucplock)-1] = '\0';
      if (uu_lock(uucplock) < 0) {
        LogPrintf(LOG_PHASE_BIT, "Modem %s is in use\n", VarDevice);
        return(-1);
      }
      modem = open(VarDevice, O_RDWR|O_NONBLOCK);
      if (modem < 0) {
        LogPrintf(LOG_PHASE_BIT, "Open Failed %s\n", VarDevice);
        (void) uu_unlock(uucplock);
        return(modem);
      }
    } else {
      /* XXX: PPP over TCP */
      cp = index(VarDevice, ':');
      if (cp) {
	*cp = 0;
	host = VarDevice;
	port =  cp + 1;
	if (*host && *port) {
	  modem = OpenConnection(host, port);
          *cp = ':';	/* Don't destroy VarDevice */
	  if (modem < 0) return(-1);
	} else {
          *cp = ':';	/* Don't destroy VarDevice */
	  return(-1);
	}
      } else
	return(-1);
    }
  }

  /* This code gets around the problem of closing descriptor 0
   * when it should not have been closed and closing descriptor 1
   * when the telnet connection dies.  Since this program always
   * opens a descriptor for the modem in auto and direct mode,
   * having to dup the descriptor here is a fatal error.
   *
   * With the other changes I have made this should no longer happen.
   * JC
  */
  while (modem < 3)
  {
    logprintf("Duping modem fd %d\n", modem);
    modem = dup(modem);
  }

  /*
   * If we are working on tty device, change it's mode into
   * the one desired for further operation. In this implementation,
   * we assume that modem is configuted to use CTS/RTS flow control.
   */
  dev_is_modem = isatty(modem) || DEV_IS_SYNC;
  if (DEV_IS_SYNC)
    sleep(1);
  if (dev_is_modem && !DEV_IS_SYNC) {
    tcgetattr(modem, &rstio);
    modemios = rstio;
#ifdef DEBUG
    logprintf("## modem = %d\n", modem);
    logprintf("modem (get): iflag = %x, oflag = %x, cflag = %x\n",
    rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
#endif
    cfmakeraw(&rstio);
    if (VarCtsRts)
	rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
    else {
	rstio.c_cflag |= CLOCAL;
	rstio.c_iflag |= IXOFF;
    }
    rstio.c_iflag |= IXON;
    if (!(mode & MODE_DEDICATED))
      rstio.c_cflag |= HUPCL;
    if ((mode & MODE_DIRECT) == 0) {
      /*
       * If we are working as direct mode, don't change tty speed.
       */
      rstio.c_cflag &= ~(CSIZE|PARODD|PARENB);
      rstio.c_cflag |= VarParity;
      cfsetspeed(&rstio, IntToSpeed(VarSpeed));
    }
    tcsetattr(modem, TCSADRAIN, &rstio);
#ifdef DEBUG
    logprintf("modem (put): iflag = %x, oflag = %x, cflag = %x\n",
    rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
#endif

    if (!(mode & MODE_DIRECT))
      ioctl(modem, TIOCMGET, &mbits);
#ifdef DEBUG
    fprintf(stderr, "modem control = %o\n", mbits);
#endif

    oldflag = fcntl(modem, F_GETFL, 0);
    fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
  }
  StartModemTimer();

  return(modem);
}

int
ModemSpeed()
{
  struct termios rstio;

  tcgetattr(modem, &rstio);
  return(SpeedToInt(cfgetispeed(&rstio)));
}

/*
 * Put modem tty line into raw mode which is necessary in packet mode operation
 */
int
RawModem(modem)
int modem;
{
  struct termios rstio;
  int oldflag;

  if (!isatty(modem) || DEV_IS_SYNC)
    return(0);
  if (!(mode & MODE_DIRECT) && modem && !Online) {
#ifdef DEBUG
    logprintf("mode = %d, modem = %d, mbits = %x\n", mode, modem, mbits);
#endif
#ifdef notdef
    return(-1);
#endif
  }
  tcgetattr(modem, &rstio);
  cfmakeraw(&rstio);
  if (VarCtsRts)
      rstio.c_cflag |= CLOCAL | CCTS_OFLOW|CRTS_IFLOW;
  else
      rstio.c_cflag |= CLOCAL;

  if (!(mode & MODE_DEDICATED))
    rstio.c_cflag |= HUPCL;
  tcsetattr(modem, TCSADRAIN, &rstio);
  oldflag = fcntl(modem, F_GETFL, 0);
  fcntl(modem, F_SETFL, oldflag | O_NONBLOCK);
#ifdef DEBUG
  oldflag = fcntl(modem, F_GETFL, 0);
  logprintf("modem (put2): iflag = %x, oflag = %x, cflag = %x\n",
   rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
  logprintf("flag = %x\n", oldflag);
#endif
  return(0);
}

void
UnrawModem(modem)
int modem;
{
  int oldflag;

  if (isatty(modem) && !DEV_IS_SYNC) {
    tcsetattr(modem, TCSAFLUSH, &modemios);
    oldflag = fcntl(modem, F_GETFL, 0);
    fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
  }
}

void
HangupModem(flag)
int flag;
{
  struct termios tio;

  if (!isatty(modem)) {
    mbits &= ~TIOCM_DTR;
    close(modem);
    modem = 0;			/* Mark as modem has closed */
    return;
  }

  if (modem && Online) {
    mbits &= ~TIOCM_DTR;
#ifdef __bsdi__ /* not a POSIX way */
    ioctl(modem, TIOCMSET, &mbits);
#else
    tcgetattr(modem, &tio);
    cfsetspeed(&tio, B0);
    tcsetattr(modem, TCSANOW, &tio);
#endif
    sleep(1);
#ifdef notdef
    mbits &= ~TIOCM_CD;
#endif
  }
  /*
   * If we are working as dedicated mode, never close it
   * until we are directed to quit program.
   */
  if (modem && (flag || !(mode & MODE_DEDICATED))) {
    ModemTimeout();			/* XXX */
    StopTimer(&ModemTimer);		/* XXX */

    /* ModemTimeout() may call DownConection() to close the modem
     * resulting in modem == 0.
    */
    if (modem)
    {
	tcflush(modem, TCIOFLUSH);
	UnrawModem(modem);
	close(modem);
    }
    (void) uu_unlock(uucplock);
    modem = 0;			/* Mark as modem has closed */
  } else if (modem) {
    mbits |= TIOCM_DTR;
#ifndef notyet
    ioctl(modem, TIOCMSET, &mbits);
#else
    tcgetattr(modem, &ts);
    cfsetspeed(&ts, IntToSpeed(VarSpeed));
    tcsetattr(modem, TCSADRAIN, &ts);
#endif
  }
}

void
CloseModem()
{
  if (modem >= 3)
  {
      close(modem);
      modem = 0;
  }
  (void) uu_unlock(uucplock);
}

/*
 * Write to modem. Actualy, requested packets are queued, and goes out
 * to the line when ModemStartOutput() is called.
 */
void
WriteModem(pri, ptr, count)
int pri;
char *ptr;
int count;
{
  struct mbuf *bp;

  bp = mballoc(count, MB_MODEM);
  bcopy(ptr, MBUF_CTOP(bp), count);

  /* Should be NORMAL and LINK only.
   * All IP frames get here marked NORMAL.
  */
  Enqueue(&OutputQueues[pri], bp);
}

void
ModemOutput(pri, bp)
int pri;
struct mbuf *bp;
{
  struct mbuf *wp;
  int len;

  len = plength(bp);
  wp = mballoc(len, MB_MODEM);
  mbread(bp, MBUF_CTOP(wp), len);
  Enqueue(&OutputQueues[pri], wp);
  ModemStartOutput(modem);
}

int
ModemQlen()
{
  struct mqueue *queue;
  int len = 0;
  int i;

  for ( i = PRI_NORMAL; i <= PRI_LINK; i ++ ) {
        queue = &OutputQueues[i];
	len += queue->qlen;
  }
  return(len);

}

void
ModemStartOutput(fd)
int fd;
{
  struct mqueue *queue;
  int nb, nw, i;

    if (modemout == NULL && ModemQlen() == 0)
      IpStartOutput();
  if (modemout == NULL) {
    i = PRI_LINK;
    for (queue = &OutputQueues[PRI_LINK]; queue >= OutputQueues; queue--) {
      if (queue->top) {
	modemout = Dequeue(queue);
#ifdef QDEBUG
	if (i > PRI_NORMAL) {
	  struct mqueue *q;

	  q = &OutputQueues[0];
	  logprintf("output from queue %d, normal has %d\n", i, q->qlen);
	}
	logprintf("Dequeue(%d): ", i);
#endif
	break;
      }
      i--;
    }
  }
  if (modemout) {
    nb = modemout->cnt;
    if (nb > 1600) nb = 1600;
    if (fd == 0) fd = 1;	/* XXX WTFO!  This is bogus */
    nw = write(fd, MBUF_CTOP(modemout), nb);
#ifdef QDEBUG
    logprintf("wrote: %d(%d)\n", nw, nb);
    LogDumpBuff(LOG_HDLC, "modem write", MBUF_CTOP(modemout), nb);
#endif
    if (nw > 0) {
      modemout->cnt -= nw;
      modemout->offset += nw;
      if (modemout->cnt == 0) {
	modemout = mbfree(modemout);
#ifdef QDEBUG
	logprintf(" mbfree\n");
#endif
      }
    } else if (nw < 0) {
      if (errno != EAGAIN)
        perror("modem write");
    }
  }
}

int
DialModem()
{
  char ScriptBuffer[200];
  int excode = 0;

  strncpy(ScriptBuffer, VarDialScript,sizeof(ScriptBuffer)-1);
  ScriptBuffer[sizeof(ScriptBuffer)-1] = '\0';
  if (DoChat(ScriptBuffer) > 0) {
    if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER)
      fprintf(stderr, "dial OK!\n");
    strncpy(ScriptBuffer, VarLoginScript,sizeof(ScriptBuffer)-1);
    if (DoChat(ScriptBuffer) > 0) {
      if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER)
	fprintf(stderr, "login OK!\n");
      return(1);
    } else {
      if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) {
	fprintf(stderr, "login failed.\n");
        excode = EX_NOLOGIN;
      }
    }
    ModemTimeout();	/* Dummy call to check modem status */
  }
  else {
    if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) {
      fprintf(stderr, "dial failed.\n");
      excode = EX_NODIAL;
    }
  }
  HangupModem(0);
  if (mode & MODE_BACKGROUND) {
      extern void Cleanup();
      CloseModem();
      Cleanup(excode);
  } 
  return(0);
}

int
ShowModemStatus()
{
#ifdef TIOCOUTQ
  int nb;
#endif

  printf("device: %s  speed: ", VarDevice);
  if (DEV_IS_SYNC)
    printf("sync\n");
  else
    printf("%d\n", VarSpeed);

  switch (VarParity & CSIZE) {
  case CS7:
    printf("cs7, ");
    break;
  case CS8:
    printf("cs8, ");
    break;
  }
  if (VarParity & PARENB) {
    if (VarParity & PARODD)
      printf("odd parity, ");
    else
      printf("even parity, ");
  } else
    printf("no parity, ");

  printf("CTS/RTS %s.\n", (VarCtsRts? "on" : "off"));

#ifdef DEBUG
  printf("fd = %d, modem control = %o\n", modem, mbits);
#endif
  printf("connect count: %d\n", connect_count);
#ifdef TIOCOUTQ
  ioctl(modem, TIOCOUTQ, &nb);
  printf("outq: %d\n", nb);
#endif
  printf("outqlen: %d\n", ModemQlen());
  printf("DialScript  = %s\n", VarDialScript);
  printf("LoginScript = %s\n", VarLoginScript);
  printf("PhoneNumber(s) = %s\n", VarPhoneList);
  return(1);
}
OpenPOWER on IntegriCloud