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/.
fixeria gerrit-no-reply at lists.osmocom.orgfixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/14576 Change subject: trx_toolkit/data_msg.py: implement header version coding ...................................................................... trx_toolkit/data_msg.py: implement header version coding Change-Id: Idb0377d66290eb9c15d6998a5806a84fa2e5dd02 Related: OS#4006 --- M src/target/trx_toolkit/data_msg.py 1 file changed, 92 insertions(+), 15 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/76/14576/1 diff --git a/src/target/trx_toolkit/data_msg.py b/src/target/trx_toolkit/data_msg.py index 9ad19f6..669c9d2 100644 --- a/src/target/trx_toolkit/data_msg.py +++ b/src/target/trx_toolkit/data_msg.py @@ -4,7 +4,7 @@ # TRX Toolkit # DATA interface message definitions and helpers # -# (C) 2018 by Vadim Yanitskiy <axilirator at gmail.com> +# (C) 2018-2019 by Vadim Yanitskiy <axilirator at gmail.com> # # All Rights Reserved # @@ -49,20 +49,53 @@ parent of both DATAMSG_L12TRX and DATAMSG_TRX2L2 (see below), and has the following fields: - +--------------+-------------------+ - | TN (1 octet) | FN (4 octets, BE) | - +--------------+-------------------+ + +-----------------+----------------+-------------------+ + | VER (1/2 octet) | TN (1/2 octet) | FN (4 octets, BE) | + +-----------------+----------------+-------------------+ where: - - TN is TDMA time-slot number (1 octet), and + - VER is the header version indicator (1/2 octet MSB), + - TN is TDMA time-slot number (1/2 octet LSB), and - FN is TDMA frame number (4 octets, big endian). + == Header version indication + + It may be necessary to extend the message specific header + with more information. Since this is not a TLV-based + protocol, we need to include the header format version. + + +-----------------+------------------------+ + | 7 6 5 4 3 2 1 0 | bit numbers | + +-----------------+------------------------+ + | X X X X . . . . | header version (0..15) | + +-----------------+------------------------+ + | . . . . . X X X | TDMA TN (0..7) | + +-----------------+------------------------+ + | . . . . X . . . | RESERVED (0) | + +-----------------+------------------------+ + + Instead of prepending an additional byte, it was decided + to use bits 4..7 of the first octet, which are always + zero-initialized due to the value range of TDMA TN. This + would prevent Wireshark from misinterpreting the message + header version (e.g. 0x01) as TDMA TN. + + The reserved bit number 3 can be used in the future to extend + the TDMA TN range to (0..15), in case anybody would need + to transfer UMTS bursts. + + The legacy header version (0x00) is assumed as the default. + """ + # NOTE: up to 15 (0x0f) versions can be encoded + known_versions = [0x00, 0x01] + # Common constructor - def __init__(self, fn = None, tn = None, burst = None): + def __init__(self, fn = None, tn = None, burst = None, ver = 0): self.burst = burst + self.ver = ver self.fn = fn self.tn = tn @@ -99,6 +132,9 @@ def desc_hdr(self): result = "" + if self.ver > 0: + result += ("ver=%u " % self.ver) + if self.fn is not None: result += ("fn=%u " % self.fn) @@ -148,6 +184,9 @@ # Validates the message fields def validate(self): + if not self.ver in self.known_versions: + return False + if self.burst is None: return False @@ -177,10 +216,10 @@ # Allocate an empty byte-array buf = bytearray() - # Put timeslot index - buf.append(self.tn) + # Put version (4 bits) and TDMA TN (3 bits) + buf.append((self.ver << 4) | (self.tn & 0x07)) - # Put frame number (4 octets, BE) + # Put TDMA FN (4 octets, BE) buf += struct.pack(">L", self.fn) # Generate message specific header part @@ -206,9 +245,12 @@ if length < (self.HDR_LEN + GSM_BURST_LEN): raise ValueError("Message is to short") - # Parse both fn and tn + # Parse version and TDMA TN + self.ver = (msg[0] >> 4) + self.tn = (msg[0] & 0x07) + + # Parse TDMA FN self.fn = struct.unpack(">L", msg[1:5])[0] - self.tn = msg[0] # Specific message part self.parse_hdr(msg) @@ -316,9 +358,9 @@ self.burst = list(burst[:GSM_BURST_LEN]) # Transforms this message to TRX2L1 message - def gen_trx2l1(self): + def gen_trx2l1(self, ver = 0): # Allocate a new message - msg = DATAMSG_TRX2L1(fn = self.fn, tn = self.tn) + msg = DATAMSG_TRX2L1(fn = self.fn, tn = self.tn, ver = ver) # Convert burst bits if self.burst is not None: @@ -477,9 +519,9 @@ self.burst = burst_sbits # Transforms this message to L12TRX message - def gen_l12trx(self): + def gen_l12trx(self, ver = 0): # Allocate a new message - msg = DATAMSG_L12TRX(fn = self.fn, tn = self.tn) + msg = DATAMSG_L12TRX(fn = self.fn, tn = self.tn, ver = ver) # Convert burst bits if self.burst is not None: @@ -602,3 +644,38 @@ assert(msg_trx2l1_dec.burst == msg_trx2l1_dec.ubit2sbit(burst_l12trx_ref)) log.info("Check L12TRX <-> TRX2L1 type transformations: OK") + + # Test header version coding + # TODO: verify transformations with different versions + for ver in DATAMSG.known_versions: + # Create messages of both types + msg_l12trx = DATAMSG_L12TRX(burst = burst_l12trx_ref, ver = ver) + msg_trx2l1 = DATAMSG_TRX2L1(burst = burst_trx2l1_ref, ver = ver) + + # Randomize message specific headers + msg_l12trx.rand_hdr() + msg_trx2l1.rand_hdr() + + # Encode DATA messages + msg_l12trx_enc = msg_l12trx.gen_msg() + msg_trx2l1_enc = msg_trx2l1.gen_msg() + + # Parse generated DATA messages + msg_l12trx_dec = DATAMSG_L12TRX() + msg_trx2l1_dec = DATAMSG_TRX2L1() + msg_l12trx_dec.parse_msg(msg_l12trx_enc) + msg_trx2l1_dec.parse_msg(msg_trx2l1_enc) + + # Match the header version + assert(msg_l12trx_dec.ver == ver) + assert(msg_trx2l1_dec.ver == ver) + + # Match common TDMA fields + assert(msg_l12trx_dec.tn == msg_l12trx.tn) + assert(msg_trx2l1_dec.fn == msg_trx2l1.fn) + + # Compare bursts + assert(msg_l12trx_dec.burst == msg_l12trx.burst) + assert(msg_trx2l1_dec.burst == msg_trx2l1.burst) + + log.info("Check header version %u coding: OK" % ver) -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/14576 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: Idb0377d66290eb9c15d6998a5806a84fa2e5dd02 Gerrit-Change-Number: 14576 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <axilirator at gmail.com> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190622/b80600e8/attachment.htm>