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