PJSIP in Asterisk


PJSIP (res_pjsip.so) replaces replaces chan_sip.so. It has a different configuration file (pjsip.conf) and a much nicer configuration syntax.

PJSIP wizard

On the downside, the configuration is much more verbose. But this complexity can be avoided by using res_pjsip_config_wizard.so and the configuration file pjsip_wizard.conf. The wizard module has an easier syntax and handles the creation of all the res_pjsip.so objects.

The nice thing is that every res_pjsip.so setting created this way can still be changed by prefixing the object name (objectname/setting). However, for some settings this is actually needed. The wizard module alone will not create a usable configuration!

Errors and possible solutions

Error Possible solution
No suitable credential Maybe the realm is wrong. It can be changed with inbound_auth/realm = …
No channel type registered for 'SIP' The technology in the Dial application must be changed from SIP to PJSIP (e.g. PJSIP/42@example.com)
No route to destination The dialed number must exist as an endpoint and must be available (see pjsip list endpoints)
SIP/2.0 403 Username in From Field required Sniff the SIP protocol. Maybe the From: header used to communicate with the provider is wrong. It must not be
From: <sip:something@your_ip>
From: <sip:your_provider_username@your_provider_domain>.

This is configured by setting endpoint/from_user and endpoint/from_domain to the username you use to authenticate with your provider and to the domain of the provider.

no media line found in SDP message There may be some endpoint/ options missing in the phone section.
The extension called by the provider is “s”, i.e. To: <sip:s@…. Explicitly set the number that will be used for incoming calls. This is also the extension that will be used in the dial plan. registration/contact_user = 12345
symbol lookup error: /usr/lib64/asterisk/modules/res_pjsip.so: undefined symbol: pj_ssl_cipher_get_availables

symbol lookup error: /usr/lib64/asterisk/modules/res_pjsip.so: undefined symbol: pjsip_tls_transport_start2

PJSIP was not compiled with OpenSSL. The cause is either a bug in the autoconf build system configuration and/or in the patch that my distribution (Gentoo) uses to fix it. I was able to build with OpenSSL by adapting the ebuild. Without the patch it works if ./configure detects OpenSSL by itself without --enable-ssl.
(And 8 hours later PJSIP was flying.)

Example configuration


; res_pjsip_config_wizard.so
; https://wiki.asterisk.org/wiki/display/AST/PJSIP+Configuration+Wizard
; https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Configuration_res_pjsip_config_wizard

type = wizard
accepts_registrations = no       ; an identify object is created to match incoming requests to the endpoint
sends_auth = yes                 ; creates auth object
sends_registrations = yes        ; creates outbound_auth registration objects
aor/qualify_frequency = 30
endpoint/disallow = all
endpoint/allow = alaw
endpoint/dtmf_mode = rfc4733
endpoint/rtp_symmetric = yes
endpoint/force_rport = yes
endpoint/rewrite_contact = yes
endpoint/timers = yes
endpoint/language = de

; https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Configuration_res_pjsip_outbound_registration
; https://wiki.asterisk.org/wiki/display/AST/Configuring+Outbound+Registrations

[sipgate_trunk](trunk) ; creates endpoint and aor
transport = udp ; unencrypted UDP on port 5060 (defined in pjsip.conf)
endpoint/context = sipgate_incoming
registration/contact_user = 2385400 ; Calls from the provider will arrive in this extension in the dialplan
remote_hosts = sipgate.de:5060   ; creates a contact for each remopte host
endpoint/from_user = 42424242
endpoint/from_domain = sipgate.de
outbound_auth/username = 42424242
outbound_auth/password = XXXXXXXX

transport = transport-tls-out ; encrypted TLS on port 5061 (defined in pjsip.conf)
endpoint/context = easybell_incoming
remote_hosts = sip.easybell.de:5061
registration/contact_user = 66666 ; Calls from the provider will arrive in this extension in the dialplan
endpoint/from_user = 0049123466666
endpoint/from_domain = easybell.de
outbound_auth/username = 0049123466666
outbound_auth/password = XXXXXXXXXXXXX

type = wizard
transport = udp
inbound_auth/realm = apfelboymchen.dol
accepts_auth = yes ; Will create an inbound auth object for the endpoint
sends_auth = no
sends_registrations = no
accepts_registrations = yes
endpoint/disallow = all
endpoint/allow = alaw
aor/max_contacts = 1
endpoint/allow_subscribe = yes
endpoint/direct_media = yes
endpoint/force_rport = yes
;endpoint/disable_direct_media_on_nat = yes
endpoint/direct_media_method = invite
;endpoint/ice_support = yes
endpoint/moh_suggest = default
endpoint/send_rpid = yes
endpoint/rewrite_contact = yes
;endpoint/send_pai = yes
endpoint/allow_transfer = yes
;endpoint/trust_id_inbound = yes
endpoint/device_state_busy_at = 1
;endpoint/trust_id_outbound = yes
;endpoint/send_diversion = yes
aor/qualify_frequency = 30
aor/authenticate_qualify = no
aor/minimum_expiration = 30
aor/support_path = yes
has_hint = no
;hint_application = Gosub(stdexten,${EXTEN},1(${HINT}))

endpoint/context = some_context_1
inbound_auth/username = 42
inbound_auth/password = XXXXXXXXXXXXXXXXX

endpoint/context = some_context_2
inbound_auth/username = 66
inbound_auth/password = XXXXXXXXXXXXXXXXX


; res_pjsip.so
; https://wiki.asterisk.org/wiki/display/AST/Configuring+res_pjsip
; https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Configuration_res_pjsip
; https://wiki.asterisk.org/wiki/display/AST/PJSIP+Configuration+Sections+and+Relationships

; res_pjsip_outbound_registration
; https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Configuration_res_pjsip_outbound_registration

; sip
; https://wiki.asterisk.org/wiki/display/AST/Creating+SIP+Accounts
; https://wiki.asterisk.org/wiki/display/AST/res_pjsip+Configuration+Examples

type = global
default_realm = apfelboymchen.net

; https://wiki.asterisk.org/wiki/display/AST/PJSIP+Transport+Selection
type = transport
protocol = udp
bind =

; pjsip list ciphers
; Transport for *registering* via TLS. Still opens a local TLS port (without 
; having a cert defined!). May not be the correct solution.
protocol = tls
method = tlsv1
bind =

; accept unauthenticted calls from the net
; Endpoints are a representation of the configuration information for a remote 
; device that is to be communicated with
; https://wiki.asterisk.org/wiki/display/AST/Endpoints+and+Location,+A+Match+Made+in+Heaven

; AOR: an identifier for a device, or multiple devices, which is used for looking up how to contact them.
; https://wiki.asterisk.org/wiki/display/AST/Endpoints+and+Location,+A+Match+Made+in+Heaven
; https://wiki.asterisk.org/wiki/display/~jcolp/AORs%2C+Contacts%2C+Device+State
; https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Configuration_res_pjsip#Asterisk15Configuration_res_pjsip-aor


Nothing fancy, just the links to the Asterisk wiki that were also mentioned in the example configuration.

Licensed under the Creative Commons Attribution-Share Alike 3.0 License.
Created 2018-03