bts_pch_timer: Avoid resend Paging Request over PCUIF if T3113 is armed

Let's avoid flooding the BTS and taking CCCH resources for no good
reason. If user configures everything correctly, the SGSN should not
attempt a retry after similar timer >= T3113.

Related: OS#5297
Change-Id: I2a77714648d16ccff2a340ce775e83dcc5ffe707
diff --git a/src/bts.cpp b/src/bts.cpp
index 2dc8ffb..dc20259 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -134,6 +134,7 @@
 	{ "llc:dl_bytes",               "RLC encapsulated PDUs"},
 	{ "llc:ul_bytes",               "full PDUs received   "},
 	{ "pch:requests",		"PCH requests sent    "},
+	{ "pch:requests:already",	"PCH requests on subscriber already being paged"},
 	{ "pch:requests:timeout",	"PCH requests timeout "},
 	{ "rach:requests",		"RACH requests received"},
 	{ "rach:requests:11bit",	"11BIT_RACH requests received"},
diff --git a/src/bts.h b/src/bts.h
index 3f482c9..3a58c63 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -126,6 +126,7 @@
 	CTR_LLC_DL_BYTES,
 	CTR_LLC_UL_BYTES,
 	CTR_PCH_REQUESTS,
+	CTR_PCH_REQUESTS_ALREADY,
 	CTR_PCH_REQUESTS_TIMEDOUT,
 	CTR_RACH_REQUESTS,
 	CTR_RACH_REQUESTS_11BIT,
diff --git a/src/bts_pch_timer.c b/src/bts_pch_timer.c
index 312d85a..d721155 100644
--- a/src/bts_pch_timer.c
+++ b/src/bts_pch_timer.c
@@ -41,7 +41,7 @@
 	return NULL;
 }
 
-static struct bts_pch_timer *bts_pch_timer_get_by_imsi(struct gprs_rlcmac_bts *bts, const char *imsi)
+struct bts_pch_timer *bts_pch_timer_get_by_imsi(struct gprs_rlcmac_bts *bts, const char *imsi)
 {
 	struct bts_pch_timer *p;
 
@@ -77,10 +77,6 @@
 	struct bts_pch_timer *p;
 	struct osmo_tdef *tdef;
 
-	/* We already have a timer running for this IMSI */
-	if (bts_pch_timer_get_by_imsi(bts, imsi))
-		return;
-
 	p = talloc_zero(bts, struct bts_pch_timer);
 	llist_add_tail(&p->entry, &bts->pch_timer);
 	p->bts = bts;
diff --git a/src/bts_pch_timer.h b/src/bts_pch_timer.h
index 3e47161..cc5dcb0 100644
--- a/src/bts_pch_timer.h
+++ b/src/bts_pch_timer.h
@@ -42,6 +42,7 @@
 			 const char *imsi);
 void bts_pch_timer_stop(struct gprs_rlcmac_bts *bts, const struct GprsMs *ms);
 void bts_pch_timer_stop_all(struct gprs_rlcmac_bts *bts);
+struct bts_pch_timer *bts_pch_timer_get_by_imsi(struct gprs_rlcmac_bts *bts, const char *imsi);
 
 #ifdef __cplusplus
 }
diff --git a/src/gprs_bssgp_pcu.c b/src/gprs_bssgp_pcu.c
index 424a381..4328e07 100644
--- a/src/gprs_bssgp_pcu.c
+++ b/src/gprs_bssgp_pcu.c
@@ -320,6 +320,11 @@
 
 	/* FIXME: look if MS is attached a specific BTS and then only page on that one? */
 	llist_for_each_entry(bts, &the_pcu->bts_list, list) {
+		if (bts_pch_timer_get_by_imsi(bts, mi_imsi.imsi)) {
+			LOGP(DBSSGP, LOGL_INFO, "PS-Paging request already pending for IMSI=%s\n", mi_imsi.imsi);
+			bts_do_rate_ctr_inc(bts, CTR_PCH_REQUESTS_ALREADY);
+			continue;
+		}
 		if (gprs_rlcmac_paging_request(bts, &paging_mi, pgroup) < 0)
 			continue;
 		bts_pch_timer_start(bts, &paging_mi, mi_imsi.imsi);