12 #define min(a,b) ((a) < (b) ? (a) : (b)) 66 size_t start, want, avail;
71 start = block->
num << (block->
szx + 4);
72 if (data_length <= start) {
79 want = (size_t)1 << (block->
szx + 4);
83 block->
m = want < data_length - start;
90 if (data_length - start <= avail) {
101 "not enough space, even the smallest block does not fit");
104 newBlockSize =
coap_flsll((
long long)avail) - 5;
106 "decrease block size for %zu to %d\n", avail, newBlockSize);
108 block->
szx = newBlockSize;
110 block->
num <<= szx - block->
szx;
126 unsigned int block_num,
unsigned char block_szx) {
128 start = block_num << (block_szx + 4);
134 min(len - start, (1U << (block_szx + 4))),
153 unsigned char buf[4];
155 int block2_requested = 0;
164 block2_requested = 1;
165 if (length <= (block2.
num << (block2.
szx + 4))) {
168 length >> (block2.
szx + 4));
174 else if (subscription && subscription->
has_block2) {
175 block2 = subscription->
block2;
177 block2_requested = 1;
182 memset(etag, 0,
sizeof(etag));
186 if ((block2.
num == 0) && subscription) {
204 if (block2_requested) {
uint8_t code
request method (value 1–10) or response code (value 40-255)
int coap_flsll(long long i)
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
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_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
#define COAP_RESPONSE_CODE(N)
int coap_add_block(coap_pdu_t *pdu, unsigned int len, const uint8_t *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.
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
unsigned char coap_key_t[4]
#define COAP_OPTION_OBSERVE
#define COAP_OPTION_MAXAGE
#define COAP_OPTION_CONTENT_TYPE
coap_subscription_t * coap_find_observer(coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token)
Returns a subscription object for given peer.
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.
coap_session_t * session
transaction session
void coap_add_data_blocked_response(coap_resource_t *resource, coap_session_t *session, coap_pdu_t *request, coap_pdu_t *response, const coap_binary_t *token, uint16_t media_type, int maxage, size_t length, const uint8_t *data)
Adds the appropriate part of data to the response pdu.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
uint16_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
#define COAP_OPT_BLOCK_LAST(opt)
Returns the value of the least significant byte of a Block option opt.
size_t used_size
used bytes of storage for token, options and payload
size_t max_size
maximum size for token, options and payload, or zero for variable size pdu
Iterator to run through PDU options.
Coap binary data definition.
coap_block_t block2
GET request Block2 definition.
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.
int coap_write_block_opt(coap_block_t *block, uint16_t type, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type type to message pdu.
#define COAP_OPTION_SIZE2
#define COAP_OPTION_BLOCK2
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
Structure of Block options.
unsigned int coap_decode_var_bytes(const uint8_t *buf, unsigned int len)
Decodes multiple-length byte sequences.
unsigned int has_block2
GET request had Block2 definition.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
uint8_t token[8]
the token to use in a response
#define COAP_OPT_BLOCK_SZX(opt)
Returns the value of the SZX-field of a Block option opt.
int coap_get_block(coap_pdu_t *pdu, uint16_t type, coap_block_t *block)
Initializes block from pdu.
#define coap_log(level,...)
Logging function.
#define COAP_OPT_BLOCK_MORE(opt)
Returns the value of the More-bit of a Block option opt.
unsigned int observe
The next value for the Observe option.
Pulls together all the internal only header files.
#define coap_hash(String, Length, Result)
unsigned int m
1 if more blocks follow, 0 otherwise
unsigned int szx
block size
unsigned int num
block number