changeset 105:9213ec8b434b

sip-in: handle themwi-mncc shutdown without terminating
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 27 Sep 2022 23:00:52 -0800
parents ce3b1db7d1d7
children 245dc4837b56
files sip-in/Makefile sip-in/mncc_sock.c sip-in/shutdown.c
diffstat 3 files changed, 67 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sip-in/Makefile	Tue Sep 27 21:52:07 2022 -0800
+++ b/sip-in/Makefile	Tue Sep 27 23:00:52 2022 -0800
@@ -3,7 +3,7 @@
 PROG=	themwi-sip-in
 OBJS=	bye_in.o bye_out.o call_list.o call_setup.o cancel.o disconnect.o \
 	invite.o main.o mgw_ops.o mgw_sock.o mncc_handle.o mncc_sock.o \
-	readconf.o retrans.o sip_ack.o sip_log.o sip_uas.o sip_udp.o
+	readconf.o retrans.o shutdown.o sip_ack.o sip_log.o sip_uas.o sip_udp.o
 LIBS=	../libnumdb/libnumdb.a ../libsip/libsip.a ../libutil/libutil.a
 INSTBIN=/usr/local/bin
 
--- a/sip-in/mncc_sock.c	Tue Sep 27 21:52:07 2022 -0800
+++ b/sip-in/mncc_sock.c	Tue Sep 27 23:00:52 2022 -0800
@@ -48,10 +48,10 @@
 	int rc;
 
 	rc = recv(gsm_socket, &msg, sizeof msg, 0);
-	if (rc < 0) {
-		syslog(LOG_CRIT, "error reading from mtcall socket: %m");
-		/* GSM disconnect handling to be implemented */
-		exit(1);
+	if (rc <= 0) {
+		syslog(LOG_ERR, "mtcall socket disconnected");
+		shutdown_gsm_conn();
+		gsm_is_connected = 0;
 	}
 	if (rc < 4) {
 		syslog(LOG_CRIT, "short read from mtcall socket: %d bytes", rc);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-in/shutdown.c	Tue Sep 27 23:00:52 2022 -0800
@@ -0,0 +1,62 @@
+/*
+ * In this module we handle the scenarios of themwi-mncc and/or themwi-mgw
+ * shutting down while we are connected to them.  In both scenarios we
+ * terminate all active calls (graceful disconnect signaling toward SIP
+ * callers and toward whichever ThemWi daemon is still running, if either),
+ * but our themwi-sip-in process itself stays running.  This way once
+ * the other required processes restart, inbound calls will start working
+ * once again, without needing to restart themwi-sip-in.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <syslog.h>
+#include "../include/mncc.h"
+#include "../include/gsm48_const.h"
+#include "call.h"
+
+extern struct call *call_list;
+
+static struct gsm_mncc_cause shutdown_cause = {
+	.coding		= GSM48_CAUSE_CODING_GSM,
+	.location	= GSM48_CAUSE_LOC_PRN_S_LU,
+	.value		= GSM48_CC_CAUSE_NETWORK_OOO,
+};
+
+void
+shutdown_gsm_conn()
+{
+	struct call *call;
+
+	for (call = call_list; call; call = call->next) {
+		call->mncc_state = MNCC_STATE_NO_EXIST;
+		if (call->overall_state != OVERALL_STATE_DEAD_SIP) {
+			call->overall_state = OVERALL_STATE_TEARDOWN;
+			disconnect_tmgw(call);
+			disconnect_sip(call, &shutdown_cause);
+		}
+	}
+}
+
+void
+shutdown_mgw_conn()
+{
+	struct call *call;
+
+	for (call = call_list; call; call = call->next) {
+		call->mgw_state = MGW_STATE_NO_EXIST;
+		call->mgw_xact = 0;
+		if (call->overall_state != OVERALL_STATE_DEAD_SIP) {
+			call->overall_state = OVERALL_STATE_TEARDOWN;
+			disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
+					GSM48_CC_CAUSE_NETWORK_OOO);
+			disconnect_sip(call, &shutdown_cause);
+		}
+	}
+}