11 #include "coap_config.h" 13 #if defined(HAVE_ASSERT_H) && !defined(assert) 27 #define ADVANCE_OPT(o,e,step) if ((e) < step) { \ 28 coap_log(LOG_DEBUG, "cannot advance opt past end\n"); \ 39 #define ADVANCE_OPT_CHECK(o,e,step) do { \ 40 ADVANCE_OPT(o,e,step); \ 55 result->
delta = (*opt & 0xf0) >> 4;
56 result->
length = *opt & 0x0f;
58 switch(result->
delta) {
69 result->
delta = ((*opt & 0xff) << 8) + 269;
70 if (result->
delta < 269) {
77 result->
delta += *opt & 0xff;
93 result->
length = ((*opt & 0xff) << 8) + 269;
97 result->
length += *opt & 0xff;
109 if (length < result->length) {
115 #undef ADVANCE_OPT_CHECK 117 return (opt + result->
length) - opt_start;
223 n = (*opt++ & 0xf0) >> 4;
236 n = ((*opt++ & 0xff) << 8) + 269;
252 length = *opt & 0x0f;
253 switch (*opt & 0xf0) {
274 length = (*opt++ << 8) + 269;
289 switch (*opt & 0xf0) {
303 switch (*opt & 0x0f) {
317 return (
const uint8_t *)opt + ofs;
330 uint16_t delta,
size_t length) {
340 }
else if (delta < 269) {
357 opt[++skip] = ((delta - 269) >> 8) & 0xff;
358 opt[++skip] = (delta - 269) & 0xff;
362 opt[0] |= length & 0x0f;
363 }
else if (length < 269) {
364 if (maxlen < skip + 2) {
373 if (maxlen < skip + 3) {
380 opt[++skip] = ((length - 269) >> 8) & 0xff;
381 opt[++skip] = (length - 269) & 0xff;
424 if (maxlen < length) {
430 memcpy(opt, val, length);
439 #define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1) 441 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1)) 479 uint16_t nr, mask = 0;
486 if (((of->
mask & nr) > 0) && (of->
long_opts[lindex] == type)) {
498 nr <<= 1, lindex++) {
500 if (((of->
mask & nr) > 0) && (of->
short_opts[lindex] == (type & 0xff))) {
528 of->
mask |= 1 << (lindex - 1);
564 memcpy(node->
data, data, length);
578 return a < b ? -1 : 1;
587 if (options && *options) {
#define LL_FOREACH(head, el)
size_t length
the option value length
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
COAP_STATIC_INLINE int coap_option_setb(coap_opt_filter_t filter, uint16_t type)
Sets the corresponding bit for type in filter.
#define COAP_OPT_FILTER_LONG
The number of option types above 255 that can be stored in an option filter.
int coap_insert_optlist(coap_optlist_t **head, coap_optlist_t *node)
Adds optlist to the given optlist_chain.
COAP_STATIC_INLINE int opt_finished(coap_opt_iterator_t *oi)
static int coap_internal_delete(coap_optlist_t *node)
size_t length
remaining length of PDU
int coap_option_filter_set(coap_opt_filter_t filter, uint16_t type)
Sets the corresponding entry for type in filter.
filter_op_t
Operation specifiers for coap_filter_op().
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
coap_opt_filter_t filter
option filter
int coap_fls(unsigned int i)
Helpers for handling options in CoAP PDUs.
uint16_t type
decoded option type
#define COAP_OPT_FILTER_SHORT
The number of option types below 256 that can be stored in an option filter.
#define ADVANCE_OPT_CHECK(o, e, step)
void coap_delete_optlist(coap_optlist_t *queue)
Removes all entries from the optlist_chain, freeing off their memory usage.
Representation of chained list of CoAP options to install.
size_t coap_opt_encode_size(uint16_t delta, size_t length)
Compute storage bytes needed for an option with given delta and length.
coap_opt_t * coap_check_option(coap_pdu_t *pdu, uint16_t type, coap_opt_iterator_t *oi)
Retrieves the first option of type type from pdu.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
int coap_option_filter_get(coap_opt_filter_t filter, uint16_t type)
Checks if type is contained in filter.
uint16_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
Representation of CoAP options.
uint16_t coap_opt_delta(const coap_opt_t *opt)
Decodes the delta value of the next option.
uint8_t * data
the option data
size_t used_size
used bytes of storage for token, options and payload
uint8_t * token
first byte of token, if any, or options
coap_opt_t * next_option
pointer to the unparsed next option
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.
Iterator to run through PDU options.
#define LL_APPEND(head, add)
unsigned int bad
iterator object is ok if not set
int coap_option_filter_unset(coap_opt_filter_t filter, uint16_t type)
Clears the corresponding entry for type in filter.
static int coap_option_filter_op(coap_opt_filter_t filter, uint16_t type, enum filter_op_t op)
Applies op on filter with respect to type.
size_t coap_add_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Adds option of given type to pdu that is passed as first parameter.
COAP_STATIC_INLINE void coap_option_filter_clear(coap_opt_filter_t f)
Clears filter f.
uint16_t number
the option number (no delta coding)
#define COAP_STATIC_INLINE
unsigned int filtered
denotes whether or not filter is used
uint16_t coap_opt_filter_t[COAP_OPT_FILTER_SIZE]
Fixed-size vector we use for option filtering.
COAP_STATIC_INLINE int coap_option_getb(coap_opt_filter_t filter, uint16_t type)
Gets the corresponding bit for type in filter.
size_t length
length of payload
#define LL_SORT(list, cmp)
#define COAP_PAYLOAD_START
COAP_STATIC_INLINE int is_long_option(uint16_t type)
Returns true iff type denotes an option type larger than 255.
size_t coap_opt_encode(coap_opt_t *opt, size_t maxlen, uint16_t delta, const uint8_t *val, size_t length)
Encodes option with given delta into opt.
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.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
#define ADVANCE_OPT(o, e, step)
#define LL_FOREACH_SAFE(head, el, tmp)
uint16_t long_opts[COAP_OPT_FILTER_LONG]
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **options)
The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then ...
uint8_t short_opts[COAP_OPT_FILTER_SHORT]
static int order_opts(void *a, void *b)
#define coap_log(level,...)
Logging function.
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_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
coap_optlist_t * coap_new_optlist(uint16_t number, size_t length, const uint8_t *data)
Create a new optlist entry.
uint8_t token_length
length of Token
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...