coap_option.h File Reference

CoAP option formatting and parsing. More...

#include "core/net.h"
#include "coap/coap_common.h"
#include "coap/coap_message.h"

Go to the source code of this file.

Data Structures

struct  CoapOption
 CoAP option. More...
 
struct  CoapOptionParameters
 CoAP option parameters. More...
 

Macros

#define COAP_OPT_DELTA_8_BITS   13
 
#define COAP_OPT_DELTA_16_BITS   14
 
#define COAP_OPT_DELTA_RESERVED   15
 
#define COAP_OPT_DELTA_MINUS_8_BITS   13
 
#define COAP_OPT_DELTA_MINUS_16_BITS   269
 
#define COAP_OPT_LEN_8_BITS   13
 
#define COAP_OPT_LEN_16_BITS   14
 
#define COAP_OPT_LEN_RESERVED   15
 
#define COAP_OPT_LEN_MINUS_8_BITS   13
 
#define COAP_OPT_LEN_MINUS_16_BITS   269
 
#define COAP_DEFAULT_MAX_AGE   60
 
#define COAP_IS_OPTION_CRITICAL(num)   (((num) & 0x01U) ? TRUE : FALSE)
 
#define COAP_IS_OPTION_UNSAFE(num)   (((num) & 0x02U) ? TRUE : FALSE)
 
#define COAP_SET_BLOCK_NUM(value, n)   value = ((value) & 0x0FU) | ((n) << 4U)
 
#define COAP_SET_BLOCK_M(value, m)   value = ((value) & ~0x08U) | (((m) << 3U) & 0x08U)
 
#define COAP_SET_BLOCK_SZX(value, s)   value = ((value) & ~0x07U) | ((s) & 0x07U)
 
#define COAP_GET_BLOCK_NUM(value)   ((value) >> 4U)
 
#define COAP_GET_BLOCK_M(value)   (((value) >> 3U) & 0x01U)
 
#define COAP_GET_BLOCK_SZX(value)   ((value) & 0x07U)
 
#define COAP_GET_BLOCK_SIZE(value)   (16U << ((value) & 0x07U))
 
#define COAP_GET_BLOCK_POS(value)   (((value) & ~0x0FU) << ((value) & 0x07U))
 

Enumerations

enum  CoapOptionNumber {
  COAP_OPT_IF_MATCH = 1, COAP_OPT_URI_HOST = 3, COAP_OPT_ETAG = 4, COAP_OPT_IF_NONE_MATCH = 5,
  COAP_OPT_OBSERVE = 6, COAP_OPT_URI_PORT = 7, COAP_OPT_LOCATION_PATH = 8, COAP_OPT_URI_PATH = 11,
  COAP_OPT_CONTENT_FORMAT = 12, COAP_OPT_MAX_AGE = 14, COAP_OPT_URI_QUERY = 15, COAP_OPT_ACCEPT = 17,
  COAP_OPT_LOCATION_QUERY = 20, COAP_OPT_BLOCK2 = 23, COAP_OPT_BLOCK1 = 27, COAP_OPT_SIZE2 = 28,
  COAP_OPT_PROXY_URI = 35, COAP_OPT_PROXY_SCHEME = 39, COAP_OPT_SIZE1 = 60, COAP_OPT_NO_RESPONSE = 258
}
 CoAP options. More...
 
enum  CoapOptionFormat { COAP_OPT_FORMAT_EMPTY = 0, COAP_OPT_FORMAT_OPAQUE = 1, COAP_OPT_FORMAT_UINT = 2, COAP_OPT_FORMAT_STRING = 3 }
 CoAP option formats. More...
 
enum  CoapObserveOption { COAP_OBSERVE_REGISTER = 0, COAP_OBSERVE_DEREGISTER = 1 }
 Observe option. More...
 
enum  CoapContentFormat {
  COAP_CONTENT_FORMAT_TEXT_PLAIN = 0, COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40, COAP_CONTENT_FORMAT_APP_XML = 41, COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42,
  COAP_CONTENT_FORMAT_APP_EXI = 47, COAP_CONTENT_FORMAT_APP_JSON = 50
}
 Content-Format option. More...
 
enum  CoapBlockSize {
  COAP_BLOCK_SIZE_16 = 0, COAP_BLOCK_SIZE_32 = 1, COAP_BLOCK_SIZE_64 = 2, COAP_BLOCK_SIZE_128 = 3,
  COAP_BLOCK_SIZE_256 = 4, COAP_BLOCK_SIZE_512 = 5, COAP_BLOCK_SIZE_1024 = 6, COAP_BLOCK_SIZE_RESERVED = 7
}
 Block size parameter. 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 CoapOptionParameterscoapGetOptionParameters (uint16_t optionNum)
 Retrieve parameters for a given option number. 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.h.

Macro Definition Documentation

◆ COAP_DEFAULT_MAX_AGE

#define COAP_DEFAULT_MAX_AGE   60

Definition at line 52 of file coap_option.h.

◆ COAP_GET_BLOCK_M

#define COAP_GET_BLOCK_M (   value)    (((value) >> 3U) & 0x01U)

Definition at line 69 of file coap_option.h.

◆ COAP_GET_BLOCK_NUM

#define COAP_GET_BLOCK_NUM (   value)    ((value) >> 4U)

Definition at line 67 of file coap_option.h.

◆ COAP_GET_BLOCK_POS

#define COAP_GET_BLOCK_POS (   value)    (((value) & ~0x0FU) << ((value) & 0x07U))

Definition at line 76 of file coap_option.h.

◆ COAP_GET_BLOCK_SIZE

#define COAP_GET_BLOCK_SIZE (   value)    (16U << ((value) & 0x07U))

Definition at line 74 of file coap_option.h.

◆ COAP_GET_BLOCK_SZX

#define COAP_GET_BLOCK_SZX (   value)    ((value) & 0x07U)

Definition at line 71 of file coap_option.h.

◆ COAP_IS_OPTION_CRITICAL

#define COAP_IS_OPTION_CRITICAL (   num)    (((num) & 0x01U) ? TRUE : FALSE)

Definition at line 55 of file coap_option.h.

◆ COAP_IS_OPTION_UNSAFE

#define COAP_IS_OPTION_UNSAFE (   num)    (((num) & 0x02U) ? TRUE : FALSE)

Definition at line 57 of file coap_option.h.

◆ COAP_OPT_DELTA_16_BITS

#define COAP_OPT_DELTA_16_BITS   14

Definition at line 39 of file coap_option.h.

◆ COAP_OPT_DELTA_8_BITS

#define COAP_OPT_DELTA_8_BITS   13

Definition at line 38 of file coap_option.h.

◆ COAP_OPT_DELTA_MINUS_16_BITS

#define COAP_OPT_DELTA_MINUS_16_BITS   269

Definition at line 42 of file coap_option.h.

◆ COAP_OPT_DELTA_MINUS_8_BITS

#define COAP_OPT_DELTA_MINUS_8_BITS   13

Definition at line 41 of file coap_option.h.

◆ COAP_OPT_DELTA_RESERVED

#define COAP_OPT_DELTA_RESERVED   15

Definition at line 40 of file coap_option.h.

◆ COAP_OPT_LEN_16_BITS

#define COAP_OPT_LEN_16_BITS   14

Definition at line 46 of file coap_option.h.

◆ COAP_OPT_LEN_8_BITS

#define COAP_OPT_LEN_8_BITS   13

Definition at line 45 of file coap_option.h.

◆ COAP_OPT_LEN_MINUS_16_BITS

#define COAP_OPT_LEN_MINUS_16_BITS   269

Definition at line 49 of file coap_option.h.

◆ COAP_OPT_LEN_MINUS_8_BITS

#define COAP_OPT_LEN_MINUS_8_BITS   13

Definition at line 48 of file coap_option.h.

◆ COAP_OPT_LEN_RESERVED

#define COAP_OPT_LEN_RESERVED   15

Definition at line 47 of file coap_option.h.

◆ COAP_SET_BLOCK_M

#define COAP_SET_BLOCK_M (   value,
  m 
)    value = ((value) & ~0x08U) | (((m) << 3U) & 0x08U)

Definition at line 62 of file coap_option.h.

◆ COAP_SET_BLOCK_NUM

#define COAP_SET_BLOCK_NUM (   value,
  n 
)    value = ((value) & 0x0FU) | ((n) << 4U)

Definition at line 60 of file coap_option.h.

◆ COAP_SET_BLOCK_SZX

#define COAP_SET_BLOCK_SZX (   value,
  s 
)    value = ((value) & ~0x07U) | ((s) & 0x07U)

Definition at line 64 of file coap_option.h.

Enumeration Type Documentation

◆ 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 156 of file coap_option.h.

◆ CoapContentFormat

Content-Format option.

Enumerator
COAP_CONTENT_FORMAT_TEXT_PLAIN 
COAP_CONTENT_FORMAT_APP_LINK_FORMAT 
COAP_CONTENT_FORMAT_APP_XML 
COAP_CONTENT_FORMAT_APP_OCTET_STREAM 
COAP_CONTENT_FORMAT_APP_EXI 
COAP_CONTENT_FORMAT_APP_JSON 

Definition at line 141 of file coap_option.h.

◆ CoapObserveOption

Observe option.

Enumerator
COAP_OBSERVE_REGISTER 
COAP_OBSERVE_DEREGISTER 

Definition at line 130 of file coap_option.h.

◆ 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 117 of file coap_option.h.

◆ CoapOptionNumber

CoAP options.

Enumerator
COAP_OPT_IF_MATCH 
COAP_OPT_URI_HOST 
COAP_OPT_ETAG 
COAP_OPT_IF_NONE_MATCH 
COAP_OPT_OBSERVE 
COAP_OPT_URI_PORT 
COAP_OPT_LOCATION_PATH 
COAP_OPT_URI_PATH 
COAP_OPT_CONTENT_FORMAT 
COAP_OPT_MAX_AGE 
COAP_OPT_URI_QUERY 
COAP_OPT_ACCEPT 
COAP_OPT_LOCATION_QUERY 
COAP_OPT_BLOCK2 
COAP_OPT_BLOCK1 
COAP_OPT_SIZE2 
COAP_OPT_PROXY_URI 
COAP_OPT_PROXY_SCHEME 
COAP_OPT_SIZE1 
COAP_OPT_NO_RESPONSE 

Definition at line 88 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]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.