Optimize PAGING-CS PDCH set selection when target MS is known

Before this patch, when a PAGING-GS was received in PCU from SGSN, it
would always forward the paging request to all PDCHs in all TRXs of all
BTS (well, it did some heuristics to avoid sending it in some PDCHs
where onyl repeated TBFs would be listening).

The previous behavior, didn't make much sense in the case where the PCU
is asked to page an MS which it knows (ie in which PDCHs is listening
to). Hence, in that case it makes sense to simply send the paging
request on 1 PDCH where the MS is listening, instead of sending it in a
big set of different PDCHs.

This commit also splits the old get_paging_mi() helper which was
erroneously created to parseboth CS/PS-PAGING requesst, since they
actually use a different set of target subscriber information (for
instance, CS-PAGING provides optionally a TLLI, and one provides P-TMSI
while the other provides TMSI).

In this patch, the handling of CS paging request is split into 2 parts:
1- A new helper "struct paging_req_cs" is introduced, where incoming
CS-PAGING requests (from both SGSN over BSSGP and BTS/BSC over PCUIF)
are parsed and information stored. Then, from available information, it
tries to find a target MS if avaialable
2- bts_add_paging() is called from both BSSGP and PCUIF paths with the
helper struct and the target MS (NULL if not found). If MS exists,
paging is forwarding only on 1 PDCH that MS is attached to. If no MS
exists, then the old heursitics are used to forward the request to all
MS.

Change-Id: Iea46d5321a29d800813b1aa2bf4ce175ce45e2cf
diff --git a/src/pcu_l1_if.cpp b/src/pcu_l1_if.cpp
index 0ccf642..cfd36d7 100644
--- a/src/pcu_l1_if.cpp
+++ b/src/pcu_l1_if.cpp
@@ -817,6 +817,9 @@
 static int pcu_rx_pag_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_pag_req *pag_req)
 {
 	struct osmo_mobile_identity mi;
+	struct GprsMs *ms = NULL;
+	struct paging_req_cs req = { .chan_needed = pag_req->chan_needed,
+				     .tlli = GSM_RESERVED_TMSI };
 	int rc;
 
 	LOGP(DL1IF, LOGL_DEBUG, "Paging request received: chan_needed=%d "
@@ -835,7 +838,23 @@
 		return -EINVAL;
 	}
 
-	return bts_add_paging(bts, pag_req->chan_needed, &mi);
+	switch (mi.type) {
+	case GSM_MI_TYPE_TMSI:
+		req.mi_tmsi = mi;
+		req.mi_tmsi_present = true;
+		/* TODO: look up MS by TMSI? Derive TLLI? */
+		break;
+	case GSM_MI_TYPE_IMSI:
+		req.mi_imsi = mi;
+		req.mi_imsi_present = true;
+		ms = bts_ms_by_imsi(bts, req.mi_imsi.imsi);
+		break;
+	default:
+		LOGP(DL1IF, LOGL_ERROR, "Unexpected MI type %u\n", mi.type);
+		return -EINVAL;
+	}
+
+	return bts_add_paging(bts, &req, ms);
 }
 
 static int pcu_rx_susp_req(struct gprs_rlcmac_bts *bts, struct gsm_pcu_if_susp_req *susp_req)