LineLedControl

Dependencies:   LPD8806 mbed

Fork of LPD8806_Test by Jelmer Tiete

Committer:
sfjmt
Date:
Mon Aug 19 12:14:37 2013 +0000
Revision:
3:b0a1b4b24d3c
LPD8806 control

Who changed what in which revision?

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