Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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