Improve TBF logging

use a format in tbf::name() which is sanitized (osmo_sanitize) and hence
can be used both in regular log as well as for its internal FSM ids.
Until now, the FSMs contained a small amount of information with
different formatting than the regular LOGPTFB(), which made it difficult
to grep or follow a TBF through its lifetime looking at logs. The new
unified format makes that a lot easier.

Extra information is now printed if available, such as IMSI.
Furthermore, the TFI is updated to include BTS and TRX, since the TFI is
unique within the scope of a TRX.

Change-Id: I3ce1f53942a2f881d0adadd6e5643f5cdf6e31da
diff --git a/src/gprs_ms.c b/src/gprs_ms.c
index f233967..aa410aa 100644
--- a/src/gprs_ms.c
+++ b/src/gprs_ms.c
@@ -473,6 +473,20 @@
 	ms_unref(old_ms);
 }
 
+/* Apply changes to the TLLI directly, used interally by functions below: */
+static void ms_apply_tlli_change(struct GprsMs *ms, uint32_t tlli)
+{
+	ms->tlli = tlli;
+	ms->new_dl_tlli = GSM_RESERVED_TMSI;
+	ms->new_ul_tlli = GSM_RESERVED_TMSI;
+
+	/* Update TBF FSM names: */
+	if (ms->ul_tbf)
+		tbf_update_state_fsm_name(ul_tbf_as_tbf(ms->ul_tbf));
+	if (ms->dl_tbf)
+		tbf_update_state_fsm_name(dl_tbf_as_tbf(ms->dl_tbf));
+}
+
 /* Set/update the MS object TLLI based on knowledge gained from the MS side (Uplink direction) */
 void ms_set_tlli(struct GprsMs *ms, uint32_t tlli)
 {
@@ -493,9 +507,7 @@
 		"already confirmed partly\n",
 		ms->tlli, tlli);
 
-	ms->tlli = tlli;
-	ms->new_dl_tlli = GSM_RESERVED_TMSI;
-	ms->new_ul_tlli = GSM_RESERVED_TMSI;
+	ms_apply_tlli_change(ms, tlli);
 }
 
 /* Set/update the MS object TLLI based on knowledge gained from the SGSN side (Downlink direction) */
@@ -520,9 +532,7 @@
 	LOGP(DRLCMAC, LOGL_INFO,
 		"Modifying MS object, TLLI: 0x%08x confirmed\n", tlli);
 
-	ms->tlli = tlli;
-	ms->new_dl_tlli = GSM_RESERVED_TMSI;
-	ms->new_ul_tlli = GSM_RESERVED_TMSI;
+	ms_apply_tlli_change(ms, tlli);
 
 	return true;
 }
@@ -565,8 +575,14 @@
 		/* old_ms may no longer be available here */
 	}
 
-
+	/* Store the new IMSI: */
 	osmo_strlcpy(ms->imsi, imsi, sizeof(ms->imsi));
+
+	/* Update TBF FSM names: */
+	if (ms->ul_tbf)
+		tbf_update_state_fsm_name(ul_tbf_as_tbf(ms->ul_tbf));
+	if (ms->dl_tbf)
+		tbf_update_state_fsm_name(dl_tbf_as_tbf(ms->dl_tbf));
 }
 
 uint16_t ms_paging_group(struct GprsMs *ms)