Help translating a simple peer config to PJSIP

Hi, I’m new to both PJSIP and Asterisk.

Could you please help me to translate a SIP config to the PJSIP syntax? I maybe need just a skeleton config to start googling by myself.

The original SIP snippet sets up a tg2sip peer. What would be its PJSIP equivalent?

BR

[telegram]
deny=0.0.0.0/0.0.0.0
type=peer
qualify=yes
permit=192.168.1.231/255.255.255.255
host=192.168.1.231
port=5062
fromdomain=192.168.1.231
nat=no
insecure=port,invite
canreinvite=no
dtmfmode=rfc2833
disallow=all
allow=opus
context=from-inbound-telegram

source in Russian

This may help: https://wiki.asterisk.org/wiki/display/AST/Migrating+from+chan_sip+to+res_pjsip

It might also help to first clean it up:

Delete deny and permit; the explicit host has the same effect.

Delete nat=no; unless your system is very strange the default of auto_comedia,auto_force_rport, should produce the same result.

Delete insecure=invite; this has no effect without a secret.

Consider deleting insecure=port; this is almost never required for UDP.

Change canreinvite to directmedia; deprecated many years ago.

Thank you for suggestions and sorry for not answering for so long. I’ve tried to sketch a PJSIP config. My current best guess is:

[telegram-endpoint]
type=endpoint
context=telegram-incoming-test
disallow=all
allow=opus                ; Set opus coded as in example, but I could see the warning from TG2SIP
auth=telegram-auth
aors=telegram-aors

[telegram-auth]
type=auth
auth_type=userpass
username=telegram  ; Is it for inbound or outbound registrations?
password=123       ; There is no place for passwords in TG2SIP settings. I suspect this is not used or wrong..

[telegram-aors]
type=aor
contact=sip:telegram@127.0.0.1:5062

; Do I also need "identify" section?

Now, if I try to dial to this endpoint using same => n,Dial(PJSIP/telegram-endpoint), I see that Asterkis does connect to TG2SIP using UDP, but TG2SIP cancels the call very soon with the following reason:

[23:45:00.765][t:23597][p:23591][pjsip][trace] Processing incoming message: Request msg INVITE/cseq=25833 (rdata0x7f75cc0018f8)                                                                                                              [25/394]
[23:45:00.765][t:23597][p:23591][pjsip][debug] RX 898 bytes Request msg INVITE/cseq=25833 (rdata0x7f75cc0018f8) from UDP 127.0.0.1:5060:                                                                                                             
INVITE sip:telegram@127.0.0.1:5062 SIP/2.0                                                                                                                                                                                                           
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bKPj73382712-ad0d-4b85-8b5e-3dd12082c2c2                                                                                                                                                           
From: "dongle0" <sip:XXXXXXXXXX@127.0.0.1>;tag=2b42e16b-5c98-42f8-bd98-ece203b9170b                                                                                                                                                                
To: <sip:telegram@127.0.0.1>                                                                                                                                                                                                                         
Contact: <sip:asterisk@127.0.0.1:5060>                                                                                                                                                                                                               
Call-ID: 7b720240-4b76-44ed-abe9-5b1687a4904e                                                                                                                                                                                                        
CSeq: 25833 INVITE                                                                                                                                                                                                                                   
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER                                                                                                                                        
Supported: 100rel, timer, replaces, norefersub                                                                                                                                                                                                       
Session-Expires: 1800                                                                                                                                                                                                                                
Min-SE: 90                                                                                                                                                                                                                                           
Max-Forwards: 70                                                                                                                                                                                                                                     
User-Agent: Asterisk PBX 16.1.1                                                                                                                                                                                                                      
Content-Type: application/sdp                                                                                                                                                                                                                        
Content-Length:   237                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                     
v=0                                                                                                                                                                                                                                                  
o=- 1026255045 1026255045 IN IP4 127.0.0.1                                                                                                                                                                                                           
s=Asterisk                                                                                                                                                                                                                                           
c=IN IP4 127.0.0.1                                                                                                                                                                                                                                   
t=0 0                                                                                                                                                                                                                                                
m=audio 10390 RTP/AVP 107 101                                                                                                                                                                                                                        
a=rtpmap:107 opus/48000/2                                                                                                                                                                                                                            
a=rtpmap:101 telephone-event/8000                                                                                                                                                                                                                    
a=fmtp:101 0-16
a=ptime:20
a=maxptime:60
a=sendrecv

--end msg--
[23:45:00.765][t:23597][p:23591][pjsip][debug] Incoming Request msg INVITE/cseq=25833 (rdata0x7f75cc0018f8)
[23:45:00.765][t:23597][p:23591][pjsip][trace] Transaction created for Request msg INVITE/cseq=25833 (rdata0x7f75cc0018f8) 
[23:45:00.765][t:23597][p:23591][pjsip][trace] Incoming Request msg INVITE/cseq=25833 (rdata0x7f75cc0018f8) in state Null
[23:45:00.765][t:23597][p:23591][pjsip][trace] State changed from Null to Trying, event=RX_MSG
[23:45:00.765][t:23597][p:23591][pjsip][trace] Transaction tsx0x7f75cc004c68 state changed to Trying
[23:45:00.765][t:23597][p:23591][pjsip][trace] UAS dialog created
[23:45:00.765][t:23597][p:23591][pjsip][trace] Module mod-invite added as dialog usage, data=0x7f75cc00ac68
[23:45:00.765][t:23597][p:23591][pjsip][trace] Session count inc to 3 by mod-invite
[23:45:00.766][t:23597][p:23591][pjsip][trace] UAS invite session created for dialog dlg0x7f75cc005aa8
[23:45:00.766][t:23597][p:23591][pjsip][trace] Session count inc to 3 by mod-pjsua
[23:45:00.766][t:23597][p:23591][pjsip][trace] Response msg 488/INVITE/cseq=25833 (tdta0x7f75cc010a38) created
[23:45:00.766][t:23597][p:23591][pjsip][error] Request verification failed: Not Acceptable Here [status=170488]
[23:45:00.766][t:23597][p:23591][pjsip][trace] Sending Response msg 488/INVITE/cseq=25833 (tdta0x7f75cc010a38)
[23:45:00.766][t:23597][p:23591][pjsip][trace] Sending Response msg 488/INVITE/cseq=25833 (tdta0x7f75cc010a38) in state Trying
[23:45:00.766][t:23597][p:23591][pjsip][debug] TX 506 bytes Response msg 488/INVITE/cseq=25833 (tdta0x7f75cc010a38) to UDP 127.0.0.1:5060:
SIP/2.0 488 Not Acceptable Here
Via: SIP/2.0/UDP 127.0.0.1:5060;rport=5060;received=127.0.0.1;branch=z9hG4bKPj73382712-ad0d-4b85-8b5e-3dd12082c2c2
Call-ID: 7b720240-4b76-44ed-abe9-5b1687a4904e
From: "dongle0" <sip:XXXXXXXXXXX@127.0.0.1>;tag=2b42e16b-5c98-42f8-bd98-ece203b9170b
To: <sip:telegram@127.0.0.1>;tag=I8mpIA3eTJop2EuonUdNXCiFZj1-mdfy
CSeq: 25833 INVITE
Warning: 399 darktower "No suitable codec for remote offer (PJMEDIA_SDPNEG_NOANSCODEC)"
Accept: application/sdp
Content-Length:  0


--end msg--
[23:45:00.766][t:23597][p:23591][pjsip][trace] State changed from Trying to Completed, event=TX_MSG

For reference: TG2SIP settings.ini:

        [logging]
        core=1                 ; 0-trace  2-info  4-err   6-off
                               ; 1-debug  3-warn  5-crit

        tgvoip=5               ; same as core
        pjsip=0                ; same as core
        sip_messages=true      ; log sip messages if pjsip debug is enabled

        console_min_level=0    ; minimal log level that will be written into console
        file_min_level=0       ; same but into file

        ;tdlib=3                ; TDLib is written to file only and has its own log level values
                                ; not affected by other log settings
                                ; 0-fatal   2-warnings  4-debug
                                ; 1-errors  3-info      5-verbose debug

        [sip]
        public_address=127.0.0.1
        port=5062
        ;port_range=0           ; Specify the port range for socket binding, relative to the start
                                ; port number specified in port.
        id_uri=sip:telegram@127.0.0.1
                                ; The Address of Record or AOR, that is full SIP URL that identifies the account.
                                ; The value can take name address or URL format, and will look something
                                ; like "sip:account@serviceprovider".

        callback_uri=sip:telegram@127.0.0.1:5060 ; FIXME: unhardcode the port
                                ; SIP URI for TG->SIP incoming calls processing

        raw_pcm=false           ; use L16@48k codec if true or OPUS@48k otherwise
                                ; keep true for lower CPU consumption

        ;thread_count=1         ; Specify the number of worker threads to handle incoming RTP
                                ; packets. A value of one is recommended for most applications.

        [telegram]
        api_id=XXXXX
        api_hash=YYYYY
        system_language_code=ru-RU      ; IETF language tag of the user's operating system language

        [other]
        extra_wait_time=10             ; If gateway gets temporary blocked with "Too Many Requests" reason,
                                       ; then block all outgoing telegram requests for X more seconds than was
                                       ; requested by server
        ;peer_flood_time=86400         ; Seconds to wait on PEER_FLOOD

Update: Here is the PJSIP config which works:

[telegram-endpoint]
type=endpoint
context=telegram-incoming-test
disallow=all
allow=opus
aors=telegram-aors

[telegram-aors]
type=aor
contact=sip:telegram@127.0.0.1:5062

[telegram-identify]
type=identify
endpoint=telegram-endpoint
match=127.0.0.1/255.255.255.255

Also some notes:

  1. In order to make original chan_sip config work, one have to disable chan_pjsip loading, because otherwise chan_pjsip may prevent chan_sip from using UDP
  2. pjproject dependency should be compiled with OPUS codec support. Also codec_opus should be installed in Asterisk

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.