ZG2100 Network interface source

Committer:
donatien
Date:
Fri Jul 09 15:37:23 2010 +0000
Revision:
0:b802fc31f1db

        

Who changed what in which revision?

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