Timur Davydov has uploaded this change for review.
trx: split TRX ctrl response parsing from socket callback
Extract TRX control response parsing logic into
trx_ctrl_parse_rsp() and call it from trx_ctrl_read_cb()
This decouples parsing from socket I/O and allows reuse
with alternative transports
No functional changes intended
Change-Id: I255c7d554aad3ac6df2c66716fae1c1fb512110e
---
M src/osmo-bts-trx/trx_if.c
1 file changed, 26 insertions(+), 20 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/95/42695/1
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index c073240..57da2f3 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -668,25 +668,18 @@
return 0;
}
-/*! Get + parse response from TRX ctrl socket */
-static void trx_ctrl_read_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
+/* Parse response from TRX ctrl */
+static int trx_ctrl_parse_rsp(struct trx_l1h *l1h, const char *buf, size_t buf_len)
{
- struct trx_l1h *l1h = osmo_iofd_get_data(iofd);
struct phy_instance *pinst = l1h->phy_inst;
- const char *buf;
struct trx_ctrl_rsp rsp;
int rc;
struct trx_ctrl_msg *tcm;
bool flushed;
- if (res <= 0)
- goto ret_free_msg;
-
- msgb_put_u8(msg, (uint8_t)'\0');
- buf = (char *)msgb_data(msg);
-
- if (parse_rsp(buf, res, &rsp) < 0)
- goto ret_free_msg;
+ rc = parse_rsp(buf, buf_len, &rsp);
+ if (rc < 0)
+ return rc;
LOGPPHI(l1h->phy_inst, DTRX, LOGL_INFO, "Response message: '%s'\n", buf);
@@ -699,10 +692,10 @@
if (l1h->last_acked && cmd_matches_rsp(l1h->last_acked, &rsp)) {
LOGPPHI(l1h->phy_inst, DTRX, LOGL_NOTICE, "Discarding duplicated RSP "
"from old CMD '%s'\n", buf);
- goto ret_free_msg;
+ return -EALREADY;
}
LOGPPHI(l1h->phy_inst, DTRX, LOGL_NOTICE, "Response message without command\n");
- goto ret_free_msg;
+ return -ENOENT;
}
tcm = llist_entry(l1h->trx_ctrl_list.next, struct trx_ctrl_msg, list);
@@ -712,7 +705,7 @@
if (l1h->last_acked && cmd_matches_rsp(l1h->last_acked, &rsp)) {
LOGPPHI(l1h->phy_inst, DTRX, LOGL_NOTICE, "Discarding duplicated RSP "
"from old CMD '%s'\n", buf);
- goto ret_free_msg;
+ return -EALREADY;
}
LOGPPHI(l1h->phy_inst, DTRX, (tcm->critical) ? LOGL_FATAL : LOGL_NOTICE,
"Response message '%s' does not match command "
@@ -742,7 +735,7 @@
/* The queue may have been flushed in the trx_ctrl_rx_rsp(): */
if (!llist_empty(&l1h->trx_ctrl_list))
osmo_timer_schedule(&l1h->trx_ctrl_timer, rc, 0);
- goto ret_free_msg;
+ return -EAGAIN;
}
if (!flushed) {
@@ -756,16 +749,29 @@
/* Send next message waiting in the list: */
trx_ctrl_send(l1h);
- msgb_free(msg);
- return;
+ return 0;
rsp_error:
bts_shutdown(pinst->trx->bts, "TRX-CTRL-MSG: CRITICAL");
/* keep tcm list, so process is stopped */
-ret_free_msg:
- msgb_free(msg);
+ return -ESHUTDOWN;
+
}
+/*! Get + parse response from TRX ctrl socket */
+static void trx_ctrl_read_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
+{
+ struct trx_l1h *l1h = osmo_iofd_get_data(iofd);
+ const char *buf;
+
+ if (res > 0) {
+ msgb_put_u8(msg, (uint8_t)'\0');
+ buf = (char *)msgb_data(msg);
+ trx_ctrl_parse_rsp(l1h, buf, res);
+ }
+
+ msgb_free(msg);
+}
static void trx_ctrl_write_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
{
To view, visit change 42695. To unsubscribe, or for help writing mail filters, visit settings.