How do I make an outbound call to a mobile number?

My asterisk is connect to an SIP Trunk with PJSIP module. I want to forward all calls to an extensions to my mobile number. How do I do it?

This is how my dialplan looks like,
+9196******** is my mobile number written without the asterisks in the dialplan file.

[forward-to-mobile]
exten => s,1,Dial(PJSIP/airtel/+9196********,40)
exten => s,2,Hangup()

In the pjsip config file, airtel is an endpoint.
When I connect to the extension connected to this context, here’s the log I see,

== Setting global variable 'SIPDOMAIN' to 'ims.airtel.in'
Executing [<DID Number from SIP>@from-external: 1] Goto ("PJSIP/airtel-00000000", "forward-to-mobile, s,1") in new stack Goto (forward-to-mobile, s, 1)
Executing [s@forward-to-mobile:1] Dial("PJSIP/airtel-00000000", "PJSIP/airtel/+9196********,40") in new stack
[Jan 28 16:54:27] ERROR [7061]: res_pjsip.c:3500 ast_sip_create_dialog_uac: Endpoint 'airtel': Could not create dialog to invalid URI +91962039****'. Is endpoint registered and reachable?
[Jan 28 16:54:27] ERROR [7061]: chan_pjsip.c: 2498 request: Failed to create outgoing session to endpoint 'airtel'
[Jan 28 16:54:27] WARNING [7124] [C-00000001]: app_dial.c:2507 dial_exec_full: Unable to create channel of type 'PJSIP' (cause3- No route to destination)
Everyone is busy/congested at this time (1:0/0/1)
Executing [s@forward-to-mobile:2] Hangup ("PJSIP/airtel-00000000","") in new stack
== Spawn extension (forward-to-mobile, s, 2) exited non-zero on 'PJSIP/airtel-00000000¹

On FreePBX, I was able to achieve this functionality by creating a misc destination for the mobile number and then creating an inbound route with misc destination as the mobile number. How do I replicate a similar behavior with asterisk config files?

The Dial string format for that is:

PJSIP/+91962039****@airtel
1 Like

Thanks @jcolp

Do you think Everyone is busy/congested at this time (1:0/0/1) this line is also related to the incorrect dial string format?

Yes, it is. All dial targets (of which there was one) failed.

And failed with an “unavailable” status. The number is the number of outgoing legs, the number that failed busy, the number that failed congested, and the number that failed unavailable.

1 Like

I tried with the following dial string formats and getting similar results,
PJSIP/+91962039****@airtel
PJSIP/91962039****@airtel

With an without the +

Logs,
Please note that
{{caller}} is the phone number of user
{{sip_number}} is the number that is being dialed by user
{{mobile_number}} is the phone number where I am trying forward the calls from user
Replaced with above for privacy

<--- Received SIP request (1228 bytes) from UDP:10.232.139.146:5060 --->
INVITE sip:{{sip_number}}@ims.airtel.in SIP/2.0
Via: SIP/2.0/UDP 10.232.139.146:5060;branch=z9hG4bK1t0sfp5ht7h45h3h41r55trpt;Role=3;Hpt=8fc2_36;TRC=ffffffff-ffffffff
Call-ID: asbc7k618m4n5gmz8ku8qqn6mnukuh76qg97@B.5.42.ims.airtel.in
From: <sip:{{caller}}@ims.airtel.in>;tag=02br0ygx
To: <sip:{{sip_number}}@ims.airtel.in>
CSeq: 1 INVITE
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,INFO,PRACK,NOTIFY,MESSAGE,REFER,UPDATE
Contact: <sip:10.232.139.146:5060;Dsp=eb9a-200;Dpt=77d8-400;Hpt=8fc2_16;CxtId=4;TRC=ffffffff-ffffffff>
Max-Forwards: 64
Supported: timer,100rel,histinfo
Session-Expires: 1800
Min-SE: 600
P-Asserted-Identity: <sip:0{{caller}}@ims.airtel.in>
P-Charging-Vector: icid-value=AE888F23F92CDD2022128194033;orig-ioi=10.232.136.242;term-ioi=Magicl_8046897600
P-Early-Media: gated
Content-Length: 380
Content-Type: application/sdp

v=0
o=- 185426899 185426899 IN IP4 10.232.139.147
s=SBC call
c=IN IP4 10.232.139.147
t=0 0
m=audio 22612 RTP/AVP 108 102 8 0 18 116
a=rtpmap:108 AMR/8000
a=fmtp:108 mode-change-neighbor=1;mode-change-period=2
a=rtpmap:102 AMR/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=rtpmap:116 telephone-event/8000
a=ptime:20
a=maxptime:20
a=3gOoBTC

  == Setting global variable 'SIPDOMAIN' to 'ims.airtel.in'
<--- Transmitting SIP response (412 bytes) to UDP:10.232.139.146:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.232.139.146:5060;rport=5060;received=10.232.139.146;branch=z9hG4bK1t0sfp5ht7h45h3h41r55trpt;Role=3;Hpt=8fc2_36;TRC=ffffffff-ffffffff
Call-ID: asbc7k618m4n5gmz8ku8qqn6mnukuh76qg97@B.5.42.ims.airtel.in
From: <sip:{{caller}}@ims.airtel.in>;tag=02br0ygx
To: <sip:{{sip_number}}@ims.airtel.in>
CSeq: 1 INVITE
Server: Asterisk PBX 16.2.1~dfsg-2ubuntu1
Content-Length:  0


    -- Executing [{{sip_number}}@from-external:1] Goto("PJSIP/airtel-00000002", "forward-to-mobile,s,1") in new stack
    -- Goto (forward-to-mobile,s,1)
    -- Executing [s@forward-to-mobile:1] Dial("PJSIP/airtel-00000002", "PJSIP/{{mobile_number}}@airtel,40") in new stack
    -- Called PJSIP/{{mobile_number}}@airtel
<--- Transmitting SIP request (927 bytes) to UDP:10.232.139.146:5060 --->
INVITE sip:{{mobile_number}}@ims.airtel.in SIP/2.0
Via: SIP/2.0/UDP 100.120.68.206:5060;rport;branch=z9hG4bKPj6259add8-76df-4e0a-8250-40823af4346c
From: <sip:{{caller}}@192.168.0.152>;tag=eac85f37-7818-487b-853c-5e9a922a5415
To: <sip:{{mobile_number}}@ims.airtel.in>
Contact: <sip:asterisk@100.120.68.206:5060>
Call-ID: 23d81fe1-0ba2-4042-8329-564283cfbfe3
CSeq: 32465 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REFER, MESSAGE
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 16.2.1~dfsg-2ubuntu1
Content-Type: application/sdp
Content-Length:   239

v=0
o=- 300513503 300513503 IN IP4 100.120.68.206
s=Asterisk
c=IN IP4 100.120.68.206
t=0 0
m=audio 15786 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

<--- Received SIP response (327 bytes) from UDP:10.232.139.146:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 100.120.68.206:5060;branch=z9hG4bKPj6259add8-76df-4e0a-8250-40823af4346c;rport=5060
Call-ID: 23d81fe1-0ba2-4042-8329-564283cfbfe3
From: <sip:{{caller}}@192.168.0.152>;tag=eac85f37-7818-487b-853c-5e9a922a5415
To: <sip:{{mobile_number}}@ims.airtel.in>
CSeq: 32465 INVITE
Content-Length: 0


<--- Received SIP response (437 bytes) from UDP:10.232.139.146:5060 --->
SIP/2.0 604 Does Not Exist Anywhere
Via: SIP/2.0/UDP 100.120.68.206:5060;branch=z9hG4bKPj6259add8-76df-4e0a-8250-40823af4346c;rport=5060
Call-ID: 23d81fe1-0ba2-4042-8329-564283cfbfe3
From: <sip:{{caller}}@192.168.0.152>;tag=eac85f37-7818-487b-853c-5e9a922a5415
To: <sip:{{mobile_number}}@ims.airtel.in>;tag=j98cqbxb
CSeq: 32465 INVITE
Warning: 399 5244.683.B.261.5.30.0.14.24839.0.0.ims.airtel.in "Unknown caller"
Content-Length: 0


<--- Transmitting SIP request (422 bytes) to UDP:10.232.139.146:5060 --->
ACK sip:{{mobile_number}}@ims.airtel.in SIP/2.0
Via: SIP/2.0/UDP 100.120.68.206:5060;rport;branch=z9hG4bKPj6259add8-76df-4e0a-8250-40823af4346c
From: <sip:{{caller}}@192.168.0.152>;tag=eac85f37-7818-487b-853c-5e9a922a5415
To: <sip:{{mobile_number}}@ims.airtel.in>;tag=j98cqbxb
Call-ID: 23d81fe1-0ba2-4042-8329-564283cfbfe3
CSeq: 32465 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 16.2.1~dfsg-2ubuntu1
Content-Length:  0


  == Everyone is busy/congested at this time (1:0/0/1)
    -- Executing [s@forward-to-mobile:2] Hangup("PJSIP/airtel-00000002", "") in new stack
  == Spawn extension (forward-to-mobile, s, 2) exited non-zero on 'PJSIP/airtel-00000002'
<--- Transmitting SIP response (479 bytes) to UDP:10.232.139.146:5060 --->
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 10.232.139.146:5060;rport=5060;received=10.232.139.146;branch=z9hG4bK1t0sfp5ht7h45h3h41r55trpt;Role=3;Hpt=8fc2_36;TRC=ffffffff-ffffffff
Call-ID: asbc7k618m4n5gmz8ku8qqn6mnukuh76qg97@B.5.42.ims.airtel.in
From: <sip:{{caller}}@ims.airtel.in>;tag=02br0ygx
To: <sip:{{sip_number}}@ims.airtel.in>;tag=63a807a4-4629-4266-967d-444b6e3d4731
CSeq: 1 INVITE
Server: Asterisk PBX 16.2.1~dfsg-2ubuntu1
Reason: Q.850;cause=1
Content-Length:  0


<--- Received SIP request (413 bytes) from UDP:10.232.139.146:5060 --->
ACK sip:{{sip_number}}@ims.airtel.in SIP/2.0
Via: SIP/2.0/UDP 10.232.139.146:5060;branch=z9hG4bK1t0sfp5ht7h45h3h41r55trpt;Role=3;Hpt=8fc2_36;TRC=ffffffff-ffffffff
Call-ID: asbc7k618m4n5gmz8ku8qqn6mnukuh76qg97@B.5.42.ims.airtel.in
From: <sip:{{caller}}@ims.airtel.in>;tag=02br0ygx
To: <sip:{{sip_number}}@ims.airtel.in>;tag=63a807a4-4629-4266-967d-444b6e3d4731
CSeq: 1 ACK
Max-Forwards: 70
Content-Length: 0

However my mobile number is not busy and has complete network signals. What could I have been going wrong here?

That’s the reason the provider is responding with a 604. I know nothing of your provider or what it requires, so can’t comment further.

Would you have any pointers what should I look into to check this?

I had this exact SIP trunk connected to a FreePBX instance and it was able to forward calls to the same mobile number just fine. The issue has to be in my configuration.

This is how my pjsip.conf looks like,

;==============TRANSPORTS

[simpletrans]
type=transport
protocol=udp
bind=0.0.0.0

;===============TRUNK

[airtel]
type=registration
outbound_auth=airtel
server_uri=sip:ims.airtel.in
client_uri=sip:{{USERNAME}}@ims.airtel.in
retry_interval=60

[airtel]
type=auth
auth_type=userpass
password={{PASSWORD}}
username={{USERNAME}}@ims.airtel.in

[airtel]
type=aor
contact=sip:ims.airtel.in

[airtel]
type=endpoint
context=from-external
disallow=all
allow=ulaw
outbound_auth=airtel
aors=airtel

[airtel]
type=identify
endpoint=airtel
match=ims.airtel.in

Also, with 604 response – the request is,

From: <sip:{{caller}}@192.168.0.152>;tag=eac85f37-7818-487b-853c-5e9a922a5415
To: <sip:{{mobile_number}}@ims.airtel.in>;tag=j98cqbxb

Shouldn’t the From here have the {{sip_number}}? Is it possible that Airtel is blocking my calls because it thinks I am spoofing callerid?

It is possible. The from_user option on the endpoint sets the From username.

I’ve added a from_user option in the endpoint.

from_user=0804689****

Yet, the latest log looked like,

<--- Received SIP response (436 bytes) from UDP:10.232.139.146:5060 --->
SIP/2.0 604 Does Not Exist Anywhere
Via: SIP/2.0/UDP 100.120.68.206:5060;branch=z9hG4bKPjde583e2f-0ea1-4166-a002-af3b3c19a2f8;rport=5060
Call-ID: aab1dd77-c040-4c20-b12e-31dfbdff9fb5
From: <sip:0804689****@192.168.0.152>;tag=799fe7d4-2303-4c05-81b0-97fff3f0df31
To: <sip:814743****@ims.airtel.in>;tag=np3uyner
CSeq: 12532 INVITE
Warning: 399 5244.683.B.261.5.11.0.14.24839.0.0.ims.airtel.in "Unknown caller"
Content-Length: 0

I think the issue here could be the format of the outbound number or the from_user string. I will check with my ISP regarding both in that case

Update, I was able to resolve the issue after setting from_user and from_domain in the pjsip.conf,

from_user=+9180********
from_domain=ims.airtel.in

Found this FreePbx discussion to be really helpful.

From the logs I noticed that REGISTER call was successful but the subsequent calls were not. Then I changed the settings so that the From header would match what was being sent in Register. That worked!

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