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