diff options
-rw-r--r-- | examples/ipa-stream-client.c | 6 | ||||
-rw-r--r-- | examples/ipa-stream-server.c | 5 | ||||
-rw-r--r-- | include/osmocom/netif/ipa.h | 5 | ||||
-rw-r--r-- | src/ipa.c | 38 | ||||
-rw-r--r-- | tests/stream/stream_test.c | 17 |
5 files changed, 57 insertions, 14 deletions
diff --git a/examples/ipa-stream-client.c b/examples/ipa-stream-client.c index db7d441..ea919a4 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_ipa_stream_cli_send(conn, osmo_ipa_msgb_cb_proto(msg), + osmo_ipa_msgb_cb_proto_ext(msg), msg); LOGP(DIPATEST, LOGL_DEBUG, "enqueueing msg %d of " "%d bytes to be sent\n", i, msg->len); diff --git a/examples/ipa-stream-server.c b/examples/ipa-stream-server.c index d31b752..4990b95 100644 --- a/examples/ipa-stream-server.c +++ b/examples/ipa-stream-server.c @@ -51,10 +51,7 @@ int read_cb(struct osmo_stream_srv *conn, struct msgb *msg) { LOGP(DSTREAMTEST, LOGL_DEBUG, "received message from stream (payload len=%d)\n", msgb_length(msg)); - ipa_prepend_header_ext(msg, IPAC_PROTO_EXT_MGCP); - osmo_ipa_msg_push_header(msg, IPAC_PROTO_OSMO); - - osmo_stream_srv_send(conn, msg); + osmo_ipa_stream_srv_send(conn, osmo_ipa_msgb_cb_proto(msg), osmo_ipa_msgb_cb_proto_ext(msg), msg); return 0; } diff --git a/include/osmocom/netif/ipa.h b/include/osmocom/netif/ipa.h index 1923253..de6cfbe 100644 --- a/include/osmocom/netif/ipa.h +++ b/include/osmocom/netif/ipa.h @@ -3,6 +3,7 @@ #include <osmocom/gsm/protocol/ipaccess.h> #include <osmocom/gsm/ipa.h> +#include <osmocom/netif/stream.h> /* This is like 'struct ipaccess_head' in libosmocore, but 'ipa_head' is * actually the more apropriate name, so rather than making more code @@ -53,4 +54,8 @@ int osmo_ipa_parse_msg_id_resp(struct msgb *msg, struct ipaccess_unit *unit_data int osmo_ipa_segmentation_cb(struct msgb *msg); +void osmo_ipa_stream_srv_send(struct osmo_stream_srv *conn, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg); +void osmo_ipa_stream_cli_send(struct osmo_stream_cli *cli, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg); #endif @@ -436,3 +436,41 @@ int osmo_ipa_segmentation_cb(struct msgb *msg) } return total_len; } + +/* Push IPA headers; if we have IPAC_PROTO_OSMO this also takes care of the + * extension header */ +static inline void ipa_push_headers(enum ipaccess_proto p, enum ipaccess_proto_ext pe, + struct msgb *msg) +{ + if (p == IPAC_PROTO_OSMO) + ipa_prepend_header_ext(msg, pe); + osmo_ipa_msg_push_header(msg, p); +} + +/*! \brief Enqueue IPA data to be sent via an Osmocom stream server + * \param[in] conn Stream Server 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 enqueue in transmit queue */ +void osmo_ipa_stream_srv_send(struct osmo_stream_srv *conn, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg) +{ + OSMO_ASSERT(msg); + ipa_push_headers(p, pe, msg); + osmo_stream_srv_send(conn, 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. + * \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_ipa_stream_cli_send(struct osmo_stream_cli *cli, enum ipaccess_proto p, + enum ipaccess_proto_ext pe, struct msgb *msg) +{ + OSMO_ASSERT(msg); + ipa_push_headers(p, pe, msg); + osmo_stream_cli_send(cli, msg); +} diff --git a/tests/stream/stream_test.c b/tests/stream/stream_test.c index 466619c..38aadfb 100644 --- a/tests/stream/stream_test.c +++ b/tests/stream/stream_test.c @@ -384,12 +384,17 @@ static const uint8_t ipac_msg_pong[] = { IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG }; +#define IPAC_MSG_IDREQ_PAYLOAD_INITIALIZER \ + IPAC_MSGT_ID_GET, \ + 0x01, IPAC_IDTAG_UNITNAME +static const uint8_t ipac_msg_idreq_payload[] = { + IPAC_MSG_IDREQ_PAYLOAD_INITIALIZER +}; #define IPAC_MSG_ID_REQ_LEN 0x03 static const uint8_t ipac_msg_idreq[] = { 0x00, IPAC_MSG_ID_REQ_LEN, IPAC_PROTO_IPACCESS, - IPAC_MSGT_ID_GET, - 0x01, IPAC_IDTAG_UNITNAME + IPAC_MSG_IDREQ_PAYLOAD_INITIALIZER }; #define ipac_msg_idreq_third (sizeof(ipac_msg_idreq)/3) #define ipac_msg_idreq_last_third (sizeof(ipac_msg_idreq) - 2 * ipac_msg_idreq_third) @@ -573,8 +578,8 @@ int test_segm_ipa_stream_srv_srv_read_cb(struct osmo_stream_srv *conn, struct ms fprintf(stderr, "Cannot allocate message\n"); return -ENOMEM; } - put_ipa_msg(data, m, ipac_msg_idreq); - osmo_stream_srv_send(conn, m); + put_ipa_msg(data, m, ipac_msg_idreq_payload); + osmo_ipa_stream_srv_send(conn, IPAC_PROTO_IPACCESS, -1, m); } else if (msgnum_srv == 7 && *msgt == IPAC_MSGT_PONG) { test_segm_ipa_stream_srv_all_msgs_processed = true; } @@ -776,8 +781,8 @@ static int test_segm_ipa_stream_cli_cli_read_cb(struct osmo_stream_cli *osc, str fprintf(stderr, "Cannot allocate message\n"); return -ENOMEM; } - put_ipa_msg(data, m, ipac_msg_idreq); - osmo_stream_cli_send(osc, m); + put_ipa_msg(data, m, ipac_msg_idreq_payload); + osmo_ipa_stream_cli_send(osc, IPAC_PROTO_IPACCESS, -1, m); } else if (msgnum_cli == 7 && *msgt == IPAC_MSGT_PONG) { test_segm_ipa_stream_cli_all_msgs_processed = true; } |