arehbein has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/32671 )
Change subject: gsm/ipa: Add segmentation callback ......................................................................
gsm/ipa: Add segmentation callback
Add segmentation callback to be used by the streaming backend of libosmo-netif.
Related: OS#5753, OS#5751 Change-Id: I3a639e6896cc3b3fc8e9b2e1a58254710efa0d3f --- M include/osmocom/gsm/ipa.h M src/gsm/ipa.c M src/gsm/libosmogsm.map 3 files changed, 48 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/71/32671/1
diff --git a/include/osmocom/gsm/ipa.h b/include/osmocom/gsm/ipa.h index 851b58e..241c010 100644 --- a/include/osmocom/gsm/ipa.h +++ b/include/osmocom/gsm/ipa.h @@ -5,6 +5,7 @@ #include <stdint.h>
#include <osmocom/core/msgb.h> +#include <osmocom/core/osmo_io.h> #include <osmocom/gsm/tlv.h>
struct osmo_fd; @@ -69,6 +70,9 @@ /* Common handling of IPA CCM, BTS side */ int ipa_ccm_rcvmsg_bts_base(struct msgb *msg, struct osmo_fd *bfd);
+/* Callback for segmenting TCP stream data into IPA packets */ +int ipa_iofd_segmentation_cb(struct msgb *msg, int read); + /* prepend (push) an ipaccess_head_ext to the msgb */ void ipa_prepend_header_ext(struct msgb *msg, int proto);
@@ -79,3 +83,5 @@
int ipa_msg_recv(int fd, struct msgb **rmsg); int ipa_msg_recv_buffered(int fd, struct msgb **rmsg, struct msgb **tmp_msg); + +int ipa_segmentation_cb(struct msgb *msg, int read); diff --git a/src/gsm/ipa.c b/src/gsm/ipa.c index 447e8e3..a92dcac 100644 --- a/src/gsm/ipa.c +++ b/src/gsm/ipa.c @@ -39,6 +39,7 @@ #include <osmocom/core/logging.h> #include <osmocom/core/macaddr.h> #include <osmocom/core/select.h> +#include <osmocom/core/osmo_io.h>
#include <osmocom/gsm/tlv.h> #include <osmocom/gsm/protocol/ipaccess.h> @@ -718,4 +719,32 @@ return nmsg; }
+int ipa_segmentation_cb(struct msgb *msg, int read) +{ + struct ipaccess_head *hh; + int len; + if (read < sizeof(*hh)) + return sizeof(*hh); + + /* (Why) would we need to do this? + * This doesn't seem like the place for changing message properties + msg->l1h = msg->data; */ + hh = (struct ipaccess_head *) msg->data; + + /* then read the length as specified in header */ + len = osmo_ntohs(hh->len); + + if (len < 0 || IPA_ALLOC_SIZE < len + sizeof(*hh)) { + LOGP(DLINP, LOGL_ERROR, "bad message length of %d bytes, " + "received %d bytes\n", len, msg->len); + return -EIO; + } + + /* + msg->l2h = hh->data; + */ + + return sizeof(*hh) + len; +} + /*! @} */ diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index 6795c57..45893d3 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -637,6 +637,7 @@ ipa_ccm_id_resp_parse; ipa_ccm_make_id_resp; ipa_ccm_make_id_resp_from_req; +ipa_segmentation_cb; ipa_msg_alloc; ipa_msg_recv; ipa_msg_recv_buffered;