summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-02-20 18:02:35 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-02-20 18:02:35 +0700
commit3dfd6cbae5b81f287bd95940330458ef1fd8d653 (patch)
tree27754b5bcf389d3a73e70772dd74b662ad50c480
parentafd110a3b5d8a565bffb251f9e031b56605558ac (diff)
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
-rwxr-xr-xsrc/target/fake_trx/trx_sniff.py30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/target/fake_trx/trx_sniff.py b/src/target/fake_trx/trx_sniff.py
index 91c2c4ad..f59e609b 100755
--- a/src/target/fake_trx/trx_sniff.py
+++ b/src/target/fake_trx/trx_sniff.py
@@ -27,6 +27,7 @@ import sys
import scapy.all
+from data_dump import DATADumpFile
from data_msg import *
COPYRIGHT = \
@@ -69,9 +70,9 @@ class Application:
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 @@ class Application:
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 @@ class Application:
# 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
@@ -208,10 +198,6 @@ class Application:
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)