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