tbf/test: Simplify RLC block number handling

The block number can always be deduced from the frame number. The
current test code handles the block number explicitely, which makes
the code more complex and has also led to block number errors cause
by not wrapping the numbers (valid block numbers range from 0 to 11).

This commit changes send_rlc_block to always compute the block number
based on the frame number. It also turns the block_nr into an
optionaly output-only parameter.

Sponsored-by: On-Waves ehf
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index f185ad7..2237d56 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -203,15 +203,18 @@
 
 static void send_rlc_block(struct gprs_rlcmac_bts *bts,
 	uint8_t trx_no, uint8_t ts_no, uint16_t arfcn,
-	uint32_t *fn, uint8_t *block_nr)
+	uint32_t *fn, uint8_t *block_nr = NULL)
 {
-	gprs_rlcmac_rcv_rts_block(bts, trx_no, ts_no, arfcn, *fn, *block_nr);
+	uint8_t bn = fn2bn(*fn);
+	gprs_rlcmac_rcv_rts_block(bts, trx_no, ts_no, arfcn, *fn, bn);
 	*fn = fn_add_blocks(*fn, 1);
-	*block_nr += 1;
+	bn += 1;
+	if (block_nr)
+		*block_nr = bn;
 }
 
 static void send_rlc_block(struct gprs_rlcmac_tbf *tbf,
-	uint32_t *fn, uint8_t *block_nr)
+	uint32_t *fn, uint8_t *block_nr = NULL)
 {
 	send_rlc_block(tbf->bts->bts_data(), tbf->trx->trx_no,
 		tbf->control_ts, tbf->trx->arfcn, fn, block_nr);
@@ -254,10 +257,10 @@
 
 	/* Send only a few RLC/MAC blocks */
 	fn = 0;
-	block_nr = 0;
-	while (block_nr < 3)
+	do {
 		/* Request to send one block */
 		send_rlc_block(dl_tbf, &fn, &block_nr);
+	} while (block_nr < 3);
 
 	OSMO_ASSERT(dl_tbf->have_data());
 	OSMO_ASSERT(dl_tbf->state_is(GPRS_RLCMAC_FLOW));
@@ -299,7 +302,6 @@
 	unsigned i;
 	uint8_t ms_class = 45;
 	uint32_t fn = 0;
-	uint8_t block_nr = 0;
 	uint8_t trx_no;
 	uint32_t tlli = 0xffeeddcc;
 
@@ -331,7 +333,7 @@
 	/* Drain the queue */
 	while (dl_tbf->have_data())
 		/* Request to send one RLC/MAC block */
-		send_rlc_block(dl_tbf, &fn, &block_nr);
+		send_rlc_block(dl_tbf, &fn);
 
 	OSMO_ASSERT(dl_tbf->state_is(GPRS_RLCMAC_FLOW));
 
@@ -342,7 +344,7 @@
 	OSMO_ASSERT(dl_tbf->m_window.window_empty());
 
 	/* Force sending of a single block containing an LLC dummy command */
-	send_rlc_block(dl_tbf, &fn, &block_nr);
+	send_rlc_block(dl_tbf, &fn);
 
 	/* Receive an ACK */
 	dl_tbf->rcvd_dl_ack(0, dl_tbf->m_window.v_s(), rbb);
@@ -350,7 +352,7 @@
 
 	/* Timeout (make sure fn % 52 remains valid) */
 	fn += 52 * ((msecs_to_frames(bts->dl_tbf_idle_msec + 100) + 51)/ 52);
-	send_rlc_block(dl_tbf, &fn, &block_nr);
+	send_rlc_block(dl_tbf, &fn);
 
 	OSMO_ASSERT(dl_tbf->state_is(GPRS_RLCMAC_FINISHED));
 
@@ -595,7 +597,6 @@
 	GprsMs *ms;
 	uint32_t rach_fn = *fn - 51;
 	uint32_t sba_fn = *fn + 52;
-	uint8_t rts_bn = fn2bn(*fn);
 	uint8_t trx_no = 0;
 	int tfi = 0;
 	gprs_rlcmac_ul_tbf *ul_tbf;
@@ -608,7 +609,7 @@
 	bts = the_bts->bts_data();
 
 	/* needed to set last_rts_fn in the PDCH object */
-	send_rlc_block(bts, trx_no, ts_no, 0, fn, &rts_bn);
+	send_rlc_block(bts, trx_no, ts_no, 0, fn);
 
 	/* simulate RACH, this sends an Immediate Assignment Uplink on the AGCH */
 	the_bts->rcv_rach(0x73, rach_fn, qta);
@@ -642,8 +643,7 @@
 
 	/* send packet uplink assignment */
 	*fn = sba_fn;
-	rts_bn = fn2bn(*fn);
-	send_rlc_block(ul_tbf, fn, &rts_bn);
+	send_rlc_block(ul_tbf, fn);
 
 	/* TODO: send real acknowledgement */
 	/* Fake acknowledgement */