edge: Provide and use CS -> CPS conversion

The MS' RLC receiver needs a valid CPS field to decode the block.

Add the function gprs_rlc_mcs_cps to generate the CPS value based on
coding scheme, puncturing, and padding.

Sponsored-by: On-Waves ehf
diff --git a/src/rlc.cpp b/src/rlc.cpp
index 44ce817..1a8efdf 100644
--- a/src/rlc.cpp
+++ b/src/rlc.cpp
@@ -311,3 +311,18 @@
 	rdbi->pi  = 0;
 	rdbi->spb = 0;
 }
+
+unsigned int gprs_rlc_mcs_cps(GprsCodingScheme cs, int punct, int with_padding)
+{
+	switch (GprsCodingScheme::Scheme(cs)) {
+	case GprsCodingScheme::MCS1: return 0b1011 + punct % 2;
+	case GprsCodingScheme::MCS2: return 0b1001 + punct % 2;
+	case GprsCodingScheme::MCS3: return (with_padding ? 0b0110 : 0b0011) +
+					    punct % 3;
+	case GprsCodingScheme::MCS4: return 0b0000 + punct % 3;
+	/* TODO: Add missing MCS */
+	default: ;
+	}
+
+	return -1;
+}
diff --git a/src/rlc.h b/src/rlc.h
index a11b4ce..76af4e1 100644
--- a/src/rlc.h
+++ b/src/rlc.h
@@ -105,6 +105,7 @@
 	GprsCodingScheme cs);
 void gprs_rlc_data_block_info_init(struct gprs_rlc_data_block_info *rdbi,
 	GprsCodingScheme cs);
+unsigned int gprs_rlc_mcs_cps(GprsCodingScheme cs, int punct, int with_padding);
 
 /*
  * I hold the currently transferred blocks and will provide
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 5607e9e..e742c79 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -539,6 +539,7 @@
 	rlc.usf = 7; /* will be set at scheduler */
 	rlc.pr = 0; /* FIXME: power reduction */
 	rlc.tfi = m_tfi; /* TFI */
+	rlc.cps = gprs_rlc_mcs_cps(cs, 0, 0);
 
 	rlc.block_info[data_block_idx] = m_rlc.block(index)->block_info;
 	rdbi = &rlc.block_info[data_block_idx];