coap_block_internal.h
Go to the documentation of this file.
/*
* coap_block_internal.h -- Structures, Enums & Functions that are not
* exposed to application programming
*
* Copyright (C) 2010-2021 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2021 Jon Shallow <supjps-libcoap@jpshallow.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_BLOCK_INTERNAL_H_
#define COAP_BLOCK_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;
uint8_t token[8];
size_t token_length;
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_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_used;
coap_release_large_data_t release_func;
void *app_ptr;
};
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 etag_set;
uint8_t etag_length;
uint8_t etag[8];
uint16_t content_format;
uint8_t last_type;
uint8_t initial;
uint8_t szx;
size_t total_len;
coap_binary_t *body_data;
coap_binary_t *app_token;
uint8_t base_token[8];
size_t base_token_length;
uint8_t token[8];
size_t token_length;
coap_pdu_t pdu;
coap_rblock_t rec_blocks;
coap_tick_t last_used;
uint16_t block_option;
};
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;
};
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);
coap_tick_t coap_block_check_lg_crcv_timeouts(coap_session_t *session,
coap_tick_t now);
void coap_block_delete_lg_srcv(coap_session_t *session,
coap_lg_srcv_t *lg_srcv);
coap_tick_t coap_block_check_lg_srcv_timeouts(coap_session_t *session,
coap_tick_t now);
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);
int coap_handle_response_send_block(coap_session_t *session, 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);
void coap_block_delete_lg_xmit(coap_session_t *session,
coap_lg_xmit_t *lg_xmit);
int coap_add_data_large_internal(coap_session_t *session,
coap_pdu_t *pdu,
coap_resource_t *resource,
const coap_string_t *query,
int maxage,
uint64_t etag,
size_t length,
const uint8_t *data,
coap_release_large_data_t release_func,
void *app_ptr);
void coap_check_code_lg_xmit(coap_session_t *session, coap_pdu_t *response,
coap_resource_t *resource, coap_string_t *query);
#endif /* COAP_BLOCK_INTERNAL_H_ */
coap_pdu_internal.h
CoAP PDU internal information.
coap_rblock_t
struct coap_rblock_t coap_rblock_t
Structure to keep track of received blocks.
coap_block_check_lg_srcv_timeouts
coap_tick_t coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now)
Definition: block.c:788
coap_block_delete_lg_srcv
void coap_block_delete_lg_srcv(coap_session_t *session, coap_lg_srcv_t *lg_srcv)
Definition: block.c:877
COAP_RBLOCK_CNT
#define COAP_RBLOCK_CNT
Definition: coap_block_internal.h:41
coap_block_delete_lg_crcv
void coap_block_delete_lg_crcv(coap_session_t *session, coap_lg_crcv_t *lg_crcv)
Definition: block.c:862
coap_l_block1_t
struct coap_l_block1_t coap_l_block1_t
Structure to keep track of block1 specific information (Requests)
coap_handle_response_get_block
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)
Definition: block.c:1611
coap_l_block2_t
struct coap_l_block2_t coap_l_block2_t
Structure to keep track of block2 specific information (Responses)
coap_recurse_t
coap_recurse_t
Definition: coap_block_internal.h:31
coap_block_delete_lg_xmit
void coap_block_delete_lg_xmit(coap_session_t *session, coap_lg_xmit_t *lg_xmit)
Definition: block.c:890
coap_check_code_lg_xmit
void coap_check_code_lg_xmit(coap_session_t *session, coap_pdu_t *response, coap_resource_t *resource, coap_string_t *query)
The function checks that the code in a newly formed lg_xmit created by coap_add_data_large_response()...
Definition: block.c:1948
coap_add_data_large_internal
int coap_add_data_large_internal(coap_session_t *session, coap_pdu_t *pdu, coap_resource_t *resource, const coap_string_t *query, int maxage, uint64_t etag, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
The function that does all the work for the coap_add_data_large*() functions.
Definition: block.c:333
coap_block_check_lg_crcv_timeouts
coap_tick_t coap_block_check_lg_crcv_timeouts(coap_session_t *session, coap_tick_t now)
Definition: block.c:734
coap_handle_request_send_block
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)
Definition: block.c:951
coap_handle_request_put_block
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)
Definition: block.c:1222
coap_block_new_lg_crcv
coap_lg_crcv_t * coap_block_new_lg_crcv(coap_session_t *session, coap_pdu_t *pdu)
Definition: block.c:810
coap_handle_response_send_block
int coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *rcvd)
Definition: block.c:1447
COAP_RECURSE_OK
@ COAP_RECURSE_OK
Definition: coap_block_internal.h:32
COAP_RECURSE_NO
@ COAP_RECURSE_NO
Definition: coap_block_internal.h:33
coap_release_large_data_t
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...
Definition: block.h:197
coap_time_t
time_t coap_time_t
CoAP time in seconds since epoch.
Definition: coap_time.h:127
coap_tick_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:122
coap_method_handler_t
void(* coap_method_handler_t)(coap_resource_t *, coap_session_t *, const coap_pdu_t *, const coap_string_t *, coap_pdu_t *)
Definition of message handler function.
Definition: resource.h:42
coap_mid_t
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition: pdu.h:231
coap_opt_t
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
Definition: option.h:26
resource.h
Generic resource handling.
coap_binary_t
CoAP binary data definition.
Definition: str.h:50
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition: coap_net_internal.h:45
coap_l_block1_t
Structure to keep track of block1 specific information (Requests)
Definition: coap_block_internal.h:56
coap_l_block1_t::token_length
size_t token_length
length of token
Definition: coap_block_internal.h:59
coap_l_block1_t::count
uint32_t count
the number of packets sent for payload
Definition: coap_block_internal.h:60
coap_l_block1_t::app_token
coap_binary_t * app_token
original PDU token
Definition: coap_block_internal.h:57
coap_l_block1_t::token
uint8_t token[8]
last used token
Definition: coap_block_internal.h:58
coap_l_block2_t
Structure to keep track of block2 specific information (Responses)
Definition: coap_block_internal.h:67
coap_l_block2_t::query
coap_string_t * query
Associated query for the resource.
Definition: coap_block_internal.h:69
coap_l_block2_t::etag
uint64_t etag
ETag value.
Definition: coap_block_internal.h:70
coap_l_block2_t::resource
coap_resource_t * resource
associated resource
Definition: coap_block_internal.h:68
coap_l_block2_t::maxage_expire
coap_time_t maxage_expire
When this entry expires.
Definition: coap_block_internal.h:71
coap_lg_crcv_t
Structure to hold large body (many blocks) client receive information.
Definition: coap_block_internal.h:99
coap_lg_crcv_t::block_option
uint16_t block_option
Block option in use.
Definition: coap_block_internal.h:121
coap_lg_crcv_t::etag
uint8_t etag[8]
ETag for block checking.
Definition: coap_block_internal.h:106
coap_lg_crcv_t::etag_length
uint8_t etag_length
ETag length.
Definition: coap_block_internal.h:105
coap_lg_crcv_t::last_type
uint8_t last_type
Last request type (CON/NON)
Definition: coap_block_internal.h:108
coap_lg_crcv_t::observe_length
uint8_t observe_length
Length of observe data.
Definition: coap_block_internal.h:102
coap_lg_crcv_t::observe
uint8_t observe[3]
Observe data (if set) (only 24 bits)
Definition: coap_block_internal.h:101
coap_lg_crcv_t::etag_set
uint8_t etag_set
Set if ETag is in receive PDU.
Definition: coap_block_internal.h:104
coap_lg_crcv_t::rec_blocks
coap_rblock_t rec_blocks
Definition: coap_block_internal.h:119
coap_lg_crcv_t::next
struct coap_lg_crcv_t * next
Definition: coap_block_internal.h:100
coap_lg_crcv_t::initial
uint8_t initial
If set, has not been used yet.
Definition: coap_block_internal.h:109
coap_lg_crcv_t::szx
uint8_t szx
size of individual blocks
Definition: coap_block_internal.h:110
coap_lg_crcv_t::content_format
uint16_t content_format
Content format for the set of blocks.
Definition: coap_block_internal.h:107
coap_lg_crcv_t::pdu
coap_pdu_t pdu
skeletal PDU
Definition: coap_block_internal.h:118
coap_lg_crcv_t::last_used
coap_tick_t last_used
< list of received blocks
Definition: coap_block_internal.h:120
coap_lg_crcv_t::app_token
coap_binary_t * app_token
app requesting PDU token
Definition: coap_block_internal.h:113
coap_lg_crcv_t::token
uint8_t token[8]
last used token
Definition: coap_block_internal.h:116
coap_lg_crcv_t::base_token
uint8_t base_token[8]
established base PDU token
Definition: coap_block_internal.h:114
coap_lg_crcv_t::token_length
size_t token_length
length of token
Definition: coap_block_internal.h:117
coap_lg_crcv_t::base_token_length
size_t base_token_length
length of token
Definition: coap_block_internal.h:115
coap_lg_crcv_t::body_data
coap_binary_t * body_data
Used for re-assembling entire body.
Definition: coap_block_internal.h:112
coap_lg_crcv_t::observe_set
uint8_t observe_set
Set if this is an observe receive PDU.
Definition: coap_block_internal.h:103
coap_lg_crcv_t::total_len
size_t total_len
Length as indicated by SIZE2 option.
Definition: coap_block_internal.h:111
coap_lg_range
Definition: coap_block_internal.h:36
coap_lg_range::end
uint32_t end
Definition: coap_block_internal.h:38
coap_lg_range::begin
uint32_t begin
Definition: coap_block_internal.h:37
coap_lg_srcv_t
Structure to hold large body (many blocks) server receive information.
Definition: coap_block_internal.h:127
coap_lg_srcv_t::rtag
uint8_t rtag[8]
RTag for block checking.
Definition: coap_block_internal.h:134
coap_lg_srcv_t::last_mid
coap_mid_t last_mid
Last received mid for this set of packets.
Definition: coap_block_internal.h:146
coap_lg_srcv_t::last_token
uint8_t last_token[8]
< list of received blocks
Definition: coap_block_internal.h:144
coap_lg_srcv_t::rtag_set
uint8_t rtag_set
Set if RTag is in receive PDU.
Definition: coap_block_internal.h:132
coap_lg_srcv_t::block_option
uint16_t block_option
Block option in use.
Definition: coap_block_internal.h:148
coap_lg_srcv_t::total_len
size_t total_len
Length as indicated by SIZE1 option.
Definition: coap_block_internal.h:138
coap_lg_srcv_t::next
struct coap_lg_srcv_t * next
Definition: coap_block_internal.h:128
coap_lg_srcv_t::observe_length
uint8_t observe_length
Length of observe data.
Definition: coap_block_internal.h:130
coap_lg_srcv_t::rec_blocks
coap_rblock_t rec_blocks
set to uri_path if unknown resource
Definition: coap_block_internal.h:143
coap_lg_srcv_t::body_data
coap_binary_t * body_data
Used for re-assembling entire body.
Definition: coap_block_internal.h:139
coap_lg_srcv_t::resource
coap_resource_t * resource
associated resource
Definition: coap_block_internal.h:141
coap_lg_srcv_t::last_token_length
size_t last_token_length
length of token
Definition: coap_block_internal.h:145
coap_lg_srcv_t::observe_set
uint8_t observe_set
Set if this is an observe receive PDU.
Definition: coap_block_internal.h:131
coap_lg_srcv_t::rtag_length
uint8_t rtag_length
RTag length.
Definition: coap_block_internal.h:133
coap_lg_srcv_t::last_type
uint8_t last_type
Last request type (CON/NON)
Definition: coap_block_internal.h:136
coap_lg_srcv_t::szx
uint8_t szx
size of individual blocks
Definition: coap_block_internal.h:137
coap_lg_srcv_t::amount_so_far
size_t amount_so_far
Amount of data seen so far.
Definition: coap_block_internal.h:140
coap_lg_srcv_t::last_used
coap_tick_t last_used
Last time data sent or 0.
Definition: coap_block_internal.h:147
coap_lg_srcv_t::observe
uint8_t observe[3]
Observe data (if set) (only 24 bits)
Definition: coap_block_internal.h:129
coap_lg_srcv_t::content_format
uint16_t content_format
Content format for the set of blocks.
Definition: coap_block_internal.h:135
coap_lg_srcv_t::uri_path
coap_str_const_t * uri_path
Definition: coap_block_internal.h:142
coap_lg_xmit_t
Structure to hold large body (many blocks) transmission information.
Definition: coap_block_internal.h:77
coap_lg_xmit_t::release_func
coap_release_large_data_t release_func
large data de-alloc function
Definition: coap_block_internal.h:92
coap_lg_xmit_t::blk_size
uint8_t blk_size
large block transmission size
Definition: coap_block_internal.h:79
coap_lg_xmit_t::b
union coap_lg_xmit_t::@1 b
coap_lg_xmit_t::data
const uint8_t * data
large data ptr
Definition: coap_block_internal.h:82
coap_lg_xmit_t::last_block
int last_block
last acknowledged block number
Definition: coap_block_internal.h:81
coap_lg_xmit_t::last_payload
coap_tick_t last_payload
Last time MAX_PAYLOAD was sent or 0.
Definition: coap_block_internal.h:90
coap_lg_xmit_t::offset
size_t offset
large data next offset to transmit
Definition: coap_block_internal.h:84
coap_lg_xmit_t::pdu
coap_pdu_t pdu
skeletal PDU
Definition: coap_block_internal.h:89
coap_lg_xmit_t::length
size_t length
large data length
Definition: coap_block_internal.h:83
coap_lg_xmit_t::last_used
coap_tick_t last_used
Last time all data sent or 0.
Definition: coap_block_internal.h:91
coap_lg_xmit_t::b1
coap_l_block1_t b1
Definition: coap_block_internal.h:86
coap_lg_xmit_t::b2
coap_l_block2_t b2
Definition: coap_block_internal.h:87
coap_lg_xmit_t::option
uint16_t option
large block transmisson CoAP option
Definition: coap_block_internal.h:80
coap_lg_xmit_t::next
struct coap_lg_xmit_t * next
Definition: coap_block_internal.h:78
coap_lg_xmit_t::app_ptr
void * app_ptr
applicaton provided ptr for de-alloc function
Definition: coap_block_internal.h:93
coap_pdu_t
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: coap_pdu_internal.h:94
coap_rblock_t
Structure to keep track of received blocks.
Definition: coap_block_internal.h:45
coap_rblock_t::retry
uint32_t retry
Definition: coap_block_internal.h:47
coap_rblock_t::used
uint32_t used
Definition: coap_block_internal.h:46
coap_rblock_t::last_seen
coap_tick_t last_seen
Definition: coap_block_internal.h:49
coap_rblock_t::range
struct coap_lg_range range[COAP_RBLOCK_CNT]
Definition: coap_block_internal.h:48
coap_resource_t
Abstraction of resource that can be attached to coap_context_t.
Definition: coap_resource_internal.h:42
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition: coap_session_internal.h:48
coap_str_const_t
CoAP string data definition with const data.
Definition: str.h:40
coap_string_t
CoAP string data definition.
Definition: str.h:32