bssgp2: Encoding + Decoding functions for BVC and MS flow control

Change-Id: I9c89bb1c03550930c07aad7ff8f67129ee7a6320
Related: OS#4891
diff --git a/include/osmocom/gprs/gprs_bssgp2.h b/include/osmocom/gprs/gprs_bssgp2.h
index 0ab3619..bf814cb 100644
--- a/include/osmocom/gprs/gprs_bssgp2.h
+++ b/include/osmocom/gprs/gprs_bssgp2.h
@@ -4,10 +4,41 @@
 #include <osmocom/gprs/protocol/gsm_08_18.h>
 #include <osmocom/gprs/gprs_ns2.h>
 
+struct bssgp2_flow_ctrl;
 struct gprs_ns2_inst;
 struct gprs_ra_id;
 struct msgb;
 
+struct bssgp2_flow_ctrl {
+	uint8_t tag;
+	/* maximum bucket size (Bmax) in bytes */
+	uint64_t bucket_size_max;
+	/*! bucket leak rate in _bytes_ per second */
+	uint64_t bucket_leak_rate;
+	/* percentage how full the given bucket is */
+	uint8_t bucket_full_ratio;
+	bool bucket_full_ratio_present;
+	union {
+		/*! FC-BVC specifi members */
+		struct {
+			/*! default maximum bucket size per MS in bytes */
+			uint64_t bmax_default_ms;
+			/*! default bucket leak rate (R) for MS flow control bucket */
+			uint64_t r_default_ms;
+
+			/*! average milliseconds of queueing delay for a BVC */
+			uint32_t measurement;
+			bool measurement_present;
+		} bvc;
+		/*! FC-MS specifi members */
+		struct {
+			/*! TLLI of the MS */
+			uint32_t tlli;
+		} ms;
+	} u;
+};
+
+
 int bssgp2_nsi_tx_ptp(struct gprs_ns2_inst *nsi, uint16_t nsei, uint16_t bvci,
 		      struct msgb *msg, uint32_t lsp);
 
@@ -29,3 +60,11 @@
 				      const uint8_t *feat_bm, const uint8_t *ext_feat_bm);
 
 struct msgb *bssgp2_enc_status(uint8_t cause, const uint16_t *bvci, const struct msgb *orig_msg);
+
+
+int bssgp2_dec_fc_bvc(struct bssgp2_flow_ctrl *fc, const struct tlv_parsed *tp);
+struct msgb *bssgp2_enc_fc_bvc(const struct bssgp2_flow_ctrl *fc, enum bssgp_fc_granularity *gran);
+struct msgb *bssgp2_enc_fc_bvc_ack(uint8_t tag);
+int bssgp2_dec_fc_ms(struct bssgp2_flow_ctrl *fc, struct tlv_parsed *tp);
+struct msgb *bssgp2_enc_fc_ms(const struct bssgp2_flow_ctrl *fc, enum bssgp_fc_granularity *gran);
+struct msgb *bssgp2_enc_fc_ms_ack(uint32_t tlli, uint8_t tag);