Move DL assignment to TBF-DL

This function does not really belongs to BTS and it heavily relies on
direct access to TBF-DL members anyway.

Change-Id: I04584103018675a2f35cfb565473bfd81a208d7c
Closes: OS#1540
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 505d488..8ce13a7 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -165,7 +165,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. */
-	dl_tbf->bts->trigger_dl_ass(dl_tbf, old_ul_tbf);
+	dl_tbf->trigger_ass(old_ul_tbf);
 	*tbf = dl_tbf;
 	return 0;
 }
@@ -484,6 +484,40 @@
 	return create_dl_acked_block(fn, ts, bsn, bsn2);
 }
 
+/* depending on the current TBF, we assign on PACCH or AGCH */
+void gprs_rlcmac_dl_tbf::trigger_ass(struct gprs_rlcmac_tbf *old_tbf)
+{
+	/* stop pending timer */
+	stop_timer();
+
+	/* check for downlink tbf:  */
+	if (old_tbf) {
+		LOGP(DRLCMACDL, LOGL_DEBUG, "Send dowlink assignment on PACCH, because %s exists\n", tbf_name(old_tbf));
+		old_tbf->dl_ass_state = GPRS_RLCMAC_DL_ASS_SEND_ASS;
+		old_tbf->was_releasing = old_tbf->state_is(GPRS_RLCMAC_WAIT_RELEASE);
+
+		/* change state */
+		set_state(GPRS_RLCMAC_ASSIGN);
+		if (!(state_flags & (1 << GPRS_RLCMAC_FLAG_CCCH)))
+			state_flags |= (1 << GPRS_RLCMAC_FLAG_PACCH);
+
+		/* start timer */
+		tbf_timer_start(this, 0, Tassign_pacch);
+	} else {
+		LOGP(DRLCMACDL, LOGL_DEBUG, "Send dowlink assignment for %s on PCH, no TBF exist (IMSI=%s)\n",
+		     tbf_name(this), imsi());
+		was_releasing = state_is(GPRS_RLCMAC_WAIT_RELEASE);
+
+		/* change state */
+		set_state(GPRS_RLCMAC_ASSIGN);
+		state_flags |= (1 << GPRS_RLCMAC_FLAG_CCCH);
+
+		/* send immediate assignment */
+		bts->snd_dl_ass(this, 0, imsi());
+		m_wait_confirm = 1;
+	}
+}
+
 void gprs_rlcmac_dl_tbf::schedule_next_frame()
 {
 	struct msgb *msg;