1 /* packet-pn.h
2  * Common functions for other PROFINET protocols like DCP, MRP, ...
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1999 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 /*
12  * Cyclic PNIO RTC1 Data Dissection:
13  *
14  * Added new structures to packet-pn.h to transfer the gained data of
15  * packet-pn-dcp.c and packet-dcerpc-pn-io.c to packet-pn-rtc-one.c for
16  * detailled dissection of cyclic PNIO RTC1 dataframes.
17  *
18  */
19 
20 #define FRAME_ID_DCP_HELLO      0xfefc
21 #define FRAME_ID_DCP_GETORSET   0xfefd
22 #define FRAME_ID_DCP_IDENT_REQ  0xfefe
23 #define FRAME_ID_DCP_IDENT_RES  0xfeff
24 
25 
26 /* ---- Structures for pnio_rtc1 ---- */
27 extern int       proto_pn_dcp;
28 extern int proto_pn_io_apdu_status;
29 extern gboolean  pnio_ps_selection;  /* given by pnio preferences */
30 
31 /* Structure for general station information */
32 typedef struct tagStationInfo {
33     /* general information */
34     gchar    *typeofstation;
35     gchar    *nameofstation;
36     guint16   u16Vendor_id;
37     guint16   u16Device_id;
38     /* frame structure */
39     guint16   ioDataObjectNr;
40     guint16   iocsNr;
41     /* GSDfile station information */
42     gboolean  gsdFound;
43     gboolean  gsdPathLength;
44     gchar    *gsdLocation;
45     /* IOCS object data */
46     wmem_list_t *iocs_data_in;
47     wmem_list_t *iocs_data_out;
48     /* IOData object data */
49     wmem_list_t *ioobject_data_in;
50     wmem_list_t *ioobject_data_out;
51     /* Different ModuleIdentnumber */
52     wmem_list_t *diff_module;
53 } stationInfo;
54 
55 typedef struct tagApduStatusSwitch
56 {
57     gboolean isRedundancyActive;
58     address dl_dst;
59     address dl_src;
60 }apduStatusSwitch;
61 
62 /* Structure for IOCS Frames */
63 typedef struct tagIocsObject {
64     guint16    slotNr;
65     guint16    subSlotNr;
66     guint16    frameOffset;
67 } iocsObject;
68 
69 /* Structure for IO Data Objects  */
70 typedef struct tagIoDataObject {
71     guint16     slotNr;
72     guint16     subSlotNr;
73     guint32     moduleIdentNr;
74     guint32     subModuleIdentNr;
75     guint16     frameOffset;
76     guint16     length;
77     guint16     amountInGSDML;
78     guint32     fParameterIndexNr;
79     guint16     f_par_crc1;
80     guint16     f_src_adr;
81     guint16     f_dest_adr;
82     gboolean    f_crc_seed;
83     guint8      f_crc_len;
84     address     srcAddr;
85     address     dstAddr;
86     gboolean    profisafeSupported;
87     gboolean    discardIOXS;
88     gchar      *moduleNameStr;
89     tvbuff_t   *tvb_slot;
90     tvbuff_t   *tvb_subslot;
91     /* Status- or Controlbyte data*/
92     guint8     last_sb_cb;
93     guint8     lastToggleBit;
94 } ioDataObject;
95 
96 /* Structure for Modules with different ModuleIdentnumber */
97 typedef struct tagModuleDiffInfo {
98     guint16    slotNr;
99     guint32    modulID;
100 } moduleDiffInfo;
101 
102 typedef struct tagARUUIDFrame {
103     e_guid_t aruuid;
104     guint32  setupframe;
105     guint32  releaseframe;
106     guint16  outputframe;
107     guint16  inputframe;
108 } ARUUIDFrame;
109 
110 extern wmem_list_t *aruuid_frame_setup_list;
111 
112 extern void init_pn(int proto);
113 extern void init_pn_io_rtc1(int proto);
114 extern void init_pn_rsi(int proto);
115 extern void pn_rsi_reassemble_init(void);
116 
117 extern void init_pnio_rtc1_station(stationInfo *station_info);
118 
119 extern int dissect_pn_uint8(tvbuff_t *tvb, gint offset, packet_info *pinfo,
120                   proto_tree *tree, int hfindex, guint8 *pdata);
121 
122 extern int dissect_pn_uint16_ret_item(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
123                        proto_tree *tree, int hfindex, guint16 *pdata, proto_item ** new_item);
124 extern int dissect_pn_uint16(tvbuff_t *tvb, gint offset, packet_info *pinfo,
125                        proto_tree *tree, int hfindex, guint16 *pdata);
126 
127 extern int dissect_pn_int16(tvbuff_t *tvb, gint offset, packet_info *pinfo,
128                        proto_tree *tree, int hfindex, gint16 *pdata);
129 
130 extern int dissect_pn_oid(tvbuff_t *tvb, int offset, packet_info *pinfo,
131                     proto_tree *tree, int hfindex, guint32 *pdata);
132 
133 extern int dissect_pn_mac(tvbuff_t *tvb, int offset, packet_info *pinfo,
134                     proto_tree *tree, int hfindex, guint8 *pdata);
135 
136 extern int dissect_pn_ipv4(tvbuff_t *tvb, int offset, packet_info *pinfo,
137                     proto_tree *tree, int hfindex, guint32 *pdata);
138 
139 extern int dissect_pn_uuid(tvbuff_t *tvb, int offset, packet_info *pinfo,
140                     proto_tree *tree, int hfindex, e_guid_t *uuid);
141 
142 extern int dissect_pn_undecoded(tvbuff_t *tvb, int offset, packet_info *pinfo,
143                     proto_tree *tree, guint32 length);
144 
145 extern int dissect_pn_user_data(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
146                     proto_tree *tree, guint32 length, const char *text);
147 
148 extern int dissect_blocks(tvbuff_t *tvb, int offset,
149                     packet_info *pinfo, proto_tree *tree, guint8 *drep);
150 
151 #define PDU_TYPE_REQ 0x05
152 #define PDU_TYPE_RSP 0x06
153 
154 extern int dissect_rsi_blocks(tvbuff_t* tvb, int offset, packet_info* pinfo, proto_tree* tree, guint8* drep, guint32 u32FOpnumOffsetOpnum, int type);
155 
156 #define SUBST_DATA  1
157 #define FRAG_DATA   2
158 
159 extern int dissect_pn_user_data_bytes(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
160                     proto_tree *tree, guint32 length, int iSelect);
161 
162 extern int dissect_pn_malformed(tvbuff_t *tvb, int offset, packet_info *pinfo,
163                     proto_tree *tree, guint32 length);
164 
165 extern int dissect_pn_padding(tvbuff_t *tvb, int offset, packet_info *pinfo,
166                     proto_tree *tree, int length);
167 
168 extern int dissect_pn_align4(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
169 
170 extern int dissect_PNIO_status(tvbuff_t *tvb, int offset, packet_info *pinfo,
171                     proto_tree *tree, guint8 *drep);
172 
173 extern int dissect_PNIO_C_SDU_RTC1(tvbuff_t* tvb, int offset, packet_info* pinfo,
174                     proto_tree* tree, guint8* drep _U_, guint16 frameid);
175 
176 extern int dissect_PNIO_RSI(tvbuff_t *tvb, int offset, packet_info *pinfo,
177                     proto_tree *tree, guint8 *drep);
178 
179 extern int dissect_PDRsiInstances_block(tvbuff_t *tvb, int offset,
180                     packet_info *pinfo, proto_tree *tree, proto_item *item _U_, guint8 *drep, guint8 u8BlockVersionHigh, guint8 u8BlockVersionLow);
181 
182 extern void pn_append_info(packet_info *pinfo, proto_item *dcp_item, const char *text);
183 
184 extern void pn_init_append_aruuid_frame_setup_list(e_guid_t aruuid, guint32 setup);
185 
186 extern ARUUIDFrame* pn_find_aruuid_frame_setup(packet_info* pinfo);
187 
188 extern void pn_find_dcp_station_info(stationInfo* station_info, conversation_t* conversation);
189 
190 extern gboolean dissect_CSF_SDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);
191 
192 #define MAX_LINE_LENGTH          1024   /* used for fgets() */
193 
194 /* Read a string from an "xml" file, dropping xml comment blocks */
195 #include <stdio.h>
196 extern char *pn_fgets(char *str, int n, FILE *stream, wmem_allocator_t *scope);
197