changeset 56:7005d5c535e8

sip-in: mtcall socket connection implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Sep 2022 13:25:31 -0800
parents f1d59210f7b2
children d61d0136f6a5
files sip-in/Makefile sip-in/main.c sip-in/mncc_sock.c
diffstat 3 files changed, 76 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sip-in/Makefile	Thu Sep 08 12:58:03 2022 -0800
+++ b/sip-in/Makefile	Thu Sep 08 13:25:31 2022 -0800
@@ -1,7 +1,8 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	themwi-sip-in
-OBJS=	invite.o main.o mgw_sock.o readconf.o sip_log.o sip_uas.o sip_udp.o
+OBJS=	invite.o main.o mgw_sock.o mncc_sock.o readconf.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/main.c	Thu Sep 08 12:58:03 2022 -0800
+++ b/sip-in/main.c	Thu Sep 08 13:25:31 2022 -0800
@@ -14,6 +14,7 @@
 #include <unistd.h>
 
 extern int mgw_socket, sip_socket;
+extern int gsm_socket, gsm_is_connected;
 
 static int max_fd;
 
@@ -56,6 +57,8 @@
 		FD_ZERO(&fds);
 		FD_SET(mgw_socket, &fds);
 		FD_SET(sip_socket, &fds);
+		if (gsm_is_connected)
+			FD_SET(gsm_socket, &fds);
 		rc = select(max_fd+1, &fds, 0, 0, 0);
 		if (rc < 0) {
 			if (errno == EINTR)
@@ -64,9 +67,11 @@
 			exit(1);
 		}
 		gettimeofday(&cur_event_time, 0);
+		if (gsm_is_connected && FD_ISSET(gsm_socket, &fds))
+			gsm_socket_select();
+		if (FD_ISSET(sip_socket, &fds))
+			sip_socket_select();
 		if (FD_ISSET(mgw_socket, &fds))
 			mgw_socket_select();
-		if (FD_ISSET(sip_socket, &fds))
-			sip_socket_select();
 	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-in/mncc_sock.c	Thu Sep 08 13:25:31 2022 -0800
@@ -0,0 +1,67 @@
+/*
+ * In this module we implement our connection to the MNCC daemon's
+ * mtcall socket.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include "../include/mncc.h"
+
+static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket";
+
+int gsm_socket, gsm_is_connected;
+
+connect_gsm_mtcall()
+{
+	struct sockaddr_un sa;
+	unsigned sa_len;
+	int rc;
+
+	if (gsm_is_connected)
+		return(0);
+	gsm_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (gsm_socket < 0) {
+		syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
+		return(-1);
+	}
+	fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len);
+	rc = connect(gsm_socket, (struct sockaddr *) &sa, sa_len);
+	if (rc < 0) {
+		syslog(LOG_ERR, "connect to %s: %m", mtcall_socket_pathname);
+		return(-1);
+	}
+	update_max_fd(gsm_socket);
+	gsm_is_connected = 1;
+	return(0);
+}
+
+void
+gsm_socket_select()
+{
+	union mncc_msg msg;
+	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 < 4) {
+		syslog(LOG_CRIT, "short read from mtcall socket: %d bytes", rc);
+		exit(1);
+	}
+	/* mncc_msg_from_gsm(&msg, rc); */
+}
+
+send_mncc_to_gsm(msg, msglen)
+	union mncc_msg *msg;
+	unsigned msglen;
+{
+	return send(gsm_socket, msg, msglen, 0);
+}