Documentation

Documentation

Includes

uri.h

#include "uri.h"
#include "uri.h"

lwip/pbuf.h

#include <lwip/pbuf.h>
#include 

stdint.h

#include <stdint.h>
#include 

Macros

Marco COAP_PDU_H_

#define COAP_PDU_H_


      

Marco COAP_DEFAULT_PORT

#define COAP_DEFAULT_PORT     5683 /* CoAP default UDP/TCP port */


      

Marco COAPS_DEFAULT_PORT

#define COAPS_DEFAULT_PORT    5684 /* CoAP default UDP/TCP port for secure transmission */


      

Marco COAP_DEFAULT_MAX_AGE

#define COAP_DEFAULT_MAX_AGE    60 /* default maximum object lifetime in seconds */


      

Marco COAP_DEFAULT_MTU

#define COAP_DEFAULT_MTU      1152


      

Marco COAP_MESSAGE_SIZE_OFFSET_TCP8

#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
/* TCP Message format constants, do not modify */

Marco COAP_MESSAGE_SIZE_OFFSET_TCP16

#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */


      

Marco COAP_MESSAGE_SIZE_OFFSET_TCP32

#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */


      

Marco COAP_MAX_MESSAGE_SIZE_TCP0

#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
/* Derived message size limits */

Marco COAP_MAX_MESSAGE_SIZE_TCP8

#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */


      

Marco COAP_MAX_MESSAGE_SIZE_TCP16

#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */


      

Marco COAP_MAX_MESSAGE_SIZE_TCP32

#define COAP_MAX_MESSAGE_SIZE_TCP32 (COAP_MESSAGE_SIZE_OFFSET_TCP32+4294967295)


      

Marco COAP_DEFAULT_MAX_PDU_RX_SIZE

#define COAP_DEFAULT_MAX_PDU_RX_SIZE (COAP_MAX_MESSAGE_SIZE_TCP16+4)


      

Marco COAP_DEFAULT_MAX_PDU_RX_SIZE

#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8*1024*1024+256)
/* 8 MiB max-message-size plus some space for options */

Marco COAP_DEBUG_BUF_SIZE

#define COAP_DEBUG_BUF_SIZE 128


      

Marco COAP_DEBUG_BUF_SIZE

#define COAP_DEBUG_BUF_SIZE (8 + 1024 * 2)
/* 1024 derived from RFC7252 4.6.  Message Size max payload */

Marco COAP_DEFAULT_VERSION

#define COAP_DEFAULT_VERSION     1 /* version of CoAP supported */


      

Marco COAP_DEFAULT_SCHEME

#define COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */


      

Marco COAP_DEFAULT_URI_WELLKNOWN

#define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
/** well-known resources URI */

Marco COAP_MESSAGE_CON

#define COAP_MESSAGE_CON      0 /* confirmable message (requires ACK/RST) */


      

Marco COAP_MESSAGE_NON

#define COAP_MESSAGE_NON      1 /* non-confirmable message (one-shot message) */


      

Marco COAP_MESSAGE_ACK

#define COAP_MESSAGE_ACK      2 /* used to acknowledge confirmable messages */


      

Marco COAP_MESSAGE_RST

#define COAP_MESSAGE_RST      3 /* indicates error in received messages */


      

Marco COAP_REQUEST_GET

#define COAP_REQUEST_GET      1


      

Marco COAP_REQUEST_POST

#define COAP_REQUEST_POST     2


      

Marco COAP_REQUEST_PUT

#define COAP_REQUEST_PUT      3


      

Marco COAP_REQUEST_DELETE

#define COAP_REQUEST_DELETE   4


      

Marco COAP_REQUEST_FETCH

#define COAP_REQUEST_FETCH    5 /* RFC 8132 */


      

Marco COAP_REQUEST_PATCH

#define COAP_REQUEST_PATCH    6 /* RFC 8132 */


      

Marco COAP_REQUEST_IPATCH

#define COAP_REQUEST_IPATCH   7 /* RFC 8132 */


      

Marco COAP_OPTION_IF_MATCH

#define COAP_OPTION_IF_MATCH       1 /* C, opaque, 0-8 B, (none) */


      

Marco COAP_OPTION_URI_HOST

#define COAP_OPTION_URI_HOST       3 /* C, String, 1-255 B, destination address */


      

Marco COAP_OPTION_ETAG

#define COAP_OPTION_ETAG           4 /* E, opaque, 1-8 B, (none) */


      

Marco COAP_OPTION_IF_NONE_MATCH

#define COAP_OPTION_IF_NONE_MATCH  5 /* empty, 0 B, (none) */


      

Marco COAP_OPTION_URI_PORT

#define COAP_OPTION_URI_PORT       7 /* C, uint, 0-2 B, destination port */


      

Marco COAP_OPTION_LOCATION_PATH

#define COAP_OPTION_LOCATION_PATH  8 /* E, String, 0-255 B, - */


      

Marco COAP_OPTION_URI_PATH

#define COAP_OPTION_URI_PATH      11 /* C, String, 0-255 B, (none) */


      

Marco COAP_OPTION_CONTENT_FORMAT

#define COAP_OPTION_CONTENT_FORMAT 12 /* E, uint, 0-2 B, (none) */


      

Marco COAP_OPTION_CONTENT_TYPE

#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT


      

Marco COAP_OPTION_MAXAGE

#define COAP_OPTION_MAXAGE        14 /* E, uint, 0--4 B, 60 Seconds */


      

Marco COAP_OPTION_URI_QUERY

#define COAP_OPTION_URI_QUERY     15 /* C, String, 1-255 B, (none) */


      

Marco COAP_OPTION_ACCEPT

#define COAP_OPTION_ACCEPT        17 /* C, uint,   0-2 B, (none) */


      

Marco COAP_OPTION_LOCATION_QUERY

#define COAP_OPTION_LOCATION_QUERY 20 /* E, String,   0-255 B, (none) */


      

Marco COAP_OPTION_SIZE2

#define COAP_OPTION_SIZE2         28 /* E, uint, 0-4 B, (none) */


      

Marco COAP_OPTION_PROXY_URI

#define COAP_OPTION_PROXY_URI     35 /* C, String, 1-1034 B, (none) */


      

Marco COAP_OPTION_PROXY_SCHEME

#define COAP_OPTION_PROXY_SCHEME  39 /* C, String, 1-255 B, (none) */


      

Marco COAP_OPTION_SIZE1

#define COAP_OPTION_SIZE1         60 /* E, uint, 0-4 B, (none) */


      

Marco COAP_OPTION_OBSERVE

#define COAP_OPTION_OBSERVE        6 /* E, empty/uint, 0 B/0-3 B, (none) */


      

Marco COAP_OPTION_SUBSCRIPTION

#define COAP_OPTION_SUBSCRIPTION COAP_OPTION_OBSERVE


      

Marco COAP_OPTION_BLOCK2

#define COAP_OPTION_BLOCK2        23 /* C, uint, 0--3 B, (none) */


      

Marco COAP_OPTION_BLOCK1

#define COAP_OPTION_BLOCK1        27 /* C, uint, 0--3 B, (none) */


      

Marco COAP_OPTION_NORESPONSE

#define COAP_OPTION_NORESPONSE   258 /* N, uint, 0--1 B, 0 */


      

Marco COAP_MAX_OPT

#define COAP_MAX_OPT           65535 /**< the highest option number we know */


      

Marco COAP_RESPONSE_CODE(N)

#define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
/* As of draft-ietf-core-coap-04, response codes are encoded to base
 * 32, i.e.  the three upper bits determine the response class while
 * the remaining five fine-grained information specific to that class.
 */

Marco COAP_RESPONSE_CLASS(C)

#define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 255)
/* Determines the class of response code C */

Marco COAP_ERROR_PHRASE_LENGTH

#define COAP_ERROR_PHRASE_LENGTH  32 /**< maximum length of error phrase */


      

Marco coap_response_phrase(x)

#define coap_response_phrase(x) ((char *)NULL)


      

Marco COAP_ERROR_PHRASE_LENGTH

#define COAP_ERROR_PHRASE_LENGTH   0 /**< maximum length of error phrase */


      

Marco COAP_RESPONSE_100

#define COAP_RESPONSE_100     40 /* 100 Continue */


      

Marco COAP_RESPONSE_200

#define COAP_RESPONSE_200     COAP_RESPONSE_CODE(200) /* 2.00 OK */


      

Marco COAP_RESPONSE_201

#define COAP_RESPONSE_201     COAP_RESPONSE_CODE(201) /* 2.01 Created */


      

Marco COAP_RESPONSE_304

#define COAP_RESPONSE_304     COAP_RESPONSE_CODE(203) /* 2.03 Valid */


      

Marco COAP_RESPONSE_400

#define COAP_RESPONSE_400     COAP_RESPONSE_CODE(400) /* 4.00 Bad Request */


      

Marco COAP_RESPONSE_404

#define COAP_RESPONSE_404     COAP_RESPONSE_CODE(404) /* 4.04 Not Found */


      

Marco COAP_RESPONSE_405

#define COAP_RESPONSE_405     COAP_RESPONSE_CODE(405) /* 4.05 Method Not Allowed */


      

Marco COAP_RESPONSE_415

#define COAP_RESPONSE_415     COAP_RESPONSE_CODE(415) /* 4.15 Unsupported Media Type */


      

Marco COAP_RESPONSE_500

#define COAP_RESPONSE_500     COAP_RESPONSE_CODE(500) /* 5.00 Internal Server Error */


      

Marco COAP_RESPONSE_501

#define COAP_RESPONSE_501     COAP_RESPONSE_CODE(501) /* 5.01 Not Implemented */


      

Marco COAP_RESPONSE_503

#define COAP_RESPONSE_503     COAP_RESPONSE_CODE(503) /* 5.03 Service Unavailable */


      

Marco COAP_RESPONSE_504

#define COAP_RESPONSE_504     COAP_RESPONSE_CODE(504) /* 5.04 Gateway Timeout */


      

Marco COAP_RESPONSE_X_242

#define COAP_RESPONSE_X_242   COAP_RESPONSE_CODE(402) /* Critical Option not supported */


      

Marco COAP_SIGNALING_CODE(N)

#define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)


      

Marco COAP_SIGNALING_CSM

#define COAP_SIGNALING_CSM    COAP_SIGNALING_CODE(701)


      

Marco COAP_SIGNALING_PING

#define COAP_SIGNALING_PING   COAP_SIGNALING_CODE(702)


      

Marco COAP_SIGNALING_PONG

#define COAP_SIGNALING_PONG   COAP_SIGNALING_CODE(703)


      

Marco COAP_SIGNALING_RELEASE

#define COAP_SIGNALING_RELEASE COAP_SIGNALING_CODE(704)


      

Marco COAP_SIGNALING_ABORT

#define COAP_SIGNALING_ABORT  COAP_SIGNALING_CODE(705)


      

Marco COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE

#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
/* Applies to COAP_SIGNALING_CSM */

Marco COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER

#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4


      

Marco COAP_SIGNALING_OPTION_CUSTODY

#define COAP_SIGNALING_OPTION_CUSTODY 2
/* Applies to COAP_SIGNALING_PING / COAP_SIGNALING_PONG */

Marco COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS

#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
/* Applies to COAP_SIGNALING_RELEASE */

Marco COAP_SIGNALING_OPTION_HOLD_OFF

#define COAP_SIGNALING_OPTION_HOLD_OFF 4


      

Marco COAP_SIGNALING_OPTION_BAD_CSM_OPTION

#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
/* Applies to COAP_SIGNALING_ABORT */

Marco COAP_MEDIATYPE_TEXT_PLAIN

#define COAP_MEDIATYPE_TEXT_PLAIN                0 /* text/plain (UTF-8) */


      
      
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT  40 /* application/link-format */


      

Marco COAP_MEDIATYPE_APPLICATION_XML

#define COAP_MEDIATYPE_APPLICATION_XML          41 /* application/xml */


      

Marco COAP_MEDIATYPE_APPLICATION_OCTET_STREAM

#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42 /* application/octet-stream */


      

Marco COAP_MEDIATYPE_APPLICATION_RDF_XML

#define COAP_MEDIATYPE_APPLICATION_RDF_XML      43 /* application/rdf+xml */


      

Marco COAP_MEDIATYPE_APPLICATION_EXI

#define COAP_MEDIATYPE_APPLICATION_EXI          47 /* application/exi  */


      

Marco COAP_MEDIATYPE_APPLICATION_JSON

#define COAP_MEDIATYPE_APPLICATION_JSON         50 /* application/json  */


      

Marco COAP_MEDIATYPE_APPLICATION_CBOR

#define COAP_MEDIATYPE_APPLICATION_CBOR         60 /* application/cbor  */


      

Marco COAP_MEDIATYPE_APPLICATION_COSE_SIGN

#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN    98 /* application/cose; cose-type="cose-sign"     */
/* Content formats from RFC 8152 */

Marco COAP_MEDIATYPE_APPLICATION_COSE_SIGN1

#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1   18 /* application/cose; cose-type="cose-sign1"    */


      

Marco COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT

#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96 /* application/cose; cose-type="cose-encrypt"  */


      

Marco COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0

#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16 /* application/cose; cose-type="cose-encrypt0" */


      

Marco COAP_MEDIATYPE_APPLICATION_COSE_MAC

#define COAP_MEDIATYPE_APPLICATION_COSE_MAC     97 /* application/cose; cose-type="cose-mac"      */


      

Marco COAP_MEDIATYPE_APPLICATION_COSE_MAC0

#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0    17 /* application/cose; cose-type="cose-mac0"     */


      

Marco COAP_MEDIATYPE_APPLICATION_COSE_KEY

#define COAP_MEDIATYPE_APPLICATION_COSE_KEY    101 /* application/cose-key  */


      

Marco COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET

#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102 /* application/cose-key-set  */


      

Marco COAP_MEDIATYPE_APPLICATION_SENML_JSON

#define COAP_MEDIATYPE_APPLICATION_SENML_JSON  110 /* application/senml+json  */
/* Content formats from RFC 8428 */

Marco COAP_MEDIATYPE_APPLICATION_SENSML_JSON

#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111 /* application/sensml+json */


      

Marco COAP_MEDIATYPE_APPLICATION_SENML_CBOR

#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR  112 /* application/senml+cbor  */


      

Marco COAP_MEDIATYPE_APPLICATION_SENSML_CBOR

#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113 /* application/sensml+cbor */


      

Marco COAP_MEDIATYPE_APPLICATION_SENML_EXI

#define COAP_MEDIATYPE_APPLICATION_SENML_EXI   114 /* application/senml-exi   */


      

Marco COAP_MEDIATYPE_APPLICATION_SENSML_EXI

#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI  115 /* application/sensml-exi  */


      

Marco COAP_MEDIATYPE_APPLICATION_SENML_XML

#define COAP_MEDIATYPE_APPLICATION_SENML_XML   310 /* application/senml+xml   */


      

Marco COAP_MEDIATYPE_APPLICATION_SENSML_XML

#define COAP_MEDIATYPE_APPLICATION_SENSML_XML  311 /* application/sensml+xml  */


      

Marco COAP_MEDIATYPE_ANY

#define COAP_MEDIATYPE_ANY                        255 /* any media type */
/* Note that identifiers for registered media types are in the range 0-65535. We
 * use an unallocated type here and hope for the best. */

Marco COAP_INVALID_TID

#define COAP_INVALID_TID -1
/** Indicates an invalid transaction id. */

Marco COAP_DROPPED_RESPONSE

#define COAP_DROPPED_RESPONSE -2
/**
 * Indicates that a response is suppressed. This will occur for error
 * responses if the request was received via IP multicast.
 */

Marco COAP_PDU_DELAYED

#define COAP_PDU_DELAYED -3


      

Marco COAP_OPT_LONG

#define COAP_OPT_LONG 15     /* OC == 0b1111 indicates that the option list
                                 * in a CoAP message is limited by 0b11110000
                                 * marker */


      

Marco COAP_OPT_END

#define COAP_OPT_END 240      /* end marker */


      

Marco COAP_PAYLOAD_START

#define COAP_PAYLOAD_START 255 /* payload marker */


      

Marco COAP_OPTION_KEY(option)

#define COAP_OPTION_KEY(option) (option).key


      

Marco COAP_OPTION_LENGTH(option)

#define COAP_OPTION_LENGTH(option) (option).length


      

Marco COAP_OPTION_DATA(option)

#define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))


      

Marco COAP_PDU_IS_EMPTY(pdu)

#define COAP_PDU_IS_EMPTY(pdu)    ((pdu)->code == 0)


      

Marco COAP_PDU_IS_REQUEST(pdu)

#define COAP_PDU_IS_REQUEST(pdu)  (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32)


      

Marco COAP_PDU_IS_RESPONSE(pdu)

#define COAP_PDU_IS_RESPONSE(pdu) ((pdu)->code >= 64 && (pdu)->code < 224)


      

Marco COAP_PDU_IS_SIGNALING(pdu)

#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)


      

Marco COAP_PDU_MAX_UDP_HEADER_SIZE

#define COAP_PDU_MAX_UDP_HEADER_SIZE 4


      

Marco COAP_PDU_MAX_TCP_HEADER_SIZE

#define COAP_PDU_MAX_TCP_HEADER_SIZE 6


      

Marco COAP_PROTO_NONE

#define COAP_PROTO_NONE        0
/**
* coap_proto_t values
*/

Marco COAP_PROTO_UDP

#define COAP_PROTO_UDP         1


      

Marco COAP_PROTO_DTLS

#define COAP_PROTO_DTLS        2


      

Marco COAP_PROTO_TCP

#define COAP_PROTO_TCP         3


      

Marco COAP_PROTO_TLS

#define COAP_PROTO_TLS         4

      

Functions

Func coap_pdu_resize

int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size);
/**
 * Dynamically grows the size of @p pdu to @p new_size. The new size
 * must not exceed the PDU's configure maximum size. On success, this
 * function returns 1, otherwise 0.
 *
 * @param pdu      The PDU to resize.
 * @param new_size The new size in bytes.
 * @return         1 if the operation succeeded, 0 otherwise.
 */

Func coap_pdu_clear

void coap_pdu_clear(coap_pdu_t *pdu, size_t size);
/**
 * Clears any contents from @p pdu and resets @c used_size,
 * and @c data pointers. @c max_size is set to @p size, any
 * other field is set to @c 0. Note that @p pdu must be a valid
 * pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
 */

Func coap_delete_pdu

void coap_delete_pdu(coap_pdu_t *);


      

Func coap_pdu_parse_header_size

size_t coap_pdu_parse_header_size(coap_proto_t proto,
                                const uint8_t *data);
/**
* Interprets @p data to determine the number of bytes in the header.
* This function returns @c 0 on error or a number greater than zero on success.
*
* @param proto  Session's protocol
* @param data   The first byte of raw data to parse as CoAP PDU.
*
* @return       A value greater than zero on success or @c 0 on error.
*/

Func coap_pdu_parse_size

size_t coap_pdu_parse_size(coap_proto_t proto,
                          const uint8_t *data,
                          size_t length);
/**
 * Parses @p data to extract the message size.
 * @p length must be at least coap_pdu_parse_header_size(proto, data).
 * This function returns @c 0 on error or a number greater than zero on success.
 *
 * @param proto  Session's protocol
 * @param data   The raw data to parse as CoAP PDU.
 * @param length The actual size of @p data.
 *
 * @return       A value greater than zero on success or @c 0 on error.
 */

Func coap_pdu_parse_header

int coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto);


      

Func coap_pdu_parse_opt

int coap_pdu_parse_opt(coap_pdu_t *pdu);
/**
 * Verify consistency in the given CoAP PDU structure and locate the data.
 * This function returns @c 0 on error or a number greater than zero on
 * success.
 * This function only parses the token and options, up to the payload start
 * marker.
 *
 * @param pdu     The PDU structure to.
 *
 * @return       1 on success or @c 0 on error.
 */

Func coap_pdu_parse

int coap_pdu_parse(coap_proto_t proto,
                  const uint8_t *data,
                  size_t length,
                  coap_pdu_t *pdu);
/**
* Parses @p data into the CoAP PDU structure given in @p result.
* The target pdu must be large enough to
* This function returns @c 0 on error or a number greater than zero on success.
*
* @param proto   Session's protocol
* @param data    The raw data to parse as CoAP PDU.
* @param length  The actual size of @p data.
* @param pdu     The PDU structure to fill. Note that the structure must
*                provide space to hold at least the token and options
*                part of the message.
*
* @return       1 on success or @c 0 on error.
*/

Func coap_add_token

int coap_add_token(coap_pdu_t *pdu,
                 size_t len,
                 const uint8_t *data);
/**
 * Adds token of length @p len to @p pdu.
 * Adding the token destroys any following contents of the pdu. Hence options
 * and data must be added after coap_add_token() has been called. In @p pdu,
 * length is set to @p len + @c 4, and max_delta is set to @c 0. This function
 * returns @c 0 on error or a value greater than zero on success.
 *
 * @param pdu  The PDU where the token is to be added.
 * @param len  The length of the new token.
 * @param data The token to add.
 *
 * @return     A value greater than zero on success, or @c 0 on error.
 */

Func coap_add_option

size_t coap_add_option(coap_pdu_t *pdu,
                      uint16_t type,
                      size_t len,
                      const uint8_t *data);
/**
 * Adds option of given type to pdu that is passed as first
 * parameter.
 * coap_add_option() destroys the PDU's data, so coap_add_data() must be called
 * after all options have been added. As coap_add_token() destroys the options
 * following the token, the token must be added before coap_add_option() is
 * called. This function returns the number of bytes written or @c 0 on error.
 */

Func coap_add_option_later

uint8_t *coap_add_option_later(coap_pdu_t *pdu,
                              uint16_t type,
                              size_t len);
/**
 * Adds option of given type to pdu that is passed as first parameter, but does
 * not write a value. It works like coap_add_option with respect to calling
 * sequence (i.e. after token and before data). This function returns a memory
 * address to which the option data has to be written before the PDU can be
 * sent, or @c NULL on error.
 */

Func coap_add_data

int coap_add_data(coap_pdu_t *pdu,
                 size_t len,
                 const uint8_t *data);
/**
 * Adds given data to the pdu that is passed as first parameter. Note that the
 * PDU's data is destroyed by coap_add_option(). coap_add_data() must be called
 * only once per PDU, otherwise the result is undefined.
 */

Func coap_add_data_after

uint8_t *coap_add_data_after(coap_pdu_t *pdu, size_t len);
/**
 * Adds given data to the pdu that is passed as first parameter but does not
 * copyt it. Note that the PDU's data is destroyed by coap_add_option().
 * coap_add_data() must be have been called once for this PDU, otherwise the
 * result is undefined.
 * The actual data must be copied at the returned location.
 */

Func coap_get_data

int coap_get_data(const coap_pdu_t *pdu,
                 size_t *len,
                 uint8_t **data);
/**
 * Retrieves the length and data pointer of specified PDU. Returns 0 on error or
 * 1 if *len and *data have correct values. Note that these values are destroyed
 * with the pdu.
 */

Func coap_pdu_encode_header

size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto);

      

Vars

Variable coap_session_t

struct coap_session_t;


      

Variable COAP_DEPRECATED

COAP_DEPRECATED typedef struct {
 uint16_t key;          /* the option key (no delta coding) */
 unsigned int length;
} coap_option;
/**
 * @deprecated Use coap_optlist_t instead.
 *
 * Structures for more convenient handling of options. (To be used with ordered
 * coap_list_t.) The option's data will be added to the end of the coap_option
 * structure (see macro COAP_OPTION_DATA).
 */

Variable coap_pdu_t

coap_pdu_t * coap_pdu_from_pbuf(struct pbuf *pbuf);
/**
 * Creates a CoAP PDU from an lwIP @p pbuf, whose reference is passed on to this
 * function.
 *
 * The pbuf is checked for being contiguous, and for having only one reference.
 * The reference is stored in the PDU and will be freed when the PDU is freed.
 *
 * (For now, these are fatal errors; in future, a new pbuf might be allocated,
 * the data copied and the passed pbuf freed).
 *
 * This behaves like coap_pdu_init(0, 0, 0, pbuf->tot_len), and afterwards
 * copying the contents of the pbuf to the pdu.
 *
 * @return A pointer to the new PDU object or @c NULL on error.
 */

Variable coap_pdu_t

coap_pdu_t *
coap_pdu_init(uint8_t type, uint8_t code, uint16_t tid, size_t size);
/**
 * Creates a new CoAP PDU with at least enough storage space for the given
 * @p size maximum message size. The function returns a pointer to the
 * node coap_pdu_t object on success, or @c NULL on error. The storage allocated
 * for the result must be released with coap_delete_pdu() if coap_send() is not
 * called.
 *
 * @param type The type of the PDU (one of COAP_MESSAGE_CON, COAP_MESSAGE_NON,
 *             COAP_MESSAGE_ACK, COAP_MESSAGE_RST).
 * @param code The message code.
 * @param tid  The transcation id to set or 0 if unknown / not applicable.
 * @param size The maximum allowed number of byte for the message.
 * @return     A pointer to the new PDU object or @c NULL on error.
 */

Variable coap_pdu_t

coap_pdu_t *coap_new_pdu(const struct coap_session_t *session);
/**
 * Creates a new CoAP PDU.
 */

Consts

Const

const char *coap_response_phrase(unsigned char code);
/**
 * Returns a human-readable response phrase for the specified CoAP response @p
 * code. This function returns @c NULL if not found.
 *
 * @param code The response code for which the literal phrase should be
 *             retrieved.
 *
 * @return     A zero-terminated string describing the error, or @c NULL if not
 *             found.
 */

Types

Typedefs

Typedef coap_tid_t

typedef int coap_tid_t;
/**
 * coap_tid_t is used to store CoAP transaction id, i.e. a hash value
 * built from the remote transport address and the message id of a
 * CoAP PDU.  Valid transaction ids are greater or equal zero.
 */

Typedef coap_pdu_t;

typedef struct coap_pdu_t {
 uint8_t type;            /**< message type */
 uint8_t code;            /**< request method (value 1--10) or response code (value 40-255) */
 uint8_t max_hdr_size;    /**< space reserved for protocol-specific header */
 uint8_t hdr_size;        /**< actaul size used for protocol-specific header */
 uint8_t token_length;    /**< length of Token */
 uint16_t tid;            /**< transaction id, if any, in regular host byte order */
 uint16_t max_delta;      /**< highest option number */
 size_t alloc_size;       /**< allocated storage for token, options and payload */
 size_t used_size;        /**< used bytes of storage for token, options and payload */
 size_t max_size;         /**< maximum size for token, options and payload, or zero for variable size pdu */
 uint8_t *token;          /**< first byte of token, if any, or options */
 uint8_t *data;           /**< first byte of payload, if any */
#ifdef WITH_LWIP
 struct pbuf *pbuf;       /**< lwIP PBUF. The package data will always reside
                             *   inside the pbuf's payload, but this pointer
                             *   has to be kept because no exact offset can be
                             *   given. This field must not be accessed from
                             *   outside, because the pbuf's reference count
                             *   is checked to be 1 when the pbuf is assigned
                             *   to the pdu, and the pbuf stays exclusive to
                             *   this pdu. */
#endif
} coap_pdu_t;


      

Typedef coap_proto_t

typedef uint8_t coap_proto_t;