From 358730476a08e9e0fc891c60c8e95e07674b5e58 Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Wed, 1 Jan 2025 15:39:40 -0700 Subject: [PATCH 1/6] BTECH UV PRO - Initial support for connecting to the Bluetooth serial device on the BTECH UV PRO. --- overlay/etc/adduser.conf | 2 +- overlay/etc/skel/notes/btech-uv-pro.md | 82 ++++++++++++++++++++ overlay/etc/sudoers.d/et-rfcomm | 7 ++ overlay/opt/emcomm-tools/bin/et-uv-pro | 102 +++++++++++++++++++++++++ scripts/install-packet.sh | 5 ++ 5 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 overlay/etc/skel/notes/btech-uv-pro.md create mode 100644 overlay/etc/sudoers.d/et-rfcomm create mode 100755 overlay/opt/emcomm-tools/bin/et-uv-pro diff --git a/overlay/etc/adduser.conf b/overlay/etc/adduser.conf index 47cc83b..b1fb999 100644 --- a/overlay/etc/adduser.conf +++ b/overlay/etc/adduser.conf @@ -79,7 +79,7 @@ USERS_GID=1981 # new users to other groups. # This is the list of groups that new non-system users will be added to # Default: -EXTRA_GROUPS="dialout cdrom floppy audio video plugdev users" +EXTRA_GROUPS="bluetooth dialout cdrom floppy audio video plugdev users" # If ADD_EXTRA_GROUPS is set to something non-zero, the EXTRA_GROUPS # option above will be default behavior for adding new, non-system users diff --git a/overlay/etc/skel/notes/btech-uv-pro.md b/overlay/etc/skel/notes/btech-uv-pro.md new file mode 100644 index 0000000..89c5a65 --- /dev/null +++ b/overlay/etc/skel/notes/btech-uv-pro.md @@ -0,0 +1,82 @@ +# BTECH UV Pro Bluetooth TNC Notes + +## Linux Packet Configuration + +Edit `/etc/ax25/axports` has root and add the following line. + +``` +PKT1200 KT7RUN 1200 255 2 145.710 +``` + +## Radio Configuration + +* KISS TNC > Enable KISS TNC = checked + +## Pair Radio and Computer + +1. On the radio, start the pairing process by navigating to + Menu > Pairing. + +2. + +3. On the computer, run `bluetoothctl` + +``` +> power on +> scan on +> pair 38:D2:00:00:ED:C8 +> trust 38:D2:00:00:ED:C8 +> quit +``` + +## If you're already paired + +1. Kill any instances of rfcomm if they are running + +``` +sudo killall rfcomm +``` + +2. + +``` +$ sudo rfcomm connect /dev/rfcomm0 38:D2:00:00:ED:C8 +Connected /dev/rfcomm0 to 38:D2:00:00:ED:C8 on channel 1 +Press CTRL-C for hangup +``` + +3. In another window, check that you are connected. + +``` +bluetoothctl info 38:D2:00:00:ED:C8 | grep Connected | awk '{print $2}' +``` + +4. Kill any instances of kissattach if they are running. + +``` +sudo killall kissattach +``` + +5. Attach to the desired AX.25 port. + +``` +$ sudo kissattach /dev/rfcomm0 PKT1200 +AX.25 port PKT1200 bound to device ax0 +``` + +6. Connect to the BBS + +``` +axcall PKT1200 TTPBBS +``` + +Listen to incoming and outgoing packets and capture the time +stamps for the traffic. + +``` +$ sudo axlisten -a -t +``` + +## Troubleshooting + +1. systemctl status bluetooth diff --git a/overlay/etc/sudoers.d/et-rfcomm b/overlay/etc/sudoers.d/et-rfcomm new file mode 100644 index 0000000..b0704af --- /dev/null +++ b/overlay/etc/sudoers.d/et-rfcomm @@ -0,0 +1,7 @@ +%bluetooth ALL=(ALL) NOPASSWD: /usr/bin/rfcomm * +%bluetooth ALL=(ALL) NOPASSWD: /usr/sbin/kissattach /dev/rfcomm0 * +%bluetooth ALL=(ALL) NOPASSWD: /usr/sbin/kissparms * + +%bluetooth ALL=(ALL) NOPASSWD: /usr/bin/killall kissattach +%bluetooth ALL=(ALL) NOPASSWD: /usr/bin/killall kissattach +%bluetooth ALL=(ALL) NOPASSWD: /usr/bin/killall rfcomm diff --git a/overlay/opt/emcomm-tools/bin/et-uv-pro b/overlay/opt/emcomm-tools/bin/et-uv-pro new file mode 100755 index 0000000..c46e37f --- /dev/null +++ b/overlay/opt/emcomm-tools/bin/et-uv-pro @@ -0,0 +1,102 @@ +#!/bin/bash +# +# Author : Gaston Gonzalez +# Date : 1 January 2025 +# Purpose : Utility for accessing the Bluetooth TNC on the BTECH +# UV Pro. + +# TODO: read from file +CONF_FILE="${HOME}/.config/emcomm-tools/btech-uv-pro.json" +MAC="38:D2:00:00:ED:C8" + +# TODO: Write to /etc/ax25/axports + +BT_DEVICE="/dev/rfcomm0" +AX25_PORT="pkt1200" + +RED='\x1B[1;31m' +BLUE='\x1B[1;34m' +CYAN='\x1B[1;36m' +GREEN='\x1B[1;32m' +YELLOW='\x1B[1;33m' +NC='\x1B[0m' + +function usage() { + echo "Usage: $(basename $0) " + echo " connect - Connect to radio via Bluetooth" + echo " pair - Pair radio via Bluetooth" + echo " unpair - Unpair radio via Bluetooth" +} + +if [ $# -ne 1 ]; then + usage + exit 1 +fi + + +stop_all_services() { + + PS_OUT=$(ps -ef | grep [k]issattach) + if [ $? -eq 0 ]; then + echo -e "${BLUE}Killing kissattach process(es)...${NC}" + sudo killall kissattach + fi + + sleep 3 + + PS_OUT=$(ps -ef | grep [r]fcomm) + if [ $? -eq 0 ]; then + echo -e "${BLUE}Killing rfcomm process(es)...${NC}" + sudo killall rfcomm + fi + +} + +case $1 in + connect) + echo -e "${YELLOW}" + read -p "Turn on BTech UV Pro, then press [ENTER] when on." + + is_paired=$(bluetoothctl info ${MAC} | grep "Paired" | awk '{print $2}') + if [ "${is_paired}" != "yes" ]; then + echo -e "${RED}" + et-log "UV Pro is not paired. Run: '$(basename $0) pair'" + echo -e "${NC}" + exit 1 + fi + + echo -e "${GREEN}Found UV Pro with MAC address: ${MAC}" + stop_all_services + + echo -e "${BLUE}Connecting to radio..." + sudo rfcomm connect /dev/rfcomm0 ${MAC} 1>/dev/null 2>&1 & + + sleep 10 && reset + + if [ -e /dev/rfcomm0 ]; then + echo -e "${GREEN}UV Pro connected via Bluetooth serial${NC}" + else + echo -e "${RED}UV Pro failed to connect via Bluetooth serial${NC}" + exit 1 + fi + + echo -e "${BLUE}Connecting KISS interface using ${BT_DEVICE} and AX.25 port: ${AX25_PORT}${NC}" + KISS_OUT=$(sudo kissattach ${BT_DEVICE} ${AX25_PORT}) + + if [ $? -eq 0 ]; then + echo -e "${GREEN}Packet port ready" + else + echo -e "${RED}Failed to setup radio for packet.${NC}" + exit 1 + fi + + KISS_OUT=$(sudo kissparms -c 1 -p ${AX25_PORT}) + + echo -e "${YELLOW}\nRun: axcall pkt1200 ${NC}" + ;; + *) + et-log "Invalid command." + usage + exit 1 + ;; +esac diff --git a/scripts/install-packet.sh b/scripts/install-packet.sh index 3ddd631..9faa7fe 100755 --- a/scripts/install-packet.sh +++ b/scripts/install-packet.sh @@ -1,6 +1,7 @@ #!/bin/bash # Author : Gaston Gonzalez # Date : 27 March 2023 +# Updated : 1 January 2025 # Purpose : Install packet packages set -e @@ -9,3 +10,7 @@ apt install \ ax25-tools \ ax25-apps \ -y + +et-log "Installing rfcomm sudoers rules..." +cp -v ../overlay/etc/sudoers.d/* /etc/sudoers.d/ + From 4d07ee8f52fa57199faf24aa60d87f023d0e98e7 Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Wed, 1 Jan 2025 16:50:49 -0700 Subject: [PATCH 2/6] BTECH UV PRO - Added support for configuring the ax25 ports file on each start using the current et-user --- overlay/opt/emcomm-tools/bin/et-uv-pro | 40 +++++++++++++++++++++++--- scripts/install-packet.sh | 4 +++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/overlay/opt/emcomm-tools/bin/et-uv-pro b/overlay/opt/emcomm-tools/bin/et-uv-pro index c46e37f..eeb112a 100755 --- a/overlay/opt/emcomm-tools/bin/et-uv-pro +++ b/overlay/opt/emcomm-tools/bin/et-uv-pro @@ -9,10 +9,9 @@ CONF_FILE="${HOME}/.config/emcomm-tools/btech-uv-pro.json" MAC="38:D2:00:00:ED:C8" -# TODO: Write to /etc/ax25/axports - BT_DEVICE="/dev/rfcomm0" AX25_PORT="pkt1200" +AX25_CONF_FILE="/etc/ax25/axports" RED='\x1B[1;31m' BLUE='\x1B[1;34m' @@ -33,6 +32,29 @@ if [ $# -ne 1 ]; then exit 1 fi +update_ax25_conf() { + + [ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json" + + CALLSIGN=$(cat ${ET_USER_CONFIG} | jq -r .callsign) + + if [ "${CALLSIGN}" = "N0CALL" ]; then + echo -e "${RED}No callsign set. Run et-user first.${NC}" + exit 1 + fi + + GREP_OUT=$(grep ${AX25_PORT} ${AX25_CONF_FILE}) + if [ $? -eq 0 ]; then + # Delete all existing pkt1200 entries. Note: we can't use sed here + # since we do not have permission to create a temporary file with + # inline replacement. ed modifies the file directly. + printf "g/^pkt1200/d\nw\nq\n" | ed ${AX25_CONF_FILE} > /dev/null 2>&1 + + fi + + echo -e "${BLUE}Adding AX25 port for ${CALLSIGN}${NC}" + echo "pkt1200 ${CALLSIGN} 1200 255 2 1200 Packet" >> ${AX25_CONF_FILE} +} stop_all_services() { @@ -55,7 +77,9 @@ stop_all_services() { case $1 in connect) echo -e "${YELLOW}" - read -p "Turn on BTech UV Pro, then press [ENTER] when on." + echo -e "1. Turn on the BTECH UV PRO" + echo -e "2. Menu > General Settings > KISS TNC = checked" + read -p "3. Press [ENTER] when done." is_paired=$(bluetoothctl info ${MAC} | grep "Paired" | awk '{print $2}') if [ "${is_paired}" != "yes" ]; then @@ -68,6 +92,8 @@ case $1 in echo -e "${GREEN}Found UV Pro with MAC address: ${MAC}" stop_all_services + update_ax25_conf + echo -e "${BLUE}Connecting to radio..." sudo rfcomm connect /dev/rfcomm0 ${MAC} 1>/dev/null 2>&1 & @@ -92,7 +118,13 @@ case $1 in KISS_OUT=$(sudo kissparms -c 1 -p ${AX25_PORT}) - echo -e "${YELLOW}\nRun: axcall pkt1200 ${NC}" + echo -e "${YELLOW}" + echo -e "SAMPLE COMMANDS DESCRIPTION " + echo -e "------------------------------- --------------------------------" + echo -e "axcall pkt1200 Connect directly to a node " + echo -e "axcall pkt1200 Connect to node via a digipeater" + echo -e "${NC}" + ;; *) et-log "Invalid command." diff --git a/scripts/install-packet.sh b/scripts/install-packet.sh index 9faa7fe..e6a2269 100755 --- a/scripts/install-packet.sh +++ b/scripts/install-packet.sh @@ -14,3 +14,7 @@ apt install \ et-log "Installing rfcomm sudoers rules..." cp -v ../overlay/etc/sudoers.d/* /etc/sudoers.d/ +et-log "Updating AX.25 port permissions..." +chgrp -v -R $ET_GROUP /etc/ax25/axports +chmod -v 664 /etc/ax25/axports + From 87f37061e36bde1dff32b05788c834ac66338d75 Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Thu, 2 Jan 2025 17:11:14 -0700 Subject: [PATCH 3/6] BTECH UV PRO - Added experimental support for pair and unpair. --- overlay/etc/skel/notes/btech-uv-pro.md | 82 ------------ overlay/opt/emcomm-tools/bin/et-log | 4 +- overlay/opt/emcomm-tools/bin/et-radio | 2 +- overlay/opt/emcomm-tools/bin/et-uv-pro | 125 ++++++++++++++++-- .../conf/radios.d/btech-uvpro.bt.json | 13 ++ 5 files changed, 128 insertions(+), 98 deletions(-) delete mode 100644 overlay/etc/skel/notes/btech-uv-pro.md create mode 100644 overlay/opt/emcomm-tools/conf/radios.d/btech-uvpro.bt.json diff --git a/overlay/etc/skel/notes/btech-uv-pro.md b/overlay/etc/skel/notes/btech-uv-pro.md deleted file mode 100644 index 89c5a65..0000000 --- a/overlay/etc/skel/notes/btech-uv-pro.md +++ /dev/null @@ -1,82 +0,0 @@ -# BTECH UV Pro Bluetooth TNC Notes - -## Linux Packet Configuration - -Edit `/etc/ax25/axports` has root and add the following line. - -``` -PKT1200 KT7RUN 1200 255 2 145.710 -``` - -## Radio Configuration - -* KISS TNC > Enable KISS TNC = checked - -## Pair Radio and Computer - -1. On the radio, start the pairing process by navigating to - Menu > Pairing. - -2. - -3. On the computer, run `bluetoothctl` - -``` -> power on -> scan on -> pair 38:D2:00:00:ED:C8 -> trust 38:D2:00:00:ED:C8 -> quit -``` - -## If you're already paired - -1. Kill any instances of rfcomm if they are running - -``` -sudo killall rfcomm -``` - -2. - -``` -$ sudo rfcomm connect /dev/rfcomm0 38:D2:00:00:ED:C8 -Connected /dev/rfcomm0 to 38:D2:00:00:ED:C8 on channel 1 -Press CTRL-C for hangup -``` - -3. In another window, check that you are connected. - -``` -bluetoothctl info 38:D2:00:00:ED:C8 | grep Connected | awk '{print $2}' -``` - -4. Kill any instances of kissattach if they are running. - -``` -sudo killall kissattach -``` - -5. Attach to the desired AX.25 port. - -``` -$ sudo kissattach /dev/rfcomm0 PKT1200 -AX.25 port PKT1200 bound to device ax0 -``` - -6. Connect to the BBS - -``` -axcall PKT1200 TTPBBS -``` - -Listen to incoming and outgoing packets and capture the time -stamps for the traffic. - -``` -$ sudo axlisten -a -t -``` - -## Troubleshooting - -1. systemctl status bluetooth diff --git a/overlay/opt/emcomm-tools/bin/et-log b/overlay/opt/emcomm-tools/bin/et-log index fc35879..ce685ad 100755 --- a/overlay/opt/emcomm-tools/bin/et-log +++ b/overlay/opt/emcomm-tools/bin/et-log @@ -2,7 +2,7 @@ # # Author : Gaston Gonzalez # Date : 16 March 2024 -# Updated : 9 October 2024 +# Updated : 2 January 2025 # Purpose : Log message to standard out and log file ET_TEMP_DIR=/tmp/et @@ -27,5 +27,5 @@ fi TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"` -echo $@ +echo -e $@ echo "$TIMESTAMP $@" >> ${ET_LOG_FILE} diff --git a/overlay/opt/emcomm-tools/bin/et-radio b/overlay/opt/emcomm-tools/bin/et-radio index eb5319b..5231894 100755 --- a/overlay/opt/emcomm-tools/bin/et-radio +++ b/overlay/opt/emcomm-tools/bin/et-radio @@ -23,7 +23,7 @@ while IFS= read -r radio; do MODEL=$(cat $radio | jq -r .model) options+=("$ID" "$VENDOR $MODEL") -done < <(find $ET_HOME/conf/radios.d -type f | sort) +done < <(find $ET_HOME/conf/radios.d -type f | grep -v "bt.json" | sort) SELECTED_RADIO=$(dialog --clear --menu "Select a radio:" 21 60 10 "${options[@]}" 3>&1 1>&2 2>&3) exit_status=$? diff --git a/overlay/opt/emcomm-tools/bin/et-uv-pro b/overlay/opt/emcomm-tools/bin/et-uv-pro index eeb112a..eeed685 100755 --- a/overlay/opt/emcomm-tools/bin/et-uv-pro +++ b/overlay/opt/emcomm-tools/bin/et-uv-pro @@ -2,23 +2,23 @@ # # Author : Gaston Gonzalez # Date : 1 January 2025 +# Updated : 2 January 2025 # Purpose : Utility for accessing the Bluetooth TNC on the BTECH -# UV Pro. - -# TODO: read from file -CONF_FILE="${HOME}/.config/emcomm-tools/btech-uv-pro.json" -MAC="38:D2:00:00:ED:C8" +# UV PRO. +ACTIVE_RADIO="${ET_HOME}/conf/radios.d/btech-uvpro.bt.json" +DEVICE_NAME="UV-PRO" BT_DEVICE="/dev/rfcomm0" AX25_PORT="pkt1200" AX25_CONF_FILE="/etc/ax25/axports" -RED='\x1B[1;31m' -BLUE='\x1B[1;34m' -CYAN='\x1B[1;36m' -GREEN='\x1B[1;32m' -YELLOW='\x1B[1;33m' -NC='\x1B[0m' +ESC="\x1B" +RED="${ESC}[1;31m" +BLUE="${ESC}[1;34m" +GREEN="${ESC}[1;32m" +WHITE="${ESC}[97m" +YELLOW="${ESC}[1;33m" +NC="${ESC}[0m" function usage() { echo "Usage: $(basename $0) " @@ -32,6 +32,39 @@ if [ $# -ne 1 ]; then exit 1 fi +error_message() { + echo -e "${RED}" + et-log $* + echo -e "${NC}" +} + +info_message() { + echo -e "${BLUE}" + et-log $* + echo -e "${NC}" +} + +success_message() { + echo -e "${GREEN}" + et-log $* + echo -e "${NC}" +} + +exit_if_no_active_radio () { + if [ ! -e ${ACTIVE_RADIO} ]; then + error_message "${ACTIVE_RADIO} file not found" + exit 1 + fi +} + +get_mac_or_exit () { + MAC=$(cat ${ACTIVE_RADIO} | jq -e -r .bluetooth.mac) + if [ $? -ne 0 ]; then + error_message "No MAC address found in ${ACTIVE_RADIO}." + exit 1 + fi +} + update_ax25_conf() { [ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json" @@ -60,7 +93,7 @@ stop_all_services() { PS_OUT=$(ps -ef | grep [k]issattach) if [ $? -eq 0 ]; then - echo -e "${BLUE}Killing kissattach process(es)...${NC}" + info_message "Killing kissattach process(es)..."$ sudo killall kissattach fi @@ -68,14 +101,80 @@ stop_all_services() { PS_OUT=$(ps -ef | grep [r]fcomm) if [ $? -eq 0 ]; then - echo -e "${BLUE}Killing rfcomm process(es)...${NC}" + info_message "Killing rfcomm process(es)..." sudo killall rfcomm fi } +exit_if_no_active_radio + case $1 in + pair) + + MAC=$(cat ${ACTIVE_RADIO} | jq -e -r .bluetooth.mac) + if [ $? -eq 0 ]; then + PAIR_STATUS=$(bluetoothctl info "${MAC}" | grep "Paired:" | awk '{print $2}') + if [ "${PAIR_STATUS}" == "yes" ]; then + error_message "Device with MAC=${MAC} is already paired." + exit 1 + fi + fi + + echo -e "${YELLOW}" + echo -e "1. Turn on the BTECH UV PRO" + echo -e "2. Goto Menu > Pairing and press OK" + read -p "3. Press [ENTER] when done." + + echo -e "${BLUE}Searching for ${DEVICE_NAME}...${NC}" + + HCI_OUT=$(hcitool scan | grep "${DEVICE_NAME}") + if [ $? -ne 0 ]; then + error_message "Can't find ${DEVICE_NAME}. Make sure that the radio is on and in pairing mode." + exit 1 + fi + + MAC=$(echo ${HCI_OUT} | awk '{print $1}') + + # Update configuration file + sed -i "s|.*mac.*| \"mac\": \"${MAC}\"|g" ${ACTIVE_RADIO} + + echo -e "Now, run the ${YELLOW}bluetooth${NC} command in another terminal.\n" + + echo -e "${BLUE}[bluetooth]# ${YELLOW}power on${NC}" + echo -e "${BLUE}[bluetooth]# ${YELLOW}scan on${NC}\n" + echo -e "Wait until ${DEVICE_NAME} appears.\n" + echo -e "${BLUE}[bluetooth]# ${YELLOW}trust ${MAC}${NC}" + echo -e "${BLUE}[bluetooth]# ${YELLOW}pair ${MAC}${NC}" + echo -e "${BLUE}[${DEVICE_NAME}]# ${YELLOW}quit${NC}" + + ;; + unpair) + MAC=$(cat ${ACTIVE_RADIO} | jq -e -r .bluetooth.mac) + if [ $? -ne 0 ]; then + error_message "No MAC found in radio configuration file." + exit 1 + fi + + PAIR_STATUS=$(bluetoothctl info "${MAC}") + if [ $? -ne 0 ]; then + error_message "No ${MAC} device found. Can't unpair." + exit 1 + fi + + info_message "Unpairing ${DEVICE_NAME}..." + bluetoothctl untrust ${MAC} + bluetoothctl remove ${MAC} + + echo -e "${YELLOW}" + echo -e "You may also want to remove this device from your UV PRO" + echo -e "under Menu > General Settings> Connection > Paired Devices." + echo -e "${NC}" + + ;; connect) + get_mac_or_exit + echo -e "${YELLOW}" echo -e "1. Turn on the BTECH UV PRO" echo -e "2. Menu > General Settings > KISS TNC = checked" diff --git a/overlay/opt/emcomm-tools/conf/radios.d/btech-uvpro.bt.json b/overlay/opt/emcomm-tools/conf/radios.d/btech-uvpro.bt.json new file mode 100644 index 0000000..ba3c7a7 --- /dev/null +++ b/overlay/opt/emcomm-tools/conf/radios.d/btech-uvpro.bt.json @@ -0,0 +1,13 @@ +{ + "id": "btech-uvpro", + "vendor": "BTECH", + "model": "UV PRO (BT)", + "bluetooth": { + "mac": "" + }, + "notes": [ + "Menu > General Settings > KISS TNC > Enable KISS TNC = checked" + ], + "fieldNotes": [ + ] +} From 6612b8401c829bee819b345cc5e0cb57ffaa62c6 Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Fri, 3 Jan 2025 03:29:05 -0700 Subject: [PATCH 4/6] BTECH UV PRO - Replaced manual pairing method with an automated approach --- overlay/opt/emcomm-tools/bin/et-uv-pro | 57 +++++++++++++++++--------- scripts/install-packet.sh | 3 +- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/overlay/opt/emcomm-tools/bin/et-uv-pro b/overlay/opt/emcomm-tools/bin/et-uv-pro index eeed685..dafd026 100755 --- a/overlay/opt/emcomm-tools/bin/et-uv-pro +++ b/overlay/opt/emcomm-tools/bin/et-uv-pro @@ -67,14 +67,14 @@ get_mac_or_exit () { update_ax25_conf() { - [ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json" + [ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json" - CALLSIGN=$(cat ${ET_USER_CONFIG} | jq -r .callsign) + CALLSIGN=$(cat ${ET_USER_CONFIG} | jq -r .callsign) - if [ "${CALLSIGN}" = "N0CALL" ]; then - echo -e "${RED}No callsign set. Run et-user first.${NC}" - exit 1 - fi + if [ "${CALLSIGN}" = "N0CALL" ]; then + error_message "No callsign set. Run et-user first." + exit 1 + fi GREP_OUT=$(grep ${AX25_PORT} ${AX25_CONF_FILE}) if [ $? -eq 0 ]; then @@ -85,7 +85,7 @@ update_ax25_conf() { fi - echo -e "${BLUE}Adding AX25 port for ${CALLSIGN}${NC}" + info_message "Adding AX25 port for ${CALLSIGN}" echo "pkt1200 ${CALLSIGN} 1200 255 2 1200 Packet" >> ${AX25_CONF_FILE} } @@ -99,7 +99,7 @@ stop_all_services() { sleep 3 - PS_OUT=$(ps -ef | grep [r]fcomm) + PS2_OUT=$(ps -ef | grep [r]fcomm) if [ $? -eq 0 ]; then info_message "Killing rfcomm process(es)..." sudo killall rfcomm @@ -116,7 +116,7 @@ case $1 in if [ $? -eq 0 ]; then PAIR_STATUS=$(bluetoothctl info "${MAC}" | grep "Paired:" | awk '{print $2}') if [ "${PAIR_STATUS}" == "yes" ]; then - error_message "Device with MAC=${MAC} is already paired." + error_message "Device with MAC ${MAC} is already paired." exit 1 fi fi @@ -126,7 +126,7 @@ case $1 in echo -e "2. Goto Menu > Pairing and press OK" read -p "3. Press [ENTER] when done." - echo -e "${BLUE}Searching for ${DEVICE_NAME}...${NC}" + info_message "Searching for ${DEVICE_NAME}..." HCI_OUT=$(hcitool scan | grep "${DEVICE_NAME}") if [ $? -ne 0 ]; then @@ -136,17 +136,34 @@ case $1 in MAC=$(echo ${HCI_OUT} | awk '{print $1}') - # Update configuration file + # Update configuration file detected MAC address sed -i "s|.*mac.*| \"mac\": \"${MAC}\"|g" ${ACTIVE_RADIO} - echo -e "Now, run the ${YELLOW}bluetooth${NC} command in another terminal.\n" + # Generate an expect script to automatically pair our device. + PAIR_SCRIPT="/tmp/pair.sh" - echo -e "${BLUE}[bluetooth]# ${YELLOW}power on${NC}" - echo -e "${BLUE}[bluetooth]# ${YELLOW}scan on${NC}\n" - echo -e "Wait until ${DEVICE_NAME} appears.\n" - echo -e "${BLUE}[bluetooth]# ${YELLOW}trust ${MAC}${NC}" - echo -e "${BLUE}[bluetooth]# ${YELLOW}pair ${MAC}${NC}" - echo -e "${BLUE}[${DEVICE_NAME}]# ${YELLOW}quit${NC}" +cat < $PAIR_SCRIPT +#!/usr/bin/expect -f + +set device "${MAC}" +set timeout 60 + +spawn bluetoothctl +expect "Agent registered" +send "power on\r" +expect "Changing power on succeeded" +send "scan on\r" +expect "${MAC}" +send "pair ${MAC}\r" +expect "Pairing successful" +send "trust ${MAC}\r" +expect "trust succeeded" +send "exit\r" +expect eof +EOF + + chmod 700 ${PAIR_SCRIPT} + ${PAIR_SCRIPT} ;; unpair) @@ -158,7 +175,7 @@ case $1 in PAIR_STATUS=$(bluetoothctl info "${MAC}") if [ $? -ne 0 ]; then - error_message "No ${MAC} device found. Can't unpair." + error_message "No device with ${MAC} found. Can't unpair." exit 1 fi @@ -168,7 +185,7 @@ case $1 in echo -e "${YELLOW}" echo -e "You may also want to remove this device from your UV PRO" - echo -e "under Menu > General Settings> Connection > Paired Devices." + echo -e "under Menu > General Settings > Connection > Paired Devices." echo -e "${NC}" ;; diff --git a/scripts/install-packet.sh b/scripts/install-packet.sh index e6a2269..62dd955 100755 --- a/scripts/install-packet.sh +++ b/scripts/install-packet.sh @@ -1,7 +1,7 @@ #!/bin/bash # Author : Gaston Gonzalez # Date : 27 March 2023 -# Updated : 1 January 2025 +# Updated : 3 January 2025 # Purpose : Install packet packages set -e @@ -9,6 +9,7 @@ et-log "Installing AX.25 packages..." apt install \ ax25-tools \ ax25-apps \ + expect \ -y et-log "Installing rfcomm sudoers rules..." From f4d68ab2589f86c65b6ea87f4f1f437a2289defd Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Fri, 3 Jan 2025 05:27:12 -0700 Subject: [PATCH 5/6] BTECH UV PRO - Fixed called to expect script following testing on field system --- overlay/opt/emcomm-tools/bin/et-uv-pro | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/overlay/opt/emcomm-tools/bin/et-uv-pro b/overlay/opt/emcomm-tools/bin/et-uv-pro index dafd026..5f5826d 100755 --- a/overlay/opt/emcomm-tools/bin/et-uv-pro +++ b/overlay/opt/emcomm-tools/bin/et-uv-pro @@ -140,9 +140,9 @@ case $1 in sed -i "s|.*mac.*| \"mac\": \"${MAC}\"|g" ${ACTIVE_RADIO} # Generate an expect script to automatically pair our device. - PAIR_SCRIPT="/tmp/pair.sh" + PAIR_SCRIPT="${HOME}/pair" -cat < $PAIR_SCRIPT +cat < ${PAIR_SCRIPT} #!/usr/bin/expect -f set device "${MAC}" @@ -162,8 +162,7 @@ send "exit\r" expect eof EOF - chmod 700 ${PAIR_SCRIPT} - ${PAIR_SCRIPT} + sleep 1 && chmod 755 ${PAIR_SCRIPT} && expect ${PAIR_SCRIPT} ;; unpair) From b85f6e981223e83f6b895278d2f7c50de5ddeede Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Sat, 4 Jan 2025 04:45:35 -0700 Subject: [PATCH 6/6] BTECH UV PRO - Fixed rfcomm kill process issues --- overlay/opt/emcomm-tools/bin/et-uv-pro | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/overlay/opt/emcomm-tools/bin/et-uv-pro b/overlay/opt/emcomm-tools/bin/et-uv-pro index 5f5826d..e54d76c 100755 --- a/overlay/opt/emcomm-tools/bin/et-uv-pro +++ b/overlay/opt/emcomm-tools/bin/et-uv-pro @@ -2,7 +2,7 @@ # # Author : Gaston Gonzalez # Date : 1 January 2025 -# Updated : 2 January 2025 +# Updated : 3 January 2025 # Purpose : Utility for accessing the Bluetooth TNC on the BTECH # UV PRO. @@ -23,8 +23,8 @@ NC="${ESC}[0m" function usage() { echo "Usage: $(basename $0) " echo " connect - Connect to radio via Bluetooth" - echo " pair - Pair radio via Bluetooth" - echo " unpair - Unpair radio via Bluetooth" + echo " pair - Pair radio (one-time operation)" + echo " unpair - Unpair radio" } if [ $# -ne 1 ]; then @@ -99,12 +99,11 @@ stop_all_services() { sleep 3 - PS2_OUT=$(ps -ef | grep [r]fcomm) + PS2_OUT=$(ps -ef | grep -v krfcommd | grep [r]fcomm) if [ $? -eq 0 ]; then info_message "Killing rfcomm process(es)..." sudo killall rfcomm fi - } exit_if_no_active_radio @@ -238,6 +237,7 @@ EOF echo -e "------------------------------- --------------------------------" echo -e "axcall pkt1200 Connect directly to a node " echo -e "axcall pkt1200 Connect to node via a digipeater" + echo -e "sudo axlisten -a -tttt -c Monitor inbound and outbound traffic" echo -e "${NC}" ;;