Embedded C project:18/12/2014

Dependencies:   DS1307 TextLCD mbed

Committer:
ninoderkinderen
Date:
Thu Dec 18 09:35:49 2014 +0000
Revision:
0:8d87bc453349
Programma embedded C

Who changed what in which revision?

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