[paging] This is paging my phone but it looks completely wrong...

- The paging block calculation is wrong but I have a hard time finding
  the right information. The table of 05.02 (Table 5 of 9) looks good
  but my phone is not happy with that group...

diff --git a/include/openbsc/abis_rsl.h b/include/openbsc/abis_rsl.h
index 420f3f4..1968671 100644
--- a/include/openbsc/abis_rsl.h
+++ b/include/openbsc/abis_rsl.h
@@ -376,6 +376,7 @@
 unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
 			      int n_pag_blocks);
 unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res);
+u_int64_t str_to_imsi(const char *imsi_str);
 
 /* to be provided by external code */
 int abis_rsl_sendmsg(struct msgb *msg);
diff --git a/src/abis_rsl.c b/src/abis_rsl.c
index 2e1224d..0fa32ed 100644
--- a/src/abis_rsl.c
+++ b/src/abis_rsl.c
@@ -852,9 +852,9 @@
 {
 	if (bts->chan_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) {
 		return MAX(1, (3 - bts->chan_desc.bs_ag_blks_res))
-			* bts->chan_desc.bs_pa_mfrms;
+			* (bts->chan_desc.bs_pa_mfrms + 2);
 	} else {
 		return (9 - bts->chan_desc.bs_ag_blks_res)
-			* bts->chan_desc.bs_pa_mfrms;
+			* (bts->chan_desc.bs_pa_mfrms + 2);
 	}
 }
diff --git a/src/paging.c b/src/paging.c
index e580ac7..0461572 100644
--- a/src/paging.c
+++ b/src/paging.c
@@ -48,6 +48,22 @@
 
 static LLIST_HEAD(managed_bts);
 
+static unsigned int calculate_group(struct gsm_bts *bts, struct gsm_subscriber *subscr)
+{
+	int ccch_conf;
+	int bs_cc_chans;
+	int blocks;
+	unsigned int group;
+	
+	ccch_conf = bts->chan_desc.ccch_conf;
+	bs_cc_chans = rsl_ccch_conf_to_bs_cc_chans(ccch_conf);
+	/* code word + 2, as 2 channels equals 0x0 */
+	blocks = bts->chan_desc.bs_pa_mfrms + 2;
+	group = get_paging_group(str_to_imsi(subscr->imsi),
+					bs_cc_chans, blocks);
+	return group;
+}
+
 /*
  * Kill one paging request update the internal list...
  */
@@ -66,6 +82,7 @@
 	u_int8_t mi[128];
 	unsigned long int tmsi;
 	unsigned int mi_len;
+	unsigned int pag_group;
 	struct paging_bts *paging_bts = (struct paging_bts *)data;
 	struct paging_request *request = NULL;
 
@@ -82,9 +99,11 @@
 	DEBUGP(DPAG, "Going to send paging commands: '%s'\n",
 		request->subscr->imsi);
 	++request->requests;
+
+	pag_group = calculate_group(paging_bts->bts, request->subscr);
 	tmsi = strtoul(request->subscr->tmsi, NULL, 10);
 	mi_len = generate_mid_from_tmsi(mi, tmsi);
-	rsl_paging_cmd(paging_bts->bts, 1, mi_len, mi,
+	rsl_paging_cmd(paging_bts->bts, pag_group, mi_len, mi,
 			request->chan_type);
 
 	if (request->requests > MAX_PAGING_REQUEST) {