libcoap 4.3.5-develop-4c3f4af
Loading...
Searching...
No Matches
coap_option.h File Reference

Helpers for handling options in CoAP PDUs. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  coap_option_t
 Representation of CoAP options. More...
struct  coap_opt_filter_t
struct  coap_opt_iterator_t
 Iterator to run through PDU options. More...
struct  coap_optlist_t
 Representation of chained list of CoAP options to install. More...

Macros

#define NULL   0
#define COAP_OPTION_CONTENT_TYPE   COAP_OPTION_CONTENT_FORMAT
#define COAP_MAX_OPT   65534
 the highest option number we know
#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE   COAP_SIG_OPT_MAX_MESSAGE_SIZE
#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER   COAP_SIG_OPT_BLOCK_WISE_TRANSFER
#define COAP_SIGNALING_OPTION_EXTENDED_TOKEN_LENGTH   COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH
#define COAP_SIGNALING_OPTION_CUSTODY   COAP_SIG_OPT_CUSTODY
#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS   COAP_SIG_OPT_ALTERNATIVE_ADDRESS
#define COAP_SIGNALING_OPTION_HOLD_OFF   COAP_SIG_OPT_HOLD_OFF
#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION   COAP_SIG_OPT_BAD_CSM_OPTION
#define PCHAR(p)
#define COAP_OPT_FILTER_SHORT   6
 The number of option types below 256 that can be stored in an option filter.
#define COAP_OPT_FILTER_LONG   2
 The number of option types above 255 that can be stored in an option filter.
#define COAP_OPT_ALL   NULL
 Pre-defined filter that includes all options.

Typedefs

typedef uint16_t coap_option_num_t
typedef enum coap_code_opt_num_t coap_code_opt_num_t
typedef enum coap_sig_csm_opt_t coap_sig_csm_opt_t
typedef enum coap_sig_ping_opt_t coap_sig_ping_opt_t
typedef enum coap_sig_release_opt_t coap_sig_release_opt_t
typedef enum coap_sig_abort_opt_t coap_sig_abort_opt_t
typedef uint8_t coap_opt_t
 Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffer may cause bus error on certain platforms.
typedef struct coap_opt_filter_t coap_opt_filter_t
typedef struct coap_optlist_t coap_optlist_t
 Representation of chained list of CoAP options to install.

Enumerations

enum  coap_code_opt_num_t {
  COAP_OPTION_IF_MATCH = 1 , COAP_OPTION_URI_HOST = 3 , COAP_OPTION_ETAG = 4 , COAP_OPTION_IF_NONE_MATCH = 5 ,
  COAP_OPTION_OBSERVE = 6 , COAP_OPTION_URI_PORT = 7 , COAP_OPTION_LOCATION_PATH = 8 , COAP_OPTION_OSCORE = 9 ,
  COAP_OPTION_URI_PATH = 11 , COAP_OPTION_CONTENT_FORMAT = 12 , COAP_OPTION_URI_PATH_ABB = 13 , COAP_OPTION_MAXAGE = 14 ,
  COAP_OPTION_URI_QUERY = 15 , COAP_OPTION_HOP_LIMIT = 16 , COAP_OPTION_ACCEPT = 17 , COAP_OPTION_Q_BLOCK1 = 19 ,
  COAP_OPTION_LOCATION_QUERY = 20 , COAP_OPTION_EDHOC = 21 , COAP_OPTION_BLOCK2 = 23 , COAP_OPTION_BLOCK1 = 27 ,
  COAP_OPTION_SIZE2 = 28 , COAP_OPTION_Q_BLOCK2 = 31 , COAP_OPTION_PROXY_URI = 35 , COAP_OPTION_PROXY_SCHEME = 39 ,
  COAP_OPTION_SIZE1 = 60 , COAP_OPTION_ECHO = 252 , COAP_OPTION_NORESPONSE = 258 , COAP_OPTION_RTAG = 292
}
enum  coap_sig_csm_opt_t { COAP_SIG_OPT_MAX_MESSAGE_SIZE = 2 , COAP_SIG_OPT_BLOCK_WISE_TRANSFER = 4 , COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH = 6 }
enum  coap_sig_ping_opt_t { COAP_SIG_OPT_CUSTODY = 2 }
enum  coap_sig_release_opt_t { COAP_SIG_OPT_ALTERNATIVE_ADDRESS = 2 , COAP_SIG_OPT_HOLD_OFF = 4 }
enum  coap_sig_abort_opt_t { COAP_SIG_OPT_BAD_CSM_OPTION = 2 }

Functions

size_t coap_opt_parse (const coap_opt_t *opt, size_t length, coap_option_t *result)
 Parses the option pointed to by opt into result.
size_t coap_opt_size (const coap_opt_t *opt)
 Returns the size of the given option, taking into account a possible option jump.
void coap_option_filter_clear (coap_opt_filter_t *filter)
 Clears filter filter.
int coap_option_filter_set (coap_opt_filter_t *filter, coap_option_num_t number)
 Sets the corresponding entry for number in filter.
int coap_option_filter_unset (coap_opt_filter_t *filter, coap_option_num_t number)
 Clears the corresponding entry for number in filter.
int coap_option_filter_get (coap_opt_filter_t *filter, coap_option_num_t number)
 Checks if number is contained in filter.
coap_opt_iterator_tcoap_option_iterator_init (const coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t *filter)
 Initializes the given option iterator oi to point to the beginning of the pdu's option list.
coap_opt_tcoap_option_next (coap_opt_iterator_t *oi)
 Updates the iterator oi to point to the next option.
coap_opt_tcoap_check_option (const coap_pdu_t *pdu, coap_option_num_t number, coap_opt_iterator_t *oi)
 Retrieves the first option of number number from pdu.
size_t coap_opt_setheader (coap_opt_t *opt, size_t maxlen, uint16_t delta, size_t length)
 Encodes the given delta and length values into opt.
size_t coap_opt_encode_size (uint16_t delta, size_t length)
 Compute storage bytes needed for an option with given delta and length.
size_t coap_opt_encode (coap_opt_t *opt, size_t n, uint16_t delta, const uint8_t *val, size_t length)
 Encodes option with given delta into opt.
uint32_t coap_opt_length (const coap_opt_t *opt)
 Returns the length of the given option.
const uint8_t * coap_opt_value (const coap_opt_t *opt)
 Returns a pointer to the value of the given option.
coap_optlist_tcoap_new_optlist (coap_option_num_t number, size_t length, const uint8_t *data)
 Create a new optlist entry.
int coap_add_optlist_pdu (coap_pdu_t *pdu, coap_optlist_t **optlist_chain)
 The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then added to the pdu.
int coap_sort_optlist (coap_optlist_t **options)
 Sorts the optlist chain.
int coap_insert_optlist (coap_optlist_t **optlist_chain, coap_optlist_t *optlist)
 Adds optlist to the given optlist_chain.
void coap_delete_optlist (coap_optlist_t *optlist_chain)
 Removes all entries from the optlist_chain, freeing off their memory usage.
COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_setb (coap_opt_filter_t *filter, coap_option_num_t type)
 Sets the corresponding bit for type in filter.
COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_clrb (coap_opt_filter_t *filter, coap_option_num_t type)
 Clears the corresponding bit for type in filter.
COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_getb (coap_opt_filter_t *filter, coap_option_num_t type)
 Gets the corresponding bit for type in filter.

Detailed Description

Helpers for handling options in CoAP PDUs.

Definition in file coap_option.h.

Macro Definition Documentation

◆ COAP_MAX_OPT

#define COAP_MAX_OPT   65534

the highest option number we know

Definition at line 107 of file coap_option.h.

◆ COAP_OPTION_CONTENT_TYPE

#define COAP_OPTION_CONTENT_TYPE   COAP_OPTION_CONTENT_FORMAT

Definition at line 102 of file coap_option.h.

◆ COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS

#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS   COAP_SIG_OPT_ALTERNATIVE_ADDRESS

Definition at line 140 of file coap_option.h.

◆ COAP_SIGNALING_OPTION_BAD_CSM_OPTION

#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION   COAP_SIG_OPT_BAD_CSM_OPTION

Definition at line 142 of file coap_option.h.

◆ COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER

#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER   COAP_SIG_OPT_BLOCK_WISE_TRANSFER

Definition at line 137 of file coap_option.h.

◆ COAP_SIGNALING_OPTION_CUSTODY

#define COAP_SIGNALING_OPTION_CUSTODY   COAP_SIG_OPT_CUSTODY

Definition at line 139 of file coap_option.h.

◆ COAP_SIGNALING_OPTION_EXTENDED_TOKEN_LENGTH

#define COAP_SIGNALING_OPTION_EXTENDED_TOKEN_LENGTH   COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH

Definition at line 138 of file coap_option.h.

◆ COAP_SIGNALING_OPTION_HOLD_OFF

#define COAP_SIGNALING_OPTION_HOLD_OFF   COAP_SIG_OPT_HOLD_OFF

Definition at line 141 of file coap_option.h.

◆ COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE

#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE   COAP_SIG_OPT_MAX_MESSAGE_SIZE

Definition at line 136 of file coap_option.h.

◆ NULL

#define NULL   0

Definition at line 30 of file coap_option.h.

◆ PCHAR

#define PCHAR ( p)
Value:
((coap_opt_t *)(p))
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...

Definition at line 149 of file coap_option.h.

Typedef Documentation

◆ coap_code_opt_num_t

◆ coap_opt_t

typedef uint8_t coap_opt_t

Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffer may cause bus error on certain platforms.

Definition at line 148 of file coap_option.h.

◆ coap_option_num_t

typedef uint16_t coap_option_num_t

Definition at line 37 of file coap_option.h.

◆ coap_sig_abort_opt_t

◆ coap_sig_csm_opt_t

◆ coap_sig_ping_opt_t

◆ coap_sig_release_opt_t

Enumeration Type Documentation

◆ coap_code_opt_num_t

Enumerator
COAP_OPTION_IF_MATCH 
COAP_OPTION_URI_HOST 
COAP_OPTION_ETAG 
COAP_OPTION_IF_NONE_MATCH 
COAP_OPTION_OBSERVE 
COAP_OPTION_URI_PORT 
COAP_OPTION_LOCATION_PATH 
COAP_OPTION_OSCORE 
COAP_OPTION_URI_PATH 
COAP_OPTION_CONTENT_FORMAT 
COAP_OPTION_URI_PATH_ABB 
COAP_OPTION_MAXAGE 
COAP_OPTION_URI_QUERY 
COAP_OPTION_HOP_LIMIT 
COAP_OPTION_ACCEPT 
COAP_OPTION_Q_BLOCK1 
COAP_OPTION_LOCATION_QUERY 
COAP_OPTION_EDHOC 
COAP_OPTION_BLOCK2 
COAP_OPTION_BLOCK1 
COAP_OPTION_SIZE2 
COAP_OPTION_Q_BLOCK2 
COAP_OPTION_PROXY_URI 
COAP_OPTION_PROXY_SCHEME 
COAP_OPTION_SIZE1 
COAP_OPTION_ECHO 
COAP_OPTION_NORESPONSE 
COAP_OPTION_RTAG 

Definition at line 70 of file coap_option.h.

◆ coap_sig_abort_opt_t

Enumerator
COAP_SIG_OPT_BAD_CSM_OPTION 

Definition at line 131 of file coap_option.h.

◆ coap_sig_csm_opt_t

Enumerator
COAP_SIG_OPT_MAX_MESSAGE_SIZE 
COAP_SIG_OPT_BLOCK_WISE_TRANSFER 
COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH 

Definition at line 113 of file coap_option.h.

◆ coap_sig_ping_opt_t

Enumerator
COAP_SIG_OPT_CUSTODY 

Definition at line 120 of file coap_option.h.

◆ coap_sig_release_opt_t

Enumerator
COAP_SIG_OPT_ALTERNATIVE_ADDRESS 
COAP_SIG_OPT_HOLD_OFF 

Definition at line 125 of file coap_option.h.

Function Documentation

◆ coap_opt_parse()

size_t coap_opt_parse ( const coap_opt_t * opt,
size_t length,
coap_option_t * result )

Parses the option pointed to by opt into result.

This function returns the number of bytes that have been parsed, or 0 on error. An error is signaled when illegal delta or length values are encountered or when option parsing would result in reading past the option (i.e. beyond opt + length).

Parameters
optThe beginning of the option to parse.
lengthThe maximum length of opt.
resultA pointer to the coap_option_t structure that is filled with actual values iff coap_opt_parse() > 0.
Returns
The number of bytes parsed or 0 on error.

Definition at line 41 of file coap_option.c.

Here is the caller graph for this function:

◆ coap_opt_size()

size_t coap_opt_size ( const coap_opt_t * opt)

Returns the size of the given option, taking into account a possible option jump.

Parameters
optAn option jump or the beginning of the option.
Returns
The number of bytes between opt and the end of the option starting at opt. In case of an error, this function returns 0 as options need at least one byte storage space.

Definition at line 284 of file coap_option.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ coap_option_clrb()

COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_clrb ( coap_opt_filter_t * filter,
coap_option_num_t type )

Clears the corresponding bit for type in filter.

This function returns 1 if bit was cleared or -1 on error (i.e. bit not set).

Deprecated
Use coap_option_filter_unset() instead.
Parameters
filterThe filter object to change.
typeThe type for which the bit should be cleared.
Returns
1 if bit was set, -1 otherwise.

Definition at line 547 of file coap_option.h.

Here is the call graph for this function:

◆ coap_option_getb()

COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_getb ( coap_opt_filter_t * filter,
coap_option_num_t type )

Gets the corresponding bit for type in filter.

This function returns 1 if the bit is set 0 if not.

Deprecated
Use coap_option_filter_get() instead.
Parameters
filterThe filter object to read bit from.
typeThe type for which the bit should be read.
Returns
1 if bit was set, 0 if not.

Definition at line 563 of file coap_option.h.

Here is the call graph for this function:

◆ coap_option_setb()

COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_setb ( coap_opt_filter_t * filter,
coap_option_num_t type )

Sets the corresponding bit for type in filter.

This function returns 1 if bit was set or -1 on error (i.e. when the given type does not fit in the filter).

Deprecated
Use coap_option_filter_set() instead.
Parameters
filterThe filter object to change.
typeThe type for which the bit should be set.
Returns
1 if bit was set, -1 otherwise.

Definition at line 531 of file coap_option.h.

Here is the call graph for this function: