11 #if defined(HAVE_ASSERT_H) && !defined(assert) 
   18 #define min(a,b) ((a) < (b) ? (a) : (b)) 
   62   size_t start, want, avail;
 
   69     warn(
"coap_write_block_opt: skipped unknown option\n");
 
   73   start = block->
num << (block->
szx + 4);
 
   74   if (data_length <= start) {
 
   75     debug(
"illegal block requested\n");
 
   80   want = 1 << (block->
szx + 4);
 
   84     block->
m = want < data_length - start;
 
   91     if (data_length - start <= avail) {
 
  100     debug(
"not enough space, even the smallest block does not fit");
 
  103       debug(
"decrease block size for %d to %d\n", avail, 
coap_fls(avail) - 5);
 
  107       block->
num <<= szx - block->
szx;
 
  122            unsigned int block_num, 
unsigned char block_szx) {
 
  124   start = block_num << (block_szx + 4);
 
  130                min(len - start, (
unsigned int)(1 << (block_szx + 4))),
 
int coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block)
Initializes block from pdu. 
 
unsigned int coap_opt_block_num(const coap_opt_t *block_opt)
Returns the value of field num in the given block option block_opt. 
 
int coap_write_block_opt(coap_block_t *block, unsigned short type, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type type to message pdu. 
 
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. 
 
int coap_fls(unsigned int i)
 
Header structure for CoAP PDUs. 
 
unsigned int coap_encode_var_bytes(unsigned char *buf, unsigned int val)
Encodes multiple-length byte sequences. 
 
#define COAP_OPT_BLOCK_LAST(opt)
Returns the value of the least significant byte of a Block option opt. 
 
size_t max_size
allocated storage for options and data 
 
int coap_add_block(coap_pdu_t *pdu, unsigned int len, const unsigned char *data, unsigned int block_num, unsigned char block_szx)
Adds the block_num block of size 1 << (block_szx + 4) from source data to pdu. 
 
Iterator to run through PDU options. 
 
size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len, const unsigned char *data)
de-duplicate code with coap_add_option_later 
 
int coap_add_data(coap_pdu_t *pdu, unsigned int len, const unsigned char *data)
Adds given data to the pdu that is passed as first parameter. 
 
#define COAP_OPTION_BLOCK2
 
Structure of Block options. 
 
#define COAP_OPT_LENGTH(opt)
 
#define COAP_OPT_BLOCK_SZX(opt)
Returns the value of the SZX-field of a Block option opt. 
 
unsigned char coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
 
#define COAP_OPT_BLOCK_MORE(opt)
Returns the value of the More-bit of a Block option opt. 
 
unsigned int coap_decode_var_bytes(unsigned char *buf, unsigned int len)
Decodes multiple-length byte sequences. 
 
unsigned short coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option. 
 
#define COAP_OPT_VALUE(opt)
 
unsigned int m
1 if more blocks follow, 0 otherwise 
 
unsigned int szx
block size 
 
unsigned int num
block number