summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-sscf-nni.c
blob: ae5b8927e48c3091755c587a80e430c9ee9e7a01 (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
/* packet-sscf-nni.c
 * Routines for SSCF-NNI (Q.2140) frame disassembly
 * Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998
 *
 * Copied from packet-sscop.c
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>

void proto_register_sscf(void);
void proto_reg_handoff_sscf(void);

static int proto_sscf = -1;

static gint ett_sscf = -1;

static dissector_handle_t mtp3_handle;

#define SSCF_PDU_LENGTH 4
#define SSCF_STATUS_OFFSET 3
#define SSCF_STATUS_LENGTH 1
#define SSCF_SPARE_OFFSET 0
#define SSCF_SPARE_LENGTH 3

static int hf_status = -1;
static int hf_spare = -1;

#define SSCF_STATUS_OOS 0x01
#define SSCF_STATUS_PO  0x02
#define SSCF_STATUS_IS  0x03
#define SSCF_STATUS_NORMAL 0x04
#define SSCF_STATUS_EMERGENCY 0x05
#define SSCF_STATUS_ALIGNMENT_NOT_SUCCESSFUL 0x7
#define SSCF_STATUS_MANAGEMENT_INITIATED 0x08
#define SSCF_STATUS_PROTOCOL_ERROR 0x09
#define SSCF_STATUS_PROVING_NOT_SUCCESSFUL 0x0a

static const value_string sscf_status_vals[] = {
  { SSCF_STATUS_OOS,                      "Out of Service" },
  { SSCF_STATUS_PO,                       "Processor Outage" },
  { SSCF_STATUS_IS,                       "In Service" },
  { SSCF_STATUS_NORMAL,                   "Normal" },
  { SSCF_STATUS_EMERGENCY,                "Emergency" },
  { SSCF_STATUS_ALIGNMENT_NOT_SUCCESSFUL, "Alignment Not Successful" },
  { SSCF_STATUS_MANAGEMENT_INITIATED,     "Management Initiated" },
  { SSCF_STATUS_PROTOCOL_ERROR,           "Protocol Error" },
  { SSCF_STATUS_PROVING_NOT_SUCCESSFUL,   "Proving Not Successful" },
  { 0,                                    NULL }
};

static int
dissect_sscf_nni(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
  guint reported_length;
  proto_item *sscf_item = NULL;
  proto_tree *sscf_tree = NULL;
  guint8 sscf_status;

  reported_length = tvb_reported_length(tvb);  /* frame length */

  if (tree) {
    sscf_item = proto_tree_add_item(tree, proto_sscf, tvb, 0, -1, ENC_NA);
    sscf_tree = proto_item_add_subtree(sscf_item, ett_sscf);
  }

  if (reported_length > SSCF_PDU_LENGTH)
  {
    call_dissector(mtp3_handle, tvb, pinfo, tree);

  } else {

    sscf_status = tvb_get_guint8(tvb, SSCF_STATUS_OFFSET);

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "SSCF-NNI");
    col_add_fstr(pinfo->cinfo, COL_INFO, "STATUS (%s) ",
                 val_to_str_const(sscf_status, sscf_status_vals, "Unknown"));


    proto_tree_add_item(sscf_tree, hf_status, tvb, SSCF_STATUS_OFFSET,
                        SSCF_STATUS_LENGTH, ENC_BIG_ENDIAN);
    proto_tree_add_item(sscf_tree, hf_spare, tvb, SSCF_SPARE_OFFSET,
                        SSCF_SPARE_LENGTH, ENC_BIG_ENDIAN);
  }

  return tvb_captured_length(tvb);
}

void
proto_register_sscf(void)
{
  static hf_register_info hf[] =
  { { &hf_status, { "Status", "sscf-nni.status", FT_UINT8, BASE_HEX,
                    VALS(sscf_status_vals), 0x0, NULL, HFILL} },
    { &hf_spare, { "Spare", "sscf-nni.spare", FT_UINT24, BASE_HEX,
                   NULL, 0x0, NULL, HFILL} }
  };

  static gint *ett[] = {
    &ett_sscf,
  };

  proto_sscf = proto_register_protocol("SSCF-NNI", "SSCF-NNI", "sscf-nni");

  proto_register_field_array(proto_sscf, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));

  register_dissector("sscf-nni", dissect_sscf_nni, proto_sscf);

}

void
proto_reg_handoff_sscf(void)
{
  mtp3_handle = find_dissector_add_dependency("mtp3", proto_sscf);
}

/*
 * 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:
 */