Index: extensions/app_radgw/rgwx_acct.c
===================================================================
--- extensions/app_radgw/rgwx_acct.c	(revision 703)
+++ extensions/app_radgw/rgwx_acct.c	(revision 705)
@@ -46,5 +46,4 @@
 #define ACV_ART_STOP_RECORD		4	/* STOP_RECORD */
 #define ACV_ART_AUTHORIZE_AUTHENTICATE	3	/* AUTHORIZE_AUTHENTICATE */
-#define ER_DIAMETER_LIMITED_SUCCESS	2002
 
 
Index: extensions/app_radgw/rgwx_auth.c
===================================================================
--- extensions/app_radgw/rgwx_auth.c	(revision 703)
+++ extensions/app_radgw/rgwx_auth.c	(revision 705)
@@ -51,6 +51,4 @@
 #define ACV_ASS_STATE_MAINTAINED	0	/* STATE_MAINTAINED */
 #define ACV_ASS_NO_STATE_MAINTAINED	1	/* NO_STATE_MAINTAINED */
-#define ER_DIAMETER_MULTI_ROUND_AUTH	1001
-#define ER_DIAMETER_LIMITED_SUCCESS	2002
 
 /* The state we keep for this plugin */
@@ -1076,4 +1074,5 @@
 	uint8_t	tuntag = 0;
 	unsigned char * req_auth = NULL;
+	int error_cause = 0;
 	
 	TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli);
@@ -1161,4 +1160,76 @@
 		
 		default:
+			/* Can we convert the value to a natural Error-Cause ? */
+			switch (ahdr->avp_value->u32) {
+				case ER_DIAMETER_AVP_UNSUPPORTED:
+					error_cause = 401; /* Unsupported Attribute */
+					break;
+					
+				case ER_DIAMETER_MISSING_AVP:
+					error_cause = 402; /* Missing Attribute */
+					break;
+					
+				case ER_DIAMETER_UNABLE_TO_COMPLY:
+					error_cause = 404; /* Invalid Request */
+					break;
+					
+				case ER_DIAMETER_APPLICATION_UNSUPPORTED:
+					error_cause = 405; /* Unsupported Service */
+					break;
+					
+				case ER_DIAMETER_COMMAND_UNSUPPORTED:
+					error_cause = 406; /* Unsupported Extension */
+					break;
+					
+				case ER_DIAMETER_INVALID_AVP_VALUE:
+					error_cause = 407; /* Invalid Attribute Value */
+					break;
+					
+				case ER_DIAMETER_AVP_NOT_ALLOWED:
+					error_cause = 501; /* Administratively Prohibited */
+					break;
+					
+				case ER_DIAMETER_REALM_NOT_SERVED:
+				case ER_DIAMETER_LOOP_DETECTED:
+				case ER_DIAMETER_UNKNOWN_PEER:
+				case ER_DIAMETER_UNABLE_TO_DELIVER:
+					error_cause = 502; /* Request Not Routable (Proxy) */
+					break;
+					
+				case ER_DIAMETER_UNKNOWN_SESSION_ID:
+					error_cause = 503; /* Session Context Not Found */
+					break;
+					
+				case ER_DIAMETER_TOO_BUSY:
+				case ER_DIAMETER_OUT_OF_SPACE:
+					error_cause = 506; /* Resources Unavailable */
+					break;
+					
+#if 0
+			/* remaining Diameter Result-Code & RADIUS Error-Cause */
+				case ER_DIAMETER_REDIRECT_INDICATION:
+				case ER_DIAMETER_INVALID_HDR_BITS:
+				case ER_DIAMETER_INVALID_AVP_BITS:
+				case ER_DIAMETER_AUTHENTICATION_REJECTED:
+				case ER_ELECTION_LOST:
+				case ER_DIAMETER_AUTHORIZATION_REJECTED:
+				case ER_DIAMETER_RESOURCES_EXCEEDED:
+				case ER_DIAMETER_CONTRADICTING_AVPS:
+				case ER_DIAMETER_AVP_OCCURS_TOO_MANY_TIMES
+				case ER_DIAMETER_NO_COMMON_APPLICATION:
+				case ER_DIAMETER_UNSUPPORTED_VERSION:
+				case ER_DIAMETER_INVALID_BIT_IN_HEADER:
+				case ER_DIAMETER_INVALID_AVP_LENGTH:
+				case ER_DIAMETER_INVALID_MESSAGE_LENGTH:
+				case ER_DIAMETER_INVALID_AVP_BIT_COMBO:
+				case ER_DIAMETER_NO_COMMON_SECURITY:
+					error_cause = 403; /* NAS Identification Mismatch */
+					error_cause = 504; /* Session Context Not Removable */
+					error_cause = 505; /* Other Proxy Processing Error */
+					error_cause = 507; /* Request Initiated */
+					error_cause = 508; /* Multiple Session Selection Unsupported */
+#endif /* 0 */
+			}
+			/* In any case, the following is processed: */
 			(*rad_fw)->hdr->code = RADIUS_CODE_ACCESS_REJECT;
 			fd_log_debug("[auth.rgwx] Received Diameter answer with error code '%d' from server '%.*s', session %.*s, translating into Access-Reject\n",
@@ -1825,8 +1896,5 @@
 					}
 					
-					if ( ! radius_msg_add_attr_int32(*rad_fw, RADIUS_ATTR_ERROR_CAUSE, 202) ) {
-						TRACE_DEBUG(INFO, "Error while adding Error-Cause attribute in RADIUS message");
-						return ENOMEM;
-					}
+					error_cause = 202; /* Invalid EAP Packet */
 					break;
 			
@@ -1852,4 +1920,11 @@
 	CHECK_FCT( fd_msg_free( aoh ) );
 	free(req_auth);
+	
+	if (error_cause) {
+		if ( ! radius_msg_add_attr_int32(*rad_fw, RADIUS_ATTR_ERROR_CAUSE, error_cause) ) {
+			TRACE_DEBUG(INFO, "Error while adding Error-Cause attribute in RADIUS message");
+			return ENOMEM;
+		}
+	}		
 
 	if ((*rad_fw)->hdr->code == RADIUS_CODE_ACCESS_ACCEPT) {
Index: extensions/app_radgw/rgwx_sip.c
===================================================================
--- extensions/app_radgw/rgwx_sip.c	(revision 639)
+++ extensions/app_radgw/rgwx_sip.c	(revision 705)
@@ -51,7 +51,4 @@
 #define ACV_ASS_STATE_MAINTAINED	0	/* STATE_MAINTAINED */
 #define ACV_ASS_NO_STATE_MAINTAINED	1	/* NO_STATE_MAINTAINED */
-#define ER_DIAMETER_MULTI_ROUND_AUTH	1001
-#define ER_DIAMETER_SUCCESS		2001
-#define ER_DIAMETER_LIMITED_SUCCESS	2002
 #define ER_DIAMETER_SUCCESS_AUTH_SENT_SERVER_NOT_STORED	2008
 #define ER_DIAMETER_SUCCESS_SERVER_NAME_NOT_STORED	2006
