Starting Ax.25

Updated Mar 31 2017

Charles S. Schuman, K4GBB
k4gbb1@gmail.com

Introduction

You've solved the riddle of installing the run-time ax25lib, ax25-apps and ax25-tools. You unraveled the mystery of attaching an ax25 device to a serial device and setting the operating parameters. Now how do you get the whole thing to work each time you boot up your computer?
A bash script will do the trick, but where do you place it so that it starts up automatically at boot-up?

Some How-to docs suggest placing Ax.25 in rc.local, but it is really a System element. It should have it's own Start Up and Shut down process

You should be able to start, restart and stop the entire service with one command.
OK that is easy enough, but how do we handle changes? You will want to add features to your packet services, experiment with settings and adapt to changing network configurations.

Start - Stop

It boils down to two operations Start & Stop. So we point Start to a specific file, /usr/local/etc/ax25/ax25-up, that takes care of starting details and Stop, /usr/local/etc/ax25/ax25-down, that halts the service in a organized manner.

../etc/ax25/ax25-up

In both Systemd and Init.d the Start option points to the executable file named ../etc/ax25/ax25-up..
which might look like this:

#!/bin/bash
# /etc/ax25/x25-up

# Set Sysctl values
sysctl -w kernel.panic=30
sysctl -w kernel.panic_on_oops=30 

# Attach KISS-device /dev/ttyS0 to Port 0 
  /usr/local/sbin/kissattach /dev/ttyS0 0 44.128.1.1 >/tmp/ax25-config.tmp
  awk '/device/ { print $7 }' /tmp/ax25-config.tmp > /tmp/ax25-config-tmp
  read Device > /tmp/ax25-config-tmp 

# Install Parameter: Persistence=128, slot=10, TX-Delay=250 
  /usr/local/sbin/kissparms -p 0 -r 228 -s 10 -l 20 -t 250 

# Parms for Port0  (LAN)
cd /proc/sys/net/ax25/$Device/
echo 3100   > t1_timeout        # (Frack) /100 = seconds (1 - 30) seconds
echo 1000   > t2_timeout        # (RESPtime) /100 = .001 seconds (1 – 20)second
echo 300000 > t3_timeout        # (Check) /600 = min (0 - 3600)seconds
echo 600000 > idle_timeout      # Disconnect when idle /600 = min (0 or greater)
echo 0      > ax25_default_mode # AX25 Default Mode 0 = Normal,1 = Extended (0)
echo 0      > ip_default_mode   # IP Default Mode 0 = Standard (mod 7),1 = Extended (mod 127)(0)
echo 0      > backoff_type      # Backoff 0 = Original, 1 = linear, 2 = exponential (1)
echo 256 > maximum_packet_length # Frame Size 1 - 512 (256)
echo 2  > connect_mode           # Connect Mode 0 = None, 1 = Network, 2 = All (2)
echo 8  > maximum_retry_count    # N2 (1 -31)
echo 180000 > dama_slave_timeout
echo 32     > extended_window_size
echo 2      > standard_window_size # Max frames
echo 0 > protocol                 

# Start ax25d daemon
  /usr/local/sbin/ax25d &
  echo "ax25d started"

# Start Mheard daemon
  /usr/local/sbin/mheardd 
  echo "mheardd Started"

# (End of ax25.up)

Add any other statements to start apps like NetRom, FBB BBS or FPAC Node.

../etc/ax25/ax25-down

The Stop procedure points to another executable file named /etc/ax25/ax25-down.
It could look like this:

#!/bin/bash
# /etc/ax25/ax25-down
# Stop Ax25 support
for PROC_NAME in beacon ax25d ax25ipd ax25rtd mheardd listen
   do
   PID=`/bin/pidof -x $PROC_NAME`
     if [ -n "$PID" ]; then 
        kill -TERM $PID > /dev/null
        echo "$PROC_NAME - $PID "
        sleep 1
     fi
   done

# Stop netromd if it is running
  pidof netromd > /dev/null
   if [ $? -eq  0 ]; then
   killall netromd
   echo Netrom Stopped 
   fi 

# Close sockets
echo "Detach Ax/Nr/Sp Devices"
echo `ifconfig|grep AMPR` > /tmp/ax25-config.tmp
read Select > /tmp/ax25-config.tmp 
i=0 
while [ "$Select" != "" ]
  do 
   let i=i+1 
   awk ' NR == '$i' { print $1 }' /tmp/ax25-config.tmp > /tmp/ax25-config-tmp 
   read Select < /tmp/ax25-config-tmp 
   if [ "$Select" != "" ]; then  
     ifconfig $Select down
     echo " $Select detached" 
   fi 
  done 

# Stop Kissattach 
  killall -KILL kissattach > /dev/null 

  echo "Ax25 Stopped"
# End of ax25-down

Host Start up Schemes

The early system of starting up a host used files in /etc/init.d/. Since then we have seen several attempts to speed up or reorganize the the initial start of a operating systems applications. The newest attempt is called Systemd.

Starting ax25 from /etc/init.d at boot-up

Create a file /etc/init.d/ax25.
To down-load the ax25 script click HERE Don't forget to make it executable.

chmod 755 /etc/init.d/ax25

When you have the ax25 script placed in /etc/init.d/ Using the Debian  utility update-rc.d, we can

setup the start links with the command :

update-rc.d ax25 defaults

An Example of a /etc/init.d/ax25 file

#! /bin/bash
# Provided by Charles S Schuman ( k4gbb1@gmail.com )
# Feb 11 2017
### BEGIN INIT INFO
# Provides: ax25
# Required-Start: $local_fs $syslog $network
# Required-Stop:  $syslog $network
# Default-Start: S
# Default-Stop: 0 1 6
# Short-Description: Ax.25 initialization
# Description: This script provides the control for the ax.25 Packet Radio Service.
#	       The fine tuning is accomplished via /etc/ax25/ax25-up and /etc/ax25/ax25-down.
#
### END INIT INFO

# Using the lsb functions to perform the operations.
#. /lib/lsb/init-functions

NAME=Ax25			# Process name ( For display )
DAEMON=/usr/local/etc/ax25/ax25-up
PIDFILE=/var/run/ax25.pid 	# pid file for the daemon

test -x $DAEMON || exit 5 # Exit - Pgm Not Installed.

case "$1" in
  start )
  # Check the status of ax25
    if [ -d /proc/sys/net/ax25/ax0 ]; then
        echo -e "\t $NAME: is already running."
        netstat|grep LISTENING
        exit 1
    fi
    echo -e "\t *** $NAME $1 ***"
    /etc/ax25/ax25-up
    ;;

    stop )
    echo "    *** $NAME $1 ***"
    /etc/ax25/ax25-down
    ;;

   restart )
    echo "    *** $NAME $1 ***"
    /etc/ax25/ax25-down
    sleep 1
    /etc/ax25/ax25-up
    ;;

  status )
    echo  "        *** $NAME $1 ***"
    if [ ! -d /proc/sys/net/ax25/ax0 ] ; then
      echo "ax25 is down"
    else
        if [ -z "$(uname -r | grep kjd)" ] ;then
#          netstat --ax25
           netstat|grep LISTENING
        else
          /sbin/ifconfig ipax0
          cat /proc/net/ax25
        fi
    fi
    ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0
# (End of Script)

Starting ax25 with Systemd at boot-up

Add the following text to a file named /lib/systemd/system/ax25.service

[Unit]
Description=AX.25 interface
After=network.target

[Service]
#EnvironmentFile=/etc/ax25
Type=forking
Restart=no
TimeoutSec=0
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SysVStartPriority=12
ExecStart=/etc/ax25/ax25-up
ExecStop=/etc/ax25/ax25-down

[Install]
WantedBy=default.target 

Enable Ax.25 start up with the systemd cmd.

sudo systemctl enable ax25

Command Line Start/Stop

Now you should be able to Start, Stop and Restart Ax.25 from the command line

Init.d

system ax25 start
system ax25 stop
system ax25 restart
system ax25 status

Systemd

systemctl start ax25
systemctl stop ax25
systemctl restart ax25
systemctl reload ax25
systemctl status ax25