Change in libosmocore[master]: gsm0808_utils: Introduce gsm0808_msgb_put_cell_id_u()

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


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


Change subject: gsm0808_utils: Introduce gsm0808_msgb_put_cell_id_u()
......................................................................

gsm0808_utils: Introduce gsm0808_msgb_put_cell_id_u()

This function is doing the bulk work of encoding a given Cell
ID List item.  gsm0808_enc_cell_id_list2() is modified to be a
wrapper / loop around the new function.

The purpose of this is to expose Cell ID List Entry encoding
so that the upcoming CBSP protocol encoder can re-use this code.

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



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/87/13887/1

diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index 47c4e95..3a7beb7 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -93,6 +93,7 @@
 void gsm0808_cell_id_from_cgi(struct gsm0808_cell_id *cid, enum CELL_IDENT id_discr,
 			      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);
 
 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 99cf188..e825930 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -737,6 +737,46 @@
 	return (int)(elem - old_elem);
 }
 
+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) {
+	case CELL_IDENT_WHOLE_GLOBAL: {
+		const struct osmo_cell_global_id *id = &u->global;
+		struct gsm48_loc_area_id lai;
+		gsm48_generate_lai2(&lai, &id->lai);
+		memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));
+		msgb_put_u16(msg, id->cell_identity);
+		break;
+	}
+	case CELL_IDENT_LAC_AND_CI: {
+		const struct osmo_lac_and_ci_id *id = &u->lac_and_ci;
+		msgb_put_u16(msg, id->lac);
+		msgb_put_u16(msg, id->ci);
+		break;
+	}
+	case CELL_IDENT_CI:
+		msgb_put_u16(msg, u->ci);
+		break;
+	case CELL_IDENT_LAI_AND_LAC: {
+		const struct osmo_location_area_id *id = &u->lai_and_lac;
+		struct gsm48_loc_area_id lai;
+		gsm48_generate_lai2(&lai, id);
+		memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));
+		break;
+	}
+	case CELL_IDENT_LAC:
+		msgb_put_u16(msg, u->lac);
+		break;
+	case CELL_IDENT_BSS:
+	case CELL_IDENT_NO_CELL:
+		/* Does not have any list items */
+		break;
+	default:
+		/* Support for other identifier list types is not implemented. */
+		OSMO_ASSERT(false);
+	}
+}
+
 /*! Encode TS 08.08 Cell Identifier List IE
  *  \param[out] msg Message Buffer to which IE is to be appended
  *  \param[in] cil Cell ID List to be encoded
@@ -758,47 +798,8 @@
 	msgb_put_u8(msg, cil->id_discr & 0x0f);
 
 	OSMO_ASSERT(cil->id_list_len <= GSM0808_CELL_ID_LIST2_MAXLEN)
-	switch (cil->id_discr) {
-	case CELL_IDENT_WHOLE_GLOBAL:
-		for (i = 0; i < cil->id_list_len; i++) {
-			const struct osmo_cell_global_id *id = &cil->id_list[i].global;
-			struct gsm48_loc_area_id lai;
-			gsm48_generate_lai2(&lai, &id->lai);
-			memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));
-			msgb_put_u16(msg, id->cell_identity);
-		}
-		break;
-	case CELL_IDENT_LAC_AND_CI:
-		for (i = 0; i < cil->id_list_len; i++) {
-			const struct osmo_lac_and_ci_id *id = &cil->id_list[i].lac_and_ci;
-			msgb_put_u16(msg, id->lac);
-			msgb_put_u16(msg, id->ci);
-		}
-		break;
-	case CELL_IDENT_CI:
-		for (i = 0; i < cil->id_list_len; i++)
-			msgb_put_u16(msg, cil->id_list[i].ci);
-		break;
-	case CELL_IDENT_LAI_AND_LAC:
-		for (i = 0; i < cil->id_list_len; i++) {
-			const struct osmo_location_area_id *id = &cil->id_list[i].lai_and_lac;
-			struct gsm48_loc_area_id lai;
-			gsm48_generate_lai2(&lai, id);
-			memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));
-		}
-		break;
-	case CELL_IDENT_LAC:
-		for (i = 0; i < cil->id_list_len; i++)
-			msgb_put_u16(msg, cil->id_list[i].lac);
-		break;
-	case CELL_IDENT_BSS:
-	case CELL_IDENT_NO_CELL:
-		/* Does not have any list items */
-		break;
-	default:
-		/* Support for other identifier list types is not implemented. */
-		OSMO_ASSERT(false);
-	}
+	for (i = 0; i < cil->id_list_len; i++)
+		gsm0808_msgb_put_cell_id_u(msg, cil->id_discr, &cil->id_list[i]);
 
 	*tlv_len = (uint8_t) (msg->tail - old_tail);
 	return *tlv_len + 2;
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index adfa096..840bac9 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -242,6 +242,7 @@
 gsm0808_lcls_status_names;
 gsm0808_enc_lcls;
 gsm0808_dec_lcls;
+gsm0808_msgb_put_cell_id_u;
 
 gsm29118_msgb_alloc;
 gsm29118_create_alert_req;

-- 
To view, visit https://gerrit.osmocom.org/13887
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: I6cc567798e20365e6587e6b2988e834306d8c80c
Gerrit-Change-Number: 13887
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/9a9fe08e/attachment.html>


More information about the gerrit-log mailing list