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 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
mbedalvaro 0:f76708a93fb3 3 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
mbedalvaro 0:f76708a93fb3 4 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
mbedalvaro 0:f76708a93fb3 5 * All rights reserved.
mbedalvaro 0:f76708a93fb3 6 *
mbedalvaro 0:f76708a93fb3 7 * Redistribution and use in source and binary forms, with or without modification,
mbedalvaro 0:f76708a93fb3 8 * are permitted provided that the following conditions are met:
mbedalvaro 0:f76708a93fb3 9 *
mbedalvaro 0:f76708a93fb3 10 * 1. Redistributions of source code must retain the above copyright notice,
mbedalvaro 0:f76708a93fb3 11 * this list of conditions and the following disclaimer.
mbedalvaro 0:f76708a93fb3 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbedalvaro 0:f76708a93fb3 13 * this list of conditions and the following disclaimer in the documentation
mbedalvaro 0:f76708a93fb3 14 * and/or other materials provided with the distribution.
mbedalvaro 0:f76708a93fb3 15 * 3. The name of the author may not be used to endorse or promote products
mbedalvaro 0:f76708a93fb3 16 * derived from this software without specific prior written permission.
mbedalvaro 0:f76708a93fb3 17 *
mbedalvaro 0:f76708a93fb3 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mbedalvaro 0:f76708a93fb3 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbedalvaro 0:f76708a93fb3 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mbedalvaro 0:f76708a93fb3 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mbedalvaro 0:f76708a93fb3 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mbedalvaro 0:f76708a93fb3 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbedalvaro 0:f76708a93fb3 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbedalvaro 0:f76708a93fb3 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mbedalvaro 0:f76708a93fb3 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mbedalvaro 0:f76708a93fb3 27 * OF SUCH DAMAGE.
mbedalvaro 0:f76708a93fb3 28 *
mbedalvaro 0:f76708a93fb3 29 * This file is part of the lwIP TCP/IP stack.
mbedalvaro 0:f76708a93fb3 30 *
mbedalvaro 0:f76708a93fb3 31 * Author: Adam Dunkels <adam@sics.se>
mbedalvaro 0:f76708a93fb3 32 *
mbedalvaro 0:f76708a93fb3 33 */
mbedalvaro 0:f76708a93fb3 34
mbedalvaro 0:f76708a93fb3 35 #ifndef __NETIF_ETHARP_H__
mbedalvaro 0:f76708a93fb3 36 #define __NETIF_ETHARP_H__
mbedalvaro 0:f76708a93fb3 37
mbedalvaro 0:f76708a93fb3 38 #include "lwip/opt.h"
mbedalvaro 0:f76708a93fb3 39
mbedalvaro 0:f76708a93fb3 40 #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
mbedalvaro 0:f76708a93fb3 41
mbedalvaro 0:f76708a93fb3 42 #include "lwip/pbuf.h"
mbedalvaro 0:f76708a93fb3 43 #include "lwip/ip_addr.h"
mbedalvaro 0:f76708a93fb3 44 #include "lwip/netif.h"
mbedalvaro 0:f76708a93fb3 45 #include "lwip/ip.h"
mbedalvaro 0:f76708a93fb3 46
mbedalvaro 0:f76708a93fb3 47 #ifdef __cplusplus
mbedalvaro 0:f76708a93fb3 48 extern "C" {
mbedalvaro 0:f76708a93fb3 49 #endif
mbedalvaro 0:f76708a93fb3 50
mbedalvaro 0:f76708a93fb3 51 #ifndef ETHARP_HWADDR_LEN
mbedalvaro 0:f76708a93fb3 52 #define ETHARP_HWADDR_LEN 6
mbedalvaro 0:f76708a93fb3 53 #endif
mbedalvaro 0:f76708a93fb3 54
mbedalvaro 0:f76708a93fb3 55 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 56 # include "arch/bpstruct.h"
mbedalvaro 0:f76708a93fb3 57 #endif
mbedalvaro 0:f76708a93fb3 58 PACK_STRUCT_BEGIN
mbedalvaro 0:f76708a93fb3 59 struct eth_addr {
mbedalvaro 0:f76708a93fb3 60 PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
mbedalvaro 0:f76708a93fb3 61 } PACK_STRUCT_STRUCT;
mbedalvaro 0:f76708a93fb3 62 PACK_STRUCT_END
mbedalvaro 0:f76708a93fb3 63 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 64 # include "arch/epstruct.h"
mbedalvaro 0:f76708a93fb3 65 #endif
mbedalvaro 0:f76708a93fb3 66
mbedalvaro 0:f76708a93fb3 67 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 68 # include "arch/bpstruct.h"
mbedalvaro 0:f76708a93fb3 69 #endif
mbedalvaro 0:f76708a93fb3 70 PACK_STRUCT_BEGIN
mbedalvaro 0:f76708a93fb3 71 /* Ethernet header */
mbedalvaro 0:f76708a93fb3 72 struct eth_hdr {
mbedalvaro 0:f76708a93fb3 73 #if ETH_PAD_SIZE
mbedalvaro 0:f76708a93fb3 74 PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
mbedalvaro 0:f76708a93fb3 75 #endif
mbedalvaro 0:f76708a93fb3 76 PACK_STRUCT_FIELD(struct eth_addr dest);
mbedalvaro 0:f76708a93fb3 77 PACK_STRUCT_FIELD(struct eth_addr src);
mbedalvaro 0:f76708a93fb3 78 PACK_STRUCT_FIELD(u16_t type);
mbedalvaro 0:f76708a93fb3 79 } PACK_STRUCT_STRUCT;
mbedalvaro 0:f76708a93fb3 80 PACK_STRUCT_END
mbedalvaro 0:f76708a93fb3 81 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 82 # include "arch/epstruct.h"
mbedalvaro 0:f76708a93fb3 83 #endif
mbedalvaro 0:f76708a93fb3 84
mbedalvaro 0:f76708a93fb3 85 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
mbedalvaro 0:f76708a93fb3 86
mbedalvaro 0:f76708a93fb3 87 #if ETHARP_SUPPORT_VLAN
mbedalvaro 0:f76708a93fb3 88
mbedalvaro 0:f76708a93fb3 89 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 90 # include "arch/bpstruct.h"
mbedalvaro 0:f76708a93fb3 91 #endif
mbedalvaro 0:f76708a93fb3 92 PACK_STRUCT_BEGIN
mbedalvaro 0:f76708a93fb3 93 /* VLAN header inserted between ethernet header and payload
mbedalvaro 0:f76708a93fb3 94 * if 'type' in ethernet header is ETHTYPE_VLAN.
mbedalvaro 0:f76708a93fb3 95 * See IEEE802.Q */
mbedalvaro 0:f76708a93fb3 96 struct eth_vlan_hdr {
mbedalvaro 0:f76708a93fb3 97 PACK_STRUCT_FIELD(u16_t tpid);
mbedalvaro 0:f76708a93fb3 98 PACK_STRUCT_FIELD(u16_t prio_vid);
mbedalvaro 0:f76708a93fb3 99 } PACK_STRUCT_STRUCT;
mbedalvaro 0:f76708a93fb3 100 PACK_STRUCT_END
mbedalvaro 0:f76708a93fb3 101 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 102 # include "arch/epstruct.h"
mbedalvaro 0:f76708a93fb3 103 #endif
mbedalvaro 0:f76708a93fb3 104
mbedalvaro 0:f76708a93fb3 105 #define SIZEOF_VLAN_HDR 4
mbedalvaro 0:f76708a93fb3 106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
mbedalvaro 0:f76708a93fb3 107
mbedalvaro 0:f76708a93fb3 108 #endif /* ETHARP_SUPPORT_VLAN */
mbedalvaro 0:f76708a93fb3 109
mbedalvaro 0:f76708a93fb3 110 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 111 # include "arch/bpstruct.h"
mbedalvaro 0:f76708a93fb3 112 #endif
mbedalvaro 0:f76708a93fb3 113 PACK_STRUCT_BEGIN
mbedalvaro 0:f76708a93fb3 114 /* the ARP message, see RFC 826 ("Packet format") */
mbedalvaro 0:f76708a93fb3 115 struct etharp_hdr {
mbedalvaro 0:f76708a93fb3 116 PACK_STRUCT_FIELD(u16_t hwtype);
mbedalvaro 0:f76708a93fb3 117 PACK_STRUCT_FIELD(u16_t proto);
mbedalvaro 0:f76708a93fb3 118 PACK_STRUCT_FIELD(u8_t hwlen);
mbedalvaro 0:f76708a93fb3 119 PACK_STRUCT_FIELD(u8_t protolen);
mbedalvaro 0:f76708a93fb3 120 PACK_STRUCT_FIELD(u16_t opcode);
mbedalvaro 0:f76708a93fb3 121 PACK_STRUCT_FIELD(struct eth_addr shwaddr);
mbedalvaro 0:f76708a93fb3 122 PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
mbedalvaro 0:f76708a93fb3 123 PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
mbedalvaro 0:f76708a93fb3 124 PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
mbedalvaro 0:f76708a93fb3 125 } PACK_STRUCT_STRUCT;
mbedalvaro 0:f76708a93fb3 126 PACK_STRUCT_END
mbedalvaro 0:f76708a93fb3 127 #ifdef PACK_STRUCT_USE_INCLUDES
mbedalvaro 0:f76708a93fb3 128 # include "arch/epstruct.h"
mbedalvaro 0:f76708a93fb3 129 #endif
mbedalvaro 0:f76708a93fb3 130
mbedalvaro 0:f76708a93fb3 131 #define SIZEOF_ETHARP_HDR 28
mbedalvaro 0:f76708a93fb3 132 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
mbedalvaro 0:f76708a93fb3 133
mbedalvaro 0:f76708a93fb3 134 /* 5 seconds period */
mbedalvaro 0:f76708a93fb3 135 #define ARP_TMR_INTERVAL 5000
mbedalvaro 0:f76708a93fb3 136
mbedalvaro 0:f76708a93fb3 137 #define ETHTYPE_ARP 0x0806
mbedalvaro 0:f76708a93fb3 138 #define ETHTYPE_IP 0x0800
mbedalvaro 0:f76708a93fb3 139 #define ETHTYPE_VLAN 0x8100
mbedalvaro 0:f76708a93fb3 140 #define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
mbedalvaro 0:f76708a93fb3 141 #define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
mbedalvaro 0:f76708a93fb3 142
mbedalvaro 0:f76708a93fb3 143 /* MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
mbedalvaro 0:f76708a93fb3 144 * or known to be 32-bit aligned within the protocol header. */
mbedalvaro 0:f76708a93fb3 145 #ifndef ETHADDR32_COPY
mbedalvaro 0:f76708a93fb3 146 #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
mbedalvaro 0:f76708a93fb3 147 #endif
mbedalvaro 0:f76708a93fb3 148
mbedalvaro 0:f76708a93fb3 149 /* MEMCPY-like macro to copy to/from struct eth_addr's that are no local
mbedalvaro 0:f76708a93fb3 150 * variables and known to be 16-bit aligned within the protocol header. */
mbedalvaro 0:f76708a93fb3 151 #ifndef ETHADDR16_COPY
mbedalvaro 0:f76708a93fb3 152 #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
mbedalvaro 0:f76708a93fb3 153 #endif
mbedalvaro 0:f76708a93fb3 154
mbedalvaro 0:f76708a93fb3 155 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
mbedalvaro 0:f76708a93fb3 156
mbedalvaro 0:f76708a93fb3 157 /* ARP message types (opcodes) */
mbedalvaro 0:f76708a93fb3 158 #define ARP_REQUEST 1
mbedalvaro 0:f76708a93fb3 159 #define ARP_REPLY 2
mbedalvaro 0:f76708a93fb3 160
mbedalvaro 0:f76708a93fb3 161 /* Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
mbedalvaro 0:f76708a93fb3 162 * to a filter function that returns the correct netif when using multiple
mbedalvaro 0:f76708a93fb3 163 * netifs on one hardware interface where the netif's low-level receive
mbedalvaro 0:f76708a93fb3 164 * routine cannot decide for the correct netif (e.g. when mapping multiple
mbedalvaro 0:f76708a93fb3 165 * IP addresses to one hardware interface).
mbedalvaro 0:f76708a93fb3 166 */
mbedalvaro 0:f76708a93fb3 167 #ifndef LWIP_ARP_FILTER_NETIF
mbedalvaro 0:f76708a93fb3 168 #define LWIP_ARP_FILTER_NETIF 0
mbedalvaro 0:f76708a93fb3 169 #endif
mbedalvaro 0:f76708a93fb3 170
mbedalvaro 0:f76708a93fb3 171 #if ARP_QUEUEING
mbedalvaro 0:f76708a93fb3 172 /* struct for queueing outgoing packets for unknown address
mbedalvaro 0:f76708a93fb3 173 * defined here to be accessed by memp.h
mbedalvaro 0:f76708a93fb3 174 */
mbedalvaro 0:f76708a93fb3 175 struct etharp_q_entry {
mbedalvaro 0:f76708a93fb3 176 struct etharp_q_entry *next;
mbedalvaro 0:f76708a93fb3 177 struct pbuf *p;
mbedalvaro 0:f76708a93fb3 178 };
mbedalvaro 0:f76708a93fb3 179 #endif /* ARP_QUEUEING */
mbedalvaro 0:f76708a93fb3 180
mbedalvaro 0:f76708a93fb3 181 #define etharp_init() /* Compatibility define, not init needed. */
mbedalvaro 0:f76708a93fb3 182 void etharp_tmr(void);
mbedalvaro 0:f76708a93fb3 183 s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr,
mbedalvaro 0:f76708a93fb3 184 struct eth_addr **eth_ret, ip_addr_t **ip_ret);
mbedalvaro 0:f76708a93fb3 185 err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
mbedalvaro 0:f76708a93fb3 186 err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q);
mbedalvaro 0:f76708a93fb3 187 err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr);
mbedalvaro 0:f76708a93fb3 188 /* For Ethernet network interfaces, we might want to send "gratuitous ARP";
mbedalvaro 0:f76708a93fb3 189 * this is an ARP packet sent by a node in order to spontaneously cause other
mbedalvaro 0:f76708a93fb3 190 * nodes to update an entry in their ARP cache.
mbedalvaro 0:f76708a93fb3 191 * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
mbedalvaro 0:f76708a93fb3 192 #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
mbedalvaro 0:f76708a93fb3 193
mbedalvaro 0:f76708a93fb3 194 #if ETHARP_SUPPORT_STATIC_ENTRIES
mbedalvaro 0:f76708a93fb3 195 err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr);
mbedalvaro 0:f76708a93fb3 196 err_t etharp_remove_static_entry(ip_addr_t *ipaddr);
mbedalvaro 0:f76708a93fb3 197 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
mbedalvaro 0:f76708a93fb3 198
mbedalvaro 0:f76708a93fb3 199 #if LWIP_AUTOIP
mbedalvaro 0:f76708a93fb3 200 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
mbedalvaro 0:f76708a93fb3 201 const struct eth_addr *ethdst_addr,
mbedalvaro 0:f76708a93fb3 202 const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
mbedalvaro 0:f76708a93fb3 203 const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
mbedalvaro 0:f76708a93fb3 204 const u16_t opcode);
mbedalvaro 0:f76708a93fb3 205 #endif /* LWIP_AUTOIP */
mbedalvaro 0:f76708a93fb3 206
mbedalvaro 0:f76708a93fb3 207 #endif /* LWIP_ARP */
mbedalvaro 0:f76708a93fb3 208
mbedalvaro 0:f76708a93fb3 209 err_t ethernet_input(struct pbuf *p, struct netif *netif);
mbedalvaro 0:f76708a93fb3 210
mbedalvaro 0:f76708a93fb3 211 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
mbedalvaro 0:f76708a93fb3 212
mbedalvaro 0:f76708a93fb3 213 extern const struct eth_addr ethbroadcast, ethzero;
mbedalvaro 0:f76708a93fb3 214
mbedalvaro 0:f76708a93fb3 215 #ifdef __cplusplus
mbedalvaro 0:f76708a93fb3 216 }
mbedalvaro 0:f76708a93fb3 217 #endif
mbedalvaro 0:f76708a93fb3 218
mbedalvaro 0:f76708a93fb3 219 #endif /* LWIP_ARP || LWIP_ETHERNET */
mbedalvaro 0:f76708a93fb3 220
mbedalvaro 0:f76708a93fb3 221 #endif /* __NETIF_ARP_H__ */