Project

General

Profile

Download (39.9 KB) Statistics
| Branch: | Tag: | Revision:
1 9ebe7028 gnhb
#################################################################
2
#
3
# $Id: mpd.script.sample,v 1.9 2009/10/04 19:36:04 amotin Exp $
4
#
5
# Copyright (c) 1995-1999 Whistle Communications, Inc. All rights reserved.
6
# See ``COPYRIGHT.whistle''
7
#
8
#################################################################
9
10
##
11
## MPD Modem script variables:
12
##
13
##  $DialPrefix		Modem dialing prefix (eg. "DT")
14
##  $Telephone		Telephone number to dial (not duplicated using &)
15
##  $ConnectTimeout	Wait-for-connect timeout, in seconds (default 45 secs)
16
##  $SpeakerOff		Set to "yes" to quiet modem speakers
17
##  $Serial230K		If "yes", we can support 230K serial port speed
18
##  $CountryCode	Country code for Winmodem
19
##  $InitString		External initialization string
20
##  $LoginScript	If "yes", look for script login
21
##
22
## pfSense specific variables:
23
##	$APN			Access Point (host)Name for 3G connections
24
##	$APNum			Access Point Number, typically "1", might not matter
25
##	$SimPin			SIM card PIN number
26
##	$PinWait		Wait for SIM to connect to network after PIN entered
27
##
28
## ISDN Terminal Adapter specific variables (all start with "TA_"):
29
##
30
##  $TA_Bonding		Bonding on TA: "yes" or "no"
31
##  $TA_NoDoubleTelno	When $TA_Bonding, don't double the dialed number
32
##  $TA_56K		Restrict to 56K on TA: "yes" or "no"
33
##  $TA_VoiceCall	Originate calls using voice mode
34
##  $TA_AuthChap	Tell TA to use CHAP: "yes" or "no"
35
##  $TA_Dirno1		TA directory #1
36
##  $TA_Dirno2		TA directory #2
37
##  $TA_SPID1		SPID #1
38
##  $TA_SPID2		SPID #2
39
##  $TA_SwitchType	One of these values
40
##				"NI-1"
41
##				"DMS-100"
42
##				"5ESS P2P"
43
##				"5ESS MP"
44
##  $TA_NewSwitch	Means the switch type is new, initiate auto-detect
45
##			(3Com Impact IQ only)
46
##
47
## We set $OptimizeNextTime to "yes" after a successful connection so we
48
## can avoid verifing configuration when things are working good.
49
##
50
## Internal variables:
51
##
52
##  $ModemSetupFunc	Routine to set up modem for dialing out
53
##  $ModemAnsSetupFunc	Routine to set up modem for answer mode (if different)
54
##  $ModemDetectRing	Routine to detect an incoming call for ringback
55
##  $ModemIsAnalog	If "yes" modem is analog (ie, not terminal adapter)
56
##
57
58
#################################################################
59
#
60
#	MODEM DIALING
61
#
62
#################################################################
63
64
DialPeer:
65
	set $CallingID ""
66
	set $CalledID $Telephone
67
	if $Telephone == "00000" goto DialNullModem
68
	set $optimize $OptimizeNextTime
69
	set $OptimizeNextTime "no"
70
71
	if $optimize == "yes" goto DialPeer2
72
	call ModemFind
73
	if $ErrorMsg == "" goto DialPeer1
74
	log $ErrorMsg
75
	failure
76
DialPeer1:
77
	set $ModTelephone $Telephone
78
	call ModemIdent
79
	if $ModemDescription != "" goto DialPeer2
80 29851d8e gnhb
	log "No match found in the ModemIdent function in the chat script."
81 9ebe7028 gnhb
	failure
82
83
DialPeer2:
84
	log "Detected $ModemDescription."
85
	call $ModemSetupFunc
86
	log "Dialing server at $Telephone..."
87
	call ModemDial
88
	if $dialResult == "OK" goto DialPeerOK
89
	set $optimize "no"
90
	failure
91
92
DialPeerOK:
93
	if $ConnectionSpeed == "" log "Connected at an unknown speed."
94
	if $ConnectionSpeed == "" goto DialPeer3
95
	log "Connected at $ConnectionSpeed."
96
DialPeer3:
97
	if $LoginScript == "yes" call AutoLogin
98
	set $OptimizeNextTime "yes"
99
	success
100
101
DialPeerSetPin:
102 ffd2059b smos
	set $modemCmd "+CPIN?"
103 158b5cc3 gnhb
	log $modemCmd
104
	call ModemQuery
105
	log $modemQuery
106 aa7504e0 smos
	if $modemQuery match ".*READY.*" goto DialPinReady
107 1a904779 gnhb
	set $modemCmd "+CPIN=\"$SimPin\""
108 9ebe7028 gnhb
	call ModemCmd2
109 158b5cc3 gnhb
	wait $PinWait
110 aa7504e0 smos
111
DialPinReady:
112 9ebe7028 gnhb
	return
113
114
DialPeerSetAPN:
115
	set $modemCmd "+CGDCONT=$APNum,\"IP\",\"$APN\""
116 aa7504e0 smos
	log $modemCmd
117 9ebe7028 gnhb
	call ModemCmd2
118
	return
119 179377b0 robjarsen
120 9ebe7028 gnhb
# Null-modem connection
121
DialNullModem:
122
	log "Connected via null modem connection."
123
	success
124
125
##
126
## Dial modem
127
##
128
## Variables:
129
##
130
##  $DialPrefix		Modem dialing prefix (eg. "DT")
131
##  $ModTelephone	Telephone number to dial
132
##  $ConnectTimeout	Wait-for-connect timeout, in seconds (default 45 secs)
133
##  $noDialToneSubr	(optional) Subroutine to call if NO DIALTONE
134
##  $dialErrorSubr	(optional) Subroutine to call if ERR
135
##
136
## Returns:
137
##
138
##  $dialResult		"OK" or "FAIL"
139
##  $ConnectionSpeed	Connection speed reported by modem (possibly empty)
140
##
141
142
ModemDial:
143
	set $dialResult "FAIL"
144
	set $ConnectionSpeed ""
145
	if $ConnectTimeout == "" set $ConnectTimeout 45
146
	print "AT${DialPrefix}${ModTelephone}\r\n"
147 aa7504e0 smos
	log "AT${DialPrefix}${ModTelephone}"
148 9ebe7028 gnhb
	match "NO CARRIER" DialAbortNoCar
149
	match "NO DIAL" DialAbortNoDial
150
	match "BUSY" DialAbortBusy
151
	regex "CONNECT *([0-9]*).*$" DialConnect
152
	match "ERR" DialError
153
	wait $ConnectTimeout
154
	log "No response from the modem after dialing."
155
	return
156
DialAbortNoCar:
157
	log "The remote modem did not answer."
158
	return
159
DialAbortNoDial:
160
	if $noDialToneSubr != "" goto $noDialToneSubr
161
	log "No dialtone. Is the modem plugged in?"
162
	return
163
DialError:
164
	if ${ModTelephone} != "" goto DialErrorInit
165
	log "Invalid empty telephone number."
166
	return
167
DialErrorInit:
168
	if $dialErrorSubr != "" goto $dialErrorSubr
169
	log "Invalid dial init string."
170
	return
171
DialAbortBusy:
172
	log "The line was busy."
173
	return
174
DialConnect:
175
	set $ConnectionSpeed $matchedString1
176
	set $dialResult "OK"
177
	return
178
179
#################################################################
180
#
181
#	MODEM ANSWERING
182
#
183
#################################################################
184
185
##
186
## This is an idle script that waits for an incoming call and answers it
187
##
188
## Variables:
189
##
190
##  $RingTimeout	How long to wait for a RING before giving up
191
##  $ConnectTimeout	Wait-for-connect timeout, in seconds (default 45 secs)
192
##
193
194
AnswerCall:
195
	set $CallingID ""
196
	set $CalledID ""
197
	set $optimize $OptimizeNextTime
198
	set $OptimizeNextTime "no"
199
200
# Skip modem detection if we connected successfully last time
201
202
	if $optimize == "yes" goto AnswerCall2
203
	call ModemFind
204
	if $ErrorMsg == "" goto AnswerCall0
205
	log $ErrorMsg
206
	failure
207
AnswerCall0:
208
	call ModemIdent
209
	if $ModemDescription != "" goto AnswerCall1
210
	log "The modem is not responding."
211
	failure
212
AnswerCall1:
213
	log "Detected $ModemDescription."
214
215
AnswerCall2:
216
	if $ModemAnsSetupFunc == "" set $ModemAnsSetupFunc $ModemSetupFunc
217
	call $ModemAnsSetupFunc
218
	log "Waiting for ring..."
219
	call ModemAnswer
220
	if $answerReturn == "OK" goto AnswerCallOK
221
	set $IdleResult ""
222
	set $optimize "no"
223
	failure
224
225
AnswerCallOK:
226
	log "Connected at $ConnectionSpeed."
227
	set $OptimizeNextTime "yes"
228
	set $IdleResult "answer"
229
	success
230
231
#################################################################
232
#
233
#	MODEM RINGBACK
234
#
235
#################################################################
236
237
##
238
## This is an idle script that implements the ringback feature.
239
## When we're idle, and we detect an incoming call, then call back
240
## to bring up the link. For analog modems, we have to wait until
241
## the ringing stops before dialing back (otherwise we'd answer the
242
## call, which we don't want to do).
243
##
244
## Variables:
245
##
246
##  $RingbackTimeout	How long before giving up (reset and try again).
247
##			Default: 60 minutes
248
##  $RingStoppedTime	Max time between consecutive "RING"s (if analog)
249
##			Default: 8 seconds
250
##
251
252
Ringback:
253
	set $CallingID ""
254
	set $CalledID ""
255
	if $RingbackTimeout == "" set $RingbackTimeout "3600"
256
	if $RingStoppedTime == "" set $RingStoppedTime "8"
257
	set $ModemDetectRing RingbackWait
258
	call ModemFind
259
	if $ErrorMsg == "" goto Ringback1
260
	log $ErrorMsg
261
	failure
262
Ringback1:
263
	call ModemIdent
264
	if $ModemDescription != "" goto Ringback2
265
	log "The modem is not responding."
266
	failure
267
268
Ringback2:
269
	log "Detected $ModemDescription."
270
	goto $ModemDetectRing
271
272
# Detect an incoming call by waiting for a "RING" indication
273
# On an analog modem, we have to wait for the ringing to stop
274
275
RingbackWait:
276
	match "RING\r\n" RingbackGotRings
277
	log "Remote Dial-Back mode enabled; waiting for incoming call."
278
	wait $RingbackTimeout
279
	failure
280
281
# We saw it ring; wait for the ringing to stop (analog modems only).
282
283
RingbackGotRings:
284
	log "Incoming call detected..."
285
	if $ModemIsAnalog != "yes" goto RingbackDone
286
RingbackWaitStop:
287
	match "RING\r\n" RingbackWaitStop
288
	wait $RingStoppedTime
289
RingbackDone:
290
	set $IdleResult "ringback"
291
	success
292
293
# Strip leading and trailing spaces and log calling party number
294
295
RingbackDetectCID:
296
	if $cid match " *(.*) *" nop
297
	set $cid $matchedString1
298
	if $cid == "" goto RingbackDetectNoCID
299
	log "Incoming call detected from $cid..."
300
	success
301
302
# We couldn't determine calling party number
303
304
RingbackDetectNoCID:
305
	log "Incoming call detected..."
306
	success
307
308
#################################################################
309
#
310
#	MODEM IDENTIFICATION
311
#
312
#################################################################
313
314
##
315
## Identify
316
##
317
## This is meant to be called from the top level, to just identify
318
## what's on the serial port and print out some info about it.
319
##
320
321
Identify:
322
	call ModemFind
323
	if $ErrorMsg == "" goto Identify1
324
	failure
325
Identify1:
326
	call ModemIdent
327
	if $ModemDescription == "" failure
328
	log "ANALOG=$ModemIsAnalog"
329
	log "DESCRIPTION=$ModemDescription"
330
	success
331
332
##
333
## ModemIdent
334
##
335
## This identifies the type of modem and sets these variables accordingly:
336
##
337
##	$ModemDescription
338
##	$ModemSetupFunc
339
##	$ModemAnsSetupFunc
340
##	$ModemDetectRing
341
##	$ModemIsAnalog
342
##
343
## If no response seen, this sets $ModemDescription to the empty string.
344
##
345
346
ModemIdent:
347
	set $ModemDescription ""
348
	set $ModemSetupFunc ""
349
	set $ModemAnsSetupFunc ""
350
	set $ModemDetectRing ""
351
	set $ModemIsAnalog "yes"
352
	if $InitString != "" goto ModemIdentCustom
353
	print "ATI\r\n"
354
	match "ADTRAN EXPRESS XR" ModemIdentAdtranXRT
355
	match "Model: Ovation MC950D Card" ModemIdentMC950D
356
	match "ERR" ModemIdentGeneric
357
	match "OK\r\n" ModemIdentGeneric
358
	wait 3
359 29851d8e gnhb
	print "ATI1\r\n"
360
	match "NTK omni.net" ModemIdentNTK
361
	match "ERR" ModemIdentGeneric
362
	match "OK\r\n" ModemIdentGeneric
363 9ebe7028 gnhb
	wait 3
364
	print "ATI3\r\n"
365
	match "Courier" ModemIdentUsr
366
	match "Sportster" ModemIdentUsr
367
	match "3ComImpact IQ" ModemIdentImpactIQ
368
	match "U.S. Robotics 56K" ModemIdentUsr
369
	match "ZOOM V.90" ModemIdentZoom56
370
	match "LT V.90" ModemIdentLucent
371
	match "ERR"
372
	match "OK\r\n"
373
	wait 3
374
	print "ATI4\r\n"
375
	match "AtermIT NEC Corporation" ModemIdentAterm
376
	match "INSMATEV-7 NTT Corporation" ModemIdentAterm
377
	match "MNP Class 10 V.34 Modem" ModemIdentDeskPorte
378
	match "Smart One 56" ModemIdentSmartOne
379
	match "ERR"
380
	match "OK\r\n"
381
	wait 3
382 29851d8e gnhb
	print "ATI5\r\n"
383
	match "C885" ModemIdentC885
384
	match "ERR"
385 9ebe7028 gnhb
	match "OK\r\n" ModemIdentGeneric
386
	wait 3
387 29851d8e gnhb
	print "ATI8\r\n"
388
	match "BitSURFR PRO\r" ModemIdentBitsurfr
389
	match "BitSURFR PRO EZ" ModemIdentBitsurfrEZ
390
	match "3C882" ModemIdentImpactIQ
391
	match "ERR"
392
	match "OK\r\n"
393
	wait 3
394
	log "The modem is not responding to any ATI[1,3-5,8] commands."
395 9ebe7028 gnhb
	failure
396
397
ModemIdentGeneric:
398
	set $ModemDescription "Hayes compatible modem"
399 75e89498 smos
	if $SimPin != "" call DialPeerSetPin
400
	if $APN != "" call DialPeerSetAPN
401 9ebe7028 gnhb
	set $ModemSetupFunc GenericSetup
402
	return
403
404
ModemIdentCustom:
405
	set $ModemDescription "Custom modem"
406 c22d9142 Sven Auhagen
	if $SimPin != "" call DialPeerSetPin
407
	if $APN != "" call DialPeerSetAPN
408 9ebe7028 gnhb
	set $ModemSetupFunc CustomSetup
409
	return
410
411
ModemIdentUsr:
412
	set $SportsterHack "no"
413
	if $matchedString == "Sportster" set $SportsterHack "yes"
414
	set $ModemDescription "USR $matchedString modem"
415
	call GetOK
416
	set $ModemSetupFunc UsrSetup
417
	return
418
ModemIdentC885:
419
	set $ModemDescription "Sierra Wireless Compass $matchedString USB 3G modem"
420
	set $ModemSetupFunc GenericSetup
421
	return
422
ModemIdentMC950D:
423
	set $ModemDescription "Novatel Wireless $matchedString USB 3G modem"
424
	set $ModemSetupFunc GenericSetup
425
	return
426
ModemIdentBitsurfrEZ:
427
	set $bitsEZ "yes"
428
ModemIdentBitsurfr:
429
	set $ModemDescription "Motorola $matchedString"
430
	call GetOK
431
	set $ModemSetupFunc BitsurfrSetup
432
	set $ModemIsAnalog "no"
433
	set $ModemDetectRing BitsurfrDetectRing
434
	return
435
436
ModemIdentImpactIQ:
437
	set $matchedString "3ComImpact IQ"
438
	set $ModemDescription "$matchedString"
439
	call GetOK
440
	set $ModemSetupFunc ImpactIQSetup
441
	set $ModemIsAnalog "no"
442
	set $ModemDetectRing ImpactIQDetectRing
443
	return
444
445
ModemIdentAdtranXRT:
446
	set $ModemDescription "AdTran Express XR/XRT"
447
	call GetOK
448
	set $ModemSetupFunc AdtranXRTSetup
449
	set $ModemIsAnalog "no"
450
	return
451
452
ModemIdentAterm:
453
	set $ModemDescription "NEC Aterm TA"
454
	call GetOK
455
	set $ModemSetupFunc AtermSetup
456
	set $ModemIsAnalog "no"
457
	return
458
459
ModemIdentNTK:
460
	set $ModemDescription "$matchedString"
461
	call GetOK
462
	set $ModemSetupFunc NTKSetup
463
	set $ModemIsAnalog "no"
464
	return
465
466
ModemIdentDeskPorte:
467
	set $ModemDescription "$matchedString"
468
	call GetOK
469
	set $ModemSetupFunc DeskPorteSetup
470
	return
471
472
ModemIdentZoom56:
473
ModemIdentSmartOne:
474
	set $ModemDescription "$matchedString"
475
	call GetOK
476
	set $ModemSetupFunc Modem56Setup
477
	return
478
479
# Support the Lucent Winmodem, Xircom 56k
480
ModemIdentLucent:
481
	set $ModemDescription "$matchedString"
482
	call GetOK
483
	set $ModemSetupFunc ModemLucentSetup
484
	return
485
486
#################################################################
487
#
488
#	GENERIC MODEM SETUP
489
#
490
#################################################################
491
492
GenericSetup:
493
	set $noDialToneSubr GenericNoDialtone
494
	set $temp "M1"
495
	if $SpeakerOff == "yes" set $temp "M0"
496
	set $modemCmd "&F&C1&D2E0S0=0${temp}"
497
	call ModemCmd2
498
	return
499
500
CustomSetup:
501
	set $noDialToneSubr GenericNoDialtone
502
	set $modemCmd "${InitString}"
503
	call ModemCmd2
504
	return
505
506
GenericNoDialtone:
507
	log "No dialtone. Is the modem plugged in?"
508
	return
509
510
#################################################################
511
#
512
#	USR MODEM SETUP
513
#
514
#################################################################
515
516
UsrSetup:
517
# Lower baudrate to 57600 for crappy internal Sportster modem
518
	if $SportsterHack != "yes" goto UsrSetup2
519
	if $modemDevice != "/dev/cuad2" goto UsrSetup2
520
	set $Baudrate 57600
521
	set $modemCmd ""
522
	call ModemCmd2
523
UsrSetup2:
524
	set $noDialToneSubr GenericNoDialtone
525
	set $temp "M1"
526
	if $SpeakerOff == "yes" set $temp "M0"
527
	set $modemCmd "&F1&C1&D2E0S0=0S13.0=1L0S6=5${temp}"
528
	call ModemCmd2
529
	return
530
531
#################################################################
532
#
533
#	GENERAL 56K MODEM SETUP
534
#
535
#################################################################
536
537
Modem56Setup:
538
	set $noDialToneSubr GenericNoDialtone
539
	set $temp "M1"
540
	if $SpeakerOff == "yes" set $temp "M0"
541
	set $modemCmd "&FL2W2E0${temp}"
542
	call ModemCmd2
543
	return
544
545
#################################################################
546
#
547
#	LUCENT WINMODEM AND XIRCOM 56K SETUP
548
#
549
#################################################################
550
551
ModemLucentSetup:
552
	set $noDialToneSubr GenericNoDialtone
553
	set $temp "M1"
554
	if $SpeakerOff == "yes" set $temp "M0"
555
	set $tempCountryCode ""
556
	if $CountryCode != "" set $tempCountryCode "+GCI=${CountryCode}"
557
	if $CountryCode != "" log "Use country ${CountryCode}"
558
	set $modemCmd "&FL2W2E0${temp}${tempCountryCode}"
559
	call ModemCmd2
560
	return
561
562
#################################################################
563
#
564
#	BITSURFR PRO AND BITSURFR PRO EZ SETUP
565
#
566
#################################################################
567
568
BitsurfrSetup:
569
	set $noDialToneSubr BitsurfrNoDialtone
570
	set $factory "1"
571
	if $bitsEZ == "yes" set $factory "0"
572
	set $modemCmd "Z&F${factory}&C1&D2E0W1X2%A2=95S0=0"
573
	call ModemCmd2
574
575
# Set to 230K baud if we support it
576
577
	if $bitsEZ != "yes" goto BitsurfrSetup1
578
	set $modemCmd "@P2=230400"
579
	set $newBaudrate "230400"
580
	call SetBaudrate
581
582
# Check software revision and ISDN settings
583
584
BitsurfrSetup1:
585
	if $optimize == "yes" goto BitsurfrSetup2
586
	if $bitsEZ != "yes" call BitsurfrCheckRev
587
	call BitsurfrCheckConfig
588
589
# Set the PAP/CHAP, multi-link, and 56K/64K settings, and return
590
591
BitsurfrSetup2:
592
	set $authCmd "@M2=P"
593
	if $TA_AuthChap == "yes" set $authCmd "@M2=C"
594
	set $bondCmd "@B0=1"
595
	if $TA_Bonding == "yes" set $bondCmd "@B0=2"
596
	set $bearCmd "%A4=0"
597
	if $TA_56K == "yes" set $bearCmd "%A4=1"
598
	if $TA_VoiceCall == "yes" set $bearCmd "%A4=1"
599
	set $voiceCmd "%A98=D%A96=0"
600
	if $TA_VoiceCall == "yes" set $voiceCmd "%A98=S%A96=1"
601
602
# BS PRO EZ changes
603
604
	if $bitsEZ == "yes" set $authCmd "${authCmd}@M20=\"\""
605
	set $modemCmd "$authCmd$bondCmd$bearCmd$voiceCmd"
606
	call ModemCmd2
607
	if $TA_NoDoubleTelno == "yes" return
608
	if $TA_Bonding == "yes" set $ModTelephone "${Telephone}&${Telephone}"
609
	return
610
611
##
612
## What to do when NO DIALTONE
613
##
614
615
BitsurfrNoDialtone:
616
	log "ISDN initialization failed (or BitSURFR restarting). Please verify proper line connection and ISDN settings."
617
	return
618
619
##
620
## BitsurfrCheckConfig
621
##
622
## Verify and adjust ISDN configuration as necessary
623
##
624
625
BitsurfrCheckConfig:
626
	log "Checking the BitSURFR's ISDN configuration..."
627
	set $valueChanged "no"
628
629
# Check switch type
630
631
	set $checkCmd "!C0"
632
	set $checkValue "000"
633
	set $checkValueNew "0"
634
	if $TA_SwitchType == "DMS-100" set $checkValue "001"
635
	if $TA_SwitchType == "DMS-100" set $checkValueNew "1"
636
	if $TA_SwitchType == "NI-1" set $checkValue "002"
637
	if $TA_SwitchType == "NI-1" set $checkValueNew "2"
638
	set $checkMsg "Reprogramming switch type ($TA_SwitchType)..."
639
	call ModemCheckValue
640
641
	set $checkCmd "!C1"
642
	set $checkValue "004"
643
	set $checkValueNew "4"
644
	if $TA_SwitchType == "DMS-100" set $checkValue "003"
645
	if $TA_SwitchType == "DMS-100" set $checkValueNew "3"
646
	if $TA_SwitchType == "5ESS P2P" set $checkValue "000"
647
	if $TA_SwitchType == "5ESS P2P" set $checkValueNew "0"
648
	if $TA_SwitchType == "5ESS MP" set $checkValue "001"
649
	if $TA_SwitchType == "5ESS MP" set $checkValueNew "1"
650
	set $checkMsg "Reprogramming switch software version..."
651
	call ModemCheckValue
652
653
# Check directory numbers
654
655
	set $checkCmd "*1!N1"
656
	set $checkValue $TA_Dirno1
657
	set $checkValueNew $TA_Dirno1
658
	set $checkMsg "Reprogramming voice line #1 directory number..."
659
	call ModemCheckValue
660
661
	set $checkCmd "*2!N1"
662
	set $checkValue $TA_Dirno2
663
	set $checkValueNew $TA_Dirno2
664
	set $checkMsg "Reprogramming voice line #2 directory number..."
665
	call ModemCheckValue
666
	set $checkCmd "!N1"
667
	set $checkMsg "Reprogramming data line directory number..."
668
	call ModemCheckValue
669
670
# Check SPIDs
671
672
	set $checkCmd "*1!C6"
673
	set $checkValue $TA_SPID1
674
	set $checkValueNew $TA_SPID1
675
	set $checkMsg "Reprogramming voice line #1 SPID..."
676
	call ModemCheckValue
677
678
	set $checkCmd "*2!C6"
679
	set $checkValue $TA_SPID2
680
	set $checkValueNew $TA_SPID2
681
	set $checkMsg "Reprogramming voice line #2 SPID..."
682
	call ModemCheckValue
683
	set $checkCmd "!C6"
684
	set $checkMsg "Reprogramming data line SPID..."
685
	call ModemCheckValue
686
687
# Restart if necessary
688
689
	if $valueChanged == "no" return
690
	log "Restarting BitSURFR Pro with new configuration..."
691
	set $modemCmd ">W"
692
	call ModemCmd2
693
	set $modemCmd ">Z"
694
	call ModemCmd2
695
	failure
696
697
##
698
## Verify the BitSURFR's software revision. Only do this
699
## once, the first time we try to dial.
700
##
701
702
BitsurfrCheckRev:
703
	log "Checking the BitSURFR's software revision..."
704
	print "ATI3\r\n"
705
	match "-1A" BitsurfrCheckRevOld
706
	match "-1B" BitsurfrCheckRevOld
707
	match "-1C" BitsurfrCheckRevOld
708
	match "-1D" BitsurfrCheckRevOld
709
	match "-1E" BitsurfrCheckRevOld
710
	match "-1F" BitsurfrCheckRevOld
711
	match "-1G" BitsurfrCheckRevOld
712
	match "-1H" BitsurfrCheckRevOld
713
	match "-1I" BitsurfrCheckRevOld
714
	match "OK\r\n" BitsurfrCheckRevOK
715
	match "ERR"
716
	wait 5
717
	log "The BitSURFR did not properly answer ATI3."
718
	failure
719
BitsurfrCheckRevOK:
720
	return
721
BitsurfrCheckRevOld:
722
	log "The BitSURFR Pro has an old software revision $matchedString. Please upgrade according to the manufacturer's instructions."
723
	call GetOK
724
	failure
725
726
# This is how we detect an incoming call with a BitSURFR
727
728
BitsurfrDetectRing:
729
# First, we need to be properly configured
730
	call BitsurfrSetup
731
# Enable Caller-ID logging
732
	set $modemCmd "@N0=1*1@N0=1*2@N0=1"
733
	call ModemCmd
734
	if $modemCmdResult != "OK" goto RingbackWait
735
# A "RING" at any time is good enough
736
	match ringset "RING\r\n" RingbackDone
737
# Clear Caller-ID buffers
738
	set $modemCmd "@L0*1@L0*2@L0"
739
	call ModemCmd2
740
# Read each buffer
741
	call BitsurfrDetectReadCID
742
	log "Remote Dial-Back mode enabled; waiting for incoming call."
743
# Now wait indefinitely for one of those buffers to change
744
BitsurfrDetectLoop:
745
	wait 5
746
	set $oldDataCID $dataCID
747
	set $oldVoice1CID $voice1CID
748
	set $oldVoice2CID $voice2CID
749
	call BitsurfrDetectReadCID
750
	if $oldDataCID != $dataCID goto BitsurfrDetectDone
751
	if $oldVoice1CID != $voice1CID goto BitsurfrDetectDone
752
	if $oldVoice2CID != $voice2CID goto BitsurfrDetectDone
753
	goto BitsurfrDetectLoop
754
755
# Examine the CID from each port
756
BitsurfrDetectDone:
757
	set $cid $dataCID
758
	call BitsurfrDetectTryCID
759
	set $cid $voice1CID
760
	call BitsurfrDetectTryCID
761
	set $cid $voice2CID
762
	call BitsurfrDetectTryCID
763
	goto RingbackDetectNoCID
764
765
# Try to extract the calling party number
766
BitsurfrDetectTryCID:
767
# Strip the log number
768
	if $cid match "[0-9] (.*)" set $cid $matchedString1
769
# Check for various strings
770
	if $cid match "BLOCKED" return
771
	if $cid match "NO NUMBER" return
772
	if $cid match "NO CID SERVICE" return
773
	if $cid match "OUT OF AREA" return
774
	goto RingbackDetectCID
775
776
# Read Caller-ID buffers
777
BitsurfrDetectReadCID:
778
	set $modemCmd "@L1"
779
	call ModemQueryStrip
780
	set $dataCID $modemQuery
781
	set $modemCmd "*1@L1"
782
	call ModemQueryStrip
783
	set $voice1CID $modemQuery
784
	set $modemCmd "*2@L1"
785
	call ModemQueryStrip
786
	set $voice2CID $modemQuery
787
	return
788
789
#################################################################
790
#
791
#	3COM IMPACT IQ SETUP
792
#
793
#################################################################
794
795
ImpactIQSetup:
796
	set $noDialToneSubr ImpactIQNoDialtone
797
	set $modemCmd "Z&F%C2E0"
798
	call ModemCmd2
799
800
# Set to 230K baud if we support it
801
802
	set $modemCmd "$$B230400"
803
	set $newBaudrate "230400"
804
	call SetBaudrate
805
806
# Check ISDN config and link status (XXX should we check revision too?)
807
808
ImpactIQSetup1:
809
	if $optimize == "yes" goto IQInitSetup2
810
	call ImpactIQCheckConfig
811
	call ImpactIQCheckLink
812
813
# Now set the PAP/CHAP setting and voice/data originate mode setting
814
815
IQInitSetup2:
816
	set $authCmd "S84=1"
817
	if $TA_AuthChap == "yes" set $authCmd "S84=0"
818
	set $voiceCmd "S61=0"
819
	if $TA_VoiceCall == "yes" set $voiceCmd "S61=1"
820
	set $modemCmd "$authCmd$voiceCmd"
821
	call ModemCmd2
822
	if $TA_NoDoubleTelno == "yes" return
823
	if $TA_Bonding == "yes" set $ModTelephone "${Telephone}&${Telephone}"
824
	return
825
826
##
827
## What to do when NO DIALTONE
828
##
829
830
ImpactIQNoDialtone:
831
	log "ISDN config problem (or modem restart). Check your ISDN switch type, directory numbers, and SPID settings."
832
	return
833
834
##
835
## ImpactIQCheckLink
836
##
837
## Check the link status registers
838
##
839
840
ImpactIQCheckLink:
841
	log "Checking the ISDN modem's link status..."
842
	print "ATS59?\r\n"
843
	match "000" IQSyncFail
844
	match "001" IQSyncOK
845
	match "ERR"
846
	match "OK\r\n"
847
	wait 3
848
	call GetOK
849
	log "The ISDN modem did not properly answer ATS59?"
850
	failure
851
IQSyncOK:
852
	call GetOK
853
	goto ImpactIQCheckInit
854
IQSyncFail:
855
	log "The ISDN modem is not receiving any ISDN signal. Please verify that it's connected to an ISDN line."
856
	call GetOK
857
	failure
858
859
ImpactIQCheckInit:
860
	set $impactInitReg "57"
861
	call IQInitCheck
862
	if $TA_Bonding == "yes" return
863
	set $impactInitReg "58"
864
	call IQInitCheck
865
	return
866
867
# A little subroutine
868
869
IQInitCheck:
870
	print "ATS${impactInitReg}?\r\n"
871
	match "000" IQInitOK
872
	match "001" IQInitOK
873
	match "002" IQInitFail
874
	match "ERR"
875
	match "OK\r\n"
876
	wait 3
877
	call GetOK
878
	log "The ISDN modem did not properly answer ATS${impactInitReg}?"
879
	failure
880
IQInitOK:
881
	call GetOK
882
	return
883
IQInitFail:
884
	log "ISDN initialization failed. Please check your ISDN switch type, directory numbers, and SPID settings."
885
	call GetOK
886
	failure
887
888
##
889
## ImpactIQCheckConfig
890
##
891
## Verify and adjust ISDN configuration as necessary
892
##
893
894
ImpactIQCheckConfig:
895
	log "Checking the ISDN modem's ISDN configuration..."
896
	set $valueChanged "no"
897
898
# Check switch type XXX
899
#
900
# NOTE: The Impact IQ changes the value of this field as it auto-detects.
901
# Not only that, but it cycles through each switch type as it is "trying
902
# out" that type, so that reading this field is pretty much useless...
903
# Our strategy is just to hope that auto-detect works!
904
905
	if $TA_NewSwitch != "yes" goto ImpactIQCheckDirnos
906
	log "Initiating switch type auto-detect..."
907
	set $modemCmd "S50=0"
908
	call ModemCmd2
909
	set $TA_NewSwitch ""
910
	set $valueChanged "yes"
911
	set $iq_new_switch "yes"
912
913
# Check directory numbers
914
915
ImpactIQCheckDirnos:
916
	set $checkCmd "S51"
917
	set $checkValue $TA_Dirno1
918
	set $checkValueNew $TA_Dirno1
919
	set $checkMsg "Reprogramming line #1 directory number..."
920
	call ModemCheckValue
921
922
	set $checkCmd "S53"
923
	set $checkValue $TA_Dirno2
924
	set $checkValueNew $TA_Dirno2
925
	set $checkMsg "Reprogramming line #2 directory number..."
926
	call ModemCheckValue
927
928
# Check SPIDs
929
930
	set $checkCmd "S52"
931
	set $checkValue $TA_SPID1
932
	set $checkValueNew $TA_SPID1
933
	set $checkMsg "Reprogramming line #1 SPID..."
934
	call ModemCheckValue
935
936
	set $checkCmd "S54"
937
	set $checkValue $TA_SPID2
938
	set $checkValueNew $TA_SPID2
939
	set $checkMsg "Reprogramming line #2 SPID..."
940
	call ModemCheckValue
941
942
# Check 56K/64K setting
943
944
	set $checkValue "064"
945
	set $checkValueNew "64"
946
	if $TA_56K == "yes" set $checkValue "056"
947
	if $TA_56K == "yes" set $checkValueNew "56"
948
	set $checkCmd "S60"
949
	set $checkMsg "Reprogramming B channel data rate to ${checkValueNew}K..."
950
	call ModemCheckValue
951
	set $checkValueNew ""
952
953
# Check Multi-link setting
954
955
	set $checkValue "000"
956
	set $checkValueNew "0"
957
	if $TA_Bonding == "yes" set $checkValue "001"
958
	if $TA_Bonding == "yes" set $checkValueNew "1"
959
	set $checkCmd "S80"
960
	set $checkMsg "Reprogramming mutli-link PPP setting..."
961
	call ModemCheckValue
962
963
# Restart if necessary, and wait extra long if the switch type changed
964
965
	if $valueChanged == "no" return
966
	log "Restarting ISDN modem with the new configuration..."
967
	set $modemCmd "Z"
968
	call ModemCmd2
969
	failure
970
971
##
972
## Detect an incoming call with the 3Com
973
##
974
975
ImpactIQDetectRing:
976
	call ImpactIQSetup
977
	if $modemCmdResult != "OK" goto RingbackWait
978
	match ringset "RING\r\n" RingbackDone
979
# Clear Caller-ID buffers
980
	set $modemCmd "\\N0"
981
# We don't care if this command fails...
982
	call ModemCmd
983
# Read most recent incoming call
984
	call ImpactIQDetectReadCID
985
	log "Remote Dial-Back mode enabled; waiting for incoming call."
986
# Now wait for a change
987
ImpactIQDetectLoop:
988
	wait 5
989
	set $oldIncomingCall $incomingCall
990
	call ImpactIQDetectReadCID
991
	if $oldIncomingCall != $incomingCall goto ImpactIQDetectDone
992
	goto ImpactIQDetectLoop
993
994
# Examine the CID from each port
995
ImpactIQDetectDone:
996
	if $incomingCall !match "((.{14}).{10}) ((.{14}).{10}) ((.{14}).{10})" goto RingbackDetectNoCID
997
	set $dataCID $matchedString2
998
	set $voice1CID $matchedString4
999
	set $voice2CID $matchedString6
1000
	set $cid $dataCID
1001
	call ImpactIQDetectTryCID
1002
	set $cid $voice1CID
1003
	call ImpactIQDetectTryCID
1004
	set $cid $voice2CID
1005
	call ImpactIQDetectTryCID
1006
	goto RingbackDetectNoCID
1007
1008
# Look for a valid CID string
1009
ImpactIQDetectTryCID:
1010
	if $cid match " *" return
1011
	if $cid match " *N/A" return
1012
	goto RingbackDetectCID
1013
1014
# Read first line of incoming call log (it's the 14th line of output)
1015
ImpactIQDetectReadCID:
1016
	set $modemCmd "\\N"
1017
	call ModemCmdSend
1018
	call ReadLine
1019
# Older version of the 3Com don't support this command
1020
	if $matchedString == "OK" return
1021
	if $matchedString match "ERR(O)?(R)?" return
1022
	call ReadLine
1023
	call ReadLine
1024
	call ReadLine
1025
	call ReadLine
1026
	call ReadLine
1027
	call ReadLine
1028
	call ReadLine
1029
	call ReadLine
1030
	call ReadLine
1031
	call ReadLine
1032
	call ReadLine
1033
	call ReadLine
1034
	call ReadLine
1035
	set $incomingCall $matchedString
1036
	call GetOK
1037
	return
1038
1039
#################################################################
1040
#
1041
#	NEC ATERM SETUP
1042
#
1043
#################################################################
1044
1045
AtermSetup:
1046
	if $AtermHardReset == "yes" goto AtermSetup2
1047
1048
# Do hardware reset, which takes a while and doesn't give back "OK"
1049
1050
	log "Initializing modem..."
1051
	print "ATZ98\r\n"
1052
	wait 6
1053
	set $AtermHardReset "yes"
1054
	failure
1055
1056
AtermSetup2:
1057
1058
# Set to 230K baud if we support it
1059
1060
	set $modemCmd ""
1061
	set $newBaudrate "230400"
1062
	call SetBaudrate
1063
1064
# Is this an IT55 or IT65?
1065
1066
	set $atermIT65 ""
1067
	set $modemCmd "$$N14=0"
1068
	call ModemCmd
1069
	if $modemCmdResult == "OK" set $atermIT65 "yes"
1070
1071
# Set normal stuff, PPP mode
1072
1073
	set $modemCmd "&C1&D0&K3X4$$N1=1$$N9=0"
1074
	call ModemCmd2
1075
1076
# Set the multi-link setting
1077
1078
	set $bondCmd "$$N11=0"
1079
	if $TA_Bonding == "yes" set $bondCmd "$$N11=1"
1080
	set $modemCmd "$bondCmd"
1081
	call ModemCmd2
1082
1083
# Additional settings for the IT65 go here...
1084
1085
	if $atermIT65 != "yes" return
1086
	return
1087
1088
#################################################################
1089
#
1090
#	MICROCOM DESKPORTE SETUP
1091
#
1092
#################################################################
1093
1094
DeskPorteSetup:
1095
	set $noDialToneSubr GenericNoDialtone
1096
	set $temp "M1"
1097
	if $SpeakerOff == "yes" set $temp "M0"
1098
	set $modemCmd "Z&F&C1&D2X3E0S0=0${temp}"
1099
	call ModemCmd2
1100
	return
1101
1102
#################################################################
1103
#
1104
#	KOREAN TERMINAL ADAPTER SETUP
1105
#
1106
#################################################################
1107
1108
NTKSetup:
1109
	set $noDialToneSubr GenericNoDialtone
1110
	set $modemCmd "ZB40&J3"
1111
	call ModemCmd2
1112
	return
1113
1114
#################################################################
1115
#
1116
#	ADTRAN EXPRESS XRT SETUP
1117
#
1118
#################################################################
1119
1120
AdtranXRTSetup:
1121
	set $noDialToneSubr ImpactIQNoDialtone
1122
	set $dialErrorSubr AdtranXRTDialError
1123
	set $bonding "&F1"
1124
	if $TA_Bonding == "yes" set $bonding "&F2"
1125
	set $chap "S118=0"
1126
	if $TA_AuthChap == "yes" set $chap "S118=32"
1127
	set $origCmd "S53=3"
1128
	if $TA_56K == "yes" set $origCmd "S53=2"
1129
	if $TA_VoiceCall == "yes" set $origCmd "S53=0"
1130
	set $modemCmd "ZE0${bonding}&C1&D2${chap}${origCmd}"
1131
	call ModemCmd2
1132
1133
# Check ISDN config and link status (XXX should we check revision too?)
1134
1135
	if $optimize == "yes" return
1136
	call AdtranXRTCheckConfig
1137
	call AdtranXRTCheckLink
1138
	return
1139
1140
##
1141
## What to do when ERROR when dialing
1142
##
1143
## This is what the Adtran returns if the line is not ready yet.
1144
## So we look into the status buffer to see if we recognize the
1145
## error condition.
1146
##
1147
1148
AdtranXRTDialError:
1149
	call AdtranXRTDiagnose
1150
	failure
1151
1152
##
1153
## Check the last status bufffer entry for what the problem is
1154
## XXX Figure out more stuff to look for and when it can happen
1155
##
1156
1157
AdtranXRTDiagnose:
1158
	log "Checking the Adtran status buffer..."
1159
	print "AT!S\r\n"
1160
	match "\r\n\r\n" AdtranXRTDiagBlank
1161
	match "END OF STATUS BUFFER" AdtranXRTDiagBlank
1162
	match "L1 not up." AdtranXRTDiagL1
1163
	match "FACILITY_NOT_SUBSCRIBED" AdtranXRTDiagFNS
1164
	match "Unknown AT cmd" IQSyncOK
1165
	match "ERR"
1166
	match "OK\r\n"
1167
	wait 3
1168
	call GetOK
1169
	log "The ISDN modem did not properly answer ATS59?"
1170
	failure
1171
	goto ImpactIQCheckInit
1172
1173
AdtranXRTDiagFNS:
1174
	log "ISDN initialization failed. Please check your ISDN switch type, directory numbers, and SPID settings."
1175
	failure
1176
1177
AdtranXRTDiagL1:
1178
	log "The ISDN modem is not receiving any ISDN signal. Please verify that it's connected to an ISDN line."
1179
	failure
1180
1181
AdtranXRTDiagBlank:
1182
	log "ISDN initialization failed or restarting link. Please verify proper line connection and ISDN settings."
1183
	failure
1184
1185
##
1186
## AdtranXRTCheckLink
1187
##
1188
## Check the link status registers
1189
##
1190
1191
AdtranXRTCheckLink:
1192
	log "Checking the ISDN modem's link status..."
1193
	print "AT!S1\r\n"
1194
	match "Link In Sync" AdtranXRTSyncReg
1195
	match "Getting" AdtranXRTSyncReg
1196
	match "Register" AdtranXRTSyncReg
1197
	match "Ready" AdtranXRTSyncOK
1198
	match "Down" AdtranXRTSyncFail
1199
	match "ERR"
1200
	match "OK\r\n"
1201
	wait 3
1202
	call GetOK
1203
	log "The ISDN modem did not properly answer AT!S1."
1204
	failure
1205
AdtranXRTSyncOK:
1206
	return
1207
AdtranXRTSyncFail:
1208
	print "ATDT1\r\n"
1209
	wait 1
1210
	goto AdtranXRTDiagnose
1211
AdtranXRTSyncReg:
1212
	log "The ISDN modem is initializing itself."
1213
	failure
1214
1215
##
1216
## AdtranXRTCheckConfig
1217
##
1218
## Verify and adjust ISDN configuration as necessary
1219
##
1220
1221
AdtranXRTCheckConfig:
1222
	log "Checking the ISDN modem's ISDN configuration..."
1223
	set $valueChanged "no"
1224
1225
	set $checkCmd "S52"
1226
	set $checkValue "000"
1227
	set $checkValueNew "0"
1228
	if $TA_SwitchType == "DMS-100" set $checkValue "001"
1229
	if $TA_SwitchType == "DMS-100" set $checkValueNew "1"
1230
	if $TA_SwitchType == "NI-1" set $checkValue "002"
1231
	if $TA_SwitchType == "NI-1" set $checkValueNew "2"
1232
	set $checkMsg "Reprogramming switch type ($TA_SwitchType)..."
1233
	call ModemCheckValue
1234
1235
# Check directory numbers
1236
1237
AdtranXRTCheckDirnos:
1238
	set $checkCmd "SS62"
1239
	set $checkValue $TA_Dirno1
1240
	set $checkValueNew $TA_Dirno1
1241
	set $checkMsg "Reprogramming line #1 directory number..."
1242
	call ModemCheckValue
1243
1244
	set $checkCmd "SS63"
1245
	set $checkValue $TA_Dirno2
1246
	set $checkValueNew $TA_Dirno2
1247
	set $checkMsg "Reprogramming line #2 directory number..."
1248
	call ModemCheckValue
1249
1250
# Check SPIDs
1251
1252
	set $checkCmd "SS60"
1253
	set $checkValue $TA_SPID1
1254
	set $checkValueNew $TA_SPID1
1255
	set $checkMsg "Reprogramming line #1 SPID..."
1256
	call ModemCheckValue
1257
1258
	set $checkCmd "SS61"
1259
	set $checkValue $TA_SPID2
1260
	set $checkValueNew $TA_SPID2
1261
	set $checkMsg "Reprogramming line #2 SPID..."
1262
	call ModemCheckValue
1263
1264
# Restart if necessary
1265
1266
	if $valueChanged == "no" return
1267
	log "Restarting ISDN modem with the new configuration..."
1268
	set $modemCmd "&W"
1269
	call ModemCmd2
1270
	set $modemCmd "Z"
1271
	call ModemCmd2
1272
	failure
1273
1274
#################################################################
1275
#
1276
#	BASIC MODEM STUFF
1277
#
1278
#################################################################
1279
1280
##
1281
## ModemAnswer
1282
##
1283
## Wait for a RING and answer it. Variables:
1284
##
1285
##  $RingTimeout	How long for a RING before giving up (default 10 min)
1286
##  $ConnectTimeout	How long for connect after answering (default 45 secs)
1287
##
1288
## Returns:
1289
##
1290
##  $answerReturn	"OK" or "FAIL"
1291
##  $ConnectionSpeed	Connection speed reported by modem (possibly empty)
1292
##
1293
1294
ModemAnswer:
1295
	if $RingTimeout == "" set $RingTimeout 600
1296
	if $ConnectTimeout == "" set $ConnectTimeout 45
1297
	match "RING\r" ModemAnswerGotRing
1298
	wait $RingTimeout
1299
	log "No RING detected after $RingTimeout seconds."
1300
	set $answerReturn "FAIL"
1301
	return
1302
ModemAnswerGotRing:
1303
	log "Incoming call detected..."
1304
	print "ATA\r\n"
1305
	regex "CONNECT *([0-9]*).*$" ModemAnswerConnect
1306
	wait $ConnectTimeout
1307
	log "Failed to connect incoming call."
1308
	set $answerReturn "FAIL"
1309
	return
1310
ModemAnswerConnect:
1311
	set $ConnectionSpeed $matchedString1
1312
	set $answerReturn "OK"
1313
	return
1314
1315
##
1316
## ModemFind
1317
##
1318
## Just try to get where we are talking to the modem.
1319
## Returns with $ErrorMsg equal to the empty string if
1320
## we found the modem, or else some error message if not.
1321
##
1322
1323
ModemFind:
1324
1325
# Do a quick check first...
1326
1327
	set $ErrorMsg ""
1328
	call ModemFind4
1329
	if $modemCmdResult == "OK" return
1330
	if $Serial230K != "yes" goto ModemFind1
1331
	set $newBaudrate 230400
1332
	if $Baudrate == "230400" set $newBaudrate 115200
1333
	set $Baudrate $newBaudrate
1334
	call ModemFind4
1335
	if $modemCmdResult == "OK" return
1336
1337
# Now try possible baud rates more extensively
1338
1339
ModemFind1:
1340
	set $Baudrate 115200
1341
	call ModemFind2
1342
	if $modemCmdResult == "OK" return
1343
	if $Serial230K != "yes" return
1344
	set $Baudrate 230400
1345
	wait 1
1346
	call ModemFind2
1347
	if $modemCmdResult == "OK" return
1348
	set $ErrorMsg "The modem is not responding."
1349
	return
1350
1351
# This tries the +++ sequence in case the modem is in "on-line" mode
1352
1353
ModemFind2:
1354
	call ModemFind3
1355
	if $modemCmdResult == "OK" return
1356
	call SendTriplePlus
1357
	call ModemFind3
1358
	return
1359
1360
# This tries a few commands to see if the modem responds with "OK"
1361
1362
ModemFind3:
1363
	set $modemCmd ""
1364
	set $modemCmdTimeout 1
1365
	call ModemCmd0
1366
	if $modemCmdResult == "OK" return
1367
	set $modemCmd "Z"
1368
	set $modemCmdTimeout 2
1369
	call ModemCmd0
1370
	if $modemCmdResult == "OK" return
1371
ModemFind4:
1372
	set $modemCmd ""
1373
	set $modemCmdTimeout 1
1374
	call ModemCmd0
1375
	return
1376
1377
##
1378
## SetBaudrate
1379
##
1380
## Change baud rates (as allowed) and verify modem is still there.
1381
## If not, then fail the script.
1382
##
1383
##   $newBaudrate	New baud rate; if we don't support it, just return.
1384
##   $modemCmd		Command to send modem to jump to the new baud rate.
1385
##
1386
1387
SetBaudrate:
1388
	if $Baudrate == $newBaudrate return
1389
	if $newBaudrate != 230400 goto SetBaudrate2
1390
	if $Serial230K != "yes" return
1391
SetBaudrate2:
1392
	log "Setting serial port speed to $newBaudrate..."
1393
	print "AT$modemCmd\r\n"
1394
	wait 1
1395
	set $Baudrate $newBaudrate
1396
	wait 1
1397
	set $modemCmd ""
1398
	goto ModemCmd2
1399
1400
##
1401 179377b0 robjarsen
## ModemCheckValue
1402 9ebe7028 gnhb
##
1403
## Check the value in an S-register (or equivalent). If it is
1404
## not what we want, then change it and set $valueChanged to "yes",
1405
## and log $checkMsg (if not empty). The value $checkValueNew is
1406
## what we program the S-register to equal if it doesn't match.
1407
##
1408
## The $checkValue must match exactly on the first line of output.
1409 0be67fe5 Chris Buechler
## If we get any weird error, then fail the script.
1410 9ebe7028 gnhb
##
1411
1412
ModemCheckValue:
1413
	set $modemCmd "${checkCmd}?"
1414
	call ModemQuery
1415
	if $modemQuery == $checkValue return
1416
	set $valueChanged "yes"
1417
	set $checkValueMyNew $checkValueNew
1418
	if $checkValueNew == "" set $checkValueMyNew $checkValue
1419
	set $modemCmd "${checkCmd}=${checkValueMyNew}"
1420
	if $checkMsg != "" log $checkMsg
1421
	goto ModemCmd2
1422
1423
##
1424
## ModemCmd
1425
##
1426
## Do the modem command in $modemCmd. Set $modemCmdResult to
1427
##
1428
##	OK	The modem returned "OK"
1429
##	ERROR	The modem returned "ERR" or "ERROR"
1430
##	TIMEOUT	The modem did not respond within three seconds
1431
##
1432
## If ERR or TIMEOUT, also set $ErrorMsg to an appropriate message
1433
##
1434
1435
ModemCmd:
1436
	set $modemCmdTimeout 3
1437
ModemCmd0:
1438
	print "AT$modemCmd\r\n"
1439
	match "OK\r\n" ModemCmdOk
1440
	match "ERR" ModemCmdErr
1441
	wait $modemCmdTimeout
1442
	set $modemCmdResult "TIMEOUT"
1443
ModemCmdTimeout:
1444 fc5324e9 gnhb
	set $ErrorMsg "The modem is not responding to \"AT$modemCmd\" at ModemCmd: label."
1445 9ebe7028 gnhb
	return
1446
ModemCmdOk:
1447
	set $modemCmdResult "OK"
1448
	return
1449
ModemCmdErr:
1450
	set $modemCmdResult "ERROR"
1451 fc5324e9 gnhb
	set $ErrorMsg "The modem responded with \"ERROR\" to the command \"AT$modemCmd\" at ModemCmd: label."
1452 9ebe7028 gnhb
	return
1453
1454
##
1455
## ModemCmd2
1456
##
1457
## Do the modem command in $modemCmd. If we don't get OK back,
1458
## fail the script and log an error message.
1459
##
1460
1461
ModemCmd2:
1462
	call ModemCmd
1463
	if $modemCmdResult == "OK" return
1464
	log $ErrorMsg
1465
	failure
1466
1467
##
1468
## ModemCmdSend
1469
##
1470
## Send a modem command and read the echo'ed CR-LF
1471
##
1472
1473
ModemCmdSend:
1474
	print "AT$modemCmd\r\n"
1475
	match "\r\n" ModemCmdSend2
1476
	wait 3
1477
	goto ModemCmdTimeout
1478
ModemCmdSend2:
1479
	return
1480
1481
##
1482
## ModemQuery
1483
##
1484
## Do the $modemCmd and expect exactly one line of response, then OK.
1485
## Return the response in $modemQuery. If anything goes wrong, die.
1486
##
1487
1488
ModemQuery:
1489
	call ModemCmdSend
1490
	call ReadLine
1491
	set $modemQuery $matchedString
1492
	if $modemQuery == "ERR" goto ModemQueryError
1493
	if $modemQuery == "ERROR" goto ModemQueryError
1494
	goto GetOK
1495
ModemQueryError:
1496
	call ModemCmdErr
1497
	failure
1498
1499
# Same thing, but strip leading and trailing blanks
1500
1501
ModemQueryStrip:
1502
	call ModemQuery
1503
	if $modemQuery match " *(.*) *" nop
1504
	set $modemQuery $matchedString1
1505
	return
1506
1507
##
1508
## ReadLine
1509
##
1510
## Read the next line of output. It should come within $modemCmdTimeout
1511
## seconds, or else we fail. Return it in $matchedString.
1512
##
1513
1514
ReadLine:
1515
	regex "^.*$" ReadLineDone
1516
	wait $modemCmdTimeout
1517
	set $ErrorMsg "The modem is not responding."
1518
	log $ErrorMsg
1519
	failure
1520
ReadLineDone:
1521
	return
1522
1523
##
1524
## Get an OK within 3 seconds or die
1525
##
1526
1527
GetOK:
1528
	match "OK\r\n" GotOK
1529
	wait 3
1530 29851d8e gnhb
	log "The modem did not respond with \"OK\"."
1531 9ebe7028 gnhb
	failure
1532 158b5cc3 gnhb
GotOK:
1533 9ebe7028 gnhb
	return
1534
1535
##
1536
## Send "+++" to get modem attention if on-line
1537
##
1538
1539
SendTriplePlus:
1540
	print "\r\n"
1541
	wait 2
1542
	print "+++"
1543
	wait 2
1544
	return
1545
1546
#################################################################
1547
#
1548
#	LOGIN AUTO-SCRIPTING
1549
#
1550
#################################################################
1551
1552
##
1553
## AutoLogin
1554
##
1555
## Here we attempt to figure out what the remote server wants
1556
## from us. We do this by checking for bytes that correspond
1557
## to PPP packets (in which case we are done) as well as common
1558
## login type stuff like "name:", "ogin:", etc.
1559
##
1560
## This always returns. The hope is that when it returns, the
1561
## remote side has reached PPP mode.
1562
##
1563
## This has been crafted from empirical evidence. Lots of terminal
1564
## servers have various intelligent/stupid features which we
1565
## take advantage of/have to work around.
1566
##
1567
## Variables (set automatically by mpd):
1568
##
1569
##  $Login		Authorization login
1570
##  $Password		Authorization password
1571
##
1572
1573
AutoLogin:
1574
	log "Initiating auto-login..."
1575
1576
# Spend at most this long doing auto-login before giving up
1577
1578
	timer autoLogin 5 AutoLoginTimeout
1579
1580
# At any time if we see an LCP frame (not our own echo) then we're done
1581
1582
	match autoLogin "\x7e\xff\x03\xc0\x21" AutoLoginFrame
1583
	match autoLogin "\x7e\xff\x7d\x23\xc0\x21\x7d\x21" AutoLoginFrame
1584
	match autoLogin "\x7e\xc0\x21" AutoLoginFrame
1585
1586
# Now send a "fake" PPP frame (this is an empty config-reject with id# 172).
1587
# This should trigger any auto-detecting servers to jump into PPP mode,
1588
# which is good because it's faster (by avoiding human readable messages)
1589
# and more reliable (PPP framing).
1590
1591
	print "\x7e\xff\x7d\x23\xc0\x21\x7d\x24\xac\x7d\x20\x7d\x24\x2e\x2b\x7e"
1592
1593
# Wait one second for server to auto-detect PPP or send a login prompt.
1594
# After one second of neither, try sending a carriage return (some servers
1595
# require this). After that, we have to see something recognizable from
1596
# the peer, otherwise we'll just timeout.
1597
1598
	match "ogin" AutoLoginPrompt
1599
	match "name" AutoLoginPrompt
1600
	wait 1
1601
	print "\r"
1602
	match "ogin" AutoLoginPrompt
1603
	match "name" AutoLoginPrompt
1604
	wait
1605
1606
# At this point we've seen a login prompt; do the manual login
1607
1608
AutoLoginPrompt:
1609
	log "Sending login..."
1610
	print "${Login}\r"
1611
	match "word"
1612
	wait
1613
	log "Sending password..."
1614
	print "${Password}\r"
1615
	match "\r"
1616
	wait
1617
	if $didLogin != "yes" match "ogin:" LoginAgain
1618
	match ">"
1619
	match "%"
1620
	match ":"
1621
	wait
1622
	log "Enabling PPP..."
1623
	print "ppp\r"
1624
	cancel all
1625
	return
1626
1627
LoginAgain:
1628
	set $didLogin "yes"
1629
	goto AutoLoginPrompt
1630
1631
# We saw a PPP frame
1632
1633
AutoLoginFrame:
1634
	log "Detected PPP frame."
1635
	cancel all
1636
	return
1637
1638
# We timed out before seeing a PPP frame. Cross your fingers and pray.
1639
1640
AutoLoginTimeout:
1641
	log "Auto-login timeout."
1642
	cancel all
1643
	return