This is an OSC library for the mbed, created to be compatible with Recotana\'s OSCClass library (http://recotana.com) for the Arduino with Ethernet shield. I have also used parts of the OSC Transceiver(Sender/Receiver) code by xshige. It has many limitations, but it works for simple things (check comments on the mbedOSC.h). It will be evolving. written by: Alvaro Cassinelli, 7.10.2011

Dependencies:   mbed

Committer:
mbedalvaro
Date:
Sat Oct 15 14:15:55 2011 +0000
Revision:
0:f76708a93fb3
First working test of this simple OSC library.

Who changed what in which revision?

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