pespin submitted this change.

View Change

Approvals: Jenkins Builder: Verified lynxis lazus: Looks good to me, approved
ranap: Introduce new APIs to encode rab_ass for gtp and rtp

This allows passing IPv6 addresses, which are already supported in
internal functions being called.

While at it, also check that sockaddr encoding succeeds and otherwise
return an error.

Related: OS#7066
Change-Id: I3a8800afd03b94349c8acec778ab7003819e80af
---
M TODO-RELEASE
M include/osmocom/ranap/ranap_msg_factory.h
M src/ranap_msg_factory.c
M tests/test-ranap.c
4 files changed, 96 insertions(+), 26 deletions(-)

diff --git a/TODO-RELEASE b/TODO-RELEASE
index 0ed7189..dad7e1f 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
+add ranap ranap_new_msg_rab_assign_voice2(), ranap_new_msg_rab_assign_data2()
diff --git a/include/osmocom/ranap/ranap_msg_factory.h b/include/osmocom/ranap/ranap_msg_factory.h
index b1175b0..e71bf25 100644
--- a/include/osmocom/ranap/ranap_msg_factory.h
+++ b/include/osmocom/ranap/ranap_msg_factory.h
@@ -2,6 +2,9 @@

#include <stdint.h>
#include <stdbool.h>
+
+#include <osmocom/core/socket.h>
+
#include <osmocom/ranap/RANAP_Cause.h>
#include <osmocom/ranap/RANAP_CN-DomainIndicator.h>
#include <osmocom/ranap/RANAP_GlobalRNC-ID.h>
@@ -39,11 +42,21 @@
/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for CS (voice) */
struct msgb *ranap_new_msg_rab_assign_voice(uint8_t rab_id, uint32_t rtp_ip,
uint16_t rtp_port,
- bool use_x213_nsap);
+ bool use_x213_nsap)
+OSMO_DEPRECATED("Use ranap_new_msg_rab_assign_voice2 instead");
+struct msgb *ranap_new_msg_rab_assign_voice2(uint8_t rab_id,
+ const struct osmo_sockaddr *rtp_addr,
+ bool use_x213_nsap);
+

/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for PS (data) */
struct msgb *ranap_new_msg_rab_assign_data(uint8_t rab_id, uint32_t gtp_ip,
- uint32_t gtp_tei, bool use_x213_nsap);
+ uint32_t gtp_tei, bool use_x213_nsap)
+OSMO_DEPRECATED("Use ranap_new_msg_rab_assign_data2 instead");
+struct msgb *ranap_new_msg_rab_assign_data2(uint8_t rab_id,
+ const struct osmo_sockaddr *gtp_addr,
+ uint32_t gtp_tei,
+ bool use_x213_nsap);

/*! \brief generate RANAP RESET message */
struct msgb *ranap_new_msg_reset(RANAP_CN_DomainIndicator_t domain,
diff --git a/src/ranap_msg_factory.c b/src/ranap_msg_factory.c
index aecd7df..cbdc403 100644
--- a/src/ranap_msg_factory.c
+++ b/src/ranap_msg_factory.c
@@ -789,20 +789,18 @@
}

/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for CS (voice).
- * See 3GPP TS 25.413 8.2.
- * RAB ID: 3GPP TS 25.413 9.2.1.2.
- * \param rtp_ip MGW's RTP IPv4 address in *host* byte order.
+ * \param[in] rab_id The RAB ID of the RAB being assigned (3GPP TS 25.413 9.2.1.2).
+ * \param[in] rtp_addr MGW's RTP IPv4 address and port.
+ * \param[in] use_x213_nsap Whether to use X.213 NSAP address encoding.
*/
-struct msgb *ranap_new_msg_rab_assign_voice(uint8_t rab_id, uint32_t rtp_ip,
- uint16_t rtp_port,
- bool use_x213_nsap)
+struct msgb *ranap_new_msg_rab_assign_voice2(uint8_t rab_id, const struct osmo_sockaddr *rtp_addr,
+ bool use_x213_nsap)
{
RANAP_ProtocolIE_FieldPair_t *pair;
RANAP_RAB_AssignmentRequestIEs_t ies;
RANAP_RAB_AssignmentRequest_t out;
struct msgb *msg;
int rc;
- struct osmo_sockaddr rtp_addr;

memset(&ies, 0, sizeof(ies));
memset(&out, 0, sizeof(out));
@@ -818,10 +816,11 @@
first.rAB_Parameters = new_rab_par_voice(6700, 12200);
first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_support_mode_for_predefined_SDU_sizes, 1); /* 2? */

- rtp_addr.u.sin.sin_family = AF_INET;
- rtp_addr.u.sin.sin_port = htons(rtp_port);
- rtp_addr.u.sin.sin_addr.s_addr = htonl(rtp_ip);
- first.transportLayerInformation = ranap_new_transp_info_rtp(&rtp_addr, use_x213_nsap);
+ first.transportLayerInformation = ranap_new_transp_info_rtp(rtp_addr, use_x213_nsap);
+ if (!first.transportLayerInformation) {
+ ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first);
+ return NULL;
+ }

/* put together the 'Second' part */
RANAP_RAB_SetupOrModifyItemSecond_t second;
@@ -864,10 +863,38 @@
return msg;
}

+/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for CS (voice).
+ * \param[in] rab_id The RAB ID of the RAB being assigned (3GPP TS 25.413 9.2.1.2).
+ * \param[in] rtp_ip MGW's RTP IPv4 address in *host* byte order.
+ * \param[in] rtp_port MGW's RTP port in *host* byte order.
+ * \param[in] use_x213_nsap Whether to use X.213 NSAP address encoding.
+ *
+ * See 3GPP TS 25.413 8.2.
+ */
+struct msgb *ranap_new_msg_rab_assign_voice(uint8_t rab_id, uint32_t rtp_ip,
+ uint16_t rtp_port,
+ bool use_x213_nsap)
+{
+ struct osmo_sockaddr rtp_addr = {
+ .u.sin = {
+ .sin_family = AF_INET,
+ .sin_port = htons(rtp_port),
+ .sin_addr.s_addr = htonl(rtp_ip),
+ }
+ };
+ return ranap_new_msg_rab_assign_voice2(rab_id, &rtp_addr, use_x213_nsap);
+}
+
/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for PS (data)
- * \param gtp_ip SGSN's GTP IPv4 address in *host* byte order. */
-struct msgb *ranap_new_msg_rab_assign_data(uint8_t rab_id, uint32_t gtp_ip,
- uint32_t gtp_tei, bool use_x213_nsap)
+ * \param[in] rab_id The RAB ID of the RAB being assigned.
+ * \param[in] gtp_addr SGSN's GTP IP address. sockaddr port is not used, ignored.
+ * \param[in] gtp_tei SGSN's GTP TEID in *host* byte order.
+ * \param[in] use_x213_nsap Whether to use X.213 NSAP address encoding.
+ */
+struct msgb *ranap_new_msg_rab_assign_data2(uint8_t rab_id,
+ const struct osmo_sockaddr *gtp_addr,
+ uint32_t gtp_tei,
+ bool use_x213_nsap)
{
RANAP_ProtocolIE_FieldPair_t *pair;
RANAP_RAB_AssignmentRequestIEs_t ies;
@@ -875,7 +902,6 @@
RANAP_DataVolumeReportingIndication_t *dat_vol_ind;
struct msgb *msg;
int rc;
- struct osmo_sockaddr gtp_addr;

memset(&ies, 0, sizeof(ies));
memset(&out, 0, sizeof(out));
@@ -891,10 +917,11 @@

first.rAB_Parameters = new_rab_par_data(1600000, 800000);
first.userPlaneInformation = new_upi(RANAP_UserPlaneMode_transparent_mode, 1);
-
- gtp_addr.u.sin.sin_family = AF_INET;
- gtp_addr.u.sin.sin_addr.s_addr = htonl(gtp_ip);
- first.transportLayerInformation = ranap_new_transp_info_gtp(&gtp_addr, gtp_tei, use_x213_nsap);
+ first.transportLayerInformation = ranap_new_transp_info_gtp(gtp_addr, gtp_tei, use_x213_nsap);
+ if (!first.transportLayerInformation) {
+ ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifyItemFirst, &first);
+ return NULL;
+ }

/* put together the 'Second' part */
RANAP_RAB_SetupOrModifyItemSecond_t second;
@@ -946,6 +973,24 @@
return msg;
}

+/*! \brief generate RANAP RAB ASSIGNMENT REQUEST message for PS (data)
+ * \param[in] rab_id The RAB ID of the RAB being assigned
+ * \param[in] gtp_ip SGSN's GTP IPv4 address in *host* byte order.
+ * \param[in] gtp_tei SGSN's GTP TEID in *host* byte order.
+ * \param[in] use_x213_nsap Whether to use X.213 NSAP address encoding.
+ */
+struct msgb *ranap_new_msg_rab_assign_data(uint8_t rab_id, uint32_t gtp_ip,
+ uint32_t gtp_tei, bool use_x213_nsap)
+{
+ struct osmo_sockaddr gtp_addr = {
+ .u.sin = {
+ .sin_family = AF_INET,
+ .sin_addr.s_addr = htonl(gtp_ip),
+ }
+ };
+ return ranap_new_msg_rab_assign_data2(rab_id, &gtp_addr, gtp_tei, use_x213_nsap);
+}
+
/*! \brief generate RANAP IU RELEASE REQUEST message */
struct msgb *ranap_new_msg_iu_rel_req(const RANAP_Cause_t *cause)
{
diff --git a/tests/test-ranap.c b/tests/test-ranap.c
index e593bd9..7213c1e 100644
--- a/tests/test-ranap.c
+++ b/tests/test-ranap.c
@@ -83,9 +83,20 @@
struct msgb *msg;
const char *imsi = "901700123456789";
uint32_t tmsi = 0x01234567;
- uint32_t rtp_ip = 0x0a0b0c0d;
- uint16_t rtp_port = 2342;
- uint32_t gtp_ip = 0x1a1b1c1d;
+ struct osmo_sockaddr rtp_addr = {
+ .u.sin = {
+ .sin_family = AF_INET,
+ .sin_port = htons(2342),
+ .sin_addr.s_addr = htonl(0x0a0b0c0d),
+ }
+ };
+ struct osmo_sockaddr gtp_addr = {
+ .u.sin = {
+ .sin_family = AF_INET,
+ .sin_port = htons(2152),
+ .sin_addr.s_addr = htonl(0x1a1b1c1d),
+ }
+ };
uint32_t gtp_tei = 0x11223344;
uint8_t ik[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
uint8_t ck[16] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
@@ -125,13 +136,13 @@
msgb_free(msg);

printf("\n==> RAB ASSIGNMENT COMMAND (VOICE)\n");
- msg = ranap_new_msg_rab_assign_voice(1, rtp_ip, rtp_port, 1);
+ msg = ranap_new_msg_rab_assign_voice2(1, &rtp_addr, 1);
if (msg)
printf("%s\n", msgb_hexdump(msg));
msgb_free(msg);

printf("\n==> RAB ASSIGNMENT COMMAND (DATA)\n");
- msg = ranap_new_msg_rab_assign_data(2, gtp_ip, gtp_tei, 1);
+ msg = ranap_new_msg_rab_assign_data2(2, &gtp_addr, gtp_tei, 1);
if (msg)
printf("%s\n", msgb_hexdump(msg));
msgb_free(msg);

To view, visit change 43258. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Change-Id: I3a8800afd03b94349c8acec778ab7003819e80af
Gerrit-Change-Number: 43258
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis@fe80.eu>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>