pcu: Take into account TbfStartingTime

New versions of osmo-pcu will validate the Pkt Resource Request is sent
on the correct FN, so we must send first UL block exactly when
requested.

Change-Id: I6dad0f3167ace8d4a763fed971db94f32faf6ced
diff --git a/pcu/PCU_Tests.ttcn b/pcu/PCU_Tests.ttcn
index a466732..52d6271 100644
--- a/pcu/PCU_Tests.ttcn
+++ b/pcu/PCU_Tests.ttcn
@@ -316,7 +316,7 @@
 			var RlcmacDlBlock dl_block;
 			var uint32_t poll_fn;
 
-			f_ms_tx_ul_data_block(g_ms[i], dummy, with_tlli := true, nr := nr);
+			f_ms_tx_ul_data_block(g_ms[i], dummy, with_tlli := true, fn := g_ms[i].ul_tbf.start_time_fn, nr := nr);
 			f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, poll_fn, nr := nr);
 		}
 	}
@@ -354,7 +354,7 @@
 		pkt_res_req := ts_RlcMacUlCtrl_PKT_RES_REQ(ms.tlli, omit);
 	}
 
-	f_ms_tx_ul_block(ms, ts_RLC_UL_CTRL_ACK(valueof(pkt_res_req)), 0, nr := f_ms_tx_TsTrxBtsNum(ms));
+	f_ms_tx_ul_block(ms, ts_RLC_UL_CTRL_ACK(valueof(pkt_res_req)), ms.ul_tbf.start_time_fn, nr := f_ms_tx_TsTrxBtsNum(ms));
 	/* Store 1st UlTBF context before receiving next one, will
 	 * overwrite the TS allocation on MS with info from new UL TBF:
 	 */
@@ -420,7 +420,7 @@
 
 	/* Send one UL block (with TLLI since we are in One-Phase Access
 	   contention resoultion) and make sure it is ACKED fine */
-	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true);
+	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true, fn := ms.ul_tbf.start_time_fn);
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -765,7 +765,7 @@
 	   contention resoultion) and make sure it is ACKED fine. */
 	/* 16 bytes fills the llc block (because TLLI takes 4 bytes) */
 	/* Set CV = 15 to signal there's still more than BS_CV_MAX blocks to be sent */
-	f_ms_tx_ul_data_block(ms, f_rnd_octstring(16), cv := 15, with_tlli := true)
+	f_ms_tx_ul_data_block(ms, f_rnd_octstring(16), cv := 15, with_tlli := true, fn := ms.ul_tbf.start_time_fn)
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -849,7 +849,7 @@
 	   contention resoultion) and make sure it is ACKED fine. */
 	/* 16 bytes fills the llc block (because TLLI takes 4 bytes) */
 	/* Set CV = 15 to signal there's still more than BS_CV_MAX blocks to be sent */
-	f_ms_tx_ul_data_block(ms, f_rnd_octstring(16), cv := 15, with_tlli := true)
+	f_ms_tx_ul_data_block(ms, f_rnd_octstring(16), cv := 15, with_tlli := true, fn := ms.ul_tbf.start_time_fn)
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -921,7 +921,7 @@
 	   contention resoultion) and make sure it is ACKED fine. */
 	/* 16 bytes fills the llc block (because TLLI takes 4 bytes) */
 	/* Set CV = 15 to signal there's still more than BS_CV_MAX blocks to be sent */
-	f_ms_tx_ul_data_block(ms, f_rnd_octstring(16), cv := 15, with_tlli := true)
+	f_ms_tx_ul_data_block(ms, f_rnd_octstring(16), cv := 15, with_tlli := true, fn := ms.ul_tbf.start_time_fn)
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -1299,7 +1299,7 @@
 
 	/* Send one UL block (with TLLI since we are in One-Phase Access
 	   contention resoultion) and make sure it is ACKED fine */
-	f_ms_tx_ul_data_block(ms, f_rnd_octstring(10), cv := 1, with_tlli := true)
+	f_ms_tx_ul_data_block(ms, f_rnd_octstring(10), cv := 1, with_tlli := true, fn := ms.ul_tbf.start_time_fn)
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, unused_fn);
 	/* UL block should NOT be received in SGSN, since we didn't get CV=0 */
 
@@ -1905,7 +1905,7 @@
 	   contention resoultion) and make sure it is ACKED fine. */
 	total_payload := f_rnd_octstring(f_ultbf_payload_fill_length(ms.ul_tbf, true));
 	/* Set CV = 15 to signal there's still more than BS_CV_MAX blocks to be sent */
-	f_ms_tx_ul_data_block(ms, total_payload, cv := 15, with_tlli := true)
+	f_ms_tx_ul_data_block(ms, total_payload, cv := 15, with_tlli := true, fn := ms.ul_tbf.start_time_fn)
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -1966,7 +1966,7 @@
 					 blocks := blocks,
 					 tlli := ms.tlli);
 	f_ultbf_inc_bsn(ms.ul_tbf);
-	f_ms_tx_ul_block(ms, ul_data);
+	f_ms_tx_ul_block(ms, ul_data, ms.ul_tbf.start_time_fn);
 
 	/* ACK and check it was received fine */
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
@@ -2122,7 +2122,7 @@
 
 	/* Send one UL block (with TLLI since we are in One-Phase Access
 	   contention resoultion) and make sure it is ACKED fine */
-	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true);
+	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true, fn := ms.ul_tbf.start_time_fn);
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -2349,7 +2349,7 @@
 	/* Send one UL block (with TLLI since we are in One-Phase Access
 	   contention resoultion) and make sure it is ACKED fine. */
 	payload := f_rnd_octstring(f_ultbf_payload_fill_length(ms.ul_tbf, true)); /* 16 bytes fills the llc block (because TLLI takes 4 bytes) */
-	f_ms_tx_ul_data_block(ms, payload, cv := 15, with_tlli := true);
+	f_ms_tx_ul_data_block(ms, payload, cv := 15, with_tlli := true, fn := ms.ul_tbf.start_time_fn);
 
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
@@ -2580,7 +2580,7 @@
 	 * RLCMAC block being sent. */
 	ul_data.data.mac_hdr.e := true;
 	f_ultbf_inc_bsn(ms.ul_tbf);
-	f_ms_tx_ul_block(ms, ul_data);
+	f_ms_tx_ul_block(ms, ul_data, ms.ul_tbf.start_time_fn);
 
 	/* UL RlcDataBlock(dataA finished, dataB starts) [BSN=1, CV=2] */
 	ul_data := t_RLCMAC_UL_DATA_TLLI(cs := CS_1,
@@ -2765,7 +2765,8 @@
 
 	/* Send one UL block (with TLLI since we are in One-Phase Access
 	   contention resoultion) and make sure it is ACKED fine */
-	f_ms_tx_ul_data_block(ms, data, with_tlli := true, nr := f_ms_tx_TsTrxBtsNum(ms));
+	f_ms_tx_ul_data_block(ms, data, with_tlli := true, fn := ms.ul_tbf.start_time_fn,
+			      nr := f_ms_tx_TsTrxBtsNum(ms));
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, poll_fn, nr := f_ms_tx_TsTrxBtsNum(ms));
 
@@ -2908,7 +2909,7 @@
 
 	/* Send one UL block (with TLLI since we are in One-Phase Access
 	   contention resoultion) and make sure it is ACKED fine */
-	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true);
+	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true, fn := ms.ul_tbf.start_time_fn);
 
 	/* UL block should be received in SGSN */
 	BSSGP[0].receive(tr_BSSGP_UL_UD(ms.tlli, mp_gb_cfg.bvc[0].cell_id));
@@ -3128,7 +3129,7 @@
 	f_ms_establish_ul_tbf(ms);
 
 	/* Fake GMM GPRS Attach or similar, PCU doesn't care about upper layers here */
-	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true);
+	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true, fn := ms.ul_tbf.start_time_fn);
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -3187,7 +3188,7 @@
 	f_ms_establish_ul_tbf(ms);
 
 	/* Fake GMM GPRS Attach or similar, PCU doesn't care about upper layers here */
-	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true);
+	f_ms_tx_ul_data_block_multi(ms, 1, with_tlli := true, fn := ms.ul_tbf.start_time_fn);
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, sched_fn);
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_ms_tx_ul_block(ms, ts_RLCMAC_CTRL_ACK(ms.tlli), sched_fn);
@@ -3676,11 +3677,16 @@
 	/* Initialize the PCU interface abstraction */
 	f_init_raw(testcasename(), info_ind);
 
+	/* Single block (two phase) packet access */
+	var uint16_t ra := bit2int(chan_req_sb);
+	f_ms_use_ra(ms, ra, ra_is_11bit := 0);
+
 	/* Establish an Uplink TBF */
 	f_ms_establish_ul_tbf(ms);
 
 	/* Send Packet Resource Request, so the network will allocate an Uplink resource */
-	f_ms_tx_ul_block(ms, ts_RLC_UL_CTRL_ACK(ts_RlcMacUlCtrl_PKT_RES_REQ(ms.tlli, omit)));
+	f_ms_tx_ul_block(ms, ts_RLC_UL_CTRL_ACK(ts_RlcMacUlCtrl_PKT_RES_REQ(ms.tlli, omit)),
+			 fn := ms.ul_tbf.start_time_fn);
 
 	/* Expect an RLC/MAC block with Packet Uplink Assignment on PACCH (see 11.2.29) */
 	f_ms_rx_pkt_ass_pacch(ms, poll_fn, tr_RLCMAC_UL_PACKET_ASS);
@@ -3729,7 +3735,7 @@
 	f_ms_establish_ul_tbf(ms);
 
 	/* Send an Uplink block, so this TBF becomes "active" */
-	f_ms_tx_ul_data_block(ms, data, with_tlli := true);
+	f_ms_tx_ul_data_block(ms, data, with_tlli := true, fn := ms.ul_tbf.start_time_fn);
 
 	/* DL ACK/NACK sets poll+rrbp requesting PACKET CONTROL ACK */
 	f_rx_rlcmac_dl_block_exp_ack_nack(dl_block, poll_fn);