Example self-announcing webserver which controls a servo through a smallHTML userinterface.

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:56:01 2010 +0000
Revision:
0:a259777c45a3

        

Who changed what in which revision?

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