19#ifndef COAP_BLOCK_INTERNAL_H_
20#define COAP_BLOCK_INTERNAL_H_
38#ifndef STATE_MAX_BLK_CNT_BITS
39#define STATE_MAX_BLK_CNT_BITS 20
41#define STATE_TOKEN_BASE(t) ((t) & (0xffffffffffffffffULL >> STATE_MAX_BLK_CNT_BITS))
42#define STATE_TOKEN_RETRY(t) ((uint64_t)(t) >> (64 - STATE_MAX_BLK_CNT_BITS))
43#define STATE_TOKEN_FULL(t,r) (STATE_TOKEN_BASE(t) + ((uint64_t)(r) << (64 - STATE_MAX_BLK_CNT_BITS)))
45#if COAP_Q_BLOCK_SUPPORT
46#define COAP_BLOCK_SET_MASK (COAP_BLOCK_USE_LIBCOAP | \
47 COAP_BLOCK_SINGLE_BODY | \
48 COAP_BLOCK_TRY_Q_BLOCK | \
49 COAP_BLOCK_USE_M_Q_BLOCK | \
50 COAP_BLOCK_NO_PREEMPTIVE_RTAG | \
51 COAP_BLOCK_STLESS_FETCH | \
52 COAP_BLOCK_STLESS_BLOCK2 | \
53 COAP_BLOCK_NOT_RANDOM_BLOCK1 | \
54 COAP_BLOCK_CACHE_RESPONSE | \
55 COAP_BLOCK_FORCE_Q_BLOCK)
57#define COAP_BLOCK_SET_MASK (COAP_BLOCK_USE_LIBCOAP | \
58 COAP_BLOCK_SINGLE_BODY | \
59 COAP_BLOCK_NO_PREEMPTIVE_RTAG | \
60 COAP_BLOCK_STLESS_FETCH | \
61 COAP_BLOCK_STLESS_BLOCK2 | \
62 COAP_BLOCK_NOT_RANDOM_BLOCK1 | \
63 COAP_BLOCK_CACHE_RESPONSE)
66#define COAP_BLOCK_MAX_SIZE_MASK 0x7000000
67#define COAP_BLOCK_MAX_SIZE_SHIFT 24
68#define COAP_BLOCK_MAX_SIZE_GET(a) (((a) & COAP_BLOCK_MAX_SIZE_MASK) >> COAP_BLOCK_MAX_SIZE_SHIFT)
69#define COAP_BLOCK_MAX_SIZE_SET(a) (((a) << COAP_BLOCK_MAX_SIZE_SHIFT) & COAP_BLOCK_MAX_SIZE_MASK)
71#if COAP_Q_BLOCK_SUPPORT
73#define COAP_BLOCK_HAS_Q_BLOCK 0x40000000
74#define COAP_BLOCK_PROBE_Q_BLOCK 0x80000000
76#define set_block_mode_probe_q(block_mode) \
78 block_mode |= COAP_BLOCK_PROBE_Q_BLOCK; \
79 block_mode &= ~(COAP_BLOCK_TRY_Q_BLOCK | COAP_BLOCK_HAS_Q_BLOCK); \
82#define set_block_mode_has_q(block_mode) \
84 block_mode |= COAP_BLOCK_HAS_Q_BLOCK; \
85 block_mode &= ~(COAP_BLOCK_TRY_Q_BLOCK | COAP_BLOCK_PROBE_Q_BLOCK); \
88#define set_block_mode_drop_q(block_mode) \
90 block_mode &= ~(COAP_BLOCK_TRY_Q_BLOCK |\
91 COAP_BLOCK_PROBE_Q_BLOCK |\
92 COAP_BLOCK_HAS_Q_BLOCK | \
93 COAP_BLOCK_USE_M_Q_BLOCK | \
94 COAP_BLOCK_FORCE_Q_BLOCK); \
97#define COAP_SINGLE_BLOCK_OR_Q (COAP_BLOCK_SINGLE_BODY|COAP_BLOCK_HAS_Q_BLOCK)
99#define COAP_SINGLE_BLOCK_OR_Q (COAP_BLOCK_SINGLE_BODY)
112#ifndef COAP_RBLOCK_CNT
113#define COAP_RBLOCK_CNT 4
115#if COAP_RBLOCK_CNT > COAP_DEFAULT_MAX_PAYLOADS -1
116#error COAP_RBLOCK_CNT too large
118#if COAP_RBLOCK_CNT < 2
119#error COAP_RBLOCK_CNT too small
128#if COAP_Q_BLOCK_SUPPORT
129 uint32_t processing_payload_set;
130 uint32_t latest_payload_set;
192#if COAP_Q_BLOCK_SUPPORT
199#if COAP_CLIENT_SUPPORT
206 uint8_t observe_length;
212 uint16_t content_format;
215 uint16_t block_option;
216 uint16_t retry_counter;
222 size_t obs_token_cnt;
223 uint16_t o_block_option;
226 uint64_t state_token;
235#if COAP_SERVER_SUPPORT
242 uint8_t observe_length;
244 uint8_t no_more_seen;
248 uint16_t content_format;
251 uint16_t block_option;
252 uint8_t dont_timeout;
265#if COAP_Q_BLOCK_SUPPORT
272#if COAP_CLIENT_SUPPORT
303 coap_block_delete_lg_crcv(session, lg_crcv);
324#if COAP_Q_BLOCK_SUPPORT
328 coap_send_pdu_t send_request);
347#if COAP_Q_BLOCK_SUPPORT
367 coap_send_pdu_t send_pdu);
370#if COAP_SERVER_SUPPORT
397 coap_block_delete_lg_srcv(session, lg_srcv);
418#if COAP_Q_BLOCK_SUPPORT
437 coap_send_pdu_t send_response);
528#if COAP_CLIENT_SUPPORT
613#if COAP_Q_BLOCK_SUPPORT
657 uint32_t block_mode);
691 const uint8_t *data,
size_t offset,
size_t total);
693#if COAP_CLIENT_SUPPORT
800#define coap_check_update_token(a,b)
struct coap_lg_crcv_t coap_lg_crcv_t
struct coap_resource_t coap_resource_t
struct coap_lg_srcv_t coap_lg_srcv_t
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
struct coap_rblock_t coap_rblock_t
Structure to keep track of received blocks.
#define coap_check_update_token(a, b)
int coap_context_set_max_block_size_lkd(coap_context_t *context, size_t max_block_size)
Set the context level maximum block size that the server supports when sending or receiving packets w...
void coap_context_set_block_mode_lkd(coap_context_t *context, uint32_t block_mode)
Set the context level CoAP block handling bits for handling RFC7959.
void coap_check_code_lg_xmit(const coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_resource_t *resource, const coap_string_t *query)
The function checks that the code in a newly formed lg_xmit created by coap_add_data_large_response_l...
COAP_STATIC_INLINE void coap_lg_xmit_reference_lkd(coap_lg_xmit_t *lg_xmit)
Increment reference counter on a lg_xmit.
void coap_block_delete_lg_xmit(coap_session_t *session, coap_lg_xmit_t *lg_xmit)
Remove a lg_xmit.
coap_binary_t * coap_block_build_body_lkd(coap_binary_t *body_data, size_t length, const uint8_t *data, size_t offset, size_t total)
Re-assemble payloads into a body.
COAP_STATIC_INLINE void coap_lg_xmit_release_lkd(coap_session_t *session, coap_lg_xmit_t *lg_xmit)
Decrement reference counter on a lg_xmit.
coap_lg_xmit_t * coap_find_lg_xmit(coap_session_t *session, coap_pdu_t *pdu)
Find the current lg_xmit for the session that matches the pdu.
int coap_block_check_lg_xmit_timeouts(coap_session_t *session, coap_tick_t now, coap_tick_t *tim_rem)
int(* coap_get_large_data_t)(coap_session_t *session, size_t max, size_t offset, uint8_t *data, size_t *length, void *app_ptr)
Callback handler for getting the data based on app_ptr provided to coap_add_data_large_request_app() ...
void(* coap_release_large_data_t)(coap_session_t *session, void *app_ptr)
Callback handler for de-allocating the data based on app_ptr provided to coap_add_data_large_*() func...
time_t coap_time_t
CoAP time in seconds since epoch.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
coap_pdu_code_t
Set of codes available for a PDU.
struct coap_str_const_t coap_str_const_t
CoAP string data definition with const data.
struct coap_binary_t coap_binary_t
CoAP binary data definition.
struct coap_bin_const_t coap_bin_const_t
CoAP binary data definition with const data.
#define COAP_STATIC_INLINE
Multi-purpose address abstraction.
CoAP binary data definition with const data.
CoAP binary data definition.
Structure of Block options with BERT support.
The CoAP stack's global state is stored in a coap_context_t object.
Structure to keep track of block1 specific information (Requests).
uint64_t state_token
state token
size_t bert_size
size of last BERT block
uint32_t count
the number of packets sent for payload
coap_binary_t * app_token
original PDU token
Structure to keep track of block2 specific information (Responses).
coap_pdu_code_t request_method
Method used to request this data.
uint8_t rtag_length
RTag length.
coap_string_t * query
Associated query for the resource.
coap_resource_t * resource
associated resource
coap_time_t maxage_expire
When this entry expires.
uint8_t rtag_set
Set if RTag is in receive PDU.
uint8_t rtag[8]
RTag for block checking.
coap_get_large_data_t get_func
Where to get data id needed.
void * app_ptr
applicaton provided ptr for de-alloc function
uint32_t ref
Reference count.
const uint8_t * data
large data ptr
size_t length
large data length
coap_release_large_data_t release_func
large data de-alloc function
Structure to hold large body (many blocks) transmission information.
coap_tick_t last_all_sent
Last time all data sent or 0.
uint8_t blk_size
large block transmission size
coap_tick_t last_sent
Last time any data sent.
coap_lg_xmit_data_t * data_info
Pointer to large data information.
union coap_lg_xmit_t::@025301310216224123377060072066277301055061031376 b
int last_block
last acknowledged block number Block1 last transmitted Q-Block2
coap_tick_t last_payload
Last time MAX_PAYLOAD was sent or 0.
coap_pdu_t * sent_pdu
The sent pdu with all the data.
uint32_t ref
Reference count.
uint16_t option
large block transmisson CoAP option
struct coap_lg_xmit_t * next
coap_tick_t last_obs
Last time used (Observe tracking) or 0.
Structure to keep track of received blocks.
uint32_t total_blocks
Set to block no + 1 when More bit unset.
uint32_t used
Number of range blocks in use.
struct coap_lg_range range[COAP_RBLOCK_CNT]
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition.