[PATCH] osmocom-bb[master]: fake_trx/trx_sniff.py: use DATADumpFile for capture writing

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
Thu Feb 22 15:33:44 UTC 2018


Review at  https://gerrit.osmocom.org/6834

fake_trx/trx_sniff.py: use DATADumpFile for capture writing

Since we have a separate class for DATA capture management now,
no need to implement the wheel - let's just use it!

Change-Id: I7c30bcea294ce7270bf905ae5420a06dbc2e46f1
---
M src/target/fake_trx/trx_sniff.py
1 file changed, 8 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/34/6834/1

diff --git a/src/target/fake_trx/trx_sniff.py b/src/target/fake_trx/trx_sniff.py
index 91c2c4a..f59e609 100755
--- a/src/target/fake_trx/trx_sniff.py
+++ b/src/target/fake_trx/trx_sniff.py
@@ -27,6 +27,7 @@
 
 import scapy.all
 
+from data_dump import DATADumpFile
 from data_msg import *
 
 COPYRIGHT = \
@@ -69,9 +70,9 @@
 		print(COPYRIGHT)
 		self.parse_argv()
 
-		# Open requested file for writing
+		# Open requested capture file
 		if self.output_file is not None:
-			self.output_file = open(self.output_file, "ab")
+			self.ddf = DATADumpFile(self.output_file)
 
 	def run(self):
 		# Compose a packet filter
@@ -126,10 +127,8 @@
 		print("[i] %s burst: %s" \
 			% ("L1 -> TRX" if l12trx else "TRX -> L1", msg.desc_hdr()))
 
-		# Poke burst handler
-		rc = self.burst_handle(l12trx, msg_raw, msg)
-		if rc is False:
-			self.shutdown()
+		# Poke message handler
+		self.msg_handle(msg)
 
 		# Poke burst counter
 		rc = self.burst_count(msg.fn, msg.tn)
@@ -158,22 +157,13 @@
 		# Burst passed ;)
 		return True
 
-	def burst_handle(self, l12trx, msg_raw, msg):
+	def msg_handle(self, msg):
 		if self.print_bursts:
 			print(msg.burst)
 
+		# Append a new message to the capture
 		if self.output_file is not None:
-			# TLV: tag defines burst direction (one byte, BE)
-			self.output_file.write('\x01' if l12trx else '\x02')
-
-			# TLV: length of value (one byte, BE)
-			length = len(msg_raw)
-			self.output_file.write(chr(length))
-
-			# TLV: raw value
-			self.output_file.write(msg_raw)
-
-		return True
+			self.ddf.append_msg(msg)
 
 	def burst_count(self, fn, tn):
 		# Update frame counter
@@ -207,10 +197,6 @@
 		# Print statistics
 		print("[i] %u bursts handled, %u dropped" \
 			% (self.cnt_burst_num, self.cnt_burst_dropped_num))
-
-		# Close output file if opened
-		if self.output_file is not None:
-			self.output_file.close()
 
 		# Exit
 		sys.exit(0)

-- 
To view, visit https://gerrit.osmocom.org/6834
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c30bcea294ce7270bf905ae5420a06dbc2e46f1
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list