Fix MS TO measurement representation

* set proper flag when saving MS Timing Offset
* use gsm_subscriber's IMSI or lchan's name if bsc_subscriber is unknown
* add comments with spec reference
* store/display MS Timing Offset instead of raw Timing Offset field from
  RSL
* Compute MS Timing Offset [-63; 192] from Timing Offset field [0; 255],
  adjust structure gsm_meas_rep with proper type to store it

Change-Id: I7e003d23a6edb714c5f17688fd6a8edac131161d
Related: OS#1574
diff --git a/openbsc/src/libbsc/abis_rsl.c b/openbsc/src/libbsc/abis_rsl.c
index 5ae707c..be687eb 100644
--- a/openbsc/src/libbsc/abis_rsl.c
+++ b/openbsc/src/libbsc/abis_rsl.c
@@ -41,6 +41,7 @@
 #include <openbsc/signal.h>
 #include <openbsc/meas_rep.h>
 #include <openbsc/rtp_proxy.h>
+#include <openbsc/gsm_subscriber.h>
 #include <osmocom/abis/e1_input.h>
 #include <osmocom/gsm/rsl.h>
 #include <osmocom/core/talloc.h>
@@ -1369,8 +1370,14 @@
 	int i;
 	const char *name = "";
 
-	if (lchan && lchan->conn)
-		name = bsc_subscr_name(lchan->conn->bsub);
+	if (lchan && lchan->conn) {
+		if (lchan->conn->bsub)
+			name = bsc_subscr_name(lchan->conn->bsub);
+		else if (lchan->conn->subscr)
+			name = lchan->conn->subscr->imsi;
+		else
+			name = lchan->name;
+	}
 
 	DEBUGP(DMEAS, "[%s] MEASUREMENT RESULT NR=%d ", name, mr->nr);
 
@@ -1379,6 +1386,7 @@
 
 	print_meas_rep_uni(&mr->ul, "ul");
 	DEBUGPC(DMEAS, "BS_POWER=%d ", mr->bs_power);
+
 	if (mr->flags & MEAS_REP_F_MS_TO)
 		DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);
 
@@ -1452,9 +1460,11 @@
 	mr->bs_power = *TLVP_VAL(&tp, RSL_IE_BS_POWER);
 
 	/* Optional Parts */
-	if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET))
-		mr->ms_timing_offset =
-			*TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET);
+	if (TLVP_PRESENT(&tp, RSL_IE_MS_TIMING_OFFSET)) {
+		/* According to 3GPP TS 48.058 § MS Timing Offset = Timing Offset field - 63 */
+		mr->ms_timing_offset = *TLVP_VAL(&tp, RSL_IE_MS_TIMING_OFFSET) - 63;
+		mr->flags |= MEAS_REP_F_MS_TO;
+	}
 
 	if (TLVP_PRESENT(&tp, RSL_IE_L1_INFO)) {
 		struct e1inp_sign_link *sign_link = msg->dst;