aboutsummaryrefslogtreecommitdiffstats
path: root/packet-q933.c
blob: c36c2f27ffa8ade4193fbd0b2ccb8adb38f0be50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
/* packet-q933.c
 * Routines for Q.933 frame disassembly
 * Guy Harris <guy@alum.mit.edu>
 *
 * $Id: packet-q933.c,v 1.5 2004/02/18 10:11:51 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <glib.h>
#include <string.h>
#include <epan/packet.h>
#include <epan/strutil.h>
#include "nlpid.h"

static int proto_q933 					= -1;
static int hf_q933_discriminator			= -1;
static int hf_q933_coding_standard			= -1;
static int hf_q933_information_transfer_capability	= -1;
static int hf_q933_transfer_mode			= -1;
static int hf_q933_uil1					= -1;
static int hf_q933_call_ref_len 			= -1;
static int hf_q933_call_ref_flag 			= -1;
static int hf_q933_call_ref 				= -1;
static int hf_q933_message_type 			= -1;
static int hf_q933_cause_value 				= -1;
static int hf_q933_number_type				= -1;
static int hf_q933_numbering_plan			= -1;
static int hf_q933_extension_ind			= -1;
static int hf_q933_calling_party_number 		= -1;
static int hf_q933_called_party_number 			= -1;
static int hf_q933_connected_number 			= -1;
static int hf_q933_redirecting_number 			= -1;

static gint ett_q933 					= -1;
static gint ett_q933_ie 				= -1;

/*
 * Q.933 message types.
 */
#define	Q933_ESCAPE		0x00
#define	Q933_ALERTING		0x01
#define	Q933_CALL_PROCEEDING	0x02
#define	Q933_CONNECT		0x07
#define	Q933_CONNECT_ACK	0x0F
#define	Q933_PROGRESS		0x03
#define	Q933_SETUP		0x05
#define	Q933_DISCONNECT		0x45
#define	Q933_RELEASE		0x4D
#define	Q933_RELEASE_COMPLETE	0x5A
#define	Q933_SEGMENT		0x60
#define	Q933_STATUS		0x7D
#define	Q933_STATUS_ENQUIRY	0x75

static const value_string q933_message_type_vals[] = {
	{ Q933_ESCAPE,			"ESCAPE" },
	{ Q933_ALERTING,		"ALERTING" },
	{ Q933_CALL_PROCEEDING,		"CALL PROCEEDING" },
	{ Q933_CONNECT,			"CONNECT" },
	{ Q933_CONNECT_ACK,		"CONNECT ACKNOWLEDGE" },
	{ Q933_PROGRESS,		"PROGRESS" },
	{ Q933_SETUP,			"SETUP" },
	{ Q933_DISCONNECT,		"DISCONNECT" },
	{ Q933_RELEASE,			"RELEASE" },
	{ Q933_RELEASE_COMPLETE,	"RELEASE COMPLETE" },
	{ Q933_SEGMENT,			"SEGMENT" },
	{ Q933_STATUS,			"STATUS" },
	{ Q933_STATUS_ENQUIRY,		"STATUS ENQUIRY" },
	{ 0,				NULL }
};

static const true_false_string tfs_call_ref_flag = {
	"Message sent to originating side",
	"Message sent from originating side"
};

/*
 * Information elements.
 */

/* Shifted codeset values */
#define CS0 0x000
#define CS1 0x100
#define CS2 0x200
#define CS3 0x300
#define CS4 0x400
#define CS5 0x500
#define CS6 0x600
#define CS7 0x700

#define	Q933_IE_SO_MASK	0x80	/* single-octet/variable-length mask */
/*
 * Single-octet IEs.
 */
#define	Q933_IE_SO_IDENTIFIER_MASK	0xf0	/* IE identifier mask */
#define	Q933_IE_SO_IDENTIFIER_SHIFT	4	/* IE identifier shift */
#define	Q933_IE_SO_IE_MASK		0x0F	/* IE mask */

#define	Q933_IE_SHIFT			0x90
#define	Q933_IE_SHIFT_NON_LOCKING	0x08	/* non-locking shift */
#define	Q933_IE_SHIFT_CODESET		0x0F	/* codeset */

#define	Q933_IE_REPEAT_INDICATOR	0xD0

/*
 * Variable-length IEs.
 */
#define	Q933_IE_VL_EXTENSION		0x80	/* Extension flag */
/*	extension bit. The bit value "0" indicates that the octet continues through the		*/
/*	next octet. The bit value "1" indicates that this octet is the last octet		*/

static const true_false_string q933_extension_ind_value = {
  "last octet",
  "information continues through the next octet",

};


/*
 * Codeset 0 (default).
 */
#define	Q933_IE_SEGMENTED_MESSAGE	0x00
#define	Q933_IE_BEARER_CAPABILITY	0x04
#define	Q933_IE_CAUSE			0x08
#define	Q933_IE_CALL_STATE		0x14
#define	Q933_IE_CHANNEL_IDENTIFICATION	0x18
#define	Q933_IE_DLCI			0x19
#define	Q933_IE_PROGRESS_INDICATOR	0x1E
#define	Q933_IE_NETWORK_SPECIFIC_FACIL	0x20	/* Network Specific Facilities */
#define	Q933_IE_DISPLAY			0x28
#define	Q933_IE_E2E_TRANSIT_DELAY	0x42	/* End-to-end Transit Delay */
#define	Q933_IE_TD_SELECTION_AND_INT	0x43	/* Transit Delay Selection and Indication */
#define	Q933_IE_PL_BINARY_PARAMETERS	0x44	/* Packet layer binary parameters */
#define	Q933_IE_LL_CORE_PARAMETERS	0x48	/* Link layer core parameters */
#define	Q933_IE_LL_PROTOCOL_PARAMETERS	0x49	/* Link layer protocol parameters */
#define	Q933_IE_REVERSE_CHARGE_IND	0x4A	/* Reverse charging indication */
#define	Q933_IE_CONNECTED_NUMBER	0x4C	/* Connected Number */
#define	Q933_IE_CONNECTED_SUBADDR	0x4D	/* Connected sub-address */
#define	Q933_IE_X_213_PRIORITY		0x50	/* X.213 priority */
#define	Q933_IE_REPORT_TYPE		0x51
#define	Q933_IE_LINK_INTEGRITY_VERF	0x53	/* Link integrity verification */
#define	Q933_IE_PVC_STATUS		0x57
#define	Q933_IE_CALLING_PARTY_NUMBER	0x6C	/* Calling Party Number */
#define	Q933_IE_CALLING_PARTY_SUBADDR	0x6D	/* Calling Party Subaddress */
#define	Q933_IE_CALLED_PARTY_NUMBER	0x70	/* Called Party Number */
#define	Q933_IE_CALLED_PARTY_SUBADDR	0x71	/* Called Party Subaddress */
#define	Q933_IE_TRANSIT_NETWORK_SEL	0x78	/* Transit Network Selection */
#define	Q933_IE_LOW_LAYER_COMPAT	0x7C	/* Low-Layer Compatibility */
#define	Q933_IE_HIGH_LAYER_COMPAT	0x7D	/* High-Layer Compatibility */
#define	Q933_IE_USER_USER		0x7E	/* User-User */
#define	Q933_IE_ESCAPE			0x7F	/* Escape for extension */

/* Codeset 0 */
static const value_string q933_info_element_vals0[] = {
	{ Q933_IE_SEGMENTED_MESSAGE,		"Segmented message" },
	{ Q933_IE_BEARER_CAPABILITY,		"Bearer capability" },
	{ Q933_IE_CAUSE,			"Cause" },
	{ Q933_IE_CALL_STATE,			"Call state" },
	{ Q933_IE_CHANNEL_IDENTIFICATION,	"Channel identification" },
	{ Q933_IE_DLCI,				"Data link connection identifier" },
	{ Q933_IE_PROGRESS_INDICATOR,		"Progress indicator" },
	{ Q933_IE_NETWORK_SPECIFIC_FACIL,	"Network specific facilities" },
	{ Q933_IE_E2E_TRANSIT_DELAY,		"End-to-end transit delay" },
	{ Q933_IE_TD_SELECTION_AND_INT,		"Transit delay selection and indication" },
	{ Q933_IE_PL_BINARY_PARAMETERS,		"Packet layer binary parameters" },
	{ Q933_IE_LL_CORE_PARAMETERS,		"Link layer core parameters" },
	{ Q933_IE_LL_PROTOCOL_PARAMETERS,	"Link layer protocol parameters" },
	{ Q933_IE_REVERSE_CHARGE_IND,		"Reverse charging indication" },
	{ Q933_IE_CONNECTED_NUMBER,		"Connected number" },
	{ Q933_IE_CONNECTED_SUBADDR,		"Connected subaddress" },
	{ Q933_IE_X_213_PRIORITY,		"X.213 priority" },
	{ Q933_IE_REPORT_TYPE,			"Report type" },
	{ Q933_IE_LINK_INTEGRITY_VERF,		"Link integrity verification" },
	{ Q933_IE_PVC_STATUS,			"PVC status" },
	{ Q933_IE_CALLING_PARTY_NUMBER,		"Calling party number" },
	{ Q933_IE_CALLING_PARTY_SUBADDR,	"Calling party subaddress" },
	{ Q933_IE_CALLED_PARTY_NUMBER,		"Called party number" },
	{ Q933_IE_CALLED_PARTY_SUBADDR,		"Called party subaddress" },
	{ Q933_IE_TRANSIT_NETWORK_SEL,		"Transit network selection" },
	{ Q933_IE_LOW_LAYER_COMPAT,		"Low-layer compatibility" },
	{ Q933_IE_HIGH_LAYER_COMPAT,		"High-layer compatibility" },
	{ Q933_IE_USER_USER,			"User-user" },
	{ Q933_IE_ESCAPE,			"Escape" },
	{ 0,					NULL }
};
/* Codeset 1 */
static const value_string q933_info_element_vals1[] = {
	{ 0,					NULL }
};
/* Codeset 2 */
static const value_string q933_info_element_vals2[] = {
	{ 0,					NULL }
};
/* Codeset 3 */
static const value_string q933_info_element_vals3[] = {
	{ 0,					NULL }
};
/* Codeset 4 */
static const value_string q933_info_element_vals4[] = {
	{ 0,					NULL }
};
/* Codeset 5 */
static const value_string q933_info_element_vals5[] = {
	{ 0,					NULL }
};
/* Codeset 6 */
static const value_string q933_info_element_vals6[] = {
	{ 0,					NULL }
};
/* Codeset 7 */
static const value_string q933_info_element_vals7[] = {
	{ 0,					NULL }
};

/* Codeset array */
static const value_string *q933_info_element_vals[] = {
  q933_info_element_vals0,
  q933_info_element_vals1,
  q933_info_element_vals2,
  q933_info_element_vals3,
  q933_info_element_vals4,
  q933_info_element_vals5,
  q933_info_element_vals6,
  q933_info_element_vals7,
};

static const value_string q933_repeat_indication_vals[] = {
	{ 0x2, "Prioritized list" },
	{ 0,   NULL }
};

/*
 * ITU-standardized coding.
 */
#define	Q933_ITU_STANDARDIZED_CODING	0x00

/*
 * Dissect a Segmented message information element.
 */
static void
dissect_q933_segmented_message_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	if (len != 2) {
		proto_tree_add_text(tree, tvb, offset, len,
		    "Segmented message: length is %d, should be 2", len);
		return;
	}
	if (tvb_get_guint8(tvb, offset) & 0x80) {
		proto_tree_add_text(tree, tvb, offset, 1,
		    "First segment: %u segments remaining",
		    tvb_get_guint8(tvb, offset) & 0x7F);
	} else {
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Not first segment: %u segments remaining",
		    tvb_get_guint8(tvb, offset) & 0x7F);
	}
	proto_tree_add_text(tree, tvb, offset + 1, 1,
	    "Segmented message type: %u", tvb_get_guint8(tvb, offset + 1));
}

/*
 * Dissect a Bearer capability or Low-layer compatibility information element.
 */
static const value_string q933_coding_standard_vals[] = {
	{ 0x0, "ITU-T standardized coding" },
	{ 0x1, "ISO/IEC standard" },
	{ 0x2, "National standard" },
	{ 0x3, "Standard defined for this particular network" },
	{ 0,    NULL }
};

static const value_string q933_information_transfer_capability_vals[] = {
	{ 0x08, "Unrestricted digital information" },
	{ 0,    NULL }
};

static const value_string q933_transfer_mode_vals[] = {
	{ 0x01, "Frame mode" },
	{ 0,    NULL }
};

static const value_string q933_uil1_vals[] = {
	{ 0x01, "V.110/I.460/X.30 rate adaption" },
	{ 0x02, "Recommendation G.711 u-law" },
	{ 0x03, "Recommendation G.711 A-law" },
	{ 0x04, "Recommendation G.721 32 kbit/s ADPCM and Recommendation I.460" },
	{ 0x05, "Recommendation H.221 and H.242" },
	{ 0x06, "Recommendation H.223 and H.245" },
	{ 0x07, "Non-ITU-T-standardized rate adaption" },
	{ 0x08, "V.120 rate adaption" },
	{ 0x09, "X.31 HDLC flag stuffing" },
	{ 0,    NULL },
};

static const value_string q933_l1_user_rate_vals[] = {
	{ 0x00, "Rate indicated by E-bits" },
	{ 0x01, "0.6 kbit/s" },
	{ 0x02, "1.2 kbit/s" },
	{ 0x03, "2.4 kbit/s" },
	{ 0x04, "3.6 kbit/s" },
	{ 0x05, "4.8 kbit/s" },
	{ 0x06, "7.2 kbit/s" },
	{ 0x07, "8 kbit/s" },
	{ 0x08, "9.6 kbit/s" },
	{ 0x09, "14.4 kbit/s" },
	{ 0x0A, "16 kbit/s" },
	{ 0x0B, "19.2 kbit/s" },
	{ 0x0C, "32 kbit/s" },
	{ 0x0E, "48 kbit/s" },
	{ 0x0F, "56 kbit/s" },
	{ 0x10, "64 kbit/s "},
	{ 0x15, "0.1345 kbit/s" },
	{ 0x16, "0.100 kbit/s" },
	{ 0x17, "0.075/1.2 kbit/s" },
	{ 0x18, "1.2/0.075 kbit/s" },
	{ 0x19, "0.050 kbit/s" },
	{ 0x1A, "0.075 kbit/s" },
	{ 0x1B, "0.110 kbit/s" },
	{ 0x1C, "0.150 kbit/s" },
	{ 0x1D, "0.200 kbit/s" },
	{ 0x1E, "0.300 kbit/s" },
	{ 0x1F, "12 kbit/s" },
	{ 0,    NULL }
};

static const value_string q933_l1_stop_bits_vals[] = {
	{ 0x20, "1" },
	{ 0x40, "1.5" },
	{ 0x60, "2" },
	{ 0,    NULL }
};

static const value_string q933_l1_data_bits_vals[] = {
	{ 0x08, "5" },
	{ 0x10, "7" },
	{ 0x18, "8" },
	{ 0,    NULL }
};

static const value_string q933_l1_parity_vals[] = {
	{ 0x00, "Odd" },
	{ 0x02, "Even" },
	{ 0x03, "None" },
	{ 0x04, "Forced to 0" },
	{ 0x05, "Forced to 1" },
	{ 0,    NULL }
};

#define	Q933_UIL2_USER_SPEC	0x10

static const value_string q933_uil2_vals[] = {
	{ 0x01,			"Basic mode ISO 1745" },
	{ 0x06,			"X.25, link level" },
	{ 0x07,			"X.25 multilink" },
	{ 0x08,			"T.71 Extended LAPB" },
	{ 0x09,			"HDLC ARM" },
	{ 0x0A,			"HDLC NRM" },
	{ 0x0B,			"HDLC ABM" },
	{ 0x0C,			"ISO 8802/2 LLC" },
	{ 0x0D,			"X.75 Single Link Procedure" },
	{ 0x0E,			"Q.922" },
	{ 0x0F,			"Core aspects of Q.922" },
	{ Q933_UIL2_USER_SPEC,	"User-specified" },
	{ 0x11,			"ISO 7776 DTE-DTE operation" },
	{ 0,			NULL }
};

static const value_string q933_address_inclusion_vals[] = {
	{ 0x01,			"Address included" },
	{ 0x02,			"Encapsulation of logical control frame" },
	{ 0,			NULL }
};

static const value_string q933_mode_vals[] = {
	{ 0x20, "Normal mode" },
	{ 0x40, "Extended mode" },
	{ 0,    NULL }
};

#define	Q933_UIL3_X25_PL	0x06
#define	Q933_UIL3_ISO_8208	0x07	/* X.25-based */
#define	Q933_UIL3_X223		0x08	/* X.25-based */
#define	Q933_UIL3_TR_9577	0x0B
#define	Q933_UIL3_USER_SPEC	0x10

static const value_string q933_uil3_vals[] = {
	{ Q933_UIL3_X25_PL,	"X.25, packet layer" },
	{ Q933_UIL3_ISO_8208,	"ISO/IEC 8208" },
	{ Q933_UIL3_X223,	"X.223/ISO 8878" },
	{ 0x09,			"ISO/IEC 8473" },
	{ 0x0A,			"T.70" },
	{ Q933_UIL3_TR_9577,	"ISO/IEC TR 9577" },
	{ Q933_UIL3_USER_SPEC,	"User-specified" },
	{ 0,			NULL }
};

static void
dissect_q933_protocol_discriminator(tvbuff_t *tvb, int offset, proto_tree *tree)
{
	unsigned int discriminator = tvb_get_guint8(tvb, offset);

	if (discriminator == NLPID_Q_933) {
		proto_tree_add_uint_format(tree, hf_q933_discriminator,
			 tvb, offset, 1, discriminator,
			 "Protocol discriminator: Q.933");
	} else if (discriminator == NLPID_Q_2931) {
		proto_tree_add_uint_format(tree, hf_q933_discriminator,
			 tvb, offset, 1, discriminator,
			 "Protocol discriminator: Q.2931");
	} else if ((discriminator >= 16 && discriminator < 63)
	    || ((discriminator >= 80) && (discriminator < 254))) {
		proto_tree_add_uint_format(tree, hf_q933_discriminator,
		    tvb, offset, 1, discriminator,
		    "Protocol discriminator: Network layer or layer 3 protocol (0x%02X)",
		    discriminator);
	} else if (discriminator >= 64 && discriminator <= 79) {
		proto_tree_add_uint_format(tree, hf_q933_discriminator,
		    tvb, offset, 1, discriminator,
		    "Protocol discriminator: National use (0x%02X)",
		    discriminator);
	} else {
		proto_tree_add_uint_format(tree, hf_q933_discriminator,
		    tvb, offset, 1, discriminator,
		    "Protocol discriminator: Reserved (0x%02X)",
		    discriminator);
	}
}

void
dissect_q933_bearer_capability_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;
	guint8 coding_standard;
	guint8 modem_type;
	guint8 uil2_protocol;
	guint8 uil3_protocol;
	guint8 add_l3_info;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	coding_standard = octet & 0x60;
	if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
		/*
		 * We don't know how the bearer capability is encoded,
		 * so just dump it as data and be done with it.
		 */
		proto_tree_add_text(tree, tvb, offset,
		    len, "Data: %s",
		    tvb_bytes_to_str(tvb, offset, len));
		proto_tree_add_uint(tree, hf_q933_coding_standard, tvb, offset, 1, octet);
		proto_tree_add_boolean(tree, hf_q933_extension_ind, tvb, offset, 1, octet);
		return;
	}
	proto_tree_add_uint(tree, hf_q933_information_transfer_capability, tvb, offset, 1, octet);
	proto_tree_add_uint(tree, hf_q933_coding_standard, tvb, offset, 1, octet);
	proto_tree_add_boolean(tree, hf_q933_extension_ind, tvb, offset, 1, octet);
	offset += 1;
	len -= 1;

	/*
	 * XXX - only in Low-layer compatibility information element.
	 */
	if (!(octet & Q933_IE_VL_EXTENSION)) {
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Out-band negotiation %spossible",
		    (octet & 0x40) ? "" : "not ");
		offset += 1;
		len -= 1;
	}

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_uint(tree, hf_q933_transfer_mode, tvb, offset, 1, octet);
	proto_tree_add_boolean(tree, hf_q933_extension_ind, tvb, offset, 1, octet);
	offset += 1;
	len -= 1;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	if ((octet & 0x60) == 0x20) {
		/*
		 * Layer 1 information.
		 */
		proto_tree_add_uint(tree, hf_q933_uil1, tvb, offset, 1, octet);
		proto_tree_add_boolean(tree, hf_q933_extension_ind, tvb, offset, 1, octet);
		offset += 1;
		len -= 1;

		if (octet & Q933_IE_VL_EXTENSION)
			goto l1_done;
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Layer 1 is %s",
		    (octet & 0x40) ? "Asynchronous" : "Synchronous");
		proto_tree_add_text(tree, tvb, offset, 1,
		    "User rate: %s",
		    val_to_str(octet & 0x1F, q933_l1_user_rate_vals,
		      "Unknown (0x%02X)"));
		offset += 1;
		len -= 1;

		if (octet & Q933_IE_VL_EXTENSION)
			goto l1_done;
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Rate adaption header %sincluded",
		    (octet & 0x40) ? "" : "not ");
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Multiple frame establishment %ssupported",
		    (octet & 0x20) ? "" : "not ");
		proto_tree_add_text(tree, tvb, offset, 1,
		    "%s mode of operation",
		    (octet & 0x10) ? "Protocol sensitive" : "Bit transparent");
		offset += 1;
		len -= 1;

		if (octet & Q933_IE_VL_EXTENSION)
			goto l1_done;
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Stop bits: %s",
		      val_to_str(octet & 0x60, q933_l1_stop_bits_vals,
		       "Unknown (0x%X)"));
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Data bits: %s",
		      val_to_str(octet & 0x18, q933_l1_data_bits_vals,
		       "Unknown (0x%X)"));
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Parity: %s",
		      val_to_str(octet & 0x07, q933_l1_parity_vals,
		       "Unknown (0x%X)"));

		if (octet & Q933_IE_VL_EXTENSION)
			goto l1_done;
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "%s duplex",
		    (octet & 0x40) ? "Full" : "Half");
		modem_type = octet & 0x3F;
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Modem type: Network-specific rules 0x%02X", modem_type);
		offset += 1;
		len -= 1;
	}
l1_done:
	;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	if ((octet & 0x60) == 0x40) {
		/*
		 * Layer 2 information.
		 */
		uil2_protocol = octet & 0x1F;
		proto_tree_add_text(tree, tvb, offset, 1,
		    "User information layer 2 protocol: %s",
		    val_to_str(uil2_protocol, q933_uil2_vals,
		      "Unknown (0x%02X)"));
		offset += 1;
		len -= 1;

		/*
		 * XXX - only in Low-layer compatibility information element.
		 */
		if (octet & Q933_IE_VL_EXTENSION)
			goto l2_done;
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		if (uil2_protocol == Q933_UIL2_USER_SPEC) {
			proto_tree_add_text(tree, tvb, offset, 1,
			    "User-specified layer 2 protocol information: 0x%02X",
			    octet & 0x7F);
		} else {
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Address inclusion: %s",
			    val_to_str(octet & 0x03, q933_address_inclusion_vals,
			      "Unknown (0x%02X)"));
		}
		offset += 1;
		len -= 1;
	}
l2_done:
	;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	if ((octet & 0x60) == 0x60) {
		/*
		 * Layer 3 information.
		 */
		uil3_protocol = octet & 0x1F;
		proto_tree_add_text(tree, tvb, offset, 1,
		    "User information layer 3 protocol: %s",
		    val_to_str(uil3_protocol, q933_uil3_vals,
		      "Unknown (0x%02X)"));
		offset += 1;
		len -= 1;


		/*
		 * XXX - only in Low-layer compatibility information element.
		 */
		if (octet & Q933_IE_VL_EXTENSION)
			goto l3_done;
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		switch (uil3_protocol) {

		case Q933_UIL3_X25_PL:
		case Q933_UIL3_ISO_8208:
		case Q933_UIL3_X223:
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Mode: %s",
			    val_to_str(octet & 0x60, q933_mode_vals,
			      "Unknown (0x%02X)"));
			offset += 1;
			len -= 1;

			if (octet & Q933_IE_VL_EXTENSION)
				goto l3_done;
			if (len == 0)
				return;
			octet = tvb_get_guint8(tvb, offset);
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Default packet size: %u", octet & 0x0F);
			offset += 1;
			len -= 1;

			if (octet & Q933_IE_VL_EXTENSION)
				goto l3_done;
			if (len == 0)
				return;
			octet = tvb_get_guint8(tvb, offset);
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Packet window size: %u", octet & 0x7F);
			offset += 1;
			len -= 1;
			break;

		case Q933_UIL3_USER_SPEC:
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Default packet size: %u octets",
			    1 << (octet & 0x0F));
			offset += 1;
			len -= 1;
			break;

		case Q933_UIL3_TR_9577:
			add_l3_info = (octet & 0x0F) << 4;
			if (octet & Q933_IE_VL_EXTENSION)
				goto l3_done;
			if (len == 0)
				return;
			octet = tvb_get_guint8(tvb, offset + 1);
			add_l3_info |= (octet & 0x0F);
			proto_tree_add_text(tree, tvb, offset, 2,
			    "Additional layer 3 protocol information: %s",
			    val_to_str(add_l3_info, nlpid_vals,
			      "Unknown (0x%02X)"));
			offset += 2;
			len -= 2;
			break;
		}
	}
l3_done:
	;
}

/*
 * Dissect a Cause information element.
 */


const value_string q933_cause_location_vals[] = {
	{ 0x00, "User (U)" },
	{ 0x01, "Private network serving the local user (LPN)" },
	{ 0x02, "Public network serving the local user (LN)" },
	{ 0x03, "Transit network (TN)" },
	{ 0x04, "Public network serving the remote user (RLN)" },
	{ 0x05, "Private network serving the remote user (RPN)" },
	{ 0x07, "International network (INTL)" },
	{ 0x0A, "Network beyond interworking point (BI)" },
	{ 0,    NULL }
};

static const value_string q933_cause_recommendation_vals[] = {
	{ 0x00, "Q.933" },
	{ 0x03, "X.21" },
	{ 0x04, "X.25" },
	{ 0x05, "Q.1031/Q.1051" },
	{ 0,    NULL }
};

/*
 * Cause codes for Cause.
 */
#define	Q933_CAUSE_UNALLOC_NUMBER	0x01
#define	Q933_CAUSE_NO_ROUTE_TO_DEST	0x03
#define	Q933_CAUSE_CALL_REJECTED	0x15
#define	Q933_CAUSE_NUMBER_CHANGED	0x16
#define	Q933_CAUSE_ACCESS_INFO_DISC	0x2B
#define	Q933_CAUSE_QOS_UNAVAILABLE	0x31
#define	Q933_CAUSE_CHAN_NONEXISTENT	0x52
#define	Q933_CAUSE_INCOMPATIBLE_DEST	0x58
#define	Q933_CAUSE_MAND_IE_MISSING	0x60
#define	Q933_CAUSE_MT_NONEX_OR_UNIMPL	0x61
#define	Q933_CAUSE_IE_NONEX_OR_UNIMPL	0x63
#define	Q933_CAUSE_INVALID_IE_CONTENTS	0x64
#define	Q933_CAUSE_MSG_INCOMPAT_W_CS	0x65
#define	Q933_CAUSE_REC_TIMER_EXP	0x66

const value_string q933_cause_code_vals[] = {
	{ 0x00,				"Valid cause code not yet received" },
	{ Q933_CAUSE_UNALLOC_NUMBER,	"Unallocated (unassigned) number" },
	{ 0x02,				"No route to specified transit network" },
	{ Q933_CAUSE_NO_ROUTE_TO_DEST,	"No route to destination" },
	{ 0x04,				"Send special information tone" },
	{ 0x05,				"Misdialled trunk prefix" },
	{ 0x06,				"Channel unacceptable" },
	{ 0x07,				"Call awarded and being delivered in an established channel" },
	{ 0x08,				"Prefix 0 dialed but not allowed" },
					/* Q.850 - "Preemption" */
	{ 0x09,				"Prefix 1 dialed but not allowed" },
					/* Q.850 - "Preemption - circuit reserved for reuse" */
	{ 0x0A,				"Prefix 1 dialed but not required" },
	{ 0x0B,				"More digits received than allowed, call is proceeding" },
	{ 0x0E,				"QoR: ported number" },
	{ 0x10,				"Normal call clearing" },
	{ 0x11,				"User busy" },
	{ 0x12,				"No user responding" },
	{ 0x13,				"No answer from user (user alerted)" },
	{ 0x14,				"Subscriber absent" },
	{ Q933_CAUSE_CALL_REJECTED,	"Call rejected" },
	{ Q933_CAUSE_NUMBER_CHANGED,	"Number changed" },
	{ 0x17,				"Reverse charging rejected" },
					/* Q.850 - "Redirection to new destination" */
	{ 0x18,				"Call suspended" },
					/* Q.850 Amendment 1 - "Call rejected due to feature at the destination" */
	{ 0x19,				"Call resumed" },
					/* Q.850 - "Exchange routing error */
	{ 0x1A,				"Non-selected user clearing" },
	{ 0x1B,				"Destination out of order" },
	{ 0x1C,				"Invalid number format (incomplete number)" },
	{ 0x1D,				"Facility rejected" },
	{ 0x1E,				"Response to STATUS ENQUIRY" },
	{ 0x1F,				"Normal unspecified" },
	{ 0x21,				"Circuit out of order" },
	{ 0x22,				"No circuit/channel available" },
	{ 0x23,				"Destination unattainable" },
	{ 0x25,				"Degraded service" },
	{ 0x26,				"Network out of order" },
	{ 0x27,				"Transit delay range cannot be achieved" },
					/* Q.850 - "Permanent frame mode connection out of service" */
	{ 0x28,				"Throughput range cannot be achieved" },
					/* Q.850 - "Permanent frame mode connection operational" */
	{ 0x29,				"Temporary failure" },
	{ 0x2A,				"Switching equipment congestion" },
	{ Q933_CAUSE_ACCESS_INFO_DISC,	"Access information discarded" },
	{ 0x2C,				"Requested circuit/channel not available" },
	{ 0x2D,				"Pre-empted" },
	{ 0x2E,				"Precedence call blocked" },
	{ 0x2F,				"Resources unavailable, unspecified" },
	{ Q933_CAUSE_QOS_UNAVAILABLE,	"Quality of service unavailable" },
	{ 0x32,				"Requested facility not subscribed" },
	{ 0x33,				"Reverse charging not allowed" },
	{ 0x34,				"Outgoing calls barred" },
	{ 0x35,				"Outgoing calls barred within CUG" },
	{ 0x36,				"Incoming calls barred" },
	{ 0x37,				"Incoming calls barred within CUG" },
	{ 0x38,				"Call waiting not subscribed" },
	{ 0x39,				"Bearer capability not authorized" },
	{ 0x3A,				"Bearer capability not presently available" },
	{ 0x3E,				"Inconsistency in designated outgoing access information and subscriber class" },
	{ 0x3F,				"Service or option not available, unspecified" },
	{ 0x41,				"Bearer capability not implemented" },
	{ 0x42,				"Channel type not implemented" },
	{ 0x43,				"Transit network selection not implemented" },
	{ 0x44,				"Message not implemented" },
	{ 0x45,				"Requested facility not implemented" },
	{ 0x46,				"Only restricted digital information bearer capability is available" },
	{ 0x4F,				"Service or option not implemented, unspecified" },
	{ 0x51,				"Invalid call reference value" },
	{ Q933_CAUSE_CHAN_NONEXISTENT,	"Identified channel does not exist" },
	{ 0x53,				"Call identity does not exist for suspended call" },
	{ 0x54,				"Call identity in use" },
	{ 0x55,				"No call suspended" },
	{ 0x56,				"Call having the requested call identity has been cleared" },
	{ 0x57,				"Called user not member of CUG" },
	{ Q933_CAUSE_INCOMPATIBLE_DEST,	"Incompatible destination" },
	{ 0x59,				"Non-existent abbreviated address entry" },
	{ 0x5A,				"Destination address missing, and direct call not subscribed" },
					/* Q.850 - "Non-existent CUG" */
	{ 0x5B,				"Invalid transit network selection (national use)" },
	{ 0x5C,				"Invalid facility parameter" },
	{ 0x5D,				"Mandatory information element is missing" },
	{ 0x5F,				"Invalid message, unspecified" },
	{ Q933_CAUSE_MAND_IE_MISSING,	"Mandatory information element is missing" },
	{ Q933_CAUSE_MT_NONEX_OR_UNIMPL,"Message type non-existent or not implemented" },
	{ 0x62,				"Message not compatible with call state or message type non-existent or not implemented" },
	{ Q933_CAUSE_IE_NONEX_OR_UNIMPL,"Information element nonexistant or not implemented" },
	{ Q933_CAUSE_INVALID_IE_CONTENTS,"Invalid information element contents" },
	{ Q933_CAUSE_MSG_INCOMPAT_W_CS,	"Message not compatible with call state" },
	{ Q933_CAUSE_REC_TIMER_EXP,	"Recovery on timer expiry" },
	{ 0x67,				"Parameter non-existent or not implemented - passed on" },
	{ 0x6E,				"Message with unrecognized parameter discarded" },
	{ 0x6F,				"Protocol error, unspecified" },
	{ 0x7F,				"Internetworking, unspecified" },
	{ 0,				NULL }
};

static const value_string q933_cause_condition_vals[] = {
	{ 0x00, "Unknown" },
	{ 0x01, "Permanent" },
	{ 0x02, "Transient" },
	{ 0x00, NULL }
};

#define	Q933_REJ_USER_SPECIFIC		0x00
#define	Q933_REJ_IE_MISSING		0x04
#define	Q933_REJ_IE_INSUFFICIENT	0x08

static const value_string q933_rejection_reason_vals[] = {
	{ 0x00, "User specific" },
	{ 0x04, "Information element missing" },
	{ 0x08, "Information element contents are not sufficient" },
	{ 0x00, NULL }
};

void
dissect_q933_cause_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree, int hf_cause_value)
{
	guint8 octet;
	guint8 cause_value;
	guint8 coding_standard;
	guint8 rejection_reason;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	coding_standard = octet & 0x60;
	proto_tree_add_uint(tree, hf_q933_coding_standard, tvb, offset, 1, octet);
	if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
		/*
		 * We don't know how the cause is encoded,
		 * so just dump it as data and be done with it.
		 */
		proto_tree_add_text(tree, tvb, offset,
		    len, "Data: %s",
		    tvb_bytes_to_str(tvb, offset, len));
		return;
	}
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Location: %s",
	    val_to_str(octet & 0x0F, q933_cause_location_vals,
	      "Unknown (0x%X)"));
	proto_tree_add_boolean(tree, hf_q933_extension_ind, tvb, offset, 1, octet);
	offset += 1;
	len -= 1;

	if (!(octet & Q933_IE_VL_EXTENSION)) {
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Recommendation: %s",
		    val_to_str(octet & 0x7F, q933_cause_recommendation_vals,
		      "Unknown (0x%02X)"));
		offset += 1;
		len -= 1;
	}

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	cause_value = octet & 0x7F;
	proto_tree_add_uint(tree, hf_cause_value, tvb, offset, 1, cause_value);
	offset += 1;
	len -= 1;

	if (len == 0)
		return;
	switch (cause_value) {

	case Q933_CAUSE_UNALLOC_NUMBER:
	case Q933_CAUSE_NO_ROUTE_TO_DEST:
	case Q933_CAUSE_QOS_UNAVAILABLE:
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Network service: %s",
		    (octet & 0x80) ? "User" : "Provider");
		proto_tree_add_text(tree, tvb, offset, 1,
		    "%s",
		    (octet & 0x40) ? "Abnormal" : "Normal");
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Condition: %s",
		    val_to_str(octet & 0x03, q933_cause_condition_vals,
		      "Unknown (0x%X)"));
		break;

	case Q933_CAUSE_CALL_REJECTED:
		rejection_reason = octet & 0x7C;
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Rejection reason: %s",
		    val_to_str(octet & 0x7C, q933_rejection_reason_vals,
		      "Unknown (0x%X)"));
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Condition: %s",
		    val_to_str(octet & 0x03, q933_cause_condition_vals,
		      "Unknown (0x%X)"));
		offset += 1;
		len -= 1;

		if (len == 0)
			return;
		switch (rejection_reason) {

		case Q933_REJ_USER_SPECIFIC:
			proto_tree_add_text(tree, tvb, offset, len,
			    "User specific diagnostic: %s",
			    tvb_bytes_to_str(tvb, offset, len));
			break;

		case Q933_REJ_IE_MISSING:
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Missing information element: %s",
			    val_to_str(tvb_get_guint8(tvb, offset), q933_info_element_vals0,
			      "Unknown (0x%02X)"));
			break;

		case Q933_REJ_IE_INSUFFICIENT:
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Insufficient information element: %s",
			    val_to_str(tvb_get_guint8(tvb, offset), q933_info_element_vals0,
			      "Unknown (0x%02X)"));
			break;

		default:
			proto_tree_add_text(tree, tvb, offset, len,
			    "Diagnostic: %s",
			    tvb_bytes_to_str(tvb, offset, len));
			break;
		}
		break;

	case Q933_CAUSE_ACCESS_INFO_DISC:
	case Q933_CAUSE_INCOMPATIBLE_DEST:
	case Q933_CAUSE_MAND_IE_MISSING:
	case Q933_CAUSE_IE_NONEX_OR_UNIMPL:
	case Q933_CAUSE_INVALID_IE_CONTENTS:
		do {
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Information element: %s",
			    val_to_str(tvb_get_guint8(tvb, offset), q933_info_element_vals0,
			      "Unknown (0x%02X)"));
			offset += 1;
			len -= 1;
		} while (len != 0);
		break;

	case Q933_CAUSE_MT_NONEX_OR_UNIMPL:
	case Q933_CAUSE_MSG_INCOMPAT_W_CS:
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Message type: %s",
		    val_to_str(tvb_get_guint8(tvb, offset), q933_message_type_vals,
		      "Unknown (0x%02X)"));
		break;

	case Q933_CAUSE_REC_TIMER_EXP:
		if (len < 3)
			return;
		proto_tree_add_text(tree, tvb, offset, 3,
		    "Timer: %.3s", tvb_get_ptr(tvb, offset, 3));
		break;

	default:
		proto_tree_add_text(tree, tvb, offset, len,
		    "Diagnostics: %s",
		    tvb_bytes_to_str(tvb, offset, len));
	}
}

/*
 * Dissect a Call state information element.
 */
static const value_string q933_call_state_vals[] = {
	{ 0x00, "Null" },
	{ 0x01, "Call initiated" },
	{ 0x02, "Overlap sending" },
	{ 0x03, "Outgoing call proceeding" },
	{ 0x04, "Call delivered" },
	{ 0x06, "Call present" },
	{ 0x07, "Call received" },
	{ 0x08, "Connect request" },
	{ 0x09, "Incoming call proceeding" },
	{ 0x0A, "Active" },
	{ 0x0B, "Disconnect request" },
	{ 0x0C, "Disconnect indication" },
	{ 0x0F, "Suspend request" },
	{ 0x12, "Resume request" },
	{ 0x13, "Release request" },
	{ 0x16, "Call abort"},
	{ 0x19, "Overlap receiving" },
	{ 0x3D, "Restart request" },
	{ 0x3E, "Restart" },
	{ 0,    NULL }
};

static void
dissect_q933_call_state_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;
	guint8 coding_standard;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	coding_standard = octet & 0x60;
	proto_tree_add_uint(tree, hf_q933_coding_standard, tvb, offset, 1, octet);
	if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
		/*
		 * We don't know how the call state is encoded,
		 * so just dump it as data and be done with it.
		 */
		proto_tree_add_text(tree, tvb, offset,
		    len, "Data: %s",
		    tvb_bytes_to_str(tvb, offset, len));
		return;
	}
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Call state: %s",
	    val_to_str(octet & 0x3F, q933_call_state_vals,
	      "Unknown (0x%02X)"));
}

/*
 * Dissect a Channel identification information element.
 */
#define	Q933_INTERFACE_IDENTIFIED	0x40
#define	Q933_NOT_BASIC_CHANNEL		0x20

static const value_string q933_basic_channel_selection_vals[] = {
	{ 0x00, "No channel" },
	{ 0x01, "B1 channel" },
	{ 0x02, "B2 channel" },
	{ 0x03, "Any channel" },
	{ 0,    NULL }
};

static const value_string q933_not_basic_channel_selection_vals[] = {
	{ 0x00, "No channel" },
	{ 0x01, "Channel indicated in following octets" },
	{ 0x03, "Any channel" },
	{ 0,    NULL }
};

#define	Q933_IS_SLOT_MAP		0x10

static const value_string q933_element_type_vals[] = {
	{ 0x03, "B-channel units" },
	{ 0x06, "H0-channel units" },
	{ 0x08, "H11-channel units" },
	{ 0x09, "H12-channel units" },
	{ 0,    NULL }
};

static void
dissect_q933_channel_identification_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;
	int identifier_offset;
	int identifier_len;
	guint8 coding_standard;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Interface %s identified",
	    (octet & Q933_INTERFACE_IDENTIFIED) ? "explicitly" : "implicitly");
	proto_tree_add_text(tree, tvb, offset, 1,
	    "%s interface",
	    (octet & Q933_NOT_BASIC_CHANNEL) ? "Not basic" : "Basic");
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Indicated channel is %s",
	    (octet & 0x08) ? "required" : "preferred");
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Indicated channel is %sthe D-channel",
	    (octet & 0x04) ? "" : "not ");
	if (octet & Q933_NOT_BASIC_CHANNEL) {
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Channel selection: %s",
		    val_to_str(octet & 0x03, q933_not_basic_channel_selection_vals,
		      "Unknown (0x%X)"));
	} else {
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Channel selection: %s",
		    val_to_str(octet & 0x03, q933_basic_channel_selection_vals,
		      NULL));
	}
	offset += 1;
	len -= 1;

	if (octet & Q933_INTERFACE_IDENTIFIED) {
		identifier_offset = offset;
		identifier_len = 0;
		do {
			if (len == 0)
				break;
			octet = tvb_get_guint8(tvb, offset);
			offset += 1;
			len -= 1;
			identifier_len++;
		} while (!(octet & Q933_IE_VL_EXTENSION));

		/*
		 * XXX - do we want to strip off the 8th bit on the
		 * last octet of the interface identifier?
		 */
		if (identifier_len != 0) {
			proto_tree_add_text(tree, tvb, identifier_offset,
			    identifier_len, "Interface identifier: %s",
			    bytes_to_str(
			      tvb_get_ptr(tvb, identifier_offset, identifier_len),
			      identifier_len));
		}
	}

	if (octet & Q933_NOT_BASIC_CHANNEL) {
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		coding_standard = octet & 0x60;
		proto_tree_add_uint(tree, hf_q933_coding_standard, tvb, offset, 1, octet);
		if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
			/*
			 * We don't know how the channel identifier is
			 * encoded, so just dump it as data and be done
			 * with it.
			 */
			proto_tree_add_text(tree, tvb, offset,
			    len, "Data: %s",
			    tvb_bytes_to_str(tvb, offset, len));
			return;
		}
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Channel is indicated by %s",
		    (octet & Q933_IS_SLOT_MAP) ? "slot map" : "number");
		proto_tree_add_text(tree, tvb, offset, 1,
		    "%s type: %s",
		    (octet & Q933_IS_SLOT_MAP) ? "Map element" : "Channel",
		    val_to_str(octet & 0x0F, q933_element_type_vals,
		        "Unknown (0x%02X)"));

		/*
		 * XXX - dump the channel number or slot map.
		 */
	}
}

/*
 * Dissect a Progress indicator information element.
 */
static const value_string q933_progress_description_vals[] = {
	{ 0x01, "Call is not end-to-end ISDN - progress information available in-band" },
	{ 0x02, "Destination address is non-ISDN" },
	{ 0x03, "Origination address is non-ISDN" },
	{ 0x04, "Call has returned to the ISDN" },
	{ 0x05, "Interworking has occurred and has resulted in a telecommunications service change" },
	{ 0x08, "In-band information or an appropriate pattern is now available" },
	{ 0,    NULL }
};

void
dissect_q933_progress_indicator_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;
	guint8 coding_standard;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	coding_standard = octet & 0x60;
	proto_tree_add_uint(tree, hf_q933_coding_standard, tvb, offset, 1, octet);
	if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
		/*
		 * We don't know how the progress indicator is encoded,
		 * so just dump it as data and be done with it.
		 */
		proto_tree_add_text(tree, tvb, offset,
		    len, "Data: %s",
		    tvb_bytes_to_str(tvb, offset, len));
		return;
	}
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Location: %s",
	    val_to_str(octet & 0x0F, q933_cause_location_vals,
	      "Unknown (0x%X)"));
	offset += 1;
	len -= 1;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Progress description: %s",
	    val_to_str(octet & 0x7F, q933_progress_description_vals,
	      "Unknown (0x%02X)"));
}

/*
 * Dissect a Network-specific facilities or Transit network selection
 * information element.
 */
static const value_string q933_netid_type_vals[] = {
	{ 0x00, "User specified" },
	{ 0x20, "National network identification" },
	{ 0x30, "International network identification" },
	{ 0,    NULL }
};

static const value_string q933_netid_plan_vals[] = {
	{ 0x00, "Unknown" },
	{ 0x01, "Carrier Identification Code" },
	{ 0x03, "X.121 data network identification code" },
	{ 0,    NULL }
};

static void
dissect_q933_ns_facilities_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;
	int netid_len;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	netid_len = octet & 0x7F;
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Network identification length: %u",
	    netid_len);
	offset += 1;
	len -= 1;
	if (netid_len != 0) {
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Type of network identification: %s",
		    val_to_str(octet & 0x70, q933_netid_type_vals,
		      "Unknown (0x%02X)"));
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Network identification plan: %s",
		    val_to_str(octet & 0x0F, q933_netid_plan_vals,
		      "Unknown (0x%02X)"));
		offset += 1;
		len -= 1;
		netid_len--;

		if (len == 0)
			return;
		if (netid_len > len)
			netid_len = len;
		if (netid_len != 0) {
			proto_tree_add_text(tree, tvb, offset, netid_len,
			    "Network identification: %s",
			    tvb_format_text(tvb, offset, netid_len));
			offset += netid_len;
			len -= netid_len;
		}
	}

	/*
	 * Whatever is left is the network-specific facility
	 * specification.
	 */
	 if (len == 0)
	 	return;
	proto_tree_add_text(tree, tvb, offset,
	    len, "Network-specific facility specification: %s",
	    tvb_bytes_to_str(tvb, offset, len));
}

static int
dissect_q933_guint16_value(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree, char *label)
{
	guint8 octet;
	guint16 value;
	int value_len;

	value_len = 0;

	octet = tvb_get_guint8(tvb, offset);
	if (octet & Q933_IE_VL_EXTENSION) {
		/*
		 * Only one octet long - error.
		 */
		goto bad_length;
	}
	value = (octet & 0x3) << 14;
	offset += 1;
	len -= 1;
	value_len++;

	if (len == 0) {
		/*
		 * We've reached the end of the information element - error.
		 */
		goto past_end;
	}
	octet = tvb_get_guint8(tvb, offset);
	if (octet & Q933_IE_VL_EXTENSION) {
		/*
		 * Only two octets long - error.
		 */
		goto bad_length;
	}
	value |= (octet & 0x7F) << 7;
	offset += 1;
	len -= 1;
	value_len++;

	if (len == 0) {
		/*
		 * We've reached the end of the information element - error.
		 */
		goto past_end;
	}
	octet = tvb_get_guint8(tvb, offset);
	if (!(octet & Q933_IE_VL_EXTENSION)) {
		/*
		 * More than three octets long - error.
		 */
		goto bad_length;
	}
	value |= (octet & 0x7F);
	offset += 1;
	len -= 1;
	value_len++;

	proto_tree_add_text(tree, tvb, offset, value_len, "%s: %u ms", label,
	    value);
	return value_len;

past_end:
	proto_tree_add_text(tree, tvb, offset, len,
	    "%s goes past end of information element", label);
	return -1;

bad_length:
	proto_tree_add_text(tree, tvb, offset, len, "%s isn't 3 octets long",
	    label);
	return -1;
}

/*
 * Dissect an End-to-end transit delay information element.
 */
static void
dissect_q933_e2e_transit_delay_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	int value_len;

	if (len == 0)
		return;
	value_len = dissect_q933_guint16_value(tvb, offset, len, tree,
	    "Cumulative transit delay");
	if (value_len < 0)
		return;	/* error */
	offset += value_len;
	len -= value_len;

	if (len == 0)
		return;
	value_len = dissect_q933_guint16_value(tvb, offset, len, tree,
	    "Requested end-to-end transit delay");
	if (value_len < 0)
		return;	/* error */
	offset += value_len;
	len -= value_len;

	if (len == 0)
		return;
	value_len = dissect_q933_guint16_value(tvb, offset, len, tree,
	    "Maximum end-to-end transit delay");
}

/*
 * Dissect a Transit delay selection and indication information element.
 */
static void
dissect_q933_td_selection_and_int_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	if (len == 0)
		return;
	dissect_q933_guint16_value(tvb, offset, len, tree,
	    "Transit delay");
}

static void
dissect_q933_pl_binary_parameters_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_text(tree, tvb, offset, 1,
	    "%s",
	    (octet & 0x04) ? "No request/request denied" :
	    		     "Request indicated/request accepted");
	proto_tree_add_text(tree, tvb, offset, 1,
	    "%s confirmation",
	    (octet & 0x02) ? "Link-by-link" : "End-to-end");
}

/*
 * Dissect a Reverse charging indication information element.
 */
static const value_string q933_reverse_charging_indication_vals[] = {
	{ 0x01, "Reverse charging requested" },
	{ 0,    NULL }
};

static void
dissect_q933_reverse_charge_ind_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	if (len == 0)
		return;
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Reverse charging indication: %s",
	    val_to_str(tvb_get_guint8(tvb, offset) & 0x07,
	      q933_reverse_charging_indication_vals, "Unknown (0x%02X)"));
}

/*
 * Dissect a (phone) number information element.
 */
static const value_string q933_number_type_vals[] = {
	{ 0x0, "Unknown" },
	{ 0x1, "International number" },
	{ 0x2, "National number" },
	{ 0x3, "Network specific number" },
	{ 0x4, "Subscriber number" },
	{ 0x6, "Abbreviated number" },
	{ 0,    NULL }
};

static const value_string q933_numbering_plan_vals[] = {
	{ 0x00, "Unknown" },
	{ 0x01, "E.164 ISDN/telephony numbering" },
	{ 0x03, "X.121 data numbering" },
	{ 0x04, "F.69 Telex numbering" },
	{ 0x08, "National standard numbering" },
	{ 0x09, "Private numbering" },
	{ 0,    NULL }
};

static const value_string q933_presentation_indicator_vals[] = {
	{ 0x00, "Presentation allowed" },
	{ 0x20, "Presentation restricted" },
	{ 0x40, "Number not available due to interworking" },
	{ 0,    NULL }
};

static const value_string q933_screening_indicator_vals[] = {
	{ 0x00, "User-provided, not screened" },
	{ 0x01, "User-provided, verified and passed" },
	{ 0x02, "User-provided, verified and failed" },
	{ 0x03, "Network-provided" },
	{ 0,    NULL }
};

static const value_string q933_redirection_reason_vals[] = {
	{ 0x00, "Unknown" },
	{ 0x01, "Call forwarding busy or called DTE busy" },
	{ 0x02, "Call forwarding no reply" },
	{ 0x04, "Call deflection" },
	{ 0x09, "Called DTE out of order" },
	{ 0x0A, "Call forwarding by the called DTE" },
	{ 0x0F, "Call forwarding unconditional or systematic call redirection" },
	{ 0,    NULL }
};

static void
dissect_q933_number_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree, int hfindex)
{
	guint8 octet;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_uint(tree, hf_q933_numbering_plan, tvb, offset, 1, octet);
	proto_tree_add_uint(tree, hf_q933_number_type, tvb, offset, 1, octet);
	proto_tree_add_boolean(tree, hf_q933_extension_ind, tvb, offset, 1, octet);
	
	offset += 1;
	len -= 1;

	if (!(octet & Q933_IE_VL_EXTENSION)) {
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Presentation indicator: %s",
		    val_to_str(octet & 0x60, q933_presentation_indicator_vals,
		      "Unknown (0x%X)"));
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Screening indicator: %s",
		    val_to_str(octet & 0x03, q933_screening_indicator_vals,
		      "Unknown (0x%X)"));
		offset += 1;
		len -= 1;
	}

	/*
	 * XXX - only in a Redirecting number information element.
	 */
	if (!(octet & Q933_IE_VL_EXTENSION)) {
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		proto_tree_add_text(tree, tvb, offset, 1,
		    "Reason for redirection: %s",
		    val_to_str(octet & 0x0F, q933_redirection_reason_vals,
		      "Unknown (0x%X)"));
		offset += 1;
		len -= 1;
	}

	if (len == 0)
		return;
	proto_tree_add_item(tree, hfindex, tvb, offset, len, FALSE);
}

/*
 * Dissect a party subaddress information element.
 */
static const value_string q933_subaddress_type_vals[] = {
	{ 0x00, "X.213/ISO 8348 Add.2 NSAP" },
	{ 0x20, "User-specified" },
	{ 0,    NULL }
};

static const value_string q933_odd_even_indicator_vals[] = {
	{ 0x00, "Even number of address signals" },
	{ 0x10, "Odd number of address signals" },
	{ 0,    NULL }
};

static void
dissect_q933_party_subaddr_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Type of subaddress: %s",
	    val_to_str(octet & 0x70, q933_subaddress_type_vals,
	      "Unknown (0x%02X)"));
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Odd/even indicator: %s",
	    val_to_str(octet & 0x10, q933_odd_even_indicator_vals,
	      NULL));
	offset += 1;
	len -= 1;

	if (len == 0)
		return;
	proto_tree_add_text(tree, tvb, offset, len, "Subaddress: %s",
	    tvb_bytes_to_str(tvb, offset, len));
}

/*
 * Dissect a High-layer compatibility information element.
 */
#define	Q933_AUDIOVISUAL	0x60
static const value_string q933_high_layer_characteristics_vals[] = {
	{ 0x01,             "Telephony" },
	{ 0x04,             "F.182 Facsimile Group 2/3" },
	{ 0x21,             "F.184 Facsimile Group 4 Class I" },
	{ 0x24,             "F.230 Teletex, basic and mixed mode, and F.184 Facsimile Group 4, Classes II and III" },
	{ 0x28,             "F.220 Teletex, basic and processable mode" },
	{ 0x31,             "F.200 Teletex, basic mode" },
	{ 0x32,             "F.300 and T.102 syntax-based Videotex" },
	{ 0x33,             "F.300 and T.101 international Videotex interworking" },
	{ 0x35,             "F.60 Telex" },
	{ 0x38,             "X.400 Message Handling Systems" },
	{ 0x41,             "X.200 OSI application" },
	{ 0x42,             "FTAM application" },
	{ 0x5E,             "Reserved for maintenance" },
	{ 0x5F,             "Reserved for management" },
	{ Q933_AUDIOVISUAL, "F.720/F.821 and F.731 Profile 1a videotelephony" },
	{ 0x61,             "F.702 and F.731 Profile 1b videoconferencing" },
	{ 0x62,             "F.702 and F.731 audiographic conferencing" },
	{ 0,                NULL }
};

static const value_string q933_audiovisual_characteristics_vals[] = {
	{ 0x01, "Capability set of initial channel of H.221" },
	{ 0x02, "Capability set of subsequent channel of H.221" },
	{ 0x21, "Capability set of initial channel of an active 3.1kHz audio or speech call" },
	{ 0x00, NULL }
};

void
dissect_q933_high_layer_compat_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;
	guint8 coding_standard;
	guint8 characteristics;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	coding_standard = octet & 0x60;
	proto_tree_add_uint(tree, hf_q933_coding_standard, tvb, offset, 1, octet);
	offset += 1;
	len -= 1;
	if (coding_standard != Q933_ITU_STANDARDIZED_CODING) {
		/*
		 * We don't know how the call state is encoded,
		 * so just dump it as data and be done with it.
		 */
		proto_tree_add_text(tree, tvb, offset,
		    len, "Data: %s",
		    tvb_bytes_to_str(tvb, offset, len));
		return;
	}

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	characteristics = octet & 0x7F;
	proto_tree_add_text(tree, tvb, offset, 1,
	    "High layer characteristics identification: %s",
	    val_to_str(characteristics, q933_high_layer_characteristics_vals,
	     "Unknown (0x%02X)"));
	offset += 1;
	len -= 1;

	if (!(octet & Q933_IE_VL_EXTENSION)) {
		if (len == 0)
			return;
		octet = tvb_get_guint8(tvb, offset);
		if (characteristics == Q933_AUDIOVISUAL) {
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Extended audiovisual characteristics identification: %s",
			    val_to_str(octet & 0x7F,
			      q933_audiovisual_characteristics_vals,
			      "Unknown (0x%02X)"));
		} else {
			proto_tree_add_text(tree, tvb, offset, 1,
			    "Extended high layer characteristics identification: %s",
			    val_to_str(octet & 0x7F,
			      q933_high_layer_characteristics_vals,
			      "Unknown (0x%02X)"));
		}
	}
}


/*
 * Dissect a User-user information element.
 */
#define	Q933_PROTOCOL_DISCRIMINATOR_IA5		0x04
#define Q933_PROTOCOL_DISCRIMINATOR_ASN1	0x05

static const value_string q933_protocol_discriminator_vals[] = {
	{ 0x00,					"User-specific protocol" },
	{ 0x01,					"OSI high layer protocols" },
	{ 0x02,					"X.244" },
	{ Q933_PROTOCOL_DISCRIMINATOR_IA5,	"IA5 characters" },
	{ Q933_PROTOCOL_DISCRIMINATOR_ASN1,	"X.208 and X.209 coded user information" },
	{ 0x07,					"V.120 rate adaption" },
	{ 0x08,					"Q.933/I.451 user-network call control messages" },
	{ 0,					NULL }
};

void
dissect_q933_user_user_ie(tvbuff_t *tvb, int offset, int len,
    proto_tree *tree)
{
	guint8 octet;

	if (len == 0)
		return;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_text(tree, tvb, offset, 1,
	    "Protocol discriminator: %s",
	    val_to_str(octet, q933_protocol_discriminator_vals,
	    "Unknown (0x%02x)"));
	offset += 1;
	len -= 1;

	if (len == 0)
		return;
	switch (octet) {

	case Q933_PROTOCOL_DISCRIMINATOR_IA5:
		proto_tree_add_text(tree, tvb, offset, len, "User information: %s",
		    tvb_format_text(tvb, offset, len));
		break;

	default:
		proto_tree_add_text(tree, tvb, offset, len, "User information: %s",
		    tvb_bytes_to_str(tvb, offset, len));
		break;
	}
}

/*
 * Dissect information elements consisting of ASCII^H^H^H^H^HIA5 text.
 */
static void
dissect_q933_ia5_ie(tvbuff_t *tvb, int offset, int len, proto_tree *tree,
    char *label)
{
	if (len != 0) {
		proto_tree_add_text(tree, tvb, offset, len, "%s: %s", label,
		    tvb_format_text(tvb, offset, len));
	}
}

static const value_string q933_codeset_vals[] = {
	{ 0x00, "Q.933 information elements" },
	{ 0x04, "Information elements for ISO/IEC use" },
	{ 0x05, "Information elements for national use" },
	{ 0x06, "Information elements specific to the local network" },
	{ 0x07, "User-specific information elements" },
	{ 0x00, NULL },
};

static void
dissect_q933(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	int		offset = 0;
	proto_tree	*q933_tree = NULL;
	proto_item	*ti;
	proto_tree	*ie_tree = NULL;
	guint8		call_ref_len;
	guint8		call_ref[15];
	guint8		message_type;
	guint8		info_element;
	guint16		info_element_len;
	int		codeset, locked_codeset;
	gboolean	non_locking_shift;

	if (check_col(pinfo->cinfo, COL_PROTOCOL))
		col_set_str(pinfo->cinfo, COL_PROTOCOL, "Q.933");

	if (tree) {
		ti = proto_tree_add_item(tree, proto_q933, tvb, offset, -1,
		    FALSE);
		q933_tree = proto_item_add_subtree(ti, ett_q933);

		dissect_q933_protocol_discriminator(tvb, offset, q933_tree);
	}
	offset += 1;
	call_ref_len = tvb_get_guint8(tvb, offset) & 0xF;	/* XXX - do as a bit field? */
	if (q933_tree != NULL)
		proto_tree_add_uint(q933_tree, hf_q933_call_ref_len, tvb, offset, 1, call_ref_len);
	offset += 1;
	if (call_ref_len != 0) {
		tvb_memcpy(tvb, call_ref, offset, call_ref_len);
		if (q933_tree != NULL) {
			proto_tree_add_boolean(q933_tree, hf_q933_call_ref_flag,
			    tvb, offset, 1, (call_ref[0] & 0x80) != 0);
			call_ref[0] &= 0x7F;
			proto_tree_add_bytes(q933_tree, hf_q933_call_ref,
			    tvb, offset, call_ref_len, call_ref);
		}
		offset += call_ref_len;
	}
	message_type = tvb_get_guint8(tvb, offset);
	if (check_col(pinfo->cinfo, COL_INFO)) {
		col_add_str(pinfo->cinfo, COL_INFO,
		    val_to_str(message_type, q933_message_type_vals,
		      "Unknown message type (0x%02X)"));
	}
	if (q933_tree != NULL)
		proto_tree_add_uint(q933_tree, hf_q933_message_type, tvb, offset, 1, message_type);
	offset += 1;

	/*
	 * And now for the information elements....
	 */
	codeset = locked_codeset = 0;	/* start out in codeset 0 */
	non_locking_shift = TRUE;
	while (tvb_reported_length_remaining(tvb, offset) > 0) {
		info_element = tvb_get_guint8(tvb, offset);

		 /* Check for the codeset shift */
		if ((info_element & Q933_IE_SO_MASK) &&
		    ((info_element & Q933_IE_SO_IDENTIFIER_MASK) == Q933_IE_SHIFT)) {
			non_locking_shift = info_element & Q933_IE_SHIFT_NON_LOCKING;
			codeset = info_element & Q933_IE_SHIFT_CODESET;
			if (!non_locking_shift)
				locked_codeset = codeset;
			if (q933_tree != NULL) {
				proto_tree_add_text(q933_tree, tvb, offset, 1,
				    "%s shift to codeset %u: %s",
				    (non_locking_shift ? "Non-locking" : "Locking"),
				    codeset,
				    val_to_str(codeset, q933_codeset_vals,
				      "Unknown (0x%02X)"));
			}
			offset += 1;
			continue;
		}

		/*
		 * Check for the single-octet IEs.
		 */
		if (info_element & Q933_IE_SO_MASK) {
			switch ((codeset << 8) | (info_element & Q933_IE_SO_IDENTIFIER_MASK)) {

			case CS0 | Q933_IE_REPEAT_INDICATOR:
				if (q933_tree != NULL) {
					proto_tree_add_text(q933_tree, tvb, offset, 1,
					    "Repeat indicator: %s",
					    val_to_str(info_element & Q933_IE_SO_IE_MASK,
				    	  q933_repeat_indication_vals,
					      "Unknown (0x%X)"));
				}
				break;

			default:
				if (q933_tree != NULL) {
					proto_tree_add_text(q933_tree, tvb, offset, 1,
					    "Unknown information element (0x%02X)",
					    info_element);
				}
				break;
			}
			offset += 1;
			codeset = locked_codeset;
			continue;
		}

		/*
		 * Variable-length IE.
		 */
		info_element_len = tvb_get_guint8(tvb, offset + 1);
		if (q933_tree != NULL) {
			ti = proto_tree_add_text(q933_tree, tvb, offset,
			    1+1+info_element_len, "%s",
			    val_to_str(info_element, q933_info_element_vals[codeset],
			      "Unknown information element (0x%02X)"));
				ie_tree = proto_item_add_subtree(ti, ett_q933_ie);
			proto_tree_add_text(ie_tree, tvb, offset, 1,
			    "Information element: %s",
			    val_to_str(info_element, q933_info_element_vals[codeset],
			      "Unknown (0x%02X)"));
			proto_tree_add_text(ie_tree, tvb, offset + 1, 1,
			    "Length: %u", info_element_len);

			switch ((codeset << 8) | info_element) {

			case CS0 | Q933_IE_SEGMENTED_MESSAGE:
				dissect_q933_segmented_message_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_BEARER_CAPABILITY:
			case CS0 | Q933_IE_LOW_LAYER_COMPAT:
				dissect_q933_bearer_capability_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_CAUSE:
				dissect_q933_cause_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree,
				    hf_q933_cause_value);
				break;

			case CS0 | Q933_IE_CALL_STATE:
				dissect_q933_call_state_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_CHANNEL_IDENTIFICATION:
				dissect_q933_channel_identification_ie(
				    tvb, offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_PROGRESS_INDICATOR:
				dissect_q933_progress_indicator_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_NETWORK_SPECIFIC_FACIL:
			case CS0 | Q933_IE_TRANSIT_NETWORK_SEL:
				dissect_q933_ns_facilities_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_DISPLAY:
				dissect_q933_ia5_ie(tvb, offset + 2,
				    info_element_len, ie_tree,
				    "Display information");
				break;

			case CS0 | Q933_IE_E2E_TRANSIT_DELAY:
				dissect_q933_e2e_transit_delay_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_TD_SELECTION_AND_INT:
				dissect_q933_td_selection_and_int_ie(
				    tvb, offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_PL_BINARY_PARAMETERS:
				dissect_q933_pl_binary_parameters_ie(
				    tvb, offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_REVERSE_CHARGE_IND:
				dissect_q933_reverse_charge_ind_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_CALLING_PARTY_NUMBER:
				dissect_q933_number_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree,
				    hf_q933_calling_party_number);
				break;

			case CS0 | Q933_IE_CONNECTED_NUMBER:
				dissect_q933_number_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree,
				    hf_q933_connected_number);
				break;

			case CS0 | Q933_IE_CALLED_PARTY_NUMBER:
				dissect_q933_number_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree,
				    hf_q933_called_party_number);
				break;

			case CS0 | Q933_IE_CALLING_PARTY_SUBADDR:
			case CS0 | Q933_IE_CALLED_PARTY_SUBADDR:
				dissect_q933_party_subaddr_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_HIGH_LAYER_COMPAT:
				dissect_q933_high_layer_compat_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			case CS0 | Q933_IE_USER_USER:
				dissect_q933_user_user_ie(tvb,
				    offset + 2, info_element_len,
				    ie_tree);
				break;

			default:
				proto_tree_add_text(ie_tree, tvb,
				    offset + 2, info_element_len,
				    "Data: %s",
				    bytes_to_str(
				      tvb_get_ptr(tvb, offset + 2,
				          info_element_len),
					  info_element_len));
				break;
			}
		}
		offset += 1 + 1 + info_element_len;
		codeset = locked_codeset;
	}
}

void
proto_register_q933(void)
{
	static hf_register_info hf[] = {
		{ &hf_q933_discriminator,
		  { "Protocol discriminator", "q933.disc", FT_UINT8, BASE_HEX, NULL, 0x0,
			"", HFILL }},

		{ &hf_q933_call_ref_flag,
		  { "Call reference flag", "q933.call_ref_flag", FT_BOOLEAN, BASE_NONE, TFS(&tfs_call_ref_flag), 0x0,
			"", HFILL }},

		{ &hf_q933_call_ref,
		  { "Call reference value", "q933.call_ref", FT_BYTES, BASE_HEX, NULL, 0x0,
			"", HFILL }},


		{ &hf_q933_coding_standard,
		  { "Coding standard", "q933.coding_standard", FT_UINT8, BASE_HEX,
			 VALS(q933_coding_standard_vals), 0x60,"", HFILL }},

		{ &hf_q933_information_transfer_capability,
		  { "Information transfer capability", "q933.information_transfer_capability", FT_UINT8, BASE_HEX,
			 VALS(q933_information_transfer_capability_vals), 0x1f,"", HFILL }},

		{ &hf_q933_transfer_mode,
		  { "Transfer mode", "q933.transfer_mode", FT_UINT8, BASE_HEX,
			 VALS(q933_transfer_mode_vals), 0x60,"", HFILL }},

		{ &hf_q933_uil1,
		  { "User information layer 1 protocol", "q933.uil1", FT_UINT8, BASE_HEX,
			 VALS(q933_uil1_vals), 0x1f,"", HFILL }},

		{ &hf_q933_call_ref_len,
		  { "Call reference value length", "q933.call_ref_len", FT_UINT8, BASE_DEC, NULL, 0x0,
			"", HFILL }},

		{ &hf_q933_message_type,
		  { "Message type", "q933.message_type", FT_UINT8, BASE_HEX, VALS(q933_message_type_vals), 0x0,
			"", HFILL }},

		{ &hf_q933_cause_value,
		  { "Cause value", "q933.cause_value", FT_UINT8, BASE_DEC, VALS(q933_cause_code_vals), 0x0,
			"", HFILL }},

		{ &hf_q933_number_type,
		  { "Number type", "q933.number_type", FT_UINT8, BASE_HEX, VALS(q933_number_type_vals), 0x70,
			"", HFILL }},

		{ &hf_q933_numbering_plan,
		  { "numbering plan", "q933.numbering_plan", FT_UINT8, BASE_HEX, VALS(q933_numbering_plan_vals), 0x0f,
			"", HFILL }},

		{ &hf_q933_extension_ind,
		  { "Extension indicator",  "q933.extension_ind",
			FT_BOOLEAN, 8, TFS(&q933_extension_ind_value), 0x80,
			"", HFILL }},

		{ &hf_q933_calling_party_number,
		  { "Calling party number digits", "q933.calling_party_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
			"", HFILL }},

		{ &hf_q933_called_party_number,
		  { "Called party number digits", "q933.called_party_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
			"", HFILL }},

		{ &hf_q933_connected_number,
		  { "Connected party number digits", "q933.connected_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
			"", HFILL }},

		{ &hf_q933_redirecting_number,
		  { "Redirecting party number digits", "q933.redirecting_number.digits", FT_STRING, BASE_NONE, NULL, 0x0,
			"", HFILL }},
	};
	static gint *ett[] = {
		&ett_q933,
		&ett_q933_ie,
	};

	proto_q933 = proto_register_protocol("Q.933", "Q.933", "q933");
	proto_register_field_array (proto_q933, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));

	register_dissector("q933", dissect_q933, proto_q933);
}

void
proto_reg_handoff_q933(void)
{
	dissector_handle_t q933_handle;

	q933_handle = create_dissector_handle(dissect_q933, proto_q933);
	dissector_add("fr.osinl", NLPID_Q_933, q933_handle);
}