From f6aee41fb1bdb0c713979d632bbce1db5c7878fc Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Fri, 15 Oct 2021 17:01:07 +0200 Subject: [PATCH] send-at-retry: add script --- src/send-at-retry/README.md | 7 +++ src/send-at-retry/data/lxc_attach.sh | 7 +++ .../data/send_at_retry_android.sh | 47 +++++++++++++++++++ src/send-at-retry/data/send_at_retry_ut.sh | 12 +++++ src/send-at-retry/send_at_retry.sh | 18 +++++++ 5 files changed, 91 insertions(+) create mode 100644 src/send-at-retry/README.md create mode 100644 src/send-at-retry/data/lxc_attach.sh create mode 100644 src/send-at-retry/data/send_at_retry_android.sh create mode 100644 src/send-at-retry/data/send_at_retry_ut.sh create mode 100755 src/send-at-retry/send_at_retry.sh diff --git a/src/send-at-retry/README.md b/src/send-at-retry/README.md new file mode 100644 index 0000000..8add0d5 --- /dev/null +++ b/src/send-at-retry/README.md @@ -0,0 +1,7 @@ +Send AT commands multiple times until an expected string is in the reply. + +This hack is a PoC for sending AT commands through the same pseudo TTY that +mtkfusionrild is using. + +Preparation: +- Ubuntu touch with ssh enabled and writable rootfs diff --git a/src/send-at-retry/data/lxc_attach.sh b/src/send-at-retry/data/lxc_attach.sh new file mode 100644 index 0000000..3d3268e --- /dev/null +++ b/src/send-at-retry/data/lxc_attach.sh @@ -0,0 +1,7 @@ +#!/bin/sh -ex +# SPDX-License-Identifier: GPL-2.0-or-later +# Author: Oliver Smith +# Copyright 2021 sysmocom - s.f.m.c. GmbH +# Related: https://github.com/ubports/ubuntu-touch/issues/1836 + +LD_PRELOAD= LD_LIBRARY_PATH= lxc-attach -n android -e -- "$@" diff --git a/src/send-at-retry/data/send_at_retry_android.sh b/src/send-at-retry/data/send_at_retry_android.sh new file mode 100644 index 0000000..0cff18d --- /dev/null +++ b/src/send-at-retry/data/send_at_retry_android.sh @@ -0,0 +1,47 @@ +#!/bin/sh -e +# SPDX-License-Identifier: GPL-2.0-or-later +# Author: Oliver Smith +# Copyright 2021 sysmocom - s.f.m.c. GmbH + +DEV="/dev/radio/ptty2cmd2" +RET="/data/local/tmp/ims_apn" + +# $1: AT command to send +# $2: retry until finding this string in reply +send() { + echo "---" + echo "> $1" + + rm -rf "$RET" + cat "$DEV" > "$RET" & + pid="$!" + + for i in $(seq 1 5); do + printf . + echo "$1" > "$DEV" + sleep 0.1 + + if grep -q "$2" "$RET"; then + cat "$RET" + kill "$pid" + return + fi + done + + kill "$pid" + echo + echo "ERROR: could not find '$2' in response:" + cat "$RET" + exit 1 +} + +# Query firmware information +send 'AT+CGMI' '+CGMI:' +send 'AT+CGMM' '+CGMM:' +send 'AT+CGMR' '+CGMR:' + +# Add your at commands below + +echo +echo "---" +echo "done" diff --git a/src/send-at-retry/data/send_at_retry_ut.sh b/src/send-at-retry/data/send_at_retry_ut.sh new file mode 100644 index 0000000..31590b2 --- /dev/null +++ b/src/send-at-retry/data/send_at_retry_ut.sh @@ -0,0 +1,12 @@ +#!/bin/sh -ex +# SPDX-License-Identifier: GPL-2.0-or-later +# Author: Oliver Smith +# Copyright 2021 sysmocom - s.f.m.c. GmbH +set -x +dump_name="$1" + +chmod +x /mnt/tmp/android_run.sh +chmod +x /tmp/lxc_attach.sh + +sudo /tmp/lxc_attach.sh /mnt/tmp/android_run.sh "$1" 2>&1 \ + | tee /tmp/"$dump_name" diff --git a/src/send-at-retry/send_at_retry.sh b/src/send-at-retry/send_at_retry.sh new file mode 100755 index 0000000..e9cfa47 --- /dev/null +++ b/src/send-at-retry/send_at_retry.sh @@ -0,0 +1,18 @@ +#!/bin/sh -ex +# SPDX-License-Identifier: GPL-2.0-or-later +# Author: Oliver Smith +# Copyright 2021 sysmocom - s.f.m.c. GmbH +dump_name="$(date "+%Y-%m-%d_%H%M%S")" + +adb push data/send_at_retry_ut.sh /tmp/run.sh +adb push data/lxc_attach.sh /tmp/lxc_attach.sh +adb push data/send_at_retry_android.sh /mnt/tmp/android_run.sh + +adb forward tcp:8023 tcp:22 +ssh -t -p 8023 phablet@localhost \ + sh -e /tmp/run.sh "$dump_name" + +mkdir -p dump/"${dump_name}_at" +adb pull /tmp/"$dump_name" "dump/${dump_name}_at/${dump_name}.txt" + +ln -sf "$PWD/dump/${dump_name}_at/${dump_name}.txt" /tmp/latest.txt