How to forward to cell phone using SIP in plain dialplan?

I have asterisk 1.8 (compiled) connected to SIP trunk (VOIP operator)
I want that asterisk will forward to number defined by variable not known when call start
(cell phone number will be set by agi).

I dont have ZAP or DAHDI channel available in asterisk and if I am correct it wont work in my case
cause I have only VOIP account registered/using SIP protocol - I dont have direct access to PSTN network nor any special hardware. am I wrong here ?

so I need use Dial(SIP/${fwdnumber}) - how to achieve it ?
is it possible using SIP?

my try:
exten => przychodzace2,n,Dial(SIP/${number})
[Aug 6 05:58:51] WARNING[14425]: chan_sip.c:5823 create_addr: Purely numeric hostname (*********), and not a peer–rejecting!
[Aug 6 05:58:51] WARNING[14425]: app_dial.c:2345 dial_exec_full: Unable to create channel of type ‘SIP’ (cause 20 - Subscriber absent)

my try2:
– Executing [przychodzace2@extravoip1:6] Dial(“SIP/extravoip1-00000000”, “SIP/@sip.extravoip.pl") in new stack
== Using SIP RTP CoS mark 5
> ast_get_srv: SRV lookup for ‘_sip._udp.sip.extravoip.pl’ mapped to host sip.extravoip.pl, port 5060
– Called SIP/
@sip.extravoip.pl
[Aug 6 07:48:32] NOTICE[14840]: chan_sip.c:21196 handle_response_invite: Failed to authenticate on INVITE to '"
***” sip:******@**********;tag=as783ad2e9’
– SIP/sip.extravoip.pl-00000001 is circuit-busy
== Everyone is busy/congested at this time (1:0/1/0)

so I need to request VOIP operator to authenticate invite any number to any number ?
am I wrong here?

my sip.conf:

[code][general]
context=default ; Default context for incoming calls
allowoverlap=no ; Disable overlap dialing support. (Default is yes)
udpbindaddr=0.0.0.0
tcpenable=no
tcpbindaddr=0.0.0.0
transport=udp
srvlookup=yes

bindport=5172
register=>myid:mypass@sip.extravoip.pl/comming

[authentication]

[extravoip]
type=peer
fromuser=***
username=***
secret=***
fromdomain=sip.extravoip.pl
context=extravoip
host=sip.extravoip.pl
port=5060
outboundproxy=sip.extravoip.pl
outboundproxyport=5060
insecure=invite
canreinvite=no
dtmfmode=rfc2833
nat=no
disallow=all
allow=alaw
allow=h263p
allow=ulaw
allow=g729
rtptimeout=60
dtmfmode=RFC2833

basic-options ; a template
dtmfmode=rfc2833
context=from-office
type=friend

natted-phone ; another template inheriting basic-options
directmedia=no
host=dynamic

public-phone ; another template inheriting basic-options
directmedia=yes

my-codecs ; a template for my preferred codecs
disallow=all
allow=ilbc
allow=g729
allow=gsm
allow=g723
allow=ulaw

ulaw-phone ; and another one for ulaw-only
disallow=all
allow=ulaw
[/code]

SIP/extravoip/${fwdnumber})

there is exactly what I did in try2:
exten => przychodzace,n,Dial(SIP/extravoip.pl/${fwdnumber})

full log of call with SIP headers:
log replacements:
400500600 is caller number
700800900 is number forwarded to.
and ip as my_very_normal_ip

<--- SIP read from UDP:80.72.37.28:5060 --->
INVITE sip:przychodzace2@my_very_normal_ip:5060 SIP/2.0
Record-Route: <sip:80.72.37.28:5060;lr;ftag=e96876b50aae3795126f69319e2879c1>
Via: SIP/2.0/UDP 80.72.37.28:5060;branch=z9hG4bK5383.1eb672d5.0
Via: SIP/2.0/UDP 80.72.35.106:5061;received=80.72.35.106;branch=z9hG4bKe6351dbf98fcc16d504cffed124c627c;rport=5061
Max-Forwards: 69
From: 400500600 <sip:400500600@80.72.35.106>;tag=e96876b50aae3795126f69319e2879c1
To: <sip:extravoip_717528_2@80.72.37.28>
Call-ID: Y2JjMGQzMTkxYTEzMjg4NjI3NjM3ZTBlMGJkNmY4MWQ.-b2b_1
CSeq: 200 INVITE
Contact: Anonymous <sip:400500600@80.72.35.106:5061>
Expires: 300
User-Agent: NetCentrica B2BUA (S2)
X-dialed-number: 222478023
Content-Type: application/sdp
Content-Length: 318

v=0
o=- 1407375013465 1407375013465 IN IP4 80.72.35.106
s=Z
c=IN IP4 80.72.35.106
t=0 0
m=audio 55724 RTP/AVP 3 98 8 0 101
a=rtpmap:3 GSM/8000
a=rtpmap:98 iLBC/8000
a=fmtp:98 mode=30
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=sendrecv
a=nortpproxy:yes
<------------->
--- (15 headers 15 lines) ---
Sending to 80.72.37.28:5060 (NAT)
Using INVITE request as basis request - Y2JjMGQzMTkxYTEzMjg4NjI3NjM3ZTBlMGJkNmY4MWQ.-b2b_1
Found peer 'extravoip1' for '400500600' from 80.72.37.28:5060
  == Using SIP RTP CoS mark 5
Found RTP audio format 3
Found RTP audio format 98
Found RTP audio format 8
Found RTP audio format 0
Found RTP audio format 101
Found audio description format GSM for ID 3
Found audio description format iLBC for ID 98
Found audio description format PCMA for ID 8
Found audio description format PCMU for ID 0
Found audio description format telephone-event for ID 101
Capabilities: us - 0x10010c (ulaw|alaw|g729|h263p), peer - audio=0x40e (gsm|ulaw|alaw|ilbc)/video=0x0 (nothing)/text=0x0 (nothing), combined - 0xc (ulaw|alaw)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
Peer audio RTP is at port 80.72.35.106:55724
Looking for przychodzace2 in extravoip1 (domain my_very_normal_ip)
list_route: hop: <sip:80.72.37.28:5060;lr;ftag=e96876b50aae3795126f69319e2879c1>

<--- Transmitting (no NAT) to 80.72.37.28:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 80.72.37.28:5060;branch=z9hG4bK5383.1eb672d5.0;received=80.72.37.28
Via: SIP/2.0/UDP 80.72.35.106:5061;received=80.72.35.106;branch=z9hG4bKe6351dbf98fcc16d504cffed124c627c;rport=5061
Record-Route: <sip:80.72.37.28:5060;lr;ftag=e96876b50aae3795126f69319e2879c1>
From: 400500600 <sip:400500600@80.72.35.106>;tag=e96876b50aae3795126f69319e2879c1
To: <sip:extravoip_717528_2@80.72.37.28>
Call-ID: Y2JjMGQzMTkxYTEzMjg4NjI3NjM3ZTBlMGJkNmY4MWQ.-b2b_1
CSeq: 200 INVITE
Server: Asterisk PBX SVN-branch-1.8-r418504
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:przychodzace2@my_very_normal_ip:5060>
Content-Length: 0
<------------>
    -- Executing [przychodzace2@extravoip1:1] Ringing("SIP/extravoip1-00000000", "") in new stack

<--- Transmitting (no NAT) to 80.72.37.28:5060 --->
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 80.72.37.28:5060;branch=z9hG4bK5383.1eb672d5.0;received=80.72.37.28
Via: SIP/2.0/UDP 80.72.35.106:5061;received=80.72.35.106;branch=z9hG4bKe6351dbf98fcc16d504cffed124c627c;rport=5061
Record-Route: <sip:80.72.37.28:5060;lr;ftag=e96876b50aae3795126f69319e2879c1>
From: 400500600 <sip:400500600@80.72.35.106>;tag=e96876b50aae3795126f69319e2879c1
To: <sip:extravoip_717528_2@80.72.37.28>;tag=as758822aa
Call-ID: Y2JjMGQzMTkxYTEzMjg4NjI3NjM3ZTBlMGJkNmY4MWQ.-b2b_1
CSeq: 200 INVITE
Server: Asterisk PBX SVN-branch-1.8-r418504
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:przychodzace2@my_very_normal_ip:5060>
Content-Length: 0


<------------>
    -- Executing [przychodzace2@extravoip1:2] Wait("SIP/extravoip1-00000000", "1") in new stack
    -- Executing [przychodzace2@extravoip1:3] Answer("SIP/extravoip1-00000000", "") in new stack
Audio is at 19726
Adding codec 0x8 (alaw) to SDP
Adding codec 0x4 (ulaw) to SDP
Adding non-codec 0x1 (telephone-event) to SDP

<--- Reliably Transmitting (no NAT) to 80.72.37.28:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 80.72.37.28:5060;branch=z9hG4bK5383.1eb672d5.0;received=80.72.37.28
Via: SIP/2.0/UDP 80.72.35.106:5061;received=80.72.35.106;branch=z9hG4bKe6351dbf98fcc16d504cffed124c627c;rport=5061
Record-Route: <sip:80.72.37.28:5060;lr;ftag=e96876b50aae3795126f69319e2879c1>
From: 400500600 <sip:400500600@80.72.35.106>;tag=e96876b50aae3795126f69319e2879c1
To: <sip:extravoip_717528_2@80.72.37.28>;tag=as758822aa
Call-ID: Y2JjMGQzMTkxYTEzMjg4NjI3NjM3ZTBlMGJkNmY4MWQ.-b2b_1
CSeq: 200 INVITE
Server: Asterisk PBX SVN-branch-1.8-r418504
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:przychodzace2@my_very_normal_ip:5060>
Content-Type: application/sdp
Content-Length: 277

v=0
o=root 1417658442 1417658442 IN IP4 my_very_normal_ip
s=Asterisk PBX SVN-branch-1.8-r418504
c=IN IP4 my_very_normal_ip
t=0 0
m=audio 19726 RTP/AVP 8 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv

<------------>

<--- SIP read from UDP:80.72.37.28:5060 --->
ACK sip:przychodzace2@my_very_normal_ip:5060 SIP/2.0
Via: SIP/2.0/UDP 80.72.37.28:5060;branch=z9hG4bK5383.1eb672d5.2
Via: SIP/2.0/UDP 80.72.35.106:5061;received=80.72.35.106;rport=5061;branch=z9hG4bKa6895dd71eaf0f2f2f05950c6bd1c11c
Max-Forwards: 69
From: 400500600 <sip:400500600@80.72.35.106>;tag=e96876b50aae3795126f69319e2879c1
To: <sip:extravoip_717528_2@80.72.37.28>;tag=as758822aa
Call-ID: Y2JjMGQzMTkxYTEzMjg4NjI3NjM3ZTBlMGJkNmY4MWQ.-b2b_1
CSeq: 200 ACK
User-Agent: NetCentrica B2BUA (S2)
Content-Length: 0

<------------->
--- (10 headers 0 lines) ---
    -- Executing [przychodzace2@extravoip1:4] Set("SIP/extravoip1-00000000", "fwdnumber=700800900") in new stack
    -- Executing [przychodzace2@extravoip1:5] Dial("SIP/extravoip1-00000000", "SIP/sip.extravoip.pl/700800900") in new stack
  == Using SIP RTP CoS mark 5
Audio is at 11906
Adding codec 0x8 (alaw) to SDP
Adding codec 0x2 (gsm) to SDP
Adding codec 0x4 (ulaw) to SDP
Adding codec 0x800000000000 (testlaw) to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (NAT) to 80.72.37.28:5060:
INVITE sip:700800900@sip.extravoip.pl SIP/2.0
Via: SIP/2.0/UDP my_very_normal_ip:5060;branch=z9hG4bK5d71140c;rport
Max-Forwards: 70
From: "400500600" <sip:400500600@my_very_normal_ip>;tag=as1fb9d0ee
To: <sip:700800900@sip.extravoip.pl>
Contact: <sip:400500600@my_very_normal_ip:5060>
Call-ID: 6400b7c2597849b361bfda5023d28e64@my_very_normal_ip:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX SVN-branch-1.8-r418504
Date: Thu, 07 Aug 2014 04:44:56 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 298

v=0
o=root 256154652 256154652 IN IP4 my_very_normal_ip
s=Asterisk PBX SVN-branch-1.8-r418504
c=IN IP4 my_very_normal_ip
t=0 0
m=audio 11906 RTP/AVP 8 3 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv

---
    -- Called SIP/sip.extravoip.pl/700800900

<--- SIP read from UDP:80.72.37.28:5060 --->
SIP/2.0 100 Giving a try
Via: SIP/2.0/UDP my_very_normal_ip:5060;received=my_very_normal_ip;branch=z9hG4bK5d71140c;rport=5060
From: "400500600" <sip:400500600@my_very_normal_ip>;tag=as1fb9d0ee
To: <sip:700800900@sip.extravoip.pl>
Call-ID: 6400b7c2597849b361bfda5023d28e64@my_very_normal_ip:5060
CSeq: 102 INVITE
Server: NetCentrica SIP LB
Content-Length: 0
Warning: 392 80.72.37.28:5060 "Noisy feedback tells: pid=20978 req_src_ip=my_very_normal_ip req_src_port=5060 in_uri=sip:700800900@sip.extravoip.pl out_uri=sip:700800900@sip.extravoip.pl via_cnt==1"

<------------->
--- (9 headers 0 lines) ---

<--- SIP read from UDP:80.72.37.28:5060 --->
SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP my_very_normal_ip:5060;received=my_very_normal_ip;branch=z9hG4bK5d71140c;rport=5060
From: "400500600" <sip:400500600@my_very_normal_ip>;tag=as1fb9d0ee
To: <sip:700800900@sip.extravoip.pl>;tag=d0b580866bbefc48e8393552524e82ac.91b4
Call-ID: 6400b7c2597849b361bfda5023d28e64@my_very_normal_ip:5060
CSeq: 102 INVITE
Proxy-Authenticate: Digest realm="my_very_normal_ip", nonce="53e30567000020404d1db1a89a4e7b8bf62abddf68cf3cb0"
Server: NetCentrica SIP Proxy (S.1)
Content-Length: 0

------------->
--- (9 headers 0 lines) ---
Transmitting (NAT) to 80.72.37.28:5060:
ACK sip:700800900@sip.extravoip.pl SIP/2.0
Via: SIP/2.0/UDP my_very_normal_ip:5060;branch=z9hG4bK5d71140c;rport
Max-Forwards: 70
From: "400500600" <sip:400500600@my_very_normal_ip>;tag=as1fb9d0ee
To: <sip:700800900@sip.extravoip.pl>;tag=d0b580866bbefc48e8393552524e82ac.91b4
Contact: <sip:400500600@my_very_normal_ip:5060>
Call-ID: 6400b7c2597849b361bfda5023d28e64@my_very_normal_ip:5060
CSeq: 102 ACK
User-Agent: Asterisk PBX SVN-branch-1.8-r418504
Content-Length: 0


---
[Aug  7 00:44:56] NOTICE[18712]: chan_sip.c:21196 handle_response_invite: Failed to authenticate on INVITE to '"400500600" <sip:400500600@my_very_normal_ip>;tag=as1fb9d0ee'
    -- SIP/sip.extravoip.pl-00000001 is circuit-busy
  == Everyone is busy/congested at this time (1:0/1/0)
    -- Executing [przychodzace2@extravoip1:6] While("SIP/extravoip1-00000000", "1") in new stack
....


my asterisk use public ip, all works fine except this forward.
what does it mean?
SIP operator do not authenticate caller number
or asterisk configuration do not allow this - do sth wrong (should I change authentication settings in sip.conf)?

for my:

I received from SIP trunk:

this is just warning, but asterisk then say:

[Aug 7 00:44:56] NOTICE[18712]: chan_sip.c:21196 handle_response_invite: Failed to authenticate on INVITE to '"177110440" <sip:177110440@my_very_normal_ip>;tag=as1fb9d0ee' -- SIP/sip.extravoip.pl-00000001 is circuit-busy Everyone is busy/congested at this time (1:0/1/0)

my effort3:
when I set

insecure=very permit=80.72.37.28/32

my asterisk will send at first request:
401 Unauthorized

more open mask do the same.


why Dial() send SIP header with different CALL-ID - is it ok while forwarding ?
callid until dial forward (set by SIP trunk operator):
Call-ID: Y2JjMGQzMTkxYTEzMjg4NjI3NjM3ZTBlMGJkNmY4MWQ.-b2b_1
callid set by my asterisk when hit Dial command:
Call-ID: 6400b7c2597849b361bfda5023d28e64@my_very_normal_ip:5060

I want forward call, not new call.

It has asked for proxy authentication and Asterisk has none to supply. Whilst I thought it would fall back to using the peer authentication, it would do no harm to provide it explicitly.

Please read up on the insecure parameter. It is not one that you should be using blind. In particular very is deprecated. In any case, it only applies to inbound calls.

the solution was add to sip.conf in [authentication]
auth=username:password@realm
insecure:port,invite

now asterisk add Proxy-Authorization header itself.

there is another problem with this forwarding.
using:
SIP/extravoip/${fwdnumber})
set new call and current registered user in asterisk will paid.

  1. how to forward in way that caller will paid (initial caller from inbound call)?
    and
  2. how to forward in way that callee will paid?

I assume what you are hoping for is the caller is going to pick up the cost of you diverting to another number… For many reasons that isnt going to happen.
If you forward the call you pay the cost.

yes, but i am interested only with technical reasons (caller will accept it explicite).
charging start after ANSWEAR and last until HANGUP and is bind with some call id I guess.
so it should be possible.

so how to redirect/transfer/forward call to external number in SIP without getting costs (caller pay).

// there is continuation of my topic with just another account.

Ok

so the caller will have an account with you and you just bu=ill them fro the leg of the call thats forwarded and offset this cost against the cost you pay for that leg of the call.

or the caller has a account with the supplier and the outbound leg uses their account not yours.

If you expecting teh ITSP to let you place calls FOC you may have a few issues convincing them that they call will pay…

caller could be any phone number in the world.
in some cases I want redirect call to consultant (could be another any phone number - external number to spec consultant),
but caller must keep paying (he is paying when calling to me, he will pay for redirect to consultant)
my number is VOIP (handled by asterisk), all works with SIP.

This used to be possible with revenue sharing numbers, but as i said you will be lucky to find aan itsp who will do this.
think about it

caller—>(their PTO billing them)---->your system------>(your PTO Billing them) ---->your consultant

you will have to get your pto to talk to theirs…

This may have been possible with a re-direct but only really at a CO level.