changeset 31:284fcb5868e2

implement SDES setting
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 08 Jul 2024 04:56:50 +0000
parents 9fd693f234f8
children aa97e77e7de6
files src/Makefile src/set_sdes.c
diffstat 2 files changed, 101 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile	Mon Jul 08 03:28:38 2024 +0000
+++ b/src/Makefile	Mon Jul 08 04:56:50 2024 +0000
@@ -1,6 +1,6 @@
 OBJS=	bind_fdpair.o endp_bind.o endp_create.o endp_register.o rtcp_rx.o \
-	rtp_rx.o rtp_tx.o set_remote.o twjit.o twjit_in.o twjit_out.o \
-	twjit_vty.o
+	rtp_rx.o rtp_tx.o set_remote.o set_sdes.o twjit.o twjit_in.o \
+	twjit_out.o twjit_vty.o
 LIB=	libtwrtp.a
 
 include ../config.defs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/set_sdes.c	Mon Jul 08 04:56:50 2024 +0000
@@ -0,0 +1,99 @@
+/*
+ * Here we implement the function that prepares the SDES subpacket
+ * for subsequent RTCP output.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+#include <arpa/inet.h>	/* for network byte order functions */
+
+#include <osmocom/core/talloc.h>
+
+#include <themwi/rtp/endp.h>
+#include <themwi/rtp/rtcp_defs.h>
+
+int twrtp_endp_set_sdes(struct twrtp_endp *endp, const char *cname,
+			const char *name, const char *email, const char *phone,
+			const char *loc, const char *tool, const char *note)
+{
+	uint16_t len_str, len_padded, len_with_hdr, len;
+	struct rtcp_sr_rr_hdr *hdr;
+	uint8_t *dp;
+
+	if (!cname)
+		return -EINVAL;
+	len_str = strlen(cname) + 2;
+	if (name)
+		len_str += strlen(name) + 2;
+	if (email)
+		len_str += strlen(email) + 2;
+	if (phone)
+		len_str += strlen(phone) + 2;
+	if (loc)
+		len_str += strlen(loc) + 2;
+	if (tool)
+		len_str += strlen(tool) + 2;
+	if (note)
+		len_str += strlen(note) + 2;
+	len_padded = (len_str + 4) & ~3;
+	len_with_hdr = len_padded + sizeof(struct rtcp_sr_rr_hdr);
+
+	if (endp->sdes_buf)
+		talloc_free(endp->sdes_buf);
+	endp->sdes_buf = talloc_size(endp, len_with_hdr);
+	if (!endp->sdes_buf)
+		return -ENOMEM;
+
+	hdr = (struct rtcp_sr_rr_hdr *) endp->sdes_buf;
+	hdr->v_p_rc = 0x81;
+	hdr->pt = RTCP_PT_SDES;
+	hdr->len = htons(len_with_hdr / 4 - 1);
+	hdr->ssrc = htonl(endp->tx.ssrc);
+	dp = endp->sdes_buf + sizeof(struct rtcp_sr_rr_hdr);
+	*dp++ = SDES_ITEM_CNAME;
+	*dp++ = len = strlen(cname);
+	memcpy(dp, cname, len);
+	dp += len;
+	if (name) {
+		*dp++ = SDES_ITEM_NAME;
+		*dp++ = len = strlen(name);
+		memcpy(dp, name, len);
+		dp += len;
+	}
+	if (email) {
+		*dp++ = SDES_ITEM_EMAIL;
+		*dp++ = len = strlen(email);
+		memcpy(dp, email, len);
+		dp += len;
+	}
+	if (phone) {
+		*dp++ = SDES_ITEM_PHONE;
+		*dp++ = len = strlen(phone);
+		memcpy(dp, phone, len);
+		dp += len;
+	}
+	if (loc) {
+		*dp++ = SDES_ITEM_LOC;
+		*dp++ = len = strlen(loc);
+		memcpy(dp, loc, len);
+		dp += len;
+	}
+	if (tool) {
+		*dp++ = SDES_ITEM_TOOL;
+		*dp++ = len = strlen(tool);
+		memcpy(dp, tool, len);
+		dp += len;
+	}
+	if (note) {
+		*dp++ = SDES_ITEM_NOTE;
+		*dp++ = len = strlen(note);
+		memcpy(dp, note, len);
+		dp += len;
+	}
+	memset(dp, 0, len_padded - len_str);
+
+	endp->sdes_len = len_with_hdr;
+	return 0;
+}