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