/*Pup.h -- All-level Pup declarations
     Last modified March 9, 1980  5:16 PM by Taft
  C version modified July 9, 1982  2:17 PM by Swinehart
  November 13, 1982  4:21 PM by Stewart
    requires #include <Env.h>  and <Queue.h>
  November 23, 1982  9:58 AM by Stewart, added maxNetworks
  November 28, 1982  5:31 PM by Stewart, formatting
  February 10, 1983  3:39 PM by Stewart, Route changed
  July 7, 1983  10:52 AM by Stewart, Route changed
/*----------------------------------------------------------------------- */
#define defaultPupDataBytes 230
  /* Total bytes, including header & encapsulation, = 256 */
#define typePup 02
            /* 01000, swapped */
#define ecNoEthernetInterface (Swab(2230))
#define ecBadEtherStatus (Swab(2231))
#define ecZeroHostAddress (Swab(2232))
/*----------------------------------------------------------------------- */


/*----------------------------------------------------------------------- */
struct PupSocket {  /* Host-relative "connection" ID */
/*----------------------------------------------------------------------- */
  word LS;
  word ms;
  };
#define lenPupSocket (sizeof (struct PupSocket)/2)
#define maxPupSockets 10

/*----------------------------------------------------------------------- */
struct Port {
/*----------------------------------------------------------------------- */
  byte net;
  byte host;
  struct PupSocket socket;
  };
#define lenPort  (sizeof(struct Port)/2)

/*----------------------------------------------------------------------- */
union PupData {
/*----------------------------------------------------------------------- */
  word words[1/*266*/];  /* actual length varies; yours probably lower */
  byte bytes [2/*defaultDataBytes*/];
  };

/*----------------------------------------------------------------------- */
struct Pup {  /* basic raw pup */
/*----------------------------------------------------------------------- */
  word length;
  byte transport; /* = { bit hopCnt 4; bit blank 4; }; */
  byte type;
  word id[2]; 
  struct Port dPort;
  struct Port sPort;
  union PupData data;
  word checksum;
  }; /* for documentation only--actual position varies */
#define pupOvBytes  22
#define pupOvWords  (pupOvBytes/2)
  /* Pup overhead (header + checksum) */

/*----------------------------------------------------------------------- */
struct EtherEncapsulation { /* Ethernet specific header */
/*----------------------------------------------------------------------- */
  byte dst;
  byte src;
  int type;
  struct Pup pup;
  };
#define lenEtherEncapsulation 2

/*----------------------------------------------------------------------- */
struct PBI  { /*packet buffer item */
/* ---------------------------------------------------------------------------- */
  struct PBI *link;    /*queue link */
  struct Queue *queue;  /* where to put packet after transmission */
  int clientWord; /* Give client a value in each PBI */
  struct Pup *pup;  /* encapsulation precedes Pup */
  };
#define lenPBIOverhead 4

/* one or the other of PortProc and q will be used */
struct SocketEntry {
  struct Port port;
  int *PortProc;
  struct Queue *q;
  };
#define lenSocketEntry (sizeof (struct SocketEntry)/2)

struct Route {
  byte host; /* Gateway host to reach target net */
  byte hops; /* hops to reach target net , FF if unknown */
  byte age; /* age of entry in seconds */
  };
#define lenRoute (sizeof(struct Route))
#define maxNetworks 256

/* Error protocol */
#define typeError 4

/* Sys.errors codes */
#define ecNoSuchSocket (Swab(2220))
#define ecBadAllocation (Swab(2221))
#define ecNoNetworkInterface (Swab(2222))
#define ecPupRTFull (Swab(2223))