#ifndef COAP_BLOCK_INTERNAL_H_
#define COAP_BLOCK_INTERNAL_H_
#include "coap_internal.h"
#include "coap_pdu_internal.h"
#include "resource.h"
typedef enum {
COAP_RECURSE_OK,
COAP_RECURSE_NO
} coap_recurse_t;
struct coap_lg_range {
uint32_t begin;
uint32_t end;
};
#define COAP_RBLOCK_CNT 4
typedef struct coap_rblock_t {
uint32_t used;
uint32_t retry;
struct coap_lg_range range[COAP_RBLOCK_CNT];
coap_tick_t last_seen;
} coap_rblock_t;
typedef struct coap_l_block1_t {
coap_binary_t *app_token;
uint64_t state_token;
size_t bert_size;
uint32_t count;
} coap_l_block1_t;
typedef struct coap_l_block2_t {
coap_resource_t *resource;
coap_string_t *query;
uint64_t etag;
coap_time_t maxage_expire;
coap_pdu_code_t request_method;
} coap_l_block2_t;
struct coap_lg_xmit_t {
struct coap_lg_xmit_t *next;
uint8_t blk_size;
uint16_t option;
int last_block;
const uint8_t *data;
size_t length;
size_t offset;
union {
coap_l_block1_t b1;
coap_l_block2_t b2;
} b;
coap_pdu_t pdu;
coap_tick_t last_payload;
coap_tick_t last_sent;
coap_tick_t last_all_sent;
coap_tick_t last_obs;
coap_release_large_data_t release_func;
void *app_ptr;
};
#if COAP_CLIENT_SUPPORT
struct coap_lg_crcv_t {
struct coap_lg_crcv_t *next;
uint8_t observe[3];
uint8_t observe_length;
uint8_t observe_set;
uint8_t szx;
uint8_t etag_set;
uint8_t etag_length;
uint8_t etag[8];
uint16_t content_format;
uint8_t last_type;
uint8_t initial;
uint16_t block_option;
uint16_t retry_counter;
size_t total_len;
coap_binary_t *body_data;
coap_binary_t *app_token;
coap_binary_t *obs_token;
uint64_t state_token;
coap_pdu_t pdu;
coap_rblock_t rec_blocks;
coap_tick_t last_used;
};
#endif
#if COAP_SERVER_SUPPORT
struct coap_lg_srcv_t {
struct coap_lg_srcv_t *next;
uint8_t observe[3];
uint8_t observe_length;
uint8_t observe_set;
uint8_t rtag_set;
uint8_t rtag_length;
uint8_t rtag[8];
uint16_t content_format;
uint8_t last_type;
uint8_t szx;
size_t total_len;
coap_binary_t *body_data;
size_t amount_so_far;
coap_resource_t *resource;
coap_str_const_t *uri_path;
coap_rblock_t rec_blocks;
uint8_t last_token[8];
size_t last_token_length;
coap_mid_t last_mid;
coap_tick_t last_used;
uint16_t block_option;
};
#endif
#if COAP_CLIENT_SUPPORT
coap_lg_crcv_t * coap_block_new_lg_crcv(coap_session_t *session,
coap_pdu_t *pdu);
void coap_block_delete_lg_crcv(coap_session_t *session,
coap_lg_crcv_t *lg_crcv);
int coap_block_check_lg_crcv_timeouts(coap_session_t *session,
coap_tick_t now,
coap_tick_t *tim_rem);
#endif
#if COAP_SERVER_SUPPORT
void coap_block_delete_lg_srcv(coap_session_t *session,
coap_lg_srcv_t *lg_srcv);
int coap_block_check_lg_srcv_timeouts(coap_session_t *session,
coap_tick_t now,
coap_tick_t *tim_rem);
int coap_handle_request_send_block(coap_session_t *session,
coap_pdu_t *pdu,
coap_pdu_t *response,
coap_resource_t *resource,
coap_string_t *query);
int coap_handle_request_put_block(coap_context_t *context,
coap_session_t *session,
coap_pdu_t *pdu,
coap_pdu_t *response,
coap_resource_t *resource,
coap_string_t *uri_path,
coap_opt_t *observe,
coap_string_t *query,
coap_method_handler_t h,
int *added_block);
#endif
#if COAP_CLIENT_SUPPORT
int coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *sent,
coap_pdu_t *rcvd);
int coap_handle_response_get_block(coap_context_t *context,
coap_session_t *session,
coap_pdu_t *sent,
coap_pdu_t *rcvd,
coap_recurse_t recursive);
#endif
void coap_block_delete_lg_xmit(coap_session_t *session,
coap_lg_xmit_t *lg_xmit);
int coap_block_check_lg_xmit_timeouts(coap_session_t *session,
coap_tick_t now,
coap_tick_t *tim_rem);
void coap_check_code_lg_xmit(coap_session_t *session, coap_pdu_t *response,
coap_resource_t *resource, coap_string_t *query,
coap_pdu_code_t request_method);
#endif