Expert info when E.212 MCC/MNC contain non-decimal digits
[obnox/wireshark/wip.git] / epan / dissectors / packet-diameter_3gpp.c
1 /* packet-diameter_3gpp.c
2  * Routines for dissecting 3GPP OctetSting AVP:s
3  * Copyright 2008, Anders Broman <anders.broman[at]ericsson.com>
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  /* This dissector registers a dissector table for 3GPP Vendor specific
27   * AVP:s which will be called from the Diameter dissector to dissect
28   * the content of AVP:s of the OctetString type(or similar).
29   */
30
31   #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include <glib.h>
40
41 #include <epan/packet.h>
42 #include <epan/proto.h>
43 #include <epan/asn1.h>
44
45 #include "packet-gsm_map.h"
46 #include "packet-gsm_a_common.h"
47 #include "packet-e212.h"
48
49 /* Initialize the protocol and registered fields */
50 static int proto_diameter_3gpp                  = -1; 
51
52 static int hf_diameter_3gpp_msisdn                                      = -1;
53 static int hf_diameter_3gpp_ipaddr                                      = -1;
54 static int hf_diameter_3gpp_mbms_required_qos_prio      = -1;
55 static int hf_diameter_3gpp_tmgi                                        = -1;
56 static int hf_diameter_mbms_service_id                          = -1;
57
58 static gint diameter_3gpp_msisdn_ett                            = -1;
59 static gint diameter_3gpp_tmgi_ett                                      = -1;
60 /* Used for Diameter */
61
62 static int
63 dissect_diameter_3gpp_msisdn(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
64
65         proto_item* item;
66         proto_tree *sub_tree;
67         int offset = 0;
68
69         item = proto_tree_add_item(tree, hf_diameter_3gpp_msisdn, tvb, offset, 6, FALSE);
70         sub_tree = proto_item_add_subtree(item,diameter_3gpp_msisdn_ett);
71
72         dissect_gsm_map_msisdn(tvb, pinfo, sub_tree);
73
74         return tvb_length(tvb);
75
76 }
77
78
79 static int
80 dissect_diameter_3gpp_tmgi(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
81
82         proto_item* item;
83         proto_tree *sub_tree;
84         int offset = 0;
85
86         item = proto_tree_add_item(tree, hf_diameter_3gpp_tmgi, tvb, offset, 6, FALSE);
87         sub_tree = proto_item_add_subtree(item,diameter_3gpp_tmgi_ett);
88
89         /* MBMS Service ID consisting of three octets. MBMS Service ID consists of a 6-digit
90          * fixed-length hexadecimal number between 000000 and FFFFFF. 
91          * MBMS Service ID uniquely identifies an MBMS bearer service within a PLMN.
92          */
93
94         proto_tree_add_item(sub_tree, hf_diameter_mbms_service_id, tvb, offset, 3, FALSE);
95         offset = offset+3;
96         offset = dissect_e212_mcc_mnc(tvb, pinfo, sub_tree, offset);
97
98         return offset;
99
100 }
101
102 static int 
103 dissect_diameter_3gpp_ipaddr(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
104
105         int offset = 0;
106
107         proto_tree_add_item(tree, hf_diameter_3gpp_ipaddr, tvb, offset, 4, FALSE);
108         offset += 4;
109
110         return offset;
111
112 }
113
114 static int 
115 dissect_diameter_3gpp_mbms_required_qos(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
116
117         int offset = 0;
118         guint length;
119
120         /* Octet
121          * 1            Allocation/Retention Priority as specified in 3GPP TS 23.107. 
122          *                      This octet encodes each priority level defined in 3GPP TS 23.107
123          *                      as the binary value of the priority level. It specifies the relative
124          *                      importance of the actual MBMS bearer service compared to other MBMS
125          *                      and non-MBMS bearer services for allocation and retention of the 
126          *                      MBMS bearer service.
127          * 2-N          QoS Profile as specified by the Quality-of-Service information element,
128          *                      from octet 3 onwards, in 3GPP TS 24.008
129          */
130         proto_tree_add_item(tree, hf_diameter_3gpp_mbms_required_qos_prio, tvb, offset, 1, FALSE);
131         offset++;
132         length = tvb_length(tvb) - 1;
133         de_sm_qos(tvb, tree, offset, length, NULL, 0);
134         return offset+length;
135
136 }
137
138 void
139 proto_reg_handoff_diameter_3gpp(void)
140 {
141
142         /* AVP Code: 701 MSISDN */
143         dissector_add("diameter.3gpp", 701, new_create_dissector_handle(dissect_diameter_3gpp_msisdn, proto_diameter_3gpp));
144
145         /* AVP Code: 900 TMGI */
146         dissector_add("diameter.3gpp", 900, new_create_dissector_handle(dissect_diameter_3gpp_tmgi, proto_diameter_3gpp));
147
148         /* AVP Code: 918 MBMS-BMSC-SSM-IP-Address */
149         dissector_add("diameter.3gpp", 918, new_create_dissector_handle(dissect_diameter_3gpp_ipaddr, proto_diameter_3gpp));
150
151         /* AVP Code: 913 MBMS-Required-QoS */
152         dissector_add("diameter.3gpp", 913, new_create_dissector_handle(dissect_diameter_3gpp_mbms_required_qos, proto_diameter_3gpp));
153
154
155 }
156
157 void
158 proto_register_diameter_3gpp(void)
159 {                 
160
161 /* Setup list of header fields  See Section 1.6.1 for details*/
162         static hf_register_info hf[] = {
163                 { &hf_diameter_3gpp_msisdn,
164                         { "MSISDN",           "diameter.3gpp.msisdn",
165                         FT_BYTES, BASE_NONE, NULL, 0x0,          
166                         NULL, HFILL }
167                 },
168                 { &hf_diameter_3gpp_ipaddr,
169                         { "IPv4 Address",           "diameter.3gpp.ipaddr",
170                         FT_IPv4, BASE_NONE, NULL, 0x0,          
171                         NULL, HFILL }
172                 },
173                 { &hf_diameter_3gpp_mbms_required_qos_prio,
174                         { "Allocation/Retention Priority",           "diameter.3gpp.mbms_required_qos_prio",
175                         FT_UINT8, BASE_DEC, NULL, 0x0,          
176                         NULL, HFILL }
177                 },
178                 { &hf_diameter_3gpp_tmgi,
179                         { "TMGI",           "diameter.3gpp.tmgi",
180                         FT_BYTES, BASE_NONE, NULL, 0x0,          
181                         NULL, HFILL }
182                 },
183                 { &hf_diameter_mbms_service_id,
184                         { "MBMS Service ID",           "diameter.3gpp.mbms_service_id",
185                         FT_UINT24, BASE_HEX, NULL, 0x0,          
186                         NULL, HFILL }
187                 },
188         };
189
190         /* Setup protocol subtree array */
191         static gint *ett[] = {
192                 &diameter_3gpp_msisdn_ett,
193                 &diameter_3gpp_tmgi_ett,
194         };
195
196         /* Required function calls to register the header fields and subtrees used */
197         proto_diameter_3gpp = proto_register_protocol("Diameter 3GPP","Diameter3GPP", "diameter3gpp");
198         proto_register_field_array(proto_diameter_3gpp, hf, array_length(hf));
199         proto_register_subtree_array(ett, array_length(ett));
200 }