move libiu to osmo-iuh/libosmo-ranap

Remove libiu here, use the functions from libosmo-ranap instead, by applying
the ranap_ / RANAP_ prefix.

Corresponding change-id in osmo-iuh.git is I6a3f7ad15be03fb94689b4af6ccfa828c25f45c0

To be able to run the msc_vlr tests for RAN_UTRAN_IU without Iu client headers
available, add iu_dummy.h, containing mere function signatures that match
iu_dummy.c and a mostly empty struct ranap_ue_conn_ctx.

Make sure we can build with and without --enable-iu: include osmo-iuh headers
only with --enable-iu.

Change-Id: Ib8c4fcdb4766c5e575618b95ce16dce51063206b
diff --git a/src/gprs/Makefile.am b/src/gprs/Makefile.am
index e05eb79..39a4c12 100644
--- a/src/gprs/Makefile.am
+++ b/src/gprs/Makefile.am
@@ -106,7 +106,6 @@
 	$(NULL)
 if BUILD_IU
 osmo_sgsn_LDADD += \
-	$(top_builddir)/src/libiu/libiu.a \
 	$(LIBOSMOSIGTRAN_LIBS) \
 	$(LIBOSMORANAP_LIBS) \
 	$(LIBASN1C_LIBS) \
diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index 15e2fed..032137f 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -52,6 +52,7 @@
 #ifdef BUILD_IU
 #include <osmocom/ranap/ranap_ies_defs.h>
 #include <osmocom/ranap/ranap_msg_factory.h>
+#include <osmocom/ranap/iu_client.h>
 #endif
 
 #include <openbsc/debug.h>
@@ -67,7 +68,6 @@
 #include <openbsc/gprs_subscriber.h>
 #include <openbsc/sgsn.h>
 #include <openbsc/signal.h>
-#include <openbsc/iu.h>
 #include <openbsc/gprs_sndcp.h>
 
 #include <pdp.h>
@@ -174,7 +174,7 @@
 
 #ifdef BUILD_IU
 int sgsn_ranap_rab_ass_resp(struct sgsn_mm_ctx *ctx, RANAP_RAB_SetupOrModifiedItemIEs_t *setup_ies);
-int sgsn_ranap_iu_event(struct ue_conn_ctx *ctx, enum iu_event_type type, void *data)
+int sgsn_ranap_iu_event(struct ranap_ue_conn_ctx *ctx, enum ranap_iu_event_type type, void *data)
 {
 	struct sgsn_mm_ctx *mm;
 	int rc = -1;
@@ -188,14 +188,14 @@
 	}
 
 	switch (type) {
-	case IU_EVENT_RAB_ASSIGN:
+	case RANAP_IU_EVENT_RAB_ASSIGN:
 		REQUIRE_MM
 		rc = sgsn_ranap_rab_ass_resp(mm, (RANAP_RAB_SetupOrModifiedItemIEs_t *)data);
 		break;
-	case IU_EVENT_IU_RELEASE:
+	case RANAP_IU_EVENT_IU_RELEASE:
 		/* fall thru */
-	case IU_EVENT_LINK_INVALIDATED:
-		/* Clean up ue_conn_ctx here */
+	case RANAP_IU_EVENT_LINK_INVALIDATED:
+		/* Clean up ranap_ue_conn_ctx here */
 		if (mm)
 			LOGMMCTXP(LOGL_INFO, mm, "IU release for imsi %s\n", mm->imsi);
 		else
@@ -205,7 +205,7 @@
 			mmctx_set_pmm_state(mm, PMM_IDLE);
 		rc = 0;
 		break;
-	case IU_EVENT_SECURITY_MODE_COMPLETE:
+	case RANAP_IU_EVENT_SECURITY_MODE_COMPLETE:
 		REQUIRE_MM
 		/* Continue authentication here */
 		mm->iu.ue_ctx->integrity_active = 1;
@@ -262,16 +262,16 @@
 		rate_ctr_inc(&mm->ctrg->ctr[GMM_CTR_PKTS_SIG_OUT]);
 #ifdef BUILD_IU
 		if (mm->ran_type == MM_CTX_T_UTRAN_Iu)
-			return iu_tx(msg, GPRS_SAPI_GMM);
+			return ranap_iu_tx(msg, GPRS_SAPI_GMM);
 #endif
 	}
 
 #ifdef BUILD_IU
-	/* In Iu mode, msg->dst contains the ue_conn_ctx pointer, in Gb mode
+	/* In Iu mode, msg->dst contains the ranap_ue_conn_ctx pointer, in Gb mode
 	 * dst is empty. */
 	/* FIXME: have a more explicit indicator for Iu messages */
 	if (msg->dst)
-		return iu_tx(msg, GPRS_SAPI_GMM);
+		return ranap_iu_tx(msg, GPRS_SAPI_GMM);
 #endif
 
 	/* caller needs to provide TLLI, BVCI and NSEI */
@@ -296,9 +296,12 @@
 	/* In case a Iu connection is reconnected we need to update the ue ctx */
 	mm->iu.ue_ctx = msg->dst;
 	if (mm->ran_type == MM_CTX_T_UTRAN_Iu
-	    && mm->iu.ue_ctx)
+	    && mm->iu.ue_ctx) {
+#ifdef BUILD_IU
 		mm->iu.ue_ctx->rab_assign_addr_enc =
 			sgsn->cfg.iu.rab_assign_addr_enc;
+#endif
+	}
 }
 
 /* Store BVCI/NSEI in MM context */
@@ -1048,7 +1051,7 @@
 	/* The MS is authorized */
 #ifdef BUILD_IU
 	if (ctx->ran_type == MM_CTX_T_UTRAN_Iu && !ctx->iu.ue_ctx->integrity_active) {
-		rc = iu_tx_sec_mode_cmd(ctx->iu.ue_ctx, &ctx->auth_triplet, 0, ctx->iu.new_key);
+		rc = ranap_iu_tx_sec_mode_cmd(ctx->iu.ue_ctx, &ctx->auth_triplet.vec, 0, ctx->iu.new_key);
 		ctx->iu.new_key = 0;
 		return rc;
 	}
@@ -1259,14 +1262,20 @@
 	 * with a foreign TLLI (P-TMSI that was allocated to the MS before),
 	 * or with random TLLI. */
 
-	/* In Iu mode, msg->dst contains the ue_conn_ctx pointer, in Gb mode
+	/* In Iu mode, msg->dst contains the ranap_ue_conn_ctx pointer, in Gb mode
 	 * dst is empty. */
 	/* FIXME: have a more explicit indicator for Iu messages */
 	if (!msg->dst) {
 		/* Gb mode */
 		cid = bssgp_parse_cell_id(&ra_id, msgb_bcid(msg));
-	} else
-		ra_id = ((struct ue_conn_ctx*)msg->dst)->ra_id;
+	} else {
+#ifdef BUILD_IU
+		ra_id = ((struct ranap_ue_conn_ctx*)msg->dst)->ra_id;
+#else
+		LOGMMCTXP(LOGL_ERROR, ctx, "Cannot handle Iu Attach Request, built without Iu support\n");
+		return -ENOTSUP;
+#endif
+	}
 
 	/* MS network capability 10.5.5.12 */
 	msnc_len = *cur++;
@@ -1627,7 +1636,7 @@
 		 * is an optimization to avoid the RA reject (impl detached)
 		 * below, which will cause a new attach cycle. */
 		/* Look-up the MM context based on old RA-ID and TLLI */
-		/* In Iu mode, msg->dst contains the ue_conn_ctx pointer, in Gb
+		/* In Iu mode, msg->dst contains the ranap_ue_conn_ctx pointer, in Gb
 		 * mode dst is empty. */
 		/* FIXME: have a more explicit indicator for Iu messages */
 		if (!msg->dst) {
@@ -2905,12 +2914,12 @@
 {
 	struct msgb *msg;
 	struct sgsn_mm_ctx *mm = pdp->mm;
-	struct ue_conn_ctx *uectx;
+	struct ranap_ue_conn_ctx *uectx;
 	uint32_t ggsn_ip;
 	bool use_x213_nsap;
 
 	uectx = mm->iu.ue_ctx;
-	use_x213_nsap = (uectx->rab_assign_addr_enc == NSAP_ADDR_ENC_X213);
+	use_x213_nsap = (uectx->rab_assign_addr_enc == RANAP_NSAP_ADDR_ENC_X213);
 
 	/* Get the IP address for ggsn user plane */
 	memcpy(&ggsn_ip, pdp->lib->gsnru.v, pdp->lib->gsnru.l);
@@ -2923,6 +2932,6 @@
 	msg = ranap_new_msg_rab_assign_data(rab_id, ggsn_ip,
 					    pdp->lib->teid_gn, use_x213_nsap);
 	msg->l2h = msg->data;
-	return iu_rab_act(uectx, msg);
+	return ranap_iu_rab_act(uectx, msg);
 }
 #endif
diff --git a/src/gprs/gprs_sgsn.c b/src/gprs/gprs_sgsn.c
index 43eeaaa..de79afb 100644
--- a/src/gprs/gprs_sgsn.c
+++ b/src/gprs/gprs_sgsn.c
@@ -40,7 +40,6 @@
 #include <openbsc/gprs_utils.h>
 #include <openbsc/signal.h>
 #include "openbsc/gprs_llc.h"
-#include <openbsc/iu.h>
 
 #include <pdp.h>
 
@@ -48,6 +47,12 @@
 
 #include <openssl/rand.h>
 
+#include "../../bscconfig.h"
+
+#if BUILD_IU
+#include <osmocom/ranap/iu_client.h>
+#endif
+
 #define GPRS_LLME_CHECK_TICK 30
 
 extern struct sgsn_instance *sgsn;
@@ -246,6 +251,7 @@
 /* Allocate a new SGSN MM context */
 struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx)
 {
+#if BUILD_IU
 	struct sgsn_mm_ctx *ctx;
 
 	ctx = talloc_zero(tall_bsc_ctx, struct sgsn_mm_ctx);
@@ -274,6 +280,9 @@
 	llist_add(&ctx->list, &sgsn_mm_ctxts);
 
 	return ctx;
+#else
+	return NULL;
+#endif
 }
 
 
diff --git a/src/gprs/sgsn_libgtp.c b/src/gprs/sgsn_libgtp.c
index 7ff8ece..90b4d16 100644
--- a/src/gprs/sgsn_libgtp.c
+++ b/src/gprs/sgsn_libgtp.c
@@ -52,7 +52,7 @@
 #include <openbsc/gprs_sndcp.h>
 
 #ifdef BUILD_IU
-#include <openbsc/iu.h>
+#include <osmocom/ranap/iu_client.h>
 #include <osmocom/ranap/ranap_ies_defs.h>
 #endif
 
@@ -548,7 +548,7 @@
 		} else {
 #ifdef BUILD_IU
 			/* Deactivate radio bearer */
-			iu_rab_deact(pctx->mm->iu.ue_ctx, 1);
+			ranap_iu_rab_deact(pctx->mm->iu.ue_ctx, 1);
 #else
 			return -ENOTSUP;
 #endif
@@ -687,7 +687,7 @@
 #ifdef BUILD_IU
 		/* Ignore the packet for now and page the UE to get the RAB
 		 * reestablished */
-		iu_page_ps(mm->imsi, &mm->p_tmsi, mm->ra.lac, mm->ra.rac);
+		ranap_iu_page_ps(mm->imsi, &mm->p_tmsi, mm->ra.lac, mm->ra.rac);
 
 		return 0;
 #else
diff --git a/src/gprs/sgsn_main.c b/src/gprs/sgsn_main.c
index d56af0e..25ee632 100644
--- a/src/gprs/sgsn_main.c
+++ b/src/gprs/sgsn_main.c
@@ -58,7 +58,6 @@
 #include <openbsc/sgsn.h>
 #include <openbsc/gprs_llc.h>
 #include <openbsc/gprs_gmm.h>
-#include <openbsc/iu.h>
 
 #include <osmocom/ctrl/control_if.h>
 #include <osmocom/ctrl/ports.h>
@@ -69,6 +68,10 @@
 
 #include "../../bscconfig.h"
 
+#if BUILD_IU
+#include <osmocom/ranap/iu_client.h>
+#endif
+
 #define _GNU_SOURCE
 #include <getopt.h>
 
@@ -322,7 +325,7 @@
 	.num_cat = ARRAY_SIZE(gprs_categories),
 };
 
-int sgsn_ranap_iu_event(struct ue_conn_ctx *ctx, enum iu_event_type type, void *data);
+int sgsn_ranap_iu_event(struct ue_conn_ctx *ctx, enum ranap_iu_event_type type, void *data);
 
 int main(int argc, char **argv)
 {
@@ -451,7 +454,7 @@
 		return 8;
 	}
 
-	iu_init(tall_bsc_ctx, sccp, gsm0408_gprs_rcvmsg_iu, sgsn_ranap_iu_event);
+	ranap_iu_init(tall_bsc_ctx, DRANAP, "OsmoSGSN-IuPS", sccp, gsm0408_gprs_rcvmsg_iu, sgsn_ranap_iu_event);
 #endif
 
 	if (daemonize) {
diff --git a/src/gprs/sgsn_vty.c b/src/gprs/sgsn_vty.c
index cf44cc4..3a5b2ca 100644
--- a/src/gprs/sgsn_vty.c
+++ b/src/gprs/sgsn_vty.c
@@ -48,7 +48,7 @@
 #include "../../bscconfig.h"
 
 #ifdef BUILD_IU
-#include <openbsc/iu.h>
+#include <osmocom/ranap/iu_client.h>
 #endif
 
 static struct sgsn_config *g_cfg = NULL;
@@ -291,7 +291,7 @@
 		vty_out(vty, " no compression v42bis%s", VTY_NEWLINE);
 
 #ifdef BUILD_IU
-	iu_vty_config_write(vty, " ");
+	ranap_iu_vty_config_write(vty, " ");
 #endif
 
 	return CMD_SUCCESS;
@@ -1285,7 +1285,7 @@
 	install_element(SGSN_NODE, &cfg_comp_v42bisp_cmd);
 
 #ifdef BUILD_IU
-	iu_vty_init(SGSN_NODE, &g_cfg->iu.rab_assign_addr_enc);
+	ranap_iu_vty_init(SGSN_NODE, &g_cfg->iu.rab_assign_addr_enc);
 #endif
 	return 0;
 }