gprs_bssgp: add IE parser/generator for RIM Routing Information

The RIM Routing Information IE (see also 3GPP TS 48.018, section
11.3.70) is used to control the flow of BSSGP rim messages at the SGSN.

Change-Id: I6f88a9aeeb50a612d32e9efd23040c9740bc4f11
Related: SYS#5103
diff --git a/include/osmocom/gprs/gprs_bssgp.h b/include/osmocom/gprs/gprs_bssgp.h
index dfbd9b7..7077044 100644
--- a/include/osmocom/gprs/gprs_bssgp.h
+++ b/include/osmocom/gprs/gprs_bssgp.h
@@ -10,6 +10,7 @@
 #include <osmocom/gsm/prim.h>
 
 #include <osmocom/gprs/protocol/gsm_08_18.h>
+#include <osmocom/gprs/protocol/gsm_24_301.h>
 
 /* gprs_bssgp_util.c */
 
@@ -175,6 +176,37 @@
 int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid,
 			 uint16_t cid);
 
+enum bssgp_rim_routing_info_discr {
+	BSSGP_RIM_ROUTING_INFO_GERAN,
+	BSSGP_RIM_ROUTING_INFO_UTRAN,
+	BSSGP_RIM_ROUTING_INFO_EUTRAN,
+};
+
+/*! BSSGP RIM Routing information, see also 3GPP TS 48.018, section 11.3.70 */
+struct bssgp_rim_routing_info {
+	enum bssgp_rim_routing_info_discr discr;
+	union {
+		struct {
+			struct gprs_ra_id raid;
+			uint16_t cid;
+		} geran;
+		struct {
+			struct gprs_ra_id raid;
+			uint16_t rncid;
+		} utran;
+		struct {
+			struct osmo_eutran_tai tai;
+			/* See also 3GPP TS 36.413 9.2.1.37 and 3GPP TS 36.401 */
+			uint8_t global_enb_id[8];
+			uint8_t global_enb_id_len;
+		} eutran;
+	};
+};
+
+int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf,
+		       unsigned int len);
+int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri);
+
 /* Wrapper around TLV parser to parse BSSGP IEs */
 static inline int bssgp_tlv_parse(struct tlv_parsed *tp, const uint8_t *buf, int len)
 {