From 2e636458a6c78a019532b912e936a43d8b2bd817 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 28 Oct 2025 16:47:22 -0700 Subject: [PATCH] op adb: forward all openpilot service ports (#36518) * op adb: forward all openpilot service ports * cleanup --- tools/scripts/adb_ssh.sh | 41 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/tools/scripts/adb_ssh.sh b/tools/scripts/adb_ssh.sh index 2fe2873a3d..ad65693722 100755 --- a/tools/scripts/adb_ssh.sh +++ b/tools/scripts/adb_ssh.sh @@ -1,7 +1,42 @@ #!/usr/bin/env bash -set -e +set -euo pipefail -# this is a little nicer than "adb shell" since -# "adb shell" doesn't do full terminal emulation +# Forward all openpilot service ports +mapfile -t SERVICE_PORTS < <(python3 - <<'PY' +from cereal.services import SERVICE_LIST + +FNV_PRIME = 0x100000001b3 +FNV_OFFSET_BASIS = 0xcbf29ce484222325 +START_PORT = 8023 +MAX_PORT = 65535 +PORT_RANGE = MAX_PORT - START_PORT +MASK = 0xffffffffffffffff + +def fnv1a(endpoint: str) -> int: + h = FNV_OFFSET_BASIS + for b in endpoint.encode(): + h ^= b + h = (h * FNV_PRIME) & MASK + return h + +ports = set() +for name in SERVICE_LIST.keys(): + port = START_PORT + fnv1a(name) % PORT_RANGE + ports.add((name, port)) + +for name, port in sorted(ports): + print(f"{name} {port}") +PY +) + +for entry in "${SERVICE_PORTS[@]}"; do + name="${entry% *}" + port="${entry##* }" + adb forward "tcp:${port}" "tcp:${port}" > /dev/null +done + +# Forward SSH port first for interactive shell access. adb forward tcp:2222 tcp:22 + +# SSH! ssh comma@localhost -p 2222 "$@"