1 /*
2 * Copyright (c) 2016, The OpenThread Authors.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /**
30 * @file
31 * @brief
32 * This file defines the top-level functions for the OpenThread CoAP implementation.
33 */
34
35 #ifndef OPENTHREAD_COAP_H_
36 #define OPENTHREAD_COAP_H_
37
38 #include <stdint.h>
39
40 #include <openthread/ip6.h>
41 #include <openthread/message.h>
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /**
48 * @addtogroup api-coap
49 *
50 * @brief
51 * This module includes functions that control CoAP communication.
52 *
53 * The functions in this module are available when CoAP API feature (`OPENTHREAD_CONFIG_COAP_API_ENABLE`) is enabled.
54 *
55 * @{
56 */
57
58 #define OT_DEFAULT_COAP_PORT 5683 ///< Default CoAP port, as specified in RFC 7252
59
60 #define OT_COAP_DEFAULT_TOKEN_LENGTH 2 ///< Default token length.
61
62 #define OT_COAP_MAX_TOKEN_LENGTH 8 ///< Max token length as specified (RFC 7252).
63
64 #define OT_COAP_MAX_RETRANSMIT 20 ///< Max retransmit supported by OpenThread.
65
66 #define OT_COAP_MIN_ACK_TIMEOUT 1000 ///< Minimal ACK timeout in milliseconds supported by OpenThread.
67
68 /**
69 * CoAP Type values (2 bit unsigned integer).
70 */
71 typedef enum otCoapType
72 {
73 OT_COAP_TYPE_CONFIRMABLE = 0, ///< Confirmable
74 OT_COAP_TYPE_NON_CONFIRMABLE = 1, ///< Non-confirmable
75 OT_COAP_TYPE_ACKNOWLEDGMENT = 2, ///< Acknowledgment
76 OT_COAP_TYPE_RESET = 3, ///< Reset
77 } otCoapType;
78
79 /**
80 * Helper macro to define CoAP Code values.
81 */
82 #define OT_COAP_CODE(c, d) ((((c)&0x7) << 5) | ((d)&0x1f))
83
84 /**
85 * CoAP Code values.
86 */
87 typedef enum otCoapCode
88 {
89 OT_COAP_CODE_EMPTY = OT_COAP_CODE(0, 0), ///< Empty message code
90 OT_COAP_CODE_GET = OT_COAP_CODE(0, 1), ///< Get
91 OT_COAP_CODE_POST = OT_COAP_CODE(0, 2), ///< Post
92 OT_COAP_CODE_PUT = OT_COAP_CODE(0, 3), ///< Put
93 OT_COAP_CODE_DELETE = OT_COAP_CODE(0, 4), ///< Delete
94
95 OT_COAP_CODE_RESPONSE_MIN = OT_COAP_CODE(2, 0), ///< 2.00
96 OT_COAP_CODE_CREATED = OT_COAP_CODE(2, 1), ///< Created
97 OT_COAP_CODE_DELETED = OT_COAP_CODE(2, 2), ///< Deleted
98 OT_COAP_CODE_VALID = OT_COAP_CODE(2, 3), ///< Valid
99 OT_COAP_CODE_CHANGED = OT_COAP_CODE(2, 4), ///< Changed
100 OT_COAP_CODE_CONTENT = OT_COAP_CODE(2, 5), ///< Content
101 OT_COAP_CODE_CONTINUE = OT_COAP_CODE(2, 31), ///< RFC7959 Continue
102
103 OT_COAP_CODE_BAD_REQUEST = OT_COAP_CODE(4, 0), ///< Bad Request
104 OT_COAP_CODE_UNAUTHORIZED = OT_COAP_CODE(4, 1), ///< Unauthorized
105 OT_COAP_CODE_BAD_OPTION = OT_COAP_CODE(4, 2), ///< Bad Option
106 OT_COAP_CODE_FORBIDDEN = OT_COAP_CODE(4, 3), ///< Forbidden
107 OT_COAP_CODE_NOT_FOUND = OT_COAP_CODE(4, 4), ///< Not Found
108 OT_COAP_CODE_METHOD_NOT_ALLOWED = OT_COAP_CODE(4, 5), ///< Method Not Allowed
109 OT_COAP_CODE_NOT_ACCEPTABLE = OT_COAP_CODE(4, 6), ///< Not Acceptable
110 OT_COAP_CODE_REQUEST_INCOMPLETE = OT_COAP_CODE(4, 8), ///< RFC7959 Request Entity Incomplete
111 OT_COAP_CODE_PRECONDITION_FAILED = OT_COAP_CODE(4, 12), ///< Precondition Failed
112 OT_COAP_CODE_REQUEST_TOO_LARGE = OT_COAP_CODE(4, 13), ///< Request Entity Too Large
113 OT_COAP_CODE_UNSUPPORTED_FORMAT = OT_COAP_CODE(4, 15), ///< Unsupported Content-Format
114
115 OT_COAP_CODE_INTERNAL_ERROR = OT_COAP_CODE(5, 0), ///< Internal Server Error
116 OT_COAP_CODE_NOT_IMPLEMENTED = OT_COAP_CODE(5, 1), ///< Not Implemented
117 OT_COAP_CODE_BAD_GATEWAY = OT_COAP_CODE(5, 2), ///< Bad Gateway
118 OT_COAP_CODE_SERVICE_UNAVAILABLE = OT_COAP_CODE(5, 3), ///< Service Unavailable
119 OT_COAP_CODE_GATEWAY_TIMEOUT = OT_COAP_CODE(5, 4), ///< Gateway Timeout
120 OT_COAP_CODE_PROXY_NOT_SUPPORTED = OT_COAP_CODE(5, 5), ///< Proxying Not Supported
121 } otCoapCode;
122
123 /**
124 * CoAP Option Numbers
125 */
126 typedef enum otCoapOptionType
127 {
128 OT_COAP_OPTION_IF_MATCH = 1, ///< If-Match
129 OT_COAP_OPTION_URI_HOST = 3, ///< Uri-Host
130 OT_COAP_OPTION_E_TAG = 4, ///< ETag
131 OT_COAP_OPTION_IF_NONE_MATCH = 5, ///< If-None-Match
132 OT_COAP_OPTION_OBSERVE = 6, ///< Observe [RFC7641]
133 OT_COAP_OPTION_URI_PORT = 7, ///< Uri-Port
134 OT_COAP_OPTION_LOCATION_PATH = 8, ///< Location-Path
135 OT_COAP_OPTION_URI_PATH = 11, ///< Uri-Path
136 OT_COAP_OPTION_CONTENT_FORMAT = 12, ///< Content-Format
137 OT_COAP_OPTION_MAX_AGE = 14, ///< Max-Age
138 OT_COAP_OPTION_URI_QUERY = 15, ///< Uri-Query
139 OT_COAP_OPTION_ACCEPT = 17, ///< Accept
140 OT_COAP_OPTION_LOCATION_QUERY = 20, ///< Location-Query
141 OT_COAP_OPTION_BLOCK2 = 23, ///< Block2 (RFC7959)
142 OT_COAP_OPTION_BLOCK1 = 27, ///< Block1 (RFC7959)
143 OT_COAP_OPTION_SIZE2 = 28, ///< Size2 (RFC7959)
144 OT_COAP_OPTION_PROXY_URI = 35, ///< Proxy-Uri
145 OT_COAP_OPTION_PROXY_SCHEME = 39, ///< Proxy-Scheme
146 OT_COAP_OPTION_SIZE1 = 60, ///< Size1
147 } otCoapOptionType;
148
149 /**
150 * Represents a CoAP option.
151 */
152 typedef struct otCoapOption
153 {
154 uint16_t mNumber; ///< Option Number
155 uint16_t mLength; ///< Option Length
156 } otCoapOption;
157
158 /**
159 * Acts as an iterator for CoAP options
160 */
161 typedef struct otCoapOptionIterator
162 {
163 const otMessage *mMessage; ///< CoAP message
164 otCoapOption mOption; ///< CoAP message option
165 uint16_t mNextOptionOffset; ///< Byte offset of next option
166 } otCoapOptionIterator;
167
168 /**
169 * CoAP Content Format codes. The full list is documented at
170 * https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats
171 */
172 typedef enum otCoapOptionContentFormat
173 {
174 /**
175 * text/plain; charset=utf-8: [RFC2046][RFC3676][RFC5147]
176 */
177 OT_COAP_OPTION_CONTENT_FORMAT_TEXT_PLAIN = 0,
178
179 /**
180 * application/cose; cose-type="cose-encrypt0": [RFC8152]
181 */
182 OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT0 = 16,
183
184 /**
185 * application/cose; cose-type="cose-mac0": [RFC8152]
186 */
187 OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC0 = 17,
188
189 /**
190 * application/cose; cose-type="cose-sign1": [RFC8152]
191 */
192 OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN1 = 18,
193
194 /**
195 * application/link-format: [RFC6690]
196 */
197 OT_COAP_OPTION_CONTENT_FORMAT_LINK_FORMAT = 40,
198
199 /**
200 * application/xml: [RFC3023]
201 */
202 OT_COAP_OPTION_CONTENT_FORMAT_XML = 41,
203
204 /**
205 * application/octet-stream: [RFC2045][RFC2046]
206 */
207 OT_COAP_OPTION_CONTENT_FORMAT_OCTET_STREAM = 42,
208
209 /**
210 * application/exi:
211 * ["Efficient XML Interchange (EXI) Format 1.0 (Second Edition)", February 2014]
212 */
213 OT_COAP_OPTION_CONTENT_FORMAT_EXI = 47,
214
215 /**
216 * application/json: [RFC7159]
217 */
218 OT_COAP_OPTION_CONTENT_FORMAT_JSON = 50,
219
220 /**
221 * application/json-patch+json: [RFC6902]
222 */
223 OT_COAP_OPTION_CONTENT_FORMAT_JSON_PATCH_JSON = 51,
224
225 /**
226 * application/merge-patch+json: [RFC7396]
227 */
228 OT_COAP_OPTION_CONTENT_FORMAT_MERGE_PATCH_JSON = 52,
229
230 /**
231 * application/cbor: [RFC7049]
232 */
233 OT_COAP_OPTION_CONTENT_FORMAT_CBOR = 60,
234
235 /**
236 * application/cwt: [RFC8392]
237 */
238 OT_COAP_OPTION_CONTENT_FORMAT_CWT = 61,
239
240 /**
241 * application/cose; cose-type="cose-encrypt": [RFC8152]
242 */
243 OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT = 96,
244
245 /**
246 * application/cose; cose-type="cose-mac": [RFC8152]
247 */
248 OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC = 97,
249
250 /**
251 * application/cose; cose-type="cose-sign": [RFC8152]
252 */
253 OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN = 98,
254
255 /**
256 * application/cose-key: [RFC8152]
257 */
258 OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY = 101,
259
260 /**
261 * application/cose-key-set: [RFC8152]
262 */
263 OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY_SET = 102,
264
265 /**
266 * application/senml+json: [RFC8428]
267 */
268 OT_COAP_OPTION_CONTENT_FORMAT_SENML_JSON = 110,
269
270 /**
271 * application/sensml+json: [RFC8428]
272 */
273 OT_COAP_OPTION_CONTENT_FORMAT_SENSML_JSON = 111,
274
275 /**
276 * application/senml+cbor: [RFC8428]
277 */
278 OT_COAP_OPTION_CONTENT_FORMAT_SENML_CBOR = 112,
279
280 /**
281 * application/sensml+cbor: [RFC8428]
282 */
283 OT_COAP_OPTION_CONTENT_FORMAT_SENSML_CBOR = 113,
284
285 /**
286 * application/senml-exi: [RFC8428]
287 */
288 OT_COAP_OPTION_CONTENT_FORMAT_SENML_EXI = 114,
289
290 /**
291 * application/sensml-exi: [RFC8428]
292 */
293 OT_COAP_OPTION_CONTENT_FORMAT_SENSML_EXI = 115,
294
295 /**
296 * application/coap-group+json: [RFC7390]
297 */
298 OT_COAP_OPTION_CONTENT_FORMAT_COAP_GROUP_JSON = 256,
299
300 /**
301 * application/senml+xml: [RFC8428]
302 */
303 OT_COAP_OPTION_CONTENT_FORMAT_SENML_XML = 310,
304
305 /**
306 * application/sensml+xml: [RFC8428]
307 */
308 OT_COAP_OPTION_CONTENT_FORMAT_SENSML_XML = 311
309 } otCoapOptionContentFormat;
310
311 /**
312 * CoAP Block Size Exponents
313 */
314 typedef enum otCoapBlockSzx
315 {
316 OT_COAP_OPTION_BLOCK_SZX_16 = 0,
317 OT_COAP_OPTION_BLOCK_SZX_32 = 1,
318 OT_COAP_OPTION_BLOCK_SZX_64 = 2,
319 OT_COAP_OPTION_BLOCK_SZX_128 = 3,
320 OT_COAP_OPTION_BLOCK_SZX_256 = 4,
321 OT_COAP_OPTION_BLOCK_SZX_512 = 5,
322 OT_COAP_OPTION_BLOCK_SZX_1024 = 6
323 } otCoapBlockSzx;
324
325 /**
326 * Pointer is called when a CoAP response is received or on the request timeout.
327 *
328 * @param[in] aContext A pointer to application-specific context.
329 * @param[in] aMessage A pointer to the message buffer containing the response. NULL if no response was received.
330 * @param[in] aMessageInfo A pointer to the message info for @p aMessage. NULL if no response was received.
331 * @param[in] aResult A result of the CoAP transaction.
332 *
333 * @retval OT_ERROR_NONE A response was received successfully.
334 * @retval OT_ERROR_ABORT A CoAP transaction was reset by peer.
335 * @retval OT_ERROR_RESPONSE_TIMEOUT No response or acknowledgment received during timeout period.
336 */
337 typedef void (*otCoapResponseHandler)(void *aContext,
338 otMessage *aMessage,
339 const otMessageInfo *aMessageInfo,
340 otError aResult);
341
342 /**
343 * Pointer is called when a CoAP request with a given Uri-Path is received.
344 *
345 * @param[in] aContext A pointer to arbitrary context information.
346 * @param[in] aMessage A pointer to the message.
347 * @param[in] aMessageInfo A pointer to the message info for @p aMessage.
348 */
349 typedef void (*otCoapRequestHandler)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
350
351 /**
352 * Pointer is called when a CoAP message with a block-wise transfer option is received.
353 *
354 * Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration
355 * is enabled.
356 *
357 * @param[in] aContext A pointer to application-specific context.
358 * @param[in] aBlock A pointer to the block segment.
359 * @param[in] aPosition The position of @p aBlock in a sequence in bytes.
360 * @param[in] aBlockLength The length of the block segment in bytes.
361 * @param[in] aMore Flag if more block segments are following.
362 * @param[in] aTotalLength The total length in bytes of the transferred information (indicated by a Size1 or Size2
363 * option).
364 *
365 * @retval OT_ERROR_NONE Block segment was stored successfully.
366 * @retval OT_ERROR_NO_BUFS No more memory to store blocks.
367 * @retval OT_ERROR_NO_FRAME_RECEIVED Block segment missing.
368 */
369 typedef otError (*otCoapBlockwiseReceiveHook)(void *aContext,
370 const uint8_t *aBlock,
371 uint32_t aPosition,
372 uint16_t aBlockLength,
373 bool aMore,
374 uint32_t aTotalLength);
375
376 /**
377 * Pointer is called before the next block in a block-wise transfer is sent.
378 *
379 * Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration
380 * is enabled.
381 *
382 * @param[in] aContext A pointer to application-specific context.
383 * @param[in,out] aBlock A pointer to where the block segment can be written to.
384 * @param[in] aPosition The position in a sequence from which to obtain the block segment.
385 * @param[in,out] aBlockLength On entry, the maximum block segment length in bytes.
386 * @param[out] aMore A pointer to the flag if more block segments will follow.
387 *
388 * @warning By changing the value of aBlockLength, the block size of the whole exchange is
389 * renegotiated. It is recommended to do this after the first block has been received as
390 * later changes could cause problems with other CoAP implementations.
391 *
392 * @retval OT_ERROR_NONE No error occurred.
393 * @retval OT_ERROR_INVALID_ARGS Block at @p aPosition does not exist.
394 */
395 typedef otError (*otCoapBlockwiseTransmitHook)(void *aContext,
396 uint8_t *aBlock,
397 uint32_t aPosition,
398 uint16_t *aBlockLength,
399 bool *aMore);
400
401 /**
402 * Represents a CoAP resource.
403 */
404 typedef struct otCoapResource
405 {
406 const char *mUriPath; ///< The URI Path string
407 otCoapRequestHandler mHandler; ///< The callback for handling a received request
408 void *mContext; ///< Application-specific context
409 struct otCoapResource *mNext; ///< The next CoAP resource in the list
410 } otCoapResource;
411
412 /**
413 * Represents a CoAP resource with block-wise transfer.
414 */
415 typedef struct otCoapBlockwiseResource
416 {
417 const char *mUriPath; ///< The URI Path string
418 otCoapRequestHandler mHandler; ///< The callback for handling a received request
419
420 /** The callback for handling incoming block-wise transfer.
421 * This callback is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
422 * configuration is enabled.
423 */
424 otCoapBlockwiseReceiveHook mReceiveHook;
425
426 /** The callback for handling outgoing block-wise transfer.
427 * This callback is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
428 * configuration is enabled.
429 */
430 otCoapBlockwiseTransmitHook mTransmitHook;
431 void *mContext; ///< Application-specific context
432 struct otCoapBlockwiseResource *mNext; ///< The next CoAP resource in the list
433 } otCoapBlockwiseResource;
434
435 /**
436 * Represents the CoAP transmission parameters.
437 *
438 * @note mAckTimeout * ((2 ** (mMaxRetransmit + 1)) - 1) * (mAckRandomFactorNumerator / mAckRandomFactorDenominator)
439 * must not exceed what can be represented by a uint32_t (0xffffffff). This limitation allows OpenThread to
440 * avoid 64-bit arithmetic.
441 */
442 typedef struct otCoapTxParameters
443 {
444 /**
445 * Minimum spacing before first retransmission when ACK is not received, in milliseconds (RFC7252 default value is
446 * 2000ms).
447 */
448 uint32_t mAckTimeout;
449
450 /**
451 * Numerator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when ACK is not
452 * received (RFC7252 default value of ACK_RANDOM_FACTOR is 1.5; must not be decreased below 1).
453 */
454 uint8_t mAckRandomFactorNumerator;
455
456 /**
457 * Denominator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when ACK is not
458 * received (RFC7252 default value of ACK_RANDOM_FACTOR is 1.5; must not be decreased below 1).
459 */
460 uint8_t mAckRandomFactorDenominator;
461
462 /**
463 * Maximum number of retransmissions for CoAP Confirmable messages (RFC7252 default value is 4).
464 */
465 uint8_t mMaxRetransmit;
466 } otCoapTxParameters;
467
468 /**
469 * Initializes the CoAP header.
470 *
471 * @param[in,out] aMessage A pointer to the CoAP message to initialize.
472 * @param[in] aType CoAP message type.
473 * @param[in] aCode CoAP message code.
474 */
475 void otCoapMessageInit(otMessage *aMessage, otCoapType aType, otCoapCode aCode);
476
477 /**
478 * Initializes a response message.
479 *
480 * @note Both message ID and token are set according to @p aRequest.
481 *
482 * @param[in,out] aResponse A pointer to the CoAP response message.
483 * @param[in] aRequest A pointer to the CoAP request message.
484 * @param[in] aType CoAP message type.
485 * @param[in] aCode CoAP message code.
486 *
487 * @retval OT_ERROR_NONE Successfully initialized the response message.
488 * @retval OT_ERROR_NO_BUFS Insufficient message buffers available to initialize the response message.
489 */
490 otError otCoapMessageInitResponse(otMessage *aResponse, const otMessage *aRequest, otCoapType aType, otCoapCode aCode);
491
492 /**
493 * Sets the Token value and length in a header.
494 *
495 * @param[in,out] aMessage A pointer to the CoAP message.
496 * @param[in] aToken A pointer to the Token value.
497 * @param[in] aTokenLength The Length of @p aToken.
498 *
499 * @retval OT_ERROR_NONE Successfully set the Token value.
500 * @retval OT_ERROR_NO_BUFS Insufficient buffers to set the Token value.
501 */
502 otError otCoapMessageSetToken(otMessage *aMessage, const uint8_t *aToken, uint8_t aTokenLength);
503
504 /**
505 * Sets the Token length and randomizes its value.
506 *
507 * @param[in,out] aMessage A pointer to the CoAP message.
508 * @param[in] aTokenLength The Length of a Token to set.
509 */
510 void otCoapMessageGenerateToken(otMessage *aMessage, uint8_t aTokenLength);
511
512 /**
513 * Appends the Content Format CoAP option as specified in
514 * https://tools.ietf.org/html/rfc7252#page-92. This *must* be called before
515 * setting otCoapMessageSetPayloadMarker if a payload is to be included in the
516 * message.
517 *
518 * The function is a convenience wrapper around otCoapMessageAppendUintOption,
519 * and if the desired format type code isn't listed in otCoapOptionContentFormat,
520 * this base function should be used instead.
521 *
522 * @param[in,out] aMessage A pointer to the CoAP message.
523 * @param[in] aContentFormat One of the content formats listed in
524 * otCoapOptionContentFormat above.
525 *
526 * @retval OT_ERROR_NONE Successfully appended the option.
527 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
528 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
529 */
530 otError otCoapMessageAppendContentFormatOption(otMessage *aMessage, otCoapOptionContentFormat aContentFormat);
531
532 /**
533 * Appends a CoAP option in a header.
534 *
535 * @param[in,out] aMessage A pointer to the CoAP message.
536 * @param[in] aNumber The CoAP Option number.
537 * @param[in] aLength The CoAP Option length.
538 * @param[in] aValue A pointer to the CoAP value.
539 *
540 * @retval OT_ERROR_NONE Successfully appended the option.
541 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
542 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
543 */
544 otError otCoapMessageAppendOption(otMessage *aMessage, uint16_t aNumber, uint16_t aLength, const void *aValue);
545
546 /**
547 * Appends an unsigned integer CoAP option as specified in
548 * https://tools.ietf.org/html/rfc7252#section-3.2
549 *
550 * @param[in,out] aMessage A pointer to the CoAP message.
551 * @param[in] aNumber The CoAP Option number.
552 * @param[in] aValue The CoAP Option unsigned integer value.
553 *
554 * @retval OT_ERROR_NONE Successfully appended the option.
555 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
556 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
557 *
558 * @see otCoapMessageGetOptionUintValue
559 */
560 otError otCoapMessageAppendUintOption(otMessage *aMessage, uint16_t aNumber, uint32_t aValue);
561
562 /**
563 * Appends an Observe option.
564 *
565 * @param[in,out] aMessage A pointer to the CoAP message.
566 * @param[in] aObserve Observe field value.
567 *
568 * @retval OT_ERROR_NONE Successfully appended the option.
569 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
570 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
571 */
572 otError otCoapMessageAppendObserveOption(otMessage *aMessage, uint32_t aObserve);
573
574 /**
575 * Appends a Uri-Path option.
576 *
577 * @param[in,out] aMessage A pointer to the CoAP message.
578 * @param[in] aUriPath A pointer to a NULL-terminated string.
579 *
580 * @retval OT_ERROR_NONE Successfully appended the option.
581 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
582 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
583 */
584 otError otCoapMessageAppendUriPathOptions(otMessage *aMessage, const char *aUriPath);
585
586 /**
587 * Appends a Uri-Query option.
588 *
589 * @param[in,out] aMessage A pointer to the CoAP message.
590 * @param[in] aUriQuery A pointer to a NULL-terminated string.
591 *
592 * @retval OT_ERROR_NONE Successfully appended the option.
593 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
594 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
595 */
596 otError otCoapMessageAppendUriQueryOptions(otMessage *aMessage, const char *aUriQuery);
597
598 /**
599 * Converts a CoAP Block option SZX field to the actual block size
600 *
601 * @param[in] aSize Block size exponent.
602 *
603 * @returns The actual size exponent value.
604 */
605 uint16_t otCoapBlockSizeFromExponent(otCoapBlockSzx aSize);
606
607 /**
608 * Appends a Block2 option
609 *
610 * @param[in,out] aMessage A pointer to the CoAP message.
611 * @param[in] aNum Current block number.
612 * @param[in] aMore Boolean to indicate more blocks are to be sent.
613 * @param[in] aSize Block Size Exponent.
614 *
615 * @retval OT_ERROR_NONE Successfully appended the option.
616 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
617 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
618 */
619 otError otCoapMessageAppendBlock2Option(otMessage *aMessage, uint32_t aNum, bool aMore, otCoapBlockSzx aSize);
620
621 /**
622 * Appends a Block1 option
623 *
624 * @param[in,out] aMessage A pointer to the CoAP message.
625 * @param[in] aNum Current block number.
626 * @param[in] aMore Boolean to indicate more blocks are to be sent.
627 * @param[in] aSize Block Size Exponent.
628 *
629 * @retval OT_ERROR_NONE Successfully appended the option.
630 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
631 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
632 */
633 otError otCoapMessageAppendBlock1Option(otMessage *aMessage, uint32_t aNum, bool aMore, otCoapBlockSzx aSize);
634
635 /**
636 * Appends a Proxy-Uri option.
637 *
638 * @param[in,out] aMessage A pointer to the CoAP message.
639 * @param[in] aUriPath A pointer to a NULL-terminated string.
640 *
641 * @retval OT_ERROR_NONE Successfully appended the option.
642 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
643 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
644 */
645 otError otCoapMessageAppendProxyUriOption(otMessage *aMessage, const char *aUriPath);
646
647 /**
648 * Appends a Max-Age option.
649 *
650 * @param[in,out] aMessage A pointer to the CoAP message.
651 * @param[in] aMaxAge The Max-Age value.
652 *
653 * @retval OT_ERROR_NONE Successfully appended the option.
654 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
655 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
656 */
657 otError otCoapMessageAppendMaxAgeOption(otMessage *aMessage, uint32_t aMaxAge);
658
659 /**
660 * Appends a single Uri-Query option.
661 *
662 * @param[in,out] aMessage A pointer to the CoAP message.
663 * @param[in] aUriQuery A pointer to NULL-terminated string, which should contain a single key=value pair.
664 *
665 * @retval OT_ERROR_NONE Successfully appended the option.
666 * @retval OT_ERROR_INVALID_ARGS The option type is not equal or greater than the last option type.
667 * @retval OT_ERROR_NO_BUFS The option length exceeds the buffer size.
668 */
669 otError otCoapMessageAppendUriQueryOption(otMessage *aMessage, const char *aUriQuery);
670
671 /**
672 * Adds Payload Marker indicating beginning of the payload to the CoAP header.
673 *
674 * @param[in,out] aMessage A pointer to the CoAP message.
675 *
676 * @retval OT_ERROR_NONE Payload Marker successfully added.
677 * @retval OT_ERROR_NO_BUFS Header Payload Marker exceeds the buffer size.
678 */
679 otError otCoapMessageSetPayloadMarker(otMessage *aMessage);
680
681 /**
682 * Returns the Type value.
683 *
684 * @param[in] aMessage A pointer to the CoAP message.
685 *
686 * @returns The Type value.
687 */
688 otCoapType otCoapMessageGetType(const otMessage *aMessage);
689
690 /**
691 * Returns the Code value.
692 *
693 * @param[in] aMessage A pointer to the CoAP message.
694 *
695 * @returns The Code value.
696 */
697 otCoapCode otCoapMessageGetCode(const otMessage *aMessage);
698
699 /**
700 * Sets the Code value.
701 *
702 * @param[in,out] aMessage A pointer to the CoAP message to initialize.
703 * @param[in] aCode CoAP message code.
704 */
705 void otCoapMessageSetCode(otMessage *aMessage, otCoapCode aCode);
706
707 /**
708 * Returns the CoAP Code as human readable string.
709 *
710 * @param[in] aMessage A pointer to the CoAP message.
711 *
712 * @ returns The CoAP Code as string.
713 */
714 const char *otCoapMessageCodeToString(const otMessage *aMessage);
715
716 /**
717 * Returns the Message ID value.
718 *
719 * @param[in] aMessage A pointer to the CoAP message.
720 *
721 * @returns The Message ID value.
722 */
723 uint16_t otCoapMessageGetMessageId(const otMessage *aMessage);
724
725 /**
726 * Returns the Token length.
727 *
728 * @param[in] aMessage A pointer to the CoAP message.
729 *
730 * @returns The Token length.
731 */
732 uint8_t otCoapMessageGetTokenLength(const otMessage *aMessage);
733
734 /**
735 * Returns a pointer to the Token value.
736 *
737 * @param[in] aMessage A pointer to the CoAP message.
738 *
739 * @returns A pointer to the Token value.
740 */
741 const uint8_t *otCoapMessageGetToken(const otMessage *aMessage);
742
743 /**
744 * Initialises an iterator for the options in the given message.
745 *
746 * @param[in,out] aIterator A pointer to the CoAP message option iterator.
747 * @param[in] aMessage A pointer to the CoAP message.
748 *
749 * @retval OT_ERROR_NONE Successfully initialised.
750 * @retval OT_ERROR_PARSE Message state is inconsistent.
751 */
752 otError otCoapOptionIteratorInit(otCoapOptionIterator *aIterator, const otMessage *aMessage);
753
754 /**
755 * Returns a pointer to the first option matching the specified option number.
756 *
757 * @param[in] aIterator A pointer to the CoAP message option iterator.
758 * @param[in] aOption The option number sought.
759 *
760 * @returns A pointer to the first matching option. If no matching option is present NULL pointer is returned.
761 */
762 const otCoapOption *otCoapOptionIteratorGetFirstOptionMatching(otCoapOptionIterator *aIterator, uint16_t aOption);
763
764 /**
765 * Returns a pointer to the first option.
766 *
767 * @param[in,out] aIterator A pointer to the CoAP message option iterator.
768 *
769 * @returns A pointer to the first option. If no option is present NULL pointer is returned.
770 */
771 const otCoapOption *otCoapOptionIteratorGetFirstOption(otCoapOptionIterator *aIterator);
772
773 /**
774 * Returns a pointer to the next option matching the specified option number.
775 *
776 * @param[in] aIterator A pointer to the CoAP message option iterator.
777 * @param[in] aOption The option number sought.
778 *
779 * @returns A pointer to the next matching option. If no further matching option is present NULL pointer is returned.
780 */
781 const otCoapOption *otCoapOptionIteratorGetNextOptionMatching(otCoapOptionIterator *aIterator, uint16_t aOption);
782
783 /**
784 * Returns a pointer to the next option.
785 *
786 * @param[in,out] aIterator A pointer to the CoAP message option iterator.
787 *
788 * @returns A pointer to the next option. If no more options are present NULL pointer is returned.
789 */
790 const otCoapOption *otCoapOptionIteratorGetNextOption(otCoapOptionIterator *aIterator);
791
792 /**
793 * Fills current option value into @p aValue assuming the current value is an unsigned integer encoded
794 * according to https://tools.ietf.org/html/rfc7252#section-3.2
795 *
796 * @param[in,out] aIterator A pointer to the CoAP message option iterator.
797 * @param[out] aValue A pointer to an unsigned integer to receive the option value.
798 *
799 * @retval OT_ERROR_NONE Successfully filled value.
800 * @retval OT_ERROR_NOT_FOUND No current option.
801 * @retval OT_ERROR_NO_BUFS Value is too long to fit in a uint64_t.
802 *
803 * @see otCoapMessageAppendUintOption
804 */
805 otError otCoapOptionIteratorGetOptionUintValue(otCoapOptionIterator *aIterator, uint64_t *aValue);
806
807 /**
808 * Fills current option value into @p aValue.
809 *
810 * @param[in,out] aIterator A pointer to the CoAP message option iterator.
811 * @param[out] aValue A pointer to a buffer to receive the option value.
812 *
813 * @retval OT_ERROR_NONE Successfully filled value.
814 * @retval OT_ERROR_NOT_FOUND No current option.
815 */
816 otError otCoapOptionIteratorGetOptionValue(otCoapOptionIterator *aIterator, void *aValue);
817
818 /**
819 * Creates a new CoAP message.
820 *
821 * @note If @p aSettings is 'NULL', the link layer security is enabled and the message priority is set to
822 * OT_MESSAGE_PRIORITY_NORMAL by default.
823 *
824 * @param[in] aInstance A pointer to an OpenThread instance.
825 * @param[in] aSettings A pointer to the message settings or NULL to set default settings.
826 *
827 * @returns A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.
828 */
829 otMessage *otCoapNewMessage(otInstance *aInstance, const otMessageSettings *aSettings);
830
831 /**
832 * Sends a CoAP request with custom transmission parameters.
833 *
834 * If a response for a request is expected, respective function and context information should be provided.
835 * If no response is expected, these arguments should be NULL pointers.
836 *
837 * @param[in] aInstance A pointer to an OpenThread instance.
838 * @param[in] aMessage A pointer to the message to send.
839 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
840 * @param[in] aHandler A function pointer that shall be called on response reception or timeout.
841 * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used.
842 * @param[in] aTxParameters A pointer to transmission parameters for this request. Use NULL for defaults.
843 * Otherwise, parameters given must meet the following conditions:
844 * 1. mMaxRetransmit is no more than OT_COAP_MAX_RETRANSMIT.
845 * 2. mAckRandomFactorNumerator / mAckRandomFactorDenominator must not be below 1.0.
846 * 3. The calculated exchange life time must not overflow uint32_t.
847 *
848 * @retval OT_ERROR_NONE Successfully sent CoAP message.
849 * @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
850 * @retval OT_ERROR_INVALID_ARGS Invalid arguments are given.
851 */
852 otError otCoapSendRequestWithParameters(otInstance *aInstance,
853 otMessage *aMessage,
854 const otMessageInfo *aMessageInfo,
855 otCoapResponseHandler aHandler,
856 void *aContext,
857 const otCoapTxParameters *aTxParameters);
858
859 /**
860 * Sends a CoAP request block-wise with custom transmission parameters.
861 *
862 * Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration
863 * is enabled.
864 *
865 * If a response for a request is expected, respective function and context information should be provided.
866 * If the response is expected to be block-wise, a respective hook function should be provided.
867 * If no response is expected, these arguments should be NULL pointers.
868 *
869 * @param[in] aInstance A pointer to an OpenThread instance.
870 * @param[in] aMessage A pointer to the message to send.
871 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
872 * @param[in] aHandler A function pointer that shall be called on response reception or timeout.
873 * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used.
874 * @param[in] aTxParameters A pointer to transmission parameters for this request. Use NULL for defaults.
875 * @param[in] aTransmitHook A pointer to a hook function for outgoing block-wise transfer.
876 * @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
877 *
878 * @retval OT_ERROR_NONE Successfully sent CoAP message.
879 * @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
880 * @retval OT_ERROR_INVALID_ARGS Invalid arguments are given.
881 */
882 otError otCoapSendRequestBlockWiseWithParameters(otInstance *aInstance,
883 otMessage *aMessage,
884 const otMessageInfo *aMessageInfo,
885 otCoapResponseHandler aHandler,
886 void *aContext,
887 const otCoapTxParameters *aTxParameters,
888 otCoapBlockwiseTransmitHook aTransmitHook,
889 otCoapBlockwiseReceiveHook aReceiveHook);
890
891 /**
892 * Sends a CoAP request block-wise.
893 *
894 * Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration
895 * is enabled.
896 *
897 * If a response for a request is expected, respective function and context information should be provided.
898 * If the response is expected to be block-wise, a respective hook function should be provided.
899 * If no response is expected, these arguments should be NULL pointers.
900 *
901 * @param[in] aInstance A pointer to an OpenThread instance.
902 * @param[in] aMessage A pointer to the message to send.
903 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
904 * @param[in] aHandler A function pointer that shall be called on response reception or timeout.
905 * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used.
906 * @param[in] aTransmitHook A pointer to a hook function for outgoing block-wise transfer.
907 * @param[in] aReceiveHook A pointer to a hook function for incoming block-wise transfer.
908 *
909 * @retval OT_ERROR_NONE Successfully sent CoAP message.
910 * @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
911 */
otCoapSendRequestBlockWise(otInstance * aInstance,otMessage * aMessage,const otMessageInfo * aMessageInfo,otCoapResponseHandler aHandler,void * aContext,otCoapBlockwiseTransmitHook aTransmitHook,otCoapBlockwiseReceiveHook aReceiveHook)912 static inline otError otCoapSendRequestBlockWise(otInstance *aInstance,
913 otMessage *aMessage,
914 const otMessageInfo *aMessageInfo,
915 otCoapResponseHandler aHandler,
916 void *aContext,
917 otCoapBlockwiseTransmitHook aTransmitHook,
918 otCoapBlockwiseReceiveHook aReceiveHook)
919 {
920 // NOLINTNEXTLINE(modernize-use-nullptr)
921 return otCoapSendRequestBlockWiseWithParameters(aInstance, aMessage, aMessageInfo, aHandler, aContext, NULL,
922 aTransmitHook, aReceiveHook);
923 }
924
925 /**
926 * Sends a CoAP request.
927 *
928 * If a response for a request is expected, respective function and context information should be provided.
929 * If no response is expected, these arguments should be NULL pointers.
930 *
931 * @param[in] aInstance A pointer to an OpenThread instance.
932 * @param[in] aMessage A pointer to the message to send.
933 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
934 * @param[in] aHandler A function pointer that shall be called on response reception or timeout.
935 * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used.
936 *
937 * @retval OT_ERROR_NONE Successfully sent CoAP message.
938 * @retval OT_ERROR_NO_BUFS Failed to allocate retransmission data.
939 */
otCoapSendRequest(otInstance * aInstance,otMessage * aMessage,const otMessageInfo * aMessageInfo,otCoapResponseHandler aHandler,void * aContext)940 static inline otError otCoapSendRequest(otInstance *aInstance,
941 otMessage *aMessage,
942 const otMessageInfo *aMessageInfo,
943 otCoapResponseHandler aHandler,
944 void *aContext)
945 {
946 // NOLINTNEXTLINE(modernize-use-nullptr)
947 return otCoapSendRequestWithParameters(aInstance, aMessage, aMessageInfo, aHandler, aContext, NULL);
948 }
949
950 /**
951 * Starts the CoAP server.
952 *
953 * @param[in] aInstance A pointer to an OpenThread instance.
954 * @param[in] aPort The local UDP port to bind to.
955 *
956 * @retval OT_ERROR_NONE Successfully started the CoAP server.
957 * @retval OT_ERROR_FAILED Failed to start the CoAP server.
958 */
959 otError otCoapStart(otInstance *aInstance, uint16_t aPort);
960
961 /**
962 * Stops the CoAP server.
963 *
964 * @param[in] aInstance A pointer to an OpenThread instance.
965 *
966 * @retval OT_ERROR_NONE Successfully stopped the CoAP server.
967 */
968 otError otCoapStop(otInstance *aInstance);
969
970 /**
971 * Adds a resource to the CoAP server.
972 *
973 * @param[in] aInstance A pointer to an OpenThread instance.
974 * @param[in] aResource A pointer to the resource.
975 */
976 void otCoapAddResource(otInstance *aInstance, otCoapResource *aResource);
977
978 /**
979 * Removes a resource from the CoAP server.
980 *
981 * @param[in] aInstance A pointer to an OpenThread instance.
982 * @param[in] aResource A pointer to the resource.
983 */
984 void otCoapRemoveResource(otInstance *aInstance, otCoapResource *aResource);
985
986 /**
987 * Adds a block-wise resource to the CoAP server.
988 *
989 * @param[in] aInstance A pointer to an OpenThread instance.
990 * @param[in] aResource A pointer to the resource.
991 */
992 void otCoapAddBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource);
993
994 /**
995 * Removes a block-wise resource from the CoAP server.
996 *
997 * @param[in] aInstance A pointer to an OpenThread instance.
998 * @param[in] aResource A pointer to the resource.
999 */
1000 void otCoapRemoveBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource);
1001
1002 /**
1003 * Sets the default handler for unhandled CoAP requests.
1004 *
1005 * @param[in] aInstance A pointer to an OpenThread instance.
1006 * @param[in] aHandler A function pointer that shall be called when an unhandled request arrives.
1007 * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used.
1008 */
1009 void otCoapSetDefaultHandler(otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext);
1010
1011 /**
1012 * Sends a CoAP response from the server with custom transmission parameters.
1013 *
1014 * @param[in] aInstance A pointer to an OpenThread instance.
1015 * @param[in] aMessage A pointer to the CoAP response to send.
1016 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
1017 * @param[in] aTxParameters A pointer to transmission parameters for this response. Use NULL for defaults.
1018 *
1019 * @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
1020 * @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
1021 * @retval OT_ERROR_INVALID_ARGS Invalid arguments are given.
1022 */
1023 otError otCoapSendResponseWithParameters(otInstance *aInstance,
1024 otMessage *aMessage,
1025 const otMessageInfo *aMessageInfo,
1026 const otCoapTxParameters *aTxParameters);
1027
1028 /**
1029 * Sends a CoAP response block-wise from the server with custom transmission parameters.
1030 *
1031 * Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration
1032 * is enabled.
1033 *
1034 * @param[in] aInstance A pointer to an OpenThread instance.
1035 * @param[in] aMessage A pointer to the CoAP response to send.
1036 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
1037 * @param[in] aTxParameters A pointer to transmission parameters for this response. Use NULL for defaults.
1038 * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used.
1039 * @param[in] aTransmitHook A pointer to a hook function for outgoing block-wise transfer.
1040 *
1041 * @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
1042 * @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
1043 * @retval OT_ERROR_INVALID_ARGS Invalid arguments are given.
1044 */
1045 otError otCoapSendResponseBlockWiseWithParameters(otInstance *aInstance,
1046 otMessage *aMessage,
1047 const otMessageInfo *aMessageInfo,
1048 const otCoapTxParameters *aTxParameters,
1049 void *aContext,
1050 otCoapBlockwiseTransmitHook aTransmitHook);
1051
1052 /**
1053 * Sends a CoAP response block-wise from the server.
1054 *
1055 * Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration
1056 * is enabled.
1057 *
1058 * @param[in] aInstance A pointer to an OpenThread instance.
1059 * @param[in] aMessage A pointer to the CoAP response to send.
1060 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
1061 * @param[in] aContext A pointer to arbitrary context information. May be NULL if not used.
1062 * @param[in] aTransmitHook A pointer to a hook function for outgoing block-wise transfer.
1063 *
1064 * @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
1065 * @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
1066 */
otCoapSendResponseBlockWise(otInstance * aInstance,otMessage * aMessage,const otMessageInfo * aMessageInfo,void * aContext,otCoapBlockwiseTransmitHook aTransmitHook)1067 static inline otError otCoapSendResponseBlockWise(otInstance *aInstance,
1068 otMessage *aMessage,
1069 const otMessageInfo *aMessageInfo,
1070 void *aContext,
1071 otCoapBlockwiseTransmitHook aTransmitHook)
1072 {
1073 // NOLINTNEXTLINE(modernize-use-nullptr)
1074 return otCoapSendResponseBlockWiseWithParameters(aInstance, aMessage, aMessageInfo, NULL, aContext, aTransmitHook);
1075 }
1076
1077 /**
1078 * Sends a CoAP response from the server.
1079 *
1080 * @param[in] aInstance A pointer to an OpenThread instance.
1081 * @param[in] aMessage A pointer to the CoAP response to send.
1082 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage.
1083 *
1084 * @retval OT_ERROR_NONE Successfully enqueued the CoAP response message.
1085 * @retval OT_ERROR_NO_BUFS Insufficient buffers available to send the CoAP response.
1086 */
otCoapSendResponse(otInstance * aInstance,otMessage * aMessage,const otMessageInfo * aMessageInfo)1087 static inline otError otCoapSendResponse(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo)
1088 {
1089 // NOLINTNEXTLINE(modernize-use-nullptr)
1090 return otCoapSendResponseWithParameters(aInstance, aMessage, aMessageInfo, NULL);
1091 }
1092
1093 /**
1094 * @}
1095 */
1096
1097 #ifdef __cplusplus
1098 } // extern "C"
1099 #endif
1100
1101 #endif /* OPENTHREAD_COAP_H_ */
1102