arehbein has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-netif/+/33204 )


Change subject: stream: Add IPA send function/IPA-mode read to cli
......................................................................

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
---
M examples/ipa-stream-client.c
M include/osmocom/netif/stream.h
M src/stream.c
3 files changed, 40 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/04/33204/1

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 @@
                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 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 @@
        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_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 @@
 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 30639e2..05fbff3 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -680,6 +680,8 @@
                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(msg, cli);
                        cli->iofd_read_cb(cli, msg);
                }
                break;
@@ -857,7 +859,6 @@
        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
@@ -1196,6 +1197,25 @@

 /*! \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)
 {

--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/33204
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I042700af6614dd1879514dca0482e05b5ff22cb7
Gerrit-Change-Number: 33204
Gerrit-PatchSet: 1
Gerrit-Owner: arehbein <arehb...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to