diff --git a/examples/ipa-stream-client.c b/examples/ipa-stream-client.c index db7d441..cb07ef6 100644 --- a/examples/ipa-stream-client.c +++ b/examples/ipa-stream-client.c @@ -93,9 +93,7 @@ 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_ipa_msg_push_headers(msg, osmo_ipa_msgb_cb_proto(msg), osmo_ipa_msgb_cb_proto_ext(msg)); osmo_stream_cli_send(conn, msg); LOGP(DIPATEST, LOGL_DEBUG, "enqueueing msg %d of " diff --git a/examples/ipa-stream-server.c b/examples/ipa-stream-server.c index d31b752..5317921 100644 --- a/examples/ipa-stream-server.c +++ b/examples/ipa-stream-server.c @@ -51,9 +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_ipa_msg_push_headers(msg, osmo_ipa_msgb_cb_proto(msg), osmo_ipa_msgb_cb_proto_ext(msg)); osmo_stream_srv_send(conn, msg); return 0; } diff --git a/include/osmocom/netif/ipa.h b/include/osmocom/netif/ipa.h index 7826895..038b9ac 100644 --- a/include/osmocom/netif/ipa.h +++ b/include/osmocom/netif/ipa.h @@ -65,4 +65,6 @@ 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_msg_push_headers(struct msgb *msg, enum ipaccess_proto p, enum ipaccess_proto_ext pe); + #endif diff --git a/src/ipa.c b/src/ipa.c index a67521f..8720427 100644 --- a/src/ipa.c +++ b/src/ipa.c @@ -436,3 +436,15 @@ int osmo_ipa_segmentation_cb(struct msgb *msg) } return total_len; } + +/*! Push IPA headers to a message + * If we have IPAC_PROTO_OSMO this also takes care of the extension header + * \param[out] msg Target message + * \param p Target IPA protocol + * \param pe Target IPA protocol extension. Ignored, unless p equals IPAC_PROTO_OSMO. */ +void osmo_ipa_msg_push_headers(struct msgb *msg, enum ipaccess_proto p, enum ipaccess_proto_ext pe) +{ + if (p == IPAC_PROTO_OSMO) + ipa_prepend_header_ext(msg, pe); + osmo_ipa_msg_push_header(msg, p); +} diff --git a/tests/stream/stream_test.c b/tests/stream/stream_test.c index 960d8fa..4830302 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) @@ -574,7 +579,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); + put_ipa_msg(data, m, ipac_msg_idreq_payload); + osmo_ipa_msg_push_headers(m, IPAC_PROTO_IPACCESS, -1); osmo_stream_srv_send(conn, m); } else if (msgnum_srv == 7 && *msgt == IPAC_MSGT_PONG) { test_segm_ipa_stream_srv_all_msgs_processed = true; @@ -766,7 +772,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); + put_ipa_msg(data, m, ipac_msg_idreq_payload); + osmo_ipa_msg_push_headers(m, IPAC_PROTO_IPACCESS, -1); osmo_stream_cli_send(osc, m); } else if (msgnum_cli == 7 && *msgt == IPAC_MSGT_PONG) { test_segm_ipa_stream_cli_all_msgs_processed = true;