This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
guides:virtual_modem:script [2022-12-17 01:08] omolini |
guides:virtual_modem:script [2022-12-20 07:12] omolini |
||
---|---|---|---|
Line 19: | Line 19: | ||
# VMODEM - Virtual Modem bootstrap | # VMODEM - Virtual Modem bootstrap | ||
# -------------------------------- | # -------------------------------- | ||
- | # Oliver Molini 2021 | + | # Oliver Molini 2020-2022 |
# | # | ||
- | # Billy Stoughton II for bug fixes and contributions | + | # Additional credits: |
+ | # - Billy Stoughton II for bug fixes and contributions | ||
+ | # - Hamish for helping test Windows 2000 compatibility | ||
# | # | ||
# Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License | # Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License | ||
Line 51: | Line 53: | ||
# Script version | # Script version | ||
- | vmodver=1.6.0 | + | vmodver=1.7.0 |
# CONFIGURATION | # CONFIGURATION | ||
Line 128: | Line 130: | ||
# SEND MESSAGE ON SCREEN AND OVER SERIAL | # SEND MESSAGE ON SCREEN AND OVER SERIAL | ||
sendtty () { | sendtty () { | ||
+ | # Prints message in console and over serial. Message is given as first parameter. | ||
message="$1" | message="$1" | ||
- | # echo -en "$message" | ||
- | # echo -en "${message//\\n/\\r\\n}" > /dev/$serport | ||
echo -en "$message" | tee /dev/$serport | echo -en "$message" | tee /dev/$serport | ||
+ | } | ||
+ | |||
+ | readtty () { | ||
+ | # Reads input from TTY and stores it in variable given as first parameter | ||
+ | line= | ||
+ | while [[ -z "$line" ]]; do | ||
+ | charhex=`head -c 1 /dev/$serport | xxd -p -` | ||
+ | char="`echo -e "\x$charhex"`" | ||
+ | echo -n "$char" | ||
+ | echo -n "$char" > /dev/$serport | ||
+ | # Newline received | ||
+ | if [ "$charhex" = "0d" -o "$charhex" = "0a" ]; then | ||
+ | line=$buffer | ||
+ | buffer= | ||
+ | char= | ||
+ | sendtty "\n" | ||
+ | fi | ||
+ | buffer=$buffer$char | ||
+ | done | ||
+ | local __resultvar=$1 | ||
+ | local result="$line" | ||
+ | eval $__resultvar="'$result'" | ||
} | } | ||
export -f sendtty | export -f sendtty | ||
+ | export -f readtty | ||
export -f ttyinit | export -f ttyinit | ||
Line 204: | Line 228: | ||
fi | fi | ||
- | # ATS AUTO ANSWER | + | # S Registers (just auto-accept) |
- | # S0=0 - no auto answer | + | |
- | # S0=1 - auto-answer on first ring | + | |
if [[ $hcmd == 'S' ]]; then | if [[ $hcmd == 'S' ]]; then | ||
- | sendtty "$hparm"; | ||
result=0; | result=0; | ||
- | #if [[ $hparm == '' ]]; then resultverbose=0; result=0; fi | ||
- | #if [[ $hparm == '0' ]]; then resultverbose=0; result=0; fi | ||
- | #if [[ $hparm == '1' ]]; then resultverbose=2; result=0; fi | ||
fi | fi | ||
Line 434: | Line 452: | ||
fi | fi | ||
- | if [[ $cmd = HELP ]]; then | + | if [[ $cmd = "HELP" ]] || [[ $cmd = "?" ]]; then |
sendtty "Command Reference for Virtual Modem Bootstrap v$vmodver\n" | sendtty "Command Reference for Virtual Modem Bootstrap v$vmodver\n" | ||
sendtty "\n" | sendtty "\n" | ||
- | sendtty "AT......Tests modem link, prints OK if successful\n" | + | sendtty "General commands:\n" |
- | sendtty "ATE0....Switch terminal echo off\n" | + | sendtty "HELP.......Display this help\n" |
- | sendtty "ATE1....Switch terminal echo on\n" | + | sendtty "LOGIN......Fork a new linux login on serial\n" |
- | sendtty "ATD?....Fork program ?.sh and output on terminal\n" | + | sendtty "SETUP......Change settings\n" |
- | sendtty "ATDT1...Open PPPD connection\n" | + | sendtty "EXIT.......End this script\n" |
- | sendtty "ATZ.....Reset modem settings\n" | + | |
- | sendtty "HELP....Display command reference\n" | + | |
- | sendtty "LOGIN...Fork a new linux login on serial\n" | + | |
- | sendtty "EXIT....End this script\n" | + | |
sendtty "\n" | sendtty "\n" | ||
- | sendtty "To establish connection over PPP, dial 1 using tone dialing (ATDT1)\n" | + | sendtty "Common Hayes commands:\n" |
+ | sendtty "AT.........Tests serial connection, prints OK if successful\n" | ||
+ | sendtty "ATE0/ATE1..Switch terminal echo 0-off or 1-on\n" | ||
+ | sendtty "ATD#.......Fork #.sh and output on terminal\n" | ||
+ | sendtty "ATD1.......Fork 1.sh, which by default starts a PPP connection\n" | ||
+ | sendtty "ATZ........Reset modem settings\n" | ||
+ | sendtty "\n" | ||
+ | sendtty "To establish connection over PPP, dial 1 (ATDT1)\n" | ||
sendtty "\n" | sendtty "\n" | ||
sendtty "READY.\n" | sendtty "READY.\n" | ||
fi | fi | ||
+ | |||
+ | if [[ $cmd = "SETUP" ]]; then | ||
+ | while true; do | ||
+ | # Display menu | ||
+ | sendtty "\n" | ||
+ | sendtty "System Setup\n" | ||
+ | sendtty "============\n" | ||
+ | sendtty "1. Change Wireless Network settings\n" | ||
+ | sendtty "2. Exit\n" | ||
+ | sendtty "Enter your selection: " | ||
+ | # Read user input | ||
+ | readtty selection | ||
+ | |||
+ | # Wireless network settings | ||
+ | if [[ "$selection" == "1" ]]; then | ||
+ | while true; do | ||
+ | sendtty "\n" | ||
+ | sendtty "Wi-Fi Settings\n" | ||
+ | sendtty "==============\n" | ||
+ | sendtty "1. Connect to new Wi-Fi network\n" | ||
+ | sendtty "2. Modify password for current Wi-Fi network\n" | ||
+ | sendtty "3. Disconnect from current Wi-Fi network\n" | ||
+ | sendtty "4. Display current Wi-Fi connection status\n" | ||
+ | sendtty "5. Exit\n" | ||
+ | sendtty "Enter your selection: " | ||
+ | # Read user input | ||
+ | readtty selection | ||
+ | # Connect to new Wi-Fi network | ||
+ | if [[ "$selection" == "1" ]]; then | ||
+ | sendtty "Enter SSID: " | ||
+ | readtty ssid | ||
+ | sendtty "Enter password: " | ||
+ | readtty password | ||
+ | #sudo wpa_cli -i wlan0 remove_network 0 | ||
+ | #sudo wpa_cli -i wlan0 add_network | ||
+ | #sudo wpa_cli -i wlan0 set_network 0 ssid "\"$ssid\"" | ||
+ | #sudo wpa_cli -i wlan0 set_network 0 psk "\"$password\"" | ||
+ | #sudo wpa_cli -i wlan0 select_network 0 | ||
+ | #sudo wpa_cli -i wlan0 enable_network 0 | ||
+ | # Modify password for current Wi-Fi network | ||
+ | elif [[ "$selection" == "2" ]]; then | ||
+ | sendtty "Enter new password: " | ||
+ | readtty password | ||
+ | #sudo wpa_cli -i wlan0 set_network 0 psk "\"$password\"" | ||
+ | # Disconnect from current Wi-Fi network | ||
+ | elif [[ "$selection" == "3" ]]; then | ||
+ | sendtty "Disconnecting from current Wi-Fi network\n" | ||
+ | #sudo wpa_cli -i wlan0 disable_network 0 | ||
+ | # Display current Wi-Fi connection status | ||
+ | elif [[ "$selection" == "4" ]]; then | ||
+ | status=$(sudo wpa_cli -i wlan0 status) | ||
+ | sendtty "$status" | ||
+ | # Exit | ||
+ | elif [[ "$selection" == "5" ]]; then | ||
+ | break | ||
+ | # Invalid selection | ||
+ | else | ||
+ | sendtty "Invalid selection. Please try again.\n" | ||
+ | fi | ||
+ | done | ||
+ | # Exit | ||
+ | elif [[ "$selection" == "2" ]]; then | ||
+ | sendtty "Exited setup\n" | ||
+ | sendtty "READY.\n" | ||
+ | break | ||
+ | # Invalid selection | ||
+ | else | ||
+ | sendtty "Invalid selection. Please try again." | ||
+ | fi | ||
+ | done | ||
+ | fi | ||
+ | |||
# LOGIN - FORK LOGIN SESSION | # LOGIN - FORK LOGIN SESSION | ||
Line 570: | Line 663: | ||
sendtty "\n" | sendtty "\n" | ||
sendtty "Please enter your name: \n" | sendtty "Please enter your name: \n" | ||
- | read -e -p "User? " username | + | readtty username |
sendtty "\n" | sendtty "\n" | ||
sendtty "Hello, $username!\n" | sendtty "Hello, $username!\n" |