checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / dissectors / packet-coap.h
1 /* packet-coap.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
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_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
27
28 /* CoAP Message information */
29 typedef struct {
30         const gchar *ctype_str;
31         guint ctype_value;
32         guint block_number;
33         guint block_mflag;
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 */
38 } coap_info;
39
40 /* CoAP Conversation information */
41 typedef struct {
42         wmem_map_t *messages;
43 } coap_conv_info;
44
45 /* CoAP Transaction tracking information */
46 typedef struct {
47         guint32  req_frame;
48         guint32  rsp_frame;
49         nstime_t req_time;
50         wmem_strbuf_t *uri_str_strbuf;
51         oscore_info_t *oscore_info;             /* OSCORE transaction to decrypt response */
52 } coap_transaction;
53
54 /* common header fields, subtrees and expert info for SSL and DTLS dissectors */
55 typedef struct coap_common_dissect {
56         struct {
57                 /* Header fields */
58                 int code;
59                 /* Payload fields */
60                 int payload;
61                 int payload_desc;
62                 int payload_length;
63
64                 /* Option fields */
65                 int opt_name;
66                 int opt_desc;
67                 int opt_delta;
68                 int opt_delta_ext;
69                 int opt_length;
70                 int opt_length_ext;
71                 int opt_end_marker;
72                 int opt_ctype;
73                 int opt_max_age;
74                 int opt_proxy_uri;
75                 int opt_proxy_scheme;
76                 int opt_size1;
77                 int opt_etag;
78                 int opt_uri_host;
79                 int opt_location_path;
80                 int opt_uri_port;
81                 int opt_location_query;
82                 int opt_uri_path;
83                 int opt_uri_path_recon;
84                 int opt_observe;
85                 int opt_accept;
86                 int opt_if_match;
87                 int opt_block_number;
88                 int opt_block_mflag;
89                 int opt_block_size;
90                 int opt_uri_query;
91                 int opt_unknown;
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;
102
103         /* do not forget to update COAP_COMMON_LIST_T and COAP_COMMON_HF_LIST! */
104         } hf;
105
106         struct {
107                 gint payload;
108                 gint option;
109
110         /* do not forget to update COAP_COMMON_LIST_T and COAP_COMMON_ETT_LIST! */
111         } ett;
112
113         struct {
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;
119
120         /* do not forget to update COAP_COMMON_LIST_T and COAP_COMMON_EI_LIST! */
121         } ei;
122 } coap_common_dissect_t;
123
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);
127
128 extern const value_string coap_vals_observe_options[];
129 extern value_string_ext coap_vals_code_ext;
130
131 /* {{{ */
132 #define COAP_COMMON_LIST_T(name)                                                \
133 coap_common_dissect_t name = {                                                  \
134         /* hf */ {                                                              \
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,                         \
139                 -1,                                                             \
140                 },                                                              \
141         /* ett */ {                                                             \
142                 -1, -1,                                                         \
143                 },                                                              \
144         /* ei */ {                                                              \
145                 EI_INIT, EI_INIT, EI_INIT, EI_INIT,                             \
146                 },                                                              \
147 }
148 /* }}} */
149
150 /* {{{ */
151 #define COAP_COMMON_HF_LIST(name, prefix)                                       \
152         { & name .hf.code,                                                      \
153           { "Code", prefix ".code",                                             \
154             FT_UINT8, BASE_DEC | BASE_EXT_STRING, &coap_vals_code_ext, 0x0,     \
155             NULL, HFILL }                                                       \
156         },                                                                      \
157         { & name .hf.payload,                                                   \
158           { "Payload",  prefix ".payload",                                      \
159             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
160             NULL, HFILL }                                                       \
161         },                                                                      \
162         { & name .hf.payload_desc,                                              \
163           { "Payload Desc",  prefix ".payload_desc",                            \
164             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
165             NULL, HFILL }                                                       \
166         },                                                                      \
167         { & name .hf.payload_length,                                            \
168           { "Payload Length",  prefix ".payload_length",                        \
169             FT_UINT32, BASE_DEC, NULL, 0x0,                                     \
170             NULL, HFILL }                                                       \
171         },                                                                      \
172         { & name .hf.opt_name,                                                  \
173           { "Opt Name",  prefix ".opt.name",                                    \
174             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
175             NULL, HFILL }                                                       \
176         },                                                                      \
177         { & name .hf.opt_desc,                                                  \
178           { "Opt Desc",  prefix ".opt.desc",                                    \
179             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
180             NULL, HFILL }                                                       \
181         },                                                                      \
182         { & name .hf.opt_delta,                                                 \
183           { "Opt Delta",  prefix ".opt.delta",                                  \
184             FT_UINT8, BASE_DEC, NULL, 0xf0,                                     \
185             NULL, HFILL }                                                       \
186         },                                                                      \
187         { & name .hf.opt_delta_ext,                                             \
188           { "Opt Delta extended",  prefix ".opt.delta_ext",                     \
189             FT_UINT16, BASE_DEC, NULL, 0x0,                                     \
190             NULL, HFILL }                                                       \
191         },                                                                      \
192         { & name .hf.opt_length,                                                \
193           { "Opt Length",  prefix ".opt.length",                                \
194             FT_UINT8, BASE_DEC, NULL, 0x0f,                                     \
195             "Option Length", HFILL }                                            \
196         },                                                                      \
197         { & name .hf.opt_length_ext,                                            \
198           { "Opt Length extended",  prefix ".opt.length_ext",                   \
199             FT_UINT16, BASE_DEC, NULL, 0x0,                                     \
200             NULL, HFILL }                                                       \
201         },                                                                      \
202         { & name .hf.opt_end_marker,                                            \
203           { "End of options marker",  prefix ".opt.end_marker",                 \
204             FT_UINT8, BASE_DEC, NULL, 0x00,                                     \
205             NULL, HFILL }                                                       \
206         },                                                                      \
207         { & name .hf.opt_ctype,                                                 \
208           { "Content-type",  prefix ".opt.ctype",                               \
209             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
210             NULL, HFILL }                                                       \
211         },                                                                      \
212         { & name .hf.opt_max_age,                                               \
213           { "Max-age",  prefix ".opt.max_age",                                  \
214             FT_UINT32, BASE_DEC, NULL, 0x0,                                     \
215             NULL, HFILL }                                                       \
216         },                                                                      \
217         { & name .hf.opt_proxy_uri,                                             \
218           { "Proxy-Uri",  prefix ".opt.proxy_uri",                              \
219             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
220             NULL, HFILL }                                                       \
221         },                                                                      \
222         { & name .hf.opt_proxy_scheme,                                          \
223           { "Proxy-Scheme",  prefix ".opt.proxy_scheme",                        \
224             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
225             NULL, HFILL }                                                       \
226         },                                                                      \
227         { & name .hf.opt_size1,                                                 \
228           { "Size1",  prefix ".opt.size1",                                      \
229             FT_UINT32, BASE_DEC, NULL, 0x0,                                     \
230             NULL, HFILL }                                                       \
231         },                                                                      \
232         { & name .hf.opt_etag,                                                  \
233           { "Etag",  prefix ".opt.etag",                                        \
234             FT_BYTES, BASE_NONE, NULL, 0x0,                                     \
235             "Option Etag", HFILL }                                              \
236         },                                                                      \
237         { & name .hf.opt_uri_host,                                              \
238           { "Uri-Host",  prefix ".opt.uri_host",                                \
239             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
240             NULL, HFILL }                                                       \
241         },                                                                      \
242         { & name .hf.opt_location_path,                                         \
243           { "Location-Path",  prefix ".opt.location_path",                      \
244             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
245             NULL, HFILL }                                                       \
246         },                                                                      \
247         { & name .hf.opt_uri_port,                                              \
248           { "Uri-Port",  prefix ".opt.uri_port",                                \
249             FT_UINT16, BASE_DEC, NULL, 0x0,                                     \
250             NULL, HFILL }                                                       \
251         },                                                                      \
252         { & name .hf.opt_location_query,                                        \
253           { "Location-Query",  prefix ".opt.location_query",                    \
254             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
255             NULL, HFILL }                                                       \
256         },                                                                      \
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,      \
260             NULL, HFILL }                                                       \
261         },                                                                      \
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,              \
265             NULL, HFILL }                                                       \
266         },                                                                      \
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,           \
270             NULL, HFILL }                                                       \
271         },                                                                      \
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,         \
275             NULL, HFILL }                                                       \
276         },                                                                      \
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,                 \
280             NULL, HFILL }                                                       \
281         },                                                                      \
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,         \
285             NULL, HFILL }                                                       \
286         },                                                                      \
287         { & name .hf.opt_object_security_piv,                                   \
288           { "Partial IV",  prefix ".opt.object_security_piv",                   \
289             FT_BYTES, BASE_NONE, NULL, 0x00,                                    \
290             NULL, HFILL }                                                       \
291         },                                                                      \
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,                                     \
295             NULL, HFILL }                                                       \
296         },                                                                      \
297         { & name .hf.opt_object_security_kid_context,                           \
298           { "Partial IV",  prefix ".opt.object_security_kid_context",           \
299             FT_BYTES, BASE_NONE, NULL, 0x00,                                    \
300             NULL, HFILL }                                                       \
301         },                                                                      \
302         { & name .hf.opt_object_security_kid,                                   \
303           { "Key ID",  prefix ".opt.object_security_kid",                       \
304             FT_BYTES, BASE_NONE, NULL, 0x00,                                    \
305             NULL, HFILL }                                                       \
306         },                                                                      \
307         { & name .hf.opt_uri_path,                                              \
308           { "Uri-Path",  prefix ".opt.uri_path",                                \
309             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
310             NULL, HFILL }                                                       \
311         },                                                                      \
312         { & name .hf.opt_uri_path_recon,                                        \
313           { "Uri-Path",  prefix ".opt.uri_path_recon",                          \
314             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
315             NULL, HFILL }                                                       \
316         },                                                                      \
317         { & name .hf.opt_observe,                                               \
318           { "Observe",  prefix ".opt.observe",                                  \
319             FT_UINT32, BASE_DEC, VALS(coap_vals_observe_options), 0x0,          \
320             NULL, HFILL }                                                       \
321         },                                                                      \
322         { & name .hf.opt_accept,                                                \
323           { "Accept",  prefix ".opt.accept",                                    \
324             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
325             NULL, HFILL }                                                       \
326         },                                                                      \
327         { & name .hf.opt_if_match,                                              \
328           { "If-Match",  prefix ".opt.if_match",                                \
329             FT_BYTES, BASE_NONE, NULL, 0x0,                                     \
330             NULL, HFILL }                                                       \
331         },                                                                      \
332         { & name .hf.opt_block_number,                                          \
333           { "Block Number",  prefix ".opt.block_number",                        \
334             FT_UINT32, BASE_DEC, NULL, 0x0,                                     \
335             NULL, HFILL }                                                       \
336         },                                                                      \
337         { & name .hf.opt_block_mflag,                                           \
338           { "More Flag",  prefix ".opt.block_mflag",                            \
339             FT_UINT8, BASE_DEC, NULL, COAP_BLOCK_MFLAG_MASK,                    \
340             NULL, HFILL }                                                       \
341         },                                                                      \
342         { & name .hf.opt_block_size,                                            \
343           { "Encoded Block Size",  prefix ".opt.block_size",                    \
344             FT_UINT8, BASE_DEC, NULL, COAP_BLOCK_SIZE_MASK,                     \
345             NULL, HFILL }                                                       \
346         },                                                                      \
347         { & name .hf.opt_uri_query,                                             \
348           { "Uri-Query",  prefix ".opt.uri_query",                              \
349             FT_STRING, BASE_NONE, NULL, 0x0,                                    \
350             NULL, HFILL }                                                       \
351         },                                                                      \
352         { & name .hf.opt_unknown,                                               \
353           { "Unknown",  prefix ".opt.unknown",                                  \
354             FT_BYTES, BASE_NONE, NULL, 0x0,                                     \
355             NULL, HFILL }                                                       \
356         },                                                                      \
357 /* }}} */
358
359 /* {{{ */
360 #define COAP_COMMON_ETT_LIST(name)                                              \
361         & name .ett.payload,                                                    \
362         & name .ett.option,                                                     \
363
364 /* }}} */
365
366 /* {{{ */
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 }                                  \
371         },                                                                      \
372         { & name .ei.opt_invalid_range,                                         \
373           { prefix ".invalid_option_range", PI_MALFORMED, PI_WARN,              \
374             "Invalid Option Range", EXPFILL }                                   \
375         },                                                                      \
376         { & name .ei.opt_length_bad,                                            \
377           { prefix ".option_length_bad", PI_MALFORMED, PI_WARN,                 \
378             "Option length bad", EXPFILL }                                      \
379         },                                                                      \
380         { & name .ei.opt_object_security_bad,                                   \
381           { prefix ".option_object_security_bad", PI_MALFORMED, PI_WARN,        \
382             "Invalid Object-Security Option Format", EXPFILL }                  \
383         },                                                                      \
384
385 /* }}} */
386
387 #endif /* __PACKET_COAP_H__ */
388
389 /*
390  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
391  *
392  * Local variables:
393  * c-basic-offset: 8
394  * tab-width: 8
395  * indent-tabs-mode: t
396  * End:
397  *
398  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
399  * :indentSize=8:tabSize=8:noTabs=false:
400  */