WIP: add SABP support to HNBGW

Change-Id: I2d91de2e37770e3635abe8004ac183857d8a6ff2
This commit is contained in:
Harald Welte 2019-09-21 00:02:46 +02:00 committed by Harald Welte
parent 9fb8cac6dc
commit e9e089128c
4 changed files with 136 additions and 2 deletions

View File

@ -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. */

View File

@ -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

View File

@ -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) {

122
src/hnbgw_sabp.c Normal file
View File

@ -0,0 +1,122 @@
/* hnb-gw specific code for SABP (Service Area Broadcast Protocol) */
/* (C) 2019 by Harald Welte <laforge@gnumonks.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <osmocom/core/msgb.h>
#include <osmocom/core/utils.h>
#include <osmocom/netif/stream.h>
#include <osmocom/sigtran/sccp_sap.h>
#include <osmocom/sigtran/sccp_helpers.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "asn1helpers.h"
#include <osmocom/iuh/hnbgw.h>
#include <osmocom/iuh/hnbgw_ranap.h>
#include <osmocom/sabp/sabp_common.h>
#include <osmocom/sabp/sabp_ies_defs.h>
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;
}