gerrit-log
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
September 2026
- 1 participants
- 1894 discussions
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43610?usp=email )
Change subject: proxy: implement TRXC SETFORMAT
......................................................................
proxy: implement TRXC SETFORMAT
Change-Id: I9c453e7ba2a799a8c4ce037afef14037b596a29d
Related: OS#6672
---
M proxy/src/ctrl_cmd.c
1 file changed, 29 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/10/43610/1
diff --git a/proxy/src/ctrl_cmd.c b/proxy/src/ctrl_cmd.c
index ca6ac7b..bf49ce3 100644
--- a/proxy/src/ctrl_cmd.c
+++ b/proxy/src/ctrl_cmd.c
@@ -28,6 +28,7 @@
#include <osmocom/trx/ep.h>
#include <osmocom/trx/trxc.h>
+#include <osmocom/trx/trxd.h>
#include <osmocom/proxy/proxy.h>
#include <osmocom/proxy/trx.h>
@@ -184,6 +185,32 @@
trx->chans[chan].ts[ss.tn].valid = true;
}
+/* SETFORMAT negotiates the TRXD PDU version used on the data socket: the
+ * response status carries the version to use (the requested one, or our
+ * preferred version if out of range), not a plain ACK/NACK. */
+static void ctrl_cmd_setformat(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ int ver_req;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d", &ver_req) != 1 || ver_req < 0) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse command arguments: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = -1;
+ return;
+ }
+
+ if (ver_req > OSMO_TRXD_PDU_VER_MAX)
+ ver_req = OSMO_TRXD_PDU_VER_MAX;
+
+ osmo_trx_ep_set_pdu_ver(trx->ep, chan, ver_req);
+ rsp->status = ver_req;
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
+ "TRXD header version set to %d\n", ver_req);
+}
+
/* FAKE_TOA/FAKE_RSSI/FAKE_CI: "<delta>" adjusts the current value by delta;
* "<value> <threshold>" sets an absolute value with a +/-threshold random
* jitter applied on every forwarded burst (see path_sim_apply()). */
@@ -340,6 +367,8 @@
ctrl_cmd_rfmute(trx, chan, cmd, &rsp);
} else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_SETSLOT)) {
ctrl_cmd_setslot(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_SETFORMAT)) {
+ ctrl_cmd_setformat(trx, chan, cmd, &rsp);
} else if (!strcmp(cmd->cmd, CTRL_CMD_SETTA)) {
ctrl_cmd_setta(trx, chan, cmd, &rsp);
} else if (!strcmp(cmd->cmd, CTRL_CMD_MEASURE)) {
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43610?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: I9c453e7ba2a799a8c4ce037afef14037b596a29d
Gerrit-Change-Number: 43610
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43611?usp=email )
Change subject: proxy: implement freq. hopping
......................................................................
proxy: implement freq. hopping
Handle TRXC SETFH ("<HSN> <MAIO> <RXF1> <TXF1> [... <RXFN> <TXFN>]"),
storing a per-channel struct proxy_trx_fh (HSN, MAIO, and the parsed
Mobile Allocation of Rx/Tx frequency pairs, struct proxy_trx_fh_freq).
burst_fwd.c resolves both the source channel's Tx frequency and each
candidate destination channel's Rx frequency per TDMA frame number via
proxy_trx_fh_resolve() whenever a channel has hopping configured,
falling back to the static RXTUNE/TXTUNE frequency otherwise.
Change-Id: I574b4d4dc337f771b044bd868088b29db9902de9
Related: OS#6672
---
M proxy/include/osmocom/proxy/trx.h
M proxy/src/burst_fwd.c
M proxy/src/ctrl_cmd.c
M proxy/src/trx.c
4 files changed, 164 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/11/43611/1
diff --git a/proxy/include/osmocom/proxy/trx.h b/proxy/include/osmocom/proxy/trx.h
index 199d95b..e47a41f 100644
--- a/proxy/include/osmocom/proxy/trx.h
+++ b/proxy/include/osmocom/proxy/trx.h
@@ -25,6 +25,21 @@
bool valid; /*!< has SETSLOT been received for this TS? */
};
+/*! One Mobile Allocation entry: the Rx/Tx frequency pair for one ARFCN. */
+struct proxy_trx_fh_freq {
+ uint32_t rx_freq; /*!< Rx frequency in Hz */
+ uint32_t tx_freq; /*!< Tx frequency in Hz */
+};
+
+/*! Synthesizer frequency hopping parameters (SETFH), per 3GPP TS 45.002:
+ * HSN, MAIO and the Mobile Allocation (list of Rx/Tx frequency pairs). */
+struct proxy_trx_fh {
+ uint8_t hsn;
+ uint8_t maio;
+ unsigned int ma_len;
+ struct proxy_trx_fh_freq *ma; /*!< talloc array of ma_len entries */
+};
+
/*! Per-channel state: each channel is conceptually its own (child)
* transceiver with an independent Rx/Tx frequency, sharing the endpoint's
* power state and clock. */
@@ -34,6 +49,7 @@
bool rf_muted; /*!< RFMUTE: force NOPE.ind on Rx */
struct path_sim_state path_sim; /*!< RF path simulation state (path_sim.c) */
struct proxy_trx_ts ts[PROXY_TRX_NUM_TS]; /*!< per-timeslot config (SETSLOT) */
+ struct proxy_trx_fh *fh; /*!< frequency hopping config (SETFH), NULL if disabled */
};
/*! One virtual transceiver endpoint */
@@ -66,3 +82,11 @@
/*! Update the endpoint's power state; (de)registers it with the TDMA clock
* generator as appropriate. */
void proxy_trx_set_power(struct proxy_trx *trx, bool on);
+
+/*! Allocate a frequency hopping configuration; ma is copied. */
+struct proxy_trx_fh *proxy_trx_fh_alloc(void *talloc_ctx, uint8_t hsn, uint8_t maio,
+ const struct proxy_trx_fh_freq *ma, unsigned int ma_len);
+
+/*! Resolve the Rx/Tx frequencies to use for the given TDMA frame number. */
+void proxy_trx_fh_resolve(const struct proxy_trx_fh *fh, uint32_t fn,
+ uint32_t *rx_freq, uint32_t *tx_freq);
diff --git a/proxy/src/burst_fwd.c b/proxy/src/burst_fwd.c
index 2166714..de057b6 100644
--- a/proxy/src/burst_fwd.c
+++ b/proxy/src/burst_fwd.c
@@ -66,8 +66,8 @@
}
/*! Forward a Tx burst request to every powered-on endpoint/channel
- * whose Rx frequency matches the source channel's Tx frequency.
- * TODO: (no frequency hopping support yet, see SETFH in fake_trx.py). */
+ * whose Rx frequency matches the source channel's Tx frequency (resolved
+ * per TDMA frame number if frequency hopping (SETFH) is configured). */
void osmo_trx_ep_rx_burst_req(struct osmo_trx_ep *ep, unsigned int chan,
const struct osmo_trxd_burst_req *br)
{
@@ -81,7 +81,10 @@
return;
}
- tx_freq = src->chans[chan].tx_freq;
+ if (src->chans[chan].fh != NULL)
+ proxy_trx_fh_resolve(src->chans[chan].fh, br->fn, NULL, &tx_freq);
+ else
+ tx_freq = src->chans[chan].tx_freq;
llist_for_each_entry(dst, &g_proxy_ctx->trx_list, list) {
unsigned int dst_chan;
@@ -90,7 +93,15 @@
continue;
for (dst_chan = 0; dst_chan < dst->num_chans; dst_chan++) {
- if (dst->chans[dst_chan].rx_freq != tx_freq)
+ struct proxy_trx_chan *dc = &dst->chans[dst_chan];
+ uint32_t rx_freq;
+
+ if (dc->fh != NULL)
+ proxy_trx_fh_resolve(dc->fh, br->fn, &rx_freq, NULL);
+ else
+ rx_freq = dc->rx_freq;
+
+ if (rx_freq != tx_freq)
continue;
burst_fwd_to_chan(src, chan, dst, dst_chan, br);
}
diff --git a/proxy/src/ctrl_cmd.c b/proxy/src/ctrl_cmd.c
index bf49ce3..fb163e7 100644
--- a/proxy/src/ctrl_cmd.c
+++ b/proxy/src/ctrl_cmd.c
@@ -26,6 +26,9 @@
#include <stdio.h>
#include <string.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/talloc.h>
+
#include <osmocom/trx/ep.h>
#include <osmocom/trx/trxc.h>
#include <osmocom/trx/trxd.h>
@@ -38,6 +41,7 @@
/* Not part of the well-known OSMO_TRXC_CMD_* verbs (libosmo-trx/trxc.h) since
* they are specific to this transceiver's RF path simulation. */
#define CTRL_CMD_SETTA "SETTA"
+#define CTRL_CMD_SETFH "SETFH"
#define CTRL_CMD_MEASURE "MEASURE"
#define CTRL_CMD_FAKE_TOA "FAKE_TOA"
#define CTRL_CMD_FAKE_RSSI "FAKE_RSSI"
@@ -185,6 +189,82 @@
trx->chans[chan].ts[ss.tn].valid = true;
}
+/* Max Mobile Allocation length accepted by SETFH (GSM ARFCN range) */
+#define CTRL_CMD_SETFH_MA_MAX 64
+
+/* Syntax: "CMD SETFH <HSN> <MAIO> <RXF1> <TXF1> [... <RXFN> <TXFN>]",
+ * frequencies in kHz. Configures synthesizer frequency hopping (3GPP TS
+ * 45.002); the per-burst Rx/Tx frequencies are then resolved by TDMA frame
+ * number (see proxy_trx_fh_resolve(), used from burst_fwd.c). */
+static void ctrl_cmd_setfh(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ struct proxy_trx_fh_freq ma[CTRL_CMD_SETFH_MA_MAX];
+ char params[OSMO_TRXC_PARAMS_LEN_MAX];
+ char *saveptr, *tok;
+ unsigned int hsn, maio, ma_len = 0;
+
+ OSMO_STRLCPY_ARRAY(params, cmd->params);
+
+ tok = strtok_r(params, " ", &saveptr);
+ if (tok == NULL || sscanf(tok, "%u", &hsn) != 1 || hsn > 63) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR, "Rx SETFH with invalid HSN\n");
+ rsp->status = 1;
+ return;
+ }
+
+ tok = strtok_r(NULL, " ", &saveptr);
+ if (tok == NULL || sscanf(tok, "%u", &maio) != 1 || maio > 63) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR, "Rx SETFH with invalid MAIO\n");
+ rsp->status = 1;
+ return;
+ }
+
+ while ((tok = strtok_r(NULL, " ", &saveptr)) != NULL) {
+ unsigned int rx_khz, tx_khz;
+ char *tok2;
+
+ if (ma_len >= ARRAY_SIZE(ma) || sscanf(tok, "%u", &rx_khz) != 1) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "Rx SETFH with an invalid/too long Mobile Allocation\n");
+ rsp->status = 1;
+ return;
+ }
+
+ tok2 = strtok_r(NULL, " ", &saveptr);
+ if (tok2 == NULL || sscanf(tok2, "%u", &tx_khz) != 1) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "Rx SETFH with an odd/malformed Mobile Allocation\n");
+ rsp->status = 1;
+ return;
+ }
+
+ ma[ma_len].rx_freq = rx_khz * 1000;
+ ma[ma_len].tx_freq = tx_khz * 1000;
+ ma_len++;
+ }
+
+ if (ma_len == 0) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "Rx SETFH with an empty Mobile Allocation\n");
+ rsp->status = 1;
+ return;
+ }
+
+ talloc_free(trx->chans[chan].fh);
+ trx->chans[chan].fh = proxy_trx_fh_alloc(trx, hsn, maio, ma, ma_len);
+ if (trx->chans[chan].fh == NULL) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to allocate frequency hopping state\n", __func__);
+ rsp->status = 1;
+ return;
+ }
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
+ "Frequency hopping configured: hsn=%u, maio=%u, ma_len=%u\n",
+ hsn, maio, ma_len);
+}
+
/* SETFORMAT negotiates the TRXD PDU version used on the data socket: the
* response status carries the version to use (the requested one, or our
* preferred version if out of range), not a plain ACK/NACK. */
@@ -371,6 +451,8 @@
ctrl_cmd_setformat(trx, chan, cmd, &rsp);
} else if (!strcmp(cmd->cmd, CTRL_CMD_SETTA)) {
ctrl_cmd_setta(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, CTRL_CMD_SETFH)) {
+ ctrl_cmd_setfh(trx, chan, cmd, &rsp);
} else if (!strcmp(cmd->cmd, CTRL_CMD_MEASURE)) {
ctrl_cmd_measure(trx, chan, cmd, &rsp);
} else if (!strcmp(cmd->cmd, CTRL_CMD_FAKE_TOA)) {
diff --git a/proxy/src/trx.c b/proxy/src/trx.c
index 5a5101f..737a7ce 100644
--- a/proxy/src/trx.c
+++ b/proxy/src/trx.c
@@ -30,6 +30,9 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/linuxlist.h>
+#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/gsm0502.h>
+
#include <osmocom/trx/ep.h>
#include <osmocom/proxy/proxy.h>
@@ -147,3 +150,43 @@
trx->num_chans = num_chans;
return 0;
}
+
+struct proxy_trx_fh *proxy_trx_fh_alloc(void *talloc_ctx, uint8_t hsn, uint8_t maio,
+ const struct proxy_trx_fh_freq *ma, unsigned int ma_len)
+{
+ struct proxy_trx_fh *fh;
+
+ if (ma_len == 0)
+ return NULL;
+
+ fh = talloc_zero(talloc_ctx, struct proxy_trx_fh);
+ if (fh == NULL)
+ return NULL;
+
+ fh->ma = talloc_memdup(fh, ma, ma_len * sizeof(*ma));
+ if (fh->ma == NULL) {
+ talloc_free(fh);
+ return NULL;
+ }
+
+ fh->hsn = hsn;
+ fh->maio = maio;
+ fh->ma_len = ma_len;
+
+ return fh;
+}
+
+void proxy_trx_fh_resolve(const struct proxy_trx_fh *fh, uint32_t fn,
+ uint32_t *rx_freq, uint32_t *tx_freq)
+{
+ struct gsm_time gt;
+ uint16_t mai;
+
+ gsm_fn2gsmtime(>, fn);
+ mai = gsm0502_hop_seq_gen(>, fh->hsn, fh->maio, fh->ma_len, NULL);
+
+ if (rx_freq)
+ *rx_freq = fh->ma[mai].rx_freq;
+ if (tx_freq)
+ *tx_freq = fh->ma[mai].tx_freq;
+}
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43611?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: I574b4d4dc337f771b044bd868088b29db9902de9
Gerrit-Change-Number: 43611
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
[M] Change in osmo-trx[master]: proxy: queue BURST.req and dispatch per TDMA frame tick
by fixeria 09 Sep '26
by fixeria 09 Sep '26
09 Sep '26
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43612?usp=email )
Change subject: proxy: queue BURST.req and dispatch per TDMA frame tick
......................................................................
proxy: queue BURST.req and dispatch per TDMA frame tick
Enqueue incoming BURST.req per endpoint instead of forwarding
immediately, and drain the queue on each TDMA clock tick: forward
entries whose fn is due, drop late ones, keep the rest waiting.
Change-Id: Ib147983e97638d2a2e487ccf76184912caf0941d
Related: OS#6672
---
M proxy/Makefile.am
A proxy/include/osmocom/proxy/burst_fwd.h
M proxy/include/osmocom/proxy/trx.h
M proxy/src/burst_fwd.c
M proxy/src/clck_gen.c
M proxy/src/trx.c
6 files changed, 78 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/12/43612/1
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 909c698..c560391 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -3,6 +3,7 @@
$(NULL)
noinst_HEADERS = \
+ include/osmocom/proxy/burst_fwd.h \
include/osmocom/proxy/clck_gen.h \
include/osmocom/proxy/logging.h \
include/osmocom/proxy/path_sim.h \
diff --git a/proxy/include/osmocom/proxy/burst_fwd.h b/proxy/include/osmocom/proxy/burst_fwd.h
new file mode 100644
index 0000000..1f60c76
--- /dev/null
+++ b/proxy/include/osmocom/proxy/burst_fwd.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <stdint.h>
+
+/*! Dispatch every queued BURST.req (see struct proxy_trx::burst_queue) whose
+ * TDMA frame number is due: forward those with fn == fn, drop those with
+ * fn < fn (arrived too late), and leave the rest queued. Call once per
+ * TDMA frame tick from the clock generator (clck_gen.c). */
+void burst_fwd_dispatch_queue(uint32_t fn);
diff --git a/proxy/include/osmocom/proxy/trx.h b/proxy/include/osmocom/proxy/trx.h
index e47a41f..a046653 100644
--- a/proxy/include/osmocom/proxy/trx.h
+++ b/proxy/include/osmocom/proxy/trx.h
@@ -7,6 +7,7 @@
#include <osmocom/core/logging.h>
#include <osmocom/trx/trxc.h>
+#include <osmocom/trx/trxd.h>
#include <osmocom/proxy/path_sim.h>
@@ -52,6 +53,15 @@
struct proxy_trx_fh *fh; /*!< frequency hopping config (SETFH), NULL if disabled */
};
+/*! One BURST.req awaiting its TDMA frame tick, queued to model real
+ * transceivers, where L1 typically submits bursts a few frames ahead of
+ * their actual air time (see burst_fwd.c). */
+struct proxy_trx_burst_queue_entry {
+ struct llist_head list;
+ unsigned int chan;
+ struct osmo_trxd_burst_req br;
+};
+
/*! One virtual transceiver endpoint */
struct proxy_trx {
struct llist_head list;
@@ -61,6 +71,7 @@
int tx_power; /*!< dBm, nominal Tx power (path_sim_state::tx_power) */
unsigned int num_chans; /*!< mirrors osmo_trx_ep_get_num_chans(ep) */
struct proxy_trx_chan *chans; /*!< array of num_chans entries, allocated on open */
+ struct llist_head burst_queue; /*!< struct proxy_trx_burst_queue_entry::list */
};
#define LOGP_TRX(trx, ss, level, fmt, args...) \
diff --git a/proxy/src/burst_fwd.c b/proxy/src/burst_fwd.c
index de057b6..62c5b14 100644
--- a/proxy/src/burst_fwd.c
+++ b/proxy/src/burst_fwd.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <osmocom/core/bits.h>
+#include <osmocom/core/talloc.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/trx/ep.h>
@@ -33,6 +34,7 @@
#include <osmocom/proxy/proxy.h>
#include <osmocom/proxy/trx.h>
#include <osmocom/proxy/path_sim.h>
+#include <osmocom/proxy/burst_fwd.h>
#include <osmocom/proxy/logging.h>
#define OSMO_TRXD_F_COMMON_MASK ( \
@@ -68,19 +70,12 @@
/*! Forward a Tx burst request to every powered-on endpoint/channel
* whose Rx frequency matches the source channel's Tx frequency (resolved
* per TDMA frame number if frequency hopping (SETFH) is configured). */
-void osmo_trx_ep_rx_burst_req(struct osmo_trx_ep *ep, unsigned int chan,
- const struct osmo_trxd_burst_req *br)
+static void burst_fwd_burst_req(struct proxy_trx *src, unsigned int chan,
+ const struct osmo_trxd_burst_req *br)
{
- struct proxy_trx *src = osmo_trx_ep_get_priv(ep);
struct proxy_trx *dst = NULL;
uint32_t tx_freq;
- if (!src->powered) {
- LOGP_TRXCH(src, chan, DTRXD, LOGL_NOTICE,
- "Rx BURST.req while not powered on, dropping\n");
- return;
- }
-
if (src->chans[chan].fh != NULL)
proxy_trx_fh_resolve(src->chans[chan].fh, br->fn, NULL, &tx_freq);
else
@@ -107,3 +102,53 @@
}
}
}
+
+/*! Enqueue a Tx burst request for later dispatch by the TDMA clock
+ * generator: real transceivers typically receive bursts a few frames ahead
+ * of their actual air time, so forwarding must happen at the matching TDMA
+ * frame tick, not immediately upon receipt (see burst_fwd_dispatch_queue()). */
+void osmo_trx_ep_rx_burst_req(struct osmo_trx_ep *ep, unsigned int chan,
+ const struct osmo_trxd_burst_req *br)
+{
+ struct proxy_trx *src = osmo_trx_ep_get_priv(ep);
+ struct proxy_trx_burst_queue_entry *entry;
+
+ if (!src->powered) {
+ LOGP_TRXCH(src, chan, DTRXD, LOGL_NOTICE,
+ "Rx BURST.req while not powered on, dropping\n");
+ return;
+ }
+
+ entry = talloc_zero(src, struct proxy_trx_burst_queue_entry);
+ OSMO_ASSERT(entry != NULL);
+ entry->chan = chan;
+ entry->br = *br;
+
+ llist_add_tail(&entry->list, &src->burst_queue);
+}
+
+void burst_fwd_dispatch_queue(uint32_t fn)
+{
+ struct proxy_trx *trx;
+
+ llist_for_each_entry(trx, &g_proxy_ctx->trx_list, list) {
+ struct proxy_trx_burst_queue_entry *entry, *entry2;
+
+ llist_for_each_entry_safe(entry, entry2, &trx->burst_queue, list) {
+ if (entry->br.fn > fn) /* XXX */
+ continue;
+
+ llist_del(&entry->list);
+
+ if (entry->br.fn < fn) { /* XXX */
+ LOGP_TRXCH(trx, entry->chan, DTRXD, LOGL_ERROR,
+ "Rx BURST.req for fn=%u too late (now fn=%u), "
+ "dropping\n", entry->br.fn, fn);
+ } else {
+ burst_fwd_burst_req(trx, entry->chan, &entry->br);
+ }
+
+ talloc_free(entry);
+ }
+ }
+}
diff --git a/proxy/src/clck_gen.c b/proxy/src/clck_gen.c
index dc70dbb..390ef60 100644
--- a/proxy/src/clck_gen.c
+++ b/proxy/src/clck_gen.c
@@ -35,6 +35,7 @@
#include <osmocom/proxy/proxy.h>
#include <osmocom/proxy/trx.h>
#include <osmocom/proxy/clck_gen.h>
+#include <osmocom/proxy/burst_fwd.h>
#include <osmocom/proxy/logging.h>
/*! Send "IND CLOCK" every N frames (matches fake_trx.py's CLCKGen default) */
@@ -66,7 +67,7 @@
}
}
- /* TODO: drive per-frame burst forwarding (burst_queue/burst_fwd) */
+ burst_fwd_dispatch_queue(gen->fn);
GSM_TDMA_FN_INC(gen->fn);
}
diff --git a/proxy/src/trx.c b/proxy/src/trx.c
index 737a7ce..a748306 100644
--- a/proxy/src/trx.c
+++ b/proxy/src/trx.c
@@ -52,6 +52,7 @@
trx->name = talloc_strdup(trx, name);
trx->tx_power = PROXY_TRX_DEFAULT_TX_POWER;
+ INIT_LLIST_HEAD(&trx->burst_queue);
trx->ep = osmo_trx_ep_alloc(trx, num_chans);
if (trx->ep == NULL) {
talloc_free(trx);
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43612?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: Ib147983e97638d2a2e487ccf76184912caf0941d
Gerrit-Change-Number: 43612
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
[L] Change in osmo-trx[master]: proxy: add TDMA clock generator and basic TRXC handler
by fixeria 09 Sep '26
by fixeria 09 Sep '26
09 Sep '26
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43604?usp=email )
Change subject: proxy: add TDMA clock generator and basic TRXC handler
......................................................................
proxy: add TDMA clock generator and basic TRXC handler
Add clck_gen: a single, process-wide timerfd-driven TDMA clock,
sending "IND CLOCK" every 102 frames to the clock socket of each
currently powered-on endpoint. The clock starts the moment any
endpoint becomes powered and stops once none remain.
Add ctrl_cmd implementing osmo_trx_ep_rx_ctrl_msg(). This module
currently handles POWERON/POWEROFF and RXTUNE/TXTUNE, and simply
ACKs all unknown commands.
Change-Id: I8c0757f15961bf0574f1305a6a8836853b66afcf
Related: OS#6672
---
M proxy/Makefile.am
A proxy/include/osmocom/proxy/clck_gen.h
M proxy/include/osmocom/proxy/trx.h
M proxy/src/Makefile.am
A proxy/src/clck_gen.c
A proxy/src/ctrl_cmd.c
M proxy/src/main.c
M proxy/src/trx.c
M proxy/src/vty.c
9 files changed, 336 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/04/43604/1
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 23a1d3a..e99dd63 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -3,6 +3,7 @@
$(NULL)
noinst_HEADERS = \
+ include/osmocom/proxy/clck_gen.h \
include/osmocom/proxy/logging.h \
include/osmocom/proxy/proxy.h \
include/osmocom/proxy/trx.h \
diff --git a/proxy/include/osmocom/proxy/clck_gen.h b/proxy/include/osmocom/proxy/clck_gen.h
new file mode 100644
index 0000000..7bc5e74
--- /dev/null
+++ b/proxy/include/osmocom/proxy/clck_gen.h
@@ -0,0 +1,9 @@
+#pragma once
+
+int clck_gen_init(void);
+
+/*! Re-evaluate g_proxy_ctx->trx_list and (re)start or stop the (single,
+ * process-wide) TDMA clock generator: running iff at least one endpoint is
+ * currently powered on. Call this after changing any struct proxy_trx's
+ * ->powered field. */
+void clck_gen_trx_list_updated(void);
diff --git a/proxy/include/osmocom/proxy/trx.h b/proxy/include/osmocom/proxy/trx.h
index e687825..4c867db 100644
--- a/proxy/include/osmocom/proxy/trx.h
+++ b/proxy/include/osmocom/proxy/trx.h
@@ -1,24 +1,48 @@
#pragma once
+#include <stdint.h>
+#include <stdbool.h>
+
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/logging.h>
struct osmo_trx_ep;
struct proxy_ctx;
+/*! Per-channel state: each channel is conceptually its own (child)
+ * transceiver with an independent Rx/Tx frequency, sharing the endpoint's
+ * power state and clock. */
+struct proxy_trx_chan {
+ uint32_t rx_freq; /*!< Rx frequency in Hz, 0 if not (yet) tuned */
+ uint32_t tx_freq; /*!< Tx frequency in Hz, 0 if not (yet) tuned */
+};
+
/*! One virtual transceiver endpoint */
struct proxy_trx {
struct llist_head list;
char *name;
struct osmo_trx_ep *ep;
+ bool powered; /*!< POWERON/POWEROFF applies to all channels at once */
+ unsigned int num_chans; /*!< mirrors osmo_trx_ep_get_num_chans(ep) */
+ struct proxy_trx_chan *chans; /*!< array of num_chans entries, allocated on open */
};
#define LOGP_TRX(trx, ss, level, fmt, args...) \
LOGP(ss, level, "(trx=%s) " fmt, (trx)->name, ##args)
+#define LOGP_TRXCH(trx, chan, ss, level, fmt, args...) \
+ LOGP(ss, level, "(trx=%s, chan=%u) " fmt, (trx)->name, chan, ##args)
+
struct proxy_trx *proxy_trx_find(struct proxy_ctx *proxy, const char *name);
struct proxy_trx *proxy_trx_alloc(struct proxy_ctx *proxy, const char *name);
void proxy_trx_free(struct proxy_trx *trx);
int proxy_trx_open(struct proxy_trx *trx);
void proxy_trx_close(struct proxy_trx *trx);
+
+/*! Change the number of channels; must be called before proxy_trx_open(). */
+int proxy_trx_set_num_chans(struct proxy_trx *trx, unsigned int num_chans);
+
+/*! Update the endpoint's power state; (de)registers it with the TDMA clock
+ * generator as appropriate. */
+void proxy_trx_set_power(struct proxy_trx *trx, bool on);
diff --git a/proxy/src/Makefile.am b/proxy/src/Makefile.am
index 0350474..4be255f 100644
--- a/proxy/src/Makefile.am
+++ b/proxy/src/Makefile.am
@@ -18,6 +18,8 @@
proxy.c \
vty.c \
trx.c \
+ clck_gen.c \
+ ctrl_cmd.c \
logging.c \
$(NULL)
diff --git a/proxy/src/clck_gen.c b/proxy/src/clck_gen.c
new file mode 100644
index 0000000..dc70dbb
--- /dev/null
+++ b/proxy/src/clck_gen.c
@@ -0,0 +1,126 @@
+/*! \file src/clck_gen.c
+ * osmo-trx-proxy: shared TDMA clock generator. */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <unistd.h>
+#include <stdint.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/select.h>
+#include <osmocom/gsm/gsm0502.h>
+
+#include <osmocom/trx/ep.h>
+
+#include <osmocom/proxy/proxy.h>
+#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/clck_gen.h>
+#include <osmocom/proxy/logging.h>
+
+/*! Send "IND CLOCK" every N frames (matches fake_trx.py's CLCKGen default) */
+#define CLCK_GEN_IND_PERIOD 102
+
+struct clck_gen {
+ struct osmo_fd timerfd;
+ uint32_t fn;
+ bool running;
+};
+
+static struct clck_gen g_clck_gen;
+
+static int clck_gen_timer_cb(struct osmo_fd *ofd, unsigned int what)
+{
+ struct clck_gen *gen = ofd->data;
+ uint64_t expire_count;
+
+ if (read(ofd->fd, &expire_count, sizeof(expire_count)) != sizeof(expire_count))
+ return 0;
+
+ while (expire_count-- > 0) {
+ struct proxy_trx *trx;
+
+ if (gen->fn % CLCK_GEN_IND_PERIOD == 0) {
+ llist_for_each_entry(trx, &g_proxy_ctx->trx_list, list) {
+ if (trx->powered && osmo_trx_ep_get_clock_socket(trx->ep))
+ osmo_trx_ep_send_clck_ind(trx->ep, gen->fn);
+ }
+ }
+
+ /* TODO: drive per-frame burst forwarding (burst_queue/burst_fwd) */
+
+ GSM_TDMA_FN_INC(gen->fn);
+ }
+
+ return 0;
+}
+
+static void clck_gen_start(struct clck_gen *gen)
+{
+ const struct timespec first = { .tv_nsec = GSM_TDMA_FN_DURATION_nS };
+ const struct timespec interval = { .tv_nsec = GSM_TDMA_FN_DURATION_nS };
+
+ if (gen->running)
+ return;
+
+ gen->fn = 0;
+ if (osmo_timerfd_schedule(&gen->timerfd, &first, &interval) < 0) {
+ LOGP(DTRXC, LOGL_ERROR, "Failed to start the TDMA clock generator\n");
+ return;
+ }
+
+ gen->running = true;
+ LOGP(DTRXC, LOGL_NOTICE, "TDMA clock generator started\n");
+}
+
+static void clck_gen_stop(struct clck_gen *gen)
+{
+ if (!gen->running)
+ return;
+
+ osmo_timerfd_disable(&gen->timerfd);
+ gen->running = false;
+ LOGP(DTRXC, LOGL_NOTICE, "TDMA clock generator stopped\n");
+}
+
+void clck_gen_trx_list_updated(void)
+{
+ bool any_active = false;
+ struct proxy_trx *trx;
+
+ llist_for_each_entry(trx, &g_proxy_ctx->trx_list, list) {
+ any_active |= trx->powered;
+ }
+
+ if (any_active)
+ clck_gen_start(&g_clck_gen);
+ else
+ clck_gen_stop(&g_clck_gen);
+}
+
+int clck_gen_init(void)
+{
+ g_clck_gen.timerfd.fd = -1;
+ return osmo_timerfd_setup(&g_clck_gen.timerfd,
+ &clck_gen_timer_cb,
+ &g_clck_gen);
+}
diff --git a/proxy/src/ctrl_cmd.c b/proxy/src/ctrl_cmd.c
new file mode 100644
index 0000000..281cc13
--- /dev/null
+++ b/proxy/src/ctrl_cmd.c
@@ -0,0 +1,130 @@
+/*! \file src/ctrl_cmd.c
+ * osmo-trx-proxy: TRXC command handling. */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <osmocom/trx/ep.h>
+#include <osmocom/trx/trxc.h>
+
+#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/logging.h>
+
+static void ctrl_cmd_poweron(struct proxy_trx *trx, struct osmo_trxc_msg *rsp)
+{
+ if (trx->powered) {
+ LOGP_TRX(trx, DTRXC, LOGL_ERROR,
+ "Rx POWERON: already powered on\n");
+ rsp->status = 1;
+ return;
+ }
+
+ for (unsigned int chan = 0; chan < trx->num_chans; chan++) {
+ if (trx->chans[chan].rx_freq == 0 || trx->chans[chan].tx_freq == 0) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "Rx POWERON: Rx/Tx frequency not (yet) set\n");
+ rsp->status = 1;
+ return;
+ }
+ }
+
+ proxy_trx_set_power(trx, true);
+}
+
+static void ctrl_cmd_poweroff(struct proxy_trx *trx, struct osmo_trxc_msg *rsp)
+{
+ proxy_trx_set_power(trx, false);
+}
+
+static void ctrl_cmd_rxtune(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ unsigned int freq_khz = 0;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%u", &freq_khz) != 1) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse Rx frequency: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ return;
+ }
+
+ trx->chans[chan].rx_freq = freq_khz * 1000;
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
+ "Rx frequency set to %u kHz\n", freq_khz);
+ snprintf(rsp->params, sizeof(rsp->params), "%u", freq_khz);
+}
+
+static void ctrl_cmd_txtune(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ unsigned int freq_khz = 0;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%u", &freq_khz) != 1) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse Tx frequency: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ return;
+ }
+
+ trx->chans[chan].tx_freq = freq_khz * 1000;
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
+ "Tx frequency set to %u kHz\n", freq_khz);
+ snprintf(rsp->params, sizeof(rsp->params), "%u", freq_khz);
+}
+
+void osmo_trx_ep_rx_ctrl_msg(struct osmo_trx_ep *ep, unsigned int chan,
+ const struct osmo_trxc_msg *cmd)
+{
+ struct proxy_trx *trx = osmo_trx_ep_get_priv(ep);
+ struct osmo_trxc_msg rsp = *cmd;
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_DEBUG,
+ "Rx '%s'\n", osmo_trxc_msg_name(cmd));
+
+ rsp.type = OSMO_TRXC_MT_RSP;
+ rsp.status = 0; /* ACK all commands by default */
+ OSMO_STRLCPY_ARRAY(rsp.cmd, cmd->cmd);
+ OSMO_STRLCPY_ARRAY(rsp.params, cmd->params);
+
+ if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_POWERON)) {
+ ctrl_cmd_poweron(trx, &rsp);
+ } else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_POWEROFF)) {
+ ctrl_cmd_poweroff(trx, &rsp);
+ } else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_RXTUNE)) {
+ ctrl_cmd_rxtune(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_TXTUNE)) {
+ ctrl_cmd_txtune(trx, chan, cmd, &rsp);
+ } else {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
+ "Unhandled command '%s'\n", cmd->cmd);
+ }
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_DEBUG,
+ "Tx '%s'\n", osmo_trxc_msg_name(&rsp));
+
+ osmo_trx_ep_send_ctrl_msg(ep, chan, &rsp);
+}
diff --git a/proxy/src/main.c b/proxy/src/main.c
index 35eec1b..e0c5937 100644
--- a/proxy/src/main.c
+++ b/proxy/src/main.c
@@ -42,6 +42,7 @@
#include <osmocom/proxy/proxy.h>
#include <osmocom/proxy/vty.h>
#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/clck_gen.h>
#include <osmocom/proxy/logging.h>
void *g_talloc_ctx;
@@ -119,6 +120,11 @@
proxy_vty_init();
+ if (clck_gen_init() < 0) {
+ LOGP(DPROXY, LOGL_FATAL, "Failed to set up the TDMA clock generator\n");
+ return 1;
+ }
+
handle_options(argc, argv);
rc = vty_read_config_file(g_config_file, NULL);
diff --git a/proxy/src/trx.c b/proxy/src/trx.c
index 6eab496..facbc45 100644
--- a/proxy/src/trx.c
+++ b/proxy/src/trx.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <string.h>
+#include <osmocom/core/utils.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/linuxlist.h>
@@ -33,10 +34,12 @@
#include <osmocom/proxy/proxy.h>
#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/clck_gen.h>
#include <osmocom/proxy/logging.h>
struct proxy_trx *proxy_trx_alloc(struct proxy_ctx *proxy, const char *name)
{
+ const unsigned int num_chans = 1;
struct proxy_trx *trx;
trx = talloc_zero(proxy, struct proxy_trx);
@@ -44,11 +47,12 @@
return NULL;
trx->name = talloc_strdup(trx, name);
- trx->ep = osmo_trx_ep_alloc(trx, 1);
+ trx->ep = osmo_trx_ep_alloc(trx, num_chans);
if (trx->ep == NULL) {
talloc_free(trx);
return NULL;
}
+ proxy_trx_set_num_chans(trx, num_chans);
osmo_trx_ep_set_priv(trx->ep, trx);
osmo_trx_ep_set_name(trx->ep, "%s", name);
@@ -86,11 +90,24 @@
{
if (!trx)
return;
+ proxy_trx_set_power(trx, false);
osmo_trx_ep_free(trx->ep);
llist_del(&trx->list);
talloc_free(trx);
}
+void proxy_trx_set_power(struct proxy_trx *trx, bool on)
+{
+ if (trx->powered == on)
+ return;
+
+ LOGP_TRX(trx, DTRXC, LOGL_INFO,
+ "Power %s\n", on ? "on" : "off");
+
+ trx->powered = on;
+ clck_gen_trx_list_updated();
+}
+
int proxy_trx_open(struct proxy_trx *trx)
{
int rc;
@@ -104,5 +121,22 @@
return rc;
}
+ if (rc == 0) { /* first successful open: num_chans is now fixed */
+ trx->chans = talloc_zero_array(trx, struct proxy_trx_chan, trx->num_chans);
+ OSMO_ASSERT(trx->chans != NULL);
+ }
+
+ return 0;
+}
+
+int proxy_trx_set_num_chans(struct proxy_trx *trx, unsigned int num_chans)
+{
+ int rc;
+
+ rc = osmo_trx_ep_set_num_chans(trx->ep, num_chans);
+ if (rc)
+ return rc;
+
+ trx->num_chans = num_chans;
return 0;
}
diff --git a/proxy/src/vty.c b/proxy/src/vty.c
index cac9372..7d57cd2 100644
--- a/proxy/src/vty.c
+++ b/proxy/src/vty.c
@@ -179,9 +179,9 @@
int num_chans = atoi(argv[0]);
int rc;
- rc = osmo_trx_ep_set_num_chans(trx->ep, num_chans);
+ rc = proxy_trx_set_num_chans(trx, num_chans);
if (rc) {
- vty_out(vty, "%% osmo_trx_ep_set_num_chans(%d) failed: rc=%d%s",
+ vty_out(vty, "%% proxy_trx_set_num_chans(%d) failed: rc=%d%s",
num_chans, rc, VTY_NEWLINE);
return CMD_WARNING;
}
@@ -231,7 +231,7 @@
if (laddr && strcmp(laddr, g_proxy_ctx->bind_addr) != 0)
vty_out(vty, " bind-addr %s%s", laddr, VTY_NEWLINE);
vty_out(vty, " base-port %u%s", osmo_trx_ep_get_base_port(trx->ep), VTY_NEWLINE);
- vty_out(vty, " num-chans %u%s", osmo_trx_ep_get_num_chans(trx->ep), VTY_NEWLINE);
+ vty_out(vty, " num-chans %u%s", trx->num_chans, VTY_NEWLINE);
if (!osmo_trx_ep_get_clock_socket(trx->ep))
vty_out(vty, " no clock-socket%s", VTY_NEWLINE);
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43604?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: I8c0757f15961bf0574f1305a6a8836853b66afcf
Gerrit-Change-Number: 43604
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
[M] Change in osmo-trx[master]: proxy: implement burst forwarding (proxying) logic
by fixeria 09 Sep '26
by fixeria 09 Sep '26
09 Sep '26
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43605?usp=email )
Change subject: proxy: implement burst forwarding (proxying) logic
......................................................................
proxy: implement burst forwarding (proxying) logic
Implement osmo_trx_ep_rx_burst_req(): forward a Tx burst request
immediately (no per-endpoint queueing yet) to every other powered-on
endpoint/channel whose Rx frequency matches the source channel's Tx
frequency. Hard bits are converted to soft bits via osmo_ubit2sbit();
toa256/rssi are left at placeholder nominal values until the upcoming
path simulation logic computes them for real.
Change-Id: I1df0389ef523a59402081deb8f74b84e136ea7dd
Related: OS#6672
---
M proxy/src/Makefile.am
A proxy/src/burst_fwd.c
2 files changed, 100 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/05/43605/1
diff --git a/proxy/src/Makefile.am b/proxy/src/Makefile.am
index 4be255f..5c8b931 100644
--- a/proxy/src/Makefile.am
+++ b/proxy/src/Makefile.am
@@ -20,6 +20,7 @@
trx.c \
clck_gen.c \
ctrl_cmd.c \
+ burst_fwd.c \
logging.c \
$(NULL)
diff --git a/proxy/src/burst_fwd.c b/proxy/src/burst_fwd.c
new file mode 100644
index 0000000..2a9f22d
--- /dev/null
+++ b/proxy/src/burst_fwd.c
@@ -0,0 +1,99 @@
+/*! \file src/burst_fwd.c
+ * osmo-trx-proxy: forward Tx bursts by Rx/Tx frequency match. */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/core/linuxlist.h>
+
+#include <osmocom/trx/ep.h>
+
+#include <osmocom/proxy/proxy.h>
+#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/logging.h>
+
+/* Placeholder measurement values, until path_sim.c computes them for real
+ * (matches fake_trx.py's FakeTRX nominal defaults: no timing offset, and
+ * -60 dBm = 50 dBm nominal Tx power - 0 dB Tx attenuation - 110 dB path loss). */
+#define BURST_FWD_TOA256_DEFAULT 0
+#define BURST_FWD_RSSI_DEFAULT -60
+
+#define OSMO_TRXD_F_COMMON_MASK ( \
+ OSMO_TRXD_F_NOPE_REQ | \
+ OSMO_TRXD_F_MOD_TYPE | \
+ OSMO_TRXD_F_TS_INFO | \
+ OSMO_TRXD_F_TRX_NUM \
+ )
+
+static void burst_fwd_to_chan(struct proxy_trx *dst, unsigned int dst_chan,
+ const struct osmo_trxd_burst_req *br)
+{
+ struct osmo_trxd_burst_ind bi = {
+ .flags = br->flags & OSMO_TRXD_F_COMMON_MASK,
+ .fn = br->fn,
+ .tn = br->tn,
+ .toa256 = BURST_FWD_TOA256_DEFAULT,
+ .rssi = BURST_FWD_RSSI_DEFAULT,
+ .burst_len = br->burst_len,
+ .mod = br->mod,
+ .tsc_set = br->tsc_set,
+ .tsc = br->tsc,
+ .trx_num = br->trx_num,
+ };
+
+ osmo_ubit2sbit(bi.burst, br->burst, br->burst_len);
+
+ osmo_trx_ep_send_burst_ind(dst->ep, dst_chan, &bi);
+}
+
+/*! Forward a Tx burst request to every powered-on endpoint/channel
+ * whose Rx frequency matches the source channel's Tx frequency.
+ * TODO: (no frequency hopping support yet, see SETFH in fake_trx.py). */
+void osmo_trx_ep_rx_burst_req(struct osmo_trx_ep *ep, unsigned int chan,
+ const struct osmo_trxd_burst_req *br)
+{
+ const struct proxy_trx *src = osmo_trx_ep_get_priv(ep);
+ const uint32_t tx_freq = src->chans[chan].tx_freq;
+ struct proxy_trx *dst;
+
+ if (!src->powered) {
+ LOGP_TRXCH(src, chan, DTRXD, LOGL_NOTICE,
+ "Rx BURST.req while not powered on, dropping\n");
+ return;
+ }
+
+ llist_for_each_entry(dst, &g_proxy_ctx->trx_list, list) {
+ unsigned int dst_chan;
+
+ if (dst == src || !dst->powered)
+ continue;
+
+ for (dst_chan = 0; dst_chan < dst->num_chans; dst_chan++) {
+ if (dst->chans[dst_chan].rx_freq != tx_freq)
+ continue;
+ burst_fwd_to_chan(dst, dst_chan, br);
+ }
+ }
+}
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43605?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: I1df0389ef523a59402081deb8f74b84e136ea7dd
Gerrit-Change-Number: 43605
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
09 Sep '26
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43603?usp=email )
Change subject: osmo-trx-proxy: initial app skeleton
......................................................................
osmo-trx-proxy: initial app skeleton
osmo-trx-proxy is a C rewrite of the fake_trx.py: a virtual
TRX endpoint that BTS/MS-side L1 implementations (osmo-bts-trx,
trxcon) can connect to over the TRXC/TRXD protocol instead of real RF
hardware, useful for testing without SDR devices. This first commit
adds just the daemon skeleton (config context, VTY, logging).
Change-Id: Id2b12e5e7d053eea53338fbabc48131b9c46c82a
Related: OS#6672
---
M .gitignore
M Makefile.am
M configure.ac
A proxy/Makefile.am
A proxy/include/osmocom/proxy/logging.h
A proxy/include/osmocom/proxy/proxy.h
A proxy/include/osmocom/proxy/trx.h
A proxy/include/osmocom/proxy/vty.h
A proxy/src/Makefile.am
A proxy/src/logging.c
A proxy/src/main.c
A proxy/src/proxy.c
A proxy/src/trx.c
A proxy/src/vty.c
14 files changed, 848 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/03/43603/1
diff --git a/.gitignore b/.gitignore
index 164e863..8c51628 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@
Transceiver52M/osmo-trx-ms-uhd
Transceiver52M/osmo-trx-ms-ipc
Transceiver52M/device/ipc/uhddev_ipc.cpp
+proxy/src/osmo-trx-proxy
.clang-format
diff --git a/Makefile.am b/Makefile.am
index 844d6e7..2585fdf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,13 @@
# Order must be preserved
SUBDIRS += \
libosmo-trx \
+ $(NULL)
+
+if ENABLE_PROXY
+SUBDIRS += proxy
+endif
+
+SUBDIRS += \
CommonLibs \
GSM \
Transceiver52M \
diff --git a/configure.ac b/configure.ac
index 22e6bc2..59c5b4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,6 +162,11 @@
[enable MS TRX])
])
+AC_ARG_WITH(proxy, [
+ AS_HELP_STRING([--with-proxy],
+ [enable osmo-trx-proxy [default=enabled]])
+])
+
AC_ARG_WITH(neon, [
AS_HELP_STRING([--with-neon],
[enable ARM NEON support])
@@ -289,6 +294,7 @@
AM_CONDITIONAL(ARCH_ARM, [test "x$with_neon" = "xyes" || test "x$with_neon_vfpv4" = "xyes"])
AM_CONDITIONAL(ARCH_ARM_A15, [test "x$with_neon_vfpv4" = "xyes"])
AM_CONDITIONAL(ENABLE_MS_TRX, [test "x$with_mstrx" = "xyes"])
+AM_CONDITIONAL(ENABLE_PROXY, [test "x$with_proxy" != "xno"])
# Disable Multi ARFCN support
AC_ARG_ENABLE(multi-arfcn,
@@ -376,6 +382,8 @@
libosmo-trx/src/Makefile \
libosmo-trx/libosmo-trx.pc \
libosmo-trx/Doxyfile.trx \
+ proxy/Makefile \
+ proxy/src/Makefile \
CommonLibs/Makefile \
GSM/Makefile \
Transceiver52M/Makefile \
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
new file mode 100644
index 0000000..23a1d3a
--- /dev/null
+++ b/proxy/Makefile.am
@@ -0,0 +1,10 @@
+SUBDIRS = \
+ src \
+ $(NULL)
+
+noinst_HEADERS = \
+ include/osmocom/proxy/logging.h \
+ include/osmocom/proxy/proxy.h \
+ include/osmocom/proxy/trx.h \
+ include/osmocom/proxy/vty.h \
+ $(NULL)
diff --git a/proxy/include/osmocom/proxy/logging.h b/proxy/include/osmocom/proxy/logging.h
new file mode 100644
index 0000000..6e94ba0
--- /dev/null
+++ b/proxy/include/osmocom/proxy/logging.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <osmocom/core/logging.h>
+
+extern const struct log_info log_info;
+
+enum {
+ DPROXY, /* main/vty/config */
+ DTRXC, /* TRXC (control) + clock handling */
+ DTRXD, /* TRXD (burst data) handling / forwarding */
+};
diff --git a/proxy/include/osmocom/proxy/proxy.h b/proxy/include/osmocom/proxy/proxy.h
new file mode 100644
index 0000000..1d742e4
--- /dev/null
+++ b/proxy/include/osmocom/proxy/proxy.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <stdbool.h>
+
+#include <osmocom/core/linuxlist.h>
+
+#define PROXY_DEFAULT_BIND_ADDR "0.0.0.0"
+
+/* Endpoints created when the config file defines none explicitly */
+#define PROXY_DEFAULT_REMOTE_ADDR "127.0.0.1"
+#define PROXY_DEFAULT_BTS_NAME "bts"
+#define PROXY_DEFAULT_BTS_PORT 5700
+#define PROXY_DEFAULT_MS_NAME "ms"
+#define PROXY_DEFAULT_MS_PORT 6700
+
+struct proxy_ctx {
+ char *bind_addr;
+ struct llist_head trx_list; /*!< struct proxy_trx::list */
+};
+
+extern struct proxy_ctx *g_proxy_ctx;
+
+struct proxy_ctx *proxy_ctx_alloc(void *talloc_ctx);
+bool proxy_ctx_add_defaults_if_empty(struct proxy_ctx *proxy);
diff --git a/proxy/include/osmocom/proxy/trx.h b/proxy/include/osmocom/proxy/trx.h
new file mode 100644
index 0000000..e687825
--- /dev/null
+++ b/proxy/include/osmocom/proxy/trx.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/logging.h>
+
+struct osmo_trx_ep;
+struct proxy_ctx;
+
+/*! One virtual transceiver endpoint */
+struct proxy_trx {
+ struct llist_head list;
+ char *name;
+ struct osmo_trx_ep *ep;
+};
+
+#define LOGP_TRX(trx, ss, level, fmt, args...) \
+ LOGP(ss, level, "(trx=%s) " fmt, (trx)->name, ##args)
+
+struct proxy_trx *proxy_trx_find(struct proxy_ctx *proxy, const char *name);
+struct proxy_trx *proxy_trx_alloc(struct proxy_ctx *proxy, const char *name);
+void proxy_trx_free(struct proxy_trx *trx);
+
+int proxy_trx_open(struct proxy_trx *trx);
+void proxy_trx_close(struct proxy_trx *trx);
diff --git a/proxy/include/osmocom/proxy/vty.h b/proxy/include/osmocom/proxy/vty.h
new file mode 100644
index 0000000..e23b350
--- /dev/null
+++ b/proxy/include/osmocom/proxy/vty.h
@@ -0,0 +1,3 @@
+#pragma once
+
+int proxy_vty_init(void);
diff --git a/proxy/src/Makefile.am b/proxy/src/Makefile.am
new file mode 100644
index 0000000..0350474
--- /dev/null
+++ b/proxy/src/Makefile.am
@@ -0,0 +1,29 @@
+AM_CPPFLAGS = \
+ -Wall \
+ -I$(top_srcdir)/proxy/include \
+ -I$(top_srcdir)/libosmo-trx/include \
+ -I$(top_builddir)/libosmo-trx/include \
+ $(NULL)
+
+AM_CFLAGS = \
+ $(LIBOSMOCORE_CFLAGS) \
+ $(LIBOSMOVTY_CFLAGS) \
+ $(LIBOSMOGSM_CFLAGS) \
+ $(NULL)
+
+bin_PROGRAMS = osmo-trx-proxy
+
+osmo_trx_proxy_SOURCES = \
+ main.c \
+ proxy.c \
+ vty.c \
+ trx.c \
+ logging.c \
+ $(NULL)
+
+osmo_trx_proxy_LDADD = \
+ $(top_builddir)/libosmo-trx/src/libosmo-trx.la \
+ $(LIBOSMOCORE_LIBS) \
+ $(LIBOSMOVTY_LIBS) \
+ $(LIBOSMOGSM_LIBS) \
+ $(NULL)
diff --git a/proxy/src/logging.c b/proxy/src/logging.c
new file mode 100644
index 0000000..b1d3fbb
--- /dev/null
+++ b/proxy/src/logging.c
@@ -0,0 +1,57 @@
+/*! \file src/logging.c
+ * osmo-trx-proxy: log category definitions. */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
+
+#include <osmocom/proxy/logging.h>
+
+static const struct log_info_cat default_categories[] = {
+ [DPROXY] = {
+ .name = "DPROXY",
+ .description = "Main generic category",
+ .loglevel = LOGL_INFO,
+ .enabled = 1,
+ },
+ [DTRXC] = {
+ .name = "DTRXC",
+ .description = "TRXC (control) interface + clock handling",
+ .color = "\033[1;33m",
+ .loglevel = LOGL_NOTICE,
+ .enabled = 1,
+ },
+ [DTRXD] = {
+ .name = "DTRXD",
+ .description = "TRXD (burst data) interface handling / forwarding",
+ .color = "\033[1;33m",
+ .loglevel = LOGL_NOTICE,
+ .enabled = 1,
+ },
+};
+
+const struct log_info log_info = {
+ .cat = default_categories,
+ .num_cat = ARRAY_SIZE(default_categories),
+};
diff --git a/proxy/src/main.c b/proxy/src/main.c
new file mode 100644
index 0000000..35eec1b
--- /dev/null
+++ b/proxy/src/main.c
@@ -0,0 +1,148 @@
+/*! \file src/main.c
+ * osmo-trx-proxy: main program entry point. */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <getopt.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/select.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/application.h>
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/command.h>
+#include <osmocom/vty/cpu_sched_vty.h>
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/ports.h>
+
+#include <osmocom/proxy/proxy.h>
+#include <osmocom/proxy/vty.h>
+#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/logging.h>
+
+void *g_talloc_ctx;
+static char *g_config_file = "osmo-trx-proxy.cfg";
+static volatile sig_atomic_t g_quit = 0;
+
+static void print_help(void)
+{
+ printf("Usage: osmo-trx-proxy [options]\n");
+ printf(" -h, --help This text\n");
+ printf(" -c, --config-file FILE Specify the configuration file (default: %s)\n",
+ g_config_file);
+}
+
+static void handle_options(int argc, char **argv)
+{
+ while (1) {
+ int option_index = 0;
+ static const struct option long_options[] = {
+ { "help", 0, 0, 'h' },
+ { "config-file", 1, 0, 'c' },
+ { 0, 0, 0, 0 }
+ };
+
+ int c = getopt_long(argc, argv, "hc:", long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_help();
+ exit(0);
+ case 'c':
+ g_config_file = optarg;
+ break;
+ default:
+ exit(2);
+ }
+ }
+}
+
+static void signal_handler(int signum)
+{
+ switch (signum) {
+ case SIGINT:
+ case SIGTERM:
+ g_quit = 1;
+ break;
+ default:
+ break;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int rc;
+
+ g_talloc_ctx = talloc_named_const(NULL, 0, "osmo-trx-proxy");
+ msgb_talloc_ctx_init(g_talloc_ctx, 0);
+
+ signal(SIGINT, &signal_handler);
+ signal(SIGTERM, &signal_handler);
+ osmo_init_ignore_signals();
+
+ g_proxy_ctx = proxy_ctx_alloc(g_talloc_ctx);
+ OSMO_ASSERT(g_proxy_ctx != NULL);
+
+ osmo_init_logging2(g_talloc_ctx, &log_info);
+ log_set_print_extended_timestamp(osmo_stderr_target, 1);
+ log_set_print_category_hex(osmo_stderr_target, 0);
+ log_set_print_category(osmo_stderr_target, 1);
+ log_set_print_level(osmo_stderr_target, 1);
+ log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
+ log_set_print_filename_pos(osmo_stderr_target, LOG_FILENAME_POS_LINE_END);
+
+ proxy_vty_init();
+
+ handle_options(argc, argv);
+
+ rc = vty_read_config_file(g_config_file, NULL);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to open config file: '%s'\n", g_config_file);
+ return 2;
+ }
+
+ rc = telnet_init_default(g_talloc_ctx, NULL, OSMO_VTY_PORT_TRX);
+ if (rc < 0)
+ return 1;
+
+ osmo_cpu_sched_vty_apply_localthread();
+
+ /* Only apply the built-in BTS/MS defaults if the config file did not
+ * declare any 'ep' stanza of its own. */
+ if (!proxy_ctx_add_defaults_if_empty(g_proxy_ctx))
+ return 1;
+
+ LOGP(DPROXY, LOGL_NOTICE, "osmo-trx-proxy started\n");
+
+ while (!g_quit)
+ osmo_select_main(0);
+
+ LOGP(DPROXY, LOGL_NOTICE, "Shutting down...\n");
+ return 0;
+}
diff --git a/proxy/src/proxy.c b/proxy/src/proxy.c
new file mode 100644
index 0000000..ca21bcd
--- /dev/null
+++ b/proxy/src/proxy.c
@@ -0,0 +1,82 @@
+/*! \file src/proxy.c
+ * osmo-trx-proxy: top-level daemon context (struct proxy_ctx). */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/linuxlist.h>
+
+#include <osmocom/trx/ep.h>
+
+#include <osmocom/proxy/proxy.h>
+#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/logging.h>
+
+struct proxy_ctx *g_proxy_ctx = NULL;
+
+struct proxy_ctx *proxy_ctx_alloc(void *talloc_ctx)
+{
+ struct proxy_ctx *proxy;
+
+ proxy = talloc_zero(talloc_ctx, struct proxy_ctx);
+ if (proxy == NULL)
+ return NULL;
+
+ proxy->bind_addr = talloc_strdup(proxy, PROXY_DEFAULT_BIND_ADDR);
+ INIT_LLIST_HEAD(&proxy->trx_list);
+
+ return proxy;
+}
+
+/*! Populate the config with the default BTS/MS endpoints (base ports 5700
+ * and 6700) and open them, iff the config file did not declare any
+ * endpoint explicitly. */
+bool proxy_ctx_add_defaults_if_empty(struct proxy_ctx *proxy)
+{
+ struct proxy_trx *trx;
+
+ if (!llist_empty(&proxy->trx_list))
+ return true;
+
+ LOGP(DPROXY, LOGL_NOTICE,
+ "No endpoints configured, creating defaults ('%s' and '%s')\n",
+ PROXY_DEFAULT_BTS_NAME, PROXY_DEFAULT_MS_NAME);
+
+ trx = proxy_trx_alloc(proxy, PROXY_DEFAULT_BTS_NAME);
+ osmo_trx_ep_set_raddr(trx->ep, PROXY_DEFAULT_REMOTE_ADDR);
+ osmo_trx_ep_set_base_port(trx->ep, PROXY_DEFAULT_BTS_PORT);
+ if (proxy_trx_open(trx) != 0)
+ return false;
+
+ trx = proxy_trx_alloc(proxy, PROXY_DEFAULT_MS_NAME);
+ osmo_trx_ep_set_raddr(trx->ep, PROXY_DEFAULT_REMOTE_ADDR);
+ osmo_trx_ep_set_base_port(trx->ep, PROXY_DEFAULT_MS_PORT);
+ /* MS (trxcon) side has no use for TRX clock indications */
+ osmo_trx_ep_set_clock_socket(trx->ep, false);
+ if (proxy_trx_open(trx) != 0)
+ return false;
+
+ return true;
+}
diff --git a/proxy/src/trx.c b/proxy/src/trx.c
new file mode 100644
index 0000000..6eab496
--- /dev/null
+++ b/proxy/src/trx.c
@@ -0,0 +1,108 @@
+/*! \file src/trx.c
+ * osmo-trx-proxy: virtual transceiver management. */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <string.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/linuxlist.h>
+
+#include <osmocom/trx/ep.h>
+
+#include <osmocom/proxy/proxy.h>
+#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/logging.h>
+
+struct proxy_trx *proxy_trx_alloc(struct proxy_ctx *proxy, const char *name)
+{
+ struct proxy_trx *trx;
+
+ trx = talloc_zero(proxy, struct proxy_trx);
+ if (trx == NULL)
+ return NULL;
+
+ trx->name = talloc_strdup(trx, name);
+ trx->ep = osmo_trx_ep_alloc(trx, 1);
+ if (trx->ep == NULL) {
+ talloc_free(trx);
+ return NULL;
+ }
+
+ osmo_trx_ep_set_priv(trx->ep, trx);
+ osmo_trx_ep_set_name(trx->ep, "%s", name);
+ osmo_trx_ep_set_log_cat(trx->ep, DPROXY);
+ osmo_trx_ep_set_mode(trx->ep, OSMO_TRX_EP_MODE_TRX);
+ osmo_trx_ep_set_laddr(trx->ep, proxy->bind_addr);
+ osmo_trx_ep_set_clock_socket(trx->ep, true);
+ osmo_trx_ep_set_ctrl_promisc(trx->ep, true);
+
+ llist_add_tail(&trx->list, &proxy->trx_list);
+
+ return trx;
+}
+
+struct proxy_trx *proxy_trx_find(struct proxy_ctx *proxy, const char *name)
+{
+ struct proxy_trx *trx;
+
+ llist_for_each_entry(trx, &proxy->trx_list, list) {
+ if (strcmp(trx->name, name) == 0)
+ return trx;
+ }
+
+ return NULL;
+}
+
+void proxy_trx_close(struct proxy_trx *trx)
+{
+ if (!trx)
+ return;
+ osmo_trx_ep_close(trx->ep);
+}
+
+void proxy_trx_free(struct proxy_trx *trx)
+{
+ if (!trx)
+ return;
+ osmo_trx_ep_free(trx->ep);
+ llist_del(&trx->list);
+ talloc_free(trx);
+}
+
+int proxy_trx_open(struct proxy_trx *trx)
+{
+ int rc;
+
+ rc = osmo_trx_ep_open(trx->ep);
+ if (rc < 0 && rc != -EALREADY) {
+ LOGP_TRX(trx, DPROXY, LOGL_ERROR,
+ "Failed to open TRX endpoint %s:%u\n",
+ osmo_trx_ep_get_raddr(trx->ep),
+ osmo_trx_ep_get_base_port(trx->ep));
+ return rc;
+ }
+
+ return 0;
+}
diff --git a/proxy/src/vty.c b/proxy/src/vty.c
new file mode 100644
index 0000000..cac9372
--- /dev/null
+++ b/proxy/src/vty.c
@@ -0,0 +1,336 @@
+/*! \file src/vty.c
+ * osmo-trx-proxy: VTY configuration interface. */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/utils.h>
+
+#include <osmocom/vty/command.h>
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/misc.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/vty/cpu_sched_vty.h>
+
+#include <osmocom/trx/ep.h>
+
+#include <osmocom/proxy/proxy.h>
+#include <osmocom/proxy/vty.h>
+#include <osmocom/proxy/trx.h>
+
+extern void *g_talloc_ctx;
+
+enum proxy_vty_node {
+ PROXY_NODE = _LAST_OSMOVTY_NODE + 1,
+ EP_NODE,
+};
+
+static struct cmd_node proxy_node = {
+ PROXY_NODE,
+ "%s(config-proxy)# ",
+ 1,
+};
+
+static struct cmd_node ep_node = {
+ EP_NODE,
+ "%s(config-proxy-ep)# ",
+ 1,
+};
+
+static int dummy_config_write(struct vty *vty)
+{
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_proxy,
+ cfg_proxy_cmd,
+ "proxy",
+ "Configure osmo-trx-proxy\n")
+{
+ vty->node = PROXY_NODE;
+ vty->index = g_proxy_ctx;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_proxy_bind_addr,
+ cfg_proxy_bind_addr_cmd,
+ "bind-addr " VTY_IPV46_CMD,
+ "Set the default local bind address for endpoints without one of their own\n"
+ "IPv4 Address\n"
+ "IPv6 Address\n")
+{
+ struct proxy_ctx *proxy = vty->index;
+
+ osmo_talloc_replace_string(proxy, &proxy->bind_addr, argv[0]);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_proxy_ep,
+ cfg_proxy_ep_cmd,
+ "ep NAME",
+ "Configure a virtual TRX endpoint\n"
+ "Endpoint name (used for logging)\n")
+{
+ struct proxy_ctx *proxy = vty->index;
+ struct proxy_trx *trx = proxy_trx_find(proxy, argv[0]);
+
+ if (!trx)
+ trx = proxy_trx_alloc(proxy, argv[0]);
+
+ vty->node = EP_NODE;
+ vty->index = trx;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_no_proxy_ep,
+ cfg_no_proxy_ep_cmd,
+ "no ep NAME",
+ NO_STR "Remove a virtual TRX endpoint, closing its sockets if currently open\n"
+ "Endpoint name\n")
+{
+ struct proxy_ctx *proxy = vty->index;
+ struct proxy_trx *trx = proxy_trx_find(proxy, argv[0]);
+
+ if (!trx) {
+ vty_out(vty, "%% Endpoint '%s' does not exist%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ proxy_trx_free(trx);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ep_remote_addr,
+ cfg_ep_remote_addr_cmd,
+ "remote-addr " VTY_IPV46_CMD,
+ "Set the remote (L1 peer) IP address\n"
+ "IPv4 Address\n"
+ "IPv6 Address\n")
+{
+ struct proxy_trx *trx = vty->index;
+
+ osmo_trx_ep_set_raddr(trx->ep, argv[0]);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ep_bind_addr,
+ cfg_ep_bind_addr_cmd,
+ "bind-addr " VTY_IPV46_CMD,
+ "Set the local bind address for this endpoint, overriding the 'proxy' default\n"
+ "IPv4 Address\n"
+ "IPv6 Address\n")
+{
+ struct proxy_trx *trx = vty->index;
+
+ osmo_trx_ep_set_laddr(trx->ep, argv[0]);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ep_base_port,
+ cfg_ep_base_port_cmd,
+ "base-port <1-65535>",
+ "Set the TRX base port\n"
+ "Base port (clock: +0, per channel N: ctrl +2N+1, data +2N+2)\n")
+{
+ struct proxy_trx *trx = vty->index;
+
+ osmo_trx_ep_set_base_port(trx->ep, atoi(argv[0]));
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ep_num_chans,
+ cfg_ep_num_chans_cmd,
+ "num-chans <1-16>",
+ "Set the number of channels (1 + number of child transceivers)\n"
+ "Number of channels\n")
+{
+ struct proxy_trx *trx = vty->index;
+ int num_chans = atoi(argv[0]);
+ int rc;
+
+ rc = osmo_trx_ep_set_num_chans(trx->ep, num_chans);
+ if (rc) {
+ vty_out(vty, "%% osmo_trx_ep_set_num_chans(%d) failed: rc=%d%s",
+ num_chans, rc, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ep_clock_socket,
+ cfg_ep_clock_socket_cmd,
+ "clock-socket",
+ "Enable the clock socket for this endpoint (default)\n")
+{
+ struct proxy_trx *trx = vty->index;
+
+ osmo_trx_ep_set_clock_socket(trx->ep, true);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ep_no_clock_socket,
+ cfg_ep_no_clock_socket_cmd,
+ "no clock-socket",
+ NO_STR "Disable the clock socket for this endpoint\n")
+{
+ struct proxy_trx *trx = vty->index;
+
+ osmo_trx_ep_set_clock_socket(trx->ep, false);
+
+ return CMD_SUCCESS;
+}
+
+static int config_write_proxy(struct vty *vty)
+{
+ struct proxy_trx *trx;
+
+ vty_out(vty, "proxy%s", VTY_NEWLINE);
+ if (g_proxy_ctx->bind_addr)
+ vty_out(vty, " bind-addr %s%s", g_proxy_ctx->bind_addr, VTY_NEWLINE);
+
+ llist_for_each_entry(trx, &g_proxy_ctx->trx_list, list) {
+ const char *raddr = osmo_trx_ep_get_raddr(trx->ep);
+ const char *laddr = osmo_trx_ep_get_laddr(trx->ep);
+
+ vty_out(vty, " ep %s%s", trx->name, VTY_NEWLINE);
+ if (raddr)
+ vty_out(vty, " remote-addr %s%s", raddr, VTY_NEWLINE);
+ if (laddr && strcmp(laddr, g_proxy_ctx->bind_addr) != 0)
+ vty_out(vty, " bind-addr %s%s", laddr, VTY_NEWLINE);
+ vty_out(vty, " base-port %u%s", osmo_trx_ep_get_base_port(trx->ep), VTY_NEWLINE);
+ vty_out(vty, " num-chans %u%s", osmo_trx_ep_get_num_chans(trx->ep), VTY_NEWLINE);
+
+ if (!osmo_trx_ep_get_clock_socket(trx->ep))
+ vty_out(vty, " no clock-socket%s", VTY_NEWLINE);
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(show_proxy,
+ show_proxy_cmd,
+ "show proxy",
+ SHOW_STR "Display configured virtual TRX endpoints\n")
+{
+ struct proxy_trx *trx;
+
+ llist_for_each_entry(trx, &g_proxy_ctx->trx_list, list) {
+ vty_out(vty, "Endpoint '%s': %s:%u, %u channel(s), %s%s",
+ trx->name,
+ osmo_trx_ep_get_raddr(trx->ep),
+ osmo_trx_ep_get_base_port(trx->ep),
+ osmo_trx_ep_get_num_chans(trx->ep),
+ osmo_trx_ep_is_open(trx->ep) ? "open" : "closed",
+ VTY_NEWLINE);
+ }
+
+ return CMD_SUCCESS;
+}
+
+/*! Called when leaving EP_NODE (interactively via 'exit'/'end', or on dedent
+ * while reading a config file): validate the endpoint config and open it,
+ * unless it is already open. Returns 0 on success, non-zero if the node
+ * should not be left (so the user/config can fix the problem). */
+static int proxy_vty_ep_node_exit(struct vty *vty, struct proxy_trx *trx)
+{
+ int rc = proxy_trx_open(trx);
+
+ if (rc < 0 && rc != -EALREADY) {
+ vty_out(vty, "%% Endpoint '%s': failed to open%s",
+ trx->name, VTY_NEWLINE);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int proxy_vty_go_parent(struct vty *vty)
+{
+ switch (vty->node) {
+ case PROXY_NODE:
+ vty->node = CONFIG_NODE;
+ break;
+ case EP_NODE:
+ if (proxy_vty_ep_node_exit(vty, vty->index) != 0)
+ break;
+ vty->node = PROXY_NODE;
+ vty->index = g_proxy_ctx;
+ break;
+ default:
+ vty->node = CONFIG_NODE;
+ }
+
+ return vty->node;
+}
+
+static struct vty_app_info g_vty_info = {
+ .name = "OsmoTRXProxy",
+ .copyright =
+ "Copyright (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>\r\n"
+ "Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>\r\n"
+ "License AGPLv3+: GNU AGPL version 3 or later "
+ "<http://gnu.org/licenses/agpl-3.0.html>\r\n"
+ "This is free software: you are free to change and redistribute it.\r\n"
+ "There is NO WARRANTY, to the extent permitted by law.\r\n",
+ .go_parent_cb = proxy_vty_go_parent,
+};
+
+int proxy_vty_init(void)
+{
+ g_vty_info.tall_ctx = g_talloc_ctx;
+ vty_init(&g_vty_info);
+
+ logging_vty_add_cmds();
+ osmo_cpu_sched_vty_init(g_talloc_ctx);
+
+ install_element_ve(&show_proxy_cmd);
+
+ install_element(CONFIG_NODE, &cfg_proxy_cmd);
+ install_node(&proxy_node, config_write_proxy);
+ install_element(PROXY_NODE, &cfg_proxy_bind_addr_cmd);
+ install_element(PROXY_NODE, &cfg_proxy_ep_cmd);
+ install_element(PROXY_NODE, &cfg_no_proxy_ep_cmd);
+
+ install_node(&ep_node, dummy_config_write);
+ install_element(EP_NODE, &cfg_ep_remote_addr_cmd);
+ install_element(EP_NODE, &cfg_ep_bind_addr_cmd);
+ install_element(EP_NODE, &cfg_ep_base_port_cmd);
+ install_element(EP_NODE, &cfg_ep_num_chans_cmd);
+ install_element(EP_NODE, &cfg_ep_clock_socket_cmd);
+ install_element(EP_NODE, &cfg_ep_no_clock_socket_cmd);
+
+ return 0;
+}
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43603?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: Id2b12e5e7d053eea53338fbabc48131b9c46c82a
Gerrit-Change-Number: 43603
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
09 Sep '26
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43606?usp=email )
Change subject: proxy: implement RF path simulation
......................................................................
proxy: implement RF path simulation
Compute real ToA/RSSI/CI values for forwarded bursts instead of the
fixed placeholder constants in burst_fwd.c. Each channel gets its own
struct path_sim_state, tracking Tx power/attenuation, Timing Advance,
reported ToA/RSSI/CI, and burst-dropping parameters. RSSI defaults to
a path-loss formula (Tx power - burst attenuation - fixed path loss)
unless overridden via FAKE_RSSI.
Add the CTRL commands needed to drive this: SETTA, SETPOWER,
NOMTXPOWER, RFMUTE, and the FAKE_TOA/FAKE_RSSI/FAKE_CI/FAKE_DROP
simulation helpers. RFMUTE and burst dropping (FAKE_DROP) turn a
forwarded burst into a NOPE.ind, matching the existing NOPE.req
handling path.
Change-Id: Iefa51d6b0e0bba1f12bdbcdf576528e7d3588b8f
Related: OS#6672
---
M proxy/Makefile.am
A proxy/include/osmocom/proxy/path_sim.h
M proxy/include/osmocom/proxy/trx.h
M proxy/src/Makefile.am
M proxy/src/burst_fwd.c
M proxy/src/ctrl_cmd.c
A proxy/src/path_sim.c
M proxy/src/trx.c
8 files changed, 368 insertions(+), 13 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/06/43606/1
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index e99dd63..909c698 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -5,6 +5,7 @@
noinst_HEADERS = \
include/osmocom/proxy/clck_gen.h \
include/osmocom/proxy/logging.h \
+ include/osmocom/proxy/path_sim.h \
include/osmocom/proxy/proxy.h \
include/osmocom/proxy/trx.h \
include/osmocom/proxy/vty.h \
diff --git a/proxy/include/osmocom/proxy/path_sim.h b/proxy/include/osmocom/proxy/path_sim.h
new file mode 100644
index 0000000..8ae7927
--- /dev/null
+++ b/proxy/include/osmocom/proxy/path_sim.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <stdint.h>
+
+struct proxy_trx_chan;
+struct osmo_trxd_burst_ind;
+struct osmo_trxd_burst_req;
+
+#define PATH_SIM_F_FAKE_RSSI (1 << 0) /*!< use rssi instead of the path-loss formula */
+
+/*! Per-channel RF path simulation state: ToA/RSSI/C-I measurement emulation
+ * and burst dropping (simulated path loss / weak signal / interference). */
+struct path_sim_state {
+ uint32_t flags; /*!< PATH_SIM_F_* */
+ int tx_power; /*!< dBm, nominal Tx power (NOMTXPOWER) */
+ int tx_att; /*!< dB, Tx power attenuation (SETPOWER) */
+ int ta; /*!< Timing Advance, symbol periods (SETTA) */
+ int toa256; /*!< reported ToA, 1/256 symbol periods (FAKE_TOA) */
+ int toa256_jitter; /*!< +/- random jitter around toa256 (FAKE_TOA "<val> <threshold>") */
+ int rssi; /*!< reported RSSI in dBm, if PATH_SIM_F_FAKE_RSSI (FAKE_RSSI) */
+ int rssi_jitter; /*!< +/- random jitter around rssi (FAKE_RSSI "<val> <threshold>") */
+ int ci; /*!< reported C/I in cB (FAKE_CI) */
+ int ci_jitter; /*!< +/- random jitter around ci (FAKE_CI "<val> <threshold>") */
+ unsigned int burst_drop_amount; /*!< bursts left to drop (FAKE_DROP) */
+ unsigned int burst_drop_period; /*!< drop if (fn % period) == 0 */
+};
+
+/*! Reset a channel's RF path simulation state to nominal defaults. */
+void path_sim_state_reset(struct path_sim_state *ps);
+
+/*! Fill in the RF path simulation results (ToA, RSSI, C/I, burst dropping,
+ * RF mute) of a BURST.ind that is about to be forwarded from src to dst. */
+void path_sim_apply(struct osmo_trxd_burst_ind *bi,
+ struct proxy_trx_chan *dst,
+ const struct osmo_trxd_burst_req *br,
+ const struct proxy_trx_chan *src);
diff --git a/proxy/include/osmocom/proxy/trx.h b/proxy/include/osmocom/proxy/trx.h
index 4c867db..d5c7de8 100644
--- a/proxy/include/osmocom/proxy/trx.h
+++ b/proxy/include/osmocom/proxy/trx.h
@@ -6,6 +6,8 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/logging.h>
+#include <osmocom/proxy/path_sim.h>
+
struct osmo_trx_ep;
struct proxy_ctx;
@@ -15,6 +17,8 @@
struct proxy_trx_chan {
uint32_t rx_freq; /*!< Rx frequency in Hz, 0 if not (yet) tuned */
uint32_t tx_freq; /*!< Tx frequency in Hz, 0 if not (yet) tuned */
+ bool rf_muted; /*!< RFMUTE: force NOPE.ind on Rx */
+ struct path_sim_state path_sim; /*!< RF path simulation state (path_sim.c) */
};
/*! One virtual transceiver endpoint */
diff --git a/proxy/src/Makefile.am b/proxy/src/Makefile.am
index 5c8b931..4c3678e 100644
--- a/proxy/src/Makefile.am
+++ b/proxy/src/Makefile.am
@@ -21,6 +21,7 @@
clck_gen.c \
ctrl_cmd.c \
burst_fwd.c \
+ path_sim.c \
logging.c \
$(NULL)
diff --git a/proxy/src/burst_fwd.c b/proxy/src/burst_fwd.c
index 2a9f22d..1254e02 100644
--- a/proxy/src/burst_fwd.c
+++ b/proxy/src/burst_fwd.c
@@ -32,14 +32,9 @@
#include <osmocom/proxy/proxy.h>
#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/path_sim.h>
#include <osmocom/proxy/logging.h>
-/* Placeholder measurement values, until path_sim.c computes them for real
- * (matches fake_trx.py's FakeTRX nominal defaults: no timing offset, and
- * -60 dBm = 50 dBm nominal Tx power - 0 dB Tx attenuation - 110 dB path loss). */
-#define BURST_FWD_TOA256_DEFAULT 0
-#define BURST_FWD_RSSI_DEFAULT -60
-
#define OSMO_TRXD_F_COMMON_MASK ( \
OSMO_TRXD_F_NOPE_REQ | \
OSMO_TRXD_F_MOD_TYPE | \
@@ -47,15 +42,14 @@
OSMO_TRXD_F_TRX_NUM \
)
-static void burst_fwd_to_chan(struct proxy_trx *dst, unsigned int dst_chan,
+static void burst_fwd_to_chan(struct proxy_trx *src, unsigned int src_chan,
+ struct proxy_trx *dst, unsigned int dst_chan,
const struct osmo_trxd_burst_req *br)
{
struct osmo_trxd_burst_ind bi = {
.flags = br->flags & OSMO_TRXD_F_COMMON_MASK,
.fn = br->fn,
.tn = br->tn,
- .toa256 = BURST_FWD_TOA256_DEFAULT,
- .rssi = BURST_FWD_RSSI_DEFAULT,
.burst_len = br->burst_len,
.mod = br->mod,
.tsc_set = br->tsc_set,
@@ -64,6 +58,8 @@
};
osmo_ubit2sbit(bi.burst, br->burst, br->burst_len);
+ path_sim_apply(&bi, &dst->chans[dst_chan],
+ br, &src->chans[src_chan]);
osmo_trx_ep_send_burst_ind(dst->ep, dst_chan, &bi);
}
@@ -74,9 +70,9 @@
void osmo_trx_ep_rx_burst_req(struct osmo_trx_ep *ep, unsigned int chan,
const struct osmo_trxd_burst_req *br)
{
- const struct proxy_trx *src = osmo_trx_ep_get_priv(ep);
- const uint32_t tx_freq = src->chans[chan].tx_freq;
- struct proxy_trx *dst;
+ struct proxy_trx *src = osmo_trx_ep_get_priv(ep);
+ struct proxy_trx *dst = NULL;
+ uint32_t tx_freq;
if (!src->powered) {
LOGP_TRXCH(src, chan, DTRXD, LOGL_NOTICE,
@@ -84,6 +80,8 @@
return;
}
+ tx_freq = src->chans[chan].tx_freq;
+
llist_for_each_entry(dst, &g_proxy_ctx->trx_list, list) {
unsigned int dst_chan;
@@ -93,7 +91,7 @@
for (dst_chan = 0; dst_chan < dst->num_chans; dst_chan++) {
if (dst->chans[dst_chan].rx_freq != tx_freq)
continue;
- burst_fwd_to_chan(dst, dst_chan, br);
+ burst_fwd_to_chan(src, chan, dst, dst_chan, br);
}
}
}
diff --git a/proxy/src/ctrl_cmd.c b/proxy/src/ctrl_cmd.c
index 281cc13..449fe81 100644
--- a/proxy/src/ctrl_cmd.c
+++ b/proxy/src/ctrl_cmd.c
@@ -30,8 +30,17 @@
#include <osmocom/trx/trxc.h>
#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/path_sim.h>
#include <osmocom/proxy/logging.h>
+/* Not part of the well-known OSMO_TRXC_CMD_* verbs (libosmo-trx/trxc.h) since
+ * they are specific to this transceiver's RF path simulation. */
+#define CTRL_CMD_SETTA "SETTA"
+#define CTRL_CMD_FAKE_TOA "FAKE_TOA"
+#define CTRL_CMD_FAKE_RSSI "FAKE_RSSI"
+#define CTRL_CMD_FAKE_CI "FAKE_CI"
+#define CTRL_CMD_FAKE_DROP "FAKE_DROP"
+
static void ctrl_cmd_poweron(struct proxy_trx *trx, struct osmo_trxc_msg *rsp)
{
if (trx->powered) {
@@ -96,6 +105,175 @@
snprintf(rsp->params, sizeof(rsp->params), "%u", freq_khz);
}
+static void ctrl_cmd_setta(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ int ta;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d", &ta) != 1) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): failed to parse Timing Advance: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ return;
+ }
+
+ trx->chans[chan].path_sim.ta = ta;
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO, "Timing Advance set to %d\n", ta);
+}
+
+static void ctrl_cmd_setpower(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ int att;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d", &att) != 1) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse Tx power attenuation: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ return;
+ }
+
+ trx->chans[chan].path_sim.tx_att = att;
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO, "Tx power attenuation set to %d dB\n", att);
+}
+
+static void ctrl_cmd_nomtxpower(struct proxy_trx *trx, unsigned int chan, struct osmo_trxc_msg *rsp)
+{
+ snprintf(rsp->params, sizeof(rsp->params), "%d", trx->chans[chan].path_sim.tx_power);
+}
+
+static void ctrl_cmd_rfmute(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ int mute;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d", &mute) != 1) {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse command arguments: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ return;
+ }
+
+ trx->chans[chan].rf_muted = mute > 0;
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
+ "RF mute %s\n", trx->chans[chan].rf_muted ? "on" : "off");
+}
+
+/* FAKE_TOA/FAKE_RSSI/FAKE_CI: "<delta>" adjusts the current value by delta;
+ * "<value> <threshold>" sets an absolute value with a +/-threshold random
+ * jitter applied on every forwarded burst (see path_sim_apply()). */
+
+static void ctrl_cmd_fake_toa(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ struct path_sim_state *ps = &trx->chans[chan].path_sim;
+ int value, threshold;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d %d", &value, &threshold) == 2) {
+ if (threshold < 0) {
+ rsp->status = 1;
+ return;
+ }
+ ps->toa256 = value;
+ ps->toa256_jitter = threshold;
+ } else if (osmo_trxc_msg_params_scan(cmd, "%d", &value) == 1) {
+ ps->toa256 += value;
+ } else {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse command arguments: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ }
+}
+
+static void ctrl_cmd_fake_rssi(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ struct path_sim_state *ps = &trx->chans[chan].path_sim;
+ int value, threshold;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d %d", &value, &threshold) == 2) {
+ if (threshold < 0) {
+ rsp->status = 1;
+ return;
+ }
+ ps->rssi = value;
+ ps->rssi_jitter = threshold;
+ } else if (osmo_trxc_msg_params_scan(cmd, "%d", &value) == 1) {
+ ps->rssi = value;
+ ps->rssi_jitter = 0;
+ } else {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse command arguments: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ return;
+ }
+
+ ps->flags |= PATH_SIM_F_FAKE_RSSI;
+}
+
+static void ctrl_cmd_fake_ci(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ struct path_sim_state *ps = &trx->chans[chan].path_sim;
+ int value, threshold;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d %d", &value, &threshold) == 2) {
+ if (threshold < 0) {
+ rsp->status = 1;
+ return;
+ }
+ ps->ci = value;
+ ps->ci_jitter = threshold;
+ } else if (osmo_trxc_msg_params_scan(cmd, "%d", &value) == 1) {
+ ps->ci += value;
+ } else {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse command arguments: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ }
+}
+
+static void ctrl_cmd_fake_drop(struct proxy_trx *trx, unsigned int chan,
+ const struct osmo_trxc_msg *cmd, struct osmo_trxc_msg *rsp)
+{
+ struct path_sim_state *ps = &trx->chans[chan].path_sim;
+ int amount, period;
+
+ if (osmo_trxc_msg_params_scan(cmd, "%d %d", &amount, &period) == 2) {
+ if (amount < 0 || period <= 0) {
+ rsp->status = 1;
+ return;
+ }
+ } else if (osmo_trxc_msg_params_scan(cmd, "%d", &amount) == 1) {
+ if (amount < 0) {
+ rsp->status = 1;
+ return;
+ }
+ period = 1;
+ } else {
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_ERROR,
+ "%s(): Failed to parse command arguments: '%s'\n",
+ __func__, osmo_trxc_msg_name(cmd));
+ rsp->status = 1;
+ return;
+ }
+
+ ps->burst_drop_amount = amount;
+ ps->burst_drop_period = period;
+
+ LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
+ "Dropping %d burst(s), every %d frame(s)\n", amount, period);
+}
+
void osmo_trx_ep_rx_ctrl_msg(struct osmo_trx_ep *ep, unsigned int chan,
const struct osmo_trxc_msg *cmd)
{
@@ -118,6 +296,22 @@
ctrl_cmd_rxtune(trx, chan, cmd, &rsp);
} else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_TXTUNE)) {
ctrl_cmd_txtune(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_SETPOWER)) {
+ ctrl_cmd_setpower(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_NOMTXPOWER)) {
+ ctrl_cmd_nomtxpower(trx, chan, &rsp);
+ } else if (!strcmp(cmd->cmd, OSMO_TRXC_CMD_RFMUTE)) {
+ ctrl_cmd_rfmute(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, CTRL_CMD_SETTA)) {
+ ctrl_cmd_setta(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, CTRL_CMD_FAKE_TOA)) {
+ ctrl_cmd_fake_toa(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, CTRL_CMD_FAKE_RSSI)) {
+ ctrl_cmd_fake_rssi(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, CTRL_CMD_FAKE_CI)) {
+ ctrl_cmd_fake_ci(trx, chan, cmd, &rsp);
+ } else if (!strcmp(cmd->cmd, CTRL_CMD_FAKE_DROP)) {
+ ctrl_cmd_fake_drop(trx, chan, cmd, &rsp);
} else {
LOGP_TRXCH(trx, chan, DTRXC, LOGL_INFO,
"Unhandled command '%s'\n", cmd->cmd);
diff --git a/proxy/src/path_sim.c b/proxy/src/path_sim.c
new file mode 100644
index 0000000..bbab7da
--- /dev/null
+++ b/proxy/src/path_sim.c
@@ -0,0 +1,118 @@
+/*! \file src/path_sim.c
+ * osmo-trx-proxy: RF path simulation (ToA/RSSI/C-I, burst dropping, RF mute). */
+
+/*
+ * (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+
+#include <osmocom/trx/trxd.h>
+
+#include <osmocom/proxy/trx.h>
+#include <osmocom/proxy/path_sim.h>
+
+#define PATH_SIM_NOMINAL_TX_POWER_DEFAULT 50 /* dBm */
+#define PATH_SIM_TX_ATT_DEFAULT 0 /* dB */
+#define PATH_SIM_PATH_LOSS_DEFAULT 110 /* dB */
+#define PATH_SIM_CI_DEFAULT 90 /* cB */
+
+/* Values reported for NOPE.ind (burst dropped / RF muted) */
+#define PATH_SIM_TOA256_NOISE_DEFAULT 0
+#define PATH_SIM_RSSI_NOISE_DEFAULT -110
+#define PATH_SIM_CI_NOISE_DEFAULT -30
+
+void path_sim_state_reset(struct path_sim_state *ps)
+{
+ ps->flags = 0;
+ ps->tx_power = PATH_SIM_NOMINAL_TX_POWER_DEFAULT;
+ ps->tx_att = PATH_SIM_TX_ATT_DEFAULT;
+ ps->ta = 0;
+ ps->toa256 = 0;
+ ps->toa256_jitter = 0;
+ ps->rssi = PATH_SIM_NOMINAL_TX_POWER_DEFAULT -
+ PATH_SIM_TX_ATT_DEFAULT - PATH_SIM_PATH_LOSS_DEFAULT;
+ ps->rssi_jitter = 0;
+ ps->ci = PATH_SIM_CI_DEFAULT;
+ ps->ci_jitter = 0;
+ ps->burst_drop_amount = 0;
+ ps->burst_drop_period = 1;
+}
+
+/* Path loss simulation: burst dropping. Returns true if the burst at the
+ * given frame number is to be dropped (and consumes one drop credit). */
+static bool path_sim_burst_drop(struct path_sim_state *dst, uint32_t fn)
+{
+ if (dst->burst_drop_amount == 0)
+ return false;
+
+ if (fn % dst->burst_drop_period == 0) {
+ dst->burst_drop_amount--;
+ return true;
+ }
+
+ return false;
+}
+
+/* Uniform random offset in [-threshold, +threshold], or 0 if threshold <= 0. */
+static int path_sim_jitter(int threshold)
+{
+ if (threshold <= 0)
+ return 0;
+
+ return (rand() % (2 * threshold + 1)) - threshold;
+}
+
+void path_sim_apply(struct osmo_trxd_burst_ind *bi,
+ struct proxy_trx_chan *dst,
+ const struct osmo_trxd_burst_req *br,
+ const struct proxy_trx_chan *src)
+{
+ bool nope = bi->flags & OSMO_TRXD_F_NOPE_IND;
+
+ if (dst->rf_muted)
+ nope = true;
+ else if (!nope)
+ nope = path_sim_burst_drop(&dst->path_sim, br->fn);
+
+ if (nope) {
+ bi->flags |= OSMO_TRXD_F_NOPE_IND | OSMO_TRXD_F_CI_CB;
+ bi->burst_len = 0;
+ bi->toa256 = PATH_SIM_TOA256_NOISE_DEFAULT;
+ bi->rssi = PATH_SIM_RSSI_NOISE_DEFAULT;
+ bi->ci_cb = PATH_SIM_CI_NOISE_DEFAULT;
+ return;
+ }
+
+ bi->toa256 = dst->path_sim.toa256 + path_sim_jitter(dst->path_sim.toa256_jitter);
+ if (src->path_sim.ta != 0)
+ bi->toa256 -= src->path_sim.ta * 256;
+
+ if (dst->path_sim.flags & PATH_SIM_F_FAKE_RSSI) {
+ bi->rssi = dst->path_sim.rssi + path_sim_jitter(dst->path_sim.rssi_jitter);
+ } else {
+ int tx_power = src->path_sim.tx_power - src->path_sim.tx_att;
+ bi->rssi = tx_power - (int)br->att - PATH_SIM_PATH_LOSS_DEFAULT;
+ }
+
+ bi->ci_cb = dst->path_sim.ci + path_sim_jitter(dst->path_sim.ci_jitter);
+ bi->flags |= OSMO_TRXD_F_CI_CB;
+}
diff --git a/proxy/src/trx.c b/proxy/src/trx.c
index facbc45..9851665 100644
--- a/proxy/src/trx.c
+++ b/proxy/src/trx.c
@@ -35,6 +35,7 @@
#include <osmocom/proxy/proxy.h>
#include <osmocom/proxy/trx.h>
#include <osmocom/proxy/clck_gen.h>
+#include <osmocom/proxy/path_sim.h>
#include <osmocom/proxy/logging.h>
struct proxy_trx *proxy_trx_alloc(struct proxy_ctx *proxy, const char *name)
@@ -124,6 +125,8 @@
if (rc == 0) { /* first successful open: num_chans is now fixed */
trx->chans = talloc_zero_array(trx, struct proxy_trx_chan, trx->num_chans);
OSMO_ASSERT(trx->chans != NULL);
+ for (unsigned int i = 0; i < trx->num_chans; i++)
+ path_sim_state_reset(&trx->chans[i].path_sim);
}
return 0;
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43606?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: Iefa51d6b0e0bba1f12bdbcdf576528e7d3588b8f
Gerrit-Change-Number: 43606
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
09 Sep '26
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43602?usp=email )
Change subject: .checkpatch.c++.conf: --ignore LEADING_SPACE
......................................................................
.checkpatch.c++.conf: --ignore LEADING_SPACE
checkpatch complains about leading spaces in C++ header files.
For instance, the following code:
```
class Transceiver {
public:
Transceiver(const struct trx_cfg *cfg, ...);
```
fails with:
WARNING:LEADING_SPACE: please, no spaces at the start of a line
Ignore it for C++, like the other rules already excluded there.
Change-Id: I542cd4e393c218979e78f56c7d3f9d2ed6d6f379
---
M .checkpatch.c++.conf
1 file changed, 1 insertion(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/02/43602/1
diff --git a/.checkpatch.c++.conf b/.checkpatch.c++.conf
index 907c8b3..dbc7bfc 100644
--- a/.checkpatch.c++.conf
+++ b/.checkpatch.c++.conf
@@ -5,3 +5,4 @@
--ignore INDENTED_LABEL
--ignore NEW_TYPEDEFS
--ignore SPACING
+--ignore LEADING_SPACE
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43602?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: I542cd4e393c218979e78f56c7d3f9d2ed6d6f379
Gerrit-Change-Number: 43602
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
[M] Change in osmo-trx[master]: libosmo-trx/ep: allow ctrl socket to accept/reply to any peer
by fixeria 09 Sep '26
by fixeria 09 Sep '26
09 Sep '26
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-trx/+/43601?usp=email )
Change subject: libosmo-trx/ep: allow ctrl socket to accept/reply to any peer
......................................................................
libosmo-trx/ep: allow ctrl socket to accept/reply to any peer
By default, the socket stays connect()ed to the configured peer, so
the kernel silently drops datagrams from anyone else. This is fine
for the normal osmo-bts/osmo-trx/trxcon use case, where both ends of
the link are fixed and known ahead of time.
Add an optional promiscuous mode that enables ttcn3-bts-test to
inject path simulation TRXC commands from its own source port: when
enabled, leave the ctrl socket unconnected and always reply to the
actual sender of the last received CMD (tracked in chan->ctrl_peer),
rather than only the configured peer.
This mode will be used by the upcoming osmo-trx-proxy.
Change-Id: I97075eb350e4270f4e909d493ba692e6b65be750
Related: OS#6672
---
M libosmo-trx/include/osmocom/trx/ep.h
M libosmo-trx/src/trx_ep.c
M tests/libosmo-trx/trx_ep_test.c
M tests/libosmo-trx/trx_ep_test.err
M tests/libosmo-trx/trx_ep_test.ok
5 files changed, 163 insertions(+), 17 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/01/43601/1
diff --git a/libosmo-trx/include/osmocom/trx/ep.h b/libosmo-trx/include/osmocom/trx/ep.h
index ad02719..f7ff75c 100644
--- a/libosmo-trx/include/osmocom/trx/ep.h
+++ b/libosmo-trx/include/osmocom/trx/ep.h
@@ -100,6 +100,10 @@
int osmo_trx_ep_set_clock_socket(struct osmo_trx_ep *ep, bool enable);
bool osmo_trx_ep_get_clock_socket(const struct osmo_trx_ep *ep);
+/*! Unconnected ctrl socket accepting/replying to any peer; default: false */
+int osmo_trx_ep_set_ctrl_promisc(struct osmo_trx_ep *ep, bool enable);
+bool osmo_trx_ep_get_ctrl_promisc(const struct osmo_trx_ep *ep);
+
/*! Per-channel TRXD PDU version in use (set after SETFORMAT negotiation) */
int osmo_trx_ep_set_pdu_ver(struct osmo_trx_ep *ep, unsigned int chan, uint8_t ver);
int osmo_trx_ep_get_pdu_ver(const struct osmo_trx_ep *ep, unsigned int chan);
diff --git a/libosmo-trx/src/trx_ep.c b/libosmo-trx/src/trx_ep.c
index 8d9d641..37ac72b 100644
--- a/libosmo-trx/src/trx_ep.c
+++ b/libosmo-trx/src/trx_ep.c
@@ -33,6 +33,7 @@
#include <stdarg.h>
#include <unistd.h>
+#include <sys/socket.h>
#include <netinet/in.h>
#include <osmocom/core/talloc.h>
@@ -65,12 +66,18 @@
* to tell whether a flush is needed on teardown (see struct
* trx_ep_ctrl_flush below). */
size_t ctrl_wr_pending;
+ /* Destination for the next ctrl message sent on ctrl_iofd.
+ * Initialized to the configured peer at open, updated in
+ * trx_ep_ctrl_recvfrom_cb(). */
+ struct osmo_sockaddr ctrl_peer;
};
/*! Sockets currently bound */
#define OSMO_TRX_EP_F_OPEN (1 << 0)
/*! Enable the clock socket (base_port + 0) */
#define OSMO_TRX_EP_F_CLOCK_SOCKET (1 << 1)
+/*! Leave the ctrl socket unconnected, accepting/replying to any peer */
+#define OSMO_TRX_EP_F_CTRL_PROMISC (1 << 2)
struct osmo_trx_ep {
uint32_t flags; /* see OSMO_TRX_EP_F_* */
@@ -168,7 +175,8 @@
msgb_free(msg);
}
-static void trx_ep_ctrl_read_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
+static void trx_ep_ctrl_recvfrom_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg,
+ const struct osmo_sockaddr *saddr)
{
struct osmo_trx_ep_chan *chan = osmo_iofd_get_data(iofd);
struct osmo_trx_ep *ep = chan->ep;
@@ -178,6 +186,10 @@
if (res <= 0)
goto ret_free_msg;
+ /* Remember the sender of every datagram received on ctrl_iofd,
+ * so the next reply goes back to whoever actually sent it. */
+ chan->ctrl_peer = *saddr;
+
rc = osmo_trxc_msg_parse(&tmsg, (const char *)msgb_data(msg), msgb_length(msg));
if (rc < 0) {
LOGEPCH(ep, chan->num, LOGL_NOTICE, "Rx malformed TRXC message (rc=%d)\n", rc);
@@ -247,7 +259,8 @@
* can tell whether anything is still in flight at teardown time (see
* struct trx_ep_ctrl_flush below for why osmo_iofd_txqueue_len() alone
* cannot answer that question). */
-static void trx_ep_ctrl_write_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
+static void trx_ep_ctrl_sendto_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg,
+ const struct osmo_sockaddr *daddr)
{
struct osmo_trx_ep_chan *chan = osmo_iofd_get_data(iofd);
@@ -282,7 +295,7 @@
size_t wr_pending;
};
-/*! Write call-back for a ctrl_iofd being flushed asynchronously after
+/*! Sendto call-back for a ctrl_iofd being flushed asynchronously after
* osmo_trx_ep_close(): a 'goodbye' TRXC message (e.g. "CMD POWEROFF") may
* have been enqueued via osmo_trx_ep_send_ctrl_msg() right before tearing
* down the endpoint; osmo_iofd_free() would otherwise drop it together
@@ -291,7 +304,8 @@
* returns) and lives on its own, driven by the same event loop, until
* every byte enqueued on it has actually completed (or a write fails),
* at which point it closes and frees itself. */
-static void trx_ep_ctrl_flush_write_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
+static void trx_ep_ctrl_flush_sendto_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg,
+ const struct osmo_sockaddr *daddr)
{
struct trx_ep_ctrl_flush *flush = osmo_iofd_get_data(iofd);
@@ -316,7 +330,7 @@
}
static const struct osmo_io_ops trx_ep_ctrl_flush_ioops = {
- .write_cb = &trx_ep_ctrl_flush_write_cb,
+ .sendto_cb = &trx_ep_ctrl_flush_sendto_cb,
};
/* Close a channel's ctrl_iofd, flushing (best-effort) any still-in-flight
@@ -361,8 +375,8 @@
};
static const struct osmo_io_ops trx_ep_ctrl_ioops = {
- .read_cb = &trx_ep_ctrl_read_cb,
- .write_cb = &trx_ep_ctrl_write_cb,
+ .recvfrom_cb = &trx_ep_ctrl_recvfrom_cb,
+ .sendto_cb = &trx_ep_ctrl_sendto_cb,
};
static const struct osmo_io_ops trx_ep_data_ioops = {
@@ -370,26 +384,34 @@
.write_cb = &trx_ep_write_cb,
};
-/* Open a single UDP socket (base port + ofs) and set up osmo_io for it */
+/* Open a single UDP socket (base port + ofs) and set up osmo_io for it.
+ * connect_socket == false leaves the socket unconnected (bind-only),
+ * accepting datagrams from and replying to any peer. */
static struct osmo_io_fd *trx_ep_open_iofd(struct osmo_trx_ep *ep, uint16_t ofs,
const struct osmo_io_ops *ioops,
- unsigned int buf_size, void *data)
+ enum osmo_io_fd_mode mode,
+ unsigned int buf_size, void *data,
+ bool connect_socket)
{
+ unsigned int flags = OSMO_SOCK_F_BIND | OSMO_SOCK_F_NONBLOCK;
char sock_name[OSMO_SOCK_NAME_MAXLEN];
struct osmo_io_fd *iofd;
int fd;
+ if (connect_socket)
+ flags |= OSMO_SOCK_F_CONNECT;
+
fd = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP,
ep->laddr, trx_ep_port(ep, true, ofs),
ep->raddr, trx_ep_port(ep, false, ofs),
- OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT | OSMO_SOCK_F_NONBLOCK);
+ flags);
if (fd < 0) {
LOGEP(ep, LOGL_ERROR, "Failed to open a socket (ofs=%u): %d\n", ofs, fd);
return NULL;
}
osmo_sock_get_name_buf(sock_name, sizeof(sock_name), fd);
- iofd = osmo_iofd_setup(ep, fd, sock_name, OSMO_IO_FD_MODE_READ_WRITE, ioops, data);
+ iofd = osmo_iofd_setup(ep, fd, sock_name, mode, ioops, data);
if (iofd == NULL) {
close(fd);
return NULL;
@@ -419,16 +441,30 @@
static int trx_ep_chan_open(struct osmo_trx_ep_chan *chan)
{
struct osmo_trx_ep *ep = chan->ep;
+ const bool connect_ctrl = !(ep->flags & OSMO_TRX_EP_F_CTRL_PROMISC);
chan->ctrl_iofd = trx_ep_open_iofd(ep, 2 * chan->num + 1, &trx_ep_ctrl_ioops,
- OSMO_TRXC_MSG_BUF_SIZE, chan);
+ OSMO_IO_FD_MODE_RECVFROM_SENDTO,
+ OSMO_TRXC_MSG_BUF_SIZE, chan, connect_ctrl);
if (chan->ctrl_iofd == NULL) {
LOGEPCH(ep, chan->num, LOGL_ERROR, "Failed to open TRXC socket\n");
return -EIO;
}
+ /* connect()ed: seed ctrl_peer with the actual peer so a CMD sent
+ * from the L1 side (osmo_trx_ep mode L1) before ever receiving
+ * anything has somewhere to go; trx_ep_ctrl_recvfrom_cb() keeps it
+ * up to date afterwards. */
+ if (connect_ctrl) {
+ struct osmo_sockaddr *peer = &chan->ctrl_peer;
+ socklen_t peer_len = sizeof(peer->u);
+
+ getpeername(osmo_iofd_get_fd(chan->ctrl_iofd), &peer->u.sa, &peer_len);
+ }
+
chan->data_iofd = trx_ep_open_iofd(ep, 2 * chan->num + 2, &trx_ep_data_ioops,
- TRX_EP_DATA_BUF_SIZE, chan);
+ OSMO_IO_FD_MODE_READ_WRITE,
+ TRX_EP_DATA_BUF_SIZE, chan, true);
if (chan->data_iofd == NULL) {
LOGEPCH(ep, chan->num, LOGL_ERROR, "Failed to open TRXD socket\n");
return -EIO;
@@ -507,7 +543,8 @@
if (ep->flags & OSMO_TRX_EP_F_CLOCK_SOCKET) {
ep->clck_iofd = trx_ep_open_iofd(ep, 0, &trx_ep_clck_ioops,
- OSMO_TRXC_MSG_BUF_SIZE, ep);
+ OSMO_IO_FD_MODE_READ_WRITE,
+ OSMO_TRXC_MSG_BUF_SIZE, ep, true);
if (ep->clck_iofd == NULL)
goto ret_error;
}
@@ -709,6 +746,29 @@
return ep->flags & OSMO_TRX_EP_F_CLOCK_SOCKET;
}
+/*! Enable/disable promiscuous ctrl socket mode (default: false): leaves the
+ * ctrl socket unconnected, accepting TRXC PDUs from any peer instead of only
+ * the configured one, e.g. a test tool injecting extra TRXC commands from
+ * its own socket. The RSP always goes back to whoever actually sent the
+ * CMD, promiscuous or not (see trx_ep_ctrl_recvfrom_cb() and chan->ctrl_peer). */
+int osmo_trx_ep_set_ctrl_promisc(struct osmo_trx_ep *ep, bool enable)
+{
+ if (ep->flags & OSMO_TRX_EP_F_OPEN)
+ return -EBUSY;
+
+ if (enable)
+ ep->flags |= OSMO_TRX_EP_F_CTRL_PROMISC;
+ else
+ ep->flags &= ~OSMO_TRX_EP_F_CTRL_PROMISC;
+ return 0;
+}
+
+/*! Whether promiscuous ctrl socket mode is enabled */
+bool osmo_trx_ep_get_ctrl_promisc(const struct osmo_trx_ep *ep)
+{
+ return ep->flags & OSMO_TRX_EP_F_CTRL_PROMISC;
+}
+
/*! Set the name (log prefix) of the given instance, e.g. "phy0" */
int osmo_trx_ep_set_name(struct osmo_trx_ep *ep, const char *fmt, ...)
{
@@ -795,11 +855,13 @@
int osmo_trx_ep_send_ctrl_msg(struct osmo_trx_ep *ep, unsigned int chan,
const struct osmo_trxc_msg *tmsg)
{
+ struct osmo_trx_ep_chan *c;
struct msgb *msg;
size_t len;
int rc;
OSMO_ASSERT(chan < ep->num_chans);
+ c = &ep->chans[chan];
msg = msgb_alloc_c(ep, OSMO_TRXC_MSG_BUF_SIZE, "trx_ep_ctrl_tx");
rc = osmo_trxc_msg_build((char *)msgb_data(msg), msgb_tailroom(msg), tmsg);
@@ -810,11 +872,11 @@
msgb_put(msg, rc);
len = msgb_length(msg);
- rc = osmo_iofd_write_msgb(ep->chans[chan].ctrl_iofd, msg);
+ rc = osmo_iofd_sendto_msgb(c->ctrl_iofd, msg, 0, &c->ctrl_peer);
if (rc < 0)
msgb_free(msg);
else
- ep->chans[chan].ctrl_wr_pending += len;
+ c->ctrl_wr_pending += len;
return rc;
}
diff --git a/tests/libosmo-trx/trx_ep_test.c b/tests/libosmo-trx/trx_ep_test.c
index 54fbec9..8d6d880 100644
--- a/tests/libosmo-trx/trx_ep_test.c
+++ b/tests/libosmo-trx/trx_ep_test.c
@@ -27,6 +27,11 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
#include <osmocom/core/application.h>
#include <osmocom/core/logging.h>
@@ -37,6 +42,7 @@
#include <osmocom/trx/ep.h>
#define TEST_BASE_PORT 16700
+#define TEST_PROMISC_BASE_PORT 16720
static void *test_ctx = NULL;
@@ -125,6 +131,72 @@
bi->burst[i] = (i & 1) ? -100 : 100;
}
+/* osmo_trx_ep_{get,set}_ctrl_promisc(): with promisc enabled, a channel's
+ * ctrl socket is left unconnected (bind-only), so it accepts a CMD from any
+ * peer, not just the configured raddr, and replies to whoever actually sent
+ * it - e.g. a test tool injecting extra TRXC commands from its own socket. */
+static void test_ctrl_promisc(void)
+{
+ struct sockaddr_in dst = { .sin_family = AF_INET };
+ struct sockaddr_in from;
+ socklen_t from_len;
+ struct osmo_trx_ep *ep;
+ int fd, rc, len;
+
+ printf("=== ctrl promisc: foreign CMD accepted by an unconnected ctrl socket ===\n");
+
+ ep = osmo_trx_ep_alloc(test_ctx, 1);
+ OSMO_ASSERT(ep != NULL);
+ osmo_trx_ep_set_priv(ep, "promisc");
+ osmo_trx_ep_set_mode(ep, OSMO_TRX_EP_MODE_TRX);
+ osmo_trx_ep_set_laddr(ep, "127.0.0.1");
+ osmo_trx_ep_set_raddr(ep, "127.0.0.1");
+ osmo_trx_ep_set_base_port(ep, TEST_PROMISC_BASE_PORT);
+ osmo_trx_ep_set_name(ep, "ep_%s", "promisc");
+
+ OSMO_ASSERT(osmo_trx_ep_get_ctrl_promisc(ep) == false);
+ OSMO_ASSERT(osmo_trx_ep_set_ctrl_promisc(ep, true) == 0);
+ OSMO_ASSERT(osmo_trx_ep_get_ctrl_promisc(ep) == true);
+
+ OSMO_ASSERT(osmo_trx_ep_open(ep) == 0);
+
+ /* config setters, including this one, are expected to fail once open */
+ OSMO_ASSERT(osmo_trx_ep_set_ctrl_promisc(ep, false) == -EBUSY);
+
+ /* chan 0 ctrl; source port of the foreign peer is left to the kernel
+ * (no bind() before sendto() below) */
+ dst.sin_port = htons(TEST_PROMISC_BASE_PORT + 1);
+ OSMO_ASSERT(inet_pton(AF_INET, "127.0.0.1", &dst.sin_addr) == 1);
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ OSMO_ASSERT(fd >= 0);
+
+ char buf[OSMO_TRXC_MSG_BUF_SIZE];
+ const struct osmo_trxc_msg cmd = {
+ .type = OSMO_TRXC_MT_CMD,
+ .cmd = "POWERON",
+ };
+
+ len = osmo_trxc_msg_build(buf, sizeof(buf), &cmd);
+ OSMO_ASSERT(len > 0);
+ rc = sendto(fd, buf, len, 0, (const struct sockaddr *)&dst, sizeof(dst));
+ OSMO_ASSERT(rc == len);
+
+ flush_io();
+
+ /* the RSP must come back to us (the foreign sender), not to raddr */
+ from_len = sizeof(from);
+ rc = recvfrom(fd, buf, sizeof(buf) - 1, MSG_DONTWAIT,
+ (struct sockaddr *)&from, &from_len);
+ OSMO_ASSERT(rc > 0);
+ buf[rc] = '\0';
+ OSMO_ASSERT(from.sin_addr.s_addr == dst.sin_addr.s_addr);
+ printf("foreign rx: '%s'\n", buf);
+
+ close(fd);
+ osmo_trx_ep_free(ep);
+}
+
int main(int argc, char **argv)
{
struct osmo_trx_ep *ep_l1, *ep_trx;
@@ -248,6 +320,8 @@
osmo_trx_ep_free(ep_l1);
osmo_trx_ep_free(ep_trx);
+ test_ctrl_promisc();
+
printf("Done\n");
return 0;
}
diff --git a/tests/libosmo-trx/trx_ep_test.err b/tests/libosmo-trx/trx_ep_test.err
index 87cce6c..46bab0a 100644
--- a/tests/libosmo-trx/trx_ep_test.err
+++ b/tests/libosmo-trx/trx_ep_test.err
@@ -5,7 +5,10 @@
DLGLOBAL INFO (ep=ep_l1) Closing TRXC/TRXD connections l=127.0.0.1:16800<->r=127.0.0.1:16700
DLGLOBAL DEBUG (ep=ep_l1, chan=0) trx_ep_ctrl_close(): nothing pending, closing immediately
DLGLOBAL DEBUG (ep=ep_l1, chan=1) trx_ep_ctrl_close(): 12 byte(s) still pending, detaching to flush asynchronously
-DLGLOBAL DEBUG (ep=ep_l1, chan=1) trx_ep_ctrl_flush_write_cb(): flush completed (res=12)
+DLGLOBAL DEBUG (ep=ep_l1, chan=1) trx_ep_ctrl_flush_sendto_cb(): flush completed (res=12)
DLGLOBAL INFO (ep=ep_trx) Closing TRXC/TRXD connections l=127.0.0.1:16700<->r=127.0.0.1:16800
DLGLOBAL DEBUG (ep=ep_trx, chan=0) trx_ep_ctrl_close(): nothing pending, closing immediately
DLGLOBAL DEBUG (ep=ep_trx, chan=1) trx_ep_ctrl_close(): nothing pending, closing immediately
+DLGLOBAL INFO (ep=ep_promisc) Opening TRXC/TRXD connections l=127.0.0.1:16720<->r=127.0.0.1:16820
+DLGLOBAL INFO (ep=ep_promisc) Closing TRXC/TRXD connections l=127.0.0.1:16720<->r=127.0.0.1:16820
+DLGLOBAL DEBUG (ep=ep_promisc, chan=0) trx_ep_ctrl_close(): nothing pending, closing immediately
diff --git a/tests/libosmo-trx/trx_ep_test.ok b/tests/libosmo-trx/trx_ep_test.ok
index bd43fd5..d554a15 100644
--- a/tests/libosmo-trx/trx_ep_test.ok
+++ b/tests/libosmo-trx/trx_ep_test.ok
@@ -17,4 +17,7 @@
l1: rx_burst_ind(chan=0): NOPE.ind tn=5 fn=200005 trx_num=0 rssi=-63 toa256=-512 C/I=-150 cB
=== TRXC CMD sent right before osmo_trx_ep_close() (L1 -> TRX) ===
trx: rx_ctrl_msg(chan=1): 'CMD POWEROFF'
+=== ctrl promisc: foreign CMD accepted by an unconnected ctrl socket ===
+promisc: rx_ctrl_msg(chan=0): 'CMD POWERON'
+foreign rx: 'RSP POWERON 0'
Done
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43601?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: I97075eb350e4270f4e909d493ba692e6b65be750
Gerrit-Change-Number: 43601
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
1
0
[M] Change in osmo-trx[master]: libosmo-trx/ep: flush pending TRXC messages on endpoint teardown
by fixeria 09 Sep '26
by fixeria 09 Sep '26
09 Sep '26
Attention is currently required from: pespin.
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-trx/+/43112?usp=email
to look at the new patch set (#6).
The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder
Change subject: libosmo-trx/ep: flush pending TRXC messages on endpoint teardown
......................................................................
libosmo-trx/ep: flush pending TRXC messages on endpoint teardown
osmo_trx_ep_close() used to drop any still-queued ctrl socket Tx data
via osmo_iofd_free(), including a 'goodbye' TRXC message (i.e. "CMD
POWEROFF") that may have just been enqueued right before teardown.
Detach such a ctrl_iofd from the endpoint (which may be freed right
after osmo_trx_ep_close() returns) and let it live on its own, driven
by the same event loop, until the pending write(s) complete (or fail),
at which point it closes and frees itself. Data sockets and pending
Tx data batches (TRXDv2 batching, see chan->tx_msg) are still dropped
immediately, as before.
Expose the "still flushing" state via the new osmo_trx_ep_is_closing(),
so a caller can tell it apart from fully closed: re-opening the same
ports while a flush is still in flight would otherwise risk a confusing
EADDRINUSE, so osmo_trx_ep_open() now returns -EBUSY in that case.
osmo_trx_ep_free() detaches any flush still in progress (clearing its
back-pointer to the endpoint) instead of leaving it to touch the
endpoint after it is gone.
This follows the async-flush pattern used by osmo-pcap's
osmo_pcap_wr_file_flush()/_is_flushing(), adapted to the osmo_io API
(there is no osmo_iofd_flush()).
Change-Id: I69e6a3bcf49afc3cfca4a72afdf459625cb91e56
---
M libosmo-trx/include/osmocom/trx/ep.h
M libosmo-trx/src/trx_ep.c
M tests/libosmo-trx/trx_ep_test.c
M tests/libosmo-trx/trx_ep_test.err
M tests/libosmo-trx/trx_ep_test.ok
5 files changed, 184 insertions(+), 7 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/12/43112/6
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43112?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I69e6a3bcf49afc3cfca4a72afdf459625cb91e56
Gerrit-Change-Number: 43112
Gerrit-PatchSet: 6
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
1
0