gprs_bssgp: add handling for BSSGP RIM primitives

Receive and forward RIM messages to bssgp_prim_cb()

Change-Id: Idfd0a65872a2cc6089885afd8d31b0b029d85d47
Related: SYS#5103
diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h
index 7077044..d228c53 100644
--- a/include/osmocom/gprs/gprs_bssgp.h
+++ b/include/osmocom/gprs/gprs_bssgp.h
@@ -56,6 +56,8 @@
 	PRIM_NM_BVC_BLOCK,
 	PRIM_NM_BVC_UNBLOCK,
 	PRIM_NM_STATUS,
+
+        PRIM_BSSGP_RIM_PDU_TRANSFER,
 };
 
 struct osmo_bssgp_prim {
diff --git a/include/osmocom/gsm/prim.h b/include/osmocom/gsm/prim.h
index e7a60e3..045e353 100644
--- a/include/osmocom/gsm/prim.h
+++ b/include/osmocom/gsm/prim.h
@@ -16,4 +16,6 @@
 	SAP_BSSGP_PFM,
 
 	SAP_NS,
+
+	SAP_BSSGP_RIM,
 };
diff --git a/src/gb/gprs_bssgp.c b/src/gb/gprs_bssgp.c
index 09f6373..fd2a48c 100644
--- a/src/gb/gprs_bssgp.c
+++ b/src/gb/gprs_bssgp.c
@@ -734,6 +734,39 @@
 	return bssgp_prim_cb(&nmp.oph, NULL);
 }
 
+static int bssgp_rx_rim(struct msgb *msg, struct tlv_parsed *tp, uint16_t bvci)
+{
+	struct osmo_bssgp_prim nmp;
+	uint16_t nsei = msgb_nsei(msg);
+	struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *)msgb_bssgph(msg);
+	enum bssgp_prim prim;
+
+	DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx RIM-PDU:%s\n", bvci, bssgp_pdu_str(bgph->pdu_type));
+
+	/* Specify PRIM type based on the RIM PDU */
+	switch (bgph->pdu_type) {
+	case BSSGP_PDUT_RAN_INFO:
+	case BSSGP_PDUT_RAN_INFO_REQ:
+	case BSSGP_PDUT_RAN_INFO_ACK:
+	case BSSGP_PDUT_RAN_INFO_ERROR:
+	case BSSGP_PDUT_RAN_INFO_APP_ERROR:
+		prim = PRIM_BSSGP_RIM_PDU_TRANSFER;
+		break;
+	default:
+		/* Caller already makes sure that this can't happen. */
+		OSMO_ASSERT(false);
+	}
+
+	/* Send BSSGP RIM indication to NM */
+	memset(&nmp, 0, sizeof(nmp));
+	nmp.nsei = nsei;
+	nmp.bvci = bvci;
+	nmp.tp = tp;
+	osmo_prim_init(&nmp.oph, SAP_BSSGP_RIM, prim, PRIM_OP_INDICATION, msg);
+	bssgp_prim_cb(&nmp.oph, NULL);
+
+	return 0;
+}
 
 /* One element (msgb) in a BSSGP Flow Control queue */
 struct bssgp_fc_queue_element {
@@ -1159,6 +1192,15 @@
 	case BSSGP_PDUT_STATUS:
 		/* This is already handled in bssgp_rcvmsg() */
 		break;
+
+	case BSSGP_PDUT_RAN_INFO:
+	case BSSGP_PDUT_RAN_INFO_REQ:
+	case BSSGP_PDUT_RAN_INFO_ACK:
+	case BSSGP_PDUT_RAN_INFO_ERROR:
+	case BSSGP_PDUT_RAN_INFO_APP_ERROR:
+		bssgp_rx_rim(msg, tp, bvci);
+		break;
+
 	/* those only exist in the SGSN -> BSS direction */
 	case BSSGP_PDUT_PAGING_PS:
 	case BSSGP_PDUT_PAGING_CS: