lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

January 2023

  • 1 participants
  • 2205 discussions
Change in libosmocore[master]: Add osmo_io with initial poll backend
by daniel 11 Jan '23

11 Jan '23
daniel has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/30934 ) Change subject: Add osmo_io with initial poll backend ...................................................................... Add osmo_io with initial poll backend * make backend configurable for later * segmentation callback for chunked streams * logging target for osmo_io * support partial writes Change-Id: I50d73cf550d6ce8154bf827bf47408131cf5b0a0 Related: SYS#5094, OS#5751 --- M TODO-RELEASE M include/Makefile.am M include/osmocom/core/logging.h A include/osmocom/core/osmo_io.h M src/Makefile.am M src/logging.c A src/osmo_io.c A src/osmo_io_internal.h A src/osmo_io_poll.c 9 files changed, 851 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/34/30934/1 diff --git a/TODO-RELEASE b/TODO-RELEASE index 6ac8db8..ef629c7 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -9,3 +9,4 @@ #library what description / commit summary line libosmocore new API osmo_sockaddr_is_any() libosmocore ABI breakage OSMO_NUM_DLIB change affecting internal_cat[] +libosmocore new API osmo_io_* diff --git a/include/Makefile.am b/include/Makefile.am index a234014..b59009d 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -37,6 +37,7 @@ osmocom/core/log2.h \ osmocom/core/logging.h \ osmocom/core/loggingrb.h \ + osmocom/core/osmo_io.h \ osmocom/core/stats.h \ osmocom/core/macaddr.h \ osmocom/core/msgb.h \ diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 5ae38c7..8e30a20 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -154,7 +154,8 @@ #define DLCSN1 -26 /*!< CSN.1 (Concrete Syntax Notation 1) codec */ #define DLM2PA -27 /*!< Osmocom M2PA (libosmo-sigtran) */ #define DLM2UA -28 /*!< Reserved for future Osmocom M2UA (libosmo-sigtran) */ -#define OSMO_NUM_DLIB 28 /*!< Number of logging sub-systems in libraries */ +#define DLIO -29 /*!< Osmocom IO sub-system */ +#define OSMO_NUM_DLIB 29 /*!< Number of logging sub-systems in libraries */ /* Colors that can be used in log_info_cat.color */ #define OSMO_LOGCOLOR_NORMAL NULL diff --git a/include/osmocom/core/osmo_io.h b/include/osmocom/core/osmo_io.h new file mode 100644 index 0000000..4fac3f1 --- /dev/null +++ b/include/osmocom/core/osmo_io.h @@ -0,0 +1,56 @@ +/*! \file osmo_io.h + * io(_uring) abstraction osmo fd compatibility + */ + +#pragma once + +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/socket.h> + +struct osmo_io_fd; + +enum osmo_io_fd_mode { + /*! use read() / write() calls */ + OSMO_IO_FD_MODE_READ_WRITE, + /*! use recvfrom() / sendto() calls */ + OSMO_IO_FD_MODE_RECVFROM_SENDTO, + /*! emulate sctp_recvmsg() and sctp_sendmsg() */ + OSMO_IO_FD_MODE_SCTP_RECVMSG_SENDMSG, +}; + +enum osmo_io_backend { + OSMO_IO_BACKEND_POLL, +}; + +struct osmo_io_ops { + /*! call-back function when something was read from fd */ + void (*read_cb)(struct osmo_io_fd *, int res, struct msgb *); + /*! call-back function when write has completed on fd */ + void (*write_cb)(struct osmo_io_fd *, int res, struct msgb *); + + /*! call-back function emulating sendto */ + void (*sendmsg_cb)(struct osmo_io_fd *, int res, struct msgb *); + /*! call-back function emulating recvfrom */ + void (*recvmsg_cb)(struct osmo_io_fd *, int res, struct msgb *, struct osmo_sockaddr *); + + /*! call-back function to segment the data returned by read_cb */ + int (*segmentation_cb)(struct msgb *, int data_len); +}; + +void osmo_io_init(); + +struct osmo_io_fd *osmo_iofd_setup(const void *ctx, unsigned int size, unsigned int headroom, + int fd, const char *name, enum osmo_io_fd_mode mode, + const struct osmo_io_ops *ioops, void *data, unsigned int priv_nr); +void osmo_iofd_close(struct osmo_io_fd *iofd); +int osmo_iofd_write_msgb(struct osmo_io_fd *iofd, struct msgb *msg); +void osmo_iofd_read_enable(struct osmo_io_fd *iofd); +void osmo_iofd_read_enable(struct osmo_io_fd *iofd); + +int osmo_iofd_sendto_msgb(struct osmo_io_fd *iofd, struct msgb *msg, + const struct osmo_sockaddr *dest); + +void *osmo_iofd_get_data(struct osmo_io_fd *iofd); +unsigned int osmo_iofd_get_priv(struct osmo_io_fd *iofd); +int osmo_iofd_get_fd(struct osmo_io_fd *iofd); diff --git a/src/Makefile.am b/src/Makefile.am index 2c73af6..ba0926e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,7 @@ it_q.c \ probes.d \ base64.c \ + osmo_io.c osmo_io_poll.c \ $(NULL) if HAVE_SSSE3 diff --git a/src/logging.c b/src/logging.c index ce42e4c..196ca37 100644 --- a/src/logging.c +++ b/src/logging.c @@ -313,6 +313,12 @@ .enabled = 1, .loglevel = LOGL_NOTICE, .color = "\033[38;5;11m", }, + [INT2IDX(DLIO)] = { + .name = "DLIO", + .description = "libosmocore IO Subsystem", + .enabled = 1, .loglevel = LOGL_NOTICE, + .color = "\033[38;5;67m", + }, }; void assert_loginfo(const char *src) diff --git a/src/osmo_io.c b/src/osmo_io.c new file mode 100644 index 0000000..a896888 --- /dev/null +++ b/src/osmo_io.c @@ -0,0 +1,440 @@ +/*! \file osmo_io.c + * New osmocom async I/O API. + * + * (C) 2022 by Harald Welte <laforge(a)osmocom.org> + * (C) 2022 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * Author: Daniel Willmann <dwillmann(a)sysmocom.de> + * + * All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + */ + + +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <talloc.h> +#include <unistd.h> +#include <string.h> +#include <stdbool.h> +#include <errno.h> + +#include <osmocom/core/osmo_io.h> +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/logging.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/socket.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/utils.h> + +#include "../config.h" +#include "osmo_io_internal.h" + +extern struct iofd_backend_ops iofd_poll_ops; +#define OSMO_IO_BACKEND_DEFAULT "POLL" + +static enum osmo_io_backend g_backend; + +/* Used by some tests, can't be static */ +struct iofd_backend_ops g_iofd_ops; + +/*! initialize osmo_io for the current thread */ +void osmo_iofd_init() +{ + switch (g_backend) { + case OSMO_IO_BACKEND_POLL: + break; + default: + OSMO_ASSERT(0); + break; + } +} + +/*! ensure main thread always has pre-initialized osmo_io */ +static __attribute__((constructor)) void on_dso_load_select(void) +{ + char *backend = getenv("LIBOSMO_IO_BACKEND"); + if (backend == NULL) + backend = OSMO_IO_BACKEND_DEFAULT; + + if (!strcmp("POLL", backend)) { + g_backend = OSMO_IO_BACKEND_POLL; + g_iofd_ops = iofd_poll_ops; + } else { + OSMO_ASSERT(0); + } + + osmo_iofd_init(); +} + +/*! Allocate the msghdr + * \param[in] iofd the osmo_io file structure + * \param[in] action the action this msg(hdr) is for (read, write, ..) + * \param[in] msg the msg buffer to use. Will allocate a new one if NULL + * \returns the newly allocated msghdr or NULL in case of error */ +struct iofd_msghdr *iofd_msghdr_alloc(struct osmo_io_fd *iofd, enum iofd_msg_action action, struct msgb *msg) +{ + struct iofd_msghdr *hdr = talloc_zero(iofd, struct iofd_msghdr); + if (!hdr) + return NULL; + if (!msg) { + msg = iofd_msgb_alloc(iofd); + if (!msg) { + talloc_free(hdr); + return NULL; + } + } + + hdr->action = action; + hdr->iofd = iofd; + hdr->msg = msg; + + return hdr; +} + +/*! Free the msghdr + * \param[in] msghdr the msghdr to free + */ +void iofd_msghdr_free(struct iofd_msghdr *msghdr) +{ + talloc_free(msghdr); +} + +/*! convenience wrapper to call msgb_alloc with parameters from osmo_io_fd */ +struct msgb *iofd_msgb_alloc(struct osmo_io_fd *iofd) +{ + uint16_t headroom = iofd->msgb_alloc.headroom; + + OSMO_ASSERT(iofd->msgb_alloc.size < 0xffff - headroom); + return msgb_alloc_headroom_c(iofd->msgb_alloc.ctx, + iofd->msgb_alloc.size + headroom, headroom, iofd->name); +} + +/*! return the pending msgb in iofd or NULL if there is none*/ +struct msgb *iofd_msgb_pending(struct osmo_io_fd *iofd) +{ + struct msgb *msg = NULL; + + msg = iofd->pending; + iofd->pending = NULL; + + return msg; +} + +/*! Return the pending msgb or allocate and return a new one */ +struct msgb *iofd_msgb_pending_or_alloc(struct osmo_io_fd *iofd) +{ + struct msgb *msg = NULL; + + msg = iofd->pending; + iofd->pending = NULL; + + if (!msg) { + msg = iofd_msgb_alloc(iofd); + } + + return msg; +} + +/*! Enqueue a message to be sent + * + * Enqueues the message at the back of the queue provided there is enough space. + * \param[in] iofd the file descriptor + * \param[in] msghdr the message to enqueue + * \returns 0 if the message was enqueued succcessfully, + * -ENOSPC if the queue already contains the maximum number of messages + */ +int iofd_txqueue_enqueue(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr) +{ + if (iofd->tx_queue.current_length >= iofd->tx_queue.max_length) + return -ENOSPC; + + llist_add_tail(&msghdr->list, &iofd->tx_queue.msg_queue); + iofd->tx_queue.current_length++; + + return 0; +} + +/*! Enqueue a message at the front + * + * Used to enqueue a msgb from a partial send again. This function will allways + * enqueue the message, even if the maximum number of messages is reached. + * \param[in] iofd the file descriptor + * \param[in] msghdr the message to enqueue + */ +void iofd_txqueue_enqueue_front(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr) +{ + llist_add(&msghdr->list, &iofd->tx_queue.msg_queue); + iofd->tx_queue.current_length++; +} + +/*! Dequeue a message from the front + * + * \param[in] iofd the file descriptor + * \returns the msghdr from the front of the queue or NULL if the queue is empty + */ +struct iofd_msghdr *iofd_txqueue_dequeue(struct osmo_io_fd *iofd) +{ + struct llist_head *lh; + + if (iofd->tx_queue.current_length == 0) + return NULL; + + lh = iofd->tx_queue.msg_queue.next; + + OSMO_ASSERT(lh); + iofd->tx_queue.current_length--; + llist_del(lh); + + return llist_entry(lh, struct iofd_msghdr, list); +} + +enum iofd_seg_act iofd_handle_segmentation(struct osmo_io_fd *iofd, struct msgb *msg) +{ + int pending_len, msg_len; + struct msgb *msg_pending; + + msg_len = msgb_length(msg); + + if (!iofd->io_ops.segmentation_cb) + return IOFD_SEG_ACT_HANDLE_ONE; + + int len = iofd->io_ops.segmentation_cb(msg, msg_len); + + pending_len = msg_len - len; + /* No segmentation needed, return */ + if (pending_len == 0) { + return IOFD_SEG_ACT_HANDLE_ONE; + } else if (pending_len < 0) { + iofd->pending = msg; + return IOFD_SEG_ACT_DEFER; + } + + /* Copy the superfluous data over */ + msg_pending = iofd_msgb_alloc(iofd); + memcpy(msgb_data(msg_pending), msgb_data(msg)+ len, pending_len); + msgb_put(msg_pending, pending_len); + iofd->pending = msg_pending; + + /* Trim the original msgb to size */ + msgb_trim(msg, len); + return IOFD_SEG_ACT_HANDLE_MORE; +} + +/*! Restore message boundaries on read() and pass individual messages to the read callback + */ +void iofd_handle_segmented_read(struct osmo_io_fd *iofd, struct msgb *msg, int rc) { + int res; + + if (rc <= 0) { + iofd->io_ops.read_cb(iofd, rc, msg); + return; + } + + do { + res = iofd_handle_segmentation(iofd, msg); + if (res != IOFD_SEG_ACT_DEFER || rc < 0) + iofd->io_ops.read_cb(iofd, rc, msg); + if (res == IOFD_SEG_ACT_HANDLE_MORE) + msg = iofd_msgb_pending(iofd); + } while (res == IOFD_SEG_ACT_HANDLE_MORE); +} + +/* Public functions */ + +/*! Send a message through a connected socket + * + * Appends the message to the internal transmit queue. + * If the function returns success (0) it will take ownership of the msgb and + * internally call msgb_free() after the write request completes. + * In case of an error the msgb needs to be freed by the caller. + * \param[in] iofd file descriptor to write to + * \param[in] msg message buffer to write + * \returns 0 in case of success; a negative value in case of error + */ +int osmo_iofd_write_msgb(struct osmo_io_fd *iofd, struct msgb *msg) +{ + int rc; + struct iofd_msghdr *msghdr = iofd_msghdr_alloc(iofd, IOFD_ACT_WRITE, msg); + if (!msghdr) { + return -ENOMEM; + } + + + rc = iofd_txqueue_enqueue(iofd, msghdr); + if (rc < 0) { + iofd_msghdr_free(msghdr); + LOGP(DLIO, LOGL_ERROR, "iofd(%s) enqueueing message failed (%i). Rejecting msgb\n", iofd->name, rc); + return rc; + } + + g_iofd_ops.write_enable(iofd); + + return 0; +} + +/*! Send a message through an unconnected socket + * + * Appends the message to the internal transmit queue. + * If the function returns success (0), it will take ownership of the msgb and + * internally call msgb_free() after the write request completes. + * In case of an error the msgb needs to be freed by the caller. + * \param[in] iofd file descriptor to write to + * \param[in] msg message buffer to send + * \param[in] dest destination address to send the message to + * \returns 0 in case of success; a negative value in case of error + */ +int osmo_iofd_sendto_msgb(struct osmo_io_fd *iofd, struct msgb *msg, const struct osmo_sockaddr *dest) +{ + int rc; + + OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_RECVFROM_SENDTO); + + struct iofd_msghdr *msghdr = iofd_msghdr_alloc(iofd, IOFD_ACT_SENDTO, msg); + if (!msghdr) { + return -ENOMEM; + } + + msghdr->sa = *dest; + + rc = iofd_txqueue_enqueue(iofd, msghdr); + if (rc < 0) { + iofd_msghdr_free(msghdr); + LOGP(DLIO, LOGL_ERROR, "iofd(%s) enqueueing message failed (%i). Rejecting msgb\n", iofd->name, rc); + return rc; + } + + g_iofd_ops.write_enable(iofd); + + return 0; +} + +/*! Enable reading from this iofd + * + * \param[in] iofd the file descriptor + */ +void osmo_iofd_read_enable(struct osmo_io_fd *iofd) +{ + g_iofd_ops.read_enable(iofd); +} + +/*! Disable reading from this iofd + * + * The read_cb can still be called for messages that arrived at the socket + * before this function was called. + * \param[in] iofd the file descriptor + */ +void osmo_iofd_read_disable(struct osmo_io_fd *iofd) +{ + g_iofd_ops.read_disable(iofd); +} + +/*! Allocate and setup a new iofd + * \param[in] ctx the parent context from which to allocate + * \param[in] size the size of the msgb when receiving data + * \param[in] headroom the headroom of the msgb when receiving data + * \param[in] fd the underlying system file descriptor + * \param[in] name the name of the iofd + * \param[in] mode the mode of the iofd, whether it should use read()/write(), sendto()/recvfrom() + * \param[in] ioops structure with read/write/send/recv callbacks + * \param[in] data user data pointer accessible by the ioops callbacks + * \param[in] priv_nr user data storage accessible by the ioops callbacks + * \returns The newly allocated osmo_io_fd struct or NULL on failure + */ +struct osmo_io_fd *osmo_iofd_setup(const void *ctx, unsigned int size, unsigned int headroom, + int fd, const char *name, enum osmo_io_fd_mode mode, + const struct osmo_io_ops *ioops, void *data, unsigned int priv_nr) +{ + struct osmo_io_fd *iofd = talloc_zero(ctx, struct osmo_io_fd); + if (!iofd) + return NULL; + + iofd->fd = fd; + iofd->mode = mode; + + iofd->name = talloc_strdup(iofd, name); + + if (ioops) + iofd->io_ops = *ioops; + + iofd->pending = NULL; + + iofd->data = data; + iofd->priv_nr = priv_nr; + + iofd->msgb_alloc.ctx = ctx; + iofd->msgb_alloc.size = size; + iofd->msgb_alloc.headroom = headroom; + + iofd->tx_queue.max_length = 32; + INIT_LLIST_HEAD(&iofd->tx_queue.msg_queue); + + if (g_iofd_ops.setup) { + int rc = g_iofd_ops.setup(iofd); + if (rc < 0) + goto err; + } + LOGP(DLIO, LOGL_DEBUG, "iofd(%s) using backend %s\n", iofd->name, g_backend == OSMO_IO_BACKEND_POLL ? "poll" : "uring"); + + return iofd; +err: + talloc_free(iofd); + return NULL; +} + +/*! Close the iofd + * + * This function is safe to use in the read/write callbacks and will defer freeing it until safe to do so. + * \param[in] iofd the file descriptor + */ +void osmo_iofd_close(struct osmo_io_fd* iofd) +{ + iofd->closing = true; + + // Free pending msgs in tx queue + msgb_queue_free(&iofd->tx_queue.msg_queue); + if (iofd->pending) + msgb_free(iofd->pending); + + iofd->pending = NULL; + + if (g_iofd_ops.close && g_iofd_ops.close(iofd)) + talloc_free(iofd); +} + +/*! Get the associated user-data from an iofd + * \param[in] iofd the file descriptor + * \returns the data that was previously set with \ref osmo_iofd_setup() + */ +void *osmo_iofd_get_data(struct osmo_io_fd *iofd) +{ + return iofd->data; +} + +/*! Get the private number from an iofd + * \param[in] iofd the file descriptor + * \returns the private number that was previously set with \ref osmo_iofd_setup() + */ +unsigned int osmo_iofd_get_priv(struct osmo_io_fd *iofd) +{ + return iofd->priv_nr; +} + +/*! Get the underlying file descriptor from an iofd + * \param[in] iofd the file descriptor + * \returns the underlying file descriptor number */ +int osmo_iofd_get_fd(struct osmo_io_fd *iofd) +{ + return iofd->fd; +} \ No newline at end of file diff --git a/src/osmo_io_internal.h b/src/osmo_io_internal.h new file mode 100644 index 0000000..f0fc791 --- /dev/null +++ b/src/osmo_io_internal.h @@ -0,0 +1,125 @@ +/*! \file osmo_io_internal.h */ + +#pragma once + +#include <unistd.h> +#include <stdbool.h> + +#include <osmocom/core/osmo_io.h> +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/select.h> +#include <osmocom/core/socket.h> + +#include "../config.h" + +struct iofd_backend_ops { + int (*setup)(struct osmo_io_fd *iofd); + int (*close)(struct osmo_io_fd *iofd); + void (*write_enable)(struct osmo_io_fd *iofd); + void (*write_disable)(struct osmo_io_fd *iofd); + void (*read_enable)(struct osmo_io_fd *iofd); + void (*read_disable)(struct osmo_io_fd *iofd); +}; + +struct osmo_io_fd { + /*! linked list for internal management */ + struct llist_head list; + /*! actual operating-system level file decriptor */ + int fd; + /*! type of read/write mode to use */ + enum osmo_io_fd_mode mode; + + /*! flags to guard closing/freeing of iofd */ + bool closing; + bool in_callback; + + /*! human-readable name to associte with fd */ + const char *name; + + /*! send/recv (msg) callback functions */ + struct osmo_io_ops io_ops; + /*! Pending msgb to keep partial data during segmentation */ + struct msgb *pending; + + /*! data pointer passed through to call-back function */ + void *data; + /*! private number, extending \a data */ + unsigned int priv_nr; + + struct { + /*! talloc context from which to allocate msgb when reading */ + const void *ctx; + /*! size of msgb to allocte (excluding headroom) */ + unsigned int size; + /*! headroom to allocate when allocating msgb's */ + unsigned int headroom; + } msgb_alloc; + + struct { + /*! maximum length of write queue */ + unsigned int max_length; + /*! current length of write queue */ + unsigned int current_length; + /*! actual linked list implementing the transmit queue */ + struct llist_head msg_queue; + } tx_queue; + + union { + struct { + struct osmo_fd ofd; + } poll; + struct { + bool read_enabled; + bool read_pending; + bool write_pending; + bool write_enabled; + /* TODO: index into array of registered fd's? */ + } uring; + } u; +}; + +enum iofd_msg_action { + IOFD_ACT_READ, + IOFD_ACT_WRITE, + IOFD_ACT_RECVFROM, + IOFD_ACT_SENDTO, + // TODO: SCTP_* +}; + + +/* serialized version of 'struct msghdr' employed by sendmsg/recvmsg */ +struct iofd_msghdr { + struct llist_head list; + enum iofd_msg_action action; + struct msghdr hdr; + struct osmo_sockaddr sa; + struct iovec iov[1]; + int flags; + + struct msgb *msg; + struct osmo_io_fd *iofd; +}; + +enum iofd_seg_act { + IOFD_SEG_ACT_HANDLE_ONE, + IOFD_SEG_ACT_HANDLE_MORE, + IOFD_SEG_ACT_DEFER, +}; + +struct iofd_msghdr *iofd_msghdr_alloc(struct osmo_io_fd *iofd, enum iofd_msg_action action, struct msgb *msg); +void iofd_msghdr_free(struct iofd_msghdr *msghdr); + +struct msgb *iofd_msgb_alloc(struct osmo_io_fd *iofd); +struct msgb *iofd_msgb_pending(struct osmo_io_fd *iofd); +struct msgb *iofd_msgb_pending_or_alloc(struct osmo_io_fd *iofd); + +enum iofd_seg_act iofd_handle_segmentation(struct osmo_io_fd *iofd, struct msgb *msg); +void iofd_handle_segmented_read(struct osmo_io_fd *iofd, struct msgb *msg, int rc); + +int iofd_txqueue_enqueue(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr); +void iofd_txqueue_enqueue_front(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr); +struct iofd_msghdr *iofd_txqueue_dequeue(struct osmo_io_fd *iofd); + +/* poll backend */ +int iofd_poll_ofd_cb_dispatch(struct osmo_fd *ofd, unsigned int what); diff --git a/src/osmo_io_poll.c b/src/osmo_io_poll.c new file mode 100644 index 0000000..448ffe0 --- /dev/null +++ b/src/osmo_io_poll.c @@ -0,0 +1,219 @@ +/*! \file osmo_io_poll.c + * New osmocom async I/O API. + * + * (C) 2022 by Harald Welte <laforge(a)osmocom.org> + * (C) 2022 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * Author: Daniel Willmann <dwillmann(a)sysmocom.de> + * + * All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + */ + +#include <stdio.h> +#include <talloc.h> +#include <unistd.h> +#include <stdbool.h> +#include <errno.h> + +#include <osmocom/core/osmo_io.h> +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/logging.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/select.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/utils.h> + +#include "../config.h" +#include "osmo_io_internal.h" + +static void iofd_poll_ofd_cb_read_write(struct osmo_fd *ofd, unsigned int what) +{ + struct osmo_io_fd *iofd = ofd->data; + struct iofd_msghdr *msghdr; + struct msgb *msg; + int rc; + + OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_READ_WRITE); + + if (what & OSMO_FD_READ) { + msg = iofd_msgb_pending_or_alloc(iofd); + if (!msg) { + LOGP(DLIO, LOGL_ERROR, "iofd(%s): Could not get msgb for reading\n", iofd->name); + OSMO_ASSERT(0); + } + + rc = read(ofd->fd, msg->tail, msgb_tailroom(msg)); + if (rc > 0) + msgb_put(msg, rc); + + iofd_handle_segmented_read(iofd, msg, rc); + } + + if (iofd->closing) { + return; + } + + if (what & OSMO_FD_WRITE) { + msghdr = iofd_txqueue_dequeue(iofd); + if (msghdr) { + msg = msghdr->msg; + rc = write(ofd->fd, msgb_data(msg), msgb_length(msg)); + if (rc < msgb_length(msg)) { + msgb_pull(msg, rc); + iofd_txqueue_enqueue_front(iofd, msghdr); + return; + } + iofd->io_ops.write_cb(iofd, rc, msg); + msgb_free(msg); + } else { + osmo_fd_write_disable(ofd); + } + } + + /* TODO: FD_EXCEPT handling? However: Rarely used in existing osmo-* */ + return; +} + +static void iofd_poll_ofd_cb_recvfrom_sendto(struct osmo_fd *ofd, unsigned int what) +{ + struct osmo_io_fd *iofd = ofd->data; + struct msgb *msg; + struct iofd_msghdr *msghdr; + int rc; + + OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_RECVFROM_SENDTO); + + if (what & OSMO_FD_READ) { + msg = iofd_msgb_pending_or_alloc(iofd); + if (!msg) { + LOGP(DLIO, LOGL_ERROR, "iofd(%s): Could not get msgb for reading\n", iofd->name); + OSMO_ASSERT(0); + } + struct osmo_sockaddr saddr; + struct sockaddr *sa = &saddr.u.sa; + socklen_t addrlen = sizeof(struct sockaddr); + + rc = recvfrom(ofd->fd, msgb_data(msg), msgb_tailroom(msg), 0, + sa, &addrlen); + if (rc > 0) + msgb_put(msg, rc); + + iofd_handle_segmentation(iofd, msg); + + iofd->io_ops.recvmsg_cb(iofd, rc, msg, &saddr); + + } + + if (iofd->closing) { + return; + } + + if (what & OSMO_FD_WRITE) { + msghdr = (struct iofd_msghdr *)msgb_dequeue_count(&iofd->tx_queue.msg_queue, &iofd->tx_queue.current_length); + if (msghdr) { + struct osmo_sockaddr *dest = &msghdr->sa; + msg = msghdr->msg; + + rc = sendto(ofd->fd, msgb_data(msg), msgb_length(msg), 0, + &dest->u.sa, sizeof(*dest)); + if (rc < msgb_length(msg)) { + msgb_pull(msg, rc); + iofd_txqueue_enqueue_front(iofd, msghdr); + return; + } + iofd->io_ops.sendmsg_cb(iofd, rc, msg); + + talloc_free(msghdr); + msgb_free(msg); + } else { + osmo_fd_write_disable(ofd); + } + } + + /* TODO: FD_EXCEPT handling? However: Rarely used in existing osmo-* */ + return; +} + +int iofd_poll_ofd_cb_dispatch(struct osmo_fd *ofd, unsigned int what) +{ + struct osmo_io_fd *iofd = ofd->data; + + iofd->in_callback = true; + + switch (iofd->mode) { + case OSMO_IO_FD_MODE_READ_WRITE: + iofd_poll_ofd_cb_read_write(ofd, what); + break; + case OSMO_IO_FD_MODE_RECVFROM_SENDTO: + iofd_poll_ofd_cb_recvfrom_sendto(ofd, what); + break; + default: + OSMO_ASSERT(0); + } + + iofd->in_callback = false; + + if (iofd->closing) { + talloc_free(iofd); + return 0; + } + + return 0; +} + +int iofd_poll_setup(struct osmo_io_fd *iofd) +{ + struct osmo_fd *ofd = &iofd->u.poll.ofd; + osmo_fd_setup(ofd, iofd->fd, 0, &iofd_poll_ofd_cb_dispatch, iofd, 0); + return osmo_fd_register(ofd); +} + +int iofd_poll_close(struct osmo_io_fd *iofd) +{ + osmo_fd_close(&iofd->u.poll.ofd); + + if (iofd->in_callback) + return 0; + else + return 1; +} + +void iofd_poll_read_enable(struct osmo_io_fd *iofd) +{ + osmo_fd_read_enable(&iofd->u.poll.ofd); +} + +void iofd_poll_read_disable(struct osmo_io_fd *iofd) +{ + osmo_fd_read_disable(&iofd->u.poll.ofd); +} + +void iofd_poll_write_enable(struct osmo_io_fd *iofd) +{ + osmo_fd_write_enable(&iofd->u.poll.ofd); +} + +void iofd_poll_write_disable(struct osmo_io_fd *iofd) +{ + osmo_fd_write_disable(&iofd->u.poll.ofd); +} + +struct iofd_backend_ops iofd_poll_ops = { + .setup = iofd_poll_setup, + .close = iofd_poll_close, + .write_enable = iofd_poll_write_enable, + .write_disable = iofd_poll_write_disable, + .read_enable = iofd_poll_read_enable, + .read_disable = iofd_poll_read_disable, +}; \ No newline at end of file -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30934 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I50d73cf550d6ce8154bf827bf47408131cf5b0a0 Gerrit-Change-Number: 30934 Gerrit-PatchSet: 1 Gerrit-Owner: daniel <dwillmann(a)sysmocom.de> Gerrit-CC: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
Change in libosmocore[master]: gsm_08_58: add IEI to signal HR GSM RTP format via RSL
by dexter 11 Jan '23

11 Jan '23
Attention is currently required from: pespin. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/30724 ) Change subject: gsm_08_58: add IEI to signal HR GSM RTP format via RSL ...................................................................... Patch Set 2: (1 comment) Patchset: PS1: > BLocking until detailed explanation is provided on why is this needed. I have extended the commit message. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30724 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I843c8a0cbe5898311f3af3294cec7c8bc96c4eb8 Gerrit-Change-Number: 30724 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: msuraev <msuraev(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Wed, 11 Jan 2023 15:44:44 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: comment
1 0
0 0
Change in libosmocore[master]: gsm_08_58: add IEI to signal HR GSM RTP format via RSL
by dexter 11 Jan '23

11 Jan '23
Attention is currently required from: pespin. Hello Jenkins Builder, pespin, msuraev, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/30724 to look at the new patch set (#2). Change subject: gsm_08_58: add IEI to signal HR GSM RTP format via RSL ...................................................................... gsm_08_58: add IEI to signal HR GSM RTP format via RSL The configuration which RTP format is used is done at the BSC side. This IE is required to signal to the BTS which of the two HR GSM RTP formats (RFC5993 or TS 101.318) the BTS should use for sending RTP packets. (In the receiving direction the BTS automatically detects the RTP format, so the IE will have no effect on that part). Change-Id: I843c8a0cbe5898311f3af3294cec7c8bc96c4eb8 Related: OS#5688 --- M include/osmocom/gsm/protocol/gsm_08_58.h M src/gsm/rsl.c 2 files changed, 2 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/24/30724/2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30724 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I843c8a0cbe5898311f3af3294cec7c8bc96c4eb8 Gerrit-Change-Number: 30724 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: msuraev <msuraev(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newpatchset
1 0
0 0
Change in libosmocore[master]: ctrl: error if program forgot to initialize the ctr handler before in...
by pespin 11 Jan '23

11 Jan '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/30877 ) Change subject: ctrl: error if program forgot to initialize the ctr handler before installing cmds ...................................................................... ctrl: error if program forgot to initialize the ctr handler before installing cmds Change-Id: Icf3873f33470499fed3150ff51922a36aa0f023e --- M src/ctrl/control_cmd.c 1 file changed, 10 insertions(+), 0 deletions(-) Approvals: daniel: Looks good to me, approved fixeria: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c index b069ca4..dec19b9 100644 --- a/src/ctrl/control_cmd.c +++ b/src/ctrl/control_cmd.c @@ -210,6 +210,16 @@ { vector cmds_vec; + /* If this assert triggers, it means the program forgot to initialize + * the CTRL interface first by calling ctrl_handle_alloc(2)() directly + * or indirectly through ctrl_interface_setup_dynip(2)() + */ + if (!ctrl_node_vec) { + LOGP(DLCTRL, LOGL_ERROR, + "ctrl_handle must be initialized prior to installing cmds.\n"); + return -ENODEV; + } + cmds_vec = vector_lookup_ensure(ctrl_node_vec, node); if (!cmds_vec) { -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30877 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Icf3873f33470499fed3150ff51922a36aa0f023e Gerrit-Change-Number: 30877 Gerrit-PatchSet: 4 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmocore[master]: uitils: add floored and euclidian modulo functions
by pespin 11 Jan '23

11 Jan '23
Attention is currently required from: neels, laforge, dexter. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/30933 ) Change subject: uitils: add floored and euclidian modulo functions ...................................................................... Patch Set 6: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30933 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: If61cd54f43643325c45f64531c57fe4c5802a9cf Gerrit-Change-Number: 30933 Gerrit-PatchSet: 6 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Wed, 11 Jan 2023 15:33:30 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in libosmocore[master]: ctrl: error if program forgot to initialize the ctr handler before in...
by daniel 11 Jan '23

11 Jan '23
Attention is currently required from: neels, pespin. daniel has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/30877 ) Change subject: ctrl: error if program forgot to initialize the ctr handler before installing cmds ...................................................................... Patch Set 3: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30877 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Icf3873f33470499fed3150ff51922a36aa0f023e Gerrit-Change-Number: 30877 Gerrit-PatchSet: 3 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Wed, 11 Jan 2023 15:32:29 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in libosmocore[master]: uitils: add floored and euclidian modulo functions
by dexter 11 Jan '23

11 Jan '23
Attention is currently required from: neels, laforge. Hello Jenkins Builder, laforge, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/30933 to look at the new patch set (#6). Change subject: uitils: add floored and euclidian modulo functions ...................................................................... uitils: add floored and euclidian modulo functions C/C++ only implements a so called "truncated modulo" function. Lets also add a floored and an euclidian modulo function to be more complete. The functions will be used to generalize the following Change: I5fb2b0ada8d409730ac22963741fb4ab0026abdd Change-Id: If61cd54f43643325c45f64531c57fe4c5802a9cf --- M include/osmocom/core/utils.h M tests/utils/utils_test.c M tests/utils/utils_test.ok 3 files changed, 102 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/33/30933/6 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30933 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: If61cd54f43643325c45f64531c57fe4c5802a9cf Gerrit-Change-Number: 30933 Gerrit-PatchSet: 6 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newpatchset
1 0
0 0
Change in libosmocore[master]: uitils: add floored and euclidian modulo functions
by dexter 11 Jan '23

11 Jan '23
Attention is currently required from: neels, laforge. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/30933 ) Change subject: uitils: add floored and euclidian modulo functions ...................................................................... Patch Set 6: (1 comment) Commit Message: https://gerrit.osmocom.org/c/libosmocore/+/30933/comment/222813a6_663f9aa5 PS4, Line 10: add a floored and an euclidian modulo function to be more complete. > please name the place where / the reason why you would like to use these ideally with change-id refe […] Done -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/30933 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: If61cd54f43643325c45f64531c57fe4c5802a9cf Gerrit-Change-Number: 30933 Gerrit-PatchSet: 6 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Comment-Date: Wed, 11 Jan 2023 15:31:05 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: comment
1 0
0 0
Change in osmocom-bb[master]: layer23/sysinfo: implement decoding of SI13 Rest Octets
by pespin 11 Jan '23

11 Jan '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30812 ) Change subject: layer23/sysinfo: implement decoding of SI13 Rest Octets ...................................................................... layer23/sysinfo: implement decoding of SI13 Rest Octets Change-Id: Ia6ff7d4e37816c6321b54c1f7f8d7110e557f8c5 Related: SYS#5500 --- M src/host/layer23/include/osmocom/bb/common/sysinfo.h M src/host/layer23/src/common/sysinfo.c M src/host/layer23/src/mobile/gsm48_rr.c 3 files changed, 171 insertions(+), 12 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved diff --git a/src/host/layer23/include/osmocom/bb/common/sysinfo.h b/src/host/layer23/include/osmocom/bb/common/sysinfo.h index 6a915d0..75cbcd9 100644 --- a/src/host/layer23/include/osmocom/bb/common/sysinfo.h +++ b/src/host/layer23/include/osmocom/bb/common/sysinfo.h @@ -21,7 +21,8 @@ struct gsm48_sysinfo { /* flags of available information */ uint8_t si1, si2, si2bis, si2ter, si3, - si4, si5, si5bis, si5ter, si6; + si4, si5, si5bis, si5ter, si6, + si13; /* memory maps to simply detect change in system info messages */ uint8_t si1_msg[23]; @@ -34,6 +35,7 @@ uint8_t si5b_msg[18]; uint8_t si5t_msg[18]; uint8_t si6_msg[18]; + uint8_t si13_msg[23]; struct gsm_sysinfo_freq freq[1024]; /* all frequencies */ uint16_t hopping[64]; /* hopping arfcn */ @@ -66,9 +68,46 @@ uint8_t ecsm; uint8_t sched; uint8_t sched_where; - uint8_t gprs; - uint8_t gprs_ra_colour; - uint8_t gprs_si13_pos; + + struct { + /* si3/si4 rest */ + uint8_t supported; + uint8_t ra_colour; + uint8_t si13_pos; + + /* si13 rest */ + uint8_t hopping; + uint8_t hsn; + uint8_t rfl_num_len; + uint8_t rfl_num[4]; + + uint8_t ma_bitlen; + uint8_t ma_bitmap[64 / 8]; + uint8_t arfcn_idx_len; + uint8_t arfcn_idx[16]; + + /* PBCCH is not present */ + uint8_t rac; + uint8_t prio_acc_thresh; + uint8_t nco; + + /* GPRS Cell Options */ + uint8_t nmo; + uint8_t T3168; + uint8_t T3192; + uint8_t ab_type; + uint8_t ctrl_ack_type_use_block; + uint8_t bs_cv_max; + uint8_t pan_params_present; + uint8_t pan_dec; + uint8_t pan_inc; + uint8_t pan_max; + + /* EGPRS Cell Options */ + uint8_t egprs_supported; + uint8_t egprs_pkt_chan_req; + uint8_t egprs_bep_period; + } gprs; /* cell selection */ int8_t ms_txpwr_max_cch; @@ -151,6 +190,8 @@ const struct gsm48_system_information_type_5ter *si, int len); int gsm48_decode_sysinfo6(struct gsm48_sysinfo *s, const struct gsm48_system_information_type_6 *si, int len); +int gsm48_decode_sysinfo13(struct gsm48_sysinfo *s, + const struct gsm48_system_information_type_13 *si, int len); int gsm48_decode_mobile_alloc(struct gsm_sysinfo_freq *freq, const uint8_t *ma, uint8_t len, uint16_t *hopping, uint8_t *hopp_len, int si4); diff --git a/src/host/layer23/src/common/sysinfo.c b/src/host/layer23/src/common/sysinfo.c index c6fc413..0201c7c 100644 --- a/src/host/layer23/src/common/sysinfo.c +++ b/src/host/layer23/src/common/sysinfo.c @@ -23,6 +23,8 @@ #include <osmocom/core/utils.h> #include <osmocom/core/bitvec.h> +#include <osmocom/gprs/rlcmac/gprs_rlcmac.h> + #include <osmocom/bb/common/osmocom_data.h> #include <osmocom/bb/common/networks.h> #include <osmocom/bb/common/logging.h> @@ -536,11 +538,11 @@ s->sched = 0; /* GPRS Indicator */ if (bitvec_get_bit_high(&bv) == H) { - s->gprs = 1; - s->gprs_ra_colour = bitvec_get_uint(&bv, 3); - s->gprs_si13_pos = bitvec_get_uint(&bv, 1); + s->gprs.supported = 1; + s->gprs.ra_colour = bitvec_get_uint(&bv, 3); + s->gprs.si13_pos = bitvec_get_uint(&bv, 1); } else - s->gprs = 0; + s->gprs.supported = 0; return 0; } @@ -571,11 +573,11 @@ s->po = 0; /* GPRS Indicator */ if (bitvec_get_bit_high(&bv) == H) { - s->gprs = 1; - s->gprs_ra_colour = bitvec_get_uint(&bv, 3); - s->gprs_si13_pos = bitvec_get_uint(&bv, 1); + s->gprs.supported = 1; + s->gprs.ra_colour = bitvec_get_uint(&bv, 3); + s->gprs.si13_pos = bitvec_get_uint(&bv, 1); } else - s->gprs = 0; + s->gprs.supported = 0; // todo: more rest octet bits return 0; @@ -840,6 +842,88 @@ return 0; } +int gsm48_decode_sysinfo13(struct gsm48_sysinfo *s, + const struct gsm48_system_information_type_13 *si, int len) +{ + SI13_RestOctets_t si13ro; + int rc; + + memcpy(s->si13_msg, si, OSMO_MIN(len, sizeof(s->si13_msg))); + + rc = osmo_gprs_rlcmac_decode_si13ro(&si13ro, si->rest_octets, sizeof(s->si13_msg)); + if (rc != 0) { + LOGP(DRR, LOGL_ERROR, "Failed to parse SI13 Rest Octets\n"); + return rc; + } + + if (si13ro.UnionType != 0) { + LOGP(DRR, LOGL_NOTICE, "PBCCH is deprecated and not supported\n"); + return -ENOTSUP; + } + + s->gprs.hopping = si13ro.Exist_MA; + if (s->gprs.hopping) { + const GPRS_Mobile_Allocation_t *gma = &si13ro.GPRS_Mobile_Allocation; + + s->gprs.hsn = gma->HSN; + s->gprs.rfl_num_len = gma->ElementsOf_RFL_NUMBER; + memcpy(&s->gprs.rfl_num[0], &gma->RFL_NUMBER[0], sizeof(gma->RFL_NUMBER)); + + if (gma->UnionType == 0) { /* MA Bitmap */ + const MobileAllocation_t *ma = &gma->u.MA; + s->gprs.ma_bitlen = ma->MA_BitLength; + memcpy(&s->gprs.ma_bitmap[0], &ma->MA_BITMAP[0], sizeof(ma->MA_BITMAP)); + } else { /* ARFCN Index List */ + const ARFCN_index_list_t *ai = &gma->u.ARFCN_index_list; + s->gprs.arfcn_idx_len = ai->ElementsOf_ARFCN_INDEX; + memcpy(&s->gprs.arfcn_idx[0], &ai->ARFCN_INDEX[0], sizeof(ai->ARFCN_INDEX)); + } + } + + const PBCCH_Not_present_t *np = &si13ro.u.PBCCH_Not_present; + + s->gprs.rac = np->RAC; + s->gprs.prio_acc_thresh = np->PRIORITY_ACCESS_THR; + s->gprs.nco = np->NETWORK_CONTROL_ORDER; + + const GPRS_Cell_Options_t *gco = &np->GPRS_Cell_Options; + + s->gprs.nmo = gco->NMO; + s->gprs.T3168 = gco->T3168; + s->gprs.T3192 = gco->T3192; + s->gprs.ab_type = gco->ACCESS_BURST_TYPE; + s->gprs.ctrl_ack_type_use_block = !gco->CONTROL_ACK_TYPE; /* inverted */ + s->gprs.bs_cv_max = gco->BS_CV_MAX; + + s->gprs.pan_params_present = gco->Exist_PAN; + if (s->gprs.pan_params_present) { + s->gprs.pan_dec = gco->PAN_DEC; + s->gprs.pan_dec = gco->PAN_INC; + s->gprs.pan_dec = gco->PAN_MAX; + } + + s->gprs.egprs_supported = 0; + if (gco->Exist_Extension_Bits) { + /* CSN.1 codec is not powerful enough (yet?) to decode this part :( */ + unsigned int ext_len = gco->Extension_Bits.extension_length; + const uint8_t *ext = &gco->Extension_Bits.Extension_Info[0]; + + s->gprs.egprs_supported = (ext[0] >> 7); + if (s->gprs.egprs_supported) { + if (ext_len < 6) + return -EINVAL; + s->gprs.egprs_pkt_chan_req = ~ext[0] & (1 << 6); /* inverted */ + s->gprs.egprs_bep_period = (ext[0] >> 2) & 0x0f; + } + } + + /* TODO: GPRS_Power_Control_Parameters */ + + s->si13 = 1; + + return 0; +} + int gsm48_encode_lai_hex(struct gsm48_loc_area_id *lai, uint16_t mcc, uint16_t mnc, uint16_t lac) { diff --git a/src/host/layer23/src/mobile/gsm48_rr.c b/src/host/layer23/src/mobile/gsm48_rr.c index 8a920ee..deb76c9 100644 --- a/src/host/layer23/src/mobile/gsm48_rr.c +++ b/src/host/layer23/src/mobile/gsm48_rr.c @@ -2086,6 +2086,38 @@ return gsm48_new_sysinfo(ms, si->system_information); } +/* receive "SYSTEM INFORMATION 13" message (9.1.43a) */ +static int gsm48_rr_rx_sysinfo13(struct osmocom_ms *ms, struct msgb *msg) +{ + const struct gsm48_system_information_type_13 *si = msgb_l3(msg); + int rest_octets_len = msgb_l3len(msg) - sizeof(si->header); + struct gsm48_sysinfo *s = ms->cellsel.si; + + if (!s) { + LOGP(DRR, LOGL_INFO, + "No cell selected, SYSTEM INFORMATION 13 ignored\n"); + return -EINVAL; + } + + if (rest_octets_len < 0) { + LOGP(DRR, LOGL_NOTICE, + "Short read of SYSTEM INFORMATION 13 message.\n"); + return -EINVAL; + } + + if (!memcmp(si, s->si13_msg, MIN(msgb_l3len(msg), sizeof(s->si6_msg)))) + return 0; + + gsm48_decode_sysinfo13(s, si, msgb_l3len(msg)); + + LOGP(DRR, LOGL_INFO, + "New SYSTEM INFORMATION 13 (%s, RAC 0x%02x, NCO %u, MNO %u)\n", + s->gprs.egprs_supported ? "EGPRS" : "GPRS only", + s->gprs.rac, s->gprs.nco, s->gprs.nmo); + + return gsm48_new_sysinfo(ms, si->header.system_information); +} + /* * paging */ @@ -4820,6 +4852,8 @@ return gsm48_rr_rx_sysinfo3(ms, msg); case GSM48_MT_RR_SYSINFO_4: return gsm48_rr_rx_sysinfo4(ms, msg); + case GSM48_MT_RR_SYSINFO_13: + return gsm48_rr_rx_sysinfo13(ms, msg); default: #if 0 LOGP(DRR, LOGL_NOTICE, "BCCH message type 0x%02x not sup.\n", -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30812 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: Ia6ff7d4e37816c6321b54c1f7f8d7110e557f8c5 Gerrit-Change-Number: 30812 Gerrit-PatchSet: 10 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in osmocom-bb[master]: modem: passive decoding of SI{3,4,13} and IA Rest Octets
by pespin 11 Jan '23

11 Jan '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30870 ) Change subject: modem: passive decoding of SI{3,4,13} and IA Rest Octets ...................................................................... modem: passive decoding of SI{3,4,13} and IA Rest Octets Use the existing application skeleton from '$(top_srcdir)/src/common/'. Use the LAPDm glue from '$(top_srcdir)/src/misc/rslms.c'. This is what the misc applications like ccch_scan are using. Change-Id: I8566a3cdc9f818bed7e28ea4b1957dce735c298b Related: SYS#5500 --- M src/host/layer23/src/modem/Makefile.am A src/host/layer23/src/modem/app_modem.c D src/host/layer23/src/modem/modem_main.c 3 files changed, 330 insertions(+), 170 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved diff --git a/src/host/layer23/src/modem/Makefile.am b/src/host/layer23/src/modem/Makefile.am index 4fb3c11..522456a 100644 --- a/src/host/layer23/src/modem/Makefile.am +++ b/src/host/layer23/src/modem/Makefile.am @@ -13,7 +13,11 @@ bin_PROGRAMS = modem -modem_SOURCES = modem_main.c +modem_SOURCES = \ + $(top_srcdir)/src/common/main.c \ + $(top_srcdir)/src/misc/rslms.c \ + app_modem.c \ + $(NULL) modem_LDADD = \ $(top_builddir)/src/common/liblayer23.a \ $(LIBOSMOCORE_LIBS) \ diff --git a/src/host/layer23/src/modem/app_modem.c b/src/host/layer23/src/modem/app_modem.c new file mode 100644 index 0000000..48c216d --- /dev/null +++ b/src/host/layer23/src/modem/app_modem.c @@ -0,0 +1,325 @@ +/* modem app (gprs) */ + +/* (C) 2022 by sysmocom - s.m.f.c. GmbH <info(a)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 <stdbool.h> +#include <stdint.h> +#include <errno.h> +#include <stdio.h> + +#include <osmocom/core/msgb.h> +#include <osmocom/core/signal.h> +#include <osmocom/core/application.h> + +#include <osmocom/gsm/rsl.h> +#include <osmocom/gsm/tlv.h> +#include <osmocom/gsm/gsm48_ie.h> +#include <osmocom/gsm/gsm48.h> +#include <osmocom/gsm/protocol/gsm_04_08.h> +#include <osmocom/gprs/rlcmac/gprs_rlcmac.h> + +#include <osmocom/bb/common/osmocom_data.h> +#include <osmocom/bb/common/logging.h> +#include <osmocom/bb/common/l1ctl.h> +#include <osmocom/bb/common/l23_app.h> +#include <osmocom/bb/common/sysinfo.h> +#include <osmocom/bb/misc/rslms.h> +#include <osmocom/bb/misc/layer3.h> + +#include <l1ctl_proto.h> + +static struct { + enum ccch_mode ccch_mode; + struct gsm48_sysinfo si; +} app_data; + +static int handle_si1(struct osmocom_ms *ms, struct msgb *msg) +{ + int rc; + + if (msgb_l3len(msg) != GSM_MACBLOCK_LEN) + return -EINVAL; + if (!memcmp(&app_data.si.si1_msg[0], msgb_l3(msg), msgb_l3len(msg))) + return 0; /* this message is already handled */ + + rc = gsm48_decode_sysinfo1(&app_data.si, msgb_l3(msg), msgb_l3len(msg)); + if (rc != 0) { + LOGP(DRR, LOGL_ERROR, "Failed to decode SI1 message\n"); + return rc; + } + + return 0; +} + +static int handle_si3(struct osmocom_ms *ms, struct msgb *msg) +{ + int rc; + + if (msgb_l3len(msg) != GSM_MACBLOCK_LEN) + return -EINVAL; + if (!memcmp(&app_data.si.si3_msg[0], msgb_l3(msg), msgb_l3len(msg))) + return 0; /* this message is already handled */ + + rc = gsm48_decode_sysinfo3(&app_data.si, msgb_l3(msg), msgb_l3len(msg)); + if (rc != 0) { + LOGP(DRR, LOGL_ERROR, "Failed to decode SI3 message\n"); + return rc; + } + + if (app_data.ccch_mode == CCCH_MODE_NONE) { + if (app_data.si.ccch_conf == RSL_BCCH_CCCH_CONF_1_C) + app_data.ccch_mode = CCCH_MODE_COMBINED; + else + app_data.ccch_mode = CCCH_MODE_NON_COMBINED; + l1ctl_tx_ccch_mode_req(ms, app_data.ccch_mode); + } + + if (!app_data.si.gprs.supported) { + LOGP(DRR, LOGL_NOTICE, "SI3 Rest Octets IE contains no GPRS Indicator\n"); + return 0; + } + + LOGP(DRR, LOGL_NOTICE, "Found GPRS Indicator (RA Colour %u, SI13 on BCCH %s)\n", + app_data.si.gprs.ra_colour, app_data.si.gprs.si13_pos ? "Ext" : "Norm"); + + return 0; +} + +static int handle_si4(struct osmocom_ms *ms, struct msgb *msg) +{ + int rc; + + if (msgb_l3len(msg) != GSM_MACBLOCK_LEN) + return -EINVAL; + if (!memcmp(&app_data.si.si4_msg[0], msgb_l3(msg), msgb_l3len(msg))) + return 0; /* this message is already handled */ + + rc = gsm48_decode_sysinfo4(&app_data.si, msgb_l3(msg), msgb_l3len(msg)); + if (rc != 0) { + LOGP(DRR, LOGL_ERROR, "Failed to decode SI4 message\n"); + return rc; + } + + if (!app_data.si.gprs.supported) { + LOGP(DRR, LOGL_NOTICE, "SI4 Rest Octets IE contains no GPRS Indicator\n"); + return 0; + } + + LOGP(DRR, LOGL_NOTICE, "Found GPRS Indicator (RA Colour %u, SI13 on BCCH %s)\n", + app_data.si.gprs.ra_colour, app_data.si.gprs.si13_pos ? "Ext" : "Norm"); + + return 0; +} + +static int handle_si13(struct osmocom_ms *ms, struct msgb *msg) +{ + int rc; + + if (msgb_l3len(msg) != GSM_MACBLOCK_LEN) + return -EINVAL; + if (!memcmp(&app_data.si.si13_msg[0], msgb_l3(msg), msgb_l3len(msg))) + return 0; /* this message is already handled */ + + rc = gsm48_decode_sysinfo13(&app_data.si, msgb_l3(msg), msgb_l3len(msg)); + if (rc != 0) + return rc; + + return 0; +} + +int gsm48_rx_bcch(struct msgb *msg, struct osmocom_ms *ms) +{ + const struct gsm48_system_information_type_header *si_hdr = msgb_l3(msg); + const uint8_t si_type = si_hdr->system_information; + + LOGP(DRR, LOGL_INFO, "BCCH message (type=0x%02x): %s\n", + si_type, gsm48_rr_msg_name(si_type)); + + switch (si_type) { + case GSM48_MT_RR_SYSINFO_1: + return handle_si1(ms, msg); + case GSM48_MT_RR_SYSINFO_3: + return handle_si3(ms, msg); + case GSM48_MT_RR_SYSINFO_4: + return handle_si4(ms, msg); + case GSM48_MT_RR_SYSINFO_13: + return handle_si13(ms, msg); + default: + return 0; + }; +} + +static int gsm48_rx_imm_ass(struct msgb *msg, struct osmocom_ms *ms) +{ + const struct gsm48_imm_ass *ia = msgb_l3(msg); + uint8_t ch_type, ch_subch, ch_ts; + int rc; + + /* Discard CS channel assignment */ + if ((ia->page_mode >> 4) == 0) + return 0; + + if (rsl_dec_chan_nr(ia->chan_desc.chan_nr, &ch_type, &ch_subch, &ch_ts) != 0) { + LOGP(DRR, LOGL_ERROR, + "%s(): rsl_dec_chan_nr(chan_nr=0x%02x) failed\n", + __func__, ia->chan_desc.chan_nr); + return -EINVAL; + } + + if (!ia->chan_desc.h0.h) { + /* Non-hopping */ + uint16_t arfcn; + + arfcn = ia->chan_desc.h0.arfcn_low | (ia->chan_desc.h0.arfcn_high << 8); + + LOGP(DRR, LOGL_INFO, "GSM48 IMM ASS (ra=0x%02x, chan_nr=0x%02x, " + "ARFCN=%u, TS=%u, SS=%u, TSC=%u)\n", ia->req_ref.ra, + ia->chan_desc.chan_nr, arfcn, ch_ts, ch_subch, + ia->chan_desc.h0.tsc); + } else { + /* Hopping */ + uint8_t maio, hsn; + + hsn = ia->chan_desc.h1.hsn; + maio = ia->chan_desc.h1.maio_low | (ia->chan_desc.h1.maio_high << 2); + + LOGP(DRR, LOGL_INFO, "GSM48 IMM ASS (ra=0x%02x, chan_nr=0x%02x, " + "HSN=%u, MAIO=%u, TS=%u, SS=%u, TSC=%u)\n", ia->req_ref.ra, + ia->chan_desc.chan_nr, hsn, maio, ch_ts, ch_subch, + ia->chan_desc.h1.tsc); + } + + const uint8_t *data = msgb_l3(msg) + sizeof(*ia) + ia->mob_alloc_len; + size_t data_len = msgb_l3len(msg) - (sizeof(*ia) + ia->mob_alloc_len); + IA_RestOctets_t iaro; + + rc = osmo_gprs_rlcmac_decode_imm_ass_ro(&iaro, data, data_len); + if (rc != 0) { + LOGP(DRR, LOGL_ERROR, "Failed to decode IA Rest Octets IE\n"); + return rc; + } + + return 0; +} + +/* Dummy Paging Request 1 with "no identity" */ +static const uint8_t paging_fill[] = { + 0x15, 0x06, 0x21, 0x00, 0x01, 0xf0, 0x2b, + /* The rest part may be randomized */ +}; + +/* LAPDm func=UI fill frame (for the BTS side) */ +static const uint8_t lapdm_fill[] = { + 0x03, 0x03, 0x01, 0x2b, + /* The rest part may be randomized */ +}; + +/* TODO: share / generalize this code */ +static bool is_fill_frame(const struct msgb *msg) +{ + const uint8_t *l2 = msgb_l3(msg); + + if (!memcmp(l2, paging_fill, sizeof(paging_fill))) + return true; + if (!memcmp(l2, lapdm_fill, sizeof(lapdm_fill))) + return true; + + return false; +} + +int gsm48_rx_ccch(struct msgb *msg, struct osmocom_ms *ms) +{ + const struct gsm48_system_information_type_header *sih = msgb_l3(msg); + + /* Skip frames with wrong length */ + if (msgb_l3len(msg) != GSM_MACBLOCK_LEN) { + LOGP(DRR, LOGL_ERROR, "Rx CCCH message with odd length=%u: %s\n", + msgb_l3len(msg), msgb_hexdump_l3(msg)); + return -EINVAL; + } + + /* Skip dummy (fill) frames */ + if (is_fill_frame(msg)) + return 0; + + if (sih->rr_protocol_discriminator != GSM48_PDISC_RR) { + LOGP(DRR, LOGL_ERROR, "PCH pdisc (%s) != RR\n", + gsm48_pdisc_name(sih->rr_protocol_discriminator)); + } + + switch (sih->system_information) { + case GSM48_MT_RR_IMM_ASS: + return gsm48_rx_imm_ass(msg, ms); + default: + return 0; + } +} + +void layer3_app_reset(void) +{ + memset(&app_data, 0x00, sizeof(app_data)); +} + +static int signal_cb(unsigned int subsys, unsigned int signal, + void *handler_data, void *signal_data) +{ + struct osmocom_ms *ms; + + if (subsys != SS_L1CTL) + return 0; + + switch (signal) { + case S_L1CTL_RESET: + ms = signal_data; + layer3_app_reset(); + return l1ctl_tx_fbsb_req(ms, ms->test_arfcn, + L1CTL_FBSB_F_FB01SB, 100, 0, + CCCH_MODE_NONE, dbm2rxlev(-85)); + } + + return 0; +} + + +int l23_app_init(struct osmocom_ms *ms) +{ + log_set_category_filter(osmo_stderr_target, DLGLOBAL, 1, LOGL_DEBUG); + log_set_category_filter(osmo_stderr_target, DLCSN1, 1, LOGL_DEBUG); + log_set_category_filter(osmo_stderr_target, DRR, 1, LOGL_INFO); + + osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL); + l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL); + + return layer3_init(ms); +} + +static int l23_cfg_supported(void) +{ + return L23_OPT_ARFCN | L23_OPT_TAP | L23_OPT_DBG; +} + +static struct l23_app_info info = { + .copyright = "Copyright (C) 2022 by sysmocom - s.m.f.c. GmbH <info(a)sysmocom.de>\n", + .cfg_supported = &l23_cfg_supported, +}; + +struct l23_app_info *l23_app_info(void) +{ + return &info; +} diff --git a/src/host/layer23/src/modem/modem_main.c b/src/host/layer23/src/modem/modem_main.c deleted file mode 100644 index 438c1fe..0000000 --- a/src/host/layer23/src/modem/modem_main.c +++ /dev/null @@ -1,169 +0,0 @@ -/* modem app (gprs) */ - -/* (C) 2022 by sysmocom - s.m.f.c. GmbH <info(a)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 <osmocom/bb/common/osmocom_data.h> -#include <osmocom/bb/common/logging.h> -#include <osmocom/bb/modem/modem.h> - -#include <osmocom/core/talloc.h> -#include <osmocom/core/linuxlist.h> -#include <osmocom/core/signal.h> -#include <osmocom/core/application.h> - -#include <arpa/inet.h> - -#define _GNU_SOURCE -#include <getopt.h> - -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <unistd.h> - -void *tall_modem_ctx = NULL; -int daemonize = 0; - -static void print_usage(const char *app) -{ - printf("Usage: %s\n", app); -} - -static void print_help(void) -{ - printf(" Some help...\n"); - printf(" -h --help this text\n"); - printf(" -d --debug Change debug flags.\n"); - printf(" -D --daemonize Run as daemon\n"); -} - -static int handle_options(int argc, char **argv) -{ - while (1) { - int option_index = 0, c; - static struct option long_options[] = { - {"help", 0, 0, 'h'}, - {"debug", 1, 0, 'd'}, - {"daemonize", 0, 0, 'D'}, - {0, 0, 0, 0}, - }; - - c = getopt_long(argc, argv, "hi:u:c:v:d:Dm", - long_options, &option_index); - if (c == -1) - break; - - switch (c) { - case 'h': - print_usage(argv[0]); - print_help(); - exit(0); - break; - case 'd': - log_parse_category_mask(osmo_stderr_target, optarg); - break; - case 'D': - daemonize = 1; - break; - default: - /* Unknown parameter passed */ - return -EINVAL; - } - } - - return 0; -} - -void signal_handler(int signum) -{ - fprintf(stdout, "signal %u received\n", signum); - - switch (signum) { - case SIGINT: - case SIGTERM: - exit(0); - break; - case SIGABRT: - /* in case of abort, we want to obtain a talloc report and - * then run default SIGABRT handler, who will generate coredump - * and abort the process. abort() should do this for us after we - * return, but program wouldn't exit if an external SIGABRT is - * received. - */ - talloc_report_full(tall_modem_ctx, stderr); - signal(SIGABRT, SIG_DFL); - raise(SIGABRT); - break; - case SIGUSR1: - talloc_report(tall_modem_ctx, stderr); - break; - case SIGUSR2: - talloc_report_full(tall_modem_ctx, stderr); - break; - default: - break; - } -} - -int modem_start(void) -{ - printf("Nothing to be done yet\n"); - return 0; -} - -int main(int argc, char **argv) -{ - int rc; - - tall_modem_ctx = talloc_named_const(NULL, 1, "modem"); - msgb_talloc_ctx_init(tall_modem_ctx, 0); - osmo_signal_talloc_ctx_init(tall_modem_ctx); - - osmo_init_logging2(tall_modem_ctx, &log_info); - - rc = handle_options(argc, argv); - if (rc) { /* Abort in case of parsing errors */ - fprintf(stderr, "Error in command line options. Exiting.\n"); - return 1; - } - - signal(SIGINT, &signal_handler); - signal(SIGTERM, &signal_handler); - signal(SIGABRT, &signal_handler); - signal(SIGUSR1, &signal_handler); - signal(SIGUSR2, &signal_handler); - osmo_init_ignore_signals(); - - if (daemonize) { - printf("Running as daemon\n"); - rc = osmo_daemonize(); - if (rc) - fprintf(stderr, "Failed to run as daemon\n"); - } - - modem_start(); - - while (!osmo_select_shutdown_done()) { - osmo_select_main_ctx(0); - } - - talloc_report_full(tall_modem_ctx, stderr); - return 0; -} -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30870 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I8566a3cdc9f818bed7e28ea4b1957dce735c298b Gerrit-Change-Number: 30870 Gerrit-PatchSet: 5 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • ...
  • 221
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.