I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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