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