changeset 167:2ebad02adbe5

themwi-mncc: route outbound calls to themwi-sip-out
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 18:08:34 -0800
parents 8adcd220c6cf
children 8c28426abef0
files mncc/Makefile mncc/call_setup.c mncc/main.c mncc/outcall.c
diffstat 4 files changed, 80 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mncc/Makefile	Wed Oct 12 17:07:49 2022 -0800
+++ b/mncc/Makefile	Wed Oct 12 18:08:34 2022 -0800
@@ -2,7 +2,7 @@
 CFLAGS=	-O2
 PROG=	themwi-mncc
 OBJS=	call_setup.o extsock.o gsm_call.o intswitch.o main.o mncc_recv.o \
-	mncc_sock.o mtsock.o
+	mncc_sock.o mtsock.o outcall.o
 LIBS=	../libnumdb/libnumdb.a ../libutil/libutil.a
 INSTBIN=/usr/local/bin
 
--- a/mncc/call_setup.c	Wed Oct 12 17:07:49 2022 -0800
+++ b/mncc/call_setup.c	Wed Oct 12 18:08:34 2022 -0800
@@ -176,16 +176,10 @@
 		return;
 	}
 	/* actually route the call */
-	if (is_local) {
+	if (is_local)
 		internal_switch_mo_setup(call, msg);
-		return;
-	}
-	/* outbound calls remain to be implemented */
-	syslog(LOG_ERR, "rejecting MO call 0x%x: outbound not implemented",
-		msg->callref);
-	reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
-			GSM48_CC_CAUSE_NO_ROUTE);
-	call->gc_flag = 1;
+	else
+		outbound_mo_setup(call, msg);
 }
 
 static void
--- a/mncc/main.c	Wed Oct 12 17:07:49 2022 -0800
+++ b/mncc/main.c	Wed Oct 12 18:08:34 2022 -0800
@@ -18,6 +18,8 @@
 extern int mtcall_listener;
 extern struct socket_conn *mtcall_socket_head;
 
+struct socket_conn outcall_conn;
+
 static int max_fd;
 
 update_max_fd(newfd)
@@ -47,6 +49,7 @@
 		exit(1);
 	}
 	signal(SIGPIPE, SIG_IGN);
+	outcall_conn.fd = -1;
 	/* main select loop */
 	for (;;) {
 		FD_ZERO(&fds);
@@ -61,6 +64,8 @@
 			FD_SET(conn->fd, &fds);
 			connp = &conn->next;
 		}
+		if (outcall_conn.fd >= 0)
+			FD_SET(outcall_conn.fd, &fds);
 		c = select(max_fd+1, &fds, 0, 0, 0);
 		if (c < 0) {
 			if (errno == EINTR)
@@ -75,6 +80,8 @@
 		for (conn = mtcall_socket_head; conn; conn = conn->next)
 			if (FD_ISSET(conn->fd, &fds))
 				extsock_read_select(conn);
+		if (outcall_conn.fd >= 0 && FD_ISSET(outcall_conn.fd, &fds))
+			extsock_read_select(&outcall_conn);
 		gc_call_list();
 	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mncc/outcall.c	Wed Oct 12 18:08:34 2022 -0800
@@ -0,0 +1,69 @@
+/*
+ * In this module we handle routing of outbound MO calls
+ * to the outcall socket provided by themwi-sip-out.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <syslog.h>
+#include <unistd.h>
+#include "../include/mncc.h"
+#include "../include/gsm48_const.h"
+#include "struct.h"
+
+extern struct socket_conn outcall_conn;
+
+static char outcall_socket_pathname[] = "/var/gsm/outcall_socket";
+
+connect_outcall_socket()
+{
+	struct sockaddr_un sa;
+	unsigned sa_len;
+	int fd, rc;
+
+	if (outcall_conn.fd >= 0)
+		return(0);
+	fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (fd < 0) {
+		syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
+		return(-1);
+	}
+	fill_sockaddr_un(outcall_socket_pathname, &sa, &sa_len);
+	rc = connect(fd, (struct sockaddr *) &sa, sa_len);
+	if (rc < 0) {
+		syslog(LOG_ERR, "connect to %s: %m", outcall_socket_pathname);
+		close(fd);
+		return(-1);
+	}
+	update_max_fd(fd);
+	outcall_conn.fd = fd;
+	return(0);
+}
+
+void
+outbound_mo_setup(call, msg)
+	struct gsm_call *call;
+	struct gsm_mncc *msg;
+{
+	int rc;
+
+	rc = connect_outcall_socket();
+	if (rc < 0) {
+		syslog(LOG_ERR, "rejecting MO call 0x%x: outbound gateway down",
+			msg->callref);
+		reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
+				GSM48_CC_CAUSE_DEST_OOO);
+		call->gc_flag = 1;
+		return;
+	}
+	call->socket = &outcall_conn;
+	call->socket_ref = msg->callref;
+	outcall_conn.ncalls++;
+	mncc_signal_to_socket(call, msg);
+}