Removed some more "statement not reached" warnings.
[obnox/wireshark/wip.git] / epan / dissectors / packet-bctp.c
1 /*\r
2  *  packet-bctp.c\r
3  *  Q.1990 BICC bearer control tunnelling protocol\r
4  *\r
5  *  (c) 2007, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>\r
6  *\r
7  * $Id: $\r
8  *\r
9  * Wireshark - Network traffic analyzer\r
10  * By Gerald Combs <gerald@wireshark.org>\r
11  * Copyright 1998 Gerald Combs\r
12  *\r
13  * This program is free software; you can redistribute it and/or\r
14  * modify it under the terms of the GNU General Public License\r
15  * as published by the Free Software Foundation; either version 2\r
16  * of the License, or (at your option) any later version.\r
17  *\r
18  * This program is distributed in the hope that it will be useful,\r
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
21  * GNU General Public License for more details.\r
22  *\r
23  * You should have received a copy of the GNU General Public License\r
24  * along with this program; if not, write to the Free Software\r
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
26  *\r
27  * Ref ITU-T Rec. Q.1990 (07/2001)\r
28  */\r
29  \r
30  #ifdef HAVE_CONFIG_H\r
31 # include "config.h"\r
32 #endif\r
33 \r
34 #include <glib.h>\r
35 #include <epan/packet.h>\r
36 \r
37 #define PNAME  "BCTP Q.1990"\r
38 #define PSNAME "BCTP"\r
39 #define PFNAME "bctp"\r
40 \r
41 static int proto_bctp = -1;\r
42 static int hf_bctp_bvei = -1;\r
43 static int hf_bctp_bvi = -1;\r
44 static int hf_bctp_tpei = -1;\r
45 static int hf_bctp_tpi = -1;\r
46 \r
47 static gint ett_bctp = -1;\r
48 static dissector_table_t bctp_dissector_table;\r
49 static dissector_handle_t data_handle;\r
50 static dissector_handle_t text_handle;\r
51 \r
52 /*\r
53 static const range_string tpi_vals[] = {\r
54         {0x00,0x17,"spare (binary encoded protocols)"},\r
55         {0x18,0x1f,"reserved for national use (binary encoded protocols)"},\r
56         {0x20,0x20,"IPBCP (text encoded)"},\r
57         {0x21,0x21,"spare (text encoded protocol)"},\r
58         {0x22,0x22,"not used"},\r
59         {0x23,0x37,"spare (text encoded protocols)"},\r
60         {0x38,0x3f,"reserved for national use (text encoded protocols)"},\r
61         {0,0,NULL}\r
62 };\r
63 */\r
64 \r
65 static const value_string bvei_vals[] = {\r
66         {0,"No indication"},\r
67         {0,"Version Error Indication, BCTP version not supported"},\r
68         {0,NULL}\r
69 };\r
70 \r
71 \r
72 static void dissect_bctp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {\r
73         proto_item* pi = proto_tree_add_item(tree, proto_bctp, tvb,0,2, FALSE);\r
74         proto_tree* pt = proto_item_add_subtree(pi,ett_bctp);\r
75         tvbuff_t* sub_tvb = tvb_new_subset(tvb, 2, -1, -1);\r
76         guint8 tpi = tvb_get_guint8(tvb,1) & 0x3f;\r
77         \r
78         proto_tree_add_item(pt, hf_bctp_bvei, tvb,0,2, FALSE);\r
79         proto_tree_add_item(pt, hf_bctp_bvi, tvb,0,2, FALSE);\r
80         proto_tree_add_item(pt, hf_bctp_tpei, tvb,0,2, FALSE);\r
81         proto_tree_add_item(pt, hf_bctp_tpi, tvb,0,2, FALSE);\r
82         \r
83         if ( dissector_try_port(bctp_dissector_table, tpi, sub_tvb, pinfo, tree) ) {\r
84                 return;\r
85         } else if (tpi <= 0x22) {\r
86                 call_dissector(data_handle,sub_tvb, pinfo, tree);\r
87         } else {\r
88                 /* tpi > 0x22 */\r
89                 call_dissector(text_handle,sub_tvb, pinfo, tree);\r
90         }\r
91 }\r
92 \r
93 void\r
94 proto_register_bctp (void)\r
95 {\r
96         static hf_register_info hf[] = {\r
97                 {&hf_bctp_bvei, {"BVEI", "bctp.bvei", FT_UINT16, BASE_HEX, VALS(bvei_vals), 0x4000, "BCTP Version Error Indicator", HFILL }},\r
98                 {&hf_bctp_bvi, {"BVI", "bctp.bvi", FT_UINT16, BASE_HEX, NULL, 0x1F00, "BCTP Version Indicator", HFILL }},\r
99                 {&hf_bctp_tpei, {"TPEI", "bctp.tpei", FT_UINT16, BASE_HEX, NULL, 0x0040, "Tunnelled Protocol Error Indicator", HFILL }},\r
100                 {&hf_bctp_tpi, {"TPI", "bctp.tpi", FT_UINT16, BASE_HEX, NULL, 0x003F, "Tunnelled Protocol Indicator", HFILL }},\r
101         };\r
102         static gint *ett[] = {\r
103                 &ett_bctp\r
104         };\r
105 \r
106         proto_bctp = proto_register_protocol(PNAME, PSNAME, PFNAME);\r
107         proto_register_field_array(proto_bctp, hf, array_length(hf));\r
108         proto_register_subtree_array(ett, array_length(ett));\r
109 \r
110         register_dissector("bctp", dissect_bctp, proto_bctp);\r
111 \r
112         bctp_dissector_table = register_dissector_table("bctp.tpi", "BCTP Tunnelled Protocol Indicator", FT_UINT32, BASE_DEC);\r
113 }\r
114 \r
115 void\r
116 proto_reg_handoff_bctp(void)\r
117 {\r
118         data_handle = find_dissector("data");\r
119         text_handle = find_dissector("data-text-lines");\r
120 }\r
121 \r