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