Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-tte-pcf.c
Line
Count
Source
1
/* packet-tte-pcf.c
2
 * Routines for Time Triggered Ethernet Protocol Control Frame dissection
3
 *
4
 * Author: Valentin Ecker
5
 * Author: Benjamin Roch, benjamin.roch (AT) tttech.com
6
 *
7
 * TTTech Computertechnik AG, Austria.
8
 * https://www.tttech.com/technologies/time-triggered-ethernet/
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/etypes.h>
21
22
#include "packet-tte.h"
23
24
void proto_register_tte_pcf(void);
25
void proto_reg_handoff_tte_pcf(void);
26
27
/* Initialize the protocol and registered fields */
28
static int proto_tte_pcf;
29
30
static int hf_tte_pcf_ic;
31
static int hf_tte_pcf_mn;
32
/* static int hf_tte_pcf_res0; */
33
static int hf_tte_pcf_sp;
34
static int hf_tte_pcf_sd;
35
static int hf_tte_pcf_type;
36
/* static int hf_tte_pcf_res1; */
37
static int hf_tte_pcf_tc;
38
39
/* Initialize the subtree pointers */
40
static int ett_tte_pcf;
41
42
static dissector_handle_t tte_pcf_handle;
43
44
static const value_string pcf_type_str_vals[] =
45
    { {2, "integration frame"}
46
    , {4, "coldstart frame"}
47
    , {8, "coldstart ack frame"}
48
    , {0, NULL}
49
    };
50
51
52
/* Code to actually dissect the packets */
53
static int
54
dissect_tte_pcf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
55
3
{
56
    /* Set up structures needed to add the protocol subtree and manage it */
57
3
    proto_item *tte_pcf_root_item;
58
3
    proto_tree *tte_pcf_tree;
59
60
    /* variables used to store the fields displayed in the info_column */
61
3
    uint8_t sync_priority = 0;
62
3
    uint8_t sync_domain   = 0;
63
64
    /* Check that there's enough data */
65
3
    if (tvb_reported_length(tvb) < TTE_PCF_LENGTH )
66
2
    {
67
2
        return 0;
68
2
    }
69
70
    /* get sync_priority and sync_domain */
71
1
    sync_priority = tvb_get_uint8(tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
72
1
        TTE_PCF_RES0_LENGTH);
73
1
    sync_domain = tvb_get_uint8(tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
74
1
        TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH);
75
76
    /* Make entries in Protocol column and Info column on summary display */
77
1
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PCF");
78
79
1
    col_add_fstr(pinfo->cinfo, COL_INFO,
80
1
            "Sync Domain: 0x%02X  Sync Priority: 0x%02X",
81
1
            sync_domain, sync_priority);
82
83
1
    if (tree) {
84
85
        /* create display subtree for the protocol */
86
1
        tte_pcf_root_item = proto_tree_add_item(tree, proto_tte_pcf, tvb, 0,
87
1
            TTE_PCF_LENGTH, ENC_NA);
88
89
1
        tte_pcf_tree = proto_item_add_subtree(tte_pcf_root_item, ett_tte_pcf);
90
91
1
        proto_tree_add_item(tte_pcf_tree,
92
1
            hf_tte_pcf_ic, tvb, 0, TTE_PCF_IC_LENGTH, ENC_BIG_ENDIAN);
93
94
1
        proto_tree_add_item(tte_pcf_tree,
95
1
            hf_tte_pcf_mn, tvb, TTE_PCF_IC_LENGTH, TTE_PCF_MN_LENGTH, ENC_BIG_ENDIAN);
96
97
     /* RESERVED FIELD --- will not be displayed */
98
     /* proto_tree_add_item(tte_pcf_tree,
99
            hf_tte_pcf_res0, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH,
100
            TTE_PCF_RES0_LENGTH, ENC_BIG_ENDIAN); */
101
102
1
        proto_tree_add_item(tte_pcf_tree,
103
1
            hf_tte_pcf_sp, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
104
1
            TTE_PCF_RES0_LENGTH, TTE_PCF_SP_LENGTH, ENC_BIG_ENDIAN);
105
106
1
        proto_tree_add_item(tte_pcf_tree,
107
1
            hf_tte_pcf_sd, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
108
1
            TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH, TTE_PCF_SD_LENGTH, ENC_BIG_ENDIAN);
109
110
1
        proto_tree_add_item(tte_pcf_tree,
111
1
            hf_tte_pcf_type, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
112
1
            TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH,
113
1
            TTE_PCF_TYPE_LENGTH, ENC_BIG_ENDIAN);
114
115
     /* RESERVED FIELD --- will not be displayed */
116
     /* proto_tree_add_item(tte_pcf_tree,
117
            hf_tte_pcf_res1, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
118
            TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH+
119
            TTE_PCF_TYPE_LENGTH, TTE_PCF_RES1_LENGTH, ENC_NA); */
120
121
1
        proto_tree_add_item(tte_pcf_tree,
122
1
            hf_tte_pcf_tc, tvb, TTE_PCF_IC_LENGTH+TTE_PCF_MN_LENGTH+
123
1
            TTE_PCF_RES0_LENGTH+TTE_PCF_SP_LENGTH+TTE_PCF_SD_LENGTH+
124
1
            TTE_PCF_TYPE_LENGTH+TTE_PCF_RES1_LENGTH, TTE_PCF_TC_LENGTH, ENC_BIG_ENDIAN);
125
1
    }
126
127
1
    return tvb_captured_length(tvb);
128
3
}
129
130
131
void
132
proto_register_tte_pcf(void)
133
14
{
134
14
    static hf_register_info hf[] = {
135
136
14
        { &hf_tte_pcf_ic,
137
14
            { "Integration Cycle", "tte_pcf.ic",
138
14
            FT_UINT32, BASE_HEX, NULL, 0x0,
139
14
            NULL, HFILL }
140
14
        },
141
14
            { &hf_tte_pcf_mn,
142
14
            { "Membership New", "tte_pcf.mn",
143
14
            FT_UINT32, BASE_HEX, NULL, 0x0,
144
14
            NULL, HFILL }
145
14
        },
146
#if 0
147
            { &hf_tte_pcf_res0,
148
            { "Reserved 0", "tte_pcf.res0",
149
            FT_UINT32, BASE_HEX, NULL, 0x0,
150
            NULL, HFILL }
151
        },
152
#endif
153
14
        { &hf_tte_pcf_sp,
154
14
            { "Sync Priority", "tte_pcf.sp",
155
14
            FT_UINT8, BASE_HEX, NULL, 0x0,
156
14
            NULL, HFILL }
157
14
        },
158
14
        { &hf_tte_pcf_sd,
159
14
            { "Sync Domain", "tte_pcf.sd",
160
14
            FT_UINT8, BASE_HEX, NULL, 0x0,
161
14
            NULL, HFILL }
162
14
        },
163
14
        { &hf_tte_pcf_type,
164
14
            { "Type", "tte_pcf.type",
165
14
            FT_UINT8, BASE_HEX, VALS(pcf_type_str_vals), 0x0F,
166
14
            NULL, HFILL }
167
14
        },
168
#if 0
169
        { &hf_tte_pcf_res1,
170
            { "Reserved 1", "tte_pcf.res1",
171
            FT_BYTES, BASE_NONE, NULL, 0x0,
172
            NULL, HFILL }
173
        },
174
#endif
175
14
        { &hf_tte_pcf_tc,
176
14
            { "Transparent Clock", "tte_pcf.tc",
177
14
            FT_UINT64, BASE_HEX, NULL, 0x0,
178
14
            NULL, HFILL }
179
14
        }
180
14
    };
181
182
    /* Setup protocol subtree array */
183
14
    static int *ett[] = {
184
14
        &ett_tte_pcf
185
14
    };
186
187
    /* Register the protocol name and description */
188
14
    proto_tte_pcf = proto_register_protocol("TTEthernet Protocol Control Frame",
189
14
        "TTE PCF", "tte_pcf");
190
191
    /* Required function calls to register header fields and subtrees used */
192
14
    proto_register_field_array(proto_tte_pcf, hf, array_length(hf));
193
14
    proto_register_subtree_array(ett, array_length(ett));
194
195
14
    tte_pcf_handle = register_dissector("tte_pcf", dissect_tte_pcf, proto_tte_pcf);
196
14
}
197
198
199
void
200
proto_reg_handoff_tte_pcf(void)
201
14
{
202
14
    dissector_add_uint("ethertype", ETHERTYPE_TTE_PCF, tte_pcf_handle);
203
204
14
}
205
206
/*
207
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
208
 *
209
 * Local variables:
210
 * c-basic-offset: 4
211
 * tab-width: 8
212
 * indent-tabs-mode: nil
213
 * End:
214
 *
215
 * vi: set shiftwidth=4 tabstop=8 expandtab:
216
 * :indentSize=4:tabSize=8:noTabs=true:
217
 */