1 /* packet-ftam_asn1.c
2 * Routine to dissect OSI ISO 8571 FTAM Protocol packets
3 * based on the ASN.1 specification from http://www.itu.int/ITU-T/asn1/database/iso/8571-4/1988/
4 *
5 * also based on original handwritten dissector by
6 * Yuriy Sidelnikov <YSidelnikov@hotmail.com>
7 *
8 * Anders Broman and Ronnie Sahlberg 2005 - 2006
9 *
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
13 *
14 * SPDX-License-Identifier: GPL-2.0-or-later
15 */
16
17 #include "config.h"
18
19 #include <epan/packet.h>
20 #include <epan/expert.h>
21 #include <epan/oids.h>
22 #include <epan/asn1.h>
23
24 #include "packet-ber.h"
25 #include "packet-acse.h"
26 #include "packet-ftam.h"
27
28 #define PNAME "ISO 8571 FTAM"
29 #define PSNAME "FTAM"
30 #define PFNAME "ftam"
31
32 void proto_register_ftam(void);
33 void proto_reg_handoff_ftam(void);
34
35 /* Initialize the protocol and registered fields */
36 static int proto_ftam = -1;
37
38 /* Declare the function to avoid a compiler warning */
39 static int dissect_ftam_OR_Set(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_);
40
41 static int hf_ftam_unstructured_text = -1; /* ISO FTAM unstructured text */
42 static int hf_ftam_unstructured_binary = -1; /* ISO FTAM unstructured binary */
43 #include "packet-ftam-hf.c"
44
45 /* Initialize the subtree pointers */
46 static gint ett_ftam = -1;
47 #include "packet-ftam-ett.c"
48
49 static expert_field ei_ftam_zero_pdu = EI_INIT;
50
51 #include "packet-ftam-fn.c"
52
53 /*
54 * Dissect FTAM unstructured text
55 */
56 static int
dissect_ftam_unstructured_text(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * parent_tree,void * data _U_)57 dissect_ftam_unstructured_text(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, void* data _U_)
58 {
59 proto_tree_add_item (parent_tree, hf_ftam_unstructured_text, tvb, 0, tvb_reported_length_remaining(tvb, 0), ENC_ASCII|ENC_NA);
60 return tvb_captured_length(tvb);
61 }
62
63 /*
64 * Dissect FTAM unstructured binary
65 */
66 static int
dissect_ftam_unstructured_binary(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * parent_tree,void * data _U_)67 dissect_ftam_unstructured_binary(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree, void* data _U_)
68 {
69 proto_tree_add_item (parent_tree, hf_ftam_unstructured_binary, tvb, 0, tvb_reported_length_remaining(tvb, 0), ENC_NA);
70 return tvb_captured_length(tvb);
71 }
72
73 /*
74 * Dissect FTAM PDUs inside a PPDU.
75 */
76 static int
dissect_ftam(tvbuff_t * tvb,packet_info * pinfo,proto_tree * parent_tree,void * data _U_)77 dissect_ftam(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
78 {
79 int offset = 0;
80 int old_offset;
81 proto_item *item=NULL;
82 proto_tree *tree=NULL;
83 asn1_ctx_t asn1_ctx;
84
85 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
86
87 if(parent_tree){
88 item = proto_tree_add_item(parent_tree, proto_ftam, tvb, 0, -1, ENC_NA);
89 tree = proto_item_add_subtree(item, ett_ftam);
90 }
91 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FTAM");
92 col_clear(pinfo->cinfo, COL_INFO);
93
94 while (tvb_reported_length_remaining(tvb, offset) > 0){
95 old_offset=offset;
96 offset=dissect_ftam_PDU(FALSE, tvb, offset, &asn1_ctx, tree, -1);
97 if(offset == old_offset){
98 proto_tree_add_expert(tree, pinfo, &ei_ftam_zero_pdu, tvb, offset, -1);
99 break;
100 }
101 }
102 return tvb_captured_length(tvb);
103 }
104
105
106 /*--- proto_register_ftam -------------------------------------------*/
proto_register_ftam(void)107 void proto_register_ftam(void) {
108
109 /* List of fields */
110 static hf_register_info hf[] =
111 {
112 { &hf_ftam_unstructured_text,
113 { "ISO FTAM unstructured text", "ftam.unstructured_text", FT_STRING,
114 BASE_NONE, NULL, 0x0, NULL, HFILL } },
115 { &hf_ftam_unstructured_binary,
116 { "ISO FTAM unstructured binary", "ftam.unstructured_binary", FT_BYTES,
117 BASE_NONE, NULL, 0x0, NULL, HFILL } },
118 #include "packet-ftam-hfarr.c"
119 };
120
121 /* List of subtrees */
122 static gint *ett[] = {
123 &ett_ftam,
124 #include "packet-ftam-ettarr.c"
125 };
126 static ei_register_info ei[] = {
127 { &ei_ftam_zero_pdu, { "ftam.zero_pdu", PI_PROTOCOL, PI_ERROR, "Internal error, zero-byte FTAM PDU", EXPFILL }},
128 };
129
130 expert_module_t* expert_ftam;
131
132 /* Register protocol */
133 proto_ftam = proto_register_protocol(PNAME, PSNAME, PFNAME);
134 register_dissector("ftam", dissect_ftam, proto_ftam);
135 /* Register fields and subtrees */
136 proto_register_field_array(proto_ftam, hf, array_length(hf));
137 proto_register_subtree_array(ett, array_length(ett));
138 expert_ftam = expert_register_protocol(proto_ftam);
139 expert_register_field_array(expert_ftam, ei, array_length(ei));
140
141 }
142
143
144 /*--- proto_reg_handoff_ftam --- */
proto_reg_handoff_ftam(void)145 void proto_reg_handoff_ftam(void) {
146 register_ber_oid_dissector("1.0.8571.1.1", dissect_ftam, proto_ftam,"iso-ftam(1)");
147 register_ber_oid_dissector("1.0.8571.2.1", dissect_ftam, proto_ftam,"ftam-pci(1)");
148 register_ber_oid_dissector("1.3.14.5.2.2", dissect_ftam, proto_ftam,"NIST file directory entry abstract syntax");
149
150 /* Unstructured text file document type FTAM-1 */
151 register_ber_oid_dissector("1.0.8571.5.1", dissect_ftam_unstructured_text, proto_ftam,"ISO FTAM unstructured text");
152 oid_add_from_string("ISO FTAM sequential text","1.0.8571.5.2");
153 oid_add_from_string("FTAM unstructured text abstract syntax","1.0.8571.2.3");
154 oid_add_from_string("FTAM simple-hierarchy","1.0.8571.2.5");
155 oid_add_from_string("FTAM hierarchical file model","1.0.8571.3.1");
156 oid_add_from_string("FTAM unstructured constraint set","1.0.8571.4.1");
157
158 /* Unstructured binary file document type FTAM-3 */
159 register_ber_oid_dissector("1.0.8571.5.3", dissect_ftam_unstructured_binary, proto_ftam,"ISO FTAM unstructured binary");
160 oid_add_from_string("FTAM unstructured binary abstract syntax","1.0.8571.2.4");
161
162 /* Filedirectory file document type NBS-9 */
163 oid_add_from_string("NBS-9 FTAM file directory file","1.3.14.5.5.9");
164
165 /* Filedirectory file document type NBS-9 (WITH OLD NIST OIDs)*/
166 oid_add_from_string("NBS-9-OLD FTAM file directory file","1.3.9999.1.5.9");
167 oid_add_from_string("NIST file directory entry abstract syntax","1.3.9999.1.2.2");
168 }
169