home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / include / sys / xtproto.h < prev   
Encoding:
C/C++ Source or Header  |  1990-12-08  |  4.9 KB  |  150 lines

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