This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hnodeb/+/26341 ) Change subject: Move Iuh code to its own module ...................................................................... Move Iuh code to its own module The Iuh code will be further extended next to properly support reconnect, and hnb will also gain proper shutdown support soon. Change-Id: I6e94210ab06a34b70c61bb074c58d7b0f4ee75de --- M include/osmocom/hnodeb/Makefile.am M include/osmocom/hnodeb/hnodeb.h A include/osmocom/hnodeb/iuh.h M src/osmo-hnodeb/Makefile.am M src/osmo-hnodeb/hnb.c M src/osmo-hnodeb/hnbap.c A src/osmo-hnodeb/iuh.c M src/osmo-hnodeb/main.c M src/osmo-hnodeb/rua.c M src/osmo-hnodeb/vty.c 10 files changed, 219 insertions(+), 146 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/include/osmocom/hnodeb/Makefile.am b/include/osmocom/hnodeb/Makefile.am index 197568c..23adb2a 100644 --- a/include/osmocom/hnodeb/Makefile.am +++ b/include/osmocom/hnodeb/Makefile.am @@ -1,6 +1,7 @@ noinst_HEADERS = \ hnbap.h \ hnodeb.h \ + iuh.h \ nas.h \ ranap.h \ rua.h \ diff --git a/include/osmocom/hnodeb/hnodeb.h b/include/osmocom/hnodeb/hnodeb.h index 5d6d088..4cc0831 100644 --- a/include/osmocom/hnodeb/hnodeb.h +++ b/include/osmocom/hnodeb/hnodeb.h @@ -36,18 +36,6 @@ }; extern const struct log_info hnb_log_info; -/* 25.467 Section 7.1 */ -#define IUH_DEFAULT_SCTP_PORT 29169 -#define RNA_DEFAULT_SCTP_PORT 25471 - -#define IUH_PPI_RUA 19 -#define IUH_PPI_HNBAP 20 -#define IUH_PPI_SABP 31 -#define IUH_PPI_RNA 42 -#define IUH_PPI_PUA 55 - -#define IUH_MSGB_SIZE 2048 - struct hnb_chan { int is_ps; uint32_t conn_id; @@ -77,11 +65,9 @@ struct hnb_chan *chan; } cs; }; + struct hnb *hnb_alloc(void *tall_ctx); void hnb_free(struct hnb *hnb); -int hnb_connect(struct hnb *hnb); - -int hnb_iuh_send(struct hnb *hnb, struct msgb *msg); extern void *tall_hnb_ctx; extern struct hnb *g_hnb; diff --git a/include/osmocom/hnodeb/iuh.h b/include/osmocom/hnodeb/iuh.h new file mode 100644 index 0000000..81ce1de --- /dev/null +++ b/include/osmocom/hnodeb/iuh.h @@ -0,0 +1,41 @@ +/* (C) 2015 by Daniel Willmann <dwillmann at sysmocom.de> + * (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de> + * Author: Pau Espin Pedrol <pespin at sysmocom.de> + * 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/lienses/>. + * + */ +#pragma once + +#include <osmocom/core/msgb.h> + +/* 25.467 Section 7.1 */ +#define IUH_DEFAULT_SCTP_PORT 29169 +#define RNA_DEFAULT_SCTP_PORT 25471 + +#define IUH_PPI_RUA 19 +#define IUH_PPI_HNBAP 20 +#define IUH_PPI_SABP 31 +#define IUH_PPI_RNA 42 +#define IUH_PPI_PUA 55 + +#define IUH_MSGB_SIZE 2048 + +struct hnb; + +void hnb_iuh_alloc(struct hnb *hnb); +void hnb_iuh_free(struct hnb *hnb); +int hnb_iuh_connect(struct hnb *hnb); +int hnb_iuh_send(struct hnb *hnb, struct msgb *msg); diff --git a/src/osmo-hnodeb/Makefile.am b/src/osmo-hnodeb/Makefile.am index 139b6b0..88f2571 100644 --- a/src/osmo-hnodeb/Makefile.am +++ b/src/osmo-hnodeb/Makefile.am @@ -33,6 +33,7 @@ debug.c \ hnbap.c \ hnb.c \ + iuh.c \ nas.c \ ranap.c \ rua.c \ diff --git a/src/osmo-hnodeb/hnb.c b/src/osmo-hnodeb/hnb.c index 420095d..3344cfb 100644 --- a/src/osmo-hnodeb/hnb.c +++ b/src/osmo-hnodeb/hnb.c @@ -20,99 +20,17 @@ #include "config.h" -#include <errno.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netinet/sctp.h> -#include <arpa/inet.h> - #include <osmocom/core/socket.h> #include <osmocom/core/talloc.h> #include <osmocom/netif/stream.h> -#include <osmocom/hnodeb/hnbap.h> -#include <osmocom/hnodeb/rua.h> #include <osmocom/hnodeb/hnodeb.h> +#include <osmocom/hnodeb/iuh.h> -static int hnb_iuh_read_cb(struct osmo_stream_cli *conn) -{ - struct osmo_fd *fd = osmo_stream_cli_get_ofd(conn); - struct hnb *hnb = osmo_stream_cli_get_data(conn); - struct sctp_sndrcvinfo sinfo; - struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx"); - int flags = 0; - int rc; - - if (!msg) - return -ENOMEM; - - rc = sctp_recvmsg(fd->fd, msgb_data(msg), msgb_tailroom(msg), - NULL, NULL, &sinfo, &flags); - if (rc < 0) { - LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n"); - /* FIXME: clean up after disappeared HNB */ - osmo_stream_cli_close(conn); - goto free_ret; - } else if (rc == 0) { - LOGP(DMAIN, LOGL_INFO, "Connection to HNB closed\n"); - osmo_stream_cli_close(conn); - rc = -1; - goto free_ret; - } else { - msgb_put(msg, rc); - } - - if (flags & MSG_NOTIFICATION) { - LOGP(DMAIN, LOGL_DEBUG, "Ignoring SCTP notification\n"); - rc = 0; - goto free_ret; - } - - sinfo.sinfo_ppid = ntohl(sinfo.sinfo_ppid); - - switch (sinfo.sinfo_ppid) { - case IUH_PPI_HNBAP: - LOGP(DHNBAP, LOGL_INFO, "HNBAP message received\n"); - rc = hnb_hnbap_rx(hnb, msg); - break; - case IUH_PPI_RUA: - LOGP(DRUA, LOGL_INFO, "RUA message received\n"); - rc = hnb_rua_rx(hnb, msg); - break; - case IUH_PPI_SABP: - case IUH_PPI_RNA: - case IUH_PPI_PUA: - LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%u received\n", - sinfo.sinfo_ppid); - rc = 0; - break; - default: - LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n", - sinfo.sinfo_ppid); - rc = 0; - break; - } - -free_ret: - msgb_free(msg); - return rc; -} - -static int hnb_iuh_connect_cb(struct osmo_stream_cli *conn) -{ - LOGP(DMAIN, LOGL_NOTICE, "Iuh connected to HNBGW\n"); - struct hnb *hnb = osmo_stream_cli_get_data(conn); - - hnb_send_register_req(hnb); - return 0; -} struct hnb *hnb_alloc(void *tall_ctx) { struct hnb *hnb; - struct osmo_stream_cli *cli; hnb = talloc_zero(tall_ctx, struct hnb); if (!hnb) @@ -123,58 +41,13 @@ .mcc = 1, .mnc = 1, }; - - hnb->iuh.local_addr = talloc_strdup(hnb, "0.0.0.0"); - hnb->iuh.local_port = 0; - hnb->iuh.remote_addr = talloc_strdup(hnb, "127.0.0.1"); - hnb->iuh.remote_port = IUH_DEFAULT_SCTP_PORT; - - cli = osmo_stream_cli_create(hnb); - OSMO_ASSERT(cli); - hnb->iuh.client = cli; - osmo_stream_cli_set_nodelay(cli, true); - osmo_stream_cli_set_proto(cli, IPPROTO_SCTP); - osmo_stream_cli_set_reconnect_timeout(cli, 5); - osmo_stream_cli_set_connect_cb(cli, hnb_iuh_connect_cb); - osmo_stream_cli_set_read_cb(cli, hnb_iuh_read_cb); - osmo_stream_cli_set_data(cli, hnb); + hnb_iuh_alloc(hnb); return hnb; } void hnb_free(struct hnb *hnb) { - if (hnb->iuh.client) { - osmo_stream_cli_destroy(hnb->iuh.client); - hnb->iuh.client = NULL; - } + hnb_iuh_free(hnb); talloc_free(hnb); } - -int hnb_connect(struct hnb *hnb) -{ - int rc; - - LOGP(DMAIN, LOGL_INFO, "Iuh Connect: %s[:%u] => %s[:%u]\n", - hnb->iuh.local_addr, hnb->iuh.local_port, hnb->iuh.remote_addr, hnb->iuh.remote_port); - - osmo_stream_cli_set_addrs(hnb->iuh.client, (const char**)&hnb->iuh.remote_addr, 1); - osmo_stream_cli_set_port(hnb->iuh.client, hnb->iuh.remote_port); - osmo_stream_cli_set_local_addrs(hnb->iuh.client, (const char**)&hnb->iuh.local_addr, 1); - osmo_stream_cli_set_local_port(hnb->iuh.client, hnb->iuh.local_port); - rc = osmo_stream_cli_open(hnb->iuh.client); - if (rc < 0) { - LOGP(DMAIN, LOGL_ERROR, "Unable to open stream client for Iuh %s[:%u] => %s[:%u]\n", - hnb->iuh.local_addr, hnb->iuh.local_port, hnb->iuh.remote_addr, hnb->iuh.remote_port); - /* we don't return error in here because osmo_stream_cli_open() - will continue to retry (due to timeout being explicitly set with - osmo_stream_cli_set_reconnect_timeout() above) to connect so the error is transient */ - } - return 0; -} - -int hnb_iuh_send(struct hnb *hnb, struct msgb *msg) -{ - osmo_stream_cli_send(hnb->iuh.client, msg); - return 0; -} diff --git a/src/osmo-hnodeb/hnbap.c b/src/osmo-hnodeb/hnbap.c index bcddfb3..585354b 100644 --- a/src/osmo-hnodeb/hnbap.c +++ b/src/osmo-hnodeb/hnbap.c @@ -32,6 +32,7 @@ #include <osmocom/hnodeb/hnbap.h> #include <osmocom/hnodeb/hnodeb.h> +#include <osmocom/hnodeb/iuh.h> static int hnb_rx_hnb_register_acc(struct hnb *hnb, ANY_t *in) { diff --git a/src/osmo-hnodeb/iuh.c b/src/osmo-hnodeb/iuh.c new file mode 100644 index 0000000..bcd047b --- /dev/null +++ b/src/osmo-hnodeb/iuh.c @@ -0,0 +1,167 @@ +/* (C) 2015 by Daniel Willmann <dwillmann at sysmocom.de> + * (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de> + * Author: Pau Espin Pedrol <pespin at sysmocom.de> + * 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/lienses/>. + * + */ + +#include "config.h" + +#include <errno.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/sctp.h> +#include <arpa/inet.h> + +#include <osmocom/core/socket.h> +#include <osmocom/core/talloc.h> +#include <osmocom/netif/stream.h> + +#include <osmocom/hnodeb/iuh.h> +#include <osmocom/hnodeb/hnbap.h> +#include <osmocom/hnodeb/rua.h> +#include <osmocom/hnodeb/hnodeb.h> + +static int hnb_iuh_read_cb(struct osmo_stream_cli *conn) +{ + struct osmo_fd *fd = osmo_stream_cli_get_ofd(conn); + struct hnb *hnb = osmo_stream_cli_get_data(conn); + struct sctp_sndrcvinfo sinfo; + struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx"); + int flags = 0; + int rc; + + if (!msg) + return -ENOMEM; + + rc = sctp_recvmsg(fd->fd, msgb_data(msg), msgb_tailroom(msg), + NULL, NULL, &sinfo, &flags); + if (rc < 0) { + LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n"); + /* FIXME: clean up after disappeared HNB */ + osmo_stream_cli_close(conn); + goto free_ret; + } else if (rc == 0) { + LOGP(DMAIN, LOGL_INFO, "Connection to HNBGW closed\n"); + osmo_stream_cli_close(conn); + rc = -1; + goto free_ret; + } else { + msgb_put(msg, rc); + } + + if (flags & MSG_NOTIFICATION) { + LOGP(DMAIN, LOGL_DEBUG, "Ignoring SCTP notification\n"); + rc = 0; + goto free_ret; + } + + sinfo.sinfo_ppid = ntohl(sinfo.sinfo_ppid); + + switch (sinfo.sinfo_ppid) { + case IUH_PPI_HNBAP: + LOGP(DHNBAP, LOGL_INFO, "HNBAP message received\n"); + rc = hnb_hnbap_rx(hnb, msg); + break; + case IUH_PPI_RUA: + LOGP(DRUA, LOGL_INFO, "RUA message received\n"); + rc = hnb_rua_rx(hnb, msg); + break; + case IUH_PPI_SABP: + case IUH_PPI_RNA: + case IUH_PPI_PUA: + LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%u received\n", + sinfo.sinfo_ppid); + rc = 0; + break; + default: + LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n", + sinfo.sinfo_ppid); + rc = 0; + break; + } + +free_ret: + msgb_free(msg); + return rc; +} + +static int hnb_iuh_connect_cb(struct osmo_stream_cli *conn) +{ + LOGP(DMAIN, LOGL_NOTICE, "Iuh connected to HNBGW\n"); + struct hnb *hnb = osmo_stream_cli_get_data(conn); + + hnb_send_register_req(hnb); + return 0; +} + +void hnb_iuh_alloc(struct hnb *hnb) +{ + struct osmo_stream_cli *cli; + + hnb->iuh.local_addr = talloc_strdup(hnb, "0.0.0.0"); + hnb->iuh.local_port = 0; + hnb->iuh.remote_addr = talloc_strdup(hnb, "127.0.0.1"); + hnb->iuh.remote_port = IUH_DEFAULT_SCTP_PORT; + + cli = osmo_stream_cli_create(hnb); + OSMO_ASSERT(cli); + hnb->iuh.client = cli; + osmo_stream_cli_set_nodelay(cli, true); + osmo_stream_cli_set_proto(cli, IPPROTO_SCTP); + osmo_stream_cli_set_reconnect_timeout(cli, 5); + osmo_stream_cli_set_connect_cb(cli, hnb_iuh_connect_cb); + osmo_stream_cli_set_read_cb(cli, hnb_iuh_read_cb); + osmo_stream_cli_set_data(cli, hnb); +} + +void hnb_iuh_free(struct hnb *hnb) +{ + if (!hnb->iuh.client) + return; + osmo_stream_cli_destroy(hnb->iuh.client); + hnb->iuh.client = NULL; +} + +int hnb_iuh_connect(struct hnb *hnb) +{ + int rc; + + LOGP(DMAIN, LOGL_INFO, "Iuh Connect: %s[:%u] => %s[:%u]\n", + hnb->iuh.local_addr, hnb->iuh.local_port, hnb->iuh.remote_addr, hnb->iuh.remote_port); + + osmo_stream_cli_set_addrs(hnb->iuh.client, (const char **)&hnb->iuh.remote_addr, 1); + osmo_stream_cli_set_port(hnb->iuh.client, hnb->iuh.remote_port); + osmo_stream_cli_set_local_addrs(hnb->iuh.client, (const char **)&hnb->iuh.local_addr, 1); + osmo_stream_cli_set_local_port(hnb->iuh.client, hnb->iuh.local_port); + rc = osmo_stream_cli_open(hnb->iuh.client); + if (rc < 0) { + LOGP(DMAIN, LOGL_ERROR, "Unable to open stream client for Iuh %s[:%u] => %s[:%u]\n", + hnb->iuh.local_addr, hnb->iuh.local_port, hnb->iuh.remote_addr, hnb->iuh.remote_port); + /* we don't return error in here because osmo_stream_cli_open() + will continue to retry (due to timeout being explicitly set with + osmo_stream_cli_set_reconnect_timeout() above) to connect so the error is transient */ + } + return 0; +} + +int hnb_iuh_send(struct hnb *hnb, struct msgb *msg) +{ + osmo_stream_cli_send(hnb->iuh.client, msg); + return 0; +} diff --git a/src/osmo-hnodeb/main.c b/src/osmo-hnodeb/main.c index 3376d8e..12d98ff 100644 --- a/src/osmo-hnodeb/main.c +++ b/src/osmo-hnodeb/main.c @@ -48,6 +48,7 @@ #include <osmocom/hnodeb/ranap.h> #include <osmocom/hnodeb/vty.h> #include <osmocom/hnodeb/hnodeb.h> +#include <osmocom/hnodeb/iuh.h> static const char * const osmohnodeb_copyright = "OsmoHNodeB - Osmocom 3G Home NodeB implementation\r\n" @@ -264,7 +265,7 @@ exit(1); } - rc = hnb_connect(g_hnb); + rc = hnb_iuh_connect(g_hnb); if (rc < 0) { perror("Error connecting to Iuh port"); exit(1); diff --git a/src/osmo-hnodeb/rua.c b/src/osmo-hnodeb/rua.c index 0dd8c3a..907cd60 100644 --- a/src/osmo-hnodeb/rua.c +++ b/src/osmo-hnodeb/rua.c @@ -28,6 +28,7 @@ #include <osmocom/hnodeb/rua.h> #include <osmocom/hnodeb/ranap.h> +#include <osmocom/hnodeb/iuh.h> int hnb_tx_dt(struct hnb *hnb, struct msgb *txm) { diff --git a/src/osmo-hnodeb/vty.c b/src/osmo-hnodeb/vty.c index 61a3f4c..e11fc2d 100644 --- a/src/osmo-hnodeb/vty.c +++ b/src/osmo-hnodeb/vty.c @@ -34,6 +34,7 @@ #include <osmocom/ranap/ranap_common.h> #include <osmocom/ranap/ranap_msg_factory.h> +#include <osmocom/hnodeb/iuh.h> #include <osmocom/hnodeb/hnbap.h> #include <osmocom/hnodeb/ranap.h> #include <osmocom/hnodeb/vty.h> -- To view, visit https://gerrit.osmocom.org/c/osmo-hnodeb/+/26341 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnodeb Gerrit-Branch: master Gerrit-Change-Id: I6e94210ab06a34b70c61bb074c58d7b0f4ee75de Gerrit-Change-Number: 26341 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211124/4d57fa46/attachment.htm>