The .cnf file tells the compiler what to do with certain things, such as skipping auto generation for some ASN.1 entries. They can contain the following directives:
#.MODULE IMPORT InformationFramework x509if #.INCLUDE ../x509if/x509if_exp.cnf #.EXPORTS + ObjectName #.PDU ObjectName #.REGISTER Certificate B "2.5.4.36" "id-at-userCertificate" #.SYNTAX ObjectName [FriendlyName] #.NO_EMIT ONLY_VALS # this can be used with: [WITH_VALS|WITHOUT_VALS|ONLY_VALS] # using NO_EMIT NO_VALS means it won't generate value_string array for it Type1 #.USER DEFINED Type1 [WITH_VALS|WITHOUT_VALS|ONLY_VALS] #.TYPE_RENAME #.FIELD_RENAME #.TYPE_ATTR Ss-Code TYPE = FT_UINT16 DISPLAY = BASE_HEX STRINGS = VALS(ssCode_vals) # This entry will change the hf definition from the auto-generated one for Ss-Code ::= OCTET STRING(SIZE(1)) { &hf_gsm_map_ss_Code, { "ss-Code", "gsm_map.ss_Code", FT_BYTES, BASE_HEX, NULL, 0, "", HFILL }}, # to: { &hf_gsm_map_ss_Code, { "ss-Code", "gsm_map.ss_Code", FT_UINT16, BASE_HEX, VALS(ssCode_vals), 0, "", HFILL }},
In the proto_abbr-template.c file the corresponding value string must be inserted. As an example the following would be included in proto_abbr-template.c to define ssCode_vals:
static const value_string ssCode_vals[] = { { 0, "ssCodeString 1" }, /* The string for value 0 */ { 1, "String 2" }, /* String for value 1 */ { 5, "String for value 5" }, /* Value String 5 */ { 0, NULL } /* Null terminated array */ }
Note that the NULL value must be the final entry and that the index values need not be consecutive.
Foo is expressed in different ways depending on where you want to insert your code and the ASN.1 code in question.
For Tagged type use:
Foo/_untag #.FN_HDR Foo /* This is code to be inserted into the dissector for Foo BEFORE the BER/PER helper is called. */ tvbuff_t *out_tvb; fragment_data *fd_head; tvbuff_t *next_tvb = NULL; #.FN_BODY Foo /* This here is code to replace the actual call to the helper completely. */ offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index, &out_tvb); /* Putting %(DEFAULT_BODY)s inside #.FN_BODY will insert the original code there. */ #.FN_FTR Foo /* This is code to be inserted into the dissector for Foo AFTER the ber/per helper has returned called. */ if (foo_reassemble) { ... } #.FN_PARS #.END
Example template.h file. Replace all PROTOCOL/protocol references with the name of your protocol.
/* packet-protocol.h * Routines for Protocol packet dissection * * $Id$ * * Wireshark - Network traffic analyzer * By Gerald Combs <[email protected]> * Copyright 1998 Gerald Combs * * SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef PACKET_PROTOCOL_H #define PACKET_PROTOCOL_H #include "packet-protocol-exp.h" #endif /* PACKET_PROTOCOL_H */
Example template.c file. Replace all PROTOCOL/protocol references with the name of your protocol.
/* packet-protocol.c * Routines for PROTOCOL packet dissection * * $Id$ * * Wireshark - Network traffic analyzer * By Gerald Combs <[email protected]> * Copyright 1998 Gerald Combs * * SPDX-License-Identifier: GPL-2.0-or-later */ #include "config.h" #include <glib.h> #include <epan/packet.h> #include <epan/conversation.h> #include <stdio.h> #include <string.h> #include "packet-ber.h" #include "packet-protocol.h" #define PNAME "This Is The Protocol Name" #define PSNAME "PROTOCOL" #define PFNAME "protocol" /* Initialize the protocol and registered fields */ int proto_protocol; #include "packet-protocol-hf.c" /* Initialize the subtree pointers */ #include "packet-protocol-ett.c" #include "packet-protocol-fn.c" /*--- proto_register_protocol ----------------------------------------------*/ void proto_register_protocol(void) { /* List of fields */ static hf_register_info hf[] = { #include "packet-protocol-hfarr.c" }; /* List of subtrees */ static int *ett[] = { #include "packet-protocol-ettarr.c" }; /* Register protocol */ proto_protocol = proto_register_protocol(PNAME, PSNAME, PFNAME); /* Register fields and subtrees */ proto_register_field_array(proto_protocol, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); } /*--- proto_reg_handoff_protocol -------------------------------------------*/ void proto_reg_handoff_protocol(void) { #include "packet-protocol-dis-tab.c" }