libcoap  4.3.0rc2
Go to the documentation of this file.
1 /*
2  * block.h -- block transfer
3  *
4  * Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
10 #ifndef COAP_BLOCK_H_
11 #define COAP_BLOCK_H_
13 #include "encode.h"
14 #include "option.h"
15 #include "pdu.h"
27 #define COAP_MAX_BLOCK_SZX 6
28 #endif /* COAP_MAX_BLOCK_SZX */
33 typedef struct {
34  unsigned int num;
35  unsigned int m:1;
36  unsigned int szx:3;
37 } coap_block_t;
39 #define COAP_BLOCK_USE_LIBCOAP 0x01 /* Use libcoap to do block requests */
40 #define COAP_BLOCK_SINGLE_BODY 0x02 /* Deliver the data as a single body */
47 #define COAP_OPT_BLOCK_LAST(opt) \
48  (coap_opt_length(opt) ? (coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
51 #define COAP_OPT_BLOCK_MORE(opt) \
52  (coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
55 #define COAP_OPT_BLOCK_SZX(opt) \
56  (coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
61 unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
68 coap_more_blocks(size_t data_len, unsigned int num, uint16_t szx) {
69  return ((num+1) << (szx + 4)) < data_len;
70 }
72 #if 0
75 coap_opt_block_set_m(coap_opt_t *block_opt, int m) {
76  if (m)
77  *(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) |= 0x08;
78  else
79  *(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) &= ~0x08;
80 }
81 #endif
97  coap_block_t *block);
120  coap_option_num_t number,
121  coap_pdu_t *pdu,
122  size_t data_length);
136 int coap_add_block(coap_pdu_t *pdu,
137  size_t len,
138  const uint8_t *data,
139  unsigned int block_num,
140  unsigned char block_szx);
156 coap_block_build_body(coap_binary_t *body_data, size_t length,
157  const uint8_t *data, size_t offset, size_t total);
181 void
183  coap_session_t *session,
184  coap_pdu_t *request,
185  coap_pdu_t *response,
186  const coap_binary_t *token,
187  uint16_t media_type,
188  int maxage,
189  size_t length,
190  const uint8_t* data);
201 typedef void (*coap_release_large_data_t)(coap_session_t *session,
202  void *app_ptr);
245  coap_pdu_t *pdu,
246  size_t length,
247  const uint8_t *data,
248  coap_release_large_data_t release_func,
249  void *app_ptr);
300 int
302  coap_session_t *session,
303  coap_pdu_t *request,
304  coap_pdu_t *response,
305  const coap_binary_t *token,
306  const coap_string_t *query,
307  uint16_t media_type,
308  int maxage,
309  uint64_t etag,
310  size_t length,
311  const uint8_t *data,
312  coap_release_large_data_t release_func,
313  void *app_ptr);
334  uint8_t block_mode);
350  coap_pdu_type_t message_type);
354 #endif /* COAP_BLOCK_H_ */
void coap_context_set_block_mode(coap_context_t *context, uint8_t block_mode)
Set the context level CoAP block handling bits for handling RFC7959.
Definition: block.c:263
int coap_get_block(coap_pdu_t *pdu, coap_option_num_t number, coap_block_t *block)
Initializes block from pdu.
Definition: block.c:35
int coap_add_data_large_response(coap_resource_t *resource, coap_session_t *session, coap_pdu_t *request, coap_pdu_t *response, const coap_binary_t *token, const coap_string_t *query, uint16_t media_type, int maxage, uint64_t etag, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the response pdu that is passed as fourth parameter.
Definition: block.c:640
int coap_add_data_large_request(coap_session_t *session, coap_pdu_t *pdu, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the pdu that is passed as second parameter.
Definition: block.c:629
int coap_add_block(coap_pdu_t *pdu, size_t 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.
Definition: block.c:124
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.
Definition: block.c:141
coap_binary_t * coap_block_build_body(coap_binary_t *body_data, size_t length, const uint8_t *data, size_t offset, size_t total)
Re-assemble payloads into a body.
Definition: block.c:1578
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:201
COAP_STATIC_INLINE int coap_more_blocks(size_t data_len, unsigned int num, uint16_t szx)
Checks if more than num blocks are required to deliver data_len bytes of data for a block size of 1 <...
Definition: block.h:68
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.
Definition: block.c:16
int coap_write_block_opt(coap_block_t *block, coap_option_num_t number, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type number to message pdu.
Definition: block.c:63
int coap_cancel_observe(coap_session_t *session, coap_binary_t *token, coap_pdu_type_t message_type)
Cancel an observe that is being tracked by the client large receive logic when using coap_send_large(...
Definition: block.c:293
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
Definition: option.c:209
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
Definition: option.c:246
CoAP PDU message type definitions.
Definition: pdu.h:54
Definition: libcoap.h:38
const uint8_t m
Definition: murmur3.c:55
Helpers for handling options in CoAP PDUs.
uint16_t coap_option_num_t
Definition: option.h:20
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
Pre-defined constants that reflect defaults for CoAP.
CoAP binary data definition.
Definition: str.h:48
Structure of Block options.
Definition: block.h:33
unsigned int num
block number
Definition: block.h:34
unsigned int szx
block size
Definition: block.h:36
unsigned int m
1 if more blocks follow, 0 otherwise
Definition: block.h:35
The CoAP stack's global state is stored in a coap_context_t object.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Abstraction of resource that can be attached to coap_context_t.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition.
Definition: str.h:30