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