Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-ccsds.c
blob4cf4f306452b3713b364d36f40020c91b721348b
1 /* packet-ccsds.c
2 * Routines for CCSDS dissection
3 * Copyright 2000, Scott Hovis scott.hovis@ums.msfc.nasa.gov
4 * Enhanced 2008, Matt Dunkle Matthew.L.Dunkle@nasa.gov
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/expert.h>
17 #include <epan/prefs.h>
18 #include <epan/to_str.h>
20 void proto_register_ccsds(void);
21 void proto_reg_handoff_ccsds(void);
24 * See
26 * https://public.ccsds.org/Pubs/133x0b1s.pdf section 4.1 -- CCSDS 133.0-B-1 replaces CCSDS 701.0-B-2
27 * http://everyspec.com/NASA/NASA-JSC/NASA-SSP-PUBS/download.php?spec=SSP_52050E.003096.pdf section 3.1.3
29 * for some information.
33 /* Initialize the protocol and registered fields */
34 static int proto_ccsds;
36 /* primary ccsds header */
37 static int hf_ccsds_header_flags;
38 static int hf_ccsds_apid;
39 static int hf_ccsds_version;
40 static int hf_ccsds_secheader;
41 static int hf_ccsds_type;
42 static int hf_ccsds_seqnum;
43 static int hf_ccsds_seqflag;
44 static int hf_ccsds_length;
46 /* common ccsds secondary header */
47 static int hf_ccsds_coarse_time;
48 static int hf_ccsds_fine_time;
49 static int hf_ccsds_timeid;
50 static int hf_ccsds_checkword_flag;
52 /* payload specific ccsds secondary header */
53 static int hf_ccsds_zoe;
54 static int hf_ccsds_packet_type_unused;
55 static int hf_ccsds_vid;
56 static int hf_ccsds_dcc;
58 /* core specific ccsds secondary header */
59 /* static int hf_ccsds_spare1; */
60 static int hf_ccsds_packet_type;
61 /* static int hf_ccsds_spare2; */
62 static int hf_ccsds_element_id;
63 static int hf_ccsds_cmd_data_packet;
64 static int hf_ccsds_format_version_id;
65 static int hf_ccsds_extended_format_id;
66 /* static int hf_ccsds_spare3; */
67 static int hf_ccsds_frame_id;
68 static int hf_ccsds_embedded_time;
69 static int hf_ccsds_user_data;
71 /* ccsds checkword (checksum) */
72 static int hf_ccsds_checkword;
73 static int hf_ccsds_checkword_good;
74 static int hf_ccsds_checkword_bad;
76 /* Initialize the subtree pointers */
77 static int ett_ccsds_primary_header_flags;
78 static int ett_ccsds;
79 static int ett_ccsds_primary_header;
80 static int ett_ccsds_secondary_header;
81 static int ett_ccsds_checkword;
83 static expert_field ei_ccsds_length_error;
84 static expert_field ei_ccsds_checkword;
86 static dissector_handle_t ccsds_handle;
87 /* Dissector table */
88 static dissector_table_t ccsds_dissector_table;
90 static const enum_val_t dissect_checkword[] = {
91 { "hdr", "Use header flag", 2 },
92 { "no", "Override header flag to be false", 0 },
93 { "yes", "Override header flag to be true", 1 },
94 { NULL, NULL, 0 }
97 /* Global preferences */
98 /* As defined above, default is to use header flag */
99 static int global_dissect_checkword = 2;
102 * Bits in the first 16-bit header word
104 #define HDR_VERSION 0xe000
105 #define HDR_TYPE 0x1000
106 #define HDR_SECHDR 0x0800
107 #define HDR_APID 0x07ff
109 /* some basic sizing parameters */
110 enum
112 IP_HEADER_LENGTH = 48,
113 VCDU_HEADER_LENGTH = 6,
114 CCSDS_PRIMARY_HEADER_LENGTH = 6,
115 CCSDS_SECONDARY_HEADER_LENGTH = 10
118 /* leap year macro */
119 #ifndef Leap
120 # define Leap(yr) ( ( 0 == (yr)%4 && 0 != (yr)%100 ) || ( 0 == (yr)%400 ) )
121 #endif
124 static const value_string ccsds_primary_header_sequence_flags[] = {
125 { 0, "Continuation segment" },
126 { 1, "First segment" },
127 { 2, "Last segment" },
128 { 3, "Unsegmented data" },
129 { 0, NULL }
132 static const value_string ccsds_secondary_header_type[] = {
133 { 0, "Core" },
134 { 1, "Payload" },
135 { 0, NULL }
138 static const value_string ccsds_secondary_header_packet_type[] = {
139 { 0, "UNDEFINED" },
140 { 1, "Data Dump" },
141 { 2, "UNDEFINED" },
142 { 3, "UNDEFINED" },
143 { 4, "TLM/Status" },
144 { 5, "UNDEFINED" },
145 { 6, "Payload Private/Science" },
146 { 7, "Ancillary Data" },
147 { 8, "Essential Cmd" },
148 { 9, "System Cmd" },
149 { 10, "Payload Cmd" },
150 { 11, "Data Load/File Transfer" },
151 { 12, "UNDEFINED" },
152 { 13, "UNDEFINED" },
153 { 14, "UNDEFINED" },
154 { 15, "UNDEFINED" },
155 { 0, NULL }
158 static const value_string ccsds_secondary_header_element_id[] = {
159 { 0, "NASA (Ground Test Only)" },
160 { 1, "NASA" },
161 { 2, "ESA/APM" },
162 { 3, "NASDA" },
163 { 4, "RSA" },
164 { 5, "CSA" },
165 { 6, "ESA/ATV" },
166 { 7, "ASI" },
167 { 8, "ESA/ERA" },
168 { 9, "Reserved" },
169 { 10, "RSA SPP" },
170 { 11, "NASDA HTV" },
171 { 12, "Reserved" },
172 { 13, "Reserved" },
173 { 14, "Reserved" },
174 { 15, "Reserved" },
175 { 0, NULL }
178 static const value_string ccsds_secondary_header_cmd_data_packet[] = {
179 { 0, "Command Packet" },
180 { 1, "Data Packet" },
181 { 0, NULL }
184 static const value_string ccsds_secondary_header_format_id[] = {
185 { 0, "Reserved" },
186 { 1, "Essential Telemetry" },
187 { 2, "Housekeeping Tlm - 1" },
188 { 3, "Housekeeping Tlm - 2" },
189 { 4, "PCS DDT" },
190 { 5, "CCS S-Band Command Response" },
191 { 6, "Contingency Telemetry via the SMCC" },
192 { 7, "Normal Data Dump" },
193 { 8, "Extended Data Dump" },
194 { 9, "Reserved" },
195 { 10, "Reserved" },
196 { 11, "Broadcast Ancillary Data" },
197 { 12, "Reserved" },
198 { 13, "NCS to OIU Telemetry and ECOMM Telemetry" },
199 { 14, "CCS to OIU Telemetry - Direct" },
200 { 15, "Reserved" },
201 { 16, "Normal File Dump" },
202 { 17, "Extended File Dump" },
203 { 18, "NCS to FGB Telemetry" },
204 { 19, "Reserved" },
205 { 20, "ZOE Normal Dump (S-Band)" },
206 { 21, "ZOE Extended Dump (S-Band)" },
207 { 22, "EMU S-Band TLM Packet" },
208 { 23, "Reserved" },
209 { 24, "Reserved" },
210 { 25, "Reserved" },
211 { 26, "CCS to OIU Telemetry via UHF" },
212 { 27, "OSTP Telemetry (After Flight 1E, CCS R5)" },
213 { 28, "Reserved" },
214 { 29, "Reserved" },
215 { 30, "Reserved" },
216 { 31, "Reserved" },
217 { 32, "Reserved" },
218 { 33, "Reserved" },
219 { 34, "Reserved" },
220 { 35, "Reserved" },
221 { 36, "Reserved" },
222 { 37, "Reserved" },
223 { 38, "Reserved" },
224 { 39, "Reserved" },
225 { 40, "Reserved" },
226 { 41, "Reserved" },
227 { 42, "Reserved" },
228 { 43, "Reserved" },
229 { 44, "Reserved" },
230 { 45, "Reserved" },
231 { 46, "Reserved" },
232 { 47, "Reserved" },
233 { 48, "Reserved" },
234 { 49, "Reserved" },
235 { 50, "Reserved" },
236 { 51, "Reserved" },
237 { 52, "Reserved" },
238 { 53, "Reserved" },
239 { 54, "Reserved" },
240 { 55, "Reserved" },
241 { 56, "Reserved" },
242 { 57, "Reserved" },
243 { 58, "Reserved" },
244 { 59, "Reserved" },
245 { 60, "Reserved" },
246 { 61, "Reserved" },
247 { 62, "Reserved" },
248 { 63, "Reserved" },
249 { 0, NULL }
251 static value_string_ext ccsds_secondary_header_format_id_ext = VALUE_STRING_EXT_INIT(ccsds_secondary_header_format_id);
255 /* convert ccsds embedded time to a human readable string - NOT THREAD SAFE */
256 static const char* embedded_time_to_string ( wmem_allocator_t *pool, int coarse_time, int fine_time )
258 static int utcdiff = 0;
259 nstime_t t;
260 int yr;
261 int fraction;
262 int multiplier = 1000;
264 /* compute the static constant difference in seconds
265 * between midnight 5-6 January 1980 (GPS time) and
266 * seconds since 1/1/1970 (UTC time) just this once
268 if ( 0 == utcdiff )
270 for ( yr = 1970; yr < 1980; ++yr )
272 utcdiff += ( Leap(yr) ? 366 : 365 ) * 24 * 60 * 60;
275 utcdiff += 5 * 24 * 60 * 60; /* five days of January 1980 */
278 t.secs = coarse_time + utcdiff;
279 fraction = ( multiplier * ( (int)fine_time & 0xff ) ) / 256;
280 t.nsecs = fraction*1000000; /* msecs to nsecs */
282 return abs_time_to_str(pool, &t, ABSOLUTE_TIME_DOY_UTC, true);
286 /* Code to actually dissect the packets */
287 static int
288 dissect_ccsds(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
290 int offset = 0;
291 proto_item *ccsds_packet;
292 proto_tree *ccsds_tree;
293 proto_item *primary_header;
294 proto_tree *primary_header_tree;
295 uint16_t first_word;
296 uint32_t coarse_time;
297 uint8_t fine_time;
298 proto_item *secondary_header;
299 proto_tree *secondary_header_tree;
300 const char *time_string;
301 int ccsds_length;
302 int length = 0;
303 int reported_length;
304 uint8_t checkword_flag = 0;
305 int counter = 0;
306 proto_item *item, *checkword_item = NULL;
307 proto_tree *checkword_tree;
308 uint16_t checkword_field = 0;
309 uint16_t checkword_sum = 0;
310 tvbuff_t *next_tvb;
311 static int * const header_flags[] = {
312 &hf_ccsds_version,
313 &hf_ccsds_type,
314 &hf_ccsds_secheader,
315 &hf_ccsds_apid,
316 NULL
319 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CCSDS");
320 col_set_str(pinfo->cinfo, COL_INFO, "CCSDS Packet");
322 first_word = tvb_get_ntohs(tvb, 0);
323 col_add_fstr(pinfo->cinfo, COL_INFO, "APID %4d (0x%03X)", first_word&HDR_APID, first_word&HDR_APID);
325 reported_length = tvb_reported_length_remaining(tvb, 0);
326 ccsds_length = tvb_get_ntohs(tvb, 4) + CCSDS_PRIMARY_HEADER_LENGTH + 1;
329 /* Min length is size of headers, whereas max length is reported length.
330 * If the length field in the CCSDS header is outside of these bounds,
331 * use the value it violates. Otherwise, use the length field value.
333 if (ccsds_length > reported_length)
334 length = reported_length;
335 else if (ccsds_length < CCSDS_PRIMARY_HEADER_LENGTH + CCSDS_SECONDARY_HEADER_LENGTH)
336 length = CCSDS_PRIMARY_HEADER_LENGTH + CCSDS_SECONDARY_HEADER_LENGTH;
337 else
338 length = ccsds_length;
340 ccsds_packet = proto_tree_add_item(tree, proto_ccsds, tvb, 0, length, ENC_NA);
341 ccsds_tree = proto_item_add_subtree(ccsds_packet, ett_ccsds);
343 /* build the ccsds primary header tree */
344 primary_header_tree = proto_tree_add_subtree(ccsds_tree, tvb, offset, CCSDS_PRIMARY_HEADER_LENGTH,
345 ett_ccsds_primary_header, &primary_header, "Primary CCSDS Header");
347 proto_tree_add_bitmask(primary_header_tree, tvb, offset, hf_ccsds_header_flags,
348 ett_ccsds_primary_header_flags, header_flags, ENC_BIG_ENDIAN);
349 offset += 2;
351 proto_tree_add_item(primary_header_tree, hf_ccsds_seqflag, tvb, offset, 2, ENC_BIG_ENDIAN);
352 proto_tree_add_item(primary_header_tree, hf_ccsds_seqnum, tvb, offset, 2, ENC_BIG_ENDIAN);
353 offset += 2;
355 item = proto_tree_add_item(primary_header_tree, hf_ccsds_length, tvb, offset, 2, ENC_BIG_ENDIAN);
357 if (ccsds_length > reported_length) {
358 expert_add_info(pinfo, item, &ei_ccsds_length_error);
361 offset += 2;
362 proto_item_set_end(primary_header, tvb, offset);
364 /* build the ccsds secondary header tree */
365 if ( first_word & HDR_SECHDR )
367 secondary_header_tree = proto_tree_add_subtree(ccsds_tree, tvb, offset, CCSDS_SECONDARY_HEADER_LENGTH,
368 ett_ccsds_secondary_header, &secondary_header, "Secondary CCSDS Header");
370 /* command ccsds secondary header flags */
371 coarse_time = tvb_get_ntohl(tvb, offset);
372 proto_tree_add_item(secondary_header_tree, hf_ccsds_coarse_time, tvb, offset, 4, ENC_BIG_ENDIAN);
373 offset += 4;
375 fine_time = tvb_get_uint8(tvb, offset);
376 proto_tree_add_item(secondary_header_tree, hf_ccsds_fine_time, tvb, offset, 1, ENC_BIG_ENDIAN);
377 ++offset;
379 time_string = embedded_time_to_string ( pinfo->pool, coarse_time, fine_time );
380 proto_tree_add_string(secondary_header_tree, hf_ccsds_embedded_time, tvb, offset-5, 5, time_string);
382 proto_tree_add_item(secondary_header_tree, hf_ccsds_timeid, tvb, offset, 1, ENC_BIG_ENDIAN);
383 checkword_item = proto_tree_add_item(secondary_header_tree, hf_ccsds_checkword_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
385 /* Global Preference: how to handle checkword flag */
386 switch (global_dissect_checkword) {
387 case 0:
388 /* force checkword presence flag to be false */
389 checkword_flag = 0;
390 break;
391 case 1:
392 /* force checkword presence flag to be true */
393 checkword_flag = 1;
394 break;
395 default:
396 /* use value of checkword presence flag from header */
397 checkword_flag = (tvb_get_uint8(tvb, offset)&0x20) >> 5;
398 break;
401 /* payload specific ccsds secondary header flags */
402 if ( first_word & HDR_TYPE )
404 proto_tree_add_item(secondary_header_tree, hf_ccsds_zoe, tvb, offset, 1, ENC_BIG_ENDIAN);
405 proto_tree_add_item(secondary_header_tree, hf_ccsds_packet_type_unused, tvb, offset, 1, ENC_BIG_ENDIAN);
406 ++offset;
408 proto_tree_add_item(secondary_header_tree, hf_ccsds_vid, tvb, offset, 2, ENC_BIG_ENDIAN);
409 offset += 2;
411 proto_tree_add_item(secondary_header_tree, hf_ccsds_dcc, tvb, offset, 2, ENC_BIG_ENDIAN);
412 offset += 2;
415 /* core specific ccsds secondary header flags */
416 else
418 /* proto_tree_add_item(secondary_header_tree, hf_ccsds_spare1, tvb, offset, 1, ENC_BIG_ENDIAN); */
419 proto_tree_add_item(secondary_header_tree, hf_ccsds_packet_type, tvb, offset, 1, ENC_BIG_ENDIAN);
420 ++offset;
422 /* proto_tree_add_item(secondary_header_tree, hf_ccsds_spare2, tvb, offset, 2, ENC_BIG_ENDIAN); */
423 proto_tree_add_item(secondary_header_tree, hf_ccsds_element_id, tvb, offset, 2, ENC_BIG_ENDIAN);
424 proto_tree_add_item(secondary_header_tree, hf_ccsds_cmd_data_packet, tvb, offset, 2, ENC_BIG_ENDIAN);
425 proto_tree_add_item(secondary_header_tree, hf_ccsds_format_version_id, tvb, offset, 2, ENC_BIG_ENDIAN);
426 proto_tree_add_item(secondary_header_tree, hf_ccsds_extended_format_id, tvb, offset, 2, ENC_BIG_ENDIAN);
427 offset += 2;
429 /* proto_tree_add_item(secondary_header_tree, hf_ccsds_spare3, tvb, offset, 1, ENC_BIG_ENDIAN); */
430 ++offset;
432 proto_tree_add_item(secondary_header_tree, hf_ccsds_frame_id, tvb, offset, 1, ENC_BIG_ENDIAN);
433 ++offset;
436 /* finish the ccsds secondary header */
437 proto_item_set_end(secondary_header, tvb, offset);
440 /* If there wasn't a full packet, then don't allow a tree item for checkword. */
441 if (reported_length < ccsds_length || ccsds_length < CCSDS_PRIMARY_HEADER_LENGTH + CCSDS_SECONDARY_HEADER_LENGTH) {
442 /* Label CCSDS payload 'User Data' */
443 if (length > offset)
444 proto_tree_add_item(ccsds_tree, hf_ccsds_user_data, tvb, offset, length-offset, ENC_NA);
445 offset += length-offset;
446 if (checkword_flag == 1)
447 expert_add_info(pinfo, checkword_item, &ei_ccsds_checkword);
449 /* Handle checkword according to CCSDS preference setting. */
450 else {
451 next_tvb = tvb_new_subset_remaining(tvb, offset);
452 /* Look for a subdissector for the CCSDS payload */
453 if (!dissector_try_uint(ccsds_dissector_table, first_word&HDR_APID, next_tvb, pinfo, tree)) {
454 /* If no subdissector is found, label the CCSDS payload as 'User Data' */
455 proto_tree_add_item(ccsds_tree, hf_ccsds_user_data, tvb, offset, length-offset-2*checkword_flag, ENC_NA);
457 offset += length-offset-2*checkword_flag;
459 /* If checkword is present, calculate packet checksum (16-bit running sum) for comparison */
460 if (checkword_flag == 1) {
461 /* don't count the checkword as part of the checksum */
462 while (counter < ccsds_length-2) {
463 checkword_sum += tvb_get_ntohs(tvb, counter);
464 counter += 2;
466 checkword_field = tvb_get_ntohs(tvb, offset);
468 /* Report checkword status */
469 if (checkword_sum == checkword_field) {
470 item = proto_tree_add_uint_format_value(ccsds_tree, hf_ccsds_checkword, tvb, offset, 2, checkword_field,
471 "0x%04x [correct]", checkword_field);
472 checkword_tree = proto_item_add_subtree(item, ett_ccsds_checkword);
473 item = proto_tree_add_boolean(checkword_tree, hf_ccsds_checkword_good, tvb, offset, 2, true);
474 proto_item_set_generated(item);
475 item = proto_tree_add_boolean(checkword_tree, hf_ccsds_checkword_bad, tvb, offset, 2, false);
476 proto_item_set_generated(item);
477 } else {
478 item = proto_tree_add_uint_format_value(ccsds_tree, hf_ccsds_checkword, tvb, offset, 2, checkword_field,
479 "0x%04x [incorrect, should be 0x%04x]", checkword_field, checkword_sum);
480 checkword_tree = proto_item_add_subtree(item, ett_ccsds_checkword);
481 item = proto_tree_add_boolean(checkword_tree, hf_ccsds_checkword_good, tvb, offset, 2, false);
482 proto_item_set_generated(item);
483 item = proto_tree_add_boolean(checkword_tree, hf_ccsds_checkword_bad, tvb, offset, 2, true);
484 proto_item_set_generated(item);
486 offset += 2;
490 /* Give the data dissector any bytes past the CCSDS packet length */
491 call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo, tree);
492 return tvb_captured_length(tvb);
496 void
497 proto_register_ccsds(void)
499 static hf_register_info hf[] = {
501 /* primary ccsds header flags */
502 { &hf_ccsds_header_flags,
503 { "Header Flags", "ccsds.header_flags",
504 FT_UINT16, BASE_HEX, NULL, 0x0,
505 NULL, HFILL }
507 { &hf_ccsds_version,
508 { "Version", "ccsds.version",
509 FT_UINT16, BASE_DEC, NULL, HDR_VERSION,
510 NULL, HFILL }
512 { &hf_ccsds_type,
513 { "Type", "ccsds.type",
514 FT_UINT16, BASE_DEC, VALS(ccsds_secondary_header_type), HDR_TYPE,
515 NULL, HFILL }
517 { &hf_ccsds_secheader,
518 { "Secondary Header", "ccsds.secheader",
519 FT_BOOLEAN, 16, NULL, HDR_SECHDR,
520 "Secondary Header Present", HFILL }
522 { &hf_ccsds_apid,
523 { "APID", "ccsds.apid",
524 FT_UINT16, BASE_DEC, NULL, HDR_APID,
525 NULL, HFILL }
527 { &hf_ccsds_seqflag,
528 { "Sequence Flags", "ccsds.seqflag",
529 FT_UINT16, BASE_DEC, VALS(ccsds_primary_header_sequence_flags), 0xc000,
530 NULL, HFILL }
532 { &hf_ccsds_seqnum,
533 { "Sequence Number", "ccsds.seqnum",
534 FT_UINT16, BASE_DEC, NULL, 0x3fff,
535 NULL, HFILL }
537 { &hf_ccsds_length,
538 { "Packet Length", "ccsds.length",
539 FT_UINT16, BASE_DEC, NULL, 0x0,
540 NULL, HFILL }
544 /* common ccsds secondary header flags */
545 { &hf_ccsds_coarse_time,
546 { "Coarse Time", "ccsds.coarse_time",
547 FT_UINT32, BASE_DEC, NULL, 0x0,
548 NULL, HFILL }
550 { &hf_ccsds_fine_time,
551 { "Fine Time", "ccsds.fine_time",
552 FT_UINT8, BASE_DEC, NULL, 0x0,
553 NULL, HFILL }
555 { &hf_ccsds_timeid,
556 { "Time Identifier", "ccsds.timeid",
557 FT_UINT8, BASE_DEC, NULL, 0xc0,
558 NULL, HFILL }
560 { &hf_ccsds_checkword_flag,
561 { "Checkword Indicator", "ccsds.checkword_flag",
562 FT_BOOLEAN, 8, NULL, 0x20,
563 "Checkword present", HFILL }
567 /* payload specific ccsds secondary header flags */
568 { &hf_ccsds_zoe,
569 { "ZOE TLM", "ccsds.zoe",
570 FT_UINT8, BASE_DEC, NULL, 0x10,
571 "Contains S-band ZOE Packets", HFILL }
573 { &hf_ccsds_packet_type_unused,
574 { "Packet Type (unused for Ku-band)", "ccsds.packet_type",
575 FT_UINT8, BASE_DEC, NULL, 0x0f,
576 NULL, HFILL }
578 { &hf_ccsds_vid,
579 { "Version Identifier", "ccsds.vid",
580 FT_UINT16, BASE_DEC, NULL, 0x0,
581 NULL, HFILL }
583 { &hf_ccsds_dcc,
584 { "Data Cycle Counter", "ccsds.dcc",
585 FT_UINT16, BASE_DEC, NULL, 0x0,
586 NULL, HFILL }
590 /* core specific ccsds secondary header flags */
591 #if 0
592 { &hf_ccsds_spare1,
593 { "Spare Bit 1", "ccsds.spare1",
594 FT_UINT8, BASE_DEC, NULL, 0x10,
595 "unused spare bit 1", HFILL }
597 #endif
598 { &hf_ccsds_packet_type,
599 { "Packet Type", "ccsds.packet_type",
600 FT_UINT8, BASE_DEC, VALS(ccsds_secondary_header_packet_type), 0x0f,
601 NULL, HFILL }
603 #if 0
604 { &hf_ccsds_spare2,
605 { "Spare Bit 2", "ccsds.spare2",
606 FT_UINT16, BASE_DEC, NULL, 0x8000,
607 NULL, HFILL }
609 #endif
610 { &hf_ccsds_element_id,
611 { "Element ID", "ccsds.element_id",
612 FT_UINT16, BASE_DEC, VALS(ccsds_secondary_header_element_id), 0x7800,
613 NULL, HFILL }
615 { &hf_ccsds_cmd_data_packet,
616 { "Cmd/Data Packet Indicator", "ccsds.cmd_data_packet",
617 FT_UINT16, BASE_DEC, VALS(ccsds_secondary_header_cmd_data_packet), 0x0400,
618 NULL, HFILL }
620 { &hf_ccsds_format_version_id,
621 { "Format Version ID", "ccsds.format_version_id",
622 FT_UINT16, BASE_DEC, NULL, 0x03c0,
623 NULL, HFILL }
625 { &hf_ccsds_extended_format_id,
626 { "Extended Format ID", "ccsds.extended_format_id",
627 FT_UINT16, BASE_DEC | BASE_EXT_STRING, &ccsds_secondary_header_format_id_ext, 0x003f,
628 NULL, HFILL }
630 #if 0
631 { &hf_ccsds_spare3,
632 { "Spare Bits 3", "ccsds.spare3",
633 FT_UINT8, BASE_DEC, NULL, 0xff,
634 NULL, HFILL }
636 #endif
637 { &hf_ccsds_frame_id,
638 { "Frame ID", "ccsds.frame_id",
639 FT_UINT8, BASE_DEC, NULL, 0x0,
640 NULL, HFILL }
642 { &hf_ccsds_embedded_time,
643 { "Embedded Time", "ccsds.embedded_time",
644 FT_STRING, BASE_NONE, NULL, 0x0,
645 NULL, HFILL }
647 { &hf_ccsds_user_data,
648 { "User Data", "ccsds.user_data",
649 FT_BYTES, BASE_NONE, NULL, 0x0,
650 NULL, HFILL }
652 { &hf_ccsds_checkword,
653 { "CCSDS checkword", "ccsds.checkword",
654 FT_UINT16, BASE_HEX, NULL, 0x0,
655 "CCSDS checkword: 16-bit running sum of all bytes excluding the checkword", HFILL }
657 { &hf_ccsds_checkword_good,
658 { "Good", "ccsds.checkword_good",
659 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
660 "True: checkword matches packet content; False: doesn't match content", HFILL }
662 { &hf_ccsds_checkword_bad,
663 { "Bad", "ccsds.checkword_bad",
664 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
665 "True: checkword doesn't match packet content; False: matches content", HFILL }
669 /* Setup protocol subtree array */
670 static int *ett[] = {
671 &ett_ccsds_primary_header_flags,
672 &ett_ccsds,
673 &ett_ccsds_primary_header,
674 &ett_ccsds_secondary_header,
675 &ett_ccsds_checkword
678 static ei_register_info ei[] = {
679 { &ei_ccsds_length_error, { "ccsds.length.error", PI_MALFORMED, PI_ERROR, "Length field value is greater than the packet seen on the wire", EXPFILL }},
680 { &ei_ccsds_checkword, { "ccsds.no_checkword", PI_PROTOCOL, PI_WARN, "Packet does not contain a Checkword", EXPFILL }},
683 /* Define the CCSDS preferences module */
684 module_t *ccsds_module;
685 expert_module_t* expert_ccsds;
687 /* Register the protocol name and description */
688 proto_ccsds = proto_register_protocol("CCSDS", "CCSDS", "ccsds");
690 /* Required function calls to register the header fields and subtrees used */
691 proto_register_field_array(proto_ccsds, hf, array_length(hf));
692 proto_register_subtree_array(ett, array_length(ett));
693 expert_ccsds = expert_register_protocol(proto_ccsds);
694 expert_register_field_array(expert_ccsds, ei, array_length(ei));
696 ccsds_handle = register_dissector ( "ccsds", dissect_ccsds, proto_ccsds );
698 /* Register preferences module */
699 ccsds_module = prefs_register_protocol(proto_ccsds, NULL);
701 prefs_register_enum_preference(ccsds_module, "global_pref_checkword",
702 "How to handle the CCSDS checkword",
703 "Specify how the dissector should handle the CCSDS checkword",
704 &global_dissect_checkword, dissect_checkword, false);
706 /* Dissector table for sub-dissectors */
707 ccsds_dissector_table = register_dissector_table("ccsds.apid", "CCSDS apid", proto_ccsds, FT_UINT16, BASE_DEC);
711 void
712 proto_reg_handoff_ccsds(void)
714 dissector_add_for_decode_as_with_preference( "udp.port", ccsds_handle);
718 * Editor modelines - https://www.wireshark.org/tools/modelines.html
720 * Local variables:
721 * c-basic-offset: 4
722 * tab-width: 8
723 * indent-tabs-mode: nil
724 * End:
726 * vi: set shiftwidth=4 tabstop=8 expandtab:
727 * :indentSize=4:tabSize=8:noTabs=true: