Add BT detection in pm3 script for linux

This commit is contained in:
Philippe Teuwen 2020-04-21 12:01:26 +02:00
parent 73c4a37684
commit 0c8624ccd1

58
pm3
View file

@ -2,6 +2,12 @@
# Usage: run option -h to get help # 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") PM3PATH=$(dirname "$0")
FULLIMAGE="fullimage.elf" FULLIMAGE="fullimage.elf"
BOOTIMAGE="bootrom.elf" BOOTIMAGE="bootrom.elf"
@ -17,6 +23,7 @@ else
fi fi
PM3LIST=() PM3LIST=()
SHOWLIST=false
function get_pm3_list_Linux { function get_pm3_list_Linux {
PM3LIST=() PM3LIST=()
@ -25,6 +32,18 @@ function get_pm3_list_Linux {
PM3LIST+=("$DEV") PM3LIST+=("$DEV")
fi fi
done 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 { function get_pm3_list_macOS {
@ -82,6 +101,8 @@ See "$CLIENT -h" for more details on options.
EOF EOF
} }
elif [ "$SCRIPT" = "pm3-flash" ]; then elif [ "$SCRIPT" = "pm3-flash" ]; then
FINDBTDONGLE=false
FINDBTDIRECT=false
CMD() { CMD() {
ARGS=("--port" "$1" "--flash") ARGS=("--port" "$1" "--flash")
shift; shift;
@ -115,6 +136,8 @@ Example:
EOF EOF
} }
elif [ "$SCRIPT" = "pm3-flash-all" ]; then elif [ "$SCRIPT" = "pm3-flash-all" ]; then
FINDBTDONGLE=false
FINDBTDIRECT=false
CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; } CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; }
HELP() { HELP() {
cat << EOF cat << EOF
@ -130,6 +153,8 @@ Usage:
EOF EOF
} }
elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then
FINDBTDONGLE=false
FINDBTDIRECT=false
CMD() { $CLIENT "--port" "$1" "--flash" "--image" "$FULLIMAGE"; } CMD() { $CLIENT "--port" "$1" "--flash" "--image" "$FULLIMAGE"; }
HELP() { HELP() {
cat << EOF cat << EOF
@ -145,6 +170,8 @@ Usage:
EOF EOF
} }
elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then
FINDBTDONGLE=false
FINDBTDIRECT=false
CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; } CMD() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; }
HELP() { HELP() {
cat << EOF cat << EOF
@ -176,6 +203,15 @@ for ARG in "$@"; do
fi fi
done 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 # Number of the proxmark3 we're interested in
N=1 N=1
if [ "$1" == "-n" ]; then if [ "$1" == "-n" ]; then
@ -189,7 +225,6 @@ if [ "$1" == "-n" ]; then
fi fi
fi fi
echo >&2 "[=] Waiting for Proxmark3 to appear..."
HOSTOS=$(uname | awk '{print toupper($0)}') HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then if [ "$HOSTOS" = "LINUX" ]; then
if uname -a|grep -q Microsoft; then if uname -a|grep -q Microsoft; then
@ -212,13 +247,32 @@ else
exit 1 exit 1
fi 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 # 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 while true; do
$GETPM3LIST $N
if [ ${#PM3LIST[*]} -ge $N ]; then if [ ${#PM3LIST[*]} -ge $N ]; then
break break
fi fi
sleep .1 sleep .1
$GETPM3LIST
done done
if [ ${#PM3LIST} -lt $N ]; then if [ ${#PM3LIST} -lt $N ]; then