coap_option.c File Reference

CoAP option formatting and parsing. More...

#include "core/net.h"
#include "coap/coap_client.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

CoAP option formatting and parsing.

License

Copyright (C) 2010-2018 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
1.9.0

Definition in file coap_option.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   COAP_TRACE_LEVEL

Definition at line 30 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 686 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 260 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 569 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 948 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 649 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 875 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 131 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 79 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 386 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 541 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 820 of file coap_option.c.

Variable Documentation

◆ coapOptionList

const CoapOptionParameters coapOptionList[]
Initial value:
=
{
}
Opaque sequence of bytes.
Definition: coap_option.h:120
#define TRUE
Definition: os_port.h:48
Zero-length sequence of bytes.
Definition: coap_option.h:119
Non-negative integer.
Definition: coap_option.h:121
#define FALSE
Definition: os_port.h:44
UTF-8 string.
Definition: coap_option.h:122

List of supported CoAP options.

Definition at line 47 of file coap_option.c.