Add SDU length for an NSE (== BSSGP PDU size)

Prepare tracking the SDU from NS. Initialize with a conservative default.
The value is not yet updated, that will happen in a later patch.

Related: OS#4889
Depends: I5016b295db6185ec131d83089cf6c806e34ef1b6 (libosmocore.git)
Depends: I9bb82ead27366b7370c9ff968e03ca2113ec11f0 (libosmocore.git)
Change-Id: Ic1080abde942ec5a2ae7cdee0ffe716a2fbddb1e
diff --git a/include/osmocom/sgsn/gb_proxy.h b/include/osmocom/sgsn/gb_proxy.h
index a36f305..c9d2fca 100644
--- a/include/osmocom/sgsn/gb_proxy.h
+++ b/include/osmocom/sgsn/gb_proxy.h
@@ -11,6 +11,7 @@
 #include <osmocom/gsm/gsm48.h>
 #include <osmocom/gsm/protocol/gsm_23_003.h>
 
+#include <osmocom/gprs/frame_relay.h>
 #include <osmocom/gprs/gprs_ns2.h>
 #include <osmocom/vty/command.h>
 
@@ -21,6 +22,9 @@
 #define GBPROXY_INIT_VU_GEN_TX 256
 #define GBPROXY_MAX_NR_SGSN	16
 
+/* Set conservative default BSSGP SDU (FR SDU - size of NS UNITDATA IEs) */
+#define DEFAULT_NSE_SDU (FRAME_RELAY_SDU - 4)
+
 /* BVCI uses 16 bits */
 #define BVC_LOG_CTX_FLAG (1<<17)
 
@@ -161,6 +165,9 @@
 	/* NSEI of the NSE */
 	uint16_t nsei;
 
+	/* Maximum side of the NS-UNITDATA NS SDU that can be transported by the NSE */
+	uint16_t max_sdu_len;
+
 	/* Are we facing towards a SGSN (true) or BSS (false) */
 	bool sgsn_facing;
 
diff --git a/src/gb_proxy.c b/src/gb_proxy.c
index 8b57315..7f4af5b 100644
--- a/src/gb_proxy.c
+++ b/src/gb_proxy.c
@@ -684,6 +684,7 @@
 			sgsn_bvc->fi = bssgp_bvc_fsm_alloc_ptp_bss(sgsn_bvc, cfg->nsi, sgsn_nse->nsei,
 								   bvci, ra_id, cell_id);
 			OSMO_ASSERT(sgsn_bvc->fi);
+			bssgp_bvc_fsm_set_max_pdu_len(sgsn_bvc->fi, sgsn_nse->max_sdu_len);
 			bssgp_bvc_fsm_set_ops(sgsn_bvc->fi, &sgsn_ptp_bvc_fsm_ops, sgsn_bvc);
 
 			gbproxy_cell_add_sgsn_bvc(bvc->cell, sgsn_bvc);
@@ -828,6 +829,7 @@
 				gbproxy_bvc_free(from_bvc);
 				return -ENOMEM;
 			}
+			bssgp_bvc_fsm_set_max_pdu_len(from_bvc->fi, nse->max_sdu_len);
 			bssgp_bvc_fsm_set_ops(from_bvc->fi, &bss_sig_bvc_fsm_ops, from_bvc);
 		}
 	} else {
@@ -844,6 +846,7 @@
 				gbproxy_bvc_free(from_bvc);
 				return -ENOMEM;
 			}
+			bssgp_bvc_fsm_set_max_pdu_len(from_bvc->fi, nse->max_sdu_len);
 			bssgp_bvc_fsm_set_ops(from_bvc->fi, &bss_ptp_bvc_fsm_ops, from_bvc);
 		}
 #if 0
@@ -1500,6 +1503,7 @@
 {
 	/* TODO: bss nsei available/unavailable  bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK, nsvc->nsei, bvc->bvci, 0);
 	 * TODO: sgsn nsei available/unavailable
+	 * TODO: Update MTU
 	 */
 
 	struct gbproxy_bvc *bvc;
diff --git a/src/gb_proxy_peer.c b/src/gb_proxy_peer.c
index 27d73b8..a9471f0 100644
--- a/src/gb_proxy_peer.c
+++ b/src/gb_proxy_peer.c
@@ -447,6 +447,7 @@
 		return NULL;
 
 	nse->nsei = nsei;
+	nse->max_sdu_len = DEFAULT_NSE_SDU;
 	nse->cfg = cfg;
 	nse->sgsn_facing = sgsn_facing;
 
diff --git a/src/gb_proxy_vty.c b/src/gb_proxy_vty.c
index 04c7173..3a52e32 100644
--- a/src/gb_proxy_vty.c
+++ b/src/gb_proxy_vty.c
@@ -241,6 +241,7 @@
 		bvc->fi = bssgp_bvc_fsm_alloc_sig_bss(bvc, nse->cfg->nsi, nsei, features);
 		if (!bvc->fi)
 			goto free_bvc;
+		bssgp_bvc_fsm_set_max_pdu_len(bvc->fi, nse->max_sdu_len);
 		bssgp_bvc_fsm_set_ops(bvc->fi, &sgsn_sig_bvc_fsm_ops, bvc);
 		osmo_fsm_inst_dispatch(bvc->fi, BSSGP_BVCFSM_E_REQ_RESET, &cause);
 	}