diff sip-in/disconnect.c @ 83:3e3fbf44f9d7

sip-in: disconnect and call clearing implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 22:06:37 -0800
parents 5beb51de1bae
children 0d6435808bcd
line wrap: on
line diff
--- a/sip-in/disconnect.c	Tue Sep 20 20:33:09 2022 -0800
+++ b/sip-in/disconnect.c	Tue Sep 20 22:06:37 2022 -0800
@@ -12,6 +12,7 @@
 #include <strings.h>
 #include <syslog.h>
 #include "../include/mncc.h"
+#include "../include/gsm48_const.h"
 #include "call.h"
 
 void
@@ -54,3 +55,52 @@
 		exit(1);
 	}
 }
+
+static char *
+cause_to_invite_err(cause)
+	struct gsm_mncc_cause *cause;
+{
+	switch (cause->value) {
+	case GSM48_CC_CAUSE_CALL_REJECTED:
+		return "403 Call rejected";
+	case GSM48_CC_CAUSE_UNASSIGNED_NR:
+		return "404 Unassigned number";
+	case GSM48_CC_CAUSE_USER_NOTRESPOND:
+		return "480 User not responding";
+	case GSM48_CC_CAUSE_RESOURCE_UNAVAIL:
+		return "503 GSM network resource unavailable";
+	case GSM48_CC_CAUSE_TEMP_FAILURE:
+		return "503 Temporary failure";
+	case GSM48_CC_CAUSE_SWITCH_CONG:
+		return "503 Switch congestion at MSC";
+	case GSM48_CC_CAUSE_USER_BUSY:
+		return "486 User busy";
+	case GSM48_CC_CAUSE_DEST_OOO:
+		return "502 Destination out of order";
+	case GSM48_CC_CAUSE_NETWORK_OOO:
+		return "503 Network out of order";
+	default:
+		return "480 Unavailable (unspecified)";
+	}
+}
+
+void
+disconnect_sip(call, cause)
+	struct call *call;
+	struct gsm_mncc_cause *cause;
+{
+	switch (call->sip_state) {
+	case SIP_STATE_INVITE_PROC:
+	case SIP_STATE_RINGING:
+	case SIP_STATE_RINGING_PRACK:
+		strcpy(call->invite_fail, cause_to_invite_err(cause));
+		signal_invite_error(call);
+		break;
+	case SIP_STATE_INVITE_200:
+		/* have to wait for SIP ACK, then send BYE */
+		break;
+	case SIP_STATE_CONNECTED:
+		initiate_bye(call);
+		break;
+	}
+}