Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
packet-coap.h
1/* packet-coap.h
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <[email protected]>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#ifndef __PACKET_COAP_H__
11#define __PACKET_COAP_H__
12
13#include "packet-oscore.h"
14
15/* bitmasks */
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_RESERVED_MASK 0xE0
22#define COAP_OBJECT_SECURITY_KID_CONTEXT_MASK 0x10
23#define COAP_OBJECT_SECURITY_KID_MASK 0x08
24#define COAP_OBJECT_SECURITY_PIVLEN_MASK 0x07
25
26/* Parent protocol for CoAP */
27typedef enum {
28 PARENT_WEBSOCKETS, /* WebSockets */
29 PARENT_TCP_TLS, /* TCP or TLS */
30 PARENT_OTHER /* UDP, WAP, other packet-based protocols */
31} coap_parent_protocol;
32
33/* CoAP Message information */
34typedef struct {
35 const char *ctype_str;
36 unsigned ctype_value;
37 unsigned block_option; /* Indicates Block1 or Block2 option */
38 unsigned block_number;
39 unsigned block_mflag;
40 unsigned block_size;
41 wmem_strbuf_t *uri_host_strbuf;
42 wmem_strbuf_t *uri_path_strbuf;
43 wmem_strbuf_t *uri_query_strbuf;
44 bool is_coap_for_tmf; /* CoAP for Thread Management Framework */
45 bool object_security;
46 oscore_info_t *oscore_info; /* OSCORE data needed to decrypt */
47} coap_info;
48
49/* CoAP Conversation information */
50typedef struct {
51 wmem_map_t *messages;
53
54/* CoAP Transaction tracking information */
55typedef struct {
56 wmem_map_t *req_rsp;
57 wmem_strbuf_t *uri_host_strbuf;
58 wmem_strbuf_t *uri_path_strbuf;
59 oscore_info_t *oscore_info; /* OSCORE transaction to decrypt response */
61
62typedef struct {
63 uint32_t req_frame;
64 uint32_t rsp_frame;
65 nstime_t req_time;
67
68/* common header fields, subtrees and expert info for SSL and DTLS dissectors */
69typedef struct coap_common_dissect {
70 struct {
71 /* Header fields */
72 int code;
73 /* Payload fields */
74 int payload;
75 int payload_desc;
76 int payload_length;
77
78 /* Option fields */
79 int opt_name;
80 int opt_desc;
81 int opt_delta;
82 int opt_delta_ext;
83 int opt_length;
84 int opt_length_ext;
85 int opt_end_marker;
86 int opt_ctype;
87 int opt_max_age;
88 int opt_proxy_uri;
89 int opt_proxy_scheme;
90 int opt_size1;
91 int opt_etag;
92 int opt_uri_host;
93 int opt_location_path;
94 int opt_uri_port;
95 int opt_location_query;
96 int opt_uri_path;
97 int opt_uri_path_recon;
98 int opt_observe_req;
99 int opt_observe_rsp;
100 int opt_hop_limit;
101 int opt_accept;
102 int opt_if_match;
103 int opt_block_number;
104 int opt_block_mflag;
105 int opt_block_size;
106 int opt_uri_query;
107 int opt_echo;
108 int opt_no_response;
109 int opt_request_tag;
110 int opt_ocf_version;
111 int opt_ocf_accept_version;
112 int opt_unknown;
113 int opt_object_security_reserved;
114 int opt_object_security_kid_context_present;
115 int opt_object_security_kid_present;
116 int opt_object_security_piv_len;
117 int opt_object_security_piv;
118 int opt_object_security_kid_context_len;
119 int opt_object_security_kid_context;
120 int opt_object_security_kid;
121
122 /* do not forget to update COAP_COMMON_HF_LIST! */
123 } hf;
124
125 struct {
126 int payload;
127 int option;
128
129 /* do not forget to update COAP_COMMON_ETT_LIST! */
130 } ett;
131
132 struct {
133 /* Generic expert info for malformed packets. */
134 expert_field opt_unknown_number;
135 expert_field opt_invalid_number;
136 expert_field opt_invalid_range;
137 expert_field opt_length_bad;
138 expert_field opt_object_security_bad;
139
140 /* do not forget to update COAP_COMMON_EI_LIST! */
141 } ei;
142} coap_common_dissect_t;
143
144uint8_t dissect_coap_code(tvbuff_t *tvb, proto_tree *coap_tree, unsigned *offset, coap_common_dissect_t *dissect_hf, uint8_t *code_class);
145unsigned dissect_coap_options(tvbuff_t *tvb, packet_info *pinfo, proto_tree *coap_tree, unsigned offset, unsigned offset_end, uint8_t code_class, coap_info *coinfo, coap_common_dissect_t *dissect_hf, bool *ok);
146void dissect_coap_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *coap_tree, proto_tree *parent_tree, int offset, int offset_end, uint8_t code_class, coap_info *coinfo, coap_common_dissect_t *dissect_hf, bool oscore);
147
148extern const value_string coap_vals_observe_options[];
149extern value_string_ext coap_vals_code_ext;
150
151/* {{{ */
152#define COAP_COMMON_LIST_T(name) \
153coap_common_dissect_t name
154/* }}} */
155
156/* {{{ */
157#define COAP_COMMON_HF_LIST(name, prefix) \
158 { & name .hf.code, \
159 { "Code", prefix ".code", \
160 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &coap_vals_code_ext, 0x0, \
161 NULL, HFILL } \
162 }, \
163 { & name .hf.payload, \
164 { "Payload", prefix ".payload", \
165 FT_STRING, BASE_NONE, NULL, 0x0, \
166 NULL, HFILL } \
167 }, \
168 { & name .hf.payload_desc, \
169 { "Payload Desc", prefix ".payload_desc", \
170 FT_STRING, BASE_NONE, NULL, 0x0, \
171 NULL, HFILL } \
172 }, \
173 { & name .hf.payload_length, \
174 { "Payload Length", prefix ".payload_length", \
175 FT_UINT32, BASE_DEC, NULL, 0x0, \
176 NULL, HFILL } \
177 }, \
178 { & name .hf.opt_name, \
179 { "Opt Name", prefix ".opt.name", \
180 FT_STRING, BASE_NONE, NULL, 0x0, \
181 NULL, HFILL } \
182 }, \
183 { & name .hf.opt_desc, \
184 { "Opt Desc", prefix ".opt.desc", \
185 FT_STRING, BASE_NONE, NULL, 0x0, \
186 NULL, HFILL } \
187 }, \
188 { & name .hf.opt_delta, \
189 { "Opt Delta", prefix ".opt.delta", \
190 FT_UINT8, BASE_DEC, NULL, 0xf0, \
191 NULL, HFILL } \
192 }, \
193 { & name .hf.opt_delta_ext, \
194 { "Opt Delta extended", prefix ".opt.delta_ext", \
195 FT_UINT16, BASE_DEC, NULL, 0x0, \
196 NULL, HFILL } \
197 }, \
198 { & name .hf.opt_length, \
199 { "Opt Length", prefix ".opt.length", \
200 FT_UINT8, BASE_DEC, NULL, 0x0f, \
201 "Option Length", HFILL } \
202 }, \
203 { & name .hf.opt_length_ext, \
204 { "Opt Length extended", prefix ".opt.length_ext", \
205 FT_UINT16, BASE_DEC, NULL, 0x0, \
206 NULL, HFILL } \
207 }, \
208 { & name .hf.opt_end_marker, \
209 { "End of options marker", prefix ".opt.end_marker", \
210 FT_UINT8, BASE_DEC, NULL, 0x00, \
211 NULL, HFILL } \
212 }, \
213 { & name .hf.opt_ctype, \
214 { "Content-type", prefix ".opt.ctype", \
215 FT_STRING, BASE_NONE, NULL, 0x0, \
216 NULL, HFILL } \
217 }, \
218 { & name .hf.opt_max_age, \
219 { "Max-age", prefix ".opt.max_age", \
220 FT_UINT32, BASE_DEC, NULL, 0x0, \
221 NULL, HFILL } \
222 }, \
223 { & name .hf.opt_proxy_uri, \
224 { "Proxy-Uri", prefix ".opt.proxy_uri", \
225 FT_STRING, BASE_NONE, NULL, 0x0, \
226 NULL, HFILL } \
227 }, \
228 { & name .hf.opt_proxy_scheme, \
229 { "Proxy-Scheme", prefix ".opt.proxy_scheme", \
230 FT_STRING, BASE_NONE, NULL, 0x0, \
231 NULL, HFILL } \
232 }, \
233 { & name .hf.opt_size1, \
234 { "Size1", prefix ".opt.size1", \
235 FT_UINT32, BASE_DEC, NULL, 0x0, \
236 NULL, HFILL } \
237 }, \
238 { & name .hf.opt_etag, \
239 { "Etag", prefix ".opt.etag", \
240 FT_BYTES, BASE_NONE, NULL, 0x0, \
241 "Option Etag", HFILL } \
242 }, \
243 { & name .hf.opt_uri_host, \
244 { "Uri-Host", prefix ".opt.uri_host", \
245 FT_STRING, BASE_NONE, NULL, 0x0, \
246 NULL, HFILL } \
247 }, \
248 { & name .hf.opt_location_path, \
249 { "Location-Path", prefix ".opt.location_path", \
250 FT_STRING, BASE_NONE, NULL, 0x0, \
251 NULL, HFILL } \
252 }, \
253 { & name .hf.opt_uri_port, \
254 { "Uri-Port", prefix ".opt.uri_port", \
255 FT_UINT16, BASE_DEC, NULL, 0x0, \
256 NULL, HFILL } \
257 }, \
258 { & name .hf.opt_location_query, \
259 { "Location-Query", prefix ".opt.location_query", \
260 FT_STRING, BASE_NONE, NULL, 0x0, \
261 NULL, HFILL } \
262 }, \
263 { & name .hf.opt_object_security_reserved, \
264 { "Reserved", prefix ".opt.object_security_reserved", \
265 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_RESERVED_MASK, \
266 NULL, HFILL } \
267 }, \
268 { & name .hf.opt_object_security_kid_context_present, \
269 { "Key ID Context Present", prefix ".opt.object_security_kid_context_present",\
270 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_KID_CONTEXT_MASK, \
271 NULL, HFILL } \
272 }, \
273 { & name .hf.opt_object_security_kid_present, \
274 { "Key ID Present", prefix ".opt.object_security_kid_present", \
275 FT_BOOLEAN, 8, NULL, COAP_OBJECT_SECURITY_KID_MASK, \
276 NULL, HFILL } \
277 }, \
278 { & name .hf.opt_object_security_piv_len, \
279 { "Partial IV Length", prefix ".opt.object_security_piv_len", \
280 FT_UINT8, BASE_DEC, NULL, COAP_OBJECT_SECURITY_PIVLEN_MASK, \
281 NULL, HFILL } \
282 }, \
283 { & name .hf.opt_object_security_piv, \
284 { "Partial IV", prefix ".opt.object_security_piv", \
285 FT_BYTES, BASE_NONE, NULL, 0x00, \
286 NULL, HFILL } \
287 }, \
288 { & name .hf.opt_object_security_kid_context_len, \
289 { "Key ID Context Length", prefix ".opt.object_security_kid_context_len",\
290 FT_UINT8, BASE_DEC, NULL, 0x00, \
291 NULL, HFILL } \
292 }, \
293 { & name .hf.opt_object_security_kid_context, \
294 { "Key ID Context", prefix ".opt.object_security_kid_context", \
295 FT_BYTES, BASE_NONE, NULL, 0x00, \
296 NULL, HFILL } \
297 }, \
298 { & name .hf.opt_object_security_kid, \
299 { "Key ID", prefix ".opt.object_security_kid", \
300 FT_BYTES, BASE_NONE, NULL, 0x00, \
301 NULL, HFILL } \
302 }, \
303 { & name .hf.opt_uri_path, \
304 { "Uri-Path", prefix ".opt.uri_path", \
305 FT_STRING, BASE_NONE, NULL, 0x0, \
306 NULL, HFILL } \
307 }, \
308 { & name .hf.opt_uri_path_recon, \
309 { "Uri-Path", prefix ".opt.uri_path_recon", \
310 FT_STRING, BASE_NONE, NULL, 0x0, \
311 NULL, HFILL } \
312 }, \
313 { & name .hf.opt_observe_req, \
314 { "Observe", prefix ".opt.observe", \
315 FT_UINT32, BASE_DEC, VALS(coap_vals_observe_options), 0x0, \
316 NULL, HFILL } \
317 }, \
318 { & name .hf.opt_observe_rsp, \
319 { "Observe sequence number", prefix ".opt.observe", \
320 FT_UINT32, BASE_DEC, NULL, 0x0, \
321 NULL, HFILL } \
322 }, \
323 { & name .hf.opt_hop_limit, \
324 { "Hop Limit", prefix ".opt.hop_limit", \
325 FT_UINT8, BASE_DEC, NULL, 0x0, \
326 NULL, HFILL } \
327 }, \
328 { & name .hf.opt_accept, \
329 { "Accept", prefix ".opt.accept", \
330 FT_STRING, BASE_NONE, NULL, 0x0, \
331 NULL, HFILL } \
332 }, \
333 { & name .hf.opt_if_match, \
334 { "If-Match", prefix ".opt.if_match", \
335 FT_BYTES, BASE_NONE, NULL, 0x0, \
336 NULL, HFILL } \
337 }, \
338 { & name .hf.opt_block_number, \
339 { "Block Number", prefix ".opt.block_number", \
340 FT_UINT32, BASE_DEC, NULL, 0x0, \
341 NULL, HFILL } \
342 }, \
343 { & name .hf.opt_block_mflag, \
344 { "More Flag", prefix ".opt.block_mflag", \
345 FT_UINT8, BASE_DEC, NULL, COAP_BLOCK_MFLAG_MASK, \
346 NULL, HFILL } \
347 }, \
348 { & name .hf.opt_block_size, \
349 { "Encoded Block Size", prefix ".opt.block_size", \
350 FT_UINT8, BASE_DEC, NULL, COAP_BLOCK_SIZE_MASK, \
351 NULL, HFILL } \
352 }, \
353 { & name .hf.opt_uri_query, \
354 { "Uri-Query", prefix ".opt.uri_query", \
355 FT_STRING, BASE_NONE, NULL, 0x0, \
356 NULL, HFILL } \
357 }, \
358 { & name .hf.opt_echo, \
359 { "Echo", prefix ".opt.opt_echo", \
360 FT_BYTES, BASE_NONE, NULL, 0x0, \
361 NULL, HFILL } \
362 }, \
363 { & name .hf.opt_no_response, \
364 { "No-Response", prefix ".opt.opt_no_response", \
365 FT_UINT8, BASE_DEC, NULL, 0x0, \
366 NULL, HFILL } \
367 }, \
368 { & name .hf.opt_request_tag, \
369 { "Request-Tag", prefix ".opt.opt_request_tag", \
370 FT_BYTES, BASE_NONE, NULL, 0x0, \
371 NULL, HFILL } \
372 }, \
373 { & name .hf.opt_ocf_version, \
374 { "OCF-Content-Format-Version", \
375 prefix ".opt.opt_ocf_version", \
376 FT_UINT8, BASE_DEC, NULL, 0x0, \
377 NULL, HFILL } \
378 }, \
379 { & name .hf.opt_ocf_accept_version, \
380 { "OCF-Accept-Content-Format-Version", \
381 prefix ".opt.opt_ocf_accept_version", \
382 FT_UINT8, BASE_DEC, NULL, 0x0, \
383 NULL, HFILL } \
384 }, \
385 { & name .hf.opt_unknown, \
386 { "Unknown", prefix ".opt.unknown", \
387 FT_BYTES, BASE_NONE, NULL, 0x0, \
388 NULL, HFILL } \
389 }, \
390/* }}} */
391
392/* {{{ */
393#define COAP_COMMON_ETT_LIST(name) \
394 & name .ett.payload, \
395 & name .ett.option, \
396
397/* }}} */
398
399/* {{{ */
400#define COAP_COMMON_EI_LIST(name, prefix) \
401 { & name .ei.opt_unknown_number, \
402 { prefix ".unknown_option_number", PI_UNDECODED, PI_WARN, \
403 "Unknown Option Number", EXPFILL } \
404 }, \
405 { & name .ei.opt_invalid_number, \
406 { prefix ".invalid_option_number", PI_MALFORMED, PI_WARN, \
407 "Invalid Option Number", EXPFILL } \
408 }, \
409 { & name .ei.opt_invalid_range, \
410 { prefix ".invalid_option_range", PI_MALFORMED, PI_WARN, \
411 "Invalid Option Range", EXPFILL } \
412 }, \
413 { & name .ei.opt_length_bad, \
414 { prefix ".option_length_bad", PI_MALFORMED, PI_WARN, \
415 "Option length bad", EXPFILL } \
416 }, \
417 { & name .ei.opt_object_security_bad, \
418 { prefix ".option_oscore_bad", PI_MALFORMED, PI_WARN, \
419 "Invalid OSCORE Option Format", EXPFILL } \
420 }, \
421
422/* }}} */
423
424#endif /* __PACKET_COAP_H__ */
425
426/*
427 * Editor modelines - https://www.wireshark.org/tools/modelines.html
428 *
429 * Local variables:
430 * c-basic-offset: 8
431 * tab-width: 8
432 * indent-tabs-mode: t
433 * End:
434 *
435 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
436 * :indentSize=8:tabSize=8:noTabs=false:
437 */
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
struct _wmem_map_t wmem_map_t
Opaque type representing a wmem-managed hash map.
Definition wmem_map.h:46
Definition packet-coap.h:69
Definition packet-coap.h:50
Definition packet-coap.h:34
Definition packet-coap.h:62
Definition packet-coap.h:55
Pairs an expert info index with its associated header field index for registration and display.
Definition expert.h:41
Definition nstime.h:26
struct _value_string value_string
Mapping between a 32-bit integer value and its string representation.