Change in osmo-bts[master]: sysinfo.c: Fix SI4 GPRS patching which overwrote CBCH IE

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/.

laforge gerrit-no-reply at lists.osmocom.org
Sun Jan 3 09:23:22 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bts/+/21922 )

Change subject: sysinfo.c: Fix SI4 GPRS patching which overwrote CBCH IE
......................................................................

sysinfo.c: Fix SI4 GPRS patching which overwrote CBCH IE

In Change-Id I1fd513ea03297918d15d4b28ed454f9b6dd6ebfa we introduced
patching of SI4 to indicate GPRS presence in terms of PCU connection
status.  Unfortauntely this didn't account for optional IEs being
present in SI4, and hence overwrote any CBCH related information
elements, if present.

This in turn meant that since the above-mentioned commit, you could
have either a GPRS-capable, network, or a Cell Broadcast capable one.

Change-Id: I0ee0cf736e2fb74a6759a68101f699b4ec2ef54e
Related: OS#3075
---
M include/osmo-bts/bts.h
M src/common/rsl.c
M src/common/sysinfo.c
3 files changed, 43 insertions(+), 9 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

Objections:
  fixeria: I would prefer this is not merged as is



diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index 2edc20e..6d8b570 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -377,6 +377,7 @@
 uint8_t *bts_sysinfo_get(struct gsm_bts *bts, const struct gsm_time *g_time);
 void regenerate_si3_restoctets(struct gsm_bts *bts);
 void regenerate_si4_restoctets(struct gsm_bts *bts);
+int get_si4_ro_offset(const uint8_t *si4_buf);
 uint8_t *lchan_sacch_get(struct gsm_lchan *lchan);
 int lchan_init_lapdm(struct gsm_lchan *lchan);
 
diff --git a/src/common/rsl.c b/src/common/rsl.c
index ef23039..8e27e77 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -380,13 +380,16 @@
 			regenerate_si3_restoctets(bts);
 		} else if (SYSINFO_TYPE_4 == osmo_si) {
 			/* decode original SI4 Rest Octets as sent by BSC */
-			const uint8_t *si4_ro_buf = (uint8_t *) GSM_BTS_SI(bts, osmo_si);
-			si4_ro_buf += offsetof(struct gsm48_system_information_type_4, data);
-			osmo_gsm48_rest_octets_si4_decode(&bts->si4_ro_decoded, si4_ro_buf,
-							  GSM_MACBLOCK_LEN - offsetof(struct gsm48_system_information_type_4, data));
-			/* patch out GPRS indicator from binary if PCU is not connected; will be enabled
-			 * after PCU connects */
-			regenerate_si4_restoctets(bts);
+			const uint8_t *si4 = (uint8_t *) GSM_BTS_SI(bts, osmo_si);
+			int si4_ro_offset = get_si4_ro_offset(si4);
+			if (si4_ro_offset < GSM_MACBLOCK_LEN) {
+				osmo_gsm48_rest_octets_si4_decode(&bts->si4_ro_decoded,
+								  si4 + si4_ro_offset,
+								  GSM_MACBLOCK_LEN - si4_ro_offset);
+				/* patch out GPRS indicator from binary if PCU is not connected; will be
+				 * enabled after PCU connects */
+				regenerate_si4_restoctets(bts);
+			}
 		}
 
 		if (SYSINFO_TYPE_13 == osmo_si)
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index f3deb0d..9eea539 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -1,4 +1,4 @@
-/* (C) 2011-2019 by Harald Welte <laforge at gnumonks.org>
+/* (C) 2011-2020 by Harald Welte <laforge at gnumonks.org>
  *
  * All Rights Reserved
  *
@@ -18,6 +18,7 @@
  */
 
 #include <stdint.h>
+#include <errno.h>
 
 #include <osmocom/gsm/gsm_utils.h>
 #include <osmocom/gsm/sysinfo.h>
@@ -212,11 +213,34 @@
 	osmo_gsm48_rest_octets_si3_encode(si3_buf + si3_size, &si3ro_tmp);
 }
 
+/* get the offset of the SI4 rest octets */
+int get_si4_ro_offset(const uint8_t *si4_buf)
+{
+	const struct gsm48_system_information_type_4 *si4 =
+					(const struct gsm48_system_information_type_4 *) si4_buf;
+	int si4_size;
+
+	/* start with the length of the mandatory part */
+	si4_size = offsetof(struct gsm48_system_information_type_4, data);
+	/* then add optional parts, if any */
+	if (si4->data[0] == GSM48_IE_CBCH_CHAN_DESC) {
+		/* fixed 4-byte TV IE, see Table 9.1.36.1 of TS 44.018 */
+		si4_size += 4;
+		if (si4->data[4] == GSM48_IE_CBCH_MOB_AL)
+			si4_size += TLV_GROSS_LEN(si4->data[5]);
+	}
+
+	if (si4_size >= GSM_MACBLOCK_LEN)
+		return -EINVAL;
+
+	return si4_size;
+}
+
 /* re-generate SI4 restoctets with GPRS indicator depending on the PCU socket connection state */
 void regenerate_si4_restoctets(struct gsm_bts *bts)
 {
 	uint8_t *si4_buf = GSM_BTS_SI(bts, SYSINFO_TYPE_4);
-	size_t si4_size = offsetof(struct gsm48_system_information_type_4, data);
+	size_t si4_size;
 	struct osmo_gsm48_si_ro_info si4ro_tmp;
 
 	/* If BSC has never set SI4, there's nothing to patch */
@@ -227,6 +251,12 @@
 	if (!bts->si4_ro_decoded.gprs_ind.present)
 		return;
 
+	si4_size = get_si4_ro_offset(si4_buf);
+	if (si4_size < 0) {
+		LOGP(DPCU, LOGL_ERROR, "Cannot parse SI4, hence not patching GPRS indicator\n");
+		return;
+	}
+
 	/* Create a temporary copy and patch that, if no PCU is around */
 	si4ro_tmp = bts->si4_ro_decoded;
 	if (!pcu_connected()) {

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

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I0ee0cf736e2fb74a6759a68101f699b4ec2ef54e
Gerrit-Change-Number: 21922
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210103/7a42d7d2/attachment.htm>


More information about the gerrit-log mailing list