13 #if defined(HAVE_ASSERT_H) && !defined(assert) 
   26   if (pdu && pdu->
hdr && 
 
   28        < (
unsigned char *)pdu->
hdr + pdu->
length)) {
 
   42   assert(opt); assert(result);
 
   44 #define ADVANCE_OPT(o,e,step) if ((e) < step) {         \ 
   45     debug("cannot advance opt past end\n");         \ 
   49     (o) = ((unsigned char *)(o)) + step;            \ 
   55   result->
delta = (*opt & 0xf0) >> 4;
 
   56   result->
length = *opt & 0x0f;
 
   58   switch(result->
delta) {
 
   61       debug(
"ignored reserved option delta 15\n");
 
   68     result->
delta = ((*opt & 0xff) << 8) + 269;
 
   69     if (result->
delta < 269) {
 
   70       debug(
"delta too large\n");
 
   76     result->
delta += *opt & 0xff;
 
   85     debug(
"found reserved option length 15\n");
 
   92     result->
length = ((*opt & 0xff) << 8) + 269;
 
   96     result->
length += *opt & 0xff;
 
  106   result->
value = (
unsigned char *)opt;
 
  107   if (length < result->length) {
 
  108     debug(
"invalid option length\n");
 
  114   return (opt + result->
length) - opt_start;
 
  178       assert(optsize <= oi->length);
 
  223   n = (*opt++ & 0xf0) >> 4;
 
  227     warn(
"coap_opt_delta: illegal option delta\n");
 
  236     n = ((*opt++ & 0xff) << 8) + 269;
 
  250   unsigned short length;
 
  252   length = *opt & 0x0f;
 
  253   switch (*opt & 0xf0) {
 
  255     debug(
"illegal option delta\n");
 
  269     debug(
"illegal option length\n");
 
  272     length = (*opt++ << 8) + 269;
 
  287   switch (*opt & 0xf0) {
 
  289     debug(
"illegal option delta\n");
 
  301   switch (*opt & 0x0f) {
 
  303     debug(
"illegal option length\n");
 
  315   return (
unsigned char *)opt + ofs;
 
  328            unsigned short delta, 
size_t length) {
 
  338   } 
else if (delta < 270) {
 
  340       debug(
"insufficient space to encode option delta %d", delta);
 
  345     opt[++skip] = delta - 13;
 
  348       debug(
"insufficient space to encode option delta %d", delta);
 
  353     opt[++skip] = ((delta - 269) >> 8) & 0xff;
 
  354     opt[++skip] = (delta - 269) & 0xff;    
 
  358     opt[0] |= length & 0x0f;
 
  359   } 
else if (length < 270) {
 
  360     if (maxlen < skip + 1) {
 
  361       debug(
"insufficient space to encode option length %d", length);
 
  366     opt[++skip] = length - 13;
 
  368     if (maxlen < skip + 2) {
 
  369       debug(
"insufficient space to encode option delta %d", delta);
 
  374     opt[++skip] = ((length - 269) >> 8) & 0xff;
 
  375     opt[++skip] = (length - 269) & 0xff;    
 
  383         const unsigned char *val, 
size_t length) {
 
  390     debug(
"coap_opt_encode: cannot set option header\n");
 
  397   if (maxlen < length) {
 
  398     debug(
"coap_opt_encode: option too large for buffer\n");
 
  403     memcpy(opt, val, length);
 
unsigned char * coap_opt_value(coap_opt_t *opt)
Returns a pointer to the value of the given option. 
unsigned short length
PDU length (including header, options, data) 
coap_opt_t * coap_check_option(coap_pdu_t *pdu, unsigned char type, coap_opt_iterator_t *oi)
Retrieves the first option of type type from pdu. 
size_t length
remaining length of PDU 
static int coap_option_getb(const coap_opt_filter_t filter, unsigned short type)
Gets 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_opt_filter_t filter
option filter 
helpers for handling options in CoAP PDUs 
static int coap_option_setb(coap_opt_filter_t filter, unsigned short type)
Sets the corresponding bit for type in filter. 
static int opt_finished(coap_opt_iterator_t *oi)
Header structure for CoAP PDUs. 
coap_opt_iterator_t * coap_option_iterator_init(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...
Representation of CoAP 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. 
unsigned short coap_opt_delta(const coap_opt_t *opt)
Decodes the delta value of the next option. 
Iterator to run through PDU options. 
unsigned int bad
iterator object is ok if not set 
unsigned char coap_opt_filter_t[(COAP_MAX_OPT >> 3)+1]
Fixed-size bit-vector we use for option filtering. 
unsigned int filtered
denotes whether or not filter is used 
unsigned short type
decoded option type 
static void coap_option_filter_clear(coap_opt_filter_t f)
Clears filter f. 
#define COAP_PAYLOAD_START
#define ADVANCE_OPT(o, e, step)
unsigned int token_length
size_t coap_opt_setheader(coap_opt_t *opt, size_t maxlen, unsigned short delta, size_t length)
Encodes the given delta and length values into opt. 
coap_opt_t * options_start(coap_pdu_t *pdu)
Calculates the beginning of the PDU's option section. 
unsigned char coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
size_t coap_opt_size(const coap_opt_t *opt)
Returns the size of the given option, taking into account a possible option jump. ...
unsigned short coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option. 
size_t coap_opt_encode(coap_opt_t *opt, size_t maxlen, unsigned short delta, const unsigned char *val, size_t length)
Encodes option with given delta into opt.