12Oct2012MbedLab

Dependents:   Lab3_VoiceMeter

Fork of EthernetNetIf by Donatien Garnier

Committer:
psawant9
Date:
Fri Oct 12 16:02:00 2012 +0000
Revision:
6:22ce63eddd2b
Parent:
0:422060928e37
Done

Who changed what in which revision?

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