Remove all $Id$ from top of file
[metze/wireshark/wip.git] / epan / dissectors / packet-sscf-nni.c
1 /* packet-sscf-nni.c
2  * Routines for SSCF-NNI (Q.2140) frame disassembly
3  * Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998
8  *
9  * Copied from packet-sscop.c
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include "config.h"
27
28 #include <glib.h>
29 #include <epan/packet.h>
30
31 void proto_register_sscf(void);
32 void proto_reg_handoff_sscf(void);
33
34 static int proto_sscf = -1;
35
36 static gint ett_sscf = -1;
37
38 static dissector_handle_t mtp3_handle;
39
40 #define SSCF_PDU_LENGTH 4
41 #define SSCF_STATUS_OFFSET 3
42 #define SSCF_STATUS_LENGTH 1
43 #define SSCF_SPARE_OFFSET 0
44 #define SSCF_SPARE_LENGTH 3
45
46 static int hf_status = -1;
47 static int hf_spare = -1;
48
49 #define SSCF_STATUS_OOS 0x01
50 #define SSCF_STATUS_PO  0x02
51 #define SSCF_STATUS_IS  0x03
52 #define SSCF_STATUS_NORMAL 0x04
53 #define SSCF_STATUS_EMERGENCY 0x05
54 #define SSCF_STATUS_ALIGNMENT_NOT_SUCCESSFUL 0x7
55 #define SSCF_STATUS_MANAGEMENT_INITIATED 0x08
56 #define SSCF_STATUS_PROTOCOL_ERROR 0x09
57 #define SSCF_STATUS_PROVING_NOT_SUCCESSFUL 0x0a
58
59 static const value_string sscf_status_vals[] = {
60         { SSCF_STATUS_OOS,                      "Out of Service" },
61         { SSCF_STATUS_PO,                       "Processor Outage" },
62         { SSCF_STATUS_IS,                       "In Service" },
63         { SSCF_STATUS_NORMAL,                   "Normal" },
64         { SSCF_STATUS_EMERGENCY,                "Emergency" },
65         { SSCF_STATUS_ALIGNMENT_NOT_SUCCESSFUL, "Alignment Not Successful" },
66         { SSCF_STATUS_MANAGEMENT_INITIATED,     "Management Initiated" },
67         { SSCF_STATUS_PROTOCOL_ERROR,           "Protocol Error" },
68         { SSCF_STATUS_PROVING_NOT_SUCCESSFUL,   "Proving Not Successful" },
69         { 0,                                    NULL }
70 };
71
72 static void
73 dissect_sscf_nni(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
74 {
75   guint reported_length;
76   proto_item *sscf_item = NULL;
77   proto_tree *sscf_tree = NULL;
78   guint8 sscf_status;
79
80   reported_length = tvb_reported_length(tvb);   /* frame length */
81
82   if (tree) {
83     sscf_item = proto_tree_add_item(tree, proto_sscf, tvb, 0, -1, ENC_NA);
84     sscf_tree = proto_item_add_subtree(sscf_item, ett_sscf);
85   }
86
87   if (reported_length > SSCF_PDU_LENGTH)
88   {
89     call_dissector(mtp3_handle, tvb, pinfo, tree);
90
91   } else {
92
93     sscf_status = tvb_get_guint8(tvb, SSCF_STATUS_OFFSET);
94
95     col_set_str(pinfo->cinfo, COL_PROTOCOL, "SSCF-NNI");
96     col_add_fstr(pinfo->cinfo, COL_INFO, "STATUS (%s) ",
97                    val_to_str_const(sscf_status, sscf_status_vals, "Unknown"));
98
99
100     proto_tree_add_item(sscf_tree, hf_status, tvb, SSCF_STATUS_OFFSET,
101                         SSCF_STATUS_LENGTH, ENC_BIG_ENDIAN);
102     proto_tree_add_item(sscf_tree, hf_spare, tvb, SSCF_SPARE_OFFSET,
103                         SSCF_SPARE_LENGTH, ENC_BIG_ENDIAN);
104   }
105
106 }
107
108 void
109 proto_register_sscf(void)
110 {
111   static hf_register_info hf[] =
112   { { &hf_status, { "Status", "sscf-nni.status", FT_UINT8, BASE_HEX,
113                     VALS(sscf_status_vals), 0x0, NULL, HFILL} },
114     { &hf_spare, { "Spare", "sscf-nni.spare", FT_UINT24, BASE_HEX,
115                     NULL, 0x0, NULL, HFILL} }
116   };
117
118   static gint *ett[] = {
119     &ett_sscf,
120   };
121
122   proto_sscf = proto_register_protocol("SSCF-NNI", "SSCF-NNI", "sscf-nni");
123
124   proto_register_field_array(proto_sscf, hf, array_length(hf));
125   proto_register_subtree_array(ett, array_length(ett));
126
127   register_dissector("sscf-nni", dissect_sscf_nni, proto_sscf);
128
129 }
130
131 void
132 proto_reg_handoff_sscf(void)
133 {
134   mtp3_handle = find_dissector("mtp3");
135 }