block.h
Go to the documentation of this file.
/*
* block.h -- block transfer
*
* Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#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;
#ifndef COAP_MAX_BLOCK_SZX
#define COAP_MAX_BLOCK_SZX 6
#endif /* COAP_MAX_BLOCK_SZX */
typedef struct {
unsigned int num;
unsigned int m:1;
unsigned int szx:3;
} coap_block_t;
#define COAP_OPT_BLOCK_LAST(opt) \
(coap_opt_length(opt) ? (coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
#define COAP_OPT_BLOCK_MORE(opt) \
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
#define COAP_OPT_BLOCK_SZX(opt) \
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
unsigned int coap_opt_block_num(const coap_opt_t *block_opt);
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
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;
else
*(coap_opt_value(block_opt) + (coap_opt_length(block_opt) - 1)) &= ~0x08;
}
#endif
int coap_get_block(coap_pdu_t *pdu, uint16_t type, coap_block_t *block);
int coap_write_block_opt(coap_block_t *block,
uint16_t type,
coap_pdu_t *pdu,
size_t data_length);
int coap_add_block(coap_pdu_t *pdu,
unsigned int len,
const uint8_t *data,
unsigned int block_num,
unsigned char block_szx);
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_ */
encode.h
coap_write_block_opt
int coap_write_block_opt(coap_block_t *block, uint16_t type, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type type to message pdu.
Definition: block.c:64
coap_add_block
int coap_add_block(coap_pdu_t *pdu, unsigned int 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:125
coap_add_data_blocked_response
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)
Adds the appropriate part of data to the response pdu.
Definition: block.c:142
coap_get_block
int coap_get_block(coap_pdu_t *pdu, uint16_t type, coap_block_t *block)
Initializes block from pdu.
Definition: block.c:36
coap_more_blocks
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
coap_opt_block_num
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:17
coap_opt_length
uint16_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
Definition: option.c:238
coap_opt_value
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
Definition: option.c:275
COAP_STATIC_INLINE
#define COAP_STATIC_INLINE
Definition: libcoap.h:38
option.h
Helpers for handling options in CoAP PDUs.
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:25
pdu.h
Pre-defined constants that reflect defaults for CoAP.
coap_binary_t
Coap binary data definition.
Definition: str.h:43
coap_block_t
Structure of Block options.
Definition: block.h:36
coap_block_t::num
unsigned int num
block number
Definition: block.h:37
coap_block_t::szx
unsigned int szx
block size
Definition: block.h:39
coap_block_t::m
unsigned int m
1 if more blocks follow, 0 otherwise
Definition: block.h:38
coap_pdu_t
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: pdu.h:285
coap_resource_t
Definition: resource.h:68
coap_session_t
Definition: coap_session.h:59
uint8_t
unsigned char uint8_t
Definition: uthash.h:79