Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Thu Apr 17 08:04:14 2014 +0000
Revision:
47:199042980678
Parent:
31:5f039cbddee8
publishing for sharing with Ken Iwasaki

Who changed what in which revision?

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