Moving from sip.conf to pjsip.conf

Hi all,

I currently have a raspberry with buster and asterisk 16.x that I need to migrate to bookworm and asterisk 20.x. I’m trying to migrate the sip.conf/users.conf config to pjsip.conf, unfortunately without success at the moment.

My asterisk server (192.168.1.25) is connected to an analog telephone adapter (ATA 192.168.1.55 → 1000 in the config) and an external provider (my.sip.domain).

;===============================================
; pjsip.conf
;===============================================
[transport-udp]
type = transport
protocol = udp
bind = 192.168.1.25:5060
external_media_address = my.own.network
external_signaling_address = my.own.network
external_signaling_port = 5060
local_net = 192.168.1.0/24

[reg_my.sip.domain]
type = registration
retry_interval = 20
transport = transport-udp
outbound_auth = auth_reg_my.sip.domain
client_uri = sip:02433322XX@my.sip.domain
server_uri = sip:my.sip.domain

[auth_reg_my.sip.domain]
type = auth
auth_type = userpass
password = some_password
username = 02433322XX

[provider1-endpoint]
type = endpoint
context = LocalSets
allow = !all,g722,alaw,ulaw,gsm
rtp_symmetric = yes
force_rport = yes
rewrite_contact = yes
direct_media = no
tone_zone = ch
language = fr
subscribe_context = default
auth = provider1-auth
outbound_auth = auth_reg_my.sip.domain
aors = provider1-aor

[provider1-aor]
type = aor
contact = sip:02433322XX@my.sip.domain

[provider1-identify]
type = identify
endpoint = provider1-endpoint
match = my.sip.domain

;===============================================
; endpoint template for ATA
;===============================================

endpoint-int
type = endpoint
transport = transport-udp
context = LocalSets
allow = !all,g722,alaw,ulaw,gsm
direct_media = no
device_state_busy_at = 1
dtmf_mode = rfc4733

auth-userpwd
type = auth
auth_type = userpass

aor-single-reg
type = aor

;===============================================
1000-endpoint
auth = 1000-auth
aors = 1000-aor

1000-auth
username = 1000
password = some_password

1000-aor
contact = sip:192.168.1.25:5060

[1000-identify]
type = identify
endpoint = 1000-endpoint
match = 192.168.1.0/24

unfortunately my ATA is not able to register to the provider and I get this message in the log full :

[Jan 29 08:59:53] DEBUG[1875] res_pjsip_outbound_registration.c: Received REGISTER response 200(OK)
[Jan 29 08:59:53] DEBUG[1875] res_pjsip_outbound_registration.c: Processing REGISTER response 200 from server 'sip:my.sip.domain' for client 'sip:02433322XX@my.sip.domain'
[Jan 29 08:59:53] DEBUG[1875] res_pjsip_outbound_registration.c: Outbound registration to 'sip:my.sip.domain' with client 'sip:02433322XX@my.sip.domain' successful
[Jan 29 08:59:53] DEBUG[1875] res_pjsip_outbound_registration.c: Scheduling outbound registration to server 'sip:my.sip.domain' from client 'sip:02433322XX@my.sip.domain' in 3590 seconds
...
[Jan 29 09:03:22] DEBUG[1874] res_pjsip/pjsip_distributor.c: Could not find matching transaction for Request msg REGISTER/cseq=658 (rdata0x7f7c003cb8)
[Jan 29 09:03:22] DEBUG[1874] res_pjsip/pjsip_distributor.c: Calculated serializer pjsip/distributor-00000036 to use for Request msg REGISTER/cseq=658 (rdata0x7f7c003cb8)
[Jan 29 09:03:22] DEBUG[1872] threadpool.c: Increasing threadpool pjsip/pool's size by 5
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_endpoint_identifier_ip.c: Source address 192.168.1.55:5060 does not match identify 'provider1-identify'
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_endpoint_identifier_ip.c: Source address 192.168.1.55:5060 matches identify '1000-identify'
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_endpoint_identifier_ip.c: Identify '1000-identify' SIP message matched to endpoint 1000-endpoint
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_authenticator_digest.c: Using default realm 'asterisk' on incoming auth '1000-auth'.
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_authenticator_digest.c: Realm: asterisk Username: 1000 Result: NOAUTH
[Jan 29 09:03:22] DEBUG[1874] res_pjsip/pjsip_distributor.c: Could not find matching transaction for Request msg REGISTER/cseq=659 (rdata0x7f7c003cb8)
[Jan 29 09:03:22] DEBUG[1874] res_pjsip/pjsip_distributor.c: Calculated serializer pjsip/distributor-00000036 to use for Request msg REGISTER/cseq=659 (rdata0x7f7c003cb8)
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_endpoint_identifier_ip.c: Source address 192.168.1.55:5060 does not match identify 'provider1-identify'
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_endpoint_identifier_ip.c: Source address 192.168.1.55:5060 matches identify '1000-identify'
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_endpoint_identifier_ip.c: Identify '1000-identify' SIP message matched to endpoint 1000-endpoint
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_authenticator_digest.c: Using default realm 'asterisk' on incoming auth '1000-auth'.
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_authenticator_digest.c: Calculated nonce 1706515402/63de3cead2da3cc437a3b223090237db. Actual nonce is 1706515402/63de3cead2da3cc437a3b223090237db
[Jan 29 09:03:22] DEBUG[1906] res_pjsip_authenticator_digest.c: Realm: asterisk Username: 1000 Result: SUCCESS
[Jan 29 09:03:22] WARNING[1906] res_pjsip_registrar.c: AOR '' not found for endpoint '1000-endpoint' (192.168.1.55:5060)

I used the pjsip.conf.sample file to create my own config. I’m not very experienced and after several unsuccessful migration attempts, I’d be very glad to have some help.

I went through this recently, I posted what for me was a working pjsip.conf in this thread and a couple of the much more knowledgeable people pointed out mistakes, but the thread might help.

Thanks a lot for your help. There is a lot of differences between our two configs. I have to check all the point. I let you know. I’ll let you know as soon as I can.

I hope it helps. I use Twilio and I’ve no idea how close or how far apart their requirements are from your provider. I struggled with converting from sip to pjsip on and off for a year or two before I finally got it working. I don’t recall sip being that hard, but it was 15 years ago and the asterisk mail list was amazing and the Asterisk book was extremely helpful. Sadly, I’ve no idea what I finally did that made it work, nor do I have what most of the config files does, but Twilio said, your system will likely stop working if you don’t upgrade so I was under a bit of pressure. A few people here were amazingly helpful in getting it working. I think those same people, david551 and jcolp, were active in the thread I linked to.

I did take your config as template. I had to add some square brackets in the last section. I still have warnings and errors:


[Jan 30 07:33:02] ERROR[18339] res_pjsip/config_auth.c: No authentication username for auth 'OfficeAuth'
[Jan 30 07:33:02] ERROR[18339] res_sorcery_config.c: Could not create an object of type 'auth' with id 'OfficeAuth' from configuration file 'pjsip.conf'
[Jan 30 07:33:02] DEBUG[18339] config.c: Parsing /etc/asterisk/pjsip.conf
...
[Jan 30 07:33:02] DEBUG[18369] res_pjsip/pjsip_options.c: Configuring AOR 'OfficeAors' with current state of configuration and world
[Jan 30 07:33:02] DEBUG[18369] res_pjsip/pjsip_options.c: AOR 'OfficeAors' is unqualified, number of available contacts is therefore '0'
[Jan 30 07:33:02] DEBUG[18369] res_pjsip/pjsip_options.c: AOR 'OfficeAors' now has 0 available contacts
[Jan 30 07:33:02] DEBUG[18369] res_pjsip/pjsip_options.c: Synchronizing endpoint 'ProviderOut' with AORs 'ProviderOut'
[Jan 30 07:33:02] DEBUG[18370] res_pjsip/pjsip_options.c: Adding endpoint compositor 'ProviderOut' to AOR 'ProviderOut'
[Jan 30 07:33:02] DEBUG[18369] res_pjsip/pjsip_options.c: Endpoint 'OfficeEndpoint' is not interested in any AORs so not creating endpoint state compositor
[Jan 30 07:33:02] DEBUG[18369] res_pjsip/pjsip_options.c: Synchronizing endpoint 'Provider' with AORs 'Provider'
...
[Jan 30 07:37:17] DEBUG[18395] res_pjsip_endpoint_identifier_ip.c: Source address 192.168.1.55:5060 matches identify 'Provider'
[Jan 30 07:37:17] DEBUG[18395] res_pjsip_endpoint_identifier_ip.c: Identify 'Provider' SIP message matched to endpoint Provider
[Jan 30 07:37:17] WARNING[18395] res_pjsip_registrar.c: AOR '' not found for endpoint 'Provider' (192.168.1.55:5060)

With my config I had the same message about AOR not found.

There are so many ways to make something wrong, I’ll double-check the configuration.
Basically, in my config, I have a register section that is not present in yours. On the other hand, I only have an endpoint section for outbound/inbound. I don’t know if this could cause a problem?

I finally managed to solve one part of my problem, thanks to this post (outbound):

https://www.reddit.com/r/Asterisk/comments/lidnfj/pjsip_how_to_customize_aor_and_auth_section_name/?rdt=62866

It seems that in some cases, the endpoint name and aor name should be same (or is easier so). I modified the extension as follows:

Inbound is still not working

I think in my examples everything but auth had the same name and as the type line defines the section it seems to work fine. I would certainly make all the names the same as a test, there is no downside I saw.

I made some progress, now I’m able to get inbound/outbound working. It seems that extensions.conf is no more working the same as previous. I have to specify my phone number with country code to catch the local phone number:

[incoming]

; incoming calls to ATA
; check if blacklisted

exten => s,1,GotoIf(${BLACKLIST()}?blacklisted)
exten => 412433322XX,1,goto(ATA,s,1)
same => n(blacklisted),Hangup()

[ATA]
exten => s,1,Dial(PJSIP/1000,m) ; ATA Gigaset dial Local


I still have 2 problems, one with moh (res_musiconhold.c:385 ast_moh_files_next: Unable to open file ‘/var/lib/asterisk/moh/moh2’: No such file or directory), This may be not a big problem. And the second problem is that I want to have a delay of 4 seconds before ringing to prevent call centers. This was working with my old sip.conf, but this is no more the case with pjsip.conf:

same => n,Dial(Local/channel_1@DelayToRing,m) ; ATA dial Local with delay
same => n(blacklisted),Hangup()

[DelayToRing]
exten => channel_1,1,Verbose(2,Dialing the ATA phone with delay)
same => n,Wait(4)
same => n,Dial(PJSIP/1000)
same => n,Hangup()

Let’s see if I can get it working again

I finally managed to solve all the problems. There were still 2 modules not loaded by default (codec_alaw.so for Europe and func_blacklist.so). Finally, the path to the music on hold file was incorrect.

To recap, for the local phone extension, the sections endpoint and aor names must be identical. Then extension.conf file needs to capture the local phone number. Finally, check the setup above.

Thanks to iraemus for providing an example, which was very helpull to compare

I don’t know why it has to have the whole phone number as a target and doesn’t work with s,1. I did look at my old sip.conf and it had the numbers in it also for both providers I use.

Typically, when you have a sip trunk, a call to a DID is sent by your provider to your PBX over the trunk as a call to that extension. So when someone calls (as an example) 555-555-1234, the call comes in to my Asterisk from the trunk as a call to extension 5555551234. Even if you only have a single number on that trunk.

The old (s,1) stuff was for when you were dealing with analog lines being digitized by cards. I still use it for IVR entrypoints in a probably improper fashion. It might be useful if you’re “faking” a trunk by using peer mode in SIP.

But for most providers that support full SIP trunking and PBX, you’re going to be sent a full DID and your dialplan needs to account for that.

Thank you, I started with Analog lines and must have put in the DID targets so long ago I didn’t remember.

[ Although my main point was correct, I got a bit confused when first writing this. I hope it is now correct. ]

That tends to be true for IP based identification, but it appears that a significant proportion of providers using REGISTER handle REGISTER as per the RFC, and set the request URI to the Contact header URI, whose user part is done as an extra string in the register string in chan_sip, but as an explicit, named, option in chan_pjsip. The default for that is s.

It is possible that chan_pjsip users are more likely to think they have to provide a value because it is an explicitly named option.

Typically, if the provider handles registration contacts correctly, they will put the DID in the To header, but other methods are used.

The request URI user becomes the initial extension.

Unfortunately, I still have a problem with my config somewhere. After a while (I haven’t yet determined how long), incoming calls no longer work.
My first thought was the problem described below:

I added the specified parameters without success. I can’t see anything particular in the log (full).

Any idea?

I finally managed to solve the last problem. In fact, with the migration to Debian 12, the firewall interrupts UDP sessions, even established, and so my server was no longer responding to INVITE from my provider.

As stated in the following link I had to add the parameter “qualify_frequency = 120” in the AOR of my endpoint. Since then, everything has worked fine.

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