Change in libosmocore[master]: gprs_bssgp: add utilities to send and parse BSSGP rim PDUs

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

dexter gerrit-no-reply at lists.osmocom.org
Thu Jan 7 21:03:11 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/22046 )


Change subject: gprs_bssgp: add utilities to send and parse BSSGP rim PDUs
......................................................................

gprs_bssgp: add utilities to send and parse BSSGP rim PDUs

At the moment libosmogb offers no convinient way to send RIM PDUs. Also
parsing an incoming RIM messages into destination, source routing
info and RIM container is not available.

Change-Id: I18134fd9938040d2facb6beee3732628b167ce8c
Related: SYS#5103
---
M include/osmocom/gprs/gprs_bssgp.h
M src/gb/gprs_bssgp_util.c
M src/gb/libosmogb.map
3 files changed, 130 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/46/22046/1

diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h
index d228c53..3caf91b 100644
--- a/include/osmocom/gprs/gprs_bssgp.h
+++ b/include/osmocom/gprs/gprs_bssgp.h
@@ -41,6 +41,19 @@
 /* Chapter 10.4.14: Status */
 int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg);
 
+/* Chapter 10.6.1: RAN-INFORMATION-REQUEST */
+struct bssgp_ran_information_pdu {
+	const uint8_t *routing_info_dest;
+	unsigned int routing_info_dest_len;
+	const uint8_t *routing_info_src;
+	unsigned int routing_info_src_len;
+	uint8_t rim_cont_iei;
+	const uint8_t *rim_cont;
+	unsigned int rim_cont_len;
+};
+int bssgp_tx_rim(struct bssgp_ran_information_pdu *pdu, uint16_t nsei);
+int bssgp_parse_rim_pdu(struct bssgp_ran_information_pdu *pdu, struct msgb *msg);
+
 enum bssgp_prim {
 	PRIM_BSSGP_DL_UD,
 	PRIM_BSSGP_UL_UD,
diff --git a/src/gb/gprs_bssgp_util.c b/src/gb/gprs_bssgp_util.c
index 92896c1..0cd59f0 100644
--- a/src/gb/gprs_bssgp_util.c
+++ b/src/gb/gprs_bssgp_util.c
@@ -588,3 +588,118 @@
 
 	return bssgp_ns_send(bssgp_ns_send_data, msg);
 }
+
+/* Chapter 10.6.1: RAN-INFORMATION-REQUEST */
+int bssgp_tx_rim(struct bssgp_ran_information_pdu *pdu, uint16_t nsei)
+{
+	struct msgb *msg = bssgp_msgb_alloc();
+	struct bssgp_normal_hdr *bgph =
+	    (struct bssgp_normal_hdr *)msgb_put(msg, sizeof(*bgph));
+
+	/* Find a suitable PDU based on the RIM container type (IEI) */
+	switch (pdu->rim_cont_iei) {
+	case BSSGP_IE_RI_REQ_RIM_CONTAINER:
+		bgph->pdu_type = BSSGP_PDUT_RAN_INFO_REQ;
+		break;
+	case BSSGP_IE_RI_RIM_CONTAINER:
+		bgph->pdu_type = BSSGP_PDUT_RAN_INFO;
+		break;
+	case BSSGP_IE_RI_APP_ERROR_RIM_CONT:
+		bgph->pdu_type = BSSGP_PDUT_RAN_INFO_APP_ERROR;
+		break;
+	case BSSGP_IE_RI_ACK_RIM_CONTAINER:
+		bgph->pdu_type = BSSGP_PDUT_RAN_INFO_ACK;
+		break;
+	case BSSGP_IE_RI_ERROR_RIM_COINTAINER:
+		bgph->pdu_type = BSSGP_PDUT_RAN_INFO_ERROR;
+		break;
+	default:
+		/* The caller must correctly specify the container type! */
+		OSMO_ASSERT(false);
+	}
+
+	LOGP(DLBSSGP, LOGL_NOTICE, "BSSGP BVCI=0 Tx RIM-PDU:%s\n",
+	     bssgp_pdu_str(bgph->pdu_type));
+
+	/* Check if anything is missing, all those fields are mandatory. The
+	 * caller must make sure that the fields are present. */
+	OSMO_ASSERT(pdu->routing_info_dest_len > 0 && pdu->routing_info_dest);
+	OSMO_ASSERT(pdu->routing_info_src_len > 0 && pdu->routing_info_src);
+	OSMO_ASSERT(pdu->rim_cont_iei != 0 && pdu->rim_cont_len > 0
+		    && pdu->rim_cont);
+
+	/* Encode BSSGP PDU */
+	msgb_nsei(msg) = nsei;
+	msgb_bvci(msg) = 0;	/* Signalling */
+	msgb_tvlv_put(msg, BSSGP_IE_RIM_ROUTING_INFO,
+		      pdu->routing_info_dest_len, pdu->routing_info_dest);
+	msgb_tvlv_put(msg, BSSGP_IE_RIM_ROUTING_INFO, pdu->routing_info_src_len,
+		      pdu->routing_info_src);
+	msgb_tvlv_put(msg, pdu->rim_cont_iei, pdu->rim_cont_len, pdu->rim_cont);
+
+	return bssgp_ns_send(bssgp_ns_send_data, msg);
+}
+
+/* Parse a given message buffer into a rim-pdu struct */
+int bssgp_parse_rim_pdu(struct bssgp_ran_information_pdu *pdu, struct msgb *msg)
+{
+	struct tlv_parsed tp[2];
+	struct bssgp_normal_hdr *bgph =
+	    (struct bssgp_normal_hdr *)msgb_bssgph(msg);
+	int data_len;
+	int rc;
+	uint16_t nsei = msgb_nsei(msg);
+
+	data_len = msgb_bssgp_len(msg) - sizeof(*bgph);
+
+	rc = tlv_parse2(tp, ARRAY_SIZE(tp), &tvlv_att_def, bgph->data, data_len,
+			0, 0);
+	if (rc < 0)
+		return -EINVAL;
+
+	if (TLVP_PRESENT(&tp[0], BSSGP_IE_RIM_ROUTING_INFO)) {
+		pdu->routing_info_dest =
+		    TLVP_VAL(&tp[0], BSSGP_IE_RIM_ROUTING_INFO);
+		pdu->routing_info_dest_len =
+		    TLVP_LEN(&tp[0], BSSGP_IE_RIM_ROUTING_INFO);
+	} else {
+		LOGP(DLBSSGP, LOGL_ERROR,
+		     "BSSGP RIM (NSEI=%u) missing Destination Cell Identifier IE\n",
+		     nsei);
+		return -EINVAL;
+	}
+
+	if (TLVP_PRESENT(&tp[0], BSSGP_IE_RIM_ROUTING_INFO)) {
+		pdu->routing_info_src =
+		    TLVP_VAL(&tp[1], BSSGP_IE_RIM_ROUTING_INFO);
+		pdu->routing_info_src_len =
+		    TLVP_LEN(&tp[1], BSSGP_IE_RIM_ROUTING_INFO);
+	} else {
+		LOGP(DLBSSGP, LOGL_ERROR,
+		     "BSSGP RIM (NSEI=%u) missing Source Cell Identifier IE\n",
+		     nsei);
+		return -EINVAL;
+	}
+
+	if (TLVP_PRESENT(&tp[0], BSSGP_IE_RI_REQ_RIM_CONTAINER))
+		pdu->rim_cont_iei = BSSGP_IE_RI_REQ_RIM_CONTAINER;
+	else if (TLVP_PRESENT(&tp[0], BSSGP_IE_RI_RIM_CONTAINER))
+		pdu->rim_cont_iei = BSSGP_IE_RI_RIM_CONTAINER;
+	else if (TLVP_PRESENT(&tp[0], BSSGP_IE_RI_APP_ERROR_RIM_CONT))
+		pdu->rim_cont_iei = BSSGP_IE_RI_APP_ERROR_RIM_CONT;
+	else if (TLVP_PRESENT(&tp[0], BSSGP_IE_RI_ACK_RIM_CONTAINER))
+		pdu->rim_cont_iei = BSSGP_IE_RI_ACK_RIM_CONTAINER;
+	else if (TLVP_PRESENT(&tp[0], BSSGP_IE_RI_ERROR_RIM_COINTAINER))
+		pdu->rim_cont_iei = BSSGP_IE_RI_ERROR_RIM_COINTAINER;
+	else {
+		LOGP(DLBSSGP, LOGL_ERROR,
+		     "BSSGP RIM (NSEI=%u) missing or wrong RIM Container IE -- rejected\n",
+		     nsei);
+		return -EINVAL;
+	}
+
+	pdu->rim_cont = TLVP_VAL(&tp[0], pdu->rim_cont_iei);
+	pdu->rim_cont_len = TLVP_LEN(&tp[0], pdu->rim_cont_iei);
+
+	return 0;
+}
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index 5c029b0..f49f9bd 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -14,6 +14,7 @@
 bssgp_msgb_tlli_put;
 bssgp_msgb_ra_put;
 bssgp_parse_cell_id;
+bssgp_parse_rim_pdu;
 bssgp_parse_rim_ri;
 bssgp_set_bssgp_callback;
 bssgp_tx_bvc_block;
@@ -32,6 +33,7 @@
 bssgp_tx_resume;
 bssgp_tx_resume_ack;
 bssgp_tx_resume_nack;
+bssgp_tx_rim;
 bssgp_tx_simple_bvci;
 bssgp_tx_status;
 bssgp_tx_suspend;

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I18134fd9938040d2facb6beee3732628b167ce8c
Gerrit-Change-Number: 22046
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210107/6542c208/attachment.htm>


More information about the gerrit-log mailing list