From Jeff Morriss: SSCOP over UDP and SSCF-NNI support.
[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  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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 <stdio.h>
33 #include <glib.h>
34 #include <string.h>
35 #include <epan/packet.h>
36
37 static int proto_sscf = -1;
38
39 static gint ett_sscf = -1;
40
41 static dissector_handle_t mtp3_handle;
42 static dissector_handle_t data_handle;
43
44 #define SSCF_PDU_LENGTH 4
45 #define SSCF_STATUS_OFFSET 3
46 #define SSCF_STATUS_LENGTH 1
47 #define SSCF_SPARE_OFFSET 0
48 #define SSCF_SPARE_LENGTH 3
49
50 static int hf_status = -1;
51 static int hf_spare = -1;
52
53 #define SSCF_STATUS_OOS 0x01
54 #define SSCF_STATUS_PO  0x02
55 #define SSCF_STATUS_IS  0x03
56 #define SSCF_STATUS_NORMAL 0x04
57 #define SSCF_STATUS_EMERGENCY 0x05
58 #define SSCF_STATUS_ALIGNMENT_NOT_SUCCESSFUL 0x7
59 #define SSCF_STATUS_MANAGEMENT_INITIATED 0x08
60 #define SSCF_STATUS_PROTOCOL_ERROR 0x09
61 #define SSCF_STATUS_PROVING_NOT_SUCCESSFUL 0x0a
62
63 static const value_string sscf_status_vals[] = {
64         { SSCF_STATUS_OOS,                      "Out of Service" },
65         { SSCF_STATUS_PO,                       "Processor Outage" },
66         { SSCF_STATUS_IS,                       "In Service" },
67         { SSCF_STATUS_NORMAL,                   "Normal" },
68         { SSCF_STATUS_EMERGENCY,                "Emergency" },
69         { SSCF_STATUS_ALIGNMENT_NOT_SUCCESSFUL, "Alignment Not Successful" },
70         { SSCF_STATUS_MANAGEMENT_INITIATED,     "Management Initiated" },
71         { SSCF_STATUS_PROTOCOL_ERROR,           "Protocol Error" },
72         { SSCF_STATUS_PROVING_NOT_SUCCESSFUL,   "Proving Not Successful" },
73         { 0,                                    NULL }
74 };
75
76 static void
77 dissect_sscf_nni(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
78 {
79   guint reported_length;
80   proto_item *sscf_item = NULL;
81   proto_tree *sscf_tree = NULL;
82   guint8 sscf_status;
83
84   reported_length = tvb_reported_length(tvb);   /* frame length */
85
86   if (tree) {
87     sscf_item = proto_tree_add_item(tree, proto_sscf, tvb, 0, -1, FALSE);
88     sscf_tree = proto_item_add_subtree(sscf_item, ett_sscf);
89   }
90
91   if (reported_length > SSCF_PDU_LENGTH)
92   {
93     call_dissector(mtp3_handle, tvb, pinfo, tree);
94
95   } else {
96
97     sscf_status = tvb_get_guint8(tvb, SSCF_STATUS_OFFSET);
98
99     if (check_col(pinfo->cinfo, COL_PROTOCOL))
100       col_set_str(pinfo->cinfo, COL_PROTOCOL, "SSCF-NNI");
101     if (check_col(pinfo->cinfo, COL_INFO))
102       col_add_fstr(pinfo->cinfo, COL_INFO, "STATUS (%s) ",
103                    val_to_str(sscf_status, sscf_status_vals, "Unknown"));
104
105     
106     proto_tree_add_item(sscf_tree, hf_status, tvb, SSCF_STATUS_OFFSET,
107                         SSCF_STATUS_LENGTH, FALSE);
108     proto_tree_add_item(sscf_tree, hf_spare, tvb, SSCF_SPARE_OFFSET,
109                         SSCF_SPARE_LENGTH, FALSE);
110   }
111
112 }
113
114 void
115 proto_register_sscf(void)
116 {
117   static hf_register_info hf[] = 
118   { { &hf_status, { "Status", "sscf-nni.status", FT_UINT8, BASE_HEX,
119                     VALS(sscf_status_vals), 0x0, "", HFILL} },
120     { &hf_spare, { "Spare", "sscf-nni.spare", FT_UINT24, BASE_HEX,
121                     NULL, 0x0, "", HFILL} }
122   };
123
124   static gint *ett[] = {
125     &ett_sscf,
126   };
127
128   proto_sscf = proto_register_protocol("SSCF-NNI", "SSCF-NNI", "sscf-nni");
129
130   proto_register_field_array(proto_sscf, hf, array_length(hf));
131   proto_register_subtree_array(ett, array_length(ett));
132
133   register_dissector("sscf-nni", dissect_sscf_nni, proto_sscf);
134
135 }
136
137 void
138 proto_reg_handoff_sscf(void)
139 {
140   static dissector_handle_t sscf_handle;         
141
142
143   sscf_handle = create_dissector_handle(dissect_sscf_nni, proto_sscf);   
144
145   mtp3_handle = find_dissector("mtp3");
146   data_handle = find_dissector("data");
147
148 }