Asterisk hangup code: Difference between revisions

From 탱이의 잡동사니
Jump to navigation Jump to search
Line 130: Line 130:
Asterisk 내부적으로 사용되는 SIP -> Hangup code 맵핑.
Asterisk 내부적으로 사용되는 SIP -> Hangup code 맵핑.


<syntaxhighlight lang=c>
<pre>
// channels/chan_pjsip.c
// channels/chan_pjsip.c


Line 223: Line 223:
return 0;
return 0;
}
}
</syntaxhighlight>
</pre>


== Retry ==
== Retry ==

Revision as of 04:58, 31 January 2023

Overview

Asterisk hangup code 내용 정리.

Basic

Hangup cause 코드 정리. Asterisk 는 Hangup code로 ITU-T Q.931 을 준수한다. Q.931과 SIP 코드와 매핑을 하기위해서는 RFC 3398 을 참조하면 된다.

/*! \name Causes for disconnection (from Q.850/Q.931)
 *  These are the internal cause codes used in Asterisk.
 *  \ref AstCauses
 */
/*@{ */
#define AST_CAUSE_UNALLOCATED                    1
#define AST_CAUSE_NO_ROUTE_TRANSIT_NET           2
#define AST_CAUSE_NO_ROUTE_DESTINATION           3
#define AST_CAUSE_MISDIALLED_TRUNK_PREFIX        5
#define AST_CAUSE_CHANNEL_UNACCEPTABLE           6
#define AST_CAUSE_CALL_AWARDED_DELIVERED         7
#define AST_CAUSE_PRE_EMPTED                     8
#define AST_CAUSE_NUMBER_PORTED_NOT_HERE        14
#define AST_CAUSE_NORMAL_CLEARING               16
#define AST_CAUSE_USER_BUSY                     17
#define AST_CAUSE_NO_USER_RESPONSE              18
#define AST_CAUSE_NO_ANSWER                     19
#define AST_CAUSE_SUBSCRIBER_ABSENT             20
#define AST_CAUSE_CALL_REJECTED                 21
#define AST_CAUSE_NUMBER_CHANGED                22
#define AST_CAUSE_REDIRECTED_TO_NEW_DESTINATION 23
#define AST_CAUSE_ANSWERED_ELSEWHERE            26
#define AST_CAUSE_DESTINATION_OUT_OF_ORDER      27
#define AST_CAUSE_INVALID_NUMBER_FORMAT         28
#define AST_CAUSE_FACILITY_REJECTED             29
#define AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY    30
#define AST_CAUSE_NORMAL_UNSPECIFIED            31
#define AST_CAUSE_NORMAL_CIRCUIT_CONGESTION     34
#define AST_CAUSE_NETWORK_OUT_OF_ORDER          38
#define AST_CAUSE_NORMAL_TEMPORARY_FAILURE      41
#define AST_CAUSE_SWITCH_CONGESTION             42
#define AST_CAUSE_ACCESS_INFO_DISCARDED         43
#define AST_CAUSE_REQUESTED_CHAN_UNAVAIL        44
#define AST_CAUSE_FACILITY_NOT_SUBSCRIBED       50
#define AST_CAUSE_OUTGOING_CALL_BARRED          52
#define AST_CAUSE_INCOMING_CALL_BARRED          54
#define AST_CAUSE_BEARERCAPABILITY_NOTAUTH      57
#define AST_CAUSE_BEARERCAPABILITY_NOTAVAIL     58
#define AST_CAUSE_BEARERCAPABILITY_NOTIMPL      65
#define AST_CAUSE_CHAN_NOT_IMPLEMENTED          66
#define AST_CAUSE_FACILITY_NOT_IMPLEMENTED      69
#define AST_CAUSE_INVALID_CALL_REFERENCE        81
#define AST_CAUSE_INCOMPATIBLE_DESTINATION      88
#define AST_CAUSE_INVALID_MSG_UNSPECIFIED       95
#define AST_CAUSE_MANDATORY_IE_MISSING          96
#define AST_CAUSE_MESSAGE_TYPE_NONEXIST         97
#define AST_CAUSE_WRONG_MESSAGE                 98
#define AST_CAUSE_IE_NONEXIST                   99
#define AST_CAUSE_INVALID_IE_CONTENTS          100
#define AST_CAUSE_WRONG_CALL_STATE             101
#define AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE     102
#define AST_CAUSE_MANDATORY_IE_LENGTH_ERROR    103
#define AST_CAUSE_PROTOCOL_ERROR               111
#define AST_CAUSE_INTERWORKING                 127

/* Special Asterisk aliases */
#define AST_CAUSE_BUSY          AST_CAUSE_USER_BUSY
#define AST_CAUSE_FAILURE       AST_CAUSE_NETWORK_OUT_OF_ORDER
#define AST_CAUSE_NORMAL        AST_CAUSE_NORMAL_CLEARING
#define AST_CAUSE_NOANSWER      AST_CAUSE_NO_ANSWER
#define AST_CAUSE_CONGESTION    AST_CAUSE_NORMAL_CIRCUIT_CONGESTION
#define AST_CAUSE_UNREGISTERED  AST_CAUSE_SUBSCRIBER_ABSENT
#define AST_CAUSE_NOTDEFINED    0
#define AST_CAUSE_NOSUCHDRIVER  AST_CAUSE_CHAN_NOT_IMPLEMENTED

Hangup code with SIP

Hangup code to SIP

Asterisk 내부적으로 사용되는 Hangup cause code -> SIP code.

<syntaxhighlight lang=c> // channels/chan_pjsip.c

/*! \brief Internal function which translates from Asterisk cause codes to SIP response codes */ static int hangup_cause2sip(int cause) { switch (cause) { case AST_CAUSE_UNALLOCATED: /* 1 */ case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */ case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */ return 404; case AST_CAUSE_CONGESTION: /* 34 */ case AST_CAUSE_SWITCH_CONGESTION: /* 42 */ return 503; case AST_CAUSE_NO_USER_RESPONSE: /* 18 */ return 408; case AST_CAUSE_NO_ANSWER: /* 19 */ case AST_CAUSE_UNREGISTERED: /* 20 */ return 480; case AST_CAUSE_CALL_REJECTED: /* 21 */ return 403; case AST_CAUSE_NUMBER_CHANGED: /* 22 */ return 410; case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */ return 480; case AST_CAUSE_INVALID_NUMBER_FORMAT: return 484; case AST_CAUSE_USER_BUSY: return 486; case AST_CAUSE_FAILURE: return 500; case AST_CAUSE_FACILITY_REJECTED: /* 29 */ return 501; case AST_CAUSE_CHAN_NOT_IMPLEMENTED: return 503; case AST_CAUSE_DESTINATION_OUT_OF_ORDER: return 502; case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */ return 488; case AST_CAUSE_INTERWORKING: /* Unspecified Interworking issues */ return 500; case AST_CAUSE_NOTDEFINED: default: ast_debug(1, "AST hangup cause %d (no match found in PJSIP)\n", cause); return 0; }

/* Never reached */ return 0; } </syntaxhighlight>

SIP to Hangup code

Asterisk 내부적으로 사용되는 SIP -> Hangup code 맵핑.

// channels/chan_pjsip.c

/*! \brief Convert SIP hangup causes to Asterisk hangup causes */
static int hangup_sip2cause(int cause)
{
	/* Possible values taken from causes.h */

	switch(cause) {
	case 401:       /* Unauthorized */
		return AST_CAUSE_CALL_REJECTED;
	case 403:       /* Not found */
		return AST_CAUSE_CALL_REJECTED;
	case 404:       /* Not found */
		return AST_CAUSE_UNALLOCATED;
	case 405:       /* Method not allowed */
		return AST_CAUSE_INTERWORKING;
	case 407:       /* Proxy authentication required */
		return AST_CAUSE_CALL_REJECTED;
	case 408:       /* No reaction */
		return AST_CAUSE_NO_USER_RESPONSE;
	case 409:       /* Conflict */
		return AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
	case 410:       /* Gone */
		return AST_CAUSE_NUMBER_CHANGED;
	case 411:       /* Length required */
		return AST_CAUSE_INTERWORKING;
	case 413:       /* Request entity too large */
		return AST_CAUSE_INTERWORKING;
	case 414:       /* Request URI too large */
		return AST_CAUSE_INTERWORKING;
	case 415:       /* Unsupported media type */
		return AST_CAUSE_INTERWORKING;
	case 420:       /* Bad extension */
		return AST_CAUSE_NO_ROUTE_DESTINATION;
	case 480:       /* No answer */
		return AST_CAUSE_NO_ANSWER;
	case 481:       /* No answer */
		return AST_CAUSE_INTERWORKING;
	case 482:       /* Loop detected */
		return AST_CAUSE_INTERWORKING;
	case 483:       /* Too many hops */
		return AST_CAUSE_NO_ANSWER;
	case 484:       /* Address incomplete */
		return AST_CAUSE_INVALID_NUMBER_FORMAT;
	case 485:       /* Ambiguous */
		return AST_CAUSE_UNALLOCATED;
	case 486:       /* Busy everywhere */
		return AST_CAUSE_BUSY;
	case 487:       /* Request terminated */
		return AST_CAUSE_INTERWORKING;
	case 488:       /* No codecs approved */
		return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
	case 491:       /* Request pending */
		return AST_CAUSE_INTERWORKING;
	case 493:       /* Undecipherable */
		return AST_CAUSE_INTERWORKING;
	case 500:       /* Server internal failure */
		return AST_CAUSE_FAILURE;
	case 501:       /* Call rejected */
		return AST_CAUSE_FACILITY_REJECTED;
	case 502:
		return AST_CAUSE_DESTINATION_OUT_OF_ORDER;
	case 503:       /* Service unavailable */
		return AST_CAUSE_CONGESTION;
	case 504:       /* Gateway timeout */
		return AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE;
	case 505:       /* SIP version not supported */
		return AST_CAUSE_INTERWORKING;
	case 600:       /* Busy everywhere */
		return AST_CAUSE_USER_BUSY;
	case 603:       /* Decline */
		return AST_CAUSE_CALL_REJECTED;
	case 604:       /* Does not exist anywhere */
		return AST_CAUSE_UNALLOCATED;
	case 606:       /* Not acceptable */
		return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
	default:
		if (cause < 500 && cause >= 400) {
			/* 4xx class error that is unknown - someting wrong with our request */
			return AST_CAUSE_INTERWORKING;
		} else if (cause < 600 && cause >= 500) {
			/* 5xx class error - problem in the remote end */
			return AST_CAUSE_CONGESTION;
		} else if (cause < 700 && cause >= 600) {
			/* 6xx - global errors in the 4xx class */
			return AST_CAUSE_INTERWORKING;
		}
		return AST_CAUSE_NORMAL;
	}
	/* Never reached */
	return 0;
}

Retry

Dialing 시도가 실패할 경우, 리턴 코드에 맞춰 재시도를 해야 할 경우가 있다. 임의로 만든 Retry table. 아직은 사용하지 말 것.

Name                                  Asterisk code   SIP code               Retry    Note
AST_CAUSE_NOT_DEFINED                    0                                   O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_UNALLOCATED                    1            404, 485, 604          O        Provider error. Retry it with another provider.
AST_CAUSE_NO_ROUTE_TRANSIT_NET           2                                   O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_NO_ROUTE_DESTINATION           3            420                    O        Provider error. Retry it with another provider.
AST_CAUSE_MISDIALLED_TRUNK_PREFIX        5                                   O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_CHANNEL_UNACCEPTABLE           6                                   O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_CALL_AWARDED_DELIVERED         7                                   O        This is happen if the channel was transferred to the wrong channel.
AST_CAUSE_PRE_EMPTED                     8                                   O        Provider error. Retry it with another provider.
AST_CAUSE_NUMBER_PORTED_NOT_HERE         14                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_NORMAL_CLEARING                16                                  X	
AST_CAUSE_USER_BUSY                      17            486, 600              X	
AST_CAUSE_NO_USER_RESPONSE               18            408                   O        Provider error. Retry it with another provider.
AST_CAUSE_NO_ANSWER                      19            480, 483              X	
AST_CAUSE_SUBSCRIBER_ABSENT              20                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_CALL_REJECTED                  21            401, 403, 407, 603    X	
AST_CAUSE_NUMBER_CHANGED                 22            410                   O        Provider error. Retry it with another provider.
AST_CAUSE_REDIRECTED_TO_NEW_DESTINATION  23                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_ANSWERED_ELSEWHERE             26                                  X
AST_CAUSE_DESTINATION_OUT_OF_ORDER       27            502                   O        Provider error. Retry it with another provider.
AST_CAUSE_INVALID_NUMBER_FORMAT          28            484                   O        Provider error. Retry it with another provider.
AST_CAUSE_FACILITY_REJECTED              29            501                   O        Provider error. Retry it with another provider.
AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY     30                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_NORMAL_UNSPECIFIED             31                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_NORMAL_CIRCUIT_CONGESTION      34                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_NETWORK_OUT_OF_ORDER           38            500                   O        Provider error. Retry it with another provider.
AST_CAUSE_NORMAL_TEMPORARY_FAILURE       41            409                   O        Provider error. Retry it with another provider.
AST_CAUSE_SWITCH_CONGESTION              42            5XX                   O        Provider error. Retry it with another provider.
AST_CAUSE_ACCESS_INFO_DISCARDED          43                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_REQUESTED_CHAN_UNAVAIL         44                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_FACILITY_NOT_SUBSCRIBED        50                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_OUTGOING_CALL_BARRED           52                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_INCOMING_CALL_BARRED           54                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_BEARERCAPABILITY_NOTAUTH       57                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_BEARERCAPABILITY_NOTAVAIL      58            488, 606              O        Provider error. Retry it with another provider.
AST_CAUSE_BEARERCAPABILITY_NOTIMPL       65                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_CHAN_NOT_IMPLEMENTED           66                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_FACILITY_NOT_IMPLEMENTED       69                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_INVALID_CALL_REFERENCE         81                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_INCOMPATIBLE_DESTINATION       88                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_INVALID_MSG_UNSPECIFIED        95                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_MANDATORY_IE_MISSING           96                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_MESSAGE_TYPE_NONEXIST          97                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_WRONG_MESSAGE                  98                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_IE_NONEXIST                    99                                  O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_INVALID_IE_CONTENTS            100                                 O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_WRONG_CALL_STATE               101                                 O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE       102           504                   O        Provider error. Retry it with another provider.
AST_CAUSE_PROTOCOL_ERROR                 111                                 O        Asterisk internal error. Retry it with another Asterisk.
AST_CAUSE_INTERWORKING                   127           4xx, 505, 6xx         O        Provider error. Retry it with another provider.

See also