gprs_llc: Assert that we send frames with either tlli or old_tlli

In case we have access to the context verify that the selected
msgb_tlli is either the old_tlli or the tlli in either local or
foreign format. It is wrong to use any other TLLI.
diff --git a/openbsc/src/gprs/gprs_llc.c b/openbsc/src/gprs/gprs_llc.c
index 5a74a63..c4be086 100644
--- a/openbsc/src/gprs/gprs_llc.c
+++ b/openbsc/src/gprs/gprs_llc.c
@@ -84,6 +84,21 @@
 
 static struct gprs_llc_llme *llme_alloc(uint32_t tlli);
 
+/* If the TLLI is foreign, return its local version */
+static inline uint32_t tlli_foreign2local(uint32_t tlli)
+{
+	uint32_t new_tlli;
+
+	if (gprs_tlli_type(tlli) == TLLI_FOREIGN) {
+		new_tlli = tlli | 0x40000000;
+		DEBUGP(DLLC, "TLLI 0x%08x is foreign, converting to "
+			"local TLLI 0x%08x\n", tlli, new_tlli);
+	} else
+		new_tlli = tlli;
+
+	return new_tlli;
+}
+
 /* Entry function from upper level (LLC), asking us to transmit a BSSGP PDU
  * to a remote MS (identified by TLLI) at a BTS identified by its BVCI and NSEI */
 static int _bssgp_tx_dl_ud(struct msgb *msg, struct sgsn_mm_ctx *mmctx)
@@ -100,6 +115,12 @@
 		dup.drx_parms = mmctx->drx_parms;
 		dup.ms_ra_cap.len = mmctx->ms_radio_access_capa.len;
 		dup.ms_ra_cap.v = mmctx->ms_radio_access_capa.buf;
+
+		/* make sure we only send it to the right llme */
+		OSMO_ASSERT(msgb_tlli(msg) == mmctx->llme->tlli
+				|| msgb_tlli(msg) == mmctx->llme->old_tlli
+				|| tlli_foreign2local(msgb_tlli(msg)) == mmctx->llme->tlli
+				|| tlli_foreign2local(msgb_tlli(msg)) == mmctx->llme->old_tlli);
 	}
 	memcpy(&dup.qos_profile, qos_profile_default,
 		sizeof(qos_profile_default));
@@ -179,21 +200,6 @@
 LLIST_HEAD(gprs_llc_llmes);
 void *llc_tall_ctx;
 
-/* If the TLLI is foreign, return its local version */
-static inline uint32_t tlli_foreign2local(uint32_t tlli)
-{
-	uint32_t new_tlli;
-
-	if (gprs_tlli_type(tlli) == TLLI_FOREIGN) {
-		new_tlli = tlli | 0x40000000;
-		DEBUGP(DLLC, "TLLI 0x%08x is foreign, converting to "
-			"local TLLI 0x%08x\n", tlli, new_tlli);
-	} else
-		new_tlli = tlli;
-
-	return new_tlli;
-}
-
 /* lookup LLC Entity based on DLCI (TLLI+SAPI tuple) */
 static struct gprs_llc_lle *lle_by_tlli_sapi(const uint32_t tlli, uint8_t sapi)
 {