Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

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