home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / NR4 < prev    next >
Text File  |  1992-02-16  |  11KB  |  259 lines

  1. /* nr4.h:  defines for netrom layer 4 (transport) support.
  2.  * Copyright 1989 by Daniel M. Frank, W9NK.  Permission granted for
  3.  * non-commercial distribution only.
  4.  */
  5.  
  6. /* compile-time limitations */
  7.  
  8. #define NR4MAXCIRC      20              /* maximum number of open circuits */
  9. #define NR4MAXWIN       127             /* maximum window size, send and receive */
  10.                                                         
  11. /* protocol limitation: */
  12.  
  13. #define NR4MAXINFO      236             /* maximum data in an info packet */
  14.  
  15. /* sequence number wraparound mask */
  16.  
  17. #define NR4SEQMASK      0xff    /* eight-bit sequence numbers */
  18.  
  19. /* flags in high nybble of opcode byte */
  20.  
  21. #define NR4CHOKE        0x80
  22. #define NR4NAK          0x40
  23. #define NR4MORE         0x20    /* The "more follows" flag for */
  24.                                                         /* pointless packet reassembly */
  25.  
  26. /* mask for opcode nybble */
  27.  
  28. #define NR4OPCODE       0x0f
  29.  
  30. /* opcodes */
  31.  
  32. #define NR4OPPID        0               /* protocol ID extension to network layer */
  33. #define NR4OPCONRQ      1               /* connect request */
  34. #define NR4OPCONAK      2               /* connect acknowledge */
  35. #define NR4OPDISRQ      3               /* disconnect request */
  36. #define NR4OPDISAK      4               /* disconnect acknowledge */
  37. #define NR4OPINFO       5               /* information packet */
  38. #define NR4OPACK        6               /* information ACK */
  39. #define NR4NUMOPS       7               /* number of transport opcodes */
  40.  
  41. /* minimum length of NET/ROM transport header */
  42.  
  43. #define NR4MINHDR       5
  44.  
  45. /* host format net/rom transport header */
  46.  
  47. struct nr4hdr {
  48.         char opcode ;          /* opcode and flags */
  49.         char yourindex ;       /* receipient's circuit index */
  50.         char yourid ;          /* receipient's circuit ID */
  51.         
  52.         union {
  53.  
  54.                 struct {                                /* network extension */
  55.                         char family ;  /* protocol family */
  56.                         char proto ;   /* protocol within family */
  57.                 } pid ;
  58.  
  59.                 struct {                                /* connect request */
  60.                         char myindex ; /* sender's circuit index */
  61.                         char myid ;    /* sender's circuit ID */
  62.                         char window ;  /* sender's proposed window size */
  63.                         struct ax25_addr user ; /* callsign of originating user */
  64.                         struct ax25_addr node ; /* callsign of originating node */
  65.                 } conreq ;
  66.  
  67.                 struct {                                /* connect acknowledge */
  68.                         char myindex ; /* sender's circuit index */
  69.                         char myid ;    /* sender's circuit ID */
  70.                         char window ;  /* accepted window size */
  71.                 } conack ;
  72.  
  73.                 struct {                                /* information */
  74.                         char txseq ;   /* sender's tx sequence number */
  75.                         char rxseq ;   /* sender's rx sequence number */
  76.                 } info ;
  77.  
  78.                 struct {                                /* information acknowledge */
  79.                         char rxseq ;   /* sender's rx sequence number */
  80.                 } ack ;
  81.  
  82.         } u ;   /* End of union */
  83.  
  84. } ;
  85.  
  86. /* The netrom circuit pointer structure */
  87.  
  88. struct nr4circp {
  89.         char cid ;                     /* circuit ID; incremented each time*/
  90.                                                                 /* this circuit is used */
  91.         struct nr4cb *ccb ;                     /* pointer to circuit control block, */
  92.                                                                 /*  NULLNR4CB if not in use */
  93. } ;
  94.  
  95. /* The circuit table: */
  96.  
  97. extern struct nr4circp Nr4circuits[NR4MAXCIRC] ;
  98.  
  99. /* A netrom send buffer structure */
  100.  
  101. struct nr4txbuf {
  102.         struct timer tretry ;           /* retry timer */
  103.         unsigned retries ;                      /* number of retries */
  104.         struct mbuf *data ;                     /* data sent but not acknowledged */
  105. } ;
  106.  
  107. /* A netrom receive buffer structure */
  108.  
  109. struct nr4rxbuf {
  110.         char occupied ;                 /* flag: buffer in use */
  111.         struct mbuf *data ;             /* data received out of sequence */
  112. } ;
  113.  
  114. /* The netrom circuit control block */
  115.  
  116. struct nr4cb {
  117.         unsigned mynum ;                        /* my circuit number */
  118.         unsigned myid ;                         /* my circuit ID */
  119.         unsigned yournum ;                      /* remote circuit number */
  120.         unsigned yourid ;                       /* remote circuit ID */
  121.         struct ax25_addr user ;         /* callsign of originating user (if any) */
  122.         struct ax25_addr node ;         /* callsign of remote node */
  123.         struct ax25_addr luser ;        /* callsign of local "user", for connections */
  124.                                                                 /* that we initiate */
  125.         unsigned window ;                       /* negotiated window size */
  126.  
  127.         /* Data for round trip timer calculation and setting */
  128.         
  129.         long srtt ;                                     /* Smoothed round trip time */
  130.         long mdev ;                                     /* Mean deviation in round trip time */
  131.         unsigned blevel ;                       /* Backoff level */
  132.         unsigned txmax ;                        /* The maximum number of retries among */
  133.                                                                 /* the frames in the window.  This is 0 */
  134.                                                                 /* if there are no frames in the window. */
  135.                                                                 /* It is used as a baseline to determine */
  136.                                                                 /* when to increment the backoff level. */
  137.                                                                 
  138.         /* flags */
  139.         
  140.         char choked ;                           /* choke received from remote */
  141.         char qfull ;                            /* receive queue is full, and we have */
  142.                                                                 /* choked the other end */
  143.         char naksent ;                          /* a NAK has already been sent */
  144.  
  145.         /* transmit buffers and window variables */
  146.  
  147.         struct nr4txbuf *txbufs ;       /* pointer to array[windowsize] of bufs */
  148.         char nextosend ;                /* sequence # of next frame to send */
  149.         char ackxpected ;               /* sequence number of next expected ACK */
  150.         unsigned nbuffered ;            /* number of buffered TX frames */
  151.         struct mbuf *txq ;              /* queue of unsent data */
  152.         
  153.         /* receive buffers and window variables */
  154.  
  155.         struct nr4rxbuf *rxbufs ;       /* pointer to array[windowsize] of bufs */
  156.         char rxpected ;                 /* # of next receive frame expected */
  157.         char rxpastwin ;                /* top of RX window + 1 */ 
  158.         struct mbuf *rxq ;              /* "fully" received data queue */
  159.  
  160.         /* Connection state */
  161.         
  162.         int state ;                                     /* connection state */
  163. #define NR4STDISC       0                       /* disconnected */
  164. #define NR4STCPEND      1                       /* connection pending */
  165. #define NR4STCON        2                       /* connected */
  166. #define NR4STDPEND      3                       /* disconnect requested locally */
  167.  
  168.         int dreason ;                           /* Reason for disconnect */
  169. #define NR4RNORMAL      0                       /* Normal, requested disconnect */
  170. #define NR4RREMOTE      1                       /* Remote requested */
  171. #define NR4RTIMEOUT     2                       /* Connection timed out */
  172. #define NR4RRESET       3                       /* Connection reset locally */
  173. #define NR4RREFUSED     4                       /* Connect request refused */
  174.  
  175.         /* Per-connection timers */
  176.         
  177.         struct timer tchoke ;           /* choke timeout */
  178.         struct timer tack ;                     /* a