9 #include "coap_config.h" 11 #if defined(HAVE_ASSERT_H) && !defined(assert) 22 #define min(a,b) ((a) < (b) ? (a) : (b)) 76 size_t start, want, avail;
81 start = block->
num << (block->
szx + 4);
82 if (data_length <= start) {
89 want = (size_t)1 << (block->
szx + 4);
93 block->
m = want < data_length - start;
100 if (data_length - start <= avail) {
111 "not enough space, even the smallest block does not fit");
114 newBlockSize =
coap_flsll((
long long)avail) - 5;
116 "decrease block size for %zu to %d\n", avail, newBlockSize);
118 block->
szx = newBlockSize;
120 block->
num <<= szx - block->
szx;
136 unsigned int block_num,
unsigned char block_szx) {
138 start = block_num << (block_szx + 4);
144 min(len - start, (1U << (block_szx + 4))),
163 unsigned char buf[4];
165 int block2_requested = 0;
174 block2_requested = 1;
175 if (length <= (block2.
num << (block2.
szx + 4))) {
178 length >> (block2.
szx + 4));
184 else if (subscription && subscription->
has_block2) {
185 block2 = subscription->
block2;
187 block2_requested = 1;
192 memset(etag, 0,
sizeof(etag));
196 if ((block2.
num == 0) && subscription) {
214 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.
Generic resource handling.
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.
definition of hash key type and helper functions
#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.
#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