This module includes functions that control CoAP communication.
Classes |
|
struct | otCoapOption |
This structure represents a CoAP option.
|
|
struct | otCoapOptionIterator |
This structure acts as an iterator for CoAP options.
|
|
struct | otCoapResource |
This structure represents a CoAP resource.
|
|
struct | otCoapBlockwiseResource |
This structure represents a CoAP resource with block-wise transfer.
|
|
struct | otCoapTxParameters |
This structure represents the CoAP transmission parameters.
|
Macros |
|
#define | OT_DEFAULT_COAP_PORT 5683 |
Default CoAP port, as specified in RFC 7252.
|
|
#define | OT_COAP_DEFAULT_TOKEN_LENGTH 2 |
Default token length.
|
|
#define | OT_COAP_MAX_TOKEN_LENGTH 8 |
Max token length as specified (RFC 7252).
|
|
#define | OT_COAP_MAX_RETRANSMIT 20 |
Max retransmit supported by OpenThread.
|
|
#define | OT_COAP_MIN_ACK_TIMEOUT 1000 |
Minimal ACK timeout in milliseconds supported by OpenThread.
|
|
#define | OT_COAP_CODE (c, d) ((((c)&0x7) << 5) | ((d)&0x1f)) |
Helper macro to define CoAP Code values.
|
Typedefs |
|
typedef enum otCoapType | otCoapType |
CoAP Type values (2 bit unsigned integer).
|
|
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 struct otCoapOptionIterator | otCoapOptionIterator |
This structure acts as an iterator for CoAP options.
|
|
typedef enum otCoapOptionContentFormat | otCoapOptionContentFormat |
CoAP Content Format codes.
|
|
typedef enum otCoapBlockSzx | otCoapBlockSzx |
CoAP Block Size Exponents.
|
|
typedef void(* | otCoapResponseHandler ) (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult) |
This function pointer is called when a CoAP response is received or on the request timeout.
|
|
typedef void(* | otCoapRequestHandler ) (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) |
This function pointer is called when a CoAP request with a given Uri-Path is received.
|
|
typedef otError (* | otCoapBlockwiseReceiveHook ) (void *aContext, const uint8_t *aBlock, uint32_t aPosition, uint16_t aBlockLength, bool aMore, uint32_t aTotalLength) |
This function pointer is called when a CoAP message with an block-wise transfer option is received.
|
|
typedef otError (* | otCoapBlockwiseTransmitHook ) (void *aContext, uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore) |
This function pointer is called before the next block in a block-wise transfer is sent.
|
|
typedef struct otCoapResource | otCoapResource |
This structure represents a CoAP resource.
|
|
typedef struct otCoapBlockwiseResource | otCoapBlockwiseResource |
This structure represents a CoAP resource with block-wise transfer.
|
|
typedef struct otCoapTxParameters | otCoapTxParameters |
This structure represents the CoAP transmission parameters.
|
Functions |
|
void | otCoapMessageInit ( otMessage *aMessage, otCoapType aType, otCoapCode aCode) |
This function initializes the CoAP header.
|
|
otError | otCoapMessageInitResponse ( otMessage *aResponse, const otMessage *aRequest, otCoapType aType, otCoapCode aCode) |
This function initializes a response message.
|
|
otError | otCoapMessageSetToken ( otMessage *aMessage, const uint8_t *aToken, uint8_t aTokenLength) |
This function sets the Token value and length in a header.
|
|
void | otCoapMessageGenerateToken ( otMessage *aMessage, uint8_t aTokenLength) |
This function sets the Token length and randomizes its value.
|
|
otError | otCoapMessageAppendContentFormatOption ( otMessage *aMessage, otCoapOptionContentFormat aContentFormat) |
This function appends the Content Format CoAP option as specified in
https://tools.ietf.org/html/rfc7252#page-92
.
|
|
otError | otCoapMessageAppendOption ( otMessage *aMessage, uint16_t aNumber, uint16_t aLength, const void *aValue) |
This function appends a CoAP option in a header.
|
|
otError | otCoapMessageAppendUintOption ( otMessage *aMessage, 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
.
|
|
otError | otCoapMessageAppendObserveOption ( otMessage *aMessage, uint32_t aObserve) |
This function appends an Observe option.
|
|
otError | otCoapMessageAppendUriPathOptions ( otMessage *aMessage, const char *aUriPath) |
This function appends a Uri-Path option.
|
|
uint16_t | otCoapBlockSizeFromExponent ( otCoapBlockSzx aSize) |
This function converts a CoAP Block option SZX field to the actual block size.
|
|
otError | otCoapMessageAppendBlock2Option ( otMessage *aMessage, uint32_t aNum, bool aMore, otCoapBlockSzx aSize) |
This function appends a Block2 option.
|
|
otError | otCoapMessageAppendBlock1Option ( otMessage *aMessage, uint32_t aNum, bool aMore, otCoapBlockSzx aSize) |
This function appends a Block1 option.
|
|
otError | otCoapMessageAppendProxyUriOption ( otMessage *aMessage, const char *aUriPath) |
This function appends a Proxy-Uri option.
|
|
otError | otCoapMessageAppendMaxAgeOption ( otMessage *aMessage, uint32_t aMaxAge) |
This function appends a Max-Age option.
|
|
otError | otCoapMessageAppendUriQueryOption ( otMessage *aMessage, const char *aUriQuery) |
This function appends a single Uri-Query option.
|
|
otError | otCoapMessageSetPayloadMarker ( otMessage *aMessage) |
This function adds Payload Marker indicating beginning of the payload to the CoAP header.
|
|
otCoapType | otCoapMessageGetType (const otMessage *aMessage) |
This function returns the Type value.
|
|
otCoapCode | otCoapMessageGetCode (const otMessage *aMessage) |
This function returns the Code value.
|
|
void | otCoapMessageSetCode ( otMessage *aMessage, otCoapCode aCode) |
This function sets the Code value.
|
|
const char * | otCoapMessageCodeToString (const otMessage *aMessage) |
This method returns the CoAP Code as human readable string.
|
|
uint16_t | otCoapMessageGetMessageId (const otMessage *aMessage) |
This function returns the Message ID value.
|
|
uint8_t | otCoapMessageGetTokenLength (const otMessage *aMessage) |
This function returns the Token length.
|
|
const uint8_t * | otCoapMessageGetToken (const otMessage *aMessage) |
This function returns a pointer to the Token value.
|
|
otError | otCoapOptionIteratorInit ( otCoapOptionIterator *aIterator, const otMessage *aMessage) |
This function initialises an iterator for the options in the given message.
|
|
const otCoapOption * | otCoapOptionIteratorGetFirstOptionMatching ( otCoapOptionIterator *aIterator, uint16_t aOption) |
This function returns a pointer to the first option matching the specified option number.
|
|
const otCoapOption * | otCoapOptionIteratorGetFirstOption ( otCoapOptionIterator *aIterator) |
This function returns a pointer to the first option.
|
|
const otCoapOption * | otCoapOptionIteratorGetNextOptionMatching ( otCoapOptionIterator *aIterator, uint16_t aOption) |
This function returns a pointer to the next option matching the specified option number.
|
|
const otCoapOption * | otCoapOptionIteratorGetNextOption ( otCoapOptionIterator *aIterator) |
This function returns a pointer to the next option.
|
|
otError | otCoapOptionIteratorGetOptionUintValue ( otCoapOptionIterator *aIterator, uint64_t *aValue) |
This function fills current option value into
aValue
assuming the current value is an unsigned integer encoded according to
https://tools.ietf.org/html/rfc7252#section-3.2
.
|
|
otError | otCoapOptionIteratorGetOptionValue ( otCoapOptionIterator *aIterator, void *aValue) |
This function fills current option value into
aValue
.
|
|
otMessage * | otCoapNewMessage ( otInstance *aInstance, const otMessageSettings *aSettings) |
This function creates a new CoAP message.
|
|
otError | otCoapSendRequestWithParameters ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext, const otCoapTxParameters *aTxParameters) |
This function sends a CoAP request with custom transmission parameters.
|
|
otError | otCoapSendRequestBlockWiseWithParameters ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext, const otCoapTxParameters *aTxParameters, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook) |
This function sends a CoAP request block-wise with custom transmission parameters.
|
|
static otError | otCoapSendRequestBlockWise ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook) |
This function sends a CoAP request block-wise.
|
|
static otError | otCoapSendRequest ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext) |
This function sends a CoAP request.
|
|
otError | otCoapStart ( otInstance *aInstance, uint16_t aPort) |
This function starts the CoAP server.
|
|
otError | otCoapStop ( otInstance *aInstance) |
This function stops the CoAP server.
|
|
void | otCoapAddResource ( otInstance *aInstance, otCoapResource *aResource) |
This function adds a resource to the CoAP server.
|
|
void | otCoapRemoveResource ( otInstance *aInstance, otCoapResource *aResource) |
This function removes a resource from the CoAP server.
|
|
void | otCoapAddBlockWiseResource ( otInstance *aInstance, otCoapBlockwiseResource *aResource) |
This function adds a block-wise resource to the CoAP server.
|
|
void | otCoapRemoveBlockWiseResource ( otInstance *aInstance, otCoapBlockwiseResource *aResource) |
This function removes a block-wise resource from the CoAP server.
|
|
void | otCoapSetDefaultHandler ( otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext) |
This function sets the default handler for unhandled CoAP requests.
|
|
otError | otCoapSendResponseWithParameters ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, const otCoapTxParameters *aTxParameters) |
This function sends a CoAP response from the server with custom transmission parameters.
|
|
otError | otCoapSendResponseBlockWiseWithParameters ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, const otCoapTxParameters *aTxParameters, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook) |
This function sends a CoAP response block-wise from the server with custom transmission parameters.
|
|
static otError | otCoapSendResponseBlockWise ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook) |
This function sends a CoAP response block-wise from the server.
|
|
static otError | otCoapSendResponse ( otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo) |
This function sends a CoAP response from the server.
|
Detailed Description
This module includes functions that control CoAP communication.
The functions in this module are available when CoAP API feature (
OPENTHREAD_CONFIG_COAP_API_ENABLE
) is enabled.
Typedef Documentation
◆ otCoapBlockwiseReceiveHook
typedef otError (* otCoapBlockwiseReceiveHook) (void *aContext, const uint8_t *aBlock, uint32_t aPosition, uint16_t aBlockLength, bool aMore, uint32_t aTotalLength) |
This function pointer is called when a CoAP message with an block-wise transfer option is received.
This function is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
- Parameters
-
[in] aContext
A pointer to application-specific context. [in] aBlock
A pointer to the block segment. [in] aPosition
The position of aBlock
in a sequence in bytes.[in] aBlockLength
The length of the block segment in bytes. [in] aMore
Flag if more block segments are following. [in] aTotalLength
The total length in bytes of the transferred information (indicated by a Size1 or Size2 option).
- Return values
-
OT_ERROR_NONE
Block segment was stored successfully. OT_ERROR_NO_BUFS
No more memory to store blocks. OT_ERROR_NO_FRAME_RECEIVED
Block segment missing.
◆ otCoapBlockwiseTransmitHook
typedef otError (* otCoapBlockwiseTransmitHook) (void *aContext, uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore) |
This function pointer is called before the next block in a block-wise transfer is sent.
This function is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
- Parameters
-
[in] aContext
A pointer to application-specific context. [in,out] aBlock
A pointer to where the block segment can be written to. [in] aPosition
The position in a sequence from which to obtain the block segment. [in,out] aBlockLength
On entry, the maximum block segment length in bytes. [out] aMore
A pointer to the flag if more block segments will follow.
- Warning
- By changing the value of aBlockLength, the block size of the whole exchange is renegotiated. It is recommended to do this after the first block has been received as later changes could cause problems with other CoAP implementations.
- Return values
-
OT_ERROR_NONE
No error occurred. OT_ERROR_INVALID_ARGS
Block at aPosition
does not exist.
◆ otCoapOptionContentFormat
typedef enum otCoapOptionContentFormat otCoapOptionContentFormat |
CoAP Content Format codes.
The full list is documented at https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats
◆ otCoapOptionIterator
typedef struct otCoapOptionIterator otCoapOptionIterator |
This structure acts as an iterator for CoAP options.
◆ otCoapRequestHandler
typedef void(* otCoapRequestHandler) (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) |
This function pointer is called when a CoAP request with a given Uri-Path is received.
- Parameters
-
[in] aContext
A pointer to arbitrary context information. [in] aMessage
A pointer to the message. [in] aMessageInfo
A pointer to the message info for aMessage
.
◆ otCoapResponseHandler
typedef void(* otCoapResponseHandler) (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult) |
This function pointer is called when a CoAP response is received or on the request timeout.
- Parameters
-
[in] aContext
A pointer to application-specific context. [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.
- Return values
-
OT_ERROR_NONE
A response was received successfully. OT_ERROR_ABORT
A CoAP transaction was reset by peer. OT_ERROR_RESPONSE_TIMEOUT
No response or acknowledgment received during timeout period.
◆ otCoapTxParameters
typedef struct otCoapTxParameters otCoapTxParameters |
This structure represents the CoAP transmission parameters.
- Note
- mAckTimeout * ((2 ** (mMaxRetransmit + 1)) - 1) * (mAckRandomFactorNumerator / mAckRandomFactorDenominator) must not exceed what can be represented by a uint32_t (0xffffffff). This limitation allows OpenThread to avoid 64-bit arithmetic.
Enumeration Type Documentation
◆ otCoapCode
enum otCoapCode |
CoAP Code values.
◆ otCoapOptionContentFormat
CoAP Content Format codes.
The full list is documented at https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats
◆ otCoapOptionType
enum otCoapOptionType |
CoAP Option Numbers.
◆ otCoapType
enum otCoapType |
Function Documentation
◆ otCoapAddBlockWiseResource()
void otCoapAddBlockWiseResource | ( | otInstance * |
aInstance,
|
otCoapBlockwiseResource * |
aResource
|
||
) |
This function adds a block-wise resource to the CoAP server.
- Parameters
-
[in] aInstance
A pointer to an OpenThread instance. [in] aResource
A pointer to the resource.
◆ otCoapAddResource()
void otCoapAddResource | ( | otInstance * |
aInstance,
|
otCoapResource * |
aResource
|
||
) |
This function adds a resource to the CoAP server.
- Parameters
-
[in] aInstance
A pointer to an OpenThread instance. [in] aResource
A pointer to the resource.
◆ otCoapBlockSizeFromExponent()
uint16_t otCoapBlockSizeFromExponent | ( | otCoapBlockSzx |
aSize
|
) |
This function converts a CoAP Block option SZX field to the actual block size.
- Parameters
-
[in] aSize
Block size exponent.
- Returns
- The actual size exponent value.
◆ otCoapMessageAppendBlock1Option()
otError otCoapMessageAppendBlock1Option | ( | otMessage * |
aMessage,
|
uint32_t |
aNum,
|
||
bool |
aMore,
|
||
otCoapBlockSzx |
aSize
|
||
) |
This function appends a Block1 option.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aNum
Current block number. [in] aMore
Boolean to indicate more blocks are to be sent. [in] aSize
Block Size Exponent.
- Return values
-
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.
◆ otCoapMessageAppendBlock2Option()
otError otCoapMessageAppendBlock2Option | ( | otMessage * |
aMessage,
|
uint32_t |
aNum,
|
||
bool |
aMore,
|
||
otCoapBlockSzx |
aSize
|
||
) |
This function appends a Block2 option.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aNum
Current block number. [in] aMore
Boolean to indicate more blocks are to be sent. [in] aSize
Block Size Exponent.
- Return values
-
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.
◆ otCoapMessageAppendContentFormatOption()
otError otCoapMessageAppendContentFormatOption | ( | otMessage * |
aMessage,
|
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 otCoapMessageSetPayloadMarker if a payload is to be included in the message.
The function is a convenience wrapper around otCoapMessageAppendUintOption, and if the desired format type code isn't listed in otCoapOptionContentFormat, this base function should be used instead.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aContentFormat
One of the content formats listed in otCoapOptionContentFormat above.
- Return values
-
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.
◆ otCoapMessageAppendMaxAgeOption()
This function appends a Max-Age option.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aMaxAge
The Max-Age value.
- Return values
-
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.
◆ otCoapMessageAppendObserveOption()
This function appends an Observe option.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aObserve
Observe field value.
- Return values
-
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.
◆ otCoapMessageAppendOption()
otError otCoapMessageAppendOption | ( | otMessage * |
aMessage,
|
uint16_t |
aNumber,
|
||
uint16_t |
aLength,
|
||
const void * |
aValue
|
||
) |
This function appends a CoAP option in a header.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aNumber
The CoAP Option number. [in] aLength
The CoAP Option length. [in] aValue
A pointer to the CoAP value.
- Return values
-
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.
◆ otCoapMessageAppendProxyUriOption()
This function appends a Proxy-Uri option.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aUriPath
A pointer to a NULL-terminated string.
- Return values
-
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.
◆ otCoapMessageAppendUintOption()
This function appends an unsigned integer CoAP option as specified in https://tools.ietf.org/html/rfc7252#section-3.2 .
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aNumber
The CoAP Option number. [in] aValue
The CoAP Option unsigned integer value.
- Return values
-
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.
- See also
- otCoapMessageGetOptionUintValue
◆ otCoapMessageAppendUriPathOptions()
This function appends a Uri-Path option.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aUriPath
A pointer to a NULL-terminated string.
- Return values
-
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.
◆ otCoapMessageAppendUriQueryOption()
This function appends a single Uri-Query option.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aUriQuery
A pointer to NULL-terminated string, which should contain a single key=value pair.
- Return values
-
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.
◆ otCoapMessageCodeToString()
const char* otCoapMessageCodeToString | ( | const otMessage * |
aMessage
|
) |
This method returns the CoAP Code as human readable string.
- Parameters
-
[in] aMessage
A pointer to the CoAP message.
@ returns The CoAP Code as string.
◆ otCoapMessageGenerateToken()
void otCoapMessageGenerateToken | ( | otMessage * |
aMessage,
|
uint8_t |
aTokenLength
|
||
) |
This function sets the Token length and randomizes its value.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aTokenLength
The Length of a Token to set.
◆ otCoapMessageGetCode()
otCoapCode otCoapMessageGetCode | ( | const otMessage * |
aMessage
|
) |
This function returns the Code value.
- Parameters
-
[in] aMessage
A pointer to the CoAP message.
- Returns
- The Code value.
◆ otCoapMessageGetMessageId()
uint16_t otCoapMessageGetMessageId | ( | const otMessage * |
aMessage
|
) |
This function returns the Message ID value.
- Parameters
-
[in] aMessage
A pointer to the CoAP message.
- Returns
- The Message ID value.
◆ otCoapMessageGetToken()
const uint8_t* otCoapMessageGetToken | ( | const otMessage * |
aMessage
|
) |
This function returns a pointer to the Token value.
- Parameters
-
[in] aMessage
A pointer to the CoAP message.
- Returns
- A pointer to the Token value.
◆ otCoapMessageGetTokenLength()
uint8_t otCoapMessageGetTokenLength | ( | const otMessage * |
aMessage
|
) |
This function returns the Token length.
- Parameters
-
[in] aMessage
A pointer to the CoAP message.
- Returns
- The Token length.
◆ otCoapMessageGetType()
otCoapType otCoapMessageGetType | ( | const otMessage * |
aMessage
|
) |
This function returns the Type value.
- Parameters
-
[in] aMessage
A pointer to the CoAP message.
- Returns
- The Type value.
◆ otCoapMessageInit()
void otCoapMessageInit | ( | otMessage * |
aMessage,
|
otCoapType |
aType,
|
||
otCoapCode |
aCode
|
||
) |
This function initializes the CoAP header.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message to initialize. [in] aType
CoAP message type. [in] aCode
CoAP message code.
◆ otCoapMessageInitResponse()
otError otCoapMessageInitResponse | ( | otMessage * |
aResponse,
|
const otMessage * |
aRequest,
|
||
otCoapType |
aType,
|
||
otCoapCode |
aCode
|
||
) |
This function initializes a response message.
- Note
-
Both message ID and token are set according to
aRequest
.
- Parameters
-
[in,out] aResponse
A pointer to the CoAP response message. [in] aRequest
A pointer to the CoAP request message. [in] aType
CoAP message type. [in] aCode
CoAP message code.
- Return values
-
OT_ERROR_NONE
Successfully initialized the response message. OT_ERROR_NO_BUFS
Insufficient message buffers available to initialize the response message.
◆ otCoapMessageSetCode()
void otCoapMessageSetCode | ( | otMessage * |
aMessage,
|
otCoapCode |
aCode
|
||
) |
This function sets the Code value.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message to initialize. [in] aCode
CoAP message code.
◆ otCoapMessageSetPayloadMarker()
This function adds Payload Marker indicating beginning of the payload to the CoAP header.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message.
- Return values
-
OT_ERROR_NONE
Payload Marker successfully added. OT_ERROR_NO_BUFS
Header Payload Marker exceeds the buffer size.
◆ otCoapMessageSetToken()
otError otCoapMessageSetToken | ( | otMessage * |
aMessage,
|
const uint8_t * |
aToken,
|
||
uint8_t |
aTokenLength
|
||
) |
This function sets the Token value and length in a header.
- Parameters
-
[in,out] aMessage
A pointer to the CoAP message. [in] aToken
A pointer to the Token value. [in] aTokenLength
The Length of aToken
.
- Return values
-
OT_ERROR_NONE
Successfully set the Token value. OT_ERROR_NO_BUFS
Insufficient buffers to set the Token value.
◆ otCoapNewMessage()
otMessage * otCoapNewMessage | ( | otInstance * |
aInstance,
|
const otMessageSettings * |
aSettings
|
||
) |
This function creates a new CoAP message.
- Note
-
If
aSettings
is 'NULL', the link layer security is enabled and the message priority is set to OT_MESSAGE_PRIORITY_NORMAL by default.
- Parameters
-
[in] aInstance
A pointer to an OpenThread instance. [in] aSettings
A pointer to the message settings or NULL to set default settings.
- Returns
- A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.
◆ otCoapOptionIteratorGetFirstOption()
const otCoapOption * otCoapOptionIteratorGetFirstOption | ( | otCoapOptionIterator * |
aIterator
|
) |
This function returns a pointer to the first option.
- Parameters
-
[in,out] aIterator
A pointer to the CoAP message option iterator.
- Returns
- A pointer to the first option. If no option is present NULL pointer is returned.
◆ otCoapOptionIteratorGetFirstOptionMatching()
const otCoapOption * otCoapOptionIteratorGetFirstOptionMatching | ( | otCoapOptionIterator * |
aIterator,
|
uint16_t |
aOption
|
||
) |
This function returns a pointer to the first option matching the specified option number.
- Parameters
-
[in] aIterator
A pointer to the CoAP message option iterator. [in] aOption
The option number sought.
- Returns
- A pointer to the first matching option. If no matching option is present NULL pointer is returned.
◆ otCoapOptionIteratorGetNextOption()
const otCoapOption * otCoapOptionIteratorGetNextOption | ( | otCoapOptionIterator * |
aIterator
|
) |
This function returns a pointer to the next option.
- Parameters
-
[in,out] aIterator
A pointer to the CoAP message option iterator.
- Returns
- A pointer to the next option. If no more options are present NULL pointer is returned.
◆ otCoapOptionIteratorGetNextOptionMatching()
const otCoapOption * otCoapOptionIteratorGetNextOptionMatching | ( | otCoapOptionIterator * |
aIterator,
|
uint16_t |
aOption
|
||
) |
This function returns a pointer to the next option matching the specified option number.
- Parameters
-
[in] aIterator
A pointer to the CoAP message option iterator. [in] aOption
The option number sought.
- Returns
- A pointer to the next matching option. If no further matching option is present NULL pointer is returned.
◆ otCoapOptionIteratorGetOptionUintValue()
otError otCoapOptionIteratorGetOptionUintValue | ( | otCoapOptionIterator * |
aIterator,
|
uint64_t * |
aValue
|
||
) |
This function fills current option value into
aValue
assuming the current value is an unsigned integer encoded according to
https://tools.ietf.org/html/rfc7252#section-3.2
.
- Parameters
-
[in,out] aIterator
A pointer to the CoAP message option iterator. [out] aValue
A pointer to an unsigned integer to receive the option value.
- Return values
-
OT_ERROR_NONE
Successfully filled value. OT_ERROR_NOT_FOUND
No current option. OT_ERROR_NO_BUFS
Value is too long to fit in a uint64_t.
- See also
- otCoapMessageAppendUintOption
◆ otCoapOptionIteratorGetOptionValue()
otError otCoapOptionIteratorGetOptionValue | ( | otCoapOptionIterator * |
aIterator,
|
void * |
aValue
|
||
) |
This function fills current option value into
aValue
.
- Parameters
-
[in,out] aIterator
A pointer to the CoAP message option iterator. [out] aValue
A pointer to a buffer to receive the option value.
- Return values
-
OT_ERROR_NONE
Successfully filled value. OT_ERROR_NOT_FOUND
No current option.
◆ otCoapOptionIteratorInit()
otError otCoapOptionIteratorInit | ( | otCoapOptionIterator * |
aIterator,
|
const otMessage * |
aMessage
|
||
) |
This function initialises an iterator for the options in the given message.
- Parameters
-
[in,out] aIterator
A pointer to the CoAP message option iterator. [in] aMessage
A pointer to the CoAP message.
- Return values
-
OT_ERROR_NONE
Successfully initialised. OT_ERROR_PARSE
Message state is inconsistent.
◆ otCoapRemoveBlockWiseResource()
void otCoapRemoveBlockWiseResource | ( | otInstance * |
aInstance,
|
otCoapBlockwiseResource * |
aResource
|
||
) |
This function removes a block-wise resource from the CoAP server.
- Parameters
-
[in] aInstance
A pointer to an OpenThread instance. [in] aResource
A pointer to the resource.
◆ otCoapRemoveResource()
void otCoapRemoveResource | ( | otInstance * |
aInstance,
|
otCoapResource * |
aResource
|
||
) |
This function removes a resource from the CoAP server.
- Parameters
-
[in] aInstance
A pointer to an OpenThread instance. [in] aResource
A pointer to the resource.
◆ otCoapSendRequest()
|
inline static |
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.
- Parameters
-
[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.
- Return values
-
OT_ERROR_NONE
Successfully sent CoAP message. OT_ERROR_NO_BUFS
Failed to allocate retransmission data.
◆ otCoapSendRequestBlockWise()
|
inline static |
This function sends a CoAP request block-wise.
This function is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
If a response for a request is expected, respective function and context information should be provided. If the response is expected to be block-wise, a respective hook function should be provided. If no response is expected, these arguments should be NULL pointers.
- Parameters
-
[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. [in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer. [in] aReceiveHook
A pointer to a hook function for incoming block-wise transfer.
- Return values
-
OT_ERROR_NONE
Successfully sent CoAP message. OT_ERROR_NO_BUFS
Failed to allocate retransmission data.
◆ otCoapSendRequestBlockWiseWithParameters()
otError otCoapSendRequestBlockWiseWithParameters | ( | otInstance * |
aInstance,
|
otMessage * |
aMessage,
|
||
const otMessageInfo * |
aMessageInfo,
|
||
otCoapResponseHandler |
aHandler,
|
||
void * |
aContext,
|
||
const otCoapTxParameters * |
aTxParameters,
|
||
otCoapBlockwiseTransmitHook |
aTransmitHook,
|
||
otCoapBlockwiseReceiveHook |
aReceiveHook
|
||
) |
This function sends a CoAP request block-wise with custom transmission parameters.
This function is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
If a response for a request is expected, respective function and context information should be provided. If the response is expected to be block-wise, a respective hook function should be provided. If no response is expected, these arguments should be NULL pointers.
- Parameters
-
[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. [in] aTxParameters
A pointer to transmission parameters for this request. Use NULL for defaults. [in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer. [in] aReceiveHook
A pointer to a hook function for incoming block-wise transfer.
- Return values
-
OT_ERROR_NONE
Successfully sent CoAP message. OT_ERROR_NO_BUFS
Failed to allocate retransmission data.
◆ otCoapSendRequestWithParameters()
otError otCoapSendRequestWithParameters | ( | otInstance * |
aInstance,
|
otMessage * |
aMessage,
|
||
const otMessageInfo * |
aMessageInfo,
|
||
otCoapResponseHandler |
aHandler,
|
||
void * |
aContext,
|
||
const otCoapTxParameters * |
aTxParameters
|
||
) |
This function sends a CoAP request with custom transmission parameters.
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.
- Parameters
-
[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. [in] aTxParameters
A pointer to transmission parameters for this request. Use NULL for defaults. Otherwise, parameters given must meet the following conditions: - mMaxRetransmit is no more than OT_COAP_MAX_RETRANSMIT.
- mAckRandomFactorNumerator / mAckRandomFactorDenominator must not be below 1.0.
- The calculated exchange life time must not overflow uint32_t.
- Return values
-
OT_ERROR_INVALID_ARGS
aTxParameters
is invalid.OT_ERROR_NONE
Successfully sent CoAP message. OT_ERROR_NO_BUFS
Failed to allocate retransmission data.
◆ otCoapSendResponse()
|
inline static |
This function sends a CoAP response from the server.
- Parameters
-
[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
.
- Return values
-
OT_ERROR_NONE
Successfully enqueued the CoAP response message. OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.
◆ otCoapSendResponseBlockWise()
|
inline static |
This function sends a CoAP response block-wise from the server.
This function is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
- Parameters
-
[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
.[in] aContext
A pointer to arbitrary context information. May be NULL if not used. [in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer.
- Return values
-
OT_ERROR_NONE
Successfully enqueued the CoAP response message. OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.
◆ otCoapSendResponseBlockWiseWithParameters()
otError otCoapSendResponseBlockWiseWithParameters | ( | otInstance * |
aInstance,
|
otMessage * |
aMessage,
|
||
const otMessageInfo * |
aMessageInfo,
|
||
const otCoapTxParameters * |
aTxParameters,
|
||
void * |
aContext,
|
||
otCoapBlockwiseTransmitHook |
aTransmitHook
|
||
) |
This function sends a CoAP response block-wise from the server with custom transmission parameters.
This function is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.
- Parameters
-
[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
.[in] aTxParameters
A pointer to transmission parameters for this response. Use NULL for defaults. [in] aContext
A pointer to arbitrary context information. May be NULL if not used. [in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer.
- Return values
-
OT_ERROR_NONE
Successfully enqueued the CoAP response message. OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.
◆ otCoapSendResponseWithParameters()
otError otCoapSendResponseWithParameters | ( | otInstance * |
aInstance,
|
otMessage * |
aMessage,
|
||
const otMessageInfo * |
aMessageInfo,
|
||
const otCoapTxParameters * |
aTxParameters
|
||
) |
This function sends a CoAP response from the server with custom transmission parameters.
- Parameters
-
[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
.[in] aTxParameters
A pointer to transmission parameters for this response. Use NULL for defaults.
- Return values
-
OT_ERROR_NONE
Successfully enqueued the CoAP response message. OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.
◆ otCoapSetDefaultHandler()
void otCoapSetDefaultHandler | ( | otInstance * |
aInstance,
|
otCoapRequestHandler |
aHandler,
|
||
void * |
aContext
|
||
) |
This function sets the default handler for unhandled CoAP requests.
- Parameters
-
[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.
◆ otCoapStart()
otError otCoapStart | ( | otInstance * |
aInstance,
|
uint16_t |
aPort
|
||
) |
This function starts the CoAP server.
- Parameters
-
[in] aInstance
A pointer to an OpenThread instance. [in] aPort
The local UDP port to bind to.
- Return values
-
OT_ERROR_NONE
Successfully started the CoAP server. OT_ERROR_FAILED
Failed to start the CoAP server.
◆ otCoapStop()
otError otCoapStop | ( | otInstance * |
aInstance
|
) |
This function stops the CoAP server.
- Parameters
-
[in] aInstance
A pointer to an OpenThread instance.
- Return values
-
OT_ERROR_NONE
Successfully stopped the CoAP server.