[asterisk-users] OriginateEvent reason codes.

Moises Silva moises.silva at gmail.com
Fri Oct 13 07:20:55 MST 2006


Jan. Unfortunately, Originate is somehow a mess. Answering your
question, the "reason" is not really a reason, at least not in release
1.2.12.1, that is the one im using. The reason is set according to the
last communication frame read from the originated channel. Let me
explain. When you originate a channel, asterisk starts creating the
internal C structure, and then trying to reach the peer. So, one first
common control frame received from our originated channel is
AST_CONTROL_RING, defined in include/asterisk/frame.h with a value of
2. If originate terminated in that very moment, the reason would be 2.
But in your scenario, when the callee does not pick up, the channel is
hangup, so the control frame AST_CONTROL_HANGUP is the last frame
read, and YES, is defined with a value of 1, the 1 you always receive.
The 4 you receive is defined as AST_CONTROL_ANSWER, because that was
the last control frame received once the call was answered and the
event OriginateSuccess sent. In my personal experience I have the
following code working good enough to handle async originate
responses, it has some comments so you can see what other reasons im
using:

        /* Asterisk Control frames are returned to us as "Reason" see:
include/asterisk/frame.h for more AST_CONTROL constants
         * some of them are unlikely to happen, or just not possible
         * Cause 0 .... Unknown ( Unreachable ( not registered,
channel does not exists, channel type unknown etc ) )
         * Cause 1 .... HANGUP ( the originated channel was hanged up )
         * It seems cause 1 es generated when soft hangup is requested
on the ringing channel, or even when the channel
         * has not ringed at all ( ie. the SIP peer exists, but has
not UNREACHABLE status yet ).
         * So we need to check out if was ever answered. If so, we
ignore it, otherwise, we report Unavailable
         * Cause 5 ( BUSY )
         * Cause 8 ( CONGESTION ) as cause 0, Unavailable
         * */
        if ( 0 == $EventData['Reason'] || 8 == $EventData['Reason'] )
        {
            $channel->SetState(IPbxChannel::STATE_UNAVAILABLE);
        }
        /* the channel was created but was busy */
        elseif ( 5 == $EventData['Reason'] )
        {
            $channel->SetState(IPbxChannel::STATE_BUSY);
        }
        /* the channel was hanged up, but never ringing, report Unavailable */
        elseif ( 1 == $EventData['Reason'] &&

!$this->expected_originates[$action_id]['channel']->TestFlag(AsteriskChannel::FLAG_EVER_AVAILABLE)
)
        {
            $channel->SetState(IPbxChannel::STATE_UNAVAILABLE);
        }
        unset($this->expected_originates[$action_id]);


I guess you should dive into the C Asterisk code a while before trying
to fill your needs.

By the way, have you ever needed to associate the Newchannel event to
the originate action? how do you make it? I have made a patch to
include the Originate ActionID into the Newchannel event when the
newchannel is product of originate action, but is messy, and I have
not tested it on all channel technologies, and looking for a non-patch
solution.

Regards

On 10/13/06, Jan du Toit <jan.du.toit at decisionworx.com> wrote:
> Hi.
>
> I'm making calls via the Manager OriginateAction. My action is set to be
> async and therefore I receive originiate events. Within the originate
> event that I receive there is a reason code. In the event of failure I
> need to dermine why the call failed (no pickup, rejected, no such
> number, circuit busy, ect) and inform the user with a meaningful
> message. I assume that one is suppose to determine the failure cause by
> interpreting the reason code. But the reason is always 1. If the callee
> does not pickup the reason is 1, if the callee rejects the call the
> reason is 1, if the number does not exist the reason is 1. If the call
> was successful the reason is 4. Is this correct behaviour? Am I doing
> something wrong?
>
> What are all the different reason codes? Where can I find a list that
> explains what all the different codes mean? Are they the same as the
> hangup causes?
> If the reason code is not meant to determine failure causes, how else
> can I determine this?
>
> Thanks. Regards, Jan.
>
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users
>


-- 
"Su nombre es GNU/Linux, no solamente Linux, mas info en http://www.gnu.org"


More information about the asterisk-users mailing list