dexter has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-bts/+/32630 )


Change subject: l1sap: Accept RFC5993 and TS 101.318 HR GSM payload
......................................................................

l1sap: Accept RFC5993 and TS 101.318 HR GSM payload

Unfotunately there are two different RTP formats for HR GSM specified
and it is unclear which should be used with GSM networks. Also each BTS
model may support only either one or the other format.

Let's use the BTS feature flags to determine which format the BTS model
supports and then let's use this information to convert incoming RTP
packets into the supported format. Doing so we will make sure that
always both formats are accepted.

Related: OS#5688
Change-Id: I9419b40c1171876879d41aba4f51c93e8ef5673c
---
M src/common/l1sap.c
1 file changed, 56 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/30/32630/1

diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index 08bf0d3..5a9cb09 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -1946,10 +1946,43 @@
        if (lchan->loopback)
                return;

-       msg = l1sap_msgb_alloc(rtp_pl_len);
-       if (!msg)
-               return;
-       memcpy(msgb_put(msg, rtp_pl_len), rtp_pl, rtp_pl_len);
+       /* There are two different specifications that describe how HR GSM 
audio should be encapsulated in RTP frames:
+        * RFC 5993 and ETSI TS 101.318 (TIPHON). In order to be able to accept 
both formats we convert them on
+        * reception depending on what the particular BTS model supports. In 
case the BTS flags indicate that both
+        * formats are supported (either by setting both or none of the flags), 
no conversion will be carried out. */
+       switch (lchan->tch_mode) {
+       case GSM48_CMODE_SPEECH_V1:
+               if (lchan->type == GSM_LCHAN_TCH_H) {
+                       bool rfc5993 =
+                           bts_internal_flag_get(lchan->ts->trx->bts, 
BTS_INTERNAL_FLAG_SPEECH_H_V1_RTP_RFC5993);
+                       bool ts101318 =
+                           bts_internal_flag_get(lchan->ts->trx->bts, 
BTS_INTERNAL_FLAG_SPEECH_H_V1_RTP_TS101318);
+
+                       /* The only difference between TS 101.318 and RFC 5993 
is that RFC 5993 specifies an additional
+                        * one byte TOC header in front of the audio payload. 
(See also: RFC 5993, section 5.2) */
+                       if (OSMO_UNLIKELY(rfc5993 && !ts101318 && rtp_pl_len == 
GSM_HR_BYTES_RTP_TS101318)) {
+                               msg = l1sap_msgb_alloc(rtp_pl_len + 1);
+                               if (!msg)
+                                       return;
+                               msgb_put_u8(msg, 0x00);
+                               memcpy(msgb_put(msg, rtp_pl_len), rtp_pl, 
rtp_pl_len);
+                               break;
+                       } else if (OSMO_UNLIKELY(ts101318 && !rfc5993 && 
rtp_pl_len == GSM_HR_BYTES_RTP_RFC5993)) {
+                               msg = l1sap_msgb_alloc(rtp_pl_len - 1);
+                               if (!msg)
+                                       return;
+                               memcpy(msgb_put(msg, rtp_pl_len - 1), rtp_pl + 
1, rtp_pl_len - 1);
+                               break;
+                       }
+               }
+               /* fallthrough, no conversion required */
+       default:
+               msg = l1sap_msgb_alloc(rtp_pl_len);
+               if (!msg)
+                       return;
+               memcpy(msgb_put(msg, rtp_pl_len), rtp_pl, rtp_pl_len);
+       }
+
        msgb_pull(msg, sizeof(struct osmo_phsap_prim));

        /* Store RTP header Marker bit in control buffer */

--
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/32630
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I9419b40c1171876879d41aba4f51c93e8ef5673c
Gerrit-Change-Number: 32630
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pma...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to