Minor spelling etc updates.
[metze/wireshark/wip.git] / packet-q2931.c
1 /* packet-q2931.c
2  * Routines for Q.2931 frame disassembly
3  * Guy Harris <guy@alum.mit.edu>
4  *
5  * $Id: packet-q2931.c,v 1.30 2002/11/10 20:26:24 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <glib.h>
32 #include <string.h>
33 #include <epan/packet.h>
34 #include "oui.h"
35 #include "nlpid.h"
36 #include "etypes.h"
37 #include "packet-q931.h"
38 #include "packet-arp.h"
39
40 /*
41  * See
42  *
43  *      http://www.protocols.com/pbook/atmsig.htm
44  *
45  * for some information on Q.2931, although, alas, not the actual message
46  * type and information element values - those I got from the FreeBSD 3.2
47  * ATM code, and from Q.2931 (and Q.931) itself.
48  */
49
50 static int proto_q2931 = -1;
51 static int hf_q2931_discriminator = -1;
52 static int hf_q2931_call_ref_len = -1;
53 static int hf_q2931_call_ref_flag = -1;
54 static int hf_q2931_call_ref = -1;
55 static int hf_q2931_message_type = -1;
56 static int hf_q2931_message_type_ext = -1;
57 static int hf_q2931_message_flag = -1;
58 static int hf_q2931_message_action_indicator = -1;
59 static int hf_q2931_message_len = -1;
60
61 static gint ett_q2931 = -1;
62 static gint ett_q2931_ext = -1;
63 static gint ett_q2931_ie = -1;
64 static gint ett_q2931_ie_ext = -1;
65 static gint ett_q2931_nsap = -1;
66
67 static void dissect_q2931_ie(tvbuff_t *tvb, int offset, int len,
68     proto_tree *tree, guint8 info_element, guint8 info_element_ext);
69
70 /*
71  * Q.2931 message types.
72  */
73 #define Q2931_ALERTING          0x01
74 #define Q2931_CALL_PROCEEDING   0x02
75 #define Q2931_CONNECT           0x07
76 #define Q2931_CONNECT_ACK       0x0F
77 #define Q2931_PROGRESS          0x03
78 #define Q2931_SETUP             0x05
79 #define Q2931_SETUP_ACK         0x0B
80 #define Q2931_RELEASE           0x4D
81 #define Q2931_RELEASE_COMPLETE  0x5A
82 #define Q2931_RESTART           0x46
83 #define Q2931_RESTART_ACK       0x4E
84 #define Q2931_INFORMATION       0x7B
85 #define Q2931_NOTIFY            0x6E
86 #define Q2931_STATUS            0x7D
87 #define Q2931_STATUS_ENQUIRY    0x75
88 #define Q2931_ADD_PARTY         0x80
89 #define Q2931_ADD_PARTY_ACK     0x81
90 #define Q2931_ADD_PARTY_REJ     0x82
91 #define Q2931_DROP_PARTY        0x83
92 #define Q2931_DROP_PARTY_ACK    0x84
93 #define Q2931_LEAF_SETUP_FAIL   0x90
94 #define Q2931_LEAF_SETUP_REQ    0x91
95
96 static const value_string q2931_message_type_vals[] = {
97         { Q2931_ALERTING,               "ALERTING" },
98         { Q2931_CALL_PROCEEDING,        "CALL PROCEEDING" },
99         { Q2931_CONNECT,                "CONNECT" },
100         { Q2931_CONNECT_ACK,            "CONNECT ACKNOWLEDGE" },
101         { Q2931_PROGRESS,               "PROGRESS" },
102         { Q2931_SETUP,                  "SETUP" },
103         { Q2931_SETUP_ACK,              "SETUP ACKNOWLEDGE" },
104         { Q2931_RELEASE,                "RELEASE" },
105         { Q2931_RELEASE_COMPLETE,       "RELEASE COMPLETE" },
106         { Q2931_RESTART,                "RESTART" },
107         { Q2931_RESTART_ACK,            "RESTART ACKNOWLEDGE" },
108         { Q2931_INFORMATION,            "INFORMATION" },
109         { Q2931_NOTIFY,                 "NOTIFY" },
110         { Q2931_STATUS,                 "STATUS" },
111         { Q2931_STATUS_ENQUIRY,         "STATUS ENQUIRY" },
112         { Q2931_ADD_PARTY,              "ADD PARTY" },
113         { Q2931_ADD_PARTY_ACK,          "ADD PARTY ACKNOWLEDGE" },
114         { Q2931_ADD_PARTY_REJ,          "ADD PARTY REJECT" },
115         { Q2931_DROP_PARTY,             "DROP PARTY" },
116         { Q2931_DROP_PARTY_ACK,         "DROP PARTY ACKNOWLEDGE" },
117         { Q2931_LEAF_SETUP_FAIL,        "LEAF SETUP FAILURE" },
118         { Q2931_LEAF_SETUP_REQ,         "LEAF SETUP REQUEST" },
119         { 0,                            NULL }
120 };
121
122 static const true_false_string tfs_call_ref_flag = {
123         "Message sent to originating side",
124         "Message sent from originating side"
125 };
126
127 /*
128  * Bits in the message type extension.
129  */
130 #define Q2931_MSG_TYPE_EXT_FOLLOW_INST  0x10    /* follow instructions in action indicator */
131 #define Q2931_MSG_TYPE_EXT_ACTION_IND   0x03    /* said instructions */
132
133 static const true_false_string tos_msg_flag = {
134         "Regular error handling procedures apply",
135         "Follow explicit error handling instructions"
136 };
137
138 static const value_string msg_action_ind_vals[] = {
139         { 0x00, "Clear call" },
140         { 0x01, "Discard and ignore" },
141         { 0x02, "Discard and report status" },
142         { 0x00, NULL }
143 };
144
145 /*
146  * Bits in the compatibility instruction indicator octet of an
147  * information element.
148  */
149 #define Q2931_IE_COMPAT_CODING_STD      0x60    /* Coding standard */
150 #define Q2931_IE_COMPAT_FOLLOW_INST     0x10    /* follow instructions in action indicator */
151 #define Q2931_IE_COMPAT_ACTION_IND      0x07
152
153 /*
154  * ITU-standardized coding.
155  */
156 #define Q2931_ITU_STANDARDIZED_CODING   0x00
157
158 static const value_string coding_std_vals[] = {
159         { 0x00, "ITU-T standardized coding" },
160         { 0x20, "ISO/IEC standard" },
161         { 0x40, "National standard" },
162         { 0x60, "Standard defined for the network" },
163         { 0,    NULL }
164 };
165
166 static const value_string ie_action_ind_vals[] = {
167         { 0x00, "Clear call" },
168         { 0x01, "Discard information element and proceed" },
169         { 0x02, "Discard information element, proceed, and report status" },
170         { 0x05, "Discard message, and ignore" },
171         { 0x06, "Discard message, and report status" },
172         { 0x00, NULL }
173 };
174
175 /*
176  * Information elements.
177  */
178 #define Q2931_IE_EXTENSION              0x80    /* Extension flag */
179
180 #define Q2931_IE_NBAND_BEARER_CAP       0x04    /* Narrowband bearer capability */
181 #define Q2931_IE_CAUSE                  0x08
182 #define Q2931_IE_CALL_STATE             0x14
183 #define Q2931_IE_PROGRESS_INDICATOR     0x1E
184 #define Q2931_IE_NOTIFICATION_INDICATOR 0x27
185 #define Q2931_IE_E2E_TRANSIT_DELAY      0x42    /* End-to-end Transit Delay */
186 #define Q2931_IE_ENDPOINT_REFERENCE     0x54
187 #define Q2931_IE_ENDPOINT_STATE         0x55
188 #define Q2931_IE_AAL_PARAMETERS         0x58    /* ATM adaptation layer parameters */
189 #define Q2931_IE_ATM_USER_CELL_RATE     0x59    /* ATM traffic descriptor */
190 #define Q2931_IE_CONNECTION_IDENTIFIER  0x5A
191 #define Q2931_IE_OAM_TRAFFIC_DESCRIPTOR 0x5B
192 #define Q2931_IE_QOS_PARAMETER          0x5C    /* Quality of Service parameter */
193 #define Q2931_IE_BBAND_HI_LAYER_INFO    0x5D    /* Broadband high-layer information */
194 #define Q2931_IE_BBAND_BEARER_CAP       0x5E    /* Broadband bearer capability */
195 #define Q2931_IE_BBAND_LOW_LAYER_INFO   0x5F    /* Broadband low-layer information */
196 #define Q2931_IE_BBAND_LOCKING_SHIFT    0x60    /* Broadband locking shift */
197 #define Q2931_IE_BBAND_NLOCKING_SHIFT   0x61    /* Broadband non-locking shift */
198 #define Q2931_IE_BBAND_SENDING_COMPL    0x62    /* Broadband sending complete */
199 #define Q2931_IE_BBAND_RPT_INDICATOR    0x63    /* Broadband repeat indicator */
200 #define Q2931_IE_CALLING_PARTY_NUMBER   0x6C    /* Calling Party Number */
201 #define Q2931_IE_CALLING_PARTY_SUBADDR  0x6D    /* Calling Party Subaddress */
202 #define Q2931_IE_CALLED_PARTY_NUMBER    0x70    /* Called Party Number */
203 #define Q2931_IE_CALLED_PARTY_SUBADDR   0x71    /* Called Party Subaddress */
204 #define Q2931_IE_TRANSIT_NETWORK_SEL    0x78    /* Transit Network Selection */
205 #define Q2931_IE_RESTART_INDICATOR      0x79
206 #define Q2931_IE_NBAND_LOW_LAYER_COMPAT 0x7C    /* Narrowband Low-Layer Compatibility */
207 #define Q2931_IE_NBAND_HIGH_LAYER_COMPAT 0x7D   /* Narrowband High-Layer Compatibility */
208 #define Q2931_IE_GENERIC_IDENT_TRANSPORT 0x7F   /* Generic identifier transport */
209
210 static const value_string q2931_info_element_vals[] = {
211         { Q2931_IE_NBAND_BEARER_CAP,            "Narrowband bearer capability" },
212         { Q2931_IE_CAUSE,                       "Cause" },
213         { Q2931_IE_CALL_STATE,                  "Call state" },
214         { Q2931_IE_PROGRESS_INDICATOR,          "Progress indicator" },
215         { Q2931_IE_NOTIFICATION_INDICATOR,      "Notification indicator" },
216         { Q2931_IE_E2E_TRANSIT_DELAY,           "End-to-end transit delay" },
217         { Q2931_IE_ENDPOINT_REFERENCE,          "Endpoint reference" },
218         { Q2931_IE_ENDPOINT_STATE,              "Endpoint state" },
219         { Q2931_IE_AAL_PARAMETERS,              "AAL parameters" },
220         { Q2931_IE_ATM_USER_CELL_RATE,          "ATM user cell rate" },
221         { Q2931_IE_CONNECTION_IDENTIFIER,       "Connection identifier" },
222         { Q2931_IE_OAM_TRAFFIC_DESCRIPTOR,      "OAM traffic descriptor" },
223         { Q2931_IE_QOS_PARAMETER,               "Quality of service parameter" },
224         { Q2931_IE_BBAND_HI_LAYER_INFO,         "Broadband high-layer information" },
225         { Q2931_IE_BBAND_BEARER_CAP,            "Broadband bearer capability" },
226         { Q2931_IE_BBAND_LOW_LAYER_INFO,        "Broadband low-layer information" },
227         { Q2931_IE_BBAND_LOCKING_SHIFT,         "Broadband locking shift" },
228         { Q2931_IE_BBAND_NLOCKING_SHIFT,        "Broadband non-locking shift" },
229         { Q2931_IE_BBAND_SENDING_COMPL,         "Broadband sending complete" },
230         { Q2931_IE_BBAND_RPT_INDICATOR,         "Broadband repeat indicator" },
231         { Q2931_IE_CALLING_PARTY_NUMBER,        "Calling party number" },
232         { Q2931_IE_CALLING_PARTY_SUBADDR,       "Calling party subaddress" },
233         { Q2931_IE_CALLED_PARTY_NUMBER,         "Called party number" },
234         { Q2931_IE_CALLED_PARTY_SUBADDR,        "Called party subaddress" },
235         { Q2931_IE_TRANSIT_NETWORK_SEL,         "Transit network selection" },
236         { Q2931_IE_RESTART_INDICATOR,           "Restart indicator" },
237         { Q2931_IE_NBAND_LOW_LAYER_COMPAT,      "Narrowband low-layer compatibility" },
238         { Q2931_IE_NBAND_HIGH_LAYER_COMPAT,     "Narrowband high-layer compatibility" },
239         { Q2931_IE_GENERIC_IDENT_TRANSPORT,     "Generic identifier transport" },
240         { 0,                                    NULL }
241 };
242
243 /*
244  * Dissect a locking or non-locking shift information element.
245  */
246 static const value_string q2931_codeset_vals[] = {
247         { 0x00, "Q.2931 information elements" },
248         { 0x04, "Information elements for ISO/IEC use" },
249         { 0x05, "Information elements for national use" },
250         { 0x06, "Information elements specific to the local network" },
251         { 0x07, "User-specific information elements" },
252         { 0x00, NULL },
253 };
254
255 static void
256 dissect_q2931_shift_ie(tvbuff_t *tvb, int offset, int len,
257     proto_tree *tree, guint8 info_element)
258 {
259         gboolean non_locking_shift;
260         guint8 codeset;
261
262         if (len == 0)
263                 return;
264         non_locking_shift = (info_element == Q2931_IE_BBAND_NLOCKING_SHIFT);
265         codeset = tvb_get_guint8(tvb, offset) & 0x07;
266         proto_tree_add_text(tree, tvb, offset, 1, "%s shift to codeset %u: %s",
267             (non_locking_shift ? "Non-locking" : "Locking"),
268             codeset,
269             val_to_str(codeset, q2931_codeset_vals, "Unknown (0x%02X)"));
270 }
271
272 /*
273  * Dissect an ATM adaptation layer parameters information element.
274  */
275 #define Q2931_AAL_VOICE         0x00
276 #define Q2931_AAL1              0x01
277 #define Q2931_AAL2              0x02
278 #define Q2931_AAL3_4            0x03
279 #define Q2931_AAL5              0x05
280 #define Q2931_USER_DEFINED_AAL  0x10
281
282 static const value_string q9231_aal_type_vals[] = {
283         { 0x00, "AAL for voice" },
284         { 0x01, "AAL type 1" },
285         { 0x02, "AAL type 2" },
286         { 0x03, "AAL type 3/4" },
287         { 0x05, "AAL type 5" },
288         { 0x10, "User-defined AAL" },
289         { 0,    NULL }
290 };
291
292 static const value_string q9231_aal1_subtype_vals[] = {
293         { 0x00, "Null" },
294         { 0x01, "64 kbit/s voice-band signal transport (G.711/G.722)" },
295         { 0x02, "Circuit transport (I.363)" },
296         { 0x03, "Circuit emulation (asynchronous)" },
297         { 0x04, "High-quality audio signal transport (I.363)" },
298         { 0x05, "Video signal transport (I.363)" },
299         { 0x00, NULL }
300 };
301
302 #define Q2931_AAL1_nx64_KBIT_S  0x40
303 #define Q2931_AAL1_nx8_KBIT_S   0x41
304
305 static const value_string q9231_aal1_cbr_rate_vals[] = {
306         { 0x01,                   "64 kbit/s" },
307         { 0x04,                   "1544 kbit/s" },
308         { 0x05,                   "6312 kbit/s" },
309         { 0x06,                   "32064 kbit/s" },
310         { 0x07,                   "44736 kbit/s" },
311         { 0x08,                   "97728 kbit/s" },
312         { 0x10,                   "2048 kbit/s" },
313         { 0x11,                   "8448 kibt/s" },
314         { 0x12,                   "34368 kbit/s" },
315         { 0x13,                   "139264 kbit/s" },
316         { Q2931_AAL1_nx64_KBIT_S, "nx64 kbit/s" },
317         { Q2931_AAL1_nx8_KBIT_S,  "nx8 kbit/s" },
318         { 0x00,                   NULL }
319 };
320
321 static const value_string q2931_aal1_src_clk_rec_meth_vals[] = {
322         { 0x00, "Null (synchronous circuit transport)" },
323         { 0x01, "SRTS method (asynchronous circuit transport" },
324         { 0x02, "Adaptive clock method" },
325         { 0x00, NULL }
326 };
327
328 static const value_string q2931_aal1_err_correction_method_vals[] = {
329         { 0x00, "Null" },
330         { 0x01, "FEC method for less sensitive signal transport" },
331         { 0x02, "FEC method for delay-sensitive signal transport" },
332         { 0x00, NULL }
333 };
334
335 static const value_string q2931_aal_mode_vals[] = {
336         { 0x01, "Message" },
337         { 0x02, "Streaming" },
338         { 0x00, NULL }
339 };
340
341 static const value_string q2931_sscs_type_vals[] = {
342         { 0x00, "Null" },
343         { 0x01, "Data SSCS based on SSCOP (assured operation)" },
344         { 0x02, "Data SSCS based on SSCOP (non-assured operation)" },
345         { 0x04, "Frame relay SSCS" },
346         { 0x00, NULL }
347 };
348
349 static void
350 dissect_q2931_aal_parameters_ie(tvbuff_t *tvb, int offset, int len,
351     proto_tree *tree)
352 {
353         guint8 aal_type;
354         guint8 identifier;
355         guint32 value;
356         guint32 low_mid, high_mid;
357
358         if (len == 0)
359                 return;
360         aal_type = tvb_get_guint8(tvb, offset);
361         proto_tree_add_text(tree, tvb, offset, 1, "AAL type: %s",
362             val_to_str(aal_type, q9231_aal_type_vals, "Unknown (0x%02X)"));
363         offset += 1;
364         len -= 1;
365
366         /*
367          * Now get the rest of the IE.
368          */
369         if (aal_type == 0x40) {
370                 /*
371                  * User-defined AAL.
372                  */
373                 if (len > 4)
374                         len = 4;
375                 proto_tree_add_text(tree, tvb, offset, len,
376                     "User defined AAL information: %s",
377                     tvb_bytes_to_str(tvb, offset, len));
378                 return;
379         }
380
381         while (len != 0) {
382                 identifier = tvb_get_guint8(tvb, offset);
383                 switch (identifier) {
384
385                 case 0x85:      /* Subtype identifier for AAL1 */
386                         if (len < 2)
387                                 return;
388                         value = tvb_get_guint8(tvb, offset + 1);
389                         proto_tree_add_text(tree, tvb, offset, 2,
390                             "Subtype: %s",
391                             val_to_str(value, q9231_aal1_subtype_vals,
392                             "Unknown (0x%02X)"));
393                         offset += 2;
394                         len -= 2;
395                         break;
396
397                 case 0x86:      /* CBR identifier for AAL1 */
398                         if (len < 2)
399                                 return;
400                         value = tvb_get_guint8(tvb, offset + 1);
401                         proto_tree_add_text(tree, tvb, offset, 2,
402                             "CBR rate: %s",
403                             val_to_str(value, q9231_aal1_cbr_rate_vals,
404                             "Unknown (0x%02X)"));
405                         offset += 2;
406                         len -= 2;
407                         break;
408
409                 case 0x87:      /* Multiplier identifier for AAL1 */
410                         if (len < 3)
411                                 return;
412                         value = tvb_get_ntohs(tvb, offset + 1);
413                         proto_tree_add_text(tree, tvb, offset, 3,
414                             "Multiplier: %u", value);
415                         offset += 3;
416                         len -= 3;
417                         break;
418
419                 case 0x88:      /* Source clock frequency recovery method identifier for AAL1 */
420                         if (len < 2)
421                                 return;
422                         value = tvb_get_guint8(tvb, offset + 1);
423                         proto_tree_add_text(tree, tvb, offset, 2,
424                             "Source clock frequency recovery method: %s",
425                             val_to_str(value, q2931_aal1_src_clk_rec_meth_vals,
426                             "Unknown (0x%02X)"));
427                         offset += 2;
428                         len -= 2;
429                         break;
430
431                 case 0x89:      /* Error correction method identifier for AAL1 */
432                         if (len < 2)
433                                 return;
434                         value = tvb_get_guint8(tvb, offset + 1);
435                         proto_tree_add_text(tree, tvb, offset, 2,
436                             "Error correction method: %s",
437                             val_to_str(value, q2931_aal1_err_correction_method_vals,
438                             "Unknown (0x%02X)"));
439                         offset += 2;
440                         len -= 2;
441                         break;
442
443                 case 0x8A:      /* Structured data transfer block size identifier for AAL1 */
444                         if (len < 3)
445                                 return;
446                         value = tvb_get_ntohs(tvb, offset + 1);
447                         proto_tree_add_text(tree, tvb, offset, 3,
448                             "Structured data transfer block size: %u", value);
449                         offset += 3;
450                         len -= 3;
451                         break;
452
453                 case 0x8B:      /* Partially filled cells identifier for AAL1 */
454                         if (len < 2)
455                                 return;
456                         value = tvb_get_guint8(tvb, offset + 1);
457                         proto_tree_add_text(tree, tvb, offset, 2,
458                             "Partially filled cells method: %u octets", value);
459                         offset += 2;
460                         len -= 2;
461                         break;
462
463                 case 0x8C:      /* Forward maximum CPCS-SDU size identifier for AAL3/4 and AAL5 */
464                         if (len < 3)
465                                 return;
466                         value = tvb_get_ntohs(tvb, offset + 1);
467                         proto_tree_add_text(tree, tvb, offset, 3,
468                             "Forward maximum CPCS-SDU size: %u", value);
469                         offset += 3;
470                         len -= 3;
471                         break;
472
473                 case 0x81:      /* Backward maximum CPCS-SDU size identifier for AAL3/4 and AAL5 */
474                         if (len < 3)
475                                 return;
476                         value = tvb_get_ntohs(tvb, offset + 1);
477                         proto_tree_add_text(tree, tvb, offset, 3,
478                             "Backward maximum CPCS-SDU size: %u", value);
479                         offset += 3;
480                         len -= 3;
481                         break;
482
483                 case 0x82:      /* MID range identifier for AAL3/4 */
484                         if (len < 5)
485                                 return;
486                         low_mid = tvb_get_ntohs(tvb, offset + 1);
487                         high_mid = tvb_get_ntohs(tvb, offset + 3);
488                         proto_tree_add_text(tree, tvb, offset, 3,
489                             "MID range: %u - %u", low_mid, high_mid);
490                         offset += 5;
491                         len -= 5;
492                         break;
493
494                 case 0x83:      /* Mode identifier for AAL3/4 and AAL5 */
495                         if (len < 2)
496                                 return;
497                         value = tvb_get_guint8(tvb, offset + 1);
498                         proto_tree_add_text(tree, tvb, offset, 2,
499                             "Mode: %s",
500                             val_to_str(value, q2931_aal_mode_vals,
501                             "Unknown (0x%02X)"));
502                         offset += 2;
503                         len -= 2;
504                         break;
505
506                 case 0x84:      /* SSCS type identifier for AAL3/4 and AAL5 */
507                         if (len < 2)
508                                 return;
509                         value = tvb_get_guint8(tvb, offset + 1);
510                         proto_tree_add_text(tree, tvb, offset, 2,
511                             "SSCS type: %s",
512                             val_to_str(value, q2931_sscs_type_vals,
513                             "Unknown (0x%02X)"));
514                         offset += 2;
515                         len -= 2;
516                         break;
517
518                 default:        /* unknown AAL parameter */
519                         proto_tree_add_text(tree, tvb, offset, 1,
520                             "Unknown AAL parameter (0x%02X)",
521                             identifier);
522                         return; /* give up */
523                 }
524         }
525 }
526
527 /*
528  * Dissect an ATM traffic descriptor information element.
529  */
530 #define Q2931_ATM_CR_FW_PEAK_CLP_0      0x82    /* Forward peak cell rate (CLP = 0) */
531 #define Q2931_ATM_CR_BW_PEAK_CLP_0      0x83    /* Backward peak cell rate (CLP = 0) */
532 #define Q2931_ATM_CR_FW_PEAK_CLP_0_1    0x84    /* Forward peak cell rate (CLP = 0 + 1) */
533 #define Q2931_ATM_CR_BW_PEAK_CLP_0_1    0x85    /* Backward peak cell rate (CLP = 0 + 1) */
534 #define Q2931_ATM_CR_FW_SUST_CLP_0      0x88    /* Forward sustainable cell rate (CLP = 0) */
535 #define Q2931_ATM_CR_BW_SUST_CLP_0      0x89    /* Backward sustainable cell rate (CLP = 0) */
536 #define Q2931_ATM_CR_FW_SUST_CLP_0_1    0x90    /* Forward sustainable cell rate (CLP = 0 + 1) */
537 #define Q2931_ATM_CR_BW_SUST_CLP_0_1    0x91    /* Backward sustainable cell rate (CLP = 0 + 1) */
538 #define Q2931_ATM_CR_FW_MAXB_CLP_0      0xA0    /* Forward maximum burst size (CLP = 0) */
539 #define Q2931_ATM_CR_BW_MAXB_CLP_0      0xA1    /* Backward maximum burst size (CLP = 0) */
540 #define Q2931_ATM_CR_FW_MAXB_CLP_0_1    0xB0    /* Forward maximum burst size (CLP = 0 + 1) */
541 #define Q2931_ATM_CR_BW_MAXB_CLP_0_1    0xB1    /* Backward maximum burst size (CLP = 0 + 1) */
542 #define Q2931_ATM_CR_BEST_EFFORT_IND    0xBE    /* Best effort indicator */
543 #define Q2931_ATM_CR_TRAFFIC_MGMT_OPT   0xBF    /* Traffic management options */
544
545 static const value_string q2931_atm_td_subfield_vals[] = {
546         { Q2931_ATM_CR_FW_PEAK_CLP_0,   "Forward peak cell rate (CLP = 0)" },
547         { Q2931_ATM_CR_BW_PEAK_CLP_0,   "Backward peak cell rate (CLP = 0)" },
548         { Q2931_ATM_CR_FW_PEAK_CLP_0_1, "Forward peak cell rate (CLP = 0 + 1)" },
549         { Q2931_ATM_CR_BW_PEAK_CLP_0_1, "Backward peak cell rate (CLP = 0 + 1)" },
550         { Q2931_ATM_CR_FW_SUST_CLP_0,   "Forward sustainable cell rate (CLP = 0)" },
551         { Q2931_ATM_CR_BW_SUST_CLP_0,   "Backward sustainable cell rate (CLP = 0)" },
552         { Q2931_ATM_CR_FW_SUST_CLP_0_1, "Forward sustainable cell rate (CLP = 0 + 1)" },
553         { Q2931_ATM_CR_BW_SUST_CLP_0_1, "Backward sustainable cell rate (CLP = 0 + 1)" },
554         { Q2931_ATM_CR_FW_MAXB_CLP_0,   "Forward maximum burst size (CLP = 0)" },
555         { Q2931_ATM_CR_BW_MAXB_CLP_0,   "Backward maximum burst size (CLP = 0)" },
556         { Q2931_ATM_CR_FW_MAXB_CLP_0_1, "Forward maximum burst size (CLP = 0 + 1)" },
557         { Q2931_ATM_CR_BW_MAXB_CLP_0_1, "Backward maximum burst size (CLP = 0 + 1)" },
558         { Q2931_ATM_CR_BEST_EFFORT_IND, "Best effort indicator" },
559         { Q2931_ATM_CR_TRAFFIC_MGMT_OPT,"Traffic management options" },
560         { 0x0,                          NULL }
561 };
562
563 static void
564 dissect_q2931_atm_cell_rate_ie(tvbuff_t *tvb, int offset, int len,
565     proto_tree *tree)
566 {
567         guint8 identifier;
568         guint32 value;
569
570         while (len != 0) {
571                 identifier = tvb_get_guint8(tvb, offset);
572                 switch (identifier) {
573
574                 case Q2931_ATM_CR_FW_PEAK_CLP_0:
575                 case Q2931_ATM_CR_BW_PEAK_CLP_0:
576                 case Q2931_ATM_CR_FW_PEAK_CLP_0_1:
577                 case Q2931_ATM_CR_BW_PEAK_CLP_0_1:
578                 case Q2931_ATM_CR_FW_SUST_CLP_0:
579                 case Q2931_ATM_CR_BW_SUST_CLP_0:
580                 case Q2931_ATM_CR_FW_SUST_CLP_0_1:
581                 case Q2931_ATM_CR_BW_SUST_CLP_0_1:
582                 case Q2931_ATM_CR_FW_MAXB_CLP_0:
583                 case Q2931_ATM_CR_BW_MAXB_CLP_0:
584                 case Q2931_ATM_CR_FW_MAXB_CLP_0_1:
585                 case Q2931_ATM_CR_BW_MAXB_CLP_0_1:
586                         if (len < 4)
587                                 return;
588                         value = tvb_get_ntoh24(tvb, offset + 1);
589                         proto_tree_add_text(tree, tvb, offset, 4,
590                             "%s: %u cell%s/s",
591                             val_to_str(identifier, q2931_atm_td_subfield_vals,
592                               NULL),
593                             value, plurality(value, "", "s"));
594                         offset += 4;
595                         len -= 4;
596                         break;
597
598                 case Q2931_ATM_CR_BEST_EFFORT_IND:
599                         /* Yes, its value *IS* 0xBE.... */
600                         proto_tree_add_text(tree, tvb, offset, 1,
601                             "%s",
602                             val_to_str(identifier, q2931_atm_td_subfield_vals,
603                               NULL));
604                         offset += 1;
605                         len -= 1;
606                         break;
607
608                 case Q2931_ATM_CR_TRAFFIC_MGMT_OPT:
609                         if (len < 2)
610                                 return;
611                         value = tvb_get_guint8(tvb, offset + 1);
612                         proto_tree_add_text(tree, tvb, offset, 2,
613                             "%s",
614                             val_to_str(identifier, q2931_atm_td_subfield_vals,
615                               NULL));
616                         proto_tree_add_text(tree, tvb, offset + 1, 1,
617                             "%s allowed in forward direction",
618                             (value & 0x80) ? "Frame discard" : "No frame discard");
619                         proto_tree_add_text(tree, tvb, offset + 1, 1,
620                             "%s allowed in backward direction",
621                             (value & 0x40) ? "Frame discard" : "No frame discard");
622                         proto_tree_add_text(tree, tvb, offset + 1, 1,
623                             "Tagging %srequested in backward direction",
624                             (value & 0x02) ? "" : "not ");
625                         proto_tree_add_text(tree, tvb, offset + 1, 1,
626                             "Tagging %srequested in forward direction",
627                             (value & 0x01) ? "" : "not ");
628                         offset += 2;
629                         len -= 2;
630                         break;
631
632                 default:        /* unknown ATM traffic descriptor element */
633                         proto_tree_add_text(tree, tvb, offset, 1,
634                             "Unknown ATM traffic descriptor element (0x%02X)",
635                             identifier);
636                         return; /* give up */
637                 }
638         }
639 }
640
641 /*
642  * Dissect a broadband bearer capability information element.
643  */
644 static const value_string q2931_bearer_class_vals[] = {
645         { 0x01, "BCOB-A" },
646         { 0x03, "BCOB-C" },
647         { 0x10, "BCOB-X" },
648         { 0x18, "Transparent VP Service" },
649         { 0x00, NULL }
650 };
651
652 static const value_string q2931_transfer_capability_vals[] = {
653         { 0x00, "No bit rate indication" },
654         { 0x01, "No bit rate indication, end-to-end timing required" },
655         { 0x02, "No bit rate indication, end-to-end timing not required" },
656         { 0x04, "CBR" },
657         { 0x05, "CBR, end-to-end timing required" },
658         { 0x06, "CBR, end-to-end timing not required" },
659         { 0x07, "CBR with CLR commitment on CLP=0+1" },
660         { 0x08, "VBR, no timing requirements indication" },
661         { 0x09, "Real time VBR" },
662         { 0x0A, "Non-real time VBR" },
663         { 0x0B, "Non-real time VBR with CLR commitment on CLP=0+1" },
664         { 0x0C, "ABR" },
665         { 0x00, NULL }
666 };
667
668 static const value_string q2931_susc_clip_vals[] = {
669         { 0x00, "Not susceptible to clipping" },
670         { 0x20, "Susceptible to clipping" },
671         { 0x00, NULL }
672 };
673
674 static const value_string q2931_up_conn_config_vals[] = {
675         { 0x00, "Point-to-point" },
676         { 0x01, "Point-to-multipoint" },
677         { 0x00, NULL }
678 };
679
680 static void
681 dissect_q2931_bband_bearer_cap_ie(tvbuff_t *tvb, int offset, int len,
682     proto_tree *tree)
683 {
684         guint8 octet;
685
686         if (len == 0)
687                 return;
688         octet = tvb_get_guint8(tvb, offset);
689         proto_tree_add_text(tree, tvb, offset, 1,
690             "Bearer class: %s",
691             val_to_str(octet & 0x1F, q2931_bearer_class_vals,
692             "Unknown (0x%02X)"));
693         offset += 1;
694         len -= 1;
695
696         if (len == 0)
697                 return;
698         if (!(octet & Q2931_IE_EXTENSION)) {
699                 octet = tvb_get_guint8(tvb, offset);
700                 proto_tree_add_text(tree, tvb, offset, 1,
701                     "ATM Transfer Capability: %s",
702                     val_to_str(octet & 0x1F, q2931_transfer_capability_vals,
703                     "Unknown (0x%02X)"));
704                 offset += 1;
705                 len -= 1;
706         }
707
708         if (len == 0)
709                 return;
710         octet = tvb_get_guint8(tvb, offset);
711         proto_tree_add_text(tree, tvb, offset, 1,
712             "Susceptibility to clipping: %s",
713             val_to_str(octet & 0x60, q2931_susc_clip_vals,
714             "Unknown (0x%02X)"));
715         proto_tree_add_text(tree, tvb, offset, 1,
716             "User-plane connection configuration: %s",
717             val_to_str(octet & 0x03, q2931_up_conn_config_vals,
718             "Unknown (0x%02X)"));
719 }
720
721 /*
722  * Dissect a broadband high layer information information element.
723  */
724 static const value_string q2931_hi_layer_info_type_vals[] = {
725         { 0x00, "ISO/IEC" },
726         { 0x01, "User-specific" },
727         { 0x03, "Vendor-specific" },
728         { 0x04, "ITU-T SG 1 B-ISDN teleservice recommendation" },
729         { 0x00, NULL }
730 };
731
732 static void
733 dissect_q2931_bband_hi_layer_info_ie(tvbuff_t *tvb, int offset, int len,
734     proto_tree *tree)
735 {
736         guint8 octet;
737
738         if (len == 0)
739                 return;
740         octet = tvb_get_guint8(tvb, offset);
741         proto_tree_add_text(tree, tvb, offset, 1,
742             "High layer information type: %s",
743             val_to_str(octet & 0x7F, q2931_hi_layer_info_type_vals,
744             "Unknown (0x%02X)"));
745         offset += 1;
746         len -= 1;
747 }
748
749 /*
750  * Dissect a Bearer capability or Low-layer compatibility information element.
751  */
752 #define Q2931_UIL2_USER_SPEC    0x10
753
754 static const value_string q2931_uil2_vals[] = {
755         { 0x01,                 "Basic mode ISO 1745" },
756         { 0x02,                 "Q.921/I.441" },        /* LAPD */
757         { 0x06,                 "X.25, link layer" },   /* LAPB */
758         { 0x07,                 "X.25 multilink" },     /* or 0x0F? */
759         { 0x08,                 "T.71 Extended LAPB" },
760         { 0x09,                 "HDLC ARM" },
761         { 0x0A,                 "HDLC NRM" },
762         { 0x0B,                 "HDLC ABM" },
763         { 0x0C,                 "ISO 8802/2 LLC" },
764         { 0x0D,                 "X.75 Single Link Procedure" },
765         { 0x0E,                 "Q.922" },
766         { Q2931_UIL2_USER_SPEC, "User-specified" },
767         { 0x11,                 "ISO 7776 DTE-DTE operation" },
768         { 0,                    NULL }
769 };
770
771 static const value_string q2931_mode_vals[] = {
772         { 0x20, "Normal mode" },
773         { 0x40, "Extended mode" },
774         { 0,    NULL }
775 };
776
777 #define Q2931_UIL3_X25_PL       0x06
778 #define Q2931_UIL3_ISO_8208     0x07    /* X.25-based */
779 #define Q2931_UIL3_X223         0x08    /* X.25-based */
780 #define Q2931_UIL3_TR_9577      0x0B
781 #define Q2931_UIL3_USER_SPEC    0x10
782
783 static const value_string q2931_uil3_vals[] = {
784         { Q2931_UIL3_X25_PL,    "X.25, packet layer" },
785         { Q2931_UIL3_ISO_8208,  "ISO/IEC 8208" },
786         { Q2931_UIL3_X223,      "X.223/ISO 8878" },
787         { 0x09,                 "ISO/IEC 8473" },
788         { 0x0A,                 "T.70" },
789         { Q2931_UIL3_TR_9577,   "ISO/IEC TR 9577" },
790         { Q2931_UIL3_USER_SPEC, "User-specified" },
791         { 0,                    NULL }
792 };
793
794 static const value_string lane_pid_vals[] = {
795         { 0x0001, "LE Configuration Direct/Control Direct/Control Distribute" },
796         { 0x0002, "Ethernet/IEEE 002.3 LE Data Direct" },
797         { 0x0003, "IEEE 802.5 LE Data Direct" },
798         { 0x0004, "Ethernet/IEEE 802.3 LE Multicast Send/Multicast Forward" },
799         { 0x0005, "IEEE 802.5 LE Multicast Send/Multicast Forward" },
800         { 0,      NULL },
801 };
802
803 /*
804  * Dissect a broadband low layer information information element.
805  */
806 static void
807 dissect_q2931_bband_low_layer_info_ie(tvbuff_t *tvb, int offset, int len,
808     proto_tree *tree)
809 {
810         guint8 octet;
811         guint8 uil2_protocol;
812         guint8 uil3_protocol;
813         guint8 add_l3_info;
814         guint32 organization_code;
815         guint16 pid;
816
817         if (len == 0)
818                 return;
819         octet = tvb_get_guint8(tvb, offset);
820         if ((octet & 0x60) == 0x20) {
821                 /*
822                  * Layer 1 information.
823                  */
824                 proto_tree_add_text(tree, tvb, offset, 1,
825                     "User information layer 1 protocol: 0x%02X",
826                     octet & 0x1F);
827                 offset += 1;
828                 len -= 1;
829         }
830
831         if (len == 0)
832                 return;
833         octet = tvb_get_guint8(tvb, offset);
834         if ((octet & 0x60) == 0x40) {
835                 /*
836                  * Layer 2 information.
837                  */
838                 uil2_protocol = octet & 0x1F;
839                 proto_tree_add_text(tree, tvb, offset, 1,
840                     "User information layer 2 protocol: %s",
841                     val_to_str(uil2_protocol, q2931_uil2_vals,
842                       "Unknown (0x%02X)"));
843                 offset += 1;
844                 len -= 1;
845
846                 if (octet & Q2931_IE_EXTENSION)
847                         goto l2_done;
848                 if (len == 0)
849                         return;
850                 octet = tvb_get_guint8(tvb, offset);
851                 if (uil2_protocol == Q2931_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, q2931_mode_vals,
859                               "Unknown (0x%02X)"));
860                 }
861                 offset += 1;
862                 len -= 1;
863
864                 if (octet & Q2931_IE_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, q2931_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 & Q2931_IE_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 Q2931_UIL3_X25_PL:
904                 case Q2931_UIL3_ISO_8208:
905                 case Q2931_UIL3_X223:
906                         proto_tree_add_text(tree, tvb, offset, 1,
907                             "Mode: %s",
908                             val_to_str(octet & 0x60, q2931_mode_vals,
909                               "Unknown (0x%02X)"));
910                         offset += 1;
911                         len -= 1;
912
913                         if (octet & Q2931_IE_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 & Q2931_IE_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 Q2931_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 Q2931_UIL3_TR_9577:
943                         add_l3_info = (octet & 0x7F) << 1;
944                         if (octet & Q2931_IE_EXTENSION)
945                                 goto l3_done;
946                         if (len < 2)
947                                 return;
948                         add_l3_info |= (tvb_get_guint8(tvb, offset + 1) & 0x40) >> 6;
949                         proto_tree_add_text(tree, tvb, offset, 2,
950                             "Additional layer 3 protocol information: %s",
951                             val_to_str(add_l3_info, nlpid_vals,
952                               "Unknown (0x%02X)"));
953                         offset += 2;
954                         len -= 2;
955                         if (add_l3_info == NLPID_SNAP) {
956                                 if (len < 6)
957                                         return;
958                                 offset += 1;
959                                 len -= 1;
960                                 organization_code = tvb_get_ntoh24(tvb, offset);
961                                 proto_tree_add_text(tree, tvb, offset, 3,
962                                     "Organization Code: 0x%06X (%s)",
963                                     organization_code,
964                                     val_to_str(organization_code, oui_vals,
965                                         "Unknown"));
966                                 offset += 3;
967                                 len -= 3;
968
969                                 if (len < 2)
970                                         return;
971                                 pid = tvb_get_ntohs(tvb, offset);
972                                 switch (organization_code) {
973
974                                 case OUI_ENCAP_ETHER:
975                                         proto_tree_add_text(tree, tvb, offset, 2,
976                                             "Ethernet type: %s",
977                                             val_to_str(pid, etype_vals,
978                                                 "Unknown (0x%04X)"));
979                                         break;
980
981                                 case OUI_ATM_FORUM:
982                                         proto_tree_add_text(tree, tvb, offset, 2,
983                                             "LANE Protocol ID: %s",
984                                             val_to_str(pid, lane_pid_vals,
985                                                 "Unknown (0x%04X)"));
986                                         break;
987
988                                 default:
989                                         proto_tree_add_text(tree, tvb, offset, 2,
990                                             "Protocol ID: 0x%04X", pid);
991                                         break;
992                                 }
993                         }
994                         break;
995                 }
996         }
997 l3_done:
998         ;
999 }
1000
1001 /*
1002  * Dissect a Cause information element.
1003  */
1004 static const value_string q2931_cause_coding_standard_vals[] = {
1005         { 0x00, "ITU-T standardized coding" },
1006         { 0x20, "ISO/IEC standard" },
1007         { 0x40, "National standard" },
1008         { 0x60, "Standard defined for the network" },
1009         { 0,    NULL }
1010 };
1011
1012 static const value_string q2931_cause_location_vals[] = {
1013         { 0x00, "User (U)" },
1014         { 0x01, "Private network serving the local user (LPN)" },
1015         { 0x02, "Public network serving the local user (LN)" },
1016         { 0x03, "Transit network (TN)" },
1017         { 0x04, "Public network serving the remote user (RLN)" },
1018         { 0x05, "Private network serving the remote user (RPN)" },
1019         { 0x07, "International network (INTL)" },
1020         { 0x0A, "Network beyond interworking point (BI)" },
1021         { 0,    NULL }
1022 };
1023
1024 /*
1025  * Cause codes for Cause.
1026  */
1027 #define Q2931_CAUSE_UNALLOC_NUMBER      0x01
1028 #define Q2931_CAUSE_NO_ROUTE_TO_DEST    0x03
1029 #define Q2931_CAUSE_CALL_REJECTED       0x15
1030 #define Q2931_CAUSE_NUMBER_CHANGED      0x16
1031 #define Q2931_CAUSE_CELL_RATE_UNAVAIL   0x25
1032 #define Q2931_CAUSE_ACCESS_INFO_DISC    0x2B
1033 #define Q2931_CAUSE_QOS_UNAVAILABLE     0x31
1034 #define Q2931_CAUSE_CHAN_NONEXISTENT    0x52
1035 #define Q2931_CAUSE_INCOMPATIBLE_DEST   0x58
1036 #define Q2931_CAUSE_MAND_IE_MISSING     0x60
1037 #define Q2931_CAUSE_MT_NONEX_OR_UNIMPL  0x61
1038 #define Q2931_CAUSE_IE_NONEX_OR_UNIMPL  0x63
1039 #define Q2931_CAUSE_INVALID_IE_CONTENTS 0x64
1040 #define Q2931_CAUSE_MSG_INCOMPAT_W_CS   0x65
1041 #define Q2931_CAUSE_REC_TIMER_EXP       0x66
1042
1043 static const value_string q2931_cause_code_vals[] = {
1044         { Q2931_CAUSE_UNALLOC_NUMBER,   "Unallocated (unassigned) number" },
1045         { 0x02,                         "No route to specified transit network" },
1046         { Q2931_CAUSE_NO_ROUTE_TO_DEST, "No route to destination" },
1047         { 0x10,                         "Normal call clearing" },
1048         { 0x11,                         "User busy" },
1049         { 0x12,                         "No user responding" },
1050         { Q2931_CAUSE_CALL_REJECTED,    "Call rejected" },
1051         { Q2931_CAUSE_NUMBER_CHANGED,   "Number changed" },
1052         { 0x17,                         "User rejects calls with calling line identification restriction" },
1053         { 0x1B,                         "Destination out of order" },
1054         { 0x1C,                         "Invalid number format (incomplete number)" },
1055         { 0x1E,                         "Response to STATUS ENQUIRY" },
1056         { 0x1F,                         "Normal unspecified" },
1057         { 0x23,                         "Requested VPCI/VCI not available" },
1058         { 0x24,                         "VPCI/VCI assignment failure" },
1059         { Q2931_CAUSE_CELL_RATE_UNAVAIL,"User cell rate not available" },
1060         { 0x26,                         "Network out of order" },
1061         { 0x29,                         "Temporary failure" },
1062         { Q2931_CAUSE_ACCESS_INFO_DISC, "Access information discarded" },
1063         { 0x2D,                         "No VPCI/VCI available" },
1064         { 0x2F,                         "Resources unavailable, unspecified" },
1065         { Q2931_CAUSE_QOS_UNAVAILABLE,  "Quality of service unavailable" },
1066         { 0x39,                         "Bearer capability not authorized" },
1067         { 0x3A,                         "Bearer capability not presently available" },
1068         { 0x3F,                         "Service or option not available, unspecified" },
1069         { 0x41,                         "Bearer capability not implemented" },
1070         { 0x49,                         "Unsupported combination of traffic parameters" },
1071         { 0x4E,                         "AAL parameters cannot be supported" },
1072         { 0x51,                         "Invalid call reference value" },
1073         { Q2931_CAUSE_CHAN_NONEXISTENT, "Identified channel does not exist" },
1074         { Q2931_CAUSE_INCOMPATIBLE_DEST,"Incompatible destination" },
1075         { 0x59,                         "Invalid endpoint reference" },
1076         { 0x5B,                         "Invalid transit network selection" },
1077         { 0x5C,                         "Too many pending ADD PARTY requests" },
1078         { Q2931_CAUSE_MAND_IE_MISSING,  "Mandatory information element is missing" },
1079         { Q2931_CAUSE_MT_NONEX_OR_UNIMPL,"Message type non-existent or not implemented" },
1080         { Q2931_CAUSE_IE_NONEX_OR_UNIMPL,"Information element nonexistant or not implemented" },
1081         { Q2931_CAUSE_INVALID_IE_CONTENTS,"Invalid information element contents" },
1082         { Q2931_CAUSE_MSG_INCOMPAT_W_CS,"Message not compatible with call state" },
1083         { Q2931_CAUSE_REC_TIMER_EXP,    "Recovery on timer expiry" },
1084         { 0x68,                         "Incorrect message length" },
1085         { 0x6F,                         "Protocol error, unspecified" },
1086         { 0,                            NULL }
1087 };
1088
1089 static const value_string q2931_cause_condition_vals[] = {
1090         { 0x00, "Unknown" },
1091         { 0x01, "Permanent" },
1092         { 0x02, "Transient" },
1093         { 0x00, NULL }
1094 };
1095
1096 #define Q2931_REJ_USER_SPECIFIC         0x00
1097 #define Q2931_REJ_IE_MISSING            0x04
1098 #define Q2931_REJ_IE_INSUFFICIENT       0x08
1099
1100 static const value_string q2931_rejection_reason_vals[] = {
1101         { 0x00, "User specific" },
1102         { 0x04, "Information element missing" },
1103         { 0x08, "Information element contents are not sufficient" },
1104         { 0x00, NULL }
1105 };
1106
1107 static void
1108 dissect_q2931_cause_ie(tvbuff_t *tvb, int offset, int len,
1109     proto_tree *tree)
1110 {
1111         guint8 octet;
1112         guint8 cause_value;
1113         guint8 rejection_reason;
1114         guint8 info_element;
1115         guint8 info_element_ext;
1116         guint16 info_element_len;
1117
1118         if (len == 0)
1119                 return;
1120         octet = tvb_get_guint8(tvb, offset);
1121         proto_tree_add_text(tree, tvb, offset, 1,
1122             "Location: %s",
1123             val_to_str(octet & 0x0F, q2931_cause_location_vals,
1124               "Unknown (0x%X)"));
1125         offset += 1;
1126         len -= 1;
1127
1128         if (len == 0)
1129                 return;
1130         octet = tvb_get_guint8(tvb, offset);
1131         cause_value = octet & 0x7F;
1132         proto_tree_add_text(tree, tvb, offset, 1,
1133             "Cause value: %s",
1134             val_to_str(cause_value, q2931_cause_code_vals,
1135               "Unknown (0x%X)"));
1136         offset += 1;
1137         len -= 1;
1138
1139         if (len == 0)
1140                 return;
1141         switch (cause_value) {
1142
1143         case Q2931_CAUSE_UNALLOC_NUMBER:
1144         case Q2931_CAUSE_NO_ROUTE_TO_DEST:
1145         case Q2931_CAUSE_QOS_UNAVAILABLE:
1146                 octet = tvb_get_guint8(tvb, offset);
1147                 proto_tree_add_text(tree, tvb, offset, 1,
1148                     "Network service: %s",
1149                     (octet & 0x80) ? "User" : "Provider");
1150                 proto_tree_add_text(tree, tvb, offset, 1,
1151                     "%s",
1152                     (octet & 0x40) ? "Abnormal" : "Normal");
1153                 proto_tree_add_text(tree, tvb, offset, 1,
1154                     "Condition: %s",
1155                     val_to_str(octet & 0x03, q2931_cause_condition_vals,
1156                       "Unknown (0x%X)"));
1157                 break;
1158
1159         case Q2931_CAUSE_CALL_REJECTED:
1160                 rejection_reason = octet & 0x7C;
1161                 proto_tree_add_text(tree, tvb, offset, 1,
1162                     "Rejection reason: %s",
1163                     val_to_str(octet & 0x7C, q2931_cause_condition_vals,
1164                       "Unknown (0x%X)"));
1165                 proto_tree_add_text(tree, tvb, offset, 1,
1166                     "Condition: %s",
1167                     val_to_str(octet & 0x03, q2931_cause_condition_vals,
1168                       "Unknown (0x%X)"));
1169                 offset += 1;
1170                 len -= 1;
1171
1172                 if (len == 0)
1173                         return;
1174                 switch (rejection_reason) {
1175
1176                 case Q2931_REJ_USER_SPECIFIC:
1177                         proto_tree_add_text(tree, tvb, offset, len,
1178                             "User specific diagnostic: %s",
1179                             tvb_bytes_to_str(tvb, offset, len));
1180                         break;
1181
1182                 case Q2931_REJ_IE_MISSING:
1183                         proto_tree_add_text(tree, tvb, offset, 1,
1184                             "Missing information element: %s",
1185                             val_to_str(tvb_get_guint8(tvb, offset), q2931_info_element_vals,
1186                               "Unknown (0x%02X)"));
1187                         break;
1188
1189                 case Q2931_REJ_IE_INSUFFICIENT:
1190                         proto_tree_add_text(tree, tvb, offset, 1,
1191                             "Insufficient information element: %s",
1192                             val_to_str(tvb_get_guint8(tvb, offset), q2931_info_element_vals,
1193                               "Unknown (0x%02X)"));
1194                         break;
1195
1196                 default:
1197                         proto_tree_add_text(tree, tvb, offset, len,
1198                             "Diagnostic: %s",
1199                             tvb_bytes_to_str(tvb, offset, len));
1200                         break;
1201                 }
1202                 break;
1203
1204         case Q2931_CAUSE_NUMBER_CHANGED:
1205                 /*
1206                  * UNI 3.1 claims this "is formatted as the called party
1207                  * number information element, including information
1208                  * element identifier.
1209                  */
1210                 info_element = tvb_get_guint8(tvb, offset);
1211                 info_element_ext = tvb_get_guint8(tvb, offset + 1);
1212                 info_element_len = tvb_get_ntohs(tvb, offset + 2);
1213                 dissect_q2931_ie(tvb, offset, info_element_len, tree,
1214                     info_element, info_element_ext);
1215                 break;
1216
1217         case Q2931_CAUSE_ACCESS_INFO_DISC:
1218         case Q2931_CAUSE_INCOMPATIBLE_DEST:
1219         case Q2931_CAUSE_MAND_IE_MISSING:
1220         case Q2931_CAUSE_IE_NONEX_OR_UNIMPL:
1221         case Q2931_CAUSE_INVALID_IE_CONTENTS:
1222                 do {
1223                         proto_tree_add_text(tree, tvb, offset, 1,
1224                             "Information element: %s",
1225                             val_to_str(tvb_get_guint8(tvb, offset), q2931_info_element_vals,
1226                               "Unknown (0x%02X)"));
1227                         offset += 1;
1228                         len -= 1;
1229                 } while (len != 0);
1230                 break;
1231
1232         case Q2931_CAUSE_CELL_RATE_UNAVAIL:
1233                 do {
1234                         proto_tree_add_text(tree, tvb, offset, 1,
1235                             "Cell rate subfield identifier: %s",
1236                             val_to_str(tvb_get_guint8(tvb, offset), q2931_atm_td_subfield_vals,
1237                               "Unknown (0x%02X)"));
1238                         offset += 1;
1239                         len -= 1;
1240                 } while (len != 0);
1241                 break;
1242
1243         case Q2931_CAUSE_CHAN_NONEXISTENT:
1244                 if (len < 2)
1245                         return;
1246                 proto_tree_add_text(tree, tvb, offset, 2,
1247                     "VPCI: %u", tvb_get_ntohs(tvb, offset));
1248                 offset += 2;
1249                 len -= 2;
1250
1251                 if (len < 2)
1252                         return;
1253                 proto_tree_add_text(tree, tvb, offset, 2,
1254                     "VCI: %u", tvb_get_ntohs(tvb, offset));
1255                 break;
1256
1257         case Q2931_CAUSE_MT_NONEX_OR_UNIMPL:
1258         case Q2931_CAUSE_MSG_INCOMPAT_W_CS:
1259                 proto_tree_add_text(tree, tvb, offset, 1,
1260                     "Message type: %s",
1261                     val_to_str(tvb_get_guint8(tvb, offset), q2931_message_type_vals,
1262                       "Unknown (0x%02X)"));
1263                 break;
1264
1265         case Q2931_CAUSE_REC_TIMER_EXP:
1266                 if (len < 3)
1267                         return;
1268                 proto_tree_add_text(tree, tvb, offset, 3,
1269                     "Timer: %.3s", tvb_get_ptr(tvb, offset, 3));
1270                 break;
1271
1272         default:
1273                 proto_tree_add_text(tree, tvb, offset, len,
1274                     "Diagnostics: %s",
1275                     tvb_bytes_to_str(tvb, offset, len));
1276         }
1277 }
1278
1279 /*
1280  * Dissect a Call state information element.
1281  */
1282 static const value_string q2931_call_state_vals[] = {
1283         { 0x00, "Null" },
1284         { 0x01, "Call initiated" },
1285         { 0x02, "Overlap sending" },
1286         { 0x03, "Outgoing call proceeding" },
1287         { 0x04, "Call delivered" },
1288         { 0x06, "Call present" },
1289         { 0x07, "Call received" },
1290         { 0x09, "Connect request" },
1291         { 0x0A, "Incoming call proceeding" },
1292         { 0x0B, "Active" },
1293         { 0x0C, "Disconnect request" },
1294         { 0x0F, "Disconnect indication" },
1295         { 0x11, "Suspend request" },
1296         { 0x13, "Resume request" },
1297         { 0x16, "Release request" },
1298         { 0x19, "Overlap receiving" },
1299         { 0x3D, "Restart request" },
1300         { 0x3E, "Restart" },
1301         { 0,    NULL }
1302 };
1303
1304 static void
1305 dissect_q2931_call_state_ie(tvbuff_t *tvb, int offset, int len,
1306     proto_tree *tree)
1307 {
1308         guint8 octet;
1309
1310         if (len == 0)
1311                 return;
1312         octet = tvb_get_guint8(tvb, offset);
1313         proto_tree_add_text(tree, tvb, offset, 1,
1314             "Call state: %s",
1315             val_to_str(octet & 0x3F, q2931_call_state_vals,
1316               "Unknown (0x%02X)"));
1317 }
1318
1319 /*
1320  * Dissect a (phone) number information element.
1321  */
1322 static const value_string q2931_number_type_vals[] = {
1323         { 0x00, "Unknown" },
1324         { 0x10, "International number" },
1325         { 0x20, "National number" },
1326         { 0x30, "Network specific number" },
1327         { 0x40, "Subscriber number" },
1328         { 0x60, "Abbreviated number" },
1329         { 0,    NULL }
1330 };
1331
1332 #define Q2931_ISDN_NUMBERING    0x01
1333 #define Q2931_NSAP_ADDRESSING   0x02
1334
1335 static const value_string q2931_numbering_plan_vals[] = {
1336         { 0x00,                  "Unknown" },
1337         { Q2931_ISDN_NUMBERING,  "E.164 ISDN/telephony numbering" },
1338         { Q2931_NSAP_ADDRESSING, "ISO/IEC 8348 NSAP addressing" },
1339         { 0x09,                  "Private numbering" },
1340         { 0,                     NULL }
1341 };
1342
1343 static const value_string q2931_presentation_indicator_vals[] = {
1344         { 0x00, "Presentation allowed" },
1345         { 0x20, "Presentation restricted" },
1346         { 0x40, "Number not available" },
1347         { 0,    NULL }
1348 };
1349
1350 static const value_string q2931_screening_indicator_vals[] = {
1351         { 0x00, "User-provided, not screened" },
1352         { 0x01, "User-provided, verified and passed" },
1353         { 0x02, "User-provided, verified and failed" },
1354         { 0x03, "Network-provided" },
1355         { 0,    NULL }
1356 };
1357
1358 static void
1359 dissect_q2931_number_ie(tvbuff_t *tvb, int offset, int len,
1360     proto_tree *tree)
1361 {
1362         guint8 octet;
1363         guint8 numbering_plan;
1364         proto_item *ti;
1365         proto_tree *nsap_tree;
1366
1367         if (len == 0)
1368                 return;
1369         octet = tvb_get_guint8(tvb, offset);
1370         proto_tree_add_text(tree, tvb, offset, 1,
1371             "Type of number: %s",
1372             val_to_str(octet & 0x70, q2931_number_type_vals,
1373               "Unknown (0x%02X)"));
1374         numbering_plan = octet & 0x0F;
1375         proto_tree_add_text(tree, tvb, offset, 1,
1376             "Numbering plan: %s",
1377             val_to_str(numbering_plan, q2931_numbering_plan_vals,
1378               "Unknown (0x%02X)"));
1379         offset += 1;
1380         len -= 1;
1381
1382         if (!(octet & Q2931_IE_EXTENSION)) {
1383                 if (len == 0)
1384                         return;
1385                 octet = tvb_get_guint8(tvb, offset);
1386                 proto_tree_add_text(tree, tvb, offset, 1,
1387                     "Presentation indicator: %s",
1388                     val_to_str(octet & 0x60, q2931_presentation_indicator_vals,
1389                       "Unknown (0x%X)"));
1390                 proto_tree_add_text(tree, tvb, offset, 1,
1391                     "Screening indicator: %s",
1392                     val_to_str(octet & 0x03, q2931_screening_indicator_vals,
1393                       "Unknown (0x%X)"));
1394                 offset += 1;
1395                 len -= 1;
1396         }
1397
1398         if (len == 0)
1399                 return;
1400         switch (numbering_plan) {
1401
1402         case Q2931_ISDN_NUMBERING:
1403                 proto_tree_add_text(tree, tvb, offset, len, "Number: %.*s",
1404                     len, tvb_get_ptr(tvb, offset, len));
1405                 break;
1406
1407         case Q2931_NSAP_ADDRESSING:
1408                 if (len < 20) {
1409                         proto_tree_add_text(tree, tvb, offset, len,
1410                             "Number (too short): %s",
1411                             tvb_bytes_to_str(tvb, offset, len));
1412                         return;
1413                 }
1414                 ti = proto_tree_add_text(tree, tvb, offset, len, "Number");
1415                 nsap_tree = proto_item_add_subtree(ti, ett_q2931_nsap);
1416                 dissect_atm_nsap(tvb, offset, len, nsap_tree);
1417                 break;
1418
1419         default:
1420                 proto_tree_add_text(tree, tvb, offset, len, "Number: %s",
1421                     tvb_bytes_to_str(tvb, offset, len));
1422                 break;
1423         }
1424 }
1425
1426 /*
1427  * Dissect a party subaddress information element.
1428  */
1429 static const value_string q2931_subaddress_type_vals[] = {
1430         { 0x00, "X.213/ISO 8348 NSAP" },
1431         { 0x10, "User-specified ATM endsystem address" },
1432         { 0x20, "User-specified" },
1433         { 0,    NULL }
1434 };
1435
1436 static const value_string q2931_odd_even_indicator_vals[] = {
1437         { 0x00, "Even number of address signals" },
1438         { 0x10, "Odd number of address signals" },
1439         { 0,    NULL }
1440 };
1441
1442 static void
1443 dissect_q2931_party_subaddr_ie(tvbuff_t *tvb, int offset, int len,
1444     proto_tree *tree)
1445 {
1446         guint8 octet;
1447
1448         if (len == 0)
1449                 return;
1450         octet = tvb_get_guint8(tvb, offset);
1451         proto_tree_add_text(tree, tvb, offset, 1,
1452             "Type of subaddress: %s",
1453             val_to_str(octet & 0x70, q2931_subaddress_type_vals,
1454               "Unknown (0x%02X)"));
1455         proto_tree_add_text(tree, tvb, offset, 1,
1456             "Odd/even indicator: %s",
1457             val_to_str(octet & 0x10, q2931_odd_even_indicator_vals,
1458               NULL));
1459         offset += 1;
1460         len -= 1;
1461
1462         if (len == 0)
1463                 return;
1464         proto_tree_add_text(tree, tvb, offset, len, "Subaddress: %s",
1465             tvb_bytes_to_str(tvb, offset, len));
1466 }
1467
1468 /*
1469  * Dissect a connection identifier information element.
1470  */
1471 static const value_string q2931_vp_associated_signalling_vals[] = {
1472         { 0x00, "Yes" },
1473         { 0x08, "No - explicit indication of VPCI" },
1474         { 0x00, NULL }
1475 };
1476
1477 static const value_string q2931_preferred_exclusive_vals[] = {
1478         { 0x00, "Exclusive VPCI; exclusive VCI" },
1479         { 0x01, "Exclusive VPCI; any VCI" },
1480         { 0x04, "Exclusive VPCI; no VCI" },
1481         { 0x00, NULL }
1482 };
1483
1484 static void
1485 dissect_q2931_connection_identifier_ie(tvbuff_t *tvb, int offset, int len,
1486     proto_tree *tree)
1487 {
1488         guint8 octet;
1489
1490         if (len == 0)
1491                 return;
1492         octet = tvb_get_guint8(tvb, offset);
1493         proto_tree_add_text(tree, tvb, offset, 1,
1494             "VP-associated signalling: %s",
1495             val_to_str(octet & 0x18, q2931_vp_associated_signalling_vals,
1496               "Unknown (0x%02X)"));
1497         proto_tree_add_text(tree, tvb, offset, 1,
1498             "Preferred/exclusive: %s",
1499             val_to_str(octet & 0x07, q2931_preferred_exclusive_vals,
1500               "Unknown (0x%02X)"));
1501         offset += 1;
1502         len -= 1;
1503
1504         if (len < 2)
1505                 return;
1506         proto_tree_add_text(tree, tvb, offset, 2, "VPCI: %u",
1507             tvb_get_ntohs(tvb, offset));
1508         offset += 2;
1509         len -= 2;
1510
1511         if (len < 2)
1512                 return;
1513         proto_tree_add_text(tree, tvb, offset, 2, "VCI: %u",
1514             tvb_get_ntohs(tvb, offset));
1515 }
1516
1517 /*
1518  * Dissect an End-to-end transit delay information element.
1519  */
1520 static void
1521 dissect_q2931_e2e_transit_delay_ie(tvbuff_t *tvb, int offset, int len,
1522     proto_tree *tree)
1523 {
1524         guint8 identifier;
1525         guint16 value;
1526
1527         while (len >= 3) {
1528                 identifier = tvb_get_guint8(tvb, offset);
1529                 value = tvb_get_ntohs(tvb, offset + 1);
1530                 switch (identifier) {
1531
1532                 case 0x01:      /* Cumulative transit delay identifier */
1533                         proto_tree_add_text(tree, tvb, offset, 3,
1534                             "Cumulative transit delay: %u ms", value);
1535                         break;
1536
1537                 case 0x03:      /* Maximum transit delay identifier */
1538                         if (value == 0xFFFF) {
1539                                 proto_tree_add_text(tree, tvb, offset, 3,
1540                                     "Any end-to-end transit delay value acceptable");
1541                         } else {
1542                                 proto_tree_add_text(tree, tvb, offset, 3,
1543                                     "Maximum end-to-end transit delay: %u ms",
1544                                     value);
1545                         }
1546                         break;
1547
1548                 default:        /* Unknown transit delay identifier */
1549                         proto_tree_add_text(tree, tvb, offset, 1,
1550                             "Unknown transit delay identifier (0x%02X)",
1551                             identifier);
1552                         return; /* give up */
1553                 }
1554         }
1555 }
1556
1557 /*
1558  * Dissect a Quality of Service parameter information element.
1559  */
1560 static const value_string q2931_qos_parameter_vals[] = {
1561         { 0x00, "Unspecified QOS class" },
1562         { 0x00, NULL }
1563 };
1564
1565 static void
1566 dissect_q2931_qos_parameter_ie(tvbuff_t *tvb, int offset, int len,
1567     proto_tree *tree)
1568 {
1569         guint8 octet;
1570
1571         if (len == 0)
1572                 return;
1573         octet = tvb_get_guint8(tvb, offset);
1574         proto_tree_add_text(tree, tvb, offset, 1,
1575             "QOS class forward: %s",
1576             val_to_str(octet, q2931_qos_parameter_vals,
1577               "Unknown (0x%02X)"));
1578         offset += 1;
1579         len -= 1;
1580
1581         if (len == 0)
1582                 return;
1583         octet = tvb_get_guint8(tvb, offset);
1584         proto_tree_add_text(tree, tvb, offset, 1,
1585             "QOS class backward: %s",
1586             val_to_str(octet, q2931_qos_parameter_vals,
1587               "Unknown (0x%02X)"));
1588 }
1589
1590 /*
1591  * Dissect a broadband repeat indicator.
1592  */
1593 static const value_string q2931_bband_rpt_indicator_vals[] = {
1594         { 0x02, "Prioritized list for selecting one possibility (descending order)" },
1595         { 0x00, NULL }
1596 };
1597
1598 static void
1599 dissect_q2931_bband_rpt_indicator(tvbuff_t *tvb, int offset, int len,
1600     proto_tree *tree)
1601 {
1602         guint8 octet;
1603
1604         if (len == 0)
1605                 return;
1606         octet = tvb_get_guint8(tvb, offset);
1607         proto_tree_add_text(tree, tvb, offset, 1,
1608             "Broadband repeat indicator: %s",
1609             val_to_str(octet & 0x0F, q2931_bband_rpt_indicator_vals,
1610               "Unknown (0x%02X)"));
1611 }
1612
1613 /*
1614  * Dissect a restart indicator.
1615  */
1616 static const value_string q2931_class_vals[] = {
1617         { 0x00, "Indicated VC" },
1618         { 0x01, "All VC's in the indicated VPC controlled via this channel" },
1619         { 0x02, "All VC's controlled by the L3 entity that sent this message" },
1620         { 0x00, NULL }
1621 };
1622
1623 static void
1624 dissect_q2931_restart_indicator(tvbuff_t *tvb, int offset, int len,
1625     proto_tree *tree)
1626 {
1627         guint8 octet;
1628
1629         if (len == 0)
1630                 return;
1631         octet = tvb_get_guint8(tvb, offset);
1632         proto_tree_add_text(tree, tvb, offset, 1,
1633             "Restart indicator: %s",
1634             val_to_str(octet & 0x07, q2931_class_vals,
1635               "Unknown (0x%02X)"));
1636 }
1637
1638 /*
1639  * Dissect an broadband sending complete information element.
1640  */
1641 static void
1642 dissect_q2931_bband_sending_compl_ie(tvbuff_t *tvb, int offset, int len,
1643     proto_tree *tree)
1644 {
1645         guint8 identifier;
1646
1647         while (len != 0) {
1648                 identifier = tvb_get_guint8(tvb, offset);
1649                 switch (identifier) {
1650
1651                 case 0xA1:      /* Sending complete indication */
1652                         proto_tree_add_text(tree, tvb, offset, 1,
1653                             "Broadband sending complete indication");
1654                         offset += 1;
1655                         len -= 1;
1656                         break;
1657
1658                 default:        /* unknown broadband sending complete element */
1659                         proto_tree_add_text(tree, tvb, offset, 1,
1660                             "Unknown broadband sending complete element (0x%02X)",
1661                             identifier);
1662                         return; /* give up */
1663                 }
1664         }
1665 }
1666
1667 /*
1668  * Dissect a Transit network selection information element.
1669  */
1670 static const value_string q2931_netid_type_vals[] = {
1671         { 0x00, "User specified" },
1672         { 0x20, "National network identification" },
1673         { 0x30, "International network identification" },
1674         { 0,    NULL }
1675 };
1676
1677 static const value_string q2931_netid_plan_vals[] = {
1678         { 0x00, "Unknown" },
1679         { 0x01, "Carrier Identification Code" },
1680         { 0x03, "X.121 data network identification code" },
1681         { 0,    NULL }
1682 };
1683
1684 static void
1685 dissect_q2931_transit_network_sel_ie(tvbuff_t *tvb, int offset, int len,
1686     proto_tree *tree)
1687 {
1688         guint8 octet;
1689
1690         if (len == 0)
1691                 return;
1692         octet = tvb_get_guint8(tvb, offset);
1693         proto_tree_add_text(tree, tvb, offset, 1,
1694             "Type of network identification: %s",
1695             val_to_str(octet & 0x70, q2931_netid_type_vals,
1696               "Unknown (0x%02X)"));
1697         proto_tree_add_text(tree, tvb, offset, 1,
1698             "Network identification plan: %s",
1699             val_to_str(octet & 0x0F, q2931_netid_plan_vals,
1700               "Unknown (0x%02X)"));
1701         offset += 1;
1702         len -= 1;
1703
1704         if (len == 0)
1705                 return;
1706         proto_tree_add_text(tree, tvb, offset, len,
1707             "Network identification: %.*s", len, tvb_get_ptr(tvb, offset, len));
1708 }
1709
1710 /*
1711  * Dissect an OAM traffic descriptor information element.
1712  */
1713 static const value_string q2931_shaping_indicator_vals[] = {
1714         { 0x00, "No user specified requirement" },
1715         { 0x20, "Aggregate shaping of user and OAM cells not allowed" },
1716         { 0,    NULL }
1717 };
1718
1719 static const value_string q2931_user_net_fault_mgmt_vals[] = {
1720         { 0x00, "No user-originated fault managment indications" },
1721         { 0x01, "User-originated fault management indications, cell rate 1 cell/s" },
1722         { 0,    NULL }
1723 };
1724
1725 static const value_string q2931_fwd_e2e_oam_f5_flow_indicator_vals[] = {
1726         { 0x00, "0% of the forward cell rate" },
1727         { 0x10, "0.1% of the forward cell rate" },
1728         { 0x40, "1% of the forward cell rate" },
1729         { 0x0,  NULL }
1730 };
1731
1732 static const value_string q2931_bwd_e2e_oam_f5_flow_indicator_vals[] = {
1733         { 0x00, "0% of the backward cell rate" },
1734         { 0x01, "0.1% of the backward cell rate" },
1735         { 0x04, "1% of the backward cell rate" },
1736         { 0x0,  NULL }
1737 };
1738
1739 static void
1740 dissect_q2931_oam_traffic_descriptor_ie(tvbuff_t *tvb, int offset, int len,
1741     proto_tree *tree)
1742 {
1743         guint8 octet;
1744
1745         if (len == 0)
1746                 return;
1747         octet = tvb_get_guint8(tvb, offset);
1748         proto_tree_add_text(tree, tvb, offset, 1,
1749             "Shaping indicator: %s",
1750             val_to_str(octet & 0x60, q2931_shaping_indicator_vals,
1751               "Unknown (0x%02X)"));
1752         proto_tree_add_text(tree, tvb, offset, 1,
1753             "Use of end-to-end OAM F5 flow is %s",
1754             (octet & 0x10) ? "mandatory" : "optional");
1755         proto_tree_add_text(tree, tvb, offset, 1,
1756             "User-Network fault management indicator: %s",
1757             val_to_str(octet & 0x07, q2931_user_net_fault_mgmt_vals,
1758               "Unknown (0x%02X)"));
1759         offset += 1;
1760         len -= 1;
1761
1762         if (len == 0)
1763                 return;
1764         octet = tvb_get_guint8(tvb, offset);
1765         proto_tree_add_text(tree, tvb, offset, 1,
1766             "Forward end-to-end OAM F5 flow indicator: %s",
1767             val_to_str(octet & 0x70, q2931_fwd_e2e_oam_f5_flow_indicator_vals,
1768               "Unknown (0x%02X)"));
1769         proto_tree_add_text(tree, tvb, offset, 1,
1770             "Backward end-to-end OAM F5 flow indicator: %s",
1771             val_to_str(octet & 0x07, q2931_bwd_e2e_oam_f5_flow_indicator_vals,
1772               "Unknown (0x%02X)"));
1773 }
1774
1775 /*
1776  * Dissect an Endpoint reference information element.
1777  */
1778 static const value_string q2931_endpoint_reference_type_vals[] = {
1779         { 0x00, "Locally defined integer" },
1780         { 0,    NULL }
1781 };
1782
1783 static void
1784 dissect_q2931_endpoint_reference_ie(tvbuff_t *tvb, int offset, int len,
1785     proto_tree *tree)
1786 {
1787         guint8 octet;
1788         guint16 value;
1789
1790         if (len == 0)
1791                 return;
1792         octet = tvb_get_guint8(tvb, offset);
1793         proto_tree_add_text(tree, tvb, offset, 1,
1794             "Endpoint reference type: %s",
1795             val_to_str(octet, q2931_endpoint_reference_type_vals,
1796               "Unknown (0x%02X)"));
1797         offset += 1;
1798         len -= 1;
1799
1800         if (len < 2)
1801                 return;
1802         value = tvb_get_ntohs(tvb, offset);
1803         proto_tree_add_text(tree, tvb, offset, 2,
1804             "Endpoint reference flag: %s",
1805             (value & 0x8000) ? "Message sent to side that originates the endpoint reference" :
1806                                "Message sent from side that originates the endpoint reference");
1807         proto_tree_add_text(tree, tvb, offset, 2,
1808             "Endpoint reference identifier value: %u",
1809             value & 0x7FFF);
1810 }
1811
1812 /*
1813  * Dissect an Endpoint state information element.
1814  */
1815 static const value_string q2931_endpoint_reference_party_state_vals[] = {
1816         { 0x00, "Null" },
1817         { 0x01, "ADD PARTY initiated" },
1818         { 0x06, "ADD PARTY received" },
1819         { 0x0B, "DROP PARTY initiated" },
1820         { 0x0C, "DROP PARTY received" },
1821         { 0x0A, "Active" },
1822         { 0,    NULL }
1823 };
1824
1825 static void
1826 dissect_q2931_endpoint_state_ie(tvbuff_t *tvb, int offset, int len,
1827     proto_tree *tree)
1828 {
1829         guint8 octet;
1830
1831         if (len == 0)
1832                 return;
1833         octet = tvb_get_guint8(tvb, offset);
1834         proto_tree_add_text(tree, tvb, offset, 1,
1835             "Endpoint reference party-state: %s",
1836             val_to_str(octet & 0x3F, q2931_endpoint_reference_party_state_vals,
1837               "Unknown (0x%02X)"));
1838 }
1839
1840 static void
1841 dissect_q2931_ie_contents(tvbuff_t *tvb, int offset, int len,
1842     proto_tree *tree, guint8 info_element)
1843 {
1844         switch (info_element) {
1845
1846         case Q2931_IE_BBAND_LOCKING_SHIFT:
1847         case Q2931_IE_BBAND_NLOCKING_SHIFT:
1848                 dissect_q2931_shift_ie(tvb, offset, len, tree, info_element);
1849                 break;
1850
1851         case Q2931_IE_NBAND_BEARER_CAP:
1852         case Q2931_IE_NBAND_LOW_LAYER_COMPAT:
1853                 dissect_q931_bearer_capability_ie(tvb, offset, len, tree);
1854                 break;
1855
1856         case Q2931_IE_NBAND_HIGH_LAYER_COMPAT:
1857                 dissect_q931_high_layer_compat_ie(tvb, offset, len, tree);
1858                 break;
1859
1860         case Q2931_IE_PROGRESS_INDICATOR:
1861                 dissect_q931_progress_indicator_ie(tvb, offset, len, tree);
1862                 break;
1863
1864         case Q2931_IE_AAL_PARAMETERS:
1865                 dissect_q2931_aal_parameters_ie(tvb, offset, len, tree);
1866                 break;
1867
1868         case Q2931_IE_ATM_USER_CELL_RATE:
1869                 dissect_q2931_atm_cell_rate_ie(tvb, offset, len, tree);
1870                 break;
1871
1872         case Q2931_IE_BBAND_BEARER_CAP:
1873                 dissect_q2931_bband_bearer_cap_ie(tvb, offset, len, tree);
1874                 break;
1875
1876         case Q2931_IE_BBAND_HI_LAYER_INFO:
1877                 dissect_q2931_bband_hi_layer_info_ie(tvb, offset, len, tree);
1878                 break;
1879
1880         case Q2931_IE_BBAND_LOW_LAYER_INFO:
1881                 dissect_q2931_bband_low_layer_info_ie(tvb, offset, len, tree);
1882                 break;
1883
1884         case Q2931_IE_CALL_STATE:
1885                 dissect_q2931_call_state_ie(tvb, offset, len, tree);
1886                 break;
1887
1888         case Q2931_IE_CALLED_PARTY_NUMBER:
1889         case Q2931_IE_CALLING_PARTY_NUMBER:
1890                 dissect_q2931_number_ie(tvb, offset, len, tree);
1891                 break;
1892
1893         case Q2931_IE_CALLED_PARTY_SUBADDR:
1894         case Q2931_IE_CALLING_PARTY_SUBADDR:
1895                 dissect_q2931_party_subaddr_ie(tvb, offset, len, tree);
1896                 break;
1897
1898         case Q2931_IE_CAUSE:
1899                 dissect_q2931_cause_ie(tvb, offset, len, tree);
1900                 break;
1901
1902         case Q2931_IE_CONNECTION_IDENTIFIER:
1903                 dissect_q2931_connection_identifier_ie(tvb, offset, len, tree);
1904                 break;
1905
1906         case Q2931_IE_E2E_TRANSIT_DELAY:
1907                 dissect_q2931_e2e_transit_delay_ie(tvb, offset, len, tree);
1908                 break;
1909
1910         case Q2931_IE_QOS_PARAMETER:
1911                 dissect_q2931_qos_parameter_ie(tvb, offset, len, tree);
1912                 break;
1913
1914         case Q2931_IE_BBAND_RPT_INDICATOR:
1915                 dissect_q2931_bband_rpt_indicator(tvb, offset, len, tree);
1916                 break;
1917
1918         case Q2931_IE_RESTART_INDICATOR:
1919                 dissect_q2931_restart_indicator(tvb, offset, len, tree);
1920                 break;
1921
1922         case Q2931_IE_BBAND_SENDING_COMPL:
1923                 dissect_q2931_bband_sending_compl_ie(tvb, offset, len, tree);
1924                 break;
1925
1926         case Q2931_IE_TRANSIT_NETWORK_SEL:
1927                 dissect_q2931_transit_network_sel_ie(tvb, offset, len, tree);
1928                 break;
1929
1930         case Q2931_IE_OAM_TRAFFIC_DESCRIPTOR:
1931                 dissect_q2931_oam_traffic_descriptor_ie(tvb, offset, len, tree);
1932                 break;
1933
1934         case Q2931_IE_ENDPOINT_REFERENCE:
1935                 dissect_q2931_endpoint_reference_ie(tvb, offset, len, tree);
1936                 break;
1937
1938         case Q2931_IE_ENDPOINT_STATE:
1939                 dissect_q2931_endpoint_state_ie(tvb, offset, len, tree);
1940                 break;
1941         }
1942 }
1943
1944 static void
1945 dissect_q2931_ie(tvbuff_t *tvb, int offset, int len, proto_tree *tree,
1946     guint8 info_element, guint8 info_element_ext)
1947 {
1948         proto_item      *ti;
1949         proto_tree      *ie_tree;
1950         proto_tree      *ie_ext_tree;
1951
1952         ti = proto_tree_add_text(tree, tvb, offset, 1+1+2+len, "%s",
1953             val_to_str(info_element, q2931_info_element_vals,
1954               "Unknown information element (0x%02X)"));
1955         ie_tree = proto_item_add_subtree(ti, ett_q2931_ie);
1956         proto_tree_add_text(ie_tree, tvb, offset, 1, "Information element: %s",
1957             val_to_str(info_element, q2931_info_element_vals,
1958               "Unknown (0x%02X)"));
1959         ti = proto_tree_add_text(ie_tree, tvb, offset + 1, 1,
1960             "Information element extension: 0x%02x",
1961             info_element_ext);
1962         ie_ext_tree = proto_item_add_subtree(ti, ett_q2931_ie_ext);
1963         proto_tree_add_text(ie_ext_tree, tvb, offset + 1, 1,
1964             decode_enumerated_bitfield(info_element_ext,
1965                 Q2931_IE_COMPAT_CODING_STD, 8,
1966                 coding_std_vals, "Coding standard: %s"));
1967         proto_tree_add_text(ie_ext_tree, tvb, offset + 1, 1,
1968             decode_boolean_bitfield(info_element_ext,
1969             Q2931_IE_COMPAT_FOLLOW_INST, 8,
1970             "Follow explicit error handling instructions",
1971             "Regular error handling procedures apply"));
1972         if (info_element_ext & Q2931_IE_COMPAT_FOLLOW_INST) {
1973                 proto_tree_add_text(ie_ext_tree, tvb, offset + 1, 1,
1974                     decode_enumerated_bitfield(info_element_ext,
1975                         Q2931_IE_COMPAT_ACTION_IND, 8,
1976                         ie_action_ind_vals,
1977                         "Action indicator: %s"));
1978         }
1979         proto_tree_add_text(ie_tree, tvb, offset + 2, 2, "Length: %u", len);
1980
1981         if ((info_element_ext & Q2931_IE_COMPAT_CODING_STD)
1982             == Q2931_ITU_STANDARDIZED_CODING) {
1983                 dissect_q2931_ie_contents(tvb, offset + 4,
1984                     len, ie_tree, info_element);
1985         } else {
1986                 /*
1987                  * We don't know how it's encoded, so just
1988                  * dump it as data and be done with it.
1989                  */
1990                 proto_tree_add_text(ie_tree, tvb, offset + 4,  len,
1991                     "Data: %s", tvb_bytes_to_str(tvb, offset + 4, len));
1992         }
1993 }
1994
1995 static void
1996 dissect_q2931(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1997 {
1998         int             offset = 0;
1999         proto_tree      *q2931_tree = NULL;
2000         proto_item      *ti;
2001         proto_tree      *ext_tree;
2002         guint8          call_ref_len;
2003         guint8          call_ref[15];
2004         guint8          message_type;
2005         guint8          message_type_ext;
2006         guint16         message_len;
2007         guint8          info_element;
2008         guint8          info_element_ext;
2009         guint16         info_element_len;
2010         int             codeset;
2011         gboolean        non_locking_shift;
2012
2013         if (check_col(pinfo->cinfo, COL_PROTOCOL))
2014                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Q.2931");
2015
2016         if (tree) {
2017                 ti = proto_tree_add_item(tree, proto_q2931, tvb, offset, -1,
2018                     FALSE);
2019                 q2931_tree = proto_item_add_subtree(ti, ett_q2931);
2020
2021                 proto_tree_add_uint(q2931_tree, hf_q2931_discriminator, tvb, offset, 1, tvb_get_guint8(tvb, offset));
2022         }
2023         offset += 1;
2024         call_ref_len = tvb_get_guint8(tvb, offset) & 0xF;       /* XXX - do as a bit field? */
2025         if (q2931_tree != NULL)
2026                 proto_tree_add_uint(q2931_tree, hf_q2931_call_ref_len, tvb, offset, 1, call_ref_len);
2027         offset += 1;
2028         if (call_ref_len != 0) {
2029                 tvb_memcpy(tvb, call_ref, offset, call_ref_len);
2030                 if (q2931_tree != NULL) {
2031                         proto_tree_add_boolean(q2931_tree, hf_q2931_call_ref_flag,
2032                             tvb, offset, 1, (call_ref[0] & 0x80) != 0);
2033                         call_ref[0] &= 0x7F;
2034                         proto_tree_add_bytes(q2931_tree, hf_q2931_call_ref, tvb, offset, call_ref_len, call_ref);
2035                 }
2036                 offset += call_ref_len;
2037         }
2038         message_type = tvb_get_guint8(tvb, offset);
2039         if (check_col(pinfo->cinfo, COL_INFO)) {
2040                 col_add_str(pinfo->cinfo, COL_INFO,
2041                     val_to_str(message_type, q2931_message_type_vals,
2042                       "Unknown message type (0x%02X)"));
2043         }
2044         if (q2931_tree != NULL)
2045                 proto_tree_add_uint(q2931_tree, hf_q2931_message_type, tvb, offset, 1, message_type);
2046         offset += 1;
2047
2048         message_type_ext = tvb_get_guint8(tvb, offset);
2049         if (q2931_tree != NULL) {
2050                 ti = proto_tree_add_uint(q2931_tree, hf_q2931_message_type_ext, tvb,
2051                     offset, 1, message_type_ext);
2052                 ext_tree = proto_item_add_subtree(ti, ett_q2931_ext);
2053                 proto_tree_add_boolean(ext_tree, hf_q2931_message_flag, tvb,
2054                     offset, 1, message_type_ext);
2055                 if (message_type_ext & Q2931_MSG_TYPE_EXT_FOLLOW_INST) {
2056                         proto_tree_add_uint(ext_tree, hf_q2931_message_action_indicator, tvb,
2057                             offset, 1, message_type_ext);
2058                 }
2059         }
2060         offset += 1;
2061
2062         message_len = tvb_get_ntohs(tvb, offset);
2063         if (q2931_tree != NULL)
2064                 proto_tree_add_uint(q2931_tree, hf_q2931_message_len, tvb, offset, 2, message_len);
2065         offset += 2;
2066
2067         /*
2068          * And now for the information elements....
2069          */
2070         codeset = 0;    /* start out in codeset 0 */
2071         non_locking_shift = TRUE;
2072         while (tvb_reported_length_remaining(tvb, offset) > 0) {
2073                 info_element = tvb_get_guint8(tvb, offset);
2074                 info_element_ext = tvb_get_guint8(tvb, offset + 1);
2075                 info_element_len = tvb_get_ntohs(tvb, offset + 2);
2076                 if (q2931_tree != NULL) {
2077                         dissect_q2931_ie(tvb, offset, info_element_len,
2078                             q2931_tree, info_element, info_element_ext);
2079                 }
2080                 if (non_locking_shift)
2081                         codeset = 0;
2082
2083                 /*
2084                  * Handle shifts.
2085                  */
2086                 switch (info_element) {
2087
2088                 case Q2931_IE_BBAND_LOCKING_SHIFT:
2089                         if (info_element_len >= 1) {
2090                                 non_locking_shift = FALSE;
2091                                 codeset = tvb_get_guint8(tvb, offset + 4) & 0x07;
2092                         }
2093                         break;
2094
2095                 case Q2931_IE_BBAND_NLOCKING_SHIFT:
2096                         if (info_element_len >= 1) {
2097                                 non_locking_shift = TRUE;
2098                                 codeset = tvb_get_guint8(tvb, offset + 4) & 0x07;
2099                         }
2100                         break;
2101                 }
2102                 offset += 1 + 1 + 2 + info_element_len;
2103         }
2104 }
2105
2106 void
2107 proto_register_q2931(void)
2108 {
2109         static hf_register_info hf[] = {
2110                 { &hf_q2931_discriminator,
2111                   { "Protocol discriminator", "q2931.disc", FT_UINT8, BASE_HEX, NULL, 0x0,
2112                         "", HFILL }},
2113
2114                 { &hf_q2931_call_ref_len,
2115                   { "Call reference value length", "q2931.call_ref_len", FT_UINT8, BASE_DEC, NULL, 0x0,
2116                         "", HFILL }},
2117
2118                 { &hf_q2931_call_ref_flag,
2119                   { "Call reference flag", "q2931.call_ref_flag", FT_BOOLEAN, BASE_NONE, TFS(&tfs_call_ref_flag), 0x0,
2120                         "", HFILL }},
2121
2122                 { &hf_q2931_call_ref,
2123                   { "Call reference value", "q2931.call_ref", FT_BYTES, BASE_HEX, NULL, 0x0,
2124                         "", HFILL }},
2125
2126                 { &hf_q2931_message_type,
2127                   { "Message type", "q2931.message_type", FT_UINT8, BASE_HEX, VALS(q2931_message_type_vals), 0x0,
2128                         "", HFILL }},
2129
2130                 { &hf_q2931_message_type_ext,
2131                   { "Message type extension", "q2931.message_type_ext", FT_UINT8, BASE_HEX, NULL, 0x0,
2132                         "", HFILL }},
2133
2134                 { &hf_q2931_message_flag,
2135                   { "Flag", "q2931.message_flag", FT_BOOLEAN, 8, TFS(&tos_msg_flag), Q2931_MSG_TYPE_EXT_FOLLOW_INST,
2136                         "", HFILL }},
2137
2138                 { &hf_q2931_message_action_indicator,
2139                   { "Action indicator", "q2931.message_action_indicator", FT_UINT8, BASE_DEC, VALS(msg_action_ind_vals), Q2931_MSG_TYPE_EXT_ACTION_IND,
2140                         "", HFILL }},
2141
2142                 { &hf_q2931_message_len,
2143                   { "Message length", "q2931.message_len", FT_UINT16, BASE_DEC, NULL, 0x0,
2144                         "", HFILL }},
2145
2146         };
2147         static gint *ett[] = {
2148                 &ett_q2931,
2149                 &ett_q2931_ext,
2150                 &ett_q2931_ie,
2151                 &ett_q2931_ie_ext,
2152                 &ett_q2931_nsap,
2153         };
2154
2155         proto_q2931 = proto_register_protocol("Q.2931", "Q.2931", "q2931");
2156         proto_register_field_array (proto_q2931, hf, array_length(hf));
2157         proto_register_subtree_array(ett, array_length(ett));
2158
2159         register_dissector("q2931", dissect_q2931, proto_q2931);
2160 }