tbf: Maintain the number of TBF per PDCH

Currently the PDCH object do not know anything about the TBFs using
them. To make the slot allocation load dependant, at least some
numbers are required.

This commit adds TBF counters (one per direction) and the related methods
attach_tbf, detach_tbf, and num_tbfs to gprs_rlcmac_pdch.

Sponsored-by: On-Waves ehf
diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index bae1ea5..29749b8 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -117,13 +117,23 @@
 	return 8;
 }
 
+static void attach_tbf_to_pdch(struct gprs_rlcmac_pdch *pdch,
+	struct gprs_rlcmac_tbf *tbf)
+{
+	if (tbf->pdch[pdch->ts_no])
+		tbf->pdch[pdch->ts_no]->detach_tbf(tbf);
+
+	tbf->pdch[pdch->ts_no] = pdch;
+	pdch->attach_tbf(tbf);
+}
+
 static void assign_uplink_tbf_usf(
 				struct gprs_rlcmac_pdch *pdch,
 				struct gprs_rlcmac_ul_tbf *tbf, int8_t usf)
 {
 	tbf->trx->ul_tbf[tbf->tfi()] = tbf;
-	tbf->pdch[pdch->ts_no] = pdch;
 	tbf->m_usf[pdch->ts_no] = usf;
+	attach_tbf_to_pdch(pdch, tbf);
 }
 
 static void assign_dlink_tbf(
@@ -131,7 +141,7 @@
 				struct gprs_rlcmac_dl_tbf *tbf)
 {
 	tbf->trx->dl_tbf[tbf->tfi()] = tbf;
-	tbf->pdch[pdch->ts_no] = pdch;
+	attach_tbf_to_pdch(pdch, tbf);
 }