1 /* 2 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 3 * 4 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 5 * 6 * Redistribution and use in source and binary forms are permitted 7 * provided that the above copyright notice and this paragraph are 8 * duplicated in all such forms and that any documentation, 9 * advertising materials, and other materials related to such 10 * distribution and use acknowledge that the software was developed 11 * by the Internet Initiative Japan. The name of the 12 * IIJ may not be used to endorse or promote products derived 13 * from this software without specific prior written permission. 14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 17 * 18 * $Id: fsm.h,v 1.18 1998/06/20 00:19:38 brian Exp $ 19 * 20 * TODO: 21 */ 22 23 /* 24 * State of machine 25 */ 26 #define ST_INITIAL 0 27 #define ST_STARTING 1 28 #define ST_CLOSED 2 29 #define ST_STOPPED 3 30 #define ST_CLOSING 4 31 #define ST_STOPPING 5 32 #define ST_REQSENT 6 33 #define ST_ACKRCVD 7 34 #define ST_ACKSENT 8 35 #define ST_OPENED 9 36 37 #define ST_MAX 10 38 #define ST_UNDEF -1 39 40 #define MODE_REQ 0 41 #define MODE_NAK 1 42 #define MODE_REJ 2 43 #define MODE_NOP 3 44 #define MODE_ACK 4 /* pseudo mode for ccp negotiations */ 45 46 #define OPEN_PASSIVE -1 47 48 struct fsm; 49 50 struct fsm_decode { 51 u_char ack[100], *ackend; 52 u_char nak[100], *nakend; 53 u_char rej[100], *rejend; 54 }; 55 56 struct fsm_callbacks { 57 int (*LayerUp) (struct fsm *); /* Layer is now up (tlu) */ 58 void (*LayerDown) (struct fsm *); /* About to come down (tld) */ 59 void (*LayerStart) (struct fsm *); /* Layer about to start up (tls) */ 60 void (*LayerFinish) (struct fsm *); /* Layer now down (tlf) */ 61 void (*InitRestartCounter) (struct fsm *); /* Set fsm timer load */ 62 void (*SendConfigReq) (struct fsm *); /* Send REQ please */ 63 void (*SentTerminateReq) (struct fsm *); /* Term REQ just sent */ 64 void (*SendTerminateAck) (struct fsm *, u_char); /* Send Term ACK please */ 65 void (*DecodeConfig) (struct fsm *, u_char *, int, int, struct fsm_decode *); 66 /* Deal with incoming data */ 67 void (*RecvResetReq) (struct fsm *fp); /* Reset output */ 68 void (*RecvResetAck) (struct fsm *fp, u_char); /* Reset input */ 69 }; 70 71 struct fsm_parent { 72 void (*LayerStart) (void *, struct fsm *); /* tls */ 73 void (*LayerUp) (void *, struct fsm *); /* tlu */ 74 void (*LayerDown) (void *, struct fsm *); /* tld */ 75 void (*LayerFinish) (void *, struct fsm *); /* tlf */ 76 void *object; 77 }; 78 79 struct link; 80 struct bundle; 81 82 struct fsm { 83 const char *name; /* Name of protocol */ 84 u_short proto; /* Protocol number */ 85 u_short min_code; 86 u_short max_code; 87 int open_mode; /* Delay before config REQ (-1 forever) */ 88 int state; /* State of the machine */ 89 u_char reqid; /* Next request id */ 90 int restart; /* Restart counter value */ 91 int maxconfig; /* Max config REQ before a close() */ 92 93 struct pppTimer FsmTimer; /* Restart Timer */ 94 struct pppTimer OpenTimer; /* Delay before opening */ 95 96 /* 97 * This timer times the ST_STOPPED state out after the given value 98 * (specified via "set stopped ..."). Although this isn't specified in the 99 * rfc, the rfc *does* say that "the application may use higher level 100 * timers to avoid deadlock". The StoppedTimer takes effect when the other 101 * side ABENDs rather than going into ST_ACKSENT (and sending the ACK), 102 * causing ppp to time out and drop into ST_STOPPED. At this point, 103 * nothing will change this state :-( 104 */ 105 struct pppTimer StoppedTimer; 106 int LogLevel; 107 108 /* The link layer active with this FSM (may be our bundle below) */ 109 struct link *link; 110 111 /* Our high-level link */ 112 struct bundle *bundle; 113 114 const struct fsm_parent *parent; 115 const struct fsm_callbacks *fn; 116 }; 117 118 struct fsmheader { 119 u_char code; /* Request code */ 120 u_char id; /* Identification */ 121 u_short length; /* Length of packet */ 122 }; 123 124 #define CODE_CONFIGREQ 1 125 #define CODE_CONFIGACK 2 126 #define CODE_CONFIGNAK 3 127 #define CODE_CONFIGREJ 4 128 #define CODE_TERMREQ 5 129 #define CODE_TERMACK 6 130 #define CODE_CODEREJ 7 131 #define CODE_PROTOREJ 8 132 #define CODE_ECHOREQ 9 /* Used in LCP */ 133 #define CODE_ECHOREP 10 /* Used in LCP */ 134 #define CODE_DISCREQ 11 135 #define CODE_IDENT 12 /* Used in LCP Extension */ 136 #define CODE_TIMEREM 13 /* Used in LCP Extension */ 137 #define CODE_RESETREQ 14 /* Used in CCP */ 138 #define CODE_RESETACK 15 /* Used in CCP */ 139 140 /* Minimum config req size. This struct is *only* used for it's size */ 141 struct fsmconfig { 142 u_char type; 143 u_char length; 144 }; 145 146 extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int, int, 147 struct bundle *, struct link *, const struct fsm_parent *, 148 struct fsm_callbacks *, const char *[3]); 149 extern void fsm_Output(struct fsm *, u_int, u_int, u_char *, int); 150 extern void fsm_Open(struct fsm *); 151 extern void fsm_Up(struct fsm *); 152 extern void fsm_Down(struct fsm *); 153 extern void fsm_Input(struct fsm *, struct mbuf *); 154 extern void fsm_Close(struct fsm *); 155 extern void fsm_NullRecvResetReq(struct fsm *); 156 extern void fsm_NullRecvResetAck(struct fsm *, u_char); 157 extern void fsm_Reopen(struct fsm *); 158 extern void fsm2initial(struct fsm *); 159 extern const char *State2Nam(u_int); 160