////////////////////////////////////////////////////////////////////////////////
// Client: attended call transfer, as a transferor (lab scenario)
//
// No counterpart in this directory: it needs a PBX with two other parties (the
// called user and extension 108) and a user that is allowed to transfer. The
// Refer-To address is the variable "target108", set at the top of the
// scenario (192.168.2.182:5060 in the file); change it for your network.
// Call_transfer_server / Call_transfer_client test a blind transfer on their
// own.
//
// It registers (407), calls the first party, puts it on hold with a re-INVITE,
// calls extension 108 and then sends a REFER to the first party with a
// Refer-To that carries a Replaces header for the second call.
//
// Messages with ;retrans are sent again over UDP until they are answered, and a copy
// of one that comes again is answered as before (RFC 3261; -t1, -t2).
//
// SIP Messages
//  ---> REGISTER ... <--- 407 ---> REGISTER (Proxy-Authorization) <--- 200
//  ---> INVITE (first party) <--- 407
//  ---> ACK ---> INVITE (Proxy-Authorization)
//  <--- 180, 200 OK ---> ACK
//  ---> INVITE (re-INVITE: hold) <--- 200 ---> ACK
//  ---> INVITE (extension 108) <--- 407 ---> ACK ---> INVITE (auth)
//  <--- 180, 200 OK ---> ACK
//  ---> REFER ;retrans (to the first party, Refer-To 108 with Replaces)
//  <--- 202
//  <--- NOTIFY ---> 200
//  <--- BYE ---> 200
////////////////////////////////////////////////////////////////////////////////

// Setting: where extension 108 is
----------
set_Variable=target108 "-" "=192.168.2.182:5060"

---------->;retrans
REGISTER sip:[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:[fromUsername]@[remote_ip]:[remote_port]>;tag=24417923471779367133
To: <sip:[fromUsername]@[remote_ip]:[remote_port]>
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq+1] REGISTER
Max-Forwards: 70
Expires: 3600
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Length: [len]


<----------*
407 Proxy Authentication Required

---------->*;retrans
REGISTER sip:[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:[fromUsername]@[remote_ip]:[remote_port]>;tag=24417923471779367133
To: <sip:[fromUsername]@[remote_ip]:[remote_port]>
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq+1] REGISTER
Max-Forwards: 70
Expires: 3600
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Proxy-Authorization: [authentication username=[authUsername]; password=[authPassword];]
Content-Length: [len]


<----------
200 OK 

----------
cmd_Pause=2000

---------->;retrans
INVITE sip:[toUsername]@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=z9hG4bK[run_tag].[call_number]inv1
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=24417923471779367133
To: <sip:[toUsername]@[remote_ip]:[remote_port]>
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq+1] INVITE
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Type: application/sdp
Content-Length: [len]

v=0
o=111 843670094 843670094 IN [IP_ver] [local_ip_sdp]
s=-
c=IN [IP_ver] [local_ip_sdp]
t=0 0
a=sendrecv
m=audio [media_port] RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20

<----------*
100 Trying

<----------;retrans
407 Proxy Authentication Required

---------->
ACK sip:[toUsername]@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=z9hG4bK[run_tag].[call_number]inv1
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=24417923471779367133
To: <sip:[toUsername]@[remote_ip]:[remote_port]>;[peer_tag_param]
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq] ACK
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Length: 0


---------->;retrans
INVITE sip:[toUsername]@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]bcd
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=24417923471779367133
To: <sip:[toUsername]@[remote_ip]:[remote_port]>
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq+1] INVITE
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Proxy-Authorization: [authentication username=[authUsername]; password=[authPassword];]
Content-Type: application/sdp
Content-Length: [len]

v=0
o=111 843670094 843670094 IN [IP_ver] [local_ip_sdp]
s=-
c=IN [IP_ver] [local_ip_sdp]
t=0 0
a=sendrecv
m=audio [media_port] RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20

<----------
180 Ringing 

<----------;retrans
200 OK 

----------
set_Variable=toTag "To:" "tag=*"

----------
set_Variable=fromTag "From:" "tag=*"

----------
set_Variable=callId "Call-ID:" "*"

---------->
ACK sip:[toUsername]@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]def
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=24417923471779367133
To: <sip:[toUsername]@[remote_ip]:[remote_port]>;[peer_tag_param]
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq] ACK
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Length: 0


----------
cmd_Pause=2000

---------->;retrans
INVITE sip:[toUsername]@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]fgh
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=24417923471779367133
To: <sip:[toUsername]@[remote_ip]:[remote_port]>;[peer_tag_param]
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq+1] INVITE
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Type: application/sdp
Content-Length: [len]

v=0
o=MxSIP 0 2092936035 IN [IP_ver] [local_ip_sdp]
s=SIP Call
c=IN [IP_ver] 0.0.0.0
t=0 0
m=audio [media_port] RTP/AVP 8 0 18 101
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=rtpmap:101 telephone-event/8000
a=silenceSupp:off - - - -
a=fmtp:18 annexb=no
a=fmtp:101 0-15
a=inactive

<----------;retrans
200 OK 

---------->
ACK sip:[toUsername]@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]ghi
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=24417923471779367133
To: <sip:[toUsername]@[remote_ip]:[remote_port]>;[peer_tag_param]
Call-ID: [call_number].[run_tag]@[local_ip]
CSeq: [cseq] ACK
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Length: 0


----------
cmd_Pause=4000

---------->;retrans
INVITE sip:108@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=z9hG4bK[run_tag].[call_number]inv3
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=244179234717793671
To: <sip:108@[remote_ip]:[remote_port]>
Call-ID: 108@[local_ip]
CSeq: [cseq+1] INVITE
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Type: application/sdp
Content-Length: [len]

v=0
o=111 843670094 843670094 IN [IP_ver] [local_ip_sdp]
s=-
c=IN [IP_ver] [local_ip_sdp]
t=0 0
a=sendrecv
m=audio [media_port] RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20

<----------*
100 Trying

<----------;retrans
407 Proxy Authentication Required

---------->
ACK sip:108@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=z9hG4bK[run_tag].[call_number]inv3
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=244179234717793671
To: <sip:108@[remote_ip]:[remote_port]>;[peer_tag_param]
Call-ID: 108@[local_ip]
CSeq: [cseq] ACK
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Length: 0


---------->;retrans
INVITE sip:108@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]jkl
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=244179234717793671
To: <sip:108@[remote_ip]:[remote_port]>
Call-ID: 108@[local_ip]
CSeq: [cseq+1] INVITE
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Proxy-Authorization: [authentication username=[authUsername]; password=[authPassword];]
Content-Type: application/sdp
Content-Length: [len]

v=0
o=111 843670094 843670094 IN [IP_ver] [local_ip_sdp]
s=-
c=IN [IP_ver] [local_ip_sdp]
t=0 0
a=sendrecv
m=audio [media_port] RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20

<----------*
100 Trying

<----------
180 Ringing 

----------
set_Variable=to2 "To:" "tag=*"

----------
set_Variable=from2 "From:" "tag=*"

----------
set_Variable=call2 "Call-ID:" "*"

<----------;retrans
200 OK 

---------->
ACK sip:108@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]klm
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=[$from2]
To: <sip:108@[remote_ip]:[remote_port]>;tag=[$to2]
Call-ID: [$call2]
CSeq: [cseq] ACK
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
User-Agent: SIPInspector_v_[ver]
Content-Length: 0


----------
cmd_Pause=10000

---------->;retrans
REFER sip:[toUsername]@[remote_ip]:[remote_port];transport=[transport] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]lmn
From: <sip:[fromUsername]@[local_ip]:[local_port]>;tag=[$fromTag]
To: <sip:[toUsername]@[remote_ip]:[remote_port]>;tag=[$toTag]
Call-ID: [$callId]
CSeq: [cseq+1] REFER
Max-Forwards: 70
Contact: <sip:[fromUsername]@[local_ip]:[local_port];transport=[transport]>
Refer-To: <sip:108@[$target108];transport=[transport]?Replaces=[$call2]%3bto-tag%3d[$to2]%3bfrom-tag%3d[$from2]>
Referred-By: [fromUsername] <sip:[fromUsername]@[local_ip]:[local_port]>
User-Agent: SIPInspector_v_[ver]
Content-Length: 0


<----------
202 OK

<----------;retrans
NOTIFY

---------->
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:]
[last_Call-ID:]
[last_CSeq:]
User-Agent: SIPInspector_v_[ver]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0

<----------;retrans
BYE

---------->
SIP/2.0 200 OK
[last_Via:]
[last_From:]
[last_To:]
[last_Call-ID:]
[last_CSeq:]
User-Agent: SIPInspector_v_[ver]
Contact: <sip:[local_ip]:[local_port];transport=[transport]>
Content-Length: 0

