[PATCH] osmo-bts[master]: Prepare for extended SI2quater support

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Fri Apr 28 12:44:58 UTC 2017


Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/2313

to look at the new patch set (#3).

Prepare for extended SI2quater support

SI2quater support as per 3GPP TS 44.018 will require chnages to the way
System Information is stored because it uses 1:n instead of 1:1 mapping
between SI type and generated SI content. This should not affect other
SI types though. To facilitate this transition:

* convert the code to always use GSM_LCHAN_SI helper instead of
  accessing buffer directly
* move duplicated code to inline function
* add logging for buffer truncation and corresponding length values

Requires I74e4e3cb86364cec869a1472a41b4a95af0d50dd in OpenBSC.

Change-Id: Ie97be6ead6ce6d2d425fbfac8429bb90afb95acc
Related: RT#8792
---
M src/common/rsl.c
M src/common/sysinfo.c
M tests/misc/misc_test.c
3 files changed, 44 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/13/2313/3

diff --git a/src/common/rsl.c b/src/common/rsl.c
index 1d0bcea..b3d8b13 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -286,14 +286,17 @@
 	/* 9.3.39 Full BCCH Information */
 	if (TLVP_PRESENT(&tp, RSL_IE_FULL_BCCH_INFO)) {
 		uint8_t len = TLVP_LEN(&tp, RSL_IE_FULL_BCCH_INFO);
-		if (len > sizeof(sysinfo_buf_t))
+		if (len > sizeof(sysinfo_buf_t)) {
+			LOGP(DRSL, LOGL_ERROR, "Truncating received Full BCCH Info (%u -> %zu) for SI%s\n",
+			     len, sizeof(sysinfo_buf_t), get_value_string(osmo_sitype_strs, osmo_si));
 			len = sizeof(sysinfo_buf_t);
+		}
 		bts->si_valid |= (1 << osmo_si);
 		memset(bts->si_buf[osmo_si], 0x2b, sizeof(sysinfo_buf_t));
 		memcpy(bts->si_buf[osmo_si],
 			TLVP_VAL(&tp, RSL_IE_FULL_BCCH_INFO), len);
-		LOGP(DRSL, LOGL_INFO, " Rx RSL BCCH INFO (SI%s)\n",
-			get_value_string(osmo_sitype_strs, osmo_si));
+		LOGP(DRSL, LOGL_INFO, " Rx RSL BCCH INFO (SI%s, %u bytes)\n",
+		     get_value_string(osmo_sitype_strs, osmo_si), len);
 
 		if (SYSINFO_TYPE_3 == osmo_si && trx->nr == 0 &&
 		    num_agch(trx, "RSL") != 1) {
@@ -432,6 +435,34 @@
 				     TLVP_VAL(&tp, RSL_IE_SMSCB_MSG));
 }
 
+/* 'buf' must be caller-allocated and hold at least len + 2 or sizeof(sysinfo_buf_t) bytes */
+static inline void lapdm_ui_prefix(uint8_t *buf, uint32_t *valid, const uint8_t *current, uint8_t osmo_si, uint16_t len)
+{
+	/* We have to pre-fix with the two-byte LAPDM UI header */
+	if (len > sizeof(sysinfo_buf_t) - 2) {
+		LOGP(DRSL, LOGL_ERROR, "Truncating received SI%s (%u -> %zu) to prepend LAPDM UI header (2 bytes)\n",
+		     get_value_string(osmo_sitype_strs, osmo_si), len, sizeof(sysinfo_buf_t) - 2);
+		len = sizeof(sysinfo_buf_t) - 2;
+	}
+
+	(*valid) |= (1 << osmo_si);
+	buf[0] = 0x03;	/* C/R + EA */
+	buf[1] = 0x03;	/* UI frame */
+
+	memset(buf + 2, GSM_MACBLOCK_PADDING, sizeof(sysinfo_buf_t) - 2);
+	memcpy(buf + 2, current, len);
+}
+
+static inline void lapdm_ui_prefix_bts(struct gsm_bts *bts, const uint8_t *current, uint8_t osmo_si, uint16_t len)
+{
+	lapdm_ui_prefix(GSM_BTS_SI(bts, osmo_si), &bts->si_valid, current, osmo_si, len);
+}
+
+static inline void lapdm_ui_prefix_lchan(struct gsm_lchan *lchan, const uint8_t *current, uint8_t osmo_si, uint16_t len)
+{
+	lapdm_ui_prefix(GSM_LCHAN_SI(lchan, osmo_si), &lchan->si.valid, current, osmo_si, len);
+}
+
 /* 8.6.2 SACCH FILLING */
 static int rsl_rx_sacch_fill(struct gsm_bts_trx *trx, struct msgb *msg)
 {
@@ -457,17 +488,10 @@
 	}
 	if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) {
 		uint16_t len = TLVP_LEN(&tp, RSL_IE_L3_INFO);
-		/* We have to pre-fix with the two-byte LAPDM UI header */
-		if (len > sizeof(sysinfo_buf_t)-2)
-			len = sizeof(sysinfo_buf_t)-2;
-		bts->si_valid |= (1 << osmo_si);
-		bts->si_buf[osmo_si][0] = 0x03;	/* C/R + EA */
-		bts->si_buf[osmo_si][1] = 0x03;	/* UI frame */
-		memset(bts->si_buf[osmo_si]+2, 0x2b, sizeof(sysinfo_buf_t)-2);
-		memcpy(bts->si_buf[osmo_si]+2,
-			TLVP_VAL(&tp, RSL_IE_L3_INFO), len);
-		LOGP(DRSL, LOGL_INFO, " Rx RSL SACCH FILLING (SI%s)\n",
-			get_value_string(osmo_sitype_strs, osmo_si));
+		lapdm_ui_prefix_bts(bts, TLVP_VAL(&tp, RSL_IE_L3_INFO), osmo_si, len);
+
+		LOGP(DRSL, LOGL_INFO, " Rx RSL SACCH FILLING (SI%s, %u bytes)\n",
+		     get_value_string(osmo_sitype_strs, osmo_si), len);
 	} else {
 		bts->si_valid &= ~(1 << osmo_si);
 		LOGP(DRSL, LOGL_INFO, " Rx RSL Disabling SACCH FILLING (SI%s)\n",
@@ -699,8 +723,7 @@
 			continue;
 		}
 		lchan->si.valid |= osmo_si_shifted;
-		memcpy(lchan->si.buf[osmo_si], bts->si_buf[osmo_si],
-			sizeof(sysinfo_buf_t));
+		memcpy(GSM_LCHAN_SI(lchan, osmo_si), GSM_BTS_SI(bts, osmo_si), sizeof(sysinfo_buf_t));
 	}
 }
 
@@ -885,7 +908,6 @@
 			uint8_t rsl_si = *cur++;
 			uint8_t si_len = *cur++;
 			uint8_t osmo_si;
-			uint8_t copy_len;
 
 			if (!OSMO_IN_ARRAY(rsl_si, rsl_sacch_sitypes))
 				return rsl_tx_error_report(msg->trx, RSL_ERR_IE_CONTENT);
@@ -896,15 +918,7 @@
 				return rsl_tx_error_report(msg->trx, RSL_ERR_IE_CONTENT);
 			}
 
-			copy_len = si_len;
-			/* We have to pre-fix with the two-byte LAPDM UI header */
-			if (copy_len > sizeof(sysinfo_buf_t)-2)
-				copy_len = sizeof(sysinfo_buf_t)-2;
-			lchan->si.valid |= (1 << osmo_si);
-			lchan->si.buf[osmo_si][0] = 0x03;
-			lchan->si.buf[osmo_si][1] = 0x03;
-			memset(lchan->si.buf[osmo_si]+2, 0x2b, sizeof(sysinfo_buf_t)-2);
-			memcpy(lchan->si.buf[osmo_si]+2, cur, copy_len);
+			lapdm_ui_prefix_lchan(lchan, cur, osmo_si, si_len);
 
 			cur += si_len;
 			if (cur >= val + tot_len) {
@@ -1337,15 +1351,8 @@
 	}
 	if (TLVP_PRESENT(&tp, RSL_IE_L3_INFO)) {
 		uint16_t len = TLVP_LEN(&tp, RSL_IE_L3_INFO);
-		/* We have to pre-fix with the two-byte LAPDM UI header */
-		if (len > sizeof(sysinfo_buf_t)-2)
-			len = sizeof(sysinfo_buf_t)-2;
-		lchan->si.valid |= (1 << osmo_si);
-		lchan->si.buf[osmo_si][0] = 0x03;
-		lchan->si.buf[osmo_si][1] = 0x03;
-		memset(lchan->si.buf[osmo_si]+2, 0x2b, sizeof(sysinfo_buf_t)-2);
-		memcpy(lchan->si.buf[osmo_si]+2,
-			TLVP_VAL(&tp, RSL_IE_L3_INFO), len);
+		lapdm_ui_prefix_lchan(lchan, TLVP_VAL(&tp, RSL_IE_L3_INFO), osmo_si, len);
+
 		LOGP(DRSL, LOGL_INFO, "%s Rx RSL SACCH FILLING (SI%s)\n",
 			gsm_lchan_name(lchan),
 			get_value_string(osmo_sitype_strs, osmo_si));
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index 177ed58..d8671c8 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -154,7 +154,7 @@
 		if (!(lchan->si.valid & (1 << tmp)))
 			continue;
 		lchan->si.last = tmp;
-		return lchan->si.buf[tmp];
+		return GSM_LCHAN_SI(lchan, tmp);
 	}
 	return NULL;
 }
diff --git a/tests/misc/misc_test.c b/tests/misc/misc_test.c
index 80dd317..c2918fb 100644
--- a/tests/misc/misc_test.c
+++ b/tests/misc/misc_test.c
@@ -142,7 +142,7 @@
 	/* initialize the input. */
 	for (i = 1; i < _MAX_SYSINFO_TYPE; ++i) {
 		lchan.si.valid |= (1 << i);
-		memset(&lchan.si.buf[i], i, sizeof(lchan.si.buf[i]));
+		memset(GSM_LCHAN_SI(&lchan, i), i, GSM_MACBLOCK_LEN);
 	}
 
 	/* It will start with '1' */

-- 
To view, visit https://gerrit.osmocom.org/2313
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ie97be6ead6ce6d2d425fbfac8429bb90afb95acc
Gerrit-PatchSet: 3
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list