2 * lib/ax25.c This file contains an implementation of the "AX.25"
5 * Version: $Id: ax25.c,v 1.9 1999/09/27 11:00:45 philip Exp $
7 * NOTE: I will redo this module as soon as I got the libax25.a
8 * library sorted out. This library contains some useful
9 * and often used address conversion functions, database
10 * lookup stuff, and more of the like.
12 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
13 * Copyright 1993 MicroWalt Corporation
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
23 #if HAVE_AFAX25 || HAVE_HWAX25
24 #include <sys/types.h>
25 #include <sys/ioctl.h>
26 #include <sys/socket.h>
27 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
28 #include <netax25/ax25.h>
30 #include <linux/ax25.h>
32 #include <net/if_arp.h>
41 #include "net-support.h"
42 #include "pathnames.h"
46 static char AX25_errmsg[128];
48 extern struct aftype ax25_aftype;
50 static char *AX25_print(unsigned char *ptr)
55 for (i = 0; i < 6; i++) {
56 buff[i] = ((ptr[i] & 0377) >> 1);
61 i = ((ptr[6] & 0x1E) >> 1);
63 sprintf(&buff[strlen(buff)], "-%d", i);
68 /* Display an AX.25 socket address. */
70 AX25_sprint(struct sockaddr *sap, int numeric)
74 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
75 return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
76 return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call));
80 static int AX25_input(int type, char *bufp, struct sockaddr *sap)
86 sap->sa_family = ax25_aftype.af;
87 ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call;
89 /* First, scan and convert the basic callsign. */
92 while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) {
96 if (!(isupper(c) || isdigit(c))) {
97 safe_strncpy(AX25_errmsg, _("Invalid callsign"), sizeof(AX25_errmsg));
99 fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig);
104 *ptr++ = (unsigned char) ((c << 1) & 0xFE);
108 /* Callsign too long? */
109 if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) {
110 strcpy(AX25_errmsg, _("Callsign too long"));
112 fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig);
117 /* Nope, fill out the address bytes with blanks. */
118 while (i++ < sizeof(ax25_address) - 1) {
119 *ptr++ = (unsigned char) ((' ' << 1) & 0xFE);
122 /* See if we need to add an SSID field. */
125 *ptr = (unsigned char) ((i << 1) & 0xFE);
127 *ptr = (unsigned char) '\0';
132 fprintf(stderr, "ax25_input(%s): ", orig);
133 for (i = 0; i < sizeof(ax25_address); i++)
134 fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
135 fprintf(stderr, "\n");
142 /* Display an error message. */
143 static void AX25_herror(char *text)
146 fprintf(stderr, "%s\n", AX25_errmsg);
148 fprintf(stderr, "%s: %s\n", text, AX25_errmsg);
152 static int AX25_hinput(char *bufp, struct sockaddr *sap)
154 if (AX25_input(0, bufp, sap) < 0)
156 sap->sa_family = ARPHRD_AX25;
161 /* Set the line discipline of a terminal line. */
162 static int KISS_set_disc(int fd, int disc)
164 if (ioctl(fd, TIOCSETD, &disc) < 0) {
165 fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno));
172 /* Start the KISS encapsulation on the file descriptor. */
173 static int KISS_init(int fd)
175 if (KISS_set_disc(fd, N_SLIP) < 0)
177 if (ioctl(fd, SIOCSIFENCAP, 4) < 0)
183 struct hwtype ax25_hwtype =
185 "ax25", NULL, /*"AMPR AX.25", */ ARPHRD_AX25, 7,
186 AX25_print, AX25_hinput, NULL
189 struct aftype ax25_aftype =
191 "ax25", NULL, /*"AMPR AX.25", */ AF_AX25, 7,
192 AX25_print, AX25_sprint, AX25_input, AX25_herror,
198 #endif /* HAVE_xxAX25 */