gprs_rlcmac_pdch: Get rid of ul/dl_tbf

The current code keeps a reference to all tbfs in the bts and another
reference in the pdch. This allows for the possibility of both lists to
go out of sync.

This patch removes the pdch-specific list of ul and dl tbfs and uses the
lists in the bts to lookup tbfs everywhere.

Performance for going through the global list is not an issue yet. We
can optimize this later and in a better way.

Sponsored-by: On-Waves ehf
diff --git a/src/bts.cpp b/src/bts.cpp
index 3ca3628..9de6dc3 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -991,16 +991,26 @@
 	return rc;
 }
 
-struct gprs_rlcmac_tbf *gprs_rlcmac_pdch::ul_tbf_by_tfi(uint8_t tfi)
+gprs_rlcmac_tbf *gprs_rlcmac_pdch::tbf_from_list_by_tfi(struct llist_head *tbf_list, uint8_t tfi)
 {
-	if (tfi >= ARRAY_SIZE(ul_tbf))
-		return NULL;
-	return ul_tbf[tfi];
+	gprs_rlcmac_tbf *tbf;
+
+	llist_for_each_entry(tbf, tbf_list, list) {
+		if (tbf->tfi() != tfi)
+			continue;
+		if (!tbf->pdch[ts_no])
+			continue;
+		return tbf;
+	}
+	return NULL;
 }
 
-struct gprs_rlcmac_tbf *gprs_rlcmac_pdch::dl_tbf_by_tfi(uint8_t tfi)
+gprs_rlcmac_tbf *gprs_rlcmac_pdch::ul_tbf_by_tfi(uint8_t tfi)
 {
-	if (tfi >= ARRAY_SIZE(dl_tbf))
-		return NULL;
-	return dl_tbf[tfi];
+	return tbf_from_list_by_tfi(&bts_data()->ul_tbfs, tfi);
+}
+
+gprs_rlcmac_tbf *gprs_rlcmac_pdch::dl_tbf_by_tfi(uint8_t tfi)
+{
+	return tbf_from_list_by_tfi(&bts_data()->dl_tbfs, tfi);
 }