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