2 * Allow users to specify the dissectors for DLTs
3 * Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
34 #include <epan/expert.h>
35 #include <epan/prefs.h>
37 #include <epan/emem.h>
40 /* disable: warning C4090: 'XY' : different 'const' qualifiers */
41 #pragma warning(disable:4090)
44 typedef struct _user_encap_t {
46 dissector_handle_t payload_proto;
47 dissector_handle_t header_proto;
48 dissector_handle_t trailer_proto;
53 #define ENCAP0_STR "User 0 (DLT=147)"
54 static const value_string user_dlts[] = {
55 { WTAP_ENCAP_USER0, ENCAP0_STR},
56 { WTAP_ENCAP_USER1, "User 1 (DLT=148)"},
57 { WTAP_ENCAP_USER2, "User 2 (DLT=149)"},
58 { WTAP_ENCAP_USER3, "User 3 (DLT=150)"},
59 { WTAP_ENCAP_USER4, "User 4 (DLT=151)"},
60 { WTAP_ENCAP_USER5, "User 5 (DLT=152)"},
61 { WTAP_ENCAP_USER6, "User 6 (DLT=153)"},
62 { WTAP_ENCAP_USER7, "User 7 (DLT=154)"},
63 { WTAP_ENCAP_USER8, "User 8 (DLT=155)"},
64 { WTAP_ENCAP_USER9, "User 9 (DLT=156)"},
65 { WTAP_ENCAP_USER10, "User 10 (DLT=157)"},
66 { WTAP_ENCAP_USER11, "User 11 (DLT=158)"},
67 { WTAP_ENCAP_USER12, "User 12 (DLT=159)"},
68 { WTAP_ENCAP_USER13, "User 13 (DLT=160)"},
69 { WTAP_ENCAP_USER14, "User 14 (DLT=161)"},
70 { WTAP_ENCAP_USER15, "User 15 (DLT=162)"},
73 static int proto_user_encap = -1;
75 static user_encap_t* encaps = NULL;
76 static guint num_encaps = 0;
77 static uat_t* encaps_uat;
78 static dissector_handle_t data_handle;
80 static void dissect_user(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
81 user_encap_t* encap = NULL;
82 tvbuff_t* payload_tvb;
87 for (i = 0; i < num_encaps; i++) {
88 if (encaps[i].encap == pinfo->match_port) {
95 char* msg = ep_strdup_printf("user encap not hanlded: DLT=%d, check you Preferences->Protocols->DLT_USER",
96 pinfo->match_port + 147 - WTAP_ENCAP_USER0);
97 proto_item* i = proto_tree_add_text(tree, tvb, 0, 0, msg);
99 expert_add_info_format(pinfo, i, PI_UNDECODED, PI_WARN, msg);
101 call_dissector(data_handle, tvb, pinfo, tree);
104 proto_item* i = proto_tree_add_item(tree,proto_user_encap,tvb,0,0,FALSE);
105 proto_item_set_text(i,"DLT: %d",pinfo->match_port + 147 - WTAP_ENCAP_USER0);
108 len = tvb_reported_length(tvb) - (encap->header_size + encap->trailer_size);
110 if (encap->header_size) {
111 tvbuff_t* hdr_tvb = tvb_new_subset(tvb, 0, encap->header_size, encap->header_size);
112 call_dissector(encap->header_proto, hdr_tvb, pinfo, tree);
113 offset = encap->header_size;
116 payload_tvb = tvb_new_subset(tvb, encap->header_size, len, len);
117 call_dissector(encap->payload_proto, payload_tvb, pinfo, tree);
119 if (encap->trailer_size) {
120 tvbuff_t* trailer_tvb = tvb_new_subset(tvb, encap->header_size + len, encap->trailer_size, encap->trailer_size);
121 call_dissector(encap->trailer_proto, trailer_tvb, pinfo, tree);
122 offset = encap->trailer_size;
126 static void user_update_cb(void* r _U_, const char** err _U_) {
129 UAT_VS_DEF(user_encap, encap, user_encap_t, WTAP_ENCAP_USER0, ENCAP0_STR)
130 UAT_PROTO_DEF(user_encap, payload_proto, user_encap_t)
131 UAT_DEC_CB_DEF(user_encap, header_size, user_encap_t)
132 UAT_DEC_CB_DEF(user_encap, trailer_size, user_encap_t)
133 UAT_PROTO_DEF(user_encap, header_proto, user_encap_t)
134 UAT_PROTO_DEF(user_encap, trailer_proto, user_encap_t)
136 static dissector_handle_t user_encap_handle;
138 void proto_reg_handoff_user_encap(void)
142 user_encap_handle = find_dissector("user_dlt");
143 data_handle = find_dissector("data");
145 for (i = WTAP_ENCAP_USER0 ; i <= WTAP_ENCAP_USER15; i++)
146 dissector_add("wtap_encap", i, user_encap_handle);
151 void proto_register_user_encap(void)
155 static uat_field_t user_flds[] = {
156 UAT_FLD_VS(user_encap,encap,user_dlts,"The DLT"),
157 UAT_FLD_PROTO(user_encap,payload_proto,"Protocol to be used for the payload of this DLT"),
158 UAT_FLD_DEC(user_encap,header_size,"Size of an eventual header that precedes the actual payload, 0 means none"),
159 UAT_FLD_PROTO(user_encap,header_proto,"Protocol to be used for the header (empty = data)"),
160 UAT_FLD_DEC(user_encap,trailer_size,"Size of an eventual trailer that follows the actual payload, 0 means none"),
161 UAT_FLD_PROTO(user_encap,trailer_proto,"Protocol to be used for the trailer (empty = data)"),
166 proto_user_encap = proto_register_protocol("DLT User","DLT_USER","user_dlt");
168 module = prefs_register_protocol(proto_user_encap, NULL);
170 encaps_uat = uat_new("User DLTs Table",
171 sizeof(user_encap_t),
182 prefs_register_uat_preference(module,
184 "Encapsulations Table",
185 "A table that enumerates the various protocols to be used against a cartain user DLT",
189 register_dissector("user_dlt",dissect_user,proto_user_encap);
192 prefs_register_protocol_obsolete(proto_register_protocol("DLT User A","DLT_USER_A","user_dlt_a"));
193 prefs_register_protocol_obsolete(proto_register_protocol("DLT User B","DLT_USER_B","user_dlt_b"));
194 prefs_register_protocol_obsolete(proto_register_protocol("DLT User C","DLT_USER_C","user_dlt_c"));
195 prefs_register_protocol_obsolete(proto_register_protocol("DLT User D","DLT_USER_D","user_dlt_d"));