1 /* $NetBSD: fsm.h,v 1.4 2014/10/25 21:11:37 christos Exp $ */ 2 3 /* 4 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. 5 * 6 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The name "Carnegie Mellon University" must not be used to 21 * endorse or promote products derived from this software without 22 * prior written permission. For permission or any legal 23 * details, please contact 24 * Office of Technology Transfer 25 * Carnegie Mellon University 26 * 5000 Forbes Avenue 27 * Pittsburgh, PA 15213-3890 28 * (412) 268-4387, fax: (412) 268-7395 29 * tech-transfer@andrew.cmu.edu 30 * 31 * 4. Redistributions of any form whatsoever must retain the following 32 * acknowledgment: 33 * "This product includes software developed by Computing Services 34 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 35 * 36 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 37 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 38 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 39 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 40 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 41 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 42 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 43 * 44 * Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp 45 */ 46 47 /* 48 * Packet header = Code, id, length. 49 */ 50 #define HEADERLEN 4 51 52 53 /* 54 * CP (LCP, IPCP, etc.) codes. 55 */ 56 #define CONFREQ 1 /* Configuration Request */ 57 #define CONFACK 2 /* Configuration Ack */ 58 #define CONFNAK 3 /* Configuration Nak */ 59 #define CONFREJ 4 /* Configuration Reject */ 60 #define TERMREQ 5 /* Termination Request */ 61 #define TERMACK 6 /* Termination Ack */ 62 #define CODEREJ 7 /* Code Reject */ 63 64 65 /* 66 * Each FSM is described by an fsm structure and fsm callbacks. 67 */ 68 typedef struct fsm { 69 int unit; /* Interface unit number */ 70 int protocol; /* Data Link Layer Protocol field value */ 71 int state; /* State */ 72 int flags; /* Contains option bits */ 73 u_char id; /* Current id */ 74 u_char reqid; /* Current request id */ 75 u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */ 76 int timeouttime; /* Timeout time in milliseconds */ 77 int maxconfreqtransmits; /* Maximum Configure-Request transmissions */ 78 int retransmits; /* Number of retransmissions left */ 79 int maxtermtransmits; /* Maximum Terminate-Request transmissions */ 80 int nakloops; /* Number of nak loops since last ack */ 81 int rnakloops; /* Number of naks received */ 82 int maxnakloops; /* Maximum number of nak loops tolerated */ 83 struct fsm_callbacks *callbacks; /* Callback routines */ 84 char *term_reason; /* Reason for closing protocol */ 85 int term_reason_len; /* Length of term_reason */ 86 } fsm; 87 88 89 typedef struct fsm_callbacks { 90 void (*resetci) /* Reset our Configuration Information */ 91 __P((fsm *)); 92 int (*cilen) /* Length of our Configuration Information */ 93 __P((fsm *)); 94 void (*addci) /* Add our Configuration Information */ 95 __P((fsm *, u_char *, int *)); 96 int (*ackci) /* ACK our Configuration Information */ 97 __P((fsm *, u_char *, int)); 98 int (*nakci) /* NAK our Configuration Information */ 99 __P((fsm *, u_char *, int, int)); 100 int (*rejci) /* Reject our Configuration Information */ 101 __P((fsm *, u_char *, int)); 102 int (*reqci) /* Request peer's Configuration Information */ 103 __P((fsm *, u_char *, int *, int)); 104 void (*up) /* Called when fsm reaches OPENED state */ 105 __P((fsm *)); 106 void (*down) /* Called when fsm leaves OPENED state */ 107 __P((fsm *)); 108 void (*starting) /* Called when we want the lower layer */ 109 __P((fsm *)); 110 void (*finished) /* Called when we don't want the lower layer */ 111 __P((fsm *)); 112 void (*protreject) /* Called when Protocol-Reject received */ 113 __P((int)); 114 void (*retransmit) /* Retransmission is necessary */ 115 __P((fsm *)); 116 int (*extcode) /* Called when unknown code received */ 117 __P((fsm *, int, int, u_char *, int)); 118 char *proto_name; /* String name for protocol (for messages) */ 119 } fsm_callbacks; 120 121 122 /* 123 * Link states. 124 */ 125 #define INITIAL 0 /* Down, hasn't been opened */ 126 #define STARTING 1 /* Down, been opened */ 127 #define CLOSED 2 /* Up, hasn't been opened */ 128 #define STOPPED 3 /* Open, waiting for down event */ 129 #define CLOSING 4 /* Terminating the connection, not open */ 130 #define STOPPING 5 /* Terminating, but open */ 131 #define REQSENT 6 /* We've sent a Config Request */ 132 #define ACKRCVD 7 /* We've received a Config Ack */ 133 #define ACKSENT 8 /* We've sent a Config Ack */ 134 #define OPENED 9 /* Connection available */ 135 136 137 /* 138 * Flags - indicate options controlling FSM operation 139 */ 140 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */ 141 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ 142 #define OPT_SILENT 4 /* Wait for peer to speak first */ 143 144 145 /* 146 * Timeouts. 147 */ 148 #define DEFTIMEOUT 3 /* Timeout time in seconds */ 149 #define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ 150 #define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ 151 #define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ 152 153 154 /* 155 * Prototypes 156 */ 157 void fsm_init __P((fsm *)); 158 void fsm_lowerup __P((fsm *)); 159 void fsm_lowerdown __P((fsm *)); 160 void fsm_open __P((fsm *)); 161 void fsm_close __P((fsm *, char *)); 162 void fsm_input __P((fsm *, u_char *, int)); 163 void fsm_protreject __P((fsm *)); 164 void fsm_sdata __P((fsm *, int, int, u_char *, int)); 165 166 167 /* 168 * Variables 169 */ 170 extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */ 171