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