view mtctest/dummy_rtp.c @ 124:7e04d28fae8b

sip-in: default use-100rel to no BulkVS servers act badly when we send a reliable 180 Ringing response to an incoming call, even though they advertise 100rel support in the Supported header in the INVITE packet, and we probably won't be implementing 100rel for outbound because doing per-the-spec PRACK as a UAC is just too burdensome. Therefore, we need to consider 100rel extension as not-really-supported in themwi-system-sw.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 01 Oct 2022 15:54:50 -0800
parents e8e82a4bf12b
children
line wrap: on
line source

/*
 * In this module we implement the code that connects to themwi-mgw
 * and obtains a dummy GSM-side RTP endpoint.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../include/tmgw_ctrl.h"
#include "../include/tmgw_const.h"

struct sockaddr_storage dummy_rtp_endp;

static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket";

obtain_dummy_rtp()
{
	struct sockaddr_un sa;
	unsigned sa_len;
	int fd, rc;
	struct tmgw_ctrl_req req;
	struct tmgw_ctrl_resp resp;

	fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
	if (fd < 0) {
		perror("socket(AF_UNIX, SOCK_SEQPACKET, 0)");
		exit(1);
	}
	fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len);
	rc = connect(fd, (struct sockaddr *) &sa, sa_len);
	if (rc < 0) {
		perror(tmgw_socket_pathname);
		exit(1);
	}
	bzero(&req, sizeof req);
	req.opcode = TMGW_CTRL_OP_CRCX;
	req.ep_id = TMGW_EP_TYPE_DUMMY_GSM;
	rc = send(fd, &req, sizeof req, 0);
	if (rc < 0) {
		perror("send to TMGW socket");
		exit(1);
	}
	rc = recv(fd, &resp, sizeof resp, 0);
	if (rc < 0) {
		perror("recv from TMGW socket");
		exit(1);
	}
	if (rc != sizeof resp) {
		fprintf(stderr,
	"error: response packet from TMGW has wrong length (%d bytes)\n",
			rc);
		exit(1);
	}
	if (resp.res != TMGW_RESP_OK) {
		fprintf(stderr, "TMGW CRCX returned error %u\n", resp.res);
		exit(1);
	}
	bcopy(&resp.gsm_addr, &dummy_rtp_endp, sizeof(struct sockaddr_storage));
	return(0);
}