-
Notifications
You must be signed in to change notification settings - Fork 3
/
ckudia.c
1558 lines (1356 loc) · 42.3 KB
/
ckudia.c
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
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef NOCKUDIA
char *dialv = " Dialer, 4G(060)";
/* C K U D I A -- Dialing program for connection to remote system */
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright (c) 2021, 2022, 2023 Jeffrey H. Johnson <trnsz@pobox.com>
*
* Copyright (c) 1985, Herman Fischer, Encino CA
*
* Copyright (c) 1981-2011,
* Trustees of Columbia University in the City of New York.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* - Neither the name of Columbia University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This module should work under all versions of UNIX. It calls externally
* defined system-depended functions for i/o, but depends upon the existence
* of various modem control functions.
*
* This module, and the supporting routines in the ckutio.c module, assume
* that the computer and modem properly utilize the following data communi-
* cations signals (that means one should prepare the modem to use, not
* circumvent, these signals):
*
* Data Terminal Ready: This signal is asserted by the computer when
* Kermit is about to ask the modem to dial a call, and is removed
* when Kermit wishes to have the modem hang up a call. The signal
* is asserted both while Kermit is asking the modem to dial a
* specific number, and after connection, while Kermit is in a data
* exchange mode.
*
* Carrier detect: This signal must be asserted by the modem when a
* carrier is detected from a remote modem on a communications
* circuit. It must be removed by the modem when the circuit
* disconnects or is hung up. (Carrier detect is ignored while
* Kermit is asking the modem to dial the call, because there is
* no consistant usage of this signal during the dialing phase
* among different modem manufacturers.)
*/
/*
* To add support for another modem, do the following:
*
* Define a modem number symbol (n_XXX) for it, keeping the
* list in alphabetical and numerical order, and renumbering
* the values as necessary.
*
* Create a MDMINF structure for it, again keeping the list
* alphabetical for sanity's sake.
*
* Add the address of the MDMINF structure to the ptrtab
* array, again in alphabetical and numerical order.
*
* Add the "user visible" modem name and corresponding modem
* number to the mdmtab array, again in alphabetical order.
*
* Read through the code and add modem-specific sections,
* as necessary.
*/
/*
* The intent of the "unknown" modem is, hopefully, to allow KERMIT
* to support unknown modems by having the user type the entire
* autodial sequence (possibly including control characters, etc.)
* as the "phone number". The only reason that the CONNECT command
* cannot be used to do this is that a remote line cannot normally
* be opened unless carrier is present.
*
* The protocol and other characteristics of this modem are unknown,
* with some "reasonable" values being chosen for some of them. The
* only way to detect if a connection is made is to look for carrier
* present.
*
* SUPPORT IS CURRENTLY ONLY PARTIALLY SKETCHED OUT FOR THIS.
* ALSO, IT SHOULD PERHAPS BE HANDLED MUCH EARLIER, SIMPLY READING
* USER INPUT AND SENDING IT TO THE MODEM AND ECHOING MODEM RESPONSES
* BACK TO THE USER, ALL THE TIME LOOKING FOR CARRIER. OF COURSE, THE
* PROBLEM THEN BECOMES ONE OF ALLOWING THE USER TO CANCEL THE DIALING.
* WE COULD CHOOSE SOME PHRASE THAT WOULD PRESUMABLY NEVER BE A PART
* OF A VALID AUTODIAL SEQUENCE (E.G., "QUIT" and "quit").
*/
#include "ckcdeb.h"
#include "ckcker.h"
#include "ckucmd.h"
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <setjmp.h>
#ifdef __linux__
#include <string.h>
#endif /* ifdef __linux__ */
void xcpy(char *to, char *from, unsigned int len);
extern int flow, local, mdmtyp, quiet, speed, parity, seslog, ttyfd;
extern char ttname[], sesfil[];
#define MDMINF struct mdminf
MDMINF /* structure for modem-specific information */
{
int dial_time; /* time modem allows for dialing (secs) */
char *pause_chars; /* character(s) to tell modem to pause */
int pause_time; /* time associated with pause chars (secs) */
char *wake_str; /* string to wakeup modem & put in cmd mode */
int wake_rate; /* delay between wake_str characters (msecs) */
char *wake_prompt; /* string prompt after wake_str */
char *dmode_str; /* string to put modem in dialing mode */
char *dmode_prompt; /* string prompt for dialing mode */
char *dial_str; /* dialing string, with "%s" for number */
int dial_rate; /* delay between dialing characters (msecs) */
};
/*
* Define symbolic modem numbers.
*
* The numbers MUST correspond to the ordering of entries
* within the ptrtab array, and start at one (1).
*
* It is assumed that there are relatively few of these
* values, and that the high(er) bytes of the value may
* be used for modem-specific mode information.
*
* REMEMBER that only the first eight characters of these
* names are guaranteed to be unique.
*/
#define n_ATTDTDM 1
#define n_ATTMODEM 2
#define n_CERMETEK 3
#define n_DF03 4
#define n_DF100 5
#define n_DF200 6
#define n_GDC 7
#define n_HAYES 8
#define n_PENRIL 9
#define n_RACAL 10
#define n_UNKNOWN 11
#define n_USROBOT 12
#define n_VENTEL 13
#define n_CONCORD 14
#define n_ATTUPC 15 /* aka UNIX PC and ATT7300 */
#define n_ROLM 16 /* Rolm CBX */
#define n_MICROCOM 17
/*
* Declare modem "variant" numbers for any of the above for
* which it is necessary to note various operational modes,
* using the second byte of a modem number.
*
* It is assumed that such modem modes share the same modem-
* specific information (see MDMINF structure) but may differ
* in some of the actions that are performed.
*/
#define n_HAYESNV ( n_HAYES + ( 1 << 8 ))
/*
* Declare structures containing modem-specific information.
*
* REMEMBER that only the first SEVEN characters of these
* names are guaranteed to be unique.
*/
static MDMINF ATTMODEM = /* Information for AT&T switched-network modems */
/* "Number" following "dial" can include: p's and
* t's to indicate pulse or tone (default) dialing,
* + for wait for dial tone, , for pause, r for
* last number dialed, and, except for 2224B, some
* comma-delimited options like o12=y before number.
*/
/* "Important" options for the modems:
*
* All: Except for 2224B, enable option 12 for "transparent
* data," o12=y. If a computer port used for both
* incoming and outgoing calls is connected to the
* modem, disable "enter interactive mode on carriage
* return," EICR. The Kermit "dial" command can
* function with EIA leads standard, EIAS.
*
* 2212C: Internal hardware switches at their default
* positions (four rockers down away from numbers)
* unless EICR is not wanted (rocker down at the 4).
* For EIAS, rocker down at the 1.
*
* 2224B: Front-panel switch position 1 must be up (at the 1,
* closed). Disable EICR with position 2 down.
* For EIAS, position 4 down.
* All switches on the back panel down.
*
* 2224CEO: All front-panel switches down except either 5 or 6.
* Enable interactive flow control with o16=y.
* Select normal asynchronous mode with o34=0 (zero).
* Disable EICR with position 3 up. For EIAS, 1 up.
* Reset the modem after changing switches.
*
* 2296A: If option 00 (zeros) is present, use o00=0.
* Enable interactive flow control with o16=y.
* Select normal asynchronous mode with o34=0 (zero).
* Enable modem-port flow control (if available) with
* o42=y. Enable asynchronous operation with o50=y.
* Disable EICR with o69=n. For EIAS, o66=n, using
* front panel.
*/
{
20, /* dial_time */
",", /* pause_chars */
2, /* pause_time */
"+", /* wake_str */
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
"", /* dmode_prompt */
"at%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF ATTDTDM = /* Information for AT&T Digital Terminal Data Module
* For dialing: KYBD switch down, others usually up.
*/
{
5, /* dial_time */
"", /* pause_chars */
0, /* pause_time */
"", /* wake_str */
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
"", /* dmode_prompt */
"%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF CERMETEK = /* Information for Cermetek Info-Mate 212A modem */
{
20, /* dial_time */
"BbPpTt", /* pause_chars */
0, /* pause_time */
" XY\016R\r", /* wake_str */
200, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"\016D '%s'\r", /* dial_str */
200 /* dial_rate */
};
static MDMINF DF03 = /* Information for "DEC DF03-AC" modem */
{
27, /* dial_time */
"=", /* pause_chars */
15, /* pause_time */
"\001\002", /* wake_str */
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"%s", /* dial_str */
0 /* dial_rate */
};
static MDMINF DF100 = /* Information for "DEC DF100-series" modem */
/*
* The phone "number" can include "P"s and/or "T"s
* within it to indicate that subsequent digits are
* to be dialed using pulse or tone dialing. The
* modem defaults to pulse dialing. You may modify
* the dial string below to explicitly default all
* dialing to pulse or tone, but doing so prevents
* the use of phone numbers that you may have stored
* in the modem's memory.
*/
{
30, /* dial_time */
"=", /* pause_chars */
15, /* pause_time */
"\001", /* wake_str */
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"%s#", /* dial_str */
0 /* dial_rate */
};
static MDMINF DF200 = /* Information for "DEC DF200-series" modem */
/*
* The phone "number" can include "P"s and/or "T"s
* within it to indicate that subsequent digits are
* to be dialed using pulse or tone dialing. The
* modem defaults to pulse dialing. You may modify
* the dial string below to explicitly default all
* dialing to pulse or tone, but doing so prevents
* the use of phone numbers that you may have stored
* in the modem's memory.
*/
{
30, /* dial_time */
"=W", /* pause_chars */
15, /* pause_time */
"\002", /* wake_str */
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"%s!", /* dial_str */
0 /* dial_rate */
};
static MDMINF GDC = /* Information for GeneralDataComm 212A/ED modem */
{
32, /* dial_time */
"%", /* pause_chars */
3, /* pause_time */
"\r\r", /* wake_str */
500, /* wake_rate */
"$", /* wake_prompt */
"D\r", /* dmode_str */
":", /* dmode_prompt */
"T%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF HAYES = /* Information for "Hayes" modem */
{
35, /* dial_time */
",", /* pause_chars */
2, /* pause_time */
"AT\r", /* wake_str */
/* Note: Other wake_str's are possible here.
* For Hayes 2400 that is to be used for both
* inbound and outbound calls, "AT&F&D3" might
* be best. For outbound calls only, possibly
* "AT&F&D2". See the Hayes 2400 manual.
*/
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
"", /* dmode_prompt */
"ATD%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF PENRIL = /* Information for "Penril" modem */
{
50, /* dial_time */
"", /* pause_chars */
0, /* pause_time */
"\r\r", /* wake_str */
300, /* wake_rate */
">", /* wake_prompt */
"k\r", /* dmode_str */
":", /* dmode_prompt */
"%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF RACAL = /* Information for "Racal Vadic" modem */
{
35, /* dial_time */
"Kk", /* pause_chars */
5, /* pause_time */
"\005\r", /* wake_str */
50, /* wake_rate */
"*", /* wake_prompt */
"D\r", /* dmode_str */
"?", /* dmode_prompt */
"%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF UNKNOWN = /* Information for "Unknown" modem */
{
30, /* dial_time */
"", /* pause_chars */
0, /* pause_time */
"", /* wake_str */
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF USROBOT = /* Information for "US Robotics 212A" modem */
{
30, /* dial_time */
",", /* pause_chars */
2, /* pause_time */
"ATS2=01\r", /* wake_str */
0, /* wake_rate */
"OK\r", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"ATTD%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF VENTEL = /* Information for "Ventel" modem */
{
20, /* dial_time */
"%", /* pause_chars */
5, /* pause_time */
"\r\r\r", /* wake_str */
300, /* wake_rate */
"$", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"<K%s\r>", /* dial_str */
0 /* dial_rate */
};
static MDMINF CONCORD = /* Information for Condor CDS 220 2400b modem */
{
35, /* dial_time */
",", /* pause_chars */
2, /* pause_time */
"\r\r", /* wake_str */
20, /* wake_rate */
"CDS >", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"<D M%s\r>", /* dial_str */
0 /* dial_rate */
};
static MDMINF
ATTUPC = /* (Dummy) Information for "ATT7300/UNIX PC" internal modem */
{
20, /* dial_time */
"", /* pause_chars */
0, /* pause_time */
"", /* wake_str */
0, /* wake_rate */
"", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"%s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF ROLM = /* IBM / Siemens / Rolm 8000, 9000, 9751 CBX */
{
60, /* dial_time */
"", /* pause_chars */
0, /* pause_time */
"\r\r", /* wake_str */
5, /* wake_rate */
"MODIFY?", /* wake_prompt */
"", /* dmode_str */
"", /* dmode_prompt */
"CALL %s\r", /* dial_str */
0 /* dial_rate */
};
static MDMINF MICROCOM = /* Information for Microcom modems; native mode */
/* (Long answer only) */
{
35, /* dial_time */
",!@", /* pause_chars */
3, /* pause_time */
"\r", /* wake_str */
100, /* wake_rate */
"!", /* wake_prompt */
"", /* dmode_str */
NULL, /* dmode_prompt */
"d%s\r", /* dial_str */
0 /* dial_rate */
};
/*
* Declare table for converting modem numbers to
* information pointers.
*
* The entries MUST be in ascending order by modem
* number, without any "gaps" in the numbers, and
* starting from one (1).
*
* This table should NOT include entries for the
* "variant" modem numbers, since it is assumed that
* they share the same information as the normal value.
*/
static MDMINF *ptrtab[] = {
&ATTDTDM, &ATTMODEM, &CERMETEK, &DF03, &DF100, &DF200,
&GDC, &HAYES, &PENRIL, &RACAL, &UNKNOWN, &USROBOT,
&VENTEL, &CONCORD, &ATTUPC, /* ATT7300 */
&ROLM, /* Rolm CBX */
&MICROCOM,
};
/*
* Declare modem names and associated numbers for command
* parsing, and also for doing number-to-name translation.
*/
/*
* The entries MUST be in alphabetical order by modem name.
*/
struct keytab mdmtab[] = {
{ "attdtdm", n_ATTDTDM, 0, },
{ "attmodem", n_ATTMODEM, 0, },
{ "att7300", n_ATTUPC, 0, },
{ "cermetek", n_CERMETEK, 0, },
{ "concord", n_CONCORD, 0, },
{ "df03-ac", n_DF03, 0, },
{ "df100-series", n_DF100, 0, },
{ "df200-series", n_DF200, 0, },
{ "direct", 0, 0, },
{ "gendatacomm", n_GDC, 0, },
{ "hayes", n_HAYES, 0, },
{ "microcom", n_MICROCOM, 0, },
{ "penril", n_PENRIL, 0, },
{ "racalvadic", n_RACAL, 0, },
{ "rolm", n_ROLM, 0, },
{ "unknown", n_UNKNOWN, 0, },
{ "usrobotics-212a", n_USROBOT, 0, },
{ "ventel", n_VENTEL, 0 }
};
int nmdm = ( sizeof ( mdmtab ) / \
sizeof ( struct keytab )); /* number of modems */
#define DIALING 4 /* for ttpkt parameter */
#define CONNECT 5
#define CONNECTED 1 /* for completion status */
#define FAILED 2
/*
* Failure reasons for use
* with the 'longjmp' exit.
*/
#define F_time 1 /* timeout */
#define F_int 2 /* interrupt */
#define F_modem 3 /* modem-detected failure */
#define F_minit 4 /* cannot initialize modem */
static char *F_reason[5] = { /* Failure reasons for message */
"Unknown",
"Timeout",
"Interrupt",
"Modem",
"Initialize"
};
static int tries = 0;
#ifdef MINBUF
#define LBUFL 48
#else /* ifdef MINBUF */
#define LBUFL 100
#endif /* ifdef MINBUF */
static char lbuf[LBUFL];
static jmp_buf sjbuf;
static SIGTYP (*savAlrm)(); /* for saving alarm handler */
static SIGTYP (*savInt)(); /* for saving interrupt handler */
void /* Copy a string of the */
xcpy(to, from, len) /* the given length. */
register char *to, *from;
register unsigned len;
{
while (len--)
{
*to++ = *from++;
}
}
SIGTYP
dialtime() /* timer interrupt handler */
{
longjmp(sjbuf, F_time);
}
SIGTYP
dialint() /* user-interrupt handler */
{
longjmp(sjbuf, F_int);
}
static int
ttolSlow(s, millisec)
char *s;
int millisec;
{ /* Output s-l-o-w-l-y */
for (; *s; s++)
{
ttoc(*s);
msleep(millisec);
}
return ( 0 );
}
/*
* Wait for a string of characters.
*
* The characters are waited for individually,
* and other characters may be received "in-
* between". This merely guarantees that the
* characters ARE received, and in the order
* specified.
*/
static int
waitFor(s)
char *s;
{
CHAR c;
while (( c = *s++ )) /* while more characters remain... */
{
while ((( ttinc(0) & \
0177 ) != c )) /* wait for the character */
{
;
}
}
return ( 0 );
}
static int
didWeGet(s, r)
char *s, *r;
{ /* Looks in string s for response r */
int lr = strlen(r); /* 0 means not found, 1 means found */
int i;
debug(F110, "didWeGet", r, 0);
debug(F110, " in", s, 0);
for (i = strlen(s) - lr; i >= 0; i--)
{
if (s[i] == r[0])
{
if (!strncmp(s + i, r, lr))
{
return ( 1 );
}
}
}
return ( 0 );
}
/* R E S E T -- Reset alarms, etc. on exit */
static int
reset()
{
alarm(0);
signal(SIGALRM, savAlrm); /* restore alarm handler */
signal(SIGINT, savInt); /* restore interrupt handler */
return ( 0 );
}
/* C K D I A L -- Dial up the remote system */
int
ckdial(telnbr)
char *telnbr;
{
char c;
char *i, *j;
int waitct = 0; /* XXX(jhj): waitct = 0 init */
int status = 0; /* XXX(jhj): status = 0 init */
char errmsg[50], *erp;
MDMINF *pmdminf; /* pointer to modem-specific info */
int augmdmtyp; /* augmented modem type, handle modem modes */
int mdmEcho = 0; /* assume modem does not echo */
int n, n1;
char *pc; /* pointer to a character */
if (!mdmtyp)
{
printf("'set modem' first\n");
return ( -2 );
}
if (!local)
{
printf("'set line' first\n");
return ( -2 );
}
if (speed < 0)
{
printf("'set speed' first\n");
return ( -2 );
}
debug(F110, "dial", telnbr, 0);
/*
* Carrier no-wait can
* be invalidated
*/
if (ttopen(
ttname, &local, mdmtyp) < 0) /* Open, no carrier wait */
{
erp = errmsg;
sprintf(erp, "Can't open %s", ttname);
perror(errmsg);
return ( -2 );
}
pmdminf = ptrtab[mdmtyp - 1]; /* Set pointer to modem info */
augmdmtyp = mdmtyp; /* Init augmented modem type */
/*
* interdigit waits
* for tone dial
*/
waitct = 1 * strlen(telnbr); /* compute time to dial worst case */
waitct += pmdminf->dial_time; /* dialtone + completion wait times */
for (i = telnbr; *i; i++) /* add in pause characters time */
{
for (j = pmdminf->pause_chars; *j; j++)
{
if (*i == *j)
{
waitct += pmdminf->pause_time;
break;
}
}
}
printf("Dialing thru %s, speed %d, number %s.\n", ttname, speed, telnbr);
printf("The timeout for completing the call is %d seconds.\n", waitct);
printf("Type the interrupt character (^C) to cancel the dialing.\n");
debug(F101, ttname, "", speed);
debug(F101, "timeout", "", waitct);
/*
* Hang up the modem
* (in case it wasn't "on hook")
*/
if (tthang() < 0)
{
printf("Can't hang up tty line\n");
return ( -2 );
}
if (augmdmtyp == n_ROLM)
{
sleep(1);
}
/*
* Condition console terminal and communication line;
* place line into "clocal" dialing state.
*/
if (ttpkt(speed, DIALING, parity) < 0)
{
printf("Can't condition line\n");
return ( -2 );
}
if (augmdmtyp == n_ROLM)
{
sleep(1);
}
/*
* Establish jump vector,
* or handle "failure" jumps.
*/
if (( n = setjmp(sjbuf))) /* if a "failure jump" was taken... */
{
alarm(0); /* disable timeouts */
if (( n1 = setjmp(sjbuf))) /* failure while handling failure */
{
printf("%s failure while handling failure.\n", F_reason[n1]);
}
else /* first (i.e., non-nested) failure */
{
signal(SIGALRM, dialtime); /* be sure to catch signals */
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
{
signal(SIGINT, dialint);
}
alarm(10); /* be sure to exit this section */
ttclos(); /* hangup and close the line */
}
switch (n) /* type of failure */
{
case F_time: /* timed out */
{
printf("No connection made within the allotted time.\n");
debug(F110, "dial", "timeout", 0);
break;
}
case F_int: /* dialing interrupted */
{
printf("Dialing interrupted.\n");
debug(F110, "dial", "interrupted", 0);
break;
}
case F_modem: /* modem detected a failure */
{
printf("Failed (\"");
for (pc = lbuf; *pc; pc++)
{
if (isprint(*pc))
{
putchar(*pc); /* display printable reason */
}
}
printf("\").\n");
debug(F110, "dial", lbuf, 0);
break;
}
case F_minit: /* cannot initialize modem */
{
printf("Cannot initialize modem.\n");
debug(F110, "dial", "modem init", 0);
break;
}
}
reset(); /* reset alarms, etc. */
return ( -2 ); /* exit with failure code */
}
/*
* Set timer and interrupt handlers.
*/
/* The following call to ttflui()
* commented out because ttpkt
* just did this!
*/
/* ttflui(); */ /* flush input buffer if any */
savAlrm = signal(
SIGALRM, dialtime); /* set alarm handler */
if (( savInt = signal(
SIGINT, SIG_IGN)) != SIG_IGN)
{
signal(SIGINT, dialint); /* set int handler if not ignored */
}
debug(F100,
"ckdial giving modem 10 secs to wake up", "", 0);
alarm(10); /* give modem 10s to wake up. */
/*
* Put modem in
* command mode.
*/
#define OKAY 1 /* modem attention attempt status */
#define IGNORE 2
#define GOT_O -2
#define GOT_A -3
switch (augmdmtyp)
{
case n_HAYES:
case n_HAYESNV:
while (tries++ < 4)
{
ttol(
HAYES.wake_str,
strlen(
HAYES.wake_str)); /* wakeup */
status = 0;
while (status <= 0)
{
switch (ttinc(0) & 0177)
{
case 'A': /* echo, ignore */
status = GOT_A;
break;
case 'T':
if (status == GOT_A)
{
mdmEcho = 1; /* expect echo later */
status = 0;
break;
}
status = IGNORE;
break;
case LF:
case CR:
status = 0;
break;
case '0': /* numeric result */
augmdmtyp = n_HAYESNV; /* nonverbal result */
status = OKAY;
break;
case 'O': /* maybe English code */
status = GOT_O;
break;
case 'K':
if (status == GOT_O)
{
augmdmtyp = n_HAYES;
status = OKAY;
break;
} /* default */
default:
status = IGNORE;
break;
}
}
if (status == OKAY)
{
break;
}
if (status == IGNORE)
{
ttflui();
}
sleep(1); /* wait, then retry */
}
if (status != 0)
{
break;
}
longjmp(sjbuf, F_minit); /* modem-init failure */
/*
* interdigit waits
* for tone dial
*/
case n_MICROCOM: {
jmp_buf savejmp;
alarm(0);
xcpy((char *)savejmp,
(char *)sjbuf,
sizeof savejmp);
if (setjmp(sjbuf)) /* autobaud sequence */
{
xcpy((char *)sjbuf, (char *)savejmp, sizeof savejmp);
alarm(5);
ttolSlow("44445", MICROCOM.wake_rate);
waitFor(MICROCOM.wake_str);