'2.23
'------------------------------------------------------------------------------------
'Session Initiation Protocol (SIP)
'
'      13.09.2010 ASI  ! updated to use labels below 32768 for BCL 1.5 compatibility
'      01.09      ASI  ! clean history (last version 0.28/13.092010
'                      ! start new version numbering from 1.00
' 1.00 02.11.2010 ASI  ! updated to the new style webUI
'                      + added Ann155 speaker and mic supervision on the home page
'                      ! fixed to recognise the keypress on Ann155
'                      ! started using long variable names (BCL 1.5 feature)
'                      ! set last 32 bits from the MAC address as RTP SSRC
'                      + added registration status
'      03.11.2010 ASI  ! simplified the Basic menu (no submenus)
'                      ! fix a bug in timer 4 and 5 sharing
'                      ! fixing some typos in the webUI help files
'      10.11.2010 ASI  ! fixed wrong remote party ID display in case of incoming call
'                      ! added missing function call in the profile selection webUI
'                        scripts
'                      ! fixed random sip call at boot with the COM port init string
'                        as remote party ID 
'                      ! fixed broken reload of the home page when speaker test is 
'                        started from the webUI
'      12.10.2010 ASI  + added close call on level feature
'   16-18.10.2010 ASI  ! fixed wrong dialing on X8 input even if the ID is not set 
'                      + added support for PS16
'                      - removed correction for detected inputs on Ann 155 (fixed 
'                        in the driver)
'                      ! updated to check for X8 every 15 seconds instead of every
'                        second	
'      15.12.2010 ASI  + added support for the IP Speaker
' 1.01 05.01.2011 ASI  ! fixed typos in the webUI
'                      ! fixed nonworking SonicIP control from the webUI
'                      + added syslog server configuration entry
'                      + added Reset  function to the security options
' 1.02 12.01.2011 ASI  ! fixed bug 069.26: Auto pick-up on timeout does not work 
'                        reliably
' 1.03 17.01.2011 ASI  ! optimised X8 keypress scan and receiving audio procedures
' 1.04 31.01.2011 ASI  + added HDX mode and AI Phone support
'                      ! fixed the names of the pickup modes in the webUI
'                      - removed defs.bcl
'                      ! fixed bug 069.27: BGM stops if the device is not registered
' 1.05 03.02.2011 ASI  ! fixed minor issues rendering the webUI in IE8
'                      ! fixed autohangup issues for outgoing and incoming calls
' 1.06 08.02.2011 ASI  ! fixed non blinking LEDs on PS16
' 1.07 21.02.2011 ASI  ! fixed bug 069.28: The CGI interface hangs after the first CGI 
'                        command
'                      - removed the unconditional switch off of relay1 at call close
' 1.08 30.03.2011 ASI  ! improved SIP call audio handling for lower latency
'                      ! updated to use LINK command for BGM
'                      ! fixed bug 069.30: No busy tone sent if the SIP client is in
'                        a call and a third party dials in
'                      + new feature 069.29: notification audio messaging
'                      - removed X8 check every 15 seconds after boot
'                      + modified command API interface to use own buffer variables
'                        to avoid variable sharing conflicts
'                      ! modified not to stop the application if BGM fails
'                      ! updated profiles help page
' 1.09 19.05.2011 ASI  ! fixed bug 069.31,069.37: Command interfaces do not work when 
'                        serial interface = OFF
'                      ! fixed bugs 069.32,33,34,35,36: Various problems related to
'                        notification messaging
'                      ! fixed bug 069.38: No pickup in P2P mode when "Debug messages" 
'                        setting is "OFF"
'                      ! fixed bug 069.40: No auto-answer set when selecting SIP Paging 
'                        Station profile in IE8 and Google Chrome browsers
'                      ! fixed bug 069.42: HTTP 200 OK is not send after processing of 
'                        some CGI commands
'                      ! fixed bug 069.43: The reverse channel of the serial tunnel, 
'                        opened with X command, does not work
'      20.05.2011 ASI  ! fixed wrong UDP control stream handle name:
'                        UDP_COMMAND_STREAM-->UDP_CONTROL_STREAM
'                      ! fixed typo in the if condition for enabling the relay on 
'                        incoming notification message
'                      ! declare undeclared variables
' 1.10 31.05.2011 ASI  ! fixed bug 069.44: Device homepage does not show indication
'                        when getting notification message
'                      ! fixed bug 069.45: In case of incoming call while the SIP 
'                        client is getting high priority message, the remote party ID 
'                        is displayed on the web page, and not cleared when the 
'                        notification message ends, and the SIP client goes in idle
'                      ! fixed bug 069.46: In SIP paging mode the BGM playback is not 
'                        restored when interrupted by a notification message
'                      ! fixed bug 069.47: Autohang-up on outgoing calls does not work 
'                        in SIP Monitor mode
'                      ! fixed bug 069.48: SIP URI is not displayed in the remote ID 
'                        in the browser for incoming calls
' 1.11 09.06.2011 ASI  ! fixed bug 069.49: There is no audio when  SIP client is run  
'                        as a Paging Station on Exstreamer 110/120/200
'                        fixed bug 069.50: The relay is not switched off after the end
'                        of the notification message
' 1.12 22.06.2011 ASI  ! fixed bug 069.51: BCL crashes when opening, or after closing 
'                        the notification message in SIP Monitoring Point mode
' 1.13 13.09.2011 ASI  + new feature 069.53: Implemented transparent passive TCP 
'                        serial GW
'      21.09.2011 ASi  ! fixed bug 069.52: Line-in not selectable in Monitoring Mode
' 1.14 26.10.2011 ASI  ! new feature 047.65: added DNS resolve if the registration 
'                        fails
'      30.11.2011 ASI  ! Fixed to disable the speaker in AI_Phone talk mode in door
'                        station profile
'      05.12.2011 ASI  ! Fixed to use autohangup=30 seconds as default in Door Station
'                        mode
'                      ! Fixed to "mute" the AI_Phone speaker using audio interface 
'                        balance setting when in encoding (talk) mode to avoid acoustic
'                        feedback
'                      + Added "Periodically Renew DNS" settings to the status page
'                      ! Fixed to check for output peak levels for AI_Phone only when
'                        the call is established
'                      ! Changed the default settings for Input Buffer, Notification 
'                        Message buffer, Trigger Level Timeout.
' 1.15 20.01.2012 ASI  + Prepare code to support for G.722 for the future song module 
'                        that will support it
'                      + new feature 069.56: Timeout on missing audio communication
'                      + new feature 069.57: Add a command to close the active call
'                      ! fixed bug 069.58:  Notification message remote party ID not 
'                        always correctly detected
' 2.00 14.02.2012 ASI  + Added support for IPAM-102 module and G.722 audio codec
' 2.01 05.03.2012 ASI  ! Rebuilding with the latest ABCL FW
'                      ! Fixing duplicate code created by the latest CVS merge
'                      ! Fixed bug 069.59: Notification message with RTP payload 100 
'                        (32 kHz uLaw) crashes the application
'                      ! Fixed bug 069.60: The call state of the SIP client is not 
'                        correctly displayed on the status page when getting 
'                        notification message
'                      + Added IPAM module detection
' 2.02 20.03.2012 ASI  ! Fixed AI_Phone direction switching to work with IPAM 102
' 2.03 23.03.2012 ASI  ! Fixed bug 069.62: The established call is not properly closed
'                        if SIP Client registration happens during the call
' 2.04 10.04.2012 ASI  ! Fixed bug 069.63: Closing established incoming call fails 
'                        with error 481
'                      ! Fixed bug 069.64. Closing established call fails when the 
'                        SIP messages from the remote party has the Contact field
'                        containing optional parameters
' 		           + New feature 069.65: Added support for PS1 buttons
'                      ! Fixed Bug 069.66: SDP description for DTMF detection is not 
'                        complete
' 2.05 18.04.2012 ASI  ! Fixed bug 069.68: SIP client does not accept any incoming 
'                        calls after it receives notification message during call 
'                        setup
'                      ! Fixed bug 069.69: Security options missing in the SIP 
'                        configuration status report
'                      ! Fixed bug 069.70: Call hang-up problem if OPTIONS message is 
'                        received between call dial and call pickup
'                      ! Fixed bug 069.71: The SIP client stops sending audio to the
'                        remote party after it rejects an incomig call during the 
'                        active call session
' 2.06 01.06.2012 ASI  + Added AEC
'                      + New feature 069.72: Support for multiple peers in P2P mode
'                      ! Fixed bug 069.73: BCL(58) warning when getting INVITE message 
'                        in P2P mode from SNOM-360 phone
'                      ! Fixed to ignore direct IP calls in SIP mode
'      05.06.2012 ASI  + Added handling of 486 Busy Here message
'                      ! Fixed to reject incoming calls with 486 when busy in another
'                        call
'                      ! Fixed bug 069.74: The SIP client does not clear the remote
'                        party ID if it rejects incoming call in "not callable" mode
'      06.06.2012 ASI  ! Fixed bug 069.75: The call ID of the remote party is not 
'                        correctly displayed on the PS16 LCD in some cases
'      08.08.2012 ASI  + New feature 069.76: Add the call ID in the FROM field of the 
'                        INVITE message also in P2P mode
' 2.07 06.09.2012 ASI  ! fixed bug 069.85: SIP client cannot initiate call on button 
'                        press when run on Annuncicom 60
' 2.08 12.09.2012 ASI  ! merged the changes to use LINK on FDX
'                      ! fixed not to use LINK in SIP Paging GW profile
'                      ! fixed to send fake RTP packets also when using LINK with
'                        decoder only devices
'      13.09.2012 ASI  + New feature 069.80: Add relay ON on incoming ring
'      14.09.2012 ASI  + new feature 069.77: Beep on call answer
'                      ! Fixed Bug 069.78: Half Duplex not fully implemented
'                      ! Fixed bug 069.84: Helptext for multipeer
'      17.09.2012 ASI  + Added beep on call answer also for incoming calls
' 2.09 25.09.2012 ASI  ! fixed bug 069.86: Sometimes outgoing call cannot be properly 
'                        closed
'                      ! fixed bug 069.87: Audio stays open in listen mode after closing
'                        the call
'                      ! fixed bug 069.88: Incoming P2P call gets rejected when the SIP 
'                        client is set to "autoanswer" mode
' 2.10 02.10.2012 ASI  ! fixed bug 053.69: Large latency (more than 1 second) at the 
'                        first Audio Open with VS1063   
' 2.11 18.10.2012 ASI  ! upgraded to song module 9.23 for fixing random audio volume
'                        increase to 100% 
' 2.12 17.04.2013 ASI  ! fixed bug 069.98: BGM starts not before a call is done
'                      + added HW types array for better HW detection
'      18.04.2013 ASI  ! fixed bug 069.96: SIP password entry is disabled when switching
'                        from P2P to SIP mode from the Advanced Settings
'      19.04.2013 ASI  + new feature 069.92: Add support for IPAM102 standalone module 
'                        (HW type=40)
'      22.04.2013 ASI  + new feature 069.93: Add QoS parameter in WEB UI network settings
'                      ! fixed bug 069.95: Auto hangup timer is not stopped when the 
'                        outgoing call is rejected from the remote party
'                      + new feature 117.03: Allow more than 16 characters for the SIP
'                        password
'                      ! fixed bug 117.01: Re-registration fails if notification message
'                        is active
'   23-26.04.2013 ASI  ! fixed bug 069.97: Stream timeout is not accurate on IPAM 102
'                      + new feature 117.09: Extend the microphone gain configuration 
'                        options in the range of 12-19.5 dB for IPAM 102 modules
'                      ! fixed bug 117.05: Wrong behaviour when dialing using DH command
'                      ! fixed bug 069.99: Add SIP Display Name
'                      + new feature 117.08: Add DA command to ANSWER incoming call
'                      ! fixed bug 117.04: Call is not properly closed when relayed 
'                        by SIP proxy
'                      + new feature 117.10: Add "View As Plain Text" button on the 
'                        status web page
' 2.13 10.10.2013 ASI  ! fixed bug 117.15: Codec bug and consequent BCL crash loop
'                        fixed bug 117.16: Processing received CGI command can cause 
'                        BCL restart
'                        fixed bug 117.17: Auto answering incoming call on timeout  can 
'                        cause BCL crash
'      23.10.2013 ASI  ! fixed bug 117.19: TCP command port not working
' 2.13hp 09.07.15 ASI  ! fixed to use lowercase SIP field names to be compatible with
'                        HP VCX 7210 IP Call processor
'      10.07.2015 ASI  ! fixed to check for bypass uri also in lowercase for HP VCX
'                        compatibility
' 2.14 17.08.2015 ASI  + new feature 117.28: Added support for the opaque parameter during 
'                        the authorization process for compatibility with Panasonic PBX
'      18.08.2015 ASI  ! fixed bug 117.24: Wrong value in the SDP description
'                      ! fixed bug 117.23: BCL warning when the nonce is 64 bytes long
'      19.08.2015 ASI  ! fixed bug 117.25: No outgoing audio in P2P mode audio in 
'                        case of concurrent calls
'      20.08.2015 ASI  + new feature 117.26: API command for relay control
'                      + new feature HY-131: Add API command for change/query the Call ID0
'      21.08.2015 ASI  + new feature HY-132: Add support for Authentication ID
'                      + new feature HY-133: Add global call timeout
'      25.08.2015 ASI  ! fixed: Removed the quotes around MD5 when specifying the
'                        algorithm in the Authorization header
'                      ! fixed bug HY-134: Extend the auto hangup timer to 2 min
'      03.12.2015 ASI  + added support for authentication using the Quality Of Protection
'                        (qop="auth")- 32kB jump to "named" function calls. Moved 
'                        the "unnamed" functions (10XXX, called by direct GOSUB) at the 
'                        end of the program.
'      11.07.2016 ASI  ! cleaned up some syslogs and prepare for official release
'      21.07.2016 ASI  + added the backup SIP server entry also to the status page
' 2.17 17.10.2016 ASI  ! fixed bug ASIP-143:
'                      ! fixed to detect properly SIP headers from the SipXecs server
' 2.15 14.06.2016 ASI  ! Fixed the opaque parameter in the authentication response to be
'                        sent only if requested by the server
' 2.16 28.06.2016 ASI  + new feature HY-136: Add a backup SIP server
'                      c changed: reworked the code by moving all "named" functions a bit
'                        earlier in the program to workaround the BCL interpreter limita-
'                        tion of maximum +/ P2P calls do not work with static IP
'      18.10.2016 ASI  ! fixed bug ASIP-144: The device shall not respond with 200 OK to 
'                        SIP INFO request when received outside SIP dialog
'      20.10.2016 ASI  ! fixed bug ASIP-146: Intermittent audio in HDX with streamtimeout 
'                        enabled
'2.17a 01.11.2016 ASI  + new feature ASIP-5: REFER function
'2.18  11.11.2016 ASI  + added support for Exstreamer 205
'      22.11.2016 ASI  ! fixed the nonce (nc) to be properly printed in 8 decimal digits
'      23.11.2016 ASI  ! increased the auto respond time on the webUI configuration page
'                        to 240 seconds
'2.19  22.02.2018 ASI  ! rebuild to update to SONG module v10.18
'2.19a 27.04.2018 ASI  ! fixed to attempt falling back to PBX1 when PBX2 is used
'                        fixed displaying correctly the resolved IP addresses in syslog
'      21.06.2018 ASI  + added partial support for reINVITEs to help switching the call 
'                        stream when changing the SIP server
'2.20  18.06.2018 ASI  ! fixed ASIP-270: SIP Paging Endpoint stutters when receiving a 
'                        notification message
'      02.07.2018 ASI  ! Merged 2.19a and 2.20 changes into the mainstream version
'                      - removed debugging syslogs
'      23.07.2018 ASI  ! fixed ASIP-272: Wrong information on relay configuration help 
'                        section
'2.21  05.11.2021 ASI  ! fixed ASIP-283: No "180 Ringing" sent after reboot in P2P mode
'                      ! fixed ASIP-281: Notification messaging not working when the SIP
'                        client is not registered
'      08.11.2021 ASI  ! ASIP-284: Added support for Exstreamer 105 and fixed issue SIP
'                        paging endpoint not working with the newest versions of pfSense
'      29.09.2022 ASI  ! Fixed ASIP-293: Full duplex device wrongly detected as receive 
'                        only
'2.22  04.11.2022 ASI  ! Fixed ASIP: Delayed call setup with 3CX server
'      07.11.2022 ASI  ! Releasing SIP V2.22
'2.23  08.11.2022 ASI  + merging changes from ASIO-287: Use Ann60 digital input as 
'                        offhook/onhook button
'                      + merging changes from ASIP-290: Remote P2P port wrongly detected 
'                        when user ID is used in the SIP URI
'      09.11.2022 ASI  ! Limit the Analog Phone behaviour only to Ann 60 in SIP Phone 
'                        profile
'                      ! relocated unnamed functions to the end of the code routine to 
'                        avoid "BCL no source" error and limited opaque$ to 120 bytes
'                        (from 256) to save code space
'      10.11.2022 ASI  ! corrected wrongly reported auto-hangup time in the syslog
'                      ! fixed ASIP-286: Wrong "Call on Level ID" in Status report
'
'-----------------------------------------------------------------------------------------

