add struct gprs_subscr, separating gprs from gsm_subscriber

Prepare for replacing gsm_subscriber with vlr_subscriber. vlr_subscriber will
not make sense to be used in gprs, so have a dedicated GPRS subscriber struct.
(Could change if the gprs code were to use libvlr; is currently independent).

Related: OS#1592
Change-Id: Ia8b391ee009c8545763cba04505be3947835120e
diff --git a/openbsc/src/gprs/gprs_gmm.c b/openbsc/src/gprs/gprs_gmm.c
index 1026474..9efe402 100644
--- a/openbsc/src/gprs/gprs_gmm.c
+++ b/openbsc/src/gprs/gprs_gmm.c
@@ -64,6 +64,7 @@
 #include <openbsc/gprs_sgsn.h>
 #include <openbsc/gprs_gmm.h>
 #include <openbsc/gprs_utils.h>
+#include <openbsc/gprs_subscriber.h>
 #include <openbsc/sgsn.h>
 #include <openbsc/signal.h>
 #include <openbsc/iu.h>
diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index 260e032..727524e 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -31,7 +31,7 @@
 #include <osmocom/gprs/gprs_bssgp.h>
 #include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
 
-#include <openbsc/gsm_subscriber.h>
+#include <openbsc/gprs_subscriber.h>
 #include <openbsc/debug.h>
 #include <openbsc/gprs_sgsn.h>
 #include <openbsc/sgsn.h>
@@ -321,9 +321,9 @@
 
 	/* Detach from subscriber which is possibly freed then */
 	if (mm->subscr) {
-		struct gsm_subscriber *subscr = subscr_get(mm->subscr);
+		struct gprs_subscr *subscr = gprs_subscr_get(mm->subscr);
 		gprs_subscr_cleanup(subscr);
-		subscr_put(subscr);
+		gprs_subscr_put(subscr);
 	}
 
 	sgsn_mm_ctx_free(mm);
diff --git a/openbsc/src/gprs/gprs_subscriber.c b/openbsc/src/gprs/gprs_subscriber.c
index 57f73c5..5f426f8 100644
--- a/openbsc/src/gprs/gprs_subscriber.c
+++ b/openbsc/src/gprs/gprs_subscriber.c
@@ -23,7 +23,8 @@
 #include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
 #include <osmocom/gsm/gsup.h>
 #include <osmocom/core/utils.h>
-#include <openbsc/gsm_subscriber.h>
+#include <osmocom/core/logging.h>
+#include <openbsc/gprs_subscriber.h>
 #include <openbsc/gsup_client.h>
 
 #include <openbsc/sgsn.h>
@@ -35,6 +36,7 @@
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <limits.h>
 
 #define SGSN_SUBSCR_MAX_RETRIES 3
 #define SGSN_SUBSCR_RETRY_INTERVAL 10
@@ -46,6 +48,9 @@
 
 extern void *tall_bsc_ctx;
 
+LLIST_HEAD(_gprs_subscribers);
+struct llist_head * const gprs_subscribers = &_gprs_subscribers;
+
 static int gsup_read_cb(struct gsup_client *gsupc, struct msgb *msg);
 
 /* TODO: Some functions are specific to the SGSN, but this file is more general
@@ -86,7 +91,7 @@
 	return rc;
 }
 
-int gprs_subscr_purge(struct gsm_subscriber *subscr);
+int gprs_subscr_purge(struct gprs_subscr *subscr);
 
 static struct sgsn_subscriber_data *sgsn_subscriber_data_alloc(void *ctx)
 {
@@ -117,28 +122,53 @@
 	return pdata;
 }
 
-struct gsm_subscriber *gprs_subscr_get_or_create(const char *imsi)
+struct gprs_subscr *gprs_subscr_get_by_imsi(const char *imsi)
 {
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *gsub;
 
-	subscr = subscr_get_or_create(NULL, imsi);
-	if (!subscr)
+	if (!imsi || !*imsi)
 		return NULL;
 
-	if (!subscr->sgsn_data)
-		subscr->sgsn_data = sgsn_subscriber_data_alloc(subscr);
-	return subscr;
+	llist_for_each_entry(gsub, gprs_subscribers, entry) {
+		if (!strcmp(gsub->imsi, imsi))
+			return gprs_subscr_get(gsub);
+	}
+	return NULL;
 }
 
-struct gsm_subscriber *gprs_subscr_get_by_imsi(const char *imsi)
+static struct gprs_subscr *gprs_subscr_alloc(void)
 {
-	return subscr_active_by_imsi(NULL, imsi);
+	struct gprs_subscr *gsub;
+	gsub = talloc_zero(tall_bsc_ctx, struct gprs_subscr);
+	if (!gsub)
+		return NULL;
+	llist_add_tail(&gsub->entry, gprs_subscribers);
+	gsub->use_count = 1;
+	gsub->tmsi = GSM_RESERVED_TMSI;
+	return gsub;
 }
 
-void gprs_subscr_cleanup(struct gsm_subscriber *subscr)
+struct gprs_subscr *gprs_subscr_get_or_create(const char *imsi)
+{
+	struct gprs_subscr *gsub;
+
+	gsub = gprs_subscr_get_by_imsi(imsi);
+	if (!gsub) {
+		gsub = gprs_subscr_alloc();
+		if (!gsub)
+			return NULL;
+		strncpy(gsub->imsi, imsi, sizeof(gsub->imsi));
+	}
+
+	if (!gsub->sgsn_data)
+		gsub->sgsn_data = sgsn_subscriber_data_alloc(gsub);
+	return gsub;
+}
+
+void gprs_subscr_cleanup(struct gprs_subscr *subscr)
 {
 	if (subscr->sgsn_data->mm) {
-		subscr_put(subscr->sgsn_data->mm->subscr);
+		gprs_subscr_put(subscr->sgsn_data->mm->subscr);
 		subscr->sgsn_data->mm->subscr = NULL;
 		subscr->sgsn_data->mm = NULL;
 	}
@@ -149,7 +179,7 @@
 	}
 }
 
-void gprs_subscr_cancel(struct gsm_subscriber *subscr)
+void gprs_subscr_cancel(struct gprs_subscr *subscr)
 {
 	subscr->authorized = 0;
 	subscr->flags |= GPRS_SUBSCRIBER_CANCELLED;
@@ -159,7 +189,7 @@
 	gprs_subscr_cleanup(subscr);
 }
 
-static int gprs_subscr_tx_gsup_message(struct gsm_subscriber *subscr,
+static int gprs_subscr_tx_gsup_message(struct gprs_subscr *subscr,
 				       struct osmo_gsup_message *gsup_msg)
 {
 	struct msgb *msg = gsup_client_msgb_alloc();
@@ -181,7 +211,7 @@
 	return gsup_client_send(sgsn->gsup_client, msg);
 }
 
-static int gprs_subscr_tx_gsup_error_reply(struct gsm_subscriber *subscr,
+static int gprs_subscr_tx_gsup_error_reply(struct gprs_subscr *subscr,
 					   struct osmo_gsup_message *gsup_orig,
 					   enum gsm48_gmm_cause cause)
 {
@@ -196,7 +226,7 @@
 	return gprs_subscr_tx_gsup_message(subscr, &gsup_reply);
 }
 
-static int gprs_subscr_handle_gsup_auth_res(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_auth_res(struct gprs_subscr *subscr,
 					    struct osmo_gsup_message *gsup_msg)
 {
 	unsigned idx;
@@ -235,7 +265,7 @@
 	return 0;
 }
 
-static int gprs_subscr_pdp_data_clear(struct gsm_subscriber *subscr)
+static int gprs_subscr_pdp_data_clear(struct gprs_subscr *subscr)
 {
 	struct sgsn_subscriber_pdp_data *pdp, *pdp2;
 	int count = 0;
@@ -250,7 +280,7 @@
 }
 
 static struct sgsn_subscriber_pdp_data *gprs_subscr_pdp_data_get_by_id(
-	struct gsm_subscriber *subscr, unsigned context_id)
+	struct gprs_subscr *subscr, unsigned context_id)
 {
 	struct sgsn_subscriber_pdp_data *pdp;
 
@@ -263,7 +293,7 @@
 }
 
 
-static void gprs_subscr_gsup_insert_data(struct gsm_subscriber *subscr,
+static void gprs_subscr_gsup_insert_data(struct gprs_subscr *subscr,
 					 struct osmo_gsup_message *gsup_msg)
 {
 	struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
@@ -340,7 +370,7 @@
 	}
 }
 
-static int gprs_subscr_handle_gsup_upd_loc_res(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_upd_loc_res(struct gprs_subscr *subscr,
 					       struct osmo_gsup_message *gsup_msg)
 {
 	/* contrary to MAP, we allow piggy-backing subscriber data onto
@@ -357,7 +387,7 @@
 	return 0;
 }
 
-static int gprs_subscr_handle_gsup_dsd_req(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_dsd_req(struct gprs_subscr *subscr,
 					   struct osmo_gsup_message *gsup_msg)
 {
 	struct osmo_gsup_message gsup_reply = {0};
@@ -377,7 +407,7 @@
 	return gprs_subscr_tx_gsup_message(subscr, &gsup_reply);
 }
 
-static int gprs_subscr_handle_gsup_isd_req(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_isd_req(struct gprs_subscr *subscr,
 					   struct osmo_gsup_message *gsup_msg)
 {
 	struct osmo_gsup_message gsup_reply = {0};
@@ -409,7 +439,7 @@
 	}
 }
 
-static int gprs_subscr_handle_gsup_auth_err(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_auth_err(struct gprs_subscr *subscr,
 					    struct osmo_gsup_message *gsup_msg)
 {
 	unsigned idx;
@@ -462,7 +492,7 @@
 	return -gsup_msg->cause;
 }
 
-static int gprs_subscr_handle_gsup_upd_loc_err(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_upd_loc_err(struct gprs_subscr *subscr,
 					       struct osmo_gsup_message *gsup_msg)
 {
 	int cause_err;
@@ -523,7 +553,7 @@
 	return 0;
 }
 
-static int gprs_subscr_handle_gsup_purge_res(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_purge_res(struct gprs_subscr *subscr,
 					     struct osmo_gsup_message *gsup_msg)
 {
 	LOGGSUBSCRP(LOGL_INFO, subscr, "Completing purge MS\n");
@@ -535,7 +565,7 @@
 	return 0;
 }
 
-static int gprs_subscr_handle_gsup_purge_err(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_gsup_purge_err(struct gprs_subscr *subscr,
 					     struct osmo_gsup_message *gsup_msg)
 {
 	LOGGSUBSCRP(LOGL_NOTICE, subscr,
@@ -568,7 +598,7 @@
 	return -gsup_msg->cause;
 }
 
-static int gprs_subscr_handle_loc_cancel_req(struct gsm_subscriber *subscr,
+static int gprs_subscr_handle_loc_cancel_req(struct gprs_subscr *subscr,
 					     struct osmo_gsup_message *gsup_msg)
 {
 	struct osmo_gsup_message gsup_reply = {0};
@@ -629,7 +659,7 @@
 	int rc = 0;
 
 	struct osmo_gsup_message gsup_msg = {0};
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
 	rc = osmo_gsup_decode(data, data_len, &gsup_msg);
 	if (rc < 0) {
@@ -715,12 +745,12 @@
 		break;
 	};
 
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	return rc;
 }
 
-int gprs_subscr_purge(struct gsm_subscriber *subscr)
+int gprs_subscr_purge(struct gprs_subscr *subscr)
 {
 	struct sgsn_subscriber_data *sdata = subscr->sgsn_data;
 	struct osmo_gsup_message gsup_msg = {0};
@@ -736,7 +766,7 @@
 	return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
 }
 
-int gprs_subscr_query_auth_info(struct gsm_subscriber *subscr)
+int gprs_subscr_query_auth_info(struct gprs_subscr *subscr)
 {
 	struct osmo_gsup_message gsup_msg = {0};
 
@@ -747,7 +777,7 @@
 	return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
 }
 
-int gprs_subscr_location_update(struct gsm_subscriber *subscr)
+int gprs_subscr_location_update(struct gprs_subscr *subscr)
 {
 	struct osmo_gsup_message gsup_msg = {0};
 
@@ -758,60 +788,59 @@
 	return gprs_subscr_tx_gsup_message(subscr, &gsup_msg);
 }
 
-void gprs_subscr_update(struct gsm_subscriber *subscr)
+void gprs_subscr_update(struct gprs_subscr *subscr)
 {
 	LOGGSUBSCRP(LOGL_DEBUG, subscr, "Updating subscriber data\n");
 
 	subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING;
-	subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT;
+	subscr->flags &= ~GPRS_SUBSCRIBER_FIRST_CONTACT;
 
 	if (subscr->sgsn_data->mm)
 		sgsn_update_subscriber_data(subscr->sgsn_data->mm);
 }
 
-void gprs_subscr_update_auth_info(struct gsm_subscriber *subscr)
+void gprs_subscr_update_auth_info(struct gprs_subscr *subscr)
 {
 	LOGGSUBSCRP(LOGL_DEBUG, subscr,
 		"Updating subscriber authentication info\n");
 
 	subscr->flags &= ~GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING;
-	subscr->flags &= ~GSM_SUBSCRIBER_FIRST_CONTACT;
+	subscr->flags &= ~GPRS_SUBSCRIBER_FIRST_CONTACT;
 
 	if (subscr->sgsn_data->mm)
 		sgsn_update_subscriber_data(subscr->sgsn_data->mm);
 }
 
-struct gsm_subscriber *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mmctx)
+struct gprs_subscr *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mmctx)
 {
-	struct gsm_subscriber *subscr = NULL;
+	struct gprs_subscr *subscr = NULL;
 
 	if (mmctx->subscr)
-		return subscr_get(mmctx->subscr);
+		return gprs_subscr_get(mmctx->subscr);
 
 	if (mmctx->imsi[0])
 		subscr = gprs_subscr_get_by_imsi(mmctx->imsi);
 
 	if (!subscr) {
 		subscr = gprs_subscr_get_or_create(mmctx->imsi);
-		subscr->flags |= GSM_SUBSCRIBER_FIRST_CONTACT;
+		subscr->flags |= GPRS_SUBSCRIBER_FIRST_CONTACT;
 		subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
 	}
 
-	osmo_strlcpy(subscr->equipment.imei, mmctx->imei,
-		     sizeof(subscr->equipment.imei));
+	osmo_strlcpy(subscr->imei, mmctx->imei, sizeof(subscr->imei));
 
 	if (subscr->lac != mmctx->ra.lac)
 		subscr->lac = mmctx->ra.lac;
 
 	subscr->sgsn_data->mm = mmctx;
-	mmctx->subscr = subscr_get(subscr);
+	mmctx->subscr = gprs_subscr_get(subscr);
 
 	return subscr;
 }
 
 int gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx)
 {
-	struct gsm_subscriber *subscr = NULL;
+	struct gprs_subscr *subscr = NULL;
 	int rc;
 
 	LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber data update\n");
@@ -821,13 +850,13 @@
 	subscr->flags |= GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING;
 
 	rc = gprs_subscr_location_update(subscr);
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 	return rc;
 }
 
 int gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx)
 {
-	struct gsm_subscriber *subscr = NULL;
+	struct gprs_subscr *subscr = NULL;
 	int rc;
 
 	LOGMMCTXP(LOGL_DEBUG, mmctx, "Requesting subscriber authentication info\n");
@@ -837,6 +866,40 @@
 	subscr->flags |= GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING;
 
 	rc = gprs_subscr_query_auth_info(subscr);
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 	return rc;
 }
+
+static void gprs_subscr_free(struct gprs_subscr *gsub)
+{
+	llist_del(&gsub->entry);
+	talloc_free(gsub);
+}
+
+struct gprs_subscr *_gprs_subscr_get(struct gprs_subscr *gsub,
+				     const char *file, int line)
+{
+	OSMO_ASSERT(gsub->use_count < INT_MAX);
+	gsub->use_count++;
+	LOGPSRC(DREF, LOGL_DEBUG, file, line,
+		"subscr %s usage increases to: %d\n",
+		gsub->imsi, gsub->use_count);
+	return gsub;
+}
+
+struct gprs_subscr *_gprs_subscr_put(struct gprs_subscr *gsub,
+				     const char *file, int line)
+{
+	gsub->use_count--;
+	LOGPSRC(DREF, gsub->use_count >= 0? LOGL_DEBUG : LOGL_ERROR,
+		file, line,
+		"subscr %s usage decreases to: %d%s\n",
+		gsub->imsi, gsub->use_count,
+		gsub->keep_in_ram? ", keep-in-ram flag is set" : "");
+	if (gsub->use_count > 0)
+		return gsub;
+	if (gsub->keep_in_ram)
+		return gsub;
+	gprs_subscr_free(gsub);
+	return NULL;
+}
diff --git a/openbsc/src/gprs/sgsn_auth.c b/openbsc/src/gprs/sgsn_auth.c
index 1fa7fc4..df7ee37 100644
--- a/openbsc/src/gprs/sgsn_auth.c
+++ b/openbsc/src/gprs/sgsn_auth.c
@@ -24,7 +24,7 @@
 #include <openbsc/sgsn.h>
 #include <openbsc/gprs_sgsn.h>
 #include <openbsc/gprs_gmm.h>
-#include <openbsc/gsm_subscriber.h>
+#include <openbsc/gprs_subscriber.h>
 #include <openbsc/debug.h>
 
 const struct value_string auth_state_names[] = {
@@ -151,7 +151,7 @@
  */
 int sgsn_auth_request(struct sgsn_mm_ctx *mmctx)
 {
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 	struct gsm_auth_tuple *at;
 	int need_update_location;
 	int rc;
@@ -169,7 +169,7 @@
 
 	/* This has the side effect of registering the subscr with the mmctx */
 	subscr = gprs_subscr_get_or_create_by_mmctx(mmctx);
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	OSMO_ASSERT(mmctx->subscr != NULL);
 
@@ -207,7 +207,7 @@
 void sgsn_auth_update(struct sgsn_mm_ctx *mmctx)
 {
 	enum sgsn_auth_state auth_state;
-	struct gsm_subscriber *subscr = mmctx->subscr;
+	struct gprs_subscr *subscr = mmctx->subscr;
 	struct gsm_auth_tuple *at;
 	int gmm_cause;
 
diff --git a/openbsc/src/gprs/sgsn_libgtp.c b/openbsc/src/gprs/sgsn_libgtp.c
index 062de44..dde1e5e 100644
--- a/openbsc/src/gprs/sgsn_libgtp.c
+++ b/openbsc/src/gprs/sgsn_libgtp.c
@@ -48,7 +48,7 @@
 #include <openbsc/gprs_llc.h>
 #include <openbsc/gprs_sgsn.h>
 #include <openbsc/gprs_gmm.h>
-#include <openbsc/gsm_subscriber.h>
+#include <openbsc/gprs_subscriber.h>
 #include <openbsc/gprs_sndcp.h>
 
 #ifdef BUILD_IU
diff --git a/openbsc/src/gprs/sgsn_vty.c b/openbsc/src/gprs/sgsn_vty.c
index 3ce054f..a730635 100644
--- a/openbsc/src/gprs/sgsn_vty.c
+++ b/openbsc/src/gprs/sgsn_vty.c
@@ -657,40 +657,37 @@
 }
 
 /* Subscriber */
-#include <openbsc/gsm_subscriber.h>
+#include <openbsc/gprs_subscriber.h>
 
-static void subscr_dump_full_vty(struct vty *vty, struct gsm_subscriber *subscr, int pending)
+static void subscr_dump_full_vty(struct vty *vty, struct gprs_subscr *gsub, int pending)
 {
+#if 0
 	char expire_time[200];
+#endif
 	struct gsm_auth_tuple *at;
 	int at_idx;
 	struct sgsn_subscriber_pdp_data *pdp;
 
-	vty_out(vty, "    ID: %llu, Authorized: %d%s", subscr->id,
-		subscr->authorized, VTY_NEWLINE);
-	if (strlen(subscr->name))
-		vty_out(vty, "    Name: '%s'%s", subscr->name, VTY_NEWLINE);
-	if (strlen(subscr->extension))
-		vty_out(vty, "    Extension: %s%s", subscr->extension,
-			VTY_NEWLINE);
+	vty_out(vty, "    Authorized: %d%s",
+		gsub->authorized, VTY_NEWLINE);
 	vty_out(vty, "    LAC: %d/0x%x%s",
-		subscr->lac, subscr->lac, VTY_NEWLINE);
-	vty_out(vty, "    IMSI: %s%s", subscr->imsi, VTY_NEWLINE);
-	if (subscr->tmsi != GSM_RESERVED_TMSI)
-		vty_out(vty, "    TMSI: %08X%s", subscr->tmsi,
+		gsub->lac, gsub->lac, VTY_NEWLINE);
+	vty_out(vty, "    IMSI: %s%s", gsub->imsi, VTY_NEWLINE);
+	if (gsub->tmsi != GSM_RESERVED_TMSI)
+		vty_out(vty, "    TMSI: %08X%s", gsub->tmsi,
 			VTY_NEWLINE);
-	if (subscr->sgsn_data->msisdn_len > 0)
+	if (gsub->sgsn_data->msisdn_len > 0)
 		vty_out(vty, "    MSISDN (BCD): %s%s",
-			osmo_hexdump(subscr->sgsn_data->msisdn,
-					subscr->sgsn_data->msisdn_len),
+			osmo_hexdump(gsub->sgsn_data->msisdn,
+				     gsub->sgsn_data->msisdn_len),
 			VTY_NEWLINE);
 
-	if (strlen(subscr->equipment.imei) > 0)
-		vty_out(vty, "    IMEI: %s%s", subscr->equipment.imei, VTY_NEWLINE);
+	if (strlen(gsub->imei) > 0)
+		vty_out(vty, "    IMEI: %s%s", gsub->imei, VTY_NEWLINE);
 
-	for (at_idx = 0; at_idx < ARRAY_SIZE(subscr->sgsn_data->auth_triplets);
+	for (at_idx = 0; at_idx < ARRAY_SIZE(gsub->sgsn_data->auth_triplets);
 	     at_idx++) {
-		at = &subscr->sgsn_data->auth_triplets[at_idx];
+		at = &gsub->sgsn_data->auth_triplets[at_idx];
 		if (at->key_seq == GSM_KEY_SEQ_INVAL)
 			continue;
 
@@ -722,36 +719,38 @@
 		}
 	}
 
-	llist_for_each_entry(pdp, &subscr->sgsn_data->pdp_list, list) {
+	llist_for_each_entry(pdp, &gsub->sgsn_data->pdp_list, list) {
 		vty_out(vty, "    PDP info: Id: %d, Type: 0x%04x, APN: '%s' QoS: %s%s",
 			pdp->context_id, pdp->pdp_type, pdp->apn_str,
 			osmo_hexdump(pdp->qos_subscribed, pdp->qos_subscribed_len),
 			VTY_NEWLINE);
 	}
 
+#if 0
 	/* print the expiration time of a subscriber */
-	if (subscr->expire_lu) {
+	if (gsub->expire_lu) {
 		strftime(expire_time, sizeof(expire_time),
-			 "%a, %d %b %Y %T %z", localtime(&subscr->expire_lu));
+			 "%a, %d %b %Y %T %z", localtime(&gsub->expire_lu));
 		expire_time[sizeof(expire_time) - 1] = '\0';
 		vty_out(vty, "    Expiration Time: %s%s", expire_time, VTY_NEWLINE);
 	}
+#endif
 
-	if (subscr->flags)
+	if (gsub->flags)
 		vty_out(vty, "    Flags: %s%s%s%s%s%s",
-			subscr->flags & GSM_SUBSCRIBER_FIRST_CONTACT ?
+			gsub->flags & GPRS_SUBSCRIBER_FIRST_CONTACT ?
 			"FIRST_CONTACT " : "",
-			subscr->flags & GPRS_SUBSCRIBER_CANCELLED ?
+			gsub->flags & GPRS_SUBSCRIBER_CANCELLED ?
 			"CANCELLED " : "",
-			subscr->flags & GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING ?
+			gsub->flags & GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING ?
 			"UPDATE_LOCATION_PENDING " : "",
-			subscr->flags & GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING ?
+			gsub->flags & GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING ?
 			"AUTH_INFO_PENDING " : "",
-			subscr->flags & GPRS_SUBSCRIBER_ENABLE_PURGE ?
+			gsub->flags & GPRS_SUBSCRIBER_ENABLE_PURGE ?
 			"ENABLE_PURGE " : "",
 			VTY_NEWLINE);
 
-	vty_out(vty, "    Use count: %u%s", subscr->use_count, VTY_NEWLINE);
+	vty_out(vty, "    Use count: %u%s", gsub->use_count, VTY_NEWLINE);
 }
 
 DEFUN(show_subscr_cache,
@@ -760,9 +759,9 @@
 	SHOW_STR "Show information about subscribers\n"
 	"Display contents of subscriber cache\n")
 {
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
-	llist_for_each_entry(subscr, &active_subscribers, entry) {
+	llist_for_each_entry(subscr, gprs_subscribers, entry) {
 		vty_out(vty, "  Subscriber:%s", VTY_NEWLINE);
 		subscr_dump_full_vty(vty, subscr, 0);
 	}
@@ -794,7 +793,7 @@
 	const char *kc_str = argv[4];
 	struct gsm_auth_tuple at = {0,};
 
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
 	subscr = gprs_subscr_get_by_imsi(imsi);
 	if (!subscr) {
@@ -825,12 +824,12 @@
 	subscr->sgsn_data->auth_triplets[cksn] = at;
 	subscr->sgsn_data->auth_triplets_updated = 1;
 
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	return CMD_SUCCESS;
 
 failed:
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 	return CMD_SUCCESS;
 }
 
@@ -844,7 +843,7 @@
 	const char *imsi = argv[0];
 	const char *cancel_type = argv[1];
 
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
 	subscr = gprs_subscr_get_by_imsi(imsi);
 	if (!subscr) {
@@ -859,7 +858,7 @@
 		subscr->sgsn_data->error_cause = GMM_CAUSE_IMPL_DETACHED;
 
 	gprs_subscr_cancel(subscr);
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	return CMD_SUCCESS;
 }
@@ -871,7 +870,7 @@
 {
 	const char *imsi = argv[0];
 
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
 	subscr = gprs_subscr_get_by_imsi(imsi);
 	if (subscr) {
@@ -882,7 +881,7 @@
 
 	subscr = gprs_subscr_get_or_create(imsi);
 	subscr->keep_in_ram = 1;
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	return CMD_SUCCESS;
 }
@@ -894,7 +893,7 @@
 {
 	const char *imsi = argv[0];
 
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
 	subscr = gprs_subscr_get_by_imsi(imsi);
 	if (!subscr) {
@@ -909,7 +908,7 @@
 	if (subscr->use_count > 1)
 		vty_out(vty, "%% subscriber is still in use%s",
 			VTY_NEWLINE);
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	return CMD_SUCCESS;
 }
@@ -934,7 +933,7 @@
 	const char *imsi = argv[0];
 	const char *ret_code_str = argv[1];
 
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
 	const struct value_string cause_mapping[] = {
 		{ GMM_CAUSE_NET_FAIL,		"system-failure" },
@@ -963,7 +962,7 @@
 
 	gprs_subscr_update(subscr);
 
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	return CMD_SUCCESS;
 }
@@ -975,7 +974,7 @@
 {
 	const char *imsi = argv[0];
 
-	struct gsm_subscriber *subscr;
+	struct gprs_subscr *subscr;
 
 	subscr = gprs_subscr_get_by_imsi(imsi);
 	if (!subscr) {
@@ -986,7 +985,7 @@
 
 	gprs_subscr_update_auth_info(subscr);
 
-	subscr_put(subscr);
+	gprs_subscr_put(subscr);
 
 	return CMD_SUCCESS;
 }