Conditional Call connect based on SIP180 and SIP200

Hi. I’ve trying for a month by now to write a dial plan that Receives call from A Party and sends it to B-Party, but the SIP 200 should be forwarded conditionally from B-Party to A , based on the time difference between the SIP 180 and SIP 200 received from the B- Party.

Below is the Extensions.conf context.
Calls arrive from 10.10.1.5 (A-Party)—> (Asterisk- 10.10.1.11)—> 10.10.1.1 ( B-Party)
[public]
exten => _0.,1,Dial(SIP/10.10.1.1/${EXTEN},M(macro-track-time))

[macro-macro-track-time]
exten => s,1,NoOp(Answering the call)
same => n,Set(__START_TIME=${STRFTIME(${EPOCH},%Y%m%d%H%M%S)})
same => n,Verbose(START_TIME set to: ${__START_TIME})
same => n,Answer()
same => n,Wait(1)
same => n,Verbose(SIP 200 OK response received)
same => n,Set(__SIP_200_TIME=STRFTIME(${EPOCH},%Y%m%d%H%M%S)})
same => n,Verbose(SIP 200 OK response time set to: ${__SIP_200_TIME})
same => n,Macro(check-difference,s,1)
same => n,NoOp(Continuing with the call)

[macro-check-difference]
exten => s,1,Set(__DIFFERENCE=${DIFF(${__SIP_200_TIME},${__START_TIME})})
same => n,NoOp(Difference value before calculation: ${__DIFFERENCE})
same => n,Verbose(Difference between START_TIME and SIP_200_TIME: ${__DIFFERENCE} seconds)
same => n,GotoIf($[${__DIFFERENCE}=0]?hangup)
same => n,Return()

exten => s,n(hangup),Hangup()

[sip-messages]
exten => _.,1,NoOp(SIP message received)
same => n,GotoIf($[“${MESSAGE}”=“SIP/2.0 200 OK”]?hangup:)

exten => hangup,1,NoOp(Hanging up)
same => n,Hangup()

  1. You haven’t actually asked a question here - you’ve simply told us what
    you’re trying to do. What is the problem?

  2. What do you mean by “conditionally … based on …”? Please explain how
    the time between SIP 180 and SIP 200 should affect the forwarding of the SIP
    200 to A.

  3. Why are you doing this? What are you actually trying to achieve / what
    real-world problem are you trying to solve by doing this?

  4. I notice you’re still using chan_sip, which means some people are likely to
    say “upgrade to chan_pjsip” since that is already deprecated, and removed
    altogether in Asterisk 21.

  5. Which version of Asterisk are you using?

Antony.

+1

I also notice you are using macros. which are also deprecated. I’m not sure if they are scheduled for removal in 21.

Answer has no effect on an outgoing leg!

I gave up before really understanding this, but _ variable prefixes only apply when a channel is created by the channel with the variable, but I didn’t notice the outgoing leg creating a channel, and the outgoing leg, itself has already passed that point with respect to the incoming leg.

Asterisk is not structured as a SIP PABX (it’s based on ISDN), and the nearest translation of this is AST_CONTROL_RINGING and AST_CONTROL_ANSWER.

  1. You haven’t actually asked a question here - you’ve simply told us what
    you’re trying to do. What is the problem?

  2. What do you mean by “conditionally … based on …”? Please explain
    how the time between SIP 180 and SIP 200 should affect the forwarding of
    the SIP 200 to A.

  3. Why are you doing this? What are you actually trying to achieve / what
    real-world problem are you trying to solve by doing this?

  4. I notice you’re still using chan_sip, which means some people are likely
    to say “upgrade to chan_pjsip” since that is already deprecated, and
    removed altogether in Asterisk 21.

Clarification: chan_sip is deprecated…

  1. Which version of Asterisk are you using?

Oh, I also forgot to ask:

  1. Why do you have a Wait(1) in the middle of a context which is attempting to
    eastablish the timing difference between two external events? What happens if
    the second event occurs in under 1 second after the first event? Why do you
    have a Wait(1) in there at all?

Antony.

Sorry if i mis-stated the case. I’ve a VOIP route with a fake IVR problem from the operator core and they are not able to solve it. If u call a switched off mobile , you get a correct (Early media IVR with SIP 183) , then 2nd IVR , with immediate consecutive SIP 180 and S200 with a difference less than 1 sec. Thus i want to use this behavior to end the calls (hangup) that have immediate sip 200 after sip 180 to avoid FALSE ANSWER. I hope this explains the case. So far i couldn’t find the correct way to do it on asterisk. Any help is highly appreciated. I’ve several version of asterisk installed on different VMs, so i can try on any version needed. Starting from ver 11 to ver 20

It would have to be done using an API, either AMI, manipulating the Dial, or ARI replacing it. AST_CONTROL_RINGING is not made available to the dialplan, which will executing within app_dial at the time.

The only thing that app_dial does with AST_CONTROL_RINGING is to repeat it, and then only if certain conditions are met (single, i.e. only one outgoing leg is being tried, and not-entertained, i.e. it hasn’t been asked to play ring back or music on hold, in band).

Thank you all for you help.
Using AMI , We could solve the problem by monitoring the sip messages thru an external java script that sends hangup once the above required conditions are met.