0.01.00
coap.h File Reference

This file defines the top-level functions for the OpenThread CoAP implementation. More...

#include <stdint.h>
#include <openthread/message.h>
#include <openthread/types.h>

Go to the source code of this file.

Classes

struct  otCoapOption
 This structure represents a CoAP option. More...
 
struct  otCoapHeader
 This structure represents a CoAP header. More...
 
struct  otCoapResource
 This structure represents a CoAP resource. More...
 

Macros

#define OT_DEFAULT_COAP_PORT   5683
 Default CoAP port, as specified in RFC 7252.
 
#define OT_COAP_CODE(c, d)   ((((c) & 0x7) << 5) | ((d) & 0x1f))
 Helper macro to define CoAP Code values.
 
#define OT_COAP_HEADER_MAX_LENGTH   128
 Max CoAP header length (bytes)
 

Typedefs

typedef enum otCoapType otCoapType
 CoAP Type values.
 
typedef enum otCoapCode otCoapCode
 CoAP Code values.
 
typedef enum otCoapOptionType otCoapOptionType
 CoAP Option Numbers.
 
typedef struct otCoapOption otCoapOption
 This structure represents a CoAP option.
 
typedef enum otCoapOptionContentFormat otCoapOptionContentFormat
 CoAP Content Format codes. More...
 
typedef struct otCoapHeader otCoapHeader
 This structure represents a CoAP header.
 
typedef void(* otCoapResponseHandler) (void *aContext, otCoapHeader *aHeader, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult)
 This function pointer is called when a CoAP response is received or on the request timeout. More...
 
typedef void(* otCoapRequestHandler) (void *aContext, otCoapHeader *aHeader, otMessage *aMessage, const otMessageInfo *aMessageInfo)
 This function pointer is called when a CoAP request with a given Uri-Path is received. More...
 
typedef struct otCoapResource otCoapResource
 This structure represents a CoAP resource.
 

Enumerations

enum  otCoapType {
  OT_COAP_TYPE_CONFIRMABLE = 0x00,
  OT_COAP_TYPE_NON_CONFIRMABLE = 0x10,
  OT_COAP_TYPE_ACKNOWLEDGMENT = 0x20,
  OT_COAP_TYPE_RESET = 0x30
}
 CoAP Type values. More...
 
enum  otCoapCode {
  OT_COAP_CODE_EMPTY = OT_COAP_CODE(0, 0),
  OT_COAP_CODE_GET = OT_COAP_CODE(0, 1),
  OT_COAP_CODE_POST = OT_COAP_CODE(0, 2),
  OT_COAP_CODE_PUT = OT_COAP_CODE(0, 3),
  OT_COAP_CODE_DELETE = OT_COAP_CODE(0, 4),
  OT_COAP_CODE_RESPONSE_MIN = OT_COAP_CODE(2, 0),
  OT_COAP_CODE_CREATED = OT_COAP_CODE(2, 1),
  OT_COAP_CODE_DELETED = OT_COAP_CODE(2, 2),
  OT_COAP_CODE_VALID = OT_COAP_CODE(2, 3),
  OT_COAP_CODE_CHANGED = OT_COAP_CODE(2, 4),
  OT_COAP_CODE_CONTENT = OT_COAP_CODE(2, 5),
  OT_COAP_CODE_BAD_REQUEST = OT_COAP_CODE(4, 0),
  OT_COAP_CODE_UNAUTHORIZED = OT_COAP_CODE(4, 1),
  OT_COAP_CODE_BAD_OPTION = OT_COAP_CODE(4, 2),
  OT_COAP_CODE_FORBIDDEN = OT_COAP_CODE(4, 3),
  OT_COAP_CODE_NOT_FOUND = OT_COAP_CODE(4, 4),
  OT_COAP_CODE_METHOD_NOT_ALLOWED = OT_COAP_CODE(4, 5),
  OT_COAP_CODE_NOT_ACCEPTABLE = OT_COAP_CODE(4, 6),
  OT_COAP_CODE_PRECONDITION_FAILED = OT_COAP_CODE(4, 12),
  OT_COAP_CODE_REQUEST_TOO_LARGE = OT_COAP_CODE(4, 13),
  OT_COAP_CODE_UNSUPPORTED_FORMAT = OT_COAP_CODE(4, 15),
  OT_COAP_CODE_INTERNAL_ERROR = OT_COAP_CODE(5, 0),
  OT_COAP_CODE_NOT_IMPLEMENTED = OT_COAP_CODE(5, 1),
  OT_COAP_CODE_BAD_GATEWAY = OT_COAP_CODE(5, 2),
  OT_COAP_CODE_SERVICE_UNAVAILABLE = OT_COAP_CODE(5, 3),
  OT_COAP_CODE_GATEWAY_TIMEOUT = OT_COAP_CODE(5, 4),
  OT_COAP_CODE_PROXY_NOT_SUPPORTED = OT_COAP_CODE(5, 5)
}
 CoAP Code values. More...
 
enum  otCoapOptionType {
  OT_COAP_OPTION_IF_MATCH = 1,
  OT_COAP_OPTION_URI_HOST = 3,
  OT_COAP_OPTION_E_TAG = 4,
  OT_COAP_OPTION_IF_NONE_MATCH = 5,
  OT_COAP_OPTION_OBSERVE = 6,
  OT_COAP_OPTION_URI_PORT = 7,
  OT_COAP_OPTION_LOCATION_PATH = 8,
  OT_COAP_OPTION_URI_PATH = 11,
  OT_COAP_OPTION_CONTENT_FORMAT = 12,
  OT_COAP_OPTION_MAX_AGE = 14,
  OT_COAP_OPTION_URI_QUERY = 15,
  OT_COAP_OPTION_ACCEPT = 17,
  OT_COAP_OPTION_LOCATION_QUERY = 20,
  OT_COAP_OPTION_PROXY_URI = 35,
  OT_COAP_OPTION_PROXY_SCHEME = 39,
  OT_COAP_OPTION_SIZE1 = 60
}
 CoAP Option Numbers. More...
 
enum  otCoapOptionContentFormat {
  OT_COAP_OPTION_CONTENT_FORMAT_TEXT_PLAIN = 0,
  OT_COAP_OPTION_CONTENT_FORMAT_LINK_FORMAT = 40,
  OT_COAP_OPTION_CONTENT_FORMAT_XML = 41,
  OT_COAP_OPTION_CONTENT_FORMAT_OCTET_STREAM = 42,
  OT_COAP_OPTION_CONTENT_FORMAT_EXI = 47,
  OT_COAP_OPTION_CONTENT_FORMAT_JSON = 50
}
 CoAP Content Format codes. More...
 

Functions

void otCoapHeaderInit (otCoapHeader *aHeader, otCoapType aType, otCoapCode aCode)
 This function initializes the CoAP header. More...
 
void otCoapHeaderSetToken (otCoapHeader *aHeader, const uint8_t *aToken, uint8_t aTokenLength)
 This function sets the Token value and length in a header. More...
 
void otCoapHeaderGenerateToken (otCoapHeader *aHeader, uint8_t aTokenLength)
 This function sets the Token length and randomizes its value. More...
 
otError otCoapHeaderAppendContentFormatOption (otCoapHeader *aHeader, otCoapOptionContentFormat aContentFormat)
 This function appends the Content Format CoAP option as specified in https://tools.ietf.org/html/rfc7252#page-92. More...
 
otError otCoapHeaderAppendOption (otCoapHeader *aHeader, const otCoapOption *aOption)
 This function appends a CoAP option in a header. More...
 
otError otCoapHeaderAppendUintOption (otCoapHeader *aHeader, uint16_t aNumber, uint32_t aValue)
 This function appends an unsigned integer CoAP option as specified in https://tools.ietf.org/html/rfc7252#section-3.2. More...
 
otError otCoapHeaderAppendObserveOption (otCoapHeader *aHeader, uint32_t aObserve)
 This function appends an Observe option. More...
 
otError otCoapHeaderAppendUriPathOptions (otCoapHeader *aHeader, const char *aUriPath)
 This function appends an Uri-Path option. More...
 
otError otCoapHeaderAppendMaxAgeOption (otCoapHeader *aHeader, uint32_t aMaxAge)
 This function appends a Max-Age option. More...
 
otError otCoapHeaderAppendUriQueryOption (otCoapHeader *aHeader, const char *aUriQuery)
 This function appends a single Uri-Query option. More...
 
void otCoapHeaderSetPayloadMarker (otCoapHeader *aHeader)
 This function adds Payload Marker indicating beginning of the payload to the CoAP header. More...
 
void otCoapHeaderSetMessageId (otCoapHeader *aHeader, uint16_t aMessageId)
 This function sets the Message ID value. More...
 
otCoapType otCoapHeaderGetType (const otCoapHeader *aHeader)
 This function returns the Type value. More...
 
otCoapCode otCoapHeaderGetCode (const otCoapHeader *aHeader)
 This function returns the Code value. More...
 
uint16_t otCoapHeaderGetMessageId (const otCoapHeader *aHeader)
 This function returns the Message ID value. More...
 
uint8_t otCoapHeaderGetTokenLength (const otCoapHeader *aHeader)
 This function returns the Token length. More...
 
const uint8_t * otCoapHeaderGetToken (const otCoapHeader *aHeader)
 This function returns a pointer to the Token value. More...
 
const otCoapOptionotCoapHeaderGetFirstOption (otCoapHeader *aHeader)
 This function returns a pointer to the first option. More...
 
const otCoapOptionotCoapHeaderGetNextOption (otCoapHeader *aHeader)
 This function returns a pointer to the next option. More...
 
otMessageotCoapNewMessage (otInstance *aInstance, const otCoapHeader *aHeader)
 This function creates a new message with a CoAP header. More...
 
otError otCoapSendRequest (otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext)
 This function sends a CoAP request. More...
 
otError otCoapStart (otInstance *aInstance, uint16_t aPort)
 This function starts the CoAP server. More...
 
otError otCoapStop (otInstance *aInstance)
 This function stops the CoAP server. More...
 
otError otCoapAddResource (otInstance *aInstance, otCoapResource *aResource)
 This function adds a resource to the CoAP server. More...
 
void otCoapRemoveResource (otInstance *aInstance, otCoapResource *aResource)
 This function removes a resource from the CoAP server. More...
 
void otCoapSetDefaultHandler (otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext)
 This function sets the default handler for unhandled CoAP requests. More...
 
otError otCoapSendResponse (otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo)
 This function sends a CoAP response from the server. More...
 

Detailed Description

This file defines the top-level functions for the OpenThread CoAP implementation.