1 /* 2 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. 3 * 4 * Copyright (c) 2000 by Sun Microsystems, Inc. 5 * All rights reserved. 6 * 7 * Permission to use, copy, modify, and distribute this software and its 8 * documentation is hereby granted, provided that the above copyright 9 * notice appears in all copies. 10 * 11 * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF 12 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 13 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 14 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR 15 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR 16 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES 17 * 18 * Copyright (c) 1989 Carnegie Mellon University. 19 * All rights reserved. 20 * 21 * Redistribution and use in source and binary forms are permitted 22 * provided that the above copyright notice and this paragraph are 23 * duplicated in all such forms and that any documentation, 24 * advertising materials, and other materials related to such 25 * distribution and use acknowledge that the software was developed 26 * by Carnegie Mellon University. The name of the 27 * University may not be used to endorse or promote products derived 28 * from this software without specific prior written permission. 29 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 30 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 31 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 32 * 33 * $Id: fsm.h,v 1.8 1999/11/15 01:51:50 paulus Exp $ 34 */ 35 36 #ifndef __FSM_H__ 37 #define __FSM_H__ 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /* 44 * Packet header = Code, id, length. 45 */ 46 #define HEADERLEN 4 47 48 /* 49 * Control Protocol (LCP, IPCP, etc.) message code numbers. 50 * (More in lcp.h and net/ppp-comp.h.) 51 */ 52 #define CODE_CONFREQ 1 /* Configuration Request */ 53 #define CODE_CONFACK 2 /* Configuration Ack */ 54 #define CODE_CONFNAK 3 /* Configuration Nak */ 55 #define CODE_CONFREJ 4 /* Configuration Reject */ 56 #define CODE_TERMREQ 5 /* Termination Request */ 57 #define CODE_TERMACK 6 /* Termination Ack */ 58 #define CODE_CODEREJ 7 /* Code Reject */ 59 60 61 /* 62 * Each FSM is described by an fsm structure and fsm callbacks. 63 */ 64 typedef struct fsm { 65 int unit; /* Interface unit number */ 66 int protocol; /* Data Link Layer Protocol field value */ 67 int state; /* State */ 68 int flags; /* Contains option bits */ 69 u_char id; /* Current id */ 70 u_char reqid; /* Current request id */ 71 u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */ 72 int timeouttime; /* Timeout time in milliseconds */ 73 int maxconfreqtransmits; /* Maximum Configure-Request transmissions */ 74 int retransmits; /* Number of retransmissions left */ 75 int maxtermtransmits; /* Maximum Terminate-Request transmissions */ 76 int nakloops; /* Number of nak loops since last ack */ 77 int maxnakloops; /* Maximum number of nak loops tolerated */ 78 struct fsm_callbacks *callbacks; /* Callback routines */ 79 char *term_reason; /* Reason for closing protocol */ 80 int term_reason_len; /* Length of term_reason */ 81 u_int32_t codemask[8]; /* Codes rejected by peer */ 82 } fsm; 83 84 /* 85 * Function RFC 1661 86 * ----- ------------------------------ 87 * ackci RCA 88 * nakci RCN 89 * rejci RCN 90 * reqci RCR+ or RCR- (by return value) 91 * up tlu (this-layer-up) 92 * down tld (this-layer-down) 93 * starting tls (this-layer-starting) 94 * finished tlf (this-layer-finished) 95 * codereject RXJ+ or RXJ- (by return value) 96 * 97 * Note that this-layer-down means "stop transmitting." 98 * This-layer-finished means "stop everything." 99 */ 100 101 typedef struct fsm_callbacks { 102 void (*resetci) /* Reset our Configuration Information */ 103 __P((fsm *)); 104 int (*cilen) /* Length of our Configuration Information */ 105 __P((fsm *)); 106 void (*addci) /* Add our Configuration Information */ 107 __P((fsm *, u_char *, int *)); 108 int (*ackci) /* ACK our Configuration Information */ 109 __P((fsm *, u_char *, int)); 110 int (*nakci) /* NAK our Configuration Information */ 111 __P((fsm *, u_char *, int)); 112 int (*rejci) /* Reject our Configuration Information */ 113 __P((fsm *, u_char *, int)); 114 int (*reqci) /* Request peer's Configuration Information */ 115 __P((fsm *, u_char *, int *, int)); 116 void (*up) /* Called when fsm reaches OPENED state */ 117 __P((fsm *)); 118 void (*down) /* Called when fsm leaves OPENED state */ 119 __P((fsm *)); 120 void (*starting) /* Called when we want the lower layer */ 121 __P((fsm *)); 122 void (*finished) /* Called when we don't want the lower layer */ 123 __P((fsm *)); 124 void (*retransmit) /* Retransmission is necessary */ 125 __P((fsm *)); 126 int (*extcode) /* Called when unknown code received */ 127 __P((fsm *, int, int, u_char *, int)); 128 char *proto_name; /* String name for protocol (for messages) */ 129 int (*codereject) /* Called when Code-Reject received */ 130 __P((fsm *p, int code, int id, u_char *inp, int len)); 131 } fsm_callbacks; 132 133 134 /* 135 * RFC 1661 NCP states. 136 */ 137 #define INITIAL 0 /* Down, hasn't been opened */ 138 #define STARTING 1 /* Down, been opened */ 139 #define CLOSED 2 /* Up, hasn't been opened */ 140 #define STOPPED 3 /* Open, waiting for down event */ 141 #define CLOSING 4 /* Terminating the connection, not open */ 142 #define STOPPING 5 /* Terminating, but open */ 143 #define REQSENT 6 /* We've sent a Config Request */ 144 #define ACKRCVD 7 /* We've received a Config Ack */ 145 #define ACKSENT 8 /* We've sent a Config Ack */ 146 #define OPENED 9 /* Connection available */ 147 148 #define FSM__STATES \ 149 "Initial", "Starting", "Closed", "Stopped", "Closing", "Stopping", \ 150 "ReqSent", "AckRcvd", "AckSent", "Opened" 151 152 /* 153 * Flags - indicate options controlling FSM operation 154 */ 155 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */ 156 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ 157 #define OPT_SILENT 4 /* Wait for peer to speak first */ 158 159 160 /* 161 * Timeouts. 162 */ 163 #define DEFTIMEOUT 3 /* Timeout time in seconds */ 164 #define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ 165 #define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ 166 #define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ 167 168 169 /* 170 * Prototypes 171 */ 172 void fsm_init __P((fsm *)); 173 void fsm_lowerup __P((fsm *)); 174 void fsm_lowerdown __P((fsm *)); 175 void fsm_open __P((fsm *)); 176 void fsm_close __P((fsm *, char *)); 177 void fsm_input __P((fsm *, u_char *, int)); 178 void fsm_protreject __P((fsm *)); 179 void fsm_sdata __P((fsm *, int, int, u_char *, int)); 180 void fsm_setpeermru __P((int, int)); 181 182 const char *fsm_state __P((int statenum)); 183 184 #ifdef __cplusplus 185 } 186 #endif 187 188 #endif /* __FSM_H__ */ 189