view mgw/dtmf_ctrl.c @ 205:0047c4c08d9e

mgw: accept the new TRAUlike RTP format in addition to standard, old BFI and zero-length payload formats
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 06 Apr 2023 19:50:09 -0800
parents a6eb2de277f6
children
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 "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;
}