ethercat: Fix some too-wide mask widths.

N.B. Some other issues spotted have been reported in
https://gitlab.com/wireshark/wireshark/~/issues/17605
This commit is contained in:
Martin Mathieson 2021-09-21 11:04:31 +01:00
parent b12644b629
commit 543ea3968c
3 changed files with 50 additions and 38 deletions

View File

@ -1527,27 +1527,27 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_coe_sdoccsid_sizeind,
{ "Size Ind.", "ecat_mailbox.coe.sdoccsid.sizeind",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x01,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsid_expedited,
{ "Expedited", "ecat_mailbox.coe.sdoccsid.expedited",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000002,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x02,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsid_size0,
{ "Bytes", "ecat_mailbox.coe.sdoccsid.size0",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000004,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x04,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsid_size1,
{ "Bytes", "ecat_mailbox.coe.sdoccsid.size1",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000008,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x08,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsid_complete,
{ "Access", "ecat_mailbox.coe.sdoccsid.complete",
FT_BOOLEAN, 8, TFS(&tfs_complete), 0x00000010,
FT_BOOLEAN, 8, TFS(&tfs_complete), 0x10,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsds,
@ -1557,17 +1557,17 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_coe_sdoccsds_lastseg,
{ "Last Segment", "ecat_mailbox.coe.sdoccsds.lastseg",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x01,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsds_size,
{ "Size", "ecat_mailbox.coe.sdoccsds.size",
FT_UINT8, BASE_DEC, NULL, 0x0000000E,
FT_UINT8, BASE_DEC, NULL, 0x0E,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsds_toggle,
{ "Toggle Bit", "ecat_mailbox.coe.sdoccsds.toggle",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x10,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoccsiu,
@ -1577,8 +1577,8 @@ void proto_register_ecat_mailbox(void)
},
#if 0
{ &hf_ecat_mailbox_coe_sdoccsiu_complete,
{ "Toggle Bit", "ecat_mailbox.coe.sdoccsiu_complete",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
{ "Toggle Bit", "ecat_mailbox.coe.sdoccsiu.complete",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x10,
NULL, HFILL }
},
#endif
@ -1589,7 +1589,7 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_coe_sdoccsus_toggle,
{ "Toggle Bit", "ecat_mailbox.coe.sdoccsus_toggle",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x10,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoidx,
@ -1651,27 +1651,27 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_coe_sdoscsiu_sizeind,
{ "Size Ind.", "ecat_mailbox.coe.sdoscsiu_sizeind",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x01,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsiu_expedited,
{ "Expedited", "ecat_mailbox.coe.sdoscsiu_expedited",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000002,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x02,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsiu_size0,
{ "Bytes", "ecat_mailbox.coe.sdoscsiu_size0",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000004,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x04,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsiu_size1,
{ "Bytes", "ecat_mailbox.coe.sdoscsiu_size1",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000008,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x08,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsiu_complete,
{ "Access", "ecat_mailbox.coe.sdoscsiu_complete",
FT_BOOLEAN, 8, TFS(&tfs_complete), 0x00000010,
FT_BOOLEAN, 8, TFS(&tfs_complete), 0x10,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsds,
@ -1681,7 +1681,7 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_coe_sdoscsds_toggle,
{ "Toggle Bit", "ecat_mailbox.coe.sdoscsds_toggle",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x10,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsus,
@ -1691,17 +1691,17 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_coe_sdoscsus_lastseg,
{ "Last Segment", "ecat_mailbox.coe.sdoscsus_lastseg",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x01,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsus_bytes,
{ "Bytes", "ecat_mailbox.coe.sdoscsus_bytes",
FT_UINT8, BASE_DEC, NULL, 0x0000000E,
FT_UINT8, BASE_DEC, NULL, 0x0E,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoscsus_toggle,
{ "Toggle Bit", "ecat_mailbox.coe.sdoscsus_toggle",
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x10,
NULL, HFILL }
},
{ &hf_ecat_mailbox_coe_sdoinfoopcode,
@ -1863,7 +1863,7 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_soe_header_error,
{ "Error", "ecat_mailbox.soe_header_error",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000010,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x0010,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_driveno,
@ -1872,42 +1872,42 @@ void proto_register_ecat_mailbox(void)
},
{ &hf_ecat_mailbox_soe_header_datastate,
{ "Datastate", "ecat_mailbox.soe_header_datastate",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000100,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x0100,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_name,
{ "Name", "ecat_mailbox.soe_header_name",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000200,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x0200,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_attribute,
{ "Attribute", "ecat_mailbox.soe_header_attribute",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000400,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x0400,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_unit,
{ "Unit", "ecat_mailbox.soe_header_unit",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000800,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x0800,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_min,
{ "Min", "ecat_mailbox.soe_header_min",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00001000,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x1000,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_max,
{ "Max", "ecat_mailbox.soe_header_max",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00002000,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x2000,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_value,
{ "Value", "ecat_mailbox.soe_header_value",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00004000,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x4000,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_header_reserved,
{ "Reserved", "ecat_mailbox.soe_header_reserved",
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00008000,
FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x8000,
NULL, HFILL }
},
{ &hf_ecat_mailbox_soe_idn,

View File

@ -3024,7 +3024,7 @@ void proto_register_ecat(void)
},
{ &hf_ecat_reg_ctrlstat_wraccess,
{"Write access", "ecat.reg.ctrlstat.wraccess",
FT_BOOLEAN, 8, TFS(&tfs_local_true_false), 0x1, NULL, HFILL }
FT_BOOLEAN, 8, TFS(&tfs_local_true_false), 0x01, NULL, HFILL }
},
{ &hf_ecat_reg_ctrlstat_eepromemul,
{"EEPROM emulation", "ecat.reg.ctrlstat.eepromemul",

View File

@ -18,7 +18,6 @@ import subprocess
# is assigned to a different variable or a macro is used, it isn't tracked.
# TODO:
# Attempt to check length (where literal value is given). Arg position differs among functions.
# Currently assuming we'll find call + first 2 args in same line...
# Attempt to check for allowed encoding types (most likely will be literal values |'d)?
@ -322,7 +321,7 @@ class Item:
return
while n <= 63:
if self.check_bit(self.mask_value, n):
print('Warning: ', self.filename, 'filter=', self.filter, ' - mask with non-contiguous bits', mask)
print('Warning:', self.filename, 'filter=', self.filter, ' - mask with non-contiguous bits', mask)
return
n += 1
@ -332,6 +331,8 @@ class Item:
return 8 # i.e. 1 byte
elif self.type_modifier == 'BASE_NONE':
return 8
elif self.type_modifier == 'SEP_DOT':
return 64
else:
return int(self.type_modifier)
else:
@ -344,7 +345,7 @@ class Item:
# There may be good reasons for having a wider field/mask, e.g. if there are 32 related flags, showing them
# all lined up as part of the same word may make it clearer. But some cases have been found
# where the grouping does not seem to be natural..
print('Warning: ', self.filename, 'filter=', self.filter, ' - mask with leading or trailing 0 bytes suggests field', self.item_type, 'may be wider than necessary?', mask)
print('Warning:', self.filename, 'filter=', self.filter, ' - mask with leading or trailing 0 bytes suggests field', self.item_type, 'may be wider than necessary?', mask)
global warnings_found
warnings_found += 1
@ -352,17 +353,17 @@ class Item:
if mask.startswith('0x') and len(mask) > 3:
global warnings_found
if len(mask) % 2:
print('Warning: ', self.filename, 'filter=', self.filter, ' - mask has odd number of digits', mask,
print('Warning:', self.filename, 'filter=', self.filter, ' - mask has odd number of digits', mask,
'expected max for', self.item_type, 'is', int(self.get_field_width_in_bits()/4))
warnings_found += 1
if self.item_type in field_widths:
if len(mask)-2 > self.get_field_width_in_bits()/4:
print('Warning: ', self.filename, 'filter=', self.filter, self.mask, "with len is", len(mask)-2,
print('Warning:', self.filename, 'filter=', self.filter, self.mask, "with len is", len(mask)-2,
"but type", self.item_type, " indicates max of", int(self.get_field_width_in_bits()/4))
warnings_found += 1
else:
print('Warning: ', self.filename, 'filter=', self.filter, ' - item has type', self.item_type, 'but mask set:', mask)
print('Warning:', self.filename, 'filter=', self.filter, ' - item has type', self.item_type, 'but mask set:', mask)
warnings_found += 1
def check_digits_all_zeros(self, mask):
@ -555,6 +556,8 @@ def checkFile(filename, check_mask=False, check_label=False, check_consecutive=F
parser = argparse.ArgumentParser(description='Check calls in dissectors')
parser.add_argument('--file', action='store', default='',
help='specify individual dissector file to test')
parser.add_argument('--folder', action='store', default='',
help='specify folder to test')
parser.add_argument('--commits', action='store',
help='last N commits to check')
parser.add_argument('--open', action='store_true',
@ -573,11 +576,20 @@ args = parser.parse_args()
# Get files from wherever command-line args indicate.
files = []
if args.file:
# Add single specified file..
if not args.file.startswith('epan'):
# Add single specified file
if not args.file.startswith('epan') and not os.path.exists(args.file):
files.append(os.path.join('epan', 'dissectors', args.file))
else:
files.append(args.file)
elif args.folder:
# Add all files from a given folder.
folder = args.folder
if not os.path.isdir(folder):
print('Folder', folder, 'not found!')
exit(1)
# Find files from folder.
print('Looking for files in', folder)
files = findDissectorFilesInFolder(folder, recursive=True)
elif args.commits:
# Get files affected by specified number of commits.
command = ['git', 'diff', '--name-only', '--diff-filter=d', 'HEAD~' + args.commits]