Coverage Report

Created: 2026-04-12 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libcoap/include/coap3/coap_block.h
Line
Count
Source
1
/*
2
 * coap_block.h -- block transfer
3
 *
4
 * Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <bergmann@tzi.org>
5
 * Copyright (C) 2022-2026           Jon Shallow <supjps-libcoap@jpshallow.com>
6
 *
7
 * SPDX-License-Identifier: BSD-2-Clause
8
 *
9
 * This file is part of the CoAP library libcoap. Please see README for terms
10
 * of use.
11
 */
12
13
/**
14
 * @file coap_block.h
15
 * @brief CoAP Block information
16
 */
17
18
#ifndef COAP_BLOCK_H_
19
#define COAP_BLOCK_H_
20
21
#include "coap_encode.h"
22
#include "coap_option.h"
23
#include "coap_pdu.h"
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
/**
30
 * @ingroup application_api
31
 * @defgroup block Block Transfer
32
 * API for handling PDUs using CoAP Block options (RFC7959)
33
 * @{
34
 */
35
36
#ifndef COAP_MAX_BLOCK_SZX
37
/**
38
 * The largest value for the SZX component in a Block option.
39
 */
40
#define COAP_MAX_BLOCK_SZX      6
41
#endif /* COAP_MAX_BLOCK_SZX */
42
43
/**
44
 * Structure of Block options.
45
 */
46
typedef struct {
47
  unsigned int num;       /**< block number */
48
  unsigned int m:1;       /**< 1 if more blocks follow, 0 otherwise */
49
  unsigned int szx:3;     /**< block size */
50
} coap_block_t;
51
52
/**
53
 * Structure of Block options with BERT support.
54
 */
55
typedef struct {
56
  unsigned int num;       /**< block number */
57
  unsigned int m:1;       /**< 1 if more blocks follow, 0 otherwise */
58
  unsigned int szx:3;     /**< block size (0-6) */
59
  unsigned int aszx:3;    /**< block size (0-7 including BERT */
60
  unsigned int defined:1; /**< Set if block found */
61
  unsigned int bert:1;    /**< Operating as BERT */
62
  uint32_t chunk_size;    /**< > 1024 if BERT */
63
} coap_block_b_t;
64
65
1.35k
#define COAP_BLOCK_USE_LIBCOAP  0x01 /* Use libcoap to do block requests */
66
154
#define COAP_BLOCK_SINGLE_BODY  0x02 /* Deliver the data as a single body */
67
755
#define COAP_BLOCK_TRY_Q_BLOCK   0x04 /* Try Q-Block method */
68
154
#define COAP_BLOCK_USE_M_Q_BLOCK 0x08 /* Use M bit when recovering Q-Block2 */
69
154
#define COAP_BLOCK_NO_PREEMPTIVE_RTAG 0x10 /* (cl) Don't use pre-emptive Request-Tags */
70
154
#define COAP_BLOCK_STLESS_FETCH  0x20 /* (cl) Assume server supports stateless FETCH */
71
200
#define COAP_BLOCK_STLESS_BLOCK2 0x40 /* (svr)Server is stateless for handling Block2 */
72
154
#define COAP_BLOCK_NOT_RANDOM_BLOCK1 0x80 /* (svr)Disable server handling random order
73
                                             block1 */
74
2.87k
#define COAP_BLOCK_CACHE_RESPONSE 0x100 /* (svr)Cache CON request's response */
75
2.93k
#define COAP_BLOCK_FORCE_Q_BLOCK  0x200 /* force Q-Block method without support check */
76
/* WARNING: Added defined values must not encroach into 0xff000000 which are defined elsewhere */
77
78
/**
79
 * Returns the value of the least significant byte of a Block option @p opt.
80
 * For zero-length options (i.e. num == m == szx == 0), COAP_OPT_BLOCK_LAST
81
 * returns @c NULL.
82
 */
83
#define COAP_OPT_BLOCK_LAST(opt) \
84
  (coap_opt_length(opt) ? (coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
85
86
/** Returns the value of the last byte of @p opt. */
87
#define COAP_OPT_BLOCK_END_BYTE(opt) \
88
16.7k
  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
89
16.7k
   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
90
91
/** Returns the value of the More-bit of a Block option @p opt. */
92
#define COAP_OPT_BLOCK_MORE(opt) \
93
992k
  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
94
95
/** Returns the value of the SZX-field of a Block option @p opt. */
96
#define COAP_OPT_BLOCK_SZX(opt)  \
97
1.98M
  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x07) : 0)
98
99
/**
100
 * Returns the value of field @c num in the given block option @p block_opt.
101
 */
102
unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
103
104
/**
105
 * Checks if more than @p num blocks are required to deliver @p data_len
106
 * bytes of data for a block size of 1 << (@p szx + 4).
107
 */
108
COAP_STATIC_INLINE int
109
0
coap_more_blocks(size_t data_len, unsigned int num, uint16_t szx) {
110
0
  return ((num+1) << (szx + 4)) < data_len;
111
0
}
Unexecuted instantiation: oscore_decrypt_target.c:coap_more_blocks
Unexecuted instantiation: coap_address.c:coap_more_blocks
Unexecuted instantiation: coap_debug.c:coap_more_blocks
Unexecuted instantiation: coap_encode.c:coap_more_blocks
Unexecuted instantiation: coap_mem.c:coap_more_blocks
Unexecuted instantiation: coap_net.c:coap_more_blocks
Unexecuted instantiation: coap_netif.c:coap_more_blocks
Unexecuted instantiation: coap_openssl.c:coap_more_blocks
Unexecuted instantiation: coap_option.c:coap_more_blocks
Unexecuted instantiation: coap_oscore.c:coap_more_blocks
Unexecuted instantiation: coap_pdu.c:coap_more_blocks
Unexecuted instantiation: coap_proxy.c:coap_more_blocks
Unexecuted instantiation: coap_prng.c:coap_more_blocks
Unexecuted instantiation: coap_resource.c:coap_more_blocks
Unexecuted instantiation: coap_session.c:coap_more_blocks
Unexecuted instantiation: coap_str.c:coap_more_blocks
Unexecuted instantiation: coap_strm_posix.c:coap_more_blocks
Unexecuted instantiation: coap_subscribe.c:coap_more_blocks
Unexecuted instantiation: coap_time.c:coap_more_blocks
Unexecuted instantiation: coap_uri.c:coap_more_blocks
Unexecuted instantiation: coap_ws.c:coap_more_blocks
Unexecuted instantiation: oscore.c:coap_more_blocks
Unexecuted instantiation: oscore_cbor.c:coap_more_blocks
Unexecuted instantiation: oscore_context.c:coap_more_blocks
Unexecuted instantiation: oscore_cose.c:coap_more_blocks
Unexecuted instantiation: oscore_crypto.c:coap_more_blocks
Unexecuted instantiation: coap_async.c:coap_more_blocks
Unexecuted instantiation: coap_block.c:coap_more_blocks
Unexecuted instantiation: coap_cache.c:coap_more_blocks
Unexecuted instantiation: coap_dgrm_posix.c:coap_more_blocks
Unexecuted instantiation: coap_dtls.c:coap_more_blocks
Unexecuted instantiation: coap_io.c:coap_more_blocks
Unexecuted instantiation: coap_io_posix.c:coap_more_blocks
Unexecuted instantiation: coap_layers.c:coap_more_blocks
Unexecuted instantiation: pdu_parse_udp_target.c:coap_more_blocks
Unexecuted instantiation: async_target.c:coap_more_blocks
Unexecuted instantiation: block_target.c:coap_more_blocks
Unexecuted instantiation: split_uri_target.c:coap_more_blocks
Unexecuted instantiation: pdu_parse_tcp_target.c:coap_more_blocks
Unexecuted instantiation: observe_target.c:coap_more_blocks
Unexecuted instantiation: pdu_parse_ws_target.c:coap_more_blocks
Unexecuted instantiation: network_message_target.c:coap_more_blocks
Unexecuted instantiation: oscore_conf_parse_target.c:coap_more_blocks
Unexecuted instantiation: get_asn1_tag_target.c:coap_more_blocks
Unexecuted instantiation: coap_asn1.c:coap_more_blocks
Unexecuted instantiation: block_check_target.c:coap_more_blocks
112
113
#if 0
114
/** Sets the More-bit in @p block_opt */
115
COAP_STATIC_INLINE void
116
coap_opt_block_set_m(coap_opt_t *block_opt, int m) {
117
  if (m)
118
    *(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) |= 0x08;
119
  else
120
    *(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) &= ~0x08;
121
}
122
#endif
123
124
/**
125
 * Initializes @p block from @p pdu. @p number must be either COAP_OPTION_BLOCK1
126
 * or COAP_OPTION_BLOCK2. When option @p number was found in @p pdu, @p block is
127
 * initialized with values from this option and the function returns the value
128
 * @c 1. Otherwise, @c 0 is returned.
129
 *
130
 * @param pdu    The pdu to search for option @p number.
131
 * @param number The option number to search for (must be COAP_OPTION_BLOCK1 or
132
 *               COAP_OPTION_BLOCK2).
133
 * @param block  The block structure to initialize.
134
 *
135
 * @return       @c 1 on success, @c 0 otherwise.
136
 */
137
int coap_get_block(const coap_pdu_t *pdu, coap_option_num_t number,
138
                   coap_block_t *block);
139
140
141
/**
142
 * Initializes @p block from @p pdu. @p number must be either COAP_OPTION_BLOCK1
143
 * or COAP_OPTION_BLOCK2. When option @p number was found in @p pdu, @p block is
144
 * initialized with values from this option and the function returns the value
145
 * @c 1. Otherwise, @c 0 is returned. BERT information is abstracted as
146
 * appropriate.
147
 *
148
 * @param session THe session that the pdu is associated with,
149
 * @param pdu    The pdu to search for option @p number.
150
 * @param number The option number to search for (must be COAP_OPTION_BLOCK1 or
151
 *               COAP_OPTION_BLOCK2).
152
 * @param block  The block structure to initialize.
153
 *
154
 * @return       @c 1 on success, @c 0 otherwise.
155
 */
156
int coap_get_block_b(const coap_session_t *session, const coap_pdu_t *pdu,
157
                     coap_option_num_t number, coap_block_b_t *block);
158
159
/**
160
 * Writes a block option of type @p number to message @p pdu. If the requested
161
 * block size is too large to fit in @p pdu, it is reduced accordingly. An
162
 * exception is made for the final block when less space is required. The actual
163
 * length of the resource is specified in @p data_length.
164
 *
165
 * This function may change *block to reflect the values written to @p pdu. As
166
 * the function takes into consideration the remaining space @p pdu, no more
167
 * options should be added after coap_write_block_opt() has returned.
168
 *
169
 * @param block       The block structure to use. On return, this object is
170
 *                    updated according to the values that have been written to
171
 *                    @p pdu.
172
 * @param number      COAP_OPTION_BLOCK1 or COAP_OPTION_BLOCK2.
173
 * @param pdu         The message where the block option should be written.
174
 * @param data_length The length of the actual data that will be added the @p
175
 *                    pdu by calling coap_add_block().
176
 *
177
 * @return            @c 1 on success, or a negative value on error.
178
 */
179
int coap_write_block_opt(coap_block_t *block,
180
                         coap_option_num_t number,
181
                         coap_pdu_t *pdu,
182
                         size_t data_length);
183
/**
184
 * Writes a block option of type @p number to message @p pdu. If the requested
185
 * block size is too large to fit in @p pdu, it is reduced accordingly. An
186
 * exception is made for the final block when less space is required. The actual
187
 * length of the resource is specified in @p data_length.
188
 *
189
 * This function may change *block to reflect the values written to @p pdu. As
190
 * the function takes into consideration the remaining space @p pdu, no more
191
 * options should be added after coap_write_block_opt() has returned.
192
 *
193
 * @param session     The CoAP session.
194
 * @param block       The block structure to use. On return, this object is
195
 *                    updated according to the values that have been written to
196
 *                    @p pdu.
197
 * @param number      COAP_OPTION_BLOCK1 or COAP_OPTION_BLOCK2.
198
 * @param pdu         The message where the block option should be written.
199
 * @param data_length The length of the actual data that will be added the @p
200
 *                    pdu by calling coap_add_block().
201
 *
202
 * @return            @c 1 on success, or a negative value on error.
203
 */
204
int coap_write_block_b_opt(coap_session_t *session,
205
                           coap_block_b_t *block,
206
                           coap_option_num_t number,
207
                           coap_pdu_t *pdu,
208
                           size_t data_length);
209
210
211
/**
212
 * Adds the @p block_num block of size 1 << (@p block_szx + 4) from source @p
213
 * data to @p pdu.
214
 *
215
 * @param pdu       The message to add the block.
216
 * @param len       The length of @p data.
217
 * @param data      The source data to fill the block with.
218
 * @param block_num The actual block number.
219
 * @param block_szx Encoded size of block @p block_number.
220
 *
221
 * @return          @c 1 on success, @c 0 otherwise.
222
 */
223
int coap_add_block(coap_pdu_t *pdu,
224
                   size_t len,
225
                   const uint8_t *data,
226
                   unsigned int block_num,
227
                   unsigned char block_szx);
228
229
/**
230
 * Adds the appropriate payload data of the body to the @p pdu.
231
 *
232
 * @param pdu       The message to add the block.
233
 * @param len       The length of @p data.
234
 * @param data      The source data to fill the block with.
235
 * @param block     The block information (including potentially BERT)
236
 *
237
 * @return          @c 1 on success, @c 0 otherwise.
238
 */
239
int coap_add_block_b_data(coap_pdu_t *pdu, size_t len, const uint8_t *data,
240
                          coap_block_b_t *block);
241
242
/**
243
 * Re-assemble payloads into a body
244
 *
245
 * @param body_data The pointer to the data for the body holding the
246
 *                  representation so far or NULL if the first time.
247
 * @param length    The length of @p data.
248
 * @param data      The payload data to update the body with.
249
 * @param offset    The offset of the @p data into the body.
250
 * @param total     The estimated total size of the body.
251
 *
252
 * @return          The current representation of the body or @c NULL if error.
253
 *                  If NULL, @p body_data will have been de-allocated.
254
 */
255
COAP_API coap_binary_t *coap_block_build_body(coap_binary_t *body_data, size_t length,
256
                                              const uint8_t *data, size_t offset, size_t total);
257
258
/**
259
 * Adds the appropriate part of @p data to the @p response pdu.  If blocks are
260
 * required, then the appropriate block will be added to the PDU and sent.
261
 * Adds a ETag option that is the hash of the entire data if the data is to be
262
 * split into blocks
263
 * Used by a request handler.
264
 *
265
 * Note: The application will get called for every packet of a large body to
266
 * process. Consider using coap_add_data_response_large() instead.
267
 *
268
 * @param request    The requesting pdu.
269
 * @param response   The response pdu.
270
 * @param media_type The format of the data.
271
 * @param maxage     The maxmimum life of the data. If @c -1, then there
272
 *                   is no maxage.
273
 * @param length     The total length of the data.
274
 * @param data       The entire data block to transmit.
275
 *
276
 */
277
void coap_add_data_blocked_response(const coap_pdu_t *request,
278
                                    coap_pdu_t *response,
279
                                    uint16_t media_type,
280
                                    int maxage,
281
                                    size_t length,
282
                                    const uint8_t *data);
283
284
/**
285
 * Callback handler for de-allocating the data based on @p app_ptr provided to
286
 * coap_add_data_large_*() functions following transmission of the supplied
287
 * data.
288
 *
289
 * @param session The session that this data is associated with.
290
 * @param app_ptr The application provided pointer provided to the
291
 *                coap_add_data_large_* functions.
292
 */
293
typedef void (*coap_release_large_data_t)(coap_session_t *session,
294
                                          void *app_ptr);
295
296
/**
297
 * Associates given data with the @p pdu that is passed as second parameter.
298
 *
299
 * This function will fail if data has already been added to the @p pdu.
300
 *
301
 * If all the data can be transmitted in a single PDU, this is functionally
302
 * the same as coap_add_data() except @p release_func (if not NULL) will get
303
 * invoked after data transmission.
304
 *
305
 * Used for a client request.
306
 *
307
 * If the data spans multiple PDUs, then the data will get transmitted using
308
 * (Q-)Block1 option with the addition of the Size1 and Request-Tag options.
309
 * The underlying library will handle the transmission of the individual blocks.
310
 * Once the body of data has been transmitted (or a failure occurred), then
311
 * @p release_func (if not NULL) will get called so the application can
312
 * de-allocate the @p data based on @p app_data. It is the responsibility of
313
 * the application not to change the contents of @p data until the data
314
 * transfer has completed.
315
 *
316
 * There is no need for the application to include the (Q-)Block1 option in the
317
 * @p pdu.
318
 *
319
 * coap_add_data_large_request() (or the alternative coap_add_data_large_*()
320
 * functions) must be called only once per PDU and must be the last PDU update
321
 * before the PDU is transmitted. The (potentially) initial data will get
322
 * transmitted when coap_send() is invoked.
323
 *
324
 * Note: COAP_BLOCK_USE_LIBCOAP must be set by coap_context_set_block_mode()
325
 * for libcoap to work correctly when using this function.
326
 *
327
 * @param session  The session to associate the data with.
328
 * @param pdu      The PDU to associate the data with.
329
 * @param length   The length of data to transmit.
330
 * @param data     The data to transmit.
331
 * @param release_func The function to call to de-allocate @p app_ptr or @c NULL
332
 *                 if the function is not required.
333
 * @param app_ptr  A Pointer that the application can provide for when
334
 *                 release_func() is called.
335
 *
336
 * @return @c 1 if addition is successful, else @c 0.
337
 */
338
COAP_API int coap_add_data_large_request(coap_session_t *session,
339
                                         coap_pdu_t *pdu,
340
                                         size_t length,
341
                                         const uint8_t *data,
342
                                         coap_release_large_data_t release_func,
343
                                         void *app_ptr);
344
345
/**
346
 * Callback handler for getting the data based on @p app_ptr provided to
347
 * coap_add_data_large_request_app() function for then sending the next block
348
 * of data.
349
 *
350
 * @param session The session that this data is associated with.
351
 * @param max     The maximum size of the data to be returned.
352
 * @param offset  The starting offset of the requested data.
353
 * @param data    Where to copy the data into.
354
 * @param length  Updated with the provided data length. This cannot be
355
 *                larger than @p max. This must be the same as @p max
356
 *                apart from the final block.
357
 * @param app_ptr The application provided pointer provided to the
358
 *                coap_add_data_large_request_app function.
359
 *
360
 * @return 1 if data provided, else 0.
361
 */
362
typedef int (*coap_get_large_data_t)(coap_session_t *session, size_t max,
363
                                     size_t offset,
364
                                     uint8_t *data, size_t *length,
365
                                     void *app_ptr);
366
/**
367
 * Associates given data callback with the @p pdu that is passed as second parameter.
368
 *
369
 * This function will fail if data has already been added to the @p pdu.
370
 *
371
 * Used for a client request.
372
 *
373
 * If the data spans multiple PDUs, then the data will get transmitted using
374
 * (Q-)Block1 option with the addition of the Size1 and Request-Tag options.
375
 * The underlying library will handle the transmission of the individual blocks.
376
 *
377
 * Each individual block of data will get requested by the use of a call-back
378
 * function @p get_func before transmission.
379
 *
380
 * There is no need for the application to include the (Q-)Block1 option in the
381
 * @p pdu.
382
 *
383
 * coap_add_data_large_request_app() (or the alternative coap_add_data_large_*()
384
 * functions) must be called only once per PDU and must be the last PDU update
385
 * before the PDU is transmitted. The (potentially) initial data will get
386
 * transmitted when coap_send() is invoked.
387
 *
388
 * Note: COAP_BLOCK_USE_LIBCOAP must be set by coap_context_set_block_mode()
389
 * for libcoap to work correctly when using this function.
390
 *
391
 * @param session  The session to associate the data with.
392
 * @param pdu      The PDU to associate the data with.
393
 * @param length   The length of data to transmit.
394
 * @param release_func The function to call to de-allocate @p app_ptr or @c NULL
395
 *                 if the function is not required.
396
 * @param get_func The function to call to get the next block of data
397
 *                 for transmission.
398
 * @param app_ptr  A Pointer that the application can provide for when
399
 *                 @p get_func is called.
400
 *
401
 * @return @c 1 if addition is successful, else @c 0.
402
 */
403
COAP_API int coap_add_data_large_request_app(coap_session_t *session,
404
                                             coap_pdu_t *pdu,
405
                                             size_t length,
406
                                             coap_release_large_data_t release_func,
407
                                             coap_get_large_data_t get_func,
408
                                             void *app_ptr);
409
410
/**
411
 * Associates given data with the @p response pdu that is passed as fourth
412
 * parameter.
413
 *
414
 * This function will fail if data has already been added to the @p pdu.
415
 *
416
 * If all the data can be transmitted in a single PDU, this is functionally
417
 * the same as coap_add_data() except @p release_func (if not NULL) will get
418
 * invoked after data transmission. The Content-Format, Max-Age and ETag
419
 * options may be added in as appropriate.
420
 *
421
 * Used by a server request handler to create the response.
422
 *
423
 * If the data spans multiple PDUs, then the data will get transmitted using
424
 * (Q-)Block2 (response) option with the addition of the Size2 and ETag
425
 * options. The underlying library will handle the transmission of the
426
 * individual blocks. Once the body of data has been transmitted (or a
427
 * failure occurred), then @p release_func (if not NULL) will get called so the
428
 * application can de-allocate the @p data based on @p app_data. It is the
429
 * responsibility of the application not to change the contents of @p data
430
 * until the data transfer has completed.
431
 *
432
 * There is no need for the application to include the (Q-)Block2 option in the
433
 * @p pdu.
434
 *
435
 * coap_add_data_large_response() (or the alternative coap_add_data_large_*()
436
 * functions) must be called only once per PDU and must be the last PDU update
437
 * before returning from the request handler function.
438
 *
439
 * Note: COAP_BLOCK_USE_LIBCOAP must be set by coap_context_set_block_mode()
440
 * for libcoap to work correctly when using this function.
441
 *
442
 * @param resource   The resource the data is associated with.
443
 * @param session    The coap session.
444
 * @param request    The requesting pdu.
445
 * @param response   The response pdu.
446
 * @param query      The query taken from the (original) requesting pdu.
447
 * @param media_type The content format of the data.
448
 * @param maxage     The maxmimum life of the data. If @c -1, then there
449
 *                   is no maxage.
450
 * @param etag       ETag to use if not 0.
451
 * @param length     The total length of the data.
452
 * @param data       The entire data block to transmit.
453
 * @param release_func The function to call to de-allocate @p app_ptr or NULL if
454
 *                   the function is not required.
455
 * @param app_ptr    A Pointer that the application can provide for when
456
 *                   release_func() is called.
457
 *
458
 * @return @c 1 if addition is successful, else @c 0.
459
 */
460
COAP_API int coap_add_data_large_response(coap_resource_t *resource,
461
                                          coap_session_t *session,
462
                                          const coap_pdu_t *request,
463
                                          coap_pdu_t *response,
464
                                          const coap_string_t *query,
465
                                          uint16_t media_type,
466
                                          int maxage,
467
                                          uint64_t etag,
468
                                          size_t length,
469
                                          const uint8_t *data,
470
                                          coap_release_large_data_t release_func,
471
                                          void *app_ptr);
472
473
/**
474
 * Set the context level CoAP block handling bits for handling RFC7959.
475
 * These bits flow down to a session when a session is created and if the peer
476
 * does not support something, an appropriate bit may get disabled in the
477
 * session block_mode.
478
 * The session block_mode then flows down into coap_crcv_t or coap_srcv_t where
479
 * again an appropriate bit may get disabled.
480
 *
481
 * Note: This function must be called before the session is set up.
482
 *
483
 * Note: COAP_BLOCK_USE_LIBCOAP must be set if libcoap is to do all the
484
 * block tracking and requesting, otherwise the application will have to do
485
 * all of this work (the default if coap_context_set_block_mode() is not
486
 * called).
487
 *
488
 * @param context        The coap_context_t object.
489
 * @param block_mode     Zero or more COAP_BLOCK_ or'd options
490
 */
491
COAP_API void coap_context_set_block_mode(coap_context_t *context,
492
                                          uint32_t block_mode);
493
494
/**
495
 * Set the context level maximum block size that the server supports when sending
496
 * or receiving packets with Block1 or Block2 options.
497
 * This maximum block size flows down to a session when a session is created.
498
 *
499
 * Note: This function must be called before the session is set up.
500
 *
501
 * Note: COAP_BLOCK_USE_LIBCOAP must be set using coap_context_set_block_mode()
502
 * if libcoap is to do this work.
503
 *
504
 * @param context        The coap_context_t object.
505
 * @param max_block_size The maximum block size a server supports.  Can be 0
506
 *                       (reset), or must be 16, 32, 64, 128, 256, 512 or 1024.
507
 */
508
COAP_API int coap_context_set_max_block_size(coap_context_t *context, size_t max_block_size);
509
510
/**@}*/
511
512
#ifdef __cplusplus
513
}
514
#endif
515
516
#endif /* COAP_BLOCK_H_ */