view sip-in/mgw_ops.c @ 256:63252528a56c

sip-out: add CDR log line
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 15 Aug 2023 10:11:51 -0800
parents 0ecbc3dc8f93
children
line wrap: on
line source

/*
 * In this module we implement all transactions from themwi-sip-in
 * 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 "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_PSTN_CONN;
	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;
	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)
	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_GSM_CONN | TMGW_CTRL_MASK_FWD_MODE;
	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;
	req.fwd_mode = TMGW_FWD_MODE_SENDRECV;
	send_req_to_tmgw(&req);
	call->mgw_state = MGW_STATE_CONNECTING;
	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_HOLD_OP;
	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_RETRIEVE_OP;
	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;
}