Loading the Apps for the Thru-Modem


An Example RC Script

Once you have the thru-modem up an running, you may want to write a runtime configuration script that automates the parametric configuration of the drivers and starts up the AX25 Utilities. You could then place this script in the rc.d directory in a file named rc.local, or something similiar on your particular OS version, which is run when the system boots.

The excerpted example is meant to serve as a guide and possible source of scripting ideas that you may want to use in your own script. You will see that subroutines are used along with their argument passing "shift" function. I would consider this script to be at the intermediate level. So, if this is your first exposure to shell scripting in Linux, it might be a good idea to review some basic principles of script writing since you will no doubt have to heavily modify the example shown below.

Scripting is code development, although at a very "primative" level. However, the same design principles apply:

  1. Decide what your objectives are.
  2. Write them down as documentation in the script. (Each command should have a line explaining what is supposed to happen, i.e., the expected outcome.)
  3. Code: Fill in the details with your command line instructions.
  4. Test one module at a time.
... and test the entire script outside of the rc.local file, and if OK, then insert into that file... Have fun, keep smiling, and keep scripting!




My do_ax25 Runtime Configuration Script

#!/bin/sh
# do_ax25
# 04-30-98, 05-12-98
# 11-23-99
# 04-06-00,
# 04-19-03 (SuSE), 05-14-03
# 06-01-03 (Bambi), 06-05-03
# KA1FSB/kbn
# --------------------------------------------------------------------
#
# NOTE: Make sure you have the cable in the right slot! COM1
#       Make sure you have removed any NULL modem from the line!
#       Make sure you have disabled any use of dev/ttyS3 in the inittab
#        file, else you will get a resources busy from ifconfig!
#       Make sure the ifconfig for the bcsf0 iface looks OK!
#       Modify the ax25d.conf and the axports files for bcsf0!	
#
# NOTE: If you want to include the sound modules, load them AFTER this
#       do_baycom has been run!!!
#
# NOTE: (This is the SuSE version! device is bcsf[0-3]. You may have to
#       convert the line to tcpip or the ax25d won't run! 
#       So far, I can only get COM1 to "attach" on irq 4. The docs
#       say use either irq 3 or 4, and com2 or com1. Doesn't talk about
#       other com's or irq's! This is for sethdlc.)
#
# NOTE: This is the Bambi version! devices are bc[0-3]. I tried irq 2
#       and this did NOT work, as it did not on SuSE either! So I
#       tried irq 5 and it worked! (3, 4, 11 all known to work) 
#
# NOTE: This is slowly converting to a generalized ax25 loader!
#       OK, we are there, 05-12-03. It is now do_ax25
#
# NOTE: Bring up axip and netrom first using this script. Then go
#       back and bring up bcsf0 for JNOS.
#
# NOTE: Can now be run from do_ax25.cf which answers the prompts so
#       that this can be automated from another script. If you want more
#       configuration ability, then you can add a cmd line switch which
#       would allow passing args by this method...
#
# ---------------------------------------------------------------------

#----- Inits...
MYDATE=`/bin/date`
LM='06-01-03'
LINUX_VER=`uname -r`
MOD_PATH="/lib/modules/$LINUX_VER"

#----- Where you want the log data...
MYLOG="/root/ax25.errors"

#----- A few more inits...
KISSDUMP="/root/bin/mykiss"
INETADDR="44.56.26.14"
DEFCALL="KA1FSB-7"
MODNAME=""
OBJPATH=""

#----- This is the list of modules that need to be loaded 
#-----  for a full radio configuration...
MODLIST="net/bsd_comp net/hdlcdrv net/baycom"

#----- A separate shorter list for axip only or no baycom...
# AX25LIST="misc/ax25 misc/netrom"

#===== Parse the cmd args...

#----- Help usage info...
if [ "$1" = "--help"  ]
then
        echo ""
        echo "Usage: do_ax25 (currently an interactive version, no cmd line args)"
        echo ""
        exit 0
fi
 

#===== Start of calls and subs...
do_axip ()
{
#----- KA1FSB-6 is the axip0 call... for ax25 utils
	local DEVICE=""
	local KISSMSG=""
	local AXIPCALL="KA1FSB-6"

#----- Attach the axip line...
	/bin/echo "   ->   Attaching the axip device on port axip0..." | tee -a $MYLOG

#----- Attach as an internal pipe, ptyqd on port axip0.
        /usr/sbin/kissattach -l /dev/ptyqd axip0 $INETADDR >$KISSDUMP
        KISSMSG=`/bin/cat $KISSDUMP`
        DEVICE=`echo $KISSMSG | tr -d "." | \
		sed -e 's/^.* \(ax[0-9].*\)/\1/' | cut -f1 -d " "`

        if [ "$DEVICE" ]
        then
                echo "   ->   $KISSMSG" | tee -a $MYLOG
                ifconfig $DEVICE $INETADDR broadcast 44.255.255.255 netmask 255.255.255.0
                axparms -setcall $DEVICE $AXIPCALL

		/bin/echo "   ->   Starting the ax25ipd daemon..." | tee -a $MYLOG

#----- Connect the other side of this pipe ttyqd for axip0...
#----- The ax25ipd.conf lists /dev/ttyqd as the other side of that pipe
		/usr/sbin/ax25ipd 1>>$MYLOG 2>>$MYLOG &

#----- 01-14-02: Make KA1FSB-7 the default route...
		/usr/sbin/axparms -route add axip0 default ka1fsb-7
	fi
}

do_netrom ()
{
#----- 12-30-01, 01-01-02: Netrom set ups, SuSE 04-23-03
        /bin/echo "   ->   Setting up NET/ROM configs... " | tee -a $MYLOG

#----- Order of ops is crucial, as usual..
        /usr/sbin/nrattach -i $INETADDR nr0 | tee -a $MYLOG

#----- netmask was 255.0.0.0, brc was 44.255.255.255
	/sbin/ifconfig nr0 44.56.26.14 netmask 255.255.255.0 

#----- Could include -q 192 for quality... ( -i at start, gives it a kick )
        /usr/sbin/netromd -i -l -t 20 -d &

        sleep 1
}

do_baycom ()
{
#----- Now set up the bc devices, up to four devices allowed...
#----- Shift in the args as this sub is called...

	local IFACE=""
	local TTY=""
	local HEXADDR=""
	local INTR=""
	local DEVCALL=""
	local PORTNET=""
	local PTERM=""

	IFACE=$1
	shift

	echo "   ...Starting do_baycom script for $IFACE" | tee -a $MYLOG
	echo "   ->   Testing for bc devices in device table..." | tee -a $MYLOG

	TEST=""
	TEST=`cat /proc/net/dev | grep -c bc[a-z0-9]:* | tr -d " "`
	if [ "$TEST" != "" ]
	then
		echo "        OK, found $TEST bc device(s)..." | tee -a $MYLOG
		TEST=""
		TEST=`cat /proc/net/dev | grep -i $IFACE: | tr -d " "`
		if [ ! "$TEST" ]
		then
			echo "Could not find bc device $IFACE!" | tee -a $MYLOG
			return
		fi
	else
		echo "        Could NOT find bc devices in /proc/net/dev" | tee -a $MYLOG
		return
	fi

#----- Pass in the rest of the parameters...
	TTY=$1
	shift

	HEXADDR=$1
	shift

	INTR=$1
	shift

	DEVCALL=$1
	shift

	PORTNET=$1
	shift

	PTERM=$1

#----- Detach the serial driver from this port, COM1...
#----- Line must be free in order to detach!
	echo "   ->   Clearing and detaching ${TTY} ..." | tee -a $MYLOG
	setserial /dev/${TTY} uart none
	sleep 2

#----- Attach the HDLC driver for this serial port... if not, then bail 
	sethdlc -p -i $IFACE mode ser12* io $HEXADDR irq $INTR

	if [ "$?" = "0" ]
	then
		echo "   ->   Freed ${TTY} and attached Baycom driver to $IFACE on ${TTY}." | tee -a $MYLOG
	else
		echo "   =>   Fail on device $IFACE attach!" | tee -a $MYLOG
		return
	fi

	sleep 7

#----- Tweak the timing parameters... ppersist was 40, txd-200, txt-20
	echo '   ->   Tweaking parameters for the hdlc...' | tee -a $MYLOG
	sethdlc -i $IFACE -a txd 250 txtail 30 slot 100 ppersist 63 half
	sleep 3

#----- Turn it on...
	echo '   ->   Setting up ifconfig, arp and mtu 256...' | tee -a $MYLOG
	ifconfig $IFACE mtu 256 up
	sleep 1

#----- Associate a callsign with the kernel iface to get the port name!
        echo "   ->   Associating $DEVCALL with interface $IFACE" | tee -a $MYLOG
        axparms -setcall $IFACE $DEVCALL
	sleep 1

#----- Convert the line to tcp/ip, may need to add routing...
#----- NOTE: On SuSE seems like the line must be a tcpip too!
        /root/do_tcpip $IFACE

#----- If JNOS, then hook this end of the pseudo terminal up...
#----- NOTE: On bambi, this does not always "take" the first time.
#----- I have to do a double boot, once for net2kiss and then for JNOS
#----- See the file baycom in /doc...
	if [ "$PORTNET" = "jnos" ]
	then
		sleep 1
		echo "   ->   Set network to kiss pseudo pty${PTERM} pipe..." | tee -a $MYLOG
		/usr/sbin/net2kiss -z -i $IFACE /dev/pty${PTERM} &
		sleep 1
	fi

#----- OK! This works fine! Gets access to all the portnet "vhf" SSID's 
#----- To activate, make PORTNET vhf or whatever networked port you want!
	if [ "$PORTNET" != "" ] && [ "$PORTNET" != "jnos" ] && [ "$PORTNET" != "none" ]
	then
		/usr/sbin/net2kiss -z -i $IFACE /dev/pty${PTERM} &
		/usr/sbin/kissattach /dev/tty${PTERM} $PORTNET $INETADDR
	fi

#----- Now show the table for ifconfig...
	ifconfig $IFACE
}


#***** Begin the main process...

clear
echo "          *** AX25 Utilities Configuration ( $LM ) ***"
echo ""
#----- Could be changed to clear file on first run...  (>)
echo $MYDATE 1>$MYLOG


#----- First disable the cua(x)'s before the module loads!
#----- This made no difference in regard to bc1 (deaf)
# setserial /dev/cua1 uart none
# sleep 1
# setserial /dev/cua2 uart none


#===== Load the module drivers...
echo "   ->   Loading required modules..." | tee -a $MYLOG
for i in $MODLIST
do
        MODNAME=`echo $i | cut -f2 -d"/"`
        echo -n "$MODNAME " | tee -a $MYLOG
        OBJPATH=$MOD_PATH"/"$i".o"
        insmod $OBJPATH
        sleep 1
done
echo "" | tee -a $MYLOG


#===== Attach devices and startup subsidiary daemons...

echo -n "Do you want to install the baycom driver module? (Y/N) : "
read MYINPUT

if [ "$MYINPUT" = "y" ] || [ "$MYINPUT" = "Y" ]
then
 	echo "OK, installing baycom module..."

#----- Configure or re-configure as required...
#----- The last is the pseudo terminal ptyqa and ttyqa,
#----- You choose the last two letters, ie, qa, qb, qc, qd...
#----- NOTE: irq 2 usually does not work, get a busy sig from device

	do_baycom bc0 ttyS2 0x3e8 5 KA1FSB-7 jnos qa
	sleep 3

#----- Line cannot RX yet! Line discipline? Order of ops?
#----- or is there a kernel conflict with the sound stuff!?
#	do_baycom bc1 ttyS1 0x2f8 3 KA1FSB-8 none -
#	sleep 5

#----- Spares...
#	do_baycom bc2 ttySx 0x??? X KA1FSB-7 jnos qc
#	do_baycom bc3 ttySx 0x??? X KA1FSB-7 jnos qd

else
	echo -e "\nNot installing the baycom driver at this time..."
fi

#----- Exit if you only want to set up the bc driver(s)
echo -n "Do you want to install the ax25 utilities? (Y/N) : "
read MYINPUT

if [ "$MYINPUT" = "y" ] || [ "$MYINPUT" = "Y" ]
then
	echo "OK, continuing with full install of ax25 modules..."
else
	echo -e "\nExiting here..." 
	exit
fi

#----- Early exit here on Bambi for a test... just in case
# exit

#----- Now do the axip links...
# do_axip

#----- Set up the netrom port(s) and start up the daemon...
#----- Netrom MUST come before the ax25d start up!
# do_netrom


#===== Clear out any control files that may be blocking...
cp /dev/null /var/ax25/pms/loggedin


#===== Now load the daemons...
echo "   ->   Starting ax25d, etc..." | tee -a $MYLOG
/usr/sbin/ax25d

#----- Now start some things AFTER the ax25d is up!
/usr/sbin/mheardd -n 10

#----- Now set up ax25 routing...
/usr/sbin/ax25rtd

#----- You may tweak/add netrom any time after all is up...
# /root/bin/do_nrparms

#----- Set the radio beacon going...
/root/do_beacon - bc0

#----- Need this for pms MBX!, mail then goes to ka1fsb on system
/usr/sbin/axparms -assoc ka1fsb-7 ka1fsb
/usr/sbin/axparms -route add bc0 default ka1fsb-7
/usr/sbin/axparms -route add bc0 default

#----- Test to see if sockets are active...
netstat --ax25
netstat --netrom

echo "   Completed do_baycom script..." | tee -a $MYLOG
echo "" >> $MYLOG
 
#===== End of do_ax25


(Courtesy KBNorton Computer Services)