CBSP: fix encoding/decoding of keep-alive repetition period

Even though the value is only between 0..120s, they didn't encode
it 1:1 in the uint8_t, but 3GPP chose to use the same encoding
as for the warning period (which has a much larger range).

Let's fix this in our implementation.

Before this patch, osmo-cbc wanted to send 30s keep-alive repetition
period, but a spec-compliant receiver actually decoded this as 80s.

Change-Id: I04baa6b6b99b092fa0512b3b6138a363c7f3a13d
diff --git a/src/gsm/cbsp.c b/src/gsm/cbsp.c
index 2c7a7b7..fa599c5 100644
--- a/src/gsm/cbsp.c
+++ b/src/gsm/cbsp.c
@@ -352,7 +352,12 @@
 /* 8.1.3.18a KEEP ALIVE */
 static int cbsp_enc_keep_alive(struct msgb *msg, const struct osmo_cbsp_keep_alive *in)
 {
-	msgb_tv_put(msg, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, in->repetition_period);
+	int rperiod = encode_wperiod(in->repetition_period);
+	if (in->repetition_period > 120)
+		return -EINVAL;
+	if (rperiod < 0)
+		return -EINVAL;
+	msgb_tv_put(msg, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, rperiod);
 	return 0;
 }
 
@@ -1083,12 +1088,14 @@
 static int cbsp_dec_keep_alive(struct osmo_cbsp_keep_alive *out, const struct tlv_parsed *tp,
 				struct msgb *in, void *ctx)
 {
+	uint8_t rperiod;
 	if (!TLVP_PRES_LEN(tp, CBSP_IEI_KEEP_ALIVE_REP_PERIOD, 1)) {
 		osmo_cbsp_errstr = "missing/short mandatory IE";
 		return -EINVAL;
 	}
 
-	out->repetition_period = *TLVP_VAL(tp, CBSP_IEI_KEEP_ALIVE_REP_PERIOD);
+	rperiod = *TLVP_VAL(tp, CBSP_IEI_KEEP_ALIVE_REP_PERIOD);
+	out->repetition_period = decode_wperiod(rperiod);
 	return 0;
 }