Don't guard col_set_str (COL_PROTOCOL) with col_check
[obnox/wireshark/wip.git] / epan / dissectors / packet-ucp.c
1 /* packet-ucp.c
2  * Routines for Universal Computer Protocol dissection
3  * Copyright 2001, Tom Uijldert <tom.uijldert@cmg.nl>
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  * Dissector of a UCP (Universal Computer Protocol) PDU, as defined for the
27  * ERMES paging system in ETS 300 133-3 (2nd final draft, September 1997,
28  * www.etsi.org).
29  * Includes the extension of EMI-UCP interface (V4.0, May 2001, www.cmgwds.com)
30  *
31  * Support for statistics using the Stats Tree API added by
32  * Abhik Sarkar <sarkar.abhik@gmail.com>
33  *
34  */
35
36 #ifdef HAVE_CONFIG_H
37 # include "config.h"
38 #endif
39
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <ctype.h>
44 #include <time.h>
45
46 #include <glib.h>
47
48 #include <epan/packet.h>
49 #include <epan/prefs.h>
50 #include <epan/emem.h>
51 #include <epan/stats_tree.h>
52
53 #include "packet-tcp.h"
54
55 /* Prototypes   */
56 static void dissect_ucp_common(tvbuff_t *, packet_info *, proto_tree *);
57
58 /* Tap Record */
59 typedef struct _ucp_tap_rec_t {
60     guint message_type; /* 0 = Operation; 1 = Result */
61     guint operation;    /* Operation Type */
62     guint result;       /* 0 = Success; Non 0 = Error Code */
63 } ucp_tap_rec_t;
64
65 /* Preferences */
66 gboolean ucp_desegment = TRUE;
67 /* STX + TRN 2 num. char.+ LEN 5 num. char. + O/R Char 'O' or 'R' + OT 2 num. char. */
68 #define UCP_HEADER_SIZE 11
69
70 /*
71  * Convert ASCII-hex character to binary equivalent. No checks, assume
72  * is valid hex character.
73  */
74 #define AHex2Bin(n)     (((n) & 0x40) ? ((n) & 0x0F) + 9 : ((n) & 0x0F))
75
76 #define UCP_STX         0x02                    /* Start of UCP PDU     */
77 #define UCP_ETX         0x03                    /* End of UCP PDU       */
78
79 #define UCP_MALFORMED   -1                      /* Not a valid PDU      */
80 #define UCP_SHORTENED   -2                      /* May be valid but short */
81 #define UCP_INV_CHK     -3                      /* Checksum doesn't add up */
82
83 #define UCP_O_R_OFFSET 10                       /* Location of O/R field*/
84 #define UCP_OT_OFFSET  12                       /* Location of OT field */
85
86 #define UCP_TRN_LEN     2                       /* Length of TRN-field  */
87 #define UCP_LEN_LEN     5                       /* Length of LEN-field  */
88 #define UCP_O_R_LEN     1                       /* Length of O/R-field  */
89 #define UCP_OT_LEN      2                       /* Length of OT-field   */
90
91 /*
92  * Initialize the protocol and registered fields
93  *
94  * Header (fixed) section
95  */
96 static int proto_ucp = -1;
97
98 static int hf_ucp_hdr_TRN       = -1;
99 static int hf_ucp_hdr_LEN       = -1;
100 static int hf_ucp_hdr_O_R       = -1;
101 static int hf_ucp_hdr_OT        = -1;
102
103 /*
104  * Stats section
105  */
106 static int st_ucp_messages      = -1;
107 static int st_ucp_ops           = -1;
108 static int st_ucp_res           = -1;
109 static int st_ucp_results       = -1;
110 static int st_ucp_results_pos   = -1;
111 static int st_ucp_results_neg   = -1;
112
113 static gchar* st_str_ucp        = "UCP Messages";
114 static gchar* st_str_ops        = "Operations";
115 static gchar* st_str_res        = "Results";
116 static gchar* st_str_ucp_res    = "UCP Results Acks/Nacks";
117 static gchar* st_str_pos        = "Positive";
118 static gchar* st_str_neg        = "Negative";
119
120 /*
121  * Data (variable) section
122  */
123 static int hf_ucp_oper_section  = -1;
124 static int hf_ucp_parm_AdC      = -1;
125 static int hf_ucp_parm_OAdC     = -1;
126 static int hf_ucp_parm_DAdC     = -1;
127 static int hf_ucp_parm_AC       = -1;
128 static int hf_ucp_parm_OAC      = -1;
129 static int hf_ucp_parm_BAS      = -1;
130 static int hf_ucp_parm_LAR      = -1;
131 static int hf_ucp_parm_LAC      = -1;
132 static int hf_ucp_parm_L1R      = -1;
133 static int hf_ucp_parm_L1P      = -1;
134 static int hf_ucp_parm_L3R      = -1;
135 static int hf_ucp_parm_L3P      = -1;
136 static int hf_ucp_parm_LCR      = -1;
137 static int hf_ucp_parm_LUR      = -1;
138 static int hf_ucp_parm_LRR      = -1;
139 static int hf_ucp_parm_RT       = -1;
140 static int hf_ucp_parm_NoN      = -1;
141 static int hf_ucp_parm_NoA      = -1;
142 static int hf_ucp_parm_NoB      = -1;
143 static int hf_ucp_parm_NAC      = -1;
144 static int hf_ucp_parm_PNC      = -1;
145 static int hf_ucp_parm_AMsg     = -1;
146 static int hf_ucp_parm_LNo      = -1;
147 static int hf_ucp_parm_LST      = -1;
148 static int hf_ucp_parm_TNo      = -1;
149 static int hf_ucp_parm_CS       = -1;
150 static int hf_ucp_parm_PID      = -1;
151 static int hf_ucp_parm_NPL      = -1;
152 static int hf_ucp_parm_GA       = -1;
153 static int hf_ucp_parm_RP       = -1;
154 static int hf_ucp_parm_LRP      = -1;
155 static int hf_ucp_parm_PR       = -1;
156 static int hf_ucp_parm_LPR      = -1;
157 static int hf_ucp_parm_UM       = -1;
158 static int hf_ucp_parm_LUM      = -1;
159 static int hf_ucp_parm_RC       = -1;
160 static int hf_ucp_parm_LRC      = -1;
161 static int hf_ucp_parm_NRq      = -1;
162 static int hf_ucp_parm_GAdC     = -1;
163 static int hf_ucp_parm_A_D      = -1;
164 static int hf_ucp_parm_CT       = -1;
165 static int hf_ucp_parm_AAC      = -1;
166 static int hf_ucp_parm_MNo      = -1;
167 static int hf_ucp_parm_R_T      = -1;
168 static int hf_ucp_parm_IVR5x    = -1;
169 static int hf_ucp_parm_REQ_OT   = -1;
170 static int hf_ucp_parm_SSTAT    = -1;
171 static int hf_ucp_parm_LMN      = -1;
172 static int hf_ucp_parm_NMESS    = -1;
173 static int hf_ucp_parm_NMESS_str= -1;
174 static int hf_ucp_parm_NAdC     = -1;
175 static int hf_ucp_parm_NT       = -1;
176 static int hf_ucp_parm_NPID     = -1;
177 static int hf_ucp_parm_LRq      = -1;
178 static int hf_ucp_parm_LRAd     = -1;
179 static int hf_ucp_parm_LPID     = -1;
180 static int hf_ucp_parm_DD       = -1;
181 static int hf_ucp_parm_DDT      = -1;
182 static int hf_ucp_parm_STx      = -1;
183 static int hf_ucp_parm_ST       = -1;
184 static int hf_ucp_parm_SP       = -1;
185 static int hf_ucp_parm_VP       = -1;
186 static int hf_ucp_parm_RPID     = -1;
187 static int hf_ucp_parm_SCTS     = -1;
188 static int hf_ucp_parm_Dst      = -1;
189 static int hf_ucp_parm_Rsn      = -1;
190 static int hf_ucp_parm_DSCTS    = -1;
191 static int hf_ucp_parm_MT       = -1;
192 static int hf_ucp_parm_NB       = -1;
193 static int hf_ucp_data_section  = -1;
194 static int hf_ucp_parm_MMS      = -1;
195 static int hf_ucp_parm_DCs      = -1;
196 static int hf_ucp_parm_MCLs     = -1;
197 static int hf_ucp_parm_RPI      = -1;
198 static int hf_ucp_parm_CPg      = -1;
199 static int hf_ucp_parm_RPLy     = -1;
200 static int hf_ucp_parm_OTOA     = -1;
201 static int hf_ucp_parm_HPLMN    = -1;
202 static int hf_ucp_parm_RES4     = -1;
203 static int hf_ucp_parm_RES5     = -1;
204 static int hf_ucp_parm_OTON     = -1;
205 static int hf_ucp_parm_ONPI     = -1;
206 static int hf_ucp_parm_STYP0    = -1;
207 static int hf_ucp_parm_STYP1    = -1;
208 static int hf_ucp_parm_ACK      = -1;
209 static int hf_ucp_parm_PWD      = -1;
210 static int hf_ucp_parm_NPWD     = -1;
211 static int hf_ucp_parm_VERS     = -1;
212 static int hf_ucp_parm_LAdC     = -1;
213 static int hf_ucp_parm_LTON     = -1;
214 static int hf_ucp_parm_LNPI     = -1;
215 static int hf_ucp_parm_OPID     = -1;
216 static int hf_ucp_parm_RES1     = -1;
217 static int hf_ucp_parm_RES2     = -1;
218 static int hf_ucp_parm_MVP      = -1;
219 static int hf_ucp_parm_EC       = -1;
220 static int hf_ucp_parm_SM       = -1;
221
222 static int hf_ucp_parm_XSer     = -1;
223 static int hf_xser_service      = -1;
224
225 /* Initialize the subtree pointers */
226 static gint ett_ucp  = -1;
227 static gint ett_sub  = -1;
228 static gint ett_XSer = -1;
229
230 /* Tap */
231 static int ucp_tap              = -1;
232
233 /*
234  * Value-arrays for certain field-contents
235  */
236 static const value_string vals_hdr_O_R[] = {
237     {  'O', "Operation" },
238     {  'R', "Result" },
239     {  0, NULL }
240 };
241
242 static const value_string vals_hdr_OT[] = {     /* Operation type       */
243     {  0, "Enquiry" },
244     {  1, "Call input" },
245     {  2, "Call input (multiple address)" },
246     {  3, "Call input (supplementary services included)" },
247     {  4, "Address list information" },
248     {  5, "Change address list" },
249     {  6, "Advice of accumulated charges" },
250     {  7, "Password management" },
251     {  8, "Legitimisation code management" },
252     {  9, "Standard text information" },
253     { 10, "Change standard text" },
254     { 11, "Request roaming information" },
255     { 12, "Change roaming information" },
256     { 13, "Roaming reset" },
257     { 14, "Message retrieval" },
258     { 15, "Request call barring" },
259     { 16, "Cancel call barring" },
260     { 17, "Request call diversion" },
261     { 18, "Cancel call diversion" },
262     { 19, "Request deferred delivery" },
263     { 20, "Cancel deferred delivery" },
264     { 21, "All features reset" },
265     { 22, "Call input (with specific character set)" },
266     { 23, "UCP version status request" },
267     { 24, "Mobile subscriber feature status request" },
268     { 30, "SMS message transfer" },
269     { 31, "SMT alert" },
270     { 32, "(proprietary)" },
271     { 34, "(proprietary)" },
272     { 36, "(proprietary)" },
273     { 38, "(proprietary)" },
274     { 40, "(proprietary)" },
275     { 41, "(proprietary)" },
276     { 42, "(proprietary)" },
277     { 43, "(proprietary)" },
278     { 44, "(proprietary)" },
279     { 45, "(proprietary)" },
280     { 51, "Submit short message" },
281     { 52, "Deliver short message" },
282     { 53, "Deliver notification" },
283     { 54, "Modify message" },
284     { 55, "Inquiry message" },
285     { 56, "Delete message" },
286     { 57, "Inquiry response message" },
287     { 58, "Delete response message" },
288     { 60, "Session management" },
289     { 61, "List management" },
290     { 95, "(proprietary)" },
291     { 96, "(proprietary)" },
292     { 97, "(proprietary)" },
293     { 98, "(proprietary)" },
294     { 99, "(proprietary)" },
295     {  0, NULL }
296 };
297
298 static const value_string vals_parm_EC[] = {    /* Error code   */
299     {  1, "Checksum error" },
300     {  2, "Syntax error" },
301     {  3, "Operation not supported by system" },
302     {  4, "Operation not allowed" },
303     {  5, "Call barring active" },
304     {  6, "AdC invalid" },
305     {  7, "Authentication failure" },
306     {  8, "Legitimisation code for all calls, failure" },
307     {  9, "GA not valid" },
308     { 10, "Repetition not allowed" },
309     { 11, "Legitimisation code for repetition, failure" },
310     { 12, "Priority call not allowed" },
311     { 13, "Legitimisation code for priority call, failure" },
312     { 14, "Urgent message not allowed" },
313     { 15, "Legitimisation code for urgent message, failure" },
314     { 16, "Reverse charging not allowed" },
315     { 17, "Legitimisation code for rev. charging, failure" },
316     { 18, "Deferred delivery not allowed" },
317     { 19, "New AC not valid" },
318     { 20, "New legitimisation code not valid" },
319     { 21, "Standard text not valid" },
320     { 22, "Time period not valid" },
321     { 23, "Message type not supported by system" },
322     { 24, "Message too long" },
323     { 25, "Requested standard text not valid" },
324     { 26, "Message type not valid for the pager type" },
325     { 27, "Message not found in SMSC" },
326     { 28, "Invalid character set" },
327     { 30, "Subscriber hang-up" },
328     { 31, "Fax group not supported" },
329     { 32, "Fax message type not supported" },
330     { 33, "Address already in list (60-series)" },
331     { 34, "Address not in list (60-series)" },
332     { 35, "List full, cannot add address to list (60-series)" },
333     { 36, "RPID already in use" },
334     { 37, "Delivery in progress" },
335     { 38, "Message forwarded" },
336     { 50, "Low network status" },
337     { 51, "Legitimisation code for standard text, failure" },
338     { 53, "Operation partially successful" },
339     { 54, "Operation not successful" },
340     { 55, "System error" },
341     { 57, "AdC already a member of GAdC address list" },
342     { 58, "AdC not a member of GAdC address list" },
343     { 59, "Requested standard text list invalid" },
344     { 61, "Not controller of GAdC address list" },
345     { 62, "Standard text too large" },
346     { 63, "Not owner of standard text list" },
347     { 64, "Address list full" },
348     { 65, "GAdC invalid" },
349     { 66, "Operation restricted to mobile subscribers" },
350     { 68, "Invalid AdC type" },
351     { 69, "Cannot add AdC to GAdC address list" },
352     { 90, "(proprietary error code)" },
353     { 91, "(proprietary error code)" },
354     { 92, "(proprietary error code)" },
355     { 93, "(proprietary error code)" },
356     { 94, "(proprietary error code)" },
357     { 95, "(proprietary error code)" },
358     { 96, "(proprietary error code)" },
359     { 97, "(proprietary error code)" },
360     { 98, "(proprietary error code)" },
361     { 99, "(proprietary error code)" },
362     {  0, NULL },
363 };
364
365 static const value_string vals_parm_NRq[] = {
366     {  '0', "NAdC not used" },
367     {  '1', "NAdC used" },
368     {  0, NULL },
369 };
370
371 static const value_string vals_parm_NT[] = {
372     {  '0', "Default value" },
373     {  '1', "Delivery notification" },
374     {  '2', "Non-delivery notification" },
375     {  '3', "Delivery and Non-delivery notification" },
376     {  '4', "Buffered message notification" },
377     {  '5', "Buffered and Delivery notification" },
378     {  '6', "Buffered and Non-delivery notification" },
379     {  '7', "All notifications" },
380     {  0, NULL },
381 };
382
383 static const value_string vals_parm_PID[] = {
384     {  100, "Mobile station" },
385     {  122, "Fax Group 3" },
386     {  131, "X.400" },
387     {  138, "Menu over PSTN" },
388     {  139, "PC appl. over PSTN (E.164)" },
389     {  339, "PC appl. over X.25 (X.121)" },
390     {  439, "PC appl. over ISDN (E.164)" },
391     {  539, "PC appl. over TCP/IP" },
392     {  0, NULL },
393 };
394
395 static const value_string vals_parm_LRq[] = {
396     {  '0', "LRAd not used" },
397     {  '1', "LRAd used" },
398     {  0, NULL },
399 };
400
401 static const value_string vals_parm_DD[] = {
402     {  '0', "DDT not used" },
403     {  '1', "DDT used" },
404     {  0, NULL },
405 };
406
407 static const value_string vals_parm_Dst[] = {
408     {  '0', "delivered" },
409     {  '1', "buffered (see Rsn)" },
410     {  '2', "not delivered (see Rsn)" },
411     {  0, NULL },
412 };
413
414 static const value_string vals_parm_Rsn[] = {
415     {    0, "Unknown subscriber" },
416     {    1, "Service temporary not available" },
417     {    2, "Service temporary not available" },
418     {    3, "Service temporary not available" },
419     {    4, "Service temporary not available" },
420     {    5, "Service temporary not available" },
421     {    6, "Service temporary not available" },
422     {    7, "Service temporary not available" },
423     {    8, "Service temporary not available" },
424     {    9, "Illegal error code" },
425     {   10, "Network time-out" },
426     {  100, "Facility not supported" },
427     {  101, "Unknown subscriber" },
428     {  102, "Facility not provided" },
429     {  103, "Call barred" },
430     {  104, "Operation barred" },
431     {  105, "SC congestion" },
432     {  106, "Facility not supported" },
433     {  107, "Absent subscriber" },
434     {  108, "Delivery fail" },
435     {  109, "Sc congestion" },
436     {  110, "Protocol error" },
437     {  111, "MS not equipped" },
438     {  112, "Unknown SC" },
439     {  113, "SC congestion" },
440     {  114, "Illegal MS" },
441     {  115, "MS nota subscriber" },
442     {  116, "Error in MS" },
443     {  117, "SMS lower layer not provisioned" },
444     {  118, "System fail" },
445     {  119, "PLMN system failure" },
446     {  120, "HLR system failure" },
447     {  121, "VLR system failure" },
448     {  122, "Previous VLR system failure" },
449     {  123, "Controlling MSC system failure" },
450     {  124, "VMSC system failure" },
451     {  125, "EIR system failure" },
452     {  126, "System failure" },
453     {  127, "Unexpected data value" },
454     {  200, "Error in address service centre" },
455     {  201, "Invalid absolute validity period" },
456     {  202, "Short message exceeds maximum" },
457     {  203, "Unable to unpack GSM message" },
458     {  204, "Unable to convert to IRA alphabet" },
459     {  205, "Invalid validity period format" },
460     {  206, "Invalid destination address" },
461     {  207, "Duplicate message submit" },
462     {  208, "Invalid message type indicator" },
463     {  0, NULL },
464 };
465
466 static const value_string vals_parm_MT[] = {
467     {  '2', "Numeric message" },
468     {  '3', "Alphanumeric message" },
469     {  '4', "Transparent data" },
470     {  0, NULL },
471 };
472
473 static const value_string vals_parm_DCs[] = {
474     {  '0', "default alphabet" },
475     {  '1', "User defined data (8 bit)" },
476     {  0, NULL },
477 };
478
479 static const value_string vals_parm_MCLs[] = {
480     {  '0', "message class 0" },
481     {  '1', "message class 1" },
482     {  '2', "message class 2" },
483     {  '3', "message class 3" },
484     {  0, NULL },
485 };
486
487 static const value_string vals_parm_RPI[] = {
488     {  '1', "Request" },
489     {  '2', "Response" },
490     {  0, NULL },
491 };
492
493 static const value_string vals_parm_ACK[] = {
494     {  'A', "Ack" },
495     {  'N', "Nack" },
496     {  0, NULL },
497 };
498
499 static const value_string vals_parm_RP[] = {
500     {  '1', "Repetition requested" },
501     {  0, NULL },
502 };
503
504 static const value_string vals_parm_UM[] = {
505     {  '1', "Urgent message" },
506     {  0, NULL },
507 };
508
509 static const value_string vals_parm_RC[] = {
510     {  '1', "Reverse charging request" },
511     {  0, NULL },
512 };
513
514 static const value_string vals_parm_OTON[] = {
515     {  '1', "International number" },
516     {  '2', "National number" },
517     {  '6', "Abbreviated number (short number alias)" },
518     {  0, NULL },
519 };
520
521 static const value_string vals_parm_ONPI[] = {
522     {  '1', "E.164 address" },
523     {  '3', "X.121 address" },
524     {  '5', "Private -TCP/IP or abbreviated number- address" },
525     {  0, NULL },
526 };
527
528 static const value_string vals_parm_STYP0[] = {
529     {  '1', "open session" },
530     {  '2', "reserved" },
531     {  '3', "change password" },
532     {  '4', "open provisioning session" },
533     {  '5', "reserved" },
534     {  '6', "change provisioning password" },
535     {  0, NULL },
536 };
537
538 static const value_string vals_parm_STYP1[] = {
539     {  '1', "add item to mo-list" },
540     {  '2', "remove item from mo-list" },
541     {  '3', "verify item mo-list" },
542     {  '4', "add item to mt-list" },
543     {  '5', "remove item from mt-list" },
544     {  '6', "verify item mt-list" },
545     {  0, NULL },
546 };
547
548 static const value_string vals_parm_OPID[] = {
549     {  0, "Mobile station" },
550     {  39, "PC application" },
551     {  0, NULL },
552 };
553
554 static const value_string vals_parm_BAS[] = {
555     {  '1', "Barred" },
556     {  0, NULL },
557 };
558
559 static const value_string vals_parm_LAR[] = {
560     {  '1', "Leg. code for all calls requested" },
561     {  0, NULL },
562 };
563
564 static const value_string vals_parm_L1R[] = {
565     {  '1', "Leg. code for priority 1 requested" },
566     {  0, NULL },
567 };
568
569 static const value_string vals_parm_L3R[] = {
570     {  '1', "Leg. code for priority 3 requested" },
571     {  0, NULL },
572 };
573
574 static const value_string vals_parm_LCR[] = {
575     {  '1', "Leg. code for reverse charging requested" },
576     {  0, NULL },
577 };
578
579 static const value_string vals_parm_LUR[] = {
580     {  '1', "Leg. code for urgent message requested" },
581     {  0, NULL },
582 };
583
584 static const value_string vals_parm_LRR[] = {
585     {  '1', "Leg. code for repetition requested" },
586     {  0, NULL },
587 };
588
589 static const value_string vals_parm_RT[] = {
590     {  '1', "Tone only" },
591     {  '2', "Numeric" },
592     {  '3', "Alphanumeric" },
593     {  '4', "Transparent data" },
594     {  0, NULL },
595 };
596
597 static const value_string vals_parm_PNC[] = {
598     {  'H', "Home PNC" },
599     {  'I', "Input PNC" },
600     {  0, NULL },
601 };
602
603 static const value_string vals_parm_A_D[] = {
604     {  'A', "Add" },
605     {  'D', "Delete" },
606     {  0, NULL },
607 };
608
609 static const value_string vals_parm_R_T[] = {
610     {  'R', "Retrieval Ok" },
611     {  'T', "Retransmit on radio channel" },
612     {  0, NULL },
613 };
614
615 static const value_string vals_parm_REQ_OT[] = {
616     {  'S', "Send used operation types" },
617     {  'N', "Don't send used operation types" },
618     {  0, NULL },
619 };
620
621 static const value_string vals_parm_SSTAT[] = {
622     {  '0', "All services" },
623     {  '1', "All in the moment active services" },
624     {  '2', "Call diversion" },
625     {  '3', "Roaming information status" },
626     {  '4', "Call barring status" },
627     {  '5', "Deferred delivery status" },
628     {  '6', "Number of stored messages" },
629     {  0, NULL },
630 };
631
632 static const value_string vals_xser_service[] = {
633     {  1, "GSM UDH information" },
634     {  2, "GSM DCS information" },
635     {  3, "[Message Type]            TDMA information exchange" },
636     {  4, "[Message Reference]       TDMA information exchange" },
637     {  5, "[Privacy Indicator]       TDMA information exchange" },
638     {  6, "[Urgency Indicator]       TDMA information exchange" },
639     {  7, "[Acknowledgement Request] TDMA information exchange" },
640     {  8, "[Message Updating]        TDMA information exchange" },
641     {  9, "[Call Back Number]        TDMA information exchange" },
642     { 10, "[Response Code]           TDMA information exchange" },
643     { 11, "[Teleservice ID]          TDMA information exchange" },
644     { 12, "Billing identifier" },
645     { 13, "Single shot indicator" },
646     {  0, NULL },
647 };
648
649 /* For statistics */
650 static void
651 ucp_stats_tree_init(stats_tree* st)
652 {
653     st_ucp_messages = stats_tree_create_node(st, st_str_ucp, 0, TRUE);
654     st_ucp_ops = stats_tree_create_node(st, st_str_ops, st_ucp_messages, TRUE);
655     st_ucp_res = stats_tree_create_node(st, st_str_res, st_ucp_messages, TRUE);
656     st_ucp_results = stats_tree_create_node(st, st_str_ucp_res, 0, TRUE);
657     st_ucp_results_pos = stats_tree_create_node(st, st_str_pos, st_ucp_results, TRUE);
658     st_ucp_results_neg = stats_tree_create_node(st, st_str_neg, st_ucp_results, TRUE);
659 }
660
661 static int
662 ucp_stats_tree_per_packet(stats_tree *st, /* st as it was passed to us */
663                                       packet_info *pinfo _U_,
664                                       epan_dissect_t *edt _U_,
665                                       const void *p) /* Used for getting UCP stats */
666 {
667     ucp_tap_rec_t* tap_rec = (ucp_tap_rec_t*)p;
668
669     tick_stat_node(st, st_str_ucp, 0, TRUE);
670
671     if (tap_rec->message_type == 0) /* Operation */
672     {
673         tick_stat_node(st, st_str_ops, st_ucp_messages, TRUE);
674         tick_stat_node(st, val_to_str(tap_rec->operation, vals_hdr_OT,
675                        "Unknown OT: %d"), st_ucp_ops, FALSE);
676     }
677     else /* Result */
678     {
679         tick_stat_node(st, st_str_res, st_ucp_messages, TRUE);
680         tick_stat_node(st, val_to_str(tap_rec->operation, vals_hdr_OT,
681                        "Unknown OT: %d"), st_ucp_res, FALSE);
682
683         tick_stat_node(st, st_str_ucp_res, 0, TRUE);
684
685         if (tap_rec->result == 0) /* Positive Result */
686         {
687             tick_stat_node(st, st_str_pos, st_ucp_results, FALSE);
688         }
689         else /* Negative Result */
690         {
691             tick_stat_node(st, st_str_neg, st_ucp_results, TRUE);
692             tick_stat_node(st, val_to_str(tap_rec->result, vals_parm_EC,
693                            "Unknown EC: %d"), st_ucp_results_neg, FALSE);
694         }
695     }
696
697     return 1;
698 }
699
700 /*!
701  * Checks whether the PDU looks a bit like UCP and checks the checksum
702  *
703  * \param       tvb     The buffer with PDU-data
704  * \param       endpkt  Returns pointer, indicating the end of the PDU
705  *
706  * \return              The state of this PDU
707  * \retval      0               Definitely UCP
708  * \retval      UCP_SHORTENED   Packet may be there, but not complete
709  * \retval      UCP_MALFORMED   Hmmmm, not UCP after all...
710  * \retval      UCP_INV_CHK     Nice packet, but checksum doesn't add up...
711  */
712 static int
713 check_ucp(tvbuff_t *tvb, int *endpkt)
714 {
715     guint        offset = 1;
716     guint        checksum = 0;
717     int          pkt_check, tmp;
718     int          length;
719
720     length = tvb_find_guint8(tvb, offset, -1, UCP_ETX);
721     if (length == -1) {
722         *endpkt = tvb_reported_length_remaining(tvb, offset);
723         return UCP_SHORTENED;
724     }
725     if (length > (int) tvb_reported_length(tvb)) {
726         /* XXX - "cannot happen" */
727         *endpkt = 0;
728         return UCP_MALFORMED;
729     }
730     for (; offset < (guint) (length - 2); offset++)
731         checksum += tvb_get_guint8(tvb, offset);
732     checksum &= 0xFF;
733     tmp = tvb_get_guint8(tvb, offset++);
734     pkt_check = AHex2Bin(tmp);
735     tmp = tvb_get_guint8(tvb, offset++);
736     pkt_check = 16 * pkt_check + AHex2Bin(tmp);
737     *endpkt = offset + 1;
738     if (checksum == (guint) pkt_check)
739         return 0;
740     else
741         return UCP_INV_CHK;
742 }
743
744 /*!
745  * UCP equivalent of mktime() (3). Convert date to standard 'time_t' format
746  *
747  * \param       datestr The UCP-formatted date to convert
748  *
749  * \return              The date in standard 'time_t' format.
750  */
751 static time_t
752 ucp_mktime(char *datestr)
753 {
754     struct tm    r_time;
755
756     r_time.tm_mday = 10 * (datestr[0] - '0') + (datestr[1] - '0');
757     r_time.tm_mon  = (10 * (datestr[2] - '0') + (datestr[3] - '0')) - 1;
758     r_time.tm_year = 10 * (datestr[4] - '0') + (datestr[5] - '0');
759     if (r_time.tm_year < 90)
760         r_time.tm_year += 100;
761     r_time.tm_hour = 10 * (datestr[6] - '0') + (datestr[7] - '0');
762     r_time.tm_min  = 10 * (datestr[8] - '0') + (datestr[9] - '0');
763     if (datestr[10])
764         r_time.tm_sec  = 10 * (datestr[10] - '0') + (datestr[11] - '0');
765     else
766         r_time.tm_sec  = 0;
767     r_time.tm_isdst = -1;
768     return mktime(&r_time);
769 }
770
771 /*!
772  * Scanning routines to add standard types (byte, int, string, data)
773  * to the protocol-tree. Each field is seperated with a slash ('/').
774  *
775  * \param       tree    The protocol tree to add to
776  * \param       tvb     Buffer containing the data
777  * \param       field   The actual field, whose value needs displaying
778  * \param       offset  Location of field within the buffer, returns location
779  *                      of next field.
780  *
781  * \return              For 'int'-types, the value of the field.
782  */
783 static void
784 ucp_handle_string(proto_tree *tree, tvbuff_t *tvb, int field, int *offset)
785 {
786     gint         idx, len;
787
788     idx = tvb_find_guint8(tvb, *offset, -1, '/');
789     if (idx == -1) {
790         /* Force the appropriate exception to be thrown. */
791         len = tvb_length_remaining(tvb, *offset);
792         tvb_ensure_bytes_exist(tvb, *offset, len + 1);
793     } else
794         len = idx - *offset;
795     if (len > 0)
796         proto_tree_add_item(tree, field, tvb, *offset, len, FALSE);
797     *offset += len;
798     if (idx != -1)
799         *offset += 1;   /* skip terminating '/' */
800 }
801
802 static void
803 ucp_handle_IRAstring(proto_tree *tree, tvbuff_t *tvb, int field, int *offset)
804 {
805     char         strval[BUFSIZ + 1],
806                 *p_dst = strval;
807     guint8       byte;
808     int          idx = 0;
809     int          tmpoff = *offset;
810
811     while (((byte = tvb_get_guint8(tvb, tmpoff++)) != '/') &&
812            (idx < BUFSIZ))
813     {
814         if (byte >= '0' && byte <= '9')
815         {
816             *p_dst = (byte - '0') * 16;
817         }
818         else
819         {
820             *p_dst = (byte - 'A' + 10) * 16;
821         }
822         if ((byte = tvb_get_guint8(tvb, tmpoff++)) == '/')
823         {
824             break;
825         }
826         if (byte >= '0' && byte <= '9')
827         {
828             *p_dst++ += byte - '0';
829         }
830         else
831         {
832             *p_dst++ += byte - 'A' + 10;
833         }
834         idx++;
835     }
836     strval[idx] = '\0';
837     if (idx == BUFSIZ)
838     {
839         /*
840          * Data clipped, eat rest of field
841          */
842         while ((tvb_get_guint8(tvb, tmpoff++)) != '/')
843             ;
844     }
845     if ((tmpoff - *offset) > 1)
846         proto_tree_add_string(tree, field, tvb, *offset,
847                               tmpoff - *offset - 1, strval);
848     *offset = tmpoff;
849 }
850
851 static guint
852 ucp_handle_byte(proto_tree *tree, tvbuff_t *tvb, int field, int *offset)
853 {
854     guint        intval = 0;
855
856     if ((intval = tvb_get_guint8(tvb, (*offset)++)) != '/') {
857         proto_tree_add_uint(tree, field, tvb, *offset - 1, 1, intval);
858         (*offset)++;
859     }
860     return intval;
861 }
862
863 static guint
864 ucp_handle_int(proto_tree *tree, tvbuff_t *tvb, int field, int *offset)
865 {
866     gint         idx, len;
867     char         *strval;
868     guint        intval = 0;
869
870     idx = tvb_find_guint8(tvb, *offset, -1, '/');
871     if (idx == -1) {
872         /* Force the appropriate exception to be thrown. */
873         len = tvb_length_remaining(tvb, *offset);
874         tvb_ensure_bytes_exist(tvb, *offset, len + 1);
875     } else
876         len = idx - *offset;
877     strval = (gchar*)tvb_get_ephemeral_string(tvb, *offset, len);
878     if (len > 0) {
879         intval = atoi(strval);
880         proto_tree_add_uint(tree, field, tvb, *offset, idx, intval);
881     }
882     *offset += len;
883     if (idx != -1)
884         *offset += 1;   /* skip terminating '/' */
885     return intval;
886 }
887
888 static void
889 ucp_handle_time(proto_tree *tree, tvbuff_t *tvb, int field, int *offset)
890 {
891     gint         idx, len;
892     char         *strval;
893     time_t       tval;
894     nstime_t     tmptime;
895
896     idx = tvb_find_guint8(tvb, *offset, -1, '/');
897     if (idx == -1) {
898         /* Force the appropriate exception to be thrown. */
899         len = tvb_length_remaining(tvb, *offset);
900         tvb_ensure_bytes_exist(tvb, *offset, len + 1);
901     } else
902         len = idx - *offset;
903     strval = (gchar*)tvb_get_ephemeral_string(tvb, *offset, len);
904     if (len > 0) {
905         tval = ucp_mktime(strval);
906         tmptime.secs  = tval;
907         tmptime.nsecs = 0;
908         proto_tree_add_time(tree, field, tvb, *offset, idx, &tmptime);
909     }
910     *offset += len;
911     if (idx != -1)
912         *offset += 1;   /* skip terminating '/' */
913 }
914
915 static void
916 ucp_handle_data(proto_tree *tree, tvbuff_t *tvb, int field, int *offset)
917 {
918     int          tmpoff = *offset;
919
920     while (tvb_get_guint8(tvb, tmpoff++) != '/')
921         ;
922     if ((tmpoff - *offset) > 1)
923         proto_tree_add_item(tree, field, tvb, *offset,
924                             tmpoff - *offset - 1, FALSE);
925     *offset = tmpoff;
926 }
927
928 /*!
929  * Handle the data-field within the UCP-message, according the Message Type
930  *      - 1     Tone only
931  *      - 2     Numeric message
932  *      - 3     Alphanumeric message
933  *      - 4     Transparent (binary) data
934  *      - 5     Standard text handling
935  *      - 6     Alphanumeric message in specified character set
936  *
937  * \param       tree    The protocol tree to add to
938  * \param       tvb     Buffer containing the data
939  * \param       field   The actual field, whose value needs displaying
940  * \param       offset  Location of field within the buffer, returns location
941  *                      of next field.
942  */
943 static void
944 ucp_handle_mt(proto_tree *tree, tvbuff_t *tvb, int *offset)
945 {
946     guint                intval;
947
948     intval = ucp_handle_byte(tree, tvb, hf_ucp_parm_MT, offset);
949     switch (intval) {
950         case '1':                               /* Tone only, no data   */
951             break;
952         case '4':                               /* TMsg, no of bits     */
953             ucp_handle_string(tree, tvb, hf_ucp_parm_NB, offset);
954             /* fall through here for the data piece     */
955         case '2':
956             ucp_handle_data(tree, tvb, hf_ucp_data_section, offset);
957             break;
958         case '3':
959             ucp_handle_IRAstring(tree, tvb, hf_ucp_parm_AMsg, offset);
960             break;
961         case '5':
962             ucp_handle_byte(tree, tvb, hf_ucp_parm_PNC, offset);
963             ucp_handle_string(tree, tvb, hf_ucp_parm_LNo, offset);
964             ucp_handle_string(tree, tvb, hf_ucp_parm_LST, offset);
965             ucp_handle_string(tree, tvb, hf_ucp_parm_TNo, offset);
966             break;
967         case '6':
968             ucp_handle_data(tree, tvb, hf_ucp_data_section, offset);
969             ucp_handle_int(tree, tvb, hf_ucp_parm_CS, offset);
970             break;
971         default:
972             break;              /* No data so ? */
973     }
974 }
975
976 /*!
977  * Handle the data within the 'Extended services' field. Each field having the
978  * format TTLLDD..., TT being the type of service, LL giving the length of the
979  * field, DD... containing the actual data
980  *
981  * \param       tree    The protocol tree to add to
982  * \param       tvb     Buffer containing the extended services data
983  */
984 static void
985 ucp_handle_XSer(proto_tree *tree, tvbuff_t *tvb)
986 {
987     int          offset = 0;
988     guint        intval;
989     int          service;
990     int          len;
991
992     while ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
993         service = AHex2Bin(intval);
994         intval = tvb_get_guint8(tvb, offset++);
995         service = service * 16 + AHex2Bin(intval);
996         intval = tvb_get_guint8(tvb, offset++);
997         len = AHex2Bin(intval);
998         intval = tvb_get_guint8(tvb, offset++);
999         len = len * 16 + AHex2Bin(intval);
1000         proto_tree_add_uint(tree, hf_xser_service, tvb, offset,
1001                             2 * len, service);
1002         offset += (2 * len);
1003     }
1004 }
1005
1006 /* Next definitions are just a convenient shorthand to make the coding a
1007  * bit more readable instead of summing up all these parameters.
1008  */
1009 #define UcpHandleString(field)  ucp_handle_string(tree, tvb, (field), &offset)
1010
1011 #define UcpHandleIRAString(field) \
1012                         ucp_handle_IRAstring(tree, tvb, (field), &offset)
1013
1014 #define UcpHandleByte(field)    ucp_handle_byte(tree, tvb, (field), &offset)
1015
1016 #define UcpHandleInt(field)     ucp_handle_int(tree, tvb, (field), &offset)
1017
1018 #define UcpHandleTime(field)    ucp_handle_time(tree, tvb, (field), &offset)
1019
1020 #define UcpHandleData(field)    ucp_handle_data(tree, tvb, (field), &offset)
1021
1022 /*!
1023  * The next set of routines handle the different operation types,
1024  * associated with UCP.
1025  */
1026 static void
1027 add_00O(proto_tree *tree, tvbuff_t *tvb)
1028 {                                               /* Enquiry      */
1029     int          offset = 1;
1030
1031     UcpHandleString(hf_ucp_parm_AdC);
1032     UcpHandleString(hf_ucp_parm_OAdC);
1033     UcpHandleString(hf_ucp_parm_OAC);
1034 }
1035
1036 static void
1037 add_00R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1038 {
1039     int          offset = 1;
1040     guint        intval;
1041
1042     intval = UcpHandleByte(hf_ucp_parm_ACK);
1043     if (intval == 'A')
1044     {
1045         UcpHandleByte(hf_ucp_parm_BAS);
1046         UcpHandleByte(hf_ucp_parm_LAR);
1047         UcpHandleByte(hf_ucp_parm_L1R);
1048         UcpHandleByte(hf_ucp_parm_L3R);
1049         UcpHandleByte(hf_ucp_parm_LCR);
1050         UcpHandleByte(hf_ucp_parm_LUR);
1051         UcpHandleByte(hf_ucp_parm_LRR);
1052         UcpHandleByte(hf_ucp_parm_RT);
1053         UcpHandleInt(hf_ucp_parm_NoN);
1054         UcpHandleInt(hf_ucp_parm_NoA);
1055         UcpHandleInt(hf_ucp_parm_NoB);
1056
1057         tap_rec->result = 0;
1058     } else {
1059         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1060         UcpHandleString(hf_ucp_parm_SM);
1061     }
1062 }
1063
1064 static void
1065 add_01O(proto_tree *tree, tvbuff_t *tvb)
1066 {                                               /* Call input   */
1067     int          offset = 1;
1068
1069     UcpHandleString(hf_ucp_parm_AdC);
1070     UcpHandleString(hf_ucp_parm_OAdC);
1071     UcpHandleString(hf_ucp_parm_OAC);
1072     ucp_handle_mt(tree, tvb, &offset);
1073 }
1074
1075 static void
1076 add_01R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1077 {
1078     int          offset = 1;
1079     guint        intval;
1080
1081     intval = UcpHandleByte(hf_ucp_parm_ACK);
1082     if (intval == 'N')
1083         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1084     else
1085         tap_rec->result = 0;
1086     UcpHandleString(hf_ucp_parm_SM);
1087 }
1088
1089 static void
1090 add_02O(proto_tree *tree, tvbuff_t *tvb)
1091 {                                               /* Multiple address call input*/
1092     int          offset = 1;
1093     guint        intval;
1094     guint        idx;
1095
1096     intval = UcpHandleInt(hf_ucp_parm_NPL);
1097     for (idx = 0; idx < intval; idx++)
1098         UcpHandleString(hf_ucp_parm_AdC);
1099
1100     UcpHandleString(hf_ucp_parm_OAdC);
1101     UcpHandleString(hf_ucp_parm_OAC);
1102     ucp_handle_mt(tree, tvb, &offset);
1103 }
1104
1105 #define add_02R(a, b, c) add_01R(a, b, c)
1106
1107 static void
1108 add_03O(proto_tree *tree, tvbuff_t *tvb)
1109 {                                               /* Call input with SS   */
1110     int          offset = 1;
1111     guint        intval;
1112     guint        idx;
1113
1114     UcpHandleString(hf_ucp_parm_AdC);
1115     UcpHandleString(hf_ucp_parm_OAdC);
1116     UcpHandleString(hf_ucp_parm_OAC);
1117     intval = UcpHandleInt(hf_ucp_parm_NPL);
1118     for (idx = 0; idx < intval; idx++)
1119         UcpHandleString(hf_ucp_parm_GA);
1120
1121     UcpHandleByte(hf_ucp_parm_RP);
1122     UcpHandleString(hf_ucp_parm_LRP);
1123     UcpHandleByte(hf_ucp_parm_PR);
1124     UcpHandleString(hf_ucp_parm_LPR);
1125     UcpHandleByte(hf_ucp_parm_UM);
1126     UcpHandleString(hf_ucp_parm_LUM);
1127     UcpHandleByte(hf_ucp_parm_RC);
1128     UcpHandleString(hf_ucp_parm_LRC);
1129     UcpHandleByte(hf_ucp_parm_DD);
1130     UcpHandleTime(hf_ucp_parm_DDT);
1131     ucp_handle_mt(tree, tvb, &offset);
1132 }
1133
1134 #define add_03R(a, b, c) add_01R(a, b, c)
1135
1136 static void
1137 add_04O(proto_tree *tree, tvbuff_t *tvb)
1138 {                                               /* Address list information */
1139     int          offset = 1;
1140
1141     UcpHandleString(hf_ucp_parm_GAdC);
1142     UcpHandleString(hf_ucp_parm_AC);
1143     UcpHandleString(hf_ucp_parm_OAdC);
1144     UcpHandleString(hf_ucp_parm_OAC);
1145 }
1146
1147 static void
1148 add_04R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1149 {
1150     int          offset = 1;
1151     guint        intval;
1152     guint        idx;
1153
1154     intval = UcpHandleByte(hf_ucp_parm_ACK);
1155     if (intval == 'A') {
1156         intval = UcpHandleInt(hf_ucp_parm_NPL);
1157         for (idx = 0; idx < intval; idx++)
1158             UcpHandleString(hf_ucp_parm_AdC);
1159         UcpHandleString(hf_ucp_parm_GAdC);
1160         tap_rec->result = 0;
1161     } else
1162         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1163     UcpHandleString(hf_ucp_parm_SM);
1164 }
1165
1166 static void
1167 add_05O(proto_tree *tree, tvbuff_t *tvb)
1168 {                                               /* Change address list */
1169     int          offset = 1;
1170     guint        intval;
1171     guint        idx;
1172
1173     UcpHandleString(hf_ucp_parm_GAdC);
1174     UcpHandleString(hf_ucp_parm_AC);
1175     UcpHandleString(hf_ucp_parm_OAdC);
1176     UcpHandleString(hf_ucp_parm_OAC);
1177     intval = UcpHandleInt(hf_ucp_parm_NPL);
1178     for (idx = 0; idx < intval; idx++)
1179         UcpHandleString(hf_ucp_parm_AdC);
1180     UcpHandleByte(hf_ucp_parm_A_D);
1181 }
1182
1183 #define add_05R(a, b, c) add_01R(a, b, c)
1184
1185 static void
1186 add_06O(proto_tree *tree, tvbuff_t *tvb)
1187 {                                               /* Advice of accum. charges */
1188     int          offset = 1;
1189
1190     UcpHandleString(hf_ucp_parm_AdC);
1191     UcpHandleString(hf_ucp_parm_AC);
1192 }
1193
1194 static void
1195 add_06R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1196 {
1197     int          offset = 1;
1198     guint        intval;
1199
1200     intval = UcpHandleByte(hf_ucp_parm_ACK);
1201     if (intval == 'A') {
1202         UcpHandleTime(hf_ucp_parm_CT);
1203         UcpHandleString(hf_ucp_parm_AAC);
1204         tap_rec->result = 0;
1205     } else
1206         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1207     UcpHandleString(hf_ucp_parm_SM);
1208 }
1209
1210 static void
1211 add_07O(proto_tree *tree, tvbuff_t *tvb)
1212 {                                               /* Password management  */
1213     int          offset = 1;
1214
1215     UcpHandleString(hf_ucp_parm_AdC);
1216     UcpHandleString(hf_ucp_parm_AC);
1217     UcpHandleString(hf_ucp_parm_NAC);
1218 }
1219
1220 #define add_07R(a, b, c) add_01R(a, b, c)
1221
1222 static void
1223 add_08O(proto_tree *tree, tvbuff_t *tvb)
1224 {                                               /* Leg. code management */
1225     int          offset = 1;
1226
1227     UcpHandleString(hf_ucp_parm_AdC);
1228     UcpHandleString(hf_ucp_parm_AC);
1229     UcpHandleString(hf_ucp_parm_LAC);
1230     UcpHandleString(hf_ucp_parm_L1P);
1231     UcpHandleString(hf_ucp_parm_L3P);
1232     UcpHandleString(hf_ucp_parm_LRC);
1233     UcpHandleString(hf_ucp_parm_LUM);
1234     UcpHandleString(hf_ucp_parm_LRP);
1235     UcpHandleString(hf_ucp_parm_LST);
1236 }
1237
1238 #define add_08R(a, b, c) add_01R(a, b, c)
1239
1240 static void
1241 add_09O(proto_tree *tree, tvbuff_t *tvb)
1242 {                                               /* Standard text information */
1243     int          offset = 1;
1244
1245     UcpHandleString(hf_ucp_parm_LNo);
1246     UcpHandleString(hf_ucp_parm_LST);
1247 }
1248
1249 static void
1250 add_09R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1251 {
1252     int          offset = 1;
1253     guint        intval;
1254     guint        idx;
1255
1256     intval = UcpHandleByte(hf_ucp_parm_ACK);
1257     if (intval == 'A') {
1258         intval = UcpHandleInt(hf_ucp_parm_NPL);
1259         for (idx = 0; idx < intval; idx++)
1260             UcpHandleString(hf_ucp_parm_LST);
1261         tap_rec->result = 0;
1262     } else
1263         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1264     UcpHandleString(hf_ucp_parm_SM);
1265 }
1266
1267 static void
1268 add_10O(proto_tree *tree, tvbuff_t *tvb)
1269 {                                               /* Change standard text */
1270     int          offset = 1;
1271
1272     UcpHandleString(hf_ucp_parm_AdC);
1273     UcpHandleString(hf_ucp_parm_AC);
1274     UcpHandleString(hf_ucp_parm_LNo);
1275     UcpHandleString(hf_ucp_parm_TNo);
1276     UcpHandleData(hf_ucp_parm_STx);
1277     UcpHandleInt(hf_ucp_parm_CS);
1278 }
1279
1280 #define add_10R(a, b, c) add_01R(a, b, c)
1281
1282 #define add_11O(a, b) add_06O(a, b)             /* Request roaming info */
1283
1284 static void
1285 add_11R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1286 {
1287     int          offset = 1;
1288     guint        intval;
1289     guint        idx;
1290
1291     intval = UcpHandleByte(hf_ucp_parm_ACK);
1292     if (intval == 'A') {
1293         intval = UcpHandleInt(hf_ucp_parm_NPL);
1294         for (idx = 0; idx < intval; idx++)
1295             UcpHandleString(hf_ucp_parm_GA);
1296         tap_rec->result = 0;
1297     } else
1298         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1299     UcpHandleString(hf_ucp_parm_SM);
1300 }
1301
1302 static void
1303 add_12O(proto_tree *tree, tvbuff_t *tvb)
1304 {                                               /* Change roaming       */
1305     int          offset = 1;
1306     guint        intval;
1307     guint        idx;
1308
1309     UcpHandleString(hf_ucp_parm_AdC);
1310     UcpHandleString(hf_ucp_parm_AC);
1311     intval = UcpHandleInt(hf_ucp_parm_NPL);
1312     for (idx = 0; idx < intval; idx++)
1313         UcpHandleString(hf_ucp_parm_GA);
1314 }
1315
1316 #define add_12R(a, b, c) add_01R(a, b, c)
1317
1318 #define add_13O(a, b) add_06O(a, b)             /* Roaming reset        */
1319
1320 #define add_13R(a, b, c) add_01R(a, b, c)
1321
1322 static void
1323 add_14O(proto_tree *tree, tvbuff_t *tvb)
1324 {                                               /* Message retrieval    */
1325     int          offset = 1;
1326
1327     UcpHandleString(hf_ucp_parm_AdC);
1328     UcpHandleString(hf_ucp_parm_AC);
1329     UcpHandleString(hf_ucp_parm_MNo);
1330     UcpHandleByte(hf_ucp_parm_R_T);
1331 }
1332
1333 static void
1334 add_14R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1335 {
1336     int          offset = 1;
1337     guint        intval;
1338     guint        idx;
1339
1340     intval = UcpHandleByte(hf_ucp_parm_ACK);
1341     if (intval == 'A') {
1342         intval = UcpHandleInt(hf_ucp_parm_NPL);
1343         /*
1344          * Spec is unclear here. Is 'SM' part of the Msg:s field or not?
1345          * For now, assume it is part of it...
1346          */
1347         for (idx = 0; idx < intval; idx++)
1348             UcpHandleData(hf_ucp_data_section);
1349         tap_rec->result = 0;
1350     } else {
1351         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1352         UcpHandleString(hf_ucp_parm_SM);
1353     }
1354 }
1355
1356 static void
1357 add_15O(proto_tree *tree, tvbuff_t *tvb)
1358 {                                               /* Request call barring */
1359     int          offset = 1;
1360
1361     UcpHandleString(hf_ucp_parm_AdC);
1362     UcpHandleString(hf_ucp_parm_AC);
1363     UcpHandleTime(hf_ucp_parm_ST);
1364     UcpHandleTime(hf_ucp_parm_SP);
1365 }
1366
1367 #define add_15R(a, b, c) add_01R(a, b, c)
1368
1369 #define add_16O(a, b) add_06O(a, b)             /* Cancel call barring  */
1370
1371 #define add_16R(a, b, c) add_01R(a, b, c)
1372
1373 static void
1374 add_17O(proto_tree *tree, tvbuff_t *tvb)
1375 {                                               /* Request call diversion */
1376     int          offset = 1;
1377
1378     UcpHandleString(hf_ucp_parm_AdC);
1379     UcpHandleString(hf_ucp_parm_AC);
1380     UcpHandleString(hf_ucp_parm_DAdC);
1381     UcpHandleTime(hf_ucp_parm_ST);
1382     UcpHandleTime(hf_ucp_parm_SP);
1383 }
1384
1385 #define add_17R(a, b, c) add_01R(a, b, c)
1386
1387 #define add_18O(a, b) add_06O(a, b)             /* Cancel call diversion */
1388
1389 #define add_18R(a, b, c) add_01R(a, b, c)
1390
1391 static void
1392 add_19O(proto_tree *tree, tvbuff_t *tvb)
1393 {                                               /* Request deferred delivery*/
1394     int          offset = 1;
1395
1396     UcpHandleString(hf_ucp_parm_AdC);
1397     UcpHandleString(hf_ucp_parm_AC);
1398     UcpHandleTime(hf_ucp_parm_ST);
1399     UcpHandleTime(hf_ucp_parm_SP);
1400 }
1401
1402 #define add_19R(a, b, c) add_01R(a, b, c)
1403
1404 #define add_20O(a, b) add_06O(a, b)             /* Cancel deferred delivery */
1405
1406 #define add_20R(a, b, c) add_01R(a, b, c)
1407
1408 #define add_21O(a, b) add_06O(a, b)             /* All features reset   */
1409
1410 #define add_21R(a, b, c) add_01R(a, b, c)
1411
1412 static void
1413 add_22O(proto_tree *tree, tvbuff_t *tvb)
1414 {                                               /* Call input w. add. CS */
1415     int          offset = 1;
1416
1417     UcpHandleString(hf_ucp_parm_AdC);
1418     UcpHandleString(hf_ucp_parm_OAdC);
1419     UcpHandleString(hf_ucp_parm_OAC);
1420     UcpHandleData(hf_ucp_data_section);
1421     UcpHandleInt(hf_ucp_parm_CS);
1422 }
1423
1424 #define add_22R(a, b, c) add_01R(a, b, c)
1425
1426 static void
1427 add_23O(proto_tree *tree, tvbuff_t *tvb)
1428 {                                               /* UCP version status   */
1429     int          offset = 1;
1430
1431     UcpHandleString(hf_ucp_parm_IVR5x);
1432     UcpHandleByte(hf_ucp_parm_REQ_OT);
1433 }
1434
1435 static void
1436 add_23R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1437 {
1438     int          offset = 1;
1439     guint        intval;
1440     guint        idx;
1441
1442     intval = UcpHandleByte(hf_ucp_parm_ACK);
1443     if (intval == 'A') {
1444         UcpHandleByte(hf_ucp_parm_IVR5x);
1445         intval = UcpHandleInt(hf_ucp_parm_NPL);
1446         for (idx = 0; idx < intval; idx++)
1447             UcpHandleInt(hf_ucp_hdr_OT);
1448         tap_rec->result = 0;
1449     } else
1450         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1451     UcpHandleString(hf_ucp_parm_SM);
1452 }
1453
1454 static void
1455 add_24O(proto_tree *tree, tvbuff_t *tvb)
1456 {                                               /* Mobile subs. feature stat*/
1457     int          offset = 1;
1458
1459     UcpHandleString(hf_ucp_parm_AdC);
1460     UcpHandleString(hf_ucp_parm_AC);
1461     UcpHandleByte(hf_ucp_parm_SSTAT);
1462 }
1463
1464 static void
1465 add_24R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1466 {
1467     int          offset = 1;
1468     guint        intval;
1469     guint        idx;
1470
1471     intval = UcpHandleByte(hf_ucp_parm_ACK);
1472     if (intval == 'A') {
1473         if ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
1474             proto_tree_add_text(tree, tvb, offset - 1, 1,
1475                                 "GA roaming definitions");
1476             if (intval == 'N') {
1477                 proto_tree_add_text(tree, tvb, offset -1, 1,
1478                                 "Not subscribed/not allowed");
1479                 offset++;
1480             } else {
1481                 --offset;
1482                 intval = UcpHandleInt(hf_ucp_parm_NPL);
1483                 for (idx = 0; idx < intval; idx++)
1484                     UcpHandleData(hf_ucp_data_section);
1485             }
1486         }
1487         if ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
1488             proto_tree_add_text(tree, tvb, offset - 1, 1,
1489                                 "Call barring definitions");
1490             if (intval == 'N') {
1491                 proto_tree_add_text(tree, tvb, offset -1, 1,
1492                                 "Not subscribed/not allowed");
1493                 offset++;
1494             } else {
1495                 --offset;
1496                 intval = UcpHandleInt(hf_ucp_parm_NPL);
1497                 for (idx = 0; idx < intval; idx++)
1498                     UcpHandleData(hf_ucp_data_section);
1499             }
1500         }
1501         if ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
1502             proto_tree_add_text(tree, tvb, offset - 1, 1,
1503                                 "Deferred delivery definitions");
1504             if (intval == 'N') {
1505                 proto_tree_add_text(tree, tvb, offset -1, 1,
1506                                 "Not subscribed/not allowed");
1507                 offset++;
1508             } else {
1509                 --offset;
1510                 intval = UcpHandleInt(hf_ucp_parm_NPL);
1511                 for (idx = 0; idx < intval; idx++)
1512                     UcpHandleData(hf_ucp_data_section);
1513             }
1514         }
1515         if ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
1516             proto_tree_add_text(tree, tvb, offset - 1, 1,
1517                                 "Diversion definitions");
1518             if (intval == 'N') {
1519                 proto_tree_add_text(tree, tvb, offset -1, 1,
1520                                 "Not subscribed/not allowed");
1521                 offset++;
1522             } else {
1523                 --offset;
1524                 intval = UcpHandleInt(hf_ucp_parm_NPL);
1525                 for (idx = 0; idx < intval; idx++)
1526                     UcpHandleData(hf_ucp_data_section);
1527             }
1528         }
1529         UcpHandleInt(hf_ucp_parm_LMN);
1530         if ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
1531             if (intval == 'N') {
1532                 proto_tree_add_string(tree, hf_ucp_parm_NMESS_str, tvb,
1533                                 offset -1, 1, "Not subscribed/not allowed");
1534                 offset++;
1535             } else {
1536                 --offset;
1537                 intval = UcpHandleInt(hf_ucp_parm_NMESS);
1538             }
1539         }
1540         tap_rec->result = 0;
1541     } else
1542         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1543     UcpHandleString(hf_ucp_parm_SM);
1544 }
1545
1546 static void
1547 add_30O(proto_tree *tree, tvbuff_t *tvb)
1548 {                                               /* SMS message transfer */
1549     int          offset = 1;
1550
1551     UcpHandleString(hf_ucp_parm_AdC);
1552     UcpHandleString(hf_ucp_parm_OAdC);
1553     UcpHandleString(hf_ucp_parm_AC);
1554     UcpHandleByte(hf_ucp_parm_NRq);
1555     UcpHandleString(hf_ucp_parm_NAdC);
1556     UcpHandleInt(hf_ucp_parm_NPID);
1557     UcpHandleByte(hf_ucp_parm_DD);
1558     UcpHandleTime(hf_ucp_parm_DDT);
1559     UcpHandleTime(hf_ucp_parm_VP);
1560     UcpHandleData(hf_ucp_data_section);
1561 }
1562
1563 static void
1564 add_30R(proto_tree *tree, tvbuff_t *tvb, ucp_tap_rec_t *tap_rec)
1565 {
1566     int          offset = 1;
1567     guint        intval;
1568
1569     intval = UcpHandleByte(hf_ucp_parm_ACK);
1570     if (intval == 'A') {
1571         UcpHandleTime(hf_ucp_parm_MVP);
1572         tap_rec->result = 0;
1573     } else {
1574         tap_rec->result = UcpHandleInt(hf_ucp_parm_EC);
1575     }
1576     UcpHandleString(hf_ucp_parm_SM);
1577 }
1578
1579 static void
1580 add_31O(proto_tree *tree, tvbuff_t *tvb)
1581 {                                               /* SMT alert            */
1582     int          offset = 1;
1583
1584     UcpHandleString(hf_ucp_parm_AdC);
1585     UcpHandleInt(hf_ucp_parm_PID);
1586 }
1587
1588 #define add_31R(a, b, c) add_01R(a, b, c)
1589
1590 static void
1591 add_5xO(proto_tree *tree, tvbuff_t *tvb)
1592 {                                               /* 50-series operations */
1593     guint        intval;
1594     int          offset = 1;
1595     int          tmpoff;
1596     proto_item  *ti;
1597     tvbuff_t    *tmptvb;
1598
1599     UcpHandleString(hf_ucp_parm_AdC);
1600     UcpHandleString(hf_ucp_parm_OAdC);
1601     UcpHandleString(hf_ucp_parm_AC);
1602     UcpHandleByte(hf_ucp_parm_NRq);
1603     UcpHandleString(hf_ucp_parm_NAdC);
1604     UcpHandleByte(hf_ucp_parm_NT);
1605     UcpHandleInt(hf_ucp_parm_NPID);
1606     UcpHandleByte(hf_ucp_parm_LRq);
1607     UcpHandleString(hf_ucp_parm_LRAd);
1608     UcpHandleInt(hf_ucp_parm_LPID);
1609     UcpHandleByte(hf_ucp_parm_DD);
1610     UcpHandleTime(hf_ucp_parm_DDT);
1611     UcpHandleTime(hf_ucp_parm_VP);
1612     UcpHandleString(hf_ucp_parm_RPID);
1613     UcpHandleTime(hf_ucp_parm_SCTS);
1614     UcpHandleByte(hf_ucp_parm_Dst);
1615     UcpHandleInt(hf_ucp_parm_Rsn);
1616     UcpHandleTime(hf_ucp_parm_DSCTS);
1617     intval = UcpHandleByte(hf_ucp_parm_MT);
1618     UcpHandleString(hf_ucp_parm_NB);
1619     if (intval != '3')
1620         UcpHandleData(hf_ucp_data_section);
1621     else
1622         UcpHandleIRAString(hf_ucp_parm_AMsg);
1623     UcpHandleByte(hf_ucp_parm_MMS);
1624     UcpHandleByte(hf_ucp_parm_PR);
1625     UcpHandleByte(hf_ucp_parm_DCs);
1626     UcpHandleByte(hf_ucp_parm_MCLs);
1627     UcpHandleByte(hf_ucp_parm_RPI);
1628     if ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
1629         proto_tree_add_string(tree, hf_ucp_parm_CPg, tvb, offset - 1,1,
1630                               "(reserved for Code Page)");
1631         offset++;
1632     }
1633     if ((intval = tvb_get_guint8(tvb, offset++)) != '/') {
1634         proto_tree_add_string(tree, hf_ucp_parm_RPLy, tvb, offset - 1,1,
1635                               "(reserved for Reply type)");
1636         offset++;
1637     }
1638     UcpHandleString(hf_ucp_parm_OTOA);
1639     UcpHandleString(hf_ucp_parm_HPLMN);
1640     tmpoff = offset;                            /* Extra services       */
1641     while (tvb_get_guint8(tvb, tmpoff++) != '/')
1642         ;
1643     if ((tmpoff - offset) > 1) {
1644         int      len = tmpoff - offset - 1;
1645
1646         ti = proto_tree_add_item(tree, hf_ucp_parm_XSer,tvb,offset,len,FALSE);
1647         tmptvb = tvb_new_subset(tvb, offset, len + 1, len + 1);
1648         proto_item_add_subtree(ti, ett_XSer);
1649         ucp_handle_XSer(ti, tmptvb);
1650     }
1651     offset = tmpoff;
1652     UcpHandleData(hf_ucp_parm_RES4);
1653     UcpHandleData(hf_ucp_parm_RES5);
1654 }
1655
1656 #define add_5xR(a, b,c ) add_30R(a, b, c)
1657
1658 static void
1659 add_6xO(proto_tree *tree, tvbuff_t *tvb, guint8 OT)
1660 {                                               /* 60-series operations */
1661     int          offset = 1;
1662
1663     UcpHandleString(hf_ucp_parm_OAdC);
1664     UcpHandleByte(hf_ucp_parm_OTON);
1665     UcpHandleByte(hf_ucp_parm_ONPI);
1666     if (OT == 60) {
1667         UcpHandleByte(hf_ucp_parm_STYP0);
1668     } else {
1669         UcpHandleByte(hf_ucp_parm_STYP1);
1670     }
1671     UcpHandleIRAString(hf_ucp_parm_PWD);
1672     UcpHandleIRAString(hf_ucp_parm_NPWD);
1673     UcpHandleString(hf_ucp_parm_VERS);
1674     UcpHandleString(hf_ucp_parm_LAdC);
1675     UcpHandleByte(hf_ucp_parm_LTON);
1676     UcpHandleByte(hf_ucp_parm_LNPI);
1677     UcpHandleInt(hf_ucp_parm_OPID);
1678     UcpHandleData(hf_ucp_parm_RES1);
1679     if (OT == 61) {
1680       UcpHandleData(hf_ucp_parm_RES2);
1681     }
1682 }
1683
1684 #define add_6xR(a, b, c) add_01R(a, b, c)
1685
1686 /*
1687  * End of convenient shorthands
1688  */
1689 #undef UcpHandleString
1690 #undef UcpHandleIRAString
1691 #undef UcpHandleByte
1692 #undef UcpHandleInt
1693 #undef UcpHandleTime
1694 #undef UcpHandleData
1695
1696 /* Code to actually dissect the packets */
1697 /*
1698  * Overlapping data for these functions
1699  */
1700 static int       result, endpkt;
1701
1702 /*
1703  * The heuristic dissector
1704  */
1705 static gboolean
1706 dissect_ucp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1707 {
1708     guint8       O_R;           /* Request or response                  */
1709
1710     /* This runs atop TCP, so we are guaranteed that there is at least one
1711        byte in the tvbuff. */
1712     if (tvb_get_guint8(tvb, 0) != UCP_STX)
1713         return FALSE;
1714
1715     result = check_ucp(tvb, &endpkt);
1716
1717     if (result == UCP_MALFORMED)
1718         return FALSE;
1719     if (endpkt < UCP_OT_OFFSET + 1)
1720         /*
1721          * Might be shortened packet but don't handle anyway.
1722          */
1723         return FALSE;
1724
1725     /*
1726      * Try getting the operation-type and whether it's a request/response
1727      */
1728     O_R = tvb_get_guint8(tvb, UCP_O_R_OFFSET);
1729     if (match_strval(O_R, vals_hdr_O_R) == NULL)
1730         return FALSE;
1731     /*
1732      * Ok, looks like a valid packet, go dissect.
1733      */
1734
1735     dissect_ucp_common(tvb, pinfo, tree);
1736     return TRUE;
1737 }
1738
1739 static guint
1740 get_ucp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
1741 {
1742     guint        intval=0;
1743     int          i;
1744
1745     offset = offset + 4;
1746     for (i = 0; i < UCP_LEN_LEN; i++) { /* Length       */
1747         intval = 10 * intval +
1748             (tvb_get_guint8(tvb, offset) - '0');
1749         offset++;
1750     }
1751
1752     return intval + 2;
1753 }
1754
1755
1756 static void
1757 dissect_ucp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1758 {
1759     tcp_dissect_pdus(tvb, pinfo, tree, ucp_desegment, UCP_HEADER_SIZE,
1760                      get_ucp_pdu_len, dissect_ucp_common);
1761 }
1762 /*
1763  * The actual dissector
1764  */
1765 static void
1766 dissect_ucp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1767 {
1768     int          offset = 0;    /* Offset in packet within tvbuff       */
1769     int          tmpoff;        /* Local offset value (per field)       */
1770     guint8       O_R;           /* Request or response                  */
1771     guint8       OT;            /* Operation type                       */
1772     guint        intval;
1773     int          i;
1774     ucp_tap_rec_t* tap_rec;     /* Tap record                           */
1775
1776     /* Set up structures needed to add the protocol subtree and manage it */
1777     proto_item  *ti;
1778     proto_item  *sub_ti;
1779     proto_tree  *ucp_tree;
1780     proto_tree  *sub_tree;
1781     tvbuff_t    *tmp_tvb;
1782
1783     /* Make entries in Protocol column */
1784     col_set_str(pinfo->cinfo, COL_PROTOCOL, "UCP");
1785
1786     /* This runs atop TCP, so we are guaranteed that there is at least one
1787        byte in the tvbuff. */
1788     if (tvb_get_guint8(tvb, 0) != UCP_STX){
1789                 proto_tree_add_text(tree, tvb, 0, -1,"UCP_STX missing, this is not a new packet");
1790                 return;
1791         }
1792
1793         /* Get data needed for dissect_ucp_common */
1794         result = check_ucp(tvb, &endpkt);
1795
1796     O_R = tvb_get_guint8(tvb, UCP_O_R_OFFSET);
1797     /*
1798      * So do an atoi() on the operation type
1799      */
1800     OT  = tvb_get_guint8(tvb, UCP_OT_OFFSET) - '0';
1801     OT  = 10 * OT + (tvb_get_guint8(tvb, UCP_OT_OFFSET + 1) - '0');
1802
1803     /* Create Tap record */
1804     tap_rec = ep_alloc0(sizeof(ucp_tap_rec_t));
1805     tap_rec->message_type = (O_R == 'O' ? 0 : 1);
1806     tap_rec->operation = OT;
1807
1808      /* Make entries in  Info column on summary display */
1809     col_set_str(pinfo->cinfo, COL_PROTOCOL, "UCP");
1810     if (check_col(pinfo->cinfo, COL_INFO)) {
1811         col_clear(pinfo->cinfo, COL_INFO);
1812         col_append_fstr(pinfo->cinfo, COL_INFO, "%s (%s)",
1813                      val_to_str(OT,  vals_hdr_OT,  "unknown operation"),
1814                      val_to_str(O_R, vals_hdr_O_R, "Unknown (%d)"));
1815         if (result == UCP_SHORTENED)
1816             col_append_str(pinfo->cinfo, COL_INFO, " [short packet]");
1817         else if (result == UCP_INV_CHK)
1818             col_append_str(pinfo->cinfo, COL_INFO, " [checksum invalid]");
1819     }
1820
1821     /* In the interest of speed, if "tree" is NULL, don't do any work not
1822        necessary to generate protocol tree items. */
1823     if (tree) {
1824
1825         /* create display subtree for the protocol */
1826         ti = proto_tree_add_item(tree, proto_ucp, tvb, 0, -1, FALSE);
1827
1828         ucp_tree = proto_item_add_subtree(ti, ett_ucp);
1829         /*
1830          * Process the packet here.
1831          * Transaction number
1832          */
1833         offset++;                               /* Skip <stx>   */
1834         tmpoff = offset;
1835         intval = tvb_get_guint8(tvb, tmpoff++) - '0';
1836         intval = 10 * intval + (tvb_get_guint8(tvb, tmpoff++) - '0');
1837         proto_tree_add_uint(ucp_tree, hf_ucp_hdr_TRN, tvb, offset,
1838                             UCP_TRN_LEN, intval);
1839         offset = tmpoff;
1840
1841         offset++;                               /* Skip '/'     */
1842         intval = 0;
1843         tmpoff = offset;
1844         for (i = 0; i < UCP_LEN_LEN; i++) {     /* Length       */
1845             intval = 10 * intval +
1846                         (tvb_get_guint8(tvb, tmpoff++) - '0');
1847         }
1848         proto_tree_add_uint(ucp_tree, hf_ucp_hdr_LEN, tvb, offset,
1849                             UCP_LEN_LEN, intval);
1850         offset = tmpoff;
1851
1852         offset++;                               /* Operation/Response   */
1853         proto_tree_add_uint(ucp_tree, hf_ucp_hdr_O_R, tvb, offset++,
1854                             UCP_O_R_LEN, O_R);
1855
1856         offset++;                               /* Operation type */
1857         proto_tree_add_uint(ucp_tree, hf_ucp_hdr_OT, tvb, offset,
1858                             UCP_OT_LEN, OT);
1859         offset += UCP_OT_LEN;
1860         /*
1861          * Variable part starts here. Don't dissect if not complete.
1862          */
1863         if (result == UCP_SHORTENED)
1864             return;
1865         tmp_tvb = tvb_new_subset(tvb, offset, -1, -1);
1866         sub_ti = proto_tree_add_item(ucp_tree, hf_ucp_oper_section, tvb,
1867                                      offset, endpkt - offset, FALSE);
1868         sub_tree = proto_item_add_subtree(sub_ti, ett_sub);
1869
1870         switch (OT) {
1871             case  0:
1872                 O_R == 'O' ? add_00O(sub_tree,tmp_tvb) : add_00R(sub_tree,tmp_tvb, tap_rec);
1873                 break;
1874             case  1:
1875                 O_R == 'O' ? add_01O(sub_tree,tmp_tvb) : add_01R(sub_tree,tmp_tvb, tap_rec);
1876                 break;
1877             case  2:
1878                 O_R == 'O' ? add_02O(sub_tree,tmp_tvb) : add_02R(sub_tree,tmp_tvb, tap_rec);
1879                 break;
1880             case  3:
1881                 O_R == 'O' ? add_03O(sub_tree,tmp_tvb) : add_03R(sub_tree,tmp_tvb, tap_rec);
1882                 break;
1883             case  4:
1884                 O_R == 'O' ? add_04O(sub_tree,tmp_tvb) : add_04R(sub_tree,tmp_tvb, tap_rec);
1885                 break;
1886             case  5:
1887                 O_R == 'O' ? add_05O(sub_tree,tmp_tvb) : add_05R(sub_tree,tmp_tvb, tap_rec);
1888                 break;
1889             case  6:
1890                 O_R == 'O' ? add_06O(sub_tree,tmp_tvb) : add_06R(sub_tree,tmp_tvb, tap_rec);
1891                 break;
1892             case  7:
1893                 O_R == 'O' ? add_07O(sub_tree,tmp_tvb) : add_07R(sub_tree,tmp_tvb, tap_rec);
1894                 break;
1895             case  8:
1896                 O_R == 'O' ? add_08O(sub_tree,tmp_tvb) : add_08R(sub_tree,tmp_tvb, tap_rec);
1897                 break;
1898             case  9:
1899                 O_R == 'O' ? add_09O(sub_tree,tmp_tvb) : add_09R(sub_tree,tmp_tvb, tap_rec);
1900                 break;
1901             case 10:
1902                 O_R == 'O' ? add_10O(sub_tree,tmp_tvb) : add_10R(sub_tree,tmp_tvb, tap_rec);
1903                 break;
1904             case 11:
1905                 O_R == 'O' ? add_11O(sub_tree,tmp_tvb) : add_11R(sub_tree,tmp_tvb, tap_rec);
1906                 break;
1907             case 12:
1908                 O_R == 'O' ? add_12O(sub_tree,tmp_tvb) : add_12R(sub_tree,tmp_tvb, tap_rec);
1909                 break;
1910             case 13:
1911                 O_R == 'O' ? add_13O(sub_tree,tmp_tvb) : add_13R(sub_tree,tmp_tvb, tap_rec);
1912                 break;
1913             case 14:
1914                 O_R == 'O' ? add_14O(sub_tree,tmp_tvb) : add_14R(sub_tree,tmp_tvb, tap_rec);
1915                 break;
1916             case 15:
1917                 O_R == 'O' ? add_15O(sub_tree,tmp_tvb) : add_15R(sub_tree,tmp_tvb, tap_rec);
1918                 break;
1919             case 16:
1920                 O_R == 'O' ? add_16O(sub_tree,tmp_tvb) : add_16R(sub_tree,tmp_tvb, tap_rec);
1921                 break;
1922             case 17:
1923                 O_R == 'O' ? add_17O(sub_tree,tmp_tvb) : add_17R(sub_tree,tmp_tvb, tap_rec);
1924                 break;
1925             case 18:
1926                 O_R == 'O' ? add_18O(sub_tree,tmp_tvb) : add_18R(sub_tree,tmp_tvb, tap_rec);
1927                 break;
1928             case 19:
1929                 O_R == 'O' ? add_19O(sub_tree,tmp_tvb) : add_19R(sub_tree,tmp_tvb, tap_rec);
1930                 break;
1931             case 20:
1932                 O_R == 'O' ? add_20O(sub_tree,tmp_tvb) : add_20R(sub_tree,tmp_tvb, tap_rec);
1933                 break;
1934             case 21:
1935                 O_R == 'O' ? add_21O(sub_tree,tmp_tvb) : add_21R(sub_tree,tmp_tvb, tap_rec);
1936                 break;
1937             case 22:
1938                 O_R == 'O' ? add_22O(sub_tree,tmp_tvb) : add_22R(sub_tree,tmp_tvb, tap_rec);
1939                 break;
1940             case 23:
1941                 O_R == 'O' ? add_23O(sub_tree,tmp_tvb) : add_23R(sub_tree,tmp_tvb, tap_rec);
1942                 break;
1943             case 24:
1944                 O_R == 'O' ? add_24O(sub_tree,tmp_tvb) : add_24R(sub_tree,tmp_tvb, tap_rec);
1945                 break;
1946             case 30:
1947                 O_R == 'O' ? add_30O(sub_tree,tmp_tvb) : add_30R(sub_tree,tmp_tvb, tap_rec);
1948                 break;
1949             case 31:
1950                 O_R == 'O' ? add_31O(sub_tree,tmp_tvb) : add_31R(sub_tree,tmp_tvb, tap_rec);
1951                 break;
1952             case 51: case 52: case 53: case 54: case 55: case 56: case 57:
1953             case 58:
1954                 O_R == 'O' ? add_5xO(sub_tree,tmp_tvb) : add_5xR(sub_tree,tmp_tvb, tap_rec);
1955                 break;
1956             case 60: case 61:
1957                 O_R == 'O' ? add_6xO(sub_tree,tmp_tvb,OT) : add_6xR(sub_tree,tmp_tvb, tap_rec);
1958                 break;
1959             default:
1960                 break;
1961         }
1962     }
1963     
1964     /* Queue packet for Tap */
1965     tap_queue_packet(ucp_tap, pinfo, tap_rec);
1966
1967     return;
1968 }
1969
1970 /* Register the protocol with Wireshark */
1971 void
1972 proto_register_ucp(void)
1973 {
1974
1975     /* Setup list of fields     */
1976     static hf_register_info hf[] = {
1977         { &hf_ucp_hdr_TRN,
1978             { "Transaction Reference Number", "ucp.hdr.TRN",
1979               FT_UINT8, BASE_DEC, NULL, 0x00,
1980               "Transaction number for this command, used in windowing.",
1981               HFILL
1982             }
1983         },
1984         { &hf_ucp_hdr_LEN,
1985             { "Length", "ucp.hdr.LEN",
1986               FT_UINT16, BASE_DEC, NULL, 0x00,
1987               "Total number of characters between <stx>...<etx>.",
1988               HFILL
1989             }
1990         },
1991         { &hf_ucp_hdr_O_R,
1992             { "Type", "ucp.hdr.O_R",
1993               FT_UINT8, BASE_DEC, VALS(vals_hdr_O_R), 0x00,
1994               "Your basic 'is a request or response'.",
1995               HFILL
1996             }
1997         },
1998         { &hf_ucp_hdr_OT,
1999             { "Operation", "ucp.hdr.OT",
2000               FT_UINT8, BASE_DEC, VALS(vals_hdr_OT), 0x00,
2001               "The operation that is requested with this message.",
2002               HFILL
2003             }
2004         },
2005         { &hf_ucp_oper_section,
2006             { "Data", "ucp.parm",
2007               FT_NONE, BASE_NONE, NULL, 0x00,
2008               "The actual content of the operation.",
2009               HFILL
2010             }
2011         },
2012         { &hf_ucp_parm_AdC,
2013             { "AdC", "ucp.parm.AdC",
2014               FT_STRING, BASE_NONE, NULL, 0x00,
2015               "Address code recipient.",
2016               HFILL
2017             }
2018         },
2019         { &hf_ucp_parm_OAdC,
2020             { "OAdC", "ucp.parm.OAdC",
2021               FT_STRING, BASE_NONE, NULL, 0x00,
2022               "Address code originator.",
2023               HFILL
2024             }
2025         },
2026         { &hf_ucp_parm_DAdC,
2027             { "DAdC", "ucp.parm.DAdC",
2028               FT_STRING, BASE_NONE, NULL, 0x00,
2029               "Diverted address code.",
2030               HFILL
2031             }
2032         },
2033         { &hf_ucp_parm_AC,
2034             { "AC", "ucp.parm.AC",
2035               FT_STRING, BASE_NONE, NULL, 0x00,
2036               "Authentication code.",
2037               HFILL
2038             }
2039         },
2040         { &hf_ucp_parm_OAC,
2041             { "OAC", "ucp.parm.OAC",
2042               FT_STRING, BASE_NONE, NULL, 0x00,
2043               "Authentication code, originator.",
2044               HFILL
2045             }
2046         },
2047         { &hf_ucp_parm_NAC,
2048             { "NAC", "ucp.parm.NAC",
2049               FT_STRING, BASE_NONE, NULL, 0x00,
2050               "New authentication code.",
2051               HFILL
2052             }
2053         },
2054         { &hf_ucp_parm_BAS,
2055             { "BAS", "ucp.parm.BAS",
2056               FT_UINT8, BASE_DEC, VALS(vals_parm_BAS), 0x00,
2057               "Barring status flag.",
2058               HFILL
2059             }
2060         },
2061         { &hf_ucp_parm_LAR,
2062             { "LAR", "ucp.parm.LAR",
2063               FT_UINT8, BASE_DEC, VALS(vals_parm_LAR), 0x00,
2064               "Leg. code for all calls flag.",
2065               HFILL
2066             }
2067         },
2068         { &hf_ucp_parm_LAC,
2069             { "LAC", "ucp.parm.LAC",
2070               FT_STRING, BASE_NONE, NULL, 0x00,
2071               "New leg. code for all calls.",
2072               HFILL
2073             }
2074         },
2075         { &hf_ucp_parm_L1R,
2076             { "L1R", "ucp.parm.L1R",
2077               FT_UINT8, BASE_DEC, VALS(vals_parm_L1R), 0x00,
2078               "Leg. code for priority 1 flag.",
2079               HFILL
2080             }
2081         },
2082         { &hf_ucp_parm_L1P,
2083             { "L1P", "ucp.parm.L1P",
2084               FT_STRING, BASE_NONE, NULL, 0x00,
2085               "New leg. code for level 1 priority.",
2086               HFILL
2087             }
2088         },
2089         { &hf_ucp_parm_L3R,
2090             { "L3R", "ucp.parm.L3R",
2091               FT_UINT8, BASE_DEC, VALS(vals_parm_L3R), 0x00,
2092               "Leg. code for priority 3 flag.",
2093               HFILL
2094             }
2095         },
2096         { &hf_ucp_parm_L3P,
2097             { "L3P", "ucp.parm.L3P",
2098               FT_STRING, BASE_NONE, NULL, 0x00,
2099               "New leg. code for level 3 priority.",
2100               HFILL
2101             }
2102         },
2103         { &hf_ucp_parm_LCR,
2104             { "LCR", "ucp.parm.LCR",
2105               FT_UINT8, BASE_DEC, VALS(vals_parm_LCR), 0x00,
2106               "Leg. code for reverse charging flag.",
2107               HFILL
2108             }
2109         },
2110         { &hf_ucp_parm_LUR,
2111             { "LUR", "ucp.parm.LUR",
2112               FT_UINT8, BASE_DEC, VALS(vals_parm_LUR), 0x00,
2113               "Leg. code for urgent message flag.",
2114               HFILL
2115             }
2116         },
2117         { &hf_ucp_parm_LRR,
2118             { "LRR", "ucp.parm.LRR",
2119               FT_UINT8, BASE_DEC, VALS(vals_parm_LRR), 0x00,
2120               "Leg. code for repetition flag.",
2121               HFILL
2122             }
2123         },
2124         { &hf_ucp_parm_RT,
2125             { "RT", "ucp.parm.RT",
2126               FT_UINT8, BASE_DEC, VALS(vals_parm_RT), 0x00,
2127               "Receiver type.",
2128               HFILL
2129             }
2130         },
2131         { &hf_ucp_parm_NoN,
2132             { "NoN", "ucp.parm.NoN",
2133               FT_UINT16, BASE_DEC, NULL, 0x00,
2134               "Maximum number of numerical characters accepted.",
2135               HFILL
2136             }
2137         },
2138         { &hf_ucp_parm_NoA,
2139             { "NoA", "ucp.parm.NoA",
2140               FT_UINT16, BASE_DEC, NULL, 0x00,
2141               "Maximum number of alphanumerical characters accepted.",
2142               HFILL
2143             }
2144         },
2145         { &hf_ucp_parm_NoB,
2146             { "NoB", "ucp.parm.NoB",
2147               FT_UINT16, BASE_DEC, NULL, 0x00,
2148               "Maximum number of data bits accepted.",
2149               HFILL
2150             }
2151         },
2152         { &hf_ucp_parm_PNC,
2153             { "PNC", "ucp.parm.PNC",
2154               FT_UINT8, BASE_DEC, VALS(vals_parm_PNC), 0x00,
2155               "Paging network controller.",
2156               HFILL
2157             }
2158         },
2159         { &hf_ucp_parm_AMsg,
2160             { "AMsg", "ucp.parm.AMsg",
2161               FT_STRING, BASE_NONE, NULL, 0x00,
2162               "The alphanumeric message that is being sent.",
2163               HFILL
2164             }
2165         },
2166         { &hf_ucp_parm_LNo,
2167             { "LNo", "ucp.parm.LNo",
2168               FT_STRING, BASE_NONE, NULL, 0x00,
2169               "Standard text list number requested by calling party.",
2170               HFILL
2171             }
2172         },
2173         { &hf_ucp_parm_LST,
2174             { "LST", "ucp.parm.LST",
2175               FT_STRING, BASE_NONE, NULL, 0x00,
2176               "Legitimisation code for standard text.",
2177               HFILL
2178             }
2179         },
2180         { &hf_ucp_parm_TNo,
2181             { "TNo", "ucp.parm.TNo",
2182               FT_STRING, BASE_NONE, NULL, 0x00,
2183               "Standard text number requested by calling party.",
2184               HFILL
2185             }
2186         },
2187         { &hf_ucp_parm_CS,
2188             { "CS", "ucp.parm.CS",
2189               FT_UINT8, BASE_DEC, NULL, 0x00,
2190               "Additional character set number.",
2191               HFILL
2192             }
2193         },
2194         { &hf_ucp_parm_PID,
2195             { "PID", "ucp.parm.PID",
2196               FT_UINT16, BASE_DEC, VALS(vals_parm_PID), 0x00,
2197               "SMT PID value.",
2198               HFILL
2199             }
2200         },
2201         { &hf_ucp_parm_NPL,
2202             { "NPL", "ucp.parm.NPL",
2203               FT_UINT16, BASE_DEC, NULL, 0x00,
2204               "Number of parameters in the following list.",
2205               HFILL
2206             }
2207         },
2208         { &hf_ucp_parm_GA,
2209             { "GA", "ucp.parm.GA",
2210               FT_STRING, BASE_NONE, NULL, 0x00,
2211               "GA?? haven't got a clue.",
2212               HFILL
2213             }
2214         },
2215         { &hf_ucp_parm_RP,
2216             { "RP", "ucp.parm.RP",
2217               FT_UINT8, BASE_DEC, VALS(vals_parm_RP), 0x00,
2218               "Repetition requested.",
2219               HFILL
2220             }
2221         },
2222         { &hf_ucp_parm_LRP,
2223             { "LRP", "ucp.parm.LRP",
2224               FT_STRING, BASE_NONE, NULL, 0x00,
2225               "Legitimisation code for repetition.",
2226               HFILL
2227             }
2228         },
2229         { &hf_ucp_parm_PR,
2230             { "PR", "ucp.parm.PR",
2231               FT_UINT8, BASE_DEC, NULL, 0x00,
2232               "Priority requested.",
2233               HFILL
2234             }
2235         },
2236         { &hf_ucp_parm_LPR,
2237             { "LPR", "ucp.parm.LPR",
2238               FT_STRING, BASE_NONE, NULL, 0x00,
2239               "Legitimisation code for priority requested.",
2240               HFILL
2241             }
2242         },
2243         { &hf_ucp_parm_UM,
2244             { "UM", "ucp.parm.UM",
2245               FT_UINT8, BASE_DEC, VALS(vals_parm_UM), 0x00,
2246               "Urgent message indicator.",
2247               HFILL
2248             }
2249         },
2250         { &hf_ucp_parm_LUM,
2251             { "LUM", "ucp.parm.LUM",
2252               FT_STRING, BASE_NONE, NULL, 0x00,
2253               "Legitimisation code for urgent message.",
2254               HFILL
2255             }
2256         },
2257         { &hf_ucp_parm_RC,
2258             { "RC", "ucp.parm.RC",
2259               FT_UINT8, BASE_DEC, VALS(vals_parm_RC), 0x00,
2260               "Reverse charging request.",
2261               HFILL
2262             }
2263         },
2264         { &hf_ucp_parm_LRC,
2265             { "LRC", "ucp.parm.LRC",
2266               FT_STRING, BASE_NONE, NULL, 0x00,
2267               "Legitimisation code for reverse charging.",
2268               HFILL
2269             }
2270         },
2271         { &hf_ucp_parm_NRq,
2272             { "NRq", "ucp.parm.NRq",
2273               FT_UINT8, BASE_DEC, VALS(vals_parm_NRq), 0x00,
2274               "Notification request.",
2275               HFILL
2276             }
2277         },
2278         { &hf_ucp_parm_GAdC,
2279             { "GAdC", "ucp.parm.GAdC",
2280               FT_STRING, BASE_NONE, NULL, 0x00,
2281               "Group address code.",
2282               HFILL
2283             }
2284         },
2285         { &hf_ucp_parm_A_D,
2286             { "A_D", "ucp.parm.A_D",
2287               FT_UINT8, BASE_DEC, VALS(vals_parm_A_D), 0x00,
2288               "Add to/delete from fixed subscriber address list record.",
2289               HFILL
2290             }
2291         },
2292         { &hf_ucp_parm_CT,
2293             { "CT", "ucp.parm.CT",
2294               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2295               "Accumulated charges timestamp.",
2296               HFILL
2297             }
2298         },
2299         { &hf_ucp_parm_AAC,
2300             { "AAC", "ucp.parm.AAC",
2301               FT_STRING, BASE_NONE, NULL, 0x00,
2302               "Accumulated charges.",
2303               HFILL
2304             }
2305         },
2306         { &hf_ucp_parm_MNo,
2307             { "MNo", "ucp.parm.MNo",
2308               FT_STRING, BASE_NONE, NULL, 0x00,
2309               "Message number.",
2310               HFILL
2311             }
2312         },
2313         { &hf_ucp_parm_R_T,
2314             { "R_T", "ucp.parm.R_T",
2315               FT_UINT8, BASE_DEC, VALS(vals_parm_R_T), 0x00,
2316               "Message number.",
2317               HFILL
2318             }
2319         },
2320         { &hf_ucp_parm_NAdC,
2321             { "NAdC", "ucp.parm.NAdC",
2322               FT_STRING, BASE_NONE, NULL, 0x00,
2323               "Notification address.",
2324               HFILL
2325             }
2326         },
2327         { &hf_ucp_parm_NT,
2328             { "NT", "ucp.parm.NT",
2329               FT_UINT8, BASE_DEC, VALS(vals_parm_NT), 0x00,
2330               "Notification type.",
2331               HFILL
2332             }
2333         },
2334         { &hf_ucp_parm_IVR5x,
2335             { "IVR5x", "ucp.parm.IVR5x",
2336               FT_STRING, BASE_NONE, NULL, 0x00,
2337               "UCP release number supported/accepted.",
2338               HFILL
2339             }
2340         },
2341         { &hf_ucp_parm_REQ_OT,
2342             { "REQ_OT", "ucp.parm.REQ_OT",
2343               FT_UINT8, BASE_DEC, VALS(vals_parm_REQ_OT), 0x00,
2344               "UCP release number supported/accepted.",
2345               HFILL
2346             }
2347         },
2348         { &hf_ucp_parm_SSTAT,
2349             { "SSTAT", "ucp.parm.SSTAT",
2350               FT_UINT8, BASE_DEC, VALS(vals_parm_SSTAT), 0x00,
2351               "Supplementary services for which status is requested.",
2352               HFILL
2353             }
2354         },
2355         { &hf_ucp_parm_LMN,
2356             { "LMN", "ucp.parm.LMN",
2357               FT_UINT8, BASE_DEC, NULL, 0x00,
2358               "Last message number.",
2359               HFILL
2360             }
2361         },
2362         { &hf_ucp_parm_NMESS,
2363             { "NMESS", "ucp.parm.NMESS",
2364               FT_UINT8, BASE_DEC, NULL, 0x00,
2365               "Number of stored messages.",
2366               HFILL
2367             }
2368         },
2369         { &hf_ucp_parm_NMESS_str,
2370             { "NMESS_str", "ucp.parm.NMESS_str",
2371               FT_STRING, BASE_NONE, NULL, 0x00,
2372               "Number of stored messages.",
2373               HFILL
2374             }
2375         },
2376         { &hf_ucp_parm_NPID,
2377             { "NPID", "ucp.parm.NPID",
2378               FT_UINT16, BASE_DEC, VALS(vals_parm_PID), 0x00,
2379               "Notification PID value.",
2380               HFILL
2381             }
2382         },
2383         { &hf_ucp_parm_LRq,
2384             { "LRq", "ucp.parm.LRq",
2385               FT_UINT8, BASE_DEC, VALS(vals_parm_LRq), 0x00,
2386               "Last resort address request.",
2387               HFILL
2388             }
2389         },
2390         { &hf_ucp_parm_LRAd,
2391             { "LRAd", "ucp.parm.LRAd",
2392               FT_STRING, BASE_NONE, NULL, 0x00,
2393               "Last resort address.",
2394               HFILL
2395             }
2396         },
2397         { &hf_ucp_parm_LPID,
2398             { "LPID", "ucp.parm.LPID",
2399               FT_UINT16, BASE_DEC, VALS(vals_parm_PID), 0x00,
2400               "Last resort PID value.",
2401               HFILL
2402             }
2403         },
2404         { &hf_ucp_parm_DD,
2405             { "DD", "ucp.parm.DD",
2406               FT_UINT8, BASE_DEC, VALS(vals_parm_DD), 0x00,
2407               "Deferred delivery requested.",
2408               HFILL
2409             }
2410         },
2411         { &hf_ucp_parm_DDT,
2412             { "DDT", "ucp.parm.DDT",
2413               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2414               "Deferred delivery time.",
2415               HFILL
2416             }
2417         },
2418         { &hf_ucp_parm_STx,
2419             { "STx", "ucp.parm.STx",
2420               FT_NONE, BASE_NONE, NULL, 0x00,
2421               "Standard text.",
2422               HFILL
2423             }
2424         },
2425         { &hf_ucp_parm_ST,
2426             { "ST", "ucp.parm.ST",
2427               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2428               "Start time.",
2429               HFILL
2430             }
2431         },
2432         { &hf_ucp_parm_SP,
2433             { "SP", "ucp.parm.SP",
2434               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2435               "Stop time.",
2436               HFILL
2437             }
2438         },
2439         { &hf_ucp_parm_VP,
2440             { "VP", "ucp.parm.VP",
2441               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2442               "Validity period.",
2443               HFILL
2444             }
2445         },
2446         { &hf_ucp_parm_RPID,
2447             { "RPID", "ucp.parm.RPID",
2448               FT_STRING, BASE_NONE, NULL, 0x00,
2449               "Replace PID",
2450               HFILL
2451             }
2452         },
2453         { &hf_ucp_parm_SCTS,
2454             { "SCTS", "ucp.parm.SCTS",
2455               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2456               "Service Centre timestamp.",
2457               HFILL
2458             }
2459         },
2460         { &hf_ucp_parm_Dst,
2461             { "Dst", "ucp.parm.Dst",
2462               FT_UINT8, BASE_DEC, VALS(vals_parm_Dst), 0x00,
2463               "Delivery status.",
2464               HFILL
2465             }
2466         },
2467         { &hf_ucp_parm_Rsn,
2468             { "Rsn", "ucp.parm.Rsn",
2469               FT_UINT16, BASE_DEC, VALS(vals_parm_Rsn), 0x00,
2470               "Reason code.",
2471               HFILL
2472             }
2473         },
2474         { &hf_ucp_parm_DSCTS,
2475             { "DSCTS", "ucp.parm.DSCTS",
2476               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2477               "Delivery timestamp.",
2478               HFILL
2479             }
2480         },
2481         { &hf_ucp_parm_MT,
2482             { "MT", "ucp.parm.MT",
2483               FT_UINT8, BASE_DEC, VALS(vals_parm_MT), 0x00,
2484               "Message type.",
2485               HFILL
2486             }
2487         },
2488         { &hf_ucp_parm_NB,
2489             { "NB", "ucp.parm.NB",
2490               FT_STRING, BASE_NONE, NULL, 0x00,
2491               "No. of bits in Transparent Data (TD) message.",
2492               HFILL
2493             }
2494         },
2495         { &hf_ucp_data_section,
2496             { "Data", "ucp.message",
2497               FT_NONE, BASE_NONE, NULL, 0x00,
2498               "The actual message or data.",
2499               HFILL
2500             }
2501         },
2502         { &hf_ucp_parm_MMS,
2503             { "MMS", "ucp.parm.MMS",
2504               FT_UINT8, BASE_DEC, NULL, 0x00,
2505               "More messages to send.",
2506               HFILL
2507             }
2508         },
2509         { &hf_ucp_parm_DCs,
2510             { "DCs", "ucp.parm.DCs",
2511               FT_UINT8, BASE_DEC, VALS(vals_parm_DCs), 0x00,
2512               "Data coding scheme (deprecated).",
2513               HFILL
2514             }
2515         },
2516         { &hf_ucp_parm_MCLs,
2517             { "MCLs", "ucp.parm.MCLs",
2518               FT_UINT8, BASE_DEC, VALS(vals_parm_MCLs), 0x00,
2519               "Message class.",
2520               HFILL
2521             }
2522         },
2523         { &hf_ucp_parm_RPI,
2524             { "RPI", "ucp.parm.RPI",
2525               FT_UINT8, BASE_DEC, VALS(vals_parm_RPI), 0x00,
2526               "Reply path.",
2527               HFILL
2528             }
2529         },
2530         { &hf_ucp_parm_CPg,
2531             { "CPg", "ucp.parm.CPg",
2532               FT_STRING, BASE_NONE, NULL, 0x00,
2533               "Reserved for Code Page.",
2534               HFILL
2535             }
2536         },
2537         { &hf_ucp_parm_RPLy,
2538             { "RPLy", "ucp.parm.RPLy",
2539               FT_STRING, BASE_NONE, NULL, 0x00,
2540               "Reserved for Reply type.",
2541               HFILL
2542             }
2543         },
2544         { &hf_ucp_parm_OTOA,
2545             { "OTOA", "ucp.parm.OTOA",
2546               FT_STRING, BASE_NONE, NULL, 0x00,
2547               "Originator Type Of Address.",
2548               HFILL
2549             }
2550         },
2551         { &hf_ucp_parm_HPLMN,
2552             { "HPLMN", "ucp.parm.HPLMN",
2553               FT_STRING, BASE_NONE, NULL, 0x00,
2554               "Home PLMN address.",
2555               HFILL
2556             }
2557         },
2558         { &hf_ucp_parm_XSer,
2559             { "Extra services:", "ucp.parm.XSer",
2560               FT_NONE, BASE_NONE, NULL, 0x00,
2561               "Extra services.",
2562               HFILL
2563             }
2564         },
2565         { &hf_ucp_parm_RES4,
2566             { "RES4", "ucp.parm.RES4",
2567               FT_STRING, BASE_NONE, NULL, 0x00,
2568               "Reserved for future use.",
2569               HFILL
2570             }
2571         },
2572         { &hf_ucp_parm_RES5,
2573             { "RES5", "ucp.parm.RES5",
2574               FT_STRING, BASE_NONE, NULL, 0x00,
2575               "Reserved for future use.",
2576               HFILL
2577             }
2578         },
2579         { &hf_ucp_parm_OTON,
2580             { "OTON", "ucp.parm.OTON",
2581               FT_UINT8, BASE_DEC, VALS(vals_parm_OTON), 0x00,
2582               "Originator type of number.",
2583               HFILL
2584             }
2585         },
2586         { &hf_ucp_parm_ONPI,
2587             { "ONPI", "ucp.parm.ONPI",
2588               FT_UINT8, BASE_DEC, VALS(vals_parm_ONPI), 0x00,
2589               "Originator numbering plan id.",
2590               HFILL
2591             }
2592         },
2593         { &hf_ucp_parm_STYP0,
2594             { "STYP0", "ucp.parm.STYP0",
2595               FT_UINT8, BASE_DEC, VALS(vals_parm_STYP0), 0x00,
2596               "Subtype of operation.",
2597               HFILL
2598             }
2599         },
2600         { &hf_ucp_parm_STYP1,
2601             { "STYP1", "ucp.parm.STYP1",
2602               FT_UINT8, BASE_DEC, VALS(vals_parm_STYP1), 0x00,
2603               "Subtype of operation.",
2604               HFILL
2605             }
2606         },
2607         { &hf_ucp_parm_PWD,
2608             { "PWD", "ucp.parm.PWD",
2609               FT_STRING, BASE_NONE, NULL, 0x00,
2610               "Current password.",
2611               HFILL
2612             }
2613         },
2614         { &hf_ucp_parm_NPWD,
2615             { "NPWD", "ucp.parm.NPWD",
2616               FT_STRING, BASE_NONE, NULL, 0x00,
2617               "New password.",
2618               HFILL
2619             }
2620         },
2621         { &hf_ucp_parm_VERS,
2622             { "VERS", "ucp.parm.VERS",
2623               FT_STRING, BASE_NONE, NULL, 0x00,
2624               "Version number.",
2625               HFILL
2626             }
2627         },
2628         { &hf_ucp_parm_LAdC,
2629             { "LAdC", "ucp.parm.LAdC",
2630               FT_STRING, BASE_NONE, NULL, 0x00,
2631               "Address for VSMSC list operation.",
2632               HFILL
2633             }
2634         },
2635         { &hf_ucp_parm_LTON,
2636             { "LTON", "ucp.parm.LTON",
2637               FT_UINT8, BASE_DEC, NULL, 0x00,
2638               "Type of number list address.",
2639               HFILL
2640             }
2641         },
2642         { &hf_ucp_parm_LNPI,
2643             { "LNPI", "ucp.parm.LNPI",
2644               FT_UINT8, BASE_DEC, NULL, 0x00,
2645               "Numbering plan id. list address.",
2646               HFILL
2647             }
2648         },
2649         { &hf_ucp_parm_OPID,
2650             { "OPID", "ucp.parm.OPID",
2651               FT_UINT8, BASE_DEC, VALS(vals_parm_OPID), 0x00,
2652               "Originator protocol identifier.",
2653               HFILL
2654             }
2655         },
2656         { &hf_ucp_parm_RES1,
2657             { "RES1", "ucp.parm.RES1",
2658               FT_STRING, BASE_NONE, NULL, 0x00,
2659               "Reserved for future use.",
2660               HFILL
2661             }
2662         },
2663         { &hf_ucp_parm_RES2,
2664             { "RES2", "ucp.parm.RES2",
2665               FT_STRING, BASE_NONE, NULL, 0x00,
2666               "Reserved for future use.",
2667               HFILL
2668             }
2669         },
2670         { &hf_ucp_parm_ACK,
2671             { "(N)Ack", "ucp.parm.ACK",
2672               FT_UINT8, BASE_DEC, VALS(vals_parm_ACK), 0x00,
2673               "Positive or negative acknowledge of the operation.",
2674               HFILL
2675             }
2676         },
2677         { &hf_ucp_parm_MVP,
2678             { "MVP", "ucp.parm.MVP",
2679               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
2680               "Modified validity period.",
2681               HFILL
2682             }
2683         },
2684         { &hf_ucp_parm_EC,
2685             { "Error code", "ucp.parm.EC",
2686               FT_UINT8, BASE_DEC, VALS(vals_parm_EC), 0x00,
2687               "The result of the requested operation.",
2688               HFILL
2689             }
2690         },
2691         { &hf_ucp_parm_SM,
2692             { "SM", "ucp.parm.SM",
2693               FT_STRING, BASE_NONE, NULL, 0x00,
2694               "System message.",
2695               HFILL
2696             }
2697         },
2698         { &hf_xser_service,
2699             { "Type of service", "ucp.xser.service",
2700               FT_UINT8, BASE_HEX, VALS(vals_xser_service), 0x00,
2701               "The type of service specified.",
2702               HFILL
2703             }
2704         },
2705     };
2706     /* Setup protocol subtree array */
2707     static gint *ett[] = {
2708         &ett_ucp,
2709         &ett_sub,
2710         &ett_XSer
2711     };
2712    module_t *ucp_module;
2713
2714    /* Register the protocol name and description */
2715     proto_ucp = proto_register_protocol("Universal Computer Protocol",
2716                                         "UCP", "ucp");
2717
2718     /* Required function calls to register header fields and subtrees used */
2719     proto_register_field_array(proto_ucp, hf, array_length(hf));
2720     proto_register_subtree_array(ett, array_length(ett));
2721
2722     /* Register for tapping */
2723     ucp_tap = register_tap("ucp");
2724
2725   /* register preferences */
2726     ucp_module = prefs_register_protocol(proto_ucp, NULL);
2727     prefs_register_bool_preference(ucp_module, "desegment_ucp_messages",
2728                            "Reassemble UCP messages spanning multiple TCP segments",
2729                            "Whether the UCP dissector should reassemble messages spanning multiple TCP segments."
2730                            " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
2731                            &ucp_desegment);
2732
2733 }
2734
2735 /*
2736  * If dissector uses sub-dissector registration add a registration routine.
2737  * This format is required because a script is used to find these routines and
2738  * create the code that calls these routines.
2739  */
2740 void
2741 proto_reg_handoff_ucp(void)
2742 {
2743     dissector_handle_t ucp_handle;
2744
2745     /*
2746      * UCP can be spoken on any port so, when not on a specific port, try this
2747      * one whenever TCP is spoken.
2748      */
2749     heur_dissector_add("tcp", dissect_ucp_heur, proto_ucp);
2750
2751     /*
2752      * Also register as one that can be selected by a TCP port number.
2753      */
2754     ucp_handle = create_dissector_handle(dissect_ucp_tcp, proto_ucp);
2755     dissector_add_handle("tcp.port", ucp_handle);
2756
2757     /* Tapping setup */
2758     stats_tree_register_with_group("ucp", "ucp_messages", "_UCP Messages", 0,
2759                         ucp_stats_tree_per_packet, ucp_stats_tree_init,
2760                         NULL, REGISTER_STAT_GROUP_TELEPHONY);
2761 }