3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef __PACKET_COAP_H__
11 #define __PACKET_COAP_H__
13 #include "packet-oscore.h"
16 #define COAP_VERSION_MASK 0xC0
17 #define COAP_TYPE_MASK 0x30
18 #define COAP_TOKEN_LEN_MASK 0x0F
19 #define COAP_BLOCK_MFLAG_MASK 0x08
20 #define COAP_BLOCK_SIZE_MASK 0x07
21 #define COAP_OBJECT_SECURITY_NON_COMPRESSED_MASK 0x80
22 #define COAP_OBJECT_SECURITY_EXPAND_MASK 0x40
23 #define COAP_OBJECT_SECURITY_SIGNATURE_MASK 0x20
24 #define COAP_OBJECT_SECURITY_KID_CONTEXT_MASK 0x10
25 #define COAP_OBJECT_SECURITY_KID_MASK 0x08
26 #define COAP_OBJECT_SECURITY_PIVLEN_MASK 0x07
28 /* CoAP Message information */
30 const gchar *ctype_str;
34 wmem_strbuf_t *uri_str_strbuf; /* the maximum is 1024 > 510 = Uri-Host:255 + Uri-Path:255 x 2 */
35 wmem_strbuf_t *uri_query_strbuf; /* the maximum is 1024 > 765 = Uri-Query:255 x 3 */
36 gboolean object_security;
37 oscore_info_t *oscore_info; /* OSCORE data needed to decrypt */
40 /* CoAP Conversation information */
45 /* CoAP Transaction tracking information */
50 wmem_strbuf_t *uri_str_strbuf;
51 oscore_info_t *oscore_info; /* OSCORE transaction to decrypt response */
54 /* common header fields, subtrees and expert info for SSL and DTLS dissectors */
55 typedef struct coap_common_dissect {
79 int opt_location_path;
81 int opt_location_query;
83 int opt_uri_path_recon;
92 int opt_object_security_non_compressed;
93 int opt_object_security_expand;
94 int opt_object_security_signature;
95 int opt_object_security_kid_context_present;
96 int opt_object_security_kid_present;
97 int opt_object_security_piv_len;
98 int opt_object_security_piv;
99 int opt_object_security_kid_context_len;
100 int opt_object_security_kid_context;
101 int opt_object_security_kid;
103 /* do not forget to update COAP_COMMON_LIST_T and COAP_COMMON_HF_LIST! */
110 /* do not forget to update COAP_COMMON_LIST_T and COAP_COMMON_ETT_LIST! */
114 /* Generic expert info for malformed packets. */
115 expert_field opt_invalid_number;
116 expert_field opt_invalid_range;
117 expert_field opt_length_bad;
118 expert_field opt_object_security_bad;
120 /* do not forget to update COAP_COMMON_LIST_T and COAP_COMMON_EI_LIST! */
122 } coap_common_dissect_t;
124 guint8 dissect_coap_code(tvbuff_t *tvb, proto_tree *coap_tree, gint *offset, coap_common_dissect_t *dissect_hf, guint8 *code_class);
125 int dissect_coap_options(tvbuff_t *tvb, packet_info *pinfo, proto_tree *coap_tree, gint offset, gint offset_end, coap_info *coinfo, coap_common_dissect_t *dissect_hf);
126 void dissect_coap_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *coap_tree, proto_tree *parent_tree, gint offset, gint offset_end, guint8 code_class, coap_info *coinfo, coap_common_dissect_t *dissect_hf, gboolean oscore);
128 extern const value_string coap_vals_observe_options[];
129 extern value_string_ext coap_vals_code_ext;
132 #define COAP_COMMON_LIST_T(name) \
133 coap_common_dissect_t name = { \
135 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, \
136 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, \
137 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, \
138 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, \
145 EI_INIT, EI_INIT, EI_INIT, EI_INIT, \
151 #define COAP_COMMON_HF_LIST(name, prefix) \
153 { "Code", prefix ".code", \
154 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &coap_vals_code_ext, 0x0, \
157 { & name .hf.payload, \
158 { "Payload", prefix ".payload", \
159 FT_STRING, BASE_NONE, NULL, 0x0, \
162 { & name .hf.payload_desc, \
163 { "Payload Desc", prefix ".payload_desc", \
164 FT_STRING, BASE_NONE, NULL, 0x0, \
167 { & name .hf.payload_length, \
168 { "Payload Length", prefix ".payload_length", \
169 FT_UINT32, BASE_DEC, NULL, 0x0, \
172 { & name .hf.opt_name, \
173 { "Opt Name", prefix ".opt.name", \
174 FT_STRING, BASE_NONE, NULL, 0x0, \
177 { & name .hf.opt_desc, \
178 { "Opt Desc", prefix ".opt.desc", \
179 FT_STRING, BASE_NONE, NULL, 0x0, \
182 { & name .hf.opt_delta, \
183 { "Opt Delta", prefix ".opt.delta", \
184 FT_UINT8, BASE_DEC, NULL, 0xf0, \
187 { & name .hf.opt_delta_ext, \
188 { "Opt Delta extended", prefix ".opt.delta_ext", \
189 FT_UINT16, BASE_DEC, NULL, 0x0, \
192 { & name .hf.opt_length, \
193 { "Opt Length", prefix ".opt.length", \
194 FT_UINT8, BASE_DEC, NULL, 0x0f, \
195 "Option Length", HFILL } \
197 { & name .hf.opt_length_ext, \
198 { "Opt Length extended", prefix ".opt.length_ext", \
199 FT_UINT16, BASE_DEC, NULL, 0x0, \
202 { & name .hf.opt_end_marker, \
203 { "End of options marker", prefix ".opt.end_marker", \
204 FT_UINT8, BASE_DEC, NULL, 0x00, \
207 { & name .hf.opt_ctype, \
208 { "Content-type", prefix ".opt.ctype", \
209 FT_STRING, BASE_NONE, NULL, 0x0, \
212 { & name .hf.opt_max_age, \
213 { "Max-age", prefix ".opt.max_age", \
214 FT_UINT32, BASE_DEC, NULL, 0x0, \
217 { & name .hf.opt_proxy_uri, \
218 { "Proxy-Uri", prefix ".opt.proxy_uri", \
219 FT_STRING, BASE_NONE, NULL, 0x0, \
222 { & name .hf.opt_proxy_scheme, \
223 { "Proxy-Scheme", prefix ".opt.proxy_scheme", \
224 FT_STRING, BASE_NONE, NULL, 0x0, \
227 { & name .hf.opt_size1, \
228 { "Size1", prefix ".opt.size1", \
229 FT_UINT32, BASE_DEC, NULL, 0x0, \
232 { & name .hf.opt_etag, \
233 { "Etag", prefix ".opt.etag", \
234 FT_BYTES, BASE_NONE, NULL, 0x0, \
235 "Option Etag", HFILL } \
237 { & name .hf.opt_uri_host, \
238 { "Uri-Host", prefix ".opt.uri_host", \
239 FT_STRING, BASE_NONE, NULL, 0x0, \
242 { & name .hf.opt_location_path, \
243 { "Location-Path", prefix ".opt.location_path", \
244 FT_STRING, BASE_NONE, NULL, 0x0, \
247 { & name .hf.opt_uri_port, \
248 { "Uri-Port", prefix ".opt.uri_port", \
249 FT_UINT16, BASE_DEC, NULL, 0x0, \
252 { & name .hf.opt_location_query, \
253 { "Location-Query", prefix ".opt.location_query", \
254 FT_STRING, BASE_NONE, NULL, 0x0, \
257 { & name .hf.opt_object_security_non_compressed, \
258 { "Non-compressed COSE message", prefix ".opt.object_security_non_compressed",\
259 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_NON_COMPRESSED_MASK, \
262 { & name .hf.opt_object_security_expand, \
263 { "Expanded Flag Byte", prefix ".opt.object_security_expand", \
264 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_EXPAND_MASK, \
267 { & name .hf.opt_object_security_signature, \
268 { "Signature Present", prefix ".opt.object_security_signature", \
269 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_SIGNATURE_MASK, \
272 { & name .hf.opt_object_security_kid_context_present, \
273 { "Key ID Context Present", prefix ".opt.object_security_kid_context_present",\
274 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_KID_CONTEXT_MASK, \
277 { & name .hf.opt_object_security_kid_present, \
278 { "Key ID Present", prefix ".opt.object_security_kid_present", \
279 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_KID_MASK, \
282 { & name .hf.opt_object_security_piv_len, \
283 { "Partial IV Length", prefix ".opt.object_security_piv_len", \
284 FT_UINT8, BASE_DEC, NULL, COAP_OBJECT_SECURITY_PIVLEN_MASK, \
287 { & name .hf.opt_object_security_piv, \
288 { "Partial IV", prefix ".opt.object_security_piv", \
289 FT_BYTES, BASE_NONE, NULL, 0x00, \
292 { & name .hf.opt_object_security_kid_context_len, \
293 { "Key ID Context Length", prefix ".opt.object_security_kid_context_len",\
294 FT_UINT8, BASE_DEC, NULL, 0x00, \
297 { & name .hf.opt_object_security_kid_context, \
298 { "Partial IV", prefix ".opt.object_security_kid_context", \
299 FT_BYTES, BASE_NONE, NULL, 0x00, \
302 { & name .hf.opt_object_security_kid, \
303 { "Key ID", prefix ".opt.object_security_kid", \
304 FT_BYTES, BASE_NONE, NULL, 0x00, \
307 { & name .hf.opt_uri_path, \
308 { "Uri-Path", prefix ".opt.uri_path", \
309 FT_STRING, BASE_NONE, NULL, 0x0, \
312 { & name .hf.opt_uri_path_recon, \
313 { "Uri-Path", prefix ".opt.uri_path_recon", \
314 FT_STRING, BASE_NONE, NULL, 0x0, \
317 { & name .hf.opt_observe, \
318 { "Observe", prefix ".opt.observe", \
319 FT_UINT32, BASE_DEC, VALS(coap_vals_observe_options), 0x0, \
322 { & name .hf.opt_accept, \
323 { "Accept", prefix ".opt.accept", \
324 FT_STRING, BASE_NONE, NULL, 0x0, \
327 { & name .hf.opt_if_match, \
328 { "If-Match", prefix ".opt.if_match", \
329 FT_BYTES, BASE_NONE, NULL, 0x0, \
332 { & name .hf.opt_block_number, \
333 { "Block Number", prefix ".opt.block_number", \
334 FT_UINT32, BASE_DEC, NULL, 0x0, \
337 { & name .hf.opt_block_mflag, \
338 { "More Flag", prefix ".opt.block_mflag", \
339 FT_UINT8, BASE_DEC, NULL, COAP_BLOCK_MFLAG_MASK, \
342 { & name .hf.opt_block_size, \
343 { "Encoded Block Size", prefix ".opt.block_size", \
344 FT_UINT8, BASE_DEC, NULL, COAP_BLOCK_SIZE_MASK, \
347 { & name .hf.opt_uri_query, \
348 { "Uri-Query", prefix ".opt.uri_query", \
349 FT_STRING, BASE_NONE, NULL, 0x0, \
352 { & name .hf.opt_unknown, \
353 { "Unknown", prefix ".opt.unknown", \
354 FT_BYTES, BASE_NONE, NULL, 0x0, \
360 #define COAP_COMMON_ETT_LIST(name) \
361 & name .ett.payload, \
362 & name .ett.option, \
367 #define COAP_COMMON_EI_LIST(name, prefix) \
368 { & name .ei.opt_invalid_number, \
369 { prefix ".invalid_option_number", PI_MALFORMED, PI_WARN, \
370 "Invalid Option Number", EXPFILL } \
372 { & name .ei.opt_invalid_range, \
373 { prefix ".invalid_option_range", PI_MALFORMED, PI_WARN, \
374 "Invalid Option Range", EXPFILL } \
376 { & name .ei.opt_length_bad, \
377 { prefix ".option_length_bad", PI_MALFORMED, PI_WARN, \
378 "Option length bad", EXPFILL } \
380 { & name .ei.opt_object_security_bad, \
381 { prefix ".option_object_security_bad", PI_MALFORMED, PI_WARN, \
382 "Invalid Object-Security Option Format", EXPFILL } \
387 #endif /* __PACKET_COAP_H__ */
390 * Editor modelines - http://www.wireshark.org/tools/modelines.html
395 * indent-tabs-mode: t
398 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
399 * :indentSize=8:tabSize=8:noTabs=false: