diff sip-out/mgw_ops.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/mgw_ops.c@0ecbc3dc8f93
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-out/mgw_ops.c	Tue Oct 11 23:04:01 2022 -0800
@@ -0,0 +1,172 @@
+/*
+ * In this module we implement all transactions from themwi-sip-out
+ * toward themwi-mgw.
+ */
+
+#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/tmgw_ctrl.h"
+#include "../include/tmgw_const.h"
+#include "../include/out_routes.h"
+#include "call.h"
+
+extern struct call *call_list;
+
+struct call *
+find_call_with_mgw_xact(xact_id)
+	uint32_t xact_id;
+{
+	struct call *call;
+
+	for (call = call_list; call; call = call->next)
+		if (call->mgw_xact && call->mgw_xact_id == xact_id)
+			return call;
+	return 0;
+}
+
+uint32_t
+get_new_tmgw_xact_id()
+{
+	static uint32_t next_xact_id;
+
+	for (;;) {
+		next_xact_id++;
+		if (!find_call_with_mgw_xact(next_xact_id))
+			return next_xact_id;
+	}
+}
+
+void
+tmgw_send_crcx(call)
+	struct call *call;
+{
+	struct tmgw_ctrl_req req;
+
+	bzero(&req, sizeof req);
+	req.opcode = TMGW_CTRL_OP_CRCX;
+	req.transact_ref = get_new_tmgw_xact_id();
+	req.ep_id = TMGW_EP_TYPE_GATEWAY;
+	req.setup_mask = TMGW_CTRL_MASK_GSM_CONN;
+	bcopy(&call->gsm_rtp_osmo, &req.gsm_addr,
+		sizeof(struct sockaddr_storage));
+	req.gsm_payload_type = call->gsm_payload_type;
+	req.gsm_payload_msg_type = call->gsm_payload_msg_type;
+	send_req_to_tmgw(&req);
+	call->mgw_xact = TMGW_CTRL_OP_CRCX;
+	call->mgw_xact_id = req.transact_ref;
+}
+
+void
+tmgw_send_mdcx_connect(call, ibt)
+	struct call *call;
+{
+	struct tmgw_ctrl_req req;
+
+	bzero(&req, sizeof req);
+	req.opcode = TMGW_CTRL_OP_MDCX;
+	req.transact_ref = get_new_tmgw_xact_id();
+	req.ep_id = call->mgw_ep_id;
+	req.setup_mask = TMGW_CTRL_MASK_PSTN_CONN | TMGW_CTRL_MASK_FWD_MODE;
+	bcopy(&call->pstn_rtp_remote, &req.pstn_addr,
+		sizeof(struct sockaddr_in));
+	req.pstn_payload_type =
+		call->use_pcma ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU;
+	req.fwd_mode = ibt ? TMGW_FWD_MODE_RECVONLY : TMGW_FWD_MODE_SENDRECV;
+	send_req_to_tmgw(&req);
+	call->mgw_state = ibt ? MGW_STATE_MDCX_IBT : MGW_STATE_MDCX_CONN;
+	call->mgw_xact = TMGW_CTRL_OP_MDCX;
+	call->mgw_xact_id = req.transact_ref;
+}
+
+void
+tmgw_send_mdcx_hold(call)
+	struct call *call;
+{
+	struct tmgw_ctrl_req req;
+
+	bzero(&req, sizeof req);
+	req.opcode = TMGW_CTRL_OP_MDCX;
+	req.transact_ref = get_new_tmgw_xact_id();
+	req.ep_id = call->mgw_ep_id;
+	req.setup_mask = TMGW_CTRL_MASK_FWD_MODE;
+	req.fwd_mode = TMGW_FWD_MODE_INACTIVE;
+	send_req_to_tmgw(&req);
+	call->mgw_state = MGW_STATE_MDCX_HOLD;
+	call->mgw_xact = TMGW_CTRL_OP_MDCX;
+	call->mgw_xact_id = req.transact_ref;
+}
+
+void
+tmgw_send_mdcx_retrieve(call)
+	struct call *call;
+{
+	struct tmgw_ctrl_req req;
+
+	bzero(&req, sizeof req);
+	req.opcode = TMGW_CTRL_OP_MDCX;
+	req.transact_ref = get_new_tmgw_xact_id();
+	req.ep_id = call->mgw_ep_id;
+	req.setup_mask = TMGW_CTRL_MASK_FWD_MODE;
+	req.fwd_mode = TMGW_FWD_MODE_SENDRECV;
+	send_req_to_tmgw(&req);
+	call->mgw_state = MGW_STATE_MDCX_RETR;
+	call->mgw_xact = TMGW_CTRL_OP_MDCX;
+	call->mgw_xact_id = req.transact_ref;
+}
+
+void
+tmgw_send_dlcx(call)
+	struct call *call;
+{
+	struct tmgw_ctrl_req req;
+
+	bzero(&req, sizeof req);
+	req.opcode = TMGW_CTRL_OP_DLCX;
+	req.transact_ref = get_new_tmgw_xact_id();
+	req.ep_id = call->mgw_ep_id;
+	send_req_to_tmgw(&req);
+	call->mgw_state = MGW_STATE_DELETING;
+	call->mgw_xact = TMGW_CTRL_OP_DLCX;
+	call->mgw_xact_id = req.transact_ref;
+}
+
+void
+tmgw_send_dtmf_start(call)
+	struct call *call;
+{
+	struct tmgw_ctrl_req req;
+
+	bzero(&req, sizeof req);
+	req.opcode = TMGW_CTRL_OP_DTMF_START;
+	req.transact_ref = get_new_tmgw_xact_id();
+	req.ep_id = call->mgw_ep_id;
+	req.fwd_mode = call->dtmf_digit;
+	send_req_to_tmgw(&req);
+	call->mgw_state = MGW_STATE_DTMF_OP;
+	call->mgw_xact = TMGW_CTRL_OP_DTMF_START;
+	call->mgw_xact_id = req.transact_ref;
+}
+
+void
+tmgw_send_dtmf_stop(call)
+	struct call *call;
+{
+	struct tmgw_ctrl_req req;
+
+	bzero(&req, sizeof req);
+	req.opcode = TMGW_CTRL_OP_DTMF_STOP;
+	req.transact_ref = get_new_tmgw_xact_id();
+	req.ep_id = call->mgw_ep_id;
+	send_req_to_tmgw(&req);
+	call->mgw_state = MGW_STATE_DTMF_OP;
+	call->mgw_xact = TMGW_CTRL_OP_DTMF_STOP;
+	call->mgw_xact_id = req.transact_ref;
+}