put Iu-common and Iu-CS stuff in proper places

Add libiu to contain the parts used by both Iu-CS (in osmo-cscn) and Iu-PS (in
gprs) into libiu. It's rather thin and may make sense to move to osmo-iuh
altogether, eventually.

iu.c is half moved to libiu/, and half to osmo-cscn/iu_cs.c.
This commit is contained in:
Neels Hofmeyr
2016-01-25 19:24:01 +01:00
parent 9dcae17866
commit ee1541d504
10 changed files with 117 additions and 99 deletions

View File

@@ -194,6 +194,7 @@ AC_OUTPUT(
src/libmgcp/Makefile
src/libcommon/Makefile
src/libfilter/Makefile
src/libiu/Makefile
src/osmo-nitb/Makefile
src/osmo-cscn/Makefile
src/osmo-bsc/Makefile

View File

@@ -19,7 +19,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \
gprs_gsup_client.h bsc_msg_filter.h \
oap.h oap_messages.h \
gtphub.h \
iu.h
iu.h iu_cs.h
openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
openbscdir = $(includedir)/openbsc

View File

@@ -0,0 +1,5 @@
#pragma once
int gsm0408_rcvmsg_iucs(struct gsm_network *network, struct msgb *msg, uint8_t link_id);
struct gsm_subscriber_connection *subscr_conn_allocate_iu(struct gsm_bts *bts);
/* TODO "bts"? this is an hNodeB, really. */

View File

@@ -2,7 +2,7 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(COVERAGE_CFLAGS)
AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(COVERAGE_LDFLAGS)
SUBDIRS = libcommon libmgcp libbsc libmsc libtrau libfilter osmo-nitb osmo-cscn osmo-bsc_mgcp utils ipaccess gprs
SUBDIRS = libcommon libmgcp libbsc libiu libmsc libtrau libfilter osmo-nitb osmo-cscn osmo-bsc_mgcp utils ipaccess gprs
# Conditional modules
if BUILD_NAT

View File

@@ -32,11 +32,11 @@ osmo_sgsn_SOURCES = gprs_gmm.c gprs_sgsn.c gprs_sndcp.c gprs_sndcp_vty.c \
sgsn_ctrl.c sgsn_auth.c gprs_subscriber.c \
gprs_gsup_messages.c gprs_utils.c gprs_gsup_client.c \
gsm_04_08_gprs.c sgsn_cdr.c sgsn_ares.c \
oap.c oap_messages.c \
iu.c
oap.c oap_messages.c
osmo_sgsn_LDADD = \
$(top_builddir)/src/libcommon/libcommon.a \
$(top_builddir)/src/libiu/libiu.a \
-lgtp $(OSMO_LIBS) $(LIBOSMOABIS_LIBS) $(LIBCARES_LIBS) \
$(LIBCRYPTO_LIBS) -lrt \
$(LIBOSMOSIGTRAN_LIBS) $(LIBOSMORANAP_LIBS) $(LIBASN1C_LIBS)

View File

@@ -0,0 +1,10 @@
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS) \
$(LIBOSMOABIS_CFLAGS) $(COVERAGE_CFLAGS) $(LIBCRYPTO_CFLAGS) \
$(LIBASN1C_CFLAGS) \
$(LIBOSMOSIGTRAN_CFLAGS) $(LIBOSMORANAP_CFLAGS)
noinst_LIBRARIES = libiu.a
libiu_a_SOURCES = iu.c

View File

@@ -461,96 +461,3 @@ int iu_init(void *ctx, const char *listen_addr, uint16_t listen_port,
return osmo_sua_server_listen(user, listen_addr, listen_port);
}
/* Return an existing Iu-CS subscriber connection record for the given link and
* connection IDs, or return NULL if not found. */
/* TODO wrong file */
static struct gsm_subscriber_connection *subscr_conn_lookup_iu(struct gsm_network *network,
uint8_t link_id,
uint32_t conn_id)
{
struct gsm_subscriber_connection *conn;
llist_for_each_entry(conn, &network->subscr_conns, entry) {
if (conn->via_iface != IFACE_IUCS)
continue;
if (conn->iu.link_id != link_id)
continue;
if (conn->iu.conn_id != conn_id)
continue;
return conn;
}
return NULL;
}
/* Receive MM/CC/... message from Iu-CS (SCCP user SAP).
* msg->dst must reference a struct ue_conn_ctx. link_id identifies the SCTP
* peer that sent the msg.
*
* For A-interface see libbsc/bsc_api.c gsm0408_rcvmsg(). */
/* TODO wrong file */
int gsm0408_rcvmsg_iucs(struct gsm_network *network, struct msgb *msg, uint8_t link_id)
{
int rc;
struct ue_conn_ctx *ue_ctx;
struct gsm_subscriber_connection *conn;
ue_ctx = (struct ue_conn_ctx*)msg->dst;
/* TODO: are there message types that could allow us to skip this
* search? */
conn = subscr_conn_lookup_iu(network, link_id, ue_ctx->conn_id);
if (conn) {
/* if we already have a connection, handle DTAP.
gsm0408_dispatch() is aka msc_dtap() */
/* Make sure we don't receive RR over Iu-CS; otherwise all
* messages handled by gsm0408_dispatch() are of interest (CC,
* MM, SMS, NS_SS, maybe even MM_GPRS and SM_GPRS). */
struct gsm48_hdr *gh = msgb_l3(msg);
uint8_t pdisc = gh->proto_discr & 0x0f;
OSMO_ASSERT(pdisc != GSM48_PDISC_RR);
gsm0408_dispatch(conn, msg);
} else {
/* allocate a new connection */
/* TODO */
#if 0
rc = BSC_API_CONN_POL_REJECT;
conn = subscr_conn_allocate_iu(msg->lchan);
if (!lchan->conn) {
lchan_release(lchan, 1, RSL_REL_NORMAL);
return -1;
}
/* fwd via bsc_api to send COMPLETE L3 INFO to MSC */
rc = api->compl_l3(lchan->conn, msg, 0);
if (rc != BSC_API_CONN_POL_ACCEPT) {
lchan->conn->lchan = NULL;
subscr_con_free(lchan->conn);
lchan_release(lchan, 1, RSL_REL_NORMAL);
}
#endif
}
return 0;
}
/* For A-interface see libbsc/bsc_api.c subscr_con_allocate() */
/* TODO wrong file */
struct gsm_subscriber_connection *subscr_conn_allocate_iu(struct gsm_bts *bts)
/* TODO "bts"? this is an hNodeB, really. */
{
struct gsm_subscriber_connection *conn;
conn = talloc_zero(bts->network, struct gsm_subscriber_connection);
if (!conn)
return NULL;
conn->via_iface = IFACE_IUCS;
conn->bts = bts;
llist_add_tail(&conn->entry, &bts->network->subscr_conns);
return conn;
}

View File

@@ -9,9 +9,11 @@ AM_LDFLAGS = $(COVERAGE_LDFLAGS)
bin_PROGRAMS = osmo-cscn
osmo_cscn_SOURCES = cscn_main.c \
$(top_builddir)/src/gprs/iu.c
iu_cs.c
osmo_cscn_LDADD = \
$(top_builddir)/src/libbsc/libbsc.a \
$(top_builddir)/src/libiu/libiu.a \
$(top_builddir)/src/libmsc/libmsc.a \
$(top_builddir)/src/libbsc/libbsc.a \
$(top_builddir)/src/libtrau/libtrau.a \

View File

@@ -0,0 +1,93 @@
#include <openbsc/gsm_data.h>
#include <openbsc/iu.h>
/* Return an existing Iu-CS subscriber connection record for the given link and
* connection IDs, or return NULL if not found. */
static struct gsm_subscriber_connection *subscr_conn_lookup_iu(struct gsm_network *network,
uint8_t link_id,
uint32_t conn_id)
{
struct gsm_subscriber_connection *conn;
llist_for_each_entry(conn, &network->subscr_conns, entry) {
if (conn->via_iface != IFACE_IUCS)
continue;
if (conn->iu.link_id != link_id)
continue;
if (conn->iu.conn_id != conn_id)
continue;
return conn;
}
return NULL;
}
/* Receive MM/CC/... message from Iu-CS (SCCP user SAP).
* msg->dst must reference a struct ue_conn_ctx. link_id identifies the SCTP
* peer that sent the msg.
*
* For A-interface see libbsc/bsc_api.c gsm0408_rcvmsg(). */
int gsm0408_rcvmsg_iucs(struct gsm_network *network, struct msgb *msg, uint8_t link_id)
{
int rc;
struct ue_conn_ctx *ue_ctx;
struct gsm_subscriber_connection *conn;
ue_ctx = (struct ue_conn_ctx*)msg->dst;
/* TODO: are there message types that could allow us to skip this
* search? */
conn = subscr_conn_lookup_iu(network, link_id, ue_ctx->conn_id);
if (conn) {
/* if we already have a connection, handle DTAP.
gsm0408_dispatch() is aka msc_dtap() */
/* Make sure we don't receive RR over Iu-CS; otherwise all
* messages handled by gsm0408_dispatch() are of interest (CC,
* MM, SMS, NS_SS, maybe even MM_GPRS and SM_GPRS). */
struct gsm48_hdr *gh = msgb_l3(msg);
uint8_t pdisc = gh->proto_discr & 0x0f;
OSMO_ASSERT(pdisc != GSM48_PDISC_RR);
gsm0408_dispatch(conn, msg);
} else {
/* allocate a new connection */
/* TODO */
#if 0
rc = BSC_API_CONN_POL_REJECT;
conn = subscr_conn_allocate_iu(msg->lchan);
if (!lchan->conn) {
lchan_release(lchan, 1, RSL_REL_NORMAL);
return -1;
}
/* fwd via bsc_api to send COMPLETE L3 INFO to MSC */
rc = api->compl_l3(lchan->conn, msg, 0);
if (rc != BSC_API_CONN_POL_ACCEPT) {
lchan->conn->lchan = NULL;
subscr_con_free(lchan->conn);
lchan_release(lchan, 1, RSL_REL_NORMAL);
}
#endif
}
return 0;
}
/* For A-interface see libbsc/bsc_api.c subscr_con_allocate() */
struct gsm_subscriber_connection *subscr_conn_allocate_iu(struct gsm_bts *bts)
/* TODO "bts"? this is an hNodeB, really. */
{
struct gsm_subscriber_connection *conn;
conn = talloc_zero(bts->network, struct gsm_subscriber_connection);
if (!conn)
return NULL;
conn->via_iface = IFACE_IUCS;
conn->bts = bts;
llist_add_tail(&conn->entry, &bts->network->subscr_conns);
return conn;
}

View File

@@ -30,9 +30,9 @@ sgsn_test_LDADD = \
$(top_builddir)/src/gprs/gsm_04_08_gprs.o \
$(top_builddir)/src/gprs/gprs_gb_parse.o \
$(top_builddir)/src/gprs/oap.o \
$(top_builddir)/src/gprs/iu.o \
$(top_builddir)/src/gprs/oap_messages.o \
$(top_builddir)/src/libcommon/libcommon.a \
$(top_builddir)/src/libiu/libiu.a \
$(LIBOSMOABIS_LIBS) \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \