aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarehbein <arehbein@sysmocom.de>2023-05-24 15:20:16 +0200
committerDaniel Willmann <dwillmann@sysmocom.de>2023-05-31 12:25:22 +0200
commit9d394f4c4e22d049d78df44fce65b107d9881034 (patch)
tree11650f567a1f9b043f4aa4a9f3ae15638b487e32
parent424eb1288143100a6766683ec7b79d3e1faf3420 (diff)
stream: Add IPA send function/IPA-mode read to cli
- Also: Adapt ipa-stream-client example to work alongside new change Related: OS#5753 Change-Id: I042700af6614dd1879514dca0482e05b5ff22cb7
-rw-r--r--examples/ipa-stream-client.c10
-rw-r--r--include/osmocom/netif/stream.h4
-rw-r--r--src/stream.c24
3 files changed, 28 insertions, 10 deletions
diff --git a/examples/ipa-stream-client.c b/examples/ipa-stream-client.c
index c3bb2a3..6aa7d5f 100644
--- a/examples/ipa-stream-client.c
+++ b/examples/ipa-stream-client.c
@@ -93,10 +93,8 @@ static int connect_cb(struct osmo_stream_cli *conn)
msg_sent->num = i;
llist_add(&msg_sent->head, &msg_sent_list);
- ipa_prepend_header_ext(msg, IPAC_PROTO_EXT_MGCP);
- osmo_ipa_msg_push_header(msg, IPAC_PROTO_OSMO);
-
- osmo_stream_cli_send(conn, msg);
+ osmo_stream_cli_send_ipa(conn, IPAC_PROTO_OSMO,
+ IPAC_PROTO_EXT_MGCP, msg);
LOGP(DIPATEST, LOGL_DEBUG, "enqueueing msg %d of "
"%d bytes to be sent\n", i, msg->len);
@@ -106,7 +104,7 @@ static int connect_cb(struct osmo_stream_cli *conn)
static int read_cb(struct osmo_stream_cli *conn, struct msgb *msg)
{
- LOGP(DIPATEST, LOGL_DEBUG, "received message from stream (len=%d)\n", msgb_length(msg));
+ LOGP(DIPATEST, LOGL_DEBUG, "received message from stream (payload len=%d)\n", msgb_length(msg));
if (osmo_ipa_process_msg(msg) < 0) {
LOGP(DIPATEST, LOGL_ERROR, "bad IPA message\n");
@@ -116,7 +114,7 @@ static int read_cb(struct osmo_stream_cli *conn, struct msgb *msg)
int num;
struct msg_sent *cur, *tmp, *found = NULL;
- num = ntohl(*((int *)(msg->data + sizeof(struct ipa_head) + sizeof(struct ipa_head_ext))));
+ num = ntohl(*((int *)(msg->data)));
LOGP(DLINP, LOGL_DEBUG, "received msg number %d\n", num);
llist_for_each_entry_safe(cur, tmp, &msg_sent_list, head) {
diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h
index 16940dc..855f8d2 100644
--- a/include/osmocom/netif/stream.h
+++ b/include/osmocom/netif/stream.h
@@ -72,7 +72,7 @@ void osmo_stream_srv_set_data(struct osmo_stream_srv *conn, void *data);
void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg);
void osmo_stream_srv_send_ipa(struct osmo_stream_srv *conn, int ipaccess_proto,
- enum ipaccess_proto_ext pe, struct msgb *msg);
+ enum ipaccess_proto_ext pe, struct msgb *msg);
int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg);
void osmo_stream_srv_clear_tx_queue(struct osmo_stream_srv *conn);
@@ -113,6 +113,8 @@ int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) \
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, int ipaccess_proto,
+ enum ipaccess_proto_ext pe, struct msgb *msg);
int osmo_stream_cli_recv(struct osmo_stream_cli *cli, 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 d1682c2..00ea33d 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -689,8 +689,8 @@ static void stream_cli_iofd_read_cb(struct osmo_io_fd *iofd, int res, struct msg
if (res == 0)
osmo_stream_cli_reconnect(cli);
else if (cli->iofd_read_cb) {
- // if (cli->stream_proto == OSMO_STREAM_IPAC)
- // ipa_check_pull_headers(
+ if (cli->stream_proto == OSMO_STREAM_IPAC)
+ ipa_check_pull_headers(msg, cli);
cli->iofd_read_cb(cli, msg);
}
break;
@@ -868,7 +868,6 @@ void osmo_stream_cli_set_stream_proto(struct osmo_stream_cli *cli, enum osmo_str
client_ops.segmentation_cb = segmentation_cbs[osp];
osmo_iofd_set_ioops(cli->iofd, &client_ops);
cli->flags |= OSMO_STREAM_CLI_F_RECONF;
- osmo_iofd_set_ioops(cli->iofd, &osmo_stream_cli_ioops);
}
/*! \brief Set the socket type for the stream server link
@@ -1207,6 +1206,25 @@ static inline int msg_get_ipa_proto_ext(struct msgb *msg)
/*! \brief Enqueue 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. When set to IPAC_PROTO_UNSPECIFIED, the protocol will be
+ * read from the msgb structure's l1 and possibly l2 headers.
+ * \param[in] pe Ignored, unless p == IPAC_PROTO_OSMO, in which case this specifies the
+ * Osmocom protocol extension
+ * \param[in] msg Message buffer to enqueue in transmit queue */
+void osmo_stream_cli_send_ipa(struct osmo_stream_cli *cli, int ipaccess_proto,
+ enum ipaccess_proto_ext pe, struct msgb *msg)
+{
+ OSMO_ASSERT(msg);
+ if (ipaccess_proto == IPAC_PROTO_UNSPECIFIED) {
+ ipaccess_proto = msg_get_ipa_proto(msg);
+ pe = msg_get_ipa_proto_ext(msg);
+ }
+ ipa_push_headers(ipaccess_proto, pe, msg);
+ osmo_stream_cli_send(cli, msg);
+}
+
+/*! \brief Enqueue data to be sent via an Osmocom stream client
+ * \param[in] cli Stream Client through which we want to send
* \param[in] msg Message buffer to enqueue in transmit queue */
void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg)
{