[M] Change in libosmo-netif[arehbein/osmo_io_ipa]: stream: Add client side recv and send for IPA
arehbein has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/32709 ) Change subject: stream: Add client side recv and send for IPA ...................................................................... stream: Add client side recv and send for IPA Related: OS#5753 Change-Id: Ic93b2d96fd14ad1a1dc063924498d87f0b1d8a56 --- M include/osmocom/netif/stream.h M src/stream.c 2 files changed, 79 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/09/32709/1 diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index cd1dd22..7f2c37e 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -4,6 +4,7 @@ #include <stdint.h> #include <osmocom/core/msgb.h> +#include <osmocom/gsm/protocol/ipaccess.h> /*! \addtogroup stream * @{ @@ -108,7 +109,11 @@ void osmo_stream_cli_close(struct osmo_stream_cli *cli); void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg); +void osmo_stream_cli_send_ipa(struct osmo_stream_cli *cli, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg); int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg); +int osmo_stream_cli_recv_ipa(struct osmo_stream_cli *cli, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg); void osmo_stream_cli_clear_tx_queue(struct osmo_stream_cli *cli); diff --git a/src/stream.c b/src/stream.c index d61a8d6..ac2dcec 100644 --- a/src/stream.c +++ b/src/stream.c @@ -37,6 +37,8 @@ #include <osmocom/core/utils.h> #include <osmocom/gsm/tlv.h> #include <osmocom/gsm/ipa.h> +#include <osmocom/netif/ipa.h> +#include <osmocom/gsm/protocol/ipaccess.h> #include <osmocom/core/msgb.h> #include <osmocom/core/osmo_io.h> #include <osmocom/core/panic.h> @@ -1155,6 +1157,23 @@ } } +/*! \brief Enqueue IPA data to be sent via an Osmocom stream client + * \param[in] cli Stream client through which we want to send + * \param[in] p Protocol transported by IPA + * \param[in] pe Ignored, unless p == IPAC_PROTO_OSMO, in which case this specifies the + * Osmocom protocol extension + * \param[in] msg Message buffer to encapsulate as IPA (or possibly IPA + IPA extended + * enqueue in transmit queue) */ +void osmo_stream_cli_send_ipa(struct osmo_stream_cli *cli, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg) +{ + OSMO_ASSERT(msg); + if (p == IPAC_PROTO_OSMO) + ipa_prepend_header_ext(msg, pe); + osmo_ipa_msg_push_header(msg, p); + osmo_stream_cli_send(cli, msg); +} + /*! \brief Receive data via an Osmocom stream client * \param[in] cli Stream Client through which we want to send * \param msg pre-allocate message buffer to which received data is appended @@ -1182,6 +1201,51 @@ return ret; } +/*! \brief Receive IPA data via an Osmocom stream client + * \param[in] cli Stream Client through which we want to send + * \param[in] p Expected protocol to be transported by IPA + * \param[in] pe Ignored, unless p == IPAC_PROTO_OSMO, in which case this specifies the + * Osmocom protocol extension expected to be received + * \param msg pre-allocated message buffer to which received data is appended + * \returns number of bytes read; <=0 in case of error. */ +int osmo_stream_cli_recv_ipa(struct osmo_stream_cli *cli, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg) +{ + struct ipa_head *ih; + struct ipa_head_ext *ihe; + size_t bytes; + int ret = osmo_stream_cli_recv(cli, msg); + if (ret <= 0) { + LOGSCLI(cli, LOGL_ERROR, "Couldn't receive IPA message\n"); + return ret; + } + bytes = ret; + if ((ret = osmo_ipa_process_msg(msg)) < 0) { + LOGSCLI(cli, LOGL_ERROR, "Error processing IPA message\n"); + return ret; + } + ih = (struct ipa_head *)msg->data; + if (ih->proto != p) { + LOGSCLI(cli, LOGL_ERROR, "Unexpected IPA protocol received: 0x%02x " + "(expected: 0x%02x)\n", ih->proto, p); + return -ENOMSG; + } + msgb_pull(msg, sizeof (struct ipa_head)); + msg->l1h = NULL; + if (ih->proto != IPAC_PROTO_OSMO) /* No extensions expected */ + return bytes; + + ihe = (struct ipa_head_ext *)msg; + if (ihe->proto != pe) { + LOGSCLI(cli, LOGL_ERROR, "Unexpected IPA Osmocom protocol extension " + "received: 0x%02x (expected: 0x%02x)\n", ihe->proto, pe); + return -ENOMSG; + } + msgb_pull(msg, sizeof (struct ipa_head_ext)); + msg->l2h = NULL; + return ret; +} + void osmo_stream_cli_clear_tx_queue(struct osmo_stream_cli *cli) { switch (cli->mode) { -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/32709 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-netif Gerrit-Branch: arehbein/osmo_io_ipa Gerrit-Change-Id: Ic93b2d96fd14ad1a1dc063924498d87f0b1d8a56 Gerrit-Change-Number: 32709 Gerrit-PatchSet: 1 Gerrit-Owner: arehbein <arehbein@sysmocom.de> Gerrit-MessageType: newchange
participants (1)
-
arehbein