Change in libosmocore[master]: gsm0808_utils: Add gsm0808_decode_cell_id_u()

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon May 6 21:21:39 UTC 2019


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/13888


Change subject: gsm0808_utils: Add gsm0808_decode_cell_id_u()
......................................................................

gsm0808_utils: Add gsm0808_decode_cell_id_u()

This function parses a single Cell ID list element into a
'union gsm0808_cell_id_u'.  This function is going to be used
by the upcoming CBSP support.

Related: OS#3537
Change-Id: I08b33881667aa32f01e53ccb70d44d5b79c7c986
---
M include/osmocom/gsm/gsm0808_utils.h
M src/gsm/gsm0808_utils.c
M src/gsm/libosmogsm.map
3 files changed, 60 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/88/13888/1

diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 3a7beb7..fa9d18e 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -94,6 +94,7 @@
 			      const struct osmo_cell_global_id *cgi);
 int gsm0808_cell_id_to_cgi(struct osmo_cell_global_id *cgi, const struct gsm0808_cell_id *cid);
 void gsm0808_msgb_put_cell_id_u(struct msgb *msg, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u);
+int gsm0808_decode_cell_id_u(union gsm0808_cell_id_u *out, enum CELL_IDENT discr, const uint8_t *buf, unsigned int len);
 
 uint8_t gsm0808_enc_cause(struct msgb *msg, uint16_t cause);
 uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index e825930..fe86031 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -49,6 +49,17 @@
  *  \file gsm0808_utils.c
  */
 
+/* Decode 5-byte LAI list element data (see TS 08.08 3.2.2.27) into MCC/MNC/LAC. */
+static void decode_lai(const uint8_t *data, struct osmo_location_area_id *decoded)
+{
+	struct gsm48_loc_area_id lai;
+
+	/* Copy data to stack to prevent unaligned access in gsm48_decode_lai2(). */
+	memcpy(&lai, data, sizeof(lai)); /* don't byte swap yet */
+
+	gsm48_decode_lai2(&lai, decoded);
+}
+
 /*! Encode TS 08.08 AoIP Cause IE
  *  \param[out] msg Message Buffer to which to append IE
  *  \param[in] cause Cause code to be used in IE
@@ -737,6 +748,53 @@
 	return (int)(elem - old_elem);
 }
 
+/*! Decode a single GSM 08.08 Cell ID list element payload
+ *  \param[out] out caller-provided output union
+ *  \param[in] discr Cell ID discriminator describing type to be decoded
+ *  \param[in] buf User-provided input buffer containing binary Cell ID list element
+ *  \param[in] len Length of buf
+ *  \returns 0 on success; negative on error */
+int gsm0808_decode_cell_id_u(union gsm0808_cell_id_u *out, enum CELL_IDENT discr, const uint8_t *buf, unsigned int len)
+{
+	switch (discr) {
+	case CELL_IDENT_WHOLE_GLOBAL:
+		if (len < 7)
+			return -EINVAL;
+		decode_lai(buf, &out->global.lai);
+		out->global.cell_identity = osmo_load16be(buf + sizeof(struct gsm48_loc_area_id));
+		break;
+	case CELL_IDENT_LAC_AND_CI:
+		if (len < 4)
+			return -EINVAL;
+		out->lac_and_ci.lac = osmo_load16be(buf);
+		out->lac_and_ci.ci = osmo_load16be(buf + sizeof(uint16_t));
+		break;
+	case CELL_IDENT_CI:
+		if (len < 2)
+			return -EINVAL;
+		out->ci = osmo_load16be(buf);
+		break;
+	case CELL_IDENT_LAI_AND_LAC:
+		if (len < 5)
+			return -EINVAL;
+		decode_lai(buf, &out->lai_and_lac);
+		break;
+	case CELL_IDENT_LAC:
+		if (len < 2)
+			return -EINVAL;
+		out->lac = osmo_load16be(buf);
+		break;
+	case CELL_IDENT_BSS:
+	case CELL_IDENT_NO_CELL:
+		/* Does not have any list items */
+		break;
+	default:
+		/* Remaining cell identification types are not implemented. */
+		return -EINVAL;
+	}
+	return 0;
+}
+
 void gsm0808_msgb_put_cell_id_u(struct msgb *msg, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u)
 {
 	switch (id_discr) {
@@ -846,17 +904,6 @@
 	return *tlv_len + 2;
 }
 
-/* Decode 5-byte LAI list element data (see TS 08.08 3.2.2.27) into MCC/MNC/LAC. */
-static void decode_lai(const uint8_t *data, struct osmo_location_area_id *decoded)
-{
-	struct gsm48_loc_area_id lai;
-
-	/* Copy data to stack to prevent unaligned access in gsm48_decode_lai2(). */
-	memcpy(&lai, data, sizeof(lai)); /* don't byte swap yet */
-
-	gsm48_decode_lai2(&lai, decoded);
-}
-
 static int parse_cell_id_global_list(struct gsm0808_cell_id_list2 *cil, const uint8_t *data, size_t remain,
 				     size_t *consumed)
 {
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 840bac9..c095650 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -243,6 +243,7 @@
 gsm0808_enc_lcls;
 gsm0808_dec_lcls;
 gsm0808_msgb_put_cell_id_u;
+gsm0808_decode_cell_id_u;
 
 gsm29118_msgb_alloc;
 gsm29118_create_alert_req;

-- 
To view, visit https://gerrit.osmocom.org/13888
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I08b33881667aa32f01e53ccb70d44d5b79c7c986
Gerrit-Change-Number: 13888
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190506/bde953fc/attachment.html>


More information about the gerrit-log mailing list