tbf: Use TLLI as ID if TFI not yet assigned

Currently the old TFI is always used as ID when a
PACKET DOWNLINK ASSIGNMENT is generated. This fails
if the old TBF has not been fully assigned yet. The
MS will then ignore the PDA.

This commit changes write_packet_downlink_assignment to accept
an additional parameter old_tfi_is_valid and uses the new TBF's
TLLI instead of the olf TFI if that parameter is set to false.

Sponsored-by: On-Waves ehf
diff --git a/src/encoding.cpp b/src/encoding.cpp
index a5e5064..9471fff 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -274,8 +274,9 @@
 
 /* generate downlink assignment */
 void Encoding::write_packet_downlink_assignment(RlcMacDownlink_t * block,
-	uint8_t old_tfi, uint8_t old_downlink, struct gprs_rlcmac_tbf *tbf,
-	uint8_t poll, uint8_t rrbp, uint8_t alpha, uint8_t gamma, int8_t ta_idx,
+	bool old_tfi_is_valid, uint8_t old_tfi, uint8_t old_downlink,
+	struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t rrbp,
+	uint8_t alpha, uint8_t gamma, int8_t ta_idx,
 	uint8_t ta_ts, bool use_egprs)
 {
 	// Packet downlink assignment TS 44.060 11.2.7
@@ -295,9 +296,14 @@
 
 	block->u.Packet_Downlink_Assignment.Exist_PERSISTENCE_LEVEL      = 0x0;          // PERSISTENCE_LEVEL: off
 
-	block->u.Packet_Downlink_Assignment.ID.UnionType                 = 0x0;          // TFI = on
-	block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.UnionType    = old_downlink; // 0=UPLINK TFI, 1=DL TFI
-	block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.u.UPLINK_TFI = old_tfi;      // TFI
+	if (old_tfi_is_valid) {
+		block->u.Packet_Downlink_Assignment.ID.UnionType                 = 0x0;          // TFI = on
+		block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.UnionType    = old_downlink; // 0=UPLINK TFI, 1=DL TFI
+		block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.u.UPLINK_TFI = old_tfi;      // TFI
+	} else {
+		block->u.Packet_Downlink_Assignment.ID.UnionType                 = 0x1;          // TLLI
+		block->u.Packet_Downlink_Assignment.ID.u.TLLI                    = tbf->tlli();
+	}
 
 	block->u.Packet_Downlink_Assignment.MAC_MODE            = 0x0;          // Dynamic Allocation
 	block->u.Packet_Downlink_Assignment.RLC_MODE            = 0x0;          // RLC acknowledged mode