bts: Remove the global state gprs_rlcmac_trigger_downlink_assignment

Remove the global state from gprs_rlcmac_trigger_downlink_assignment
and walk up to the pcu_l1_if.cpp where I find the timeout handling
that should be part of the SBA and TBF functionality. In terms of
hierachies things start to be more clear.

There should be the BTS object. That holds the SBA and TBF Controllers
that can allocate TBFs and SBAs and will handle the timeout polling
for a BTS.
diff --git a/src/gprs_rlcmac.h b/src/gprs_rlcmac.h
index b8afdcd..760579b 100644
--- a/src/gprs_rlcmac.h
+++ b/src/gprs_rlcmac.h
@@ -183,7 +183,7 @@
 
 int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf);
 
-int gprs_rlcmac_poll_timeout(struct gprs_rlcmac_tbf *tbf);
+int gprs_rlcmac_poll_timeout(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_tbf *tbf);
 
 int gprs_rlcmac_sba_timeout(struct gprs_rlcmac_sba *sba);
 
@@ -198,10 +198,12 @@
 struct msgb *gprs_rlcmac_send_packet_downlink_assignment(
         struct gprs_rlcmac_tbf *tbf, uint32_t fn);
 
-void gprs_rlcmac_trigger_downlink_assignment(struct gprs_rlcmac_tbf *tbf,
+void gprs_rlcmac_trigger_downlink_assignment(struct gprs_rlcmac_bts *bts,
+	struct gprs_rlcmac_tbf *tbf,
         struct gprs_rlcmac_tbf *old_tbf, const char *imsi);
 
-int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_tbf *tbf, uint8_t final,
+int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_bts *bts,
+	struct gprs_rlcmac_tbf *tbf, uint8_t final,
         uint8_t ssn, uint8_t *rbb);
 
 int gprs_rlcmac_paging_request(uint8_t *ptmsi, uint16_t ptmsi_len,
diff --git a/src/gprs_rlcmac_data.cpp b/src/gprs_rlcmac_data.cpp
index c2ed9e6..cd503f3 100644
--- a/src/gprs_rlcmac_data.cpp
+++ b/src/gprs_rlcmac_data.cpp
@@ -74,7 +74,8 @@
 } __attribute__ ((packed));
 }
 
-static void gprs_rlcmac_downlink_assignment(gprs_rlcmac_tbf *tbf, uint8_t poll,
+static void gprs_rlcmac_downlink_assignment(struct gprs_rlcmac_bts *bts,
+	gprs_rlcmac_tbf *tbf, uint8_t poll,
 	const char *imsi);
 
 static int gprs_rlcmac_diag(struct gprs_rlcmac_tbf *tbf)
@@ -82,7 +83,7 @@
 	return tbf->rlcmac_diag();
 }
 
-int gprs_rlcmac_poll_timeout(struct gprs_rlcmac_tbf *tbf)
+int gprs_rlcmac_poll_timeout(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_tbf *tbf)
 {
 	LOGP(DRLCMAC, LOGL_NOTICE, "Poll timeout for %s TBF=%d\n",
 		(tbf->direction == GPRS_RLCMAC_UL_TBF) ? "UL" : "DL", tbf->tfi);
@@ -99,8 +100,6 @@
 		tbf->ul_ack_state = GPRS_RLCMAC_UL_ACK_NONE;
 		debug_diagram(tbf->diag, "timeout UL-ACK");
 		if (tbf->state_is(GPRS_RLCMAC_FINISHED)) {
-			struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
-
 			tbf->dir.ul.n3103++;
 			if (tbf->dir.ul.n3103 == bts->n3103) {
 				LOGP(DRLCMAC, LOGL_NOTICE,
@@ -185,7 +184,7 @@
 				"for TBF=%d on PCH (IMSI=%s)\n", tbf->tfi,
 				tbf->dir.dl.imsi);
 			/* send immediate assignment */
-			gprs_rlcmac_downlink_assignment(tbf, 0, tbf->dir.dl.imsi);
+			gprs_rlcmac_downlink_assignment(bts, tbf, 0, tbf->dir.dl.imsi);
 			tbf->dir.dl.wait_confirm = 1;
 		}
 	} else
@@ -352,7 +351,7 @@
 		tbf->poll_state = GPRS_RLCMAC_POLL_NONE;
 		debug_diagram(tbf->diag, "got DL-ACK");
 
-		rc = gprs_rlcmac_downlink_ack(tbf,
+		rc = gprs_rlcmac_downlink_ack(bts, tbf,
 			ul_control_block->u.Packet_Downlink_Ack_Nack.Ack_Nack_Description.FINAL_ACK_INDICATION,
 			ul_control_block->u.Packet_Downlink_Ack_Nack.Ack_Nack_Description.STARTING_SEQUENCE_NUMBER,
 			ul_control_block->u.Packet_Downlink_Ack_Nack.Ack_Nack_Description.RECEIVED_BLOCK_BITMAP);
@@ -1479,7 +1478,8 @@
 	return dl_msg;
 }
 
-int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_tbf *tbf, uint8_t final,
+int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_bts *bts,
+	struct gprs_rlcmac_tbf *tbf, uint8_t final,
 	uint8_t ssn, uint8_t *rbb)
 {
 	char show_rbb[65], show_v_b[RLC_MAX_SNS + 1];
@@ -1618,7 +1618,7 @@
 	tbf->state_flags &= GPRS_RLCMAC_FLAG_TO_MASK; /* keep TO flags */
 	tbf->state_flags &= ~(1 << GPRS_RLCMAC_FLAG_CCCH);
 	tbf_update(tbf);
-	gprs_rlcmac_trigger_downlink_assignment(tbf, tbf, NULL);
+	gprs_rlcmac_trigger_downlink_assignment(bts, tbf, tbf, NULL);
 
 	return 0;
 }
@@ -1715,10 +1715,10 @@
 	return msg;
 }
 
-static void gprs_rlcmac_downlink_assignment(gprs_rlcmac_tbf *tbf, uint8_t poll,
+static void gprs_rlcmac_downlink_assignment(struct gprs_rlcmac_bts *bts,
+	gprs_rlcmac_tbf *tbf, uint8_t poll,
 	const char *imsi)
 {
-	struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
 	int plen;
 
 	debug_diagram(tbf->diag, "IMM.ASS (PCH)");
@@ -1736,7 +1736,8 @@
 }
 
 /* depending on the current TBF, we assign on PACCH or AGCH */
-void gprs_rlcmac_trigger_downlink_assignment(struct gprs_rlcmac_tbf *tbf,
+void gprs_rlcmac_trigger_downlink_assignment(struct gprs_rlcmac_bts *bts,
+	struct gprs_rlcmac_tbf *tbf,
 	struct gprs_rlcmac_tbf *old_tbf, const char *imsi)
 {
 #ifdef DEBUG_DL_ASS_IDLE
@@ -1779,7 +1780,7 @@
 		tbf->state_flags |= (1 << GPRS_RLCMAC_FLAG_CCCH);
 		strncpy(tbf->dir.dl.imsi, imsi, sizeof(tbf->dir.dl.imsi));
 		/* send immediate assignment */
-		gprs_rlcmac_downlink_assignment(tbf, 0, imsi);
+		gprs_rlcmac_downlink_assignment(bts, tbf, 0, imsi);
 		tbf->dir.dl.wait_confirm = 1;
 	}
 }
diff --git a/src/pcu_l1_if.cpp b/src/pcu_l1_if.cpp
index a31974f..31ea8dc 100644
--- a/src/pcu_l1_if.cpp
+++ b/src/pcu_l1_if.cpp
@@ -523,7 +523,7 @@
 			elapsed = (frame_number + 2715648 - tbf->poll_fn)
 								% 2715648;
 			if (elapsed >= 20 && elapsed < 2715400)
-				gprs_rlcmac_poll_timeout(tbf);
+				gprs_rlcmac_poll_timeout(gprs_rlcmac_bts, tbf);
 		}
 	}
 	llist_for_each_entry(tbf, &gprs_rlcmac_dl_tbfs, list) {
@@ -531,7 +531,7 @@
 			elapsed = (frame_number + 2715648 - tbf->poll_fn)
 								% 2715648;
 			if (elapsed >= 20 && elapsed < 2715400)
-				gprs_rlcmac_poll_timeout(tbf);
+				gprs_rlcmac_poll_timeout(gprs_rlcmac_bts, tbf);
 		}
 	}
 	llist_for_each_entry_safe(sba, sba2, &gprs_rlcmac_sbas, list) {
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 6ba117e..acff1ff 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -71,7 +71,7 @@
 		tbf->state_flags &= ~(1 << GPRS_RLCMAC_FLAG_CCCH);
 		tbf_update_ms_class(tbf, ms_class);
 		tbf_update(tbf);
-		gprs_rlcmac_trigger_downlink_assignment(tbf, tbf, NULL);
+		gprs_rlcmac_trigger_downlink_assignment(bts, tbf, tbf, NULL);
 	} else {
 		/* the TBF exists, so we must write it in the queue
 		 * we prepend lifetime in front of PDU */
@@ -177,7 +177,7 @@
 	 * we don't use old_downlink, so the possible uplink is used
 	 * to trigger downlink assignment. if there is no uplink,
 	 * AGCH is used. */
-	gprs_rlcmac_trigger_downlink_assignment(tbf, old_tbf, imsi);
+	gprs_rlcmac_trigger_downlink_assignment(bts, tbf, old_tbf, imsi);
 
 	/* store IMSI for debugging purpose. TODO: it is more than debugging */
 	tbf_assign_imsi(tbf, imsi);