mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-24 07:47:14 +02:00
IDF release/v4.0 08219f3cf
This commit is contained in:
@ -7,24 +7,27 @@
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef _COAP_BLOCK_H_
|
||||
#define _COAP_BLOCK_H_
|
||||
#ifndef COAP_BLOCK_H_
|
||||
#define COAP_BLOCK_H_
|
||||
|
||||
#include "encode.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
|
||||
struct coap_resource_t;
|
||||
struct coap_session_t;
|
||||
|
||||
/**
|
||||
* @defgroup block Block Transfer
|
||||
* API functions for handling PDUs using CoAP BLOCK options
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef COAP_MAX_BLOCK_SZX
|
||||
/**
|
||||
* The largest value for the SZX component in a Block option. Note that
|
||||
* 1 << (COAP_MAX_BLOCK_SZX + 4) should not exceed COAP_MAX_PDU_SIZE.
|
||||
* The largest value for the SZX component in a Block option.
|
||||
*/
|
||||
#define COAP_MAX_BLOCK_SZX 4
|
||||
#define COAP_MAX_BLOCK_SZX 6
|
||||
#endif /* COAP_MAX_BLOCK_SZX */
|
||||
|
||||
/**
|
||||
@ -42,15 +45,15 @@ typedef struct {
|
||||
* returns @c NULL.
|
||||
*/
|
||||
#define COAP_OPT_BLOCK_LAST(opt) \
|
||||
(COAP_OPT_LENGTH(opt) ? (COAP_OPT_VALUE(opt) + (COAP_OPT_LENGTH(opt)-1)) : 0)
|
||||
(coap_opt_length(opt) ? (coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
|
||||
|
||||
/** Returns the value of the More-bit of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_MORE(opt) \
|
||||
(COAP_OPT_LENGTH(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
|
||||
|
||||
/** Returns the value of the SZX-field of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_SZX(opt) \
|
||||
(COAP_OPT_LENGTH(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
|
||||
|
||||
/**
|
||||
* Returns the value of field @c num in the given block option @p block_opt.
|
||||
@ -61,19 +64,21 @@ unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
|
||||
* Checks if more than @p num blocks are required to deliver @p data_len
|
||||
* bytes of data for a block size of 1 << (@p szx + 4).
|
||||
*/
|
||||
static inline int
|
||||
coap_more_blocks(size_t data_len, unsigned int num, unsigned short szx) {
|
||||
COAP_STATIC_INLINE int
|
||||
coap_more_blocks(size_t data_len, unsigned int num, uint16_t szx) {
|
||||
return ((num+1) << (szx + 4)) < data_len;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/** Sets the More-bit in @p block_opt */
|
||||
static inline void
|
||||
COAP_STATIC_INLINE void
|
||||
coap_opt_block_set_m(coap_opt_t *block_opt, int m) {
|
||||
if (m)
|
||||
*(COAP_OPT_VALUE(block_opt) + (COAP_OPT_LENGTH(block_opt) - 1)) |= 0x08;
|
||||
*(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) |= 0x08;
|
||||
else
|
||||
*(COAP_OPT_VALUE(block_opt) + (COAP_OPT_LENGTH(block_opt) - 1)) &= ~0x08;
|
||||
*(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) &= ~0x08;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initializes @p block from @p pdu. @p type must be either COAP_OPTION_BLOCK1
|
||||
@ -88,7 +93,7 @@ coap_opt_block_set_m(coap_opt_t *block_opt, int m) {
|
||||
*
|
||||
* @return @c 1 on success, @c 0 otherwise.
|
||||
*/
|
||||
int coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block);
|
||||
int coap_get_block(coap_pdu_t *pdu, uint16_t type, coap_block_t *block);
|
||||
|
||||
/**
|
||||
* Writes a block option of type @p type to message @p pdu. If the requested
|
||||
@ -111,7 +116,7 @@ int coap_get_block(coap_pdu_t *pdu, unsigned short type, coap_block_t *block);
|
||||
* @return @c 1 on success, or a negative value on error.
|
||||
*/
|
||||
int coap_write_block_opt(coap_block_t *block,
|
||||
unsigned short type,
|
||||
uint16_t type,
|
||||
coap_pdu_t *pdu,
|
||||
size_t data_length);
|
||||
|
||||
@ -129,9 +134,40 @@ int coap_write_block_opt(coap_block_t *block,
|
||||
*/
|
||||
int coap_add_block(coap_pdu_t *pdu,
|
||||
unsigned int len,
|
||||
const unsigned char *data,
|
||||
const uint8_t *data,
|
||||
unsigned int block_num,
|
||||
unsigned char block_szx);
|
||||
|
||||
/**
|
||||
* Adds the appropriate part of @p data to the @p response pdu. If blocks are
|
||||
* required, then the appropriate block will be added to the PDU and sent.
|
||||
* Adds a ETAG option that is the hash of the entire data if the data is to be
|
||||
* split into blocks
|
||||
* Used by a GET request handler.
|
||||
*
|
||||
* @param resource The resource the data is associated with.
|
||||
* @param session The coap session.
|
||||
* @param request The requesting pdu.
|
||||
* @param response The response pdu.
|
||||
* @param token The token taken from the (original) requesting pdu.
|
||||
* @param media_type The format of the data.
|
||||
* @param maxage The maxmimum life of the data. If @c -1, then there
|
||||
* is no maxage.
|
||||
* @param length The total length of the data.
|
||||
* @param data The entire data block to transmit.
|
||||
*
|
||||
*/
|
||||
void
|
||||
coap_add_data_blocked_response(struct coap_resource_t *resource,
|
||||
struct 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);
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif /* _COAP_BLOCK_H_ */
|
||||
#endif /* COAP_BLOCK_H_ */
|
||||
|
Reference in New Issue
Block a user