From e9e089128c4e191dd762d23973a794f1c45f61c6 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 21 Sep 2019 00:02:46 +0200 Subject: WIP: add SABP support to HNBGW Change-Id: I2d91de2e37770e3635abe8004ac183857d8a6ff2 --- include/osmocom/iuh/hnbgw.h | 3 ++ src/Makefile.am | 4 +- src/hnbgw.c | 9 ++++ src/hnbgw_sabp.c | 122 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 src/hnbgw_sabp.c diff --git a/include/osmocom/iuh/hnbgw.h b/include/osmocom/iuh/hnbgw.h index 4848c2f..344d20a 100644 --- a/include/osmocom/iuh/hnbgw.h +++ b/include/osmocom/iuh/hnbgw.h @@ -16,6 +16,7 @@ enum { DHNBAP, DRUA, DRANAP, + DSABP, }; enum hnb_ctrl_node { @@ -96,6 +97,8 @@ struct hnb_context { uint16_t hnbap_stream; /*! SCTP stream ID for RUA */ uint16_t rua_stream; + /*! SCTP stream ID for SABP */ + uint16_t sabp_stream; /*! True if a HNB-REGISTER-REQ from this HNB has been accepted. Note that * this entire data structure is freed if the HNB sends HNB-DE-REGISTER-REQ. */ diff --git a/src/Makefile.am b/src/Makefile.am index b1f8153..24977c2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -85,13 +85,13 @@ osmo_hnbgw_SOURCES = hnbap_encoder.c hnbap_decoder.c hnbap_common.c \ rua_msg_factory.c \ hnbgw.c hnbgw_hnbap.c hnbgw_rua.c hnbgw_ranap.c \ hnbgw_vty.c \ - context_map.c hnbgw_cn.c + context_map.c hnbgw_cn.c hnbgw_sabp.c osmo_hnbgw_LDADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(OSMOVTY_LIBS) $(OSMOCTRL_LIBS) \ $(ASN1C_LIBS) $(OSMOSIGTRAN_LIBS) \ $(OSMONETIF_LIBS) \ hnbap/libosmo-asn1-hnbap.a rua/libosmo-asn1-rua.a \ - libosmo-ranap.la + libosmo-ranap.la libosmo-sabp.la regen: regenerate-from-asn1-source diff --git a/src/hnbgw.c b/src/hnbgw.c index 9dc67a2..d8ca123 100644 --- a/src/hnbgw.c +++ b/src/hnbgw.c @@ -258,6 +258,9 @@ static int hnb_read_cb(struct osmo_stream_srv *conn) rc = hnbgw_rua_rx(hnb, msg); break; case IUH_PPI_SABP: + hnb->sabp_stream = msgb_sctp_stream(msg); + rc = hnbgw_sabp_rx(hnb, msg); + break; case IUH_PPI_RNA: case IUH_PPI_PUA: LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%lu received\n", @@ -354,6 +357,11 @@ static const struct log_info_cat log_cat[] = { .color = "", .description = "RAN Application Part", }, + [DSABP] = { + .name = "DSABP", .loglevel = LOGL_DEBUG, .enabled = 1, + .color = "", + .description = "Service Area Broadcast Protocol", + }, }; static const struct log_info hnbgw_log_info = { @@ -588,6 +596,7 @@ int main(int argc, char **argv) } ranap_set_log_area(DRANAP); + sabp_set_log_area(DSABP); rc = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.1", M3UA_PORT, NULL); if (rc < 0) { diff --git a/src/hnbgw_sabp.c b/src/hnbgw_sabp.c new file mode 100644 index 0000000..95177ac --- /dev/null +++ b/src/hnbgw_sabp.c @@ -0,0 +1,122 @@ +/* hnb-gw specific code for SABP (Service Area Broadcast Protocol) */ + +/* (C) 2019 by Harald Welte + * 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 +#include +#include + +#include +#include + +#include +#include +#include + +#include "asn1helpers.h" + +#include +#include +#include +#include + +static int hnbgw_sabp_tx(struct hnb_context *ctx, struct msgb *msg) +{ + if (!msg) + return -EINVAL; + + msgb_sctp_ppid(msg) = IUH_PPI_SABP; + osmo_stream_srv_send(ctx->conn, msg); + + return 0; +} + +static int sabp_rx_initiating_msg(struct msgb *msg, SABP_InitiatingMessage_t *imsg) +{ + int rc; + + switch (imsg->procedureCode) { + default: + LOGP(DSABP, LOGL_NOTICE, "Unknown SABP Procedure %lu\n", imsg->procedureCode); + rc = -1; + } + + return rc; +} + +static int sabp_rx_successful_outcome_msg(struct msgb *msg, SABP_SuccessfulOutcome_t *in) +{ + /* FIXME */ + LOGP(DSABP, LOGL_NOTICE, "Unexpected SABP Successful Outcome\n"); + return -1; +} + +static int sabp_rx_unsuccessful_outcome_msg(struct msgb *msg, SABP_UnsuccessfulOutcome_t *in) +{ + /* FIXME */ + LOGP(DSABP, LOGL_NOTICE, "Unexpected SABP Unsucessful Outcome\n"); + return -1; +} + + + +static int _hnbgw_sabp_rx(struct msgb *msg, SABP_SABP_PDU_t *pdu) +{ + int rc; + + /* it's a bit odd that we can't dispatch on procedure code, but + * that's not possible */ + switch (pdu->present) { + case SABP_SABP_PDU_PR_initiatingMessage: + rc = sabp_rx_initiating_msg(msg, &pdu->choice.initiatingMessage); + break; + case SABP_SABP_PDU_PR_successfulOutcome: + rc = sabp_rx_successful_outcome_msg(msg, &pdu->choice.successfulOutcome); + break; + case SABP_SABP_PDU_PR_unsuccessfulOutcome: + rc = sabp_rx_unsuccessful_outcome_msg(msg, &pdu->choice.unsuccessfulOutcome); + break; + default: + LOGP(DSABP, LOGL_NOTICE, "Unknown SABP presence %u\n", pdu->present); + rc = -1; + } + + return rc; +} + +int hnbgw_sabp_rx(struct hnb_context *hnb, struct msgb *msg) +{ + SABP_SABP_PDU_t _pdu, *pdu = &_pdu; + asn_dec_rval_t dec_ret; + int rc; + + /* decode and handle to _hnbgw_hnbap_rx() */ + + memset(pdu, 0, sizeof(*pdu)); + dec_ret = aper_decode(NULL, &asn_DEF_SABP_SABP_PDU, (void **) &pdu, + msg->data, msgb_length(msg), 0, 0); + if (dec_ret.code != RC_OK) { + LOGP(DSABP, LOGL_ERROR, "Error in ASN.1 decode\n"); + return -1; + } + + rc = _hnbgw_sabp_rx(msg, pdu); + + return rc; +} -- cgit v1.2.3