changeset 169:648a64b2e16b

mgw: accept Themyscira-extension RTP BFI packets
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 19 Nov 2022 23:08:49 -0800
parents 8c28426abef0
children a6eb2de277f6
files mgw/gsm2pstn.c mgw/int_defs.h
diffstat 2 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mgw/gsm2pstn.c	Sat Nov 19 22:57:59 2022 -0800
+++ b/mgw/gsm2pstn.c	Sat Nov 19 23:08:49 2022 -0800
@@ -37,16 +37,18 @@
 	struct rtp_packet pkt;
 	struct sockaddr_in sin_from;
 	socklen_t addrlen;
+	unsigned pktsize;
 	int16_t seq_delta;
 	int32_t ts_delta;
 	int16_t pcm_samples[SAMPLES_PER_FRAME];
-	int rc, m_out;
+	int rc, bfi, taf, m_out;
 
 	addrlen = sizeof(struct sockaddr_in);
 	rc = recvfrom(in_fd, &pkt, sizeof pkt, 0,
 			(struct sockaddr *) &sin_from, &addrlen);
 	if (rc < 0)
 		return;
+	pktsize = rc;
 	if (sin_from.sin_addr.s_addr != ep->rtp_gsm.remote_addr.sin_addr.s_addr
 	    || sin_from.sin_port != ep->rtp_gsm.remote_addr.sin_port) {
 		if (!(ep->g2p_err_flags & ERR_WRONG_UDP_SRC)) {
@@ -56,7 +58,7 @@
 		}
 		return;
 	}
-	if (rc != ep->gsm_rtp_pkt_size) {
+	if (pktsize < RTP_PACKET_SIZE_BFI) {
 bad_rtp_pkt:	if (!(ep->g2p_err_flags & ERR_BAD_RTP_PACKET)) {
 			syslog(LOG_ERR, "Rx bad RTP packet on GSM side");
 			ep->g2p_err_flags |= ERR_BAD_RTP_PACKET;
@@ -67,7 +69,13 @@
 		goto bad_rtp_pkt;
 	if ((pkt.m_pt & 0x7F) != ep->gsm_payload_type)
 		goto bad_rtp_pkt;
-	if ((pkt.payload[0] & 0xF0) != ep->gsm_payload_magic)
+	if (pktsize == ep->gsm_rtp_pkt_size &&
+	    (pkt.payload[0] & 0xF0) == ep->gsm_payload_magic)
+		bfi = 0;
+	else if (pktsize == RTP_PACKET_SIZE_BFI && pkt.payload[0] == 0xBF) {
+		bfi = 1;
+		taf = pkt.payload[1] & 1;
+	} else
 		goto bad_rtp_pkt;
 	if (ep->g2p_state && pkt.ssrc != ep->g2p_ssrc) {
 		if (!(ep->g2p_err_flags & ERR_SSRC_CHANGE)) {
@@ -134,8 +142,12 @@
 	}
 	switch (ep->gsm_payload_msg_type) {
 	case GSM_TCHF_FRAME:
-		gsmfr_preproc_good_frame(ep->gsm_decoder_extra_state,
-					 pkt.payload);
+		if (bfi)
+			gsmfr_preproc_bfi(ep->gsm_decoder_extra_state, taf,
+					  pkt.payload);
+		else
+			gsmfr_preproc_good_frame(ep->gsm_decoder_extra_state,
+						 pkt.payload);
 		gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples);
 		break;
 	}
--- a/mgw/int_defs.h	Sat Nov 19 22:57:59 2022 -0800
+++ b/mgw/int_defs.h	Sat Nov 19 23:08:49 2022 -0800
@@ -5,6 +5,7 @@
 #define	RTP_PACKET_SIZE_PSTN	172
 #define	RTP_PACKET_SIZE_GSM_FR	45
 #define	RTP_PACKET_SIZE_GSM_EFR	43
+#define	RTP_PACKET_SIZE_BFI	14
 #define	RTP_MAX_PAYLOAD		160
 
 struct rtp_packet {