libcoap 4.3.5-develop-ea01661
Loading...
Searching...
No Matches
coap_option.h
Go to the documentation of this file.
1/*
2 * coap_option.h -- helpers for handling options in CoAP PDUs
3 *
4 * Copyright (C) 2010-2013,2022-2025 Olaf Bergmann <bergmann@tzi.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
17#ifndef COAP_OPTION_H_
18#define COAP_OPTION_H_
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24typedef uint16_t coap_option_num_t;
25
30typedef uint8_t coap_opt_t;
31#define PCHAR(p) ((coap_opt_t *)(p))
32
36typedef struct {
37 uint16_t delta;
38 size_t length;
39 const uint8_t *value;
41
54size_t coap_opt_parse(const coap_opt_t *opt,
55 size_t length,
56 coap_option_t *result);
57
67size_t coap_opt_size(const coap_opt_t *opt);
68
82#define COAP_OPT_FILTER_SHORT 6
83
90#define COAP_OPT_FILTER_LONG 2
91
92/* Ensure that COAP_OPT_FILTER_SHORT and COAP_OPT_FILTER_LONG are set
93 * correctly. */
94#if (COAP_OPT_FILTER_SHORT + COAP_OPT_FILTER_LONG > 16)
95#error COAP_OPT_FILTER_SHORT + COAP_OPT_FILTER_LONG must be less or equal 16
96#endif /* (COAP_OPT_FILTER_SHORT + COAP_OPT_FILTER_LONG > 16) */
97
98/*
99 * mask contains a bit vector that indicates which fields in the long_opts[]
100 * and subsequent short_opts[] are used. The first COAP_OPT_FILTER_LONG bits
101 * correspond to the long option types that are stored in long_opts[]
102 * elements. The next COAP_OPT_FILTER_SHORT bits correspond to the short
103 * option types that are stored in short_opts[].
104 */
110
112#define COAP_OPT_ALL NULL
113
120
132
143 coap_option_num_t number);
144
155
180
199 const coap_opt_filter_t *filter);
200
218
233 coap_option_num_t number,
235
251 size_t maxlen,
252 uint16_t delta,
253 size_t length);
254
264size_t coap_opt_encode_size(uint16_t delta, size_t length);
265
281size_t coap_opt_encode(coap_opt_t *opt,
282 size_t n,
283 uint16_t delta,
284 const uint8_t *val,
285 size_t length);
286
300uint32_t coap_opt_length(const coap_opt_t *opt);
301
311const uint8_t *coap_opt_value(const coap_opt_t *opt);
312
329typedef struct coap_optlist_t {
331 uint16_t number;
332 size_t length;
333 uint8_t *data;
335
352 size_t length,
353 const uint8_t *data);
354
364int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **optlist_chain);
365
377int coap_insert_optlist(coap_optlist_t **optlist_chain,
378 coap_optlist_t *optlist);
379
386void coap_delete_optlist(coap_optlist_t *optlist_chain);
387
403coap_option_setb(coap_opt_filter_t *filter, uint16_t type) {
404 return coap_option_filter_set(filter, type) ? 1 : -1;
405}
406
419coap_option_clrb(coap_opt_filter_t *filter, uint16_t type) {
420 return coap_option_filter_unset(filter, type) ? 1 : -1;
421}
422
435coap_option_getb(coap_opt_filter_t *filter, uint16_t type) {
436 return coap_option_filter_get(filter, type);
437}
438
439#ifdef __cplusplus
440}
441#endif
442
443#endif /* COAP_OPTION_H_ */
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.
Definition coap_option.c:41
size_t coap_opt_size(const coap_opt_t *opt)
Returns the size of the given option, taking into account a possible option jump.
uint16_t coap_option_num_t
Definition coap_option.h:24
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
Definition coap_option.h:30
COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_clrb(coap_opt_filter_t *filter, uint16_t type)
Clears the corresponding bit for type in filter.
COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_getb(coap_opt_filter_t *filter, uint16_t type)
Gets the corresponding bit for type in filter.
COAP_STATIC_INLINE COAP_DEPRECATED int coap_option_setb(coap_opt_filter_t *filter, uint16_t type)
Sets the corresponding bit for type in filter.
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
coap_optlist_t * coap_new_optlist(uint16_t number, size_t length, const uint8_t *data)
Create a new optlist entry.
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.
coap_opt_iterator_t * coap_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.
void coap_delete_optlist(coap_optlist_t *optlist_chain)
Removes all entries from the optlist_chain, freeing off their memory usage.
size_t coap_opt_encode_size(uint16_t delta, size_t length)
Compute storage bytes needed for an option with given delta and length.
#define COAP_OPT_FILTER_SHORT
The number of option types below 256 that can be stored in an option filter.
Definition coap_option.h:82
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_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 ...
#define COAP_OPT_FILTER_LONG
The number of option types above 255 that can be stored in an option filter.
Definition coap_option.h:90
void coap_option_filter_clear(coap_opt_filter_t *filter)
Clears filter filter.
coap_opt_t * coap_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.
int coap_insert_optlist(coap_optlist_t **optlist_chain, coap_optlist_t *optlist)
Adds optlist to the given optlist_chain.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
int coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t number)
Checks if number is contained in filter.
int coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t number)
Sets the corresponding entry for number in filter.
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.
#define COAP_DEPRECATED
Definition libcoap.h:66
#define COAP_STATIC_INLINE
Definition libcoap.h:57
uint8_t short_opts[COAP_OPT_FILTER_SHORT]
uint16_t long_opts[COAP_OPT_FILTER_LONG]
Iterator to run through PDU options.
coap_opt_t * next_option
pointer to the unparsed next option
coap_opt_filter_t filter
option filter
unsigned int bad
iterator object is ok if not set
size_t length
remaining length of PDU
unsigned int filtered
denotes whether or not filter is used
coap_option_num_t number
decoded option number
Representation of CoAP options.
Definition coap_option.h:36
const uint8_t * value
Definition coap_option.h:39
uint16_t delta
Definition coap_option.h:37
Representation of chained list of CoAP options to install.
uint16_t number
the option number (no delta coding)
size_t length
the option value length
uint8_t * data
the option data
struct coap_optlist_t * next
next entry in the optlist chain
structure for CoAP PDUs