Dl TBF: Get rid of LLC UI dummy blocks following other data

According to:
* 3GPP TS 44.060 version 16.0.0 "9.3.1a Delayed release of downlink Temporary Block Flow"
* 3GPP TS 44.064 version 16.0.0 "6.4.2.2 Unconfirmed Information (UI) Dummy command"

LLC UI Dummy frames are to be used when there no more data to send, only
in order to delay the release of a TBF. Hence, while not incorrect per
se, makes no sense to send those LLC UI Dummy frames inserted into
rlcmac blocks which already contain other LLC frames, since the MS in
that case is already being kept active.
It only makes sense to send those LLC UI Dummy frames when we have
nothing else to send, that is, alone inside a RLCMAC block without other
LLC frames.

Related: OS#4849
Change-Id: Ifae1a7b2b3dfad8df19585063088ba0df2749c8f
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index ad98510..bb89e81 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -694,9 +694,33 @@
 		int payload_written = 0;
 
 		if (m_llc.frame_length() == 0) {
-			/* nothing to sent - delay the release of the TBF */
+			/* It is not clear, when the next real data will
+			 * arrive, so request a DL ack/nack now */
+			request_dl_ack();
 
 			int space = block_data_len - write_offset;
+
+			if (num_chunks != 0) {
+				/* Nothing to send, and we already put some data in
+				 * rlcmac data block, we are done */
+				LOGPTBFDL(this, LOGL_DEBUG,
+					  "LLC queue completely drained and there's "
+					  "still %d free bytes in rlcmac data block\n", space);
+				if (mcs_is_edge(cs)) {
+					/* in EGPRS there's no M bit, so we need
+					 * to flag padding with LI=127 */
+					Encoding::rlc_data_to_dl_append_egprs_li_padding(rdbi,
+											 &write_offset,
+											 &num_chunks,
+											 data);
+				}
+				break;
+			}
+
+			/* Nothing to send from upper layers (LLC), but still
+			 * requested to send something to MS to delay the
+			 * release of the TBF. See 3GPP TS 44.060 9.3.1a
+			 * "Delayed release of downlink Temporary Block Flow" */
 			/* A header will need to by added, so we just need
 			 * space-1 octets */
 			m_llc.put_dummy_frame(space - 1);
@@ -705,10 +729,6 @@
 			if (m_last_dl_drained_fn < 0)
 				m_last_dl_drained_fn = fn;
 
-			/* It is not clear, when the next real data will
-			 * arrive, so request a DL ack/nack now */
-			request_dl_ack();
-
 			LOGPTBFDL(this, LOGL_DEBUG,
 				  "Empty chunk, added LLC dummy command of size %d, drained_since=%d\n",
 				  m_llc.frame_length(), frames_since_last_drain(fn));