pax_global_header00006660000000000000000000000064125460052340014513gustar00rootroot0000000000000052 comment=d0b3fad6db6b7bb43c444a8e30a3c75f4e45f075 aprsdigi-3.10.0/000077500000000000000000000000001254600523400133765ustar00rootroot00000000000000aprsdigi-3.10.0/.gitignore000066400000000000000000000002201254600523400153600ustar00rootroot00000000000000Makefile Makefile.in aclocal.m4 aprsdigi.spec autom4te.cache/ config.log config.status configure *.o *.a *~ .deps/ .vagrant/ missing *.rpm *.gz aprsdigi-3.10.0/AUTHORS000066400000000000000000000000371254600523400144460ustar00rootroot00000000000000Alan Crosswell, n2ygk@weca.org aprsdigi-3.10.0/BUILD.md000066400000000000000000000063601254600523400145640ustar00rootroot00000000000000# Building and deploying _aprsdigi_ ## Introduction When I first started developing _aprsdigi_ (in the late 1990's!), I had a dual-boot Intel laptop running some linux distro (most recently Fedora Core). I had been deploying on real hardware (servers located at various radio tower sites) using [Cobbler](https://github.com/cobbler/cobbler) and a crossover Ethernet cable between the laptop and the server being installed. My current development hardware is a Mac OS X laptop and I am trying to modernize and virtualize development using tools like vagrant, git, puppet, razor, etc. and thought I would document my environment here as a reminder to me and as a means for others to potentially develop and package _aprsdigi_. ## Building a CentOS development VM I use [Virtualbox](https://www.virtualbox.org/) for the VM infrastructure and [Vagrant](https://www.vagrantup.com/) to configure those VMs. Because I'm paranoid (foolish), I didn't want to use the pre-built boxes from [Hashicorp](https://atlas.hashicorp.com/boxes/search), instead preferring to build my boxes from a known vanilla [CentOS](https://www.centos.org/) distro. Then, when I'm finally ready to deploy _aprsdigi_ on real hardware, I can use [razor](https://github.com/puppetlabs/razor-server) to deploy basically the same distro. ### Build a virtualbox image with packer and boxcutter I want something based on vanilla CentOS 7.1 with the latest updates installed. I do this with [packer](https://packer.io/) and [CentOS boxcutter] (https://github.com/boxcutter/) templates. It should be pretty easy to use other distro templates to similarly build aprsdigi. ``` git clone https://github.com/boxcutter/centos.git cd centos cat >Makefile.local < Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. aprsdigi-3.10.0/ChangeLog000066400000000000000000000103651254600523400151550ustar00rootroot00000000000000* Changes in aprsdigi-2.6.0, August 2009: - added aprsdigi.init script to help automate installation * Changes in aprsdigi-2.4.4, April 2003: * Changes in aprsdigi-2.4.3, April 2003: - Add support for IP/UDP interface, including IPv4 and IPv6 unicast and IPv4 any-source multicast (until I learn how to do SSM and v6 multicast). - Add Unix fifo interface and two test programs, fiforead and fifowrite. Mostly useful for debugging. - "-p port:call...." for ax25 ports is deprecated. Use "-p ax25:port:..." - Add interfaces options to toggle TX-enable, RX-enable and don't retransmit on received interface (e.g. for pt-to-pt and IP interface). - Add budlist (permit/deny access lists). - parse_cooked_ax25() and gen_cooked_ax25() added to libax25ext. Supports parsing TNC2 and AEA formats. Generates TNC2 format. - Corrected destination SSID routing to always work, not just for mic-E packets (per APRS Spec 1.02 Ch. 3 p. 12) - Added 3rd-party tunneling/de-tunneling (-3) per APRS Spec 1.02 Ch 17. I don't understand it, but it's there now. I use transparent tunneling (-0)! - Really fix the fencepost error that I claimed I fixed in 2.4.2! * Changes in aprsdigi-2.4.2, June 2002: - Fix fencepost error in expansion of TRACEn-n that was causing a seg fault. * Changes in aprsdigi-2.4.1, December 2001: - Fix loop killing (-L) to actually drop looping packets and not other random packets! * Changes in aprsdigi-2.4.0, November 2001: - Apply patches from Hamish Moffatt to update to the latest libax25. - Change keep default to 28 seconds to match the documented typical value per p.11 of the APRS Protocol Spec 1.0. - Don't digipeat packets that my station originated and then got repeated back to me (e.g. beacon -d "APRS via WIDE WIDE" should not be digi'd). (Thanks for noticing this one Arte.) - Make other cosmetic changes to eliminate need to patch libax25. - Rename a couple of functions. - Built and tested under a 2.4 kernel. Renumber the version to reflect the kernel version it runs with. * Changes in aprsdigi-2.0, March 1999: General aprsmon and aprsdigi changes: - Fix incorrect order of Mic-E longitude calculation which resulted in, among other errors, a zero longitude displaying as 19060.00W. - Corrections and changes to Mic-E -> "MIM" translations as requested by Bob Bruninga, including support for Kenwood TH-D7. - Fix T#MIC telemetry - Strip TheNet X1J4 BTEXT prefix, making an X1J4 node's beacon look like a regular APRS beacon. - Rename the package from aprsmon to aprsdigi-2.0 since the dominant useful code in the package is now the digi. arpsmon should probably be replaced by WA4DSY's aprsd. - Changes for Linux kernel 2.2 (AF_PACKET instead of AF_INET). - Changes for GNU libc 2 (glibc, a/k/a libc6). - Use autoconf and automake. aprsdigi-specific changes: - Bring aprsdigi WIDE flooding implementation into alignment with current WIDEn-n definition. - Add real control of how to interconnect (gate) multiple interfaces: - Tie each of my callsigns/aliases to an interface: replace -rxa switches with -p port1:alias,alias... -p port2:alias... - routing between interfaces now based on next-hop callsign. - one-to-many relationship supported by giving the same alias to multiple interfaces. Each interface with the matching next-hop alias will transmit, with per-interface customizations (e.g. MYCALL substitution is based on the callsign of the interface). - Make tag/idinterval, reformatting of Mic-E and X1J4, etc. selectable per-interface (rather than global) options. - Implement TRACE: Note that TRACEn-n vs. plain TRACE do different things: TRACEn-n *inserts* calls into the digipath while decrementing ssid. e.g.: RELAY*,TRACE3-3 RELAY,N2YGK-7*,TRACE3-2 RELAY,N2YGK-7,WB2ZII*,TRACE3-1 RELAY,N2YGK-7,WB2ZII,N2MH-15*,TRACE3 RELAY,N2YGK-7,WB2ZII,N2MH-15,WA2YSM-14* "Plain Old" TRACE just does a one-for-one mycall substitution. - Kill looping packets (-L option): RELAY*,WIDE,WIDE,WIDE RELAY,N2YGK-7*,WIDE,WIDE RELAY,N2YGK-7,WIDE*,WIDE ^---- normally n2ygk-7 would respond to this, but, by finding one of mycall earlier in the path, I know to ignore it. aprsdigi-3.10.0/INSTALL000066400000000000000000000021611254600523400144270ustar00rootroot00000000000000N2YGK's aprsdigi 2.4.3 installation instructions ---------------------------------------------- Alan Crosswell, n2ygk@weca.org PREREQUISITES: ------------- 1. You must have a Linux 2.4.x kernel with AX.25 and "Packet socket" configured (CONFIG_AX25 and CONFIG_PACKET) along with the applicable low-level AX.25 drivers (CONFIG_MKISS, CONFIG_BAYCOM*, CONFIG_SOUNDMODEM*, etc.) This release of my software has been tested with Linux 2.4 and GNU libc 2 (glibc) on a Red Hat 8.0 distribution. See the AX25-HOWTO for instructions: http://www.linuxdoc.org/HOWTO/AX25-HOWTO.html 2. You need libax25.a and the corresponding include files. These are part of the libax25-0.0.7 (or later) package. You also will need ax25-tools and you might as well get ax25-apps too. The AX25-HOWTO tells how to get and install these as well. INSTALLING FROM SOURCES: ----------------------- First make sure you have libax25 installed. Then untar and build aprsdigi: gunzip -c aprsdigi-2.4.3.tar.gz | tar xfz - cd aprsdigi-2.4.3 ./configure make make install CONFIGURING ----------- See the man page, aprsdigi.8. aprsdigi-3.10.0/Makefile.am000066400000000000000000000022331254600523400154320ustar00rootroot00000000000000# automake Makefile.am for Laprs (linux APRS(tm)) package # APRS is a registered trademark of Bob Bruninga, WB4APR SUFFIXES = .fig .html .8 .pdf noinst_LIBRARIES = libaprs.a sbin_PROGRAMS = aprsmon aprsdigi noinst_PROGRAMS = mic_e_test testparse testmcast fiforead fifowrite aprsmon_SOURCES = aprsmon.c aprsshm.c aprsshm.h LDADD = libaprs.a aprsdigi_SOURCES = aprsdigi.c mic_e_test_SOURCES = mic_e_test.c testparse_SOURCES = testparse.c testmcast_SOURCES = testmcast.c fiforead_SOURCES = fiforead.c fifowrite_SOURCES = fifowrite.c libaprs_a_SOURCES = mic_e.c mic_e.h libax25ext.c libax25ext.h man_MANS = aprsdigi.8 aprsmon.8 fiforead.8 fifowrite.8 HTMLS = aprsdigi.html aprsmon.html fiforead.html fifowrite.html noinst_SCRIPTS = $(HTMLS) aprsdigi.spec aprsdigi.init aprsdigi.service aprsbeacon.service aprsdigi.logrotate missing depcomp mkinstalldirs Vagrantfile bootstrap-aprsdev.sh DOCS = aprsdigi.lsm parse_cooked_ax25.pdf parse_cooked_ax25.fig examples/README.examples examples/aprsdigi.conf examples/axports examples/aprsdigi-fc17.ks BUILD.md README.md EXTRA_DIST= $(MANS) $(SCRIPTS) $(DOCS) .8.html: $(GROFF) -mandoc -Thtml $< >$@ .fig.pdf: fig2dev -L pdf $< $@ aprsdigi-3.10.0/NEWS000066400000000000000000000101511254600523400140730ustar00rootroot00000000000000Announcing N2YGK's Linux aprsdigi-3.10.0. June 20, 2015 Release 3.10.0 of N2YGK's advanced APRS digipeater is now available for free under the terms of the GNU Public License (GPL) at https://github.com/n2ygk/aprsdigi. This release has no new features in the base code from aprsdigi-2.4.5 as the APRS protocol and aprsdigi code have been stable and operating in production on a number of digipeaters for many years. However, a number of bug fixes, and packaging updates have happened: Changed in 3.10.0: - As usual, the version number has been updated to match the Linux kernel release that Aprsdigi has been built and tested against. - Sourcecode management has has been switched from CVS to git and the primary hosting repo changed from sourceforge.net to github.com. - bugfix of a longstanding typo, thanks to dcb https://github.com/n2ygk/aprsdigi/commit/722bddfd286aeaa18b905637569c38e191b0af46 - added lintian and typo corrections from Debian Ham Radio Maintainers https://github.com/n2ygk/aprsdigi/commit/53db4ad43ba4374f8c6a9db1c385fdd00b66b344 - now builds cleanly without compiler warnings Added in 3.5.1: - As usual, the version number has been updated to match the Linux kernel release that Aprsdigi has been built and tested against. (The code actually hasn't had to change since kernel 2.4 when ax25 stuff stopped changing.) - Minor source code changes for netax25 include files no longer required. - Updated the RPM SPEC file to build aprsdigi for use on Fedora Core 17 or similar systems. - Replaced SysV init script (/etc/init.d/aprsdigi) with systemd unit files. - Added some example configuration files and description of how I build APRS digipeaters in ./examples - Documentation here of 2.4.5 changes that weren't documented at the time (shame on me): Added in 2.4.5: - Updated the man page for the "--long" command line options. - Fixes SIGUSR1 only working once (bug 916083 reported by KE2LJ) - Updates to the TODO list Added in 2.4.4: - Aprsdigi is now a sourceforge.net project. Please visit aprsdigi.sf.net and sign up to be a developer or join the users or developers mailing lists. - Short (-s) command line options replaced with long ones (--long). Short options are now deprecated and may disappear in a future release. - Ability to specify a list of ports that get sent a verbatim duplicate copy of all packets received on a given port. Useful for "reflecting" what's heard on an RF port to a local LAN for instance. This is different from APRS-IS (e.g. aprsd) since the data is sent with UDP (multicast or unicast). Use with caution (or not at all) on RF ports. Added in 2.4.3: - UDP/IP (v4 and v6) unicast and multicast (ASM) support. Useful for connecting aprsdigi's over the Internet, WLANs, etc. (Note: this is *not* TCP support as used by APRS-IS, aprsd, etc.) Both transparent and "3rd party" tunneling are supported. - Budlist to permit/deny digipeating of traffic for individuals or groups of AX.25 and IP sources. IP budlists are helpful when using IP multicast! - Interfaces may be set to transmit- or receive-only. - Interfaces may be set to disable retransmission of received packets on the same interface (one-armed routing). - Unix FIFO supported as an interface type. Mostly useful for debugging. - Bug fixed that caused aprsdigi to crash upon TRACEn-n callsign insertion when the digipeater list was full. Along with these features: - Digipeater callsign substitution (e.g. RELAY replaced w/N0CLU-12). - WIDE, WIDEn-n, TRACE, and TRACEn-n. - As many radio interfaces as you can plug into your Linux machine with flexible gatewaying between them. - Special handling for Mic-Encoder, Kenwood TH-D7, and TheNet X1J4, including SSID-based digipeating. - Suppression of duplicate and looping packets. - Works with Linux 2.4 kernel AX.25 network stack. This means any AX.25 interface supported by the kernel will work, not just a TNC2 clone. Examples include all the BAYCOM interfaces (BAYPAC, PICPAR, PICSER, etc.), soundcards, 8530 SCC cards, any serial port KISS TNC, etc. Aprsdigi is Copyright (c) 1996,1997,1999,2001,2002,2003,2004,2009,2012,2015 Alan Crosswell, n2ygk@weca.org aprsdigi-3.10.0/README000066400000000000000000000000161254600523400142530ustar00rootroot00000000000000see README.md aprsdigi-3.10.0/README.md000066400000000000000000000056411254600523400146630ustar00rootroot00000000000000# Linux aprsdigi and aprsmon Copyright (c) 1996,1997,1998,1999,2001,2002,2003,2004,2009,2012,2014 Alan Crosswell Released under the GNU Public License. See the file COPYING for details. Alan Crosswell, N2YGK n2ygk@weca.org ## Description *Aprsdigi* is a specialized Amateur Packet Radio (AX.25) UI-frame digipeater for the Automatic Position Reporting Systems, APRS(tm). It uses the Linux kernel AX.25 network stack as well as the SOCK_PACKET facility to listen for packets on one or more radio interfaces (ports) and repeat those packets -- with several possible modifications -- on the same or other interfaces. Aprsdigi can also use the Internet to tunnel connections among other APRS digipeaters and nodes using IPv4 or IPv6 UDP unicast or multicast. *Aprsdigi* implements conventional packet radio AX.25 digipeating, in which a packet is digipeated if the next hop (non-repeated) digipeater ("via") callsign matches the AX.25 port's callsign and sub-station ID (SSID) or an alias callsign and SSID. There are a number of extensions to conventional digipeating that have been proposed for use in the APRS community. Some of these features have been adopted by Terminal Node Controller (TNC) manufacturers, notably Paccomm and Kantronics. Aprsdigi implements most if not all of the commercialy adopted and proposed features. See the APRS 1.0 Protocol Specification at www.tapr.org for protocol documentation. Aprsdigi attempts to minimally comply with the protocol specification as well as support experimental APRS features. Specific features implemented include: - Single-interface conventional UI-frame digipeating. - Cross-interface digipeating (also known as bridging, routing or gatewaying) and one-to-many fanout. - Substitution of a digipeated alias with the interface's callsign (typically used to substitute RELAY, WIDE or TRACE aliases). - WIDEn-n flooding algorithim. - TRACEn-n route recording. - Mic-Encoder(tm) support, including SSID-based digipeating, decompression of packets into the conventional APRS MIM format. (The Mic-Encoder compression is also used by other products such as the Kenwood TH-D7A and D700, and TAPR PIC-Encoder). - TheNet X1J4 node beacon text translation (removal of the lqTheNet X1J4 (alias)rq prefix from the btext). ## Where to find aprsdigi The official place where new versions are found is: https://github.com/n2ygk/aprsdigi Others may mirror this stuff elsewhere, but I only promise that the latest will be at the above site. ## More information If you are not a member of Tucson Amateur Packet Radio (TAPR), consider joining! See www.tapr.org See the aprsdigi.8 and aprsmon.1 man pages. Aprsdigi is an intelligent digipeater (see the APRS Protocol Reference, ISBN 0-9644707-6-4, at http://www.tapr.org). Aprsmon is deprecated in favor of Dale Heatherington's aprsd, http://sourceforge.net/projects/aprsd/. See the file INSTALL for installation instructions. See the file NEWS for latest news. aprsdigi-3.10.0/TODO000066400000000000000000000062621254600523400140740ustar00rootroot00000000000000revised 8/6/2012 aprsdigi: - try to get added to https://fedoraproject.org/wiki/AmateurRadio - Figure out how to get the most current packaged added to Debian, Ubuntu, etc. distros. - stuff based on my understanding of fix14439.html and WB4APR's future digi wish list (1 Dec 2004; revised 6 May 2005): - [wishlist 1] Add "--subst_first" to replace the first flooding callsign with mycall. - [wishlist 2] Done: multiple "--trace" has been there for a long time. - [wishlist 3] Add "--max_hops N" to restrict flooding calls to a maximum number of hopes (subtract N-n from WIDEn-N). - [wishlist 4] Done: "--kill_dupes" kills all dupes not just those with flood/trace aliases. - [wishlist 5] Ooops, there is no item 5:-) - [wishlist 6] (bi-directional) routing among several transmitters is supported by having multiple "--interface" but rig control to switch frequencies is not. IMHO a busy digi does better to be monitoring each radio fulltime rather than going off-frequency. [6d] (routing all traffic to an alternate channel) is handled by "--dupe". - [fix14439] add "--subst_last" to substitute my call when I am the last digi in the WIDEn-N path (e.g. N counts down to zero or exceeds "--max_hops"). - add rate-limiting for lids. For example, a fixed station transmitting it's position every 30 seconds would have all transmissions ignored for say 15 minutes at which point the next beacon would be digipeated. If the station is moving (info is changing) then don't rate-limit since there's useful new information being transmitted. - add stats collection ala MHEARD - add query responder for MHEARD, etc. - add remote sysop via RF ala the way X1J4 does it with one time passwords or something. - document how to use aprsd UDP port support or whether it makes sense to do so vs. just running aprsd in parallel. - suppress loops/dupes per-interface??? Currently done globally. - make log file list rx/tx port and timestamp? - add "tcp:" interface types (both initiator/client and responder/server). netcat ./nc -v -u -p 14439 -l | ./nc -v -l -p 14439 localhost - make aprs-is compatible (see aprsd/doc/q.html) or just use aprsd? - add file: and/or tty: intf type to support non-KISS-capable TNCs and broken KISS implentations like TH-D7A (this is getting gross). - support more than 8 digipeaters in cooked mode? - digipeat other than UI frames (digi_ned && requested for opentrac pid 99) - Combine unproto() and parsecalls(). - Figure out why I can't just use standard full_sockaddr instead of struct ax_calls. - assure 100% alignment with APRS Protocol Spec 1.0 - If and when there's an official updated protocol spec align to that too. - add a real config file instead of hokey command line switches. - add IPv6 multicast, IPv4 SSM? - Implement HOME: (or did this idea die out?) - Implement compressed and/or decompressed GPS strings and posits. - Make a new distro rpm and tarball. mic_e.c: [deprecated - use aprsd] - looked at Dale's changes but they *broke* parsing of D7, mic_e pkts??? - Add PIC-E support: /P>mon - Is this necessary anymore given aprsd? aprsdigi-3.10.0/Vagrantfile000066400000000000000000000056401254600523400155700ustar00rootroot00000000000000# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure(2) do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. config.vm.box = "centos71-puppetlatest-1.0.17" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. # config.vm.synced_folder "../data", "/vagrant_data" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # # View the documentation for the provider you are using for more # information on available options. # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies # such as FTP and Heroku are also available. See the documentation at # https://docs.vagrantup.com/v2/push/atlas.html for more information. # config.push.define "atlas" do |push| # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" # end # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. config.vm.provision "shell", path: "bootstrap-aprsdev.sh" end aprsdigi-3.10.0/aprsbeacon.service000066400000000000000000000004661254600523400171030ustar00rootroot00000000000000[Unit] Description=APRS digipeater beacon (invokes ax25-tools beacon) Wants=aprsdigi.service After=soundmodem.service [Service] EnvironmentFile=/etc/ax25/aprsdigi.conf ExecStart=/usr/sbin/beacon -d "${BEACON_DEST}" ${BEACON_PORT} "${BEACON_TEXT}" StopWhenUnneeded=true [Install] WantedBy=aprsdigi.service aprsdigi-3.10.0/aprsdigi.8000066400000000000000000000470511254600523400153000ustar00rootroot00000000000000.TH APRSDIGI 8 "25 February 2004" .SH NAME aprsdigi \- APRS(\*(Tm) digipeater .SH SYNOPSIS .nf .BI "aprsdigi " options .fi .SH DESCRIPTION .PP .I Aprsdigi is a specialized Amateur Packet Radio (AX.25) UI-frame digipeater for the Automatic Position Reporting Systems, APRS(tm). It uses the Linux kernel AX.25 network stack as well as the SOCK_PACKET facility to listen for packets on one or more radio interfaces (ports) and repeat those packets -- with several possible modifications -- on the same or other interfaces. .I Aprsdigi can also use the Internet to tunnel connections among other APRS digipeaters and nodes using IPv4 or IPv6 UDP unicast or multicast. .PP .I Aprsdigi implements conventional packet radio AX.25 digipeating, in which a packet is digipeated if the next hop (non-repeated) digipeater ("via") callsign matches the AX.25 port's callsign and sub-station ID (SSID) or an .I alias callsign and SSID. .PP There are a number of extensions to conventional digipeating that have been proposed for use in the APRS community. Some of these features have been adopted by Terminal Node Controller (TNC) manufacturers, notably Paccomm and Kantronics. .I Aprsdigi implements most if not all of the commercialy adopted and proposed features. See the APRS 1.0 Protocol Specification at www.tapr.org for protocol documentation. .I Aprsdigi attempts to minimally comply with the protocol specification as well as support experimental APRS features. Specific features implemented include: .PP .IP \(bu 2 Single-interface conventional UI-frame digipeating. .IP \(bu 2 Cross-interface digipeating (also known as bridging, routing or gatewaying) and one-to-many fanout. .IP \(bu 2 Substitution of a digipeated alias with the interface's callsign (typically used to substitute .BI RELAY, .BI WIDE or .BI TRACE aliases). .IP \(bu 2 .BI "WIDEn-n" flooding algorithim. .IP \(bu 2 .BI "TRACEn-n" route recording. .IP \(bu 2 .I Mic-Encoder(tm) support, including SSID-based digipeating, decompression of packets into the conventional APRS MIM format. (The Mic-Encoder compression is also used by other products such as the Kenwood TH-D7A and D700, and TAPR PIC-Encoder). .IP \(bu 2 TheNet X1J4 node beacon text translation (removal of the \(lqTheNet X1J4 (alias)\(rq prefix from the btext). .PP .SH "GENERAL OPTIONS" .TP 10 .BI "\-v \--verbose" Produce verbose debugging output. .TP 10 .BI "\-T \--testing" Test mode: listen to my packets too. This mode is useful for off-air experimentation and configuration testing. Do not use it on-air. .TP 10 .BI "\-D \--kill_dupes" Suppress Duplicate packets. Remembers duplicate packets for the number of seconds given by the \-k option and will not repeat them more than once. This reduces conjestion caused when several digipeaters that share a common flooding alias (e.g. WIDE) have overlapping footprints, causing geometric duplication of packets addressed via \(lqWIDE,WIDE\(rq for example. .TP 10 .BI "\-L \--kill_loops" Suppress Looping packets. Similar in function to duplicate packet suppression, but looks back through the list of already digipeated callsigns in the packet's digipeat list and kills any packets that list a callsign belonging to this .I aprsdigi. Note that only real callsigns are compared. Generic flooding aliases are not. Therefore, loop detection is only useful when callsign substitution is used. .TP 10 .BI "\-V \--version" Print program version and exit. .TP 10 .BI "\-n|s|e|w \--north|south|east|west" Set North|South|East|West SSID directional path. .TP 10 .BI "\-d \--digipath" Set SSID omnidirectional next-hops when operating in a non flooding network (e.g. when WIDEn-n is not an option). .TP 10 .BI "\-f \--flood" Set flooding alias. Use \(lq-f WIDE\(rq to enable WIDEn-n flooding. Use \-f multiple times to define several flooding aliases. .TP 10 .BI "\-F \--trace" Set flooding trace callsign. Use \(lq-F TRACE\(rq to enable TRACE and TRACEn-n flooding. Use \-F multiple times to define several trace aliases. .TP 10 .BI "\-k \--keep secs" Remember old packets for this long for duplicate packet detection. Default is 28 seconds. .TP 10 .BI "\-l \--logfile file" Log digipeated packets to this file. .SH "PER-INTERFACE OPTIONS" Put these options .I before each .BI "\-p \--interface" to set new values as needed. The values you set are remembered for subsequent .BI "\-p's" so options you want to set for all interfaces need only be specified once, before the first .BI "\-p." But you have to remember to unset an option if you don't want it to apply to subsequent interfaces. .TP 10 .BI "\-C (-c) \--[no]subst_mycall" Do (not) perform callsign substitution. When enabled, aliases are replaced with the interface's callsign when repeated. .TP 10 .BI "\-M (-m) \--[no]mice_xlate" Do (not) perform Mic-E to MIM translation. When enabled, compressed Mic-E reports are expanded into one MIM-style position report packet and optionally a second telemetry packet if telemetry was supplied in the Mic-E packet. .TP 10 .BI "\-X (-x) \--[no]x1j4_xlate" Do (not) perform X1J4 translation. When enabled, the leading \(lqTheNet X1J4 (alias)\(rq text is removed when digipeated. This allows non-compliant APRS implementations to detect an APRS position report in an X1J4 beacon. .TP 10 .BI "\-i \--idinterval secs" Seconds between ID transmissions. Set to 0 to disable IDs on this interface. Default is 570 (9 minutes 30 seconds). IDs are only sent if the interface transmitted anything since the last ID. ID packets are addressed to the \(lqID\(rq callsign, have no digipeat path, and list the callsign and aliases for the interface the ID is being transmitted on. .TP 10 .BI "\-t \--tag text" Text to append to received packets. Use .I "\-t -" to reset to empty. Use this, for example, when gatewaying Mic-E packets from a voice repeater to the APRS net frequency to indicate where the report originated. .TP 10 .B "\-3 \--3rdparty" Enable 3rd party tunneling. Packets tunneled .I to a 3rd party interface are sent with the unused digipeaters removed from the digipeater list. Packets tunneled .I from a 3rd party interface have the Source Path Header prepended to the packet payload prefixed by the "}" character. .TP 10 .B "\-0 \--no3rdparty" Enable transparent tunneling. No special tricks are done when sending to or receiving from a tunneled interface. If the interface does not natively support AX.25 addresses (from-call, to-call, and digipeater list), then the address header is prepended to the payload in "cooked" format. Likewise, a cooked prepended header is stripped from a cooked interface and put back in the AX.25 address when going from a non-AX.25 to AX.25 interface. .TP 10 .BI "\-o r \--norx" Disable receiving on the following interface(s). .TP 10 .BI "\-o R \--rx" Enable receiving on the following interface(s). .TP 10 .BI "\-o t \--notx" Disable transmitting on the following interface(s). .TP 10 .BI "\-o T \--tx" Enable transmitting on the following interface(s). .TP 10 .BI "\-o s \--notxsame" Disable retransmitting a received packet on the same interface. .TP 10 .BI "\-o S \--txsame" Enable retransmitting a received packet on the same interface. .TP 10 .BI "\-o d \--duplicate intf" Duplicate received packets without modification to the given interface (port). .TP 10 .BI "-p \--interface ax25:port:alias1,alias2,..." AX25 interface name (port) and optional list of aliases. The primary callsign is obtained from the interface's configuration. (See ifconfig(8)). .TP 10 .BI "-p \--interface udp:host/port/ttl:alias1,alias2,..." IP host name or address and list of aliases. IP addresses may be IPv4 unicast or multicast or IPv6 unicast. The primary callsign is obtained from the first alias. .TP 10 .BI "-p \--interface unix:filename:alias1,alias2,..." Unix file and list of aliases. Useful for debugging by setting up a simulated APRS network on one machine. You may want to make your FIFOs explicitly transmit- or receive-only to avoid confusion. The primary callsign is obtained from the first alias. .TP 10 .BI "\-B|b \--[no]bud" .I addr Is similar to a TNC-2's BUDLIST. Use .BI "\-B \--bud" to accept or .BI "\-b \--nobud" to ignore packets from a sender or group of senders. Budlists are attached to each interface and can be reset with .BI "\--bud \-" .br You can set up a global budlist once, or per-interface budlists. The format of .I addr varies based on the interface type: .HP .BI "\--bud ax25:callsign-ssid" matches only a given digipeater callsign and SSID. For example, \-B ax25:n0clu-14. .HP .BI "\--bud ax25:callsign" matches all SSIDs for the given callsign. For example \-B ax25:n0clu. .HP .BI "\--bud ip:hostname" matches one Internet host name (IPv6 or IPv4). For example \-B ip:n0clu.ampr.net .HP .BI "\--bud ip:address/maskbits" matches all IP addresses that have the given prefix. For example \--bud ip:44.0.0.0/8 matches the entire class-A network. \--bud ip:192.168.0.0/16 matches the entire class-B network. \--bud ip:fe80::201:3ff:fe9a:38c6 matches a single IPv6 host. \--bud ip:2002:905::/32 matches the 32-bit IPv6 prefix. .PP .SH "RUNTIME CONTROLS" .PP .I aprsdigi responds to the following signals: .TP 10 .B "SIGUSR1" Print cumulative statistics. For each port, the following counters are displayed: packets received and how many of those where ignored, duplicates, loops, mic-E formatted; packets transmitted and how many of those where conventional digipeats, flooding digipeats (WIDEn-n), SSID-based digipeats, and IDs. If a log file was specified with the .B "\-l \--logfile" option, then the statistics are written to that file. Otherwise they are written to stderr. .TP 10 .B "SIGUSR2" Prints the statistics and then resets all counters to zero. .PP All other normal termination signals cause final statistics to print before .I aprsdigi exits. .SH "SSID-BASED ROUTING" .PP SSID-based routing uses a non-zero sub-station ID in the destination callsign, an empty digipeater path to indicate that the APRS digipeater should repeat the packet after filling in an appropriate digipeater path. For example, a packet sent to \(lqT1QS4W-3\(rq would be repeated with a modifed destination of \(lqAPRS VIA WIDE3-3\(rq (in a network that supports WIDEn-n flooding). A packet sent to \(lqAPRS-11\(rq would be repeated to the West unproto path, as defined with the .B \--west option. A table of SSID values and their paths follows: .sp .nf SSID unproto path ---- ------------ 0 none 1 WIDE1-1 2 WIDE2-2 3 WIDE3-3 4 WIDE4-4 5 WIDE5-5 6 WIDE6-6 7 WIDE7-7 8 NORTH UNPROTO path 9 SOUTH UNPROTO path 10 EAST UNPROTO path 11 WEST UNPROTO path 12 NORTH UNPROTO path + WIDE 13 SOUTH UNPROTO path + WIDE 14 EAST UNPROTO path + WIDE 15 WEST UNPROTO path + WIDE .fi .sp SSID digipeating was first introduced with the Mic-Encoder but works with any destination callsign with a non-zero SSID. The theory behind destination SSID digipeating is described in more detail in the APRSdos README, MIC-E.TXT. Basically, the idea is to minimize packet lengths and to have the manager of the WIDE APRS digipeater determine the most appropriate directional digipeat paths, removing the burden from the mobile user. .PP .I Aprsdigi also fits into a non WIDEn-n network by using the same algorithm for selection of subset of digipeaters from a list supplied with the .B \--digipath option as the MIC-E. That is, SSIDs of 1, 2 or 3 select that number of digipeaters from the first three digipeaters in the .B \--digipath list. SSIDs of 4, 5, 6, or 7, start at the fourth digipeater in the list. .PP .SH "FLOODING ALIASES" APRS flooding (WIDEn-n) digipeating works by repeating any received packet whose next hop digipeater has a flooding alias (specified with the .B \--flood option), and the SSID is 1 or greater. The SSID is decremented by one, and the packet is repeated. Furthermore, to prevent broadcast storms, recently transmitted packets are remembered for a period of time specified by the .B \--keep option and are not repeated if they are heard within that time period. .PP Unlike conventional digipeating, in which the digipeater callsign/alias is flagged as \(lqrepeated\(rq, the flooding mode does not do this. Once the SSID decrements to zero, then a flooding alias is treated just like any other alias, and does get marked as repeated upon transmission. .PP .SH "TRACE and TRACEn-n ALIASES" \(lqFlooding\(rq Trace aliases (TRACEn-n; .B \--trace option) are treated like flooding aliases with the addition that, besides decrementing the SSID, the current interface's callsign is inserted in front of the trace alias, providing a record-route function. \(lqPlain\(rq trace aliases (TRACE; also .B \--trace option) are simply substituted in the conventional ( .B \--subst_mycall ) manner. .PP .SH "MULTI PORT OPERATION" In single port operation, there is only one interface specified with .BI "\--interface." All packets are received and some are retransmitted on the same interface, depending on whether they match the criteria for retransmission after translation of the digpeater path from one of the APRS-specific formats: .IP \(bu 2 Mic-E TO-call SSID-based route. .IP \(bu 2 WIDEn-n/TRACEn-n flooding. .PP or a conventional next-hop (non-repeated) digipeater matching the callsign or one of the aliases for the interface. .PP The decision to transmit is made by matching the next hop callsign/alias with the table of callsigns and aliases you supply to .BI "\--interface." .PP In multi-port operation, this same technique simply extends to several interfaces. Besides each interface's unique callsign, you can give the same alias to several interfaces. This results in a one-to-many fanout which might be useful for dual frequency operation such as a general use APRS net frequency and an event-specific frequency. .PP By using different flags for Mic-E expansions, etc. you can tailor these fanouts differently on each of these interfaces, perhaps keeping Mic-E packets compressed on one frequency while decompressing them on another. .SH DUPLICATING PACKETS The .B "\--dupe intf" option will duplicate a packet received on one interface to the interface name given. If you want to duplicate to several other interface, repeat .B "\--dupe intf" for each interface. The packet is duplicated verbatim as received. No callsign substitution, flooding or other processing or checking such as whether the packet still has any non-repeated digipeaters in the list is checked. This feature is meant to provide a means to simply repeat received packets verbatim, on an RF interface, for example, out an interface that might be an Ethernet, that has APRS client applications running on it (or .I aprsd listening on a UDP interface). Digipeating without the normal processing can be dangerous since the digipeater list is never used up. Because of this, packets received on a given interface will never be blindly duplicated back to the same interface, regardless of the option setting. .PP .SH TRACE vs. TRACEN-N .PP Note that TRACEn-n vs. plain TRACE do different things: TRACEn-n *inserts* calls into the digipath while decrementing ssid, e.g.: .nf RELAY*,TRACE3-3 RELAY,N2YGK-7*,TRACE3-2 RELAY,N2YGK-7,WB2ZII*,TRACE3-1 RELAY,N2YGK-7,WB2ZII,N2MH-15*,TRACE3 RELAY,N2YGK-7,WB2ZII,N2MH-15,WA2YSM-14* .fi .PP .SH KILLING LOOPING PACKETS .PP Kill looping packets (\--kill_loops option): .nf RELAY*,WIDE,WIDE,WIDE RELAY,N2YGK-7*,WIDE,WIDE RELAY,N2YGK-7,WIDE*,WIDE .fi Normally n2ygk-7 would respond to this, but, by finding one of mycall earlier in the path, I know to ignore it. .PP .SH EXAMPLES .PP Following is a sample invocation of .I aprsdigi running on two ports. This is a contrived example that tries to show all the features. Comments to the right describe each feature. .nf aprsdigi \\ \-\-verbose \\ # verbose \-\-north "N2YGK-2 WB2ZII WA2YSM-14" \\ # North digi path \-\-south "N2YGK-3 WB2ZII WA2JNF-4" \\ # South ... \-\-east "N2YGK-3 WB2ZII KD1LY" \\ # East ... \-\-west "N2YGK-2 WB2ZII N2MH-15" \\ # West ... \-\-flood "WIDE" \\ # WIDEn-n flooding \-\-trace "TRACE" \\ # TRACEn-n tracing \-\-kill_dupes \\ # kill dupes \-\-kill_loops \\ # kill loops \-\-mice_xlate \\ # do Mic-E translation \-\-subst_mycall \\ # do callsign substituton \-\-tag " via 147.06 (WB2ZII/R)" \\ # add this tag to rec'd pkts \-\-nobud "ax25:NOCALL" \\ # ignore pkts from NOCALL \-\-dupe udp:233.0.14.100 \\ # dupe everything heard \-\-int ax25:sm0:RELAY,WIDE,TRACE \\ # ax25 soundmodem intf \-\-nomice_xlate \\ # turn off Mic-E translation \-\-x1j4_xlate \\ # do X1J4 translation \-\-nosubst_mycall \\ # turn off callsign subst. \-\-tag - \\ # clear the tag \-\-int ax25:ax0:RELAY,WIDE,FOO,TRACE \\ # ax25 ax0 intf. \-\-bud - \\ # clear the budlist \-\-bud ip:128.59.39.150/32 \\ # allow only from this IP host \-\-int udp:233.0.14.99/12345/16:N2YGK-4,RELAY,WIDE,TRACE \\ # multicast \-\-int udp:233.0.14.100/12345/16:N2YGK-5 # to this mcast group opening UDP socket on 233.0.14.99/12345/16 UDP address info: family 2 type 2 proto 17 next 0x0 Linux APRS(tm) digipeater Copyright (c) 1996,1997,1999,2001,2002,2003 Alan Crosswell, n2ygk@weca.org Version: aprsdigi aprsdigi-2.4.3 This is free software covered under the GNU General Public License. There is no warranty. See the file COPYING for details. # configuration: budlist 1 deny NOCALL/48 budlist 2 permit 128.59.39.150/32 interface ax25:sm0 callsign N2YGK-2 alias RELAY alias WIDE alias TRACE option SUBST_MYCALL on option MICE_XLATE on option X1J4_XLATE off option I_TX on option I_RX on option I_TXSAME on option idinterval 570 #(09:30) option tag via 147.06 (WB2ZII/R) budlist 1 interface ax25:ax0 callsign N2YGK-3 alias RELAY alias WIDE alias FOO option SUBST_MYCALL off option MICE_XLATE off option X1J4_XLATE on option I_TX on option I_RX on option I_TXSAME on option idinterval 570 #(09:30) option tag #(none) budlist 2 interface udp:233.0.14.99 callsign N2YGK-4 alias RELAY alias WIDE alias FOO option SUBST_MYCALL off option MICE_XLATE off option X1J4_XLATE on option I_TX on option I_RX on option I_TXSAME off option idinterval 570 #(09:30) option tag #(none) budlist 2 # end of configuration My callsigns and aliases (routing table): Callsign Interfaces... N2YGK-2 sm0 RELAY sm0 ax0 233.0.14.99 WIDEn-n sm0 ax0 233.0.14.99 TRACEn-n sm0 N2YGK-3 ax0 FOO ax0 233.0.14.99 N2YGK-4 233.0.14.99 SSID-based directional routing: N: N2YGK-2 WB2ZII WA2YSM-14 S: N2YGK-3 WB2ZII WA2JNF-4 E: N2YGK-3 WB2ZII KD1LY W: N2YGK-2 WB2ZII N2MH-15 keep dupes for: 28 seconds log file: (none) kill dupes: ON loops: ON testing: OFF .fi .SH BUGS .I Aprsdigi should not be confused with a Wes Johnson's DOS program of the same name. This code has most recently been tested with the Linux 2.4.20 kernel under Red Hat Fedora Core 1. The command line syntax is ugly and will eventually be replaced by a configuration file. Short options are deprecated and will dissappear in a future release. Please use long options. .PP .SH FILES .BR /etc/ax25/axports .SH "SEE ALSO" .BR call (1), .BR listen (1), .BR beacon (1), .BR ax25 (4), .BR kissattach (8), .BR ifconfig (8), .BR aprsmon (1), .BR http://www.tapr.org .SH AUTHORS .nf Alan Crosswell, n2ygk@weca.org .br APRS and the Mic-Encoder are Trademarks of APRS Engineering LLC. .fi aprsdigi-3.10.0/aprsdigi.c000066400000000000000000002403041254600523400153470ustar00rootroot00000000000000/* aprsdigi: APRS-style UI frame digipeater and node. * * APRS has some peculiar digipeating ideas, so let's test them here: * * 1. Several digipeater aliases such as RELAY, WIDE, GATE. * 2. WIDEn-n flooding algorithm. * 3. SSID-based shorthand for digi path. * * See Bob Bruninga's (WB4APR) README/MIC-E.TXT for a description of * methods 2 and 3. #1 is conventional TNC digipeating with MYAlias, etc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * (See the file "COPYING" that is included with this source distribution.) * * portions derived from ax25-utils/listen.c * */ static char copyr[] = "Copyright (c) 1996,1997,1999,2001,2002,2003,2004,2009,2012 Alan Crosswell, n2ygk@weca.org"; /* * Alan Crosswell, N2YGK * 144 Washburn Road * Briarcliff Manor, NY 10510, USA * n2ygk@weca.org * * TODO: * see ./TODO */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef AX25_MTU #define AX25_MTU 256 #endif #include #include "mic_e.h" #include "libax25ext.h" #include "netax25/axconfig.h" #ifndef PACKAGE #define PACKAGE "aprsdigi" #endif #ifndef VERSION #define VERSION "$Revision$"; #endif /* some defines that really belong in a header file! */ #define ALEN 6 /* index to where the SSID and flags go */ #define AXLEN 7 /* length of a callsign */ /* SSID mask and various flags that are stuffed into the SSID byte */ #define SSID 0x1E #define HDLCAEB 0x01 #define REPEATED 0x80 #define UI 0x03 /* unnumbered information (unproto) */ #define PID_NO_L3 0xF0 /* no level-3 (text) */ #define C 0x80 #define SSSID_SPARE 0x40 /* must be set if not used */ #define ESSID_SPARE 0x20 struct statistics { /* counters */ int rx; /* packets received */ int rx_ign; /* rx packets ignored */ int rx_dup; /* dupe packets killed */ int rx_loop; /* looping packets killed */ int rx_mic; /* mic_e packets received */ int rx_ssid; /* dest SSID packets received */ int tx; /* packets transmitted, sum of: */ int digi; /* regular digipeats */ int flood; /* flood-N digipeats */ int ssid; /* dest SSID digipeats */ int ids; /* id packets */ }; /* the per-interface information */ #define MAXALIASES 5 #define MAXINTF 10 struct budlist_entry { /* budlist entry */ struct budlist_entry *be_next; int be_permit; /* permit/deny */ struct sockaddr_storage be_addr, be_mask; int be_maskbits; }; struct budlist { /* a given budlist */ struct budlist *bl_next; int bl_list_no; /* list number */ struct budlist_entry *bl_ent_head, *bl_ent_last; }; static struct budlist *Bl_head = NULL, *Bl_last = NULL; struct dupelist_entry { /* dupelist entry */ struct dupelist_entry *de_next; char *de_dev; /* interface device name to dupe to */ }; struct dupelist { /* a given dupelist */ struct dupelist *dl_next; int dl_list_no; /* list number */ struct interface_list *dl_il; /* list of interfaces to dupe to */ struct dupelist_entry *dl_ent_head, *dl_ent_last; }; static struct dupelist *Dl_head = NULL, *Dl_last=NULL; static struct interface { char *port; /* axports port name */ char *dev; /* kernel device name */ char *devname; /* user-friendly device name */ char *tag; /* optional tag text */ int taglen; int idinterval; /* seconds between IDs; 0 for none. */ int i_flags; /* status flags */ enum { P_UDP=1, /* interface is UDP socket */ P_AX25=2, /* interface is AX25 socket */ P_UNIX=3, /* interface is a unix file */ } i_proto; ax25_address aliases[MAXALIASES]; /* intf call & aliases */ int n_aliases; int rsock,tsock; /* socket fds */ #ifdef IPV6 struct sockaddr_storage rsa,tsa,rsafrom; /* and their sockaddrs */ #else struct sockaddr rsa,tsa,rsafrom; /* and their sockaddrs */ #endif /*IPV6*/ int rsa_size,tsa_size; /* sendto() bug w/sizeof(sockaddr_storage)? */ time_t next_id; /* next time we ID */ u_char idbuf[AX25_MTU]; /* An ID packet for this intf */ int idlen; struct statistics stats; /* statistics */ struct budlist *bud; /* budlist */ struct dupelist *dupe; /* list of interfaces to dupe to */ } Intf[MAXINTF]; #define MYCALL(n) Intf[n].aliases[0] #define I_MYCALL(i) i->aliases[0] static int N_intf = 0; struct interface_list { /* a list of interfaces (duh) */ struct interface_list *next; struct interface *i; }; struct stuff { /* maybe I should learn C++... */ u_char *cp; /* pointer into the packet */ int len; /* length of it */ struct ax_calls in; /* the received packet's calls, flags, etc. */ struct ax_calls out; /* the transmitted packet's calls, etc. */ struct interface *i; /* the interface received on */ }; /* some global stuff */ /* General options: */ static int Verbose = 0; static int Testing = 0; static int Digi_SSID = 0; static int Kill_dupes = 0; /* kill dupes even in conventional mode */ static int Kill_loops = 0; /* kill loops */ static int Doing_dupes = 0; /* dupelist was set on some interface */ static char *Logfile = NULL; static ax25_address Aprscall; /* replace mic-e encoded to-call with this */ static ax25_address Trace_dummy; /* dummy call for tracen-n substitution */ static ax25_address Widecall; /* dummy call for WIDEn-n substitution */ static ax25_address Udpipcall; /* dummy call for UDPIP 3rd party */ static int Have_digipath = 0; #define DIGISIZE 7 /* one more than usual! */ static ax25_address Digipath[DIGISIZE]; /* for SSID-[1:7] w/o flooding */ static struct full_sockaddr_ax25 Path[4]; /* for SSID-[8:15] N S E W */ static char Dirs[5] = "NSEW"; /* per-interface default options: */ static char *Tag = NULL; /* tag onto end of rx'd posit */ static int Taglen = 0; static int Idinterval = (9*60)+30; /* default to 9:30 */ static int Keep = 28; /* seconds to remember for dupe test */ static int I_flags = 0; /* interface default flags */ #define I_NEED_ID 0x01 /* need to ID */ #define SUBST_MYCALL 0x02 /* replace digi alias w/mycall */ #define MICE_XLATE 0x04 /* translate mic-e to tracker format */ #define X1J4_XLATE 0x08 /* translate x1j4 to plain format */ #define I_COOKED 0x20 /* interface is cooked */ #define I_RX 0x40 /* interface is enabled to receive */ #define I_TX 0x80 /* interface is enabled to transmit */ #define I_TXSAME 0x0100 /* enable re-TX on received interface */ #define I_3RDP 0x0200 /* enable 3rd party tunneling */ /* * A table of recognized flooding alias prefixes. In current practice, * the only recognized flood aliases are WIDEn and TRACEn(where n is 0-7) * where the latter has truly odd behavior. The flavors of WIDE and TRACE * are: * 1. WIDE: A conventional alias, eligible for MYCALL substitution. * Roughly equivalent to WIDE0-0. * 2. WIDEn-n: Flooding algorithm. Decrement SSID and repeat the packet * without setting the DIGIPEATED flag until it reaches zero at which * point do set the DIGIPEATED flag and move on to the next callsign * in the digipeat list. Does not get MYCALL substituted (even WIDEn-0) * so the user can see that the packet came in via n (anonymous) WIDE * digis. * 3. TRACE: Like WIDE but MYCALL substitution is not required. * 4. TRACEn-n: Do the SSID substitution like WIDE, but also insert MYCALL * into the digi list: * RELAY*,TRACE3-3 * RELAY,N2YGK-7*,TRACE3-2 * RELAY,N2YGK-7,WB2ZII*,TRACE3-1 * RELAY,N2YGK-7,WB2ZII,N2MH-15*,TRACE3 * RELAY,N2YGK-7,WB2ZII,N2MH-15,WA2YSM-14* * (What happens when the digi list gets too long for the AX.25 protocol * appears not to have been considered in this design. I guess we'll * just insert as many as we can.) */ /* * These flags are shared by the calltab and floods tables and by * the floodtype of a specific received call. That is, while there is * only one WIDE calltab entry, a received callsign can be WIDE-n or * WIDEn-n. */ #define C_IS_NOFLOOD 0 /* not a flood */ #define C_IS_FLOOD 1 /* this callsign is a flood (WIDE) */ #define C_IS_FLOODN 2 /* this is an N-N type flood (WIDEn-n) */ #define C_IS_TRACE 4 /* this is a trace-type flood (TRACE*) */ struct flood { ax25_address call; /* the flooding callsign prefix */ int len; /* length */ int flags; } Floods[MAXALIASES]; static int N_floods = 0; #define FLOODCALL Floods[0].call #define FLOODLEN Floods[0].len /* forward declarations */ static int unproto(struct full_sockaddr_ax25 *, char *); static int parsecalls(ax25_address*, int, char *); static void print_it(FILE *,struct ax_calls *,unsigned char *,int len); static void add_text(u_char **,int *,u_char *,int,char *,int); static int dupe_packet(struct ax_calls *,u_char *,int); static int loop_packet(struct ax_calls *,u_char *,int); static int xmit(struct stuff *s, struct interface_list *list); static void set_id(void); static void rx_packet(struct interface *i, u_char *buffer, int len); static void fix_recvfrom(struct stuff *s); static int floodcmp(ax25_address *a, int len, ax25_address *b); static int floodtype(ax25_address *c, int i); static void sked_id(struct interface *iface); static void budlist_add(char *, int); static int budlist_permit(struct stuff *); static void budlist_print_all(FILE *f); static void budlist_print(FILE *f,struct budlist *); static void dupelist_add(char *); static void dupelist_print_all(FILE *f); static void dupelist_print(FILE *f,struct dupelist *); static void dupelist_init(void); static void printaddr(struct sockaddr_storage *s, char *buf, int buflen); static void setmask(int, u_char *); static int cmpmask(int, u_char *, u_char *, u_char *); static void die(char *); static void usage(void); static void usage_udp(void); static void usage_unix(void); static void usage_ax25(void); static void usage_budlist(void); static void check_config(); static void config_print(FILE *f); static void print_dupes(void); static struct interface_list *intf_of(ax25_address *callsign); static void to_3rdparty(struct ax_calls *calls); static void drop_unused_digis(struct ax_calls *calls); static void from_3rdparty(struct stuff *s, int npkts, /* dimension of the next two vectors */ u_char *pkt[], /* output buffers for source path header */ int pktl[]); /* output length of sph (AX25_MTU max) */ /* signal handlers */ static void cleanup(int),identify(int),identify_final(int), print_stats(int),reset_stats(int); static void do_opts(int argc, char **argv); static void do_ports(void); static void do_port_ax25(struct interface *); static void do_port_udp(struct interface *); static void do_port_unix(struct interface *); static void set_sig(void); static int rx_loop(void); int main(int argc, char **argv) { int r; bzero(Intf,sizeof(Intf)); do_opts(argc,argv); do_ports(); set_id(); set_sig(); check_config(); r = rx_loop(); exit(r); } /* Listen for received packets and farm out the work */ static int rx_loop() { unsigned char buffer[AX25_MTU]; int n,selfds = 0; struct interface *i; fd_set select_mask; /* set up the initial select mask */ FD_ZERO(&select_mask); for (n = 0, i = Intf; n < N_intf; n++, i++) { if (i->rsock >= 0 && (i->i_flags & I_RX)) { FD_SET(i->rsock, &select_mask); selfds = (i->rsock>selfds)?i->rsock:selfds; } } ++selfds; for (;;) { int len; fd_set rmask = select_mask; if (select(selfds,&rmask,NULL,NULL,NULL) < 0) { if (errno == EINTR) continue; perror("select"); return 1; } /* find which sockets have data */ for (n = 0, i = Intf; n < N_intf; n++, i++) { if (i->rsock >= 0 && FD_ISSET(i->rsock,&rmask)) { int size = sizeof(i->rsafrom); if ((len = recvfrom(i->rsock,buffer,sizeof(buffer),0,(struct sockaddr *)&i->rsafrom,&size)) < 0) { if (errno == EINTR) continue; perror(i->port); return 1; } rx_packet(i,buffer,len); /* process the received packet */ } } } /* end of for(;;) */ return 0; /* NOTREACHED */ } /* Parse a received packet, convert and digipeat if necessary. */ static void rx_dupeit(struct stuff *s); static int rx_nodigi(struct stuff *s,int r); static int rx_dupe(struct stuff *s); static int rx_to_me(struct stuff *s); static int rx_bud_deny(struct stuff *s); static int rx_from_me(struct stuff *s); static int rx_ssid(struct stuff *s); static int rx_flood(struct stuff *s); static int rx_digi(struct stuff *s); static void rx_packet(struct interface *i, /* which interface received on */ u_char *buffer, /* what was received */ int len) /* length received */ { int r; struct stuff s; bzero(&s,sizeof(s)); s.i = i; ++s.i->stats.rx; s.cp = buffer; s.len = len; /* parse the cooked or raw kiss frame */ if (i->i_flags&I_COOKED) r = parse_cooked_ax25(&s.cp,&s.len,&s.in); else r = parse_raw_ax25(&s.cp,&s.len,&s.in); fix_recvfrom(&s); /* workaround bug in AF_AX25 */ if (Verbose) { char buf[20]; time_t tick = time(0); strftime(buf,sizeof(buf),"%T",gmtime(&tick)); fprintf(stderr,"%s %s: RX: ",buf,s.i->port); print_it(stderr,&s.in,s.cp,s.len); } /* go through a bunch of choices until we eat the packet or die:-) */ if (Doing_dupes) rx_dupeit(&s); /* blindly dupe it */ if (rx_bud_deny(&s)) /* budlisted */ return; else if (rx_from_me(&s)) /* don't digi my own repeated beacons! */ return; else if (rx_ssid(&s)) /* dest SSID handling */ return; else if (rx_nodigi(&s,r)) /* Nothing to digi? */ return; else if (rx_dupe(&s)) /* Is it a killed dupe or loop? */ return; else if (rx_to_me(&s)) /* Addressed to me? */ return; else if (rx_flood(&s)) /* flood special handling */ return; else if (rx_digi(&s)) /* conventional digi */ return; /* How'd we get here? */ if (Testing) { fprintf(stderr,"%s: Not repeatable\n",s.i->port); } } /* XXX bug(?) in AF_AX25 for raw sockets puts the interface name in sax25_call instead of the sender's callsign: (gdb) p (struct sockaddr_ax25)i->rsafrom $3 = {sax25_family = 3, sax25_call = {ax25_call = "ax0\0\0\0"}, sax25_ndigis = 0} */ static void fix_recvfrom(struct stuff *s) { struct sockaddr_ax25 *sax25 = (struct sockaddr_ax25 *)&s->i->rsafrom; if (sax25->sax25_family == AF_AX25) { bcopy(&s->in.ax_from_call, sax25->sax25_call.ax25_call,sizeof(sax25->sax25_call.ax25_call)); } } static void rx_dupeit(struct stuff *s) { int n; if (s->i->dupe && s->i->dupe->dl_il) { if (Verbose) { fprintf(stderr,"%s: duping to dupelist %d\n",s->i->devname, s->i->dupe->dl_list_no); } s->out = s->in; if (xmit(s,s->i->dupe->dl_il) < 0) perror("xmit"); } } static int rx_nodigi(struct stuff *s,int r) { int result = 0; /* bail if invalid or not doing SSID & no unrepeated digis */ if (r == PK_INVALID || r == PK_VALID || (r != PK_VALDIGI && !Digi_SSID)) { ++s->i->stats.rx_ign; result = 1; } if (Verbose) { if (result) fprintf(stderr,"packet is %s. (r=%d)\n", (r == PK_INVALID)?"invalid":"not repeatable",r); else fprintf(stderr,"packet is repeatable. (r=%d)\n",r); } return result; } static int rx_dupe(struct stuff *s) { int result = 0; static char *lupedupe[] = {"dupe or loop","dupe","loop"}; /* If packet was last transmitted by me, then don't digipeat it! */ if (Kill_dupes && dupe_packet(&s->in,s->cp,s->len)) { ++s->i->stats.rx_dup; result = 1; } else if (Kill_loops && loop_packet(&s->in,s->cp,s->len)) { ++s->i->stats.rx_loop; result = 2; } if (Verbose) { fprintf(stderr,"packet is%sa %s\n",result?" ":" not ",lupedupe[result]); } return result; } /* * find interfaces belonging to a callsign or alias. Returns a pointer to * a list of interfaces or NULL if not found. */ static struct callsign_list { ax25_address *callsign; int flags; int floodlen; /* length of flood call */ struct interface_list *l; /* list of interfaces having this callsign */ struct interface_list *illast; struct callsign_list *next; } *calltab = NULL, *ctlast = NULL; static void calltab_init(void); static struct callsign_list * calltab_entry(ax25_address *callsign,int *flags) { struct callsign_list *c; int flagdummy; if (flags == NULL) flags = &flagdummy; /* dummy the flags if not needed */ *flags = 0; for (c = calltab; c; c = c->next) { if ((c->flags&C_IS_FLOOD && (*flags = floodcmp(c->callsign,c->floodlen,callsign))) || (ax25_cmp(c->callsign,callsign) == 0)) { *flags |= c->flags; /* add stuff floodcmp doesn't know about */ return c; } } return NULL; } static void calltab_init(void) { struct interface *i; int n,m; /* iterate over all interfaces' callsigns */ for (i = Intf, n = 0; n < N_intf; n++,i++) { for (m = 0; m < i->n_aliases; m++) { struct interface_list *new_il = (struct interface_list *)calloc(1,sizeof(struct interface_list)); struct callsign_list *c = (calltab)?calltab_entry(&i->aliases[m],0):NULL; if (!c) { /* first time seeing this call */ int f; c = (struct callsign_list *)calloc(1,sizeof(struct callsign_list)); c->callsign = &i->aliases[m]; /* see if this is a flood call */ for (f = 0; f < N_floods; f++) { if (floodcmp(&Floods[f].call,Floods[f].len,c->callsign)) { c->flags = Floods[f].flags; c->floodlen = Floods[f].len; break; } } /* add the new callsign_list to calltab */ if (ctlast) { ctlast->next = c; ctlast = c; } else { calltab = ctlast = c; /* very first entry */ } } new_il->i = i; /* initialize the interface list */ if (c->illast) { /* and link it in to the callsign's list */ c->illast->next = new_il; c->illast = new_il; } else { c->l = c->illast = new_il; } } } } static struct interface_list * intf_of(ax25_address *callsign) { struct callsign_list *c; if (c = calltab_entry(callsign,0)) return c->l; return NULL; } static int rx_to_me(struct stuff *s) { int result = 0; struct interface_list *l = intf_of(&s->in.ax_to_call); if (l) { result = 1; ++s->i->stats.rx_ign; } if (Verbose) { fprintf(stderr,"packet is%saddressed to me.\n",result?" ":" not "); } return result; } static int rx_bud_deny(struct stuff *s) { int permit = 0; permit = budlist_permit(s); if (Verbose) { fprintf(stderr,"packet is %s by budlist.\n",permit?"permitted":"denied"); } return !permit; /* true if denied */ } static int rx_from_me(struct stuff *s) { int n,result = 0; struct interface *iface; for (n = 0, iface = Intf; n < N_intf; n++, iface++) { if (ax25_cmp(&MYCALL(n),&s->in.ax_from_call) == 0) { result=1; ++s->i->stats.rx_ign; } } if (Verbose) { fprintf(stderr,"packet is%sfrom me.\n",result?" ":" not "); } return result; } /* * SSID path selection only applies if: * 1. SSID digipeating is enabled. * 2. To-call's SSID must be non zero: this is the route. * 3. Digipeater path must be empty. * Count up mic_e packets while we are here. */ static int rx_ssid(struct stuff *s) { int ssid, mic_e, result = 0; mic_e = (*(s->cp) == 0x60 || *(s->cp) == 0x27 || *(s->cp) == 0x1c || *(s->cp) == 0x1d); if (mic_e) ++s->i->stats.rx_mic; if (Verbose) { fprintf(stderr,"%s mic_e...\n",mic_e?"is":"is not"); } if (Digi_SSID && s->in.ax_n_digis == 0 && (ssid = (s->in.ax_to_call.ax25_call[ALEN]&SSID)>>1) && s->len > 0) { if (Verbose) { fprintf(stderr,"Got an SSID route for path %d.\n",ssid); } ++s->i->stats.rx_ssid; s->out.ax_from_call = s->in.ax_from_call; s->out.ax_to_call = s->in.ax_to_call; s->out.ax_to_call.ax25_call[ALEN]&=~SSID; /* zero the SSID */ s->out.ax_type = s->in.ax_type; s->out.ax_pid = s->in.ax_pid; if (ssid <= 7) { /* omnidirectional */ if (N_floods || ssid == 0) { /* in a flooding network? */ s->out.ax_n_digis = 1; s->out.ax_digi_call[0] = FLOODCALL; s->out.ax_digi_call[0].ax25_call[FLOODLEN] = (ssid+'0') << 1; s->out.ax_digi_call[0].ax25_call[ALEN] |= SSID&(ssid<<1); if (Verbose) { fprintf(stderr,"Flooding: setting path to %s\n", ax25_ntoa_pretty(&s->out.ax_digi_call[0])); } } else { /* not in a flooding network */ int startat,i; if (ssid < 4) { /* RTFM for why this is */ startat = 0; /* starting point in digipath */ s->out.ax_n_digis = ssid; /* number of digis from there. */ } else { startat = 3; s->out.ax_n_digis = ssid-3; } if (Verbose) { fprintf(stderr,"Non-flooding: converting SSID WIDE-%d path to DIGI[%d:%d]\n", ssid,startat,startat+s->out.ax_n_digis-1); } /* fill in the digipeater list */ for (i = 0; i < s->out.ax_n_digis; i++,startat++) { s->out.ax_digi_call[i] = Digipath[startat]; } } /* flooding/non-flooding network */ } else { /* SSID > 7 is directional */ int j; if (Verbose) { fprintf(stderr,"setting path to %c UNPROTO%s\n", Dirs[ssid&3],(ssid&4)?" + WIDE":""); } s->out.ax_n_digis = Path[ssid&3].fsa_ax25.sax25_ndigis; for (j = 0; j <= s->out.ax_n_digis; j++) s->out.ax_digi_call[j] = Path[ssid&3].fsa_digipeater[j]; if (ssid&4) { /* directional + wide call */ s->out.ax_digi_call[s->out.ax_n_digis++] = Widecall; } } ++s->i->stats.ssid; if (xmit(s,NULL) < 0) perror("xmit"); result = 1; } if (Verbose) { fprintf(stderr,"did%srequire destination SSID handling.\n", result?" ":" not "); } return result; } /* see if special WIDEn-n & TRACEn-n handling applies. */ static int rx_flood(struct stuff *s) { int i,wide,thisflags,result=0; struct callsign_list *c; /* FLOODn-n algorithm: next digi with non-zero ssid callsign */ c = calltab_entry(&s->in.ax_digi_call[s->in.ax_next_digi],&thisflags); if (c && thisflags&C_IS_FLOOD && (wide = (s->in.ax_digi_call[s->in.ax_next_digi].ax25_call[ALEN]&SSID)>>1)) { if (Verbose) { fprintf(stderr,"Got a flooding %s route.\n", ax25_ntoa_pretty(&s->in.ax_digi_call[s->in.ax_next_digi])); } /* flooding algorithm always kills dupes. If kill_dupes option was not selected, then do the dupe checking here */ if (!Kill_dupes && dupe_packet(&s->in,s->cp,s->len)) { if (Verbose) { fprintf(stderr,"flood packet is a dupe\n"); } return 1; } /* decrement the flood counter (SSID) */ s->out = s->in; /* copy the input header */ s->out.ax_digi_call[s->out.ax_next_digi].ax25_call[ALEN] &= ~SSID; s->out.ax_digi_call[s->out.ax_next_digi].ax25_call[ALEN] |= ((--wide) << 1)&SSID; /* TRACEn-n: insert dummy mycall in front: xmit will put the real one in */ if ((thisflags&(C_IS_FLOODN|C_IS_TRACE)) == (C_IS_FLOODN|C_IS_TRACE)) { int n; if (s->out.ax_n_digis >= AX25_MAX_DIGIS) { fprintf(stderr,"%s: TRACEn-n list overflow. Last digi dropped.\n", s->i->port); s->out.ax_n_digis--; } /* shift remaining digis right one slot to make room */ for (n = s->out.ax_n_digis; n >= s->out.ax_next_digi; n--) { s->out.ax_digi_call[n] = s->out.ax_digi_call[n-1]; } /* then stuff in a dummy "TRACE" and mark it repeated */ s->out.ax_digi_call[s->out.ax_next_digi] = Trace_dummy; s->out.ax_digi_call[s->out.ax_next_digi].ax25_call[ALEN] |= REPEATED; s->out.ax_n_digis++; } if (Verbose) { fprintf(stderr,"Rewriting it as %s:\n", ax25_ntoa_pretty(&s->out.ax_digi_call[s->out.ax_next_digi])); } ++s->i->stats.flood; if (xmit(s,NULL) < 0) perror("xmit"); return 1; } if (Verbose) { fprintf(stderr,"Did %s require special flooding handling.\n", result?" ":" not "); } return result; } /* see if conventional digipeat handling applies. */ static int rx_digi(struct stuff *s) { int j, result = 0; struct interface_list *l; /* conventional: see if the next digipeater matches one of my calls */ if (l = intf_of(&s->in.ax_digi_call[s->in.ax_next_digi])) { /* a packet for me to digipeat */ if (Verbose) { fprintf(stderr,"Got a conventional digipeat.\n"); } s->out = s->in; /* copy input list to output unmodifed */ s->out.ax_digi_call[s->out.ax_next_digi].ax25_call[ALEN] |= REPEATED; ++s->i->stats.digi; if (xmit(s,NULL) < 0) perror("xmit"); result = 1; } if (Verbose) { fprintf(stderr,"Did%srequire conventional digipeat handling.\n", result?" ":" not "); } return result; } static void add_text(op,oleft,text,len,tag,taglen) unsigned char **op; int *oleft; u_char *text; int len; char *tag; int taglen; { if ((*oleft -= len) > 0) { bcopy(text,*op,len); /* copy the text */ *op += len; } if (taglen && tag && (*oleft -= taglen) > 0) { bcopy(tag,*op,taglen); /* and tack on the tag */ *op += taglen; } } /* watch out for overflow when adding mycall and/or wide */ static int unproto(calls,str) /* parse a via path into a calls struct */ struct full_sockaddr_ax25 *calls; char *str; { char buf[200]; bzero(calls, sizeof(*calls)); sprintf(buf,"dummy via %s",str); return ax25_aton(buf,calls); } static int parsecalls(calls,ncalls,str) /* parse a via path into a calls struct */ ax25_address *calls; int ncalls; /* max number */ char *str; { char *cp; int i; bzero(calls,ncalls*sizeof(*calls)); cp = strtok(str," \t\n,"); for (i = 0; cp && i < ncalls; i++) { if (ax25_aton_entry(cp,calls[i].ax25_call) < 0) return -1; cp = strtok(NULL," \t\n,"); } return i; } static void print_it(FILE *f, struct ax_calls *calls, u_char *data, int len) { int j; char asc_from[12],asc_to[12]; if (f == NULL) return; strncpy(asc_to,ax25_ntoa_pretty(&calls->ax_to_call),sizeof(asc_to)); strncpy(asc_from,ax25_ntoa_pretty(&calls->ax_from_call),sizeof(asc_from)); fprintf(f,"%s>%s",asc_from,asc_to); for (j = 0; j < calls->ax_n_digis; j++) { fprintf(f,",%s%s",ax25_ntoa_pretty(&calls->ax_digi_call[j]), (calls->ax_digi_call[j].ax25_call[ALEN]&REPEATED && (j == calls->ax_next_digi-1))?"*":""); } fprintf(f,":%.*s\n",len,data); } /* * packet reformatter * depending on options flags on transmit interface, perform reformatting * of the payload. Current methods include mic_E expansion, X1J4 * stripping of the the "TheNet X1J4 (alias)" prefix. Future methods * to include GPS/APRS position compression, expansion, etc. */ static int reformat(struct stuff *s, /* "class data":-) */ struct interface *i, /* this iteration's transmit interface */ u_char ***ovec, /* returns ptr to array of u_char ptrs */ int **olen) /* returns ptr to array of lengths */ { int r; time_t now; static u_char mic1[AX25_MTU], mic2[AX25_MTU]; /* MTU is *not* max payload! */ static u_char pref1[AX25_MTU], pref2[AX25_MTU]; static u_char *vecp[2]; static int vecl[2]; time(&now); *ovec = vecp; /* returned ptrs */ *olen = vecl; vecp[0] = mic1; vecl[0] = 0; vecp[1] = mic2; vecl[1] = 0; /* does xmit intf want mic-E translation? */ if (i->i_flags&MICE_XLATE && fmt_mic_e(ax25_ntoa_pretty(&s->out.ax_to_call),s->cp,s->len, mic1,&vecl[0],mic2,&vecl[1],now)) { s->out.ax_to_call = Aprscall; /* replace compressed lat w/"APRS" */ } else if (i->i_flags&X1J4_XLATE && /* want x1j4 translation? */ fmt_x1j4(ax25_ntoa_pretty(&s->out.ax_to_call),s->cp,s->len, mic1,&vecl[0],mic2,&vecl[1],now)) { } else { /* no reformat; just pass thru */ vecp[0] = s->cp; vecl[0] = s->len; } return (vecl[0]>0)+(vecl[1]>0); } /* * xmit looks at the next digipeater call to see which interfaces the * packet has to go out. By giving several interfaces the same callsign * or alias, multi-way fanout and/or gatewaying can be performed. * * An overriding interface list passed in is used by rx_dupeit(). */ static int xmit(struct stuff *s, struct interface_list *dupelist) { struct callsign_list *c; struct interface_list *l; int r = 0, sent; int thisflags = 0; /* transmit the packet on the interface(s) of the next callsign */ if (!dupelist) { if ((c = calltab_entry(&s->out.ax_digi_call[s->out.ax_next_digi],&thisflags)) == NULL) { fprintf(stderr,"xmit: Assertion failed: call %s not found\n", ax25_ntoa_pretty(&s->out.ax_digi_call[s->out.ax_next_digi])); return -1; } } for(l = (dupelist)?dupelist:c->l; l; l = l->next) { /* loop over each tx interface */ u_char obuf[AX25_MTU]; u_char *op = obuf; int oleft = sizeof(obuf); int olen; int npkt,n; u_char **vecp; /* output vector */ int *vecl; /* and lengths */ if (!(l->i->i_flags & I_TX)) { if (Verbose) fprintf(stderr,"%s: interface will not xmit.\n",l->i->devname); continue; } if (!(l->i->i_flags & I_TXSAME) && l->i == s->i) { if (Verbose) fprintf(stderr,"%s: will not retransmit on same interface.\n",l->i->devname); continue; } /* do any required per-intf expansion/translation/compression of payload */ npkt = reformat(s,l->i,&vecp,&vecl); if (s->i != l->i && l->i->i_flags&I_3RDP) { if (Verbose) fprintf(stderr,"3rd party de-tunnel: source port: %s dest port: %s\n", s->i->port, l->i->port); from_3rdparty(s,npkt,vecp,vecl); } for (n = 0; n < npkt; n++) { struct ax_calls calls = s->out; /* * Adjust the next_digi pointer only if REPEATED was set. * Only substitute MYCALL if marked REPEATED and the callsign * flags permit it. Flags and their rules: * FLOOD FLOODN TRACE Rule * ----- ------ ----- ----------------------------------- * 0 X X only if SUBST_MYCALL substitute MYCALL * 1 0 X always substitute MYCALL (WIDE/TRACE->MYCALL) * 1 1 0 never substitute MYCALL (WIDEn-n) * 1 1 1 always substitute MYCALL (???->MYCALL) * rx_flood will have inserted tracecall in front of TRACEn-n. * but MYCALL subst happens here since it is iface-specific. */ if (!dupelist) { /* if dupeing, ignore this crap */ if (calls.ax_digi_call[calls.ax_next_digi].ax25_call[ALEN]&REPEATED) { if ((!(thisflags&C_IS_FLOOD) && l->i->i_flags&SUBST_MYCALL) || ((thisflags&C_IS_FLOOD) && !(thisflags&C_IS_FLOODN)) || ((thisflags&(C_IS_FLOOD|C_IS_FLOODN|C_IS_TRACE)) == (C_IS_FLOOD|C_IS_FLOODN|C_IS_TRACE))) { calls.ax_digi_call[calls.ax_next_digi] = I_MYCALL(l->i); calls.ax_digi_call[calls.ax_next_digi].ax25_call[ALEN] |= REPEATED; } ++calls.ax_next_digi; } } /* XXX - deal with detunneled 3rdparty (empty digi list) -- or is some default digi list supposed to be used? */ if (s->i != l->i && s->i->i_flags&I_3RDP) { if (Verbose) fprintf(stderr,"3rd party tunnel: source port: %s dest port: %s\n", s->i->port, l->i->port); to_3rdparty(&calls); } if (l->i->i_flags&I_COOKED) gen_cooked_ax25(&op,&oleft,&calls); /* generate cooked header */ else gen_raw_ax25(&op,&oleft,&calls); /* generate the raw kiss header */ add_text(&op,&oleft,vecp[n],vecl[n],l->i->tag,l->i->taglen); /* fill in the info field */ olen = sizeof(obuf) - oleft; if (Logfile) { /* XXX this gets duplicated crap for multiple intfs */ FILE *of; if (Logfile[0] == '-' && Logfile[1] == '\0') of = stdout; else of = fopen(Logfile,"a"); print_it(of,&calls,op-(vecl[n]+l->i->taglen),vecl[n]+l->i->taglen); if (of != stdout && of != stderr) fclose(of); } if (Verbose) { fprintf(stderr,"%s: TX: ",l->i->port); print_it(stderr,&calls,op-(vecl[n]+l->i->taglen),vecl[n]+l->i->taglen); } ++l->i->stats.tx; sked_id(l->i); if ((sent = sendto(l->i->tsock,obuf,olen,0,(struct sockaddr *)&l->i->tsa, l->i->tsa_size)) < 0) perror(l->i->port); else r += sent; } /* end for n */ } /* end for l */ return r; } /* * packet dupe checking * * Compare the to, from, and info. Ignore the digipeater path. * If the packet matches one already received within the 'keep' * interval then it is a dupe. Keep the list sorted in reverse * chronological order and throw out any stale packets. */ struct pkt { struct pkt *next,*prev; time_t t; /* when recevied */ ax25_address to; /* destination */ ax25_address fr; /* source */ int l; /* length of text */ u_char d[AX25_MTU]; /* the text */ }; static struct pkt *top; /* stacked in reverse chronological order */ static int dupe_packet(struct ax_calls *calls,u_char *cp,int len) { struct pkt *p, *matched = NULL, *old = NULL; time_t now = time(0); time_t stale = now - Keep; if (Verbose) { print_dupes(); } for (p = top; p; p = p->next) { if (p->t >= stale) { /* packet is still fresh */ if (p->l == len && bcmp(p->d,cp,len) == 0 && bcmp(&calls->ax_to_call,&p->to,sizeof(p->to)) == 0 && bcmp(&calls->ax_from_call,&p->fr,sizeof(p->fr)) == 0) { matched = p; break; } else continue; } else { /* all following packets are stale */ old = p; break; } } if (old) { /* trim list of stale pkts */ if (top == old) top = NULL; /* entire list is stale */ else { old->prev->next = NULL; } while (old) { p = old->next; free(old); old = p; } } if (matched) { /* move matched packet to head of list? */ #ifdef DUPE_REFRESH_STAMP /* * Should dupe-checking update the time stamp each time a dupe is * heard again or let it age out so that it can get digi'd * periodically? For example, if a station beacons once every 15 * seconds, then only the first packet received ever will be * digi'd if the "memory" is 28 sec. Good example of where this * could be a problem is a MIC-E beaconing an emergency. By not * refreshing the timestamp, the desired behavior of reducing channel * clutter is still achieved. */ matched->t = now; /* updated timestamp */ if (matched == top) /* already on top */ return 1; /* unlink matched packet from list */ if (matched->prev) matched->prev->next = matched->next; if (matched->next) matched->next->prev = matched->prev; matched->prev = matched->next = NULL; /* push matched packet on top of list */ matched->next = top; if (top) top->prev = matched; top = matched; #endif return 1; } else { /* not matched: push new packet on top */ if ((p = (struct pkt *)calloc(1,sizeof(struct pkt))) == NULL) { fprintf(stderr,"failed to calloc!\n"); return 0; } p->t = now; p->l = (len>AX25_MTU)?AX25_MTU:len; bcopy(cp,p->d,p->l); p->to = calls->ax_to_call; p->fr = calls->ax_from_call; /* push new packet on top of list */ p->next = top; if (top) top->prev = p; top = p; return 0; } } static void print_dupes(void) { struct pkt *p; for (p = top; p ; p = p->next) { fprintf(stderr,"dupe @ 0x%0x: prev->0x%0x next->0x%0x time %d len %d\n", p,p->prev,p->next,p->t,p->l); } } /* * is packet looping? * e.g. FOO,mycall,WIDE*,mycall,somecall.... * Only look for one of my already repeated real callsigns (e.g. MYCALL(n)). * * Search through the list of already-repeated digipeaters and compare * each to one of my interface callsigns (since these are the ones that * replace generic callsigns). */ static int loop_packet(struct ax_calls *calls,u_char *cp,int len) { int n, flags; int j; struct interface *iface; struct callsign_list *cl; for (n = 0; n < calls->ax_next_digi; n++) { if (calls->ax_digi_call[n].ax25_call[ALEN]&REPEATED) { for (j = 0, iface = Intf; j < N_intf; j++, iface++) { if (ax25_cmp(&MYCALL(j),&calls->ax_digi_call[n]) == 0) { if (Verbose) fprintf(stderr,"loop_packet: found my call %s at digi_call[%d]\n", ax25_ntoa_pretty(&calls->ax_digi_call[n]),n); return 1; } } } else return 0; /* last repeated call */ } return 0; } static void cleanup(sig) int sig; /* dont't really care what it was */ { if (alarm(0) > 0) /* an alarm was pending, so... */ sked_id(NULL); /* ID one last time */ identify_final(sig); print_stats(sig); /* dump final stats */ exit(0); /* and exit */ } static void print_stats(sig) int sig; { FILE *of = stderr; struct interface *i; int n; if (Logfile) { if (Logfile[0] == '-' && Logfile[1] == '\0') of = stdout; else of = fopen(Logfile,"a"); } if (of == NULL) return; for (i = Intf, n = 0; n < N_intf; n++,i++) { fprintf(of,"# %s: rx %d (ign %d dup %d loop %d mic %d ssid %d) tx %d (digi %d flood %d ssid %d ids %d)\n", i->port, i->stats.rx,i->stats.rx_ign,i->stats.rx_dup,i->stats.rx_loop, i->stats.rx_mic,i->stats.rx_ssid, i->stats.tx,i->stats.digi,i->stats.flood,i->stats.ssid, i->stats.ids); } if (of != stdout && of != stderr) fclose(of); if (sig >= 0) signal(sig,print_stats); } static void reset_stats(sig) int sig; { struct interface *i; int n; print_stats(-1); for (i = Intf, n = 0; n < N_intf; n++,i++) { bzero(&i->stats,sizeof(i->stats)); } signal(sig,reset_stats); } /* setup a bare minimum legal ID (don't QRM the world with a digi path!) */ static void set_id() { struct ax_calls id; char idinfo[AX25_MTU]; int i,n; struct interface *iface; for (n = 0, iface = Intf; n < N_intf; n++, iface++) { u_char *op = iface->idbuf; int oleft = sizeof(iface->idbuf); bzero(&id,sizeof(id)); ax25_aton_entry("ID",id.ax_to_call.ax25_call); id.ax_to_call.ax25_call[ALEN] |= C; /* it's a command */ id.ax_from_call = MYCALL(n); id.ax_type = UI; id.ax_pid = PID_NO_L3; id.ax_n_digis = 0; if (iface->i_flags&I_COOKED) gen_cooked_ax25(&op,&oleft,&id); /* generate the kiss header */ else gen_raw_ax25(&op,&oleft,&id); /* generate the kiss header */ *idinfo = '\0'; for (i = 0; i < iface->n_aliases; i++) { strcat(idinfo,ax25_ntoa_pretty(&iface->aliases[i])); strcat(idinfo,"/R "); } for (i = 0; i < N_floods; i++) { strcat(idinfo,ax25_ntoa_pretty(&Floods[i].call)); strcat(idinfo,"n-n/R "); } add_text(&op,&oleft,idinfo,strlen(idinfo),0,0); iface->idlen = sizeof(iface->idbuf) - oleft; } } static void xmit_id(struct interface *i) { if (Verbose) { fprintf(stderr,"%s: TX: ID\n",i->port); } if (sendto(i->tsock,i->idbuf,i->idlen, 0,(struct sockaddr *)&i->tsa,i->tsa_size) < 0) /* ship it off */ perror(i->devname); i->i_flags &= ~I_NEED_ID; i->next_id = 0; ++i->stats.ids; } /* * sched alarm for next id. Called with intf ptr if that interface * needs to schedule an ID, NULL during alarm sig handler. */ static struct interface *ID_next = NULL; static void sked_id(struct interface *iface) { struct interface *i; int n; time_t now = time(0); time_t min = now+24*60*60; time_t when; if (iface && !(iface->i_flags&I_NEED_ID) && iface->idinterval) { iface->next_id = now+iface->idinterval; iface->i_flags |= I_NEED_ID; } /* find minimum time among all interfaces 'til next needed ID. */ for (i = Intf, n = 0, ID_next = NULL; n < N_intf; n++,i++) { if (i->i_flags&I_NEED_ID && i->idinterval && i->next_id > 0) { if ((when = i->next_id - now) <= 0) /* catch any already due */ xmit_id(i); else if (i->next_id < min) { ID_next = i; /* new minimum */ min = ID_next->next_id; } } } if (ID_next && ID_next->next_id && ID_next->next_id > 0) { alarm(when); /* next alarm in this many secs */ if (Verbose) { fprintf(stderr,"next ID for %s in %d seconds\n",ID_next->port, when); } } } static void identify(int sig) /* wake up and ID! */ { if (ID_next && ID_next->i_flags&I_NEED_ID) { xmit_id(ID_next); ID_next = NULL; sked_id(NULL); /* schedule next ID */ signal(sig,identify); } } static void identify_final(int sig) /* wake up and ID! */ { struct interface *i; int n; for (i = Intf, n = 0; n < N_intf; n++,i++) { if (i->i_flags&I_NEED_ID && i->idinterval && i->next_id > 0) { xmit_id(i); } } } #include enum {NONE=no_argument,REQD=required_argument,OPT=optional_argument}; static struct option opts[] = { {"verbose",OPT,0,'v'}, {"testing",NONE,0,'T'}, {"interface",REQD,0,'p'}, {"port",REQD,0,'p'}, {"trace",REQD,0,'F'}, {"flood",REQD,0,'f'}, {"east",REQD,0,'e'}, {"west",REQD,0,'w'}, {"north",REQD,0,'n'}, {"south",REQD,0,'s'}, {"digipath",REQD,0,'d'}, {"tag",REQD,0,'t'}, {"keep",REQD,0,'k'}, {"logfile",REQD,0,'l'}, {"idinterval",REQD,0,'i'}, {"subst_mycall",NONE,0,'C'}, {"nosubst_mycall",NONE,0,'c'}, {"mice_xlate",NONE,0,'M'}, {"nomice_xlate",NONE,0,'m'}, {"x1j4_xlate",NONE,0,'X'}, {"nox1j4_xlate",NONE,0,'x'}, {"3rdparty",NONE,0,'3'}, {"no3rdparty",NONE,0,'0'}, {"kill_dupes",NONE,0,'D'}, {"kill_loops",NONE,0,'L'}, {"bud",REQD,0,'B'}, {"nobud",REQD,0,'b'}, {"version",NONE,0,'V'}, {"help",NONE,0,'?'}, {"opts",REQD,0,'o'}, /* ran out of letters */ #define O(x) ((int)(256+(int)x)) {"rx",NONE,0,O('R')}, {"norx",NONE,0,O('r')}, {"tx",NONE,0,O('T')}, {"notx",NONE,0,O('t')}, {"txsame",NONE,0,O('S')}, {"notxsame",NONE,0,O('s')}, {"dupe",REQD,0,O('d')}, {"duplicate",REQD,0,O('d')}, {0,0,0,0} }; static char *optstring = "CcMmXxF:f:n:s:e:w:t:k:l:i:d:p:DLVvT30o:B:b:"; static void do_opts(int argc, char **argv) { int s; int opt_index = 0; /* set interface defaults */ I_flags = I_TX|I_RX|I_TXSAME; while ((s = getopt_long(argc, argv, optstring, opts, &opt_index)) != -1) { int p = -1; /* used for NSEW hack, below */ int fflags = 0; /* use for fF hack */ switch (s) { case 'v': ++Verbose; break; case 'T': ++Testing; break; case 'p': /* -p port[:alias,alias,alias...] */ if (N_intf >= MAXINTF) { fprintf(stderr,"too many interfaces!\n"); exit(1); } { struct interface *i = &Intf[N_intf++]; int a_i = 1; /* default 0'th alias is MYCALL */ char *op = strchr(optarg,':'); /* fill in defaults */ i->i_flags = I_flags; i->tag = Tag; i->taglen = Taglen; i->idinterval = Idinterval; i->bud = Bl_last; i->dupe = Dl_last; if (strncasecmp(optarg,"udp:",4) == 0) { /* IP/UDP port */ i->i_flags |= I_COOKED; i->i_proto = P_UDP; i->i_flags &= ~I_TXSAME; /* prevent stupid loops? */ a_i = 0; /* get MYCALL here */ /* udp:foo.bar.net/aprs/ttl:call,alias... */ /* or udp:224.1.2.3/1234/ttl:call,alias... */ /* or udp:fe80::204:e2ff:fe3c:ca2a/1234/ttl:call,alias... */ if (!op || !*op) { /* missing operand */ usage_udp(); } i->port = ++op; /* parse host/service/ttl later on */ op = strrchr(op,':'); /* skip backwards to the callsigns */ } else if (strncasecmp(optarg,"ax25:",5) == 0) { /* new-style axlib */ i->i_proto = P_AX25; if (!op || !*op) { /* missing operand */ usage_ax25(); } i->port = ++op; op = strchr(op,':'); if (op) *op = '\0'; } else if (strncasecmp(optarg,"unix:",5) == 0) { /* Unix fifo */ i->i_flags |= I_COOKED; i->i_proto = P_UNIX; a_i = 0; /* get MYCALL here */ if (!op || !*op) { /* missing operand */ usage_unix(); } i->port = ++op; op = strrchr(op,':'); /* skip backwards to the callsigns */ } else { /* ax25lib port name (same as ax25:) */ fprintf(stderr,"Warning: deprecated usage. Use \"-p ax25:%s\"\n",optarg); i->i_proto = P_AX25; i->port = optarg; } if (op) { /* additional aliases... */ *op++ = '\0'; if ((i->n_aliases=parsecalls(&i->aliases[a_i],MAXALIASES-1,op)) < 1) { fprintf(stderr,"Don't understand port %s aliases %s\n",optarg,op); exit(1); } if (i->i_proto == P_UDP || i->i_proto == P_UNIX) i->n_aliases--; /* alias 0 is MYCALL */ } } #ifdef notdef /* -p is an implicit -B - XXX why? */ budlist_add("-",0); #endif break; case 'F': /* flooding trace alias */ fflags = C_IS_TRACE; case 'f': /* flooding wide alias */ fflags |= C_IS_FLOOD; if (N_floods >= MAXALIASES) { fprintf(stderr,"too many flooding aliases!\n"); exit(1); } if (ax25_aton_entry(optarg,Floods[N_floods].call.ax25_call) < 0) { fprintf(stderr,"Don't understand callsign %s\n",optarg); exit(1); } if ((Floods[N_floods].call.ax25_call[ALEN]&SSID) != 0) { fprintf(stderr,"-f %s: flooding callsign must have a zero SSID\n", optarg); exit(1); } Floods[N_floods].flags = fflags; Floods[N_floods++].len = strlen(optarg); break; case 'w': /* directional unproto path */ ++p; case 'e': ++p; case 's': ++p; case 'n': ++p; ++Digi_SSID; if (unproto(&Path[p],optarg) < 0) { fprintf(stderr,"Don't understand %c path %s\n",toupper(s),optarg); exit(1); } break; case 'd': /* DIGI-style(non-SSID) unproto path */ ++Have_digipath; if (parsecalls(Digipath,DIGISIZE,optarg)!=DIGISIZE) { fprintf(stderr,"Don't understand %c path %s\n",toupper(s),optarg); exit(1); } break; case 't': /* tag to tack on to end of all packets */ Tag = optarg; Taglen = strlen(optarg); if (*Tag == '-' && Taglen == 1) { Tag = NULL; Taglen = 0; } break; case 'k': if ((Keep = atoi(optarg)) <= 0) Keep = 28; /* default keep is 28 */ break; case 'l': Logfile = optarg; /* log digipeated packets */ break; case 'i': Idinterval = atoi(optarg); break; case 'C': I_flags |= SUBST_MYCALL; break; case 'c': I_flags &= ~SUBST_MYCALL; break; case 'M': I_flags |= MICE_XLATE; break; case 'm': I_flags &= ~MICE_XLATE; break; case 'X': I_flags |= X1J4_XLATE; break; case 'x': I_flags &= ~X1J4_XLATE; break; case '3': I_flags |= I_3RDP; /* enable 3rd party tunneling */ break; case '0': I_flags &= ~I_3RDP; /* disable 3rd party tunneling (transparent) */ break; case 'o': /* o for options cuz I'm out of letters! */ switch (*optarg) { case 'R': /* RX enable */ I_flags |= I_RX; break; case 'r': /* RX disable */ I_flags &= ~I_RX; break; case 'T': I_flags |= I_TX; /* TX enable */ break; case 't': I_flags &= ~I_TX; /* TX disable */ break; case 'S': I_flags |= I_TXSAME; /* re-TX on RX interface */ break; case 's': I_flags &= ~I_TXSAME; /* no re-TX on RX interface */ break; default: usage(); } break; case O('d'): /* dupe to interface w/no modification */ dupelist_add(optarg); break; case O('R'): I_flags |= I_RX; break; case O('r'): I_flags &= ~I_RX; break; case O('T'): I_flags |= I_TX; /* TX enable */ break; case O('t'): I_flags &= ~I_TX; /* TX disable */ break; case O('S'): I_flags |= I_TXSAME; /* re-TX on RX interface */ break; case O('s'): I_flags &= ~I_TXSAME; /* no re-TX on RX interface */ break; case 'D': Kill_dupes++; break; case 'L': Kill_loops++; break; case 'B': budlist_add(optarg,1); break; case 'b': budlist_add(optarg,0); break; case 'V': printf("aprsdigi: %s-%s\n",PACKAGE,VERSION); exit(0); case '?': usage(); } } /* sanity-check args */ if (N_intf <= 0) { fprintf(stderr,"aprsdigi: must specify at least one port with -p\n"); exit(1); } } static void die(char *s) { perror(s); exit(1); } static void usage() { fprintf(stderr,"Usage: aprsdigi [-CcDLMXv] [-n|s|e|w path] [-fF call] [-t tag] [-k secs] [-l logfile] [-i interval] [-o r|R|t|T|s|S] [-p port:alias1,alias2...] [-B budlist] [-b budlist] ...\n"); fprintf(stderr," general options:\n"); fprintf(stderr," -v | --verbose -- produce verbose debugging output\n"); fprintf(stderr," -T | --testing -- test mode: listen to my packets too\n"); fprintf(stderr," -D | --kill_dupes -- suppress Duplicate packets\n"); fprintf(stderr," -L | --kill_loops -- suppress Looping packets\n"); fprintf(stderr," -V | --version -- print program version and exit\n"); fprintf(stderr," -n|s|e|w -- set North|South|East|West SSID directional path\n"); fprintf(stderr," --north | --south | --east | --west\n"); fprintf(stderr," -f | --flood -- set Flooding callsign (usually WIDE)\n"); fprintf(stderr," -F | --trace -- set Flooding TRACE callsign (usually TRACE)\n"); fprintf(stderr," -k | --keep -- seconds of old dupes to remember\n"); fprintf(stderr," -l | --logfile -- log digipeated packets here\n"); fprintf(stderr," per-interface options (put *before* each -p as needed):\n"); fprintf(stderr," -C (-c) | --[no]subst_mycall -- do (not) perform Mycall substitution\n"); fprintf(stderr," -M (-m) | --[no]mice_xlate -- do (not) perform Mic-E translation\n"); fprintf(stderr," -X (-x) | --[no]x1j4_xlate -- do (not) perform X1J4 translation\n"); fprintf(stderr," -3 | --3rdparty -- perform 3rd party tunneling\n"); fprintf(stderr," -0 | --no3rdparty -- perform transparent tunneling (default)\n"); fprintf(stderr," -o r (R) | --[no]rx -- do (not) mark interface receive-only\n"); fprintf(stderr," -o t (T) | --[no]tx -- do (not) mark interface transmit-only\n"); fprintf(stderr," -o s (S) | --[no]txsame -- do (not) suppress retransmission on RX intf.\n"); fprintf(stderr," -i | --idinterval -- seconds between ID transmissions\n"); fprintf(stderr," (Use \"-i 0\" to disable IDs)\n"); fprintf(stderr," -t | --tag -- tag text to add to received packets\n"); fprintf(stderr," (Use \"-t -\" to reset to empty)\n"); fprintf(stderr," -B | --bud call|addr -- accept traffic only from matching source.\n"); fprintf(stderr," -b | --nobud call|addr -- deny traffic from matching source.\n"); fprintf(stderr," --dupe interface -- copy traffic from this interface.\n"); fprintf(stderr,"\n"); fprintf(stderr," -p | --port | --interface ax25:port:a1,a2,... -- port name and optional list of aliases\n"); fprintf(stderr," port is from /etc/ax25/axports\n"); fprintf(stderr," (primary callsign is obtained from the port)\n"); fprintf(stderr," -p | --port | --interface udp:address/port/ttl:call,a1,a2... -- IP host,service,ttl,call and optional list of aliases\n"); fprintf(stderr," -p | --port | --interface unix:path:call,a1,a2... -- FIFO filename, call and optional list of aliases\n"); exit(1); } static void usage_udp() { fprintf(stderr,"aprsdigi: Use --int udp:host/service/ttl:callsign,a1,a2,...\n"); fprintf(stderr," example: --int udp:224.1.2.3/1234/127:N2YGK-2,RELAY,WIDE\n"); fprintf(stderr," --int udp:192.168.1.2/1234/16:N2YGK-2,RELAY,WIDE\n"); fprintf(stderr," --int udp:n0clu.ampr.net/1234/16:N2YGK-2,RELAY,WIDE\n"); fprintf(stderr," --int udp:2002:123:45::ab:cd/1234/16:N2YGK-2,RELAY,WIDE\n"); exit(1); } static void usage_ax25() { fprintf(stderr,"aprsdigi: Use --int ax25:port:a1,a2,...\n"); fprintf(stderr," example: --int ax25:1:N2YGK-7,RELAY,WIDE\n"); exit(1); } static void usage_unix() { fprintf(stderr,"aprsdigi: Use --int unix:path:a1,a2,...\n"); fprintf(stderr," example: --int unix:/tmp/fifo:N2YGK-7,RELAY,WIDE\n"); exit(1); } static void usage_budlist() { fprintf(stderr,"aprsdigi: Use --[no]bud ax25:callsign[-SSID]|ip:host|udp:addr[/mask].\n"); fprintf(stderr," \"--bud -\" resets the list to empty\n"); fprintf(stderr," Use callsign-SSID to match specific station.\n"); fprintf(stderr," Use callsign to match all SSIDs.\n"); fprintf(stderr," Use host to match a given IP host.\n"); fprintf(stderr," Use addr/mask to match a given IP range.\n"); fprintf(stderr,"examples: --bud ax25:n0clu-14 -- matches only n0clu-14.\n"); fprintf(stderr," --bud ax25:n0clu -- matches all n0clu's\n"); fprintf(stderr," --bud ip:n0clu.ampr.net -- matches one host.\n"); fprintf(stderr," --bud ip:192.168.5.3 -- matches one host.\n"); fprintf(stderr," --bud ip:192.168.5.3/32 -- matches one host.\n"); fprintf(stderr," --bud ip:192.168.5.0/25 -- matches subnet\n"); fprintf(stderr," --bud ip:fe80::201:3ff:fe9a:38c6 -- matches one host.\n"); fprintf(stderr," --bud ip:fe80::201:3ff:fe9a:38c6/128 -- matches one host.\n"); fprintf(stderr," --bud ip:2002:905::/32 -- matches prefix.\n"); exit(1); } static void usage_dupelist() { fprintf(stderr,"aprsdigi: Use --dupe ax25:interface|udp:addr|unix:file.\n"); fprintf(stderr," \"--dupe -\" resets the list to empty\n"); exit(1); } /* * do_ports: Initialize interfaces. */ static void do_ports() { struct interface *i; ax25_aton_entry("APRS",Aprscall.ax25_call); ax25_aton_entry("WIDE",Widecall.ax25_call); ax25_aton_entry("UDPIP",Udpipcall.ax25_call); ax25_aton_entry("trace",Trace_dummy.ax25_call); if (ax25_config_load_ports() == 0) fprintf(stderr, "aprsdigi: no AX.25 port data configured\n"); for (i = Intf; i < &Intf[N_intf]; i++) { ++i->n_aliases; /* count the zeroth element too! */ switch (i->i_proto) { case P_AX25: do_port_ax25(i); break; case P_UNIX: do_port_unix(i); break; case P_UDP: do_port_udp(i); break; default: fprintf(stderr,"Unknown proto %d\n",i->i_proto); exit(1); break; } } calltab_init(); dupelist_init(); } static void do_port_ax25(struct interface *i) { struct ifreq ifr; int proto = (Testing)?ETH_P_ALL:ETH_P_AX25; if ((i->dev = ax25_config_get_dev(i->port)) == NULL) { fprintf(stderr, "aprsdigi: invalid ax25 port name - %s\n", i->port); exit(1); } i->devname = strdup(i->port); i->rsa_size = i->tsa_size = sizeof(struct sockaddr_ax25); if (!(i->i_flags & I_TX)) { i->tsock = -1; } else { /* open transmit socket */ if ((i->tsock = socket(AF_PACKET, SOCK_PACKET, htons(proto))) == -1) { die(i->port); } strcpy(((struct sockaddr*)&i->tsa)->sa_data, i->dev); ((struct sockaddr *)&i->tsa)->sa_family = AF_AX25; } if (!(i->i_flags & I_RX)) { i->rsock = -1; } else { /* open receive socket */ if ((i->rsock = socket(AF_PACKET, SOCK_PACKET, htons(proto))) == -1) { die(i->port); } strcpy(((struct sockaddr *)&i->rsa)->sa_data, i->dev); ((struct sockaddr *)&i->rsa)->sa_family = AF_AX25; if (bind(i->rsock, (struct sockaddr *)&i->rsa, i->rsa_size) < 0) { die(i->devname); } } /* set mycall (zeroth alias) to the port's */ strcpy(ifr.ifr_name, i->dev); /* get this port's callsign */ if (ioctl(i->rsock, SIOCGIFHWADDR, &ifr) < 0) { die(i->devname); } if (ifr.ifr_hwaddr.sa_family != AF_AX25) { fprintf(stderr,"%s: not AX25\n",i->port); exit(1); } bcopy(ifr.ifr_hwaddr.sa_data,I_MYCALL(i).ax25_call,sizeof(I_MYCALL(i).ax25_call)); I_MYCALL(i).ax25_call[ALEN] |= ESSID_SPARE|SSSID_SPARE; } static void do_port_udp(struct interface *i) { struct hostent *hp; struct servent *sp; char *name, *service, *ttl; const int one=1; int ttlval; struct addrinfo *ai, hints = {0, PF_UNSPEC, SOCK_DGRAM, 0}; /* hostname/service(port)/ttl */ i->dev = i->port; name = i->port; service = strchr(name,'/'); if (!service || *service != '/') usage_udp(); // *service++ = '\0'; ttl = strchr(&service[1],'/'); if (!ttl || *ttl != '/') usage_udp(); *ttl++ = '\0'; i->devname = strdup(name); *service++ = '\0'; if ((ttlval = atoi(ttl)) <= 0) usage_udp(); if (Verbose) fprintf(stderr,"opening UDP socket on %s/%s/%d\n", name, service, ttlval); if (getaddrinfo(name,service,&hints,&ai) < 0) die(name); if (Verbose) fprintf(stderr,"UDP address info: family %d type %d proto %d next 0x%0x\n", ai->ai_family,ai->ai_socktype,ai->ai_protocol,ai->ai_next); if (ai->ai_socktype != SOCK_DGRAM) { die("getaddrinfo returned non SOCK_DGRAM!\n"); } if (!(i->i_flags & I_TX)) { i->tsock = -1; } else { if ((i->tsock = socket(ai->ai_family, SOCK_DGRAM, 0)) == -1) die(name); if (setsockopt(i->tsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) die(i->port); if (ai->ai_family == AF_INET) { /* IPv4 */ i->tsa_size = sizeof(struct sockaddr); if (IN_MULTICAST(ntohl(((struct sockaddr_in*)ai->ai_addr)->sin_addr.s_addr))) { if (setsockopt(i->tsock, SOL_IP, IP_MULTICAST_TTL, &ttlval, sizeof(ttlval)) < 0) die(i->port); } else { if (setsockopt(i->tsock, SOL_IP, IP_TTL, &ttlval, sizeof(ttlval)) < 0) die(i->port); } #ifdef IPV6 } else if (ai->ai_family == AF_INET6) { /* IPv6 */ i->tsa_size = sizeof(struct sockaddr_storage); /* XXX ??? */ #endif /* IPV6 */ } else { fprintf(stderr,"%s: unsupported protocol family\n",i->port); exit(1); } bzero(&i->tsa,sizeof(i->tsa)); bcopy((struct sockaddr*)ai->ai_addr,&i->tsa,sizeof(i->tsa)); /* fill sockaddr w/sockaddr_in */ if (connect(i->tsock, (struct sockaddr *)&i->tsa, i->tsa_size) < 0) { die(i->devname); } } /* now the receive socket */ if (!(i->i_flags & I_RX)) { i->rsock = -1; } else { if ((i->rsock = socket(ai->ai_family, SOCK_DGRAM, 0)) == -1) { die(i->port); } if (setsockopt(i->rsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) die(i->port); if (ai->ai_family == AF_INET && !IN_MULTICAST(ntohl(((struct sockaddr_in*)ai->ai_addr)->sin_addr.s_addr))) { ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr = INADDR_ANY; /* not mcast so wildcard listen */ i->rsa_size = sizeof(struct sockaddr); #ifdef IPV6 } else if (ai->ai_family == AF_INET6) { /* IPv6 */ /* XXX ??? */ #endif /* IPV6 */ } i->rsa_size = sizeof(struct sockaddr_storage); bzero(&i->rsa,sizeof(i->rsa)); bcopy((struct sockaddr*)ai->ai_addr,&i->rsa,sizeof(i->rsa)); if (bind(i->rsock, (struct sockaddr *)&i->rsa, i->rsa_size) < 0) { die(i->devname); } /* if the UDP socket is a multicast group, then do IGMP join for rsock */ if (ai->ai_family == AF_INET && IN_MULTICAST(ntohl(((struct sockaddr_in*)ai->ai_addr)->sin_addr.s_addr))) { struct ip_mreq mreq; mreq.imr_multiaddr = ((struct sockaddr_in*)ai->ai_addr)->sin_addr; mreq.imr_interface.s_addr = INADDR_ANY; if (setsockopt(i->rsock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) die(i->port); #ifdef IPV6 } else if (ai->ai_family == AF_INET6) { /* IPv6 */ /* XXX ??? */ #endif /* IPV6 */ } } } static void do_port_unix(struct interface *i) { const int one=1; struct sockaddr_un *sun; char name[sizeof(sun->sun_path)]; i->dev = i->port; i->devname = strdup(i->dev); strncpy(name,i->dev,sizeof(name)); i->rsa_size = i->tsa_size = sizeof(struct sockaddr_un); /* the receive socket */ if (!(i->i_flags & I_RX)) { i->rsock = -1; } else { if (Verbose) fprintf(stderr,"opening RX FIFO socket on %s\n", name); if ((i->rsock = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) { die(name); } bzero(&i->rsa,sizeof(i->rsa)); sun = (struct sockaddr_un *)&i->rsa; sun->sun_family = AF_UNIX; strncpy(sun->sun_path,name,sizeof(sun->sun_path)); /* create the fifo if it doesn't already exist */ if (bind(i->rsock, (struct sockaddr *)&i->rsa, i->rsa_size) < 0 && errno != EADDRINUSE) { die(name); } } /* the transmit socket */ if (!(i->i_flags & I_TX)) { i->tsock = -1; } else { if (Verbose) fprintf(stderr,"opening TX FIFO socket on %s\n", name); if ((i->tsock = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) { die(name); } bzero(&i->tsa,sizeof(i->tsa)); sun = (struct sockaddr_un *)&i->tsa; sun->sun_family = AF_UNIX; strncpy(sun->sun_path,name,sizeof(sun->sun_path)); if (setsockopt(i->tsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) die(i->port); } } static void set_sig() { signal(SIGHUP,cleanup); signal(SIGINT,cleanup); signal(SIGQUIT,cleanup); signal(SIGTERM,cleanup); signal(SIGPWR,cleanup); signal(SIGPIPE,cleanup); signal(SIGUSR1,print_stats); signal(SIGUSR2,reset_stats); signal(SIGALRM,identify); } /* * compare two ax.25 "flooding" addresses. * returns: floodtype * args: f is the known flood call prefix, len is its len. * c is what we are testing against it to see if it is * flood, floodN, or none. */ static int floodcmp(ax25_address *f, int len, ax25_address *c) { int i; for (i = 0; i < len; i++) if ((f->ax25_call[i] & 0xFE) != (c->ax25_call[i] & 0xFE)) return C_IS_NOFLOOD; return floodtype(c,i); } /* * floodtype: Is it a flood, or floodN, or not a flood at all? * The call should have blanks in the remainder * (e.g. WIDE-3), or a single digit followed by blanks * (WIDE3-3). If it has other junk then is is not a flood (WIDENED). */ static int floodtype(ax25_address *c, int i) { int dig = (c->ax25_call[i]&0xFE)>>1; if (dig == ' ') return C_IS_FLOOD; else if (dig >= '0' && dig <= '9' && ((i>=5) || (c->ax25_call[i+1] & 0xFE)>>1 == ' ')) return C_IS_FLOOD|C_IS_FLOODN; else return C_IS_NOFLOOD; } #define DEVTYPE(i) ((i)->i_proto == P_UDP)?"udp":\ ((i)->i_proto == P_AX25)?"ax25":\ ((i)->i_proto == P_UNIX)?"unix":"???" static void check_config() { int n, j; struct callsign_list *cl; printf("Linux APRS(tm) digipeater\n%s\n",copyr); printf("Version: aprsdigi %s-%s\n",PACKAGE,VERSION); printf("This is free software covered under the GNU General Public License.\n"); printf("There is no warranty. See the file COPYING for details.\n\n"); config_print(stdout); printf("My callsigns and aliases (routing table):\n"); printf("Callsign Interfaces...\n"); for (cl = calltab; cl; cl = cl->next) { struct interface_list *l; char t[10]; strcpy(t,ax25_ntoa_pretty(cl->callsign)); if (cl->flags&C_IS_FLOOD) strcat(t,"n-n"); /* indicate a WIDEn-n */ printf("%-9.9s",t); for (l = cl->l; l; l = l->next) { printf(" %s:%s",DEVTYPE(l->i),l->i->devname); } printf("\n"); } if (N_floods == 0) printf("No flooding callsigns\n"); if (Have_digipath) { printf("SSID-based omnidirectional routing:\n"); if (N_floods) { /* doing WIDEn-n so this won't get used */ fprintf(stderr,"ERROR: -d is inconsistent with WIDEn-n flooding\n"); exit(1); } if (intf_of(&Digipath[0]) == NULL) { fprintf(stderr,"ERROR: %s: first callsign in omni route is not one of my callsigns.\n", ax25_ntoa_pretty(&Path[n].fsa_digipeater[0])); exit(1); } for (j = 0; j < DIGISIZE; j++) { printf("%-9.9s ",ax25_ntoa_pretty(&Digipath[j])); } printf("\n"); } if (Digi_SSID) { printf("SSID-based directional routing:\n"); for (n = 0; n < 4; n++) { if (intf_of(&Path[n].fsa_digipeater[0]) == NULL) { fprintf(stderr,"ERROR: %s: first callsign in %c route is not one of my callsigns.\n", ax25_ntoa_pretty(&Path[n].fsa_digipeater[0]),Dirs[n]); exit(1); } printf("\n%c: ",Dirs[n]); for (j = 0; j < Path[n].fsa_ax25.sax25_ndigis; j++) printf("%-9.9s ",ax25_ntoa_pretty(&Path[n].fsa_digipeater[j])); } printf("\n"); } else { printf("SSID-based routing: (none)\n"); } /* flags */ printf("keep dupes for: %d seconds\n",Keep); printf("log file: %s\n",(Logfile)?Logfile:"(none)"); #define onoff(x) (x)?"ON":"OFF" printf("kill dupes: %s loops: %s testing: %s\n", onoff(Kill_dupes), onoff(Kill_loops), onoff(Testing)); #undef onoff fflush(stdout); } static void config_print(FILE *f) { struct interface *i; int n, j; fprintf(f,"# configuration:\n"); budlist_print_all(f); dupelist_print_all(f); for (i = Intf, n = 0; n < N_intf; i++,n++) { fprintf(f,"interface %s:%s\n", DEVTYPE(i),i->devname); fprintf(f," callsign %s\n",ax25_ntoa_pretty(&i->aliases[0])); for (j = 1; j < i->n_aliases; j++) { fprintf(f," alias %s\n",ax25_ntoa_pretty(&i->aliases[j])); } #define onoff(opt) fprintf(f," option %s %s\n",(#opt),((i->i_flags&(opt))?("on"):("off"))) onoff(SUBST_MYCALL); onoff(MICE_XLATE); onoff(X1J4_XLATE); onoff(I_TX); onoff(I_RX); onoff(I_TXSAME); onoff(I_3RDP); #undef onoff fprintf(f," option idinterval %d #(%02d:%02d)\n",i->idinterval, i->idinterval/60,i->idinterval%60); fprintf(f," option tag %s\n",(i->taglen)?i->tag:"#(none)"); if (i->bud) fprintf(f," budlist %d\n",i->bud->bl_list_no); if (i->dupe && i->dupe->dl_ent_head) fprintf(f," dupelist %d\n",i->dupe->dl_list_no); } fprintf(f,"# end of configuration\n\n"); } /* * budlist's can be "global" or per-interface. Basically, the * budlist is built up with -B|-b's prior to the interface's -p * and then these get glued to the per-interface budlist. To * reset the budlist between ports, use "-B -". */ static void budlist_add(char *item,int permit) { struct sockaddr_in *sin, *sinmask; struct sockaddr_in6 *sin6, *sin6mask; struct sockaddr_ax25 *sinax25, *sinax25mask; struct budlist_entry *e; if (!item || !*item) usage_budlist(); if (!Bl_head) { /* this is first invocation */ Bl_head = Bl_last = (struct budlist *)calloc(1,sizeof(struct budlist)); if (!Bl_head) die("malloc"); Bl_head->bl_list_no = 1; } if (item[0] == '-' && item[1] == '\0') { /* start a new list */ if (Bl_last->bl_ent_last) { /* if the list has entries... */ /* ... start a new list */ Bl_last->bl_next = (struct budlist *)calloc(1,sizeof(struct budlist)); if (!Bl_last->bl_next) die("malloc"); Bl_last->bl_next->bl_list_no = Bl_last->bl_list_no+1; Bl_last = Bl_last->bl_next; } return; } if (!Bl_last->bl_ent_head) { /* list has no elements yet */ Bl_last->bl_ent_head = Bl_last->bl_ent_last = (struct budlist_entry *)calloc(1,sizeof(struct budlist_entry)); if (!Bl_last->bl_ent_head) die("malloc"); } else if (!Bl_last->bl_ent_last->be_next) { /* alloc a new entry */ Bl_last->bl_ent_last->be_next = (struct budlist_entry *)calloc(1,sizeof(struct budlist_entry)); if (!Bl_last->bl_ent_last->be_next) die("malloc"); Bl_last->bl_ent_last = Bl_last->bl_ent_last->be_next; } /* done with all that allocation foolishness */ e = Bl_last->bl_ent_last; e->be_permit = permit; if (!strcasecmp(item,"any")) { bzero(&e->be_addr,sizeof(e->be_addr)); setmask(8*sizeof(e->be_mask), (u_char *)&e->be_mask); e->be_maskbits = -1; } else if (strncasecmp(item,"ax25:",5) == 0) { char *name; struct sockaddr_ax25 *call = (struct sockaddr_ax25 *)&e->be_addr; struct sockaddr_ax25 *callmask = (struct sockaddr_ax25 *)&e->be_mask; name = &item[5]; bzero(&e->be_addr,sizeof(e->be_addr)); if (ax25_aton_entry(name,call->sax25_call.ax25_call) < 0) die(item); call->sax25_family = AF_AX25; call->sax25_ndigis = 0; /* set maskbits as follows: * if callsign then mask the 6 bytes containing the call. * if callsign-SSID then mask all 7. */ bzero(&e->be_mask,sizeof(e->be_mask)); e->be_maskbits = (strchr(name,'-'))? 7*8 : 6*8; setmask(8*sizeof(call->sax25_family), (u_char *)&callmask->sax25_family); setmask(e->be_maskbits, (u_char *)callmask->sax25_call.ax25_call); } else if (strncasecmp(item,"ip:",3) == 0) { struct addrinfo *ai, hints = {0, PF_UNSPEC, SOCK_DGRAM, 0}; char *name, *mask; e->be_maskbits = 0; name = &item[3]; if (mask = strrchr(name,'/')) { *mask++ = '\0'; e->be_maskbits = atoi(mask); } if (getaddrinfo(name,NULL,&hints,&ai) < 0) die(item); bzero(&e->be_mask,sizeof(e->be_mask)); bcopy(ai->ai_addr,&e->be_addr,ai->ai_addrlen); switch (ai->ai_family) { case AF_INET: /* IPv4 */ sin = (struct sockaddr_in *)&e->be_addr; sinmask = (struct sockaddr_in *)&e->be_mask; if (e->be_maskbits == 0) e->be_maskbits = 32; /* sockaddr_in bitmask: sin_family all ones; sin_port all zeros; sin_addr specified number of ones */ setmask(8*sizeof(sin->sin_family), (u_char *)&sinmask->sin_family); setmask(e->be_maskbits, (u_char *)&sinmask->sin_addr); break; case AF_INET6: /* IPv6 */ sin6 = (struct sockaddr_in6 *)&e->be_addr; sin6mask = (struct sockaddr_in6 *)&e->be_mask; if (e->be_maskbits == 0) e->be_maskbits = 128; /* sockaddr_in6 bitmask: sin6_family ones; sin6_port zeros; sin6_flowinfo zeros; sin6_addr specified; sin6_scope_id zeros */ setmask(8*sizeof(sin6->sin6_family), (u_char *)&sin6mask->sin6_family), setmask(e->be_maskbits,(u_char *)&sin6mask->sin6_addr); break; default: fprintf(stderr,"%s: Unsupported protocol family (%d)\n",name,ai->ai_family); exit(1); } freeaddrinfo(ai); } else usage_budlist(); } static void budlist_print_all(FILE *f) { struct budlist *l; for (l = Bl_head; l; l=l->bl_next) budlist_print(f,l); } static void budlist_print(FILE *f, struct budlist *bud) { char host[1000]; struct sockaddr_in *sin; struct sockaddr_in6 *sin6; struct sockaddr_ax25 *sinax25; struct budlist_entry *b; if (!bud || !bud->bl_ent_head) return; for (b = bud->bl_ent_head; b; b = b->be_next) { printaddr(&b->be_addr,host,sizeof(host)); fprintf(f," budlist %d %s %s",bud->bl_list_no, (b->be_permit)?"permit":"deny",host); if (b->be_maskbits>=0) fprintf(f,"/%d\n",b->be_maskbits); else fprintf(f,"\n"); } } static void printaddr(struct sockaddr_storage *s, char *buf, int buflen) { struct sockaddr_in *sin = (struct sockaddr_in *)s; struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)s; struct sockaddr_ax25 *sinax25 = (struct sockaddr_ax25 *)s; switch (sin->sin_family) { case AF_INET: inet_ntop(sin->sin_family,&sin->sin_addr, buf, buflen); break; case AF_INET6: inet_ntop(sin6->sin6_family,&sin6->sin6_addr, buf, buflen); break; case AF_AX25: strncpy(buf,ax25_ntoa_pretty(&sinax25->sax25_call),buflen); break; case 0: strncpy(buf,"any",buflen); break; default: strncpy(buf,"???",buflen); break; } } /* * Is this packet permitted by budlist? * 1. Check (possibly IP) source address * 2. Check AX25 source callsign * 3. Check intermediate repeated digis * First match wins. */ int budlist_permit(struct stuff *s) { struct budlist_entry *be; struct interface *i = s->i; char testhost[200],host[200]; int j; if (!s->i->bud || !s->i->bud->bl_ent_head) /* no budlist */ return 1; /* permitted */ for (be = s->i->bud->bl_ent_head; be; be = be->be_next) { struct sockaddr_ax25 *be25 = (struct sockaddr_ax25 *)&be->be_addr; struct sockaddr_ax25 *bemask = (struct sockaddr_ax25 *)&be->be_mask; /* 1: check source address */ if (Verbose) { printaddr(&be->be_addr,testhost,sizeof(testhost)); printaddr(&i->rsafrom,host,sizeof(host)); fprintf(stderr,"budlist_permit: budlist %d %s %s/%d vs. net source %s\n", s->i->bud->bl_list_no, (be->be_permit)?"permit":"deny", testhost, be->be_maskbits, host); } if (cmpmask(8*sizeof(be->be_addr), (u_char *)&be->be_addr, (u_char *)&be->be_mask, (u_char *)&i->rsafrom) == 0) return be->be_permit; /* 2: check ax25 from call. */ if (be25->sax25_family != AF_AX25) continue; /* no need to compare non-ax25 buds */ if (Verbose) { fprintf(stderr,"budlist_permit: budlist %d %s %s/%d vs. ax25 source %s\n", s->i->bud->bl_list_no, (be->be_permit)?"permit":"deny", testhost, be->be_maskbits, ax25_ntoa_pretty(&s->in.ax_from_call)); } if (cmpmask(be->be_maskbits, (u_char *)&be25->sax25_call.ax25_call, (u_char *)&bemask->sax25_call.ax25_call, (u_char *)&s->in.ax_from_call) == 0) return be->be_permit; /* 3. check ax25 digis. */ for (j = 0; j < s->in.ax_next_digi-1; j++) { if (Verbose) { fprintf(stderr,"budlist_permit: budlist %d %s %s/%d vs. ax25 digi[%d] %s\n", s->i->bud->bl_list_no, (be->be_permit)?"permit":"deny", testhost, be->be_maskbits, j, ax25_ntoa_pretty(&s->in.ax_digi_call[j])); } if (cmpmask(be->be_maskbits, (u_char *)&be25->sax25_call.ax25_call, (u_char *)&bemask->sax25_call.ax25_call, (u_char *)&s->in.ax_digi_call[j]) == 0) return be->be_permit; } } return 1; /* permit */ } static void setmask(int bits, u_char *mask) { int B,b,rem; for (B = 0; B < bits/8; B++) { mask[B] |= 0xff; } for (b = 0, rem = 0; b < bits%8; b++) { rem = rem >> 1; rem |= 0x80; } mask[B] = rem; } static int cmpmask(int bits, u_char *val1, u_char *mask, u_char *val2) { int B,bytes; bytes = bits/8; if (bits%8) ++bytes; for (B = 0; B < bytes; B++) { if ((val1[B] & mask[B]) != (val2[B] & mask[B])) return val1[B] - val2[B]; } return 0; } /* gee, this looks like a copy of budlist. I should make a class. */ static void dupelist_add(char *item) { struct dupelist_entry *e; if (!item || !*item) usage_dupelist(); ++Doing_dupes; if (!Dl_head) { /* this is first invocation */ Dl_head = Dl_last = (struct dupelist *)calloc(1,sizeof(struct dupelist)); if (!Dl_head) die("malloc"); Dl_head->dl_list_no = 1; } if (item[0] == '-' && item[1] == '\0') { /* start a new list */ if (Dl_last->dl_ent_last) { /* if the list has entries... */ /* ... start a new list */ Dl_last->dl_next = (struct dupelist *)calloc(1,sizeof(struct dupelist)); if (!Dl_last->dl_next) die("malloc"); Dl_last->dl_next->dl_list_no = Dl_last->dl_list_no+1; Dl_last = Dl_last->dl_next; } return; } if (!Dl_last->dl_ent_head) { /* list has no elements yet */ Dl_last->dl_ent_head = Dl_last->dl_ent_last = (struct dupelist_entry *)calloc(1,sizeof(struct dupelist_entry)); if (!Dl_last->dl_ent_head) die("malloc"); } else if (!Dl_last->dl_ent_last->de_next) { /* alloc a new entry */ Dl_last->dl_ent_last->de_next = (struct dupelist_entry *)calloc(1,sizeof(struct dupelist_entry)); if (!Dl_last->dl_ent_last->de_next) die("malloc"); Dl_last->dl_ent_last = Dl_last->dl_ent_last->de_next; } /* done with all that allocation foolishness */ e = Dl_last->dl_ent_last; e->de_dev = item; } static void dupelist_print_all(FILE *f) { struct dupelist *l; for (l = Dl_head; l; l=l->dl_next) dupelist_print(f,l); } static void dupelist_print(FILE *f, struct dupelist *dupe) { char host[1000]; struct dupelist_entry *l; if (!dupe || !dupe->dl_ent_head) return; for (l = dupe->dl_ent_head; l; l = l->de_next) { fprintf(f," dupelist %d %s\n",dupe->dl_list_no,l->de_dev); } } static void add_intflist(struct interface_list **il, struct interface *i); /* * dupelist_init: Take dupelist from i->dupe, search for interfaces * with matching names and add them to i->dupe->dl_il. Do not add own * interface. */ static void dupelist_init() { struct dupelist_entry *de; struct dupelist *dl; struct interface *i,*j; int n; for (i = Intf; i < &Intf[N_intf]; i++) { if (i->dupe) { /* walk all entries in this list */ for (de = i->dupe->dl_ent_head; de; de = de->de_next) { char devname[100]; /* search for an interface name that matches */ for (j = Intf, n = 0; n < N_intf; j++,n++) { sprintf(devname,"%s:%s",DEVTYPE(j),j->devname); if (Verbose) fprintf(stderr,"dupelist_init: comparing %s to %s...\n", de->de_dev,devname); if ((strcasecmp(devname,de->de_dev) == 0) && j != i) { if (Verbose) fprintf(stderr," ... matched. Adding to interface list\n"); add_intflist(&i->dupe->dl_il,j); /* add j to dupe interface list */ break; } } if (n >= N_intf) { /* search fell through */ fprintf(stderr,"warning: dupelist %d interface %s not found.\n", i->dupe->dl_list_no,de->de_dev); } } } } } /* * add_intflist: Add an interface to an interface list. */ static void add_intflist(struct interface_list **il, struct interface *i) { struct interface_list *n = calloc(1,sizeof(struct interface_list)); if (n == NULL) die("malloc"); n->i = i; if (*il == NULL) *il = n; else { for (; (*il)->next; (*il) = (*il)->next) ; (*il)->next = n; } } /* * 3rd party tunneling per APRS spec 1.01 Ch. 17 * * What I implement is what I will call "transparent" tunneling. * For APRS 1.0 compatibility, need to implement "3rd party" tunneling: * 0. 3rd party only applies when input and output intfs are different. * 1. Make 3rdparty an option so I can do transparent tunneling too. * 2. For transmit to a 3rdparty intf: just drop unusused digipeaters. * 3. For transmit to any intf when pkt is received from a 3rdparty intf: * a. drop unused digipeaters (in case the sender didn't) * b. append Third-Party Network ID (Use UDPIP) followed by the xmit * intf callsign (MYCALL(i)) to digi list, marked as repeated. * c. Spit out "}" and then gen_cooked_ax25() (the Source Path * Header) into the payload, followed by the original payload. * d. Rewrite the raw ax25 header with a from_call of MYCALL, and no * digipeat path(!). * e. xmit on the ax25 interface(s). * Editorial note: Tunneling was implemented this way because the APRS * authors were using hardware TNC-2's in CONVerse mode and were unable to * modify the real AX.25 headers the way I can. */ /* removed non-repeated digipeaters */ static void drop_unused_digis(struct ax_calls *calls) { if (!calls->ax_n_digis || calls->ax_next_digi >= calls->ax_n_digis) return; /* all digis are used up */ if ((calls->ax_n_digis = calls->ax_next_digi) > 0) { /* truncate the list */ calls->ax_digi_call[calls->ax_next_digi-1].ax25_call[ALEN] |= HDLCAEB; } else { /* no digis left */ calls->ax_from_call.ax25_call[ALEN] |= HDLCAEB; } if (Verbose) fprintf(stderr,"3rd party: Unused digis have been dropped.\n"); } /* * from_3rdparty: generates the source path header and insert it into * the list of packet payloads in pkt[]. * clobbers the s->out digipeater list as well. */ static void from_3rdparty(struct stuff *s, int npkts, /* dimension of the next two vectors */ u_char *pkt[], /* output buffers for source path header */ int pktl[]) /* output length of sph (AX25_MTU max) */ { u_char pref[AX25_MTU], *pp; int j, plen, rem; /* a. drop unused digipeaters (in case the sender didn't) */ drop_unused_digis(&s->out); /* b. append Third-Party Network ID (Use UDPIP) ... */ /* XXX fencepost check */ if (s->out.ax_n_digis >= AX25_MAX_DIGIS-1) { if (Verbose) fprintf(stderr,"%s: 3rd party digi list overflow. First 2 digis dropped.\n", s->i->port); for (j = 2; j < s->out.ax_n_digis; j++) s->out.ax_digi_call[j - 2] = s->out.ax_digi_call[j]; s->out.ax_n_digis -= 2; s->out.ax_next_digi -= 2; } s->out.ax_digi_call[s->out.ax_n_digis] = Udpipcall; s->out.ax_digi_call[s->out.ax_n_digis].ax25_call[ALEN] |= REPEATED; /* ... followed by the xmit intf callsign (MYCALL(i)) ... */ s->out.ax_digi_call[s->out.ax_n_digis+1] = I_MYCALL(s->i); s->out.ax_digi_call[s->out.ax_n_digis+1].ax25_call[ALEN] |= REPEATED|HDLCAEB; s->out.ax_n_digis += 2; s->out.ax_next_digi += 2; /* c. Spit out "}" and then gen_cooked_ax25() (the Source Path Header) into the payload, followed by the original payload. */ plen = 0; pref[plen++] = '}'; rem = AX25_MTU - plen; pp = &pref[1]; gen_cooked_ax25(&pp,&rem,&s->out); /* generate the source path header */ plen = AX25_MTU - rem + 1; /* XXX??? */ /* for each payload, insert the prefix in front of it! */ for (j = 0; j < npkts; j++) { /* may have to repeat for multiple pkts */ u_char *oldp = pkt[j]; if (pktl[j]) { if (pktl[j] + plen > AX25_MTU) { pktl[j] -= AX25_MTU-pktl[j]-plen; if (Verbose) fprintf(stderr,"%s: Oversized 3rd party detunneled packet truncated.\n", s->i->port); } bcopy(pkt[j],&pref[plen-1],pktl[j]); /* tag vecp onto end of pref. */ bcopy(pref,pkt[j],pktl[j]+=plen-1); /* not sure why this is -1 */ pref[plen] = '\0'; } } /* d. Rewrite the raw ax25 header with a from_call of MYCALL, and no * digipeat path(!). */ s->out.ax_n_digis = s->out.ax_next_digi = 0; s->out.ax_from_call.ax25_call[ALEN] |= HDLCAEB; s->out.ax_from_call = I_MYCALL(s->i); } static void to_3rdparty(struct ax_calls *calls) { drop_unused_digis(calls); /* just drop unused digipeaters */ } aprsdigi-3.10.0/aprsdigi.init000077500000000000000000000050341254600523400160720ustar00rootroot00000000000000#!/bin/sh # aprsdigi - This is the init script for starting up the APRS digipeater # Also starts beacon. # # chkconfig: 345 52 48 # description: starts and stops the aprsdigi APRS digipeater # processname: aprsdigi # pidfile: /var/run/aprsdigi.pid # # Source function library. . /etc/init.d/functions # Find the name of the script NAME=`basename $0` if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ] then NAME=${NAME:3} fi # For SELinux we need to use 'runuser' not 'su' if [ -x /sbin/runuser ] then SU=runuser else SU=su fi APRSDIGI="/usr/sbin/aprsdigi" BEACON="/usr/sbin/beacon" APRSDIGI_CONF="/etc/ax25/aprsdigi.conf" APRSDIGI_PIDFILE="/var/run/aprsdigi.pid" BEACON_PIDFILE="/var/run/beacon.pid" APRSDIGI_LOCKFILE="/var/lock/subsys/aprsdigi" BEACON_LOCKFILE="/var/lock/subsys/beacon" . ${APRSDIGI_CONF} script_result=0 # start - runs beacon and aprsdigi if conf files are found. start_beacon(){ BEACON_START="Starting ${NAME} beacon: " if [ -x "${BEACON}" -a -f "${APRSDIGI_CONF}" ] then echo -n "${BEACON_START}" ${BEACON} -d "${BEACON_DEST}" ${BEACON_PORT} "${BEACON_TEXT}" && success || failure retval=$? echo [ $retval -eq 0 ] && { touch ${BEACON_LOCKFILE} success } || failure fi return $retval } start_aprsdigi(){ APRSDIGI_START="Starting ${NAME} digipeater: " if [ -x "${APRSDIGI}" -a -f "${APRSDIGI_CONF}" ] then echo -n "${APRSDIGI_START}" ${APRSDIGI} ${APRSDIGI_OPTS} >/dev/null & retval=$? echo [ $retval -eq 0 ] && { touch ${APRSDIGI_LOCKFILE} success } || failure fi return $retval } start(){ start_beacon start_aprsdigi # don't care if beacon failed; aprsdigi should still start } stop_beacon(){ echo -n $"Stopping ${NAME} beacon: " killproc ${BEACON} retval=$? echo [ $retval -eq 0 ] && rm -f ${BEACON_LOCKFILE} return $retval } stop_aprsdigi(){ echo -n $"Stopping ${NAME} digipeater: " killproc ${APRSDIGI} retval=$? echo [ $retval -eq 0 ] && rm -f ${APRSDIGI_LOCKFILE} return $retval } stop(){ stop_beacon stop_aprsdigi } check_status_aprsdigi(){ status ${APRSDIGI} } check_status_beacon(){ status ${BEACON} } check_status(){ check_status_beacon check_status_aprsdigi } restart(){ stop start } case "$1" in start) start ;; stop|condstop) stop ;; status) check_status script_result=$? ;; restart|condrestart|reload|force-reload) restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|condstop|reload|force-reload}" exit 1 esac exit $script_result aprsdigi-3.10.0/aprsdigi.logrotate000066400000000000000000000001421254600523400171170ustar00rootroot00000000000000/var/log/aprsdigi.log { missingok compress weekly notifempty delaycompress } aprsdigi-3.10.0/aprsdigi.lsm000066400000000000000000000014111254600523400157120ustar00rootroot00000000000000Begin3 Title: aprsdigi Version: 2.4.1 Entered-date: 28 Dec 01 Description: Aprsdigi is a specialized Amateur Packet Radio (AX.25) UI-frame digipeater for the Automatic Position Reporting System, APRS(tm). Aprsmon collects and displays standard AX.25 UI text frames in a format similar to that output by a standard TNC in "Monitor ON" mode and is intended to be used with programs like javAPRS which wish to see a TNC data stream over a TCP connection. Keywords: AX.25 APRS Amateur Radio Author: n2ygk@weca.org (Alan Crosswell) Maintained-by: n2ygk@weca.org (Alan Crosswell) Primary-site: http://www.cloud9.net/~alan/ham/aprsdigi-2.4.1.tar.gz Alternate-site: ftp://ftp.tapr.org/aprssig/linux/aprsdigi-2.4.1.tar.gz Original-site: Copying-policy: GPL. End aprsdigi-3.10.0/aprsdigi.service000066400000000000000000000004761254600523400165710ustar00rootroot00000000000000[Unit] Description=APRS digipeater Documentation=man:aprsdigi(8) http://aprsdigi.sf.net Wants=aprsbeacon.service After=soundmodem.service [Service] EnvironmentFile=/etc/ax25/aprsdigi.conf ExecStart=/usr/sbin/aprsdigi $APRSDIGI_CFG StandardOutput=syslog [Install] WantedBy=multi-user.target Also=aprsbeacon.service aprsdigi-3.10.0/aprsdigi.spec.in000066400000000000000000000060241254600523400164630ustar00rootroot00000000000000Summary: AX.25 Automatic Position Reporting System aprsdigi and aprsmon Name: aprsdigi Version: @VERSION@ Release: 7 License: GPLv2+ Group: Applications/Communications Source: https://github.com/n2ygk/aprsdigi/archive/v%{version}.tar.gz Url: https://github.com/n2ygk/aprsdigi Requires: libax25 >= 0.0.7, systemd, logrotate BuildRequires: systemd-units, libax25-devel, automake, autoconf %changelog * Sat Jun 20 2015 Alan Crosswell - update to reflect hosting at github.com - add automake, autoconf to BuildRequires - add logrotate to Requires * Sun Sep 23 2012 Alan Crosswell - add libax25-devel to BuildRequires - make the spec file pass rpmlint * Sat Sep 08 2012 Alan Crosswell - Update to reflect hosting at sourceforge.net - Track changes to rpm SPEC specs! - Add systemd-based aprsdigi.service & aprsbeacon.service and remove aprsdigi.init - Add logrotate * Fri Aug 29 2009 Alan Crosswell - Update to use configure to set version, install initscript. * Fri Dec 28 2001 Alan Crosswell - Try to make a new RPM, but first need to find RPMs for libax25. * Mon Apr 05 1999 Alan Crosswell - Initial rpm %description Aprsdigi is a specialized Amateur Packet Radio (AX.25) UI-frame digipeater for the Automatic Position Reporting System, APRS(tm). Aprsmon collects and displays standard AX.25 UI text frames in a format similar to that output by a standard TNC in "Monitor ON" mode and is intended to be used with programs like javAPRS which wish to see a TNC data stream over a TCP connection. %prep %setup -q -n aprsdigi-%{version} %build aclocal automake --add-missing autoconf ./configure make %install rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install install -D -m 644 aprsdigi.service ${RPM_BUILD_ROOT}%{_unitdir}/aprsdigi.service install -D -m 644 aprsbeacon.service ${RPM_BUILD_ROOT}%{_unitdir}/aprsbeacon.service install -D -m 644 aprsdigi.logrotate ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/aprsdigi %clean rm -rf $RPM_BUILD_ROOT %post if [ $1 -eq 1 ] ; then %{_bindir}/systemctl enable aprsdigi.service >/dev/null 2>&1 || : %{_bindir}/systemctl enable aprsbeacon.service >/dev/null 2>&1 || : fi %preun if [ $1 -eq 0 ]; then %{_bindir}/systemctl -q disable aprsdigi.service >/dev/null 2>&1 || : %{_bindir}/systemctl -q stop aprsdigi.service >/dev/null 2>&1 || : %{_bindir}/systemctl -q disable aprsbeacon.service >/dev/null 2>&1 || : %{_bindir}/systemctl -q stop aprsbeacon.service >/dev/null 2>&1 || : fi %postun if [ $1 -ge 1 ] ; then %{_bindir}/systemctl daemon-reload >/dev/null 2>&1 || : %{_bindir}/systemctl -q try-restart aprsdigi.service >/dev/null 2>&1 || : %{_bindir}/systemctl -q try-estart aprsbeacon.service >/dev/null 2>&1 || : fi %files %doc README %doc INSTALL %doc COPYING %doc NEWS %doc ChangeLog %doc TODO %doc AUTHORS %doc aprsdigi.lsm %doc examples %{_sbindir}/aprsdigi %{_sbindir}/aprsmon %{_unitdir}/aprsbeacon.service %{_unitdir}/aprsdigi.service %{_sysconfdir}/logrotate.d/aprsdigi %{_mandir}/man8 aprsdigi-3.10.0/aprsmon.8000066400000000000000000000107641254600523400151560ustar00rootroot00000000000000.TH APRSMON 8 "9 February 1999" Linux "Linux Programmer's Manual" .SH NAME aprsmon \- monitor APRS AX.25 traffic for javAPRS .SH SYNOPSIS .B aprsmon [-a] [-m] [-r] [-k minutes] [-p port] [-t title] [-i infofile] .SH DESCRIPTION .LP .B Aprsmon uses SOCK_PACKET facilities to provide a network monitor of all AX.25 UI text traffic heard by the system. It is based on listen(1). .LP .B Aprsmon collects (\-m) or displays standard AX.25 UI text frames in a format similar to that output by a standard TNC in "Monitor ON" mode and is intended to be used with programs like javAPRS which wish to see a TNC data stream over a TCP connection. When the .B aprsmon master has been running for a while and a new .B aprsmon slave starts up, first all saved up reports are sent, then a title line indicating the beginning of live data is sent, and new reports are sent as received. .LP Compressed position and telemetry reports as generated by the APRS Mic Encoder are translated into the conventional uncompressed APRS Micro-Interface-Module (MIM) telemtry format so that these stations are visible in javAPRS. Reports containing a TheNet X1J4 beacon header are also edited to strip off the header making these nodes visible in javAPRS as well. .LP .SH OPTIONS .TP 10 .BI \-a Allow for the monitoring of outgoing frames as well as incoming ones. .TP 10 .BI \-r Choose "raw" mode which allows non-printable data through. .TP 10 .BI "\-p port" Monitor only those frames received on a particular port, by default all AX.25 interfaces are monitored. .TP 10 .BI "-m" "Master" mode. Retain monitored data for the number of minutes specified with the .B -k option in a shared memory segment. .TP 10 .BI "-k minutes" Retain monitored packets going back the given number of minutes. Default is 30. .TP 10 .BI "-t title" Sets the .I javAPRS or .I aprsd title string. Default is "Live data from Linux." For use with aprsd the format must be something like "aprsmon v2.4.4 padd padb." pada and padb can be anything, and are ignored but you *must* have 4 words in all. .TP 10 .BI "-i infofile" .I Infofile is the path to the file that the aprsmon master writes the shared memory segment and semaphore id's into. Default is "/var/ax25/aprsmon.info." .SH "javAPRS CONFIGURATION" Set up one .I aprsmon master running on your system to collect historical data going back a while. You will probably want to set up an /etc/rc.d/init.d script for this. .sp .nf aprsmon \-a \-m& .fi .sp Add an entry into /etc/services with the port number you want javAPRS to connect on. For example: .sp .nf aprs 14439/tcp # APRS monitor on 144.39 .fi .sp Add an entry into /etc/inetd.conf for this service: .sp .nf aprs stream tcp nowait root /usr/sbin/aprsmon aprsmon \-a .fi .sp To test, simply "telnet localhost aprs". To use with javAPRS, set, for example, .sp .nf .fi in your HTML file as described in the .B javAPRS documentation, and then use .B appletviewer to run javAPRS: .nf appletviewer mydemo.html .fi .sp .SH "Mic-E to MIM Translation" The Mic-E reduces the duration of packet noise on a voice frequency by encoding its data in a compressed form, some of which is binary. Some APRS-decoding software, notably javAPRS, is unable to deal with this data. To solve this problem .B aprsmon expands the Mic-E packet into one or two MIM packets as follows: .sp .nf @\fBddhhmm\fPz\fBDDMM.hhN/DDDMM.hhW$cse/spd/E\fP>mon/M\fBm\fP/\fBstatus\fP T#MIC,\fBaaabbbcccdddeeefffComments .fi .sp .TP 10 .BI ddhhmm is the UTC day and time the packet was received by the host running .B aprsmon. .TP 10 .BI DDMM.hhN is the latitude. .TP 10 .BI / is the symbol table selection (/ or \\). .TP 10 .BI DDDMM.hhW is the longitude. .TP 10 .BI $ is the symbol. .TP 10 .BI "cse,spd" are course and speed. .TP 10 .BI E is the type of Mic-Encoder: .IP .nf E - TAPR Mic-Encoder T - Kenwood TH-D7 .fi .sp .TP 10 .BI m is the status message number, and .TP 10 .BI status is the status message number expanded as follows: .IP .nf 0 - Off duty.. 1 - Enroute... 2 - In Service 3 - Returning. 4 - Committed. 5 - Special... 6 - PRIORITY.. 7 - EMERGENCY. .fi .sp .TP 10 .BI aaa,bbb,ccc,ddd,eee,fff are the values of the telemetry channels. .SH FILES .BR /etc/ax25/axports .BR /var/ax25/aprsmon.info .SH "SEE ALSO" .BR call (1), .BR listen (1), .BR beacon (1), .BR ax25 (4), .BR axattach (8), .BR http://www.bridge.net/~sdimse/javAPRS.html, .BR http://www.tapr.org, .BR http://www.aprs.net, .BR MIC-E.TXT, TELEMTRY.TXT, PROTOCOL.TXT .SH AUTHOR .nf Alan Crosswell, n2ygk@weca.org .fi aprsdigi-3.10.0/aprsmon.c000066400000000000000000000214551254600523400152300ustar00rootroot00000000000000/* aprsmon: An incredible simulation of a non-KISS TNC with MONitor ON * (for UI frames only) on a Linux AX.25 interface. Why? So it can * be run under inetd and connected to by programs like javAPRS that * want to see a TNC datastream. * (e.g. FROM>TO,DIGI,DIGI...DIGI:text) * * Runs in two modes: * 1. Just spits out received data to stdout. * 2. Buffers up some number of minutes worth of received packets into * a segment. #1 mode dumps contents of this segment before going "live." * * A socket opened in SOCK_PACKET mode returns frames that are exactly * what a KISS TNC sends: a zero, indicating data, followed by the * contents of the AX.25 packet. This program has to decode all that * AX.25 junk all over again just to print it out in generic TNC MONitor * format. * * This program is derived from AX.25 utils 2.0.12 listen(8) written by * (according to the lsm): * * jsn@cs.nott.ac.uk (Jonathan Naylor) * tpmannin@cc.hut.fi (Tomi Manninen) * A.Cox@swansea.ac.uk (Alan Cox) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * (See the file "COPYING" that is included with this source distribution.) * * portions Copyright (c) 1996,1997,1998,1999 Alan Crosswell * Alan Crosswell, N2YGK * 144 Washburn Road * Briarcliff Manor, NY 10510, USA * n2ygk@weca.org */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netax25/axconfig.h" #ifndef HAVE_LIBAX25_EXTENSIONS #include "libax25ext.h" #endif #ifdef USE_SHM #include "aprsshm.h" #endif #include "mic_e.h" #define ALEN 6 #define AXLEN 7 /* SSID mask and various flags that are stuffed into the SSID byte */ #define SSID 0x1E #define HDLCAEB 0x01 #define REPEATED 0x80 #define UI 0x03 /* unnumbered information (unproto) */ #define PID_NO_L3 0xF0 /* no level-3 (text) */ void dump(FILE *f,unsigned char *, int,time_t); void fmt(const unsigned char *, int, unsigned char **, unsigned char **,time_t); char *pax25(char *, const unsigned char *); void cleanup(int); int master = 0; /* data collector */ int keepfor = 30; /* minutes to keep collected data. */ int raw = 0; /* print raw data */ char *infofile = "/var/ax25/aprsmon.info"; #ifndef PACKAGE #define PACKAGE "aprsmon" #endif #ifndef VERSION #define VERSION "$Revision$" #endif char *title = "Live data from Linux"; int main(int argc, char **argv) { unsigned char buffer[1500]; int size; int s; char *port = NULL, *dev = NULL; struct sockaddr sa; struct ifreq ifr; int proto = ETH_P_AX25; time_t now; #ifdef USE_SHM #define OPTS "p:amk:i:t:rv" #else #define OPTS "p:at:rv" #endif while ((s = getopt(argc, argv, OPTS)) != -1) { switch (s) { #ifdef USE_SHM case 'm': master++; break; case 'i': infofile = optarg; /* file name for passing seg/sem info */ break; case 'k': /* keep for optarg minutes */ keepfor = atoi(optarg); break; #endif case 'p': /* entry in axports */ port = optarg; break; case 'a': /* allows 'hearing' my transmitted packets */ proto = ETH_P_ALL; break; case 'r': /* raw data printing */ raw++; break; case 't': title = optarg; break; case 'v': printf("aprsmon: %s-%s\n",PACKAGE,VERSION); exit(0); case '?': #ifdef USE_SHM fprintf(stderr, "Usage: aprsmon [-ar] [-p port] [-m [-k minutes]] [-i infofile] [-t title]\n"); #else fprintf(stderr, "Usage: aprsmon [-ar] [-p port] [-t title]\n"); #endif return 1; } } if (ax25_config_load_ports() == 0) fprintf(stderr, "aprsmon: no AX.25 port data configured\n"); if (port != NULL) { if ((dev = ax25_config_get_dev(port)) == NULL) { fprintf(stderr, "aprsmon: invalid port name - %s\n", port); return 1; } } if ((s = socket(AF_PACKET, SOCK_PACKET, htons(proto))) == -1) { perror("socket"); return 1; } signal(SIGHUP,cleanup); signal(SIGINT,cleanup); signal(SIGQUIT,cleanup); signal(SIGPWR,cleanup); signal(SIGPIPE,cleanup); #ifdef USE_SHM if (master) { if (shm_master(keepfor,infofile)) return 1; } else #endif { struct utsname me; uname(&me); printf("aprsmon>JAVA:javaMSG :Linux APRS server (%s-%s by Alan Crosswell, N2YGK) on %s running %s %s\r\n", PACKAGE, VERSION, me.nodename, me.sysname, me.release); printf("# %s\r\n",title); #ifdef USE_SHM (void) shm_slave(stdout,infofile); #endif printf("# Live data follows:\r\n"); printf("aprsmon>JAVA:javaTITLE:%s\r\n",title); fflush(stdout); } for (;;) { int asize; asize = sizeof(sa); if ((size = recvfrom(s, buffer, sizeof(buffer), 0, &sa, &asize)) == -1) { perror("recv"); return 1; } if (dev != NULL && strcmp(dev, sa.sa_data) != 0) continue; time(&now); if (proto == ETH_P_ALL) { /* promiscuous mode? */ strcpy(ifr.ifr_name, sa.sa_data); if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0 || ifr.ifr_hwaddr.sa_family != AF_AX25) continue; /* not AX25 so ignore this packet */ } #ifdef USE_SHM if (master) collect(buffer,size); else #endif dump(stdout,buffer,size,now); } } void dump(FILE *f, unsigned char *buf, int len, time_t now) { unsigned char *cp1,*cp2; fmt(buf,len,&cp1,&cp2,now); if (*cp1) { fprintf(f,"%s\r\n",cp1); } if (*cp2) { fprintf(f,"%s\r\n",cp2); } fflush(f); } void fmt(const unsigned char *buf, int len,unsigned char **cp1, unsigned char **cp2, time_t now) { static unsigned char buf1[1000],buf2[100]; char mic1[200],mic2[200]; int l1,l2; char from[10],to[10],digis[100]; int i,hadlast,l; char tmp[15]; *buf1 = *buf2 = '\0'; *cp1 = buf1; *cp2 = buf2; if ((buf[0] & 0xf) != 0) /* not a kiss data frame */ return; ++buf; --len; if (len < (AXLEN+ALEN+1)) /* too short */ return; pax25(to,buf); /* to call */ pax25(from,&buf[AXLEN]); /* from call */ buf+=AXLEN; /* skip over the from call now... */ len-=AXLEN; *digis = '\0'; if (!(buf[ALEN] & HDLCAEB)) { /* is there a digipeater path? */ for (l=0, buf+=AXLEN, len-=AXLEN, i = 0; i < 6 && len >= 0; i++, len-=AXLEN, buf+=AXLEN) { int nextrept = buf[AXLEN+ALEN]&REPEATED; if (buf[ALEN]&HDLCAEB) nextrept = 0; pax25(tmp,buf); if (*tmp) { sprintf(&digis[l],",%s%s",tmp,(buf[ALEN]&REPEATED&&!nextrept)?"*":""); ++hadlast; l += strlen(&digis[l]); } if (buf[ALEN] & HDLCAEB) break; } } buf += AXLEN; len -= AXLEN; if (len <= 0) return; /* no data after callsigns */ if (*buf++ == UI && *buf++ == PID_NO_L3) { len -= 2; } else { return; /* must have UI text to be useful */ } /* now check to see if it's a mic-e frame & rewrite it */ if (fmt_mic_e(to,buf,len,mic1,&l1,mic2,&l2,now)) { /* it was a MIC-E */ mic1[l1] = mic2[l2] = '\0'; if (l1) sprintf(buf1,"%s>%s%s:%s",from,"APRS",digis,mic1); if (l2) sprintf(buf2,"%s>%s%s:%s",from,"APRS",digis,mic2); } else if (fmt_x1j4(to,buf,len,mic1,&l1,mic2,&l2,now)) { /* it was an X1J4 digi */ mic1[l1] = mic2[l2] = '\0'; if (l1) sprintf(buf1,"%s>%s%s:%s",from,to,digis,mic1); } else { /* not mic-e/x1j4, so just print the packet without editing */ sprintf(buf1,"%s>%s%s:",from,to,digis); l = strlen(buf1); for (i = 0; i < len; i++,l++) { buf1[l] = (raw||isprint(buf[i]))?buf[i]:' '; /* keep it clean */ } buf1[l] = '\0'; } return; } char *pax25(char *buf, const unsigned char *data) { int i, ssid; char *s; char c; s = buf; for (i = 0; i < ALEN; i++) { c = (data[i] >> 1) & 0x7F; if (!isalnum(c) && c != ' ') { strcpy(buf, "[invalid]"); return buf; } if (c != ' ') *s++ = c; } if ((ssid = (data[ALEN] & SSID)>>1) != 0) sprintf(s, "-%d", ssid); else *s = '\0'; return(buf); } void cleanup(sig) int sig; { #ifdef USE_SHM shm_cleanup(sig); /* clean up shared memory, etc. */ #endif exit(0); } aprsdigi-3.10.0/aprsshm.c000066400000000000000000000171431254600523400152250ustar00rootroot00000000000000#if defined(USE_SHM) && defined(HAVE_SHMCTL) /* * routines to collect up packets for 'keepfor' minutes, manage shared * memory circular buffer, etc. * See aprsmon.c for the main program. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * (See the file "COPYING" that is included with this source distribution.) * * Copyright (c) 1996,1997,1999 Alan Crosswell * Alan Crosswell, N2YGK * 144 Washburn Road * Briarcliff Manor, NY 10510, USA * n2ygk@weca.org */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "aprsshm.h" #define MAXPPM 10 #define MAXPKT 256 struct pkt { /* we make a circular buffer of these */ int len; /* packet length */ time_t recvd; /* when received */ unsigned char data[MAXPKT]; /* the packet. */ }; struct pktseg { /* mapping of the shared segment */ struct pkt *head, *tail; /* relative addr */ int keepfor; /* might as well make this info available */ int filled; /* and fact that we did some early tosses */ int segsize; /* need this in the client */ struct pkt pkt0; /* first packet in seg */ }; static int seg = -1, segsize = 0, sem = -1, master = 0; static struct pktseg *pktseg = NULL; static char *infofile = NULL; /* convert relative ptr to absolute & vice-versa */ #define RELABS(x) ((struct pkt *)(((intptr_t)(x))+(intptr_t)pktseg)) #define ABSREL(x) ((struct pkt *)(((intptr_t)(x))-(intptr_t)pktseg)) #define PKTSIZE (sizeof(struct pkt)) int shm_master(k,ifile) /* "collector" shared memory master */ int k; /* keep for n minutes */ char *ifile; { struct sembuf sops[1]; FILE *info; master = 1; infofile = ifile; segsize = sizeof(struct pktseg)+(k*MAXPPM*PKTSIZE); if ((seg = shmget(IPC_PRIVATE,segsize,IPC_CREAT|0644)) < 0) { perror("shmget"); return -1; } if ((pktseg = (struct pktseg *)shmat(seg,0,0)) < 0) { perror("shmat"); return -1; } if ((sem = semget(IPC_PRIVATE,1,IPC_CREAT|0644)) < 0) { perror("semget"); return -1; } if (semctl(sem,0,SETVAL,1) < 0) { /* initialize the semaphore to locked */ perror("semctl"); return -1; } if ((info = fopen(infofile,"w")) != NULL) { fprintf(info,"%d %d\n",seg,sem); fclose(info); } else { perror(infofile); return -1; } bzero(pktseg,segsize); /* initialize the shared segment */ pktseg->segsize = segsize; pktseg->keepfor = k; pktseg->head = ABSREL(&pktseg->pkt0); pktseg->tail = (struct pkt *)-1; sops[0].sem_num = 0; sops[0].sem_op = -1; /* release the lock */ sops[0].sem_flg = 0; if (semop(sem,sops,1) < 0) { perror("semop"); return -1; } return 0; } void shm_cleanup(sig) /* release segment and semaphore */ int sig; { if (pktseg) { shmdt((char *)pktseg); } if (master) { if (infofile) unlink(infofile); if (seg >= 0) shmctl(seg,IPC_RMID,0); if (sem >= 0) semctl(sem,0,IPC_RMID,0); } } int shm_slave(f,ifile) /* "client" shared memory slave */ FILE *f; char *ifile; { struct sembuf sops[1]; FILE *info; infofile = ifile; if ((info = fopen(infofile,"r"))) { if (fscanf(info,"%d%d",&seg,&sem) != 2) { fclose(info); fprintf(stderr,"#%s: didn't scan\n",infofile); return -1; } fclose(info); } else { /* no collector running. That's OK. */ printf("# No saved data available.\r\n"); return -1; } if ((pktseg = (struct pktseg *)shmat(seg,0,SHM_RDONLY)) < 0) { perror("shmat"); return -1; } segsize = pktseg->segsize; sops[0].sem_num = 0; sops[0].sem_op = 0; /* wait for a read lock?? */ sops[0].sem_flg = 0; if (semop(sem,sops,1) < 0) { perror("semop"); return -1; } dump_saved(f); /* print out the saved stuff */ shmdt((char *)pktseg); return 0; } /* accumulate packets and age out stale ones */ void collect(buf,len) unsigned char *buf; int len; { time_t now = time(NULL); struct pkt *p; struct sembuf sops[1]; if (len>MAXPKT) { fprintf(stderr,"buffer overrun (pkt len %d)\n",len); len = MAXPKT; } /* obtain the write lock */ sops[0].sem_num = 0; sops[0].sem_op = 1; sops[0].sem_flg = 0; if (semop(sem,sops,1) < 0) { perror("semop"); return; } /* next free packet goes right after tail packet */ p = free_stale(now,1); /* toss stale packets/make room */ p->recvd = now; p->len = len; bcopy(buf,p->data,len); bzero(&p->data[len],MAXPKT-len); /* clean out any garbage */ pktseg->tail = ABSREL(p); /* new tail */ /* release the write lock */ sops[0].sem_num = 0; sops[0].sem_op = -1; sops[0].sem_flg = 0; if (semop(sem,sops,1) < 0) { perror("semop"); } } /* get rid of stale (older than keepfor minutes) packets and more packets if the buffer is full and makespace is true. Returns abs pointer to where there's room for next packet. */ struct pkt * free_stale(now,makespace) /* lose stale packets */ time_t now; int makespace; { struct pkt *head = RELABS(pktseg->head); struct pkt *tail = RELABS(pktseg->tail); struct pkt *segend = (struct pkt *)((char *)pktseg+segsize); struct pkt *nextp; int tossed = 0; if (pktseg->tail == (struct pkt *)-1) { /* nothing in buffer yet! */ return head; } /* throw out any stale packets, moving head forward through list. */ while((head->recvd < (now - pktseg->keepfor*60)) && head != tail) { ++tossed; if (++head >= segend) { /* wrap around */ head = &pktseg->pkt0; } } pktseg->head = ABSREL(head); /* find where the next packet will be stuffed */ nextp = &tail[1]; if (nextp >= segend) { /* have to circle around */ nextp = &pktseg->pkt0; } /* must flush oldest non-stale (head) packet */ if (makespace && !tossed && head == nextp) { if (++head >= segend) /* wrap around */ head = &pktseg->pkt0; pktseg->head = ABSREL(head); pktseg->filled++; } if (pktseg->filled && tossed) /* full buffer remedied by stale-out */ pktseg->filled = 0; return nextp; } void dump_saved(f) /* write saved pkts to file */ FILE *f; { extern void dump(FILE *,unsigned char *, int,time_t); struct pkt *head = RELABS(pktseg->head); struct pkt *tail = RELABS(pktseg->tail); struct pkt *segend = (struct pkt *)((char *)pktseg+segsize); struct pkt *p; struct tm *t; if (pktseg->tail == (struct pkt *)-1) return; /* no logged packets yet. */ t = gmtime(&head->recvd); fprintf(f,"# Activity seen since %04d%02d%02d %02d%02dZ:\r\n", t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min); for (p = head; p != tail;) { /* then print the rest */ dump(f,p->data,p->len,p->recvd); if (++p >= segend) { /* have to circle around */ p = &pktseg->pkt0; } } if (p == tail) { dump(f,p->data,p->len,p->recvd); } fprintf(f,"# end of recorded activity.\r\n"); } #endif aprsdigi-3.10.0/aprsshm.h000066400000000000000000000003341254600523400152240ustar00rootroot00000000000000extern int shm_master(int,char *); extern int shm_slave(FILE *,char *); extern void collect(unsigned char *, int); extern struct pkt *free_stale(time_t,int); extern void dump_saved(FILE *); extern void shm_cleanup(int); aprsdigi-3.10.0/bootstrap-aprsdev.sh000066400000000000000000000015401254600523400174110ustar00rootroot00000000000000#!/bin/sh echo "bootstraping an aprsdigi development system" sudo yum makecache fast sudo yum -y upgrade sudo yum -y install yum-cron sudo yum -y install yum-updateonboot sudo yum -y install yum-utils # aprsdigi-specific requirements sudo yum -y group install 'Development Tools' sudo yum -y install emacs # install libax25 and friends. sudo rpm -Uvh https://linuxax25.googlecode.com/svn/downloads/libax25-1.0.5-140.x86_64.rpm # libx25-devel conflicts with glibc ax25.h! sudo rpm -Uvh --force https://linuxax25.googlecode.com/svn/downloads/libax25-devel-1.0.5-140.x86_64.rpm sudo rpm -Uvh https://linuxax25.googlecode.com/svn/downloads/ax25tools-1.0.3-140.x86_64.rpm echo "your dev environment is built and aprsdigi is in /vagrant" echo "build aprsdig as follows:" echo "aclocal" echo "automake --add-mising" echo "autoconf" echo "./configure" echo "make" aprsdigi-3.10.0/configure.ac000066400000000000000000000042161254600523400156670ustar00rootroot00000000000000dnl Process this file with autoconf to produce a configure script. AC_INIT([aprsdigi], [3.10.0]) AC_CONFIG_SRCDIR([aprsshm.h]) AM_INIT_AUTOMAKE AC_PREFIX_DEFAULT(/usr) dnl Checks for programs. AC_PROG_CC AC_PROG_RANLIB AC_PROG_INSTALL AC_PATH_PROG(GROFF,groff,.:$PATH) dnl Checks for libraries. AC_CHECKING(for N2YGK's -lax25 extensions:) AC_CHECK_LIB(ax25, parse_raw_ax25, AC_DEFINE(HAVE_LIBAX25_EXTENSIONS)) AC_CHECK_LIB(ax25, ax25_config_load_ports) dnl Checks for header files. AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(fcntl.h limits.h sys/ioctl.h sys/time.h unistd.h ax25/axconfig.h) if test "$ac_cv_header_ax25_axconfig_h" = yes ; then CPPFLAGS="$CPPFLAGS -I/usr/include/ax25" fi dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_SIZE_T AC_STRUCT_TM dnl following ip6 test lifted from iperf: dnl =================================================================== dnl Check for IPV6 support dnl We have avoided checking for ss_family in sockaddr_storage because dnl linux 2.4.x versions support IPv6 but do not have this structure dnl Just check for the presence of sockaddr_storage, sockaddr_in6 dnl and sin6_port dnl =================================================================== AC_CHECKING(for IPv6) AC_TRY_COMPILE( [#include #include #include #include ], [struct sockaddr_storage sa_union, *sa_unionp; struct sockaddr_in6 *sa; sa_unionp = &sa_union; sa = (struct sockaddr_in6 *)sa_unionp; sa->sin6_port = ntohs(5001); ], ac_accept_ipv6=yes, ac_accept_ipv6=no) if test "$ac_accept_ipv6" = yes ; then AC_DEFINE(IPV6) fi dnl Checks for library functions. AC_PROG_GCC_TRADITIONAL AC_TYPE_SIGNAL AC_FUNC_WAIT3 AC_CHECK_FUNCS(select socket strdup strtol uname shmctl) dnl Compile-time options. AC_ARG_ENABLE(shm,[ --disable-shm Do not use shared memory]) if test "$enable_shm" != no; then AC_DEFINE(USE_SHM) fi AC_ARG_WITH(ax25inc,[ --with-ax25inc=path Location of ax25 include files if other than ],CPPFLAGS="$CPPFLAGS -I$with_ax25inc") AC_OUTPUT(Makefile) AC_OUTPUT(aprsdigi.spec) aprsdigi-3.10.0/depcomp000077500000000000000000000275331254600523400147650ustar00rootroot00000000000000#! /bin/sh # depcomp - compile a program generating dependencies as side-effects # Copyright 1999, 2000 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Originally written by Alexandre Oliva . if test -z "$depmode" || test -z "$source" || test -z "$object"; then echo "depcomp: Variables source, object and depmode must be set" 1>&2 exit 1 fi # `libtool' can also be set to `yes' or `no'. if test -z "$depfile"; then base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'` dir=`echo "$object" | sed 's,/.*$,/,'` if test "$dir" = "$object"; then dir= fi # FIXME: should be _deps on DOS. depfile="$dir.deps/$base" fi tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} rm -f "$tmpdepfile" # Some modes work just like other modes, but use different flags. We # parameterize here, but still list the modes in the big case below, # to make depend.m4 easier to write. Note that we *cannot* use a case # here, because this file can only contain one case statement. if test "$depmode" = hp; then # HP compiler uses -M and no extra arg. gccflag=-M depmode=gcc fi if test "$depmode" = dashXmstdout; then # This is just like dashmstdout with a different argument. dashmflag=-xM depmode=dashmstdout fi case "$depmode" in gcc3) ## gcc 3 implements dependency tracking that does exactly what ## we want. Yay! Note: for some reason libtool 1.4 doesn't like ## it if -MD -MP comes after the -MF stuff. Hmm. "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi mv "$tmpdepfile" "$depfile" ;; gcc) ## There are various ways to get dependency output from gcc. Here's ## why we pick this rather obscure method: ## - Don't want to use -MD because we'd like the dependencies to end ## up in a subdir. Having to rename by hand is ugly. ## (We might end up doing this anyway to support other compilers.) ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like ## -MM, not -M (despite what the docs say). ## - Using -M directly means running the compiler twice (even worse ## than renaming). if test -z "$gccflag"; then gccflag=-MD, fi "$@" -Wp,"$gccflag$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ## The second -e expression handles DOS-style file names with drive letters. sed -e 's/^[^:]*: / /' \ -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" ## This next piece of magic avoids the `deleted header file' problem. ## The problem is that when a header file which appears in a .P file ## is deleted, the dependency causes make to die (because there is ## typically no way to rebuild the header). We avoid this by adding ## dummy dependencies for each header file. Too bad gcc doesn't do ## this for us directly. tr ' ' ' ' < "$tmpdepfile" | ## Some versions of gcc put a space before the `:'. On the theory ## that the space means something, we add a space to the output as ## well. ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; sgi) if test "$libtool" = yes; then "$@" "-Wp,-MDupdate,$tmpdepfile" else "$@" -MDupdate "$tmpdepfile" fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files echo "$object : \\" > "$depfile" # Clip off the initial element (the dependent). Don't try to be # clever and replace this with sed code, as IRIX sed won't handle # lines with more than a fixed number of characters (4096 in # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; # the IRIX cc adds comments like `#:fec' to the end of the # dependency line. tr ' ' ' ' < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ tr ' ' ' ' >> $depfile echo >> $depfile # The second pass generates a dummy entry for each header file. tr ' ' ' ' < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ >> $depfile else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; aix) # The C for AIX Compiler uses -M and outputs the dependencies # in a .u file. This file always lives in the current directory. # Also, the AIX compiler puts `$object:' at the start of each line; # $object doesn't have directory information. stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` tmpdepfile="$stripped.u" outname="$stripped.o" if test "$libtool" = yes; then "$@" -Wc,-M else "$@" -M fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi if test -f "$tmpdepfile"; then # Each line is of the form `foo.o: dependent.h'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; tru64) # The Tru64 compiler uses -MD to generate dependencies as a side # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put # dependencies in `foo.d' instead, so we check for that too. # Subdirectories are respected. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then tmpdepfile1="$dir.libs/$base.lo.d" tmpdepfile2="$dir.libs/$base.d" "$@" -Wc,-MD else tmpdepfile1="$dir$base.o.d" tmpdepfile2="$dir$base.d" "$@" -MD fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" exit $stat fi if test -f "$tmpdepfile1"; then tmpdepfile="$tmpdepfile1" else tmpdepfile="$tmpdepfile2" fi if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" # That's a space and a tab in the []. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" else echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; #nosideeffect) # This comment above is used by automake to tell side-effect # dependency tracking mechanisms from slower ones. dashmstdout) # Important note: in order to support this mode, a compiler *must* # always write the proprocessed file to stdout, regardless of -o. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test $1 != '--mode=compile'; do shift done shift fi # Remove `-o $object'. We will use -o /dev/null later, # however we can't do the remplacement now because # `-o $object' might simply not be used IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done test -z "$dashmflag" && dashmflag=-M "$@" -o /dev/null $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" tr ' ' ' ' < "$tmpdepfile" | \ ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; dashXmstdout) # This case only exists to satisfy depend.m4. It is never actually # run, as this mode is specially recognized in the preamble. exit 1 ;; makedepend) "$@" || exit $? # X makedepend shift cleared=no for arg in "$@"; do case $cleared in no) set ""; shift cleared=yes ;; esac case "$arg" in -D*|-I*) set fnord "$@" "$arg"; shift ;; -*) ;; *) set fnord "$@" "$arg"; shift ;; esac done obj_suffix="`echo $object | sed 's/^.*\././'`" touch "$tmpdepfile" ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" sed '1,2d' "$tmpdepfile" | tr ' ' ' ' | \ ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" "$tmpdepfile".bak ;; cpp) # Important note: in order to support this mode, a compiler *must* # always write the proprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test $1 != '--mode=compile'; do shift done shift fi # Remove `-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done "$@" -E | sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | sed '$ s: \\$::' > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" cat < "$tmpdepfile" >> "$depfile" sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; msvisualcpp) # Important note: in order to support this mode, a compiler *must* # always write the proprocessed file to stdout, regardless of -o, # because we must use -o when running libtool. "$@" || exit $? IFS=" " for arg do case "$arg" in "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") set fnord "$@" shift shift ;; *) set fnord "$@" "$arg" shift shift ;; esac done "$@" -E | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" echo " " >> "$depfile" . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" rm -f "$tmpdepfile" ;; none) exec "$@" ;; *) echo "Unknown depmode $depmode" 1>&2 exit 1 ;; esac exit 0 aprsdigi-3.10.0/examples/000077500000000000000000000000001254600523400152145ustar00rootroot00000000000000aprsdigi-3.10.0/examples/README.examples000066400000000000000000000045511254600523400177160ustar00rootroot00000000000000These are examples of files that I put in /etc/ax25 and elsewhere on the system. Typically I build APRS digipeaters using the following pieces: 1. Fedora Core Linux. Most of the necessary amateur radio packages are in the standard or "extras" distros. Make sure you have a kernel with the optional mkiss.ko kernel module available. The default kernel distro doesn't include it, but there's a kernel-modules-extra RPM that does. 2. Thomas Sailer's soundmodem. This involves getting your soundcard properly configured, etc. I've successfully used this with motherboard and PCI soundcards on random old PCs and with Dell R200 servers (overkill!) and *good-quality* (expensive) USB sound cards (on a fast USB port). I generally build a serial PTT cable to use with soundmodem on newer machines and use an LPT port parallel PTT cable on older machines that have one. 3. My aprsdigi for the RF digipeater. It can actually do multiport RF gatewaying, IPv6 multicast and other crazy stuff you'll never use. 4. Dale Heatherington's aprsd for APRS-IS functionality. 5. beacon (part of ax25-tools) to beacon my digipeaters location. I'm a strong believer in not reinventing the wheel, so I used the existing beacon tool instead of adding beaconing to aprsdigi. Aprsdigi does, however, meet the US FCC requirement to transmit its callsign once every 10 minutes within the last time it transmitted, so if you want to run a stealthy digipeater, feel free to not use beacon! I use cobbler to automate and replicate building multiple APRS digipeaters, D-STAR gateways and so on based on a Fedora Core distribution. Aprsdigi will run on any Linux x86 distro, I just happen to have been using Fedora Core from back in the day when it was just called Red Hat after I switched from Slackware. The files in this directory are: README.examples this file aprsdigi.conf is sourced by the systemd aprsdigi.service file to configure aprsdigi and a beacon. It basically sets some environment variables that contain the aprsdigi and beacon command line opts. axports is the ax25 port file. aprsdigi-fc17.ks is a Cobbler kickstart file which I use to automate building aprsdigi PCs. It may be useful just to see which packages I include, what tweaks I make to the standard Fedora Core distro and so on (e.g. disabling root ssh login). aprsdigi-3.10.0/examples/aprsdigi-fc17.ks000066400000000000000000000076501254600523400201230ustar00rootroot00000000000000# Kickstart template for use by cobbler. $Revision$ # $Log$ # Revision 1.2 2012/09/02 18:17:44 alan # add base-system to include X, etc. so can run soundmodemconfig # # Revision 1.1 2012/08/05 18:48:45 alan # Initial revision # # Revision 1.1 2012/08/05 03:37:14 alan # Initial revision # # updated from fc17 anaconda-ks.cfg # shadow passwords, md5 crypt auth --useshadow --enablemd5 # try to get rid of rhgb quiet from boot loader bootloader --location=mbr --driveorder=sda --append="" # clear partitions clearpart --all --drives=sda # Use text mode install text # allow SSH, telnet to 10151,10152 firewall --enabled --ssh --port=10151:tcp,10152:tcp # don't run the setup agent firstboot --disable # System keyboard keyboard us # System language lang en_US.UTF-8 # Use network installation url --url=$tree # If any cobbler repo definitions were referenced in the kickstart profile, include them here. $yum_repo_stanza # Network information $SNIPPET('network_config') # Reboot after installation reboot #network --onboot no --device p4p1 --bootproto dhcp --noipv6 --hostname n2fmc-15 timezone --utc America/New_York # Root password rootpw --iscrypted XXX # add initial users user --name=n2ygk --password=XXX --iscrypted selinux --enforcing authconfig --enableshadow --passalgo=sha512 install # Clear the Master Boot Record zerombr # Allow anaconda to partition the system as needed autopart # Disable avahi which sends out IP multicasts on the ax.25 interface! # add appropriate other services here: services --disabled="avahi-daemon" --enabled="soundmodem,aprsdigi,aprsd,yum-updatesd,ntpd" %pre $SNIPPET('log_ks_pre') $kickstart_start $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end # Customize this list of packages as needed: %packages $SNIPPET('func_install_if_enabled') # base system: @core @base-system @online-docs # dev tools @development-libs @development-tools @editors emacs # these are in the standard fc17 repo but probabably not in the distro ISO image so a local # copy of these packages needs to be installed on the cobbler server: # need this for mkiss.ko: kernel-modules-extra kernel-PAE-modules-extra yum-updatesd libax25 libax25-devel ax25-apps ax25-tools alsa-utils alsa-lib alsa-lib-devel soundmodem aprsd # this is not in a standard distro. Need my own custom repo. aprsdigi # don't need this junk XXX - these removes are not working! -printing # avahi multicasts on the AX.25 interface! -avahi* # do not want alsa-plugins-pulseaudio. Make sure it didn't get dragged in. %end %post $SNIPPET('log_ks_post') # Start yum configuration $yum_config_stanza # End yum configuration $SNIPPET('post_install_kernel_options') $SNIPPET('post_install_network_config') $SNIPPET('func_register_if_enabled') $SNIPPET('download_config_files') $SNIPPET('koan_environment') $SNIPPET('redhat_register') $SNIPPET('cobbler_register') # Enable post-install boot notification $SNIPPET('post_anamon') # add host-specific stuff here: HN=`/bin/hostname` # disable ssh root login sed -i.bak -e 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config # turn on automatic yum updates if [ -f /etc/yum/yum-updatesd.conf ];then sed -i.bak \ -e 's/^do_update = no/do_update = yes/' \ -e 's/^emit_via = dbus/emit_via = syslog/' \ /etc/yum/yum-updatesd.conf fi # wget axports, soundmodem config, sound card defaults mkdir /etc/ax25 wget "http://$http_server/~alan/aprsdigi-cfg/$HN.asoundstate" -O /var/lib/alsa/asound.state wget "http://$http_server/~alan/aprsdigi-cfg/$HN.axports" -O /etc/ax25/axports wget "http://$http_server/~alan/aprsdigi-cfg/$HN.soundmodemconf" -O /etc/ax25/soundmodem.conf wget "http://$http_server/~alan/aprsdigi-cfg/$HN.aprsdigiconf" -O /etc/ax25/aprsdigi.conf wget "http://$http_server/~alan/aprsdigi-cfg/$HN.aprsdconf" -O /etc/aprsd/aprsd.conf # shouldn't need to do this, but... /sbin/chkconfig soundmodem on /sbin/chkconfig aprsd on # Start final steps $kickstart_done # End final steps %end aprsdigi-3.10.0/examples/aprsdigi.conf000066400000000000000000000004741254600523400176720ustar00rootroot00000000000000# configuration for demo WIDE digipeater APRSDIGI_CFG='--kill_dupes --kill_loops --logfile /var/log/aprsdigi.log \ --flood WIDE --trace TRACE --subst_mycall --x1j4_xlate --interface ax25:sm0:RELAY,WIDE,TRACE' BEACON_DEST='APRS via WIDE2-2' BEACON_PORT=sm0 BEACON_TEXT='!4116.30N/07355.57W#PHG7300 testing de N2YGK' aprsdigi-3.10.0/examples/axports000066400000000000000000000000561254600523400166400ustar00rootroot00000000000000sm0 N2YGK-15 1200 255 2 144.39 MHz (1200 bps) aprsdigi-3.10.0/fiforead.8000066400000000000000000000005301254600523400152440ustar00rootroot00000000000000.TH FIFOREAD 8 "4 April 2003" .SH NAME fiforead \- test program for aprsdigi. .SH SYNOPSIS .nf .BI "fiforead " filename .fi .SH DESCRIPTION .PP .I Fiforead is useful for testing aprsdigi. Unix datagrams received from .BI "aprsdigi \-p:unix:" filename,callsign,alias... are written to stdout. .SH AUTHOR .nf Alan Crosswell, n2ygk@weca.org .fi aprsdigi-3.10.0/fiforead.c000066400000000000000000000023421254600523400153220ustar00rootroot00000000000000/* fiforead: read from the aprsdigi fifo */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int Verbose = 1; static void die(char *s); main(int argc, char **argv) { struct sockaddr_un mysun,remsun; int size; int sock; u_char buf[1024]; int n; if (argc != 2) { fprintf(stderr,"Usage: %s file\n", argv[0]); exit(1); } bzero(&mysun,sizeof(mysun)); mysun.sun_family = AF_UNIX; strncpy(mysun.sun_path,argv[1],sizeof(mysun.sun_path)); if (Verbose) fprintf(stderr,"opening unix socket on %s\n", mysun.sun_path); if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { die("socket"); } if (bind(sock, (struct sockaddr *)&mysun, sizeof(mysun)) < 0 && errno != EADDRINUSE) { die(mysun.sun_path); } size = sizeof(remsun); while ((n = recvfrom(sock,buf,sizeof(buf),0,(struct sockaddr *)&remsun,&size)) >= 0) { printf("read %d: %*.*s\n",n,n,n,buf); size = sizeof(remsun); } } static void die(char *s) { perror(s); exit(1); } aprsdigi-3.10.0/fifowrite.8000066400000000000000000000006641254600523400154730ustar00rootroot00000000000000.TH FIFOWRITE 8 "4 April 2003" .SH NAME fifowrite \- test program for aprsdigi. .SH SYNOPSIS .nf .BI "fifowrite " filename .fi .SH DESCRIPTION .PP .I Fifowrite is useful for testing aprsdigi. Lines of text read from stdin are written as a Unix datagram to the fifo at .I filename which is expected to have been opened for reading by .BI "aprsdigi \-p unix:" filename,callsign,alias... .SH AUTHOR .nf Alan Crosswell, n2ygk@weca.org .fi aprsdigi-3.10.0/fifowrite.c000066400000000000000000000017751254600523400155520ustar00rootroot00000000000000/* fifowrite: write to the aprsdigi fifo */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int Verbose = 1; static void die(char *s); main(int argc, char **argv) { struct sockaddr_un mysun; int sock; u_char buf[1024]; int n; if (argc != 2) { fprintf(stderr,"Usage: %s file\n", argv[0]); exit(1); } bzero(&mysun,sizeof(mysun)); mysun.sun_family = AF_UNIX; strncpy(mysun.sun_path,argv[1],sizeof(mysun.sun_path)); if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { die("socket"); } while (fgets(buf,sizeof(buf),stdin)) { int sent; if ((sent = sendto(sock,buf,strlen(buf),0,(struct sockaddr *)&mysun, sizeof(mysun))) < 0) die("sendto"); } } static void die(char *s) { perror(s); exit(1); } aprsdigi-3.10.0/install-sh000077500000000000000000000127211254600523400154050ustar00rootroot00000000000000#! /bin/sh # # install - install a program, script, or datafile # This comes from X11R5 (mit/util/scripts/install.sh). # # Copyright 1991 by the Massachusetts Institute of Technology # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation, and that the name of M.I.T. not be used in advertising or # publicity pertaining to distribution of the software without specific, # written prior permission. M.I.T. makes no representations about the # suitability of this software for any purpose. It is provided "as is" # without express or implied warranty. # # Calling this script install-sh is preferred over install.sh, to prevent # `make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. It can only install one file at a time, a restriction # shared with many OS's install programs. # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit="${DOITPROG-}" # put in absolute paths if you don't have them in your path; or use env. vars. mvprog="${MVPROG-mv}" cpprog="${CPPROG-cp}" chmodprog="${CHMODPROG-chmod}" chownprog="${CHOWNPROG-chown}" chgrpprog="${CHGRPPROG-chgrp}" stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" transformbasename="" transform_arg="" instcmd="$mvprog" chmodcmd="$chmodprog 0755" chowncmd="" chgrpcmd="" stripcmd="" rmcmd="$rmprog -f" mvcmd="$mvprog" src="" dst="" dir_arg="" while [ x"$1" != x ]; do case $1 in -c) instcmd="$cpprog" shift continue;; -d) dir_arg=true shift continue;; -m) chmodcmd="$chmodprog $2" shift shift continue;; -o) chowncmd="$chownprog $2" shift shift continue;; -g) chgrpcmd="$chgrpprog $2" shift shift continue;; -s) stripcmd="$stripprog" shift continue;; -t=*) transformarg=`echo $1 | sed 's/-t=//'` shift continue;; -b=*) transformbasename=`echo $1 | sed 's/-b=//'` shift continue;; *) if [ x"$src" = x ] then src=$1 else # this colon is to work around a 386BSD /bin/sh bug : dst=$1 fi shift continue;; esac done if [ x"$src" = x ] then echo "install: no input file specified" exit 1 else true fi if [ x"$dir_arg" != x ]; then dst=$src src="" if [ -d $dst ]; then instcmd=: else instcmd=mkdir fi else # Waiting for this to be detected by the "$instcmd $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if [ -f $src -o -d $src ] then true else echo "install: $src does not exist" exit 1 fi if [ x"$dst" = x ] then echo "install: no destination specified" exit 1 else true fi # If destination is a directory, append the input filename; if your system # does not like double slashes in filenames, you may need to add some logic if [ -d $dst ] then dst="$dst"/`basename $src` else true fi fi ## this sed command emulates the dirname command dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` # Make sure that the destination directory exists. # this part is taken from Noah Friedman's mkinstalldirs script # Skip lots of stat calls in the usual case. if [ ! -d "$dstdir" ]; then defaultIFS=' ' IFS="${IFS-${defaultIFS}}" oIFS="${IFS}" # Some sh's can't handle IFS=/ for some reason. IFS='%' set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` IFS="${oIFS}" pathcomp='' while [ $# -ne 0 ] ; do pathcomp="${pathcomp}${1}" shift if [ ! -d "${pathcomp}" ] ; then $mkdirprog "${pathcomp}" else true fi pathcomp="${pathcomp}/" done fi if [ x"$dir_arg" != x ] then $doit $instcmd $dst && if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi else # If we're going to rename the final executable, determine the name now. if [ x"$transformarg" = x ] then dstfile=`basename $dst` else dstfile=`basename $dst $transformbasename | sed $transformarg`$transformbasename fi # don't allow the sed command to completely eliminate the filename if [ x"$dstfile" = x ] then dstfile=`basename $dst` else true fi # Make a temp file name in the proper directory. dsttmp=$dstdir/#inst.$$# # Move or copy the file name to the temp name $doit $instcmd $src $dsttmp && trap "rm -f ${dsttmp}" 0 && # and set any options; do chmod last to preserve setuid bits # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $instcmd $src $dsttmp" command. if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && # Now rename the file to the real destination. $doit $rmcmd -f $dstdir/$dstfile && $doit $mvcmd $dsttmp $dstdir/$dstfile fi && exit 0 aprsdigi-3.10.0/libax25ext.c000066400000000000000000000240311254600523400155310ustar00rootroot00000000000000/* * libax25ext.c: Some added functions for libax25. Conditionally * compiled only if the installed libax25 has not integrated them. * which they haven't :-( * Copyright (c) 1999,2001,2002 E. Alan Crosswell, N2YGK */ #ifndef HAVE_LIBAX25_EXTENSIONS #include #include #include "libax25ext.h" #include #define ALEN 6 #define AXLEN 7 #define HDLCAEB 0x01 #define REPEATED 0x80 #define UI 0x03 /* unnumbered information (unproto) */ #define PID_NO_L3 0xF0 /* no level-3 */ /* * parse a received kiss data frame into ax_calls and update data pointer * and length next byte of frame. Returns -1 on invalid or non-UI frame, 0 * on valid frame, 1 on valid frame that still has a non-repeated digi. */ pk_val parse_raw_ax25(unsigned char **frame, int *len, struct ax_calls *calls) { if ((**frame & 0xf) != 0 || *len < 1+(2*AXLEN)) return PK_INVALID; /* not a valid kiss data frame */ ++*frame; --*len; bzero(calls,sizeof(*calls)); calls->ax_next_digi = 0; bcopy(*frame,calls->ax_to_call.ax25_call,AXLEN); *frame += AXLEN; *len -= AXLEN; bcopy(*frame,calls->ax_from_call.ax25_call,AXLEN); *frame += AXLEN; *len -= AXLEN; if (*len <= 0) return PK_VALID; if (!(calls->ax_from_call.ax25_call[ALEN] & HDLCAEB)) { /* digis listed */ for (calls->ax_n_digis = 0; calls->ax_n_digis < AX25_MAX_DIGIS && *len > 0; calls->ax_n_digis++, *len-=AXLEN,*frame+=AXLEN) { bcopy(*frame,calls->ax_digi_call[calls->ax_n_digis].ax25_call,AXLEN); if ((*frame)[ALEN]&REPEATED) calls->ax_next_digi = calls->ax_n_digis+1; if ((*frame)[ALEN]&HDLCAEB) { /* last digi */ *frame += AXLEN; *len -= AXLEN; calls->ax_n_digis++; break; } } } if (--*len >= 0) calls->ax_type = *(*frame)++; if (--*len >= 0) calls->ax_pid = *(*frame)++; if (!(calls->ax_type == UI && calls->ax_pid == PID_NO_L3)) return PK_INVALID; /* not a UI text frame */ if (calls->ax_n_digis == 0 || calls->ax_next_digi >= calls->ax_n_digis) /* all digis used up */ return PK_VALID; else return PK_VALDIGI; } /* * like parse_raw_ax25 but the frame header is in TNC-2 or AEA format * per APRS spec 1.01 p. 84 * TNC-2: source>dest,digi1,digi2*,...,digi8: * AEA: source*>digi1>digi2*>...,digi8>dest: * * See parse_cooked_ax25.(fig,pdf) for a state diagram for the parser (uggh). */ pk_val parse_cooked_ax25(unsigned char **frame, int *len, struct ax_calls *calls) { unsigned char *tok; int state,next_state = 0; while (next_state <= 99) { int switchtok, i; state = next_state; switch(state) { case 0: /* 0: Initial state */ bzero(calls,sizeof(*calls)); calls->ax_n_digis = 0; /* this is "n = 0" in the diagram */ if ((tok = strpbrk(*frame,"*>")) == NULL) /* source callsign */ return PK_INVALID; switchtok = *tok; *tok++ = '\0'; ax25_aton_entry(*frame,calls->ax_from_call.ax25_call); *len -= tok - *frame; *frame = tok; switch (switchtok) { case '*': calls->ax_from_call.ax25_call[ALEN] |= REPEATED; next_state = 1; break; case '>': next_state= 2; break; } break; case 1: if (*tok++ == '>') { /* 1->3: AEA */ next_state = 3; *len -= tok - *frame; *frame = tok; } else return PK_INVALID; break; case 11: /* 11->3: AEA */ if (*tok++ != '>') return PK_INVALID; *frame = tok; /* ? */ (*len)--; next_state = 3; break; case 3: /* 3->5: AEA */ if ((tok = strpbrk(*frame,">*:")) == NULL) /* callsign */ return PK_INVALID; switchtok = *tok; *tok++ = '\0'; switch (switchtok) { case '>': /* 5->3: digi */ case '*': if (calls->ax_n_digis >= AX25_MAX_DIGIS) return PK_INVALID; ax25_aton_entry(*frame,calls->ax_digi_call[calls->ax_n_digis].ax25_call); *len -= tok - *frame; *frame = tok; calls->ax_n_digis++; if (switchtok == '>') { next_state = 3; } else { /* set REPEATED flag for all digis up to and including this */ for (i = 0; i < calls->ax_n_digis; i++) calls->ax_digi_call[i].ax25_call[ALEN] |= REPEATED; calls->ax_next_digi = calls->ax_n_digis; next_state = 7; } break; case ':': ax25_aton_entry(*frame,calls->ax_to_call.ax25_call); *len -= tok - *frame; *frame = tok; next_state = 99; break; default: return PK_INVALID; } break; case 5: /* not really a state */ return PK_INVALID; break; case 7: if (*tok++ != '>') return PK_INVALID; (*len)--; *frame = tok; next_state = 3; break; case 2: /* 2->4: TNC2, unless it's an AEA:-) */ if ((tok = strpbrk(*frame,">*:,")) == NULL) /* callsign */ return PK_INVALID; switchtok = *tok; switch (switchtok) { case '>': /* 4->3: AEA */ *tok++ = '\0'; if (calls->ax_n_digis >= AX25_MAX_DIGIS) return PK_INVALID; ax25_aton_entry(*frame,calls->ax_digi_call[calls->ax_n_digis].ax25_call); *len -= tok - *frame; *frame = tok; calls->ax_n_digis++; next_state = 3; break; case '*': /* 4->3: AEA, heard direct */ *tok++ = '\0'; if (calls->ax_n_digis >= AX25_MAX_DIGIS) return PK_INVALID; ax25_aton_entry(*frame,calls->ax_digi_call[calls->ax_n_digis].ax25_call); *len -= tok - *frame; *frame = tok; calls->ax_n_digis++; /* set repeated AEB flags for all digis up to and including this */ for (i = 0; i < calls->ax_n_digis; i++) calls->ax_digi_call[i].ax25_call[ALEN] |= REPEATED; /* +HDLCAEB? */ calls->ax_next_digi = calls->ax_n_digis; next_state = 11; break; case ':': *tok++ = '\0'; ax25_aton_entry(*frame,calls->ax_to_call.ax25_call); *len -= tok - *frame; *frame = tok; next_state = 99; break; case ',': *tok++ = '\0'; ax25_aton_entry(*frame,calls->ax_to_call.ax25_call); *len -= tok - *frame; *frame = tok; next_state = 6; break; } break; case 4: /* not really a state */ return PK_INVALID; break; case 6: /* 6->8 */ if ((tok = strpbrk(*frame,":*,")) == NULL) /* callsign */ return PK_INVALID; switchtok = *tok; *tok++ = '\0'; if (calls->ax_n_digis >= AX25_MAX_DIGIS) return PK_INVALID; ax25_aton_entry(*frame,calls->ax_digi_call[calls->ax_n_digis].ax25_call); *len -= tok - *frame; *frame = tok; calls->ax_n_digis++; switch (switchtok) { case ':': /* 8->T */ next_state = 99; break; case '*': /* 8->10 */ /* set repeated AEB flags for all digis up to and including this */ for (i = 0; i < calls->ax_n_digis; i++) calls->ax_digi_call[i].ax25_call[ALEN] |= REPEATED; /* +HDLCAEB? */ calls->ax_next_digi = calls->ax_n_digis; next_state = 10; break; case ',': /* 8->6 */ next_state = 6; break; } break; case 8: return PK_INVALID; /* not really a state */ break; case 10: switch(*tok) { case ',': next_state = 6; break; case ':': next_state = 99; break; default: return PK_INVALID; } *tok++ = '\0'; (*len)--; *frame = tok; break; case 99: /* terminal */ calls->ax_type = UI; calls->ax_pid = PID_NO_L3; if (calls->ax_n_digis == 0) calls->ax_from_call.ax25_call[ALEN] |= HDLCAEB; else calls->ax_digi_call[calls->ax_n_digis-1].ax25_call[ALEN] |= HDLCAEB; if (calls->ax_n_digis == 0 || calls->ax_next_digi >= calls->ax_n_digis) /* all digis used up */ return PK_VALID; else return PK_VALDIGI; break; default: return PK_INVALID; } } /* NOTREACHED */ } /* reverse of parse_raw_ax25: generates a kiss frame */ int gen_raw_ax25(unsigned char **frame, int *len, struct ax_calls *calls) { int minsize = 1+AXLEN+AXLEN+(calls->ax_n_digis*AXLEN)+2; int i; if (*len < minsize) return -1; *len -= minsize; if (calls->ax_n_digis == 0) calls->ax_from_call.ax25_call[ALEN] |= HDLCAEB; else calls->ax_from_call.ax25_call[ALEN] &= ~HDLCAEB; *(*frame)++ = '\0'; /* KISS type 0 */ bcopy(calls->ax_to_call.ax25_call,*frame,AXLEN); *frame += AXLEN; bcopy(calls->ax_from_call.ax25_call,*frame,AXLEN); *frame += AXLEN; for (i = 0; i < calls->ax_n_digis; i++,*frame += AXLEN) { calls->ax_digi_call[i].ax25_call[ALEN] &= ~HDLCAEB; bcopy(calls->ax_digi_call[i].ax25_call,*frame,AXLEN); } if (i > 0) *(*frame-AXLEN+ALEN) |= HDLCAEB; *(*frame)++ = calls->ax_type; *(*frame)++ = calls->ax_pid; return 0; } /* Like gen_raw_ax25 but in "cooked" TNC-2 format per APRS spec 1.01 p. 83 */ /* source_call>dest_call,digi1,digi2*,...,digi8: */ int gen_cooked_ax25(unsigned char **frame, int *len, struct ax_calls *calls) { int minsize = AXLEN+3+1+AXLEN+3+1+(calls->ax_n_digis*(AXLEN+3+1))+2; int i,l; if (*len < minsize) return -1; strncpy(*frame,ax25_ntoa_pretty(&calls->ax_from_call),AXLEN+3); l = strlen(*frame); *frame += l; *(*frame)++ = '>'; *len -= (l+1); strncpy(*frame,ax25_ntoa_pretty(&calls->ax_to_call),AXLEN+3); l = strlen(*frame); *frame += l; *len -= l; for (i = 0; i < calls->ax_n_digis; i++) { *(*frame)++ = ','; (*len)--; strncpy(*frame,ax25_ntoa_pretty(&calls->ax_digi_call[i]),AXLEN+3); l = strlen(*frame); *frame += l; *len -= l; /* only the last repeated digi gets * */ if (calls->ax_n_digis && calls->ax_next_digi-1 == i) { *(*frame)++ = '*'; (*len)--; } } *(*frame)++ = ':'; (*len)--; return 0; } /* * ax25 -> ascii conversion, pretty version * * lifted from libax25/axutils.c and fixed so that SSID 0 comes out * as MYCALL instead of MYCALL-0, just like most people expect! * The libax25 developers didn't accept my patch submission so I have * to drag this code around forever. Oh well. */ char *ax25_ntoa_pretty(const ax25_address *a) { static char buf[11]; char c, *s; int n; for (n = 0, s = buf; n < 6; n++) { c = (a->ax25_call[n] >> 1) & 0x7F; if (c != ' ') *s++ = c; } if ((n = ((a->ax25_call[6] >> 1) & 0x0F))) { /* not SSID=0 */ *s++ = '-'; if (n > 9) { *s++ = '1'; n -= 10; } *s++ = n + '0'; } *s++ = '\0'; return buf; } #endif aprsdigi-3.10.0/libax25ext.h000066400000000000000000000026611254600523400155430ustar00rootroot00000000000000/* * libax25ext.h: Some added functions for libax25. Conditionally * compiled only if the installed libax25 has not integrated them. * Copyright (c) 1999 E. Alan Crosswell, N2YGK */ #ifndef HAVE_LIBAX25_EXTENSIONS struct ax_calls { ax25_address ax_to_call; ax25_address ax_from_call; int ax_n_digis; /* number of digis to follow */ ax25_address ax_digi_call[AX25_MAX_DIGIS]; int ax_next_digi; /* index of next digi (1st non-repeated) */ unsigned char ax_type; /* frame type */ unsigned char ax_pid; /* protocol ID */ }; /* * parse a received kiss data frame into ax_calls and update data pointer * and length next byte of frame. Returns -1 on invalid frame, 0 * on valid frame, 1 on valid frame that still has a non-repeated digi. */ typedef enum {PK_INVALID=-1,PK_VALID=0,PK_VALDIGI=1} pk_val; extern pk_val parse_raw_ax25(unsigned char **, int *, struct ax_calls *); /* parse a received cooked TNC-2 or AEA format data frame */ extern pk_val parse_cooked_ax25(unsigned char **, int *, struct ax_calls *); /* generate a raw kiss data frame header (converse of parse_raw_ax25) */ extern int gen_raw_ax25(unsigned char **, int *, struct ax_calls *); /* generate a cooked TNC-2 format data frame header (converse of parse_cooked_ax25) */ extern int gen_cooked_ax25(unsigned char **, int *, struct ax_calls *); /* pretty version of stand libax25's ax25_ntoa */ extern char *ax25_ntoa_pretty(const ax25_address *a); #endif aprsdigi-3.10.0/mic_e.c000066400000000000000000000154771254600523400146340ustar00rootroot00000000000000/* * mic_e: function to reformat APRS Mic Encoder compressed position report * into a conventional (non-binary) tracker report. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * (See the file "COPYING" that is included with this source distribution.) * * Copyright (c) 1997,1999 Alan Crosswell * Alan Crosswell, N2YGK * 144 Washburn Road * Briarcliff Manor, NY 10510, USA * n2ygk@weca.org */ #include #include #include #include #include #include "mic_e.h" static char *msgname[] = { "Off duty..", "Enroute...", "In Service", "Returning.", "Committed.", "Special...", "PRIORITY..", "EMERGENCY." }; static unsigned int hex2i(u_char,u_char); int fmt_mic_e(const u_char *t, /* tocall */ const u_char *i, /* info */ const int l, /* length of info */ u_char *buf1, /* output buffer */ int *l1, /* length of output buffer */ u_char *buf2, /* 2nd output buffer */ int *l2, /* length of 2nd output buffer */ time_t tick) /* received timestamp of the packet */ { u_int msg,sp,dc,se,spd,cse; char north, west; int lon1,lonDD,lonMM,lonHH; char *bp; struct tm *gmt; enum {none=0, BETA, REV1} rev = none; /* mic_e revision level */ int gps_valid = 0; char symtbl = '/', symbol = '$', etype = 'E'; int buf2_n = 0; *l1 = *l2 = 0; switch (i[0]) { /* possible valid MIC-E flags */ case 0x60: gps_valid = 1; rev = REV1; break; case 0x27: gps_valid = 0; rev = REV1; break; case 0x1c: gps_valid = 1; rev = BETA; break; case 0x1d: gps_valid = 0; rev = BETA; break; default: gps_valid = 0; rev = none; break; } if (l >= 7 && (rev != none)) { msg = ((t[0]&0x40)?0:4) + ((t[1]&0x40)?0:2) + ((t[2]&0x40)?0:1); north = t[3]&0x40?'N':'S'; west = t[5]&0x40?'W':'E'; lon1 = t[4]&0x40; lonDD = i[1] - 28; lonMM = i[2] - 28; lonHH = i[3] - 28; #ifdef DEBUG fprintf(stderr,"raw lon 0x%02x(%d) 0x%02x(%d) 0x%02x(%d) 0x%02x(%d)\n", i[1],i[1],i[2],i[2],i[3],i[3],i[4],i[4]); fprintf(stderr,"before: lonDD=%d, lonMM=%d, lonHH=%d lon1=0x%0x\n",lonDD,lonMM,lonHH,lon1); #endif if (rev >= REV1) { if (lon1) /* do this first? */ lonDD += 100; if (180 <= lonDD && lonDD <= 189) lonDD -= 80; if (190 <= lonDD && lonDD <= 199) lonDD -= 190; if (lonMM >= 60) lonMM -= 60; } #ifdef DEBUG fprintf(stderr,"after: lonDD=%d, lonMM=%d, lonHH=%d lon1=0x%0x\n",lonDD,lonMM,lonHH,lon1); #endif sp = i[4] - 28; dc = i[5] - 28; se = i[6] - 28; buf2_n = 6; /* keep track of where we are */ #ifdef DEBUG fprintf(stderr,"sp=%02x dc==%02x se=%02x\n",sp,dc,se); #endif spd = sp*10+dc/10; cse = (dc%10)*100+se; if (rev >= REV1) { if (spd >= 800) spd -= 800; if (cse >= 400) cse -= 400; } gmt = gmtime(&tick); #ifdef DEBUG fprintf(stderr,"symbol=0x%02x, symtbl=0x%02x\n",i[7],i[8]); #endif symtbl = (l >= 8 && rev >= REV1)? i[8] : '/'; /* rev1 bug workaround: sends null symbol/table bytes */ if (symtbl != '/' && symtbl != '\\' && !('0' <= symtbl && symtbl <= '9') && !('A' <= symtbl && symtbl <= 'J') && symtbl != '*' && symtbl != '!') symtbl = '/'; symbol = i[7]; if (!isprint(symbol)) symbol = '$'; buf2_n = (rev == BETA)?8:9; if (l >= 10) { buf2_n = (rev == BETA)?8:9; switch (i[buf2_n]) { case '>': /* Kenwood TH-D7: no telemetry */ etype = 'T'; buf2_n++; break; case 0x60: /* two-channel telemetry */ sprintf(buf2,"T#MIC%03d,%03d", hex2i(i[buf2_n+1],i[buf2_n+2]), hex2i(i[buf2_n+3],i[buf2_n+4])); buf2_n+=5; *l2 = strlen(buf2); break; case 0x27: /* five-channel telemetry */ sprintf(buf2,"T#MIC%03d,%03d,%03d,%03d,%03d", hex2i(i[buf2_n+1],i[buf2_n+2]), hex2i(i[buf2_n+3],i[buf2_n+4]), hex2i(i[buf2_n+5],i[buf2_n+6]), hex2i(i[buf2_n+7],i[buf2_n+8]), hex2i(i[buf2_n+9],i[buf2_n+10])); buf2_n+=11; *l2 = strlen(buf2); break; case 0x1d: /* five-channel telemetry */ sprintf(buf2,"T#MIC%03d,%03d,%03d,%03d,%03d", i[buf2_n+1],i[buf2_n+2],i[buf2_n+3],i[buf2_n+4],i[buf2_n+5]); buf2_n+=6; *l2 = strlen(buf2); break; default: break; /* no telemetry */ } } sprintf(buf1,"@%02d%02d%02dz%d%d%d%d.%d%d%c%c%03d%02d.%02d%c%c%03d/%03d/%c>mon/M%d/%s", gmt->tm_mday,gmt->tm_hour,gmt->tm_min, t[0]&0x0f,t[1]&0x0f,t[2]&0x0f,t[3]&0x0f,t[4]&0x0f,t[5]&0x0f, north,symtbl, lonDD,lonMM,lonHH, west, symbol, cse,spd, etype, msg,msgname[msg]); bp = &buf1[(*l1 = strlen(buf1))]; if (buf2_n < l) { /* additional comments/btext */ *bp++ = ' '; /* add a space */ (*l1)++; memcpy(bp,&i[buf2_n],l-buf2_n); *l1 += l-buf2_n; } } return ((*l1>0)+(*l2>0)); } /* * here's another APRS device that get's mistreated by some APRS * implementations: A TNC2 running TheNet X1J4. * * 1 2 * 1234567890123456789012 * TheNet X-1J4 (RELAY) */ static u_char x1j4prefix[] = "TheNet X-1J4"; #define MINX1J4LEN 14 /* min length w/TheNet X1J4 prefix */ #define MAXX1J4LEN 22 /* max length w/(alias) */ int fmt_x1j4(const u_char *t, /* tocall */ const u_char *i, /* info */ const int l, /* length of info */ u_char *buf1, /* output buffer */ int *l1, /* length of output buffer */ u_char *buf2, /* 2nd output buffer */ int *l2, /* length of 2nd output buffer */ time_t tick) /* received timestamp of the packet */ { const u_char *cp; *l1 = *l2 = 0; if (l < MINX1J4LEN || memcmp(i,x1j4prefix,sizeof(x1j4prefix)-1) != 0) return 0; /* it's a TheNet beacon: either has ()'s w/alias name or no ()'s and the btext starts after some white space! */ cp = memchr(&i[MINX1J4LEN],')',MAXX1J4LEN-MINX1J4LEN); if (cp == NULL) /* no parens (no alias call) */ cp = &i[MINX1J4LEN]; else cp++; /* skip over the ) */ while (cp <= &i[l-1] && *cp == ' ') cp++; /* skip blanks */ memcpy(buf1,cp,*l1=&i[l-1]-cp); return 1; } static unsigned int hex2i(u_char a,u_char b) { unsigned int r = 0; if (a >= '0' && a <= '9') { r = (a-'0') << 4; } else if (a >= 'A' && a <= 'F') { r = (a-'A'+10) << 4; } if (b >= '0' && b <= '9') { r += (b-'0'); } else if (b >= 'A' && b <= 'F') { r += (b-'A'+10); } return r; } aprsdigi-3.10.0/mic_e.h000066400000000000000000000013631254600523400146260ustar00rootroot00000000000000/* * mic_e.h: APRS Mic Encoder special case functions */ extern int fmt_mic_e(const u_char *t, /* tocall */ const u_char *i, /* info */ const int l, /* length of info */ u_char *buf1, /* output buffer */ int *l1, /* length of output buffer */ u_char *buf2, /* 2nd output buffer */ int *l2, /* length of 2nd output buffer */ time_t tick); /* received timestamp of the packet */ extern int fmt_x1j4(const u_char *t, /* tocall */ const u_char *i, /* info */ const int l, /* length of info */ u_char *buf1, /* output buffer */ int *l1, /* length of output buffer */ u_char *buf2, /* 2nd output buffer */ int *l2, /* length of 2nd output buffer */ time_t tick); /* received timestamp of the packet */ aprsdigi-3.10.0/mic_e_test.c000066400000000000000000000017231254600523400156600ustar00rootroot00000000000000#include #include #include #include #include #include #include "mic_e.h" void main(argc,argv) /* test this formatter */ int argc; char **argv; { char b[100]; char ob1[512],ob2[512]; int ol1,ol2; bzero(b,sizeof(b)); while (fgets(b,sizeof(b),stdin)) { int tl = strlen(b); u_char *to = strchr(b,'>'); u_char *i = strchr(b,':'); time_t tick; if (tl < sizeof(b) && b[tl-1] == '\n') b[tl-1] = '\0'; if (!to || !i) { putchar('?'); puts(b); continue; } ++to; ++i; time(&tick); if (fmt_mic_e(to,i,strlen(i),ob1,&ol1,ob2,&ol2,tick) || fmt_x1j4(to,i,strlen(i),ob1,&ol1,ob2,&ol2,tick)) { if (ol2) { fwrite(ob2,ol2,1,stdout); /* telemetry */ putchar('\n'); } if (ol1) { fwrite(ob1,ol1,1,stdout); /* posit */ putchar('\n'); } } else { putchar('#'); puts(b); } bzero(b,sizeof(b)); } } aprsdigi-3.10.0/mkinstalldirs000077500000000000000000000034111254600523400162030ustar00rootroot00000000000000#! /bin/sh # mkinstalldirs --- make directory hierarchy # Author: Noah Friedman # Created: 1993-05-16 # Public domain errstatus=0 dirmode="" usage="\ Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." # process command line arguments while test $# -gt 0 ; do case "${1}" in -h | --help | --h* ) # -h for help echo "${usage}" 1>&2; exit 0 ;; -m ) # -m PERM arg shift test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; } dirmode="${1}" shift ;; -- ) shift; break ;; # stop option processing -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option * ) break ;; # first non-opt arg esac done for file do if test -d "$file"; then shift else break fi done case $# in 0) exit 0 ;; esac case $dirmode in '') if mkdir -p -- . 2>/dev/null; then echo "mkdir -p -- $*" exec mkdir -p -- "$@" fi ;; *) if mkdir -m "$dirmode" -p -- . 2>/dev/null; then echo "mkdir -m $dirmode -p -- $*" exec mkdir -m "$dirmode" -p -- "$@" fi ;; esac for file do set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` shift pathcomp= for d do pathcomp="$pathcomp$d" case "$pathcomp" in -* ) pathcomp=./$pathcomp ;; esac if test ! -d "$pathcomp"; then echo "mkdir $pathcomp" mkdir "$pathcomp" || lasterr=$? if test ! -d "$pathcomp"; then errstatus=$lasterr else if test ! -z "$dirmode"; then echo "chmod $dirmode $pathcomp" lasterr="" chmod "$dirmode" "$pathcomp" || lasterr=$? if test ! -z "$lasterr"; then errstatus=$lasterr fi fi fi fi pathcomp="$pathcomp/" done done exit $errstatus # Local Variables: # mode: shell-script # sh-indentation: 3 # End: # mkinstalldirs ends here aprsdigi-3.10.0/parse_cooked_ax25.fig000066400000000000000000000135271254600523400173720ustar00rootroot00000000000000#FIG 3.2 Landscape Center Inches Letter 100.00 Single -2 1200 2 5 1 0 1 0 7 50 0 -1 0.000 0 0 1 0 3821.677 3827.374 4275 3825 3750 4275 3375 3750 0 0 1.00 60.00 120.00 5 1 0 1 0 7 50 0 -1 0.000 0 0 1 0 3814.195 4314.407 4500 4650 3225 4800 3300 3750 0 0 1.00 60.00 120.00 5 1 0 1 0 7 50 0 -1 0.000 0 1 1 0 2850.000 1370.833 3300 1575 3000 900 2400 1575 0 0 1.00 60.00 120.00 5 1 0 1 0 7 50 0 -1 0.000 0 0 1 0 3358.928 1923.214 3675 2850 2550 2475 2400 1725 0 0 1.00 60.00 120.00 5 1 0 1 0 7 50 0 -1 0.000 0 0 1 0 2662.500 2437.500 2325 3150 1875 2400 2325 1725 0 0 1.00 60.00 120.00 5 1 0 1 0 7 50 0 -1 0.000 0 0 1 0 2323.987 2376.689 2325 3225 1575 2775 1500 2175 0 0 1.00 60.00 120.00 5 1 0 1 0 7 50 0 -1 0.000 0 0 1 0 2212.500 2362.500 1575 2025 1875 1725 2325 1650 0 0 1.00 60.00 120.00 6 2250 1500 2550 1800 6 2250 1500 2550 1800 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 2400 1650 106 106 2400 1650 2475 1725 -6 4 1 0 50 0 0 12 0.0000 4 135 90 2400 1725 3\001 -6 6 3150 1500 3450 1800 6 3150 1500 3450 1800 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 3300 1650 106 106 3300 1650 3375 1725 -6 4 1 0 50 0 0 12 0.0000 4 135 90 3300 1725 5\001 -6 6 2250 3075 2550 3375 6 2250 3075 2550 3375 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 2400 3225 106 106 2400 3225 2475 3300 -6 4 1 0 50 0 0 12 0.0000 4 135 90 2400 3300 4\001 -6 6 3225 3525 3525 3825 6 3225 3525 3525 3825 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 3375 3675 106 106 3375 3675 3450 3750 -6 4 1 0 50 0 0 12 0.0000 4 135 90 3375 3750 6\001 -6 6 4125 3525 4425 3825 6 4125 3525 4425 3825 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 4275 3675 106 106 4275 3675 4350 3750 -6 4 1 0 50 0 0 12 0.0000 4 135 90 4275 3750 8\001 -6 6 4425 4425 4725 4725 6 4425 4425 4725 4725 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 4575 4575 106 106 4575 4575 4650 4650 -6 4 1 0 50 0 0 12 0.0000 4 135 180 4575 4650 10\001 -6 6 3600 2700 3900 3000 6 3600 2700 3900 3000 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 3750 2850 106 106 3750 2850 3825 2925 -6 4 1 0 50 0 0 12 0.0000 4 135 90 3750 2925 7\001 -6 6 900 3075 1200 3375 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 1050 3225 106 106 1050 3225 1125 3300 4 1 0 50 0 0 12 0.0000 4 135 90 1050 3300 2\001 -6 6 1350 1950 1650 2250 6 1350 1950 1650 2250 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 1500 2100 106 106 1500 2100 1575 2175 -6 4 1 0 50 0 0 12 0.0000 4 135 180 1500 2175 11\001 -6 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 750 2325 106 106 750 2325 825 2400 1 3 0 1 0 7 50 0 -1 0.000 1 0.0000 1125 1650 106 106 1125 1650 1200 1725 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 1125 3225 2273 3225 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 1200 1650 2325 1650 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 2498 1650 3173 1650 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 2475 3150 5250 3600 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 2475 3300 3248 3675 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 3473 3675 4148 3675 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 4373 3675 5250 3675 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 4364 3746 4589 4496 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 4650 4500 5250 3750 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 3375 1725 5250 3525 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 3300 1725 3750 2775 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 825 2400 1050 3150 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 825 2250 1125 1725 2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 0 0 1.00 60.00 120.00 225 1800 750 2250 4 0 4 50 0 0 18 0.0000 4 75 60 2775 3375 ,\001 4 0 4 50 0 0 18 0.0000 4 75 60 3750 4125 ,\001 4 0 4 50 0 0 18 0.0000 4 135 60 4575 3600 :\001 4 0 4 50 0 0 16 0.0000 4 90 120 4500 4200 *\001 4 0 4 50 0 0 18 0.0000 4 135 60 4875 4125 :\001 4 0 4 50 0 0 18 0.0000 4 75 60 3750 4950 ,\001 4 1 0 50 0 0 12 0.0000 4 135 120 4350 4200 R\001 4 0 4 50 0 0 18 0.0000 4 135 60 3225 3225 :\001 4 0 4 50 0 0 12 0.0000 4 180 585 3525 3600 callsign\001 4 0 0 50 0 0 12 0.0001 4 180 690 3450 3900 digi[n++]\001 4 0 4 50 0 0 12 0.0000 4 180 585 2550 1575 callsign\001 4 0 4 50 0 0 18 0.0000 4 135 165 2850 825 >\001 4 0 0 50 0 0 12 0.0001 4 180 690 2475 1200 digi[n++]\001 4 0 4 50 0 0 18 0.0000 4 135 60 4275 2475 :\001 4 0 0 50 0 0 12 5.4978 4 135 555 3975 2550 dst call\001 4 0 4 50 0 0 16 0.0000 4 90 120 3450 2175 *\001 4 0 0 50 0 0 12 5.1487 4 135 120 3225 2175 R\001 4 0 0 50 0 0 12 0.0000 4 135 105 5400 3675 T\001 4 0 0 50 0 0 12 5.8469 4 135 555 2475 3525 dst call\001 4 0 0 50 0 0 12 6.1087 4 135 555 3000 3450 dst call\001 4 0 0 50 0 0 12 1.2218 4 180 690 2025 2550 digi[n++]\001 4 0 0 50 0 0 12 5.3233 4 180 690 2325 2400 digi[n++]\001 4 0 4 50 0 0 18 0.0000 4 135 165 2925 2700 >\001 4 1 0 50 0 0 12 0.0000 4 180 1500 5025 750 parse_cooked_ax25\001 4 1 0 50 0 0 12 0.0000 4 180 1035 5025 975 state diagram\001 4 1 4 50 0 0 12 0.0000 4 135 855 5025 1200 red = token\001 4 1 0 50 0 0 12 0.0000 4 135 1065 5025 1425 black = action\001 4 1 0 50 0 0 12 0.0000 4 180 600 5250 4425 (TNC2)\001 4 1 0 50 0 0 12 0.0000 4 180 540 5250 3000 (AEA)\001 4 1 0 50 0 0 12 0.0000 4 135 90 750 2400 0\001 4 0 4 50 0 0 16 0.0000 4 90 120 825 2100 *\001 4 0 0 50 0 0 12 1.0472 4 135 435 975 2325 direct\001 4 1 0 50 0 0 12 0.0000 4 135 90 1125 1725 1\001 4 0 4 50 0 0 18 0.0000 4 135 165 975 2700 >\001 4 0 4 50 0 0 12 5.5851 4 180 585 300 1800 callsign\001 4 0 0 50 0 0 12 5.5851 4 135 555 150 1950 src call\001 4 0 0 50 0 0 12 0.0000 4 135 285 225 1650 n=0\001 4 0 0 50 0 0 12 0.0000 4 135 60 225 1425 I\001 4 0 4 50 0 0 18 0.0000 4 135 165 1500 1575 >\001 4 0 4 50 0 0 16 0.0000 4 90 120 1350 2775 *\001 4 0 4 50 0 0 12 0.0000 4 180 585 1200 3150 callsign\001 4 0 4 50 0 0 18 0.0000 4 135 165 1875 1950 >\001 4 0 4 50 0 0 18 0.0000 4 135 165 1500 1875 >\001 4 1 0 50 0 0 12 1.5708 4 135 120 1650 2400 R\001 4 0 0 50 0 0 12 2.2690 4 180 690 2100 3075 digi[n++]\001 aprsdigi-3.10.0/parse_cooked_ax25.pdf000066400000000000000000000076451254600523400174020ustar00rootroot00000000000000%PDF-1.3 %쏢 6 0 obj <> stream xZߏ ~߿b; -ЗC]׵\s4GRhv̹ G#ERl'rN'??'뭛D&Ҵ9ɺfK-%d0m|9YgT')G_ۨf릶,u|Uhl*եӏW_&+0ex<-i[N/w:}w7<F+4B)B.rX! T+4BKPZ mMtj6`M_0|Aǃ/I̷F_6 uBl ֥kLb?v2Nً*aHݓa}RŅ:-qԩ,~Jz1@%2@b"!;kSK[y|0b;boD@ɧ;y7`'oG=Q1 Px6M\uG#bOy:#ؕbE 0P3ZPBa|}̓)+% 5+x" %a2QT(9l4m ]-iIS$FzNTJRo8)_3*N6AV@@S 0u+D3JRШ 1UJsT#4u݄g|]>hAϣݤ=s4"&f_uI%M^N)U yX6&U"l`_C$cr*SzŞ$`wk;(_[/ŜǓs9n<&] &2$, 9ya~4d%;FSN TDt둛<2pxFrsmoYc&ɩЉ=r-8JūTL:s, gF(Ǔp!^LNlq4 >;<o.A(0l&Ti\"gb #sܳgڭpԺ"PAq?hQɮ[zIyLO>2rS^iBR='ʉ9C@[t{ uĀEFړҔْ;/1kOs,He2a# ^-JȀ0X8]R%r%>!jKVƋs 4٠cdړR.5/pҨ`7h#eh&benޮ2' ¼4|mI׃<lU<8q8[J҄j PynyL{6:`'$)Ue,ej"~R(oa 3q,`x8%x+vDDnad#d{pTzꐟK%Hxm99jR e`> w2D08&xUB"±nͺFwWZĆ/ue%ŠeVÀ4YyK-C\AQ98?$5;PC'" /d)9@#}?rn玣~˞|N^{ARuRKPxBZzҞ.lTE M#bkw>#)Ro!tp(ju.y{&>hAOUoKy3qJ ЬsM5)9a(ni``{5{-A YZ%IN|G <[Jm81[p|=$BnT\[ C]XJΪT%r[g6S I\ydg'ԡj_Ҋ5ʪ3;PЌP,}B|  .X9)U]d4r*Sk9^%IL7c-"6QҫhI v*s^kƐ,(Kǚ!^,[Wbb.ܦVjph"bw/ȝWܾu5kG}zf$EP!gQF,fM|ة{b hwm,72W*q4&m?Ύyh-Xz{nX,[D43|_|NO@|-|AUd %oamX,7XRZV$JV1{R}U*zL{+"nذYlxU?r4| ӡ]Wra:0ݽO<_A4GG7Yٳ2eǵDBr/o_^FK' _?>DPmlbt0ûTBdo=W_gU~Tog湚;6r=yCri.VgMr;Y Q㧉qHvyvBzgE(8o ([w2m9 ESB]n,QDX 8T(}`91$/G/.W >y:bKۍ=ԗ,,z0tlZp޾$h2xONo}_>' i޾>AsӒ|2[?/?ͨ M:y/_ Bt~Ν 1iRи ;BuqnC o/H)׿*x,-\ChQ<~=Gsj)u٘$JiskgKslH(eHUvOQU:X\>˿行V[&GVV6_$7tN/O Tendstream endobj 7 0 obj 3009 endobj 10 0 obj <> endobj 11 0 obj <> endobj 5 0 obj <> /Contents 6 0 R >> endobj 3 0 obj << /Type /Pages /Kids [ 5 0 R ] /Count 1 >> endobj 1 0 obj <> endobj 4 0 obj <> endobj 9 0 obj <> endobj 8 0 obj <> endobj 2 0 obj <>endobj xref 0 12 0000000000 65535 f 0000003384 00000 n 0000003635 00000 n 0000003325 00000 n 0000003432 00000 n 0000003174 00000 n 0000000015 00000 n 0000003094 00000 n 0000003574 00000 n 0000003501 00000 n 0000003114 00000 n 0000003144 00000 n trailer << /Size 12 /Root 1 0 R /Info 2 0 R >> startxref 3687 %%EOF aprsdigi-3.10.0/sourceforge-to-github.sh000066400000000000000000000022161254600523400201560ustar00rootroot00000000000000#!/bin/bash # one time script to move aprsdigi from sourceforge CVS to github # meant to be run with vagrant. # convert CVS to git: http://cvs2svn.tigris.org/cvs2git.html echo installing cvs2git curl -o cvs2svn.tgz http://cvs2svn.tigris.org/files/documents/1462/49237/cvs2svn-2.4.0.tar.gz tar xfz cvs2svn.tgz cd cvs2svn-2.4.0 sudo make install cd echo copying aprsdigi CVS repo from sourceforge rsync -av 'rsync://n2ygk@aprsdigi.cvs.sourceforge.net/cvsroot/aprsdigi/*' . mv aprsdigi sf-aprsdigi echo converting CVS to git mkdir cvs2git-tmp cvs2git --blobfile=cvs2git-tmp/git-blob.dat \ --dumpfile=cvs2git-tmp/git-dump.dat \ --username=cvs2git \ aprsdigi # get my git configuration cp /vagrant/.gitconfig ~ git init --bare aprsdigi.git cd aprsdigi.git cat ../cvs2git-tmp/git-blob.dat ../cvs2git-tmp/git-dump.dat | git fast-import git branch -D TAG.FIXUP git gc --prune=now cd git clone aprsdigi.git cd aprsdigi # get rid of aprsdigi.git as the 'origin' remote git remote remove origin # set up aprsdigi on github git remote add origin git@github.com:n2ygk/aprsdigi.git git push -u origin master mv aprsdigi /vagrant # so I can edit in my "normal" environment aprsdigi-3.10.0/testmcast.c000066400000000000000000000110361254600523400155520ustar00rootroot00000000000000/* test multicast */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef AX25_MTU #define AX25_MTU 256 #endif #include #include "libax25ext.h" static void die(char *p, char *s) { fprintf(stderr,"%s: ",p); perror(s); exit(1); } main(int argc,char **argv) { struct sockaddr_in sin; struct sockaddr tsa, rsa; struct hostent *hp; struct servent *sp; char *name = argv[1], *service = argv[2], *ttl = argv[3]; const int one=1; int ttlval; int tsock, rsock; unsigned char buffer[AX25_MTU]; int selfds = 0; fd_set select_mask; if (argc < 4 || (ttlval = atoi(ttl)) <= 0) { fprintf(stderr,"Usage: %s destination port ttl\n",argv[0]); exit(1); } fprintf(stderr,"opening UDP socket on %s/%s/%d\n", name, service, ttlval); bzero(&sin, sizeof(struct sockaddr_in)); if (isdigit(*name)) { sin.sin_addr.s_addr = inet_addr(name); } else if (hp = gethostbyname(name)) { bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length); } else { fprintf(stderr,"Unrecognized host name: %s\n",name); exit(1); } if (isdigit(*service)) { sin.sin_port = htons(atoi(service)); } else if (sp = getservbyname(service,"udp")) { sin.sin_port = sp->s_port; } else { fprintf(stderr,"Unrecognized service: %s\n",service); exit(1); } sin.sin_family = AF_INET; if (argc == 4) { if ((tsock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { perror(name); exit(1); } if (setsockopt(tsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) die("setsockopt SO_REUSEADDR",name); if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) { if (setsockopt(tsock, SOL_IP, IP_MULTICAST_TTL, &ttlval, sizeof(ttlval)) < 0) die("setsockopt MULTICAST_TTL",name); } else { if (setsockopt(tsock, SOL_IP, IP_TTL, &ttlval, sizeof(ttlval)) < 0) die("setsockopt IP_TTL",name); } bzero(&tsa,sizeof(tsa)); bcopy(&sin,&tsa,sizeof(sin)); /* fill sockaddr w/sockaddr_in */ } if (argc == 4) { if (connect(tsock, &tsa, sizeof(struct sockaddr)) < 0) { die("connect(tsock)",name); } } /* now the rsock */ if ((rsock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { die("rsock = socket",name); } if (setsockopt(rsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) die("rsock SO_REUSEADDR",name); /* if the UDP socket is a multicast group, then do IGMP join for rsock */ if (!IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) sin.sin_addr.s_addr = INADDR_ANY; bzero(&rsa,sizeof(rsa)); bcopy(&sin,&rsa,sizeof(sin)); if (bind(rsock, &rsa, sizeof(struct sockaddr)) < 0) { die("bind(rsock)",name); } if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) { struct ip_mreq mreq; mreq.imr_multiaddr = sin.sin_addr; mreq.imr_interface.s_addr = INADDR_ANY; setsockopt(rsock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); } /* sockets set up, enter loop, receiving from stdin & rsock, transmitting what's read from stdin on tsock */ /* set up the initial select mask */ FD_ZERO(&select_mask); FD_SET(rsock, &select_mask); FD_SET(0, &select_mask); selfds = rsock+1; for (;;) { int len; fd_set rmask = select_mask; int size = sizeof(struct sockaddr); fprintf(stderr,"before select rsock=%d rmask=0x%0x\n",rsock,rmask); if (select(selfds,&rmask,NULL,NULL,NULL) < 0) { if (errno == EINTR) continue; perror("select"); return 1; } fprintf(stderr,"after select rmask=0x%0x\n",rmask); /* find which sockets have data */ if (FD_ISSET(rsock,&rmask)) { fprintf(stderr,"rsock was set\n"); if ((len = recvfrom(rsock,buffer,sizeof(buffer),0,&rsa,&size)) < 0) { if (errno == EINTR) continue; perror(name); exit(1); } fprintf(stderr,"rsock rec'd %d: %s\n",len,buffer); } if (FD_ISSET(0,&rmask)) { int r; fprintf(stderr,"stdin was set\n"); if ((len = read(0,buffer,sizeof(buffer))) < 0) { perror("stdin"); exit(1); } fprintf(stderr,"stdin read %d: %s\n",len,buffer); /* now xmit it */ if ((r = sendto(tsock,buffer,len,0,&tsa,sizeof(tsa))) < 0) die("sendto","xmit"); fprintf(stderr,"transmitted %d\n",r); } } /* end of for(;;) */ return 0; /* NOTREACHED */ } aprsdigi-3.10.0/testparse.c000066400000000000000000000076351254600523400155670ustar00rootroot00000000000000/* test parse_cooked_ax25 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "libax25ext.h" static void print_it(FILE *f, struct ax_calls *calls, u_char *data, int len); static void drop_unused_digis(struct ax_calls *); main() { unsigned char buf[2048],*bp; int buflen, *lp = &buflen; while (fgets(buf,sizeof(buf),stdin)) { unsigned char obuf[2048], *op; int r,olen = sizeof(obuf), *olp = &olen; struct ax_calls calls; bp = buf; buflen = strlen(buf); if (buf[buflen-1] == '\n') buf[--buflen] = '\0'; op = obuf; olen = sizeof(obuf); bzero(obuf,sizeof(obuf)); fprintf(stderr,"================================\ninput: %s\n",buf); switch(r=parse_cooked_ax25(&bp,lp,&calls)) { case PK_VALID: case PK_VALDIGI: fprintf(stderr,"valid%s packet. n_digis: %d next_digi: %d type: %d pid: %d\n", (r==PK_VALDIGI)?" repeatable":"", calls.ax_n_digis, calls.ax_next_digi, calls.ax_type, calls.ax_pid); fprintf(stderr,"data @0x%0x (len %d): %s\n",bp,buflen,bp); fprintf(stderr,"---- print_it ----\n"); print_it(stderr,&calls,bp,buflen); fprintf(stderr,"---- gen_cooked thing: ----\n"); fprintf(stderr,"gen_cooked rc: %d\n",gen_cooked_ax25(&op,olp,&calls)); fprintf(stderr,"cooked@0x%0x (len %d): %s\n",obuf,olen,obuf);/* ?? */ fprintf(stderr,"data @0x%0x (len %d): %s\n", bp, buflen, bp); strncpy(&obuf[sizeof(obuf)-olen],bp,buflen); printf("%s\n",obuf); fprintf(stderr,"after dropping unused digis:\n"); drop_unused_digis(&calls); fprintf(stderr," n_digis: %d next_digi: %d type: %d pid: %d\n", calls.ax_n_digis, calls.ax_next_digi, calls.ax_type, calls.ax_pid); print_it(stderr,&calls,bp,buflen); break; case PK_INVALID: fprintf(stderr,"failed to parse\n"); break; default: fprintf(stderr,"bogus return value\n"); break; } } } /* some defines that really belong in a header file! */ #define ALEN 6 /* index to where the SSID and flags go */ #define AXLEN 7 /* length of a callsign */ /* SSID mask and various flags that are stuffed into the SSID byte */ #define SSID 0x1E #define HDLCAEB 0x01 #define REPEATED 0x80 #define UI 0x03 /* unnumbered information (unproto) */ #define PID_NO_L3 0xF0 /* no level-3 (text) */ #define C 0x80 #define SSSID_SPARE 0x40 /* must be set if not used */ #define ESSID_SPARE 0x20 static void print_it(FILE *f, struct ax_calls *calls, u_char *data, int len) { int j; char asc_from[12],asc_to[12]; if (f == NULL) return; fprintf(stderr,"print_it: n_digis %d next_digi %d\n", calls->ax_n_digis,calls->ax_next_digi); strncpy(asc_to,ax25_ntoa_pretty(&calls->ax_to_call),sizeof(asc_to)); strncpy(asc_from,ax25_ntoa_pretty(&calls->ax_from_call),sizeof(asc_from)); fprintf(f,"%s>%s",asc_from,asc_to); for (j = 0; j < calls->ax_n_digis; j++) { fprintf(stderr,"\nprint_it: digi[%d]: %s %s\n",j, (calls->ax_digi_call[j].ax25_call[ALEN]&REPEATED)?"REPEATED":"", (calls->ax_digi_call[j].ax25_call[ALEN]&HDLCAEB)?"HDLCAEB":""); fprintf(f,",%s%s",ax25_ntoa_pretty(&calls->ax_digi_call[j]), (calls->ax_digi_call[j].ax25_call[ALEN]&REPEATED && (j == calls->ax_next_digi-1))?"*":""); } fprintf(f,":%.*s\n",len,data); } static void drop_unused_digis(struct ax_calls *calls) { if (!calls->ax_n_digis || calls->ax_next_digi >= calls->ax_n_digis) return; /* all digis are used up */ calls->ax_n_digis = calls->ax_next_digi; /* truncate the list */ calls->ax_digi_call[calls->ax_next_digi-1].ax25_call[ALEN] |= HDLCAEB; }