summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-02-20 19:43:02 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-02-20 19:43:02 +0700
commit318f8b78aad5961eba6b179f84e772bff759ade3 (patch)
tree579a991dff3f717b40b222039030a2ea3efe56c6
parentd406afd23e5e0efb38a11bd40a7ff6f0a01ee7f6 (diff)
fake_trx/data_dump.py: use 2 bytes to store message length
One byte may store a value in range [0x00, 0xff]. The maximal 0xff value is 255 in dec, so a message length is limited to 255 bytes. This is enough for GSM bursts, but not for EDGE. Since this change, two bytes of header are used to store the pending message length. All captures created before are not supported anymore... Change-Id: I5a69d5cf2914fe56b2f9acca6054c9470627f91e
-rw-r--r--src/target/fake_trx/data_dump.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/target/fake_trx/data_dump.py b/src/target/fake_trx/data_dump.py
index b9047365..56e314c4 100644
--- a/src/target/fake_trx/data_dump.py
+++ b/src/target/fake_trx/data_dump.py
@@ -30,7 +30,7 @@ class DATADump:
# Constants
TAG_L12TRX = '\x01'
TAG_TRX2L1 = '\x02'
- HDR_LENGTH = 2
+ HDR_LENGTH = 3
# Generates raw bytes from a DATA message
# Return value: raw message bytes
@@ -46,15 +46,18 @@ class DATADump:
# Generate a message payload
msg_raw = msg.gen_msg()
- # Calculate the length
+ # Calculate and pack the message length
msg_len = len(msg_raw)
+ # Pack to unsigned short (2 bytes, BE)
+ msg_len = struct.pack(">H", msg_len)
+
# Concatenate a message with header
- return bytearray([tag, msg_len]) + msg_raw
+ return bytearray(tag + msg_len) + msg_raw
def parse_hdr(self, hdr):
# Extract the header info
- msg_len = struct.unpack("<B", hdr[1])[0]
+ msg_len = struct.unpack(">H", hdr[1:3])[0]
tag = hdr[0]
# Check if tag is known