<p>laforge <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bts/+/14611">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">osmo-bts-trx/trx_if.c: add TRXD header version negotiation<br><br>This change introduces a new command for TRXD header format<br>negotiation - SETFORMAT. If the transceiver does not support<br>the format negotiation, it would reject this command with<br>'RSP ERR 1'. If the requested version is not supported by<br>the transceiver, status code of the response message should<br>indicate a preferred (basically, the latest) version.<br><br>The format of SETFORMAT command is the following:<br><br>  L1 -> TRX: CMD SETFORMAT VER_REQ<br>  L1 <- TRX: RSP SETFORMAT VER_RSP VER_REQ<br><br>where:<br><br>  - VER_REQ is the requested version (suggested by the L1),<br>  - VER_RSP is either the applied version if matches VER_REQ,<br>    or a preferred version if VER_REQ is not supported.<br><br>If the transceiver indicates VER_RSP different than VER_REQ,<br>OsmoBTS is supposed to reinitiate the version negotiation<br>using the suggested VER_RSP. For example:<br><br>  L1 -> TRX: CMD SETFORMAT 2<br>  L1 <- TRX: RSP SETFORMAT 1 2<br><br>  L1 -> TRX: CMD SETFORMAT 1<br>  L1 <- TRX: RSP SETFORMAT 1 1<br><br>If no suitable VER_RSP is found, or the VER_REQ is incorrect,<br>the status code in the response would be -1.<br><br>As soon as VER_RSP matches VER_REQ in the response, the process<br>of negotiation is complete. Changing the header version is<br>supposed to be done before POWERON.<br><br>Change-Id: I8afe950bd1ec2afaf3347ff848ee46e69c4f5011<br>Related: OS#4006<br>---<br>M src/osmo-bts-trx/l1_if.c<br>M src/osmo-bts-trx/l1_if.h<br>M src/osmo-bts-trx/trx_if.c<br>M src/osmo-bts-trx/trx_if.h<br>4 files changed, 91 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c</span><br><span>index e6e384a..9c1dc18 100644</span><br><span>--- a/src/osmo-bts-trx/l1_if.c</span><br><span>+++ b/src/osmo-bts-trx/l1_if.c</span><br><span>@@ -208,6 +208,13 @@</span><br><span>                        l1h->config.bsic_sent = 1;</span><br><span>                }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+         /* Ask transceiver to use the newest TRXD header version */</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!l1h->config.setformat_sent) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 trx_if_cmd_setformat(l1h, TRX_DATA_FORMAT_VER);</span><br><span style="color: hsl(120, 100%, 40%);">+                       l1h->config.trxd_hdr_ver_req = TRX_DATA_FORMAT_VER;</span><br><span style="color: hsl(120, 100%, 40%);">+                        l1h->config.setformat_sent = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+            }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>          if (!l1h->config.poweron_sent) {</span><br><span>                  trx_if_cmd_poweron(l1h);</span><br><span>                     l1h->config.poweron_sent = 1;</span><br><span>@@ -264,6 +271,9 @@</span><br><span>       llist_for_each_entry(trx, &bts->trx_list, list) {</span><br><span>             struct phy_instance *pinst = trx_phy_instance(trx);</span><br><span>          struct trx_l1h *l1h = pinst->u.osmotrx.hdl;</span><br><span style="color: hsl(120, 100%, 40%);">+                l1h->config.trxd_hdr_ver_req = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+          l1h->config.trxd_hdr_ver_use = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+          l1h->config.setformat_sent = 0;</span><br><span>           l1h->config.arfcn_sent = 0;</span><br><span>               l1h->config.tsc_sent = 0;</span><br><span>                 l1h->config.bsic_sent = 0;</span><br><span>diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h</span><br><span>index 9c95c53..87df951 100644</span><br><span>--- a/src/osmo-bts-trx/l1_if.h</span><br><span>+++ b/src/osmo-bts-trx/l1_if.h</span><br><span>@@ -6,6 +6,10 @@</span><br><span> #include "trx_if.h"</span><br><span> </span><br><span> struct trx_config {</span><br><span style="color: hsl(120, 100%, 40%);">+     uint8_t                 trxd_hdr_ver_req; /* requested TRXD header version */</span><br><span style="color: hsl(120, 100%, 40%);">+ uint8_t                 trxd_hdr_ver_use; /* actual TRXD header version in use */</span><br><span style="color: hsl(120, 100%, 40%);">+     int                     setformat_sent;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>    uint8_t                 poweron;        /* poweron(1) or poweroff(0) */</span><br><span>      int                     poweron_sent;</span><br><span> </span><br><span>diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c</span><br><span>index e9193ca..3e53fdb 100644</span><br><span>--- a/src/osmo-bts-trx/trx_if.c</span><br><span>+++ b/src/osmo-bts-trx/trx_if.c</span><br><span>@@ -269,6 +269,15 @@</span><br><span>            return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Send "SETFORMAT" command to TRX: change TRXD header format version */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_if_cmd_setformat(struct trx_l1h *l1h, uint8_t ver)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        LOGPPHI(l1h->phy_inst, DTRX, LOGL_INFO,</span><br><span style="color: hsl(120, 100%, 40%);">+            "Requesting TRXD header format version %u\n", ver);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       return trx_ctrl_cmd(l1h, 0, "SETFORMAT", "%u", ver);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Send "SETTSC" command to TRX */</span><br><span> int trx_if_cmd_settsc(struct trx_l1h *l1h, uint8_t tsc)</span><br><span> {</span><br><span>@@ -433,6 +442,8 @@</span><br><span>            expected that they can return different values */</span><br><span>         if (strcmp(tcm->cmd, "SETSLOT") == 0 && strcmp(tcm->params, rsp->params))</span><br><span>                 return false;</span><br><span style="color: hsl(120, 100%, 40%);">+ else if (strcmp(tcm->cmd, "SETFORMAT") == 0 && strcmp(tcm->params, rsp->params))</span><br><span style="color: hsl(120, 100%, 40%);">+           return false;</span><br><span> </span><br><span>    return true;</span><br><span> }</span><br><span>@@ -460,11 +471,59 @@</span><br><span>    return rsp->status == 0 ? 0 : -EINVAL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* TRXD header format negotiation handler.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * If the transceiver does not support the format negotiation, it would</span><br><span style="color: hsl(120, 100%, 40%);">+ * reject SETFORMAT with 'RSP ERR 1'. If the requested version is not</span><br><span style="color: hsl(120, 100%, 40%);">+ * supported by the transceiver, status code of the response message</span><br><span style="color: hsl(120, 100%, 40%);">+ * should indicate a preferred (basically, the latest) version.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int trx_ctrl_rx_rsp_setformat(struct trx_l1h *l1h,</span><br><span style="color: hsl(120, 100%, 40%);">+                                  struct trx_ctrl_rsp *rsp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Old transceivers reject 'SETFORMAT' with 'RSP ERR 1' */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (strcmp(rsp->cmd, "SETFORMAT") != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                LOGPPHI(l1h->phy_inst, DTRX, LOGL_NOTICE,</span><br><span style="color: hsl(120, 100%, 40%);">+                  "Transceiver rejected the format negotiation command, "</span><br><span style="color: hsl(120, 100%, 40%);">+                     "using legacy TRXD header format version (0)\n");</span><br><span style="color: hsl(120, 100%, 40%);">+           l1h->config.trxd_hdr_ver_use = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+          return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Status shall indicate a proper version supported by the transceiver */</span><br><span style="color: hsl(120, 100%, 40%);">+     if (rsp->status < 0 || rsp->status > l1h->config.trxd_hdr_ver_req) {</span><br><span style="color: hsl(120, 100%, 40%);">+           LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                   "Transceiver indicated an out of range "</span><br><span style="color: hsl(120, 100%, 40%);">+                    "header format version %d (requested %u)\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                        rsp->status, l1h->config.trxd_hdr_ver_req);</span><br><span style="color: hsl(120, 100%, 40%);">+             return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Transceiver may suggest a lower version (than requested) */</span><br><span style="color: hsl(120, 100%, 40%);">+        if (rsp->status == l1h->config.trxd_hdr_ver_req) {</span><br><span style="color: hsl(120, 100%, 40%);">+              l1h->config.trxd_hdr_ver_use = rsp->status;</span><br><span style="color: hsl(120, 100%, 40%);">+             LOGPPHI(l1h->phy_inst, DTRX, LOGL_INFO,</span><br><span style="color: hsl(120, 100%, 40%);">+                    "Using TRXD header format version %u\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                    l1h->config.trxd_hdr_ver_use);</span><br><span style="color: hsl(120, 100%, 40%);">+     } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              LOGPPHI(l1h->phy_inst, DTRX, LOGL_DEBUG,</span><br><span style="color: hsl(120, 100%, 40%);">+                   "Transceiver suggests TRXD header version %u (requested %u)\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                     rsp->status, l1h->config.trxd_hdr_ver_req);</span><br><span style="color: hsl(120, 100%, 40%);">+             /* Send another SETFORMAT with suggested version */</span><br><span style="color: hsl(120, 100%, 40%);">+           l1h->config.trxd_hdr_ver_req = rsp->status;</span><br><span style="color: hsl(120, 100%, 40%);">+             trx_if_cmd_setformat(l1h, rsp->status);</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* -EINVAL: unrecoverable error, exit BTS</span><br><span>  * N > 0: try sending originating command again after N seconds</span><br><span>  * 0: Done with response, get originating command out from send queue</span><br><span>  */</span><br><span style="color: hsl(0, 100%, 40%);">-static int trx_ctrl_rx_rsp(struct trx_l1h *l1h, struct trx_ctrl_rsp *rsp, bool critical)</span><br><span style="color: hsl(120, 100%, 40%);">+static int trx_ctrl_rx_rsp(struct trx_l1h *l1h,</span><br><span style="color: hsl(120, 100%, 40%);">+                       struct trx_ctrl_rsp *rsp,</span><br><span style="color: hsl(120, 100%, 40%);">+                     struct trx_ctrl_msg *tcm)</span><br><span> {</span><br><span>    struct phy_instance *pinst = l1h->phy_inst;</span><br><span> </span><br><span>@@ -484,14 +543,18 @@</span><br><span>           }</span><br><span>    } else if (strcmp(rsp->cmd, "SETSLOT") == 0) {</span><br><span>          return trx_ctrl_rx_rsp_setslot(l1h, rsp);</span><br><span style="color: hsl(120, 100%, 40%);">+     /* We may get 'RSP ERR 1' if 'SETFORMAT' is not supported,</span><br><span style="color: hsl(120, 100%, 40%);">+     * so that's why we should use tcm instead of rsp. */</span><br><span style="color: hsl(120, 100%, 40%);">+     } else if (strcmp(tcm->cmd, "SETFORMAT") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+         return trx_ctrl_rx_rsp_setformat(l1h, rsp);</span><br><span>  }</span><br><span> </span><br><span>        if (rsp->status) {</span><br><span style="color: hsl(0, 100%, 40%);">-           LOGPPHI(l1h->phy_inst, DTRX, critical ? LOGL_FATAL : LOGL_NOTICE,</span><br><span style="color: hsl(120, 100%, 40%);">+          LOGPPHI(l1h->phy_inst, DTRX, tcm->critical ? LOGL_FATAL : LOGL_NOTICE,</span><br><span>                         "transceiver rejected TRX command with response: '%s%s%s %d'\n",</span><br><span>                   rsp->cmd, rsp->params[0] != '\0' ? " ":"",</span><br><span>                         rsp->params, rsp->status);</span><br><span style="color: hsl(0, 100%, 40%);">-                if (critical)</span><br><span style="color: hsl(120, 100%, 40%);">+         if (tcm->critical)</span><br><span>                        return -EINVAL;</span><br><span>      }</span><br><span>    return 0;</span><br><span>@@ -547,13 +610,16 @@</span><br><span>                    "Response message '%s' does not match command "</span><br><span>                    "message 'CMD %s%s%s'\n",</span><br><span>                  buf, tcm->cmd, tcm->params_len ? " ":"", tcm->params);</span><br><span style="color: hsl(0, 100%, 40%);">-             goto rsp_error;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+             /* We may get 'RSP ERR 1' for non-critical commands */</span><br><span style="color: hsl(120, 100%, 40%);">+                if (tcm->critical)</span><br><span style="color: hsl(120, 100%, 40%);">+                 goto rsp_error;</span><br><span>      }</span><br><span> </span><br><span>        rsp.cb = tcm->cb;</span><br><span> </span><br><span>     /* check for response code */</span><br><span style="color: hsl(0, 100%, 40%);">-   rc = trx_ctrl_rx_rsp(l1h, &rsp, tcm->critical);</span><br><span style="color: hsl(120, 100%, 40%);">+        rc = trx_ctrl_rx_rsp(l1h, &rsp, tcm);</span><br><span>    if (rc == -EINVAL)</span><br><span>           goto rsp_error;</span><br><span> </span><br><span>diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h</span><br><span>index cdfbd41..dda7116 100644</span><br><span>--- a/src/osmo-bts-trx/trx_if.h</span><br><span>+++ b/src/osmo-bts-trx/trx_if.h</span><br><span>@@ -35,4 +35,10 @@</span><br><span>    const ubit_t *bits, uint16_t nbits);</span><br><span> int trx_if_powered(struct trx_l1h *l1h);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* The latest supported TRXD header format version */</span><br><span style="color: hsl(120, 100%, 40%);">+#define TRX_DATA_FORMAT_VER    1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* Format negotiation command */</span><br><span style="color: hsl(120, 100%, 40%);">+int trx_if_cmd_setformat(struct trx_l1h *l1h, uint8_t ver);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif /* TRX_IF_H */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bts/+/14611">change 14611</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-bts/+/14611"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-bts </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I8afe950bd1ec2afaf3347ff848ee46e69c4f5011 </div>
<div style="display:none"> Gerrit-Change-Number: 14611 </div>
<div style="display:none"> Gerrit-PatchSet: 9 </div>
<div style="display:none"> Gerrit-Owner: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-CC: ipse <Alexander.Chemeris@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>