SAMV71 Xplained Ultra Software Package 1.3

fsm.h

00001 /*****************************************************************************
00002 * fsm.h - Network Control Protocol Finite State Machine header file.
00003 *
00004 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
00005 * Copyright (c) 1997 Global Election Systems Inc.
00006 *
00007 * The authors hereby grant permission to use, copy, modify, distribute,
00008 * and license this software and its documentation for any purpose, provided
00009 * that existing copyright notices are retained in all copies and that this
00010 * notice and the following disclaimer are included verbatim in any 
00011 * distributions. No written agreement, license, or royalty fee is required
00012 * for any of the authorized uses.
00013 *
00014 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
00015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
00017 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024 *
00025 ******************************************************************************
00026 * REVISION HISTORY
00027 *
00028 * 03-01-01 Marc Boucher <marc@mbsi.ca>
00029 *   Ported to lwIP.
00030 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
00031 *   Original based on BSD code.
00032 *****************************************************************************/
00033 /*
00034  * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
00035  *
00036  * Copyright (c) 1989 Carnegie Mellon University.
00037  * All rights reserved.
00038  *
00039  * Redistribution and use in source and binary forms are permitted
00040  * provided that the above copyright notice and this paragraph are
00041  * duplicated in all such forms and that any documentation,
00042  * advertising materials, and other materials related to such
00043  * distribution and use acknowledge that the software was developed
00044  * by Carnegie Mellon University.  The name of the
00045  * University may not be used to endorse or promote products derived
00046  * from this software without specific prior written permission.
00047  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
00048  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
00049  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00050  *
00051  * $Id: fsm.h,v 1.4 2007/12/19 20:47:23 fbernon Exp $
00052  */
00053 
00054 #ifndef FSM_H
00055 #define FSM_H
00056 
00057 /*****************************************************************************
00058 ************************* PUBLIC DEFINITIONS *********************************
00059 *****************************************************************************/
00060 /*
00061  * LCP Packet header = Code, id, length.
00062  */
00063 #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
00064 
00065 
00066 /*
00067  *  CP (LCP, IPCP, etc.) codes.
00068  */
00069 #define CONFREQ     1 /* Configuration Request */
00070 #define CONFACK     2 /* Configuration Ack */
00071 #define CONFNAK     3 /* Configuration Nak */
00072 #define CONFREJ     4 /* Configuration Reject */
00073 #define TERMREQ     5 /* Termination Request */
00074 #define TERMACK     6 /* Termination Ack */
00075 #define CODEREJ     7 /* Code Reject */
00076 
00077 /*
00078  * Link states.
00079  */
00080 #define LS_INITIAL  0 /* Down, hasn't been opened */
00081 #define LS_STARTING 1 /* Down, been opened */
00082 #define LS_CLOSED   2 /* Up, hasn't been opened */
00083 #define LS_STOPPED  3 /* Open, waiting for down event */
00084 #define LS_CLOSING  4 /* Terminating the connection, not open */
00085 #define LS_STOPPING 5 /* Terminating, but open */
00086 #define LS_REQSENT  6 /* We've sent a Config Request */
00087 #define LS_ACKRCVD  7 /* We've received a Config Ack */
00088 #define LS_ACKSENT  8 /* We've sent a Config Ack */
00089 #define LS_OPENED   9 /* Connection available */
00090 
00091 /*
00092  * Flags - indicate options controlling FSM operation
00093  */
00094 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
00095 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
00096 #define OPT_SILENT  4 /* Wait for peer to speak first */
00097 
00098 
00099 /*****************************************************************************
00100 ************************* PUBLIC DATA TYPES **********************************
00101 *****************************************************************************/
00102 /*
00103  * Each FSM is described by an fsm structure and fsm callbacks.
00104  */
00105 typedef struct fsm {
00106   int unit;                        /* Interface unit number */
00107   u_short protocol;                /* Data Link Layer Protocol field value */
00108   int state;                       /* State */
00109   int flags;                       /* Contains option bits */
00110   u_char id;                       /* Current id */
00111   u_char reqid;                    /* Current request id */
00112   u_char seen_ack;                 /* Have received valid Ack/Nak/Rej to Req */
00113   int timeouttime;                 /* Timeout time in milliseconds */
00114   int maxconfreqtransmits;         /* Maximum Configure-Request transmissions */
00115   int retransmits;                 /* Number of retransmissions left */
00116   int maxtermtransmits;            /* Maximum Terminate-Request transmissions */
00117   int nakloops;                    /* Number of nak loops since last ack */
00118   int maxnakloops;                 /* Maximum number of nak loops tolerated */
00119   struct fsm_callbacks* callbacks; /* Callback routines */
00120   char* term_reason;               /* Reason for closing protocol */
00121   int term_reason_len;             /* Length of term_reason */
00122 } fsm;
00123 
00124 
00125 typedef struct fsm_callbacks {
00126   void (*resetci)(fsm*);                            /* Reset our Configuration Information */
00127   int  (*cilen)(fsm*);                              /* Length of our Configuration Information */
00128   void (*addci)(fsm*, u_char*, int*);               /* Add our Configuration Information */
00129   int  (*ackci)(fsm*, u_char*, int);                /* ACK our Configuration Information */
00130   int  (*nakci)(fsm*, u_char*, int);                /* NAK our Configuration Information */
00131   int  (*rejci)(fsm*, u_char*, int);                /* Reject our Configuration Information */
00132   int  (*reqci)(fsm*, u_char*, int*, int);          /* Request peer's Configuration Information */
00133   void (*up)(fsm*);                                 /* Called when fsm reaches LS_OPENED state */
00134   void (*down)(fsm*);                               /* Called when fsm leaves LS_OPENED state */
00135   void (*starting)(fsm*);                           /* Called when we want the lower layer */
00136   void (*finished)(fsm*);                           /* Called when we don't want the lower layer */
00137   void (*protreject)(int);                          /* Called when Protocol-Reject received */
00138   void (*retransmit)(fsm*);                         /* Retransmission is necessary */
00139   int  (*extcode)(fsm*, int, u_char, u_char*, int); /* Called when unknown code received */
00140   char *proto_name;                                 /* String name for protocol (for messages) */
00141 } fsm_callbacks;
00142 
00143 
00144 /*****************************************************************************
00145 *********************** PUBLIC DATA STRUCTURES *******************************
00146 *****************************************************************************/
00147 /*
00148  * Variables
00149  */
00150 extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
00151 
00152 
00153 /*****************************************************************************
00154 ************************** PUBLIC FUNCTIONS **********************************
00155 *****************************************************************************/
00156 
00157 /*
00158  * Prototypes
00159  */
00160 void fsm_init (fsm*);
00161 void fsm_lowerup (fsm*);
00162 void fsm_lowerdown (fsm*);
00163 void fsm_open (fsm*);
00164 void fsm_close (fsm*, char*);
00165 void fsm_input (fsm*, u_char*, int);
00166 void fsm_protreject (fsm*);
00167 void fsm_sdata (fsm*, u_char, u_char, u_char*, int);
00168 
00169 #endif /* FSM_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines