
/* Copyright 1986 by the Massachusetts Institute of Technology */
/* See permission and disclaimer notice in file notice.h */
#include	<notice.h>

/* Structure definition for ARPAnet packets.
 * Host-to-IMP and IMP-to-Host use the same format.
 * See sections 3.3 and 3.4 of BBN 1822 report for details.
 */


#define	arpkt	struct	arpstr

arpkt	{	bitb	ar_frmt;	/* format flags in low 4 */
		unsb	ar_net;		/* net (mbz) */
		bitb	ar_flags;	/* trace and leader flags */
		unsb	ar_mtype;	/* message type */
		bitb	ar_htype;	/* handling type */
		unsb	ar_host;	/* host */
		unss	ar_imp;		/* imp */
		unsb	ar_link;	/* link field of msg ID */
		bitb	ar_sblk;	/* sub-link and sub-type */
		unss	ar_len;		/* length in bits of msg */
/*		byte	ar_data[];	/* actual message bytes */
		};

#define	mkar(x)		((arpkt *) (x))
#define	mksara(x)	(mkar(x)->ar_host), (swab(mkar(x)->ar_imp))


/* Fields which are reserved and must be zero */

#define AR_UN0	0360	/* mask for first mbz field; unassigned 0 */
#define AR_UN1	0360	/* unassigned 1 */
#define AR_ULRF	03	/* Unused Leader flags */
#define	AR_UHT	0170	/* Unused bits in handling type */


/* Bit field manipulation */

#define AR_FMTM	017	/* mask to select format */
#define AR_FMT	017	/* Format indicator for 96 bit leaders */
#define	AR_TRC	010	/* Trace bit in leader flags */
#define	AR_HST	04	/* Host bit in leader flags */
#define	AR_HTP	0200	/* Priority bit for handling type */
#define	AR_HTL	07	/* Handling type msg length field */
#define	AR_SLM	0340	/* make for sub-link */
#define	AR_SLSH	4	/* shift value to look at it */
#define	AR_STM	017	/* mask for sub-type */



/* Various random ARPANet parameters and things. A connection is
 * specified by the three parameters IMP, Host, and Handling
 * type.
 */

#define	ARSPRI	044		/* Priority for setting up ARPANet sync */
#define	ARIPPRI	050		/* Priority for handling ARPANet input */
#define	NNOP	4		/* Number of NOP msgs to send to init imp */
#define HTR	7		/* Handling type for the messages we send */
#define RLTICS  2		/* Time to debounce ready line changes (secs)*/


/* Structures for maintaining RFNM counts. */

#define rbkt struct _rbktst_
rbkt {
    rbkt *r_link;		/* Link to next bucket */
    word r_addr;		/* Host address to identify link */
    int r_count;		/* Count of outstanding pkts on this link */
    unsl r_time;		/* time link was blocked */
};

#define rtbl struct _rtblst_
rtbl {
    net *r_netp;		/* Pointer back to net structure */
    rbkt *r_blks;		/* List of links with outsatnding packets */
    rbkt *r_free;		/* Free list of buckets */
    bitf r_flag;		/* Flag set if there is a timeout
				 * routine queued to scan for links
				 * that have been blocked too long.  */
};


/* This structure contains information specific to arpanet like interfaces.
 * The first half of the fields are initialized once, the second half
 * are initialized each time the imp goes down.
 */

#define	arneti	struct	arntst

arneti	{	inaddr	*a_name;	/* our Internet address */
		unsb	a_state;	/* state of imp synchronization */
		unsb	a_idwnc;	/* count of # time imp goes down */
		long	a_cmi;		/* Total # of control msgs received */
		long	a_cmo;		/* Total # of control messages sent */
	 	rtbl	a_rfnm;		/* # non-rfnm'ed msgs */
		unsw	a_scmi;		/* # control msgs rcved during sync */
		unsw	a_scmo;		/* # control msgs sent  during sync */
	};

#define	mkarni(x)	((arneti *) (x))


/* Macro to log a message and discard the packet.
 */

#define	dispkt(n_field)		freebuf(iob); \
				netp->n_field++; \
				return; \


/* Interface states, numerical order is important. */
#define	SDWN	0	/* Got I/O error so imp must be down */
#define SRDYL	1	/* Ready line lowered */
#define SRDYR	2	/* Host ready line raised */
#define	SNOP	3	/* Have flapped ready line, now sending NOPs */
#define	SUP	4	/* All NOPs sent, imp is probably up */
