diff mncc/gsm_call.c @ 15:ccc5ab6d8388

first version of themwi-mncc for ThemWi2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 26 Jun 2022 16:31:47 -0800
parents
children 660126bd5f59
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mncc/gsm_call.c	Sun Jun 26 16:31:47 2022 -0800
@@ -0,0 +1,101 @@
+/*
+ * In this module we implement allocation, freeing and retrieval
+ * of gsm_call structures.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <syslog.h>
+#include "struct.h"
+#include "gsm_call.h"
+
+struct gsm_call *call_list_head;
+
+static uint32_t mt_callref;
+
+struct gsm_call *
+find_gsm_callref(callref)
+	uint32_t callref;
+{
+	struct gsm_call *call;
+
+	for (call = call_list_head; call; call = call->next) {
+		if (call->gc_flag)
+			continue;
+		if (call->callref == callref)
+			return call;
+	}
+	return 0;
+}
+
+struct gsm_call *
+find_socket_call(conn, ref)
+	struct socket_conn *conn;
+	uint32_t ref;
+{
+	struct gsm_call *call;
+
+	for (call = call_list_head; call; call = call->next) {
+		if (call->gc_flag)
+			continue;
+		if (call->socket == conn && call->socket_ref == ref)
+			return call;
+	}
+	return 0;
+}
+
+struct gsm_call *
+create_gsm_call(callref)
+	uint32_t callref;
+{
+	struct gsm_call *call;
+
+	call = malloc(sizeof(struct gsm_call));
+	if (call) {
+		bzero(call, sizeof(struct gsm_call));
+		call->callref = callref;
+		call->next = call_list_head;
+		call_list_head = call;
+	}
+	return call;
+}
+
+uint32_t
+alloc_mt_callref()
+{
+	mt_callref++;
+	if (mt_callref > 0x7FFFFFFF)
+		mt_callref = 1;
+	return mt_callref;
+}
+
+struct gsm_call *
+create_new_mt_call()
+{
+	uint32_t callref;
+
+	for (;;) {
+		callref = alloc_mt_callref();
+		if (!find_gsm_callref(callref))
+			break;
+	}
+	return create_gsm_call(callref);
+}
+
+gc_call_list()
+{
+	struct gsm_call *call, **cp;
+
+	for (cp = &call_list_head; call = *cp; ) {
+		if (call->gc_flag) {
+			*cp = call->next;
+			free(call);
+			continue;
+		}
+		cp = &call->next;
+	}
+}