fsm.h revision 32381
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.13 1997/12/03 10:23:47 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_ACTIVE 0 47#define OPEN_PASSIVE 1 48 49struct fsm { 50 const char *name; /* Name of protocol */ 51 u_short proto; /* Protocol number */ 52 u_short max_code; 53 int open_mode; 54 int state; /* State of the machine */ 55 u_char reqid; /* Next request id */ 56 int restart; /* Restart counter value */ 57 int maxconfig; 58 59 int reqcode; /* Request code sent */ 60 struct pppTimer FsmTimer; /* Restart Timer */ 61 62 /* 63 * This timer times the ST_STOPPED state out after the given value 64 * (specified via "set stopped ..."). Although this isn't specified in the 65 * rfc, the rfc *does* say that "the application may use higher level 66 * timers to avoid deadlock". The StoppedTimer takes effect when the other 67 * side ABENDs rather than going into ST_ACKSENT (and sending the ACK), 68 * causing ppp to time out and drop into ST_STOPPED. At this point, 69 * nothing will change this state :-( 70 */ 71 struct pppTimer StoppedTimer; 72 int LogLevel; 73 74 void (*LayerUp) (struct fsm *); 75 void (*LayerDown) (struct fsm *); 76 void (*LayerStart) (struct fsm *); 77 void (*LayerFinish) (struct fsm *); 78 void (*InitRestartCounter) (struct fsm *); 79 void (*SendConfigReq) (struct fsm *); 80 void (*SendTerminateReq) (struct fsm *); 81 void (*SendTerminateAck) (struct fsm *); 82 void (*DecodeConfig) (u_char *, int, int); 83}; 84 85struct fsmheader { 86 u_char code; /* Request code */ 87 u_char id; /* Identification */ 88 u_short length; /* Length of packet */ 89}; 90 91#define CODE_CONFIGREQ 1 92#define CODE_CONFIGACK 2 93#define CODE_CONFIGNAK 3 94#define CODE_CONFIGREJ 4 95#define CODE_TERMREQ 5 96#define CODE_TERMACK 6 97#define CODE_CODEREJ 7 98#define CODE_PROTOREJ 8 99#define CODE_ECHOREQ 9 /* Used in LCP */ 100#define CODE_ECHOREP 10 /* Used in LCP */ 101#define CODE_DISCREQ 11 102#define CODE_IDENT 12 /* Used in LCP Extension */ 103#define CODE_TIMEREM 13 /* Used in LCP Extension */ 104#define CODE_RESETREQ 14 /* Used in CCP */ 105#define CODE_RESETACK 15 /* Used in CCP */ 106 107struct fsmcodedesc { 108 void (*action) (struct fsm *, struct fsmheader *, struct mbuf *); 109 const char *name; 110}; 111 112struct fsmconfig { 113 u_char type; 114 u_char length; 115}; 116 117extern u_char AckBuff[200]; 118extern u_char NakBuff[200]; 119extern u_char RejBuff[100]; 120extern u_char ReqBuff[200]; 121extern u_char *ackp; 122extern u_char *nakp; 123extern u_char *rejp; 124 125extern char const *StateNames[]; 126 127extern void FsmInit(struct fsm *); 128extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int); 129extern void FsmOpen(struct fsm *); 130extern void FsmUp(struct fsm *); 131extern void FsmDown(struct fsm *); 132extern void FsmInput(struct fsm *, struct mbuf *); 133extern void FsmClose(struct fsm *); 134