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/.
Harald Welte gerrit-no-reply at lists.osmocom.org
Review at https://gerrit.osmocom.org/6824
fake_trx/data_msg.py: implement header randomization
This feature could be used by both burst_gen.py and burst_send.py.
Change-Id: I724e267382ff32ef1f964b1ee6cbe99069139867
---
M src/target/fake_trx/data_msg.py
1 file changed, 64 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/24/6824/1
diff --git a/src/target/fake_trx/data_msg.py b/src/target/fake_trx/data_msg.py
index 9acc0f1..c561280 100644
--- a/src/target/fake_trx/data_msg.py
+++ b/src/target/fake_trx/data_msg.py
@@ -44,6 +44,19 @@
def parse_hdr(self, hdr):
raise NotImplementedError
+ # Generates a random frame number
+ def rand_fn(self):
+ return random.randint(0, GSM_HYPERFRAME)
+
+ # Generates a random timeslot number
+ def rand_tn(self):
+ return random.randint(0, 7)
+
+ # Randomizes the message header
+ def rand_hdr(self):
+ self.fn = self.rand_fn()
+ self.tn = self.rand_tn()
+
# Converts unsigned soft-bits {254..0} to soft-bits {-127..127}
def usbit2sbit(self, bits):
buf = []
@@ -201,6 +214,21 @@
return True
+ # Generates a random power level
+ def rand_pwr(self, min = None, max = None):
+ if min is None:
+ min = self.PWR_MIN
+
+ if max is None:
+ max = self.PWR_MAX
+
+ return random.randint(min, max)
+
+ # Randomizes message specific header
+ def rand_hdr(self):
+ DATAMSG.rand_hdr(self)
+ self.pwr = self.rand_pwr()
+
# Generates message specific header part
def gen_hdr(self):
# Allocate an empty byte-array
@@ -257,6 +285,32 @@
return False
return True
+
+ # Generates a random RSSI value
+ def rand_rssi(self, min = None, max = None):
+ if min is None:
+ min = self.RSSI_MIN
+
+ if max is None:
+ max = self.RSSI_MAX
+
+ return random.randint(min, max)
+
+ # Generates a ToA (Time of Arrival) value
+ def rand_toa(self, min = None, max = None):
+ if min is None:
+ min = self.TOA_MIN
+
+ if max is None:
+ max = self.TOA_MAX
+
+ return random.uniform(min, max)
+
+ # Randomizes message specific header
+ def rand_hdr(self):
+ DATAMSG.rand_hdr(self)
+ self.rssi = self.rand_rssi()
+ self.toa = self.rand_toa()
# Generates message specific header part
def gen_hdr(self):
@@ -350,6 +404,16 @@
print("[?] Compare message specific data: OK")
+ # Validate header randomization
+ for i in range(0, 100):
+ msg_l12trx_ref.rand_hdr()
+ msg_trx2l1_ref.rand_hdr()
+
+ assert(msg_l12trx_ref.validate())
+ assert(msg_trx2l1_ref.validate())
+
+ print("[?] Validate header randomization: OK")
+
# Bit conversation test
usbits_ref = range(0, 256)
sbits_ref = range(-127, 128)
--
To view, visit https://gerrit.osmocom.org/6824
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I724e267382ff32ef1f964b1ee6cbe99069139867
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>