1 /*- 2 * Copyright (c) University of British Columbia, 1984 3 * Copyright (c) 1991 The Regents of the University of California. 4 * 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 * %sccs.include.redist.c% 11 * 12 * @(#)hdlc.h 7.4 (Berkeley) 05/06/91 13 */ 14 15 #ifndef ORDER4 16 #define FALSE 0 17 #define TRUE 1 18 typedef u_char octet; 19 typedef 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 37 38 #define MAX_INFO_LEN 4096+3+4 39 #define ADDRESS_A 3 /* B'00000011' */ 40 #define ADDRESS_B 1 /* B'00000001' */ 41 42 struct Hdlc_iframe { 43 octet address; 44 octet ORDER4(nr:3, pf:1, ns:3, hdlc_0:1); 45 octet i_field[MAX_INFO_LEN]; 46 }; 47 48 struct Hdlc_sframe { 49 octet address; 50 octet ORDER4(nr:3, pf:1, s2:2, hdlc_01:2); 51 }; 52 53 struct Hdlc_uframe { 54 octet address; 55 octet ORDER4(m3:3, pf:1, m2:2, hdlc_11:2); 56 }; 57 58 struct Frmr_frame { 59 octet address; 60 octet control; 61 octet frmr_control; 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); 64 }; 65 66 #define HDHEADERLN 2 67 #define MINFRLN 2 /* Minimum frame length. */ 68 69 struct Hdlc_frame { 70 octet address; 71 octet control; 72 octet info[3]; /* min for FRMR */ 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 128 bool range_check (); 129 bool valid_nr (); 130 struct mbuf *hd_remove (); 131