LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
All rights reserved. 
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
derived from this software without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
donatien
Date:
Thu May 24 15:53:48 2012 +0000
Revision:
0:8e01dca41002
Merge with Emilio's LwIp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:8e01dca41002 1 /*
donatien 0:8e01dca41002 2 * Definitions for tcp compression routines.
donatien 0:8e01dca41002 3 *
donatien 0:8e01dca41002 4 * $Id: vj.h,v 1.7 2010/02/22 17:52:09 goldsimon Exp $
donatien 0:8e01dca41002 5 *
donatien 0:8e01dca41002 6 * Copyright (c) 1989 Regents of the University of California.
donatien 0:8e01dca41002 7 * All rights reserved.
donatien 0:8e01dca41002 8 *
donatien 0:8e01dca41002 9 * Redistribution and use in source and binary forms are permitted
donatien 0:8e01dca41002 10 * provided that the above copyright notice and this paragraph are
donatien 0:8e01dca41002 11 * duplicated in all such forms and that any documentation,
donatien 0:8e01dca41002 12 * advertising materials, and other materials related to such
donatien 0:8e01dca41002 13 * distribution and use acknowledge that the software was developed
donatien 0:8e01dca41002 14 * by the University of California, Berkeley. The name of the
donatien 0:8e01dca41002 15 * University may not be used to endorse or promote products derived
donatien 0:8e01dca41002 16 * from this software without specific prior written permission.
donatien 0:8e01dca41002 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
donatien 0:8e01dca41002 18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
donatien 0:8e01dca41002 19 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
donatien 0:8e01dca41002 20 *
donatien 0:8e01dca41002 21 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
donatien 0:8e01dca41002 22 * - Initial distribution.
donatien 0:8e01dca41002 23 */
donatien 0:8e01dca41002 24
donatien 0:8e01dca41002 25 #ifndef VJ_H
donatien 0:8e01dca41002 26 #define VJ_H
donatien 0:8e01dca41002 27
donatien 0:8e01dca41002 28 #include "lwip/ip.h"
donatien 0:8e01dca41002 29 #include "lwip/tcp_impl.h"
donatien 0:8e01dca41002 30
donatien 0:8e01dca41002 31 #define MAX_SLOTS 16 /* must be > 2 and < 256 */
donatien 0:8e01dca41002 32 #define MAX_HDR 128
donatien 0:8e01dca41002 33
donatien 0:8e01dca41002 34 /*
donatien 0:8e01dca41002 35 * Compressed packet format:
donatien 0:8e01dca41002 36 *
donatien 0:8e01dca41002 37 * The first octet contains the packet type (top 3 bits), TCP
donatien 0:8e01dca41002 38 * 'push' bit, and flags that indicate which of the 4 TCP sequence
donatien 0:8e01dca41002 39 * numbers have changed (bottom 5 bits). The next octet is a
donatien 0:8e01dca41002 40 * conversation number that associates a saved IP/TCP header with
donatien 0:8e01dca41002 41 * the compressed packet. The next two octets are the TCP checksum
donatien 0:8e01dca41002 42 * from the original datagram. The next 0 to 15 octets are
donatien 0:8e01dca41002 43 * sequence number changes, one change per bit set in the header
donatien 0:8e01dca41002 44 * (there may be no changes and there are two special cases where
donatien 0:8e01dca41002 45 * the receiver implicitly knows what changed -- see below).
donatien 0:8e01dca41002 46 *
donatien 0:8e01dca41002 47 * There are 5 numbers which can change (they are always inserted
donatien 0:8e01dca41002 48 * in the following order): TCP urgent pointer, window,
donatien 0:8e01dca41002 49 * acknowlegement, sequence number and IP ID. (The urgent pointer
donatien 0:8e01dca41002 50 * is different from the others in that its value is sent, not the
donatien 0:8e01dca41002 51 * change in value.) Since typical use of SLIP links is biased
donatien 0:8e01dca41002 52 * toward small packets (see comments on MTU/MSS below), changes
donatien 0:8e01dca41002 53 * use a variable length coding with one octet for numbers in the
donatien 0:8e01dca41002 54 * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
donatien 0:8e01dca41002 55 * range 256 - 65535 or 0. (If the change in sequence number or
donatien 0:8e01dca41002 56 * ack is more than 65535, an uncompressed packet is sent.)
donatien 0:8e01dca41002 57 */
donatien 0:8e01dca41002 58
donatien 0:8e01dca41002 59 /*
donatien 0:8e01dca41002 60 * Packet types (must not conflict with IP protocol version)
donatien 0:8e01dca41002 61 *
donatien 0:8e01dca41002 62 * The top nibble of the first octet is the packet type. There are
donatien 0:8e01dca41002 63 * three possible types: IP (not proto TCP or tcp with one of the
donatien 0:8e01dca41002 64 * control flags set); uncompressed TCP (a normal IP/TCP packet but
donatien 0:8e01dca41002 65 * with the 8-bit protocol field replaced by an 8-bit connection id --
donatien 0:8e01dca41002 66 * this type of packet syncs the sender & receiver); and compressed
donatien 0:8e01dca41002 67 * TCP (described above).
donatien 0:8e01dca41002 68 *
donatien 0:8e01dca41002 69 * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
donatien 0:8e01dca41002 70 * is logically part of the 4-bit "changes" field that follows. Top
donatien 0:8e01dca41002 71 * three bits are actual packet type. For backward compatibility
donatien 0:8e01dca41002 72 * and in the interest of conserving bits, numbers are chosen so the
donatien 0:8e01dca41002 73 * IP protocol version number (4) which normally appears in this nibble
donatien 0:8e01dca41002 74 * means "IP packet".
donatien 0:8e01dca41002 75 */
donatien 0:8e01dca41002 76
donatien 0:8e01dca41002 77 /* packet types */
donatien 0:8e01dca41002 78 #define TYPE_IP 0x40
donatien 0:8e01dca41002 79 #define TYPE_UNCOMPRESSED_TCP 0x70
donatien 0:8e01dca41002 80 #define TYPE_COMPRESSED_TCP 0x80
donatien 0:8e01dca41002 81 #define TYPE_ERROR 0x00
donatien 0:8e01dca41002 82
donatien 0:8e01dca41002 83 /* Bits in first octet of compressed packet */
donatien 0:8e01dca41002 84 #define NEW_C 0x40 /* flag bits for what changed in a packet */
donatien 0:8e01dca41002 85 #define NEW_I 0x20
donatien 0:8e01dca41002 86 #define NEW_S 0x08
donatien 0:8e01dca41002 87 #define NEW_A 0x04
donatien 0:8e01dca41002 88 #define NEW_W 0x02
donatien 0:8e01dca41002 89 #define NEW_U 0x01
donatien 0:8e01dca41002 90
donatien 0:8e01dca41002 91 /* reserved, special-case values of above */
donatien 0:8e01dca41002 92 #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
donatien 0:8e01dca41002 93 #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
donatien 0:8e01dca41002 94 #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
donatien 0:8e01dca41002 95
donatien 0:8e01dca41002 96 #define TCP_PUSH_BIT 0x10
donatien 0:8e01dca41002 97
donatien 0:8e01dca41002 98
donatien 0:8e01dca41002 99 /*
donatien 0:8e01dca41002 100 * "state" data for each active tcp conversation on the wire. This is
donatien 0:8e01dca41002 101 * basically a copy of the entire IP/TCP header from the last packet
donatien 0:8e01dca41002 102 * we saw from the conversation together with a small identifier
donatien 0:8e01dca41002 103 * the transmit & receive ends of the line use to locate saved header.
donatien 0:8e01dca41002 104 */
donatien 0:8e01dca41002 105 struct cstate {
donatien 0:8e01dca41002 106 struct cstate *cs_next; /* next most recently used state (xmit only) */
donatien 0:8e01dca41002 107 u_short cs_hlen; /* size of hdr (receive only) */
donatien 0:8e01dca41002 108 u_char cs_id; /* connection # associated with this state */
donatien 0:8e01dca41002 109 u_char cs_filler;
donatien 0:8e01dca41002 110 union {
donatien 0:8e01dca41002 111 char csu_hdr[MAX_HDR];
donatien 0:8e01dca41002 112 struct ip_hdr csu_ip; /* ip/tcp hdr from most recent packet */
donatien 0:8e01dca41002 113 } vjcs_u;
donatien 0:8e01dca41002 114 };
donatien 0:8e01dca41002 115 #define cs_ip vjcs_u.csu_ip
donatien 0:8e01dca41002 116 #define cs_hdr vjcs_u.csu_hdr
donatien 0:8e01dca41002 117
donatien 0:8e01dca41002 118
donatien 0:8e01dca41002 119 struct vjstat {
donatien 0:8e01dca41002 120 unsigned long vjs_packets; /* outbound packets */
donatien 0:8e01dca41002 121 unsigned long vjs_compressed; /* outbound compressed packets */
donatien 0:8e01dca41002 122 unsigned long vjs_searches; /* searches for connection state */
donatien 0:8e01dca41002 123 unsigned long vjs_misses; /* times couldn't find conn. state */
donatien 0:8e01dca41002 124 unsigned long vjs_uncompressedin; /* inbound uncompressed packets */
donatien 0:8e01dca41002 125 unsigned long vjs_compressedin; /* inbound compressed packets */
donatien 0:8e01dca41002 126 unsigned long vjs_errorin; /* inbound unknown type packets */
donatien 0:8e01dca41002 127 unsigned long vjs_tossed; /* inbound packets tossed because of error */
donatien 0:8e01dca41002 128 };
donatien 0:8e01dca41002 129
donatien 0:8e01dca41002 130 /*
donatien 0:8e01dca41002 131 * all the state data for one serial line (we need one of these per line).
donatien 0:8e01dca41002 132 */
donatien 0:8e01dca41002 133 struct vjcompress {
donatien 0:8e01dca41002 134 struct cstate *last_cs; /* most recently used tstate */
donatien 0:8e01dca41002 135 u_char last_recv; /* last rcvd conn. id */
donatien 0:8e01dca41002 136 u_char last_xmit; /* last sent conn. id */
donatien 0:8e01dca41002 137 u_short flags;
donatien 0:8e01dca41002 138 u_char maxSlotIndex;
donatien 0:8e01dca41002 139 u_char compressSlot; /* Flag indicating OK to compress slot ID. */
donatien 0:8e01dca41002 140 #if LINK_STATS
donatien 0:8e01dca41002 141 struct vjstat stats;
donatien 0:8e01dca41002 142 #endif
donatien 0:8e01dca41002 143 struct cstate tstate[MAX_SLOTS]; /* xmit connection states */
donatien 0:8e01dca41002 144 struct cstate rstate[MAX_SLOTS]; /* receive connection states */
donatien 0:8e01dca41002 145 };
donatien 0:8e01dca41002 146
donatien 0:8e01dca41002 147 /* flag values */
donatien 0:8e01dca41002 148 #define VJF_TOSS 1U /* tossing rcvd frames because of input err */
donatien 0:8e01dca41002 149
donatien 0:8e01dca41002 150 extern void vj_compress_init (struct vjcompress *comp);
donatien 0:8e01dca41002 151 extern u_int vj_compress_tcp (struct vjcompress *comp, struct pbuf *pb);
donatien 0:8e01dca41002 152 extern void vj_uncompress_err (struct vjcompress *comp);
donatien 0:8e01dca41002 153 extern int vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp);
donatien 0:8e01dca41002 154 extern int vj_uncompress_tcp (struct pbuf **nb, struct vjcompress *comp);
donatien 0:8e01dca41002 155
donatien 0:8e01dca41002 156 #endif /* VJ_H */