aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sercosiii/packet-sercosiii_1v1.c
blob: fa4288aee5f4cabbe2c8988b4e5877787a6b95e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* packet-sercosiii_1v1.c
 * Routines for SERCOS III dissection
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <glib.h>

#include <epan/packet.h>
#include <epan/etypes.h>

#include "packet-sercosiii.h"

/* Initialize the protocol and registered fields */
static gint proto_siii = -1;

/* Initialize the subtree pointers */
static gint ett_siii = -1;
static gint ett_siii_header = -1;

/* Main dissector entry */
static void
dissect_siii(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_item*  ti;
  proto_tree*  siii_tree;
  guint    type;
  char* tel_ch="?";
  char* tel_type="?";
  guint tel_no = 0;

  /* setup columns */
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "SERCOS III V1.1");
  col_clear(pinfo->cinfo, COL_INFO);

  /* check what we got on our hand */
  type = tvb_get_guint8(tvb, 0);
  if(type&0x80) /* primary or secondary channel */
    tel_ch="S";
  else
    tel_ch="P";

  if(type&0x40) /* master data telegram (mdt) or slave telegram (at) */
    tel_type="AT ";
  else
    tel_type="MDT";

  tel_no = type &0xF; /* even though it's reserved (the V1.1 spec states that it is reserved for additional MDT/AT) */

  col_append_fstr(pinfo->cinfo, COL_INFO, "%s%u Channel=%s", tel_type, tel_no, tel_ch);

  ti = proto_tree_add_item(tree, proto_siii, tvb, 0, -1, FALSE);

  siii_tree = proto_item_add_subtree(ti, ett_siii);

   /* enter the specific dissector for AT or MDT */
  if(type & 0x40)
    dissect_siii_at(tvb, pinfo, siii_tree);
  else
    dissect_siii_mdt(tvb, pinfo, siii_tree);
}

void
proto_register_sercosiii(void)
{
  /* Setup protocol subtree array */
  static gint *ett[] = {
    &ett_siii,
    &ett_siii_header
  };

  /* Register the protocol name and description */
  proto_siii = proto_register_protocol("SERCOS III V1.1",
      "SERCOS III V1.1", "sercosiii");

  /* Required function calls to register the header fields and subtrees used */
  proto_register_subtree_array(ett, array_length(ett));

  dissect_siii_mdt_init(proto_siii);
  dissect_siii_at_init(proto_siii);
  dissect_siii_mdt_devctrl_init(proto_siii);
  dissect_siii_at_devstat_init(proto_siii);
  dissect_siii_svc_init(proto_siii);
  dissect_siii_mst_init(proto_siii);
  dissect_siii_hp_init(proto_siii);

}

void
proto_reg_handoff_sercosiii(void)
{
  dissector_handle_t siii_handle;

  siii_handle = create_dissector_handle(dissect_siii, proto_siii);
  dissector_add("ethertype", ETHERTYPE_SERCOS, siii_handle);
}