!  Novatel U530!
!	Modified by: Eran <eran AT over-here.org>!	Author:	Ross Barkman!!	History:!		18 Sep 01	First release!		20 Nov 01	Change response parsing!		07 Mar 02	Switch to Context ID 2!		15 Mar 02	Fix init string error!		21 Mar 02	Re-create Context ID 1 version (some networks reject CID2)!		24 Dec 02	Change dialstring fron *99# to *99***1#!		04 Jan 04	Add APN check, retry initial AT, plus minor improvements
!		09 Nov 04	Modified to fit Merlin U530 card (Eran)!!  'mlts' resource info:!    byte 1 == 01 -> modem HAS built-in error correction protocols!    byte 2 == 01 -> modem HAS built-in data compression protocols!    byte 3 == 200 -> max number of chars in varstr 7!    byte 4 == 200 -> max number of chars in varstr 8!    byte 5 == 200 -> max number of chars in varstr 9!	@ORIGINATE@ANSWER!note "Novatel Wireless" 1
note "Test" 1!!	Check APN!!	Common mistake: using *99 instead of APN!ifstr 1 110 "*99***1#"!! ---- Modem setup ----!!! Set serial port speed based on EC/Compression flag, for low-speed serial ports!	(flag is otherwise irrelevant since we always leave EC/Compression on)!		=0 : 57600!		=1 : 115200!ifstr 5 1 "0"! serreset 115200, 0, 8, 1hsreset 0 0 0 0 0 0settries 0jump 2!@LABEL 1! serreset 57600, 0, 8, 1hsreset 0 0 0 0 0 0settries 0!!@LABEL 2!! Check the phone is responding!
!note "Label 2" 1matchclrmatchstr 1 3 "OK\13\10"write "AT\13"matchread 30inctriesiftries 3 101jsr 9jump 2!!@LABEL 3!! Check the phone is a (Sony) Ericsson!!matchclr!matchstr 1 4  "Ericsson"!write "AT+CGMI\13"!matchread 60!jump 109!!@LABEL 4!! Configure the phone!
!note "Label 4" 1matchclrmatchstr 1 5   "OK\13\10"matchstr 2 101 "ERROR\13\10"write "AT&F\13"matchread 30inctriesiftries 3 101jsr 9jump 4!!@LABEL 5pause 20settries 0!!@LABEL 6!! Set additional options!
!note "Label 6" 1matchclrmatchstr 1 10  "OK\13\10"matchstr 2 108 "ERROR\13\10"!! Check Access Point Name stored in dialstring (VarString 1)! If APN is set to None, ignore it!ifstr 1 7 "NONE"!!	Set APN using +CGDCONT=1,"IP","<APN>"!	Set requested QoS using +CGQREQ=1,2,2,2,4,16!		1 = context ID 1!		2 = normal priority!		2 = moderate transfer delay!		2 = non-real-time, can cope with some loss!		4 = 64k peak throughput!		16 = 22k mean throughput!
write "AT&F\13"
write "AT+CMEE=1\13"write "AT+CGDCONT=1,\34IP\34,\34uinternet\34\13"jump 8!!@LABEL 7!!	No APN!write "AT+CGQREQ=1,2,2,2,4,16\13"!!@LABEL 8matchread 60inctriesiftries 3 101
jump 6
jump 10!!@LABEL 9!! Attempt to reset the phone!
!note "Label 9" 1DTRClearpause 5DTRSetflushreturn!!@LABEL 10!! Setup complete!ifANSWER 32!!! ---- Place a call ----!@LABEL 20!!flushnote "Making GPRS connection" 3
write "ATD*99***1#\13"!!! ---- Connect response ----!! Parses successful connect responses in the following format:!   CARRIER!	PROTOCOL: ppp!	COMPRESSION: ccc!   CONNECT zzzzz!@LABEL 32matchclrmatchstr  1 81  "RING\13\10"matchstr  2 102 "NO DIALTONE\13\10"matchstr  3 103 "NO CARRIER"matchstr  4 103 "ERROR\13\10"matchstr  5 104 "BUSY\13\10"matchstr  6 105 "NO ANSWER\13\10"matchstr  7 33  "CARRIER"matchstr  8 34  "CONNECT"matchstr  9 61  "PROTOCOL"matchstr 10 66  "COMPRESSION"matchread 700ifANSWER 32jump 105!!  CARRIER parsing!@LABEL 33!jump 32!!  CONNECT parsing!@LABEL 34!!    2400 and 4800 have three entries each!    to distinguish them from 24000 and 48000!matchclrmatchstr  1 40 "2400\13"matchstr  2 40 "2400/"matchstr  3 40 "2400 "matchstr  4 41 "4800\13"matchstr  5 41 "4800/"matchstr  6 41 "4800 "matchstr  7 42 "7200"matchstr  8 43 "9600"matchstr  9 44 "12000"matchstr 10 45 "14400"matchstr 11 46 "19200"matchstr 12 51 "28800"matchstr 13 52 "38400"matchstr 14 53 "57600"matchstr 15 54 "64000"matchstr 15 55 "115200"matchstr 16 55 "115,200"matchstr 17 56 "230400"matchread 10jump 59!! -- Connection rates --!! CommunicatingAt informs ARA of the link speed!@LABEL 40note "Communicating at 2400 bps." 2CommunicatingAt 2400jump 60!@LABEL 41note "Communicating at 4800 bps." 2CommunicatingAt 4800jump 60!@LABEL 42note "Communicating at 7200 bps." 2CommunicatingAt 7200jump 60!@LABEL 43note "Communicating at 9600 bps." 2CommunicatingAt 9600jump 60!@LABEL 44note "Communicating at 12400 bps." 2CommunicatingAt 12400jump 60!@LABEL 45note "Communicating at 14400 bps." 2CommunicatingAt 14400jump 60!@LABEL 46note "Communicating at 19200 bps." 2CommunicatingAt 19200jump 60!@LABEL 51note "Communicating at 28800 bps." 2CommunicatingAt 28800jump 60!@LABEL 52note "Communicating at 38400 bps." 2CommunicatingAt 38400jump 60!@LABEL 53note "Communicating at 57600 bps." 2CommunicatingAt 57600jump 60!@LABEL 54note "Communicating at 64000 bps." 2CommunicatingAt 64000jump 60!@LABEL 55note "Communicating at 115200 bps." 2CommunicatingAt 115200jump 60!@LABEL 56note "Communicating at 230400 bps." 2CommunicatingAt 230400jump 60!@LABEL 59note "Communicating at GSM variable rate." 2!@LABEL 60!! Check for protocol and compression reports ! following the CONNECT message.!matchclrmatchstr  1 63 "LAPM"matchstr  2 63 "REL"matchstr  3 63 "ARQ"matchstr  4 68 "COMP/"matchstr  5 68 "COMP\13"matchstr  6 63 "V42/"matchstr  7 63 "V42\13"matchstr  8 68 "V42BIS"matchstr  9 68 "V42bis"matchstr 10 63 "MNP\13"matchstr 11 68 "MNP5"matchstr 12 70 "\10"matchread 30jump 70!! -- PROTOCOL parsing --!! Userhook 2 informs ARA that a modem-to-modem error! correcting protocol has been negotiated!@LABEL 61matchclrmatchstr  1 32 "NONE"matchstr  2 62 "LAP"matchstr  3 62 "MNP"matchstr  4 62 "ALT"matchstr  5 32 "\13"matchread 10jump 63!@LABEL 62jsr 64jump 32!@LABEL 63jsr 64jump 60!@LABEL 64note "Modem Reliable Link Established." 2userhook 2return!! -- COMPRESSION parsing --!! Userhook 3 informs ARA that a modem-to-modem compression! protocol has been negotiated!@LABEL 66matchclrmatchstr  1 32 "NONE"matchstr  2 67 "V"matchstr  3 67 "MNP5"matchstr  4 67 "CLASS"matchstr  5 32 "\13"matchread 10jump 68!@LABEL 67jsr 69jump 32!@LABEL 68jsr 69jump 60!@LABEL 69note "Modem Compression Established." 2userhook 3return!!! -- Normal exit after "CONNECT" --!!@LABEL 70!! Turn CTS on, for hardware flow control!HSReset 0 1 0 0 0 0!ifANSWER 71pause 30!@LABEL 71exit 0!!! ---- Answer calls ----!!	A RING result from the modem and in ANSWERING mode!	claims the serial port and answering the phone!@LABEL 81ifORIGINATE 32userhook 1note "Answering phone..." 2write "ATA\13"jump 32!!! ---- Hang up and reset modem ----!@HANGUP@LABEL 90settries 0HSReset 0 0 0 0 0 0!@LABEL 92!!  Escape from data to command mode!matchclrmatchstr 1 94 "OK\13\10"pause 11write "+++"matchread 20!@LABEL 94!! Send hangup command!pause 10matchclrmatchstr 1 98 "NO CARRIER\13\10"matchstr 2 98 "OK\13\10"matchstr 3 98 "ERROR\13\10"matchstr 4 98 "0\13\10"write "ATH0\13"matchread 30! ! If that fails, toggle DTR!DTRClearpause 5DTRSetflush!! Try this three times only!inctriesiftries 3 101jump 92!!@LABEL 98!! Reset phone to default settings!pause 10matchclrmatchstr 1 99 "OK\13\10"write "AT&F\13"matchread 30jump 101!@LABEL 99exit 0!! ---- Error messages -----!! Modem Not Responding@LABEL 101exit -6019!! No Dial Tone@LABEL 102exit -6020!! No Carrier or Error@LABEL 103exit -6021!! Busy@LABEL 104exit -6022!! No Answer@LABEL 105exit -6023!! User Cancellation@LABEL 107exit -6008!@LABEL 108exit -6002 "The phone or network does not seem to support the GPRS options required for this script"!@LABEL 109exit -6002 "This script is only suitable for Ericsson mobile phones"!@LABEL 110exit -6002 "DO NOT put *99... in the telephone number - use the Access Point Name (APN) for your network instead"