![]() |
0.01.00
|
This module includes functions that control CoAP communication. More...
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. | |
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 otCoapOption * | otCoapHeaderGetFirstOption (otCoapHeader *aHeader) |
This function returns a pointer to the first option. More... | |
const otCoapOption * | otCoapHeaderGetNextOption (otCoapHeader *aHeader) |
This function returns a pointer to the next option. More... | |
otMessage * | otCoapNewMessage (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... | |
This module includes functions that control CoAP communication.
The functions in this module are available when application-coap feature (OPENTHREAD_ENABLE_APPLICATION_COAP
) is enabled.
typedef enum otCoapOptionContentFormat otCoapOptionContentFormat |
CoAP Content Format codes.
The full list is documented at https://tools.ietf.org/html/rfc7252#page-92
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.
[in] | aContext | A pointer to arbitrary context information. |
[in] | aHeader | A pointer to the CoAP header. |
[in] | aMessage | A pointer to the message. |
[in] | aMessageInfo | A pointer to the message info for aMessage . |
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.
[in] | aContext | A pointer to application-specific context. |
[in] | aHeader | A pointer to the received CoAP header. NULL if no response was received. |
[in] | aMessage | A pointer to the message buffer containing the response. NULL if no response was received. |
[in] | aMessageInfo | A pointer to the message info for aMessage . NULL if no response was received. |
[in] | aResult | A result of the CoAP transaction. |
OT_ERROR_NONE | A response was received successfully. |
OT_ERROR_ABORT | A CoAP transaction was reseted by peer. |
OT_ERROR_RESPONSE_TIMEOUT | No response or acknowledgment received during timeout period. |
enum otCoapCode |
CoAP Code values.
CoAP Content Format codes.
The full list is documented at https://tools.ietf.org/html/rfc7252#page-92
enum otCoapOptionType |
CoAP Option Numbers.
enum otCoapType |
otError otCoapAddResource | ( | otInstance * | aInstance, |
otCoapResource * | aResource | ||
) |
This function adds a resource to the CoAP server.
[in] | aInstance | A pointer to an OpenThread instance. |
[in] | aResource | A pointer to the resource. |
OT_ERROR_NONE | Successfully added aResource . |
OT_ERROR_ALREADY | The aResource was already added. |
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.
This must be called before setting otCoapHeaderSetPayloadMarker if a payload is to be included in the message.
The function is a convenience wrapper around otCoapHeaderAppendUintOption, and if the desired format type code isn't listed in otCoapOptionContentFormat, this base function should be used instead.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aContentFormat | One of the content formats listed in otCoapOptionContentFormat above. |
OT_ERROR_NONE | Successfully appended the option. |
OT_ERROR_INVALID_ARGS | The option type is not equal or greater than the last option type. |
OT_ERROR_NO_BUFS | The option length exceeds the buffer size. |
otError otCoapHeaderAppendMaxAgeOption | ( | otCoapHeader * | aHeader, |
uint32_t | aMaxAge | ||
) |
This function appends a Max-Age option.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aMaxAge | The Max-Age value. |
OT_ERROR_NONE | Successfully appended the option. |
OT_ERROR_INVALID_ARGS | The option type is not equal or greater than the last option type. |
OT_ERROR_NO_BUFS | The option length exceeds the buffer size. |
otError otCoapHeaderAppendObserveOption | ( | otCoapHeader * | aHeader, |
uint32_t | aObserve | ||
) |
This function appends an Observe option.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aObserve | Observe field value. |
OT_ERROR_NONE | Successfully appended the option. |
OT_ERROR_INVALID_ARGS | The option type is not equal or greater than the last option type. |
OT_ERROR_NO_BUFS | The option length exceeds the buffer size. |
otError otCoapHeaderAppendOption | ( | otCoapHeader * | aHeader, |
const otCoapOption * | aOption | ||
) |
This function appends a CoAP option in a header.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aOption | A pointer to the CoAP option. |
OT_ERROR_NONE | Successfully appended the option. |
OT_ERROR_INVALID_ARGS | The option type is not equal or greater than the last option type. |
OT_ERROR_NO_BUFS | The option length exceeds the buffer size. |
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.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aNumber | The CoAP Option number. |
[in] | aValue | The CoAP Option unsigned integer value. |
OT_ERROR_NONE | Successfully appended the option. |
OT_ERROR_INVALID_ARGS | The option type is not equal or greater than the last option type. |
OT_ERROR_NO_BUFS | The option length exceeds the buffer size. |
otError otCoapHeaderAppendUriPathOptions | ( | otCoapHeader * | aHeader, |
const char * | aUriPath | ||
) |
This function appends an Uri-Path option.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aUriPath | A pointer to a NULL-terminated string. |
OT_ERROR_NONE | Successfully appended the option. |
OT_ERROR_INVALID_ARGS | The option type is not equal or greater than the last option type. |
OT_ERROR_NO_BUFS | The option length exceeds the buffer size. |
otError otCoapHeaderAppendUriQueryOption | ( | otCoapHeader * | aHeader, |
const char * | aUriQuery | ||
) |
This function appends a single Uri-Query option.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aUriQuery | A pointer to NULL-terminated string, which should contain a single key=value pair. |
OT_ERROR_NONE | Successfully appended the option. |
OT_ERROR_INVALID_ARGS | The option type is not equal or greater than the last option type. |
OT_ERROR_NO_BUFS | The option length exceeds the buffer size. |
void otCoapHeaderGenerateToken | ( | otCoapHeader * | aHeader, |
uint8_t | aTokenLength | ||
) |
This function sets the Token length and randomizes its value.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aTokenLength | The Length of a Token to set. |
otCoapCode otCoapHeaderGetCode | ( | const otCoapHeader * | aHeader | ) |
This function returns the Code value.
[in] | aHeader | A pointer to the CoAP header. |
const otCoapOption* otCoapHeaderGetFirstOption | ( | otCoapHeader * | aHeader | ) |
This function returns a pointer to the first option.
[in] | aHeader | A pointer to the CoAP header. |
uint16_t otCoapHeaderGetMessageId | ( | const otCoapHeader * | aHeader | ) |
This function returns the Message ID value.
[in] | aHeader | A pointer to the CoAP header. |
const otCoapOption* otCoapHeaderGetNextOption | ( | otCoapHeader * | aHeader | ) |
This function returns a pointer to the next option.
[in] | aHeader | A pointer to the CoAP header. |
const uint8_t* otCoapHeaderGetToken | ( | const otCoapHeader * | aHeader | ) |
This function returns a pointer to the Token value.
[in] | aHeader | A pointer to the CoAP header. |
uint8_t otCoapHeaderGetTokenLength | ( | const otCoapHeader * | aHeader | ) |
This function returns the Token length.
[in] | aHeader | A pointer to the CoAP header. |
otCoapType otCoapHeaderGetType | ( | const otCoapHeader * | aHeader | ) |
This function returns the Type value.
[in] | aHeader | A pointer to the CoAP header. |
void otCoapHeaderInit | ( | otCoapHeader * | aHeader, |
otCoapType | aType, | ||
otCoapCode | aCode | ||
) |
This function initializes the CoAP header.
[in,out] | aHeader | A pointer to the CoAP header to initialize. |
[in] | aType | CoAP message type. |
[in] | aCode | CoAP message code. |
void otCoapHeaderSetMessageId | ( | otCoapHeader * | aHeader, |
uint16_t | aMessageId | ||
) |
This function sets the Message ID value.
[in] | aHeader | A pointer to the CoAP header. |
[in] | aMessageId | The Message ID value. |
void otCoapHeaderSetPayloadMarker | ( | otCoapHeader * | aHeader | ) |
This function adds Payload Marker indicating beginning of the payload to the CoAP header.
[in,out] | aHeader | A pointer to the CoAP header. |
OT_ERROR_NONE | Payload Marker successfully added. |
OT_ERROR_NO_BUFS | Header Payload Marker exceeds the buffer size. |
void otCoapHeaderSetToken | ( | otCoapHeader * | aHeader, |
const uint8_t * | aToken, | ||
uint8_t | aTokenLength | ||
) |
This function sets the Token value and length in a header.
[in,out] | aHeader | A pointer to the CoAP header. |
[in] | aToken | A pointer to the Token value. |
[in] | aTokenLength | The Length of aToken . |
otMessage* otCoapNewMessage | ( | otInstance * | aInstance, |
const otCoapHeader * | aHeader | ||
) |
This function creates a new message with a CoAP header.
[in] | aInstance | A pointer to an OpenThread instance. |
[in] | aHeader | A pointer to a CoAP header that is used to create the message. |
void otCoapRemoveResource | ( | otInstance * | aInstance, |
otCoapResource * | aResource | ||
) |
This function removes a resource from the CoAP server.
[in] | aInstance | A pointer to an OpenThread instance. |
[in] | aResource | A pointer to the resource. |
otError otCoapSendRequest | ( | otInstance * | aInstance, |
otMessage * | aMessage, | ||
const otMessageInfo * | aMessageInfo, | ||
otCoapResponseHandler | aHandler, | ||
void * | aContext | ||
) |
This function sends a CoAP request.
If a response for a request is expected, respective function and context information should be provided. If no response is expected, these arguments should be NULL pointers.
[in] | aInstance | A pointer to an OpenThread instance. |
[in] | aMessage | A pointer to the message to send. |
[in] | aMessageInfo | A pointer to the message info associated with aMessage . |
[in] | aHandler | A function pointer that shall be called on response reception or timeout. |
[in] | aContext | A pointer to arbitrary context information. May be NULL if not used. |
OT_ERROR_NONE | Successfully sent CoAP message. |
OT_ERROR_NO_BUFS | Failed to allocate retransmission data. |
otError otCoapSendResponse | ( | otInstance * | aInstance, |
otMessage * | aMessage, | ||
const otMessageInfo * | aMessageInfo | ||
) |
This function sends a CoAP response from the server.
[in] | aInstance | A pointer to an OpenThread instance. |
[in] | aMessage | A pointer to the CoAP response to send. |
[in] | aMessageInfo | A pointer to the message info associated with aMessage . |
OT_ERROR_NONE | Successfully enqueued the CoAP response message. |
OT_ERROR_NO_BUFS | Insufficient buffers available to send the CoAP response. |
void otCoapSetDefaultHandler | ( | otInstance * | aInstance, |
otCoapRequestHandler | aHandler, | ||
void * | aContext | ||
) |
This function sets the default handler for unhandled CoAP requests.
[in] | aInstance | A pointer to an OpenThread instance. |
[in] | aHandler | A function pointer that shall be called when an unhandled request arrives. |
[in] | aContext | A pointer to arbitrary context information. May be NULL if not used. |
otError otCoapStart | ( | otInstance * | aInstance, |
uint16_t | aPort | ||
) |
This function starts the CoAP server.
[in] | aInstance | A pointer to an OpenThread instance. |
[in] | aPort | The local UDP port to bind to. |
OT_ERROR_NONE | Successfully started the CoAP server. |
otError otCoapStop | ( | otInstance * | aInstance | ) |
This function stops the CoAP server.
[in] | aInstance | A pointer to an OpenThread instance. |
OT_ERROR_NONE | Successfully stopped the CoAP server. |