libcoap
4.1.1
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Macros
Groups
Pages
block.h
Go to the documentation of this file.
1
/* block.h -- block transfer
2
*
3
* Copyright (C) 2010--2012,2014 Olaf Bergmann <bergmann@tzi.org>
4
*
5
* This file is part of the CoAP library libcoap. Please see
6
* README for terms of use.
7
*/
8
9
#ifndef _COAP_BLOCK_H_
10
#define _COAP_BLOCK_H_
11
12
#include "
option.h
"
13
#include "
encode.h
"
14
#include "
pdu.h
"
15
21
#ifndef COAP_MAX_BLOCK_SZX
22
27
#define COAP_MAX_BLOCK_SZX 4
28
#endif
/* COAP_MAX_BLOCK_SZX */
29
30
#if (COAP_MAX_PDU_SIZE - 6) < (1 << (COAP_MAX_BLOCK_SZX + 4))
31
#error "COAP_MAX_BLOCK_SZX too large"
32
#endif
33
37
typedef
struct
{
38
unsigned
int
num:20;
39
unsigned
int
m:1;
40
unsigned
int
szx:3;
41
}
coap_block_t
;
42
48
#define COAP_OPT_BLOCK_LAST(opt) \
49
(COAP_OPT_LENGTH(opt) ? (COAP_OPT_VALUE(opt) + (COAP_OPT_LENGTH(opt)-1)) : 0)
50
52
#define COAP_OPT_BLOCK_MORE(opt) \
53
(COAP_OPT_LENGTH(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
54
56
#define COAP_OPT_BLOCK_SZX(opt) \
57
(COAP_OPT_LENGTH(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
58
63
unsigned
int
coap_opt_block_num
(
const
coap_opt_t
*block_opt);
64
69
static
inline
int
70
coap_more_blocks
(
size_t
data_len,
unsigned
int
num,
unsigned
short
szx) {
71
return
((num+1) << (szx + 4)) < data_len;
72
}
73
75
static
inline
void
76
coap_opt_block_set_m
(
coap_opt_t
*block_opt,
int
m) {
77
if
(m)
78
*(
COAP_OPT_VALUE
(block_opt) + (
COAP_OPT_LENGTH
(block_opt) - 1)) |= 0x08;
79
else
80
*(
COAP_OPT_VALUE
(block_opt) + (
COAP_OPT_LENGTH
(block_opt) - 1)) &= ~0x08;
81
}
82
95
int
coap_get_block
(
coap_pdu_t
*pdu,
unsigned
short
type,
coap_block_t
*
block
);
96
119
int
coap_write_block_opt
(
coap_block_t
*
block
,
unsigned
short
type,
120
coap_pdu_t
*pdu,
size_t
data_length);
121
133
int
coap_add_block
(
coap_pdu_t
*pdu,
unsigned
int
len,
const
unsigned
char
*data,
134
unsigned
int
block_num,
unsigned
char
block_szx);
137
#endif
/* _COAP_BLOCK_H_ */
Generated on Wed Feb 5 2014 15:10:20 for libcoap by
1.8.4