<p>fixeria <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmocom-bb/+/14692">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  osmith: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">trx_toolkit/ctrl_if_trx.py: implement TRXD header version negotiation<br><br>Messages on DATA interface may have different header formats, defined<br>by a version number, which can be negotiated on the control interface.<br>By default, the Transceiver will use the legacy header version (0).<br><br>The header format negotiation can be initiated by the L1 using the<br>'SETFORMAT' command. If the requested version is not supported by<br>the transceiver, status code of the response message should indicate<br>a preferred (basically, the latest) version. The format of this<br>message 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, the L1<br>is supposed to reinitiate the version negotiation using the suggested<br>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 shall 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, but can be also done after.<br><br>Change-Id: I8d441b2559863d2dbd680db371062e4f3a2f9ff9<br>Related: OS#4006<br>---<br>M src/target/trx_toolkit/ctrl_if_trx.py<br>M src/target/trx_toolkit/data_if.py<br>2 files changed, 75 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/target/trx_toolkit/ctrl_if_trx.py b/src/target/trx_toolkit/ctrl_if_trx.py</span><br><span>index 26a844f..8cb5c1a 100644</span><br><span>--- a/src/target/trx_toolkit/ctrl_if_trx.py</span><br><span>+++ b/src/target/trx_toolkit/ctrl_if_trx.py</span><br><span>@@ -4,7 +4,7 @@</span><br><span> # TRX Toolkit</span><br><span> # CTRL interface implementation (common commands)</span><br><span> #</span><br><span style="color: hsl(0, 100%, 40%);">-# (C) 2016-2018 by Vadim Yanitskiy <axilirator@gmail.com></span><br><span style="color: hsl(120, 100%, 40%);">+# (C) 2016-2019 by Vadim Yanitskiy <axilirator@gmail.com></span><br><span> #</span><br><span> # All Rights Reserved</span><br><span> #</span><br><span>@@ -25,6 +25,7 @@</span><br><span> import logging as log</span><br><span> </span><br><span> from ctrl_if import CTRLInterface</span><br><span style="color: hsl(120, 100%, 40%);">+from data_msg import DATAMSG</span><br><span> </span><br><span> class CTRLInterfaceTRX(CTRLInterface):</span><br><span>   """ CTRL interface handler for common transceiver management commands.</span><br><span>@@ -42,6 +43,45 @@</span><br><span>   that is prioritized, i.e. it can overwrite any commands mentioned</span><br><span>    above. If None is returned, a command is considered as unhandled.</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ == TRXD header version negotiation</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  Messages on DATA interface may have different header formats,</span><br><span style="color: hsl(120, 100%, 40%);">+ defined by a version number, which can be negotiated on the</span><br><span style="color: hsl(120, 100%, 40%);">+   control interface. By default, the Transceiver will use the</span><br><span style="color: hsl(120, 100%, 40%);">+   legacy header version (0).</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  The header format negotiation can be initiated by the L1</span><br><span style="color: hsl(120, 100%, 40%);">+      using 'SETFORMAT' command. If the requested version is not</span><br><span style="color: hsl(120, 100%, 40%);">+    supported by the transceiver, status code of the response</span><br><span style="color: hsl(120, 100%, 40%);">+     message should indicate a preferred (basically, the latest)</span><br><span style="color: hsl(120, 100%, 40%);">+   version. The format of this message is the following:</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+         L1 -> TRX: CMD SETFORMAT VER_REQ</span><br><span style="color: hsl(120, 100%, 40%);">+   L1 <- TRX: RSP SETFORMAT VER_RSP VER_REQ</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       where:</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        - VER_REQ is the requested version (suggested by the L1),</span><br><span style="color: hsl(120, 100%, 40%);">+     - VER_RSP is either the applied version if matches VER_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+     or a preferred version if VER_REQ is not supported.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     If the transceiver indicates VER_RSP different than VER_REQ,</span><br><span style="color: hsl(120, 100%, 40%);">+  the L1 is supposed to reinitiate the version negotiation</span><br><span style="color: hsl(120, 100%, 40%);">+      using the suggested VER_RSP. For example:</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     L1 -> TRX: CMD SETFORMAT 2</span><br><span style="color: hsl(120, 100%, 40%);">+         L1 <- TRX: RSP SETFORMAT 1 2</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     L1 -> TRX: CMD SETFORMAT 1</span><br><span style="color: hsl(120, 100%, 40%);">+         L1 <- TRX: RSP SETFORMAT 1 1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   If no suitable VER_RSP is found, or the VER_REQ is incorrect,</span><br><span style="color: hsl(120, 100%, 40%);">+ the status code in the response shall be -1.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        As soon as VER_RSP matches VER_REQ in the response, the process</span><br><span style="color: hsl(120, 100%, 40%);">+       of negotiation is complete. Changing the header version is</span><br><span style="color: hsl(120, 100%, 40%);">+    supposed to be done before POWERON, but can be also done after.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>    """</span><br><span> </span><br><span>       def __init__(self, trx, *udp_link_args):</span><br><span>@@ -147,6 +187,31 @@</span><br><span> </span><br><span>                  return (0, [str(meas_dbm)])</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+               # TRXD header version negotiation</span><br><span style="color: hsl(120, 100%, 40%);">+             if self.verify_cmd(request, "SETFORMAT", 1):</span><br><span style="color: hsl(120, 100%, 40%);">+                        log.debug("(%s) Recv SETFORMAT cmd" % self.trx)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                   # Parse the requested version</span><br><span style="color: hsl(120, 100%, 40%);">+                 ver_req = int(request[1])</span><br><span style="color: hsl(120, 100%, 40%);">+                     # ... and store current for logging</span><br><span style="color: hsl(120, 100%, 40%);">+                   ver_cur = self.trx.data_if._hdr_ver</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                 if ver_req < 0 or ver_req > DATAMSG.CHDR_VERSION_MAX:</span><br><span style="color: hsl(120, 100%, 40%);">+                           log.error("(%s) Incorrect TRXD header version %u"</span><br><span style="color: hsl(120, 100%, 40%);">+                                   % (self.trx, ver_req))</span><br><span style="color: hsl(120, 100%, 40%);">+                                return -1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                   if not self.trx.data_if.set_hdr_ver(ver_req):</span><br><span style="color: hsl(120, 100%, 40%);">+                         ver_rsp = self.trx.data_if.pick_hdr_ver(ver_req)</span><br><span style="color: hsl(120, 100%, 40%);">+                              log.warn("(%s) Requested TRXD header version %u "</span><br><span style="color: hsl(120, 100%, 40%);">+                                     "is not supported, suggesting %u..."</span><br><span style="color: hsl(120, 100%, 40%);">+                                      % (self.trx, ver_req, ver_rsp))</span><br><span style="color: hsl(120, 100%, 40%);">+                               return ver_rsp</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                      log.info("(%s) TRXD header version %u -> %u"</span><br><span style="color: hsl(120, 100%, 40%);">+                             % (self.trx, ver_cur, ver_req))</span><br><span style="color: hsl(120, 100%, 40%);">+                       return ver_req</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>             # Wrong / unknown command</span><br><span>            else:</span><br><span>                        # We don't care about other commands,</span><br><span>diff --git a/src/target/trx_toolkit/data_if.py b/src/target/trx_toolkit/data_if.py</span><br><span>index 10df438..11df756 100644</span><br><span>--- a/src/target/trx_toolkit/data_if.py</span><br><span>+++ b/src/target/trx_toolkit/data_if.py</span><br><span>@@ -42,6 +42,15 @@</span><br><span>              self._hdr_ver = ver</span><br><span>          return True</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+       def pick_hdr_ver(self, ver_req):</span><br><span style="color: hsl(120, 100%, 40%);">+              # Pick a version that is lower or equal to ver_req</span><br><span style="color: hsl(120, 100%, 40%);">+            for ver in DATAMSG.known_versions[::-1]:</span><br><span style="color: hsl(120, 100%, 40%);">+                      if ver <= ver_req:</span><br><span style="color: hsl(120, 100%, 40%);">+                         return ver</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          # No suitable version found</span><br><span style="color: hsl(120, 100%, 40%);">+           return -1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  def match_hdr_ver(self, msg):</span><br><span>                if msg.ver == self._hdr_ver:</span><br><span>                         return True</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmocom-bb/+/14692">change 14692</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/osmocom-bb/+/14692"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmocom-bb </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I8d441b2559863d2dbd680db371062e4f3a2f9ff9 </div>
<div style="display:none"> Gerrit-Change-Number: 14692 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </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: osmith <osmith@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>