/* AX.25 datagram (address) sub-layer definitions */

/* Maximum number of digipeaters */
#define MAXDIGIS	8	/* 8 digipeaters plus src/dest */
#define ALEN		6	/* Number of chars in callsign field */
#define AXALEN		7	/* Total AX.25 address length, including SSID */

/* Internal representation of an AX.25 address */
struct ax25_addr {
	char call[ALEN];
	char ssid;
#define SSID		0x1e	/* Sub station ID */
#define REPEATED	0x80	/* Has-been-repeated bit in repeater field */
#define E		0x01	/* Address extension bit */
#define C		0x80	/* Command/response designation */
};
#define NULLAXADDR	(struct ax25_addr *)0

/* Internal representation of an AX.25 header */
struct ax25 {
	struct ax25_addr dest;			/* Destination address */
	struct ax25_addr source;		/* Source address */
	struct ax25_addr digis[MAXDIGIS];	/* Digi string */
	int ndigis;				/* Number of digipeaters */
	int cmdrsp;				/* Command/response */
};

/* Per-call control block
 * These are indexed through 3 hash tables.
 * One table contains entries for each callsign capable of digipeating,
 * the second table contains entries each connectable callsign + the broadcast
 * addresses for IP and ARP (QST-0) and NET/ROM (NODES-0).  The third table
 * contains AX25 callsigns to be excluded from connects and digipeats.
 *
 * When it is a connectable callsing with a port number, initial upcall handlers
 * will also be stored by the server on this port.
 * The tables are used in ax_recv().
 */
struct ax25_call {
	struct ax25_call *next;		/* Doubly linked list pointers */
	struct ax25_call *prev;

	struct ax25_call *p_next;	/* Doubly linked list of port numbers */
	struct ax25_call *p_prev;

	struct ax25_addr addr;		/* Callsign */
	struct interface *interface;	/* Associated interface */
	int	port;			/* AX25 port number (when connectable) */
/* fixed port numbers for ax.25 servers */

#define TNCPORT		1		/* interactive AX25 connection port */
#define NETDIGIPORT	2		/* intelligent digipeater */
#define MHEARDPORT	3		/* show MHEARD list */
#define BRIDGEPORT	4		/* conference bridge */
#define TNC2PORT	5		/* TNC2 emulator */
#define MBOXPORT	6		/* mini mailbox */

	int	mode;			/* Operation mode for this callsign */
#define IP_ARP_CON	0		/* Normal callsign for interface */
#define CONNECT		1		/* AX25 connected mode */
#define DIGIPEAT	2		/* Standard digipeater, or gateway */
#define DIGICONNECT	3		/* Digipeater simulating a connect */

	int	flags;			/* Capability and Permission flags */
#define MULTICAST	0x01		/* Set if this entry is the multicast addr */
#define MULTI_IF	0x02		/* Set if callsign valid on all interfaces */
#define DIGIGATEWAY	0x04		/* Set if digipeater is a gateway */
#define IP_ARP_MULTI	0x10		/* when MULTICAST, this is QST-0 */
#define NETROM_MULTI	0x20		/* when MULTICAST, this is NODES-0 */

	void	(*r_upcall)();		/* Receiver upcall */
	void	(*t_upcall)();		/* Transmit upcall */
	void	(*s_upcall)();		/* State change upcall */
	char	*user;			/* User pointer */
};
#define NULLAXCALL	(struct ax25_call *)0
extern struct ax25_call *ax25_digi[];
extern struct ax25_call *ax25_call[];
extern struct ax25_call *ax25_excl[];
extern struct ax25_call *ax25_port;
extern struct ax25_call *cr_axcall(),*find_axcall();

/* C-bit stuff */
#define UNKNOWN		0
#define COMMAND		1
#define RESPONSE	2

/* Bit fields in AX.25 Level 3 Protocol IDs (PIDs)
 * The high order two bits control multi-frame messages.
 * The lower 6 bits is the actual PID. Single-frame messages are
 * sent with both the FIRST and LAST bits set, so that the resulting PIDs
 * are compatible with older code.
 */
#define PID_FIRST	0x80	/* Frame is first in a message */
#define PID_LAST	0x40	/* Frame is last in a message */
#define PID_PID		0x3f	/* Protocol ID subfield */

#define PID_IP		0x0c	/* ARPA Internet Protocol */
#define PID_ARP		0x0d	/* ARPA Address Resolution Protocol */
#define PID_NETROM	0x0f	/* NET/ROM */
#define PID_NO_L3	0x30	/* No level 3 protocol */
