Maybe the problem is that the compilers used on AIX weren't defining
[obnox/wireshark/wip.git] / packet-q931.c
1 /* packet-q931.c
2  * Routines for Q.931 frame disassembly
3  * Guy Harris <guy@alum.mit.edu>
4  *
5  * $Id: packet-q931.c,v 1.63 2003/11/10 08:14:07 sahlberg Exp $
6  *
7  * Modified by Andreas Sikkema for possible use with H.323
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33 #include <glib.h>
34 #include <string.h>
35 #include <epan/packet.h>
36 #include <epan/strutil.h>
37 #include "nlpid.h"
38 #include "packet-q931.h"
39 #include "prefs.h"
40
41 #include "packet-tpkt.h"
42
43 /* Q.931 references:
44  *
45  * http://www.acacia-net.com/Clarinet/Protocol/q9313svn.htm
46  * http://www.acacia-net.com/Clarinet/Protocol/q9311sc3.htm
47  * http://www.acacia-net.com/Clarinet/Protocol/q9317oz7.htm
48  * http://www.protocols.com/pbook/isdn.htm
49  * http://freesoft.org/CIE/Topics/126.htm
50  * http://noc.comstar.ru/miscdocs/ascend-faq-cause-codes.html
51  * http://www.andrews-arnold.co.uk/isdn/q931cause.html
52  * http://www.tulatelecom.ru/staff/german/DSSHelp/MessList/InfEl/InfElList.html
53  */
54
55 static int proto_q931                                   = -1;
56 static int hf_q931_discriminator                        = -1;
57 static int hf_q931_coding_standard                      = -1;
58 static int hf_q931_information_transfer_capability      = -1;
59 static int hf_q931_transfer_mode                        = -1;
60 static int hf_q931_information_transfer_rate            = -1;
61 static int hf_q931_uil1                                 = -1;
62 static int hf_q931_call_ref_len                         = -1;
63 static int hf_q931_call_ref_flag                        = -1;
64 static int hf_q931_call_ref                             = -1;
65 static int hf_q931_message_type                         = -1;
66 static int hf_q931_cause_value                          = -1;
67 static int hf_q931_number_type                          = -1;
68 static int hf_q931_numbering_plan                       = -1;
69 static int hf_q931_extension_ind                        = -1;
70 static int hf_q931_calling_party_number                 = -1;
71 static int hf_q931_called_party_number                  = -1;
72 static int hf_q931_connected_number                     = -1;
73 static int hf_q931_redirecting_number                   = -1;
74
75 static gint ett_q931                                    = -1;
76 static gint ett_q931_ie                                 = -1;
77
78 static dissector_table_t codeset_dissector_table;
79 static dissector_table_t ie_dissector_table;
80
81 /* desegmentation of Q.931 over TPKT over TCP */
82 static gboolean q931_desegment = TRUE;
83
84 static dissector_handle_t h225_handle;
85 static dissector_handle_t q931_tpkt_pdu_handle;
86
87 /*
88  * Q.931 message types.
89  */
90 #define Q931_ESCAPE             0x00
91 #define Q931_ALERTING           0x01
92 #define Q931_CALL_PROCEEDING    0x02
93 #define Q931_CONNECT            0x07
94 #define Q931_CONNECT_ACK        0x0F
95 #define Q931_PROGRESS           0x03
96 #define Q931_SETUP              0x05
97 #define Q931_SETUP_ACK          0x0D
98 #define Q931_HOLD               0x24
99 #define Q931_HOLD_ACK           0x28
100 #define Q931_HOLD_REJECT        0x30
101 #define Q931_RESUME             0x26
102 #define Q931_RESUME_ACK         0x2E
103 #define Q931_RESUME_REJECT      0x22
104 #define Q931_RETRIEVE           0x31
105 #define Q931_RETRIEVE_ACK       0x33
106 #define Q931_RETRIEVE_REJECT    0x37
107 #define Q931_SUSPEND            0x25
108 #define Q931_SUSPEND_ACK        0x2D
109 #define Q931_SUSPEND_REJECT     0x21
110 #define Q931_USER_INFORMATION   0x20
111 #define Q931_DISCONNECT         0x45
112 #define Q931_RELEASE            0x4D
113 #define Q931_RELEASE_COMPLETE   0x5A
114 #define Q931_RESTART            0x46
115 #define Q931_RESTART_ACK        0x4E
116 #define Q931_CONGESTION_CONTROL 0x79
117 #define Q931_FACILITY           0x62
118 #define Q931_INFORMATION        0x7B
119 #define Q931_NOTIFY             0x6E
120 #define Q931_REGISTER           0x64
121 #define Q931_SEGMENT            0x60
122 #define Q931_STATUS             0x7D
123 #define Q931_STATUS_ENQUIRY     0x75
124
125 static const value_string q931_message_type_vals[] = {
126         { Q931_ESCAPE,                  "ESCAPE" },
127         { Q931_ALERTING,                "ALERTING" },
128         { Q931_CALL_PROCEEDING,         "CALL PROCEEDING" },
129         { Q931_CONNECT,                 "CONNECT" },
130         { Q931_CONNECT_ACK,             "CONNECT ACKNOWLEDGE" },
131         { Q931_PROGRESS,                "PROGRESS" },
132         { Q931_SETUP,                   "SETUP" },
133         { Q931_SETUP_ACK,               "SETUP ACKNOWLEDGE" },
134         { Q931_HOLD,                    "HOLD" },
135         { Q931_HOLD_ACK,                "HOLD_ACKNOWLEDGE" },
136         { Q931_HOLD_REJECT,             "HOLD_REJECT" },
137         { Q931_RESUME,                  "RESUME" },
138         { Q931_RESUME_ACK,              "RESUME ACKNOWLEDGE" },
139         { Q931_RESUME_REJECT,           "RESUME REJECT" },
140         { Q931_RETRIEVE,                "RETRIEVE" },
141         { Q931_RETRIEVE_ACK,            "RETRIEVE ACKNOWLEDGE" },
142         { Q931_RETRIEVE_REJECT,         "RETRIEVE REJECT" },
143         { Q931_SUSPEND,                 "SUSPEND" },
144         { Q931_SUSPEND_ACK,             "SUSPEND ACKNOWLEDGE" },
145         { Q931_SUSPEND_REJECT,          "SUSPEND REJECT" },
146         { Q931_USER_INFORMATION,        "USER INFORMATION" },
147         { Q931_DISCONNECT,              "DISCONNECT" },
148         { Q931_RELEASE,                 "RELEASE" },
149         { Q931_RELEASE_COMPLETE,        "RELEASE COMPLETE" },
150         { Q931_RESTART,                 "RESTART" },
151         { Q931_RESTART_ACK,             "RESTART ACKNOWLEDGE" },
152         { Q931_CONGESTION_CONTROL,      "CONGESTION CONTROL" },
153         { Q931_FACILITY,                "FACILITY" },
154         { Q931_INFORMATION,             "INFORMATION" },
155         { Q931_NOTIFY,                  "NOTIFY" },
156         { Q931_REGISTER,                "REGISTER" },
157         { Q931_SEGMENT,                 "SEGMENT" },
158         { Q931_STATUS,                  "STATUS" },
159         { Q931_STATUS_ENQUIRY,          "STATUS ENQUIRY" },
160         { 0,                            NULL }
161 };
162
163 static const true_false_string tfs_call_ref_flag = {
164         "Message sent to originating side",
165         "Message sent from originating side"
166 };
167
168 /*
169  * Information elements.
170  */
171
172 /* Shifted codeset values */
173 #define CS0 0x000
174 #define CS1 0x100
175 #define CS2 0x200
176 #define CS3 0x300
177 #define CS4 0x400
178 #define CS5 0x500
179 #define CS6 0x600
180 #define CS7 0x700
181
182 #define Q931_IE_SO_MASK 0x80    /* single-octet/variable-length mask */
183 /*
184  * Single-octet IEs.
185  */
186 #define Q931_IE_SO_IDENTIFIER_MASK      0xf0    /* IE identifier mask */
187 #define Q931_IE_SO_IDENTIFIER_SHIFT     4       /* IE identifier shift */
188 #define Q931_IE_SO_IE_MASK              0x0F    /* IE mask */
189
190 #define Q931_IE_SHIFT                   0x90
191 #define Q931_IE_SHIFT_NON_LOCKING       0x08    /* non-locking shift */
192 #define Q931_IE_SHIFT_CODESET           0x0F    /* codeset */
193
194 #define Q931_IE_MORE_DATA_OR_SEND_COMP  0xA0    /* More Data or Sending Complete */
195 #define Q931_IE_MORE_DATA               0xA0
196 #define Q931_IE_SENDING_COMPLETE        0xA1
197
198 #define Q931_IE_CONGESTION_LEVEL        0xB0
199 #define Q931_IE_REPEAT_INDICATOR        0xD0
200
201 /*
202  * Variable-length IEs.
203  */
204 #define Q931_IE_VL_EXTENSION            0x80    /* Extension flag */
205 /*      extension bit. The bit value "0" indicates that the octet continues through the         */
206 /*      next octet. The bit value "1" indicates that this octet is the last octet               */
207
208 static const true_false_string q931_extension_ind_value = {
209   "last octet",
210   "information continues through the next octet",
211
212 };
213
214
215 /*
216  * Codeset 0 (default).
217  */
218 #define Q931_IE_SEGMENTED_MESSAGE       0x00
219 #define Q931_IE_BEARER_CAPABILITY       0x04
220 #define Q931_IE_CAUSE                   0x08
221 #define Q931_IE_CALL_IDENTITY           0x10
222 #define Q931_IE_CALL_STATE              0x14
223 #define Q931_IE_CHANNEL_IDENTIFICATION  0x18
224 #define Q931_IE_FACILITY                0x1C
225 #define Q931_IE_PROGRESS_INDICATOR      0x1E
226 #define Q931_IE_NETWORK_SPECIFIC_FACIL  0x20    /* Network Specific Facilities */
227 #define Q931_IE_NOTIFICATION_INDICATOR  0x27
228 #define Q931_IE_DISPLAY                 0x28
229 #define Q931_IE_DATE_TIME               0x29
230 #define Q931_IE_KEYPAD_FACILITY         0x2C
231 #define Q931_IE_INFORMATION_REQUEST     0x32
232 #define Q931_IE_SIGNAL                  0x34
233 #define Q931_IE_SWITCHHOOK              0x36
234 #define Q931_IE_FEATURE_ACTIVATION      0x38
235 #define Q931_IE_FEATURE_INDICATION      0x39
236 #define Q931_IE_ENDPOINT_IDENTIFIER     0x3B
237 #define Q931_IE_SERVICE_PROFILE_ID      0x3A
238 #define Q931_IE_INFORMATION_RATE        0x40
239 #define Q931_IE_E2E_TRANSIT_DELAY       0x42    /* End-to-end Transit Delay */
240 #define Q931_IE_TD_SELECTION_AND_INT    0x43    /* Transit Delay Selection and Indication */
241 #define Q931_IE_PL_BINARY_PARAMETERS    0x44    /* Packet layer binary parameters */
242 #define Q931_IE_PL_WINDOW_SIZE          0x45    /* Packet layer window size */
243 #define Q931_IE_PACKET_SIZE             0x46    /* Packet size */
244 #define Q931_IE_CUG                     0x47    /* Closed user group */
245 #define Q931_IE_REVERSE_CHARGE_IND      0x4A    /* Reverse charging indication */
246 #define Q931_IE_CONNECTED_NUMBER_DEFAULT        0x4C    /* Connected Number */
247 #define Q931_IE_CALLING_PARTY_NUMBER    0x6C    /* Calling Party Number */
248 #define Q931_IE_CALLING_PARTY_SUBADDR   0x6D    /* Calling Party Subaddress */
249 #define Q931_IE_CALLED_PARTY_NUMBER     0x70    /* Called Party Number */
250 #define Q931_IE_CALLED_PARTY_SUBADDR    0x71    /* Called Party Subaddress */
251 #define Q931_IE_REDIRECTING_NUMBER      0x74
252 #define Q931_IE_REDIRECTION_NUMBER      0x76
253 #define Q931_IE_TRANSIT_NETWORK_SEL     0x78    /* Transit Network Selection */
254 #define Q931_IE_RESTART_INDICATOR       0x79
255 #define Q931_IE_LOW_LAYER_COMPAT        0x7C    /* Low-Layer Compatibility */
256 #define Q931_IE_HIGH_LAYER_COMPAT       0x7D    /* High-Layer Compatibility */
257 #define Q931_IE_USER_USER               0x7E    /* User-User */
258 #define Q931_IE_ESCAPE                  0x7F    /* Escape for extension */
259
260 /*
261  * Codeset 0 ETSI.
262  */
263 #define Q931_IE_CONNECTED_NUMBER        0x8C
264 #define Q931_IE_CONNECTED_SUBADDR       0x8D
265
266 /*
267  * Codeset 5 (National-specific) Belgium.
268  */
269 #define Q931_IE_CHARGING_ADVICE         0x1A
270
271 /*
272  * Codeset 5 (National-specific) Bellcore National ISDN.
273  */
274 #define Q931_IE_OPERATOR_SYSTEM_ACCESS  0x1D
275
276 /*
277  * Codeset 6 (Network-specific) Belgium.
278  */
279 /* 0x1A is Charging Advice, as with Codeset 5 */
280 #define Q931_IE_REDIRECTING_NUMBER      0x74
281
282 /*
283  * Codeset 6 (Network-specific) FT-Numeris.
284  */
285 /* 0x1D is User Capability */
286
287 /*
288  * Codeset 6 (Network-specific) Bellcore National ISDN.
289  */
290 #define Q931_IE_REDIRECTING_SUBADDR     0x75    /* Redirecting Subaddress */
291 /* 0x76 is Redirection Number, but that's also Codeset 0 */
292 #define Q931_IE_CALL_APPEARANCE         0x7B
293
294 /* Codeset 0 */
295 static const value_string q931_info_element_vals0[] = {
296         { Q931_IE_SEGMENTED_MESSAGE,            "Segmented message" },
297         { Q931_IE_BEARER_CAPABILITY,            "Bearer capability" },
298         { Q931_IE_CAUSE,                        "Cause" },
299         { Q931_IE_CALL_IDENTITY,                "Call identity" },
300         { Q931_IE_CALL_STATE,                   "Call state" },
301         { Q931_IE_CHANNEL_IDENTIFICATION,       "Channel identification" },
302         { Q931_IE_FACILITY,                     "Facility" },
303         { Q931_IE_PROGRESS_INDICATOR,           "Progress indicator" },
304         { Q931_IE_NETWORK_SPECIFIC_FACIL,       "Network specific facilities" },
305         { Q931_IE_NOTIFICATION_INDICATOR,       "Notification indicator" },
306         { Q931_IE_DISPLAY,                      "Display" },
307         { Q931_IE_DATE_TIME,                    "Date/Time" },
308         { Q931_IE_KEYPAD_FACILITY,              "Keypad facility" },
309         { Q931_IE_INFORMATION_REQUEST,          "Information request" },
310         { Q931_IE_SIGNAL,                       "Signal" },
311         { Q931_IE_SWITCHHOOK,                   "Switchhook" },
312         { Q931_IE_FEATURE_ACTIVATION,           "Feature activation" },
313         { Q931_IE_FEATURE_INDICATION,           "Feature Indication" },
314         { Q931_IE_ENDPOINT_IDENTIFIER,          "Endpoint identifier" },
315         { Q931_IE_SERVICE_PROFILE_ID,           "Service profile ID" },
316         { Q931_IE_INFORMATION_RATE,             "Information rate" },
317         { Q931_IE_E2E_TRANSIT_DELAY,            "End-to-end transit delay" },
318         { Q931_IE_TD_SELECTION_AND_INT,         "Transit delay selection and indication" },
319         { Q931_IE_PL_BINARY_PARAMETERS,         "Packet layer binary parameters" },
320         { Q931_IE_PL_WINDOW_SIZE,               "Packet layer window size" },
321         { Q931_IE_PACKET_SIZE,                  "Packet size" },
322         { Q931_IE_CUG,                          "Closed user group" },
323         { Q931_IE_REVERSE_CHARGE_IND,           "Reverse charging indication" },
324         { Q931_IE_CONNECTED_NUMBER_DEFAULT,     "Connected number" },
325         { Q931_IE_CALLING_PARTY_NUMBER,         "Calling party number" },
326         { Q931_IE_CALLING_PARTY_SUBADDR,        "Calling party subaddress" },
327         { Q931_IE_CALLED_PARTY_NUMBER,          "Called party number" },
328         { Q931_IE_CALLED_PARTY_SUBADDR,         "Called party subaddress" },
329         { Q931_IE_REDIRECTING_NUMBER,           "Redirecting number" },
330         { Q931_IE_REDIRECTION_NUMBER,           "Redirection number" },
331         { Q931_IE_TRANSIT_NETWORK_SEL,          "Transit network selection" },
332         { Q931_IE_RESTART_INDICATOR,            "Restart indicator" },
333         { Q931_IE_LOW_LAYER_COMPAT,             "Low-layer compatibility" },
334         { Q931_IE_HIGH_LAYER_COMPAT,            "High-layer compatibility" },
335         { Q931_IE_USER_USER,                    "User-user" },
336         { Q931_IE_ESCAPE,                       "Escape" },
337         { Q931_IE_CONNECTED_NUMBER,             "Connected number" },
338         { Q931_IE_CONNECTED_SUBADDR,            "Connected subaddress" },
339         { 0,                                    NULL }
340 };
341 /* Codeset 1 */
342 static const value_string q931_info_element_vals1[] = {
343         { 0,                                    NULL }
344 };
345 /* Codeset 2 */
346 static const value_string q931_info_element_vals2[] = {
347         { 0,                                    NULL }
348 };
349 /* Codeset 3 */
350 static const value_string q931_info_element_vals3[] = {
351         { 0,                                    NULL }
352 };
353 /* Codeset 4 */
354 static const value_string q931_info_element_vals4[] = {
355         { 0,                                    NULL }
356 };
357 /* Codeset 5 */
358 static const value_string q931_info_element_vals5[] = {
359         { Q931_IE_CHARGING_ADVICE,              "Charging advice" },
360         { Q931_IE_OPERATOR_SYSTEM_ACCESS,       "Operator system access" },
361         { 0,                                    NULL }
362 };
363 /* Codeset 6 */
364 static const value_string q931_info_element_vals6[] = {
365         { Q931_IE_REDIRECTING_NUMBER,           "Redirecting number" },
366         { Q931_IE_REDIRECTING_SUBADDR,          "Redirecting subaddress" },
367         { Q931_IE_CALL_APPEARANCE,              "Call appearance" },
368         { 0,                                    NULL }
369 };
370 /* Codeset 7 */
371 static const value_string q931_info_element_vals7[] = {
372         { 0,                                    NULL }
373 };
374
375 /* Codeset array */
376 #define NUM_INFO_ELEMENT_VALS   8
377 static const value_string *q931_info_element_vals[NUM_INFO_ELEMENT_VALS] = {
378   q931_info_element_vals0,
379   q931_info_element_vals1,
380   q931_info_element_vals2,
381   q931_info_element_vals3,
382   q931_info_element_vals4,
383   q931_info_element_vals5,
384   q931_info_element_vals6,
385   q931_info_element_vals7,
386 };
387
388 static const value_string q931_congestion_level_vals[] = {
389         { 0x0, "Receiver ready" },
390         { 0xF, "Receiver not ready" },
391         { 0,   NULL }
392 };
393
394 static const value_string q931_repeat_indication_vals[] = {
395         { 0x2, "Prioritized list" },
396         { 0,   NULL }
397 };
398
399 /*
400  * ITU-standardized coding.
401  */
402 #define Q931_ITU_STANDARDIZED_CODING    0x00
403
404 /*
405  * Dissect a Segmented message information element.
406  */
407 static void
408 dissect_q931_segmented_message_ie(tvbuff_t *tvb, int offset, int len,
409     proto_tree *tree)
410 {
411         if (len != 2) {
412                 proto_tree_add_text(tree, tvb, offset, len,
413                     "Segmented message: length is %d, should be 2\n", len);
414                 return;
415         }
416         if (tvb_get_guint8(tvb, offset) & 0x80) {
417                 proto_tree_add_text(tree, tvb, offset, 1,
418                     "First segment: %u segments remaining",
419                     tvb_get_guint8(tvb, offset) & 0x7F);
420         } else {
421                 proto_tree_add_text(tree, tvb, offset, 1,
422                     "Not first segment: %u segments remaining",
423                     tvb_get_guint8(tvb, offset) & 0x7F);
424         }
425         proto_tree_add_text(tree, tvb, offset + 1, 1,
426             "Segmented message type: %u\n", tvb_get_guint8(tvb, offset + 1));
427 }
428
429 /*
430  * Dissect a Bearer capability or Low-layer compatibility information element.
431  */
432 static const value_string q931_coding_standard_vals[] = {
433         { 0x0, "ITU-T standardized coding" },
434         { 0x1, "ISO/IEC standard" },
435         { 0x2, "National standard" },
436         { 0x3, "Standard defined for this particular network" },
437         { 0,    NULL }
438 };
439
440 static const value_string q931_information_transfer_capability_vals[] = {
441         { 0x00, "Speech" },
442         { 0x08, "Unrestricted digital information" },
443         { 0x09, "Restricted digital information" },
444         { 0x10, "3.1 kHz audio" },
445         { 0x11, "Unrestricted digital information with tones/announcements" },
446         { 0x18, "Video" },
447         { 0,    NULL }
448 };
449
450 static const value_string q931_transfer_mode_vals[] = {
451         { 0x00, "Circuit mode" },
452         { 0x02, "Packet mode" },
453         { 0,    NULL }
454 };
455
456 #define Q931_IT_RATE_MULTIRATE  0x18
457
458 static const value_string q931_information_transfer_rate_vals[] = {
459         { 0x00,                         "Packet mode" },
460         { 0x10,                         "64 kbit/s" },
461         { 0x11,                         "2 x 64 kbit/s" },
462         { 0x13,                         "384 kbit/s" },
463         { 0x15,                         "1536 kbit/s" },
464         { 0x17,                         "1920 kbit/s" },
465         { Q931_IT_RATE_MULTIRATE,       "Multirate (64 kbit/s base rate)" },
466         { 0,                            NULL }
467 };
468
469 static const value_string q931_uil1_vals[] = {
470         { 0x01, "V.110/I.460/X.30 rate adaption" },
471         { 0x02, "Recommendation G.711 u-law" },
472         { 0x03, "Recommendation G.711 A-law" },
473         { 0x04, "Recommendation G.721 32 kbit/s ADPCM and Recommendation I.460" },
474         { 0x05, "Recommendation H.221 and H.242" },
475         { 0x06, "Recommendation H.223 and H.245" },
476         { 0x07, "Non-ITU-T-standardized rate adaption" },
477         { 0x08, "V.120 rate adaption" },
478         { 0x09, "X.31 HDLC flag stuffing" },
479         { 0,    NULL },
480 };
481
482 static const value_string q931_l1_user_rate_vals[] = {
483         { 0x00, "Rate indicated by E-bits" },
484         { 0x01, "0.6 kbit/s" },
485         { 0x02, "1.2 kbit/s" },
486         { 0x03, "2.4 kbit/s" },
487         { 0x04, "3.6 kbit/s" },
488         { 0x05, "4.8 kbit/s" },
489         { 0x06, "7.2 kbit/s" },
490         { 0x07, "8 kbit/s" },
491         { 0x08, "9.6 kbit/s" },
492         { 0x09, "14.4 kbit/s" },
493         { 0x0A, "16 kbit/s" },
494         { 0x0B, "19.2 kbit/s" },
495         { 0x0C, "32 kbit/s" },
496         { 0x0E, "48 kbit/s" },
497         { 0x0F, "56 kbit/s" },
498         { 0x10, "64 kbit/s "},
499         { 0x15, "0.1345 kbit/s" },
500         { 0x16, "0.100 kbit/s" },
501         { 0x17, "0.075/1.2 kbit/s" },
502         { 0x18, "1.2/0.075 kbit/s" },
503         { 0x19, "0.050 kbit/s" },
504         { 0x1A, "0.075 kbit/s" },
505         { 0x1B, "0.110 kbit/s" },
506         { 0x1C, "0.150 kbit/s" },
507         { 0x1D, "0.200 kbit/s" },
508         { 0x1E, "0.300 kbit/s" },
509         { 0x1F, "12 kbit/s" },
510         { 0,    NULL }
511 };
512
513 static const value_string q931_l1_intermediate_rate_vals[] = {
514         { 0x20, "8 kbit/s" },
515         { 0x40, "16 kbit/s" },
516         { 0x60, "32 kbit/s" },
517         { 0,    NULL }
518 };
519
520 static const value_string q931_l1_stop_bits_vals[] = {
521         { 0x20, "1" },
522         { 0x40, "1.5" },
523         { 0x60, "2" },
524         { 0,    NULL }
525 };
526
527 static const value_string q931_l1_data_bits_vals[] = {
528         { 0x08, "5" },
529         { 0x10, "7" },
530         { 0x18, "8" },
531         { 0,    NULL }
532 };
533
534 static const value_string q931_l1_parity_vals[] = {
535         { 0x00, "Odd" },
536         { 0x02, "Even" },
537         { 0x03, "None" },
538         { 0x04, "Forced to 0" },
539         { 0x05, "Forced to 1" },
540         { 0,    NULL }
541 };
542
543 static const value_string q931_l1_modem_type_vals[] = {
544         { 0x11, "V.21" },
545         { 0x12, "V.22" },
546         { 0x13, "V.22 bis" },
547         { 0x14, "V.23" },
548         { 0x15, "V.26" },
549         { 0x16, "V.26 bis" },
550         { 0x17, "V.26 ter" },
551         { 0x18, "V.27" },
552         { 0x19, "V.27 bis" },
553         { 0x1A, "V.27 ter" },
554         { 0x1B, "V.29" },
555         { 0x1C, "V.32" },
556         { 0x1E, "V.34" },
557         { 0,    NULL }
558 };
559
560 #define Q931_UIL2_USER_SPEC     0x10
561
562 static const value_string q931_uil2_vals[] = {
563         { 0x01,                 "Basic mode ISO 1745" },
564         { 0x02,                 "Q.921/I.441" },        /* LAPD */
565         { 0x06,                 "X.25, link layer" },   /* LAPB */
566         { 0x07,                 "X.25 multilink" },     /* or 0x0F? */
567         { 0x08,                 "T.71 Extended LAPB" },
568         { 0x09,                 "HDLC ARM" },
569         { 0x0A,                 "HDLC NRM" },
570         { 0x0B,                 "HDLC ABM" },
571         { 0x0C,                 "ISO 8802/2 LLC" },
572         { 0x0D,                 "X.75 Single Link Procedure" },
573         { 0x0E,                 "Q.922" },
574         { 0x0F,                 "Core aspects of Q.922" },
575         { Q931_UIL2_USER_SPEC,  "User-specified" },
576         { 0x11,                 "ISO 7776 DTE-DTE operation" },
577         { 0,                    NULL }
578 };
579
580 static const value_string q931_mode_vals[] = {
581         { 0x20, "Normal mode" },
582         { 0x40, "Extended mode" },
583         { 0,    NULL }
584 };
585
586 #define Q931_UIL3_X25_PL        0x06
587 #define Q931_UIL3_ISO_8208      0x07    /* X.25-based */
588 #define Q931_UIL3_X223          0x08    /* X.25-based */
589 #define Q931_UIL3_TR_9577       0x0B
590 #define Q931_UIL3_USER_SPEC     0x10
591
592 static const value_string q931_uil3_vals[] = {
593         { 0x02,                 "Q.931/I.451" },
594         { Q931_UIL3_X25_PL,     "X.25, packet layer" },
595         { Q931_UIL3_ISO_8208,   "ISO/IEC 8208" },
596         { Q931_UIL3_X223,       "X.223/ISO 8878" },
597         { 0x09,                 "ISO/IEC 8473" },
598         { 0x0A,                 "T.70" },
599         { Q931_UIL3_TR_9577,    "ISO/IEC TR 9577" },
600         { Q931_UIL3_USER_SPEC,  "User-specified" },
601         { 0,                    NULL }
602 };
603
604 static void
605 dissect_q931_protocol_discriminator(tvbuff_t *tvb, int offset, proto_tree *tree)
606 {
607         unsigned int discriminator = tvb_get_guint8(tvb, offset);
608
609         if (discriminator == NLPID_Q_931) {
610                 proto_tree_add_uint_format(tree, hf_q931_discriminator,
611                          tvb, offset, 1, discriminator,
612                          "Protocol discriminator: Q.931");
613         } else if (discriminator == NLPID_Q_2931) {
614                 proto_tree_add_uint_format(tree, hf_q931_discriminator,
615                          tvb, offset, 1, discriminator,
616                          "Protocol discriminator: Q.2931");
617         } else if ((discriminator >= 16 && discriminator < 63)
618             || ((discriminator >= 80) && (discriminator < 254))) {
619                 proto_tree_add_uint_format(tree, hf_q931_discriminator,
620                     tvb, offset, 1, discriminator,
621                     "Protocol discriminator: Network layer or layer 3 protocol (0x%02X)",
622                     discriminator);
623         } else if (discriminator >= 64 && discriminator <= 79) {
624                 proto_tree_add_uint_format(tree, hf_q931_discriminator,
625                     tvb, offset, 1, discriminator,
626                     "Protocol discriminator: National use (0x%02X)",
627                     discriminator);
628         } else {
629                 proto_tree_add_uint_format(tree, hf_q931_discriminator,
630                     tvb, offset, 1, discriminator,
631                     "Protocol discriminator: Reserved (0x%02X)",
632                     discriminator);
633         }
634 }
635
636 void
637 dissect_q931_bearer_capability_ie(tvbuff_t *tvb, int offset, int len,
638     proto_tree *tree)
639 {
640         guint8 octet;
641         guint8 coding_standard;
642         guint8 it_rate;
643         guint8 modem_type;
644         guint8 uil2_protocol;
645         guint8 uil3_protocol;
646         guint8 add_l3_info;
647
648         if (len == 0)
649                 return;
650         octet = tvb_get_guint8(tvb, offset);
651         coding_standard = octet & 0x60;
652         if (coding_standard != Q931_ITU_STANDARDIZED_CODING) {
653                 /*
654                  * We don't know how the bearer capability is encoded,
655                  * so just dump it as data and be done with it.
656                  */
657                 proto_tree_add_text(tree, tvb, offset,
658                     len, "Data: %s",
659                     tvb_bytes_to_str(tvb, offset, len));
660                 proto_tree_add_uint(tree, hf_q931_coding_standard, tvb, offset, 1, octet);
661                 proto_tree_add_boolean(tree, hf_q931_extension_ind, tvb, offset, 1, octet);
662                 return;
663         }
664         proto_tree_add_uint(tree, hf_q931_information_transfer_capability, tvb, offset, 1, octet);
665         proto_tree_add_uint(tree, hf_q931_coding_standard, tvb, offset, 1, octet);
666         proto_tree_add_boolean(tree, hf_q931_extension_ind, tvb, offset, 1, octet);
667         offset += 1;
668         len -= 1;
669
670         /*
671          * XXX - only in Low-layer compatibility information element.
672          */
673         if (!(octet & Q931_IE_VL_EXTENSION)) {
674                 if (len == 0)
675                         return;
676                 octet = tvb_get_guint8(tvb, offset);
677                 proto_tree_add_text(tree, tvb, offset, 1,
678                     "Out-band negotiation %spossible",
679                     (octet & 0x40) ? "" : "not ");
680                 offset += 1;
681                 len -= 1;
682         }
683
684         if (len == 0)
685                 return;
686         octet = tvb_get_guint8(tvb, offset);
687         proto_tree_add_uint(tree, hf_q931_information_transfer_rate, tvb, offset, 1, octet);
688         proto_tree_add_uint(tree, hf_q931_transfer_mode, tvb, offset, 1, octet);
689         proto_tree_add_boolean(tree, hf_q931_extension_ind, tvb, offset, 1, octet);
690         it_rate = octet & 0x1F;
691         offset += 1;
692         len -= 1;
693
694         if (it_rate == Q931_IT_RATE_MULTIRATE) {
695                 if (len == 0)
696                         return;
697                 proto_tree_add_text(tree, tvb, offset, 1, "Rate multiplier: %u", tvb_get_guint8(tvb, offset));
698                 offset += 1;
699                 len -= 1;
700         }
701
702         if (len == 0)
703                 return;
704         octet = tvb_get_guint8(tvb, offset);
705         if ((octet & 0x60) == 0x20) {
706                 /*
707                  * Layer 1 information.
708                  */
709                 proto_tree_add_uint(tree, hf_q931_uil1, tvb, offset, 1, octet);
710                 proto_tree_add_boolean(tree, hf_q931_extension_ind, tvb, offset, 1, octet);
711                 offset += 1;
712                 len -= 1;
713
714                 if (octet & Q931_IE_VL_EXTENSION)
715                         goto l1_done;
716                 if (len == 0)
717                         return;
718                 octet = tvb_get_guint8(tvb, offset);
719                 proto_tree_add_text(tree, tvb, offset, 1,
720                     "Layer 1 is %s",
721                     (octet & 0x40) ? "Asynchronous" : "Synchronous");
722                 proto_tree_add_text(tree, tvb, offset, 1,
723                     "Layer 1 in-band negotiation is %spossible",
724                     (octet & 0x20) ? "" : "not ");
725                 proto_tree_add_text(tree, tvb, offset, 1,
726                     "User rate: %s",
727                     val_to_str(octet & 0x1F, q931_l1_user_rate_vals,
728                       "Unknown (0x%02X)"));
729                 offset += 1;
730                 len -= 1;
731
732                 if (octet & Q931_IE_VL_EXTENSION)
733                         goto l1_done;
734                 if (len == 0)
735                         return;
736                 octet = tvb_get_guint8(tvb, offset);
737                 proto_tree_add_text(tree, tvb, offset, 1,
738                     "Intermediate rate: %s",
739                       val_to_str(octet & 0x60, q931_l1_intermediate_rate_vals,
740                        "Unknown (0x%X)"));
741                 proto_tree_add_text(tree, tvb, offset, 1,
742                     "%s to send data with network independent clock",
743                     (octet & 0x10) ? "Required" : "Not required");
744                 proto_tree_add_text(tree, tvb, offset, 1,
745                     "%s accept data with network independent clock",
746                     (octet & 0x08) ? "Can" : "Cannot");
747                 proto_tree_add_text(tree, tvb, offset, 1,
748                     "%s to send data with flow control mechanism",
749                     (octet & 0x04) ? "Required" : "Not required");
750                 proto_tree_add_text(tree, tvb, offset, 1,
751                     "%s accept data with flow control mechanism",
752                     (octet & 0x02) ? "Can" : "Cannot");
753                 offset += 1;
754                 len -= 1;
755
756                 if (octet & Q931_IE_VL_EXTENSION)
757                         goto l1_done;
758                 if (len == 0)
759                         return;
760                 octet = tvb_get_guint8(tvb, offset);
761                 proto_tree_add_text(tree, tvb, offset, 1,
762                     "Rate adaption header %sincluded",
763                     (octet & 0x40) ? "" : "not ");
764                 proto_tree_add_text(tree, tvb, offset, 1,
765                     "Multiple frame establishment %ssupported",
766                     (octet & 0x20) ? "" : "not ");
767                 proto_tree_add_text(tree, tvb, offset, 1,
768                     "%s mode of operation",
769                     (octet & 0x10) ? "Protocol sensitive" : "Bit transparent");
770                 proto_tree_add_text(tree, tvb, offset, 1,
771                     (octet & 0x08) ?
772                       "Full protocol negotiation" : "LLI = 256 only");
773                 proto_tree_add_text(tree, tvb, offset, 1,
774                     "Message originator is %s",
775                     (octet & 0x04) ? "Assignor only" : "Default assignee");
776                 proto_tree_add_text(tree, tvb, offset, 1,
777                     "Negotiation is done %s",
778                     (octet & 0x02) ? "in-band" : "out-of-band");
779                 offset += 1;
780                 len -= 1;
781
782                 if (octet & Q931_IE_VL_EXTENSION)
783                         goto l1_done;
784                 if (len == 0)
785                         return;
786                 octet = tvb_get_guint8(tvb, offset);
787                 proto_tree_add_text(tree, tvb, offset, 1,
788                     "Stop bits: %s",
789                       val_to_str(octet & 0x60, q931_l1_stop_bits_vals,
790                        "Unknown (0x%X)"));
791                 proto_tree_add_text(tree, tvb, offset, 1,
792                     "Data bits: %s",
793                       val_to_str(octet & 0x18, q931_l1_data_bits_vals,
794                        "Unknown (0x%X)"));
795                 proto_tree_add_text(tree, tvb, offset, 1,
796                     "Parity: %s",
797                       val_to_str(octet & 0x07, q931_l1_parity_vals,
798                        "Unknown (0x%X)"));
799
800                 if (octet & Q931_IE_VL_EXTENSION)
801                         goto l1_done;
802                 if (len == 0)
803                         return;
804                 octet = tvb_get_guint8(tvb, offset);
805                 proto_tree_add_text(tree, tvb, offset, 1,
806                     "%s duplex",
807                     (octet & 0x40) ? "Full" : "Half");
808                 modem_type = octet & 0x3F;
809                 if (modem_type <= 0x5 ||
810                     (modem_type >= 0x20 && modem_type <= 0x2F)) {
811                         proto_tree_add_text(tree, tvb, offset, 1,
812                             "Modem type: National use 0x%02X", modem_type);
813                 } else if (modem_type >= 0x30) {
814                         proto_tree_add_text(tree, tvb, offset, 1,
815                             "Modem type: User specified 0x%02X", modem_type);
816                 } else {
817                         proto_tree_add_text(tree, tvb, offset, 1,
818                             "Modem type: %s",
819                               val_to_str(modem_type, q931_l1_modem_type_vals,
820                               "Unknown (0x%02X)"));
821                 }
822                 offset += 1;
823                 len -= 1;
824         }
825 l1_done:
826         ;
827
828         if (len == 0)
829                 return;
830         octet = tvb_get_guint8(tvb, offset);
831         if ((octet & 0x60) == 0x40) {
832                 /*
833                  * Layer 2 information.
834                  */
835                 uil2_protocol = octet & 0x1F;
836                 proto_tree_add_text(tree, tvb, offset, 1,
837                     "User information layer 2 protocol: %s",
838                     val_to_str(uil2_protocol, q931_uil2_vals,
839                       "Unknown (0x%02X)"));
840                 offset += 1;
841                 len -= 1;
842
843                 /*
844                  * XXX - only in Low-layer compatibility information element.
845                  */
846                 if (octet & Q931_IE_VL_EXTENSION)
847                         goto l2_done;
848                 if (len == 0)
849                         return;
850                 octet = tvb_get_guint8(tvb, offset);
851                 if (uil2_protocol == Q931_UIL2_USER_SPEC) {
852                         proto_tree_add_text(tree, tvb, offset, 1,
853                             "User-specified layer 2 protocol information: 0x%02X",
854                             octet & 0x7F);
855                 } else {
856                         proto_tree_add_text(tree, tvb, offset, 1,
857                             "Mode: %s",
858                             val_to_str(octet & 0x60, q931_mode_vals,
859                               "Unknown (0x%02X)"));
860                 }
861                 offset += 1;
862                 len -= 1;
863
864                 if (octet & Q931_IE_VL_EXTENSION)
865                         goto l2_done;
866                 if (len == 0)
867                         return;
868                 octet = tvb_get_guint8(tvb, offset);
869                 proto_tree_add_text(tree, tvb, offset, 1,
870                     "Window size: %u k", octet & 0x7F);
871                 offset += 1;
872                 len -= 1;
873         }
874 l2_done:
875         ;
876
877         if (len == 0)
878                 return;
879         octet = tvb_get_guint8(tvb, offset);
880         if ((octet & 0x60) == 0x60) {
881                 /*
882                  * Layer 3 information.
883                  */
884                 uil3_protocol = octet & 0x1F;
885                 proto_tree_add_text(tree, tvb, offset, 1,
886                     "User information layer 3 protocol: %s",
887                     val_to_str(uil3_protocol, q931_uil3_vals,
888                       "Unknown (0x%02X)"));
889                 offset += 1;
890                 len -= 1;
891
892
893                 /*
894                  * XXX - only in Low-layer compatibility information element.
895                  */
896                 if (octet & Q931_IE_VL_EXTENSION)
897                         goto l3_done;
898                 if (len == 0)
899                         return;
900                 octet = tvb_get_guint8(tvb, offset);
901                 switch (uil3_protocol) {
902
903                 case Q931_UIL3_X25_PL:
904                 case Q931_UIL3_ISO_8208:
905                 case Q931_UIL3_X223:
906                         proto_tree_add_text(tree, tvb, offset, 1,
907                             "Mode: %s",
908                             val_to_str(octet & 0x60, q931_mode_vals,
909                               "Unknown (0x%02X)"));
910                         offset += 1;
911                         len -= 1;
912
913                         if (octet & Q931_IE_VL_EXTENSION)
914                                 goto l3_done;
915                         if (len == 0)
916                                 return;
917                         octet = tvb_get_guint8(tvb, offset);
918                         proto_tree_add_text(tree, tvb, offset, 1,
919                             "Default packet size: %u", octet & 0x0F);
920                         offset += 1;
921                         len -= 1;
922
923                         if (octet & Q931_IE_VL_EXTENSION)
924                                 goto l3_done;
925                         if (len == 0)
926                                 return;
927                         octet = tvb_get_guint8(tvb, offset);
928                         proto_tree_add_text(tree, tvb, offset, 1,
929                             "Packet window size: %u", octet & 0x7F);
930                         offset += 1;
931                         len -= 1;
932                         break;
933
934                 case Q931_UIL3_USER_SPEC:
935                         proto_tree_add_text(tree, tvb, offset, 1,
936                             "Default packet size: %u octets",
937                             1 << (octet & 0x0F));
938                         offset += 1;
939                         len -= 1;
940                         break;
941
942                 case Q931_UIL3_TR_9577:
943                         add_l3_info = (octet & 0x0F) << 4;
944                         if (octet & Q931_IE_VL_EXTENSION)
945                                 goto l3_done;
946                         if (len == 0)
947                                 return;
948                         octet = tvb_get_guint8(tvb, offset + 1);
949                         add_l3_info |= (octet & 0x0F);
950                         proto_tree_add_text(tree, tvb, offset, 2,
951                             "Additional layer 3 protocol information: %s",
952                             val_to_str(add_l3_info, nlpid_vals,
953                               "Unknown (0x%02X)"));
954                         offset += 2;
955                         len -= 2;
956                         break;
957                 }
958         }
959 l3_done:
960         ;
961 }
962
963 /*
964  * Dissect a Cause information element.
965  */
966
967
968 const value_string q931_cause_location_vals[] = {
969         { 0x00, "User (U)" },
970         { 0x01, "Private network serving the local user (LPN)" },
971         { 0x02, "Public network serving the local user (LN)" },
972         { 0x03, "Transit network (TN)" },
973         { 0x04, "Public network serving the remote user (RLN)" },
974         { 0x05, "Private network serving the remote user (RPN)" },
975         { 0x07, "International network (INTL)" },
976         { 0x0A, "Network beyond interworking point (BI)" },
977         { 0,    NULL }
978 };
979
980 static const value_string q931_cause_recommendation_vals[] = {
981         { 0x00, "Q.931" },
982         { 0x03, "X.21" },
983         { 0x04, "X.25" },
984         { 0x05, "Q.1031/Q.1051" },
985         { 0,    NULL }
986 };
987
988 /*
989  * Cause codes for Cause.
990  */
991 #define Q931_CAUSE_UNALLOC_NUMBER       0x01
992 #define Q931_CAUSE_NO_ROUTE_TO_DEST     0x03
993 #define Q931_CAUSE_CALL_REJECTED        0x15
994 #define Q931_CAUSE_NUMBER_CHANGED       0x16
995 #define Q931_CAUSE_ACCESS_INFO_DISC     0x2B
996 #define Q931_CAUSE_QOS_UNAVAILABLE      0x31
997 #define Q931_CAUSE_CHAN_NONEXISTENT     0x52
998 #define Q931_CAUSE_INCOMPATIBLE_DEST    0x58
999 #define Q931_CAUSE_MAND_IE_MISSING      0x60
1000 #define Q931_CAUSE_MT_NONEX_OR_UNIMPL   0x61
1001 #define Q931_CAUSE_IE_NONEX_OR_UNIMPL   0x63
1002 #define Q931_CAUSE_INVALID_IE_CONTENTS  0x64
1003 #define Q931_CAUSE_MSG_INCOMPAT_W_CS    0x65
1004 #define Q931_CAUSE_REC_TIMER_EXP        0x66
1005
1006 const value_string q931_cause_code_vals[] = {
1007         { 0x00,                         "Valid cause code not yet received" },
1008         { Q931_CAUSE_UNALLOC_NUMBER,    "Unallocated (unassigned) number" },
1009         { 0x02,                         "No route to specified transit network" },
1010         { Q931_CAUSE_NO_ROUTE_TO_DEST,  "No route to destination" },
1011         { 0x04,                         "Send special information tone" },
1012         { 0x05,                         "Misdialled trunk prefix" },
1013         { 0x06,                         "Channel unacceptable" },
1014         { 0x07,                         "Call awarded and being delivered in an established channel" },
1015         { 0x08,                         "Prefix 0 dialed but not allowed" },
1016                                         /* Q.850 - "Preemption" */
1017         { 0x09,                         "Prefix 1 dialed but not allowed" },
1018                                         /* Q.850 - "Preemption - circuit reserved for reuse" */
1019         { 0x0A,                         "Prefix 1 dialed but not required" },
1020         { 0x0B,                         "More digits received than allowed, call is proceeding" },
1021         { 0x0E,                         "QoR: ported number" },
1022         { 0x10,                         "Normal call clearing" },
1023         { 0x11,                         "User busy" },
1024         { 0x12,                         "No user responding" },
1025         { 0x13,                         "No answer from user (user alerted)" },
1026         { 0x14,                         "Subscriber absent" },
1027         { Q931_CAUSE_CALL_REJECTED,     "Call rejected" },
1028         { Q931_CAUSE_NUMBER_CHANGED,    "Number changed" },
1029         { 0x17,                         "Reverse charging rejected" },
1030                                         /* Q.850 - "Redirection to new destination" */
1031         { 0x18,                         "Call suspended" },
1032                                         /* Q.850 Amendment 1 - "Call rejected due to feature at the destination" */
1033         { 0x19,                         "Call resumed" },
1034                                         /* Q.850 - "Exchange routing error */
1035         { 0x1A,                         "Non-selected user clearing" },
1036         { 0x1B,                         "Destination out of order" },
1037         { 0x1C,                         "Invalid number format (incomplete number)" },
1038         { 0x1D,                         "Facility rejected" },
1039         { 0x1E,                         "Response to STATUS ENQUIRY" },
1040         { 0x1F,                         "Normal unspecified" },
1041         { 0x21,                         "Circuit out of order" },
1042         { 0x22,                         "No circuit/channel available" },
1043         { 0x23,                         "Destination unattainable" },
1044         { 0x25,                         "Degraded service" },
1045         { 0x26,                         "Network out of order" },
1046         { 0x27,                         "Transit delay range cannot be achieved" },
1047                                         /* Q.850 - "Permanent frame mode connection out of service" */
1048         { 0x28,                         "Throughput range cannot be achieved" },
1049                                         /* Q.850 - "Permanent frame mode connection operational" */
1050         { 0x29,                         "Temporary failure" },
1051         { 0x2A,                         "Switching equipment congestion" },
1052         { Q931_CAUSE_ACCESS_INFO_DISC,  "Access information discarded" },
1053         { 0x2C,                         "Requested circuit/channel not available" },
1054         { 0x2D,                         "Pre-empted" },
1055         { 0x2E,                         "Precedence call blocked" },
1056         { 0x2F,                         "Resources unavailable, unspecified" },
1057         { Q931_CAUSE_QOS_UNAVAILABLE,   "Quality of service unavailable" },
1058         { 0x32,                         "Requested facility not subscribed" },
1059         { 0x33,                         "Reverse charging not allowed" },
1060         { 0x34,                         "Outgoing calls barred" },
1061         { 0x35,                         "Outgoing calls barred within CUG" },
1062         { 0x36,                         "Incoming calls barred" },
1063         { 0x37,                         "Incoming calls barred within CUG" },
1064         { 0x38,                         "Call waiting not subscribed" },
1065         { 0x39,                         "Bearer capability not authorized" },
1066         { 0x3A,                         "Bearer capability not presently available" },
1067         { 0x3E,                         "Inconsistency in designated outgoing access information and subscriber class" },
1068         { 0x3F,                         "Service or option not available, unspecified" },
1069         { 0x41,                         "Bearer capability not implemented" },
1070         { 0x42,                         "Channel type not implemented" },
1071         { 0x43,                         "Transit network selection not implemented" },
1072         { 0x44,                         "Message not implemented" },
1073         { 0x45,                         "Requested facility not implemented" },
1074         { 0x46,                         "Only restricted digital information bearer capability is available" },
1075         { 0x4F,                         "Service or option not implemented, unspecified" },
1076         { 0x51,                         "Invalid call reference value" },
1077         { Q931_CAUSE_CHAN_NONEXISTENT,  "Identified channel does not exist" },
1078         { 0x53,                         "Call identity does not exist for suspended call" },
1079         { 0x54,                         "Call identity in use" },
1080         { 0x55,                         "No call suspended" },
1081         { 0x56,                         "Call having the requested call identity has been cleared" },
1082         { 0x57,                         "Called user not member of CUG" },
1083         { Q931_CAUSE_INCOMPATIBLE_DEST, "Incompatible destination" },
1084         { 0x59,                         "Non-existent abbreviated address entry" },
1085         { 0x5A,                         "Destination address missing, and direct call not subscribed" },
1086                                         /* Q.850 - "Non-existent CUG" */
1087         { 0x5B,                         "Invalid transit network selection (national use)" },
1088         { 0x5C,                         "Invalid facility parameter" },
1089         { 0x5D,                         "Mandatory information element is missing" },
1090         { 0x5F,                         "Invalid message, unspecified" },
1091         { Q931_CAUSE_MAND_IE_MISSING,   "Mandatory information element is missing" },
1092         { Q931_CAUSE_MT_NONEX_OR_UNIMPL,"Message type non-existent or not implemented" },
1093         { 0x62,                         "Message not compatible with call state or message type non-existent or not implemented" },
1094         { Q931_CAUSE_IE_NONEX_OR_UNIMPL,"Information element nonexistant or not implemented" },
1095         { Q931_CAUSE_INVALID_IE_CONTENTS,"Invalid information element contents" },
1096         { Q931_CAUSE_MSG_INCOMPAT_W_CS, "Message not compatible with call state" },
1097         { Q931_CAUSE_REC_TIMER_EXP,     "Recovery on timer expiry" },
1098         { 0x67,                         "Parameter non-existent or not implemented - passed on" },
1099         { 0x6E,                         "Message with unrecognized parameter discarded" },
1100         { 0x6F,                         "Protocol error, unspecified" },
1101         { 0x7F,                         "Internetworking, unspecified" },
1102         { 0,                            NULL }
1103 };
1104
1105 static const value_string q931_cause_condition_vals[] = {
1106         { 0x00, "Unknown" },
1107         { 0x01, "Permanent" },
1108         { 0x02, "Transient" },
1109         { 0x00, NULL }
1110 };
1111
1112 #define Q931_REJ_USER_SPECIFIC          0x00
1113 #define Q931_REJ_IE_MISSING             0x04
1114 #define Q931_REJ_IE_INSUFFICIENT        0x08
1115
1116 static const value_string q931_rejection_reason_vals[] = {
1117         { 0x00, "User specific" },
1118         { 0x04, "Information element missing" },
1119         { 0x08, "Information element contents are not sufficient" },
1120         { 0x00, NULL }
1121 };
1122
1123 void
1124 dissect_q931_cause_ie(tvbuff_t *tvb, int offset, int len,
1125     proto_tree *tree, int hf_cause_value)
1126 {
1127         guint8 octet;
1128         guint8 cause_value;
1129         guint8 coding_standard;
1130         guint8 rejection_reason;
1131
1132         if (len == 0)
1133                 return;
1134         octet = tvb_get_guint8(tvb, offset);
1135         coding_standard = octet & 0x60;
1136         proto_tree_add_uint(tree, hf_q931_coding_standard, tvb, offset, 1, octet);
1137         if (coding_standard != Q931_ITU_STANDARDIZED_CODING) {
1138                 /*
1139                  * We don't know how the cause is encoded,
1140                  * so just dump it as data and be done with it.
1141                  */
1142                 proto_tree_add_text(tree, tvb, offset,
1143                     len, "Data: %s",
1144                     tvb_bytes_to_str(tvb, offset, len));
1145                 return;
1146         }
1147         proto_tree_add_text(tree, tvb, offset, 1,
1148             "Location: %s",
1149             val_to_str(octet & 0x0F, q931_cause_location_vals,
1150               "Unknown (0x%X)"));
1151         proto_tree_add_boolean(tree, hf_q931_extension_ind, tvb, offset, 1, octet);
1152         offset += 1;
1153         len -= 1;
1154
1155         if (!(octet & Q931_IE_VL_EXTENSION)) {
1156                 if (len == 0)
1157                         return;
1158                 octet = tvb_get_guint8(tvb, offset);
1159                 proto_tree_add_text(tree, tvb, offset, 1,
1160                     "Recommendation: %s",
1161                     val_to_str(octet & 0x7F, q931_cause_recommendation_vals,
1162                       "Unknown (0x%02X)"));
1163                 offset += 1;
1164                 len -= 1;
1165         }
1166
1167         if (len == 0)
1168                 return;
1169         octet = tvb_get_guint8(tvb, offset);
1170         cause_value = octet & 0x7F;
1171         proto_tree_add_uint(tree, hf_cause_value, tvb, offset, 1, cause_value);
1172         offset += 1;
1173         len -= 1;
1174
1175         if (len == 0)
1176                 return;
1177         switch (cause_value) {
1178
1179         case Q931_CAUSE_UNALLOC_NUMBER:
1180         case Q931_CAUSE_NO_ROUTE_TO_DEST:
1181         case Q931_CAUSE_QOS_UNAVAILABLE:
1182                 octet = tvb_get_guint8(tvb, offset);
1183                 proto_tree_add_text(tree, tvb, offset, 1,
1184                     "Network service: %s",
1185                     (octet & 0x80) ? "User" : "Provider");
1186                 proto_tree_add_text(tree, tvb, offset, 1,
1187                     "%s",
1188                     (octet & 0x40) ? "Abnormal" : "Normal");
1189                 proto_tree_add_text(tree, tvb, offset, 1,
1190                     "Condition: %s",
1191                     val_to_str(octet & 0x03, q931_cause_condition_vals,
1192                       "Unknown (0x%X)"));
1193                 break;
1194
1195         case Q931_CAUSE_CALL_REJECTED:
1196                 rejection_reason = octet & 0x7C;
1197                 proto_tree_add_text(tree, tvb, offset, 1,
1198                     "Rejection reason: %s",
1199                     val_to_str(octet & 0x7C, q931_rejection_reason_vals,
1200                       "Unknown (0x%X)"));
1201                 proto_tree_add_text(tree, tvb, offset, 1,
1202                     "Condition: %s",
1203                     val_to_str(octet & 0x03, q931_cause_condition_vals,
1204                       "Unknown (0x%X)"));
1205                 offset += 1;
1206                 len -= 1;
1207
1208                 if (len == 0)
1209                         return;
1210                 switch (rejection_reason) {
1211
1212                 case Q931_REJ_USER_SPECIFIC:
1213                         proto_tree_add_text(tree, tvb, offset, len,
1214                             "User specific diagnostic: %s",
1215                             tvb_bytes_to_str(tvb, offset, len));
1216                         break;
1217
1218                 case Q931_REJ_IE_MISSING:
1219                         proto_tree_add_text(tree, tvb, offset, 1,
1220                             "Missing information element: %s",
1221                             val_to_str(tvb_get_guint8(tvb, offset), q931_info_element_vals0,
1222                               "Unknown (0x%02X)"));
1223                         break;
1224
1225                 case Q931_REJ_IE_INSUFFICIENT:
1226                         proto_tree_add_text(tree, tvb, offset, 1,
1227                             "Insufficient information element: %s",
1228                             val_to_str(tvb_get_guint8(tvb, offset), q931_info_element_vals0,
1229                               "Unknown (0x%02X)"));
1230                         break;
1231
1232                 default:
1233                         proto_tree_add_text(tree, tvb, offset, len,
1234                             "Diagnostic: %s",
1235                             tvb_bytes_to_str(tvb, offset, len));
1236                         break;
1237                 }
1238                 break;
1239
1240         case Q931_CAUSE_ACCESS_INFO_DISC:
1241         case Q931_CAUSE_INCOMPATIBLE_DEST:
1242         case Q931_CAUSE_MAND_IE_MISSING:
1243         case Q931_CAUSE_IE_NONEX_OR_UNIMPL:
1244         case Q931_CAUSE_INVALID_IE_CONTENTS:
1245                 do {
1246                         proto_tree_add_text(tree, tvb, offset, 1,
1247                             "Information element: %s",
1248                             val_to_str(tvb_get_guint8(tvb, offset), q931_info_element_vals0,
1249                               "Unknown (0x%02X)"));
1250                         offset += 1;
1251                         len -= 1;
1252                 } while (len != 0);
1253                 break;
1254
1255         case Q931_CAUSE_MT_NONEX_OR_UNIMPL:
1256         case Q931_CAUSE_MSG_INCOMPAT_W_CS:
1257                 proto_tree_add_text(tree, tvb, offset, 1,
1258                     "Message type: %s",
1259                     val_to_str(tvb_get_guint8(tvb, offset), q931_message_type_vals,
1260                       "Unknown (0x%02X)"));
1261                 break;
1262
1263         case Q931_CAUSE_REC_TIMER_EXP:
1264                 if (len < 3)
1265                         return;
1266                 proto_tree_add_text(tree, tvb, offset, 3,
1267                     "Timer: %.3s", tvb_get_ptr(tvb, offset, 3));
1268                 break;
1269
1270         default:
1271                 proto_tree_add_text(tree, tvb, offset, len,
1272                     "Diagnostics: %s",
1273                     tvb_bytes_to_str(tvb, offset, len));
1274         }
1275 }
1276
1277 /*
1278  * Dissect a Call state information element.
1279  */
1280 static const value_string q931_call_state_vals[] = {
1281         { 0x00, "Null" },
1282         { 0x01, "Call initiated" },
1283         { 0x02, "Overlap sending" },
1284         { 0x03, "Outgoing call proceeding" },
1285         { 0x04, "Call delivered" },
1286         { 0x06, "Call present" },
1287         { 0x07, "Call received" },
1288         { 0x08, "Connect request" },
1289         { 0x09, "Incoming call proceeding" },
1290         { 0x0A, "Active" },
1291         { 0x0B, "Disconnect request" },
1292         { 0x0C, "Disconnect indication" },
1293         { 0x0F, "Suspend request" },
1294         { 0x12, "Resume request" },
1295         { 0x13, "Release request" },
1296         { 0x16, "Call abort"},
1297         { 0x19, "Overlap receiving" },
1298         { 0x3D, "Restart request" },
1299         { 0x3E, "Restart" },
1300         { 0,    NULL }
1301 };
1302
1303 static void
1304 dissect_q931_call_state_ie(tvbuff_t *tvb, int offset, int len,
1305     proto_tree *tree)
1306 {
1307         guint8 octet;
1308         guint8 coding_standard;
1309
1310         if (len == 0)
1311                 return;
1312         octet = tvb_get_guint8(tvb, offset);
1313         coding_standard = octet & 0x60;
1314         proto_tree_add_uint(tree, hf_q931_coding_standard, tvb, offset, 1, octet);
1315         if (coding_standard != Q931_ITU_STANDARDIZED_CODING) {
1316                 /*
1317                  * We don't know how the call state is encoded,
1318                  * so just dump it as data and be done with it.
1319                  */
1320                 proto_tree_add_text(tree, tvb, offset,
1321                     len, "Data: %s",
1322                     tvb_bytes_to_str(tvb, offset, len));
1323                 return;
1324         }
1325         proto_tree_add_text(tree, tvb, offset, 1,
1326             "Call state: %s",
1327             val_to_str(octet & 0x3F, q931_call_state_vals,
1328               "Unknown (0x%02X)"));
1329 }
1330
1331 /*
1332  * Dissect a Channel identification information element.
1333  */
1334 #define Q931_INTERFACE_IDENTIFIED       0x40
1335 #define Q931_NOT_BASIC_CHANNEL          0x20
1336
1337 static const value_string q931_basic_channel_selection_vals[] = {
1338         { 0x00, "No channel" },
1339         { 0x01, "B1 channel" },
1340         { 0x02, "B2 channel" },
1341         { 0x03, "Any channel" },
1342         { 0,    NULL }
1343 };
1344
1345 static const value_string q931_not_basic_channel_selection_vals[] = {
1346         { 0x00, "No channel" },
1347         { 0x01, "Channel indicated in following octets" },
1348         { 0x03, "Any channel" },
1349         { 0,    NULL }
1350 };
1351
1352 #define Q931_IS_SLOT_MAP                0x10
1353
1354 static const value_string q931_element_type_vals[] = {
1355         { 0x03, "B-channel units" },
1356         { 0x06, "H0-channel units" },
1357         { 0x08, "H11-channel units" },
1358         { 0x09, "H12-channel units" },
1359         { 0,    NULL }
1360 };
1361
1362 static void
1363 dissect_q931_channel_identification_ie(tvbuff_t *tvb, int offset, int len,
1364     proto_tree *tree)
1365 {
1366         guint8 octet;
1367         int identifier_offset;
1368         int identifier_len;
1369         guint8 coding_standard;
1370
1371         if (len == 0)
1372                 return;
1373         octet = tvb_get_guint8(tvb, offset);
1374         proto_tree_add_text(tree, tvb, offset, 1,
1375             "Interface %s identified",
1376             (octet & Q931_INTERFACE_IDENTIFIED) ? "explicitly" : "implicitly");
1377         proto_tree_add_text(tree, tvb, offset, 1,
1378             "%s interface",
1379             (octet & Q931_NOT_BASIC_CHANNEL) ? "Not basic" : "Basic");
1380         proto_tree_add_text(tree, tvb, offset, 1,
1381             "Indicated channel is %s",
1382             (octet & 0x08) ? "required" : "preferred");
1383         proto_tree_add_text(tree, tvb, offset, 1,
1384             "Indicated channel is %sthe D-channel",
1385             (octet & 0x04) ? "" : "not ");
1386         if (octet & Q931_NOT_BASIC_CHANNEL) {
1387                 proto_tree_add_text(tree, tvb, offset, 1,
1388                     "Channel selection: %s",
1389                     val_to_str(octet & 0x03, q931_not_basic_channel_selection_vals,
1390                       "Unknown (0x%X)"));
1391         } else {
1392                 proto_tree_add_text(tree, tvb, offset, 1,
1393                     "Channel selection: %s",
1394                     val_to_str(octet & 0x03, q931_basic_channel_selection_vals,
1395                       NULL));
1396         }
1397         offset += 1;
1398         len -= 1;
1399
1400         if (octet & Q931_INTERFACE_IDENTIFIED) {
1401                 identifier_offset = offset;
1402                 identifier_len = 0;
1403                 do {
1404                         if (len == 0)
1405                                 break;
1406                         octet = tvb_get_guint8(tvb, offset);
1407                         offset += 1;
1408                         len -= 1;
1409                         identifier_len++;
1410                 } while (!(octet & Q931_IE_VL_EXTENSION));
1411
1412                 /*
1413                  * XXX - do we want to strip off the 8th bit on the
1414                  * last octet of the interface identifier?
1415                  */
1416                 if (identifier_len != 0) {
1417                         proto_tree_add_text(tree, tvb, identifier_offset,
1418                             identifier_len, "Interface identifier: %s",
1419                             bytes_to_str(
1420                               tvb_get_ptr(tvb, identifier_offset, identifier_len),
1421                               identifier_len));
1422                 }
1423         }
1424
1425         if (octet & Q931_NOT_BASIC_CHANNEL) {
1426                 if (len == 0)
1427                         return;
1428                 octet = tvb_get_guint8(tvb, offset);
1429                 coding_standard = octet & 0x60;
1430                 proto_tree_add_uint(tree, hf_q931_coding_standard, tvb, offset, 1, octet);
1431                 if (coding_standard != Q931_ITU_STANDARDIZED_CODING) {
1432                         /*
1433                          * We don't know how the channel identifier is
1434                          * encoded, so just dump it as data and be done
1435                          * with it.
1436                          */
1437                         proto_tree_add_text(tree, tvb, offset,
1438                             len, "Data: %s",
1439                             tvb_bytes_to_str(tvb, offset, len));
1440                         return;
1441                 }
1442                 proto_tree_add_text(tree, tvb, offset, 1,
1443                     "Channel is indicated by %s",
1444                     (octet & Q931_IS_SLOT_MAP) ? "slot map" : "number");
1445                 proto_tree_add_text(tree, tvb, offset, 1,
1446                     "%s type: %s",
1447                     (octet & Q931_IS_SLOT_MAP) ? "Map element" : "Channel",
1448                     val_to_str(octet & 0x0F, q931_element_type_vals,
1449                         "Unknown (0x%02X)"));
1450
1451                 /*
1452                  * XXX - dump the channel number or slot map.
1453                  */
1454         }
1455 }
1456
1457 /*
1458  * Dissect a Progress indicator information element.
1459  */
1460 static const value_string q931_progress_description_vals[] = {
1461         { 0x01, "Call is not end-to-end ISDN - progress information available in-band" },
1462         { 0x02, "Destination address is non-ISDN" },
1463         { 0x03, "Origination address is non-ISDN" },
1464         { 0x04, "Call has returned to the ISDN" },
1465         { 0x05, "Interworking has occurred and has resulted in a telecommunications service change" },
1466         { 0x08, "In-band information or an appropriate pattern is now available" },
1467         { 0,    NULL }
1468 };
1469
1470 void
1471 dissect_q931_progress_indicator_ie(tvbuff_t *tvb, int offset, int len,
1472     proto_tree *tree)
1473 {
1474         guint8 octet;
1475         guint8 coding_standard;
1476
1477         if (len == 0)
1478                 return;
1479         octet = tvb_get_guint8(tvb, offset);
1480         coding_standard = octet & 0x60;
1481         proto_tree_add_uint(tree, hf_q931_coding_standard, tvb, offset, 1, octet);
1482         if (coding_standard != Q931_ITU_STANDARDIZED_CODING) {
1483                 /*
1484                  * We don't know how the progress indicator is encoded,
1485                  * so just dump it as data and be done with it.
1486                  */
1487                 proto_tree_add_text(tree, tvb, offset,
1488                     len, "Data: %s",
1489                     tvb_bytes_to_str(tvb, offset, len));
1490                 return;
1491         }
1492         proto_tree_add_text(tree, tvb, offset, 1,
1493             "Location: %s",
1494             val_to_str(octet & 0x0F, q931_cause_location_vals,
1495               "Unknown (0x%X)"));
1496         offset += 1;
1497         len -= 1;
1498
1499         if (len == 0)
1500                 return;
1501         octet = tvb_get_guint8(tvb, offset);
1502         proto_tree_add_text(tree, tvb, offset, 1,
1503             "Progress description: %s",
1504             val_to_str(octet & 0x7F, q931_progress_description_vals,
1505               "Unknown (0x%02X)"));
1506 }
1507
1508 /*
1509  * Dissect a Network-specific facilities or Transit network selection
1510  * information element.
1511  */
1512 static const value_string q931_netid_type_vals[] = {
1513         { 0x00, "User specified" },
1514         { 0x20, "National network identification" },
1515         { 0x30, "International network identification" },
1516         { 0,    NULL }
1517 };
1518
1519 static const value_string q931_netid_plan_vals[] = {
1520         { 0x00, "Unknown" },
1521         { 0x01, "Carrier Identification Code" },
1522         { 0x03, "X.121 data network identification code" },
1523         { 0,    NULL }
1524 };
1525
1526 static void
1527 dissect_q931_ns_facilities_ie(tvbuff_t *tvb, int offset, int len,
1528     proto_tree *tree)
1529 {
1530         guint8 octet;
1531         int netid_len;
1532
1533         if (len == 0)
1534                 return;
1535         octet = tvb_get_guint8(tvb, offset);
1536         netid_len = octet & 0x7F;
1537         proto_tree_add_text(tree, tvb, offset, 1,
1538             "Network identification length: %u",
1539             netid_len);
1540         offset += 1;
1541         len -= 1;
1542         if (netid_len != 0) {
1543                 if (len == 0)
1544                         return;
1545                 octet = tvb_get_guint8(tvb, offset);
1546                 proto_tree_add_text(tree, tvb, offset, 1,
1547                     "Type of network identification: %s",
1548                     val_to_str(octet & 0x70, q931_netid_type_vals,
1549                       "Unknown (0x%02X)"));
1550                 proto_tree_add_text(tree, tvb, offset, 1,
1551                     "Network identification plan: %s",
1552                     val_to_str(octet & 0x0F, q931_netid_plan_vals,
1553                       "Unknown (0x%02X)"));
1554                 offset += 1;
1555                 len -= 1;
1556                 netid_len--;
1557
1558                 if (len == 0)
1559                         return;
1560                 if (netid_len > len)
1561                         netid_len = len;
1562                 if (netid_len != 0) {
1563                         proto_tree_add_text(tree, tvb, offset, netid_len,
1564                             "Network identification: %s",
1565                             tvb_format_text(tvb, offset, netid_len));
1566                         offset += netid_len;
1567                         len -= netid_len;
1568                 }
1569         }
1570
1571         /*
1572          * Whatever is left is the network-specific facility
1573          * specification.
1574          */
1575          if (len == 0)
1576                 return;
1577         proto_tree_add_text(tree, tvb, offset,
1578             len, "Network-specific facility specification: %s",
1579             tvb_bytes_to_str(tvb, offset, len));
1580 }
1581
1582 /*
1583  * Dissect a Notification indicator information element.
1584  */
1585 static const value_string q931_notification_description_vals[] = {
1586         { 0x00, "User suspended" },
1587         { 0x01, "User resumed" },
1588         { 0x02, "Bearer service change" },
1589         { 0,    NULL }
1590 };
1591
1592 static void
1593 dissect_q931_notification_indicator_ie(tvbuff_t *tvb, int offset, int len,
1594     proto_tree *tree)
1595 {
1596         guint8 octet;
1597
1598         if (len == 0)
1599                 return;
1600         octet = tvb_get_guint8(tvb, offset);
1601         proto_tree_add_text(tree, tvb, offset, 1,
1602             "Notification description: %s",
1603             val_to_str(octet & 0x7F, q931_notification_description_vals,
1604               "Unknown (0x%02X)"));
1605 }
1606
1607 /*
1608  * Dissect a Date/time information element.
1609  */
1610 static void
1611 dissect_q931_date_time_ie(tvbuff_t *tvb, int offset, int len,
1612     proto_tree *tree)
1613 {
1614         if (len != 6) {
1615                 proto_tree_add_text(tree, tvb, offset, len,
1616                     "Date/time: length is %d, should be 6\n", len);
1617                 return;
1618         }
1619         /*
1620          * XXX - what is "year" relative to?  Is "month" 0-origin or
1621          * 1-origin?  Q.931 doesn't say....
1622          */
1623         proto_tree_add_text(tree, tvb, offset, 6,
1624             "Date/time: %02u-%02u-%02u %02u:%02u:%02u",
1625             tvb_get_guint8(tvb, offset + 0), tvb_get_guint8(tvb, offset + 1), tvb_get_guint8(tvb, offset + 2),
1626             tvb_get_guint8(tvb, offset + 3), tvb_get_guint8(tvb, offset + 4), tvb_get_guint8(tvb, offset + 5));
1627 }
1628
1629 /*
1630  * Dissect a Signal information element.
1631  */
1632 static const value_string q931_signal_vals[] = {
1633         { 0x00, "Dial tone on" },
1634         { 0x01, "Ring tone on" },
1635         { 0x02, "Intercept tone on" },
1636         { 0x03, "Network congestion tone on" }, /* "fast busy" */
1637         { 0x04, "Busy tone on" },
1638         { 0x05, "Confirm tone on" },
1639         { 0x06, "Answer tone on" },
1640         { 0x07, "Call waiting tone on" },
1641         { 0x08, "Off-hook warning tone on" },
1642         { 0x09, "Preemption tone on" },
1643         { 0x3F, "Tones off" },
1644         { 0x40, "Alerting on - pattern 0" },
1645         { 0x41, "Alerting on - pattern 1" },
1646         { 0x42, "Alerting on - pattern 2" },
1647         { 0x43, "Alerting on - pattern 3" },
1648         { 0x44, "Alerting on - pattern 4" },
1649         { 0x45, "Alerting on - pattern 5" },
1650         { 0x46, "Alerting on - pattern 6" },
1651         { 0x47, "Alerting on - pattern 7" },
1652         { 0x4F, "Alerting off" },
1653         { 0,    NULL }
1654 };
1655
1656 static void
1657 dissect_q931_signal_ie(tvbuff_t *tvb, int offset, int len,
1658     proto_tree *tree)
1659 {
1660         if (len != 1) {
1661                 proto_tree_add_text(tree, tvb, offset, len,
1662                     "Signal: length is %d, should be 1\n", len);
1663                 return;
1664         }
1665         proto_tree_add_text(tree, tvb, offset, 1,
1666             "Signal: %s",
1667             val_to_str(tvb_get_guint8(tvb, offset), q931_signal_vals,
1668                 "Unknown (0x%02X)"));
1669 }
1670
1671 /*
1672  * Dissect an Information rate information element.
1673  */
1674 static const value_string q931_throughput_class_vals[] = {
1675         { 0x03, "75 bit/s" },
1676         { 0x04, "150 bit/s" },
1677         { 0x05, "300 bit/s" },
1678         { 0x06, "600 bit/s" },
1679         { 0x07, "1200 bit/s" },
1680         { 0x08, "2400 bit/s" },
1681         { 0x09, "4800 bit/s" },
1682         { 0x0A, "9600 bit/s" },
1683         { 0x0B, "19200 bit/s" },
1684         { 0x0C, "48000 bit/s" },
1685         { 0x0D, "64000 bit/s" },
1686         { 0,    NULL }
1687 };
1688
1689 static void
1690 dissect_q931_information_rate_ie(tvbuff_t *tvb, int offset, int len,
1691     proto_tree *tree)
1692 {
1693         if (len != 4) {
1694                 proto_tree_add_text(tree, tvb, offset, len,
1695                     "Information rate: length is %d, should be 4\n", len);
1696                 return;
1697         }
1698         proto_tree_add_text(tree, tvb, offset + 0, 1,
1699             "Incoming information rate: %s",
1700             val_to_str(tvb_get_guint8(tvb, offset + 0) & 0x1F,
1701               q931_throughput_class_vals, "Unknown (0x%02X)"));
1702         proto_tree_add_text(tree, tvb, offset + 1, 1,
1703             "Outgoing information rate: %s",
1704             val_to_str(tvb_get_guint8(tvb, offset + 1) & 0x1F,
1705               q931_throughput_class_vals, "Unknown (0x%02X)"));
1706         proto_tree_add_text(tree, tvb, offset + 2, 1,
1707             "Minimum incoming information rate: %s",
1708             val_to_str(tvb_get_guint8(tvb, offset + 2) & 0x1F,
1709               q931_throughput_class_vals, "Unknown (0x%02X)"));
1710         proto_tree_add_text(tree, tvb, offset + 3, 1,
1711             "Minimum outgoing information rate: %s",
1712             val_to_str(tvb_get_guint8(tvb, offset + 3) & 0x1F,
1713               q931_throughput_class_vals, "Unknown (0x%02X)"));
1714 }
1715
1716 static int
1717 dissect_q931_guint16_value(tvbuff_t *tvb, int offset, int len,
1718     proto_tree *tree, char *label)
1719 {
1720         guint8 octet;
1721         guint16 value;
1722         int value_len;
1723
1724         value_len = 0;
1725
1726         octet = tvb_get_guint8(tvb, offset);
1727         if (octet & Q931_IE_VL_EXTENSION) {
1728                 /*
1729                  * Only one octet long - error.
1730                  */
1731                 goto bad_length;
1732         }
1733         value = (octet & 0x3) << 14;
1734         offset += 1;
1735         len -= 1;
1736         value_len++;
1737
1738         if (len == 0) {
1739                 /*
1740                  * We've reached the end of the information element - error.
1741                  */
1742                 goto past_end;
1743         }
1744         octet = tvb_get_guint8(tvb, offset);
1745         if (octet & Q931_IE_VL_EXTENSION) {
1746                 /*
1747                  * Only two octets long - error.
1748                  */
1749                 goto bad_length;
1750         }
1751         value |= (octet & 0x7F) << 7;
1752         offset += 1;
1753         len -= 1;
1754         value_len++;
1755
1756         if (len == 0) {
1757                 /*
1758                  * We've reached the end of the information element - error.
1759                  */
1760                 goto past_end;
1761         }
1762         octet = tvb_get_guint8(tvb, offset);
1763         if (!(octet & Q931_IE_VL_EXTENSION)) {
1764                 /*
1765                  * More than three octets long - error.
1766                  */
1767                 goto bad_length;
1768         }
1769         value |= (octet & 0x7F);
1770         offset += 1;
1771         len -= 1;
1772         value_len++;
1773
1774         proto_tree_add_text(tree, tvb, offset, value_len, "%s: %u ms", label,
1775             value);
1776         return value_len;
1777
1778 past_end:
1779         proto_tree_add_text(tree, tvb, offset, len,
1780             "%s goes past end of information element", label);
1781         return -1;
1782
1783 bad_length:
1784         proto_tree_add_text(tree, tvb, offset, len, "%s isn't 3 octets long",
1785             label);
1786         return -1;
1787 }
1788
1789 /*
1790  * Dissect an End-to-end transit delay information element.
1791  */
1792 static void
1793 dissect_q931_e2e_transit_delay_ie(tvbuff_t *tvb, int offset, int len,
1794     proto_tree *tree)
1795 {
1796         int value_len;
1797
1798         if (len == 0)
1799                 return;
1800         value_len = dissect_q931_guint16_value(tvb, offset, len, tree,
1801             "Cumulative transit delay");
1802         if (value_len < 0)
1803                 return; /* error */
1804         offset += value_len;
1805         len -= value_len;
1806
1807         if (len == 0)
1808                 return;
1809         value_len = dissect_q931_guint16_value(tvb, offset, len, tree,
1810             "Requested end-to-end transit delay");
1811         if (value_len < 0)
1812                 return; /* error */
1813         offset += value_len;
1814         len -= value_len;
1815
1816         if (len == 0)
1817                 return;
1818         value_len = dissect_q931_guint16_value(tvb, offset, len, tree,
1819             "Maximum end-to-end transit delay");
1820 }
1821
1822 /*
1823  * Dissect a Transit delay selection and indication information element.
1824  */
1825 static void
1826 dissect_q931_td_selection_and_int_ie(tvbuff_t *tvb, int offset, int len,
1827     proto_tree *tree)
1828 {
1829         if (len == 0)
1830                 return;
1831         dissect_q931_guint16_value(tvb, offset, len, tree,
1832             "Transit delay");
1833 }
1834
1835 /*
1836  * Dissect a Packet layer binary parameters information element.
1837  */
1838 static const value_string q931_fast_selected_vals[] = {
1839         { 0x00, "Fast select not requested" },
1840         { 0x08, "Fast select not requested" },
1841         { 0x10, "Fast select requested with no restriction of response" },
1842         { 0x18, "Fast select requested with restrictions of response" },
1843         { 0x00, NULL }
1844 };
1845
1846 static void
1847 dissect_q931_pl_binary_parameters_ie(tvbuff_t *tvb, int offset, int len,
1848     proto_tree *tree)
1849 {
1850         guint8 octet;
1851
1852         if (len == 0)
1853                 return;
1854         octet = tvb_get_guint8(tvb, offset);
1855         proto_tree_add_text(tree, tvb, offset, 1,
1856             "Fast select: %s",
1857             val_to_str(octet & 0x18, q931_fast_selected_vals, NULL));
1858         proto_tree_add_text(tree, tvb, offset, 1,
1859             "%s",
1860             (octet & 0x04) ? "No request/request denied" :
1861                              "Request indicated/request accepted");
1862         proto_tree_add_text(tree, tvb, offset, 1,
1863             "%s confirmation",
1864             (octet & 0x02) ? "Link-by-link" : "End-to-end");
1865         proto_tree_add_text(tree, tvb, offset, 1,
1866             "Modulus %u sequencing",
1867             (octet & 0x01) ? 8 : 128);
1868 }
1869
1870 /*
1871  * Dissect a Packet layer window size information element.
1872  */
1873 static void
1874 dissect_q931_pl_window_size_ie(tvbuff_t *tvb, int offset, int len,
1875     proto_tree *tree)
1876 {
1877         if (len == 0)
1878                 return;
1879         proto_tree_add_text(tree, tvb, offset, 1,
1880             "Forward value: %u", tvb_get_guint8(tvb, offset) & 0x7F);
1881         offset += 1;
1882         len -= 1;
1883
1884         if (len == 0)
1885                 return;
1886         proto_tree_add_text(tree, tvb, offset, 1,
1887             "Backward value: %u", tvb_get_guint8(tvb, offset) & 0x7F);
1888 }
1889
1890 /*
1891  * Dissect a Packet size information element.
1892  */
1893 static void
1894 dissect_q931_packet_size_ie(tvbuff_t *tvb, int offset, int len,
1895     proto_tree *tree)
1896 {
1897         if (len == 0)
1898                 return;
1899         proto_tree_add_text(tree, tvb, offset, 1,
1900             "Forward value: %u", tvb_get_guint8(tvb, offset) & 0x7F);
1901         offset += 1;
1902         len -= 1;
1903
1904         if (len == 0)
1905                 return;
1906         proto_tree_add_text(tree, tvb, offset, 1,
1907             "Backward value: %u", tvb_get_guint8(tvb, offset) & 0x7F);
1908 }
1909
1910 /*
1911  * Dissect a Closed user group information element.
1912  */
1913 static const value_string q931_cug_indication_vals[] = {
1914         { 0x01, "Closed user group selection" },
1915         { 0x02, "Closed user group with outgoing access selection and indication" },
1916         { 0,    NULL }
1917 };
1918
1919 static void
1920 dissect_q931_cug_ie(tvbuff_t *tvb, int offset, int len, proto_tree *tree)
1921 {
1922         if (len == 0)
1923                 return;
1924         proto_tree_add_text(tree, tvb, offset, 1,
1925             "CUG indication: %s",
1926             val_to_str(tvb_get_guint8(tvb, offset) & 0x07,
1927               q931_cug_indication_vals, "Unknown (0x%02X)"));
1928         offset += 1;
1929         len -= 1;
1930
1931         if (len == 0)
1932                 return;
1933         proto_tree_add_text(tree, tvb, offset, len, "CUG index code: %s",
1934             tvb_format_text(tvb, offset, len));
1935 }
1936
1937 /*
1938  * Dissect a Reverse charging indication information element.
1939  */
1940 static const value_string q931_reverse_charging_indication_vals[] = {
1941         { 0x01, "Reverse charging requested" },
1942         { 0,    NULL }
1943 };
1944
1945 static void
1946 dissect_q931_reverse_charge_ind_ie(tvbuff_t *tvb, int offset, int len,
1947     proto_tree *tree)
1948 {
1949         if (len == 0)
1950                 return;
1951         proto_tree_add_text(tree, tvb, offset, 1,
1952             "Reverse charging indication: %s",
1953             val_to_str(tvb_get_guint8(tvb, offset) & 0x07,
1954               q931_reverse_charging_indication_vals, "Unknown (0x%02X)"));
1955 }
1956
1957 /*
1958  * Dissect a (phone) number information element.
1959  */
1960 static const value_string q931_number_type_vals[] = {
1961         { 0x0, "Unknown" },
1962         { 0x1, "International number" },
1963         { 0x2, "National number" },
1964         { 0x3, "Network specific number" },
1965         { 0x4, "Subscriber number" },
1966         { 0x6, "Abbreviated number" },
1967         { 0,    NULL }
1968 };
1969
1970 static const value_string q931_numbering_plan_vals[] = {
1971         { 0x00, "Unknown" },
1972         { 0x01, "E.164 ISDN/telephony numbering" },
1973         { 0x03, "X.121 data numbering" },
1974         { 0x04, "F.69 Telex numbering" },
1975         { 0x08, "National standard numbering" },
1976         { 0x09, "Private numbering" },
1977         { 0,    NULL }
1978 };
1979
1980 static const value_string q931_presentation_indicator_vals[] = {
1981         { 0x00, "Presentation allowed" },
1982         { 0x20, "Presentation restricted" },
1983         { 0x40, "Number not available due to interworking" },
1984         { 0,    NULL }
1985 };
1986
1987 static const value_string q931_screening_indicator_vals[] = {
1988         { 0x00, "User-provided, not screened" },
1989         { 0x01, "User-provided, verified and passed" },
1990         { 0x02, "User-provided, verified and failed" },
1991         { 0x03, "Network-provided" },
1992         { 0,    NULL }
1993 };
1994
1995 static const value_string q931_redirection_reason_vals[] = {
1996         { 0x00, "Unknown" },
1997         { 0x01, "Call forwarding busy or called DTE busy" },
1998         { 0x02, "Call forwarding no reply" },
1999         { 0x04, "Call deflection" },
2000         { 0x09, "Called DTE out of order" },
2001         { 0x0A, "Call forwarding by the called DTE" },
2002         { 0x0F, "Call forwarding unconditional or systematic call redirection" },
2003         { 0,    NULL }
2004 };
2005
2006 static void
2007 dissect_q931_number_ie(tvbuff_t *tvb, int offset, int len,
2008     proto_tree *tree, int hfindex)
2009 {
2010         guint8 octet;
2011
2012         if (len == 0)
2013                 return;
2014         octet = tvb_get_guint8(tvb, offset);
2015         proto_tree_add_uint(tree, hf_q931_numbering_plan, tvb, offset, 1, octet);
2016         proto_tree_add_uint(tree, hf_q931_number_type, tvb, offset, 1, octet);
2017         proto_tree_add_boolean(tree, hf_q931_extension_ind, tvb, offset, 1, octet);
2018         
2019         offset += 1;
2020         len -= 1;
2021
2022         if (!(octet & Q931_IE_VL_EXTENSION)) {
2023                 if (len == 0)
2024                         return;
2025                 octet = tvb_get_guint8(tvb, offset);
2026                 proto_tree_add_text(tree, tvb, offset, 1,
2027                     "Presentation indicator: %s",
2028                     val_to_str(octet & 0x60, q931_presentation_indicator_vals,
2029                       "Unknown (0x%X)"));
2030                 proto_tree_add_text(tree, tvb, offset, 1,
2031                     "Screening indicator: %s",
2032                     val_to_str(octet & 0x03, q931_screening_indicator_vals,
2033                       "Unknown (0x%X)"));
2034                 offset += 1;
2035                 len -= 1;
2036         }
2037
2038         /*
2039          * XXX - only in a Redirecting number information element.
2040          */
2041         if (!(octet & Q931_IE_VL_EXTENSION)) {
2042                 if (len == 0)
2043                         return;
2044                 octet = tvb_get_guint8(tvb, offset);
2045                 proto_tree_add_text(tree, tvb, offset, 1,
2046                     "Reason for redirection: %s",
2047                     val_to_str(octet & 0x0F, q931_redirection_reason_vals,
2048                       "Unknown (0x%X)"));
2049                 offset += 1;
2050                 len -= 1;
2051         }
2052
2053         if (len == 0)
2054                 return;
2055         proto_tree_add_item(tree, hfindex, tvb, offset, len, FALSE);
2056 }
2057
2058 /*
2059  * Dissect a party subaddress information element.
2060  */
2061 static const value_string q931_subaddress_type_vals[] = {
2062         { 0x00, "X.213/ISO 8348 Add.2 NSAP" },
2063         { 0x20, "User-specified" },
2064         { 0,    NULL }
2065 };
2066
2067 static const value_string q931_odd_even_indicator_vals[] = {
2068         { 0x00, "Even number of address signals" },
2069         { 0x10, "Odd number of address signals" },
2070         { 0,    NULL }
2071 };
2072
2073 static void
2074 dissect_q931_party_subaddr_ie(tvbuff_t *tvb, int offset, int len,
2075     proto_tree *tree)
2076 {
2077         guint8 octet;
2078
2079         if (len == 0)
2080                 return;
2081         octet = tvb_get_guint8(tvb, offset);
2082         proto_tree_add_text(tree, tvb, offset, 1,
2083             "Type of subaddress: %s",
2084             val_to_str(octet & 0x70, q931_subaddress_type_vals,
2085               "Unknown (0x%02X)"));
2086         proto_tree_add_text(tree, tvb, offset, 1,
2087             "Odd/even indicator: %s",
2088             val_to_str(octet & 0x10, q931_odd_even_indicator_vals,
2089               NULL));
2090         offset += 1;
2091         len -= 1;
2092
2093         if (len == 0)
2094                 return;
2095         proto_tree_add_text(tree, tvb, offset, len, "Subaddress: %s",
2096             tvb_bytes_to_str(tvb, offset, len));
2097 }
2098
2099 /*
2100  * Dissect a Restart indicator information element.
2101  */
2102 static const value_string q931_restart_indicator_class_vals[] = {
2103         { 0x00, "Indicated channels" },
2104         { 0x06, "Single interface" },
2105         { 0x07, "All interfaces" },
2106         { 0,    NULL }
2107 };
2108
2109 static void
2110 dissect_q931_restart_indicator_ie(tvbuff_t *tvb, int offset, int len,
2111     proto_tree *tree)
2112 {
2113         if (len != 1) {
2114                 proto_tree_add_text(tree, tvb, offset, len,
2115                     "Restart indicator: length is %d, should be 1\n", len);
2116                 return;
2117         }
2118         proto_tree_add_text(tree, tvb, offset, 1,
2119             "Restart indicator: %s",
2120             val_to_str(tvb_get_guint8(tvb, offset) & 0x07,
2121               q931_restart_indicator_class_vals, "Unknown (0x%02X)"));
2122 }
2123
2124 /*
2125  * Dissect a High-layer compatibility information element.
2126  */
2127 #define Q931_AUDIOVISUAL        0x60
2128 static const value_string q931_high_layer_characteristics_vals[] = {
2129         { 0x01,             "Telephony" },
2130         { 0x04,             "F.182 Facsimile Group 2/3" },
2131         { 0x21,             "F.184 Facsimile Group 4 Class I" },
2132         { 0x24,             "F.230 Teletex, basic and mixed mode, and F.184 Facsimile Group 4, Classes II and III" },
2133         { 0x28,             "F.220 Teletex, basic and processable mode" },
2134         { 0x31,             "F.200 Teletex, basic mode" },
2135         { 0x32,             "F.300 and T.102 syntax-based Videotex" },
2136         { 0x33,             "F.300 and T.101 international Videotex interworking" },
2137         { 0x35,             "F.60 Telex" },
2138         { 0x38,             "X.400 Message Handling Systems" },
2139         { 0x41,             "X.200 OSI application" },
2140         { 0x42,             "FTAM application" },
2141         { 0x5E,             "Reserved for maintenance" },
2142         { 0x5F,             "Reserved for management" },
2143         { Q931_AUDIOVISUAL, "F.720/F.821 and F.731 Profile 1a videotelephony" },
2144         { 0x61,             "F.702 and F.731 Profile 1b videoconferencing" },
2145         { 0x62,             "F.702 and F.731 audiographic conferencing" },
2146         { 0,                NULL }
2147 };
2148
2149 static const value_string q931_audiovisual_characteristics_vals[] = {
2150         { 0x01, "Capability set of initial channel of H.221" },
2151         { 0x02, "Capability set of subsequent channel of H.221" },
2152         { 0x21, "Capability set of initial channel of an active 3.1kHz audio or speech call" },
2153         { 0x00, NULL }
2154 };
2155
2156 void
2157 dissect_q931_high_layer_compat_ie(tvbuff_t *tvb, int offset, int len,
2158     proto_tree *tree)
2159 {
2160         guint8 octet;
2161         guint8 coding_standard;
2162         guint8 characteristics;
2163
2164         if (len == 0)
2165                 return;
2166         octet = tvb_get_guint8(tvb, offset);
2167         coding_standard = octet & 0x60;
2168         proto_tree_add_uint(tree, hf_q931_coding_standard, tvb, offset, 1, octet);
2169         offset += 1;
2170         len -= 1;
2171         if (coding_standard != Q931_ITU_STANDARDIZED_CODING) {
2172                 /*
2173                  * We don't know how the call state is encoded,
2174                  * so just dump it as data and be done with it.
2175                  */
2176                 proto_tree_add_text(tree, tvb, offset,
2177                     len, "Data: %s",
2178                     tvb_bytes_to_str(tvb, offset, len));
2179                 return;
2180         }
2181
2182         if (len == 0)
2183                 return;
2184         octet = tvb_get_guint8(tvb, offset);
2185         characteristics = octet & 0x7F;
2186         proto_tree_add_text(tree, tvb, offset, 1,
2187             "High layer characteristics identification: %s",
2188             val_to_str(characteristics, q931_high_layer_characteristics_vals,
2189              "Unknown (0x%02X)"));
2190         offset += 1;
2191         len -= 1;
2192
2193         if (!(octet & Q931_IE_VL_EXTENSION)) {
2194                 if (len == 0)
2195                         return;
2196                 octet = tvb_get_guint8(tvb, offset);
2197                 if (characteristics == Q931_AUDIOVISUAL) {
2198                         proto_tree_add_text(tree, tvb, offset, 1,
2199                             "Extended audiovisual characteristics identification: %s",
2200                             val_to_str(octet & 0x7F,
2201                               q931_audiovisual_characteristics_vals,
2202                               "Unknown (0x%02X)"));
2203                 } else {
2204                         proto_tree_add_text(tree, tvb, offset, 1,
2205                             "Extended high layer characteristics identification: %s",
2206                             val_to_str(octet & 0x7F,
2207                               q931_high_layer_characteristics_vals,
2208                               "Unknown (0x%02X)"));
2209                 }
2210         }
2211 }
2212
2213
2214 /*
2215  * Dissect a User-user information element.
2216  */
2217 #define Q931_PROTOCOL_DISCRIMINATOR_IA5         0x04
2218 #define Q931_PROTOCOL_DISCRIMINATOR_ASN1        0x05
2219
2220 static const value_string q931_protocol_discriminator_vals[] = {
2221         { 0x00,                                 "User-specific protocol" },
2222         { 0x01,                                 "OSI high layer protocols" },
2223         { 0x02,                                 "X.244" },
2224         { Q931_PROTOCOL_DISCRIMINATOR_IA5,      "IA5 characters" },
2225         { Q931_PROTOCOL_DISCRIMINATOR_ASN1,     "X.208 and X.209 coded user information" },
2226         { 0x07,                                 "V.120 rate adaption" },
2227         { 0x08,                                 "Q.931/I.451 user-network call control messages" },
2228         { 0,                                    NULL }
2229 };
2230
2231 void
2232 dissect_q931_user_user_ie(tvbuff_t *tvb, int offset, int len,
2233     proto_tree *tree)
2234 {
2235         guint8 octet;
2236
2237         if (len == 0)
2238                 return;
2239         octet = tvb_get_guint8(tvb, offset);
2240         proto_tree_add_text(tree, tvb, offset, 1,
2241             "Protocol discriminator: %s",
2242             val_to_str(octet, q931_protocol_discriminator_vals,
2243             "Unknown (0x%02x)"));
2244         offset += 1;
2245         len -= 1;
2246
2247         if (len == 0)
2248                 return;
2249         switch (octet) {
2250
2251         case Q931_PROTOCOL_DISCRIMINATOR_IA5:
2252                 proto_tree_add_text(tree, tvb, offset, len, "User information: %s",
2253                     tvb_format_text(tvb, offset, len));
2254                 break;
2255
2256         default:
2257                 proto_tree_add_text(tree, tvb, offset, len, "User information: %s",
2258                     tvb_bytes_to_str(tvb, offset, len));
2259                 break;
2260         }
2261 }
2262
2263 /*
2264  * Dissect information elements consisting of ASCII^H^H^H^H^HIA5 text.
2265  */
2266 static void
2267 dissect_q931_ia5_ie(tvbuff_t *tvb, int offset, int len, proto_tree *tree,
2268     char *label)
2269 {
2270         if (len != 0) {
2271                 proto_tree_add_text(tree, tvb, offset, len, "%s: %s", label,
2272                     tvb_format_text(tvb, offset, len));
2273         }
2274 }
2275
2276 static const value_string q931_codeset_vals[] = {
2277         { 0x00, "Q.931 information elements" },
2278         { 0x04, "Information elements for ISO/IEC use" },
2279         { 0x05, "Information elements for national use" },
2280         { 0x06, "Information elements specific to the local network" },
2281         { 0x07, "User-specific information elements" },
2282         { 0x00, NULL },
2283 };
2284
2285 static void
2286 dissect_q931_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
2287     gboolean is_tpkt)
2288 {
2289         int             offset = 0;
2290         proto_tree      *q931_tree = NULL;
2291         proto_item      *ti;
2292         proto_tree      *ie_tree = NULL;
2293         guint8          call_ref_len;
2294         guint8          call_ref[15];
2295         guint8          message_type;
2296         guint8          info_element;
2297         guint16         info_element_len;
2298         int             codeset, locked_codeset;
2299         gboolean        non_locking_shift;
2300         tvbuff_t        *h225_tvb, *next_tvb;
2301
2302         if (check_col(pinfo->cinfo, COL_PROTOCOL))
2303                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Q.931");
2304
2305         if (tree) {
2306                 ti = proto_tree_add_item(tree, proto_q931, tvb, offset, -1,
2307                     FALSE);
2308                 q931_tree = proto_item_add_subtree(ti, ett_q931);
2309
2310                 dissect_q931_protocol_discriminator(tvb, offset, q931_tree);
2311         }
2312         offset += 1;
2313         call_ref_len = tvb_get_guint8(tvb, offset) & 0xF;       /* XXX - do as a bit field? */
2314         if (q931_tree != NULL)
2315                 proto_tree_add_uint(q931_tree, hf_q931_call_ref_len, tvb, offset, 1, call_ref_len);
2316         offset += 1;
2317         if (call_ref_len != 0) {
2318                 tvb_memcpy(tvb, call_ref, offset, call_ref_len);
2319                 if (q931_tree != NULL) {
2320                         proto_tree_add_boolean(q931_tree, hf_q931_call_ref_flag,
2321                             tvb, offset, 1, (call_ref[0] & 0x80) != 0);
2322                         call_ref[0] &= 0x7F;
2323                         proto_tree_add_bytes(q931_tree, hf_q931_call_ref,
2324                             tvb, offset, call_ref_len, call_ref);
2325                 }
2326                 offset += call_ref_len;
2327         }
2328         message_type = tvb_get_guint8(tvb, offset);
2329         if (check_col(pinfo->cinfo, COL_INFO)) {
2330                 col_add_str(pinfo->cinfo, COL_INFO,
2331                     val_to_str(message_type, q931_message_type_vals,
2332                       "Unknown message type (0x%02X)"));
2333         }
2334         if (q931_tree != NULL)
2335                 proto_tree_add_uint(q931_tree, hf_q931_message_type, tvb, offset, 1, message_type);
2336         offset += 1;
2337
2338         /*
2339          * And now for the information elements....
2340          */
2341         codeset = locked_codeset = 0;   /* start out in codeset 0 */
2342         non_locking_shift = TRUE;
2343         while (tvb_reported_length_remaining(tvb, offset) > 0) {
2344                 info_element = tvb_get_guint8(tvb, offset);
2345
2346                  /* Check for the codeset shift */
2347                 if ((info_element & Q931_IE_SO_MASK) &&
2348                     ((info_element & Q931_IE_SO_IDENTIFIER_MASK) == Q931_IE_SHIFT)) {
2349                         non_locking_shift = info_element & Q931_IE_SHIFT_NON_LOCKING;
2350                         codeset = info_element & Q931_IE_SHIFT_CODESET;
2351                         if(codeset>=NUM_INFO_ELEMENT_VALS){
2352                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2353                                         "Invalid codeset: %d", codeset);
2354                                 return;
2355                         }
2356                         if (!non_locking_shift)
2357                                 locked_codeset = codeset;
2358                         if (q931_tree != NULL) {
2359                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2360                                     "%s shift to codeset %u: %s",
2361                                     (non_locking_shift ? "Non-locking" : "Locking"),
2362                                     codeset,
2363                                     val_to_str(codeset, q931_codeset_vals,
2364                                       "Unknown (0x%02X)"));
2365                         }
2366                         offset += 1;
2367                         continue;
2368                 }
2369
2370                 /*
2371                  * Check for the single-octet IEs.
2372                  */
2373                 if (info_element & Q931_IE_SO_MASK) {
2374                         /*
2375                          * Check for subdissectors for this IE or
2376                          * for all IEs in this codeset.
2377                          */
2378                         if (dissector_get_port_handle(codeset_dissector_table, codeset) ||
2379                             dissector_get_port_handle(ie_dissector_table, (codeset << 8) | (info_element & Q931_IE_SO_IDENTIFIER_MASK))) {
2380                                 next_tvb = tvb_new_subset (tvb, offset, 1, 1);
2381                                 if (dissector_try_port(ie_dissector_table, (codeset << 8) | (info_element & Q931_IE_SO_IDENTIFIER_MASK), next_tvb, pinfo, q931_tree) ||
2382                                     dissector_try_port(codeset_dissector_table, codeset, next_tvb, pinfo, q931_tree)) {
2383                                         offset += 1;
2384                                         codeset = locked_codeset;
2385                                         if(codeset>=NUM_INFO_ELEMENT_VALS){
2386                                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2387                                                 "Invalid codeset: %d", codeset);
2388                                                 return;
2389                                         }
2390                                         continue;
2391                                 }
2392                         }
2393
2394                         switch ((codeset << 8) | (info_element & Q931_IE_SO_IDENTIFIER_MASK)) {
2395
2396                         case CS0 | Q931_IE_MORE_DATA_OR_SEND_COMP:
2397                                 switch (info_element) { 
2398
2399                                 case Q931_IE_MORE_DATA:
2400                                         if (q931_tree != NULL) {
2401                                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2402                                                     "More data");
2403                                         }
2404                                         break;
2405
2406                                 case Q931_IE_SENDING_COMPLETE:
2407                                         if (q931_tree != NULL) {
2408                                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2409                                                     "Sending complete");
2410                                         }
2411                                         break;
2412
2413                                 default:
2414                                         if (q931_tree != NULL) {
2415                                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2416                                                     "Unknown information element (0x%02X)",
2417                                                     info_element);
2418                                         }
2419                                         break;
2420                                 }
2421                                 break;
2422
2423                         case CS0 | Q931_IE_CONGESTION_LEVEL:
2424                                 if (q931_tree != NULL) {
2425                                         proto_tree_add_text(q931_tree, tvb, offset, 1,
2426                                             "Congestion level: %s",
2427                                             val_to_str(info_element & Q931_IE_SO_IE_MASK,
2428                                               q931_congestion_level_vals,
2429                                               "Unknown (0x%X)"));
2430                                 }
2431                                 break;
2432
2433                         case CS0 | Q931_IE_REPEAT_INDICATOR:
2434                                 if (q931_tree != NULL) {
2435                                         proto_tree_add_text(q931_tree, tvb, offset, 1,
2436                                             "Repeat indicator: %s",
2437                                             val_to_str(info_element & Q931_IE_SO_IE_MASK,
2438                                           q931_repeat_indication_vals,
2439                                               "Unknown (0x%X)"));
2440                                 }
2441                                 break;
2442
2443                         default:
2444                                 if (q931_tree != NULL) {
2445                                         proto_tree_add_text(q931_tree, tvb, offset, 1,
2446                                             "Unknown information element (0x%02X)",
2447                                             info_element);
2448                                 }
2449                                 break;
2450                         }
2451                         offset += 1;
2452                         codeset = locked_codeset;
2453                         if(codeset>=NUM_INFO_ELEMENT_VALS){
2454                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2455                                 "Invalid codeset: %d", codeset);
2456                                 return;
2457                         }
2458                         continue;
2459                 }
2460
2461                 /*
2462                  * Variable-length IE.
2463                  *
2464                  * According to page 18 from Recommendation H.225.0 :
2465                  * " Length of user-user contents contents
2466                  * - Shall be 2 octets instead of 1 (as in Figure 4-36/Q.931)"
2467                  *
2468                  * We assume that if this is Q.931-over-TPKT, it might
2469                  * be H.225 traffic, and check for the IE being a user-user
2470                  * IE with ASN.1 encoding of the user information.
2471                  */
2472                 if (is_tpkt && tvb_bytes_exist(tvb, offset, 4) &&
2473                     codeset == 0 && tvb_get_guint8(tvb, offset) == Q931_IE_USER_USER &&
2474                     tvb_get_guint8(tvb, offset + 3) == Q931_PROTOCOL_DISCRIMINATOR_ASN1)  {
2475                         info_element_len = tvb_get_ntohs(tvb, offset + 1);
2476                         if (q931_tree != NULL) {
2477                                 ti = proto_tree_add_text(q931_tree, tvb, offset,
2478                                     1+2+info_element_len, "%s",
2479                                     val_to_str(info_element,
2480                                       q931_info_element_vals[codeset],
2481                                       "Unknown information element (0x%02X)"));
2482                                 ie_tree = proto_item_add_subtree(ti,
2483                                     ett_q931_ie);
2484                                 proto_tree_add_text(ie_tree, tvb, offset, 1,
2485                                     "Information element: %s",
2486                                     val_to_str(info_element,
2487                                       q931_info_element_vals[codeset], "Unknown (0x%02X)"));
2488                                 proto_tree_add_text(ie_tree, tvb, offset + 1,
2489                                     2, "Length: %u", info_element_len);
2490                                 proto_tree_add_text(ie_tree, tvb, offset + 3,
2491                                     1, "Protocol discriminator: %s",
2492                                     val_to_str(tvb_get_guint8(tvb, offset + 3),
2493                                       q931_protocol_discriminator_vals,
2494                                       "Unknown (0x%02x)"));
2495                         }
2496
2497                         if (info_element_len > 1) {
2498                                 /*
2499                                  * Do we have a handle for the H.225
2500                                  * dissector?
2501                                  */
2502                                 if (h225_handle != NULL) {
2503                                         /*
2504                                          * Yes - call it, regardless of
2505                                          * whether we're building a
2506                                          * protocol tree or not.
2507                                          */
2508                                         h225_tvb = tvb_new_subset(tvb,
2509                                             offset + 4, info_element_len - 1,
2510                                             info_element_len - 1);
2511                                         call_dissector(h225_handle, h225_tvb,
2512                                             pinfo, tree);
2513                                 } else {
2514                                         /*
2515                                          * No - just show it as "User
2516                                          * information" (if "ie_tree" is
2517                                          * null, this won't add anything).
2518                                          */
2519                                         proto_tree_add_text(ie_tree, tvb,
2520                                             offset + 4, info_element_len - 1,
2521                                             "User information: %s",
2522                                             tvb_bytes_to_str(tvb, offset + 4,
2523                                               info_element_len - 1));
2524                                 }
2525                         }
2526                         offset += 1 + 2 + info_element_len;
2527                 } else {
2528                         info_element_len = tvb_get_guint8(tvb, offset + 1);
2529
2530                         /*
2531                          * Check for subdissectors for this IE or
2532                          * for all IEs in this codeset.
2533                          */
2534                         if (dissector_get_port_handle(codeset_dissector_table, codeset) ||
2535                             dissector_get_port_handle(ie_dissector_table, (codeset << 8) | info_element)) {
2536                                 next_tvb = tvb_new_subset (tvb, offset, info_element_len + 2, info_element_len + 2);
2537                                 if (dissector_try_port(ie_dissector_table, (codeset << 8) | info_element, next_tvb, pinfo, q931_tree) ||
2538                                     dissector_try_port(codeset_dissector_table, codeset, next_tvb, pinfo, q931_tree)) {
2539                                         offset += 2 + info_element_len;
2540                                         codeset = locked_codeset;
2541                                         if(codeset>=NUM_INFO_ELEMENT_VALS){
2542                                                 proto_tree_add_text(q931_tree, tvb, offset, 1,
2543                                                 "Invalid codeset: %d", codeset);
2544                                                 return;
2545                                         }
2546                                         continue;
2547                                 }
2548                         }
2549
2550                         if (q931_tree != NULL) {
2551                                 ti = proto_tree_add_text(q931_tree, tvb, offset,
2552                                     1+1+info_element_len, "%s",
2553                                     val_to_str(info_element, q931_info_element_vals[codeset],
2554                                       "Unknown information element (0x%02X)"));
2555                                         ie_tree = proto_item_add_subtree(ti, ett_q931_ie);
2556                                 proto_tree_add_text(ie_tree, tvb, offset, 1,
2557                                     "Information element: %s",
2558                                     val_to_str(info_element, q931_info_element_vals[codeset],
2559                                       "Unknown (0x%02X)"));
2560                                 proto_tree_add_text(ie_tree, tvb, offset + 1, 1,
2561                                     "Length: %u", info_element_len);
2562
2563                                 switch ((codeset << 8) | info_element) {
2564
2565                                 case CS0 | Q931_IE_SEGMENTED_MESSAGE:
2566                                         dissect_q931_segmented_message_ie(tvb,
2567                                             offset + 2, info_element_len,
2568                                             ie_tree);
2569                                         break;
2570
2571                                 case CS0 | Q931_IE_BEARER_CAPABILITY:
2572                                 case CS0 | Q931_IE_LOW_LAYER_COMPAT:
2573                                         dissect_q931_bearer_capability_ie(tvb,
2574                                             offset + 2, info_element_len,
2575                                             ie_tree);
2576                                         break;
2577
2578                                 case CS0 | Q931_IE_CAUSE:
2579                                         dissect_q931_cause_ie(tvb,
2580                                             offset + 2, info_element_len,
2581                                             ie_tree,
2582                                             hf_q931_cause_value);
2583                                         break;
2584
2585                                 case CS0 | Q931_IE_CALL_STATE:
2586                                         dissect_q931_call_state_ie(tvb,
2587                                             offset + 2, info_element_len,
2588                                             ie_tree);
2589                                         break;
2590
2591                                 case CS0 | Q931_IE_CHANNEL_IDENTIFICATION:
2592                                         dissect_q931_channel_identification_ie(
2593                                             tvb, offset + 2, info_element_len,
2594                                             ie_tree);
2595                                         break;
2596
2597                                 case CS0 | Q931_IE_PROGRESS_INDICATOR:
2598                                         dissect_q931_progress_indicator_ie(tvb,
2599                                             offset + 2, info_element_len,
2600                                             ie_tree);
2601                                         break;
2602
2603                                 case CS0 | Q931_IE_NETWORK_SPECIFIC_FACIL:
2604                                 case CS0 | Q931_IE_TRANSIT_NETWORK_SEL:
2605                                         dissect_q931_ns_facilities_ie(tvb,
2606                                             offset + 2, info_element_len,
2607                                             ie_tree);
2608                                         break;
2609
2610                                 case CS0 | Q931_IE_NOTIFICATION_INDICATOR:
2611                                         dissect_q931_notification_indicator_ie(
2612                                             tvb, offset + 2, info_element_len,
2613                                             ie_tree);
2614                                         break;
2615
2616                                 case CS0 | Q931_IE_DISPLAY:
2617                                         dissect_q931_ia5_ie(tvb, offset + 2,
2618                                             info_element_len, ie_tree,
2619                                             "Display information");
2620                                         break;
2621
2622                                 case CS0 | Q931_IE_DATE_TIME:
2623                                         dissect_q931_date_time_ie(tvb,
2624                                             offset + 2, info_element_len,
2625                                             ie_tree);
2626                                         break;
2627
2628                                 case CS0 | Q931_IE_KEYPAD_FACILITY:
2629                                         dissect_q931_ia5_ie(tvb, offset + 2,
2630                                             info_element_len, ie_tree,
2631                                             "Keypad facility");
2632                                         break;
2633
2634                                 case CS0 | Q931_IE_SIGNAL:
2635                                         dissect_q931_signal_ie(tvb,
2636                                             offset + 2, info_element_len,
2637                                             ie_tree);
2638                                         break;
2639
2640                                 case CS0 | Q931_IE_INFORMATION_RATE:
2641                                         dissect_q931_information_rate_ie(tvb,
2642                                             offset + 2, info_element_len,
2643                                             ie_tree);
2644                                         break;
2645
2646                                 case CS0 | Q931_IE_E2E_TRANSIT_DELAY:
2647                                         dissect_q931_e2e_transit_delay_ie(tvb,
2648                                             offset + 2, info_element_len,
2649                                             ie_tree);
2650                                         break;
2651
2652                                 case CS0 | Q931_IE_TD_SELECTION_AND_INT:
2653                                         dissect_q931_td_selection_and_int_ie(
2654                                             tvb, offset + 2, info_element_len,
2655                                             ie_tree);
2656                                         break;
2657
2658                                 case CS0 | Q931_IE_PL_BINARY_PARAMETERS:
2659                                         dissect_q931_pl_binary_parameters_ie(
2660                                             tvb, offset + 2, info_element_len,
2661                                             ie_tree);
2662                                         break;
2663
2664                                 case CS0 | Q931_IE_PL_WINDOW_SIZE:
2665                                         dissect_q931_pl_window_size_ie(tvb,
2666                                             offset + 2, info_element_len,
2667                                             ie_tree);
2668                                         break;
2669
2670                                 case CS0 | Q931_IE_PACKET_SIZE:
2671                                         dissect_q931_packet_size_ie(tvb,
2672                                             offset + 2, info_element_len,
2673                                             ie_tree);
2674                                         break;
2675
2676                                 case CS0 | Q931_IE_CUG:
2677                                         dissect_q931_cug_ie(tvb,
2678                                             offset + 2, info_element_len,
2679                                             ie_tree);
2680                                         break;
2681
2682                                 case CS0 | Q931_IE_REVERSE_CHARGE_IND:
2683                                         dissect_q931_reverse_charge_ind_ie(tvb,
2684                                             offset + 2, info_element_len,
2685                                             ie_tree);
2686                                         break;
2687
2688                                 case CS0 | Q931_IE_CALLING_PARTY_NUMBER:
2689                                         dissect_q931_number_ie(tvb,
2690                                             offset + 2, info_element_len,
2691                                             ie_tree,
2692                                             hf_q931_calling_party_number);
2693                                         break;
2694
2695                                 case CS0 | Q931_IE_CONNECTED_NUMBER_DEFAULT:
2696                                         dissect_q931_number_ie(tvb,
2697                                             offset + 2, info_element_len,
2698                                             ie_tree,
2699                                             hf_q931_connected_number);
2700                                         break;
2701
2702                                 case CS0 | Q931_IE_CALLED_PARTY_NUMBER:
2703                                         dissect_q931_number_ie(tvb,
2704                                             offset + 2, info_element_len,
2705                                             ie_tree,
2706                                             hf_q931_called_party_number);
2707                                         break;
2708
2709                                 case CS0 | Q931_IE_REDIRECTING_NUMBER:
2710                                         dissect_q931_number_ie(tvb,
2711                                             offset + 2, info_element_len,
2712                                             ie_tree,
2713                                             hf_q931_redirecting_number);
2714                                         break;
2715
2716                                 case CS0 | Q931_IE_CALLING_PARTY_SUBADDR:
2717                                 case CS0 | Q931_IE_CALLED_PARTY_SUBADDR:
2718                                         dissect_q931_party_subaddr_ie(tvb,
2719                                             offset + 2, info_element_len,
2720                                             ie_tree);
2721                                         break;
2722
2723                                 case CS0 | Q931_IE_RESTART_INDICATOR:
2724                                         dissect_q931_restart_indicator_ie(tvb,
2725                                             offset + 2, info_element_len,
2726                                             ie_tree);
2727                                         break;
2728
2729                                 case CS0 | Q931_IE_HIGH_LAYER_COMPAT:
2730                                         dissect_q931_high_layer_compat_ie(tvb,
2731                                             offset + 2, info_element_len,
2732                                             ie_tree);
2733                                         break;
2734
2735                                 case CS0 | Q931_IE_USER_USER:
2736                                         dissect_q931_user_user_ie(tvb,
2737                                             offset + 2, info_element_len,
2738                                             ie_tree);
2739                                         break;
2740
2741                                 default:
2742                                         proto_tree_add_text(ie_tree, tvb,
2743                                             offset + 2, info_element_len,
2744                                             "Data: %s",
2745                                             bytes_to_str(
2746                                               tvb_get_ptr(tvb, offset + 2,
2747                                                   info_element_len),
2748                                                   info_element_len));
2749                                         break;
2750                                 }
2751                         }
2752                         offset += 1 + 1 + info_element_len;
2753                 }
2754                 codeset = locked_codeset;
2755                 if(codeset>=NUM_INFO_ELEMENT_VALS){
2756                         proto_tree_add_text(q931_tree, tvb, offset, 1,
2757                         "Invalid codeset: %d", codeset);
2758                         return;
2759                 }
2760         }
2761 }
2762
2763 /*
2764  * Q.931-over-TPKT-over-TCP.
2765  */
2766 static gboolean
2767 dissect_q931_tpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2768 {
2769         int lv_tpkt_len;
2770
2771         /*
2772          * Check whether this looks like a TPKT-encapsulated
2773          * Q.931 packet.
2774          *
2775          * The minimum length of a Q.931 message is 3:
2776          * 1 byte for the protocol discriminator,
2777          * 1 for the call_reference length,
2778          * and one for the message type.
2779          */
2780         lv_tpkt_len = is_tpkt(tvb, 3);
2781         if (lv_tpkt_len == -1) {
2782                 /*
2783                  * It's not a TPKT packet; reject it.
2784                  */
2785                 return FALSE;
2786         }
2787
2788         /*
2789          * If this segment is *exactly* the length of a TPKT header,
2790          * we assume that, as it looks like a TPKT header, it
2791          * is one, and that the code put a TPKT header in one
2792          * segment and the rest of the PDU in another.
2793          */
2794         if (tvb_length(tvb) == 4) {
2795                 /*
2796                  * It is - call the "dissect TPKT over a TCP stream"
2797                  * routine.
2798                  */
2799                 dissect_tpkt_encap(tvb, pinfo, tree, q931_desegment,
2800                     q931_tpkt_pdu_handle);
2801                 return TRUE;
2802         }
2803
2804         /*
2805          * Well, we have more data than just the TPKT header;
2806          * check whether it looks like the beginning of a
2807          * Q.931 message.
2808          *
2809          * The minimum length of a Q.931 message is 3, as per the
2810          * above.
2811          *
2812          * Check that we have that many bytes past the TPKT header in
2813          * the tvbuff; we already know that the TPKT header says we
2814          * have that many bytes (as we passed 3 as the "min_len" argument
2815          * to "is_tpkt()").
2816          */
2817         if (!tvb_bytes_exist(tvb, 4, 3))
2818                 return FALSE;
2819
2820         /* Check the protocol discriminator */
2821         if (tvb_get_guint8(tvb, 4) != NLPID_Q_931) {
2822                 /* Doesn't look like Q.931 inside TPKT */
2823                 return FALSE;
2824         }
2825
2826         /*
2827          * OK, it looks like Q.931-over-TPKT.
2828          * Call the "dissect TPKT over a TCP stream" routine.
2829          */
2830         dissect_tpkt_encap(tvb, pinfo, tree, q931_desegment,
2831             q931_tpkt_pdu_handle);
2832
2833         return TRUE;
2834 }
2835
2836 static void
2837 dissect_q931_tpkt_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2838 {
2839         dissect_q931_pdu(tvb, pinfo, tree, TRUE);
2840 }
2841
2842 static void
2843 dissect_q931(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2844 {
2845         dissect_q931_pdu(tvb, pinfo, tree, FALSE);
2846 }
2847
2848 void
2849 proto_register_q931(void)
2850 {
2851         static hf_register_info hf[] = {
2852                 { &hf_q931_discriminator,
2853                   { "Protocol discriminator", "q931.disc", FT_UINT8, BASE_HEX, NULL, 0x0,
2854                         "", HFILL }},
2855
2856                 { &hf_q931_call_ref_flag,
2857                   { "Call reference flag", "q931.call_ref_flag", FT_BOOLEAN, BASE_NONE, TFS(&tfs_call_ref_flag), 0x0,
2858                         "", HFILL }},
2859
2860                 { &hf_q931_call_ref,
2861                   { "Call reference value", "q931.call_ref", FT_BYTES, BASE_HEX, NULL, 0x0,
2862                         "", HFILL }},
2863
2864
2865                 { &hf_q931_coding_standard,
2866                   { "Coding standard", "q931.coding_standard", FT_UINT8, BASE_HEX,
2867                          VALS(q931_coding_standard_vals), 0x60,"", HFILL }},
2868
2869                 { &hf_q931_information_transfer_capability,
2870                   { "Information transfer capability", "q931.information_transfer_capability", FT_UINT8, BASE_HEX,
2871                          VALS(q931_information_transfer_capability_vals), 0x1f,"", HFILL }},
2872
2873                 { &hf_q931_transfer_mode,
2874                   { "Transfer mode", "q931.transfer_mode", FT_UINT8, BASE_HEX,
2875                          VALS(q931_transfer_mode_vals), 0x60,"", HFILL }},
2876
2877                 { &hf_q931_information_transfer_rate,
2878                   { "Information transfer rate", "q931.information_transfer_rate", FT_UINT8, BASE_HEX,
2879                          VALS(q931_information_transfer_rate_vals), 0x1f,"", HFILL }},
2880
2881                 { &hf_q931_uil1,
2882                   { "User information layer 1 protocol", "q931.uil1", FT_UINT8, BASE_HEX,
2883                          VALS(q931_uil1_vals), 0x1f,"", HFILL }},
2884
2885                 { &hf_q931_call_ref_len,
2886                   { "Call reference value length", "q931.call_ref_len", FT_UINT8, BASE_DEC, NULL, 0x0,
2887                         "", HFILL }},
2888
2889                 { &hf_q931_message_type,
2890                   { "Message type", "q931.message_type", FT_UINT8, BASE_HEX, VALS(q931_message_type_vals), 0x0,
2891                         "", HFILL }},
2892
2893                 { &hf_q931_cause_value,
2894                   { "Cause value", "q931.cause_value", FT_UINT8, BASE_DEC, VALS(q931_cause_code_vals), 0x0,
2895                         "", HFILL }},
2896
2897                 { &hf_q931_number_type,
2898                   { "Number type", "q931.number_type", FT_UINT8, BASE_HEX, VALS(q931_number_type_vals), 0x70,
2899                         "", HFILL }},
2900
2901                 { &hf_q931_numbering_plan,
2902                   { "Numbering plan", "q931.numbering_plan", FT_UINT8, BASE_HEX, VALS(q931_numbering_plan_vals), 0x0f,
2903                         "", HFILL }},
2904
2905                 { &hf_q931_extension_ind,
2906                   { "Extension indicator",  "q931.extension_ind",
2907                         FT_BOOLEAN, 8, TFS(&q931_extension_ind_value), 0x80,
2908                         "", HFILL }},
2909
2910                 { &hf_q931_calling_party_number,
2911                   { "Calling party number digits", "q931.calling_party_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2912                         "", HFILL }},
2913
2914                 { &hf_q931_called_party_number,
2915                   { "Called party number digits", "q931.called_party_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2916                         "", HFILL }},
2917
2918                 { &hf_q931_connected_number,
2919                   { "Connected party number digits", "q931.connected_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2920                         "", HFILL }},
2921
2922                 { &hf_q931_redirecting_number,
2923                   { "Redirecting party number digits", "q931.redirecting_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
2924                         "", HFILL }},
2925         };
2926         static gint *ett[] = {
2927                 &ett_q931,
2928                 &ett_q931_ie,
2929         };
2930         module_t *q931_module;
2931
2932         proto_q931 = proto_register_protocol("Q.931", "Q.931", "q931");
2933         proto_register_field_array (proto_q931, hf, array_length(hf));
2934         proto_register_subtree_array(ett, array_length(ett));
2935
2936         register_dissector("q931", dissect_q931, proto_q931);
2937         q931_tpkt_pdu_handle = create_dissector_handle(dissect_q931_tpkt_pdu,
2938             proto_q931);
2939
2940         /* subdissector code */ 
2941         codeset_dissector_table = register_dissector_table("q931.codeset", "Q.931 Codeset", FT_UINT8, BASE_HEX);
2942         ie_dissector_table = register_dissector_table("q931.ie", "Q.931 IE", FT_UINT16, BASE_HEX);
2943
2944         q931_module = prefs_register_protocol(proto_q931, NULL);
2945         prefs_register_bool_preference(q931_module, "desegment_h323_messages",
2946             "Desegment all Q.931 messages spanning multiple TCP segments",
2947             "Whether the Q.931 dissector should desegment all messages spanning multiple TCP segments",
2948             &q931_desegment);
2949 }
2950
2951 void
2952 proto_reg_handoff_q931(void)
2953 {
2954         /*
2955          * Attempt to get a handle for the H.225 dissector.
2956          * If we can't, the handle we get is null, and we'll just
2957          * dissect putatively-H.255 Call Signaling stuff as User
2958          * Information.
2959          */
2960         h225_handle = find_dissector("h225");
2961
2962         /*
2963          * For H.323.
2964          */
2965         heur_dissector_add("tcp", dissect_q931_tpkt, proto_q931);
2966 }