diff sip-in/mncc_sock.c @ 56:7005d5c535e8

sip-in: mtcall socket connection implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Sep 2022 13:25:31 -0800
parents mncc/mncc_sock.c@ccc5ab6d8388
children d61d0136f6a5
line wrap: on
line diff
--- /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);
+}