changeset 195:a3d71489672f

sip-manual-out: implement tfo-req command
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 17:22:42 -0800
parents 05d01e810217
children eac3e0b6ce02
files sip-manual-out/rtp_tx.c sip-manual-out/user_cmd.c
diffstat 2 files changed, 79 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sip-manual-out/rtp_tx.c	Fri Mar 17 16:52:21 2023 -0800
+++ b/sip-manual-out/rtp_tx.c	Fri Mar 17 17:22:42 2023 -0800
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include "../include/tmgw_const.h"
 #include "../include/rtp_defs.h"
+#include "../libutil/osmo_bits.h"
 
 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr;
 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected;
@@ -23,12 +24,32 @@
 static uint32_t rtp_out_ts;
 static uint16_t rtp_out_seq;
 
+static uint16_t is_out_buf[7], *is_out_ptr;
+static unsigned is_out_count;
+
 void
 assign_rtpout_ssrc()
 {
 	rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid();
 }
 
+static void
+insert_is_msg(payload, word)
+	uint8_t *payload;
+	uint16_t word;
+{
+	ubit_t is_bits[10];
+	uint8_t *bytep;
+	unsigned n;
+
+	uint16_to_bits(word, is_bits, 10);
+	for (n = 0; n < 10; n++) {
+		bytep = payload + n * 16;
+		*bytep &= 0xFE;
+		*bytep |= is_bits[n];
+	}
+}
+
 void
 generate_rtp_packet()
 {
@@ -42,7 +63,25 @@
 	rtp_out_ts += 160;
 	pkt.ssrc = rtp_ssrc;
 	memset(pkt.payload, pcma_selected ? 0xD5 : 0xFF, RTP_MAX_PAYLOAD);
+	if (is_out_count) {
+		insert_is_msg(pkt.payload, *is_out_ptr++);
+		is_out_count--;
+	}
 	addrlen = sizeof(struct sockaddr_in);
 	sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0,
 		(struct sockaddr *) &rtp_remote_addr, addrlen);
 }
+
+void
+send_tfo_req(sig, codec)
+	unsigned sig, codec;
+{
+	is_out_buf[0] = 0x15A;
+	is_out_buf[1] = 0x1A9;
+	is_out_buf[2] = 0x05D;
+	is_out_buf[3] = 0x14E;
+	is_out_buf[4] = 0x14B;
+	encode_tfo_ext_words(sig, codec, 0, is_out_buf + 5);
+	is_out_ptr = is_out_buf;
+	is_out_count = 7;
+}
--- a/sip-manual-out/user_cmd.c	Fri Mar 17 16:52:21 2023 -0800
+++ b/sip-manual-out/user_cmd.c	Fri Mar 17 17:22:42 2023 -0800
@@ -9,6 +9,44 @@
 #include <string.h>
 #include <strings.h>
 
+static void
+tfo_req_cmd(args)
+	char *args;
+{
+	char *cp;
+	unsigned sig, codec;
+
+	for (cp = args; isspace(*cp); cp++)
+		;
+	if (!isdigit(*cp)) {
+inv_syntax:	fprintf(stderr, "error: tfo-req command invalid syntax\n");
+		return;
+	}
+	sig = strtoul(cp, &cp, 0);
+	if (!isspace(*cp))
+		goto inv_syntax;
+	if (sig > 0xFF) {
+		fprintf(stderr, "error: Sig argument out of range\n");
+		return;
+	}
+	while (isspace(*cp))
+		cp++;
+	if (!isdigit(*cp))
+		goto inv_syntax;
+	codec = strtoul(cp, &cp, 0);
+	if (*cp && !isspace(*cp))
+		goto inv_syntax;
+	if (codec > 14) {
+		fprintf(stderr, "error: Codec_Type argument out of range\n");
+		return;
+	}
+	while (isspace(*cp))
+		cp++;
+	if (*cp)
+		goto inv_syntax;
+	send_tfo_req(sig, codec);
+}
+
 void
 select_stdin()
 {
@@ -29,6 +67,8 @@
 		send_bye_req();
 	else if (!strcmp(cp, "c") || !strcasecmp(cp, "cancel"))
 		send_cancel_req();
+	else if (!strncmp(cp, "tfo-req", 7) && isspace(cp[7]))
+		tfo_req_cmd(cp + 8);
 	else
 		fprintf(stderr, "error: non-understood stdin command\n");
 }