Change in ...osmocom-bb[master]: trx_toolkit/ctrl_if_trx.py: implement TRXD header version negotiation

fixeria gerrit-no-reply at lists.osmocom.org
Tue Jul 16 08:02:06 UTC 2019


fixeria has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/osmocom-bb/+/14692 )

Change subject: trx_toolkit/ctrl_if_trx.py: implement TRXD header version negotiation
......................................................................

trx_toolkit/ctrl_if_trx.py: implement TRXD header version negotiation

Messages on DATA interface may have different header formats, defined
by a version number, which can be negotiated on the control interface.
By default, the Transceiver will use the legacy header version (0).

The header format negotiation can be initiated by the L1 using the
'SETFORMAT' command. If the requested version is not supported by
the transceiver, status code of the response message should indicate
a preferred (basically, the latest) version. The format of this
message is the following:

  L1 -> TRX: CMD SETFORMAT VER_REQ
  L1 <- TRX: RSP SETFORMAT VER_RSP VER_REQ

where:

  - VER_REQ is the requested version (suggested by the L1),
  - VER_RSP is either the applied version if matches VER_REQ,
    or a preferred version if VER_REQ is not supported.

If the transceiver indicates VER_RSP different than VER_REQ, the L1
is supposed to reinitiate the version negotiation using the suggested
VER_RSP. For example:

  L1 -> TRX: CMD SETFORMAT 2
  L1 <- TRX: RSP SETFORMAT 1 2

  L1 -> TRX: CMD SETFORMAT 1
  L1 <- TRX: RSP SETFORMAT 1 1

If no suitable VER_RSP is found, or the VER_REQ is incorrect,
the status code in the response shall be -1.

As soon as VER_RSP matches VER_REQ in the response, the process
of negotiation is complete. Changing the header version is
supposed to be done before POWERON, but can be also done after.

Change-Id: I8d441b2559863d2dbd680db371062e4f3a2f9ff9
Related: OS#4006
---
M src/target/trx_toolkit/ctrl_if_trx.py
M src/target/trx_toolkit/data_if.py
2 files changed, 75 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  osmith: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



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

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I8d441b2559863d2dbd680db371062e4f3a2f9ff9
Gerrit-Change-Number: 14692
Gerrit-PatchSet: 4
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190716/2fc306b7/attachment.html>


More information about the gerrit-log mailing list