summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ipsi-ctl.c
blob: 8f71b6574a2a7fa0fc91529f6e799838ba8d9c21 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* packet-ipsi-ctl.c
 * Routines for Avaya IPSI Control packet disassembly
 * Traffic is encapsulated Avaya proprietary CCMS
 * (Control Channel Message Set) between PCD and SIM
 *
 * Copyright 2008, Randy McEoin <rmceoin@ahbelo.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>

void proto_register_ipsictl(void);
void proto_reg_handoff_ipsictl(void);

static dissector_handle_t ipsictl_handle;

#define IPSICTL_PORT            5010 /* Not IANA registered */
#define IPSICTL_PDU_MAGIC       0x0300

static int proto_ipsictl;

static int hf_ipsictl_pdu;
static int hf_ipsictl_magic;
static int hf_ipsictl_length;
static int hf_ipsictl_type;
static int hf_ipsictl_sequence;
static int hf_ipsictl_field1;
static int hf_ipsictl_data;

static int ett_ipsictl;
static int ett_ipsictl_pdu;

static int dissect_ipsictl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{

  proto_tree   *ipsictl_tree;
  proto_tree   *pdu_tree;
  proto_item   *ti;
  int           offset = 0;
  int           loffset = 0;
  int           llength = 0;
  int           remaining_length;
  uint16_t      magic;
  uint16_t      length;
  uint16_t      type=0;
  uint16_t      sequence=0;
  int           first_sequence=-1;
  int           last_sequence=-1;
  uint16_t      field1=0;
  uint16_t      pdu=0;
  int           haspdus=0;

  remaining_length=tvb_reported_length_remaining(tvb, offset);

  ti = proto_tree_add_item(tree, proto_ipsictl, tvb, offset, remaining_length, ENC_NA);
  ipsictl_tree = proto_item_add_subtree(ti, ett_ipsictl);

  magic = tvb_get_ntohs(tvb, offset);
  if (magic == IPSICTL_PDU_MAGIC)
  {
    haspdus=1;
  }

  while (haspdus &&
    ((remaining_length=tvb_reported_length_remaining(tvb, offset)) > 6))
  {
    loffset = offset;

    magic = tvb_get_ntohs(tvb, loffset); loffset+=2;
    length = tvb_get_ntohs(tvb, loffset); loffset+=2;
    llength=length;
    remaining_length-=4;
    if (remaining_length>=2)
    {
      type = tvb_get_ntohs(tvb, loffset); loffset+=2;
      remaining_length-=2;
      llength-=2;
    }
    if (remaining_length>=2)
    {
      sequence = tvb_get_ntohs(tvb, loffset); loffset+=2;
      remaining_length-=2;
      llength-=2;
      if (first_sequence==-1)
      {
        first_sequence=sequence;
      }else{
        last_sequence=sequence;
      }
    }
    if (remaining_length>=2)
    {
      field1 = tvb_get_ntohs(tvb, loffset);
      llength-=2;
    }

    ti = proto_tree_add_uint(ipsictl_tree, hf_ipsictl_pdu, tvb,
           offset, (length+4), pdu);
    pdu_tree = proto_item_add_subtree(ti, ett_ipsictl_pdu);

    loffset=offset;
    remaining_length=tvb_reported_length_remaining(tvb, offset);

    if (tree) {
      proto_tree_add_uint(pdu_tree, hf_ipsictl_magic, tvb, loffset, 2, magic);
    }
    loffset+=2; remaining_length-=2;
    if (tree) {
      proto_tree_add_uint(pdu_tree, hf_ipsictl_length, tvb, loffset, 2, length);
    }
    loffset+=2; remaining_length-=2;

    if (remaining_length>=2)
    {
      if (tree) {
        proto_tree_add_uint(pdu_tree, hf_ipsictl_type, tvb, loffset, 2, type);
      }
      loffset+=2; remaining_length-=2;
    }
    if (remaining_length>=2)
    {
      if (tree) {
        proto_tree_add_uint(pdu_tree, hf_ipsictl_sequence, tvb, loffset, 2, sequence);
      }
      loffset+=2; remaining_length-=2;
    }
    if (remaining_length>=2)
    {
      if (tree) {
        proto_tree_add_uint(pdu_tree, hf_ipsictl_field1, tvb, loffset, 2, field1);
      }
      loffset+=2; remaining_length-=2;
    }
    if (remaining_length>=2)
    {
      if (tree) {
        proto_tree_add_item(pdu_tree, hf_ipsictl_data, tvb, loffset, llength, ENC_NA);
      }
      loffset+=llength;
    }

    offset=loffset;
    pdu++;
  }

  if (!haspdus)
  {
    proto_tree_add_item(ipsictl_tree, hf_ipsictl_data, tvb, offset, -1, ENC_NA);
  }

  col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPSICTL");

  if (haspdus)
  {
    if (last_sequence==-1)
    {
      col_add_fstr(pinfo->cinfo, COL_INFO, "PDUS=%d, Seq=0x%04x",
        pdu,first_sequence);
    }else{
      col_add_fstr(pinfo->cinfo, COL_INFO, "PDUS=%d, Seq=0x%04x-0x%04x",
        pdu,first_sequence,last_sequence);
    }
  }else{
    col_set_str(pinfo->cinfo, COL_INFO, "Initialization");
  }

  return tvb_captured_length(tvb);

} /* dissect_ipsictl */

void proto_register_ipsictl(void)
{

  static hf_register_info hf[] = {
    { &hf_ipsictl_pdu,
      { "PDU",  "ipsictl.pdu",
        FT_UINT16,      BASE_DEC,       NULL,   0x0,
        "IPSICTL PDU", HFILL }},
    { &hf_ipsictl_magic,
      { "Magic",        "ipsictl.magic",
        FT_UINT16,      BASE_HEX,       NULL,   0x0,
        "IPSICTL Magic", HFILL }},
    { &hf_ipsictl_length,
      { "Length",       "ipsictl.length",
        FT_UINT16,      BASE_HEX,       NULL,   0x0,
        "IPSICTL Length", HFILL }},
    { &hf_ipsictl_type,
      { "Type", "ipsictl.type",
        FT_UINT16,      BASE_HEX,       NULL,   0x0,
        "IPSICTL Type", HFILL }},
    { &hf_ipsictl_sequence,
      { "Sequence",     "ipsictl.sequence",
        FT_UINT16,      BASE_HEX,       NULL,   0x0,
        "IPSICTL Sequence", HFILL }},
    { &hf_ipsictl_field1,
      { "Field1",       "ipsictl.field1",
        FT_UINT16,      BASE_HEX,       NULL,   0x0,
        "IPSICTL Field1", HFILL }},
    { &hf_ipsictl_data,
      { "Data", "ipsictl.data",
        FT_BYTES,       BASE_NONE,      NULL,   0x0,
        "IPSICTL data", HFILL }},
  };

  static int *ett[] = {
    &ett_ipsictl,
    &ett_ipsictl_pdu
  };

  proto_ipsictl = proto_register_protocol("IPSICTL", "IPSICTL", "ipsictl");
  proto_register_field_array(proto_ipsictl, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));

  ipsictl_handle = register_dissector("ipsictl", dissect_ipsictl, proto_ipsictl);
}

void proto_reg_handoff_ipsictl(void)
{

  dissector_add_uint_with_preference("tcp.port", IPSICTL_PORT, ipsictl_handle);

}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local Variables:
 * c-basic-offset: 2
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=2 tabstop=8 expandtab:
 * :indentSize=2:tabSize=8:noTabs=true:
 */