view mgw/mdcx.c @ 64:1f863c63f96b

sip-in: beginning of disconnect handling
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 18 Sep 2022 15:29:30 -0800
parents 020ba624bdd8
children f280328e7e2e
line wrap: on
line source

/*
 * In this module we implement our MDCX operation.
 */

#include <sys/types.h>
#include <sys/socket.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"

extern struct endpoint *find_ep_by_id();

mdcx_operation(ep, req, resp)
	struct endpoint *ep;
	struct tmgw_ctrl_req *req;
	struct tmgw_ctrl_resp *resp;
{
	if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) {
		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
			resp->res = TMGW_RESP_ERR_PROT;
			return(-1);
		}
		if (req->gsm_addr.ss_family != AF_INET) {
			resp->res = TMGW_RESP_ERR_PARAM;
			return(-1);
		}
		switch (req->gsm_payload_msg_type) {
		case GSM_TCHF_FRAME:
			break;
		case GSM_TCHF_FRAME_EFR:
		case GSM_TCHH_FRAME:
		case GSM_TCH_FRAME_AMR:
			resp->res = TMGW_RESP_ERR_NOTSUP;
			return(-1);
		default:
			resp->res = TMGW_RESP_ERR_PARAM;
			return(-1);
		}
		bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
			sizeof(struct sockaddr_in));
		ep->gsm_payload_type = req->gsm_payload_type;
		ep->gsm_payload_msg_type = req->gsm_payload_msg_type;
	}
	if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) {
		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
			resp->res = TMGW_RESP_ERR_PROT;
			return(-1);
		}
		if (req->pstn_addr.ss_family != AF_INET) {
			resp->res = TMGW_RESP_ERR_PARAM;
			return(-1);
		}
		switch (req->pstn_payload_type) {
		case PSTN_CODEC_PCMU:
		case PSTN_CODEC_PCMA:
			break;
		default:
			resp->res = TMGW_RESP_ERR_PARAM;
			return(-1);
		}
		bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
			sizeof(struct sockaddr_in));
		ep->pstn_payload_type = req->pstn_payload_type;
	}
	if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) {
		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY ||
		    ep->rtp_gsm.remote_addr.sin_family != AF_INET ||
		    ep->rtp_pstn.remote_addr.sin_family != AF_INET) {
			resp->res = TMGW_RESP_ERR_PROT;
			return(-1);
		}
		ep->fwd_mode = req->fwd_mode;
	}
	return(0);
}

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

	ep = find_ep_by_id(conn, req->ep_id);
	if (!ep) {
		resp->res = TMGW_RESP_ERR_PROT;
		return;
	}
	rc = mdcx_operation(ep, req, resp);
	if (rc == 0)
		resp->res = TMGW_RESP_OK;
}