bssgp_bvc_fsm: Set/get maximum BSSGP PDU length

Add functions to get/set the maximum supported BSSGP PDU size by the NS
layer.

IPv4 and IPv6 should not matter since we can just enable IP
fragmentation and send NS PDUs up to 2**16 + bytes. Frame relay does not
support fragmentation and this is the reason we need to be aware of the
maximum PDU size. Luckily with 1600 bytes the MTU in frame relay can hold a
regular IP packet including NS/BSSGP overhead.

On the NS layer this corresponds to the size of an NS SDU in NS-UNITDATA
(3GPP TS 48.016 Ch. 9.2.10)

Change-Id: I9bb82ead27366b7370c9ff968e03ca2113ec11f0
Related: OS#4889
diff --git a/include/osmocom/gprs/bssgp_bvc_fsm.h b/include/osmocom/gprs/bssgp_bvc_fsm.h
index e69c205..824cdec 100644
--- a/include/osmocom/gprs/bssgp_bvc_fsm.h
+++ b/include/osmocom/gprs/bssgp_bvc_fsm.h
@@ -64,3 +64,6 @@
 uint32_t bssgp_bvc_get_features_advertised(struct osmo_fsm_inst *fi);
 uint32_t bssgp_bvc_get_features_received(struct osmo_fsm_inst *fi);
 uint32_t bssgp_bvc_get_features_negotiated(struct osmo_fsm_inst *fi);
+
+void bssgp_bvc_fsm_set_max_pdu_len(struct osmo_fsm_inst *fi, uint16_t max_pdu_len);
+uint16_t bssgp_bvc_fsm_get_max_pdu_len(const struct osmo_fsm_inst *fi);
\ No newline at end of file
diff --git a/src/gb/bssgp_bvc_fsm.c b/src/gb/bssgp_bvc_fsm.c
index 6b8bd14..d2ee146 100644
--- a/src/gb/bssgp_bvc_fsm.c
+++ b/src/gb/bssgp_bvc_fsm.c
@@ -116,6 +116,8 @@
 
 	/* NSEI of the underlying NS Entity */
 	uint16_t nsei;
+	/* Maximum size of the BSSGP PDU */
+	uint16_t max_pdu_len;
 
 	/* BVCI of this BVC */
 	uint16_t bvci;
@@ -666,6 +668,7 @@
 	bfp->role_sgsn = role_sgsn;
 	bfp->nsei = nsei;
 	bfp->bvci = bvci;
+	bfp->max_pdu_len = UINT16_MAX;
 
 	return fi;
 }
@@ -817,6 +820,26 @@
 	return bfp->features.negotiated;
 }
 
+/*! Set the maximum size of a BSSGP PDU.
+ *! On the NS layer this corresponds to the size of an NS SDU in NS-UNITDATA (3GPP TS 48.016 Ch. 9.2.10) */
+void bssgp_bvc_fsm_set_max_pdu_len(struct osmo_fsm_inst *fi, uint16_t max_pdu_len) {
+	struct bvc_fsm_priv *bfp = fi->priv;
+
+	OSMO_ASSERT(fi->fsm == &bssgp_bvc_fsm);
+	bfp->max_pdu_len = max_pdu_len;
+}
+
+/*! Return the maximum size of a BSSGP PDU
+ *! On the NS layer this corresponds to the size of an NS SDU in NS-UNITDATA (3GPP TS 48.016 Ch. 9.2.10) */
+uint16_t bssgp_bvc_fsm_get_max_pdu_len(const struct osmo_fsm_inst *fi)
+{
+	const struct bvc_fsm_priv *bfp = fi->priv;
+
+	OSMO_ASSERT(fi->fsm == &bssgp_bvc_fsm);
+	return bfp->max_pdu_len;
+}
+
+
 static __attribute__((constructor)) void on_dso_load_bvc_fsm(void)
 {
 	OSMO_ASSERT(osmo_fsm_register(&bssgp_bvc_fsm) == 0);
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index 7da11cd..2327815 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -96,6 +96,8 @@
 bssgp_bvc_get_features_advertised;
 bssgp_bvc_get_features_received;
 bssgp_bvc_get_features_negotiated;
+bssgp_bvc_fsm_set_max_pdu_len;
+bssgp_bvc_fsm_get_max_pdu_len;
 
 osmo_fr_network_alloc;
 osmo_fr_link_alloc;