aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2024-03-02 20:02:55 +0100
committerHarald Welte <laforge@osmocom.org>2024-03-02 20:48:23 +0100
commit4f155022d8cd64a1a4795b851c49aa2633947740 (patch)
treef37d1b46c270bdd5c2622219b2a3f9a5ceb14678
parent319a77e519bb2e7ba086290d5ed57af2c097a725 (diff)
cbsp: Add osmo_cbsp_segmentation_cb for message segmentationlaforge/cbsp
This call-back can for example be used as segmentation call-back for libosmo-netif stream_cli/stream_srv or directly for osmo_io. Related: OS#5755 Change-Id: I5e922c54b3431d759b38e81e55076125c5a34008
-rw-r--r--include/osmocom/gsm/cbsp.h1
-rw-r--r--src/gsm/cbsp.c20
-rw-r--r--src/gsm/libosmogsm.map1
3 files changed, 22 insertions, 0 deletions
diff --git a/include/osmocom/gsm/cbsp.h b/include/osmocom/gsm/cbsp.h
index 536c54d6..efa4ce6f 100644
--- a/include/osmocom/gsm/cbsp.h
+++ b/include/osmocom/gsm/cbsp.h
@@ -312,3 +312,4 @@ void osmo_cbsp_init_struct(struct osmo_cbsp_decoded *cbsp, enum cbsp_msg_type ms
struct osmo_cbsp_decoded *osmo_cbsp_decoded_alloc(void *ctx, enum cbsp_msg_type msg_type);
int osmo_cbsp_recv_buffered(void *ctx, int fd, struct msgb **rmsg, struct msgb **tmp_msg);
+int osmo_cbsp_segmentation_cb(struct msgb *msg);
diff --git a/src/gsm/cbsp.c b/src/gsm/cbsp.c
index 28852f6f..a5e58f4c 100644
--- a/src/gsm/cbsp.c
+++ b/src/gsm/cbsp.c
@@ -1567,6 +1567,26 @@ discard_msg:
return rc;
}
+/*! call-back function to segment the data at message boundaries.
+ * Returns the size of the next message. If it returns -EAGAIN or a value larger than msgb_length() (message
+ * is incomplete), the caller (e.g. osmo_io) has to wait for more data to be read. */
+int osmo_cbsp_segmentation_cb(struct msgb *msg)
+{
+ const struct cbsp_header *h;
+ int len;
+
+ if (msgb_length(msg) < sizeof(*h))
+ return -EAGAIN;
+
+ h = (const struct cbsp_header *) msg->data;
+ msg->l1h = msg->data;
+ msg->l2h = msg->data + sizeof(*h);
+ /* then read the length as specified in the header */
+ len = h->len[0] << 16 | h->len[1] << 8 | h->len[2];
+
+ return sizeof(*h) + len;
+}
+
/*! value_string[] for enum osmo_cbsp_cause. */
const struct value_string osmo_cbsp_cause_names[] = {
{ OSMO_CBSP_CAUSE_PARAM_NOT_RECOGNISED, "Parameter-not-recognised" },
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index db2dbcb7..2c4c621c 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -793,6 +793,7 @@ osmo_cbsp_encode;
osmo_cbsp_decode;
osmo_cbsp_recv_buffered;
osmo_cbsp_errstr;
+osmo_cbsp_segmentation_cb;
osmo_i460_demux_in;
osmo_i460_mux_enqueue;