home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 April / macformat-049.iso / mac / Shareware Plus / Developers / dropg++ / usr / include / netccitt / hdlc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.7 KB  |  157 lines  |  [TEXT/R*ch]

  1. /*-
  2.  * Copyright (c) University of British Columbia, 1984
  3.  * Copyright (c) 1991, 1993
  4.  *    The Regents of the University of California.  All rights reserved.
  5.  *
  6.  * This code is derived from software contributed to Berkeley by the
  7.  * Laboratory for Computation Vision and the Computer Science Department
  8.  * of the University of British Columbia.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    @(#)hdlc.h    8.1 (Berkeley) 6/10/93
  39.  */
  40.  
  41. #ifndef ORDER4
  42. #define FALSE   0
  43. #define TRUE    1
  44. typedef u_char octet;
  45. typedef char    bool;
  46.  
  47. /*
  48.  *  HDLC Packet format definitions
  49.  *  This will eventually have to be rewritten without reference
  50.  *  to bit fields, to be compliant with ANSI C and alignment safe.
  51.  */
  52.  
  53. #if BYTE_ORDER == BIG_ENDIAN
  54. #define ORDER4(a, b, c, d) a , b , c , d
  55. #define ORDER5(a, b, c, d, e) a , b , c , d , e
  56. #endif
  57.  
  58. #if BYTE_ORDER == LITTLE_ENDIAN
  59. #define ORDER4(a, b, c, d) d , c , b , a
  60. #define ORDER5(a, b, c, d, e) e , d , c , b , a
  61. #endif
  62. #endif
  63.  
  64. #define MAX_INFO_LEN    4096+3+4
  65. #define ADDRESS_A       3    /* B'00000011' */
  66. #define ADDRESS_B       1    /* B'00000001' */
  67.  
  68. struct Hdlc_iframe {
  69.     octet    address;
  70.     octet    ORDER4(nr:3, pf:1, ns:3, hdlc_0:1);
  71.     octet    i_field[MAX_INFO_LEN];
  72. };
  73.  
  74. struct Hdlc_sframe {
  75.     octet    address;
  76.     octet    ORDER4(nr:3, pf:1, s2:2, hdlc_01:2);
  77. };
  78.  
  79. struct    Hdlc_uframe {
  80.     octet    address;
  81.     octet    ORDER4(m3:3, pf:1, m2:2, hdlc_11:2);
  82. };
  83.  
  84. struct    Frmr_frame {
  85.     octet    address;
  86.     octet    control;
  87.     octet    frmr_control;
  88.     octet    ORDER4(frmr_nr:3, frmr_f1_0:1, frmr_ns:3, frmr_f2_0:1);
  89.     octet    ORDER5(frmr_0000:4, frmr_z:1, frmr_y:1, frmr_x:1, frmr_w:1);
  90. };
  91.  
  92. #define HDHEADERLN    2
  93. #define MINFRLN        2        /* Minimum frame length. */
  94.  
  95. struct    Hdlc_frame {
  96.     octet    address;
  97.     octet    control;
  98.     octet    info[3];    /* min for FRMR */
  99. };
  100.  
  101. #define SABM_CONTROL 057    /* B'00101111' */
  102. #define UA_CONTROL   0143    /* B'01100011' */
  103. #define DISC_CONTROL 0103    /* B'01000011' */
  104. #define DM_CONTROL   017    /* B'00001111' */
  105. #define FRMR_CONTROL 0207    /* B'10000111' */
  106. #define RR_CONTROL   01        /* B'00000001' */
  107. #define RNR_CONTROL  05        /* B'00000101' */
  108. #define REJ_CONTROL  011    /* B'00001001' */
  109.  
  110. #define POLLOFF  0
  111. #define POLLON   1
  112.  
  113. /* Define Link State constants. */
  114.  
  115. #define INIT        0
  116. #define DM_SENT        1
  117. #define SABM_SENT    2
  118. #define ABM        3
  119. #define WAIT_SABM    4
  120. #define WAIT_UA        5
  121. #define DISC_SENT    6
  122. #define DISCONNECTED    7
  123. #define MAXSTATE    8
  124.  
  125. /* The following constants are used in a switch statement to process
  126.    frames read from the communications line. */
  127.  
  128. #define SABM     0 * MAXSTATE
  129. #define DM       1 * MAXSTATE
  130. #define DISC     2 * MAXSTATE
  131. #define UA       3 * MAXSTATE
  132. #define FRMR     4 * MAXSTATE
  133. #define RR       5 * MAXSTATE
  134. #define RNR      6 * MAXSTATE
  135. #define REJ      7 * MAXSTATE
  136. #define IFRAME   8 * MAXSTATE
  137. #define ILLEGAL  9 * MAXSTATE
  138.  
  139. #define T1    (3 * PR_SLOWHZ)        /*  IFRAME TIMEOUT - 3 seconds */
  140. #define T3    (T1 / 2)        /*  RR generate timeout - 1.5 seconds */
  141. #define N2    10
  142. #define MODULUS 8
  143. #define MAX_WINDOW_SIZE 7
  144.  
  145. #define Z  0
  146. #define Y  1
  147. #define X  2
  148. #define W  3
  149. #define A  4
  150.  
  151. #define TX 0
  152. #define RX 1
  153.  
  154. bool    range_check ();
  155. bool    valid_nr ();
  156. struct    mbuf *hd_remove ();
  157.