Starting Ax.25

Updated Feb 11 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 in in rc.local, but Ax.25 is really a system element.
It should have it's own script in /etc/init.d/
You should be able to start, restart and stop the entire service from one script.
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.

The ax25 init.d script

Start with a script file in /etc/init.d/ that will take care of the basics. It boils down to two operations Start & Stop. So we point Start to a specific file that takes care of starting details and Stop to another that halts the service in a organized manner.

Create a file in /etc/init.d/ax25. Then cut and paste the ax25 script below into the file and make it executable.
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)

ax25-up

The /etc/init.d/ax25 start option points to an 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.

ax25-down

Stop 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

Now you should be able to start, stop and restart ax25 from the command line

system ax25 start

system ax25 stop

system ax25 restart

system ax25 status