Skip to content

Commit

Permalink
fix(power-cycle): Make all occurrences of power cycles respect the --…
Browse files Browse the repository at this point in the history
…power-cycle-sleep parameter.
  • Loading branch information
emedav authored and rumpelsepp committed Apr 10, 2024
1 parent 8140403 commit c137cd5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/gallia/commands/fuzz/uds/pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async def main(self, args: Namespace) -> None:
logger.result(f"Flow control frames missing: {flow_control_miss}")

logger.info(f"Leaving session 0x{session:02x} via hook")
await self.ecu.leave_session(session)
await self.ecu.leave_session(session, sleep=args.power_cycle_sleep)

if args.observe_can_ids:
recv_task.cancel()
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/commands/scan/uds/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def main(self, args: Namespace) -> None:

logger.result(f"Scan in session {g_repr(session)} is complete!")
logger.info(f"Leaving session {g_repr(session)} via hook")
await self.ecu.leave_session(session)
await self.ecu.leave_session(session, sleep=args.power_cycle_sleep)

async def perform_scan(self, args: Namespace, session: None | int = None) -> None:
positive_DIDs = 0
Expand Down
4 changes: 2 additions & 2 deletions src/gallia/commands/scan/uds/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def main(self, args: Namespace) -> None:
logger.result(f"Scanning in session: {g_repr(session)}")
await self.perform_scan(args, session)

await self.ecu.leave_session(session)
await self.ecu.leave_session(session, sleep=args.power_cycle_sleep)

async def perform_scan(self, args: Namespace, session: None | int = None) -> None:
l_ok: list[int] = []
Expand Down Expand Up @@ -138,7 +138,7 @@ async def perform_scan(self, args: Namespace, session: None | int = None) -> Non
f"ECU did not respond after reset level {g_repr(sub_func)}; try power cycle…"
)
try:
await self.ecu.power_cycle()
await self.ecu.power_cycle(args.power_cycle_sleep)
await self.ecu.wait_for_ecu()
except (TimeoutError, ConnectionError) as e:
logger.error(f"Failed to recover ECU: {g_repr(e)}; exit")
Expand Down
2 changes: 1 addition & 1 deletion src/gallia/commands/scan/uds/sa_dump_seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ async def main(self, args: Namespace) -> None:

await file.close()
self.log_size(seeds_file, time.time() - start_time)
await self.ecu.leave_session(session)
await self.ecu.leave_session(session, sleep=args.power_cycle_sleep)
2 changes: 1 addition & 1 deletion src/gallia/commands/scan/uds/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def main(self, args: Namespace) -> None:

found[session] = await self.perform_scan(args, session)

await self.ecu.leave_session(session)
await self.ecu.leave_session(session, sleep=args.power_cycle_sleep)

for key, value in found.items():
logger.result(f"findings in session 0x{key:02X}:")
Expand Down
24 changes: 14 additions & 10 deletions src/gallia/services/uds/ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,31 @@ async def callback() -> None:
self.state.reset()
return True

async def leave_session(self, level: int, config: UDSRequestConfig | None = None) -> bool:
async def leave_session(
self,
level: int,
config: UDSRequestConfig | None = None,
sleep: int | None = None,
) -> bool:
"""leave_session() is a hook which can be called explicitly by a
scanner when a session is to be disabled. Use this hook if resetting
the ECU is required, e.g. when disabling the programming session.
Args:
uds: The UDSClient class where this hook is embedded. The caller typically
calls this function with `self` as the first argument.
session: The desired session identifier.
Returns:
True on success, False on error.
"""
resp: service.UDSResponse = await self.ecu_reset(0x01)
if isinstance(resp, service.NegativeResponse):
await self.power_cycle()
if sleep is not None:
await self.power_cycle(sleep=sleep)
else:
await self.power_cycle()
await self.reconnect()
await self.wait_for_ecu()

resp = await self.set_session(0x01, config=config)
if isinstance(resp, service.NegativeResponse):
await self.power_cycle()
if sleep is not None:
await self.power_cycle(sleep=sleep)
else:
await self.power_cycle()
await self.reconnect()
return True

Expand Down

0 comments on commit c137cd5

Please sign in to comment.