-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flexray): Add a helper script to dump bus traffic
- Loading branch information
1 parent
08becc0
commit 9dcf671
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import sys | ||
from argparse import BooleanOptionalAction, Namespace | ||
|
||
assert sys.platform == "win32" | ||
|
||
from gallia.command import AsyncScript | ||
from gallia.transports.flexray_vector import RawFlexRayTransport | ||
from gallia.utils import auto_int | ||
|
||
|
||
class FRDump(AsyncScript): | ||
"""Spawn a virtual ECU for testing purposes""" | ||
|
||
COMMAND = "fr-dump" | ||
SHORT_HELP = "runs a helper tool that dumps flexray bus traffic to stdout" | ||
|
||
def configure_parser(self) -> None: | ||
self.parser.add_argument( | ||
"--src-slot", | ||
type=auto_int, | ||
help="the source flexray slot", | ||
) | ||
self.parser.add_argument( | ||
"--target-slot", | ||
type=auto_int, | ||
help="the target flexray slot", | ||
) | ||
self.parser.add_argument( | ||
"--filter-null-frames", | ||
action=BooleanOptionalAction, | ||
default=True, | ||
help="filter mysterious null frames out", | ||
) | ||
|
||
async def main(self, args: Namespace) -> None: | ||
tp = await RawFlexRayTransport.connect("fr-raw:", None) | ||
|
||
if args.src_slot or args.target_slot: | ||
tp.add_block_all_filter() | ||
|
||
if args.src_slot is not None: | ||
tp.set_acceptance_filter(args.src_slot) | ||
|
||
if args.target_slot is not None: | ||
tp.set_acceptance_filter(args.target_slot) | ||
|
||
tp.activate_channel() | ||
|
||
while True: | ||
frame = await tp.read_frame() | ||
|
||
if args.filter_null_frames is True: | ||
# Best effort; in our use case this was the ISO-TP header. | ||
# The first ISO-TP header byte is never 0x00. | ||
if frame.data[0] == 0x00: | ||
continue | ||
|
||
print(f" -> slot_id: {frame.slot_id}; data: {frame.data.hex()}") |