tbf: Replace static casts by calls to as_ul_tbf/as_dl_tbf

Currently casts from gprs_rlcmac_tbf to gprs_rlcmac_ul_tbf and
gprs_rlcmac_dl_tbf are done by using static_cast. This doesn't provide
protection against converting a gprs_rlcmac_ul_tbf pointer to a
gprs_rlcmac_dl_tbf pointer and vice versa.

This commit provides two functions as_ul_tbf and as_dl_tbf, that
behave similar like dynamic_cast but use the direction field instead
of RTTI.

Sponsored-by: On-Waves ehf
diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 0daeaf5..e6c8ad4 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -480,14 +480,12 @@
 	/* The allocation will be successful, so the system state and tbf_/ms_
 	 * may be modified from now on. */
 	if (tbf->direction == GPRS_RLCMAC_UL_TBF) {
-		struct gprs_rlcmac_ul_tbf *ul_tbf =
-			static_cast<gprs_rlcmac_ul_tbf *>(tbf_);
+		struct gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf_);
 		LOGP(DRLCMAC, LOGL_DEBUG, "- Assign uplink TS=%d TFI=%d USF=%d\n",
 			ts, tfi, usf);
 		assign_uplink_tbf_usf(pdch, ul_tbf, tfi, usf);
 	} else {
-		struct gprs_rlcmac_dl_tbf *dl_tbf =
-			static_cast<gprs_rlcmac_dl_tbf *>(tbf_);
+		struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
 		LOGP(DRLCMAC, LOGL_DEBUG, "- Assign downlink TS=%d TFI=%d\n",
 			ts, tfi);
 		assign_dlink_tbf(pdch, dl_tbf, tfi);
@@ -1010,8 +1008,7 @@
 	tbf_->first_ts = first_ts;
 
 	if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-		struct gprs_rlcmac_dl_tbf *dl_tbf =
-			static_cast<gprs_rlcmac_dl_tbf *>(tbf_);
+		struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
 		for (ts = 0; ts < 8; ts++) {
 			if (!(dl_slots & (1 << ts)))
 				continue;
@@ -1021,8 +1018,7 @@
 			assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
 		}
 	} else {
-		struct gprs_rlcmac_ul_tbf *ul_tbf =
-			static_cast<gprs_rlcmac_ul_tbf *>(tbf_);
+		struct gprs_rlcmac_ul_tbf *ul_tbf = as_ul_tbf(tbf_);
 
 		for (ts = 0; ts < 8; ts++) {
 			if (!(ul_slots & (1 << ts)))