Home | History | Annotate | Download | only in ppp
      1 /*****************************************************************************
      2 * fsm.h - Network Control Protocol Finite State Machine header file.
      3 *
      4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
      5 * Copyright (c) 1997 Global Election Systems Inc.
      6 *
      7 * The authors hereby grant permission to use, copy, modify, distribute,
      8 * and license this software and its documentation for any purpose, provided
      9 * that existing copyright notices are retained in all copies and that this
     10 * notice and the following disclaimer are included verbatim in any
     11 * distributions. No written agreement, license, or royalty fee is required
     12 * for any of the authorized uses.
     13 *
     14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
     15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24 *
     25 ******************************************************************************
     26 * REVISION HISTORY
     27 *
     28 * 03-01-01 Marc Boucher <marc (at) mbsi.ca>
     29 *   Ported to lwIP.
     30 * 97-11-05 Guy Lancaster <glanca (at) gesn.com>, Global Election Systems Inc.
     31 *   Original based on BSD code.
     32 *****************************************************************************/
     33 /*
     34  * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
     35  *
     36  * Copyright (c) 1989 Carnegie Mellon University.
     37  * All rights reserved.
     38  *
     39  * Redistribution and use in source and binary forms are permitted
     40  * provided that the above copyright notice and this paragraph are
     41  * duplicated in all such forms and that any documentation,
     42  * advertising materials, and other materials related to such
     43  * distribution and use acknowledge that the software was developed
     44  * by Carnegie Mellon University.  The name of the
     45  * University may not be used to endorse or promote products derived
     46  * from this software without specific prior written permission.
     47  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
     48  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
     49  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     50  *
     51  * $Id: fsm.h,v 1.5 2009/12/31 17:08:08 goldsimon Exp $
     52  */
     53 
     54 #ifndef FSM_H
     55 #define FSM_H
     56 
     57 /*
     58  * LCP Packet header = Code, id, length.
     59  */
     60 #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
     61 
     62 
     63 /*
     64  *  CP (LCP, IPCP, etc.) codes.
     65  */
     66 #define CONFREQ     1 /* Configuration Request */
     67 #define CONFACK     2 /* Configuration Ack */
     68 #define CONFNAK     3 /* Configuration Nak */
     69 #define CONFREJ     4 /* Configuration Reject */
     70 #define TERMREQ     5 /* Termination Request */
     71 #define TERMACK     6 /* Termination Ack */
     72 #define CODEREJ     7 /* Code Reject */
     73 
     74 
     75 /*
     76  * Each FSM is described by an fsm structure and fsm callbacks.
     77  */
     78 typedef struct fsm {
     79   int unit;                        /* Interface unit number */
     80   u_short protocol;                /* Data Link Layer Protocol field value */
     81   int state;                       /* State */
     82   int flags;                       /* Contains option bits */
     83   u_char id;                       /* Current id */
     84   u_char reqid;                    /* Current request id */
     85   u_char seen_ack;                 /* Have received valid Ack/Nak/Rej to Req */
     86   int timeouttime;                 /* Timeout time in milliseconds */
     87   int maxconfreqtransmits;         /* Maximum Configure-Request transmissions */
     88   int retransmits;                 /* Number of retransmissions left */
     89   int maxtermtransmits;            /* Maximum Terminate-Request transmissions */
     90   int nakloops;                    /* Number of nak loops since last ack */
     91   int maxnakloops;                 /* Maximum number of nak loops tolerated */
     92   struct fsm_callbacks* callbacks; /* Callback routines */
     93   char* term_reason;               /* Reason for closing protocol */
     94   int term_reason_len;             /* Length of term_reason */
     95 } fsm;
     96 
     97 
     98 typedef struct fsm_callbacks {
     99   void (*resetci)(fsm*);                            /* Reset our Configuration Information */
    100   int  (*cilen)(fsm*);                              /* Length of our Configuration Information */
    101   void (*addci)(fsm*, u_char*, int*);               /* Add our Configuration Information */
    102   int  (*ackci)(fsm*, u_char*, int);                /* ACK our Configuration Information */
    103   int  (*nakci)(fsm*, u_char*, int);                /* NAK our Configuration Information */
    104   int  (*rejci)(fsm*, u_char*, int);                /* Reject our Configuration Information */
    105   int  (*reqci)(fsm*, u_char*, int*, int);          /* Request peer's Configuration Information */
    106   void (*up)(fsm*);                                 /* Called when fsm reaches LS_OPENED state */
    107   void (*down)(fsm*);                               /* Called when fsm leaves LS_OPENED state */
    108   void (*starting)(fsm*);                           /* Called when we want the lower layer */
    109   void (*finished)(fsm*);                           /* Called when we don't want the lower layer */
    110   void (*protreject)(int);                          /* Called when Protocol-Reject received */
    111   void (*retransmit)(fsm*);                         /* Retransmission is necessary */
    112   int  (*extcode)(fsm*, int, u_char, u_char*, int); /* Called when unknown code received */
    113   char *proto_name;                                 /* String name for protocol (for messages) */
    114 } fsm_callbacks;
    115 
    116 
    117 /*
    118  * Link states.
    119  */
    120 #define LS_INITIAL  0 /* Down, hasn't been opened */
    121 #define LS_STARTING 1 /* Down, been opened */
    122 #define LS_CLOSED   2 /* Up, hasn't been opened */
    123 #define LS_STOPPED  3 /* Open, waiting for down event */
    124 #define LS_CLOSING  4 /* Terminating the connection, not open */
    125 #define LS_STOPPING 5 /* Terminating, but open */
    126 #define LS_REQSENT  6 /* We've sent a Config Request */
    127 #define LS_ACKRCVD  7 /* We've received a Config Ack */
    128 #define LS_ACKSENT  8 /* We've sent a Config Ack */
    129 #define LS_OPENED   9 /* Connection available */
    130 
    131 /*
    132  * Flags - indicate options controlling FSM operation
    133  */
    134 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
    135 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
    136 #define OPT_SILENT  4 /* Wait for peer to speak first */
    137 
    138 
    139 /*
    140  * Prototypes
    141  */
    142 void fsm_init (fsm*);
    143 void fsm_lowerup (fsm*);
    144 void fsm_lowerdown (fsm*);
    145 void fsm_open (fsm*);
    146 void fsm_close (fsm*, char*);
    147 void fsm_input (fsm*, u_char*, int);
    148 void fsm_protreject (fsm*);
    149 void fsm_sdata (fsm*, u_char, u_char, u_char*, int);
    150 
    151 
    152 /*
    153  * Variables
    154  */
    155 extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
    156 
    157 #endif /* FSM_H */
    158