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