dfilter2pod.pl and ethereal-filter.pod.template are in $(srcdir) (which
[obnox/wireshark/wip.git] / packet-q933.c
1 /* packet-q933.c
2  * Routines for Q.933 frame disassembly
3  * Guy Harris <guy@alum.mit.edu>
4  *
5  * $Id: packet-q933.c,v 1.2 2003/09/03 18:27:55 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <glib.h>
32 #include <string.h>
33 #include <epan/packet.h>
34 #include <epan/strutil.h>
35 #include "nlpid.h"
36 #include "prefs.h"
37
38 #include "packet-tpkt.h"
39
40 static int proto_q933 = -1;
41 static int hf_q933_discriminator = -1;
42 static int hf_q933_call_ref_len = -1;
43 static int hf_q933_call_ref_flag = -1;
44 static int hf_q933_call_ref = -1;
45 static int hf_q933_message_type = -1;
46 static int hf_q933_cause_value = -1;
47 static int hf_q933_calling_party_number = -1;
48 static int hf_q933_called_party_number = -1;
49 static int hf_q933_connected_number = -1;
50 static int hf_q933_redirecting_number = -1;
51
52 static gint ett_q933 = -1;
53 static gint ett_q933_ie = -1;
54
55 /*
56  * Q.933 message types.
57  */
58 #define Q933_ESCAPE             0x00
59 #define Q933_ALERTING           0x01
60 #define Q933_CALL_PROCEEDING    0x02
61 #define Q933_CONNECT            0x07
62 #define Q933_CONNECT_ACK        0x0F
63 #define Q933_PROGRESS           0x03
64 #define Q933_SETUP              0x05
65 #define Q933_DISCONNECT         0x45
66 #define Q933_RELEASE            0x4D
67 #define Q933_RELEASE_COMPLETE   0x5A
68 #define Q933_SEGMENT            0x60
69 #define Q933_STATUS             0x7D
70 #define Q933_STATUS_ENQUIRY     0x75
71
72 static const value_string q933_message_type_vals[] = {
73         { Q933_ESCAPE,                  "ESCAPE" },
74         { Q933_ALERTING,                "ALERTING" },
75         { Q933_CALL_PROCEEDING,         "CALL PROCEEDING" },
76         { Q933_CONNECT,                 "CONNECT" },
77         { Q933_CONNECT_ACK,             "CONNECT ACKNOWLEDGE" },
78         { Q933_PROGRESS,                "PROGRESS" },
79         { Q933_SETUP,                   "SETUP" },
80         { Q933_DISCONNECT,              "DISCONNECT" },
81         { Q933_RELEASE,                 "RELEASE" },
82         { Q933_RELEASE_COMPLETE,        "RELEASE COMPLETE" },
83         { Q933_SEGMENT,                 "SEGMENT" },
84         { Q933_STATUS,                  "STATUS" },
85         { Q933_STATUS_ENQUIRY,          "STATUS ENQUIRY" },
86         { 0,                            NULL }
87 };
88
89 static const true_false_string tfs_call_ref_flag = {
90         "Message sent to originating side",
91         "Message sent from originating side"
92 };
93
94 /*
95  * Information elements.
96  */
97
98 /* Shifted codeset values */
99 #define CS0 0x000
100 #define CS1 0x100
101 #define CS2 0x200
102 #define CS3 0x300
103 #define CS4 0x400
104 #define CS5 0x500
105 #define CS6 0x600
106 #define CS7 0x700
107
108 #define Q933_IE_SO_MASK 0x80    /* single-octet/variable-length mask */
109 /*
110  * Single-octet IEs.
111  */
112 #define Q933_IE_SO_IDENTIFIER_MASK      0xf0    /* IE identifier mask */
113 #define Q933_IE_SO_IDENTIFIER_SHIFT     4       /* IE identifier shift */
114 #define Q933_IE_SO_IE_MASK              0x0F    /* IE mask */
115
116 #define Q933_IE_SHIFT                   0x90
117 #define Q933_IE_SHIFT_NON_LOCKING       0x08    /* non-locking shift */
118 #define Q933_IE_SHIFT_CODESET           0x0F    /* codeset */
119
120 #define Q933_IE_REPEAT_INDICATOR        0xD0
121
122 /*
123  * Variable-length IEs.
124  */
125 #define Q933_IE_VL_EXTENSION            0x80    /* Extension flag */
126
127 /*
128  * Codeset 0 (default).
129  */
130 #define Q933_IE_SEGMENTED_MESSAGE       0x00
131 #define Q933_IE_BEARER_CAPABILITY       0x04
132 #define Q933_IE_CAUSE                   0x08
133 #define Q933_IE_CALL_STATE              0x14
134 #define Q933_IE_CHANNEL_IDENTIFICATION  0x18
135 #define Q933_IE_DLCI                    0x19
136 #define Q933_IE_PROGRESS_INDICATOR      0x1E
137 #define Q933_IE_NETWORK_SPECIFIC_FACIL  0x20    /* Network Specific Facilities */
138 #define Q933_IE_DISPLAY                 0x28
139 #define Q933_IE_E2E_TRANSIT_DELAY       0x42    /* End-to-end Transit Delay */
140 #define Q933_IE_TD_SELECTION_AND_INT    0x43    /* Transit Delay Selection and Indication */
141 #define Q933_IE_PL_BINARY_PARAMETERS    0x44    /* Packet layer binary parameters */
142 #define Q933_IE_LL_CORE_PARAMETERS      0x48    /* Link layer core parameters */
143 #define Q933_IE_LL_PROTOCOL_PARAMETERS  0x49    /* Link layer protocol parameters */
144 #define Q933_IE_REVERSE_CHARGE_IND      0x4A    /* Reverse charging indication */
145 #define Q933_IE_CONNECTED_NUMBER        0x4C    /* Connected Number */
146 #define Q933_IE_CONNECTED_SUBADDR       0x4D    /* Connected sub-address */
147 #define Q933_IE_X_213_PRIORITY          0x50    /* X.213 priority */
148 #define Q933_IE_REPORT_TYPE             0x51
149 #define Q933_IE_LINK_INTEGRITY_VERF     0x53    /* Link integrity verification */
150 #define Q933_IE_PVC_STATUS              0x57
151 #define Q933_IE_CALLING_PARTY_NUMBER    0x6C    /* Calling Party Number */
152 #define Q933_IE_CALLING_PARTY_SUBADDR   0x6D    /* Calling Party Subaddress */
153 #define Q933_IE_CALLED_PARTY_NUMBER     0x70    /* Called Party Number */
154 #define Q933_IE_CALLED_PARTY_SUBADDR    0x71    /* Called Party Subaddress */
155 #define Q933_IE_TRANSIT_NETWORK_SEL     0x78    /* Transit Network Selection */
156 #define Q933_IE_LOW_LAYER_COMPAT        0x7C    /* Low-Layer Compatibility */
157 #define Q933_IE_HIGH_LAYER_COMPAT       0x7D    /* High-Layer Compatibility */
158 #define Q933_IE_USER_USER               0x7E    /* User-User */
159 #define Q933_IE_ESCAPE                  0x7F    /* Escape for extension */
160
161 /* Codeset 0 */
162 static const value_string q933_info_element_vals0[] = {
163         { Q933_IE_SEGMENTED_MESSAGE,            "Segmented message" },
164         { Q933_IE_BEARER_CAPABILITY,            "Bearer capability" },
165         { Q933_IE_CAUSE,                        "Cause" },
166         { Q933_IE_CALL_STATE,                   "Call state" },
167         { Q933_IE_CHANNEL_IDENTIFICATION,       "Channel identification" },
168         { Q933_IE_DLCI,                         "Data link connection identifier" },
169         { Q933_IE_PROGRESS_INDICATOR,           "Progress indicator" },
170         { Q933_IE_NETWORK_SPECIFIC_FACIL,       "Network specific facilities" },
171         { Q933_IE_E2E_TRANSIT_DELAY,            "End-to-end transit delay" },
172         { Q933_IE_TD_SELECTION_AND_INT,         "Transit delay selection and indication" },
173         { Q933_IE_PL_BINARY_PARAMETERS,         "Packet layer binary parameters" },
174         { Q933_IE_LL_CORE_PARAMETERS,           "Link layer core parameters" },
175         { Q933_IE_LL_PROTOCOL_PARAMETERS,       "Link layer protocol parameters" },
176         { Q933_IE_REVERSE_CHARGE_IND,           "Reverse charging indication" },
177         { Q933_IE_CONNECTED_NUMBER,             "Connected number" },
178         { Q933_IE_CONNECTED_SUBADDR,            "Connected subaddress" },
179         { Q933_IE_X_213_PRIORITY,               "X.213 priority" },
180         { Q933_IE_REPORT_TYPE,                  "Report type" },
181         { Q933_IE_LINK_INTEGRITY_VERF,          "Link integrity verification" },
182         { Q933_IE_PVC_STATUS,                   "PVC status" },
183         { Q933_IE_CALLING_PARTY_NUMBER,         "Calling party number" },
184         { Q933_IE_CALLING_PARTY_SUBADDR,        "Calling party subaddress" },
185         { Q933_IE_CALLED_PARTY_NUMBER,          "Called party number" },
186         { Q933_IE_CALLED_PARTY_SUBADDR,         "Called party subaddress" },
187         { Q933_IE_TRANSIT_NETWORK_SEL,          "Transit network selection" },
188         { Q933_IE_LOW_LAYER_COMPAT,             "Low-layer compatibility" },
189         { Q933_IE_HIGH_LAYER_COMPAT,            "High-layer compatibility" },
190         { Q933_IE_USER_USER,                    "User-user" },
191         { Q933_IE_ESCAPE,                       "Escape" },
192         { 0,                                    NULL }
193 };
194 /* Codeset 1 */
195 static const value_string q933_info_element_vals1[] = {
196         { 0,                                    NULL }
197 };
198 /* Codeset 2 */
199 static const value_string q933_info_element_vals2[] = {
200         { 0,                                    NULL }
201 };
202 /* Codeset 3 */
203 static const value_string q933_info_element_vals3[] = {
204         { 0,                                    NULL }
205 };
206 /* Codeset 4 */
207 static const value_string q933_info_element_vals4[] = {
208         { 0,                                    NULL }
209 };
210 /* Codeset 5 */
211 static const value_string q933_info_element_vals5[] = {
212         { 0,                                    NULL }
213 };
214 /* Codeset 6 */
215 static const value_string q933_info_element_vals6[] = {
216         { 0,                                    NULL }
217 };
218 /* Codeset 7 */
219 static const value_string q933_info_element_vals7[] = {
220         { 0,                                    NULL }
221 };
222
223 /* Codeset array */
224 static const value_string *q933_info_element_vals[] = {
225   q933_info_element_vals0,
226   q933_info_element_vals1,
227   q933_info_element_vals2,
228   q933_info_element_vals3,
229   q933_info_element_vals4,
230   q933_info_element_vals5,
231   q933_info_element_vals6,
232   q933_info_element_vals7,
233 };
234
235 static const value_string q933_repeat_indication_vals[] = {
236         { 0x2, "Prioritized list" },
237         { 0,   NULL }
238 };
239
240 /*
241  * ITU-standardized coding.
242  */
243 #define Q933_ITU_STANDARDIZED_CODING    0x00
244
245 /*
246  * Dissect a Segmented message information element.
247  */
248 static void
249 dissect_q933_segmented_message_ie(tvbuff_t *tvb, int offset, int len,
250     proto_tree *tree)
251 {
252         if (len != 2) {
253                 proto_tree_add_text(tree, tvb, offset, len,
254                     "Segmented message: length is %d, should be 2\n", len);
255                 return;
256         }
257         if (tvb_get_guint8(tvb, offset) & 0x80) {
258                 proto_tree_add_text(tree, tvb, offset, 1,
259                     "First segment: %u segments remaining",
260                     tvb_get_guint8(tvb, offset) & 0x7F);
261         } else {
262                 proto_tree_add_text(tree, tvb, offset, 1,
263                     "Not first segment: %u segments remaining",
264                     tvb_get_guint8(tvb, offset) & 0x7F);
265         }
266         proto_tree_add_text(tree, tvb, offset + 1, 1,
267             "Segmented message type: %u\n", tvb_get_guint8(tvb, offset + 1));
268 }
269
270 /*
271  * Dissect a Bearer capability or Low-layer compatibility information element.
272  */
273 static const value_string q933_bc_coding_standard_vals[] = {
274         { 0x00, "ITU-T standardized coding" },
275         { 0x20, "ISO/IEC standard" },
276         { 0x40, "National standard" },
277         { 0x60, "Standard defined for this particular network" },
278         { 0,    NULL }
279 };
280
281 static const value_string q933_information_transfer_capability_vals[] = {
282         { 0x08, "Unrestricted digital information" },
283         { 0,    NULL }
284 };
285
286 static const value_string q933_transfer_mode_vals[] = {
287         { 0x20, "Frame mode" },
288         { 0,    NULL }
289 };
290
291 static const value_string q933_uil1_vals[] = {
292         { 0x01, "V.110/I.460/X.30 rate adaption" },
293         { 0x02, "Recommendation G.711 u-law" },
294         { 0x03, "Recommendation G.711 A-law" },
295         { 0x04, "Recommendation G.721 32 kbit/s ADPCM and Recommendation I.460" },
296         { 0x05, "Recommendation H.221 and H.242" },
297         { 0x06, "Recommendation H.223 and H.245" },
298         { 0x07, "Non-ITU-T-standardized rate adaption" },
299         { 0x08, "V.120 rate adaption" },
300         { 0x09, "X.31 HDLC flag stuffing" },
301         { 0,    NULL },
302 };
303
304 static const value_string q933_l1_user_rate_vals[] = {
305         { 0x00, "Rate indicated by E-bits" },
306         { 0x01, "0.6 kbit/s" },
307         { 0x02, "1.2 kbit/s" },
308         { 0x03, "2.4 kbit/s" },
309         { 0x04, "3.6 kbit/s" },
310         { 0x05, "4.8 kbit/s" },
311         { 0x06, "7.2 kbit/s" },
312         { 0x07, "8 kbit/s" },
313         { 0x08, "9.6 kbit/s" },
314         { 0x09, "14.4 kbit/s" },
315         { 0x0A, "16 kbit/s" },
316         { 0x0B, "19.2 kbit/s" },
317         { 0x0C, "32 kbit/s" },
318         { 0x0E, "48 kbit/s" },
319         { 0x0F, "56 kbit/s" },
320         { 0x10, "64 kbit/s "},
321         { 0x15, "0.1345 kbit/s" },
322         { 0x16, "0.100 kbit/s" },
323         { 0x17, "0.075/1.2 kbit/s" },
324         { 0x18, "1.2/0.075 kbit/s" },
325         { 0x19, "0.050 kbit/s" },
326         { 0x1A, "0.075 kbit/s" },
327         { 0x1B, "0.110 kbit/s" },
328         { 0x1C, "0.150 kbit/s" },
329         { 0x1D, "0.200 kbit/s" },
330         { 0x1E, "0.300 kbit/s" },
331         { 0x1F, "12 kbit/s" },
332         { 0,    NULL }
333 };
334
335 static const value_string q933_l1_stop_bits_vals[] = {
336         { 0x20, "1" },
337         { 0x40, "1.5" },
338         { 0x60, "2" },
339         { 0,    NULL }
340 };
341
342 static const value_string q933_l1_data_bits_vals[] = {
343         { 0x08, "5" },
344         { 0x10, "7" },
345         { 0x18, "8" },
346         { 0,    NULL }
347 };
348
349 static const value_string q933_l1_parity_vals[] = {
350         { 0x00, "Odd" },
351         { 0x02, "Even" },
352         { 0x03, "None" },
353         { 0x04, "Forced to 0" },
354         { 0x05, "Forced to 1" },
355         { 0,    NULL }
356 };
357
358 #define Q933_UIL2_USER_SPEC     0x10
359
360 static const value_string q933_uil2_vals[] = {
361         { 0x01,                 "Basic mode ISO 1745" },
362         { 0x06,                 "X.25, link level" },
363         { 0x07,                 "X.25 multilink" },
364         { 0x08,                 "T.71 Extended LAPB" },
365         { 0x09,                 "HDLC ARM" },
366         { 0x0A,                 "HDLC NRM" },
367         { 0x0B,                 "HDLC ABM" },
368         { 0x0C,                 "ISO 8802/2 LLC" },
369         { 0x0D,                 "X.75 Single Link Procedure" },
370         { 0x0E,                 "Q.922" },
371         { 0x0F,                 "Core aspects of Q.922" },
372         { Q933_UIL2_USER_SPEC,  "User-specified" },
373         { 0x11,                 "ISO 7776 DTE-DTE operation" },
374         { 0,                    NULL }
375 };
376
377 static const value_string q933_address_inclusion_vals[] = {
378         { 0x01,                 "Address included" },
379         { 0x02,                 "Encapsulation of logical control frame" },
380         { 0,                    NULL }
381 };
382
383 static const value_string q933_mode_vals[] = {
384         { 0x20, "Normal mode" },
385         { 0x40, "Extended mode" },
386         { 0,    NULL }
387 };
388
389 #define Q933_UIL3_X25_PL        0x06
390 #define Q933_UIL3_ISO_8208      0x07    /* X.25-based */
391 #define Q933_UIL3_X223          0x08    /* X.25-based */
392 #define Q933_UIL3_TR_9577       0x0B
393 #define Q933_UIL3_USER_SPEC     0x10
394
395 static const value_string q933_uil3_vals[] = {
396         { Q933_UIL3_X25_PL,     "X.25, packet layer" },
397         { Q933_UIL3_ISO_8208,   "ISO/IEC 8208" },
398         { Q933_UIL3_X223,       "X.223/ISO 8878" },
399         { 0x09,                 "ISO/IEC 8473" },
400         { 0x0A,                 "T.70" },
401         { Q933_UIL3_TR_9577,    "ISO/IEC TR 9577" },
402         { Q933_UIL3_USER_SPEC,  "User-specified" },
403         { 0,                    NULL }
404 };
405
406 static void
407 dissect_q933_protocol_discriminator(tvbuff_t *tvb, int offset, proto_tree *tree)
408 {
409         unsigned int discriminator = tvb_get_guint8(tvb, offset);
410
411         if (discriminator == NLPID_Q_933) {
412                 proto_tree_add_uint_format(tree, hf_q933_discriminator,
413                          tvb, offset, 1, discriminator,
414                          "Protocol discriminator: Q.933");
415         } else if (discriminator == NLPID_Q_2931) {
416                 proto_tree_add_uint_format(tree, hf_q933_discriminator,
417                          tvb, offset, 1, discriminator,
418                          "Protocol discriminator: Q.2931");
419         } else if ((discriminator >= 16 && discriminator < 63)
420             || ((discriminator >= 80) && (discriminator < 254))) {
421                 proto_tree_add_uint_format(tree, hf_q933_discriminator,
422                     tvb, offset, 1, discriminator,
423                     "Protocol discriminator: Network layer or layer 3 protocol (0x%02X)",
424                     discriminator);
425         } else if (discriminator >= 64 && discriminator <= 79) {
426                 proto_tree_add_uint_format(tree, hf_q933_discriminator,
427                     tvb, offset, 1, discriminator,
428                     "Protocol discriminator: National use (0x%02X)",
429                     discriminator);
430         } else {
431                 proto_tree_add_uint_format(tree, hf_q933_discriminator,
432                     tvb, offset, 1, discriminator,
433                     "Protocol discriminator: Reserved (0x%02X)",
434                     discriminator);
435         }
436 }
437
438 void
439 dissect_q933_bearer_capability_ie(tvbuff_t *tvb, int offset, int len,
440     proto_tree *tree)
441 {
442         guint8 octet;
443         guint8 coding_standard;
444         guint8 modem_type;
445         guint8 uil2_protocol;
446         guint8 uil3_protocol;
447         guint8 add_l3_info;
448
449         if (len == 0)
450                 return;
451         octet = tvb_get_guint8(tvb, offset);
452         coding_standard = octet & 0x60;
453         proto_tree_add_text(tree, tvb, offset, 1,
454             "Coding standard: %s",
455             val_to_str(coding_standard, q933_bc_coding_standard_vals, NULL));
456         if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
457                 /*
458                  * We don't know how the bearer capability is encoded,
459                  * so just dump it as data and be done with it.
460                  */
461                 proto_tree_add_text(tree, tvb, offset,
462                     len, "Data: %s",
463                     tvb_bytes_to_str(tvb, offset, len));
464                 return;
465         }
466         proto_tree_add_text(tree, tvb, offset, 1,
467             "Information transfer capability: %s",
468             val_to_str(octet & 0x1F, q933_information_transfer_capability_vals,
469               "Unknown (0x%02X)"));
470         offset += 1;
471         len -= 1;
472
473         /*
474          * XXX - only in Low-layer compatibility information element.
475          */
476         if (!(octet & Q933_IE_VL_EXTENSION)) {
477                 if (len == 0)
478                         return;
479                 octet = tvb_get_guint8(tvb, offset);
480                 proto_tree_add_text(tree, tvb, offset, 1,
481                     "Out-band negotiation %spossible",
482                     (octet & 0x40) ? "" : "not ");
483                 offset += 1;
484                 len -= 1;
485         }
486
487         if (len == 0)
488                 return;
489         octet = tvb_get_guint8(tvb, offset);
490         proto_tree_add_text(tree, tvb, offset, 1,
491             "Transfer mode: %s",
492             val_to_str(octet & 0x60, q933_transfer_mode_vals,
493               "Unknown (0x%02X)"));
494         offset += 1;
495         len -= 1;
496
497         if (len == 0)
498                 return;
499         octet = tvb_get_guint8(tvb, offset);
500         if ((octet & 0x60) == 0x20) {
501                 /*
502                  * Layer 1 information.
503                  */
504                 proto_tree_add_text(tree, tvb, offset, 1,
505                     "User information layer 1 protocol: %s",
506                     val_to_str(octet & 0x1F, q933_uil1_vals,
507                       "Unknown (0x%02X)"));
508                 offset += 1;
509                 len -= 1;
510
511                 if (octet & Q933_IE_VL_EXTENSION)
512                         goto l1_done;
513                 if (len == 0)
514                         return;
515                 octet = tvb_get_guint8(tvb, offset);
516                 proto_tree_add_text(tree, tvb, offset, 1,
517                     "Layer 1 is %s",
518                     (octet & 0x40) ? "Asynchronous" : "Synchronous");
519                 proto_tree_add_text(tree, tvb, offset, 1,
520                     "User rate: %s",
521                     val_to_str(octet & 0x1F, q933_l1_user_rate_vals,
522                       "Unknown (0x%02X)"));
523                 offset += 1;
524                 len -= 1;
525
526                 if (octet & Q933_IE_VL_EXTENSION)
527                         goto l1_done;
528                 if (len == 0)
529                         return;
530                 octet = tvb_get_guint8(tvb, offset);
531                 proto_tree_add_text(tree, tvb, offset, 1,
532                     "Rate adaption header %sincluded",
533                     (octet & 0x40) ? "" : "not ");
534                 proto_tree_add_text(tree, tvb, offset, 1,
535                     "Multiple frame establishment %ssupported",
536                     (octet & 0x20) ? "" : "not ");
537                 proto_tree_add_text(tree, tvb, offset, 1,
538                     "%s mode of operation",
539                     (octet & 0x10) ? "Protocol sensitive" : "Bit transparent");
540                 offset += 1;
541                 len -= 1;
542
543                 if (octet & Q933_IE_VL_EXTENSION)
544                         goto l1_done;
545                 if (len == 0)
546                         return;
547                 octet = tvb_get_guint8(tvb, offset);
548                 proto_tree_add_text(tree, tvb, offset, 1,
549                     "Stop bits: %s",
550                       val_to_str(octet & 0x60, q933_l1_stop_bits_vals,
551                        "Unknown (0x%X)"));
552                 proto_tree_add_text(tree, tvb, offset, 1,
553                     "Data bits: %s",
554                       val_to_str(octet & 0x18, q933_l1_data_bits_vals,
555                        "Unknown (0x%X)"));
556                 proto_tree_add_text(tree, tvb, offset, 1,
557                     "Parity: %s",
558                       val_to_str(octet & 0x07, q933_l1_parity_vals,
559                        "Unknown (0x%X)"));
560
561                 if (octet & Q933_IE_VL_EXTENSION)
562                         goto l1_done;
563                 if (len == 0)
564                         return;
565                 octet = tvb_get_guint8(tvb, offset);
566                 proto_tree_add_text(tree, tvb, offset, 1,
567                     "%s duplex",
568                     (octet & 0x40) ? "Full" : "Half");
569                 modem_type = octet & 0x3F;
570                 proto_tree_add_text(tree, tvb, offset, 1,
571                     "Modem type: Network-specific rules 0x%02X", modem_type);
572                 offset += 1;
573                 len -= 1;
574         }
575 l1_done:
576         ;
577
578         if (len == 0)
579                 return;
580         octet = tvb_get_guint8(tvb, offset);
581         if ((octet & 0x60) == 0x40) {
582                 /*
583                  * Layer 2 information.
584                  */
585                 uil2_protocol = octet & 0x1F;
586                 proto_tree_add_text(tree, tvb, offset, 1,
587                     "User information layer 2 protocol: %s",
588                     val_to_str(uil2_protocol, q933_uil2_vals,
589                       "Unknown (0x%02X)"));
590                 offset += 1;
591                 len -= 1;
592
593                 /*
594                  * XXX - only in Low-layer compatibility information element.
595                  */
596                 if (octet & Q933_IE_VL_EXTENSION)
597                         goto l2_done;
598                 if (len == 0)
599                         return;
600                 octet = tvb_get_guint8(tvb, offset);
601                 if (uil2_protocol == Q933_UIL2_USER_SPEC) {
602                         proto_tree_add_text(tree, tvb, offset, 1,
603                             "User-specified layer 2 protocol information: 0x%02X",
604                             octet & 0x7F);
605                 } else {
606                         proto_tree_add_text(tree, tvb, offset, 1,
607                             "Address inclusion: %s",
608                             val_to_str(octet & 0x03, q933_address_inclusion_vals,
609                               "Unknown (0x%02X)"));
610                 }
611                 offset += 1;
612                 len -= 1;
613         }
614 l2_done:
615         ;
616
617         if (len == 0)
618                 return;
619         octet = tvb_get_guint8(tvb, offset);
620         if ((octet & 0x60) == 0x60) {
621                 /*
622                  * Layer 3 information.
623                  */
624                 uil3_protocol = octet & 0x1F;
625                 proto_tree_add_text(tree, tvb, offset, 1,
626                     "User information layer 3 protocol: %s",
627                     val_to_str(uil3_protocol, q933_uil3_vals,
628                       "Unknown (0x%02X)"));
629                 offset += 1;
630                 len -= 1;
631
632
633                 /*
634                  * XXX - only in Low-layer compatibility information element.
635                  */
636                 if (octet & Q933_IE_VL_EXTENSION)
637                         goto l3_done;
638                 if (len == 0)
639                         return;
640                 octet = tvb_get_guint8(tvb, offset);
641                 switch (uil3_protocol) {
642
643                 case Q933_UIL3_X25_PL:
644                 case Q933_UIL3_ISO_8208:
645                 case Q933_UIL3_X223:
646                         proto_tree_add_text(tree, tvb, offset, 1,
647                             "Mode: %s",
648                             val_to_str(octet & 0x60, q933_mode_vals,
649                               "Unknown (0x%02X)"));
650                         offset += 1;
651                         len -= 1;
652
653                         if (octet & Q933_IE_VL_EXTENSION)
654                                 goto l3_done;
655                         if (len == 0)
656                                 return;
657                         octet = tvb_get_guint8(tvb, offset);
658                         proto_tree_add_text(tree, tvb, offset, 1,
659                             "Default packet size: %u", octet & 0x0F);
660                         offset += 1;
661                         len -= 1;
662
663                         if (octet & Q933_IE_VL_EXTENSION)
664                                 goto l3_done;
665                         if (len == 0)
666                                 return;
667                         octet = tvb_get_guint8(tvb, offset);
668                         proto_tree_add_text(tree, tvb, offset, 1,
669                             "Packet window size: %u", octet & 0x7F);
670                         offset += 1;
671                         len -= 1;
672                         break;
673
674                 case Q933_UIL3_USER_SPEC:
675                         proto_tree_add_text(tree, tvb, offset, 1,
676                             "Default packet size: %u octets",
677                             1 << (octet & 0x0F));
678                         offset += 1;
679                         len -= 1;
680                         break;
681
682                 case Q933_UIL3_TR_9577:
683                         add_l3_info = (octet & 0x0F) << 4;
684                         if (octet & Q933_IE_VL_EXTENSION)
685                                 goto l3_done;
686                         if (len == 0)
687                                 return;
688                         octet = tvb_get_guint8(tvb, offset + 1);
689                         add_l3_info |= (octet & 0x0F);
690                         proto_tree_add_text(tree, tvb, offset, 2,
691                             "Additional layer 3 protocol information: %s",
692                             val_to_str(add_l3_info, nlpid_vals,
693                               "Unknown (0x%02X)"));
694                         offset += 2;
695                         len -= 2;
696                         break;
697                 }
698         }
699 l3_done:
700         ;
701 }
702
703 /*
704  * Dissect a Cause information element.
705  */
706 static const value_string q933_cause_coding_standard_vals[] = {
707         { 0x00, "ITU-T standardized coding" },
708         { 0x20, "ISO/IEC standard" },
709         { 0x40, "National standard" },
710         { 0x60, "Standard specific to identified location" },
711         { 0,    NULL }
712 };
713
714 const value_string q933_cause_location_vals[] = {
715         { 0x00, "User (U)" },
716         { 0x01, "Private network serving the local user (LPN)" },
717         { 0x02, "Public network serving the local user (LN)" },
718         { 0x03, "Transit network (TN)" },
719         { 0x04, "Public network serving the remote user (RLN)" },
720         { 0x05, "Private network serving the remote user (RPN)" },
721         { 0x07, "International network (INTL)" },
722         { 0x0A, "Network beyond interworking point (BI)" },
723         { 0,    NULL }
724 };
725
726 static const value_string q933_cause_recommendation_vals[] = {
727         { 0x00, "Q.933" },
728         { 0x03, "X.21" },
729         { 0x04, "X.25" },
730         { 0x05, "Q.1031/Q.1051" },
731         { 0,    NULL }
732 };
733
734 /*
735  * Cause codes for Cause.
736  */
737 #define Q933_CAUSE_UNALLOC_NUMBER       0x01
738 #define Q933_CAUSE_NO_ROUTE_TO_DEST     0x03
739 #define Q933_CAUSE_CALL_REJECTED        0x15
740 #define Q933_CAUSE_NUMBER_CHANGED       0x16
741 #define Q933_CAUSE_ACCESS_INFO_DISC     0x2B
742 #define Q933_CAUSE_QOS_UNAVAILABLE      0x31
743 #define Q933_CAUSE_CHAN_NONEXISTENT     0x52
744 #define Q933_CAUSE_INCOMPATIBLE_DEST    0x58
745 #define Q933_CAUSE_MAND_IE_MISSING      0x60
746 #define Q933_CAUSE_MT_NONEX_OR_UNIMPL   0x61
747 #define Q933_CAUSE_IE_NONEX_OR_UNIMPL   0x63
748 #define Q933_CAUSE_INVALID_IE_CONTENTS  0x64
749 #define Q933_CAUSE_MSG_INCOMPAT_W_CS    0x65
750 #define Q933_CAUSE_REC_TIMER_EXP        0x66
751
752 const value_string q933_cause_code_vals[] = {
753         { 0x00,                         "Valid cause code not yet received" },
754         { Q933_CAUSE_UNALLOC_NUMBER,    "Unallocated (unassigned) number" },
755         { 0x02,                         "No route to specified transit network" },
756         { Q933_CAUSE_NO_ROUTE_TO_DEST,  "No route to destination" },
757         { 0x04,                         "Send special information tone" },
758         { 0x05,                         "Misdialled trunk prefix" },
759         { 0x06,                         "Channel unacceptable" },
760         { 0x07,                         "Call awarded and being delivered in an established channel" },
761         { 0x08,                         "Prefix 0 dialed but not allowed" },
762                                         /* Q.850 - "Preemption" */
763         { 0x09,                         "Prefix 1 dialed but not allowed" },
764                                         /* Q.850 - "Preemption - circuit reserved for reuse" */
765         { 0x0A,                         "Prefix 1 dialed but not required" },
766         { 0x0B,                         "More digits received than allowed, call is proceeding" },
767         { 0x0E,                         "QoR: ported number" },
768         { 0x10,                         "Normal call clearing" },
769         { 0x11,                         "User busy" },
770         { 0x12,                         "No user responding" },
771         { 0x13,                         "No answer from user (user alerted)" },
772         { 0x14,                         "Subscriber absent" },
773         { Q933_CAUSE_CALL_REJECTED,     "Call rejected" },
774         { Q933_CAUSE_NUMBER_CHANGED,    "Number changed" },
775         { 0x17,                         "Reverse charging rejected" },
776                                         /* Q.850 - "Redirection to new destination" */
777         { 0x18,                         "Call suspended" },
778                                         /* Q.850 Amendment 1 - "Call rejected due to feature at the destination" */
779         { 0x19,                         "Call resumed" },
780                                         /* Q.850 - "Exchange routing error */
781         { 0x1A,                         "Non-selected user clearing" },
782         { 0x1B,                         "Destination out of order" },
783         { 0x1C,                         "Invalid number format (incomplete number)" },
784         { 0x1D,                         "Facility rejected" },
785         { 0x1E,                         "Response to STATUS ENQUIRY" },
786         { 0x1F,                         "Normal unspecified" },
787         { 0x21,                         "Circuit out of order" },
788         { 0x22,                         "No circuit/channel available" },
789         { 0x23,                         "Destination unattainable" },
790         { 0x25,                         "Degraded service" },
791         { 0x26,                         "Network out of order" },
792         { 0x27,                         "Transit delay range cannot be achieved" },
793                                         /* Q.850 - "Permanent frame mode connection out of service" */
794         { 0x28,                         "Throughput range cannot be achieved" },
795                                         /* Q.850 - "Permanent frame mode connection operational" */
796         { 0x29,                         "Temporary failure" },
797         { 0x2A,                         "Switching equipment congestion" },
798         { Q933_CAUSE_ACCESS_INFO_DISC,  "Access information discarded" },
799         { 0x2C,                         "Requested circuit/channel not available" },
800         { 0x2D,                         "Pre-empted" },
801         { 0x2E,                         "Precedence call blocked" },
802         { 0x2F,                         "Resources unavailable, unspecified" },
803         { Q933_CAUSE_QOS_UNAVAILABLE,   "Quality of service unavailable" },
804         { 0x32,                         "Requested facility not subscribed" },
805         { 0x33,                         "Reverse charging not allowed" },
806         { 0x34,                         "Outgoing calls barred" },
807         { 0x35,                         "Outgoing calls barred within CUG" },
808         { 0x36,                         "Incoming calls barred" },
809         { 0x37,                         "Incoming calls barred within CUG" },
810         { 0x38,                         "Call waiting not subscribed" },
811         { 0x39,                         "Bearer capability not authorized" },
812         { 0x3A,                         "Bearer capability not presently available" },
813         { 0x3E,                         "Inconsistency in designated outgoing access information and subscriber class" },
814         { 0x3F,                         "Service or option not available, unspecified" },
815         { 0x41,                         "Bearer capability not implemented" },
816         { 0x42,                         "Channel type not implemented" },
817         { 0x43,                         "Transit network selection not implemented" },
818         { 0x44,                         "Message not implemented" },
819         { 0x45,                         "Requested facility not implemented" },
820         { 0x46,                         "Only restricted digital information bearer capability is available" },
821         { 0x4F,                         "Service or option not implemented, unspecified" },
822         { 0x51,                         "Invalid call reference value" },
823         { Q933_CAUSE_CHAN_NONEXISTENT,  "Identified channel does not exist" },
824         { 0x53,                         "Call identity does not exist for suspended call" },
825         { 0x54,                         "Call identity in use" },
826         { 0x55,                         "No call suspended" },
827         { 0x56,                         "Call having the requested call identity has been cleared" },
828         { 0x57,                         "Called user not member of CUG" },
829         { Q933_CAUSE_INCOMPATIBLE_DEST, "Incompatible destination" },
830         { 0x59,                         "Non-existent abbreviated address entry" },
831         { 0x5A,                         "Destination address missing, and direct call not subscribed" },
832                                         /* Q.850 - "Non-existent CUG" */
833         { 0x5B,                         "Invalid transit network selection (national use)" },
834         { 0x5C,                         "Invalid facility parameter" },
835         { 0x5D,                         "Mandatory information element is missing" },
836         { 0x5F,                         "Invalid message, unspecified" },
837         { Q933_CAUSE_MAND_IE_MISSING,   "Mandatory information element is missing" },
838         { Q933_CAUSE_MT_NONEX_OR_UNIMPL,"Message type non-existent or not implemented" },
839         { 0x62,                         "Message not compatible with call state or message type non-existent or not implemented" },
840         { Q933_CAUSE_IE_NONEX_OR_UNIMPL,"Information element nonexistant or not implemented" },
841         { Q933_CAUSE_INVALID_IE_CONTENTS,"Invalid information element contents" },
842         { Q933_CAUSE_MSG_INCOMPAT_W_CS, "Message not compatible with call state" },
843         { Q933_CAUSE_REC_TIMER_EXP,     "Recovery on timer expiry" },
844         { 0x67,                         "Parameter non-existent or not implemented - passed on" },
845         { 0x6E,                         "Message with unrecognized parameter discarded" },
846         { 0x6F,                         "Protocol error, unspecified" },
847         { 0x7F,                         "Internetworking, unspecified" },
848         { 0,                            NULL }
849 };
850
851 static const value_string q933_cause_condition_vals[] = {
852         { 0x00, "Unknown" },
853         { 0x01, "Permanent" },
854         { 0x02, "Transient" },
855         { 0x00, NULL }
856 };
857
858 #define Q933_REJ_USER_SPECIFIC          0x00
859 #define Q933_REJ_IE_MISSING             0x04
860 #define Q933_REJ_IE_INSUFFICIENT        0x08
861
862 static const value_string q933_rejection_reason_vals[] = {
863         { 0x00, "User specific" },
864         { 0x04, "Information element missing" },
865         { 0x08, "Information element contents are not sufficient" },
866         { 0x00, NULL }
867 };
868
869 void
870 dissect_q933_cause_ie(tvbuff_t *tvb, int offset, int len,
871     proto_tree *tree, int hf_cause_value)
872 {
873         guint8 octet;
874         guint8 cause_value;
875         guint8 coding_standard;
876         guint8 rejection_reason;
877
878         if (len == 0)
879                 return;
880         octet = tvb_get_guint8(tvb, offset);
881         coding_standard = octet & 0x60;
882         proto_tree_add_text(tree, tvb, offset, 1,
883             "Coding standard: %s",
884             val_to_str(coding_standard, q933_cause_coding_standard_vals, NULL));
885         if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
886                 /*
887                  * We don't know how the cause is encoded,
888                  * so just dump it as data and be done with it.
889                  */
890                 proto_tree_add_text(tree, tvb, offset,
891                     len, "Data: %s",
892                     tvb_bytes_to_str(tvb, offset, len));
893                 return;
894         }
895         proto_tree_add_text(tree, tvb, offset, 1,
896             "Location: %s",
897             val_to_str(octet & 0x0F, q933_cause_location_vals,
898               "Unknown (0x%X)"));
899         offset += 1;
900         len -= 1;
901
902         if (!(octet & Q933_IE_VL_EXTENSION)) {
903                 if (len == 0)
904                         return;
905                 octet = tvb_get_guint8(tvb, offset);
906                 proto_tree_add_text(tree, tvb, offset, 1,
907                     "Recommendation: %s",
908                     val_to_str(octet & 0x7F, q933_cause_recommendation_vals,
909                       "Unknown (0x%02X)"));
910                 offset += 1;
911                 len -= 1;
912         }
913
914         if (len == 0)
915                 return;
916         octet = tvb_get_guint8(tvb, offset);
917         cause_value = octet & 0x7F;
918         proto_tree_add_uint(tree, hf_cause_value, tvb, 0, 1, cause_value);
919         offset += 1;
920         len -= 1;
921
922         if (len == 0)
923                 return;
924         switch (cause_value) {
925
926         case Q933_CAUSE_UNALLOC_NUMBER:
927         case Q933_CAUSE_NO_ROUTE_TO_DEST:
928         case Q933_CAUSE_QOS_UNAVAILABLE:
929                 octet = tvb_get_guint8(tvb, offset);
930                 proto_tree_add_text(tree, tvb, offset, 1,
931                     "Network service: %s",
932                     (octet & 0x80) ? "User" : "Provider");
933                 proto_tree_add_text(tree, tvb, offset, 1,
934                     "%s",
935                     (octet & 0x40) ? "Abnormal" : "Normal");
936                 proto_tree_add_text(tree, tvb, offset, 1,
937                     "Condition: %s",
938                     val_to_str(octet & 0x03, q933_cause_condition_vals,
939                       "Unknown (0x%X)"));
940                 break;
941
942         case Q933_CAUSE_CALL_REJECTED:
943                 rejection_reason = octet & 0x7C;
944                 proto_tree_add_text(tree, tvb, offset, 1,
945                     "Rejection reason: %s",
946                     val_to_str(octet & 0x7C, q933_rejection_reason_vals,
947                       "Unknown (0x%X)"));
948                 proto_tree_add_text(tree, tvb, offset, 1,
949                     "Condition: %s",
950                     val_to_str(octet & 0x03, q933_cause_condition_vals,
951                       "Unknown (0x%X)"));
952                 offset += 1;
953                 len -= 1;
954
955                 if (len == 0)
956                         return;
957                 switch (rejection_reason) {
958
959                 case Q933_REJ_USER_SPECIFIC:
960                         proto_tree_add_text(tree, tvb, offset, len,
961                             "User specific diagnostic: %s",
962                             tvb_bytes_to_str(tvb, offset, len));
963                         break;
964
965                 case Q933_REJ_IE_MISSING:
966                         proto_tree_add_text(tree, tvb, offset, 1,
967                             "Missing information element: %s",
968                             val_to_str(tvb_get_guint8(tvb, offset), q933_info_element_vals0,
969                               "Unknown (0x%02X)"));
970                         break;
971
972                 case Q933_REJ_IE_INSUFFICIENT:
973                         proto_tree_add_text(tree, tvb, offset, 1,
974                             "Insufficient information element: %s",
975                             val_to_str(tvb_get_guint8(tvb, offset), q933_info_element_vals0,
976                               "Unknown (0x%02X)"));
977                         break;
978
979                 default:
980                         proto_tree_add_text(tree, tvb, offset, len,
981                             "Diagnostic: %s",
982                             tvb_bytes_to_str(tvb, offset, len));
983                         break;
984                 }
985                 break;
986
987         case Q933_CAUSE_ACCESS_INFO_DISC:
988         case Q933_CAUSE_INCOMPATIBLE_DEST:
989         case Q933_CAUSE_MAND_IE_MISSING:
990         case Q933_CAUSE_IE_NONEX_OR_UNIMPL:
991         case Q933_CAUSE_INVALID_IE_CONTENTS:
992                 do {
993                         proto_tree_add_text(tree, tvb, offset, 1,
994                             "Information element: %s",
995                             val_to_str(tvb_get_guint8(tvb, offset), q933_info_element_vals0,
996                               "Unknown (0x%02X)"));
997                         offset += 1;
998                         len -= 1;
999                 } while (len != 0);
1000                 break;
1001
1002         case Q933_CAUSE_MT_NONEX_OR_UNIMPL:
1003         case Q933_CAUSE_MSG_INCOMPAT_W_CS:
1004                 proto_tree_add_text(tree, tvb, offset, 1,
1005                     "Message type: %s",
1006                     val_to_str(tvb_get_guint8(tvb, offset), q933_message_type_vals,
1007                       "Unknown (0x%02X)"));
1008                 break;
1009
1010         case Q933_CAUSE_REC_TIMER_EXP:
1011                 if (len < 3)
1012                         return;
1013                 proto_tree_add_text(tree, tvb, offset, 3,
1014                     "Timer: %.3s", tvb_get_ptr(tvb, offset, 3));
1015                 break;
1016
1017         default:
1018                 proto_tree_add_text(tree, tvb, offset, len,
1019                     "Diagnostics: %s",
1020                     tvb_bytes_to_str(tvb, offset, len));
1021         }
1022 }
1023
1024 /*
1025  * Dissect a Call state information element.
1026  */
1027 static const value_string q933_coding_standard_vals[] = {
1028         { 0x00, "ITU-T standardized coding" },
1029         { 0x20, "ISO/IEC standard" },
1030         { 0x40, "National standard" },
1031         { 0x60, "Standard defined for the network" },
1032         { 0,    NULL }
1033 };
1034
1035 static const value_string q933_call_state_vals[] = {
1036         { 0x00, "Null" },
1037         { 0x01, "Call initiated" },
1038         { 0x02, "Overlap sending" },
1039         { 0x03, "Outgoing call proceeding" },
1040         { 0x04, "Call delivered" },
1041         { 0x06, "Call present" },
1042         { 0x07, "Call received" },
1043         { 0x08, "Connect request" },
1044         { 0x09, "Incoming call proceeding" },
1045         { 0x0A, "Active" },
1046         { 0x0B, "Disconnect request" },
1047         { 0x0C, "Disconnect indication" },
1048         { 0x0F, "Suspend request" },
1049         { 0x12, "Resume request" },
1050         { 0x13, "Release request" },
1051         { 0x16, "Call abort"},
1052         { 0x19, "Overlap receiving" },
1053         { 0x3D, "Restart request" },
1054         { 0x3E, "Restart" },
1055         { 0,    NULL }
1056 };
1057
1058 static void
1059 dissect_q933_call_state_ie(tvbuff_t *tvb, int offset, int len,
1060     proto_tree *tree)
1061 {
1062         guint8 octet;
1063         guint8 coding_standard;
1064
1065         if (len == 0)
1066                 return;
1067         octet = tvb_get_guint8(tvb, offset);
1068         coding_standard = octet & 0x60;
1069         proto_tree_add_text(tree, tvb, offset, 1,
1070             "Coding standard: %s",
1071             val_to_str(coding_standard, q933_coding_standard_vals, NULL));
1072         if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
1073                 /*
1074                  * We don't know how the call state is encoded,
1075                  * so just dump it as data and be done with it.
1076                  */
1077                 proto_tree_add_text(tree, tvb, offset,
1078                     len, "Data: %s",
1079                     tvb_bytes_to_str(tvb, offset, len));
1080                 return;
1081         }
1082         proto_tree_add_text(tree, tvb, offset, 1,
1083             "Call state: %s",
1084             val_to_str(octet & 0x3F, q933_call_state_vals,
1085               "Unknown (0x%02X)"));
1086 }
1087
1088 /*
1089  * Dissect a Channel identification information element.
1090  */
1091 #define Q933_INTERFACE_IDENTIFIED       0x40
1092 #define Q933_NOT_BASIC_CHANNEL          0x20
1093
1094 static const value_string q933_basic_channel_selection_vals[] = {
1095         { 0x00, "No channel" },
1096         { 0x01, "B1 channel" },
1097         { 0x02, "B2 channel" },
1098         { 0x03, "Any channel" },
1099         { 0,    NULL }
1100 };
1101
1102 static const value_string q933_not_basic_channel_selection_vals[] = {
1103         { 0x00, "No channel" },
1104         { 0x01, "Channel indicated in following octets" },
1105         { 0x03, "Any channel" },
1106         { 0,    NULL }
1107 };
1108
1109 #define Q933_IS_SLOT_MAP                0x10
1110
1111 static const value_string q933_element_type_vals[] = {
1112         { 0x03, "B-channel units" },
1113         { 0x06, "H0-channel units" },
1114         { 0x08, "H11-channel units" },
1115         { 0x09, "H12-channel units" },
1116         { 0,    NULL }
1117 };
1118
1119 static void
1120 dissect_q933_channel_identification_ie(tvbuff_t *tvb, int offset, int len,
1121     proto_tree *tree)
1122 {
1123         guint8 octet;
1124         int identifier_offset;
1125         int identifier_len;
1126         guint8 coding_standard;
1127
1128         if (len == 0)
1129                 return;
1130         octet = tvb_get_guint8(tvb, offset);
1131         proto_tree_add_text(tree, tvb, offset, 1,
1132             "Interface %s identified",
1133             (octet & Q933_INTERFACE_IDENTIFIED) ? "explicitly" : "implicitly");
1134         proto_tree_add_text(tree, tvb, offset, 1,
1135             "%s interface",
1136             (octet & Q933_NOT_BASIC_CHANNEL) ? "Not basic" : "Basic");
1137         proto_tree_add_text(tree, tvb, offset, 1,
1138             "Indicated channel is %s",
1139             (octet & 0x08) ? "required" : "preferred");
1140         proto_tree_add_text(tree, tvb, offset, 1,
1141             "Indicated channel is %sthe D-channel",
1142             (octet & 0x04) ? "" : "not ");
1143         if (octet & Q933_NOT_BASIC_CHANNEL) {
1144                 proto_tree_add_text(tree, tvb, offset, 1,
1145                     "Channel selection: %s",
1146                     val_to_str(octet & 0x03, q933_not_basic_channel_selection_vals,
1147                       "Unknown (0x%X)"));
1148         } else {
1149                 proto_tree_add_text(tree, tvb, offset, 1,
1150                     "Channel selection: %s",
1151                     val_to_str(octet & 0x03, q933_basic_channel_selection_vals,
1152                       NULL));
1153         }
1154         offset += 1;
1155         len -= 1;
1156
1157         if (octet & Q933_INTERFACE_IDENTIFIED) {
1158                 identifier_offset = offset;
1159                 identifier_len = 0;
1160                 do {
1161                         if (len == 0)
1162                                 break;
1163                         octet = tvb_get_guint8(tvb, offset);
1164                         offset += 1;
1165                         len -= 1;
1166                         identifier_len++;
1167                 } while (!(octet & Q933_IE_VL_EXTENSION));
1168
1169                 /*
1170                  * XXX - do we want to strip off the 8th bit on the
1171                  * last octet of the interface identifier?
1172                  */
1173                 if (identifier_len != 0) {
1174                         proto_tree_add_text(tree, tvb, identifier_offset,
1175                             identifier_len, "Interface identifier: %s",
1176                             bytes_to_str(
1177                               tvb_get_ptr(tvb, identifier_offset, identifier_len),
1178                               identifier_len));
1179                 }
1180         }
1181
1182         if (octet & Q933_NOT_BASIC_CHANNEL) {
1183                 if (len == 0)
1184                         return;
1185                 octet = tvb_get_guint8(tvb, offset);
1186                 coding_standard = octet & 0x60;
1187                 proto_tree_add_text(tree, tvb, offset, 1,
1188                     "Coding standard: %s",
1189                     val_to_str(coding_standard, q933_coding_standard_vals,
1190                       NULL));
1191                 if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
1192                         /*
1193                          * We don't know how the channel identifier is
1194                          * encoded, so just dump it as data and be done
1195                          * with it.
1196                          */
1197                         proto_tree_add_text(tree, tvb, offset,
1198                             len, "Data: %s",
1199                             tvb_bytes_to_str(tvb, offset, len));
1200                         return;
1201                 }
1202                 proto_tree_add_text(tree, tvb, offset, 1,
1203                     "Channel is indicated by %s",
1204                     (octet & Q933_IS_SLOT_MAP) ? "slot map" : "number");
1205                 proto_tree_add_text(tree, tvb, offset, 1,
1206                     "%s type: %s",
1207                     (octet & Q933_IS_SLOT_MAP) ? "Map element" : "Channel",
1208                     val_to_str(octet & 0x0F, q933_element_type_vals,
1209                         "Unknown (0x%02X)"));
1210
1211                 /*
1212                  * XXX - dump the channel number or slot map.
1213                  */
1214         }
1215 }
1216
1217 /*
1218  * Dissect a Progress indicator information element.
1219  */
1220 static const value_string q933_progress_description_vals[] = {
1221         { 0x01, "Call is not end-to-end ISDN - progress information available in-band" },
1222         { 0x02, "Destination address is non-ISDN" },
1223         { 0x03, "Origination address is non-ISDN" },
1224         { 0x04, "Call has returned to the ISDN" },
1225         { 0x05, "Interworking has occurred and has resulted in a telecommunications service change" },
1226         { 0x08, "In-band information or an appropriate pattern is now available" },
1227         { 0,    NULL }
1228 };
1229
1230 void
1231 dissect_q933_progress_indicator_ie(tvbuff_t *tvb, int offset, int len,
1232     proto_tree *tree)
1233 {
1234         guint8 octet;
1235         guint8 coding_standard;
1236
1237         if (len == 0)
1238                 return;
1239         octet = tvb_get_guint8(tvb, offset);
1240         coding_standard = octet & 0x60;
1241         proto_tree_add_text(tree, tvb, offset, 1,
1242             "Coding standard: %s",
1243             val_to_str(coding_standard, q933_cause_coding_standard_vals, NULL));
1244         if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
1245                 /*
1246                  * We don't know how the progress indicator is encoded,
1247                  * so just dump it as data and be done with it.
1248                  */
1249                 proto_tree_add_text(tree, tvb, offset,
1250                     len, "Data: %s",
1251                     tvb_bytes_to_str(tvb, offset, len));
1252                 return;
1253         }
1254         proto_tree_add_text(tree, tvb, offset, 1,
1255             "Location: %s",
1256             val_to_str(octet & 0x0F, q933_cause_location_vals,
1257               "Unknown (0x%X)"));
1258         offset += 1;
1259         len -= 1;
1260
1261         if (len == 0)
1262                 return;
1263         octet = tvb_get_guint8(tvb, offset);
1264         proto_tree_add_text(tree, tvb, offset, 1,
1265             "Progress description: %s",
1266             val_to_str(octet & 0x7F, q933_progress_description_vals,
1267               "Unknown (0x%02X)"));
1268 }
1269
1270 /*
1271  * Dissect a Network-specific facilities or Transit network selection
1272  * information element.
1273  */
1274 static const value_string q933_netid_type_vals[] = {
1275         { 0x00, "User specified" },
1276         { 0x20, "National network identification" },
1277         { 0x30, "International network identification" },
1278         { 0,    NULL }
1279 };
1280
1281 static const value_string q933_netid_plan_vals[] = {
1282         { 0x00, "Unknown" },
1283         { 0x01, "Carrier Identification Code" },
1284         { 0x03, "X.121 data network identification code" },
1285         { 0,    NULL }
1286 };
1287
1288 static void
1289 dissect_q933_ns_facilities_ie(tvbuff_t *tvb, int offset, int len,
1290     proto_tree *tree)
1291 {
1292         guint8 octet;
1293         int netid_len;
1294
1295         if (len == 0)
1296                 return;
1297         octet = tvb_get_guint8(tvb, offset);
1298         netid_len = octet & 0x7F;
1299         proto_tree_add_text(tree, tvb, offset, 1,
1300             "Network identification length: %u",
1301             netid_len);
1302         offset += 1;
1303         len -= 1;
1304         if (netid_len != 0) {
1305                 if (len == 0)
1306                         return;
1307                 octet = tvb_get_guint8(tvb, offset);
1308                 proto_tree_add_text(tree, tvb, offset, 1,
1309                     "Type of network identification: %s",
1310                     val_to_str(octet & 0x70, q933_netid_type_vals,
1311                       "Unknown (0x%02X)"));
1312                 proto_tree_add_text(tree, tvb, offset, 1,
1313                     "Network identification plan: %s",
1314                     val_to_str(octet & 0x0F, q933_netid_plan_vals,
1315                       "Unknown (0x%02X)"));
1316                 offset += 1;
1317                 len -= 1;
1318                 netid_len--;
1319
1320                 if (len == 0)
1321                         return;
1322                 if (netid_len > len)
1323                         netid_len = len;
1324                 if (netid_len != 0) {
1325                         proto_tree_add_text(tree, tvb, offset, netid_len,
1326                             "Network identification: %s",
1327                             tvb_format_text(tvb, offset, netid_len));
1328                         offset += netid_len;
1329                         len -= netid_len;
1330                 }
1331         }
1332
1333         /*
1334          * Whatever is left is the network-specific facility
1335          * specification.
1336          */
1337          if (len == 0)
1338                 return;
1339         proto_tree_add_text(tree, tvb, offset,
1340             len, "Network-specific facility specification: %s",
1341             tvb_bytes_to_str(tvb, offset, len));
1342 }
1343
1344 static int
1345 dissect_q933_guint16_value(tvbuff_t *tvb, int offset, int len,
1346     proto_tree *tree, char *label)
1347 {
1348         guint8 octet;
1349         guint16 value;
1350         int value_len;
1351
1352         value_len = 0;
1353
1354         octet = tvb_get_guint8(tvb, offset);
1355         if (octet & Q933_IE_VL_EXTENSION) {
1356                 /*
1357                  * Only one octet long - error.
1358                  */
1359                 goto bad_length;
1360         }
1361         value = (octet & 0x3) << 14;
1362         offset += 1;
1363         len -= 1;
1364         value_len++;
1365
1366         if (len == 0) {
1367                 /*
1368                  * We've reached the end of the information element - error.
1369                  */
1370                 goto past_end;
1371         }
1372         octet = tvb_get_guint8(tvb, offset);
1373         if (octet & Q933_IE_VL_EXTENSION) {
1374                 /*
1375                  * Only two octets long - error.
1376                  */
1377                 goto bad_length;
1378         }
1379         value |= (octet & 0x7F) << 7;
1380         offset += 1;
1381         len -= 1;
1382         value_len++;
1383
1384         if (len == 0) {
1385                 /*
1386                  * We've reached the end of the information element - error.
1387                  */
1388                 goto past_end;
1389         }
1390         octet = tvb_get_guint8(tvb, offset);
1391         if (!(octet & Q933_IE_VL_EXTENSION)) {
1392                 /*
1393                  * More than three octets long - error.
1394                  */
1395                 goto bad_length;
1396         }
1397         value |= (octet & 0x7F);
1398         offset += 1;
1399         len -= 1;
1400         value_len++;
1401
1402         proto_tree_add_text(tree, tvb, offset, value_len, "%s: %u ms", label,
1403             value);
1404         return value_len;
1405
1406 past_end:
1407         proto_tree_add_text(tree, tvb, offset, len,
1408             "%s goes past end of information element", label);
1409         return -1;
1410
1411 bad_length:
1412         proto_tree_add_text(tree, tvb, offset, len, "%s isn't 3 octets long",
1413             label);
1414         return -1;
1415 }
1416
1417 /*
1418  * Dissect an End-to-end transit delay information element.
1419  */
1420 static void
1421 dissect_q933_e2e_transit_delay_ie(tvbuff_t *tvb, int offset, int len,
1422     proto_tree *tree)
1423 {
1424         int value_len;
1425
1426         if (len == 0)
1427                 return;
1428         value_len = dissect_q933_guint16_value(tvb, offset, len, tree,
1429             "Cumulative transit delay");
1430         if (value_len < 0)
1431                 return; /* error */
1432         offset += value_len;
1433         len -= value_len;
1434
1435         if (len == 0)
1436                 return;
1437         value_len = dissect_q933_guint16_value(tvb, offset, len, tree,
1438             "Requested end-to-end transit delay");
1439         if (value_len < 0)
1440                 return; /* error */
1441         offset += value_len;
1442         len -= value_len;
1443
1444         if (len == 0)
1445                 return;
1446         value_len = dissect_q933_guint16_value(tvb, offset, len, tree,
1447             "Maximum end-to-end transit delay");
1448 }
1449
1450 /*
1451  * Dissect a Transit delay selection and indication information element.
1452  */
1453 static void
1454 dissect_q933_td_selection_and_int_ie(tvbuff_t *tvb, int offset, int len,
1455     proto_tree *tree)
1456 {
1457         if (len == 0)
1458                 return;
1459         dissect_q933_guint16_value(tvb, offset, len, tree,
1460             "Transit delay");
1461 }
1462
1463 static void
1464 dissect_q933_pl_binary_parameters_ie(tvbuff_t *tvb, int offset, int len,
1465     proto_tree *tree)
1466 {
1467         guint8 octet;
1468
1469         if (len == 0)
1470                 return;
1471         octet = tvb_get_guint8(tvb, offset);
1472         proto_tree_add_text(tree, tvb, offset, 1,
1473             "%s",
1474             (octet & 0x04) ? "No request/request denied" :
1475                              "Request indicated/request accepted");
1476         proto_tree_add_text(tree, tvb, offset, 1,
1477             "%s confirmation",
1478             (octet & 0x02) ? "Link-by-link" : "End-to-end");
1479 }
1480
1481 /*
1482  * Dissect a Reverse charging indication information element.
1483  */
1484 static const value_string q933_reverse_charging_indication_vals[] = {
1485         { 0x01, "Reverse charging requested" },
1486         { 0,    NULL }
1487 };
1488
1489 static void
1490 dissect_q933_reverse_charge_ind_ie(tvbuff_t *tvb, int offset, int len,
1491     proto_tree *tree)
1492 {
1493         if (len == 0)
1494                 return;
1495         proto_tree_add_text(tree, tvb, offset, 1,
1496             "Reverse charging indication: %s",
1497             val_to_str(tvb_get_guint8(tvb, offset) & 0x07,
1498               q933_reverse_charging_indication_vals, "Unknown (0x%02X)"));
1499 }
1500
1501 /*
1502  * Dissect a (phone) number information element.
1503  */
1504 static const value_string q933_number_type_vals[] = {
1505         { 0x00, "Unknown" },
1506         { 0x10, "International number" },
1507         { 0x20, "National number" },
1508         { 0x30, "Network specific number" },
1509         { 0x40, "Subscriber number" },
1510         { 0x60, "Abbreviated number" },
1511         { 0,    NULL }
1512 };
1513
1514 static const value_string q933_numbering_plan_vals[] = {
1515         { 0x00, "Unknown" },
1516         { 0x01, "E.164 ISDN/telephony numbering" },
1517         { 0x03, "X.121 data numbering" },
1518         { 0x04, "F.69 Telex numbering" },
1519         { 0x08, "National standard numbering" },
1520         { 0x09, "Private numbering" },
1521         { 0,    NULL }
1522 };
1523
1524 static const value_string q933_presentation_indicator_vals[] = {
1525         { 0x00, "Presentation allowed" },
1526         { 0x20, "Presentation restricted" },
1527         { 0x40, "Number not available due to interworking" },
1528         { 0,    NULL }
1529 };
1530
1531 static const value_string q933_screening_indicator_vals[] = {
1532         { 0x00, "User-provided, not screened" },
1533         { 0x01, "User-provided, verified and passed" },
1534         { 0x02, "User-provided, verified and failed" },
1535         { 0x03, "Network-provided" },
1536         { 0,    NULL }
1537 };
1538
1539 static const value_string q933_redirection_reason_vals[] = {
1540         { 0x00, "Unknown" },
1541         { 0x01, "Call forwarding busy or called DTE busy" },
1542         { 0x02, "Call forwarding no reply" },
1543         { 0x04, "Call deflection" },
1544         { 0x09, "Called DTE out of order" },
1545         { 0x0A, "Call forwarding by the called DTE" },
1546         { 0x0F, "Call forwarding unconditional or systematic call redirection" },
1547         { 0,    NULL }
1548 };
1549
1550 static void
1551 dissect_q933_number_ie(tvbuff_t *tvb, int offset, int len,
1552     proto_tree *tree, int hfindex)
1553 {
1554         guint8 octet;
1555
1556         if (len == 0)
1557                 return;
1558         octet = tvb_get_guint8(tvb, offset);
1559         proto_tree_add_text(tree, tvb, offset, 1,
1560             "Type of number: %s",
1561             val_to_str(octet & 0x70, q933_number_type_vals,
1562               "Unknown (0x%02X)"));
1563         proto_tree_add_text(tree, tvb, offset, 1,
1564             "Numbering plan: %s",
1565             val_to_str(octet & 0x0F, q933_numbering_plan_vals,
1566               "Unknown (0x%02X)"));
1567         offset += 1;
1568         len -= 1;
1569
1570         if (!(octet & Q933_IE_VL_EXTENSION)) {
1571                 if (len == 0)
1572                         return;
1573                 octet = tvb_get_guint8(tvb, offset);
1574                 proto_tree_add_text(tree, tvb, offset, 1,
1575                     "Presentation indicator: %s",
1576                     val_to_str(octet & 0x60, q933_presentation_indicator_vals,
1577                       "Unknown (0x%X)"));
1578                 proto_tree_add_text(tree, tvb, offset, 1,
1579                     "Screening indicator: %s",
1580                     val_to_str(octet & 0x03, q933_screening_indicator_vals,
1581                       "Unknown (0x%X)"));
1582                 offset += 1;
1583                 len -= 1;
1584         }
1585
1586         /*
1587          * XXX - only in a Redirecting number information element.
1588          */
1589         if (!(octet & Q933_IE_VL_EXTENSION)) {
1590                 if (len == 0)
1591                         return;
1592                 octet = tvb_get_guint8(tvb, offset);
1593                 proto_tree_add_text(tree, tvb, offset, 1,
1594                     "Reason for redirection: %s",
1595                     val_to_str(octet & 0x0F, q933_redirection_reason_vals,
1596                       "Unknown (0x%X)"));
1597                 offset += 1;
1598                 len -= 1;
1599         }
1600
1601         if (len == 0)
1602                 return;
1603         proto_tree_add_item(tree, hfindex, tvb, offset, len, FALSE);
1604 }
1605
1606 /*
1607  * Dissect a party subaddress information element.
1608  */
1609 static const value_string q933_subaddress_type_vals[] = {
1610         { 0x00, "X.213/ISO 8348 Add.2 NSAP" },
1611         { 0x20, "User-specified" },
1612         { 0,    NULL }
1613 };
1614
1615 static const value_string q933_odd_even_indicator_vals[] = {
1616         { 0x00, "Even number of address signals" },
1617         { 0x10, "Odd number of address signals" },
1618         { 0,    NULL }
1619 };
1620
1621 static void
1622 dissect_q933_party_subaddr_ie(tvbuff_t *tvb, int offset, int len,
1623     proto_tree *tree)
1624 {
1625         guint8 octet;
1626
1627         if (len == 0)
1628                 return;
1629         octet = tvb_get_guint8(tvb, offset);
1630         proto_tree_add_text(tree, tvb, offset, 1,
1631             "Type of subaddress: %s",
1632             val_to_str(octet & 0x70, q933_subaddress_type_vals,
1633               "Unknown (0x%02X)"));
1634         proto_tree_add_text(tree, tvb, offset, 1,
1635             "Odd/even indicator: %s",
1636             val_to_str(octet & 0x10, q933_odd_even_indicator_vals,
1637               NULL));
1638         offset += 1;
1639         len -= 1;
1640
1641         if (len == 0)
1642                 return;
1643         proto_tree_add_text(tree, tvb, offset, len, "Subaddress: %s",
1644             tvb_bytes_to_str(tvb, offset, len));
1645 }
1646
1647 /*
1648  * Dissect a High-layer compatibility information element.
1649  */
1650 #define Q933_AUDIOVISUAL        0x60
1651 static const value_string q933_high_layer_characteristics_vals[] = {
1652         { 0x01,             "Telephony" },
1653         { 0x04,             "F.182 Facsimile Group 2/3" },
1654         { 0x21,             "F.184 Facsimile Group 4 Class I" },
1655         { 0x24,             "F.230 Teletex, basic and mixed mode, and F.184 Facsimile Group 4, Classes II and III" },
1656         { 0x28,             "F.220 Teletex, basic and processable mode" },
1657         { 0x31,             "F.200 Teletex, basic mode" },
1658         { 0x32,             "F.300 and T.102 syntax-based Videotex" },
1659         { 0x33,             "F.300 and T.101 international Videotex interworking" },
1660         { 0x35,             "F.60 Telex" },
1661         { 0x38,             "X.400 Message Handling Systems" },
1662         { 0x41,             "X.200 OSI application" },
1663         { 0x42,             "FTAM application" },
1664         { 0x5E,             "Reserved for maintenance" },
1665         { 0x5F,             "Reserved for management" },
1666         { Q933_AUDIOVISUAL, "F.720/F.821 and F.731 Profile 1a videotelephony" },
1667         { 0x61,             "F.702 and F.731 Profile 1b videoconferencing" },
1668         { 0x62,             "F.702 and F.731 audiographic conferencing" },
1669         { 0,                NULL }
1670 };
1671
1672 static const value_string q933_audiovisual_characteristics_vals[] = {
1673         { 0x01, "Capability set of initial channel of H.221" },
1674         { 0x02, "Capability set of subsequent channel of H.221" },
1675         { 0x21, "Capability set of initial channel of an active 3.1kHz audio or speech call" },
1676         { 0x00, NULL }
1677 };
1678
1679 void
1680 dissect_q933_high_layer_compat_ie(tvbuff_t *tvb, int offset, int len,
1681     proto_tree *tree)
1682 {
1683         guint8 octet;
1684         guint8 coding_standard;
1685         guint8 characteristics;
1686
1687         if (len == 0)
1688                 return;
1689         octet = tvb_get_guint8(tvb, offset);
1690         coding_standard = octet & 0x60;
1691         proto_tree_add_text(tree, tvb, offset, 1,
1692             "Coding standard: %s",
1693             val_to_str(coding_standard, q933_coding_standard_vals, NULL));
1694         offset += 1;
1695         len -= 1;
1696         if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
1697                 /*
1698                  * We don't know how the call state is encoded,
1699                  * so just dump it as data and be done with it.
1700                  */
1701                 proto_tree_add_text(tree, tvb, offset,
1702                     len, "Data: %s",
1703                     tvb_bytes_to_str(tvb, offset, len));
1704                 return;
1705         }
1706
1707         if (len == 0)
1708                 return;
1709         octet = tvb_get_guint8(tvb, offset);
1710         characteristics = octet & 0x7F;
1711         proto_tree_add_text(tree, tvb, offset, 1,
1712             "High layer characteristics identification: %s",
1713             val_to_str(characteristics, q933_high_layer_characteristics_vals,
1714              "Unknown (0x%02X)"));
1715         offset += 1;
1716         len -= 1;
1717
1718         if (!(octet & Q933_IE_VL_EXTENSION)) {
1719                 if (len == 0)
1720                         return;
1721                 octet = tvb_get_guint8(tvb, offset);
1722                 if (characteristics == Q933_AUDIOVISUAL) {
1723                         proto_tree_add_text(tree, tvb, offset, 1,
1724                             "Extended audiovisual characteristics identification: %s",
1725                             val_to_str(octet & 0x7F,
1726                               q933_audiovisual_characteristics_vals,
1727                               "Unknown (0x%02X)"));
1728                 } else {
1729                         proto_tree_add_text(tree, tvb, offset, 1,
1730                             "Extended high layer characteristics identification: %s",
1731                             val_to_str(octet & 0x7F,
1732                               q933_high_layer_characteristics_vals,
1733                               "Unknown (0x%02X)"));
1734                 }
1735         }
1736 }
1737
1738
1739 /*
1740  * Dissect a User-user information element.
1741  */
1742 #define Q933_PROTOCOL_DISCRIMINATOR_IA5         0x04
1743 #define Q933_PROTOCOL_DISCRIMINATOR_ASN1        0x05
1744
1745 static const value_string q933_protocol_discriminator_vals[] = {
1746         { 0x00,                                 "User-specific protocol" },
1747         { 0x01,                                 "OSI high layer protocols" },
1748         { 0x02,                                 "X.244" },
1749         { Q933_PROTOCOL_DISCRIMINATOR_IA5,      "IA5 characters" },
1750         { Q933_PROTOCOL_DISCRIMINATOR_ASN1,     "X.208 and X.209 coded user information" },
1751         { 0x07,                                 "V.120 rate adaption" },
1752         { 0x08,                                 "Q.933/I.451 user-network call control messages" },
1753         { 0,                                    NULL }
1754 };
1755
1756 void
1757 dissect_q933_user_user_ie(tvbuff_t *tvb, int offset, int len,
1758     proto_tree *tree)
1759 {
1760         guint8 octet;
1761
1762         if (len == 0)
1763                 return;
1764         octet = tvb_get_guint8(tvb, offset);
1765         proto_tree_add_text(tree, tvb, offset, 1,
1766             "Protocol discriminator: %s",
1767             val_to_str(octet, q933_protocol_discriminator_vals,
1768             "Unknown (0x%02x)"));
1769         offset += 1;
1770         len -= 1;
1771
1772         if (len == 0)
1773                 return;
1774         switch (octet) {
1775
1776         case Q933_PROTOCOL_DISCRIMINATOR_IA5:
1777                 proto_tree_add_text(tree, tvb, offset, len, "User information: %s",
1778                     tvb_format_text(tvb, offset, len));
1779                 break;
1780
1781         default:
1782                 proto_tree_add_text(tree, tvb, offset, len, "User information: %s",
1783                     tvb_bytes_to_str(tvb, offset, len));
1784                 break;
1785         }
1786 }
1787
1788 /*
1789  * Dissect information elements consisting of ASCII^H^H^H^H^HIA5 text.
1790  */
1791 static void
1792 dissect_q933_ia5_ie(tvbuff_t *tvb, int offset, int len, proto_tree *tree,
1793     char *label)
1794 {
1795         if (len != 0) {
1796                 proto_tree_add_text(tree, tvb, offset, len, "%s: %s", label,
1797                     tvb_format_text(tvb, offset, len));
1798         }
1799 }
1800
1801 static const value_string q933_codeset_vals[] = {
1802         { 0x00, "Q.933 information elements" },
1803         { 0x04, "Information elements for ISO/IEC use" },
1804         { 0x05, "Information elements for national use" },
1805         { 0x06, "Information elements specific to the local network" },
1806         { 0x07, "User-specific information elements" },
1807         { 0x00, NULL },
1808 };
1809
1810 static void
1811 dissect_q933(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1812 {
1813         int             offset = 0;
1814         proto_tree      *q933_tree = NULL;
1815         proto_item      *ti;
1816         proto_tree      *ie_tree = NULL;
1817         guint8          call_ref_len;
1818         guint8          call_ref[15];
1819         guint8          message_type;
1820         guint8          info_element;
1821         guint16         info_element_len;
1822         int             codeset, locked_codeset;
1823         gboolean        non_locking_shift;
1824
1825         if (check_col(pinfo->cinfo, COL_PROTOCOL))
1826                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Q.933");
1827
1828         if (tree) {
1829                 ti = proto_tree_add_item(tree, proto_q933, tvb, offset, -1,
1830                     FALSE);
1831                 q933_tree = proto_item_add_subtree(ti, ett_q933);
1832
1833                 dissect_q933_protocol_discriminator(tvb, offset, q933_tree);
1834         }
1835         offset += 1;
1836         call_ref_len = tvb_get_guint8(tvb, offset) & 0xF;       /* XXX - do as a bit field? */
1837         if (q933_tree != NULL)
1838                 proto_tree_add_uint(q933_tree, hf_q933_call_ref_len, tvb, offset, 1, call_ref_len);
1839         offset += 1;
1840         if (call_ref_len != 0) {
1841                 tvb_memcpy(tvb, call_ref, offset, call_ref_len);
1842                 if (q933_tree != NULL) {
1843                         proto_tree_add_boolean(q933_tree, hf_q933_call_ref_flag,
1844                             tvb, offset, 1, (call_ref[0] & 0x80) != 0);
1845                         call_ref[0] &= 0x7F;
1846                         proto_tree_add_bytes(q933_tree, hf_q933_call_ref,
1847                             tvb, offset, call_ref_len, call_ref);
1848                 }
1849                 offset += call_ref_len;
1850         }
1851         message_type = tvb_get_guint8(tvb, offset);
1852         if (check_col(pinfo->cinfo, COL_INFO)) {
1853                 col_add_str(pinfo->cinfo, COL_INFO,
1854                     val_to_str(message_type, q933_message_type_vals,
1855                       "Unknown message type (0x%02X)"));
1856         }
1857         if (q933_tree != NULL)
1858                 proto_tree_add_uint(q933_tree, hf_q933_message_type, tvb, offset, 1, message_type);
1859         offset += 1;
1860
1861         /*
1862          * And now for the information elements....
1863          */
1864         codeset = locked_codeset = 0;   /* start out in codeset 0 */
1865         non_locking_shift = TRUE;
1866         while (tvb_reported_length_remaining(tvb, offset) > 0) {
1867                 info_element = tvb_get_guint8(tvb, offset);
1868
1869                  /* Check for the codeset shift */
1870                 if ((info_element & Q933_IE_SO_MASK) &&
1871                     ((info_element & Q933_IE_SO_IDENTIFIER_MASK) == Q933_IE_SHIFT)) {
1872                         non_locking_shift = info_element & Q933_IE_SHIFT_NON_LOCKING;
1873                         codeset = info_element & Q933_IE_SHIFT_CODESET;
1874                         if (!non_locking_shift)
1875                                 locked_codeset = codeset;
1876                         if (q933_tree != NULL) {
1877                                 proto_tree_add_text(q933_tree, tvb, offset, 1,
1878                                     "%s shift to codeset %u: %s",
1879                                     (non_locking_shift ? "Non-locking" : "Locking"),
1880                                     codeset,
1881                                     val_to_str(codeset, q933_codeset_vals,
1882                                       "Unknown (0x%02X)"));
1883                         }
1884                         offset += 1;
1885                         continue;
1886                 }
1887
1888                 /*
1889                  * Check for the single-octet IEs.
1890                  */
1891                 if (info_element & Q933_IE_SO_MASK) {
1892                         switch ((codeset << 8) | (info_element & Q933_IE_SO_IDENTIFIER_MASK)) {
1893
1894                         case CS0 | Q933_IE_REPEAT_INDICATOR:
1895                                 if (q933_tree != NULL) {
1896                                         proto_tree_add_text(q933_tree, tvb, offset, 1,
1897                                             "Repeat indicator: %s",
1898                                             val_to_str(info_element & Q933_IE_SO_IE_MASK,
1899                                           q933_repeat_indication_vals,
1900                                               "Unknown (0x%X)"));
1901                                 }
1902                                 break;
1903
1904                         default:
1905                                 if (q933_tree != NULL) {
1906                                         proto_tree_add_text(q933_tree, tvb, offset, 1,
1907                                             "Unknown information element (0x%02X)",
1908                                             info_element);
1909                                 }
1910                                 break;
1911                         }
1912                         offset += 1;
1913                         codeset = locked_codeset;
1914                         continue;
1915                 }
1916
1917                 /*
1918                  * Variable-length IE.
1919                  */
1920                 info_element_len = tvb_get_guint8(tvb, offset + 1);
1921                 if (q933_tree != NULL) {
1922                         ti = proto_tree_add_text(q933_tree, tvb, offset,
1923                             1+1+info_element_len, "%s",
1924                             val_to_str(info_element, q933_info_element_vals[codeset],
1925                               "Unknown information element (0x%02X)"));
1926                                 ie_tree = proto_item_add_subtree(ti, ett_q933_ie);
1927                         proto_tree_add_text(ie_tree, tvb, offset, 1,
1928                             "Information element: %s",
1929                             val_to_str(info_element, q933_info_element_vals[codeset],
1930                               "Unknown (0x%02X)"));
1931                         proto_tree_add_text(ie_tree, tvb, offset + 1, 1,
1932                             "Length: %u", info_element_len);
1933
1934                         switch ((codeset << 8) | info_element) {
1935
1936                         case CS0 | Q933_IE_SEGMENTED_MESSAGE:
1937                                 dissect_q933_segmented_message_ie(tvb,
1938                                     offset + 2, info_element_len,
1939                                     ie_tree);
1940                                 break;
1941
1942                         case CS0 | Q933_IE_BEARER_CAPABILITY:
1943                         case CS0 | Q933_IE_LOW_LAYER_COMPAT:
1944                                 dissect_q933_bearer_capability_ie(tvb,
1945                                     offset + 2, info_element_len,
1946                                     ie_tree);
1947                                 break;
1948
1949                         case CS0 | Q933_IE_CAUSE:
1950                                 dissect_q933_cause_ie(tvb,
1951                                     offset + 2, info_element_len,
1952                                     ie_tree,
1953                                     hf_q933_cause_value);
1954                                 break;
1955
1956                         case CS0 | Q933_IE_CALL_STATE:
1957                                 dissect_q933_call_state_ie(tvb,
1958                                     offset + 2, info_element_len,
1959                                     ie_tree);
1960                                 break;
1961
1962                         case CS0 | Q933_IE_CHANNEL_IDENTIFICATION:
1963                                 dissect_q933_channel_identification_ie(
1964                                     tvb, offset + 2, info_element_len,
1965                                     ie_tree);
1966                                 break;
1967
1968                         case CS0 | Q933_IE_PROGRESS_INDICATOR:
1969                                 dissect_q933_progress_indicator_ie(tvb,
1970                                     offset + 2, info_element_len,
1971                                     ie_tree);
1972                                 break;
1973
1974                         case CS0 | Q933_IE_NETWORK_SPECIFIC_FACIL:
1975                         case CS0 | Q933_IE_TRANSIT_NETWORK_SEL:
1976                                 dissect_q933_ns_facilities_ie(tvb,
1977                                     offset + 2, info_element_len,
1978                                     ie_tree);
1979                                 break;
1980
1981                         case CS0 | Q933_IE_DISPLAY:
1982                                 dissect_q933_ia5_ie(tvb, offset + 2,
1983                                     info_element_len, ie_tree,
1984                                     "Display information");
1985                                 break;
1986
1987                         case CS0 | Q933_IE_E2E_TRANSIT_DELAY:
1988                                 dissect_q933_e2e_transit_delay_ie(tvb,
1989                                     offset + 2, info_element_len,
1990                                     ie_tree);
1991                                 break;
1992
1993                         case CS0 | Q933_IE_TD_SELECTION_AND_INT:
1994                                 dissect_q933_td_selection_and_int_ie(
1995                                     tvb, offset + 2, info_element_len,
1996                                     ie_tree);
1997                                 break;
1998
1999                         case CS0 | Q933_IE_PL_BINARY_PARAMETERS:
2000                                 dissect_q933_pl_binary_parameters_ie(
2001                                     tvb, offset + 2, info_element_len,
2002                                     ie_tree);
2003                                 break;
2004
2005                         case CS0 | Q933_IE_REVERSE_CHARGE_IND:
2006                                 dissect_q933_reverse_charge_ind_ie(tvb,
2007                                     offset + 2, info_element_len,
2008                                     ie_tree);
2009                                 break;
2010
2011                         case CS0 | Q933_IE_CALLING_PARTY_NUMBER:
2012                                 dissect_q933_number_ie(tvb,
2013                                     offset + 2, info_element_len,
2014                                     ie_tree,
2015                                     hf_q933_calling_party_number);
2016                                 break;
2017
2018                         case CS0 | Q933_IE_CONNECTED_NUMBER:
2019                                 dissect_q933_number_ie(tvb,
2020                                     offset + 2, info_element_len,
2021                                     ie_tree,
2022                                     hf_q933_connected_number);
2023                                 break;
2024
2025                         case CS0 | Q933_IE_CALLED_PARTY_NUMBER:
2026                                 dissect_q933_number_ie(tvb,
2027                                     offset + 2, info_element_len,
2028                                     ie_tree,
2029                                     hf_q933_called_party_number);
2030                                 break;
2031
2032                         case CS0 | Q933_IE_CALLING_PARTY_SUBADDR:
2033                         case CS0 | Q933_IE_CALLED_PARTY_SUBADDR:
2034                                 dissect_q933_party_subaddr_ie(tvb,
2035                                     offset + 2, info_element_len,
2036                                     ie_tree);
2037                                 break;
2038
2039                         case CS0 | Q933_IE_HIGH_LAYER_COMPAT:
2040                                 dissect_q933_high_layer_compat_ie(tvb,
2041                                     offset + 2, info_element_len,
2042                                     ie_tree);
2043                                 break;
2044
2045                         case CS0 | Q933_IE_USER_USER:
2046                                 dissect_q933_user_user_ie(tvb,
2047                                     offset + 2, info_element_len,
2048                                     ie_tree);
2049                                 break;
2050
2051                         default:
2052                                 proto_tree_add_text(ie_tree, tvb,
2053                                     offset + 2, info_element_len,
2054                                     "Data: %s",
2055                                     bytes_to_str(
2056                                       tvb_get_ptr(tvb, offset + 2,
2057                                           info_element_len),
2058                                           info_element_len));
2059                                 break;
2060                         }
2061                 }
2062                 offset += 1 + 1 + info_element_len;
2063                 codeset = locked_codeset;
2064         }
2065 }
2066
2067 void
2068 proto_register_q933(void)
2069 {
2070         static hf_register_info hf[] = {
2071                 { &hf_q933_discriminator,
2072                   { "Protocol discriminator", "q933.disc", FT_UINT8, BASE_HEX, NULL, 0x0,
2073                         "", HFILL }},
2074
2075                 { &hf_q933_call_ref_len,
2076                   { "Call reference value length", "q933.call_ref_len", FT_UINT8, BASE_DEC, NULL, 0x0,
2077                         "", HFILL }},
2078
2079                 { &hf_q933_call_ref_flag,
2080                   { "Call reference flag", "q933.call_ref_flag", FT_BOOLEAN, BASE_NONE, TFS(&tfs_call_ref_flag), 0x0,
2081                         "", HFILL }},
2082
2083                 { &hf_q933_call_ref,
2084                   { "Call reference value", "q933.call_ref", FT_BYTES, BASE_HEX, NULL, 0x0,
2085                         "", HFILL }},
2086
2087                 { &hf_q933_message_type,
2088                   { "Message type", "q933.message_type", FT_UINT8, BASE_HEX, VALS(q933_message_type_vals), 0x0,
2089                         "", HFILL }},
2090
2091                 { &hf_q933_cause_value,
2092                   { "Cause value", "q933.cause_value", FT_UINT8, BASE_DEC, VALS(q933_cause_code_vals), 0x0,
2093                         "", HFILL }},
2094
2095                 { &hf_q933_calling_party_number,
2096                   { "Calling party number digits", "q933.calling_party_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2097                         "", HFILL }},
2098
2099                 { &hf_q933_called_party_number,
2100                   { "Called party number digits", "q933.called_party_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2101                         "", HFILL }},
2102
2103                 { &hf_q933_connected_number,
2104                   { "Connected party number digits", "q933.connected_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2105                         "", HFILL }},
2106
2107                 { &hf_q933_redirecting_number,
2108                   { "Redirecting party number digits", "q933.redirecting_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2109                         "", HFILL }},
2110         };
2111         static gint *ett[] = {
2112                 &ett_q933,
2113                 &ett_q933_ie,
2114         };
2115
2116         proto_q933 = proto_register_protocol("Q.933", "Q.933", "q933");
2117         proto_register_field_array (proto_q933, hf, array_length(hf));
2118         proto_register_subtree_array(ett, array_length(ett));
2119
2120         register_dissector("q933", dissect_q933, proto_q933);
2121 }
2122
2123 void
2124 proto_reg_handoff_q933(void)
2125 {
2126         dissector_handle_t q933_handle;
2127
2128         q933_handle = create_dissector_handle(dissect_q933, proto_q933);
2129         dissector_add("fr.osinl", NLPID_Q_933, q933_handle);
2130 }