Web server based weather station using Sparkfun Weather Meters.

Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Committer:
AdamGreen
Date:
Thu Feb 23 21:38:39 2012 +0000
Revision:
0:616601bde9fb

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdamGreen 0:616601bde9fb 1 /*
AdamGreen 0:616601bde9fb 2 * Routines to compress and uncompess tcp packets (for transmission
AdamGreen 0:616601bde9fb 3 * over low speed serial lines.
AdamGreen 0:616601bde9fb 4 *
AdamGreen 0:616601bde9fb 5 * Copyright (c) 1989 Regents of the University of California.
AdamGreen 0:616601bde9fb 6 * All rights reserved.
AdamGreen 0:616601bde9fb 7 *
AdamGreen 0:616601bde9fb 8 * Redistribution and use in source and binary forms are permitted
AdamGreen 0:616601bde9fb 9 * provided that the above copyright notice and this paragraph are
AdamGreen 0:616601bde9fb 10 * duplicated in all such forms and that any documentation,
AdamGreen 0:616601bde9fb 11 * advertising materials, and other materials related to such
AdamGreen 0:616601bde9fb 12 * distribution and use acknowledge that the software was developed
AdamGreen 0:616601bde9fb 13 * by the University of California, Berkeley. The name of the
AdamGreen 0:616601bde9fb 14 * University may not be used to endorse or promote products derived
AdamGreen 0:616601bde9fb 15 * from this software without specific prior written permission.
AdamGreen 0:616601bde9fb 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
AdamGreen 0:616601bde9fb 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
AdamGreen 0:616601bde9fb 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
AdamGreen 0:616601bde9fb 19 *
AdamGreen 0:616601bde9fb 20 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
AdamGreen 0:616601bde9fb 21 * Initial distribution.
AdamGreen 0:616601bde9fb 22 *
AdamGreen 0:616601bde9fb 23 * Modified June 1993 by Paul Mackerras, paulus@cs.anu.edu.au,
AdamGreen 0:616601bde9fb 24 * so that the entire packet being decompressed doesn't have
AdamGreen 0:616601bde9fb 25 * to be in contiguous memory (just the compressed header).
AdamGreen 0:616601bde9fb 26 *
AdamGreen 0:616601bde9fb 27 * Modified March 1998 by Guy Lancaster, glanca@gesn.com,
AdamGreen 0:616601bde9fb 28 * for a 16 bit processor.
AdamGreen 0:616601bde9fb 29 */
AdamGreen 0:616601bde9fb 30
AdamGreen 0:616601bde9fb 31 #include "lwip/opt.h"
AdamGreen 0:616601bde9fb 32
AdamGreen 0:616601bde9fb 33 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
AdamGreen 0:616601bde9fb 34
AdamGreen 0:616601bde9fb 35 #include "ppp.h"
AdamGreen 0:616601bde9fb 36 #include "pppdebug.h"
AdamGreen 0:616601bde9fb 37
AdamGreen 0:616601bde9fb 38 #include "vj.h"
AdamGreen 0:616601bde9fb 39
AdamGreen 0:616601bde9fb 40 #include <string.h>
AdamGreen 0:616601bde9fb 41
AdamGreen 0:616601bde9fb 42 #if VJ_SUPPORT
AdamGreen 0:616601bde9fb 43
AdamGreen 0:616601bde9fb 44 #if LINK_STATS
AdamGreen 0:616601bde9fb 45 #define INCR(counter) ++comp->stats.counter
AdamGreen 0:616601bde9fb 46 #else
AdamGreen 0:616601bde9fb 47 #define INCR(counter)
AdamGreen 0:616601bde9fb 48 #endif
AdamGreen 0:616601bde9fb 49
AdamGreen 0:616601bde9fb 50 void
AdamGreen 0:616601bde9fb 51 vj_compress_init(struct vjcompress *comp)
AdamGreen 0:616601bde9fb 52 {
AdamGreen 0:616601bde9fb 53 register u_char i;
AdamGreen 0:616601bde9fb 54 register struct cstate *tstate = comp->tstate;
AdamGreen 0:616601bde9fb 55
AdamGreen 0:616601bde9fb 56 #if MAX_SLOTS == 0
AdamGreen 0:616601bde9fb 57 memset((char *)comp, 0, sizeof(*comp));
AdamGreen 0:616601bde9fb 58 #endif
AdamGreen 0:616601bde9fb 59 comp->maxSlotIndex = MAX_SLOTS - 1;
AdamGreen 0:616601bde9fb 60 comp->compressSlot = 0; /* Disable slot ID compression by default. */
AdamGreen 0:616601bde9fb 61 for (i = MAX_SLOTS - 1; i > 0; --i) {
AdamGreen 0:616601bde9fb 62 tstate[i].cs_id = i;
AdamGreen 0:616601bde9fb 63 tstate[i].cs_next = &tstate[i - 1];
AdamGreen 0:616601bde9fb 64 }
AdamGreen 0:616601bde9fb 65 tstate[0].cs_next = &tstate[MAX_SLOTS - 1];
AdamGreen 0:616601bde9fb 66 tstate[0].cs_id = 0;
AdamGreen 0:616601bde9fb 67 comp->last_cs = &tstate[0];
AdamGreen 0:616601bde9fb 68 comp->last_recv = 255;
AdamGreen 0:616601bde9fb 69 comp->last_xmit = 255;
AdamGreen 0:616601bde9fb 70 comp->flags = VJF_TOSS;
AdamGreen 0:616601bde9fb 71 }
AdamGreen 0:616601bde9fb 72
AdamGreen 0:616601bde9fb 73
AdamGreen 0:616601bde9fb 74 /* ENCODE encodes a number that is known to be non-zero. ENCODEZ
AdamGreen 0:616601bde9fb 75 * checks for zero (since zero has to be encoded in the long, 3 byte
AdamGreen 0:616601bde9fb 76 * form).
AdamGreen 0:616601bde9fb 77 */
AdamGreen 0:616601bde9fb 78 #define ENCODE(n) { \
AdamGreen 0:616601bde9fb 79 if ((u_short)(n) >= 256) { \
AdamGreen 0:616601bde9fb 80 *cp++ = 0; \
AdamGreen 0:616601bde9fb 81 cp[1] = (u_char)(n); \
AdamGreen 0:616601bde9fb 82 cp[0] = (u_char)((n) >> 8); \
AdamGreen 0:616601bde9fb 83 cp += 2; \
AdamGreen 0:616601bde9fb 84 } else { \
AdamGreen 0:616601bde9fb 85 *cp++ = (u_char)(n); \
AdamGreen 0:616601bde9fb 86 } \
AdamGreen 0:616601bde9fb 87 }
AdamGreen 0:616601bde9fb 88 #define ENCODEZ(n) { \
AdamGreen 0:616601bde9fb 89 if ((u_short)(n) >= 256 || (u_short)(n) == 0) { \
AdamGreen 0:616601bde9fb 90 *cp++ = 0; \
AdamGreen 0:616601bde9fb 91 cp[1] = (u_char)(n); \
AdamGreen 0:616601bde9fb 92 cp[0] = (u_char)((n) >> 8); \
AdamGreen 0:616601bde9fb 93 cp += 2; \
AdamGreen 0:616601bde9fb 94 } else { \
AdamGreen 0:616601bde9fb 95 *cp++ = (u_char)(n); \
AdamGreen 0:616601bde9fb 96 } \
AdamGreen 0:616601bde9fb 97 }
AdamGreen 0:616601bde9fb 98
AdamGreen 0:616601bde9fb 99 #define DECODEL(f) { \
AdamGreen 0:616601bde9fb 100 if (*cp == 0) {\
AdamGreen 0:616601bde9fb 101 u32_t tmp = ntohl(f) + ((cp[1] << 8) | cp[2]); \
AdamGreen 0:616601bde9fb 102 (f) = htonl(tmp); \
AdamGreen 0:616601bde9fb 103 cp += 3; \
AdamGreen 0:616601bde9fb 104 } else { \
AdamGreen 0:616601bde9fb 105 u32_t tmp = ntohl(f) + (u32_t)*cp++; \
AdamGreen 0:616601bde9fb 106 (f) = htonl(tmp); \
AdamGreen 0:616601bde9fb 107 } \
AdamGreen 0:616601bde9fb 108 }
AdamGreen 0:616601bde9fb 109
AdamGreen 0:616601bde9fb 110 #define DECODES(f) { \
AdamGreen 0:616601bde9fb 111 if (*cp == 0) {\
AdamGreen 0:616601bde9fb 112 u_short tmp = ntohs(f) + (((u_short)cp[1] << 8) | cp[2]); \
AdamGreen 0:616601bde9fb 113 (f) = htons(tmp); \
AdamGreen 0:616601bde9fb 114 cp += 3; \
AdamGreen 0:616601bde9fb 115 } else { \
AdamGreen 0:616601bde9fb 116 u_short tmp = ntohs(f) + (u_short)*cp++; \
AdamGreen 0:616601bde9fb 117 (f) = htons(tmp); \
AdamGreen 0:616601bde9fb 118 } \
AdamGreen 0:616601bde9fb 119 }
AdamGreen 0:616601bde9fb 120
AdamGreen 0:616601bde9fb 121 #define DECODEU(f) { \
AdamGreen 0:616601bde9fb 122 if (*cp == 0) {\
AdamGreen 0:616601bde9fb 123 (f) = htons(((u_short)cp[1] << 8) | cp[2]); \
AdamGreen 0:616601bde9fb 124 cp += 3; \
AdamGreen 0:616601bde9fb 125 } else { \
AdamGreen 0:616601bde9fb 126 (f) = htons((u_short)*cp++); \
AdamGreen 0:616601bde9fb 127 } \
AdamGreen 0:616601bde9fb 128 }
AdamGreen 0:616601bde9fb 129
AdamGreen 0:616601bde9fb 130 /*
AdamGreen 0:616601bde9fb 131 * vj_compress_tcp - Attempt to do Van Jacobson header compression on a
AdamGreen 0:616601bde9fb 132 * packet. This assumes that nb and comp are not null and that the first
AdamGreen 0:616601bde9fb 133 * buffer of the chain contains a valid IP header.
AdamGreen 0:616601bde9fb 134 * Return the VJ type code indicating whether or not the packet was
AdamGreen 0:616601bde9fb 135 * compressed.
AdamGreen 0:616601bde9fb 136 */
AdamGreen 0:616601bde9fb 137 u_int
AdamGreen 0:616601bde9fb 138 vj_compress_tcp(struct vjcompress *comp, struct pbuf *pb)
AdamGreen 0:616601bde9fb 139 {
AdamGreen 0:616601bde9fb 140 register struct ip_hdr *ip = (struct ip_hdr *)pb->payload;
AdamGreen 0:616601bde9fb 141 register struct cstate *cs = comp->last_cs->cs_next;
AdamGreen 0:616601bde9fb 142 register u_short hlen = IPH_HL(ip);
AdamGreen 0:616601bde9fb 143 register struct tcp_hdr *oth;
AdamGreen 0:616601bde9fb 144 register struct tcp_hdr *th;
AdamGreen 0:616601bde9fb 145 register u_short deltaS, deltaA;
AdamGreen 0:616601bde9fb 146 register u_long deltaL;
AdamGreen 0:616601bde9fb 147 register u_int changes = 0;
AdamGreen 0:616601bde9fb 148 u_char new_seq[16];
AdamGreen 0:616601bde9fb 149 register u_char *cp = new_seq;
AdamGreen 0:616601bde9fb 150
AdamGreen 0:616601bde9fb 151 /*
AdamGreen 0:616601bde9fb 152 * Check that the packet is IP proto TCP.
AdamGreen 0:616601bde9fb 153 */
AdamGreen 0:616601bde9fb 154 if (IPH_PROTO(ip) != IP_PROTO_TCP) {
AdamGreen 0:616601bde9fb 155 return (TYPE_IP);
AdamGreen 0:616601bde9fb 156 }
AdamGreen 0:616601bde9fb 157
AdamGreen 0:616601bde9fb 158 /*
AdamGreen 0:616601bde9fb 159 * Bail if this is an IP fragment or if the TCP packet isn't
AdamGreen 0:616601bde9fb 160 * `compressible' (i.e., ACK isn't set or some other control bit is
AdamGreen 0:616601bde9fb 161 * set).
AdamGreen 0:616601bde9fb 162 */
AdamGreen 0:616601bde9fb 163 if ((IPH_OFFSET(ip) & PP_HTONS(0x3fff)) || pb->tot_len < 40) {
AdamGreen 0:616601bde9fb 164 return (TYPE_IP);
AdamGreen 0:616601bde9fb 165 }
AdamGreen 0:616601bde9fb 166 th = (struct tcp_hdr *)&((long *)ip)[hlen];
AdamGreen 0:616601bde9fb 167 if ((TCPH_FLAGS(th) & (TCP_SYN|TCP_FIN|TCP_RST|TCP_ACK)) != TCP_ACK) {
AdamGreen 0:616601bde9fb 168 return (TYPE_IP);
AdamGreen 0:616601bde9fb 169 }
AdamGreen 0:616601bde9fb 170 /*
AdamGreen 0:616601bde9fb 171 * Packet is compressible -- we're going to send either a
AdamGreen 0:616601bde9fb 172 * COMPRESSED_TCP or UNCOMPRESSED_TCP packet. Either way we need
AdamGreen 0:616601bde9fb 173 * to locate (or create) the connection state. Special case the
AdamGreen 0:616601bde9fb 174 * most recently used connection since it's most likely to be used
AdamGreen 0:616601bde9fb 175 * again & we don't have to do any reordering if it's used.
AdamGreen 0:616601bde9fb 176 */
AdamGreen 0:616601bde9fb 177 INCR(vjs_packets);
AdamGreen 0:616601bde9fb 178 if (!ip_addr_cmp(&ip->src, &cs->cs_ip.src)
AdamGreen 0:616601bde9fb 179 || !ip_addr_cmp(&ip->dest, &cs->cs_ip.dest)
AdamGreen 0:616601bde9fb 180 || *(long *)th != ((long *)&cs->cs_ip)[IPH_HL(&cs->cs_ip)]) {
AdamGreen 0:616601bde9fb 181 /*
AdamGreen 0:616601bde9fb 182 * Wasn't the first -- search for it.
AdamGreen 0:616601bde9fb 183 *
AdamGreen 0:616601bde9fb 184 * States are kept in a circularly linked list with
AdamGreen 0:616601bde9fb 185 * last_cs pointing to the end of the list. The
AdamGreen 0:616601bde9fb 186 * list is kept in lru order by moving a state to the
AdamGreen 0:616601bde9fb 187 * head of the list whenever it is referenced. Since
AdamGreen 0:616601bde9fb 188 * the list is short and, empirically, the connection
AdamGreen 0:616601bde9fb 189 * we want is almost always near the front, we locate
AdamGreen 0:616601bde9fb 190 * states via linear search. If we don't find a state
AdamGreen 0:616601bde9fb 191 * for the datagram, the oldest state is (re-)used.
AdamGreen 0:616601bde9fb 192 */
AdamGreen 0:616601bde9fb 193 register struct cstate *lcs;
AdamGreen 0:616601bde9fb 194 register struct cstate *lastcs = comp->last_cs;
AdamGreen 0:616601bde9fb 195
AdamGreen 0:616601bde9fb 196 do {
AdamGreen 0:616601bde9fb 197 lcs = cs; cs = cs->cs_next;
AdamGreen 0:616601bde9fb 198 INCR(vjs_searches);
AdamGreen 0:616601bde9fb 199 if (ip_addr_cmp(&ip->src, &cs->cs_ip.src)
AdamGreen 0:616601bde9fb 200 && ip_addr_cmp(&ip->dest, &cs->cs_ip.dest)
AdamGreen 0:616601bde9fb 201 && *(long *)th == ((long *)&cs->cs_ip)[IPH_HL(&cs->cs_ip)]) {
AdamGreen 0:616601bde9fb 202 goto found;
AdamGreen 0:616601bde9fb 203 }
AdamGreen 0:616601bde9fb 204 } while (cs != lastcs);
AdamGreen 0:616601bde9fb 205
AdamGreen 0:616601bde9fb 206 /*
AdamGreen 0:616601bde9fb 207 * Didn't find it -- re-use oldest cstate. Send an
AdamGreen 0:616601bde9fb 208 * uncompressed packet that tells the other side what
AdamGreen 0:616601bde9fb 209 * connection number we're using for this conversation.
AdamGreen 0:616601bde9fb 210 * Note that since the state list is circular, the oldest
AdamGreen 0:616601bde9fb 211 * state points to the newest and we only need to set
AdamGreen 0:616601bde9fb 212 * last_cs to update the lru linkage.
AdamGreen 0:616601bde9fb 213 */
AdamGreen 0:616601bde9fb 214 INCR(vjs_misses);
AdamGreen 0:616601bde9fb 215 comp->last_cs = lcs;
AdamGreen 0:616601bde9fb 216 hlen += TCPH_OFFSET(th);
AdamGreen 0:616601bde9fb 217 hlen <<= 2;
AdamGreen 0:616601bde9fb 218 /* Check that the IP/TCP headers are contained in the first buffer. */
AdamGreen 0:616601bde9fb 219 if (hlen > pb->len) {
AdamGreen 0:616601bde9fb 220 return (TYPE_IP);
AdamGreen 0:616601bde9fb 221 }
AdamGreen 0:616601bde9fb 222 goto uncompressed;
AdamGreen 0:616601bde9fb 223
AdamGreen 0:616601bde9fb 224 found:
AdamGreen 0:616601bde9fb 225 /*
AdamGreen 0:616601bde9fb 226 * Found it -- move to the front on the connection list.
AdamGreen 0:616601bde9fb 227 */
AdamGreen 0:616601bde9fb 228 if (cs == lastcs) {
AdamGreen 0:616601bde9fb 229 comp->last_cs = lcs;
AdamGreen 0:616601bde9fb 230 } else {
AdamGreen 0:616601bde9fb 231 lcs->cs_next = cs->cs_next;
AdamGreen 0:616601bde9fb 232 cs->cs_next = lastcs->cs_next;
AdamGreen 0:616601bde9fb 233 lastcs->cs_next = cs;
AdamGreen 0:616601bde9fb 234 }
AdamGreen 0:616601bde9fb 235 }
AdamGreen 0:616601bde9fb 236
AdamGreen 0:616601bde9fb 237 oth = (struct tcp_hdr *)&((long *)&cs->cs_ip)[hlen];
AdamGreen 0:616601bde9fb 238 deltaS = hlen;
AdamGreen 0:616601bde9fb 239 hlen += TCPH_OFFSET(th);
AdamGreen 0:616601bde9fb 240 hlen <<= 2;
AdamGreen 0:616601bde9fb 241 /* Check that the IP/TCP headers are contained in the first buffer. */
AdamGreen 0:616601bde9fb 242 if (hlen > pb->len) {
AdamGreen 0:616601bde9fb 243 PPPDEBUG(LOG_INFO, ("vj_compress_tcp: header len %d spans buffers\n", hlen));
AdamGreen 0:616601bde9fb 244 return (TYPE_IP);
AdamGreen 0:616601bde9fb 245 }
AdamGreen 0:616601bde9fb 246
AdamGreen 0:616601bde9fb 247 /*
AdamGreen 0:616601bde9fb 248 * Make sure that only what we expect to change changed. The first
AdamGreen 0:616601bde9fb 249 * line of the `if' checks the IP protocol version, header length &
AdamGreen 0:616601bde9fb 250 * type of service. The 2nd line checks the "Don't fragment" bit.
AdamGreen 0:616601bde9fb 251 * The 3rd line checks the time-to-live and protocol (the protocol
AdamGreen 0:616601bde9fb 252 * check is unnecessary but costless). The 4th line checks the TCP
AdamGreen 0:616601bde9fb 253 * header length. The 5th line checks IP options, if any. The 6th
AdamGreen 0:616601bde9fb 254 * line checks TCP options, if any. If any of these things are
AdamGreen 0:616601bde9fb 255 * different between the previous & current datagram, we send the
AdamGreen 0:616601bde9fb 256 * current datagram `uncompressed'.
AdamGreen 0:616601bde9fb 257 */
AdamGreen 0:616601bde9fb 258 if (((u_short *)ip)[0] != ((u_short *)&cs->cs_ip)[0]
AdamGreen 0:616601bde9fb 259 || ((u_short *)ip)[3] != ((u_short *)&cs->cs_ip)[3]
AdamGreen 0:616601bde9fb 260 || ((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4]
AdamGreen 0:616601bde9fb 261 || TCPH_OFFSET(th) != TCPH_OFFSET(oth)
AdamGreen 0:616601bde9fb 262 || (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2))
AdamGreen 0:616601bde9fb 263 || (TCPH_OFFSET(th) > 5 && BCMP(th + 1, oth + 1, (TCPH_OFFSET(th) - 5) << 2))) {
AdamGreen 0:616601bde9fb 264 goto uncompressed;
AdamGreen 0:616601bde9fb 265 }
AdamGreen 0:616601bde9fb 266
AdamGreen 0:616601bde9fb 267 /*
AdamGreen 0:616601bde9fb 268 * Figure out which of the changing fields changed. The
AdamGreen 0:616601bde9fb 269 * receiver expects changes in the order: urgent, window,
AdamGreen 0:616601bde9fb 270 * ack, seq (the order minimizes the number of temporaries
AdamGreen 0:616601bde9fb 271 * needed in this section of code).
AdamGreen 0:616601bde9fb 272 */
AdamGreen 0:616601bde9fb 273 if (TCPH_FLAGS(th) & TCP_URG) {
AdamGreen 0:616601bde9fb 274 deltaS = ntohs(th->urgp);
AdamGreen 0:616601bde9fb 275 ENCODEZ(deltaS);
AdamGreen 0:616601bde9fb 276 changes |= NEW_U;
AdamGreen 0:616601bde9fb 277 } else if (th->urgp != oth->urgp) {
AdamGreen 0:616601bde9fb 278 /* argh! URG not set but urp changed -- a sensible
AdamGreen 0:616601bde9fb 279 * implementation should never do this but RFC793
AdamGreen 0:616601bde9fb 280 * doesn't prohibit the change so we have to deal
AdamGreen 0:616601bde9fb 281 * with it. */
AdamGreen 0:616601bde9fb 282 goto uncompressed;
AdamGreen 0:616601bde9fb 283 }
AdamGreen 0:616601bde9fb 284
AdamGreen 0:616601bde9fb 285 if ((deltaS = (u_short)(ntohs(th->wnd) - ntohs(oth->wnd))) != 0) {
AdamGreen 0:616601bde9fb 286 ENCODE(deltaS);
AdamGreen 0:616601bde9fb 287 changes |= NEW_W;
AdamGreen 0:616601bde9fb 288 }
AdamGreen 0:616601bde9fb 289
AdamGreen 0:616601bde9fb 290 if ((deltaL = ntohl(th->ackno) - ntohl(oth->ackno)) != 0) {
AdamGreen 0:616601bde9fb 291 if (deltaL > 0xffff) {
AdamGreen 0:616601bde9fb 292 goto uncompressed;
AdamGreen 0:616601bde9fb 293 }
AdamGreen 0:616601bde9fb 294 deltaA = (u_short)deltaL;
AdamGreen 0:616601bde9fb 295 ENCODE(deltaA);
AdamGreen 0:616601bde9fb 296 changes |= NEW_A;
AdamGreen 0:616601bde9fb 297 }
AdamGreen 0:616601bde9fb 298
AdamGreen 0:616601bde9fb 299 if ((deltaL = ntohl(th->seqno) - ntohl(oth->seqno)) != 0) {
AdamGreen 0:616601bde9fb 300 if (deltaL > 0xffff) {
AdamGreen 0:616601bde9fb 301 goto uncompressed;
AdamGreen 0:616601bde9fb 302 }
AdamGreen 0:616601bde9fb 303 deltaS = (u_short)deltaL;
AdamGreen 0:616601bde9fb 304 ENCODE(deltaS);
AdamGreen 0:616601bde9fb 305 changes |= NEW_S;
AdamGreen 0:616601bde9fb 306 }
AdamGreen 0:616601bde9fb 307
AdamGreen 0:616601bde9fb 308 switch(changes) {
AdamGreen 0:616601bde9fb 309 case 0:
AdamGreen 0:616601bde9fb 310 /*
AdamGreen 0:616601bde9fb 311 * Nothing changed. If this packet contains data and the
AdamGreen 0:616601bde9fb 312 * last one didn't, this is probably a data packet following
AdamGreen 0:616601bde9fb 313 * an ack (normal on an interactive connection) and we send
AdamGreen 0:616601bde9fb 314 * it compressed. Otherwise it's probably a retransmit,
AdamGreen 0:616601bde9fb 315 * retransmitted ack or window probe. Send it uncompressed
AdamGreen 0:616601bde9fb 316 * in case the other side missed the compressed version.
AdamGreen 0:616601bde9fb 317 */
AdamGreen 0:616601bde9fb 318 if (IPH_LEN(ip) != IPH_LEN(&cs->cs_ip) &&
AdamGreen 0:616601bde9fb 319 ntohs(IPH_LEN(&cs->cs_ip)) == hlen) {
AdamGreen 0:616601bde9fb 320 break;
AdamGreen 0:616601bde9fb 321 }
AdamGreen 0:616601bde9fb 322
AdamGreen 0:616601bde9fb 323 /* (fall through) */
AdamGreen 0:616601bde9fb 324
AdamGreen 0:616601bde9fb 325 case SPECIAL_I:
AdamGreen 0:616601bde9fb 326 case SPECIAL_D:
AdamGreen 0:616601bde9fb 327 /*
AdamGreen 0:616601bde9fb 328 * actual changes match one of our special case encodings --
AdamGreen 0:616601bde9fb 329 * send packet uncompressed.
AdamGreen 0:616601bde9fb 330 */
AdamGreen 0:616601bde9fb 331 goto uncompressed;
AdamGreen 0:616601bde9fb 332
AdamGreen 0:616601bde9fb 333 case NEW_S|NEW_A:
AdamGreen 0:616601bde9fb 334 if (deltaS == deltaA && deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
AdamGreen 0:616601bde9fb 335 /* special case for echoed terminal traffic */
AdamGreen 0:616601bde9fb 336 changes = SPECIAL_I;
AdamGreen 0:616601bde9fb 337 cp = new_seq;
AdamGreen 0:616601bde9fb 338 }
AdamGreen 0:616601bde9fb 339 break;
AdamGreen 0:616601bde9fb 340
AdamGreen 0:616601bde9fb 341 case NEW_S:
AdamGreen 0:616601bde9fb 342 if (deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
AdamGreen 0:616601bde9fb 343 /* special case for data xfer */
AdamGreen 0:616601bde9fb 344 changes = SPECIAL_D;
AdamGreen 0:616601bde9fb 345 cp = new_seq;
AdamGreen 0:616601bde9fb 346 }
AdamGreen 0:616601bde9fb 347 break;
AdamGreen 0:616601bde9fb 348 }
AdamGreen 0:616601bde9fb 349
AdamGreen 0:616601bde9fb 350 deltaS = (u_short)(ntohs(IPH_ID(ip)) - ntohs(IPH_ID(&cs->cs_ip)));
AdamGreen 0:616601bde9fb 351 if (deltaS != 1) {
AdamGreen 0:616601bde9fb 352 ENCODEZ(deltaS);
AdamGreen 0:616601bde9fb 353 changes |= NEW_I;
AdamGreen 0:616601bde9fb 354 }
AdamGreen 0:616601bde9fb 355 if (TCPH_FLAGS(th) & TCP_PSH) {
AdamGreen 0:616601bde9fb 356 changes |= TCP_PUSH_BIT;
AdamGreen 0:616601bde9fb 357 }
AdamGreen 0:616601bde9fb 358 /*
AdamGreen 0:616601bde9fb 359 * Grab the cksum before we overwrite it below. Then update our
AdamGreen 0:616601bde9fb 360 * state with this packet's header.
AdamGreen 0:616601bde9fb 361 */
AdamGreen 0:616601bde9fb 362 deltaA = ntohs(th->chksum);
AdamGreen 0:616601bde9fb 363 BCOPY(ip, &cs->cs_ip, hlen);
AdamGreen 0:616601bde9fb 364
AdamGreen 0:616601bde9fb 365 /*
AdamGreen 0:616601bde9fb 366 * We want to use the original packet as our compressed packet.
AdamGreen 0:616601bde9fb 367 * (cp - new_seq) is the number of bytes we need for compressed
AdamGreen 0:616601bde9fb 368 * sequence numbers. In addition we need one byte for the change
AdamGreen 0:616601bde9fb 369 * mask, one for the connection id and two for the tcp checksum.
AdamGreen 0:616601bde9fb 370 * So, (cp - new_seq) + 4 bytes of header are needed. hlen is how
AdamGreen 0:616601bde9fb 371 * many bytes of the original packet to toss so subtract the two to
AdamGreen 0:616601bde9fb 372 * get the new packet size.
AdamGreen 0:616601bde9fb 373 */
AdamGreen 0:616601bde9fb 374 deltaS = (u_short)(cp - new_seq);
AdamGreen 0:616601bde9fb 375 if (!comp->compressSlot || comp->last_xmit != cs->cs_id) {
AdamGreen 0:616601bde9fb 376 comp->last_xmit = cs->cs_id;
AdamGreen 0:616601bde9fb 377 hlen -= deltaS + 4;
AdamGreen 0:616601bde9fb 378 if(pbuf_header(pb, -hlen)){
AdamGreen 0:616601bde9fb 379 /* Can we cope with this failing? Just assert for now */
AdamGreen 0:616601bde9fb 380 LWIP_ASSERT("pbuf_header failed\n", 0);
AdamGreen 0:616601bde9fb 381 }
AdamGreen 0:616601bde9fb 382 cp = (u_char *)pb->payload;
AdamGreen 0:616601bde9fb 383 *cp++ = (u_char)(changes | NEW_C);
AdamGreen 0:616601bde9fb 384 *cp++ = cs->cs_id;
AdamGreen 0:616601bde9fb 385 } else {
AdamGreen 0:616601bde9fb 386 hlen -= deltaS + 3;
AdamGreen 0:616601bde9fb 387 if(pbuf_header(pb, -hlen)) {
AdamGreen 0:616601bde9fb 388 /* Can we cope with this failing? Just assert for now */
AdamGreen 0:616601bde9fb 389 LWIP_ASSERT("pbuf_header failed\n", 0);
AdamGreen 0:616601bde9fb 390 }
AdamGreen 0:616601bde9fb 391 cp = (u_char *)pb->payload;
AdamGreen 0:616601bde9fb 392 *cp++ = (u_char)changes;
AdamGreen 0:616601bde9fb 393 }
AdamGreen 0:616601bde9fb 394 *cp++ = (u_char)(deltaA >> 8);
AdamGreen 0:616601bde9fb 395 *cp++ = (u_char)deltaA;
AdamGreen 0:616601bde9fb 396 BCOPY(new_seq, cp, deltaS);
AdamGreen 0:616601bde9fb 397 INCR(vjs_compressed);
AdamGreen 0:616601bde9fb 398 return (TYPE_COMPRESSED_TCP);
AdamGreen 0:616601bde9fb 399
AdamGreen 0:616601bde9fb 400 /*
AdamGreen 0:616601bde9fb 401 * Update connection state cs & send uncompressed packet (that is,
AdamGreen 0:616601bde9fb 402 * a regular ip/tcp packet but with the 'conversation id' we hope
AdamGreen 0:616601bde9fb 403 * to use on future compressed packets in the protocol field).
AdamGreen 0:616601bde9fb 404 */
AdamGreen 0:616601bde9fb 405 uncompressed:
AdamGreen 0:616601bde9fb 406 BCOPY(ip, &cs->cs_ip, hlen);
AdamGreen 0:616601bde9fb 407 IPH_PROTO_SET(ip, cs->cs_id);
AdamGreen 0:616601bde9fb 408 comp->last_xmit = cs->cs_id;
AdamGreen 0:616601bde9fb 409 return (TYPE_UNCOMPRESSED_TCP);
AdamGreen 0:616601bde9fb 410 }
AdamGreen 0:616601bde9fb 411
AdamGreen 0:616601bde9fb 412 /*
AdamGreen 0:616601bde9fb 413 * Called when we may have missed a packet.
AdamGreen 0:616601bde9fb 414 */
AdamGreen 0:616601bde9fb 415 void
AdamGreen 0:616601bde9fb 416 vj_uncompress_err(struct vjcompress *comp)
AdamGreen 0:616601bde9fb 417 {
AdamGreen 0:616601bde9fb 418 comp->flags |= VJF_TOSS;
AdamGreen 0:616601bde9fb 419 INCR(vjs_errorin);
AdamGreen 0:616601bde9fb 420 }
AdamGreen 0:616601bde9fb 421
AdamGreen 0:616601bde9fb 422 /*
AdamGreen 0:616601bde9fb 423 * "Uncompress" a packet of type TYPE_UNCOMPRESSED_TCP.
AdamGreen 0:616601bde9fb 424 * Return 0 on success, -1 on failure.
AdamGreen 0:616601bde9fb 425 */
AdamGreen 0:616601bde9fb 426 int
AdamGreen 0:616601bde9fb 427 vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp)
AdamGreen 0:616601bde9fb 428 {
AdamGreen 0:616601bde9fb 429 register u_int hlen;
AdamGreen 0:616601bde9fb 430 register struct cstate *cs;
AdamGreen 0:616601bde9fb 431 register struct ip_hdr *ip;
AdamGreen 0:616601bde9fb 432
AdamGreen 0:616601bde9fb 433 ip = (struct ip_hdr *)nb->payload;
AdamGreen 0:616601bde9fb 434 hlen = IPH_HL(ip) << 2;
AdamGreen 0:616601bde9fb 435 if (IPH_PROTO(ip) >= MAX_SLOTS
AdamGreen 0:616601bde9fb 436 || hlen + sizeof(struct tcp_hdr) > nb->len
AdamGreen 0:616601bde9fb 437 || (hlen += TCPH_OFFSET(((struct tcp_hdr *)&((char *)ip)[hlen])) << 2)
AdamGreen 0:616601bde9fb 438 > nb->len
AdamGreen 0:616601bde9fb 439 || hlen > MAX_HDR) {
AdamGreen 0:616601bde9fb 440 PPPDEBUG(LOG_INFO, ("vj_uncompress_uncomp: bad cid=%d, hlen=%d buflen=%d\n",
AdamGreen 0:616601bde9fb 441 IPH_PROTO(ip), hlen, nb->len));
AdamGreen 0:616601bde9fb 442 comp->flags |= VJF_TOSS;
AdamGreen 0:616601bde9fb 443 INCR(vjs_errorin);
AdamGreen 0:616601bde9fb 444 return -1;
AdamGreen 0:616601bde9fb 445 }
AdamGreen 0:616601bde9fb 446 cs = &comp->rstate[comp->last_recv = IPH_PROTO(ip)];
AdamGreen 0:616601bde9fb 447 comp->flags &=~ VJF_TOSS;
AdamGreen 0:616601bde9fb 448 IPH_PROTO_SET(ip, IP_PROTO_TCP);
AdamGreen 0:616601bde9fb 449 BCOPY(ip, &cs->cs_ip, hlen);
AdamGreen 0:616601bde9fb 450 cs->cs_hlen = (u_short)hlen;
AdamGreen 0:616601bde9fb 451 INCR(vjs_uncompressedin);
AdamGreen 0:616601bde9fb 452 return 0;
AdamGreen 0:616601bde9fb 453 }
AdamGreen 0:616601bde9fb 454
AdamGreen 0:616601bde9fb 455 /*
AdamGreen 0:616601bde9fb 456 * Uncompress a packet of type TYPE_COMPRESSED_TCP.
AdamGreen 0:616601bde9fb 457 * The packet is composed of a buffer chain and the first buffer
AdamGreen 0:616601bde9fb 458 * must contain an accurate chain length.
AdamGreen 0:616601bde9fb 459 * The first buffer must include the entire compressed TCP/IP header.
AdamGreen 0:616601bde9fb 460 * This procedure replaces the compressed header with the uncompressed
AdamGreen 0:616601bde9fb 461 * header and returns the length of the VJ header.
AdamGreen 0:616601bde9fb 462 */
AdamGreen 0:616601bde9fb 463 int
AdamGreen 0:616601bde9fb 464 vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp)
AdamGreen 0:616601bde9fb 465 {
AdamGreen 0:616601bde9fb 466 u_char *cp;
AdamGreen 0:616601bde9fb 467 struct tcp_hdr *th;
AdamGreen 0:616601bde9fb 468 struct cstate *cs;
AdamGreen 0:616601bde9fb 469 u_short *bp;
AdamGreen 0:616601bde9fb 470 struct pbuf *n0 = *nb;
AdamGreen 0:616601bde9fb 471 u32_t tmp;
AdamGreen 0:616601bde9fb 472 u_int vjlen, hlen, changes;
AdamGreen 0:616601bde9fb 473
AdamGreen 0:616601bde9fb 474 INCR(vjs_compressedin);
AdamGreen 0:616601bde9fb 475 cp = (u_char *)n0->payload;
AdamGreen 0:616601bde9fb 476 changes = *cp++;
AdamGreen 0:616601bde9fb 477 if (changes & NEW_C) {
AdamGreen 0:616601bde9fb 478 /*
AdamGreen 0:616601bde9fb 479 * Make sure the state index is in range, then grab the state.
AdamGreen 0:616601bde9fb 480 * If we have a good state index, clear the 'discard' flag.
AdamGreen 0:616601bde9fb 481 */
AdamGreen 0:616601bde9fb 482 if (*cp >= MAX_SLOTS) {
AdamGreen 0:616601bde9fb 483 PPPDEBUG(LOG_INFO, ("vj_uncompress_tcp: bad cid=%d\n", *cp));
AdamGreen 0:616601bde9fb 484 goto bad;
AdamGreen 0:616601bde9fb 485 }
AdamGreen 0:616601bde9fb 486
AdamGreen 0:616601bde9fb 487 comp->flags &=~ VJF_TOSS;
AdamGreen 0:616601bde9fb 488 comp->last_recv = *cp++;
AdamGreen 0:616601bde9fb 489 } else {
AdamGreen 0:616601bde9fb 490 /*
AdamGreen 0:616601bde9fb 491 * this packet has an implicit state index. If we've
AdamGreen 0:616601bde9fb 492 * had a line error since the last time we got an
AdamGreen 0:616601bde9fb 493 * explicit state index, we have to toss the packet.
AdamGreen 0:616601bde9fb 494 */
AdamGreen 0:616601bde9fb 495 if (comp->flags & VJF_TOSS) {
AdamGreen 0:616601bde9fb 496 PPPDEBUG(LOG_INFO, ("vj_uncompress_tcp: tossing\n"));
AdamGreen 0:616601bde9fb 497 INCR(vjs_tossed);
AdamGreen 0:616601bde9fb 498 return (-1);
AdamGreen 0:616601bde9fb 499 }
AdamGreen 0:616601bde9fb 500 }
AdamGreen 0:616601bde9fb 501 cs = &comp->rstate[comp->last_recv];
AdamGreen 0:616601bde9fb 502 hlen = IPH_HL(&cs->cs_ip) << 2;
AdamGreen 0:616601bde9fb 503 th = (struct tcp_hdr *)&((u_char *)&cs->cs_ip)[hlen];
AdamGreen 0:616601bde9fb 504 th->chksum = htons((*cp << 8) | cp[1]);
AdamGreen 0:616601bde9fb 505 cp += 2;
AdamGreen 0:616601bde9fb 506 if (changes & TCP_PUSH_BIT) {
AdamGreen 0:616601bde9fb 507 TCPH_SET_FLAG(th, TCP_PSH);
AdamGreen 0:616601bde9fb 508 } else {
AdamGreen 0:616601bde9fb 509 TCPH_UNSET_FLAG(th, TCP_PSH);
AdamGreen 0:616601bde9fb 510 }
AdamGreen 0:616601bde9fb 511
AdamGreen 0:616601bde9fb 512 switch (changes & SPECIALS_MASK) {
AdamGreen 0:616601bde9fb 513 case SPECIAL_I:
AdamGreen 0:616601bde9fb 514 {
AdamGreen 0:616601bde9fb 515 register u32_t i = ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen;
AdamGreen 0:616601bde9fb 516 /* some compilers can't nest inline assembler.. */
AdamGreen 0:616601bde9fb 517 tmp = ntohl(th->ackno) + i;
AdamGreen 0:616601bde9fb 518 th->ackno = htonl(tmp);
AdamGreen 0:616601bde9fb 519 tmp = ntohl(th->seqno) + i;
AdamGreen 0:616601bde9fb 520 th->seqno = htonl(tmp);
AdamGreen 0:616601bde9fb 521 }
AdamGreen 0:616601bde9fb 522 break;
AdamGreen 0:616601bde9fb 523
AdamGreen 0:616601bde9fb 524 case SPECIAL_D:
AdamGreen 0:616601bde9fb 525 /* some compilers can't nest inline assembler.. */
AdamGreen 0:616601bde9fb 526 tmp = ntohl(th->seqno) + ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen;
AdamGreen 0:616601bde9fb 527 th->seqno = htonl(tmp);
AdamGreen 0:616601bde9fb 528 break;
AdamGreen 0:616601bde9fb 529
AdamGreen 0:616601bde9fb 530 default:
AdamGreen 0:616601bde9fb 531 if (changes & NEW_U) {
AdamGreen 0:616601bde9fb 532 TCPH_SET_FLAG(th, TCP_URG);
AdamGreen 0:616601bde9fb 533 DECODEU(th->urgp);
AdamGreen 0:616601bde9fb 534 } else {
AdamGreen 0:616601bde9fb 535 TCPH_UNSET_FLAG(th, TCP_URG);
AdamGreen 0:616601bde9fb 536 }
AdamGreen 0:616601bde9fb 537 if (changes & NEW_W) {
AdamGreen 0:616601bde9fb 538 DECODES(th->wnd);
AdamGreen 0:616601bde9fb 539 }
AdamGreen 0:616601bde9fb 540 if (changes & NEW_A) {
AdamGreen 0:616601bde9fb 541 DECODEL(th->ackno);
AdamGreen 0:616601bde9fb 542 }
AdamGreen 0:616601bde9fb 543 if (changes & NEW_S) {
AdamGreen 0:616601bde9fb 544 DECODEL(th->seqno);
AdamGreen 0:616601bde9fb 545 }
AdamGreen 0:616601bde9fb 546 break;
AdamGreen 0:616601bde9fb 547 }
AdamGreen 0:616601bde9fb 548 if (changes & NEW_I) {
AdamGreen 0:616601bde9fb 549 DECODES(cs->cs_ip._id);
AdamGreen 0:616601bde9fb 550 } else {
AdamGreen 0:616601bde9fb 551 IPH_ID_SET(&cs->cs_ip, ntohs(IPH_ID(&cs->cs_ip)) + 1);
AdamGreen 0:616601bde9fb 552 IPH_ID_SET(&cs->cs_ip, htons(IPH_ID(&cs->cs_ip)));
AdamGreen 0:616601bde9fb 553 }
AdamGreen 0:616601bde9fb 554
AdamGreen 0:616601bde9fb 555 /*
AdamGreen 0:616601bde9fb 556 * At this point, cp points to the first byte of data in the
AdamGreen 0:616601bde9fb 557 * packet. Fill in the IP total length and update the IP
AdamGreen 0:616601bde9fb 558 * header checksum.
AdamGreen 0:616601bde9fb 559 */
AdamGreen 0:616601bde9fb 560 vjlen = (u_short)(cp - (u_char*)n0->payload);
AdamGreen 0:616601bde9fb 561 if (n0->len < vjlen) {
AdamGreen 0:616601bde9fb 562 /*
AdamGreen 0:616601bde9fb 563 * We must have dropped some characters (crc should detect
AdamGreen 0:616601bde9fb 564 * this but the old slip framing won't)
AdamGreen 0:616601bde9fb 565 */
AdamGreen 0:616601bde9fb 566 PPPDEBUG(LOG_INFO, ("vj_uncompress_tcp: head buffer %d too short %d\n",
AdamGreen 0:616601bde9fb 567 n0->len, vjlen));
AdamGreen 0:616601bde9fb 568 goto bad;
AdamGreen 0:616601bde9fb 569 }
AdamGreen 0:616601bde9fb 570
AdamGreen 0:616601bde9fb 571 #if BYTE_ORDER == LITTLE_ENDIAN
AdamGreen 0:616601bde9fb 572 tmp = n0->tot_len - vjlen + cs->cs_hlen;
AdamGreen 0:616601bde9fb 573 IPH_LEN_SET(&cs->cs_ip, htons((u_short)tmp));
AdamGreen 0:616601bde9fb 574 #else
AdamGreen 0:616601bde9fb 575 IPH_LEN_SET(&cs->cs_ip, htons(n0->tot_len - vjlen + cs->cs_hlen));
AdamGreen 0:616601bde9fb 576 #endif
AdamGreen 0:616601bde9fb 577
AdamGreen 0:616601bde9fb 578 /* recompute the ip header checksum */
AdamGreen 0:616601bde9fb 579 bp = (u_short *) &cs->cs_ip;
AdamGreen 0:616601bde9fb 580 IPH_CHKSUM_SET(&cs->cs_ip, 0);
AdamGreen 0:616601bde9fb 581 for (tmp = 0; hlen > 0; hlen -= 2) {
AdamGreen 0:616601bde9fb 582 tmp += *bp++;
AdamGreen 0:616601bde9fb 583 }
AdamGreen 0:616601bde9fb 584 tmp = (tmp & 0xffff) + (tmp >> 16);
AdamGreen 0:616601bde9fb 585 tmp = (tmp & 0xffff) + (tmp >> 16);
AdamGreen 0:616601bde9fb 586 IPH_CHKSUM_SET(&cs->cs_ip, (u_short)(~tmp));
AdamGreen 0:616601bde9fb 587
AdamGreen 0:616601bde9fb 588 /* Remove the compressed header and prepend the uncompressed header. */
AdamGreen 0:616601bde9fb 589 if(pbuf_header(n0, -((s16_t)(vjlen)))) {
AdamGreen 0:616601bde9fb 590 /* Can we cope with this failing? Just assert for now */
AdamGreen 0:616601bde9fb 591 LWIP_ASSERT("pbuf_header failed\n", 0);
AdamGreen 0:616601bde9fb 592 goto bad;
AdamGreen 0:616601bde9fb 593 }
AdamGreen 0:616601bde9fb 594
AdamGreen 0:616601bde9fb 595 if(LWIP_MEM_ALIGN(n0->payload) != n0->payload) {
AdamGreen 0:616601bde9fb 596 struct pbuf *np, *q;
AdamGreen 0:616601bde9fb 597 u8_t *bufptr;
AdamGreen 0:616601bde9fb 598
AdamGreen 0:616601bde9fb 599 np = pbuf_alloc(PBUF_RAW, n0->len + cs->cs_hlen, PBUF_POOL);
AdamGreen 0:616601bde9fb 600 if(!np) {
AdamGreen 0:616601bde9fb 601 PPPDEBUG(LOG_WARNING, ("vj_uncompress_tcp: realign failed\n"));
AdamGreen 0:616601bde9fb 602 goto bad;
AdamGreen 0:616601bde9fb 603 }
AdamGreen 0:616601bde9fb 604
AdamGreen 0:616601bde9fb 605 if(pbuf_header(np, -cs->cs_hlen)) {
AdamGreen 0:616601bde9fb 606 /* Can we cope with this failing? Just assert for now */
AdamGreen 0:616601bde9fb 607 LWIP_ASSERT("pbuf_header failed\n", 0);
AdamGreen 0:616601bde9fb 608 goto bad;
AdamGreen 0:616601bde9fb 609 }
AdamGreen 0:616601bde9fb 610
AdamGreen 0:616601bde9fb 611 bufptr = (u8_t *)n0->payload;
AdamGreen 0:616601bde9fb 612 for(q = np; q != NULL; q = q->next) {
AdamGreen 0:616601bde9fb 613 MEMCPY(q->payload, bufptr, q->len);
AdamGreen 0:616601bde9fb 614 bufptr += q->len;
AdamGreen 0:616601bde9fb 615 }
AdamGreen 0:616601bde9fb 616
AdamGreen 0:616601bde9fb 617 if(n0->next) {
AdamGreen 0:616601bde9fb 618 pbuf_chain(np, n0->next);
AdamGreen 0:616601bde9fb 619 pbuf_dechain(n0);
AdamGreen 0:616601bde9fb 620 }
AdamGreen 0:616601bde9fb 621 pbuf_free(n0);
AdamGreen 0:616601bde9fb 622 n0 = np;
AdamGreen 0:616601bde9fb 623 }
AdamGreen 0:616601bde9fb 624
AdamGreen 0:616601bde9fb 625 if(pbuf_header(n0, cs->cs_hlen)) {
AdamGreen 0:616601bde9fb 626 struct pbuf *np;
AdamGreen 0:616601bde9fb 627
AdamGreen 0:616601bde9fb 628 LWIP_ASSERT("vj_uncompress_tcp: cs->cs_hlen <= PBUF_POOL_BUFSIZE", cs->cs_hlen <= PBUF_POOL_BUFSIZE);
AdamGreen 0:616601bde9fb 629 np = pbuf_alloc(PBUF_RAW, cs->cs_hlen, PBUF_POOL);
AdamGreen 0:616601bde9fb 630 if(!np) {
AdamGreen 0:616601bde9fb 631 PPPDEBUG(LOG_WARNING, ("vj_uncompress_tcp: prepend failed\n"));
AdamGreen 0:616601bde9fb 632 goto bad;
AdamGreen 0:616601bde9fb 633 }
AdamGreen 0:616601bde9fb 634 pbuf_cat(np, n0);
AdamGreen 0:616601bde9fb 635 n0 = np;
AdamGreen 0:616601bde9fb 636 }
AdamGreen 0:616601bde9fb 637 LWIP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen);
AdamGreen 0:616601bde9fb 638 MEMCPY(n0->payload, &cs->cs_ip, cs->cs_hlen);
AdamGreen 0:616601bde9fb 639
AdamGreen 0:616601bde9fb 640 *nb = n0;
AdamGreen 0:616601bde9fb 641
AdamGreen 0:616601bde9fb 642 return vjlen;
AdamGreen 0:616601bde9fb 643
AdamGreen 0:616601bde9fb 644 bad:
AdamGreen 0:616601bde9fb 645 comp->flags |= VJF_TOSS;
AdamGreen 0:616601bde9fb 646 INCR(vjs_errorin);
AdamGreen 0:616601bde9fb 647 return (-1);
AdamGreen 0:616601bde9fb 648 }
AdamGreen 0:616601bde9fb 649
AdamGreen 0:616601bde9fb 650 #endif /* VJ_SUPPORT */
AdamGreen 0:616601bde9fb 651
AdamGreen 0:616601bde9fb 652 #endif /* PPP_SUPPORT */