EthernetNetIf Compatibility.

Dependents:   XBeeWiFi_SPI_example

Fork of NetServicesSource by Donatien Garnier

Committer:
donatien
Date:
Thu Aug 05 15:01:33 2010 +0000
Revision:
11:da4498f591ee
Parent:
0:632c9925f013

        

Who changed what in which revision?

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