diff sip-out/disconnect.c @ 154:e54b0a9e322f

beginning of themwi-sip-out
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2022 23:04:01 -0800
parents sip-in/disconnect.c@e499e8db8b82
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-out/disconnect.c	Tue Oct 11 23:04:01 2022 -0800
@@ -0,0 +1,88 @@
+/*
+ * In this module we implement call disconnection and clearing procedures.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.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 "../include/out_routes.h"
+#include "call.h"
+
+extern unsigned sip_linger_timeout;
+
+void
+disconnect_mncc(call, cause_loc, cause_val)
+	struct call *call;
+{
+	struct gsm_mncc msg;
+
+	if (!call->mncc)
+		return;
+	switch (call->mncc_state) {
+	case MNCC_STATE_DISCONNECT:
+	case MNCC_STATE_RELEASE:
+		return;
+	}
+	bzero(&msg, sizeof(struct gsm_mncc));
+	msg.msg_type = MNCC_DISC_REQ;
+	msg.callref = call->mncc_callref;
+	mncc_set_cause(&msg, cause_loc, cause_val);
+	send_mncc_to_sock(call->mncc, &msg, sizeof(struct gsm_mncc));
+	call->mncc_state = MNCC_STATE_DISCONNECT;
+}
+
+void
+disconnect_tmgw(call)
+	struct call *call;
+{
+	switch (call->mgw_state) {
+	case MGW_STATE_NO_EXIST:
+	case MGW_STATE_DELETING:
+	case MGW_STATE_MDCX_IBT:
+	case MGW_STATE_MDCX_CONN:
+	case MGW_STATE_MDCX_HOLD:
+	case MGW_STATE_MDCX_RETR:
+	case MGW_STATE_DTMF_OP:
+		return;
+	case MGW_STATE_ALLOCATED:
+	case MGW_STATE_IBT_CONN:
+	case MGW_STATE_COMPLETE:
+	case MGW_STATE_HELD:
+		tmgw_send_dlcx(call);
+		return;
+	default:
+		syslog(LOG_CRIT,
+			"FATAL: invalid MGW state 0x%x in disconnect_tmgw()",
+			call->mgw_state);
+		exit(1);
+	}
+}
+
+void
+disconnect_sip(call)
+	struct call *call;
+{
+	if (!call->sip_call_exists)
+		return;
+	switch (call->sip_state) {
+	case SIP_STATE_INV_SENT:
+		call->sip_state = SIP_STATE_ACCEPT_100;
+		sip_mark_end_time(call, sip_linger_timeout);
+		break;
+	case SIP_STATE_100_RCVD:
+		initiate_sip_cancel(call);
+		break;
+	case SIP_STATE_CONNECTED:
+		initiate_bye(call);
+		break;
+	}
+}