1 /* 2 * Copyright (c) University of British Columbia, 1984 3 * Copyright (c) 1990 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the 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 are permitted 11 * provided that: (1) source distributions retain this entire copyright 12 * notice and comment, and (2) distributions including binaries display 13 * the following acknowledgement: ``This product includes software 14 * developed by the University of California, Berkeley and its contributors'' 15 * in the documentation or other materials provided with the distribution 16 * and in all advertising materials mentioning features or use of this 17 * software. Neither the name of the University nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 23 * 24 * @(#)hdlc.h 7.3 (Berkeley) 05/25/90 25 */ 26 #ifndef ORDER4 27 #define FALSE 0 28 #define TRUE 1 29 typedef u_char octet; 30 typedef char bool; 31 32 /* 33 * HDLC Packet format definitions 34 * This will eventually have to be rewritten without reference 35 * to bit fields, to be compliant with ANSI C and alignment safe. 36 */ 37 38 #if BYTE_ORDER == BIG_ENDIAN 39 #define ORDER4(a, b, c, d) a , b , c , d 40 #define ORDER5(a, b, c, d, e) a , b , c , d , e 41 #endif 42 43 #if BYTE_ORDER == LITTLE_ENDIAN 44 #define ORDER4(a, b, c, d) d , c , b , a 45 #define ORDER5(a, b, c, d, e) e , d , c , b , a 46 #endif 47 #endif 48 49 #define MAX_INFO_LEN 4096+3+4 50 #define ADDRESS_A 3 /* B'00000011' */ 51 #define ADDRESS_B 1 /* B'00000001' */ 52 53 struct Hdlc_iframe { 54 octet address; 55 octet ORDER4(nr:3, pf:1, ns:3, hdlc_0:1); 56 octet i_field[MAX_INFO_LEN]; 57 }; 58 59 struct Hdlc_sframe { 60 octet address; 61 octet ORDER4(nr:3, pf:1, s2:2, hdlc_01:2); 62 }; 63 64 struct Hdlc_uframe { 65 octet address; 66 octet ORDER4(m3:3, pf:1, m2:2, hdlc_11:2); 67 }; 68 69 struct Frmr_frame { 70 octet address; 71 octet control; 72 octet frmr_control; 73 octet ORDER4(frmr_nr:3, frmr_f1_0:1, frmr_ns:3, frmr_f2_0:1); 74 octet ORDER5(frmr_0000:4, frmr_z:1, frmr_y:1, frmr_x:1, frmr_w:1); 75 }; 76 77 #define HDHEADERLN 2 78 #define MINFRLN 2 /* Minimum frame length. */ 79 80 struct Hdlc_frame { 81 octet address; 82 octet control; 83 octet info[3]; /* min for FRMR */ 84 }; 85 86 #define SABM_CONTROL 057 /* B'00101111' */ 87 #define UA_CONTROL 0143 /* B'01100011' */ 88 #define DISC_CONTROL 0103 /* B'01000011' */ 89 #define DM_CONTROL 017 /* B'00001111' */ 90 #define FRMR_CONTROL 0207 /* B'10000111' */ 91 #define RR_CONTROL 01 /* B'00000001' */ 92 #define RNR_CONTROL 05 /* B'00000101' */ 93 #define REJ_CONTROL 011 /* B'00001001' */ 94 95 #define POLLOFF 0 96 #define POLLON 1 97 98 /* Define Link State constants. */ 99 100 #define INIT 0 101 #define DM_SENT 1 102 #define SABM_SENT 2 103 #define ABM 3 104 #define WAIT_SABM 4 105 #define WAIT_UA 5 106 #define DISC_SENT 6 107 #define DISCONNECTED 7 108 #define MAXSTATE 8 109 110 /* The following constants are used in a switch statement to process 111 frames read from the communications line. */ 112 113 #define SABM 0 * MAXSTATE 114 #define DM 1 * MAXSTATE 115 #define DISC 2 * MAXSTATE 116 #define UA 3 * MAXSTATE 117 #define FRMR 4 * MAXSTATE 118 #define RR 5 * MAXSTATE 119 #define RNR 6 * MAXSTATE 120 #define REJ 7 * MAXSTATE 121 #define IFRAME 8 * MAXSTATE 122 #define ILLEGAL 9 * MAXSTATE 123 124 #define T1 (3 * PR_SLOWHZ) /* IFRAME TIMEOUT - 3 seconds */ 125 #define T3 (T1 / 2) /* RR generate timeout - 1.5 seconds */ 126 #define N2 10 127 #define MODULUS 8 128 #define MAX_WINDOW_SIZE 7 129 130 #define Z 0 131 #define Y 1 132 #define X 2 133 #define W 3 134 #define A 4 135 136 #define TX 0 137 #define RX 1 138 139 bool range_check (); 140 bool valid_nr (); 141 struct mbuf *hd_remove (); 142