Pjsip trunk and @ in the username

Hello everyone, I just cannot find a solution in this! The provider requires @ in the username ([email protected]), but pjsip keeps rejecting the URI with error:

res_pjsip.c:3888 create_out_of_dialog_request: Unable to create outbound OPTIONS request to endpoint EEE–123456789 as URI ‘sip:[email protected]@www.xxx.com:5060’ is not valid
[2020-10-12 21:35:42] ERROR[6882]: res_pjsip/pjsip_options.c:877 sip_options_qualify_contact: Unable to create request to qualify contact sip:[email protected]@www.xxx.com:5060 on AOR 123456

How can I use “@” in the username?
is there an alternative to the username (authuser)?

The provider gave me the instructions:
Username [email protected]
Password:YYYY
Account Name: phone
port:5060

Finally, a post with good information.

Please try these trunk settings (replacing xxxx with the last 4 digits of your number):

Trunk Name: OTE–211402xxxx
Username: +30211402xxxx
Secret: (your password at OTE)
Authentication: Outbound
Registration: Send
SIP Server: ims.otenet.gr
SIP Server Port: 5060
Context: from-trunk
From Domain: ims.otenet.gr
From User: +30211402xxxx

Leave other settings blank or at their defaults.

Then, put these two lines into /etc/asterisk/pjsip.auth_custom_post.conf

[OTE-211402xxxx](+type=auth)
[email protected]

Restart Asterisk and test. If it won’t register, post the REGISTER request being sent, with Authorization header if available.

1 Like

Yeah, gave too much information though I think :smile: ,had to dial it down a bit… It registers(!!!) but no outbound or inbound calls. Outbound - message: “The number you have dialed is not in service”- log:

Executing [s-INVALIDNMBR@macro-dialout-trunk:1] NoOp(“PJSIP/999-00000006”, “Dial failed due to trunk reporting Address Incomplete - giving up”) in new stack

Although, I used the same address for the sip trunk…
Just a quick question…how did you know the provider???

Are you sending the destination number in the correct format? If OTE requires +30xxxxxxxxxx, your Outbound Route or trunk Manipulation Rules need to convert whatever you dialed to that format. Search the log for OUTNUM to see what it sent. If you still have trouble, compare the INVITE sent by your working chan_sip trunk with the one sent by pjsip.

What goes wrong on incoming? Possibly, the Contact header has the wrong address. Does anything get logged on an attempted call?

Pjsip sip log (with error):
INVITE sip:[email protected]:5060 SIP/2.0
198008 Via: SIP/2.0/UDP 7x.XXX.XXX.164:5060;rport;branch=z9hG4bKPja0264178-d117-4fa1-9233-b670defbdd15
198009 From: sip:[email protected];tag=c13dea4d-32ef-4f15-a667-10c196cf2b0a
198010 To: sip:[email protected]
198011 Contact: sip:[email protected]:5060
198012 Call-ID: 3a305235-784d-415a-93eb-16bf1bbcd465
198013 CSeq: 29281 INVITE
198014 Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
198015 Supported: 100rel, timer, replaces, norefersub
198016 Session-Expires: 1800
198017 Min-SE: 90
198018 Max-Forwards: 70
198019 User-Agent: FPBX-15.0.16.75(16.13.0)
198020 Content-Type: application/sdp
198021 Content-Length: 390
198022
198023 v=0
198024 o=- 1280648200 1280648200 IN IP4 7x.XXX.XXX.164
198025 s=Asterisk
198026 c=IN IP4 7x.XXX.XXX.164
198027 t=0 0
198028 m=audio 14556 RTP/AVP 0 8 3 9 18 111 101
198029 a=rtpmap:0 PCMU/8000
198030 a=rtpmap:8 PCMA/8000
198031 a=rtpmap:3 GSM/8000
198032 a=rtpmap:9 G722/8000
198033 a=rtpmap:18 G729/8000
198034 a=fmtp:18 annexb=no
198035 a=rtpmap:111 G726-32/8000
198036 a=rtpmap:101 telephone-event/8000
198037 a=fmtp:101 0-16
198038 a=ptime:20
198039 a=maxptime:150
198040 a=sendrecv
198041
198042 [2020-10-12 23:13:52] VERBOSE[21102] res_pjsip_logger.c: <— Received SIP response (330 bytes) from UDP:195.167.16.1:5060 —>
198043 SIP/2.0 100 Trying
198044 Via: SIP/2.0/UDP 7x.XXX.XXX.164:5060;branch=z9hG4bKPja0264178-d117-4fa1-9233-b670defbdd15;rport=18500
198045 Call-ID: 3a305235-784d-415a-93eb-16bf1bbcd465
198046 From: sip:[email protected];tag=c13dea4d-32ef-4f15-a667-10c196cf2b0a
198047 To: sip:[email protected]
198048 CSeq: 29281 INVITE
198049 Content-Length: 0
198050
198051
198052 [2020-10-12 23:13:53] VERBOSE[21102] res_pjsip_logger.c: <— Received SIP response (449 bytes) from UDP:195.167.16.1:5060 —>
198053 SIP/2.0 604 Does Not Exist Anywhere
198054 Via: SIP/2.0/UDP 7x.XXX.XXX.164:5060;branch=z9hG4bKPja0264178-d117-4fa1-9233-b670defbdd15;rport=18500
198055 Call-ID: 3a305235-784d-415a-93eb-16bf1bbcd465
198056 From: sip:[email protected];tag=c13dea4d-32ef-4f15-a667-10c196cf2b0a
198057 To: sip:[email protected];tag=sbc0507f2stz0vf
198058 CSeq: 29281 INVITE
198059 Warning: 399 5244.684.I.261.11.345.0.13.24839.0.0.ims.otenet.gr “Unknown caller”
198060 Content-Length: 0
198061
198062
198063 [2020-10-12 23:13:53] VERBOSE[21103] res_pjsip_logger.c: <— Transmitting SIP request (425 bytes) to UDP:195.167.16.1:5060 —>
198064 ACK sip:[email protected]:5060 SIP/2.0
198065 Via: SIP/2.0/UDP 7x.XXX.XXX.164:5060;rport;branch=z9hG4bKPja0264178-d117-4fa1-9233-b670defbdd15
198066 From: sip:[email protected];tag=c13dea4d-32ef-4f15-a667-10c196cf2b0a
198067 To: sip:[email protected];tag=sbc0507f2stz0vf
198068 Call-ID: 3a305235-784d-415a-93eb-16bf1bbcd465
198069 CSeq: 29281 ACK
198070 Max-Forwards: 70
198071 User-Agent: FPBX-15.0.16.75(16.13.0)
198072 Content-Length: 0

CHAN SIP LOG (Correct)

INVITE sip:6********@ims.otenet.gr SIP/2.0
210804 Via: SIP/2.0/UDP 192.168.10.251:5260;branch=z9hG4bK0499d648
210805 Max-Forwards: 70
210806 From: sip:[email protected]:5260;tag=as7e995a97
210807 To: sip:6********@ims.otenet.gr
210808 Contact: sip:[email protected]:5260
210809 Call-ID: [email protected]
210810 CSeq: 102 INVITE
210811 User-Agent: FPBX-15.0.16.75(16.13.0)
210812 Date: Mon, 12 Oct 2020 23:27:11 GMT
210813 Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
210814 Supported: replaces, timer
210815 Content-Type: application/sdp
210816 Content-Length: 403
210817
210818 v=0
210819 o=root 182134353 182134353 IN IP4 192.168.10.251
210820 s=Asterisk PBX 16.13.0
210821 c=IN IP4 192.168.10.251
210822 t=0 0
210823 m=audio 11440 RTP/AVP 9 0 8 3 18 111 101
210824 a=rtpmap:9 G722/8000
210825 a=rtpmap:0 PCMU/8000
210826 a=rtpmap:8 PCMA/8000
210827 a=rtpmap:3 GSM/8000
210828 a=rtpmap:18 G729/8000
210829 a=fmtp:18 annexb=no
210830 a=rtpmap:111 G726-32/8000
210831 a=rtpmap:101 telephone-event/8000
210832 a=fmtp:101 0-16
210833 a=ptime:20
210834 a=maxptime:150
210835 a=sendrecv
210836
210837 —
210838 [2020-10-12 23:27:11] VERBOSE[1529][C-00000003] app_dial.c: Called SIP/OTE211XXXXXX/6********
210839 [2020-10-12 23:27:11] VERBOSE[30939] chan_sip.c:
210840 <— SIP read from UDP:195.167.16.1:5060 —>
210841 SIP/2.0 100 Trying
210842 Via: SIP/2.0/UDP 192.168.10.251:5260;branch=z9hG4bK0499d648;received=7*.***.**.164
210843 Call-ID: [email protected]
210844 From: sip:[email protected]:5260;tag=as7e995a97
210845 To: sip:6********@ims.otenet.gr
210846 CSeq: 102 INVITE
210847 Content-Length: 0
210848
210849 <------------->
210850 [2020-10-12 23:27:11] VERBOSE[30939] chan_sip.c: — (7 headers 0 lines) —
210851 [2020-10-12 23:27:12] VERBOSE[30939] chan_sip.c:
210852 <— SIP read from UDP:195.167.16.1:5060 —>
210853 SIP/2.0 183 Session Progress
210854 Via: SIP/2.0/UDP 192.168.10.251:5260;branch=z9hG4bK0499d648;received=7
.***.**.164
210855 Call-ID: [email protected]
210856 From: sip:[email protected]:5260;tag=as7e995a97
210857 To: sip:6********@ims.otenet.gr;tag=sbc0504ncf61due-CC-79
210858 CSeq: 102 INVITE
210859 Contact: sip:195.167.16.1:5060
210860 Content-Length: 196
210861 Content-Type: application/sdp
210862
210863 v=0
210864 o=- 8875229 8875229 IN IP4 195.167.17.1
210865 s=SBC call
210866 c=IN IP4 195.167.17.1
210867 t=0 0
210868 m=audio 21462 RTP/AVP 8
210869 b=RS:1000
210870 b=RR:3000
210871 a=rtpmap:8 PCMA/8000
210872 a=ptime:20
210873 a=maxptime:40
210874 a=sendrecv
210875 <------------->
210876 [2020-10-12 23:27:12] VERBOSE[30939] chan_sip.c: — (9 headers 12 lines) —
210877 [2020-10-12 23:27:12] VERBOSE[30939][C-00000003] sip/route.c: sip_route_dump: route/path hop: sip:195.167.16.1:5060
210878 [2020-10-12 23:27:12] VERBOSE[30939][C-00000003] chan_sip.c: Got SDP version 8875229 and unique parts [- 8875229 IN IP4 195.167.17.1]
210879 [2020-10-12 23:27:12] VERBOSE[30939][C-00000003] chan_sip.c: Found RTP audio format 8
210880 [2020-10-12 23:27:12] VERBOSE[30939][C-00000003] chan_sip.c: Found audio description format PCMA for ID 8
210881 [2020-10-12 23:27:12] VERBOSE[30939][C-00000003] chan_sip.c: Capabilities: us - (ulaw|alaw|gsm|g729|g726|g722), peer - audio=(alaw)/video=(nothing)/text=(nothing), combined - (alaw)
210882 [2020-10-12 23:27:12] VERBOSE[30939][C-00000003] chan_sip.c: Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x0 (nothing), combined - 0x0 (nothing)
210883 [2020-10-12 23:27:12] VERBOSE[30939][C-00000003] chan_sip.c: Peer audio RTP is at port 195.167.17.1:21462
210884 [2020-10-12 23:27:12] VERBOSE[1529][C-00000003] app_dial.c: SIP/OTE21XXXXXXX-00000001 is making progress passing it to PJSIP/999-00000003
210885 [2020-10-12 23:27:12] VERBOSE[30939] chan_sip.c:
210886 <— SIP read from UDP:195.167.16.1:5060 —>
210887 SIP/2.0 180 Ringing
210888 Via: SIP/2.0/UDP 192.168.10.251:5260;branch=z9hG4bK0499d648;received=7
.***.***.164
210889 Call-ID: [email protected]
210890 From: sip:[email protected]:5260;tag=as7e995a97
210891 To: sip:6********@ims.otenet.gr;tag=sbc0504ncf61due-CC-79
210892 CSeq: 102 INVITE
210893 Contact: sip:195.167.16.1:5060
210894 Content-Length: 0

It appears that you don’t have From Domain set in your trunk. If you do, check for funny characters such as leading or trailing spaces.

Done!! Outbound is working!! But no inbound, and no logs. Tried enabling authentication in both inbound and outbound, but no luck…

Post the REGISTER request and the 200 OK response, for both the working chan_sip and the failing pjsip.

How can I capture the REGISTER request? When I restart asterisk, I cannot see the sip logs at same time and when I go back, it’s already registered…

Yes, it’s unfortunate that the pjsip logger option gets turned off by a reload.

For chan_sip, you can do
sip set debug on
then
core reload
and see the registration request.

For pjsip, options include:

  1. Turn logger on and wait for re-registration, possibly setting a shorter expiry if provider permits.
  2. Add a config override debug=yes under [global]
  3. Use sngrep, tcpdump or a similar tool to capture traffic independent of Asterisk.
  4. Use an external traffic capture tool e.g. Wireshark with a managed switch.

After a lot of work, I finally have the logs:
Sip (working)
REGISTER 11 headers, 0 lines
Reliably Transmitting (NAT) to 195.167.16.1:5060:
REGISTER sip:ims.provider.gr SIP/2.0
Via: SIP/2.0/UDP 192.168.10.251:5260;branch=z9hG4bK53f47c0b;rport
Max-Forwards: 70
From: sip:[email protected];tag=as5a30053b
To: sip:[email protected]
Call-ID: [email protected]
CSeq: 103 REGISTER
Supported: replaces, timer
User-Agent: FPBX-15.0.16.75(16.13.0)
Expires: 120
Contact: sip:[email protected]:5260
Content-Length: 0


<— SIP read from UDP:195.167.16.1:5060 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.10.251:5260;branch=z9hG4bK53f47c0b;rport
Call-ID: [email protected]
From: sip:[email protected];tag=as5a30053b
To: sip:[email protected];tag=sbc0508kzoom2y3
CSeq: 103 REGISTER
Contact: sip:[email protected]:5260;expires=120
Max-Forwards: 70
Content-Length: 0

Pjsip (not working)
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 7X.XXX.XXX.XXX:5060;branch=z9hG4bKPj72390bef-871d-4ee2-9834-a32e0660e6fd;received=7X.XXX.XXX.XXX;rport=49801
Call-ID: 74f7afca-0adb-4e62-af9e-70b806541eb9
From: sip:[email protected];tag=68dd4179-8e0a-4f5b-82b9-9788b7dbe008
To: sip:[email protected];tag=s7yjgies
CSeq: 21800 REGISTER
WWW-Authenticate: Digest realm=“ims.provider.gr”,nonce=“ZSpnLHh8dNCwF8p80QcLWg==”,algorithm=MD5
Content-Length: 0

<— Transmitting SIP request (790 bytes) to UDP:195.167.16.1:5060 —>
REGISTER sip:ims.provider.gr:5060 SIP/2.0
Via: SIP/2.0/UDP 7X.XXX.XXX.XXX:5060;rport;branch=z9hG4bKPjdcc45cf1-0475-4768-9116-8f9cf22186b2
From: sip:[email protected];tag=68dd4179-8e0a-4f5b-82b9-9788b7dbe008
To: sip:[email protected]
Call-ID: 74f7afca-0adb-4e62-af9e-70b806541eb9
CSeq: 21801 REGISTER
Contact: sip:[email protected]:5060;line=jjjkmkg
Expires: 30
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Max-Forwards: 70
User-Agent: FPBX-15.0.16.75(16.13.0)
Authorization: Digest username="[email protected]", realm=“ims.provider.gr”, nonce=“ZSpnLHh8dNCwF8p80QcLWg==”, uri=“sip:ims.provider.gr:5060”, response=“6d5dc9570a5dc4b5593a4dab8d8b349c”, algorithm=MD5
Content-Length: 0

<— Received SIP response (539 bytes) from UDP:195.167.16.1:5060 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 7X.XXX.XXX.XXX:5060;branch=z9hG4bKPjdcc45cf1-0475-4768-9116-8f9cf22186b2;received=7X.XXX.XXX.XXX;rport=49801
Call-ID: 74f7afca-0adb-4e62-af9e-70b806541eb9
From: sip:[email protected];tag=68dd4179-8e0a-4f5b-82b9-9788b7dbe008
To: sip:[email protected];tag=yjh2uehs
CSeq: 21801 REGISTER
P-Associated-URI: tel:+3123456789,sip:[email protected]
Accept-Resource-Priority: wps.4
Contact: sip:[email protected]:5060;line=jjjkmkg;q=1;expires=30
Content-Length: 0

In opnsense, disable source port rewriting, restart Asterisk. With luck you’ll now see rport=5060. If this doesn’t work, please explain your network setup. Are you double NATted (opnsense + modem NAT)?

An alternative is to let the provider do NAT traversal. In Asterisk SIP Settings, add 195.167.16.0/24 to Local Networks, restart Asterisk.

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