1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
* coap_pdu_internal.h -- CoAP PDU structure
*
* Copyright (C) 2010-2022 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
/**
* @file coap_pdu_internal.h
* @brief CoAP PDU internal information
*/
/**
* @ingroup internal_api
* @defgroup pdu_internal PDU
* Internal API for PDUs
* @{
*/
/* TCP Message format constants, do not modify */
/* Derived message size limits */
/* 1024 derived from RFC7252 4.6. Message Size max payload */
/* defined(WITH_CONTIKI) || defined(WITH_LWIP) */
/* COAP_DEBUG_BUF_SIZE */
/* 8 MiB max-message-size plus some space for options */
/* COAP_DEFAULT_MAX_PDU_RX_SIZE */
/**
* Indicates that a response is suppressed. This will occur for error
* responses if the request was received via IP multicast.
*/
/**
* structure for CoAP PDUs
*
* Separate COAP_PDU_BUF is allocated with offsets held in coap_pdu_t.
* token, if any, follows the fixed size header, then optional options until
* payload marker (0xff) (if paylooad), then the optional payload.
*
* Memory layout is:
* <---header--->|<---token---><---options--->0xff<---payload--->
*
* header is addressed with a negative offset to token, its maximum size is
* max_hdr_size.
*
* allocated buffer always starts max_hdr_size before token.
*
* options starts at token + token_length.
* payload starts at data, its length is used_size - (data - token).
*
* alloc_size, used_size and max_size are the offsets from token.
*/
;
/**
* Dynamically grows the size of @p pdu to @p new_size. The new size
* must not exceed the PDU's configure maximum size. On success, this
* function returns 1, otherwise 0.
*
* @param pdu The PDU to resize.
* @param new_size The new size in bytes.
* @return 1 if the operation succeeded, 0 otherwise.
*/
int ;
/**
* Dynamically grows the size of @p pdu to @p new_size if needed. The new size
* must not exceed the PDU's configured maximum size. On success, this
* function returns 1, otherwise 0.
*
* @param pdu The PDU to resize.
* @param new_size The new size in bytes.
* @return 1 if the operation succeeded, 0 otherwise.
*/
int ;
/**
* Interprets @p data to determine the number of bytes in the header.
* This function returns @c 0 on error or a number greater than zero on success.
*
* @param proto Session's protocol
* @param data The first byte of raw data to parse as CoAP PDU.
*
* @return A value greater than zero on success or @c 0 on error.
*/
size_t ;
/**
* Parses @p data to extract the message size.
* @p length must be at least coap_pdu_parse_header_size(proto, data).
* This function returns @c 0 on error or a number greater than zero on success.
*
* @param proto Session's protocol
* @param data The raw data to parse as CoAP PDU.
* @param length The actual size of @p data.
*
* @return A value greater than zero on success or @c 0 on error.
*/
size_t ;
/**
* Decode the protocol specific header for the specified PDU.
* @param pdu A newly received PDU.
* @param proto The target wire protocol.
* @return 1 for success or 0 on error.
*/
int ;
/**
* Verify consistency in the given CoAP PDU structure and locate the data.
* This function returns @c 0 on error or a number greater than zero on
* success.
* This function only parses the token and options, up to the payload start
* marker.
*
* @param pdu The PDU structure to check.
*
* @return 1 on success or @c 0 on error.
*/
int ;
/**
* Clears any contents from @p pdu and resets @c used_size,
* and @c data pointers. @c max_size is set to @p size, any
* other field is set to @c 0. Note that @p pdu must be a valid
* pointer to a coap_pdu_t object created e.g. by coap_pdu_init().
*
* @param pdu The PDU to clear.
* @param size The maximum size of the PDU.
*/
void ;
/**
* Adds option of given @p number to @p pdu that is passed as first
* parameter.
*
* The internal version of coap_add_option() may cause an @p option to be
* inserted, even if there is any data in the @p pdu.
*
* Note: Where possible, the option @p data needs to be stripped of leading
* zeros (big endian) to reduce the amount of data needed in the PDU, as well
* as in some cases the maximum data size of an option can be exceeded if not
* stripped and hence be illegal. This is done by using coap_encode_var_safe()
* or coap_encode_var_safe8().
*
* @param pdu The PDU where the option is to be added.
* @param number The number of the new option.
* @param len The length of the new option.
* @param data The data of the new option.
*
* @return The overall length of the option or @c 0 on failure.
*/
size_t ;
/**
* Removes (first) option of given number from the @p pdu.
*
* @param pdu The PDU to remove the option from.
* @param number The number of the CoAP option to remove (first only removed).
*
* @return @c 1 if success else @c 0 if error.
*/
int ;
/**
* Inserts option of given number in the @p pdu with the appropriate data.
* The option will be inserted in the appropriate place in the options in
* the pdu.
*
* @param pdu The PDU where the option is to be inserted.
* @param number The number of the new option.
* @param len The length of the new option.
* @param data The data of the new option.
*
* @return The overall length of the option or @c 0 on failure.
*/
size_t ;
/**
* Updates existing first option of given number in the @p pdu with the new
* data.
*
* @param pdu The PDU where the option is to be updated.
* @param number The number of the option to update (first only updated).
* @param len The length of the updated option.
* @param data The data of the updated option.
*
* @return The overall length of the updated option or @c 0 on failure.
*/
size_t ;
/**
* Compose the protocol specific header for the specified PDU.
*
* @param pdu A newly composed PDU.
* @param proto The target wire protocol.
*
* @return Number of header bytes prepended before pdu->token or 0 on error.
*/
size_t ;
/**
* Updates token in @p pdu with length @p len and @p data.
* This function returns @c 0 on error or a value greater than zero on success.
*
* @param pdu The PDU where the token is to be updated.
* @param len The length of the new token.
* @param data The token to add.
*
* @return A value greater than zero on success, or @c 0 on error.
*/
int ;
/** @} */
/* COAP_COAP_PDU_INTERNAL_H_ */