A modified version of http://mbed.org/users/segundo/libraries/NetServices/ljhqix to add HTTP proxy feature (based on http://mbed.org/users/igorsk/programs/NetServicesSource/ltjpag)

Dependents:   SenseClient

Committer:
mimil
Date:
Tue Sep 06 13:26:45 2011 +0000
Revision:
0:308f83189a3f

        

Who changed what in which revision?

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