Formatting and parsing of CoAP options. More...
Go to the source code of this file.
| Data Structures | |
| struct | CoapOption | 
| CoAP option.  More... | |
| struct | CoapOptionParameters | 
| CoAP option parameters.  More... | |
| Functions | |
| error_t | coapParseOptions (const uint8_t *p, size_t length, size_t *consumed) | 
| Parse the list of CoAP options.  More... | |
| error_t | coapParseOption (const uint8_t *p, size_t length, uint16_t prevOptionNum, CoapOption *option, size_t *consumed) | 
| Parse CoAP option.  More... | |
| error_t | coapFormatOption (uint8_t *p, uint16_t prevOptionNum, CoapOption *option, size_t *written) | 
| Format CoAP option.  More... | |
| error_t | coapSetOption (CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const uint8_t *optionValue, size_t optionLen) | 
| Add an option to the specified CoAP message.  More... | |
| error_t | coapSetUintOption (CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t optionValue) | 
| Add a uint option to the specified CoAP message.  More... | |
| error_t | coapGetOption (const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const uint8_t **optionValue, size_t *optionLen) | 
| Get the value of the specified option.  More... | |
| error_t | coapGetUintOption (const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t *optionValue) | 
| Get the value of the specified uint option.  More... | |
| error_t | coapDeleteOption (CoapMessage *message, uint16_t optionNum, uint_t optionIndex) | 
| Remove an option from the specified CoAP message.  More... | |
| error_t | coapSplitRepeatableOption (CoapMessage *message, uint16_t optionNum, const char_t *optionValue, char_t separator) | 
| Encode a path or query component into multiple repeatable options.  More... | |
| error_t | coapJoinRepeatableOption (const CoapMessage *message, uint16_t optionNum, char_t *optionValue, size_t maxLen, char_t separator) | 
| Decode a path or query component from multiple repeatable options.  More... | |
| const CoapOptionParameters * | coapGetOptionParameters (uint16_t optionNum) | 
| Retrieve parameters for a given option number.  More... | |
Detailed Description
Formatting and parsing of CoAP options.
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneTCP Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- Version
- 2.5.4
Definition in file coap_option.h.
Macro Definition Documentation
◆ COAP_DEFAULT_MAX_AGE
| #define COAP_DEFAULT_MAX_AGE 60 | 
Definition at line 54 of file coap_option.h.
◆ COAP_GET_BLOCK_M
Definition at line 71 of file coap_option.h.
◆ COAP_GET_BLOCK_NUM
Definition at line 69 of file coap_option.h.
◆ COAP_GET_BLOCK_POS
Definition at line 78 of file coap_option.h.
◆ COAP_GET_BLOCK_SIZE
Definition at line 76 of file coap_option.h.
◆ COAP_GET_BLOCK_SZX
Definition at line 73 of file coap_option.h.
◆ COAP_IS_OPTION_CRITICAL
Definition at line 57 of file coap_option.h.
◆ COAP_IS_OPTION_UNSAFE
Definition at line 59 of file coap_option.h.
◆ COAP_OPT_DELTA_16_BITS
| #define COAP_OPT_DELTA_16_BITS 14 | 
Definition at line 41 of file coap_option.h.
◆ COAP_OPT_DELTA_8_BITS
| #define COAP_OPT_DELTA_8_BITS 13 | 
Definition at line 40 of file coap_option.h.
◆ COAP_OPT_DELTA_MINUS_16_BITS
| #define COAP_OPT_DELTA_MINUS_16_BITS 269 | 
Definition at line 44 of file coap_option.h.
◆ COAP_OPT_DELTA_MINUS_8_BITS
| #define COAP_OPT_DELTA_MINUS_8_BITS 13 | 
Definition at line 43 of file coap_option.h.
◆ COAP_OPT_DELTA_RESERVED
| #define COAP_OPT_DELTA_RESERVED 15 | 
Definition at line 42 of file coap_option.h.
◆ COAP_OPT_LEN_16_BITS
| #define COAP_OPT_LEN_16_BITS 14 | 
Definition at line 48 of file coap_option.h.
◆ COAP_OPT_LEN_8_BITS
| #define COAP_OPT_LEN_8_BITS 13 | 
Definition at line 47 of file coap_option.h.
◆ COAP_OPT_LEN_MINUS_16_BITS
| #define COAP_OPT_LEN_MINUS_16_BITS 269 | 
Definition at line 51 of file coap_option.h.
◆ COAP_OPT_LEN_MINUS_8_BITS
| #define COAP_OPT_LEN_MINUS_8_BITS 13 | 
Definition at line 50 of file coap_option.h.
◆ COAP_OPT_LEN_RESERVED
| #define COAP_OPT_LEN_RESERVED 15 | 
Definition at line 49 of file coap_option.h.
◆ COAP_SET_BLOCK_M
Definition at line 64 of file coap_option.h.
◆ COAP_SET_BLOCK_NUM
Definition at line 62 of file coap_option.h.
◆ COAP_SET_BLOCK_SZX
Definition at line 66 of file coap_option.h.
Enumeration Type Documentation
◆ CoapBlockSize
| enum CoapBlockSize | 
Block size parameter.
| Enumerator | |
|---|---|
| COAP_BLOCK_SIZE_16 | |
| COAP_BLOCK_SIZE_32 | |
| COAP_BLOCK_SIZE_64 | |
| COAP_BLOCK_SIZE_128 | |
| COAP_BLOCK_SIZE_256 | |
| COAP_BLOCK_SIZE_512 | |
| COAP_BLOCK_SIZE_1024 | |
| COAP_BLOCK_SIZE_RESERVED | |
Definition at line 199 of file coap_option.h.
◆ CoapContentFormat
| enum CoapContentFormat | 
Content-Format option.
Definition at line 145 of file coap_option.h.
◆ CoapObserveOption
| enum CoapObserveOption | 
Observe option.
| Enumerator | |
|---|---|
| COAP_OBSERVE_REGISTER | |
| COAP_OBSERVE_DEREGISTER | |
Definition at line 134 of file coap_option.h.
◆ CoapOptionFormat
| enum CoapOptionFormat | 
CoAP option formats.
| Enumerator | |
|---|---|
| COAP_OPT_FORMAT_EMPTY | Zero-length sequence of bytes. | 
| COAP_OPT_FORMAT_OPAQUE | Opaque sequence of bytes. | 
| COAP_OPT_FORMAT_UINT | Non-negative integer. | 
| COAP_OPT_FORMAT_STRING | UTF-8 string. | 
Definition at line 121 of file coap_option.h.
◆ CoapOptionNumber
| enum CoapOptionNumber | 
CoAP options.
Definition at line 90 of file coap_option.h.
Function Documentation
◆ coapDeleteOption()
| error_t coapDeleteOption | ( | CoapMessage * | message, | 
| uint16_t | optionNum, | ||
| uint_t | optionIndex | ||
| ) | 
Remove an option from the specified CoAP message.
- Parameters
- 
  [in] message Pointer to the CoAP message [in] optionNum Option number [in] optionIndex Occurrence index (for repeatable options only) 
- Returns
- Error code
Definition at line 688 of file coap_option.c.
◆ coapFormatOption()
| error_t coapFormatOption | ( | uint8_t * | p, | 
| uint16_t | prevOptionNum, | ||
| CoapOption * | option, | ||
| size_t * | written | ||
| ) | 
Format CoAP option.
- Parameters
- 
  [in] p Buffer where to format the CoAP option (optional parameter) [in] prevOptionNum Option number of the previous instance [in] option CoAP option content [out] written Total number of bytes that have been written 
- Returns
- Error code
Definition at line 262 of file coap_option.c.
◆ coapGetOption()
| error_t coapGetOption | ( | const CoapMessage * | message, | 
| uint16_t | optionNum, | ||
| uint_t | optionIndex, | ||
| const uint8_t ** | optionValue, | ||
| size_t * | optionLen | ||
| ) | 
Get the value of the specified option.
- Parameters
- 
  [in] message Pointer to the CoAP message [in] optionNum Option number [in] optionIndex Occurrence index (for repeatable options only) [out] optionValue Pointer to the first byte of the option value [out] optionLen Length of the option, in bytes 
- Returns
- Error code
Definition at line 571 of file coap_option.c.
◆ coapGetOptionParameters()
| const CoapOptionParameters* coapGetOptionParameters | ( | uint16_t | optionNum | ) | 
Retrieve parameters for a given option number.
- Parameters
- 
  [in] optionNum Option number 
- Returns
- Option parameters
Definition at line 950 of file coap_option.c.
◆ coapGetUintOption()
| error_t coapGetUintOption | ( | const CoapMessage * | message, | 
| uint16_t | optionNum, | ||
| uint_t | optionIndex, | ||
| uint32_t * | optionValue | ||
| ) | 
Get the value of the specified uint option.
- Parameters
- 
  [in] message Pointer to the CoAP message [in] optionNum Option number to search for [in] optionIndex Occurrence index (for repeatable options only) [out] optionValue Option value (unsigned integer) 
- Returns
- Error code
Definition at line 651 of file coap_option.c.
◆ coapJoinRepeatableOption()
| error_t coapJoinRepeatableOption | ( | const CoapMessage * | message, | 
| uint16_t | optionNum, | ||
| char_t * | optionValue, | ||
| size_t | maxLen, | ||
| char_t | separator | ||
| ) | 
Decode a path or query component from multiple repeatable options.
- Parameters
- 
  [in] message Pointer to the CoAP message [in] optionNum Option number [out] optionValue Buffer where to copy the path or query component [in] maxLen Maximum number of characters the buffer can hold [in] separator Delimiting character 
- Returns
- Error code
Definition at line 877 of file coap_option.c.
◆ coapParseOption()
| error_t coapParseOption | ( | const uint8_t * | p, | 
| size_t | length, | ||
| uint16_t | prevOptionNum, | ||
| CoapOption * | option, | ||
| size_t * | consumed | ||
| ) | 
Parse CoAP option.
- Parameters
- 
  [in] p Input stream where to read the CoAP option [in] length Number of bytes available in the input stream [in] prevOptionNum Option number of the previous instance [out] option CoAP option content [out] consumed Total number of bytes that have been consumed 
- Returns
- Error code
Definition at line 133 of file coap_option.c.
◆ coapParseOptions()
| error_t coapParseOptions | ( | const uint8_t * | p, | 
| size_t | length, | ||
| size_t * | consumed | ||
| ) | 
Parse the list of CoAP options.
- Parameters
- 
  [in] p Input stream where to read the CoAP options [in] length Number of bytes available in the input stream [out] consumed Total number of bytes that have been consumed 
- Returns
- Error code
Definition at line 81 of file coap_option.c.
◆ coapSetOption()
| error_t coapSetOption | ( | CoapMessage * | message, | 
| uint16_t | optionNum, | ||
| uint_t | optionIndex, | ||
| const uint8_t * | optionValue, | ||
| size_t | optionLen | ||
| ) | 
Add an option to the specified CoAP message.
- Parameters
- 
  [in] message Pointer to the CoAP message [in] optionNum Option number [in] optionIndex Occurrence index (for repeatable options only) [in] optionValue Pointer to the first byte of the option value [in] optionLen Length of the option, in bytes 
- Returns
- Error code
Definition at line 388 of file coap_option.c.
◆ coapSetUintOption()
| error_t coapSetUintOption | ( | CoapMessage * | message, | 
| uint16_t | optionNum, | ||
| uint_t | optionIndex, | ||
| uint32_t | optionValue | ||
| ) | 
Add a uint option to the specified CoAP message.
- Parameters
- 
  [in] message Pointer to the CoAP message [in] optionNum Option number [in] optionIndex Occurrence index (for repeatable options only) [in] optionValue Option value (unsigned integer) 
- Returns
- Error code
Definition at line 543 of file coap_option.c.
◆ coapSplitRepeatableOption()
| error_t coapSplitRepeatableOption | ( | CoapMessage * | message, | 
| uint16_t | optionNum, | ||
| const char_t * | optionValue, | ||
| char_t | separator | ||
| ) | 
Encode a path or query component into multiple repeatable options.
- Parameters
- 
  [in] message Pointer to the CoAP message [in] optionNum Option number [in] optionValue Path or a query component to be encoded [in] separator Delimiting character 
- Returns
- Error code
Definition at line 822 of file coap_option.c.
