6469bfa2debcb851e5e1f8044d12ebf75595ede0
[obnox/wireshark/wip.git] / asn1 / smrse / packet-smrse-template.c
1 /* packet-smrse.c
2  * Routines for SMRSE Short Message Relay Service packet dissection
3  *   Ronnie Sahlberg 2004
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/asn1.h>
33
34 #include "packet-ber.h"
35 #include "packet-smrse.h"
36
37 #define PNAME  "Short Message Relaying Service"
38 #define PSNAME "SMRSE"
39 #define PFNAME "smrse"
40
41 #define TCP_PORT_SMRSE 4321
42
43 /* Initialize the protocol and registered fields */
44 static int proto_smrse = -1;
45 static int hf_smrse_reserved = -1;
46 static int hf_smrse_tag = -1;
47 static int hf_smrse_length = -1;
48 static int hf_smrse_Octet_Format = -1;
49 #include "packet-smrse-hf.c"
50
51 /* Initialize the subtree pointers */
52 static gint ett_smrse = -1;
53 #include "packet-smrse-ett.c"
54
55
56 #include "packet-smrse-fn.c"
57
58 static const value_string tag_vals[] = {
59         {  1,   "AliveTest" },
60         {  2,   "AliveTestRsp" },
61         {  3,   "Bind" },
62         {  4,   "BindRsp" },
63         {  5,   "BindFail" },
64         {  6,   "Unbind" },
65         {  7,   "MT" },
66         {  8,   "MO" },
67         {  9,   "Ack" },
68         { 10,   "Error" },
69         { 11,   "Alert" },
70         { 0, NULL }
71 };
72
73 static int
74 dissect_smrse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
75 {
76         proto_item *item = NULL;
77         proto_tree *tree = NULL;
78         guint8 reserved, tag;
79         guint16 length;
80         int offset=0;
81         asn1_ctx_t asn1_ctx;
82         asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
83
84         reserved=tvb_get_guint8(tvb, 0);
85         length=tvb_get_ntohs(tvb,1);
86         tag=tvb_get_guint8(tvb, 3);
87
88         if( reserved!= 126 )
89                 return 0;
90         if( (tag<1)||(tag>11) )
91                 return 0;
92
93         if(parent_tree){
94                 item = proto_tree_add_item(parent_tree, proto_smrse, tvb, 0, -1, FALSE);
95                 tree = proto_item_add_subtree(item, ett_smrse);
96         }
97
98         col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMRSE");
99         if (check_col(pinfo->cinfo, COL_INFO))
100                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(tag, tag_vals,"Unknown Tag:0x%02x"));
101
102         proto_tree_add_item(tree, hf_smrse_reserved, tvb, 0, 1, FALSE);
103         proto_tree_add_item(tree, hf_smrse_length, tvb, 1, 2, ENC_BIG_ENDIAN);
104         proto_tree_add_item(tree, hf_smrse_tag, tvb, 3, 1, ENC_BIG_ENDIAN);
105
106         switch(tag){
107         case 1:
108         case 2:
109                 offset=4;
110                 break;
111         case 3:
112                 offset=dissect_smrse_SMR_Bind(FALSE, tvb, 4, &asn1_ctx, tree, -1);
113                 break;
114         case 4:
115                 offset=dissect_smrse_SMR_Bind_Confirm(FALSE, tvb, 4, &asn1_ctx, tree, -1);
116                 break;
117         case 5:
118                 offset=dissect_smrse_SMR_Bind_Failure(FALSE, tvb, 4, &asn1_ctx, tree, -1);
119                 break;
120         case 6:
121                 offset=dissect_smrse_SMR_Unbind(FALSE, tvb, 4, &asn1_ctx, tree, -1);
122                 break;
123         case 7:
124                 offset=dissect_smrse_RPDataMT(FALSE, tvb, 4, &asn1_ctx, tree, -1);
125                 break;
126         case 8:
127                 offset=dissect_smrse_RPDataMO(FALSE, tvb, 4, &asn1_ctx, tree, -1);
128                 break;
129         case 9:
130                 offset=dissect_smrse_RPAck(FALSE, tvb, 4, &asn1_ctx, tree, -1);
131                 break;
132         case 10:
133                 offset=dissect_smrse_RPError(FALSE, tvb, 4, &asn1_ctx, tree, -1);
134                 break;
135         case 11:
136                 offset=dissect_smrse_RPAlertSC(FALSE, tvb, 4, &asn1_ctx, tree, -1);
137                 break;
138         }
139
140         return offset;
141 }
142
143 /*--- proto_register_smrse ----------------------------------------------*/
144 void proto_register_smrse(void) {
145
146   /* List of fields */
147   static hf_register_info hf[] = {
148         { &hf_smrse_reserved, {
149                 "Reserved", "smrse.reserved", FT_UINT8, BASE_DEC,
150                 NULL, 0, "Reserved byte, must be 126", HFILL }},
151         { &hf_smrse_tag, {
152                 "Tag", "smrse.tag", FT_UINT8, BASE_DEC,
153                 VALS(tag_vals), 0, NULL, HFILL }},
154         { &hf_smrse_length, {
155                 "Length", "smrse.length", FT_UINT16, BASE_DEC,
156                 NULL, 0, "Length of SMRSE PDU", HFILL }},
157     { &hf_smrse_Octet_Format,
158       { "octet-Format", "smrse.octet_Format",
159         FT_STRING, BASE_NONE, NULL, 0,
160         "SMS-Address/address-value/octet-format", HFILL }},
161
162 #include "packet-smrse-hfarr.c"
163   };
164
165   /* List of subtrees */
166   static gint *ett[] = {
167     &ett_smrse,
168 #include "packet-smrse-ettarr.c"
169   };
170
171   /* Register protocol */
172   proto_smrse = proto_register_protocol(PNAME, PSNAME, PFNAME);
173
174   /* Register fields and subtrees */
175   proto_register_field_array(proto_smrse, hf, array_length(hf));
176   proto_register_subtree_array(ett, array_length(ett));
177
178 }
179
180
181 /*--- proto_reg_handoff_smrse -------------------------------------------*/
182 void proto_reg_handoff_smrse(void) {
183   dissector_handle_t smrse_handle;
184
185   smrse_handle = new_create_dissector_handle(dissect_smrse, proto_smrse);
186   dissector_add_uint("tcp.port",TCP_PORT_SMRSE, smrse_handle);
187 }
188