coap_option.c File Reference

Formatting and parsing of CoAP options. More...

#include "core/net.h"
#include "coap/coap_client.h"
#include "coap/coap_server.h"
#include "coap/coap_option.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   COAP_TRACE_LEVEL
 

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 CoapOptionParameterscoapGetOptionParameters (uint16_t optionNum)
 Retrieve parameters for a given option number. More...
 

Variables

const CoapOptionParameters coapOptionList []
 List of supported CoAP options. More...
 

Detailed Description

Formatting and parsing of CoAP options.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 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.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file coap_option.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   COAP_TRACE_LEVEL

Definition at line 32 of file coap_option.c.

Function Documentation

◆ coapDeleteOption()

error_t coapDeleteOption ( CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex 
)

Remove an option from the specified CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence 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]pBuffer where to format the CoAP option (optional parameter)
[in]prevOptionNumOption number of the previous instance
[in]optionCoAP option content
[out]writtenTotal 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]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence index (for repeatable options only)
[out]optionValuePointer to the first byte of the option value
[out]optionLenLength 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]optionNumOption 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]messagePointer to the CoAP message
[in]optionNumOption number to search for
[in]optionIndexOccurrence index (for repeatable options only)
[out]optionValueOption 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]messagePointer to the CoAP message
[in]optionNumOption number
[out]optionValueBuffer where to copy the path or query component
[in]maxLenMaximum number of characters the buffer can hold
[in]separatorDelimiting 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]pInput stream where to read the CoAP option
[in]lengthNumber of bytes available in the input stream
[in]prevOptionNumOption number of the previous instance
[out]optionCoAP option content
[out]consumedTotal 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]pInput stream where to read the CoAP options
[in]lengthNumber of bytes available in the input stream
[out]consumedTotal 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]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence index (for repeatable options only)
[in]optionValuePointer to the first byte of the option value
[in]optionLenLength 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]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence index (for repeatable options only)
[in]optionValueOption 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]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionValuePath or a query component to be encoded
[in]separatorDelimiting character
Returns
Error code

Definition at line 822 of file coap_option.c.

Variable Documentation

◆ coapOptionList

const CoapOptionParameters coapOptionList[]
Initial value:
=
{
}

List of supported CoAP options.

Definition at line 49 of file coap_option.c.

@ COAP_OPT_ETAG
Definition: coap_option.h:94
@ COAP_OPT_LOCATION_PATH
Definition: coap_option.h:98
#define TRUE
Definition: os_port.h:50
@ COAP_OPT_FORMAT_UINT
Non-negative integer.
Definition: coap_option.h:125
@ COAP_OPT_CONTENT_FORMAT
Definition: coap_option.h:100
@ COAP_OPT_URI_HOST
Definition: coap_option.h:93
@ COAP_OPT_FORMAT_STRING
UTF-8 string.
Definition: coap_option.h:126
#define FALSE
Definition: os_port.h:46
@ COAP_OPT_URI_QUERY
Definition: coap_option.h:102
@ COAP_OPT_ACCEPT
Definition: coap_option.h:103
@ COAP_OPT_FORMAT_EMPTY
Zero-length sequence of bytes.
Definition: coap_option.h:123
@ COAP_OPT_PROXY_URI
Definition: coap_option.h:108
@ COAP_OPT_BLOCK1
Definition: coap_option.h:106
@ COAP_OPT_OBSERVE
Definition: coap_option.h:96
@ COAP_OPT_PROXY_SCHEME
Definition: coap_option.h:109
@ COAP_OPT_URI_PATH
Definition: coap_option.h:99
@ COAP_OPT_SIZE1
Definition: coap_option.h:110
@ COAP_OPT_MAX_AGE
Definition: coap_option.h:101
@ COAP_OPT_IF_NONE_MATCH
Definition: coap_option.h:95
@ COAP_OPT_URI_PORT
Definition: coap_option.h:97
@ COAP_OPT_LOCATION_QUERY
Definition: coap_option.h:104
@ COAP_OPT_BLOCK2
Definition: coap_option.h:105
@ COAP_OPT_FORMAT_OPAQUE
Opaque sequence of bytes.
Definition: coap_option.h:124
@ COAP_OPT_SIZE2
Definition: coap_option.h:107
@ COAP_OPT_IF_MATCH
Definition: coap_option.h:92