home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / UNIX3862.ZIP / U386-06.ZIP / U386-6.TD0 / usr / include / sys / xtproto.h < prev   
Encoding:
C/C++ Source or Header  |  1988-06-26  |  4.7 KB  |  148 lines

  1. /*    Copyright (c) 1984, 1986, 1987, 1988 AT&T    */
  2. /*      All Rights Reserved      */
  3.  
  4. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T    */
  5. /*    The copyright notice above does not evidence any       */
  6. /*    actual or intended publication of such source code.    */
  7.  
  8.  
  9. #ident    "@(#)head.sys:xtproto.h    1.3"
  10.  
  11. /*
  12. **    Bx -- Blit packet protocol definition
  13. */
  14.  
  15. typedef    unsigned char    Pbyte;            /* The unit of communication */
  16.  
  17. #define    NPCBUFS        2            /* Double buffered protocol */
  18. #define    MAXPCHAN    8            /* Maximum channel number */
  19.  
  20. /*    Packet Header:
  21.  *
  22.  *      High order bits                                      Low order bits
  23.  *    ____________________________________________________________________
  24.  *    |       |       |        |       ||                                |
  25.  *    | ptyp  | cntl  | chan   | seq   || dsize                          |
  26.  *    |       |       |        |       ||                                |
  27.  *    --------------------------------------------------------------------
  28.  *     15      14      13    11 10    8  7                              0
  29.  *
  30.  *    ptyp  - always 1.
  31.  *    cntl  - TRUE if control packet.
  32.  *    chan  - channel number.
  33.  *    seq   - sequence number.
  34.  *    dsize - size of the data part.
  35.  *
  36.  *    Note:   The following macros are used to set the bits in the packet
  37.  *            header for portability reasons. The bit fields that can be
  38.  *            defined in C are preferable for simplicity reasons, but are
  39.  *            highly machine dependent.
  40.  */
  41.  
  42. #define GET_BITS(byte,pos,len,mask)     ((byte & mask) >> pos)
  43. #define SET_BITS(byte,pos,len,mask,val) (byte = (byte &(~mask))|((val<<pos)&mask))
  44.  
  45. #define PTYPPOS             7
  46. #define PTYPSIZ             1
  47. #define PTYPMASK            0x80
  48. #define GET_PTYP(pkt)       GET_BITS(pkt.header[0],PTYPPOS,PTYPSIZ,PTYPMASK)
  49. #define SET_PTYP(pkt,val)   SET_BITS(pkt.header[0],PTYPPOS,PTYPSIZ,PTYPMASK,val)
  50.  
  51. #define CNTLPOS             6
  52. #define CNTLSIZ             1
  53. #define CNTLMASK            0x40
  54. #define GET_CNTL(pkt)       GET_BITS(pkt.header[0],CNTLPOS,CNTLSIZ,CNTLMASK)
  55. #define SET_CNTL(pkt,val)   SET_BITS(pkt.header[0],CNTLPOS,CNTLSIZ,CNTLMASK,val)
  56.  
  57. #define CHANPOS             3
  58. #define CHANSIZ             3
  59. #define CHANMASK            0x38
  60. #define GET_CHAN(pkt)       GET_BITS(pkt.header[0],CHANPOS,CHANSIZ,CHANMASK)
  61. #define SET_CHAN(pkt,val)   SET_BITS(pkt.header[0],CHANPOS,CHANSIZ,CHANMASK,val)
  62.  
  63. #define SEQPOS              0
  64. #define SEQSIZ              3
  65. #define    SEQMOD              8
  66. #define SEQMASK             0x07
  67. #define GET_SEQ(pkt)        GET_BITS(pkt.header[0],SEQPOS,SEQSIZ,SEQMASK)
  68. #define SET_SEQ(pkt,val)    SET_BITS(pkt.header[0],SEQPOS,SEQSIZ,SEQMASK,val)
  69.  
  70. #define HEADER_DSIZE        header[1]
  71.  
  72. /*
  73. **    Packet definition for maximum sized packet
  74. */
  75. #define    PKTHDRSIZE    (2 * sizeof(Pbyte))    /* packet header part size */
  76. #define    MAXPKTDSIZE    (32 * sizeof(Pbyte))    /* Maximum data part size */
  77. #define    EDSIZE        (2 * sizeof(Pbyte))    /* Error detection part size */
  78.  
  79. struct Packet
  80. {
  81.     Pbyte    header[PKTHDRSIZE];    /* Packet Header */
  82.     Pbyte    data[MAXPKTDSIZE];    /* Data part */
  83.     Pbyte    edb[EDSIZE];        /* Error detection part */
  84. };
  85.  
  86. typedef struct Packet *    Pkt_p;
  87.  
  88. /*
  89. **    Control codes
  90. */
  91.  
  92. #define    PCDATA        (Pbyte)002        /* Data only control packet       */
  93. #define    ACK        (Pbyte)006        /* Last packet ok and in sequence */
  94. #define    NAK        (Pbyte)025        /* Last packet out of sequence    */
  95.  
  96. /*
  97. **    Definition of a structure to hold status information
  98. **    for a conversation with a channel.
  99. */
  100.  
  101. struct Pktstate
  102. {
  103.     struct Packet    pkt;            /* The packet */
  104.     short        timo;            /* Timeout count */
  105.     unsigned char    state;            /* Protocol state */
  106.     unsigned char    size;            /* Packet size */
  107. };
  108.  
  109. typedef struct Pktstate *Pks_p;
  110.  
  111. struct Pchannel
  112. {
  113.     struct Pktstate    pkts[NPCBUFS];        /* The packets */
  114.     Pks_p        nextpkt;        /* Next packet to be acknowledged */
  115.     Pbyte        cdata[SEQMOD];        /* Remember transmitted control data */
  116.     Pbyte        rseq    :SEQSIZ;    /* Next receive sequence number */
  117.     Pbyte        xseq    :SEQSIZ;    /* Next transmit sequence number */
  118.     char        outen;            /* Output packets enabled */
  119.     char        flags;            /* Control flags */
  120. #if XTDRIVER == 1
  121.     char        channo;            /* This channel's number */
  122.     char        link;            /* This channel's link */
  123. #endif
  124. };
  125.  
  126. #define    XACK        1            /* Send ACK */
  127. #define    XNAK        2            /* Send NAK */
  128. #define    XCDATA        4            /* Send control data in ACK packet */
  129.  
  130. typedef struct Pchannel *Pch_p;
  131.  
  132. /**    Transmit packet states    **/
  133.  
  134. enum {    px_null, px_ready, px_wait, px_ok    };
  135.  
  136. #define    PX_NULL        (int)px_null        /* Empty packet */
  137. #define    PX_READY    (int)px_ready        /* Full packet awaiting transmission */
  138. #define    PX_WAIT        (int)px_wait        /* Packet awaiting acknowledgement */
  139. #define    PX_OK        (int)px_ok        /* Packet has been acknowledged */
  140.  
  141. /**    Receive packet states    **/
  142.  
  143. enum { pr_null, pr_size, pr_data };
  144.  
  145. #define    PR_NULL        (int)pr_null        /* New packet expected */
  146. #define    PR_SIZE        (int)pr_size        /* Size byte next */
  147. #define    PR_DATA        (int)pr_data        /* Receiving data */
  148.