changes to run over both LLC and HDLC, and also use explicit shifts
[unix-history] / usr / src / sys / netccitt / hdlc.h
CommitLineData
7bcd1bb8 1/*-
fa58c82e 2 * Copyright (c) University of British Columbia, 1984
7bcd1bb8 3 * Copyright (c) 1991 The Regents of the University of California.
fa58c82e
KS
4 * All rights reserved.
5 *
7bcd1bb8
KB
6 * This code is derived from software contributed to Berkeley by the
7 * Laboratory for Computation Vision and the Computer Science Department
fa58c82e
KS
8 * of the University of British Columbia.
9 *
7bcd1bb8 10 * %sccs.include.redist.c%
fa58c82e 11 *
7bcd1bb8 12 * @(#)hdlc.h 7.4 (Berkeley) %G%
fa58c82e 13 */
7bcd1bb8 14
f44ae296 15#ifndef ORDER4
82237f5b
KS
16#define FALSE 0
17#define TRUE 1
82237f5b 18typedef u_char octet;
f44ae296
KS
19typedef char bool;
20
21/*
22 * HDLC Packet format definitions
23 * This will eventually have to be rewritten without reference
24 * to bit fields, to be compliant with ANSI C and alignment safe.
25 */
26
27#if BYTE_ORDER == BIG_ENDIAN
28#define ORDER4(a, b, c, d) a , b , c , d
29#define ORDER5(a, b, c, d, e) a , b , c , d , e
30#endif
31
32#if BYTE_ORDER == LITTLE_ENDIAN
33#define ORDER4(a, b, c, d) d , c , b , a
34#define ORDER5(a, b, c, d, e) e , d , c , b , a
35#endif
36#endif
82237f5b
KS
37
38#define MAX_INFO_LEN 4096+3+4
39#define ADDRESS_A 3 /* B'00000011' */
40#define ADDRESS_B 1 /* B'00000001' */
41
42struct Hdlc_iframe {
43 octet address;
f44ae296
KS
44 octet ORDER4(nr:3, pf:1, ns:3, hdlc_0:1);
45 octet i_field[MAX_INFO_LEN];
82237f5b
KS
46};
47
48struct Hdlc_sframe {
49 octet address;
f44ae296 50 octet ORDER4(nr:3, pf:1, s2:2, hdlc_01:2);
82237f5b
KS
51};
52
53struct Hdlc_uframe {
54 octet address;
f44ae296 55 octet ORDER4(m3:3, pf:1, m2:2, hdlc_11:2);
82237f5b
KS
56};
57
58struct Frmr_frame {
59 octet address;
60 octet control;
61 octet frmr_control;
f44ae296
KS
62 octet ORDER4(frmr_nr:3, frmr_f1_0:1, frmr_ns:3, frmr_f2_0:1);
63 octet ORDER5(frmr_0000:4, frmr_z:1, frmr_y:1, frmr_x:1, frmr_w:1);
82237f5b
KS
64};
65
66#define HDHEADERLN 2
67#define MINFRLN 2 /* Minimum frame length. */
68
69struct Hdlc_frame {
70 octet address;
71 octet control;
f44ae296 72 octet info[3]; /* min for FRMR */
82237f5b
KS
73};
74
75#define SABM_CONTROL 057 /* B'00101111' */
76#define UA_CONTROL 0143 /* B'01100011' */
77#define DISC_CONTROL 0103 /* B'01000011' */
78#define DM_CONTROL 017 /* B'00001111' */
79#define FRMR_CONTROL 0207 /* B'10000111' */
80#define RR_CONTROL 01 /* B'00000001' */
81#define RNR_CONTROL 05 /* B'00000101' */
82#define REJ_CONTROL 011 /* B'00001001' */
83
84#define POLLOFF 0
85#define POLLON 1
86
87/* Define Link State constants. */
88
89#define INIT 0
90#define DM_SENT 1
91#define SABM_SENT 2
92#define ABM 3
93#define WAIT_SABM 4
94#define WAIT_UA 5
95#define DISC_SENT 6
96#define DISCONNECTED 7
97#define MAXSTATE 8
98
99/* The following constants are used in a switch statement to process
100 frames read from the communications line. */
101
102#define SABM 0 * MAXSTATE
103#define DM 1 * MAXSTATE
104#define DISC 2 * MAXSTATE
105#define UA 3 * MAXSTATE
106#define FRMR 4 * MAXSTATE
107#define RR 5 * MAXSTATE
108#define RNR 6 * MAXSTATE
109#define REJ 7 * MAXSTATE
110#define IFRAME 8 * MAXSTATE
111#define ILLEGAL 9 * MAXSTATE
112
113#define T1 (3 * PR_SLOWHZ) /* IFRAME TIMEOUT - 3 seconds */
114#define T3 (T1 / 2) /* RR generate timeout - 1.5 seconds */
115#define N2 10
116#define MODULUS 8
117#define MAX_WINDOW_SIZE 7
118
119#define Z 0
120#define Y 1
121#define X 2
122#define W 3
123#define A 4
124
125#define TX 0
126#define RX 1
127
128bool range_check ();
129bool valid_nr ();
130struct mbuf *hd_remove ();