Major at-socat-bridge update

-Now uses both smd11 and smd7 for separate AT streams
-smd11 is linked to ttyOUT
-smd7 is linked to ttyOUT2

ttyOUT is intended for automated AT commands (for parse scripts, etc)

ttyOUT2 is intended for manual user initiated AT commands; the new atcmd bin is now linked to /bin as well for utilization of ttyOUT2 by shell. Just type the command atcmd to run it.

Separating these streams will improve responsiveness and help the progress of more development.
This commit is contained in:
iamromulan
2024-03-16 17:49:52 -04:00
parent eb1ae610a0
commit 127db81532
13 changed files with 109 additions and 163 deletions

View File

@@ -1,12 +1,12 @@
#!/bin/sh
# Define toolkit paths
GITUSER="iamromulan"
GITTREE="development"
TMP_DIR="/tmp"
USRDATA_DIR="/usrdata"
SOCAT_AT_DIR="/usrdata/socat-at-bridge"
SOCAT_AT_SYSD_DIR="/usrdata/socat-at-bridge/systemd_units"
SOCAT_AT_SMD7_SYSD_DIR="/usrdata/socat-at-bridge/smd7_systemd_units"
SIMPLE_ADMIN_DIR="/usrdata/simpleadmin"
SIMPLE_FIREWALL_DIR="/usrdata/simplefirewall"
SIMPLE_FIREWALL_SCRIPT="$SIMPLE_FIREWALL_DIR/simplefirewall.sh"
@@ -47,12 +47,9 @@ send_at_command() {
fi
if [ "$at_command" = "install" ]; then
wget -P /usrdata https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/main/atcmd
chmod +x /usrdata/atcmd
remount_rw
ln -sf /usrdata/atcmd /sbin
remount_ro
echo -e "\e[1;32mInstalled. Type atcmd from adb shell or ssh to start an AT Command session\e[0m"
install_update_at_socat
echo -e "\e[1;32mInstalled. Type atcmd from adb shell or ssh to start an AT Command session\e[0m"
return 1
fi
echo -e "${at_command}\r" > "$DEVICE_FILE"
}
@@ -112,80 +109,82 @@ is_simple_admin_installed() {
# Function to install/update AT Socat Bridge
install_update_at_socat() {
remount_rw
mkdir "$SOCAT_AT_DIR"
cd "$SOCAT_AT_DIR"
# Stop and disable existing services/files before installing new ones
echo -e "\033[0;32mRemoving installed AT Socat Bridge services...\033[0m"
systemctl stop at-telnet-daemon > /dev/null 2>&1
systemctl disable at-telnet-daemon > /dev/null 2>&1
systemctl stop socat-smd11 > /dev/null 2>&1
systemctl stop socat-smd11-to-ttyIN > /dev/null 2>&1
systemctl stop socat-smd11-from-ttyIN > /dev/null 2>&1
systemctl stop socat-smd7 > /dev/null 2>&1
systemctl stop socat-smd7-to-ttyIN2 > /dev/null 2>&1
systemctl stop socat-smd7-to-ttyIN > /dev/null 2>&1
systemctl stop socat-smd7-from-ttyIN2 > /dev/null 2>&1
systemctl stop socat-smd7-from-ttyIN > /dev/null 2>&1
rm /lib/systemd/system/at-telnet-daemon.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd11.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd11-to-ttyIN.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd11-from-ttyIN.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd7.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd7-to-ttyIN2.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd7-to-ttyIN.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd7-from-ttyIN.service > /dev/null 2>&1
rm /lib/systemd/system/socat-smd7-from-ttyIN2.service > /dev/null 2>&1
systemctl daemon-reload > /dev/null 2>&1
rm -rf "$SOCAT_AT_DIR" > /dev/null 2>&1
# Install service units
echo -e "\033[0;32mInstalling AT Socat Bridge services...\033[0m"
mkdir $SOCAT_AT_DIR
cd $SOCAT_AT_DIR
mkdir $SOCAT_AT_SYSD_DIR
mkdir $SOCAT_AT_SMD7_SYSD_DIR
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/socat-armel-static
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/killsmd7bridge
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/atcmd
cd $SOCAT_AT_SYSD_DIR
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd11.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd11-from-ttyIN.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd11-to-ttyIN.service
cd $SOCAT_AT_SMD7_SYSD_DIR
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/smd7_systemd_units/socat-smd7-from-ttyIN.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/smd7_systemd_units/socat-smd7-to-ttyIN.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/smd7_systemd_units/socat-smd7.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-killsmd7bridge.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd7-from-ttyIN2.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd7-to-ttyIN2.service
wget https://raw.githubusercontent.com/iamromulan/quectel-rgmii-toolkit/$GITTREE/socat-at-bridge/systemd_units/socat-smd7.service
# Set execute permissions
chmod +x "$SOCAT_AT_DIR"/socat-armel-static
# User prompt for selecting device
echo -e "\e[1;32mWhich device should Simpleadmin use?\e[0m"
echo -e "\e[1;32mThis will create virtual tty ports (serial ports) that will use either smd11 or smd7\e[0m"
echo -e "\e[38;5;40m1) Use smd11 (default)\e[0m"
echo -e "\e[38;5;27m2) Use smd7 (use this if another application is using smd11 already)\e[0m"
read -p "Enter your choice (1 or 2): " device_choice
# Stop and disable existing services before installing new ones
echo -e "\033[0;32mThese errors are OK, script tries to remove all first in case you are updating\033[0m"
systemctl stop at-telnet-daemon
systemctl disable at-telnet-daemon
systemctl stop socat-smd11
systemctl stop socat-smd11-to-ttyIN
systemctl stop socat-smd11-from-ttyIN
systemctl stop socat-smd7
systemctl stop socat-smd7-to-ttyIN
systemctl stop socat-smd7-from-ttyIN
rm /lib/systemd/system/at-telnet-daemon.service
rm /lib/systemd/system/socat-smd11.service
rm /lib/systemd/system/socat-smd11-to-ttyIN.service
rm /lib/systemd/system/socat-smd11-from-ttyIN.service
rm /lib/systemd/system/socat-smd7.service
rm /lib/systemd/system/socat-smd7-to-ttyIN.service
rm /lib/systemd/system/socat-smd7-from-ttyIN.service
systemctl daemon-reload
echo -e "\033[0;32mThese errors are OK, script tries to remove all first in case you are updating\033[0m"
chmod +x socat-armel-static
chmod +x killsmd7bridge
chmod +x atcmd
# Depending on the choice, copy the respective systemd unit files
case $device_choice in
2)
cp -rf $SOCAT_AT_SMD7_SYSD_DIR/*.service /lib/systemd/system
ln -sf /lib/systemd/system/socat-smd7.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd7-to-ttyIN.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd7-from-ttyIN.service /lib/systemd/system/multi-user.target.wants/
systemctl daemon-reload
systemctl start socat-smd7
sleep 2s
systemctl start socat-smd7-to-ttyIN
systemctl start socat-smd7-from-ttyIN
remount_ro
cd /
;;
1)
cp -rf $SOCAT_AT_SYSD_DIR/*.service /lib/systemd/system
ln -sf /lib/systemd/system/socat-smd11.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd11-to-ttyIN.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd11-from-ttyIN.service /lib/systemd/system/multi-user.target.wants/
systemctl daemon-reload
systemctl start socat-smd11
sleep 2s
systemctl start socat-smd11-to-ttyIN
systemctl start socat-smd11-from-ttyIN
remount_ro
cd /
;;
esac
# Link new command for AT Commands from the shell
ln -sf $SOCAT_AT_DIR/atcmd /bin
# Install service units
echo -e "\033[0;32mAdding AT Socat Bridge systemd service units...\033[0m"
cp -rf $SOCAT_AT_SYSD_DIR/*.service /lib/systemd/system
ln -sf /lib/systemd/system/socat-killsmd7bridge.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd11.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd11-to-ttyIN.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd11-from-ttyIN.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd7.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd7-to-ttyIN2.service /lib/systemd/system/multi-user.target.wants/
ln -sf /lib/systemd/system/socat-smd7-from-ttyIN2.service /lib/systemd/system/multi-user.target.wants/
systemctl daemon-reload
systemctl start socat-smd11
sleep 2s
systemctl start socat-smd11-to-ttyIN
systemctl start socat-smd11-from-ttyIN
echo -e "\033[0;32mAT Socat Bridge service online: smd11 to ttyOUT\033[0m"
systemctl start socat-killsmd7bridge
sleep 1s
systemctl start socat-smd7
sleep 2s
systemctl start socat-smd7-to-ttyIN2
systemctl start socat-smd7-from-ttyIN2
echo -e "\033[0;32mAT Socat Bridge service online: smd7 to ttyOUT2\033[0m"
remount_ro
cd /
echo -e "\033[0;32mAT Socat Bridge services Installed!\033[0m"
}
# Function to install Simple Firewall

38
socat-at-bridge/atcmd Normal file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
while true; do
echo "Type \"exit\" to end the session"
echo "Enter AT Command:"
read user_input
if [[ "$user_input" == "exit" ]]; then
echo "Exiting..."
exit 0
else
# Create a temporary file for output
tmpfile=$(mktemp /tmp/microcom_output.XXXXXX)
# Send the input to microcom, redirect output to the temporary file
# Note: Adjust the path to microcom as necessary
echo "$user_input" > /dev/ttyOUT2
microcom -d /dev/ttyOUT2 > "$tmpfile" &
microcom_pid=$!
# Use tail to monitor the temporary file's output
tail -f "$tmpfile" | while read line; do
echo "$line"
if [[ "$line" == *OK || "$line" == *ERROR ]]; then
kill -SIGINT $microcom_pid
break
fi
done
# Wait for microcom to finish
wait $microcom_pid
# Cleanup
rm "$tmpfile"
fi
done

View File

@@ -1,14 +0,0 @@
[Unit]
Description=Read from /dev/ttyIN and write to smd7
BindsTo=socat-smd7.service
After=socat-smd7.service
[Service]
ExecStart=/bin/bash -c "/bin/cat /dev/ttyIN > /dev/smd7"
ExecStartPost=/bin/sleep 2s
StandardInput=tty-force
Restart=always
RestartSec=1s
[Install]
WantedBy=multi-user.target

View File

@@ -1,14 +0,0 @@
[Unit]
Description=Read from /dev/smd7 and write to ttyIN
BindsTo=socat-smd7.service
After=socat-smd7.service
[Service]
ExecStart=/bin/bash -c "/bin/cat /dev/smd7 > /dev/ttyIN"
ExecStartPost=/bin/sleep 2s
StandardInput=tty-force
Restart=always
RestartSec=1s
[Install]
WantedBy=multi-user.target

View File

@@ -1,13 +0,0 @@
[Unit]
Description=Socat Serial Emulation for smd7
After=ql-netd.service
[Service]
ExecStart=/usrdata/socat-at-bridge/socat-armel-static -d -d pty,link=/dev/ttyIN,raw,echo=0 pty,link=/dev/ttyOUT,raw,echo=1
# Add a delay to prevent the clients from starting too early
ExecStartPost=/bin/sleep 2s
Restart=always
RestartSec=1s
[Install]
WantedBy=multi-user.target

View File

@@ -1,9 +0,0 @@
[Unit]
Description=Kill port_bridge process on boot
[Service]
Type=oneshot
ExecStart=/usrdata/socat-at-bridge/killsmd7bridge
[Install]
WantedBy=multi-user.target

View File

@@ -1,14 +0,0 @@
[Unit]
Description=Read from /dev/ttyIN2 and write to smd11
BindsTo=socat-smd11.service
After=socat-smd11.service
[Service]
ExecStart=/bin/bash -c "/bin/cat /dev/ttyIN2 > /dev/smd11"
ExecStartPost=/bin/sleep 2s
StandardInput=tty-force
Restart=always
RestartSec=1s
[Install]
WantedBy=multi-user.target

View File

@@ -1,14 +0,0 @@
[Unit]
Description=Read from /dev/smd11 and write to ttyIN2
BindsTo=socat-smd11.service
After=socat-smd11.service
[Service]
ExecStart=/bin/bash -c "/bin/cat /dev/smd11 > /dev/ttyIN2"
ExecStartPost=/bin/sleep 2s
StandardInput=tty-force
Restart=always
RestartSec=1s
[Install]
WantedBy=multi-user.target

View File

@@ -1,13 +0,0 @@
[Unit]
Description=Socat Serial Emulation for smd11
After=ql-netd.service
[Service]
ExecStart=/usrdata/socat-at-bridge/socat-armel-static -d -d pty,link=/dev/ttyIN2,raw,echo=0 pty,link=/dev/ttyOUT2,raw,echo=1
# Add a delay to prevent the clients from starting too early
ExecStartPost=/bin/sleep 2s
Restart=always
RestartSec=1s
[Install]
WantedBy=multi-user.target