2 * lib/netrom.c This file contains an implementation of the "NET/ROM"
3 * support functions for the NET-2 base distribution.
5 * Version: $Id: netrom.c,v 1.8 2000/03/05 11:26:03 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
16 * 980701 {1.21} Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
17 * strncpy instead of strcpy for
20 * This program is free software; you can redistribute it
21 * and/or modify it under the terms of the GNU General
22 * Public License as published by the Free Software
23 * Foundation; either version 2 of the License, or (at
24 * your option) any later version.
28 #if HAVE_AFNETROM || HAVE_HWNETROM
29 #include <sys/types.h>
30 #include <sys/ioctl.h>
31 #include <sys/socket.h>
32 #include <net/if_arp.h>
33 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
34 #include <netax25/ax25.h>
36 #include <linux/ax25.h>
46 #include "net-support.h"
47 #include "pathnames.h"
51 static char netrom_errmsg[128];
53 extern struct aftype netrom_aftype;
55 static const char *NETROM_print(const char *ptr)
60 for (i = 0; i < 6; i++) {
61 buff[i] = ((ptr[i] & 0377) >> 1);
66 i = ((ptr[6] & 0x1E) >> 1);
68 sprintf(&buff[strlen(buff)], "-%d", i);
73 /* Display an AX.25 socket address. */
74 static const char *NETROM_sprint(struct sockaddr *sap, int numeric)
77 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
78 return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
79 return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call));
88 static int NETROM_input(int type, char *bufp, struct sockaddr *sap)
94 sap->sa_family = netrom_aftype.af;
95 ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call;
97 /* First, scan and convert the basic callsign. */
100 while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) {
104 if (!(isupper(c) || isdigit(c))) {
105 safe_strncpy(netrom_errmsg, _("Invalid callsign"), sizeof(netrom_errmsg));
107 fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig);
111 *ptr++ = (unsigned char) ((c << 1) & 0xFE);
115 /* Callsign too long? */
116 if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) {
117 safe_strncpy(netrom_errmsg, _("Callsign too long"), sizeof(netrom_errmsg));
119 fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig);
123 /* Nope, fill out the address bytes with blanks. */
124 while (i++ < sizeof(ax25_address) - 1) {
125 *ptr++ = (unsigned char) ((' ' << 1) & 0xFE);
128 /* See if we need to add an SSID field. */
131 *ptr = (unsigned char) ((i << 1) & 0xFE);
133 *ptr = (unsigned char) '\0';
138 fprintf(stderr, "netrom_input(%s): ", orig);
139 for (i = 0; i < sizeof(ax25_address); i++)
140 fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
141 fprintf(stderr, "\n");
148 /* Display an error message. */
149 static void NETROM_herror(char *text)
152 fprintf(stderr, "%s\n", netrom_errmsg);
154 fprintf(stderr, "%s: %s\n", text, netrom_errmsg);
158 static int NETROM_hinput(char *bufp, struct sockaddr *sap)
160 if (NETROM_input(0, bufp, sap) < 0)
162 sap->sa_family = ARPHRD_NETROM;
167 /* Set the line discipline of a terminal line. */
168 static int KISS_set_disc(int fd, int disc)
170 if (ioctl(fd, TIOCSETD, &disc) < 0) {
171 fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno));
178 /* Start the KISS encapsulation on the file descriptor. */
179 static int KISS_init(int fd)
181 if (KISS_set_disc(fd, N_SLIP) < 0)
183 if (ioctl(fd, SIOCSIFENCAP, 4) < 0)
189 struct hwtype netrom_hwtype =
191 "netrom", NULL, /* "AMPR NET/ROM", */ ARPHRD_NETROM, 7,
192 NETROM_print, NETROM_hinput, NULL, 0
195 struct aftype netrom_aftype =
197 "netrom", NULL, /* "AMPR NET/ROM", */ AF_NETROM, 7,
198 NETROM_print, NETROM_sprint, NETROM_input, NETROM_herror,
204 #endif /* HAVE_AFNETROM */