From 06b1e972c82be3a14718314f5ae8694535d63b31 Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Tue, 18 Feb 2025 15:46:08 -0900 Subject: [PATCH 1/8] initial impl --- platform/jetson/scripts/lte_configure.sh | 220 +++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100755 platform/jetson/scripts/lte_configure.sh diff --git a/platform/jetson/scripts/lte_configure.sh b/platform/jetson/scripts/lte_configure.sh new file mode 100755 index 0000000..2f3c90e --- /dev/null +++ b/platform/jetson/scripts/lte_configure.sh @@ -0,0 +1,220 @@ +#!/bin/bash + +set -euo pipefail + +# Configuration +APN="fast.t-mobile.com" # Change this to your carrier's APN +TIMEOUT=60 # Timeout in seconds to wait for modem + +# Function to check prerequisites +check_prerequisites() { + echo "Checking prerequisites..." + + # Check for QMI_WWAN kernel module + if ! lsmod | grep -q "qmi_wwan"; then + echo "Error: qmi_wwan kernel module not loaded" + echo "Try: sudo modprobe qmi_wwan" + exit 1 + fi + + # Check for required tools + for cmd in mmcli nmcli; do + if ! command -v "$cmd" >/dev/null 2>&1; then + echo "Error: Required command '$cmd' not found" + exit 1 + fi + done + + # Check if NetworkManager is running + if ! systemctl is-active --quiet NetworkManager; then + echo "Error: NetworkManager is not running" + exit 1 + fi + + # Check for SIM presence (basic check) + if ! mmcli -L | grep -q "Sierra.*RC7611"; then + echo "Warning: Modem not detected. Please check:" + echo " - SIM card is properly inserted" + echo " - Antennas are properly connected" + echo " - Device is properly powered" + exit 1 + fi +} + +# Function to wait for modem +wait_for_modem() { + echo "Waiting for modem to be detected..." + local count=0 + while [ $count -lt $TIMEOUT ]; do + if mmcli -L | grep -q "Sierra.*RC7611"; then + return 0 + fi + sleep 1 + count=$((count + 1)) + done + echo "Error: Modem not detected within timeout period" + exit 1 +} + +# Function to get modem index +get_modem_index() { + local modem_index + modem_index=$(mmcli -L | grep "Sierra.*RC7611" | grep -o "/[0-9]*" | tr -d '/') + echo "$modem_index" +} + +# Function to verify modem state +verify_modem_state() { + local modem_index=$1 + local modem_status + + echo "Verifying modem state..." + modem_status=$(mmcli -m "$modem_index") + + # Check if modem is enabled + if ! echo "$modem_status" | grep -q "state: 'enabled'"; then + echo "Error: Modem is not enabled" + exit 1 + fi + + # Check for SIM + if ! echo "$modem_status" | grep -q "SIM.*active"; then + echo "Error: No active SIM detected" + exit 1 + fi +} + +# Function to setup initial EPS bearer +setup_eps_bearer() { + local modem_index=$1 + echo "Configuring initial EPS bearer settings..." + sudo mmcli -m "$modem_index" --3gpp-set-initial-eps-bearer-settings="apn=$APN" + + # Verify bearer setup + local bearer_status + bearer_status=$(mmcli -m "$modem_index" --bearer=0) + if ! echo "$bearer_status" | grep -q "connected.*yes"; then + echo "Error: Bearer not connected" + exit 1 + fi +} + +# Function to create NetworkManager connection +create_nm_connection() { + local modem_index=$1 + local conn_name="sierra-lte" + + # Check if connection already exists + if nmcli connection show | grep -q "^$conn_name "; then + echo "Connection '$conn_name' already exists. Removing..." + nmcli connection delete "$conn_name" + fi + + echo "Creating NetworkManager connection..." + nmcli connection add \ + type gsm \ + con-name "$conn_name" \ + ifname wwan0 \ + apn "$APN" \ + connection.autoconnect yes \ + gsm.auto-config yes \ + ipv4.method auto \ + ipv4.route-metric 4294967295 \ + ipv6.method auto + + echo "Setting connection permissions..." + nmcli connection modify "$conn_name" connection.permissions "user:$USER" + + # Get bearer settings and configure interface + local bearer_info + bearer_info=$(mmcli -m "$modem_index" --bearer=0) + local mtu + mtu=$(echo "$bearer_info" | grep "mtu:" | awk '{print $3}') + + # If we couldn't get MTU from bearer, default to 1500 + if [ -z "$mtu" ]; then + mtu=1500 + fi + + echo "Configuring interface settings..." + nmcli connection modify "$conn_name" gsm.mtu "$mtu" + nmcli connection modify "$conn_name" 802-3-ethernet.accept-all-mac-addresses no + nmcli connection modify "$conn_name" ethernet.arp no + + return 0 +} + +# Function to verify connection +verify_connection() { + local conn_name="sierra-lte" + local max_attempts=12 + local attempt=0 + + echo "Waiting for connection to become active..." + while [ $attempt -lt $max_attempts ]; do + if nmcli -g GENERAL.STATE connection show "$conn_name" 2>/dev/null | grep -q "activated"; then + echo "Connection is active" + return 0 + fi + sleep 5 + attempt=$((attempt + 1)) + done + + echo "Error: Connection failed to activate" + return 1 +} + +# Function for connection testing +test_connection() { + echo "Testing connection..." + + # Test IPv4 connectivity + if ! ping -c 4 -I wwan0 8.8.8.8; then + echo "Warning: IPv4 connectivity test failed" + echo "Troubleshooting steps:" + echo "1. Check APN settings" + echo "2. Verify SIM card is active" + echo "3. Check signal strength" + echo "4. Verify carrier account status" + return 1 + fi + + return 0 +} + +# Main script +echo "Starting Sierra RC7611 modem setup with NetworkManager..." + +# Check if running as root +if [ "$EUID" -eq 0 ]; then + echo "Please run this script as a regular user with sudo privileges" + exit 1 +fi + +# Run setup steps +check_prerequisites +wait_for_modem + +MODEM_INDEX=$(get_modem_index) +if [ -z "$MODEM_INDEX" ]; then + echo "Error: Could not determine modem index" + exit 1 +fi + +verify_modem_state "$MODEM_INDEX" +setup_eps_bearer "$MODEM_INDEX" +create_nm_connection "$MODEM_INDEX" + +echo "Starting connection..." +nmcli connection up sierra-lte + +if verify_connection; then + if test_connection; then + echo "Setup completed successfully!" + else + echo "Setup completed with warnings (connection test failed)" + fi +else + echo "Setup failed - connection could not be activated" + exit 1 +fi From 24bdf04a6073b8a7fb6b1151cdec36dc85d41b91 Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Tue, 18 Feb 2025 16:00:35 -0900 Subject: [PATCH 2/8] second pass --- platform/jetson/scripts/lte_configure.sh | 265 ++++++++++++++--------- scripts/install_software.sh | 3 + 2 files changed, 161 insertions(+), 107 deletions(-) diff --git a/platform/jetson/scripts/lte_configure.sh b/platform/jetson/scripts/lte_configure.sh index 2f3c90e..8b8414a 100755 --- a/platform/jetson/scripts/lte_configure.sh +++ b/platform/jetson/scripts/lte_configure.sh @@ -2,9 +2,70 @@ set -euo pipefail -# Configuration -APN="fast.t-mobile.com" # Change this to your carrier's APN -TIMEOUT=60 # Timeout in seconds to wait for modem +# Help text +usage() { + cat << EOF +Usage: $0 --apn [--dns1 ] [--dns2 ] [--user ] [--password ] + +Required arguments: + --apn Access Point Name for the cellular connection + +Optional arguments: + --dns1 Primary DNS server + --dns2 Secondary DNS server + --user Username for carriers that require authentication + --password Password for carriers that require authentication + --help Show this help message +EOF +} + +# Parse arguments +APN="" +DNS1="" +DNS2="" +USERNAME="" +PASSWORD="" + +while [[ $# -gt 0 ]]; do + case $1 in + --apn) + APN="$2" + shift 2 + ;; + --dns1) + DNS1="$2" + shift 2 + ;; + --dns2) + DNS2="$2" + shift 2 + ;; + --user) + USERNAME="$2" + shift 2 + ;; + --password) + PASSWORD="$2" + shift 2 + ;; + --help) + usage + exit 0 + ;; + *) + echo "Error: Unknown parameter $1" + usage + exit 1 + ;; + esac +done + +# Validate required arguments +if [ -z "$APN" ]; then + echo "Error: APN is required" + usage + exit 1 +fi # Function to check prerequisites check_prerequisites() { @@ -13,7 +74,7 @@ check_prerequisites() { # Check for QMI_WWAN kernel module if ! lsmod | grep -q "qmi_wwan"; then echo "Error: qmi_wwan kernel module not loaded" - echo "Try: sudo modprobe qmi_wwan" + echo "Try: modprobe qmi_wwan" exit 1 fi @@ -30,22 +91,15 @@ check_prerequisites() { echo "Error: NetworkManager is not running" exit 1 fi - - # Check for SIM presence (basic check) - if ! mmcli -L | grep -q "Sierra.*RC7611"; then - echo "Warning: Modem not detected. Please check:" - echo " - SIM card is properly inserted" - echo " - Antennas are properly connected" - echo " - Device is properly powered" - exit 1 - fi } -# Function to wait for modem +# Function to wait for modem with timeout wait_for_modem() { - echo "Waiting for modem to be detected..." + local timeout=30 local count=0 - while [ $count -lt $TIMEOUT ]; do + + echo "Waiting for modem to be detected..." + while [ $count -lt $timeout ]; do if mmcli -L | grep -q "Sierra.*RC7611"; then return 0 fi @@ -80,141 +134,138 @@ verify_modem_state() { # Check for SIM if ! echo "$modem_status" | grep -q "SIM.*active"; then echo "Error: No active SIM detected" + echo "Please check:" + echo " - SIM card is properly inserted" + echo " - SIM card is not locked" + echo " - SIM card is activated with carrier" exit 1 fi + + # Check signal quality + local signal_quality + signal_quality=$(echo "$modem_status" | grep "signal quality:" | grep -o "[0-9]*" | head -1) + if [ -n "$signal_quality" ] && [ "$signal_quality" -lt 10 ]; then + echo "Warning: Very weak signal strength ($signal_quality%)" + echo "Please check antenna connections" + fi } -# Function to setup initial EPS bearer -setup_eps_bearer() { +# Function to verify bearer state +verify_bearer_state() { local modem_index=$1 - echo "Configuring initial EPS bearer settings..." - sudo mmcli -m "$modem_index" --3gpp-set-initial-eps-bearer-settings="apn=$APN" - # Verify bearer setup + echo "Verifying bearer state..." local bearer_status - bearer_status=$(mmcli -m "$modem_index" --bearer=0) - if ! echo "$bearer_status" | grep -q "connected.*yes"; then - echo "Error: Bearer not connected" - exit 1 + bearer_status=$(mmcli -m "$modem_index" --bearer=0 2>/dev/null || true) + + if [ -n "$bearer_status" ]; then + if ! echo "$bearer_status" | grep -q "connected.*yes"; then + echo "Warning: Bearer not connected" + echo "This may be normal if connection hasn't been started yet" + fi fi } -# Function to create NetworkManager connection -create_nm_connection() { - local modem_index=$1 - local conn_name="sierra-lte" +# Function to configure connection +configure_connection() { + local conn_name="ark-lte" - # Check if connection already exists + # Remove existing connection if present if nmcli connection show | grep -q "^$conn_name "; then - echo "Connection '$conn_name' already exists. Removing..." + echo "Removing existing connection..." nmcli connection delete "$conn_name" fi - echo "Creating NetworkManager connection..." - nmcli connection add \ + # Build base connection command + local cmd="nmcli connection add \ type gsm \ - con-name "$conn_name" \ + con-name $conn_name \ ifname wwan0 \ - apn "$APN" \ + apn $APN \ connection.autoconnect yes \ gsm.auto-config yes \ ipv4.method auto \ ipv4.route-metric 4294967295 \ - ipv6.method auto - - echo "Setting connection permissions..." - nmcli connection modify "$conn_name" connection.permissions "user:$USER" - - # Get bearer settings and configure interface - local bearer_info - bearer_info=$(mmcli -m "$modem_index" --bearer=0) - local mtu - mtu=$(echo "$bearer_info" | grep "mtu:" | awk '{print $3}') - - # If we couldn't get MTU from bearer, default to 1500 - if [ -z "$mtu" ]; then - mtu=1500 - fi - - echo "Configuring interface settings..." - nmcli connection modify "$conn_name" gsm.mtu "$mtu" - nmcli connection modify "$conn_name" 802-3-ethernet.accept-all-mac-addresses no - nmcli connection modify "$conn_name" ethernet.arp no - - return 0 -} - -# Function to verify connection -verify_connection() { - local conn_name="sierra-lte" - local max_attempts=12 - local attempt=0 - - echo "Waiting for connection to become active..." - while [ $attempt -lt $max_attempts ]; do - if nmcli -g GENERAL.STATE connection show "$conn_name" 2>/dev/null | grep -q "activated"; then - echo "Connection is active" - return 0 + ipv6.method auto \ + ethernet.arp no" + + # Add optional DNS servers if specified + if [ -n "$DNS1" ] || [ -n "$DNS2" ]; then + local dns_servers="" + if [ -n "$DNS1" ]; then + dns_servers="$DNS1" + if [ -n "$DNS2" ]; then + dns_servers="$dns_servers,$DNS2" + fi + elif [ -n "$DNS2" ]; then + dns_servers="$DNS2" fi - sleep 5 - attempt=$((attempt + 1)) - done - - echo "Error: Connection failed to activate" - return 1 -} + cmd="$cmd ipv4.dns \"$dns_servers\"" + cmd="$cmd ipv4.ignore-auto-dns yes" + fi -# Function for connection testing -test_connection() { - echo "Testing connection..." - - # Test IPv4 connectivity - if ! ping -c 4 -I wwan0 8.8.8.8; then - echo "Warning: IPv4 connectivity test failed" - echo "Troubleshooting steps:" - echo "1. Check APN settings" - echo "2. Verify SIM card is active" - echo "3. Check signal strength" - echo "4. Verify carrier account status" - return 1 + # Add authentication if specified + if [ -n "$USERNAME" ]; then + cmd="$cmd gsm.username \"$USERNAME\"" + fi + if [ -n "$PASSWORD" ]; then + cmd="$cmd gsm.password \"$PASSWORD\"" fi - return 0 + # Execute the assembled command + eval "$cmd" + + # Configure MTU and other link settings + nmcli connection modify "$conn_name" gsm.mtu 1500 + nmcli connection modify "$conn_name" 802-3-ethernet.accept-all-mac-addresses no } # Main script -echo "Starting Sierra RC7611 modem setup with NetworkManager..." +echo "Configuring ARK LTE modem..." # Check if running as root -if [ "$EUID" -eq 0 ]; then - echo "Please run this script as a regular user with sudo privileges" +if [ "$EUID" -ne 0 ]; then + echo "Error: This script must be run as root" exit 1 fi -# Run setup steps +# Run prerequisite checks check_prerequisites + +# Wait for modem wait_for_modem +# Verify modem state +verify_modem_state "$MODEM_INDEX" + +# Verify bearer state +verify_bearer_state "$MODEM_INDEX" + +# Get modem index MODEM_INDEX=$(get_modem_index) if [ -z "$MODEM_INDEX" ]; then echo "Error: Could not determine modem index" exit 1 fi -verify_modem_state "$MODEM_INDEX" -setup_eps_bearer "$MODEM_INDEX" -create_nm_connection "$MODEM_INDEX" +# Configure EPS bearer +echo "Configuring initial EPS bearer settings..." +mmcli -m "$MODEM_INDEX" --3gpp-set-initial-eps-bearer-settings="apn=$APN" + +# Create and configure connection +echo "Creating NetworkManager connection..." +configure_connection echo "Starting connection..." -nmcli connection up sierra-lte +nmcli connection up ark-lte -if verify_connection; then - if test_connection; then - echo "Setup completed successfully!" - else - echo "Setup completed with warnings (connection test failed)" - fi -else - echo "Setup failed - connection could not be activated" +# Quick connection verification +echo "Verifying connection..." +sleep 5 +if ! nmcli -g GENERAL.STATE connection show ark-lte 2>/dev/null | grep -q "activated"; then + echo "Error: Connection failed to activate" exit 1 fi + +echo "Configuration completed successfully" +exit 0 diff --git a/scripts/install_software.sh b/scripts/install_software.sh index e351130..41e3f14 100755 --- a/scripts/install_software.sh +++ b/scripts/install_software.sh @@ -139,6 +139,9 @@ if [ "$TARGET" = "jetson" ]; then echo "JetPack installation finished" fi + # Required for FW updating ARK LTE + sudo apt-get install libqmi-utils -y + sudo pip3 install \ Jetson.GPIO \ smbus2 \ From 8fe6a35efe8370e7ea6d456808d3b3e49072577a Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Tue, 18 Feb 2025 20:43:22 -0900 Subject: [PATCH 3/8] simple impl, had to give up on NetworkManager since wwan0 is virtual interface --- platform/jetson/scripts/lte_configure.sh | 298 ++++++++--------------- 1 file changed, 96 insertions(+), 202 deletions(-) diff --git a/platform/jetson/scripts/lte_configure.sh b/platform/jetson/scripts/lte_configure.sh index 8b8414a..afb84db 100755 --- a/platform/jetson/scripts/lte_configure.sh +++ b/platform/jetson/scripts/lte_configure.sh @@ -2,103 +2,30 @@ set -euo pipefail -# Help text -usage() { - cat << EOF -Usage: $0 --apn [--dns1 ] [--dns2 ] [--user ] [--password ] - -Required arguments: - --apn Access Point Name for the cellular connection - -Optional arguments: - --dns1 Primary DNS server - --dns2 Secondary DNS server - --user Username for carriers that require authentication - --password Password for carriers that require authentication - --help Show this help message -EOF -} - -# Parse arguments -APN="" -DNS1="" -DNS2="" -USERNAME="" -PASSWORD="" - -while [[ $# -gt 0 ]]; do - case $1 in - --apn) - APN="$2" - shift 2 - ;; - --dns1) - DNS1="$2" - shift 2 - ;; - --dns2) - DNS2="$2" - shift 2 - ;; - --user) - USERNAME="$2" - shift 2 - ;; - --password) - PASSWORD="$2" - shift 2 - ;; - --help) - usage - exit 0 - ;; - *) - echo "Error: Unknown parameter $1" - usage - exit 1 - ;; - esac -done - -# Validate required arguments -if [ -z "$APN" ]; then - echo "Error: APN is required" - usage - exit 1 -fi - -# Function to check prerequisites check_prerequisites() { - echo "Checking prerequisites..." - - # Check for QMI_WWAN kernel module - if ! lsmod | grep -q "qmi_wwan"; then - echo "Error: qmi_wwan kernel module not loaded" - echo "Try: modprobe qmi_wwan" + if ! modprobe qmi_wwan; then + echo "Error: Failed to load qmi_wwan kernel module" exit 1 fi - # Check for required tools - for cmd in mmcli nmcli; do + for cmd in mmcli; do if ! command -v "$cmd" >/dev/null 2>&1; then echo "Error: Required command '$cmd' not found" exit 1 fi done - # Check if NetworkManager is running if ! systemctl is-active --quiet NetworkManager; then echo "Error: NetworkManager is not running" exit 1 fi } -# Function to wait for modem with timeout -wait_for_modem() { +wait_for_modem_alive() { local timeout=30 local count=0 - echo "Waiting for modem to be detected..." + echo "Waiting for modem" while [ $count -lt $timeout ]; do if mmcli -L | grep -q "Sierra.*RC7611"; then return 0 @@ -110,162 +37,129 @@ wait_for_modem() { exit 1 } -# Function to get modem index -get_modem_index() { - local modem_index - modem_index=$(mmcli -L | grep "Sierra.*RC7611" | grep -o "/[0-9]*" | tr -d '/') - echo "$modem_index" -} - -# Function to verify modem state -verify_modem_state() { +wait_for_modem_network_connected() { local modem_index=$1 - local modem_status + local timeout=60 + local count=0 - echo "Verifying modem state..." - modem_status=$(mmcli -m "$modem_index") + while [ $count -lt $timeout ]; do + # Get status, strip colors, and check states + local modem_status + modem_status=$(mmcli -m "$modem_index" | TERM=dumb sed 's/\x1b\[[0-9;]*m//g') - # Check if modem is enabled - if ! echo "$modem_status" | grep -q "state: 'enabled'"; then - echo "Error: Modem is not enabled" - exit 1 - fi + if echo "$modem_status" | sed 's/^[ \t]*//' | grep -q "state: connected" && \ + echo "$modem_status" | sed 's/^[ \t]*//' | grep -q "packet service state: attached"; then + return 0 + fi - # Check for SIM - if ! echo "$modem_status" | grep -q "SIM.*active"; then - echo "Error: No active SIM detected" - echo "Please check:" - echo " - SIM card is properly inserted" - echo " - SIM card is not locked" - echo " - SIM card is activated with carrier" - exit 1 - fi + echo -n "Waiting for modem to connect... ($count/$timeout seconds)\r" + sleep 1 + count=$((count + 1)) + done - # Check signal quality - local signal_quality - signal_quality=$(echo "$modem_status" | grep "signal quality:" | grep -o "[0-9]*" | head -1) - if [ -n "$signal_quality" ] && [ "$signal_quality" -lt 10 ]; then - echo "Warning: Very weak signal strength ($signal_quality%)" - echo "Please check antenna connections" - fi + echo -e "\nError: Timeout waiting for modem to connect" + exit 1 } -# Function to verify bearer state -verify_bearer_state() { - local modem_index=$1 - - echo "Verifying bearer state..." - local bearer_status - bearer_status=$(mmcli -m "$modem_index" --bearer=0 2>/dev/null || true) +usage() { + cat << EOF +Usage: $0 --apn - if [ -n "$bearer_status" ]; then - if ! echo "$bearer_status" | grep -q "connected.*yes"; then - echo "Warning: Bearer not connected" - echo "This may be normal if connection hasn't been started yet" - fi - fi +Required arguments: + --apn Access Point Name for the cellular connection +EOF } -# Function to configure connection -configure_connection() { - local conn_name="ark-lte" - - # Remove existing connection if present - if nmcli connection show | grep -q "^$conn_name "; then - echo "Removing existing connection..." - nmcli connection delete "$conn_name" - fi - - # Build base connection command - local cmd="nmcli connection add \ - type gsm \ - con-name $conn_name \ - ifname wwan0 \ - apn $APN \ - connection.autoconnect yes \ - gsm.auto-config yes \ - ipv4.method auto \ - ipv4.route-metric 4294967295 \ - ipv6.method auto \ - ethernet.arp no" - - # Add optional DNS servers if specified - if [ -n "$DNS1" ] || [ -n "$DNS2" ]; then - local dns_servers="" - if [ -n "$DNS1" ]; then - dns_servers="$DNS1" - if [ -n "$DNS2" ]; then - dns_servers="$dns_servers,$DNS2" - fi - elif [ -n "$DNS2" ]; then - dns_servers="$DNS2" - fi - cmd="$cmd ipv4.dns \"$dns_servers\"" - cmd="$cmd ipv4.ignore-auto-dns yes" - fi - - # Add authentication if specified - if [ -n "$USERNAME" ]; then - cmd="$cmd gsm.username \"$USERNAME\"" - fi - if [ -n "$PASSWORD" ]; then - cmd="$cmd gsm.password \"$PASSWORD\"" - fi +APN="" +DNS1="" +DNS2="" +USERNAME="" +PASSWORD="" - # Execute the assembled command - eval "$cmd" +while [[ $# -gt 0 ]]; do + case $1 in + --apn) + APN="$2" + shift 2 + ;; + --help) + usage + exit 0 + ;; + *) + echo "Error: Unknown parameter $1" + usage + exit 1 + ;; + esac +done - # Configure MTU and other link settings - nmcli connection modify "$conn_name" gsm.mtu 1500 - nmcli connection modify "$conn_name" 802-3-ethernet.accept-all-mac-addresses no -} +if [ -z "$APN" ]; then + echo "Error: APN is required" + usage + exit 1 +fi -# Main script -echo "Configuring ARK LTE modem..." +echo "Setting up ARK LTE modem" -# Check if running as root if [ "$EUID" -ne 0 ]; then echo "Error: This script must be run as root" exit 1 fi -# Run prerequisite checks check_prerequisites -# Wait for modem -wait_for_modem +wait_for_modem_alive -# Verify modem state -verify_modem_state "$MODEM_INDEX" - -# Verify bearer state -verify_bearer_state "$MODEM_INDEX" - -# Get modem index -MODEM_INDEX=$(get_modem_index) +MODEM_INDEX=$(mmcli -L | grep "Sierra.*RC7611" | grep -o "/[0-9]*" | tr -d '/' | tr -d '\n') if [ -z "$MODEM_INDEX" ]; then echo "Error: Could not determine modem index" exit 1 fi -# Configure EPS bearer -echo "Configuring initial EPS bearer settings..." +echo "Configuring initial EPS bearer settings" mmcli -m "$MODEM_INDEX" --3gpp-set-initial-eps-bearer-settings="apn=$APN" -# Create and configure connection -echo "Creating NetworkManager connection..." -configure_connection +echo "Waiting for modem to connect to network" +mmcli -m "$MODEM_INDEX" --simple-connect="apn=$APN,ip-type=ipv4v6" +wait_for_modem_network_connected "$MODEM_INDEX" + +echo "Creating connection" +modem_status=$(mmcli -m 0) +bearer_index=$(echo "$modem_status" | awk '/Bearer.*paths:/ { last = $NF } END { gsub(".*/", "", last); print last }') +bearer_info=$(mmcli -m 0 --bearer=$bearer_index) + +conn_name="ark-lte" +interface=$(echo "$bearer_info" | awk -F': ' '/interface/ {print $2}') +address=$(echo "$bearer_info" | awk -F': ' '/address/ {print $2}') +prefix=$(echo "$bearer_info" | awk -F': ' '/prefix/ {print $2}') +gateway=$(echo "$bearer_info" | awk -F': ' '/gateway/ {print $2}') +# TODO: optional dns +# dns=$(echo "$bearer_info" | awk -F': ' '/dns/ {print $2}') +mtu=$(echo "$bearer_info" | awk -F': ' '/mtu/ {print $2}') + +sudo ip link set $interface up + +# Add IP if it doesn't already exist +if ! ip addr show $interface | grep -q "$address"; then + sudo ip addr add "$address/$prefix" dev $interface +fi -echo "Starting connection..." -nmcli connection up ark-lte +sudo ip link set dev $interface arp off +sudo ip link set $interface mtu $mtu -# Quick connection verification -echo "Verifying connection..." -sleep 5 -if ! nmcli -g GENERAL.STATE connection show ark-lte 2>/dev/null | grep -q "activated"; then - echo "Error: Connection failed to activate" +# Add route if it doesn't already exist +if ! ip route show | grep -q "default via $gateway dev $interface"; then + sudo ip route add default via $gateway dev $interface metric 4294967295 +fi + +echo "Testing connection" + +if ! ping -4 -c 4 -I $interface 8.8.8.8 >/dev/null 2>&1; then + echo "Failed!" exit 1 fi -echo "Configuration completed successfully" +echo "Connected!" + exit 0 From 5bc9e080a8d70f8fd41fe17e596cbe42770cb37d Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Tue, 18 Feb 2025 21:04:04 -0900 Subject: [PATCH 4/8] add dns servers, wait for modem forever, flush ip and route, don't exit on command fail --- platform/jetson/scripts/lte_configure.sh | 41 +++++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/platform/jetson/scripts/lte_configure.sh b/platform/jetson/scripts/lte_configure.sh index afb84db..5debf3c 100755 --- a/platform/jetson/scripts/lte_configure.sh +++ b/platform/jetson/scripts/lte_configure.sh @@ -1,7 +1,5 @@ #!/bin/bash -set -euo pipefail - check_prerequisites() { if ! modprobe qmi_wwan; then echo "Error: Failed to load qmi_wwan kernel module" @@ -22,19 +20,14 @@ check_prerequisites() { } wait_for_modem_alive() { - local timeout=30 - local count=0 - - echo "Waiting for modem" - while [ $count -lt $timeout ]; do - if mmcli -L | grep -q "Sierra.*RC7611"; then - return 0 + while true; do + modem_instance=$(mmcli -L | grep -oP '(?<=/Modem/)\d+') + if [ -n "$modem_instance" ]; then + break fi - sleep 1 - count=$((count + 1)) + sleep 2 done - echo "Error: Modem not detected within timeout period" - exit 1 + echo "Modem instance: $modem_instance" } wait_for_modem_network_connected() { @@ -129,15 +122,28 @@ modem_status=$(mmcli -m 0) bearer_index=$(echo "$modem_status" | awk '/Bearer.*paths:/ { last = $NF } END { gsub(".*/", "", last); print last }') bearer_info=$(mmcli -m 0 --bearer=$bearer_index) -conn_name="ark-lte" interface=$(echo "$bearer_info" | awk -F': ' '/interface/ {print $2}') address=$(echo "$bearer_info" | awk -F': ' '/address/ {print $2}') prefix=$(echo "$bearer_info" | awk -F': ' '/prefix/ {print $2}') gateway=$(echo "$bearer_info" | awk -F': ' '/gateway/ {print $2}') -# TODO: optional dns -# dns=$(echo "$bearer_info" | awk -F': ' '/dns/ {print $2}') +dns=$(echo "$bearer_info" | awk -F': ' '/dns/ {print $2}') mtu=$(echo "$bearer_info" | awk -F': ' '/mtu/ {print $2}') +IFS=', ' read -r dns1 dns2 <<< "$dns" +# Remove ending comma from dns1 +dns1=${dns1%,} + +echo "IPv4 Address: $address" +echo "IPv4 Prefix: $prefix" +echo "IPv4 Gateway: $gateway" +echo "IPv4 DNS1: $dns1" +echo "IPv4 DNS2: $dns2" +echo "IPv4 MTU: $mtu" + +# Flush any existing ip or routes +sudo ip addr flush dev $interface +sudo ip route flush dev $interface + sudo ip link set $interface up # Add IP if it doesn't already exist @@ -148,6 +154,9 @@ fi sudo ip link set dev $interface arp off sudo ip link set $interface mtu $mtu +sudo sh -c "echo 'nameserver $dns1' >> /etc/resolv.conf" +sudo sh -c "echo 'nameserver $dns2' >> /etc/resolv.conf" + # Add route if it doesn't already exist if ! ip route show | grep -q "default via $gateway dev $interface"; then sudo ip route add default via $gateway dev $interface metric 4294967295 From f8144a0869db01004fbb9a8879b66b6699f63485 Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Tue, 18 Feb 2025 21:10:30 -0900 Subject: [PATCH 5/8] cleanupg --- platform/jetson/scripts/lte_configure.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/platform/jetson/scripts/lte_configure.sh b/platform/jetson/scripts/lte_configure.sh index 5debf3c..149be0f 100755 --- a/platform/jetson/scripts/lte_configure.sh +++ b/platform/jetson/scripts/lte_configure.sh @@ -64,10 +64,6 @@ EOF } APN="" -DNS1="" -DNS2="" -USERNAME="" -PASSWORD="" while [[ $# -gt 0 ]]; do case $1 in From de2d292339d9829b4b0effaed4bbdf82eb10e678 Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Wed, 19 Feb 2025 10:34:05 -0900 Subject: [PATCH 6/8] modem instance generic --- platform/jetson/scripts/lte_configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/jetson/scripts/lte_configure.sh b/platform/jetson/scripts/lte_configure.sh index 149be0f..378dd12 100755 --- a/platform/jetson/scripts/lte_configure.sh +++ b/platform/jetson/scripts/lte_configure.sh @@ -100,7 +100,7 @@ check_prerequisites wait_for_modem_alive -MODEM_INDEX=$(mmcli -L | grep "Sierra.*RC7611" | grep -o "/[0-9]*" | tr -d '/' | tr -d '\n') +MODEM_INDEX=$(mmcli -L | grep -oP '(?<=/Modem/)\d+') if [ -z "$MODEM_INDEX" ]; then echo "Error: Could not determine modem index" exit 1 From dc2b17a232dce9ceb14d1542435d57fccf47e04e Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Thu, 27 Feb 2025 13:02:01 -0900 Subject: [PATCH 7/8] update ark-ui and rtsp-server --- submodules/ark-ui | 2 +- submodules/rtsp-server | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/ark-ui b/submodules/ark-ui index 9645de6..dd2e96d 160000 --- a/submodules/ark-ui +++ b/submodules/ark-ui @@ -1 +1 @@ -Subproject commit 9645de6c0b797b234723675bc64e4b779f544bff +Subproject commit dd2e96d5552355d0895abf345699443b322f3942 diff --git a/submodules/rtsp-server b/submodules/rtsp-server index 58038a1..e9d12a6 160000 --- a/submodules/rtsp-server +++ b/submodules/rtsp-server @@ -1 +1 @@ -Subproject commit 58038a178c02a0d42c0f8e588db7db70c0ec3676 +Subproject commit e9d12a60721f9d870fcab4cbaec3aaa139302bcc From 1d84c3b0fd258d6718fd026b94f8fab8679a1687 Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Thu, 27 Feb 2025 17:08:19 -0900 Subject: [PATCH 8/8] submodules --- submodules/ark-ui | 2 +- submodules/rtsp-server | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/ark-ui b/submodules/ark-ui index dd2e96d..9e7aab1 160000 --- a/submodules/ark-ui +++ b/submodules/ark-ui @@ -1 +1 @@ -Subproject commit dd2e96d5552355d0895abf345699443b322f3942 +Subproject commit 9e7aab1571d4e24a996e740fbf1c301fc2543e3f diff --git a/submodules/rtsp-server b/submodules/rtsp-server index e9d12a6..78a3f01 160000 --- a/submodules/rtsp-server +++ b/submodules/rtsp-server @@ -1 +1 @@ -Subproject commit e9d12a60721f9d870fcab4cbaec3aaa139302bcc +Subproject commit 78a3f01011a09925c331c14bac1b3ab2c9981046