diff --git a/include/osmocom/bsc_nat/Makefile.am b/include/osmocom/bsc_nat/Makefile.am index 398b0aa..1c675f7 100644 --- a/include/osmocom/bsc_nat/Makefile.am +++ b/include/osmocom/bsc_nat/Makefile.am @@ -4,5 +4,6 @@ noinst_HEADERS = \ bsc_nat_fsm.h \ bssap.h \ logging.h \ + msc.h \ vty.h \ $(NULL) diff --git a/include/osmocom/bsc_nat/bsc_nat.h b/include/osmocom/bsc_nat/bsc_nat.h index aac06ab..9e58a79 100644 --- a/include/osmocom/bsc_nat/bsc_nat.h +++ b/include/osmocom/bsc_nat/bsc_nat.h @@ -40,6 +40,7 @@ struct bsc_nat { struct { struct bsc_nat_sccp_inst *sccp_inst; + struct llist_head mscs; /* list of struct msc */ } cn; struct { diff --git a/include/osmocom/bsc_nat/msc.h b/include/osmocom/bsc_nat/msc.h new file mode 100644 index 0000000..1f91de0 --- /dev/null +++ b/include/osmocom/bsc_nat/msc.h @@ -0,0 +1,34 @@ +/* (C) 2021 by sysmocom - s.f.m.c. GmbH + * Author: Oliver Smith + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#pragma once + +#include + +struct msc { + struct llist_head list; + struct osmo_sccp_addr addr; +}; + +struct msc *msc_alloc(struct osmo_sccp_addr *addr); +int msc_alloc_from_addr_book(void); + +struct msc *msc_get(void); + +void msc_free(struct msc *msc); diff --git a/src/osmo-bsc-nat/Makefile.am b/src/osmo-bsc-nat/Makefile.am index bb8e990..1dd82fd 100644 --- a/src/osmo-bsc-nat/Makefile.am +++ b/src/osmo-bsc-nat/Makefile.am @@ -31,6 +31,7 @@ osmo_bsc_nat_SOURCES = \ bssap.c \ logging.c \ main.c \ + msc.c \ vty.c \ $(NULL) diff --git a/src/osmo-bsc-nat/bsc_nat.c b/src/osmo-bsc-nat/bsc_nat.c index 8baa096..23d7498 100644 --- a/src/osmo-bsc-nat/bsc_nat.c +++ b/src/osmo-bsc-nat/bsc_nat.c @@ -24,6 +24,7 @@ #include #include #include +#include struct bsc_nat *bsc_nat_alloc(void *tall_ctx) { @@ -40,6 +41,7 @@ struct bsc_nat *bsc_nat_alloc(void *tall_ctx) OSMO_ASSERT(bsc_nat->ran.sccp_inst); talloc_set_name_const(bsc_nat->ran.sccp_inst, "struct bsc_nat_sccp_inst (RAN)"); + INIT_LLIST_HEAD(&bsc_nat->cn.mscs); INIT_LLIST_HEAD(&bsc_nat->ran.bscs); bsc_nat_fsm_alloc(bsc_nat); @@ -49,6 +51,7 @@ struct bsc_nat *bsc_nat_alloc(void *tall_ctx) void bsc_nat_free(struct bsc_nat *bsc_nat) { + struct msc *msc, *m; struct bsc *bsc, *b; if (bsc_nat->fi) { @@ -56,6 +59,10 @@ void bsc_nat_free(struct bsc_nat *bsc_nat) bsc_nat->fi = NULL; } + llist_for_each_entry_safe(msc, m, &bsc_nat->cn.mscs, list) { + msc_free(msc); + } + llist_for_each_entry_safe(bsc, b, &bsc_nat->ran.bscs, list) { bsc_free(bsc); } diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c index 07b9eb5..4193ae9 100644 --- a/src/osmo-bsc-nat/bsc_nat_fsm.c +++ b/src/osmo-bsc-nat/bsc_nat_fsm.c @@ -186,22 +186,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu) case OSMO_PRIM(OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_INDICATION): /* connection-less data received */ - addr = &prim->u.unitdata.calling_addr; - - if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0) - goto error; - - LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out)); - - /* oph->msg stores oph and unitdata msg. Move oph->msg->data to - * unitdata msg and send it again. */ - msgb_pull_to_l2(oph->msg); - osmo_sccp_tx_unitdata(g_bsc_nat->ran.sccp_inst->scu, - &g_bsc_nat->ran.sccp_inst->addr, - &peer_addr_out, - oph->msg->data, - msgb_length(oph->msg)); - rc = 0; + rc = bssap_handle_udt(sccp_inst, &prim->u.unitdata.calling_addr, oph->msg, msgb_l2len(oph->msg)); break; default: diff --git a/src/osmo-bsc-nat/main.c b/src/osmo-bsc-nat/main.c index c0b65ea..6cb1e0f 100644 --- a/src/osmo-bsc-nat/main.c +++ b/src/osmo-bsc-nat/main.c @@ -30,6 +30,7 @@ #include #include #include +#include #include static const char *const copyright = @@ -199,6 +200,9 @@ int main(int argc, char **argv) bsc_nat_fsm_start(g_bsc_nat); + if (msc_alloc_from_addr_book() < 0) + exit(1); + while (!osmo_select_shutdown_done()) osmo_select_main_ctx(0); diff --git a/src/osmo-bsc-nat/msc.c b/src/osmo-bsc-nat/msc.c new file mode 100644 index 0000000..70f9d76 --- /dev/null +++ b/src/osmo-bsc-nat/msc.c @@ -0,0 +1,71 @@ +/* (C) 2021 by sysmocom - s.f.m.c. GmbH + * Author: Oliver Smith + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#include "config.h" +#include +#include +#include +#include + +struct msc *msc_alloc(struct osmo_sccp_addr *addr) +{ + struct msc *msc = talloc_zero(g_bsc_nat, struct msc); + + OSMO_ASSERT(msc); + talloc_set_name(msc, "MSC(PC=%s)", osmo_ss7_pointcode_print(NULL, addr->pc)); + + LOGP(DMAIN, LOGL_DEBUG, "Add %s\n", talloc_get_name(msc)); + + msc->addr = *addr; + + INIT_LLIST_HEAD(&msc->list); + llist_add(&msc->list, &g_bsc_nat->cn.mscs); + + return msc; +} + +int msc_alloc_from_addr_book(void) +{ + struct osmo_sccp_addr addr; + + /* For now only one MSC is supported */ + if (osmo_sccp_addr_by_name_local(&addr, "msc", g_bsc_nat->cn.sccp_inst->ss7_inst) < 0) { + LOGP(DMAIN, LOGL_ERROR, "Configuration error, MSC not found in address book\n"); + return -ENOENT; + } + + msc_alloc(&addr); + return 0; +} + +struct msc *msc_get(void) +{ + /* For now only one MSC is supported */ + + OSMO_ASSERT(!llist_empty(&g_bsc_nat->cn.mscs)); + + return llist_first_entry(&g_bsc_nat->cn.mscs, struct msc, list); +} + +void msc_free(struct msc *msc) +{ + LOGP(DMAIN, LOGL_DEBUG, "Del %s\n", talloc_get_name(msc)); + llist_del(&msc->list); + talloc_free(msc); +}