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
diff --git a/src/gb/gprs_bssgp_rim.c b/src/gb/gprs_bssgp_rim.c
index 0dc6d21..7094f5f 100644
--- a/src/gb/gprs_bssgp_rim.c
+++ b/src/gb/gprs_bssgp_rim.c
@@ -96,6 +96,7 @@
 {
 	int rc;
 	struct gprs_ra_id raid_temp;
+	int len;
 
 	buf[0] = ri->discr & 0x0f;
 	buf++;
@@ -105,11 +106,13 @@
 		rc = bssgp_create_cell_id(buf, &ri->geran.raid, ri->geran.cid);
 		if (rc < 0)
 			return -EINVAL;
-		return rc + 1;
+		len = rc + 1;
+		break;
 	case BSSGP_RIM_ROUTING_INFO_UTRAN:
 		gsm48_encode_ra((struct gsm48_ra_id *)buf, &ri->utran.raid);
 		osmo_store16be(ri->utran.rncid, buf + 6);
-		return 9;
+		len = 9;
+		break;
 	case BSSGP_RIM_ROUTING_INFO_EUTRAN:
 		/* Note: 3GPP TS 24.301 Figure 9.9.3.32.1 and 3GPP TS 24.008
 		 * Figure 10.5.130 specify MCC/MNC encoding in the same way,
@@ -126,10 +129,14 @@
 			    sizeof(ri->eutran.global_enb_id));
 		memcpy(buf + 5, ri->eutran.global_enb_id,
 		       ri->eutran.global_enb_id_len);
-		return ri->eutran.global_enb_id_len + 6;
+		len = ri->eutran.global_enb_id_len + 6;
+		break;
 	default:
 		return -EINVAL;
 	}
+
+	OSMO_ASSERT(len <= BSSGP_RIM_ROUTING_INFO_MAXLEN);
+	return len;
 }
 
 /*! Decode a RAN Information Request Application Container for NACC (3GPP TS 48.018, section 11.3.63.1.1).