From Kovarththanan Rajaratnam via bug 3548:
[obnox/wireshark/wip.git] / epan / dissectors / packet-e212.c
1 /* packet-e212.c
2  * Routines for output and filtering of E.212 numbers common
3  * to many dissectors.
4  * Copyright 2006, Anders Broman <anders.broman@ericsson.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  *
26  * Ref COMPLEMENT TO ITU-T RECOMMENDATION E.212 (11/98)
27  *
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <glib.h>
35 #include <epan/packet.h>
36
37 #include "packet-e212.h"
38
39
40 const value_string E212_codes[] = {
41         {  202, "Greece" },
42         {  204, "Netherlands (Kingdom of the)" },
43         {  206, "Belgium" },
44         {  208, "France" },
45         {  212, "Monaco (Principality of)" },
46         {  213, "Andorra (Principality of)" },
47         {  214, "Spain" },
48         {  216, "Hungary (Republic of)" },
49         {  218, "Bosnia and Herzegovina" },
50         {  219, "Croatia (Republic of)" },
51         {  220, "Serbia and Montenegro" },
52         {  222, "Italy" },
53         {  225, "Vatican City State" },
54         {  226, "Romania" },
55         {  228, "Switzerland (Confederation of)" },
56         {  230, "Czech Republic" },
57         {  231, "Slovak Republic" },
58         {  232, "Austria" },
59         {  234, "United Kingdom of Great Britain and Northern Ireland" },
60         {  235, "United Kingdom of Great Britain and Northern Ireland" },
61         {  238, "Denmark" },
62         {  240, "Sweden" },
63         {  242, "Norway" },
64         {  244, "Finland" },
65         {  246, "Lithuania (Republic of)" },
66         {  247, "Latvia (Republic of)" },
67         {  248, "Estonia (Republic of)" },
68         {  250, "Russian Federation" },
69         {  255, "Ukraine" },
70         {  257, "Belarus (Republic of)" },
71         {  259, "Moldova (Republic of)" },
72         {  260, "Poland (Republic of)" },
73         {  262, "Germany (Federal Republic of)" },
74         {  266, "Gibraltar" },
75         {  268, "Portugal" },
76         {  270, "Luxembourg" },
77         {  272, "Ireland" },
78         {  274, "Iceland" },
79         {  276, "Albania (Republic of)" },
80         {  278, "Malta" },
81         {  280, "Cyprus (Republic of)" },
82         {  282, "Georgia" },
83         {  283, "Armenia (Republic of)" },
84         {  284, "Bulgaria (Republic of)" },
85         {  286, "Turkey" },
86         {  288, "Faroe Islands" },
87         {  290, "Greenland (Denmark)" },
88         {  292, "San Marino (Republic of)" },
89         {  293, "Slovenia (Republic of)" },
90         {  294, "The Former Yugoslav Republic of Macedonia" },
91         {  295, "Liechtenstein (Principality of)" },
92         {  302, "Canada" },
93         {  308, "Saint Pierre and Miquelon (Collectivite territoriale de la Republique francaise)" },
94         {  310, "United States of America" },
95         {  311, "United States of America" },
96         {  312, "United States of America" },
97         {  313, "United States of America" },
98         {  314, "United States of America" },
99         {  315, "United States of America" },
100         {  316, "United States of America" },
101         {  330, "Puerto Rico" },
102         {  332, "United States Virgin Islands" },
103         {  334, "Mexico" },
104         {  338, "Jamaica" },
105         {  340, "Martinique (French Department of)" },
106         {  340, "Guadeloupe (French Department of)" },
107         {  342, "Barbados" },
108         {  344, "Antigua and Barbuda" },
109         {  346, "Cayman Islands" },
110         {  348, "British Virgin Islands" },
111         {  350, "Bermuda" },
112         {  352, "Grenada" },
113         {  354, "Montserrat" },
114         {  356, "Saint Kitts and Nevis" },
115         {  358, "Saint Lucia" },
116         {  360, "Saint Vincent and the Grenadines" },
117         {  362, "Netherlands Antilles" },
118         {  363, "Aruba" },
119         {  364, "Bahamas (Commonwealth of the)" },
120         {  365, "Anguilla" },
121         {  366, "Dominica (Commonwealth of)" },
122         {  368, "Cuba" },
123         {  370, "Dominican Republic" },
124         {  372, "Haiti (Republic of)" },
125         {  374, "Trinidad and Tobago" },
126         {  376, "Turks and Caicos Islands" },
127         {  400, "Azerbaijani Republic" },
128         {  401, "Kazakhstan (Republic of)" },
129         {  402, "Bhutan (Kingdom of)" },
130         {  404, "India (Republic of)" },
131         {  410, "Pakistan (Islamic Republic of)" },
132         {  412, "Afghanistan" },
133         {  413, "Sri Lanka (Democratic Socialist Republic of)" },
134         {  414, "Myanmar (Union of)" },
135         {  415, "Lebanon" },
136         {  416, "Jordan (Hashemite Kingdom of)" },
137         {  417, "Syrian Arab Republic" },
138         {  418, "Iraq (Republic of)" },
139         {  419, "Kuwait (State of)" },
140         {  420, "Saudi Arabia (Kingdom of)" },
141         {  421, "Yemen (Republic of)" },
142         {  422, "Oman (Sultanate of)" },
143         {  424, "United Arab Emirates" },
144         {  425, "Israel (State of)" },
145         {  426, "Bahrain (Kingdom of)" },
146         {  427, "Qatar (State of)" },
147         {  428, "Mongolia" },
148         {  429, "Nepal" },
149         {  430, "United Arab Emirates (Abu Dhabi)" },
150         {  431, "United Arab Emirates (Dubai)" },
151         {  432, "Iran (Islamic Republic of)" },
152         {  434, "Uzbekistan (Republic of)" },
153         {  436, "Tajikistan (Republic of)" },
154         {  437, "Kyrgyz Republic" },
155         {  438, "Turkmenistan" },
156         {  440, "Japan" },
157         {  441, "Japan" },
158         {  450, "Korea (Republic of)" },
159         {  452, "Viet Nam (Socialist Republic of)" },
160         {  454, "Hongkong, China" },
161         {  455, "Macao, China" },
162         {  456, "Cambodia (Kingdom of)" },
163         {  457, "Lao People's Democratic Republic" },
164         {  460, "China (People's Republic of)" },
165         {  461, "China (People's Republic of)" },
166         {  466, "Taiwan, China" },
167         {  467, "Democratic People's Republic of Korea" },
168         {  470, "Bangladesh (People's Republic of)" },
169         {  472, "Maldives (Republic of)" },
170         {  502, "Malaysia" },
171         {  505, "Australia" },
172         {  510, "Indonesia (Republic of)" },
173         {  514, "Democratique Republic of Timor-Leste" },
174         {  515, "Philippines (Republic of the)" },
175         {  520, "Thailand" },
176         {  525, "Singapore (Republic of)" },
177         {  528, "Brunei Darussalam" },
178         {  530, "New Zealand" },
179         {  534, "Northern Mariana Islands (Commonwealth of the)" },
180         {  535, "Guam" },
181         {  536, "Nauru (Republic of)" },
182         {  537, "Papua New Guinea" },
183         {  539, "Tonga (Kingdom of)" },
184         {  540, "Solomon Islands" },
185         {  541, "Vanuatu (Republic of)" },
186         {  542, "Fiji (Republic of)" },
187         {  543, "Wallis and Futuna (Territoire francais d'outre-mer)" },
188         {  544, "American Samoa" },
189         {  545, "Kiribati (Republic of)" },
190         {  546, "New Caledonia (Territoire francais d'outre-mer)" },
191         {  547, "French Polynesia (Territoire francais d'outre-mer)" },
192         {  548, "Cook Islands" },
193         {  549, "Samoa (Independent State of)" },
194         {  550, "Micronesia (Federated States of)" },
195         {  551, "Marshall Islands (Republic of the)" },
196         {  552, "Palau (Republic of)" },
197         {  602, "Egypt (Arab Republic of)" },
198         {  603, "Algeria (People's Democratic Republic of)" },
199         {  604, "Morocco (Kingdom of)" },
200         {  605, "Tunisia" },
201         {  606, "Libya (Socialist People's Libyan Arab Jamahiriya)" },
202         {  607, "Gambia (Republic of the)" },
203         {  608, "Senegal (Republic of)" },
204         {  609, "Mauritania (Islamic Republic of)" },
205         {  610, "Mali (Republic of)" },
206         {  611, "Guinea (Republic of)" },
207         {  612, "Cote d'Ivoire (Republic of)" },
208         {  613, "Burkina Faso" },
209         {  614, "Niger (Republic of the)" },
210         {  615, "Togolese Republic" },
211         {  616, "Benin (Republic of)" },
212         {  617, "Mauritius (Republic of)" },
213         {  618, "Liberia (Republic of)" },
214         {  619, "Sierra Leone" },
215         {  620, "Ghana" },
216         {  621, "Nigeria (Federal Republic of)" },
217         {  622, "Chad (Republic of)" },
218         {  623, "Central African Republic" },
219         {  624, "Cameroon (Republic of)" },
220         {  625, "Cape Verde (Republic of)" },
221         {  626, "Sao Tome and Principe (Democratic Republic of)" },
222         {  627, "Equatorial Guinea (Republic of)" },
223         {  628, "Gabonese Republic" },
224         {  629, "Congo (Republic of the)" },
225         {  630, "Democratic Republic of the Congo" },
226         {  631, "Angola (Republic of)" },
227         {  632, "Guinea-Bissau (Republic of)" },
228         {  633, "Seychelles (Republic of)" },
229         {  634, "Sudan (Republic of the)" },
230         {  635, "Rwandese Republic" },
231         {  636, "Ethiopia (Federal Democratic Republic of)" },
232         {  637, "Somali Democratic Republic" },
233         {  638, "Djibouti (Republic of)" },
234         {  639, "Kenya (Republic of)" },
235         {  640, "Tanzania (United Republic of)" },
236         {  641, "Uganda (Republic of)" },
237         {  642, "Burundi (Republic of)" },
238         {  643, "Mozambique (Republic of)" },
239         {  645, "Zambia (Republic of)" },
240         {  646, "Madagascar (Republic of)" },
241         {  647, "Reunion (French Department of)" },
242         {  648, "Zimbabwe (Republic of)" },
243         {  649, "Namibia (Republic of)" },
244         {  650, "Malawi" },
245         {  651, "Lesotho (Kingdom of)" },
246         {  652, "Botswana (Republic of)" },
247         {  653, "Swaziland (Kingdom of)" },
248         {  654, "Comoros (Union of the)" },
249         {  655, "South Africa (Republic of)" },
250         {  657, "Eritrea" },
251         {  702, "Belize" },
252         {  704, "Guatemala (Republic of)" },
253         {  706, "El Salvador (Republic of)" },
254         {  708, "Honduras (Republic of)" },
255         {  710, "Nicaragua" },
256         {  712, "Costa Rica" },
257         {  714, "Panama (Republic of)" },
258         {  716, "Peru" },
259         {  722, "Argentine Republic" },
260         {  724, "Brazil (Federative Republic of)" },
261         {  730, "Chile" },
262         {  732, "Colombia (Republic of)" },
263         {  734, "Venezuela (Bolivarian Republic of)" },
264         {  736, "Bolivia (Republic of)" },
265         {  738, "Guyana" },
266         {  740, "Ecuador" },
267         {  742, "French Guiana (French Department of)" },
268         {  744, "Paraguay (Republic of)" },
269         {  746, "Suriname (Republic of)" },
270         {  748, "Uruguay (Eastern Republic of)" },
271         {  901, "International Mobile, shared code" },
272         { 0, NULL }
273 };
274
275 static int proto_e212                                           = -1;
276 static int hf_E212_mcc                                          = -1;
277 static int hf_E212_mnc                                          = -1;
278 static int hf_E212_msin                                         = -1;
279
280 /*
281  *      8   7   6   5   4   3   2   1
282  *      MCC digit 2     MCC digit 1    octet x
283  *      MNC digit 3     MCC digit 3    octet x+1
284  *      MNC digit 2     MNC digit 1    octet x+2
285  */
286
287
288 int
289 dissect_e212_mcc_mnc(tvbuff_t *tvb, proto_tree *tree, int offset){
290
291         int                     start_offset;   
292         guint8          octet;
293         guint16         mcc, mnc;
294         guint8          mcc1, mcc2, mcc3, mnc1, mnc2, mnc3;
295
296         start_offset = offset;
297         /* Mobile country code MCC */
298         octet = tvb_get_guint8(tvb,offset);
299         mcc1 = octet & 0x0f;
300         mcc2 = octet >> 4;
301         offset++;
302         octet = tvb_get_guint8(tvb,offset);
303         mcc3 = octet & 0x0f;
304         /* MNC, Mobile network code (octet 3 bits 5 to 8, octet 4)  */
305         mnc3 = octet >> 4;
306         offset++;
307         octet = tvb_get_guint8(tvb,offset);
308         mnc1 = octet & 0x0f;
309         mnc2 = octet >> 4;
310
311         mcc = 100 * mcc1 + 10 * mcc2 + mcc3;
312         mnc = 10 * mnc1 + mnc2;
313         if (mnc3 != 0xf) {
314                 mnc = 10 * mnc + mnc3;
315         }
316         proto_tree_add_uint(tree, hf_E212_mcc , tvb, start_offset, 2, mcc );
317         proto_tree_add_uint(tree, hf_E212_mnc , tvb, start_offset + 1, 2, mnc );
318         offset++;
319         return offset;
320 }
321
322 /*
323  * Register the protocol with Wireshark.
324  *
325  * This format is required because a script is used to build the C function
326  * that calls all the protocol registration.
327  */
328
329
330 void
331 proto_register_e212(void)
332 {
333
334 /* Setup list of header fields  See Section 1.6.1 for details */
335         static hf_register_info hf[] = {
336         { &hf_E212_mcc,
337                 { "Mobile Country Code (MCC)","e212.mcc",
338                 FT_UINT16, BASE_DEC, VALS(E212_codes), 0x0,          
339                 "Mobile Country Code MCC", HFILL }
340         },
341         { &hf_E212_mnc,
342                 { "Mobile network code (MNC)","e212.mnc",
343                 FT_UINT16, BASE_DEC, NULL, 0x0,          
344                 "Mobile network code", HFILL }
345         },
346         { &hf_E212_msin,
347       { "Mobile Subscriber Identification Number (MSIN)", "e212.msin",
348         FT_STRING, BASE_NONE, NULL, 0,
349         "Mobile Subscriber Identification Number(MSIN)", HFILL }},
350         };
351
352         /*
353          * Register the protocol name and description
354          */
355         proto_e212 = proto_register_protocol(
356                         "ITU-T E.212 number",
357                         "E.212",
358                         "e212");
359
360         /*
361          * Required function calls to register
362          * the header fields and subtrees used.
363          */
364         proto_register_field_array(proto_e212, hf, array_length(hf));
365
366 }