From 0c8624ccd15e622583ba80df44b5311f77c8e9ad Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 21 Apr 2020 12:01:26 +0200 Subject: [PATCH] Add BT detection in pm3 script for linux --- pm3 | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/pm3 b/pm3 index e702e277f..72a6304a6 100755 --- a/pm3 +++ b/pm3 @@ -2,6 +2,12 @@ # Usage: run option -h to get help +# BT auto detection: only working under Linux at the moment +# Shall we look for white HC-06-USB dongle ? +FINDBTDONGLE=true +# Shall we look for rfcomm interface ? +FINDBTDIRECT=true + PM3PATH=$(dirname "$0") FULLIMAGE="fullimage.elf" BOOTIMAGE="bootrom.elf" @@ -17,6 +23,7 @@ else fi PM3LIST=() +SHOWLIST=false function get_pm3_list_Linux { PM3LIST=() @@ -25,6 +32,18 @@ function get_pm3_list_Linux { PM3LIST+=("$DEV") fi done + if $FINDBTDONGLE; then + for DEV in $(find /dev/ttyUSB* 2>/dev/null); do + if udevadm info -q property -n "$DEV" |grep -q "ID_MODEL=CP2104_USB_to_UART_Bridge_Controller"; then + PM3LIST+=("$DEV") + fi + done + fi + if $FINDBTDIRECT; then + for DEV in $(rfcomm -a|grep " 20:19:0[45]"|sed 's/:.*//'); do + PM3LIST+=("/dev/$DEV") + done + fi } function get_pm3_list_macOS { @@ -82,6 +101,8 @@ See "$CLIENT -h" for more details on options. EOF } elif [ "$SCRIPT" = "pm3-flash" ]; then + FINDBTDONGLE=false + FINDBTDIRECT=false CMD() { ARGS=("--port" "$1" "--flash") shift; @@ -115,6 +136,8 @@ Example: EOF } elif [ "$SCRIPT" = "pm3-flash-all" ]; then + FINDBTDONGLE=false + FINDBTDIRECT=false CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; } HELP() { cat << EOF @@ -130,6 +153,8 @@ Usage: EOF } elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then + FINDBTDONGLE=false + FINDBTDIRECT=false CMD() { $CLIENT "--port" "$1" "--flash" "--image" "$FULLIMAGE"; } HELP() { cat << EOF @@ -145,6 +170,8 @@ Usage: EOF } elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then + FINDBTDONGLE=false + FINDBTDIRECT=false CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; } HELP() { cat << EOF @@ -176,6 +203,15 @@ for ARG in "$@"; do fi done +if [ "$1" == "--list" ]; then + shift + if [ "$1" != "" ]; then + echo "Option --list must be used alone" + exit 1 + fi + SHOWLIST=true +fi + # Number of the proxmark3 we're interested in N=1 if [ "$1" == "-n" ]; then @@ -189,7 +225,6 @@ if [ "$1" == "-n" ]; then fi fi -echo >&2 "[=] Waiting for Proxmark3 to appear..." HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then if uname -a|grep -q Microsoft; then @@ -212,13 +247,32 @@ else exit 1 fi +if $SHOWLIST; then + $GETPM3LIST + if [ ${#PM3LIST} -lt 1 ]; then + echo "[!!] No port found" + exit 0 + fi + n=1 + for DEV in ${PM3LIST[@]} + do + echo "$n: $DEV" + n=$((n+1)) + done + exit 0 +fi + # Wait till we get at least N proxmark3 devices +$GETPM3LIST +if [ ${#PM3LIST} -lt $N ]; then + echo >&2 "[=] Waiting for Proxmark3 to appear..." +fi while true; do - $GETPM3LIST $N if [ ${#PM3LIST[*]} -ge $N ]; then break fi sleep .1 + $GETPM3LIST done if [ ${#PM3LIST} -lt $N ]; then