fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/43106?usp=email )
Change subject: libosmo-trx/trxc: enlarge the params buffer
......................................................................
libosmo-trx/trxc: enlarge the params buffer
The SETFH command (implemented by trxcon and fake_trx) carries the
whole Mobile Allocation as pairs of Rx/Tx frequencies in kHz:
CMD SETFH <HSN> <MAIO> <RXF1> <TXF1> [... <RXFN> <TXFN>]
With up to 64 ARFCNs in the Mobile Allocation, the parameters string
alone can exceed 1000 characters, far beyond the old 128 byte limit.
Derive OSMO_TRXC_PARAMS_LEN_MAX from OSMO_TRXC_MSG_BUF_SIZE, so that
any message ("RSP " + verb + status + params) still fits the
recommended socket buffer size. Also add the OSMO_TRXC_CMD_SETFH
verb constant and a regression test doing a round-trip of a maximum
size SETFH command (64 ARFCNs).
Change-Id: I2f65b213f5ada499eea4abae87d3727057e03e22
---
M libosmo-trx/include/osmocom/trx/trxc.h
M tests/libosmo-trx/trxc_test.c
M tests/libosmo-trx/trxc_test.ok
3 files changed, 56 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/06/43106/1
diff --git a/libosmo-trx/include/osmocom/trx/trxc.h
b/libosmo-trx/include/osmocom/trx/trxc.h
index ee7935a..6f6891e 100644
--- a/libosmo-trx/include/osmocom/trx/trxc.h
+++ b/libosmo-trx/include/osmocom/trx/trxc.h
@@ -7,10 +7,13 @@
/*! Maximum length of a command verb (incl. '\0') */
#define OSMO_TRXC_CMD_LEN_MAX 32
-/*! Maximum length of the parameters string (incl. '\0') */
-#define OSMO_TRXC_PARAMS_LEN_MAX 128
/*! Recommended TRXC socket read/send buffer size */
#define OSMO_TRXC_MSG_BUF_SIZE 1500
+/*! Maximum length of the parameters string (incl. '\0'). Must be large
+ * enough for SETFH, which carries the whole Mobile Allocation as pairs of
+ * Rx/Tx frequencies in kHz (over 1000 characters for 64 ARFCNs). Sized so
+ * that any message ("RSP " + verb + status) still fits the buffer above. */
+#define OSMO_TRXC_PARAMS_LEN_MAX (OSMO_TRXC_MSG_BUF_SIZE -
OSMO_TRXC_CMD_LEN_MAX - 32)
enum osmo_trxc_msg_type {
OSMO_TRXC_MT_CMD, /*!< "CMD <verb> [<params>]" (L1 -> TRX) */
@@ -52,6 +55,7 @@
#define OSMO_TRXC_CMD_HANDOVER "HANDOVER"
#define OSMO_TRXC_CMD_NOHANDOVER "NOHANDOVER"
#define OSMO_TRXC_CMD_RFMUTE "RFMUTE"
+#define OSMO_TRXC_CMD_SETFH "SETFH"
#define OSMO_TRXC_CMD_ERR "ERR" /*!< verb of a reject response */
/* Clock socket: "IND CLOCK <fn>" */
diff --git a/tests/libosmo-trx/trxc_test.c b/tests/libosmo-trx/trxc_test.c
index 82676a7..93eea83 100644
--- a/tests/libosmo-trx/trxc_test.c
+++ b/tests/libosmo-trx/trxc_test.c
@@ -114,6 +114,50 @@
OSMO_ASSERT(rc == 2 && tn == 3 && ts_type == 7);
}
+/* SETFH (trxcon dialect) carries the whole Mobile Allocation as pairs of
+ * Rx/Tx frequencies in kHz, so its parameters can be over 1000 characters
+ * long (up to 64 ARFCNs). Ensure that such messages survive a round-trip. */
+static void test_long_params(void)
+{
+ char buf[OSMO_TRXC_MSG_BUF_SIZE];
+ struct osmo_trxc_msg msg = {
+ .type = OSMO_TRXC_MT_CMD,
+ .cmd = OSMO_TRXC_CMD_SETFH,
+ };
+ struct osmo_trxc_msg parsed;
+ size_t len;
+ int rc;
+
+ printf("=== %s ===\n", __func__);
+
+ /* HSN=32 MAIO=5, then 64 pairs of DCS1800 Rx/Tx frequencies */
+ len = snprintf(msg.params, sizeof(msg.params), "32 5");
+ for (unsigned int i = 0; i < 64; i++) {
+ len += snprintf(msg.params + len, sizeof(msg.params) - len,
+ " %u %u", 1805200 + i * 200, 1710200 + i * 200);
+ }
+ printf("SETFH params_len=%zu\n", len);
+ OSMO_ASSERT(len < sizeof(msg.params));
+
+ rc = osmo_trxc_msg_build(buf, sizeof(buf), &msg);
+ printf("build: rc=%d\n", rc);
+ OSMO_ASSERT(rc > 0);
+
+ rc = osmo_trxc_msg_parse(&parsed, buf, rc);
+ printf("parse: rc=%d cmd='%s' params_len=%zu\n",
+ rc, parsed.cmd, strlen(parsed.params));
+ OSMO_ASSERT(rc == 0);
+ OSMO_ASSERT(strcmp(parsed.params, msg.params) == 0);
+
+ /* parameters longer than OSMO_TRXC_PARAMS_LEN_MAX shall be rejected */
+ len = strlen(buf);
+ memset(buf + len, '6', sizeof(buf) - len - 1);
+ buf[sizeof(buf) - 1] = '\0';
+ rc = osmo_trxc_msg_parse(&parsed, buf, strlen(buf));
+ printf("parse oversized params: rc=%d\n", rc);
+ OSMO_ASSERT(rc < 0);
+}
+
static void test_clk_ind(void)
{
static const char * const messages[] = {
@@ -155,6 +199,7 @@
test_msg_parse();
test_msg_build();
test_params_scan();
+ test_long_params();
test_clk_ind();
printf("Done\n");
diff --git a/tests/libosmo-trx/trxc_test.ok b/tests/libosmo-trx/trxc_test.ok
index 9422d19..845d4da 100644
--- a/tests/libosmo-trx/trxc_test.ok
+++ b/tests/libosmo-trx/trxc_test.ok
@@ -38,6 +38,11 @@
build into a too small buffer: rc=-90
=== test_params_scan ===
'3 7' -> rc=2 tn=3 ts_type=7
+=== test_long_params ===
+SETFH params_len=1028
+build: rc=1038
+parse: rc=0 cmd='SETFH' params_len=1028
+parse oversized params: rc=-90
=== test_clk_ind ===
'IND CLOCK 402312' -> fn=402312
'IND CLOCK 0' -> fn=0
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43106?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I2f65b213f5ada499eea4abae87d3727057e03e22
Gerrit-Change-Number: 43106
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>