view mgw/dtmf_ctrl.c @ 201:d3c99b41fb04

sip-manual-out TFO: rework for continuous output of TFO_REQ
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 02 Apr 2023 18:01:34 -0800
parents a6eb2de277f6
children 0047c4c08d9e
line wrap: on
line source

/*
 * In this module we implement start/stop control of DTMF generation
 * toward PSTN on GSM-to-PSTN gateway endpoints.
 */

#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 "struct.h"
#include "int_defs.h"
#include "dtmf_defs.h"

extern struct endpoint *find_ep_by_id();

extern struct dtmf_desc dtmf_table[];

void
process_dtmf_start(conn, req, resp)
	struct ctrl_conn *conn;
	struct tmgw_ctrl_req *req;
	struct tmgw_ctrl_resp *resp;
{
	struct endpoint *ep;
	struct dtmf_desc *desc;

	ep = find_ep_by_id(conn, req->ep_id);
	if (!ep) {
protocol_err:	resp->res = TMGW_RESP_ERR_PROT;
		return;
	}
	if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
		goto protocol_err;
	if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN))
		goto protocol_err;
	for (desc = dtmf_table; desc->digit; desc++)
		if (desc->digit == req->fwd_mode)
			break;
	if (!desc->digit) {
		resp->res = TMGW_RESP_ERR_PARAM;
		return;
	}
	if (ep->dtmf_sample_ptr) {
		resp->res = TMGW_RESP_ERR_BUSY;
		return;
	}
	/* start it */
	ep->dtmf_sample_ptr = desc->samples;
	ep->dtmf_frames_sent = 0;
	/* return success */
	resp->res = TMGW_RESP_OK;
}

void
process_dtmf_stop(conn, req, resp)
	struct ctrl_conn *conn;
	struct tmgw_ctrl_req *req;
	struct tmgw_ctrl_resp *resp;
{
	struct endpoint *ep;

	ep = find_ep_by_id(conn, req->ep_id);
	if (!ep) {
protocol_err:	resp->res = TMGW_RESP_ERR_PROT;
		return;
	}
	if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
		goto protocol_err;
	ep->dtmf_sample_ptr = 0;
	resp->res = TMGW_RESP_OK;
}