RLC/MAC process makes use from attributes, received from PCU socket

For OpenBTS interface and BSSGP, fixed values are still used.
diff --git a/src/gprs_rlcmac.cpp b/src/gprs_rlcmac.cpp
index a9f4d13..bfed57d 100644
--- a/src/gprs_rlcmac.cpp
+++ b/src/gprs_rlcmac.cpp
@@ -385,6 +385,7 @@
 	}
 	else
 	{
+		struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
 		// GMS 04.08 10.5.2.37b 10.5.2.16
 		bitvec_write_field(dest, wp, 3, 2);    // "HH"
 		bitvec_write_field(dest, wp, 0, 2);    // "0" Packet Uplink Assignment
@@ -395,8 +396,8 @@
 		bitvec_write_field(dest, wp, usf, 3);    // USF
 		bitvec_write_field(dest, wp, 0, 1);    // USF_GRANULARITY
 		bitvec_write_field(dest, wp, 0 , 1);   // "0" power control: Not Present
-		bitvec_write_field(dest, wp, 0, 2);    // CHANNEL_CODING_COMMAND 
-		bitvec_write_field(dest, wp, 0, 1);    // TLLI_BLOCK_CHANNEL_CODING
+		bitvec_write_field(dest, wp, bts->initial_cs-1, 2);    // CHANNEL_CODING_COMMAND 
+		bitvec_write_field(dest, wp, 1, 1);    // TLLI_BLOCK_CHANNEL_CODING
 		bitvec_write_field(dest, wp, 1 , 1);   // "1" Alpha : Present
 		bitvec_write_field(dest, wp, 0, 4);    // Alpha
 		bitvec_write_field(dest, wp, 0, 5);    // Gamma
@@ -417,6 +418,7 @@
 	uint8_t poll)
 {
 	// TODO We should use our implementation of encode RLC/MAC Control messages.
+	struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
 	unsigned wp = 0;
 	int i;
 
@@ -439,8 +441,8 @@
 	}
 
 	bitvec_write_field(dest, wp,0x0,1); // Message escape
-	bitvec_write_field(dest, wp,0x0,2); // CHANNEL_CODING_COMMAND
-	bitvec_write_field(dest, wp,0x0,1); // TLLI_BLOCK_CHANNEL_CODING 
+	bitvec_write_field(dest, wp, bts->initial_cs-1, 2); // CHANNEL_CODING_COMMAND 
+	bitvec_write_field(dest, wp,0x1,1); // TLLI_BLOCK_CHANNEL_CODING 
 
 	bitvec_write_field(dest, wp,0x1,1); // switch TIMING_ADVANCE_VALUE = on
 	bitvec_write_field(dest, wp,ta,6); // TIMING_ADVANCE_VALUE
@@ -448,7 +450,7 @@
 
 #if 1
 	bitvec_write_field(dest, wp,0x1,1); // Frequency Parameters information elements = present
-	bitvec_write_field(dest, wp,tsc,3); // Training Sequence Code (TSC) = 2
+	bitvec_write_field(dest, wp,tsc,3); // Training Sequence Code (TSC)
 	bitvec_write_field(dest, wp,0x0,2); // ARFCN = present
 	bitvec_write_field(dest, wp,arfcn,10); // ARFCN
 #else
diff --git a/src/gprs_rlcmac.h b/src/gprs_rlcmac.h
index 686b70e..94d88d2 100644
--- a/src/gprs_rlcmac.h
+++ b/src/gprs_rlcmac.h
@@ -85,14 +85,6 @@
 
 #define Tassign_agch 0,500000/* wait for assignment, before transmitting DL */
 #define Tassign_pacch 0,100000/* wait for assignment, before transmitting DL */
-#define T3169 6,0	/* 5 seconds + one second, because we don't use
-			 * counters before starting timer. */
-#define T3191 5,0	/* 5 Seconds */
-#define T3193 2,0	/* >T3192, which can be max 1,5s */
-#define T3195 5,0	/* 5 Seconds */
-//#define N3101_MAX 12	/* how many missed uplink blocks */
-#define N3103_MAX 4	/* how many tries to poll PACKET CONTROL ACK */
-#define N3105_MAX 4	/* how many tries to poll PACKET DOWNLINK ACK */
 
 enum gprs_rlcmac_tbf_state {
 	GPRS_RLCMAC_NULL = 0,	/* new created TBF */
diff --git a/src/gprs_rlcmac_data.cpp b/src/gprs_rlcmac_data.cpp
index c88ca04..a2b21a9 100644
--- a/src/gprs_rlcmac_data.cpp
+++ b/src/gprs_rlcmac_data.cpp
@@ -73,11 +73,13 @@
 			"CONTROL ACK for PACKET UPLINK ACK\n");
 		tbf->ul_ack_state = GPRS_RLCMAC_UL_ACK_NONE;
 		if (tbf->state == GPRS_RLCMAC_FINISHED) {
+			struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
+
 			tbf->dir.ul.n3103++;
-			if (tbf->dir.ul.n3103 == N3103_MAX) {
+			if (tbf->dir.ul.n3103 == bts->n3103) {
 				LOGP(DRLCMAC, LOGL_DEBUG, "- N3103 exceeded\n");
 				tbf_new_state(tbf, GPRS_RLCMAC_RELEASING);
-				tbf_timer_start(tbf, 3169, T3169);
+				tbf_timer_start(tbf, 3169, bts->t3169, 0);
 				return 0;
 			}
 			/* reschedule UL ack */
@@ -101,13 +103,15 @@
 	} else
 	if (tbf->direction == GPRS_RLCMAC_DL_TBF)
 	{
+		struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
+
 		LOGP(DRLCMAC, LOGL_DEBUG, "- Timeout for polling PACKET "
 			" DOWNLINK ACK.\n");
 		tbf->dir.dl.n3105++;
-		if (tbf->dir.dl.n3105 == N3105_MAX) {
+		if (tbf->dir.dl.n3105 == bts->n3105) {
 			LOGP(DRLCMAC, LOGL_DEBUG, "- N3105 exceeded\n");
 			tbf_new_state(tbf, GPRS_RLCMAC_RELEASING);
-			tbf_timer_start(tbf, 3195, T3195);
+			tbf_timer_start(tbf, 3195, bts->t3195, 0);
 			return 0;
 		}
 	}
@@ -189,6 +193,7 @@
 		if (ul_control_block->u.Packet_Downlink_Ack_Nack.Exist_Channel_Request_Description) {
 			uint8_t trx, ts, usf;
 			struct gprs_rlcmac_tbf *ul_tbf;
+			struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
 
 			LOGP(DRLCMAC, LOGL_DEBUG, "MS requests UL TBF in ack "
 				"message, so we provide one:\n");
@@ -213,7 +218,7 @@
 			ul_tbf->direction = GPRS_RLCMAC_UL_TBF;
 			ul_tbf->dir.ul.usf = usf;
 			tbf_new_state(ul_tbf, GPRS_RLCMAC_FLOW);
-			tbf_timer_start(ul_tbf, 3169, T3169);
+			tbf_timer_start(ul_tbf, 3169, bts->t3169, 0);
 			LOGP(DRLCMAC, LOGL_NOTICE, "TBF: [UPLINK] START TFI: %u\n", ul_tbf->tfi);
 			/* schedule uplink assignment */
 			tbf->ul_ass_state = GPRS_RLCMAC_UL_ASS_SEND_ASS;
@@ -550,14 +555,30 @@
  */
 int gprs_rlcmac_rcv_data_block_acknowledged(uint8_t *data, uint8_t len)
 {
+	struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
 	struct gprs_rlcmac_tbf *tbf;
 	struct rlc_ul_header *rh = (struct rlc_ul_header *)data;
 	uint16_t mod_sns, mod_sns_half, offset_v_q, offset_v_r, index;
 	int rc;
 
-	if (len < 23) {
-		LOGP(DRLCMACUL, LOGL_ERROR, "Dropping short frame "
-			"(len = %d)\n", len);
+	switch (len) {
+		case 54:
+			/* omitting spare bits */
+			len = 53;
+			break;
+		case 40:
+			/* omitting spare bits */
+			len = 39;
+			break;
+		case 34:
+			/* omitting spare bits */
+			len = 33;
+			break;
+		case 23:
+			break;
+	default:
+		LOGP(DRLCMACUL, LOGL_ERROR, "Dropping data block with invalid"
+			"length: %d)\n", len);
 		return -EINVAL;
 	}
 
@@ -616,7 +637,7 @@
 	mod_sns_half = (tbf->sns >> 1) - 1;
 
 	/* restart T3169 */
-	tbf_timer_start(tbf, 3169, T3169);
+	tbf_timer_start(tbf, 3169, bts->t3169, 0);
 
 	/* Increment RX-counter */
 	tbf->dir.ul.rx_counter++;
@@ -782,6 +803,7 @@
 
 int gprs_rlcmac_rcv_rach(uint8_t ra, uint32_t Fn, int16_t qta)
 {
+	struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts;
 	struct gprs_rlcmac_tbf *tbf;
 	uint8_t trx, ts;
 	int tfi, usf; /* must be signed */
@@ -810,7 +832,7 @@
 	tbf->direction = GPRS_RLCMAC_UL_TBF;
 	tbf->dir.ul.usf = usf;
 	tbf_new_state(tbf, GPRS_RLCMAC_FLOW);
-	tbf_timer_start(tbf, 3169, T3169);
+	tbf_timer_start(tbf, 3169, bts->t3169, 0);
 	LOGP(DRLCMAC, LOGL_NOTICE, "TBF: [UPLINK] START TFI: %u\n", tbf->tfi);
 	LOGP(DRLCMAC, LOGL_NOTICE, "RX: [PCU <- BTS] TFI: %u RACH qbit-ta=%d ra=%d, Fn=%d (%d,%d,%d)\n", tbf->tfi, qta, ra, Fn, (Fn / (26 * 51)) % 32, Fn % 51, Fn % 26);
 	LOGP(DRLCMAC, LOGL_NOTICE, "TX: [PCU -> BTS] TFI: %u Packet Immidiate Assignment\n", tbf->tfi);
@@ -1106,7 +1128,7 @@
 		else  {
 			/* start timer whenever we send the final block */
 			if (rh->fbi == 1)
-				tbf_timer_start(tbf, 3191, T3191);
+				tbf_timer_start(tbf, 3191, bts->t3191, 0);
 
 			/* schedule polling */
 			tbf->poll_state = GPRS_RLCMAC_POLL_SCHED;
@@ -1219,7 +1241,8 @@
 		LOGP(DRLCMACDL, LOGL_DEBUG, "- No new message, so we "
 			"release.\n");
 		/* start T3193 */
-		tbf_timer_start(tbf, 3193, T3193);
+		tbf_timer_start(tbf, 3193, bts->t3193_msec / 1000,
+			bts->t3193_msec & 1000);
 		tbf_new_state(tbf, GPRS_RLCMAC_WAIT_RELEASE);
 
 		return 0;
diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp
index ae176bc..8f64e31 100644
--- a/src/pcu_main.cpp
+++ b/src/pcu_main.cpp
@@ -54,11 +54,22 @@
 	uint16_t nsvci = NSVCI;
 	struct gprs_ns_inst *sgsn_nsi;
 	struct gprs_nsvc *nsvc;
+	struct gprs_rlcmac_bts *bts;
 
-	gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts);
+	bts = gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts);
 	if (!gprs_rlcmac_bts)
 		return -ENOMEM;
 	gprs_rlcmac_bts->initial_cs = 1;
+	bts->initial_cs = 1;
+	bts->cs1 = 1;
+	bts->t3142 = 20;
+	bts->t3169 = 5;
+	bts->t3191 = 5;
+	bts->t3193_msec = 100;
+	bts->t3195 = 5;
+	bts->n3101 = 10;
+	bts->n3103 = 4;
+	bts->n3105 = 8;
 
 	osmo_init_logging(&gprs_log_info);
 	pcu_l1if_open();