Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Dialogic HMP test program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Dialogic HMP test program

    Code:
    '==================================================================================================
    ' Dialogic HMP demo program
    ' Compile with PbWin10
    '==================================================================================================
    #Compiler PBWin 10
    #Compile Exe
    #Debug Error On
    #Debug Display On
    #Dim All
    #Resource Icon AA_PROGRAM  "PHONERD.ICO"
    #Resource Manifest, 1, "XPTheme.xml"
    #Include "WIN32API.INC"
    #Include "HMP_IP.INC"
    
    %LBMSG = 1001
    %TB_TEL1     = 1101 : %CMD_DIAL1 = 1102 : %CMD_STOP = 1103 : %LINE1 = 1104
    
    Global hDlg, Cmd As Dword, DataString As String, DataReady As Word
    Global Ch As Channel, GCLMCB As GCLIB_MAKECALL_BLK
    Global GCLibStart As GC_START_STRUCT, CCLibStart() As CCLIB_START_STRUCT
    Global IPCCLibStart As IPCCLIB_START_DATA, IPVirtBoard() As IP_VIRTBOARD
    Global Lib1, Lib2, Lib3 As AsciiZ * 64, hThread, hEvent, Started As Long
    Global IPAddress As String, SV As NCMSysVersion
    
    '==================================================================================================
    ' InitApplcation()
    '==================================================================================================
    Function InitApplication() As Long
      Local lRet, lTmp As Long
      '------------------------------------------------------------------------------------------------
      NCM_Getsystemstate(lRet)                                                      'See if HMP is
      If lRet = %NCM_SYSTEM_RUNNING Then Started = 1 Else Started = 0               'running
      If Started Then                                                               'If started, set to
        lTmp = %SR_MTASYNC                                                          'async multithread
        lRet = sr_setparm(%SRL_DEVICE, %SR_MODEID, lTmp)                            '
        Init_GC_Start_Struct()                                                      'Fill start struct
        lRet = gc_start (GCLibStart)                                                'Start system
        AddList "gc_startup returned: " & GetError(lRet)                            '
        SR_Enbhdlr (%EV_ANYDEV, %EV_ANYEVT, ByVal CodePtr(HMPCallback))             'Callback handler
        Init_Channels()                                                             'Set values
        lRet = gc_openEx(Ch.lDev, Ch.DevName,%EV_SYNC,0)                            'Open channel 1
        AddList "gc_openex returned: " & geterror (lRet)                            'Get line, voice,
          lRet = gc_GetResourceH(ByVal Ch.lDev, _                                   'and network handle
                                 Ch.vDev, %GC_VOICEDEVICE)                          '
          lRet = gc_GetResourceH(ByVal Ch.lDev, _                                   '
                                 Ch.nDev, %GC_NETWORKDEVICE)                        '
          Ch.hEvent(0) = CreateEvent(ByVal 0,ByVal 1,ByVal 0,ByVal 0)               'Create channel
          Ch.hEvent(1) = CreateEvent(ByVal 0,ByVal 1,ByVal 0,ByVal 0)               'events
          AddList "Creating channelthread "                                         '
          Thread Create ChannelThread(1) To Ch.hThread                              'Create thread
          Thread Close Ch.hThread To lRet
          NCM_GetVersionInfo (SV)                                                   '
          AddList "System: " & SV.szDSSRelease & SV.szDSSVersion & _                '
                    ", build: " & SV.szDSSBuild                                     '
          Sleep 1000                                                                'Set codecs
          Set_Channel_Codecs 1                                                      '
          Function = Started                                                        '
      End If                                                                        '
    End Function                                                                    '
    
    '==================================================================================================
    Function PBMain () As Long
    '==================================================================================================
      Dialog New 0, "Dialogic HMP test program",,,  650,350, %WS_Caption Or %WS_SysMenu, 0 To hDlg
      Control Add Label,   hDlg, -1, "M e s s a g e s :",250, 12, 100, 14
      Control Add ListBox, hDlg, %LBMSG ,,10, 26,515,325, %WS_VScroll Or %WS_TabStop, %WS_Ex_ClientEdge
    
      Control Add Label,   hDlg, -1, "Tel.number #1:",              560, 20, 60, 12
      Control Add TextBox, hDlg, %TB_TEL1, "",                      550, 32, 80, 12
      Control Add Button,  hDlg, %CMD_DIAL1, "Dial #1",             550, 52, 80, 18
      Control Add Button,  hDlg, %CMD_STOP, "End/stop",             550,310, 80, 18
    
      Control Add Line, hDlg, %LINE1,"", 0, 0, 550, 1
      Dialog Set Icon     hDlg, "AA_PROGRAM"
      Control Set Color hDlg, %LBMSG, -1, %rgb_LightYellow
      Dialog Stabilize hDlg
    
      Dialog Show Modal hDlg Call DlgProc
    End Function
    
    '==================================================================================================
    CallBack Function DlgProc() As Long
    '==================================================================================================
      Select Case As Long Cb.Msg                                                    '
        Case %WM_InitDialog                                                         '
          If InitApplication() Then                                                 'Init OK?
            AddList "HMP is running"                                                '
          Else                                                                      '
            AddList "HMP not running - error."                                      '
          End If                                                                    '
        Case %WM_Command                                                            '
          Select Case Cb.Ctl                                                        '
            Case %CMD_DIAL1                                                         'Dialout request
              If CbCtlMsg =  %BN_Clicked Then                                       '
                SetEvent Ch.hEvent (%CALLOUT)                                       '
              End If                                                                '
            Case %CMD_STOP                                                          '
              If CbCtlMsg =  %BN_Clicked Then                                       'Stop program
                If Started Then StopHMP()                                           '
                Started = 0                                                         '
                Sleep 2000                                                          '
                Dialog End hDlg                                                     '
              End If                                                                '
          End Select                                                                '
      End Select                                                                    '
    End Function                                                                    '
    
    '==================================================================================================
    ' HMPCallback()  - Callback function for HMP events
    '==================================================================================================
    Function HMPCallback CDecl (ByVal Ev As Dword) As Long
      Local lRet, lChan As Long, lME As METAEVENT, lpGPB As GC_PARM_BLK Ptr, GCI As GC_INFO
      Local lpGPD As GC_PARM_DATA Ptr,  IPMTIp As IPM_TELEPHONY_INFO Ptr, lstrDig As String
      Local DXCST As DX_CST Ptr
      '------------------------------------------------------------------------------------------------
      lRet = gc_GetMetaEvent(lME)                                                   'Event received. Get
      AddList "gc_getmetaevent result: " & GetError(lRet)                           'channelnr and meta
      lChan = GetChannelFromHandle(lME.LineDev)                                     'event data
      Ch.Crn = lME.Crn                                                              '
      Ch.LastEvent = lME.EvtType                                                    '
      If (lME.EvtType <> %SR_NOEVT) And (lChan <> %SR_NOEVT) Then                   'Type/channel must
        Select Case lME.EvtType                                                     'be non-zero
          '--------------------------------------------------------------------------------------------
          Case %GCEV_OFFERED                                                        'Inbound call
            SetEvent Ch.hEvent(%CALLIN)                                             'Setevent starts ch
            AddList "Setevent CallIn. (GCEV_OFFERED)"                               'thread processing
          '--------------------------------------------------------------------------------------------
          Case %GCEV_ANSWERED                                                       'Call is answered
            Reset Ch.DtmfIn                                                         'Clear dtmf buffer
            Ch.DtmfToneDet = 0                                                      'Reset
            AddList "Channel answered (GCEV_ANSWERED)"                              '
          '--------------------------------------------------------------------------------------------
          Case %GCEV_TELEPHONY_EVENT                                                'Some telephony evt
            lpGPB  = 0                                                              'Pointer must be 0
            If lME.ExtEvtDatap Then                                                 'Extra data?
              lRet = gc_util_copy_parm_blk(lpGPB, lME.@ExtEvtDatap)                 'Copy PARM_BLK from
              AddList "gc_util_copy_parm_blk: " & GetError(lRet)                    'METAEVT parm blk
              lpGPD = gc_util_find_parm(@lpGPB, _                                   'Find parm block
                                        %IPSET_DTMF, _                              'Returns pointer to
                                        %IPPARM_TELEPHONY_EVENT_INFO)               'datablock
              IPMTIp = VarPtr(@lpGPD.Value_buf)                                     'Is a TELECOM_INFO ptr
              lRet = @IPMTIp.TelEvtInfo.eTelephonyEventID                           '
              lstrDig = Choose$(@IPMTIp.TelEvtInfo.eTelephonyEventID + 1, _         'Make digit string
              "0","1","2","3","4","5","6","7","8","9","*","#","A","B","C","D")      '
              Ch.DtmfIn = Ch.DtmfIn + lstrDig                                       'Add digit to string
              Ch.DtmfToneDet = 1                                                    'Signal detect
              gc_util_delete_parm_blk(ByVal lpGPB)                                  'Delete parameterblock
              AddList "Telecom event: " & Format$(lRet)                             '
            End If                                                                  '
          '--------------------------------------------------------------------------------------------
          Case %TDX_PLAY                                                            'Play voicefile end
             lret = sr_getevtdev(0)                                                 '
             AddList "Voice play ended..."                                          '
          '--------------------------------------------------------------------------------------------
          Case %GCEV_DISCONNECTED                                                   'Disconnect
            gc_resultinfo(lME,GCI)                                                  '
            AddList "Channel has disconnected (GCEV_DISCONNECTED)"                  '
          '--------------------------------------------------------------------------------------------
          Case %GCEV_CONNECTED                                                      'Connect made
            AddList "Channel has connected (GCEV_CONNECTED)"                        '
          '--------------------------------------------------------------------------------------------
        End Select                                                                  '
      End If
      Function = 0                                                                  'Return '0' to HMP
    End Function
    
    '==================================================================================================
    ' ChannelThread()  - Handles in or outgoing calls.
    '==================================================================================================
    Thread Function ChannelThread(ByVal pPar As Long) As Long
      Local lRet, lLoops, lCnt, lTmp, lRetval As Long, lszStr As AsciiZ * 64
      Local lST As SYSTEMTIME, lStr As String, lszTel As AsciiZ * 64
      '------------------------------------------------------------------------------------------------
      AddList "Channelthread started: "                                             '
      While IPAddress = ""                                                          'Wait for IPaddress
        Sleep 10                                                                    '
      Wend                                                                          '
      Ch.Callstate = %CH_INIT                                                       '
      '------------------------------------------------------------------------------------------------
      While %True                                                                   'Loop forever
        If Ch.Callstate <> %CH_IDLE Then                                            '
          Ch.LastEvent = 0                                                          '
          Ch.Callstate = %CH_IDLE                                                   'Mark chan. as idle
          If Ch.Crn Then                                                            'Pending call,clear
            gc_dropCall(Ch.Crn, %GC_NORMAL_CLEARING, %EV_ASYNC)                     '
            Sleep 100                                                               '
            gc_ReleaseCallEx(Ch.Crn, %EV_ASYNC)                                     '
            AddList "Release line..."                                                '
            Ch.Crn = 0                                                              '
          End If                                                                    '
          Sleep 200                                                                 '
          dx_resetCh(Ch.vDev, %EV_ASYNC)                                            '
          lret = gc_resetlinedev(Ch.ldev, %EV_ASYNC)                                'Reset listview / line
          lTmp = WaitForEvent(%GCEV_RESETLINEDEV)                                 '
          AddList "gc_resetlinedev result: " & GetError(lRet)                       '
          lret = gc_waitcall(Ch.lDev, ByVal 0, ByVal 0, ByVal 0, %EV_ASYNC)         '
          AddList "gc_waitcall result: " & GetError(lRet)                           '
          Sleep 200                                                                 '
        End If                                                                      '
        lRet = WaitForMultipleObjects(2, Ch.hEvent(0), 0, 50)                       'Wait for events
        Select Case lRet                                                            '
          '============================================================================================
          ' Time-out
          '============================================================================================
          Case %WAIT_TIMEOUT        'Time-out                                       'Timeout, exit if
            If Started = 0 Then Exit Loop                                           'not running
          '============================================================================================
          ' Incoming call
          '============================================================================================
          Case %WAIT_OBJECT_0                                                       'Incoming call
            Ch.Callstate = %CH_CALLIN                                               'Mark chan. in use
            If Ch.LastEvent = %GCEV_OFFERED Then                                    'Incoming call?
              If Started Then                                                       'System active:take
                lRet = Gc_getANI(Ch.Crn, ByRef lszStr)                              'Get ANI (callerID)
                AddList "Caller ID (gc_getANI): " & lszStr                          '
                lRet = gc_AnswerCall(Ch.Crn, 0, %EV_ASYNC)                          'Take line
                AddList "Call answered. (gc_answercall)"                            '
               '---------------------------------------------------------------------------------------
                Sleep 1000
                AddList "Play voicefile... "                                        '
                  lRet = PlayVox(1, "voicedemo.vox")                                '
                  Sleep 2000                                                        '
                  '------------------------------------------------------------------------------------
                Ch.CallState = %CH_INIT                                             '
                Sleep 1000                                                          '
              End If                                                                '
            End If                                                                  '
            AddList "Verbreken..."                                                  '
            Sleep 500                                                               '
            ResetEvent(Ch.hEvent(%CALLIN))                                          '
    
          '============================================================================================
          ' Outgoing call
          '============================================================================================
          Case %WAIT_OBJECT_0 + 1                                                   'Outbound callreq.
            Ch.Callstate = %CH_CALLOUT                                              'Mark channel busy
            Control Get Text hDlg, %TB_TEL1 To lszStr                               '
            lszStr = Trim$(lszStr)                                                  'If not number, add
            GCLMCB.Destination.Address  =  lszStr                                   'Set dest. nr
            AddList "Dialing: " & GCLMCB.Destination.Address                        '
            lRet = gc_MakeCall(Ch.ldev, _                                           'call
                                   Ch.Crn, _                                        '
                                   ByVal 0, _                                       '
                                   Ch.Makecallblk, _                                '
                                   0, _                                             '
                                   %EV_ASYNC)                                       '
            AddList "Result gc_makecall: " & GetError(lRet)                         'Log result
            Sleep 500                                                               '
            '------------------------------------------------------------------------------------------
            AddList "Dial complete, wait connect..."                                '
            Sleep 600                                                               '
            lCnt = 0                                                                '
            While Ch.LastEvent <> %GCEV_CONNECTED                                   '
              Sleep 100
              Incr lCnt                                                             '
              If (lCnt>300) Then Exit Loop                                          '
            Wend                                                                    '
            If Ch.LastEvent = %GCEV_CONNECTED Then                                  '
              AddList "Connected..."                                                '
              Sleep 500                                                             '
              lCnt = 0                                                              '
              Ch.Callstate = %CH_CONNECTED                                          '
             '---------------------------------------------------------------------------------------
              Sleep 1000
              AddList "Play voicefile... "                                        '
                lRet = PlayVox(1, "voicedemo.vox")                                '
                Sleep 2000                                                        '
                '------------------------------------------------------------------------------------
              Ch.CallState = %CH_INIT                                             '
            End If                                                                  '
            AddList "Disconnected... "                                              '
            Sleep 500                                                               '
            ResetEvent(Ch.hEvent(%CALLOUT))                                         '
        End Select                                                                  '
      Wend                                                                          '
      AddList "Channelthread stopped... "                                           '
    End Function                                                                    '
    
    '==================================================================================================
    ' GetChannelFromHandle - Gets channelnumber from handle (Ch(x).ldev)
    '==================================================================================================
    Function GetChannelFromHandle (ByVal pHandle As Long) As Long
      Local lCnt As Long
      '------------------------------------------------------------------------------------------------
      lCnt = 0
      If pHandle > 0 Then
        For lCnt = 1 To 2
          If (pHandle = Ch.lDev) Then
            Function = lCnt
            Exit For
          End If
        Next
      End If
    End Function
    
    '==================================================================================================
    ' Init_Channels()
    '==================================================================================================
    Sub Init_Channels()
      Ch.CodecRx.Capability                    = %GCCAP_AUDIO_g711Alaw64k      'codecs
      Ch.CodecRx.Type                          = %GCCAPTYPE_AUDIO              '
      Ch.CodecRx.Direction                     = %IP_CAP_DIR_LCLRECEIVE        '
      Ch.CodecRx.Extra.Audio.Frames_Per_Pkt    = 20                            '
      Ch.CodecRx.Extra.Audio.VAD               = %GCPV_DISABLE                 '
      Ch.CodecTx.Capability                    = %GCCAP_AUDIO_g711Alaw64k      '
      Ch.CodecTx.Type                          = %GCCAPTYPE_AUDIO              '
      Ch.CodecTx.Direction                     = %IP_CAP_DIR_LCLTRANSMIT       '
      Ch.CodecTx.Extra.Audio.Frames_Per_Pkt    = 20                            '
      Ch.CodecTx.Extra.Audio.VAD               = %GCPV_DISABLE                 '
    
      Ch.LineName            = "iptB1T1"                                       'Line name
      Ch.DevName             = ":N_iptB1T1:P_SIP:M_ipmB1C1:V_dxxxB1C1"         'Devicename
      Ch.VoiceName           = "ipmB1C1"                                       'Voicename
      Ch.MakecallBlk.GCLib = VarPtr(GCLMCB)
      Ch.makecallblk.cclib   = 0
    
      GCLMCB.Destination.Address      = IPAddress
      GCLMCB.Destination.Address_type = %GCADDRTYPE_TRANSPARENT
      GCLMCB.Origination.Address      = "123@" & Trim$(IPAddress)
      GCLMCB.Origination.Address_type = %GCADDRTYPE_TRANSPARENT
      GCLMCB.ext_datap = 0
    End Sub
    
    '==================================================================================================
    ' SetChannelCodecs - Set codec values and DTMF capability
    '==================================================================================================
    Sub set_channel_codecs(ByVal Index As Long)
      Local scope, lRet As Long, ipcap As IP_CAPABILITY, lTmp As Dword
      Local szStr As AsciiZ * %MAX_STRING_SIZE, GCParmBlkp As GC_PARM_BLK Ptr, dwPtr As Dword Ptr
    
      GCParmBlkp = 0
      Reset ipcap
      '------------------------------------------------------------------------------------------------
      ' Tx settings
      '------------------------------------------------------------------------------------------------
      ipcap.capability = %GCCAP_AUDIO_g711Alaw64k
      ipcap.type = %GCCAPTYPE_AUDIO
      ipcap.direction = %IP_CAP_DIR_LCLTRANSMIT
      ipcap.extra.audio.frames_per_pkt = Ch.codectx.Extra.Audio.Frames_Per_Pkt
      ipcap.extra.audio.VAD = %NO
      lRet = gc_util_insert_parm_ref(GCParmblkp, %GCSET_CHAN_CAPABILITY, %IPPARM_LOCAL_CAPABILITY, _
                                     SizeOf(IP_CAPABILITY), ipcap)
      '-----------------------------------------------------------------------------------------------
      ' Rx settings
      '-----------------------------------------------------------------------------------------------
      ipcap.capability = %GCCAP_AUDIO_g711Alaw64k
      ipcap.type = %GCCAPTYPE_AUDIO
      ipcap.direction  = %IP_CAP_DIR_LCLRECEIVE
      ipcap.extra.audio.frames_per_pkt = Ch.codecrx.Extra.Audio.Frames_Per_Pkt
      ipcap.extra.audio.VAD = %NO
      lRet = gc_util_insert_parm_ref(GCParmblkp, _
                                     %GCSET_CHAN_CAPABILITY, _
                                     %IPPARM_LOCAL_CAPABILITY, _
                                     SizeOf(IP_CAPABILITY), _
                                     ipcap)
      '------------------------------------------------------------------------------------------------
      ' DTMF settings
      '------------------------------------------------------------------------------------------------
      lRet = gc_util_insert_parm_val(GCparmblkp, _
                                     %IPSET_DTMF, _
                                     %IPPARM_SUPPORT_DTMF_BITMASK, _
                                     1, _
                                     %IP_DTMF_TYPE_RFC_2833)
    
      lRet = gc_util_insert_parm_val(GCParmblkp, _
                                     %IPSET_DTMF, _
                                     %IPPARM_TELEPHONY_EVENT_DTMF, _
                                     4, _
                                     %IP_ENABLE)
    
      '------------------------------------------------------------------------------------------------
      ' Write SetUserInfo()
      '------------------------------------------------------------------------------------------------
      Scope = %GC_ALLCALLS  'SINGLECALL
          lRet = gc_SetUserInfo(%GCTGT_GCLIB_CHAN, _
                                Ch.ldev, _
                                @GCparmblkp, _
                                scope)
      gc_util_delete_parm_blk(GCparmblkp)
    End Sub
    
    '==================================================================================================
    ' AddList() Adds entry to listbox
    '==================================================================================================
    Sub AddList(pTxt As String)
      Local lRet As Long
      '------------------------------------------------------------------------------------------------
      ListBox Add hDlg, %LBMSG, pTxt
      ListBox Get Count hDlg, %LBMSG To lRet
      ListBox Select hDlg, %LBMSG, lRet
    End Sub
    
    '==================================================================================================
    ' Init_GC_Start_Struct()
    '==================================================================================================
    Sub Init_GC_Start_Struct()
      Local lCnt, lRet As Long, lStr As String, szStr As AsciiZ * 64
      Local lAddr As IN_ADDR Ptr, lszPtr As AsciiZ Ptr, lWSAData As WSADATA
      ReDim CCLibStart(1) As Global CCLIB_START_STRUCT
      ReDim IPVirtBoard(1) As Global IP_VIRTBOARD
      '------------------------------------------------------------------------------------------------
      GCLibStart.num_ccLibs          = 2                                            'GC_START_STRUCT
      GCLibStart.ccLibs_list         = VarPtr(CCLibStart(0))                        '
      '------------------------------------------------------------------------------------------------
      Lib1                        = "GC_IPM_LIB"                                    'CCLIB_START_STRUCT
      CCLibStart(0).ccLib_name    = VarPtr(Lib1)                                    'Libname #1
      CCLibStart(0).ccLib_data    = 0                                               'No extra data
      Lib2                        = "GC_H3R_LIB"
      CCLibStart(1).ccLib_name    = VarPtr(Lib2)                                    'Libname #2
      CCLibStart(1).ccLib_data    = VarPtr(IPCCLibStart)                            'Pointer to data
      '------------------------------------------------------------------------------------------------
      lRet = WSAStartup (&h0202, lWSAData)                                          '
      If lRet <> 0 Then AddList "Winsock init error on init_boards"                 '
      lAddr = GetHostAddr()                                                         '
      If lAddr Then                                                                 '
        lszPtr = inet_ntoa(@lAddr.s_addr)                                           '
        IPAddress = @lszPtr                                                         '
      End If                                                                        '
      WSACleanup()                                                                  '
      AddList "Local IP address set to: " & @lszPtr                                 '
      For lCnt = 0 To 1                                                             '
        Init_IP_Virtboard(IPVirtBoard(lCnt))                                        '
        IPVirtBoard(lCnt).sip_max_calls                 = 1                         '
        IPVirtBoard(lCnt).h323_max_calls                = 1                         '
        IPVirtBoard(lCnt).total_max_calls               = 1                         '
        '----------------------------------------------------------------------------------------------
        IPVirtBoard(lCnt).LocalIP.IPv4 = Inet_Addr(@lszPtr)                         '
      Next lCnt                                                                     '
      '------------------------------------------------------------------------------------------------
      IPCCLibStart.version                  = &h0201                                'IPCCLIB_START_DATA
      IPCCLibStart.delimiter                = Asc(",")                              '
      IPCCLibStart.num_boards               = 1                                     '
      IPCCLibStart.board_list               = VarPtr(IPVirtBoard(0))                '
      IPCCLibStart.max_parm_data_size       = %IP_CFG_DEFAULT                       '
      IPCCLibStart.media_operational_mode   = %MEDIA_OPERATIONAL_MODE_1PCC          '
    End Sub                                                                         '
    
    '==================================================================================================
    ' GetError() - Gets last gc_xx call error as text
    '==================================================================================================
    Function GetError(ByVal pRet As Long) As String
      Local lRet As Long, lGCI As GC_INFO, lStr As String
      '------------------------------------------------------------------------------------------------
      If pRet = 0 Then                                                              '
        lStr = "Success"                                                            '
      Else                                                                          '
        lStr = " - error: "                                                         '
        gc_ErrorInfo(lGCI)                                                          '
        lStr = lStr & lGCI.@gcmsg                                                   '
      End If                                                                        '
      If lGCI.ccmsg Then                                                            '
        lStr = lStr & " ( gc: 0x" & Hex$(lGCI.GCvalue) & ", " & _                   '
        lGCI.@ccmsg & " cc: 0x" & Hex$(lGCI.cCValue) &" )" '& lGCI.@cclibname       '
      Else                                                                          '
        lStr = lStr & " ( gc: 0x" & Hex$(lGCI.GCvalue) & _                          '
                  ", -- cc: 0x" & Hex$(lGCI.cCValue) &" )"                          '
      End If                                                                        '
      Function = lStr                                                               '
    End Function                                                                    '
    
    '==================================================================================================
    ' WaitForEvent()
    '==================================================================================================
    Function WaitForEvent(ByVal pEvt As Long) As Long
      Local lCnt, lRet As Long
      '------------------------------------------------------------------------------------------------
      lCnt = 0                                                                      '
      Function = 0                                                                  '
      While lCnt < 100                                                              '
        Sleep 10                                                                    '
        If Ch.Lastevent = pEvt Then Function = 1 : Exit Loop                        '
        Incr lCnt                                                                   '
      Wend                                                                          '
    End Function                                                                    '
    
    '==================================================================================================
    ' PlayVox()
    '==================================================================================================
    Function PlayVox(ByVal pCh As Long, pVFName As String) As Long
      Local lDVtpt As DV_TPT, lRet As Long
      '------------------------------------------------------------------------------------------------
      lDVtpt.tp_type    = %IO_EOT                                                   '
      lDVtpt.tp_termno  = %DX_MAXDTMF                                               '
      lDVtpt.tp_length  = 0                                                         '
      lDVtpt.tp_flags   = %TF_MAXDTMF                                               '
      lRet = dx_playvox(Ch.vDev, ByCopy pVFName,lDVtpt, ByVal 0, %EV_SYNC)          '
      Function = lRet                                                               '
      Sleep 1000  'LC 2000                                                          '
    End Function                                                                    '
    
    '==================================================================================================
    ' StopHMP()   - Stop HMP / Close all channels (iptxx, ipmxx, dxx)
    '==================================================================================================
    Function StopHMP() As Long
      Local lCnt, lRet As Long
      '------------------------------------------------------------------------------------------------
      SR_Dishdlr (%EV_ANYDEV, %EV_ANYEVT, ByVal CodePtr(HMPCallback))             '
      AddList "Release callback function..."                                      '
      lret =  gc_close(Ch.lDev)                                                   '
      AddList "Channel 1 closed (gc_Close)"                                       '
      lRet = gc_stop()                                                            '
      AddList "System stopped (gc_stop)"                                          '
    End Function                                                                  '
    Include file:

    Code:
    '======================================================================================================================
    ' HMP_IP.INC - Include file for Powerbasic - Dialogic HMP boards
    '======================================================================================================================
    %SR_MTASYNC                     = 1
    %SRL_DEVICE                     = 0
    %NCM_SYSTEM_RUNNING             = 4
    %EV_ASYNC                       = &h08000???
    %EV_SYNC                        = &h000000
    %SR_MODEID                      = &h0002
    %GC_VOICEDEVICE                 = 2
    %GC_NETWORKDEVICE               = 1
    %EV_ANYDEV                      = -1
    %EV_ANYEVT                      = &hFFFFFFFF???
    %SUCCESS                        = 0
    %SR_NOEVT                       = -1
    %DT_GC                          = &h0800
    %GCEV_ANSWERED                  = %DT_GC + &h002
    %GCEV_OFFERED                   = %DT_GC + &h024
    %GCEV_TELEPHONY_EVENT           = %DT_GC + &h09E
    %GC_IP_TECH_SET_MIN             = &h03000
    %BASE_SETID                     = %GC_IP_TECH_SET_MIN
    %IPSET_DTMF                     = %BASE_SETID + 14
    %IPPARM_TELEPHONY_EVENT_INFO    = &h007
    %TDX_PLAY                       = &h081
    %GCEV_DISCONNECTED              = %DT_GC + &h026
    %GCEV_CONNECTED                 = %DT_GC + &h022
    %GC_NORMAL_CLEARING             = &h010
    %GCEV_RESETLINEDEV              = %DT_GC + &h006
    %CODEC_AUDIO_G711ALAW64K        = &h065
    %GCCAP_AUDIO_G711ALAW64K        = %CODEC_AUDIO_G711ALAW64K
    %GCCAPTYPE_AUDIO                = 2
    %IP_CAP_DIR_LCLTRANSMIT         = 1
    %IP_CAP_DIR_LCLRECEIVE          = 2
    %GCPV_DISABLE                   = 0
    %GCADDRTYPE_TRANSPARENT         = 1
    %GCSET_CHAN_CAPABILITY          = &h01004
    %IPPARM_LOCAL_CAPABILITY        = &h002
    %IPPARM_SUPPORT_DTMF_BITMASK    = 1
    %IP_DTMF_TYPE_RFC_2833          = 2
    %IPPARM_TELEPHONY_EVENT_DTMF    = &h006
    %IP_ENABLE                      = 1
    %GC_ALLCALLS                    = 1
    %GCTGT_GCLIB_CHAN               = 12
    %IP_CFG_DEFAULT                 = -1
    %MEDIA_OPERATIONAL_MODE_1PCC    = 0
    %IO_EOT                         = &h0004
    %DX_MAXDTMF                     = 1
    %TF_LEVEL                       = &h0001
    %TF_USE                         = &h0008
    %TF_MAXDTMF                     = %TF_LEVEL Or %TF_USE
    %IP_SUP_SERV_DISABLED           = 0
    %MIME_MEM_VERSION               = &h0100
    %IP_TT_GATEWAY                  = 60
    %ENUM_DISABLED                  = 0
    %ENUM_ENABLED                   = 1
    %ENUM_UDP                       = 0
    %ENUM_PERSISTENCE_TRANSACT_USER = 1
    %DEFAULT_MAXUDPMSGLEN           = 0
    %ENUM_REQUEST_RETRY_ALL         = 4
    %IPVER4                         = 0
    %IPVER6                         = 1
    %IP_RETRIEVE_HOST_IPADDR        = 0
    
    
    
    %GC_ADDRSIZE            = 128               'ANI/DNIS digits storing
    %MAX_ADDRESS_LEN        = %GC_ADDRSIZE      'Maximum address length
    %MAX_CALLS              = 2                 'Calls per channel
    %MAX_CHANNELS           = 2                 'Max channels
    %MAX_DEVNAME            = 64                'Maximum length of device name
    %MAX_CODECNAME          = 20                'Maximum length of codec name
    %MAX_VADSTR             = 10                'Maximum length of VAD string, e.g. "ON", "OFF", "N/A"
    %MAX_CODECS             = 10                'Maximum number of codecs per VoIP channel
    %MAX_STRING_SIZE        = 1500
    $DEV_CLASS_VOICE        = "Voice"
    
    %MAX_RESOURCENAME       = 32                '
    
    %H323               = 5
    %SIP                = 6
    %DIR_IN             = 1
    %DIR_OUT            = 2
    %YES                =    1
    %NO                 =    0
    
    %CALLIN                 = 0
    %CALLOUT                = 1
    %CALLAST                = 1
    
    %CH_IDLE                = 0
    %CH_CALLIN              = 1
    %CH_CALLOUT             = 2
    %CH_CONNECTED           = 3
    %CH_INIT                = 4
    
    %VIRTBOARD_VERSION_UNREGISTERED_HDRS_SUPPORT    = &h0117
    %IP_VIRTBOARD_VERSION                           = %VIRTBOARD_VERSION_UNREGISTERED_HDRS_SUPPORT
    
    '--------------------------------------------------------------------------------------------------
    ' Transfer parameter block
    '--------------------------------------------------------------------------------------------------
     Type DX_XPB
       wFileFormat      As Word  '  file format
       wDataFormat      As Word     'data encoding
       nSamplesPerSec   As Dword    'sampling rate
       wBitsPerSample   As Word     'bits per sample
    End Type
    
    '======================================================================================================================
    ' DV_TPT - Termination Parameter Table Structure.
    '----------------------------------------------------------------------------------------------------------------------
    Type DV_TPT
      Tp_Type       As Word         'Flags Describing this Entry
      Tp_Termno     As Word         'Termination Parameter Number
      Tp_Length     As Word         'Length of Terminator
      Tp_Flags      As Word         'Termination Parameter Attributes Flag
      Tp_Data       As Word         'Optional Additional Data
      Rfu           As Word         'Reserved
      Tp_Nextp      As DV_TPT Ptr   'Ptr to next DV_TPT if IO_LINK set
    End Type
    '======================================================================================================================
    '
    '----------------------------------------------------------------------------------------------------------------------
    Type GCLIB_WAITCALL_BLK
      flags     As Long
      rfu       As Long
    End Type
    
    '======================================================================================================================
    '
    '----------------------------------------------------------------------------------------------------------------------
    Type GC_WAITCALL_BLK
      gclib     As GCLIB_WAITCALL_BLK Ptr       'GlobalCall specific portion
      cclib     As Dword                        'cclib specific portion
    End Type
    
    '==================================================================================================
    ' DX_CST - Call Status Transition Structure
    ' NOTE: All user-accessible structures must be defined so as to be unaffected by structure packing.
    '--------------------------------------------------------------------------------------------------
    Type DX_CST
      cst_event As Word    'CST Event
      cst_data  As Word    'Data Associated with the Event
    End Type
    
    Type IPM_TELEPHONY_EVENT_INFO
      unVersion         As Dword            'Structure version For library use Only
      eTelephonyEventID As Dword            'The named Event usually DTMF named Event
      sVolume           As Integer          'The power level For the DTMF Event tone
      usDuration        As Word             'Duration For the DTMF digit In ms
    End Type
    
    Type IPM_TELEPHONY_TONE_INFO
      unVersion         As Dword        'Structure version For library use Only
      eTelephonyEventID As Dword        'The named Event usually DTMF named Event
      usModulationFreq  As Word         'The modulation frequency In Hz
      ucModFreqDivBy3   As Byte         'If Set To 1 the modulation frequency Is To be divided by 3
      sVolume           As Integer      'Power level Of tone
      usDuration        As Word         'Duration Of tone In ms
      usFreq1           As Word         'The frequency Of tone 1 To be added
      usFreq2           As Word         'The frequency Of tone 2 To be added
      usFreq3           As Word         'The frequency Of tone 3 To be added
      usFreq4           As Word         'The frequency Of tone 4 To be added
    End Type
    
    Union TELEPHONYINFO
      TelEvtInfo  As IPM_TELEPHONY_EVENT_INFO    'RFC2833 named Event info eg. DTMF digit
      TelToneInfo As IPM_TELEPHONY_TONE_INFO    'RFC2833 non-standard tone signal Information
    End Union
    
    Type IPM_TELEPHONY_INFO
      unVersion         As Dword        'Structure version For library use Only
      eTelInfoType      As Dword        'RFC2833 Info Type - named Event Or tone
      TELEPHONYINFO
    End Type
    
    Type IPM_TELEPHONY_SIGNAL_INFO
      unVersion             As Dword        'Structure version For library use Only
      sPayloadType          As Integer
      sPTime                As Integer
      nClockRate            As Long
      usDurationMultiplier  As Dword
      unOptions             As Dword
      eTelInfoType          As Dword        'RFC2833/4733 Info Type - named Event Or tone
      TELEPHONYINFO
    End Type
    
    '======================================================================================================================
    ' For GC_PARM_DATA/GC_PARM_BLK, value_buf and parm_data_buf parameters resp, are used as placeholders to access data in
    ' the contagious memory block, which is what GC_PARM_BLK was designed for. Applications should be aware that the one
    ' byte allocated should be used for the data. Applications, however, are strongly recommended to use the gc_util
    ' functions for manipulation of the GC_PARM_BLK to avoid having to deal with these issues.
    '======================================================================================================================
    ' GC_PARM_DATA data structure used in GC_PARM_BLK
    '----------------------------------------------------------------------------------------------------------------------
    Type GC_PARM_DATA
      set_ID        As Word         'Set ID (two bytes long)
      parm_ID       As Word         'Parameter ID (two bytes long)
      value_size    As Byte         'Size of value_buf in bytes
      value_buf     As Byte  'Asciiz * 1   'Address to the parm value buffer
    End Type
    
    '======================================================================================================================
    ' The following data structure defines the error or result information
    '----------------------------------------------------------------------------------------------------------------------
    Type GC_INFO
      gcValue           As Long
      gcMsg             As AsciiZ Ptr
      ccLibId           As Long
      ccLibName         As AsciiZ Ptr
      ccValue           As Long
      ccMsg             As AsciiZ Ptr
      additionalInfo    As AsciiZ Ptr
    End Type
    
    '======================================================================================================================
    ' SIP_STACK_CFG :
    ' Used in IP_VIRTBOARD to specify virtual board settings. Use INIT_SIP_STACK_CFG function to init structure to default
    '   version:                        version of structure
    '   retransmissionT1:               T1 determines several timers as defined in RFC3261. A Client General transaction
    '                                   retransmits requests at interval that starts at T1 and doubles until it reaches T2.
    '   retransmissionT2:               Determines maximum retransmission interval as defined in RFC 3261. If a provisional
    '                                   response is received, retransmissions continue but at an interval of T2.The para-
    '                                   meter value cannot be less than 4000.
    '   retransmissionT4:               T4 represents amount of time the network takes to clear messages between client and
    '                                   server transactions as defined in RFC 3261.
    '   generalLingerTimer:             After server sends a final response, server cannot be sure that the client received
    '                                   response message. Server should be able to retransmit response upon receiving re-
    '                                   transmissions of request for generalLingerTimer milliseconds.
    '   inviteLingerTimer:              After sending ACK for an INVITE final response, a client cannot be sure that the
    '                                   server has received ACK message. Client should be able to retransmit ACK upon re-
    '                                   ceiving retransmissions of the final response for inviteLingerTimer milliseconds.
    '   provisionalTimer:               ProvisionalTimer is set when receiving provisional response on Invite transaction.
    '                                   The transaction will stop retransmissions of the Invite request and will wait for
    '                                   a final response until provisionalTimer expires. If you set provisionalTimer to
    '                                   zero (0), no timer is set. Invite transaction waits indefinitely on final response.
    '   cancelGeneralNoResponseTimer:   When sending a CANCEL request on a General transaction, the User Agent waits
    '                                   cancelGeneralNoResponseTimer milliseconds before timeout termination if there is no
    '                                   response for the cancelled transaction.
    '   cancelInviteNoResponseTimer:    When sending a CANCEL request on an Invite request, the User Agent waits
    '                                   cancelInviteNoResponseTimer milliseconds before timeout termination if there is no
    '                                   response for the cancelled transaction.
    '   generalRequestTimeoutTimer:     After sending a General request, the User Agent waits for a final response
    '                                   generalRequestTimeoutTimer milliseconds before timeout termination (in this time
    '                                   the User Agent retransmits the request every T1, 2*T1, ... , T2, ...milliseconds)
    '   forked1xxTimerTimeout:          Sets timeout value for forked-1xx-timer which is set by a forked call-leg after
    '                                   receiving the first 1xx response. This timer is released when the call-leg receives
    '                                   a 2xx response. If timer expires before 2xx reception, call-leg is terminated. This
    '                                   timeout value defines how long call-leg waits for 2xx response before termination.
    '   removeOldAuth:                  This Enum indicates whether to remove old received authentication challenges from
    '                                   the same realm. If a new challenge is received from the server (401/407) and this
    '                                   field is enabled, the Stack will check whether an old challenge from the same realm
    '                                   exists. If so, the old challenge will be removed.
    '----------------------------------------------------------------------------------------------------------------------
    Type SIP_STACK_CFG
      version                       As Dword            'version set by INIT_SIP_STACK_CFG
      retransmissionT1              As Long
      retransmissionT2              As Long
      retransmissionT4              As Long
      generalLingerTimer            As Long
      inviteLingerTimer             As Long
      provisionalTimer              As Long
      cancelGeneralNoResponseTimer  As Long
      cancelInviteNoResponseTimer   As Long
      generalRequestTimeoutTimer    As Long
      forked1xxTimerTimeout         As Long             'added in version 0x101
      removeOldAuth                 As Long   'ENUMSIP_ENABLED  'added in version 0x102
    End Type
    
    %SIP_STACK_CFG_VERSION      = &h00300102    '((0x102 & 0xFFFF) | (sizeof(SIP_STACK_CFG) << 16))
    
    Sub INIT_SIP_STACK_CFG(pSipSCfg As SIP_STACK_CFG )
      pSipSCfg.version                      = %SIP_STACK_CFG_VERSION
      pSipSCfg.retransmissionT1             = 1000
      pSipSCfg.retransmissionT2             = 8000
      pSipSCfg.retransmissionT4             = 10000
      pSipSCfg.generalLingerTimer           = 32000
      pSipSCfg.inviteLingerTimer            = 32000
      pSipSCfg.provisionalTimer             = 180000
      pSipSCfg.cancelGeneralNoResponseTimer = 32000
      pSipSCfg.cancelInviteNoResponseTimer  = 32000
      pSipSCfg.generalRequestTimeoutTimer   = 32000
      pSipSCfg.forked1xxTimerTimeout        = 32000             'added ver 0x101, to disable forking set Timer to 0
      pSipSCfg.removeOldAuth                = %ENUM_Disabled    'added ver 0x102 for removal of (Proxy-)Authorizationheader
    End Sub
    
    
    '==================================================================================================
    ' SIP TLS certificate verification callback to application
    '--------------------------------------------------------------------------------------------------
    'typedef int (CBCALLCONV *VerifyCertificateCallback)(const char *const, int, int );
    'typedef int (CBCALLCONV *VerifyCertificateCallback)(const char *const, int, int );
    '
    '/* SIP TLS post-connection hostname callback to application */
    'typedef int (CBCALLCONV *PostConnectCallback) (const GC_PARM_BLK *const);
    '
    '==================================================================================================
    ' SIP_TLS_ENGINE :      Used in IP_VIRTBOARD to specify virtual board settings.
    '   version:                        version of structure
    '   sip_tls_port:                   TLS port number GC will listen, default port number is 5061
    '   E_sip_tls_method:               indicates the version of SSL to use: only TLSv1 is supported
    '   local_rsa_private_key_filename: File with TLS RSA key certificate, (base64 encoded)/X509 format
    '   local_rsa_private_key_password: Passw.string to read TLS RSA privatekey of local certificate
    '   local_rsa_cert_filename:        PEM file with TLS RSA certificate for local ident, must be PEM
    '   local_dss_private_key_filename: file with TLS DSS private key certificate, must be PEM
    '   local_dss_private_key_password: pswstring to read TLS DSS private key of local certificate,
    '   local_dss_cert_filename:        PEM file with TLS DSS certificate local identity, must be PEM
    '   ca_cert_number:                 nr of trusted certificates.TLS can trust zero, one or more root
    '   ca_cert_filename:               array of trusted certificates filenames, must be PEM
    '   chain_cert_number:              nr of chained certificates.
    '   chain_cert_filename:            array of chained certificate filenames, must be base64/X509
    '   crl_number:                     Nr of CRL files.An engine may lookup certificate revocationlist
    '   crl_filename:                   array of CRL filenames, must be PEM format in plain text.
    '   local_cipher_suite:             Cypherslist specified by formatted string defined by OPENSSL.
    '   dh_param_512_filename:          filename containing DH parameter with 512 bit key length.
    '   dh_param_1024_filename:         Filename containing DH parameter with 1024 bit key length.
    '   session_id:                     If session id set, session caching is enabled on server side.
    '   E_client_cert_required:         If set to ENUM_Enabled,TLS server requires client's certificate
    '   E_block_udp_port:               If set to ENUM_Enabled,UDP port is disabled to prevent attack.
    '   E_block_tcp_port:               If set to ENUM_Enabled,TCP port is disabled to prevent attack.
    '   verify_cert_CB:                 If not NULL, expects ptr to C function for application
    '   post_connect_CB:                If not NULL, expects ptr to C function for appl post-connect
    '--------------------------------------------------------------------------------------------------
    Type SIP_TLS_ENGINE
      Version                           As Dword
      Sip_Tls_Port                      As Word
      E_Sip_Tls_Method                  As Long  'ENUMSIP_TLS_METHOD
      local_rsa_private_key_filename    As AsciiZ Ptr
      local_rsa_private_key_password    As AsciiZ Ptr
      local_rsa_cert_filename           As AsciiZ Ptr
      local_dss_private_key_filename    As AsciiZ Ptr
      local_dss_private_key_password    As AsciiZ Ptr
      local_dss_cert_filename           As AsciiZ Ptr
      ca_cert_number                    As Dword
      ca_cert_filename                  As Dword Ptr
      chain_cert_number                 As Dword
      chain_cert_filename               As Dword Ptr
      crl_number                        As Dword
      crl_filename                      As Dword Ptr
      local_cipher_suite                As AsciiZ Ptr
      dh_param_512_filename             As AsciiZ Ptr
      dh_param_1024_filename            As AsciiZ Ptr
      session_id                        As AsciiZ Ptr
      E_client_cert_required            As Long  'ENUMSIP_ENABLED
      E_block_udp_port                  As Long  'ENUMSIP_ENABLED
      E_block_tcp_port                  As Long  'ENUMSIP_ENABLED
      verify_cert_CB                    As Long 'VERYFYCERTIFICATECALLBACK
      post_connect_CB                   As Long 'POSTCONNECTCALLBACK
    End Type
    
    '==================================================================================================
    ' MIME_MEM :            Used in IP_VIRTBOARD to spec MIME mempool. Use INIT_MIME_MEM to init
    '   Version :           0x104 or up
    '   Size :              size of MIME buffer
    '   Number:             number of MIME buffer
    '--------------------------------------------------------------------------------------------------
    Type MIME_MEM
      Version           As Word         'library use only. do not change value
      Size              As Dword        'size of MIME buffer
      Number            As Dword        'number of MIME buffer
    End Type
    
    %MIME_MEM_VERSION   = &h0100
    
    '==================================================================================================
    ' Use INIT_MIME_MEM function to initialize the structure to default values.
    '--------------------------------------------------------------------------------------------------
    Sub INIT_MIME_MEM(pMimeMem As MIME_MEM)
      pMimeMem.version = %MIME_MEM_VERSION
      pMimeMem.size    = %IP_CFG_DEFAULT
      pMimeMem.number  = %IP_CFG_DEFAULT
    End Sub
    '
    '==================================================================================================
    ' IP_ADDR :
    '   ip_ver :            IP version as IPVER4 or IPVER6
    '   u_ipaddr :          IP addr 32bit(IPv4)/128bit(IPv6)/IP_RETRIEVE_HOST_IPADDR to get hostIP addr
    '--------------------------------------------------------------------------------------------------
    Union U_IPADDR
      IpV4      As Dword
      IpV6(3)   As Dword
    End Union
    
    Type IP_ADDR
      ip_ver            As Byte
      U_IPADDR
    End Type
    
    '======================================================================================================================
    ' New version number and structure member must be added to 5.1 line as well to preserve compatibility with 5.2 line
    '----------------------------------------------------------------------------------------------------------------------
    Type IP_VIRTBOARD
      Version                               As Word                         'library use only. do not change value
      Total_max_calls                       As Dword
      h323_max_calls                        As Dword
      sip_max_calls                         As Dword
      localIP                               As IP_ADDR
      h323_signaling_port                   As Word
      sip_signaling_port                    As Word
      reserved                              As Dword                        'library use only. do not change value
      size                                  As Word                         'library use only. do not change value
      sip_msginfo_mask                      As Dword                        'added in version 0x0101
      sup_serv_mask                         As Dword                        'added in version 0x0102
      h323_msginfo_mask                     As Dword                        'added in version 0x0103
      sip_mime_mem                          As MIME_MEM                     'added in version 0x0104
      terminal_type                         As Word                         'added in version 0x0104
      outbound_proxy_IP                     As IP_ADDR                      'added in version 0x0105
      outbound_proxy_port                   As Word                         'added in version 0x0105
      outbound_proxy_hostname               As AsciiZ Ptr                   'added in version 0x0105
      E_SIP_tcpenabled                      As Long                         'EnumSIP_Enabled
      E_SIP_OutboundProxyTransport          As Long                         'EnumSIP_TransportProtocol
      E_SIP_Persistence                     As Long                         'EnumSIP_Persistence
      SIP_maxUDPmsgLen                      As Word
      E_SIP_DefaultTransport                As Long                         'EnumSIP_TransportProtocol
      E_SIP_RequestRetry                    As Long                         'EnumSIP_RequestRetry
      E_SIP_OPTIONS_Access                  As Long                         'EnumSIP_Enabled
      SIP_registrar_registrations           As Long
      sip_tls_engine                        As SIP_TLS_ENGINE Ptr
      E_SIP_PrackEnabled                    As Long                         'EnumSIP_Enabled
      E_SIP_SessionTimer_Enabled            As Long                         'EnumSIP_Enabled
      SIP_SessionTimer_SessionExpires       As Dword
      SIP_SessionTimer_MinSE                As Dword
      sip_stack_cfg                         As SIP_STACK_CFG Ptr
      E_SIP_UPDATE_Access                   As Long                         'EnumSIP_Enabled
      E_SIP_dynamic_outbound_proxy_enabled  As Long                         'EnumSIP_Enabled
      E_SIP_IPv6                            As Long                         'EnumSIP_Enabled              'Enable IPv6 Support
      localIPv6                             As IP_ADDR                      'Local IP Address for IPv6
      localIPv6_iface_name                  As AsciiZ Ptr                   'Name of local IP address interface (IPv6 Only)
      sip_max_subscription                  As Dword
      E_SIP_MESSAGE_Access                  As Long                         'EnumSIP_Enabled              'FR6192 SIP MESSAGE method support
      E_SIP_OOD_NOTIFY_Access               As Long                         'EnumSIP_Enabled              'FR6280 SIP out of dialog NOTIFY support
      E_SIP_Add_rport_to_Via_Header         As Long                         'EnumSIP_Enabled              'FR6234 - rport support
      E_SIP_PreConditions_Enabled           As Long                         'EnumSIP_Enabled              'XMS-1773
      E_SIP_Overlapped_INFO_Enabled         As Long                         'EnumSIP_Enabled              'XMS-3174
      E_SIP_GetUnregisteredHdrs_Enabled     As Long                         'EnumSIP_Enabled              'XMS-3858
    End Type
    
    Sub Init_IP_VirtBoard(pIpVb As IP_VIRTBOARD)
      pIpVb.Version                                 = %IP_VIRTBOARD_VERSION
      pIpVb.Size                                    = SizeOf(IP_VIRTBOARD)
      pIpVb.sip_msginfo_mask                        = 0
      pIpVb.sup_serv_mask                           = %IP_SUP_SERV_DISABLED
      pIpVb.h323_msginfo_mask                       = 0
      pIpVb.sip_mime_mem.version                    = %MIME_MEM_VERSION
      pIpVb.sip_mime_mem.size                       = %IP_CFG_DEFAULT
      pIpVb.sip_mime_mem.number                     = %IP_CFG_DEFAULT
      pIpVb.terminal_type                           = %IP_TT_GATEWAY
      pIpVb.outbound_proxy_hostname                 = 0
      pIpVb.E_SIP_tcpenabled                        = %ENUM_DISABLED
      pIpVb.E_SIP_OutboundProxyTransport            = %ENUM_UDP
      pIpVb.E_SIP_Persistence                       = %ENUM_PERSISTENCE_TRANSACT_USER
      pIpVb.SIP_maxUDPmsgLen                        = %DEFAULT_MAXUDPMSGLEN
      pIpVb.E_SIP_DefaultTransport                  = %ENUM_UDP
      pIpVb.E_SIP_RequestRetry                      = %ENUM_REQUEST_RETRY_ALL
      pIpVb.E_SIP_OPTIONS_Access                    = %ENUM_DISABLED
      pIpVb.sip_tls_engine                          = 0
      pIpVb.E_SIP_PrackEnabled                      = %ENUM_DISABLED
      pIpVb.E_SIP_SessionTimer_Enabled              = %ENUM_DISABLED
      pIpVb.SIP_SessionTimer_SessionExpires         = 1800
      pIpVb.SIP_SessionTimer_MinSE                  = 90
      pIpVb.sip_stack_cfg                           = 0
      pIpVb.E_SIP_UPDATE_Access                     = %ENUM_DISABLED
      pIpVb.E_SIP_dynamic_outbound_proxy_enabled    = %ENUM_DISABLED
      pIpVb.E_SIP_IPv6                              = %ENUM_DISABLED
      pIpVb.localIPv6_iface_name                    = 0
      pIpVb.sip_max_subscription                    = 0
      pIpVb.E_SIP_MESSAGE_Access                    = %ENUM_DISABLED
      pIpVb.E_SIP_OOD_NOTIFY_Access                 = %ENUM_ENABLED
      pIpVb.E_SIP_Add_rport_to_Via_Header           = %ENUM_DISABLED
      pIpVb.E_SIP_PreConditions_Enabled             = %ENUM_DISABLED
      pIpVb.E_SIP_Overlapped_INFO_Enabled           = %ENUM_DISABLED
      pIpVb.E_SIP_GetUnregisteredHdrs_Enabled       = %ENUM_DISABLED
      '------------------------------------------------------------------------------------------------
      pIpVb.LocalIP.IP_Ver                          = %IPVER4
      pIpVb.LocalIPV6.IP_Ver                        = %IPVER6
      pIpVb.LocalIP.IpV4                            = %IP_RETRIEVE_HOST_IPADDR
      pIpVb.LocalIPv6.IpV4                          = %IP_RETRIEVE_HOST_IPADDR
    End Sub
    
    '======================================================================================================================
    ' IPCCLIB_START_DATA :
    ' Used in CCLIB_START_STRUCT to configure GC_H3R_LIB library
    '   version :               version of structure - set to 0x100 for this release
    '                           - set to 0x101 for Request-URI feature
    '                           - set to 0x200 for get/set access of GC parm data greater than 255 bytes.
    '   delimiter :             ANSI character used to change default address string delimiter of ","
    '   num_boards :            number of virtual boards specifed in board_info array element.
    '   board_info:             array of virtual board board elements of type IP_VIRTBOARD
    '   media_operational_mode: 1PCC Embedded media or 3PCC Split Media library operation
    '----------------------------------------------------------------------------------------------------------------------
    Type IPCCLIB_START_DATA
      Version                   As Word
      delimiter                 As Byte
      num_boards                As Byte
      board_list                As IP_VIRTBOARD Ptr
      max_parm_data_size        As Dword
      media_operational_mode    As Long
    End Type
    
    '======================================================================================================================
    ' CCLib specific start structure, used by GC_START_STRUCT
    ' Libraries should find its own structure by looking at the name field in the array pointed to by GC_START_STRUCT
    '----------------------------------------------------------------------------------------------------------------------
    Type CCLIB_START_STRUCT
      CCLib_Name    As AsciiZ Ptr
      CCLib_Data    As Dword Ptr
    End Type
    
    '======================================================================================================================
    ' GC start structure, points to an array of CCLIB_START_STRUCT
    '----------------------------------------------------------------------------------------------------------------------
    Type GC_START_STRUCT
      Num_CCLibs    As Long
      CCLibs_List   As CCLIB_START_STRUCT Ptr
    End Type
    
    '======================================================================================================================
    ' Generic GC_PARM_BLK data structure
    '----------------------------------------------------------------------------------------------------------------------
    Type GC_PARM_BLK
      parm_data_size    As Word         'Size of parm_data_buf in bytes
    '  parm_data_buf     As Asciiz Ptr   'Address to the parm data buffer, a chain of GC_PARM_DATA
      parm_data_buf     As Byte 'GC_PARM_DATA
    End Type
    
    Type GC_PARM_DATA_EXT
      version       As Dword        'Current version of this structure
      pInternal     As Dword        'For internal use only (was void*)
      set_ID        As Dword        'Set ID (four bytes long)
      parm_ID       As Dword        'Parameter ID (four bytes long)
      data_size     As Dword        'Size of data pointed to by pData (four bytes long)
      pData         As Dword        'Data pointer(four bytes long) (was void*)
    End Type
    
    Type METAEVENT
      MagicNo       As Long
      Flags         As Dword
      EvtDataP      As Dword
      EvtLen        As Long
      EvtDev        As Long
      EvtType       As Long
      LineDev       As Long
      Crn           As Long
      ExtEvtDataP   As GC_PARM_BLK Ptr  'Dword
      UsrAttr       As Dword
      CCLibID       As Long
      Rfu1          As Long
    End Type
    '======================================================================================================================
    ' Structure used for providing address information about origination and destination parties in makecall block.    <OK>
    '----------------------------------------------------------------------------------------------------------------------
    Type GCLIB_ADDRESS_BLK
      Address           As AsciiZ * %MAX_ADDRESS_LEN    'address data element
      Address_type      As Byte                         'address type parameter
      Address_plan      As Byte                         'address plan parameter
      Sub_address       As AsciiZ * %MAX_ADDRESS_LEN    'address data element
      Sub_address_type  As Byte                         'sub-address data element
      Sub_address_plan  As Byte                         'sub-address plan data element
    End Type
    
    '======================================================================================================================
    ' Structure provides information about medium/timeslot used for call. See Technology User's Guide for supportinfo. <OK>
    '----------------------------------------------------------------------------------------------------------------------
    Type GCLIB_CHAN_BLK
      medium_id         As Byte         'select timeslot/port
      medium_sel        As Byte         'Preferred or exclusive
    End Type
    
    '======================================================================================================================
    ' Structure provides information about the call e.g. category of call. See Technology UserGuide for supportinfo.  <OK>
    '----------------------------------------------------------------------------------------------------------------------
    Type GCLIB_CALL_BLK
      category          As Byte         'Category of the call
      address_info      As Byte         'Indicates if address is complete or overlap mode
    End Type
    
    '======================================================================================================================
    ' This is the Generic GC makecall block to be used for all technologies.                                           <OK>
    '----------------------------------------------------------------------------------------------------------------------
    Type GCLIB_MAKECALL_BLK
      destination   As GCLIB_ADDRESS_BLK            'Called party information
      origination   As GCLIB_ADDRESS_BLK            'Calling party information
      chan_info     As GCLIB_CHAN_BLK               'Channel information
      call_info     As GCLIB_CALL_BLK               'Call information
      ext_datap     As GC_PARM_BLK Ptr              'Extended parameters
    End Type
    
    '======================================================================================================================
    '    This structure is used for passing the GC generic makecall block or a technology specific makecall block.     <OK>
    '----------------------------------------------------------------------------------------------------------------------
    Type GC_MAKECALL_BLK
      gclib     As GCLIB_MAKECALL_BLK Ptr   'Generic makecall block
      cclib     As Dword                    'cclib specific portion
    End Type
    
    '==================================================================================================
    ' IP_AUDIO_CAPABILITY : Struct used to allow min. set of exchangeinfo along with audio codec ident.
    '   frames_per_pkt :    If bundling 1+ audioframes into a packet, value should represent max.nr of
    '                       frames/packet which will be sent. If set zero, indicates exact nr of frames
    '                       is unknown or it indicates that this data is not applicable.
    '   VAD :               For audio algo's supporting voice activity detection (VAD), value will be
    '                       GCPV_ENABLE or GCPV_DISABLE. Param ignored for non-VAD algorithms.
    '--------------------------------------------------------------------------------------------------
    Type IP_AUDIO_CAPABILITY
      Frames_per_pkt    As Dword
      VAD               As Word
    End Type
    
    '==================================================================================================
    ' IP_VIDEO_CAPABILITY : Struct used to allow min. set of exchangeinfo along with video codec ident.
    '   mean_pict_intrvl :  Field used to indicate max. framerate videostream. The frame rate maps
    '                       to MPI through the following formula:  * fps = 29.97/MPI.
    '--------------------------------------------------------------------------------------------------
    Type IP_VIDEO_CAPABILITY
      Mean_pict_intrvl  As Dword
    End Type
    
    '==================================================================================================
    ' IP_DATA_CAPABILITY :  Struct used to allow min. set of exchangeinfo along with data capability.
    '   max_bit_rate :      Field used to indicate max. bitrate for the data channel.
    '                       The bitrate should be specified in 100's of bit/sec.
    '--------------------------------------------------------------------------------------------------
    Type IP_DATA_CAPABILITY
      Max_bit_rate  As Dword
    End Type
    
    '==================================================================================================
    ' IP_CAPABILITY_UNION : This union allows defining different capability categories own parameters.
    '   audio :             Structure representing audio capability
    '   video :             Structure representing video capability
    '   data  :             Structure representing data capability
    '--------------------------------------------------------------------------------------------------
    Union IP_CAPABILITY_UNION
      Audio     As IP_AUDIO_CAPABILITY
      Video     As IP_VIDEO_CAPABILITY
      Data      As IP_DATA_CAPABILITY
    End Union
    
    '==================================================================================================
    ' IP_CAPABILITY :       Struct intended for simplified capability representation.
    '   capability :        Media capability for this structure.
    '   type :              Capability category specified in struct. Indicates which members used.
    '   direction :         This is the direction for this capability.
    '   payload_type :      Field only applies to dynamic payloads. Ignored for static payload type.
    '   extra :             Contents of IP_CAPABILITY_UNION will be indicated by the type field.
    '   rfu   :             Reserved for future use. Must be set to zero when not used.
    '--------------------------------------------------------------------------------------------------
    Type IP_CAPABILITY
      Capability    As Long
      Type          As Long
      Direction     As Long
      Payload_Type  As Long
      Extra         As IP_CAPABILITY_UNION
      Rfu           As String * 16
    End Type
    
    '==================================================================================================
    ' Data structure which stores call information for each line device
    '--------------------------------------------------------------------------------------------------
    Type CALLTYPE
      Crn               As Long     'GlobalCall call handle
      Call_state        As Long     'State of first layer state machine
      Dropcall_active   As Long     'Flag for simultaneous disconnect check
    End Type
    
    '==================================================================================================
    ' TX and RX codecs for each line device although only used for H.323 or SIP
    '--------------------------------------------------------------------------------------------------
    Type CODECS
      Txcodec           As AsciiZ * %MAX_CODECNAME  'TX codec type (H.323 or SIP only)
      Txrate            As Long                     'TX codec rate (H.323 or SIP only)
      TxVAD             As AsciiZ * %MAX_VADSTR     'TX VAD enabled/disabled (H.323 or SIP only)
      Rxcodec           As AsciiZ * %MAX_CODECNAME  'RX codec type (H.323 or SIP only)
      Rxrate            As Long                     'RX codec rate (H.323 or SIP only)
      RxVAD             As AsciiZ * %MAX_VADSTR     'RX VAD enabled/disabled (H.323 or SIP only)
    End Type
    
    Type ToneFlags
      GenToneDet    As Bit * 1 In Byte
      DialToneDet   As Bit * 1
      BusyToneDet   As Bit * 1
      DtmfToneDet   As Bit * 1
      FlashComplete As Bit * 1
      GenToneEnded  As Bit * 1
      VoiceEnded    As Bit * 1
      Resbits       As Bit * 1
    End Type
    
    '==================================================================================================
    ' Data structure which stores all information for each line device
    '--------------------------------------------------------------------------------------------------
    Type Channel
      hEvent(%CALLAST)  As Long
      hThread           As Long
      DevName           As AsciiZ * %MAX_DEVNAME
      LineName          As AsciiZ * %MAX_RESOURCENAME
      VoiceName         As AsciiZ * %MAX_RESOURCENAME
      MediaName         As AsciiZ * %MAX_RESOURCENAME
      lDev              As Long
      vDev              As Long
      nDev              As Long
      mDev              As Long
      CodecRx           As IP_CAPABILITY
      CodecTx           As IP_CAPABILITY
      TxLineSlot        As Dword
      TxVoiceSlot       As Dword
      Makecallblk       As GC_MAKECALL_BLK
      Opened            As Bit * 1 In Byte
      Res3              As Bit * 7
      DtmfIn            As AsciiZ * 24
      LastEvent         As Dword
      CallState         As Dword
      TONEFLAGS
      Crn               As Long
      WorkStation       As Long
      hRec              As Dword
      ChOut             As Dword
    End Type
    
    Type NCMSysVersion
      szOSName      As AsciiZ * %Max_Path
      szOSVersion   As AsciiZ * %Max_Path
      szOSBuild     As AsciiZ * %Max_Path
      szOSType      As AsciiZ * %Max_Path
      szOSSvcPack   As AsciiZ * %Max_Path
      szDSSVersion  As AsciiZ * %Max_Path
      szDSSRelease  As AsciiZ * %Max_Path
      szDSSBuild    As AsciiZ * %Max_Path
      szDSSSvcPack  As AsciiZ * %Max_Path
    End Type
    
    Declare Function NCM_GetSystemState Lib "NCMapi.dll" CDecl Alias "NCM_GetSystemState" (SystemState As Long) As Long
    Declare Function sr_setparm Lib "LibSRLmt.dll" CDecl Alias "sr_setparm" (ByVal ddd As Long, ByVal ParmID As Long, Valuep As Dword) As Long
    Declare Function gc_Start Lib "LibGC.dll" CDecl Alias "gc_Start" (startp As GC_START_STRUCT) As Long
    Declare Function sr_enbhdlr Lib "LibSRLmt.dll" CDecl Alias "sr_enbhdlr" (ByVal ddd As Long, ByVal event_type As Long, pHandler As Dword) As Long
    Declare Function sr_dishdlr Lib "LibSRLmt.dll" CDecl Alias "sr_dishdlr" (ByVal ddd As Long, ByVal event_type As Long, pHandler As Dword) As Long
    Declare Function gc_OpenEx Lib "LibGC.dll" CDecl Alias "gc_OpenEx" (linedevp As Long, devicename As AsciiZ, ByVal pMode As Long, ByVal usrattr As Long) As Long  'void *usrattr
    Declare Function gc_GetResourceH Lib "LibGC.dll" CDecl Alias "gc_GetResourceH" (ByVal linedev As Long, resourcehp As Long, ByVal resourcetype As Long) As Long
    Declare Function gc_GetMetaEvent Lib "LibGC.dll" CDecl Alias "gc_GetMetaEvent" (metaeventp As METAEVENT) As Long
    Declare Function gc_util_copy_parm_blk Lib "LibGC.dll" CDecl Alias "gc_util_copy_parm_blk" (parm_blkpp As Any, parm_blk As Any) As Long
    Declare Function gc_util_find_parm Lib "LibGC.dll" CDecl Alias "gc_util_find_parm" (parm_blk As Any, ByVal setID As Word, ByVal parmID As Word) As Dword
    Declare Sub      gc_util_delete_parm_blk Lib "LibGC.dll" CDecl Alias "gc_util_delete_parm_blk" (parm_blk As Any)
    Declare Function sr_getevtdev Lib "LibSRLmt.dll" CDecl Alias "sr_getevtdev" (ByVal Evt_handle As Dword) As Long
    Declare Function gc_ResultInfo Lib "LibGC.dll" CDecl Alias "gc_ResultInfo" (a_Metaevent As METAEVENT, a_Info As GC_INFO) As Long
    Declare Function gc_DropCall Lib "LibGC.dll" CDecl Alias "gc_DropCall" (ByVal crn As Long, ByVal cause As Long, ByVal pMode As Dword) As Long
    Declare Function gc_ReleaseCallEx Lib "LibGC.dll" CDecl Alias "gc_ReleaseCallEx" (ByVal crn As Long, ByVal pMode As Dword) As Long
    Declare Function dx_resetch Lib "LibDxxMT.dll" CDecl Alias "dx_resetch"( ByVal ChDev As Long, ByVal pMode As Word ) As Long
    Declare Function gc_ResetLineDev Lib "LibGC.dll" CDecl Alias "gc_ResetLineDev" (ByVal linedev As Long, ByVal pMode As Dword) As Long
    Declare Function gc_WaitCall Lib "LibGC.dll" CDecl Alias "gc_WaitCall" (ByVal linedev As Long, crnp As Long, waitcallp As GC_WAITCALL_BLK, ByVal ptimeout As Long, ByVal pMode As Dword) As Long
    Declare Function gc_GetANI Lib "LibGC.dll" CDecl Alias "gc_GetANI" (ByVal crn As Long, anibuf As AsciiZ) As Long
    Declare Function gc_AnswerCall Lib "LibGC.dll" CDecl Alias "gc_AnswerCall" (ByVal crn As Long, ByVal rings As Long, ByVal pMode As Dword) As Long
    Declare Function gc_MakeCall Lib "LibGC.dll" CDecl Alias "gc_MakeCall" (ByVal linedev As Long, crnp As Long, numberstr As AsciiZ, makecallp As GC_MAKECALL_BLK, ByVal ptimeout As Long, ByVal pMode As Dword) As Long
    Declare Function gc_util_insert_parm_ref Lib "LibGC.dll" CDecl Alias "gc_util_insert_parm_ref" (parm_blkp As Dword, ByVal setID As Word, ByVal parmID As Word, ByVal data_size As Byte, datap As Any) As Long
    Declare Function gc_util_insert_parm_val Lib "LibGC.dll" CDecl Alias "gc_util_insert_parm_val" (parm_blkp As Dword, ByVal setID As Word, ByVal parmID As Word, ByVal data_size As Byte, ByVal pdData As Long ) As Long
    Declare Function gc_SetUserInfo Lib "LibGC.dll" CDecl Alias "gc_SetUserInfo" (ByVal target_type As Long, ByVal target_id As Long, infoparmblkp As Any, ByVal duration As Long) As Long
    Declare Function gc_ErrorInfo Lib "LibGC.dll" CDecl Alias "gc_ErrorInfo" (a_Info As GC_INFO) As Long
    Declare Function dx_playvox Lib "LibDxxMT.dll" CDecl Alias "dx_playvox"( ByVal ChDev As Long, fNamep As AsciiZ, tptp As DV_TPT, xpbp As DX_XPB, ByVal pMode As Word) As Long
    Declare Function gc_Close Lib "LibGC.dll" CDecl Alias "gc_Close" (ByVal linedev As Long) As Long
    Declare Function gc_Stop Lib "LibGC.dll" CDecl Alias "gc_Stop" () As Long
    Declare Function NCM_GetVersionInfo Lib "NCMapi.dll" CDecl Alias "NCM_GetVersionInfo"(psysver As NCMSysVersion) As Long
    Attached Files
    Regards,
    Peter

    "Simplicity is a prerequisite for reliability"

    #2
    To save other ignorant members from having to look it up like I did



    A telephony system based on host media processing (HMP) is one that uses a general-purpose computer to process a telephony call’s media stream rather than using digital signal processors (DSPs) to perform the task

    Also note, it's not Dialog HMP Test as I read it at first!
    It is not about a Windows Dialog (although it does use one)
    =========================
    https://camcopng.com
    =========================

    Comment


      #3
      Thanks Stuart for your explanation. I added some more info in the Programming section: https://forum.powerbasic.com/forum/u...p-test-program
      Regards,
      Peter

      "Simplicity is a prerequisite for reliability"

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎