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/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am
index 5cd5afc..30c1191 100644
--- a/openbsc/include/openbsc/Makefile.am
+++ b/openbsc/include/openbsc/Makefile.am
@@ -31,6 +31,7 @@
 	gprs_sndcp_dcomp.h \
 	gprs_sndcp_pcomp.h \
 	gprs_sndcp_xid.h \
+	gprs_subscriber.h \
 	gprs_utils.h \
 	gsm_04_08.h \
 	gsm_04_11.h \
diff --git a/openbsc/include/openbsc/gprs_sgsn.h b/openbsc/include/openbsc/gprs_sgsn.h
index 2cc5b0c..c3cac7f 100644
--- a/openbsc/include/openbsc/gprs_sgsn.h
+++ b/openbsc/include/openbsc/gprs_sgsn.h
@@ -18,7 +18,7 @@
 
 struct gprs_llc_lle;
 struct ctrl_handle;
-struct gsm_subscriber;
+struct gprs_subscr;
 
 enum gsm48_gsm_cause;
 
@@ -225,7 +225,7 @@
 	/* the current GGSN look-up operation */
 	struct sgsn_ggsn_lookup *ggsn_lookup;
 
-	struct gsm_subscriber   *subscr;
+	struct gprs_subscr	*subscr;
 };
 
 #define LOGMMCTXP(level, mm, fmt, args...) \
@@ -433,6 +433,7 @@
 /*
  * GPRS subscriber data
  */
+#define GPRS_SUBSCRIBER_FIRST_CONTACT	0x00000001
 #define GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING	(1 << 16)
 #define GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING		(1 << 17)
 #define GPRS_SUBSCRIBER_CANCELLED			(1 << 18)
@@ -446,13 +447,13 @@
 int gprs_subscr_init(struct sgsn_instance *sgi);
 int gprs_subscr_request_update_location(struct sgsn_mm_ctx *mmctx);
 int gprs_subscr_request_auth_info(struct sgsn_mm_ctx *mmctx);
-void gprs_subscr_cleanup(struct gsm_subscriber *subscr);
-struct gsm_subscriber *gprs_subscr_get_or_create(const char *imsi);
-struct gsm_subscriber *gprs_subscr_get_or_create_by_mmctx( struct sgsn_mm_ctx *mmctx);
-struct gsm_subscriber *gprs_subscr_get_by_imsi(const char *imsi);
-void gprs_subscr_cancel(struct gsm_subscriber *subscr);
-void gprs_subscr_update(struct gsm_subscriber *subscr);
-void gprs_subscr_update_auth_info(struct gsm_subscriber *subscr);
+void gprs_subscr_cleanup(struct gprs_subscr *subscr);
+struct gprs_subscr *gprs_subscr_get_or_create(const char *imsi);
+struct gprs_subscr *gprs_subscr_get_or_create_by_mmctx( struct sgsn_mm_ctx *mmctx);
+struct gprs_subscr *gprs_subscr_get_by_imsi(const char *imsi);
+void gprs_subscr_cancel(struct gprs_subscr *subscr);
+void gprs_subscr_update(struct gprs_subscr *subscr);
+void gprs_subscr_update_auth_info(struct gprs_subscr *subscr);
 int gprs_subscr_rx_gsup_message(struct msgb *msg);
 
 /* Called on subscriber data updates */
diff --git a/openbsc/include/openbsc/gprs_subscriber.h b/openbsc/include/openbsc/gprs_subscriber.h
new file mode 100644
index 0000000..be78feb
--- /dev/null
+++ b/openbsc/include/openbsc/gprs_subscriber.h
@@ -0,0 +1,31 @@
+/* GPRS subscriber details for use in SGSN land */
+#pragma once
+
+#include <stdint.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/gsm/protocol/gsm_23_003.h>
+
+extern struct llist_head * const gprs_subscribers;
+
+struct gprs_subscr {
+	struct llist_head entry;
+	int use_count;
+
+	char imsi[GSM23003_IMSI_MAX_DIGITS+1];
+	uint32_t tmsi;
+	char imei[GSM23003_IMEISV_NUM_DIGITS+1];
+	bool authorized;
+	bool keep_in_ram;
+	uint32_t flags;
+	uint16_t lac;
+
+	struct sgsn_subscriber_data *sgsn_data;
+};
+
+struct gprs_subscr *_gprs_subscr_get(struct gprs_subscr *gsub,
+				     const char *file, int line);
+struct gprs_subscr *_gprs_subscr_put(struct gprs_subscr *gsub,
+				     const char *file, int line);
+#define gprs_subscr_get(gsub) _gprs_subscr_get(gsub, __BASE_FILE__, __LINE__)
+#define gprs_subscr_put(gsub) _gprs_subscr_put(gsub, __BASE_FILE__, __LINE__)
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 4425a10..a14e59f 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -26,6 +26,8 @@
 
 #define OBSC_LINKID_CB(__msgb)	(__msgb)->cb[3]
 
+#define tmsi_from_string(str) strtoul(str, NULL, 10)
+
 enum gsm_security_event {
 	GSM_SECURITY_NOAVAIL,
 	GSM_SECURITY_AUTH_FAILED,
diff --git a/openbsc/include/openbsc/gsm_subscriber.h b/openbsc/include/openbsc/gsm_subscriber.h
index 314d619..7e65614 100644
--- a/openbsc/include/openbsc/gsm_subscriber.h
+++ b/openbsc/include/openbsc/gsm_subscriber.h
@@ -16,7 +16,6 @@
 
 #define GSM_SUBSCRIBER_FIRST_CONTACT	0x00000001
 /* gprs_sgsn.h defines additional flags including and above bit 16 (0x10000) */
-#define tmsi_from_string(str) strtoul(str, NULL, 10)
 
 #define GSM_SUBSCRIBER_NO_EXPIRATION	0x0