Asterisk can not detect hangup

i want to make a call from asterisk using calling card with out any calling card voice prompt.
i have used the following context for dialing out.

[from-internal-custom]
exten => _1XXXXXXXXXX,1,Dial(SIP/trunkname/1800xxxxxxx,M(sendccdigits))

[macro-sendccdigits]
exten => s,1,Wait(1) ; wait 1 second
exten => s,n,SendDTMF(xxxxx); send the PIN
exten => s,n,Wait(1) ; wait 4 seconds for the time remaining on card
exten => s,n,SendDTMF(1xxxxxxxxxx); send the number
exten => s,n,Wait(34)

The above context is working fine.but there is one problem that is the Asterisk can not detect hangup. For example, If I call from SIP phone as leg 1, and then select calling card to dial out to a different phone number as leg 2, after finising the conversation, 2 leg hang up, Asterisk does not detect the leg 2 remote has hung up and still keeps the line off-hook. Now, I am able to hear the calling card ivr voice prompt.i can’t get no response from calling card provider.i want to hang up the 1st leg call immediately when 2 leg is hang up