Change in osmo-bts[master]: bts-trx: trx_if: Use struct to store CTRL msg parsed responses

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Mon Nov 19 10:43:56 UTC 2018


Pau Espin Pedrol has submitted this change and it was merged. ( https://gerrit.osmocom.org/11765 )

Change subject: bts-trx: trx_if: Use struct to store CTRL msg parsed responses
......................................................................

bts-trx: trx_if: Use struct to store CTRL msg parsed responses

Change-Id: Icb84bce0621042afa4301678ba1cc58d8e3662bb
---
M src/osmo-bts-trx/trx_if.c
1 file changed, 28 insertions(+), 22 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index f3de245..4bcdfc6 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -368,8 +368,13 @@
 	return trx_ctrl_cmd(l1h, 1, "NOHANDOVER", "%d %d", tn, ss);
 }
 
-static int parse_rsp(const char *buf_in, size_t len_in, char *cmdname_out, size_t cmdname_len,
-			char *params_out, size_t params_len, int *status)
+struct trx_ctrl_rsp {
+	char cmd[50];
+	char params[100];
+	int status;
+};
+
+static int parse_rsp(const char *buf_in, size_t len_in, struct trx_ctrl_rsp *rsp)
 {
 	char *p, *k;
 
@@ -380,18 +385,18 @@
 	if (!(p = strchr(buf_in + 4, ' ')))
 		goto parse_err;
 
-	if (p - buf_in >= cmdname_len) {
-		LOGP(DTRX, LOGL_ERROR, "cmdname buffer too small %lu >= %lu\n",
-			p - buf_in, cmdname_len);
+	if (p - buf_in >= sizeof(rsp->cmd)) {
+		LOGP(DTRX, LOGL_ERROR, "cmd buffer too small %lu >= %lu\n",
+			p - buf_in, sizeof(rsp->cmd));
 		goto parse_err;
 	}
 
-	cmdname_out[0] = '\0';
-	strncat(cmdname_out, buf_in + 4, p - buf_in - 4);
+	rsp->cmd[0] = '\0';
+	strncat(rsp->cmd, buf_in + 4, p - buf_in - 4);
 
 	/* Now comes the status code of the response */
 	p++;
-	if (sscanf(p, "%d", status) != 1)
+	if (sscanf(p, "%d", &rsp->status) != 1)
 		goto parse_err;
 
 	/* Now copy back the parameters */
@@ -401,13 +406,13 @@
 	else
 		k = p + strlen(p);
 
-	if (strlen(k) >= params_len) {
+	if (strlen(k) >= sizeof(rsp->params)) {
 		LOGP(DTRX, LOGL_ERROR, "params buffer too small %lu >= %lu\n",
-			strlen(k), params_len);
+			strlen(k), sizeof(rsp->params));
 		goto parse_err;
 	}
-	params_out[0] = '\0';
-	strcat(params_out, k);
+	rsp->params[0] = '\0';
+	strcat(rsp->params, k);
 	return 0;
 
 parse_err:
@@ -416,15 +421,15 @@
 	return -1;
 }
 
-static bool cmd_matches_rsp(struct trx_ctrl_msg *tcm, char *rspname, char* params)
+static bool cmd_matches_rsp(struct trx_ctrl_msg *tcm, struct trx_ctrl_rsp *rsp)
 {
-	if (strcmp(tcm->cmd, rspname))
+	if (strcmp(tcm->cmd, rsp->cmd))
 		return false;
 
 	/* For SETSLOT we also need to check if it's the response for the
 	   specific timeslot. For other commands such as SETRXGAIN, it is
 	   expected that they can return different values */
-	if (strcmp(tcm->cmd, "SETSLOT") == 0 && strcmp(tcm->params, params))
+	if (strcmp(tcm->cmd, "SETSLOT") == 0 && strcmp(tcm->params, rsp->params))
 		return false;
 
 	return true;
@@ -435,8 +440,9 @@
 {
 	struct trx_l1h *l1h = ofd->data;
 	struct phy_instance *pinst = l1h->phy_inst;
-	char buf[1500], cmdname[50], params[100];
-	int len, resp;
+	char buf[1500];
+	struct trx_ctrl_rsp rsp;
+	int len;
 	struct trx_ctrl_msg *tcm;
 
 	len = recv(ofd->fd, buf, sizeof(buf) - 1, 0);
@@ -444,7 +450,7 @@
 		return len;
 	buf[len] = '\0';
 
-	if (parse_rsp(buf, len, cmdname, sizeof(cmdname), params, sizeof(params), &resp) < 0)
+	if (parse_rsp(buf, len, &rsp) < 0)
 		return 0;
 
 	LOGP(DTRX, LOGL_INFO, "Response message: '%s'\n", buf);
@@ -456,7 +462,7 @@
 	/* get command for response message */
 	if (llist_empty(&l1h->trx_ctrl_list)) {
 		/* RSP from a retransmission, skip it */
-		if (l1h->last_acked && cmd_matches_rsp(l1h->last_acked, cmdname, params)) {
+		if (l1h->last_acked && cmd_matches_rsp(l1h->last_acked, &rsp)) {
 			LOGP(DTRX, LOGL_NOTICE, "Discarding duplicated RSP "
 				"from old CMD '%s'\n", buf);
 			return 0;
@@ -469,9 +475,9 @@
 		list);
 
 	/* check if response matches command */
-	if (!cmd_matches_rsp(tcm, cmdname, params)) {
+	if (!cmd_matches_rsp(tcm, &rsp)) {
 		/* RSP from a retransmission, skip it */
-		if (l1h->last_acked && cmd_matches_rsp(l1h->last_acked, cmdname, params)) {
+		if (l1h->last_acked && cmd_matches_rsp(l1h->last_acked, &rsp)) {
 			LOGP(DTRX, LOGL_NOTICE, "Discarding duplicated RSP "
 				"from old CMD '%s'\n", buf);
 			return 0;
@@ -484,7 +490,7 @@
 	}
 
 	/* check for response code */
-	if (resp) {
+	if (rsp.status) {
 		LOGP(DTRX, (tcm->critical) ? LOGL_FATAL : LOGL_NOTICE,
 			"transceiver (%s) rejected TRX command "
 			"with response: '%s'\n",

-- 
To view, visit https://gerrit.osmocom.org/11765
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Icb84bce0621042afa4301678ba1cc58d8e3662bb
Gerrit-Change-Number: 11765
Gerrit-PatchSet: 2
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-CC: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181119/e474437c/attachment.htm>


More information about the gerrit-log mailing list