/* * Copyright (c) 2011, Institute for Pervasive Computing, ETH Zurich * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Institute nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * This file is part of the Contiki operating system. */ /** * \file * An implementation of the Constrained Application Protocol (draft 03) * \author * Matthias Kovatsch */ #ifndef COAP_03_H_ #define COAP_03_H_ #include /* for size_t */ #include "contiki-net.h" #include "erbium.h" #define COAP_DEFAULT_PORT 61616 #ifndef COAP_SERVER_PORT #define COAP_SERVER_PORT COAP_DEFAULT_PORT #endif #define COAP_DEFAULT_MAX_AGE 60 #define COAP_RESPONSE_TIMEOUT 1 #define COAP_MAX_RETRANSMIT 5 #define COAP_HEADER_LEN 4 /* | oc:0xF0 type:0x0C version:0x03 | code | tid:0x00FF | tid:0xFF00 | */ #define COAP_ETAG_LEN 4 /* The maximum number of bytes for the ETag, which is 4 for coap-03 */ #define COAP_TOKEN_LEN 2 /* The maximum number of bytes for the ETag, which is 4 for coap-03 */ #define COAP_HEADER_VERSION_MASK 0xC0 #define COAP_HEADER_VERSION_POSITION 6 #define COAP_HEADER_TYPE_MASK 0x30 #define COAP_HEADER_TYPE_POSITION 4 #define COAP_HEADER_OPTION_COUNT_MASK 0x0F #define COAP_HEADER_OPTION_COUNT_POSITION 0 #define COAP_HEADER_OPTION_DELTA_MASK 0xF0 #define COAP_HEADER_OPTION_SHORT_LENGTH_MASK 0x0F /* * Conservative size limit, as not all options have to be set at the same time. */ /* Hdr CoT Age Tag Obs Tok Blo strings */ #define COAP_MAX_HEADER_SIZE (4 + 2 + 5 + 5 + 5 + 5 + 4 + 0) #define COAP_MAX_PACKET_SIZE (COAP_MAX_HEADER_SIZE + REST_MAX_CHUNK_SIZE) /* 0/14 48 for IPv6 (28 for IPv4) */ #if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN) #error "UIP_CONF_BUFFER_SIZE too small for REST_MAX_CHUNK_SIZE" #endif /* * Maximum number of failed request attempts before action */ #ifndef COAP_MAX_ATTEMPTS #define COAP_MAX_ATTEMPTS 4 #endif /* COAP_MAX_ATTEMPTS */ #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) #define SET_OPTION(packet, opt) ((packet)->options |= 1<options & 1<