aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ppp.c
blob: b30ad047849f1d9d5416950f4f65010a02877d12 (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
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
/* packet-ppp.c
 * Routines for ppp packet disassembly
 * RFC 1661, RFC 1662
 *
 * $Id$
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 *
 * This file created and by Mike Hall <mlh@io.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 <string.h>
#include <glib.h>
#include <epan/prefs.h>
#include <epan/packet.h>
#include "packet-ppp.h"
#include "ppptypes.h"
#include "etypes.h"
#include "ip_opts.h"
#include <epan/atalk-utils.h>
#include "packet-chdlc.h"
#include "packet-ip.h"
#include "packet-ipx.h"
#include "packet-vines.h"
#include "nlpid.h"
#include <epan/crc16.h>
#include <epan/crc32.h>

#define ppp_min(a, b)  ((a<b) ? a : b)

static int proto_ppp = -1;
static int hf_ppp_address = -1;
static int hf_ppp_control = -1;
static int hf_ppp_protocol = -1;

static gint ett_ppp = -1;

static int proto_ppp_hdlc = -1;

static gint ett_ppp_hdlc_data = -1;

static int proto_lcp = -1;

static gint ett_lcp = -1;
static gint ett_lcp_options = -1;
static gint ett_lcp_authprot_opt = -1;
static gint ett_lcp_qualprot_opt = -1;
static gint ett_lcp_fcs_alternatives_opt = -1;
static gint ett_lcp_numbered_mode_opt = -1;
static gint ett_lcp_callback_opt = -1;
static gint ett_lcp_multilink_ep_disc_opt = -1;
static gint ett_lcp_internationalization_opt = -1;

static int proto_ipcp = -1;

static gint ett_ipcp = -1;
static gint ett_ipcp_options = -1;
static gint ett_ipcp_ipaddrs_opt = -1;
static gint ett_ipcp_compress_opt = -1;
static gint ett_ipcp_iphc_disableprot_opt = -1;

static int proto_osicp = -1;

static gint ett_osicp = -1;
static gint ett_osicp_options = -1;
static gint ett_osicp_align_npdu_opt = -1;

static int proto_ccp = -1;

static gint ett_ccp = -1;
static gint ett_ccp_options = -1;
static gint ett_ccp_stac_opt = -1;
static gint ett_ccp_mppc_opt = -1;
static gint ett_ccp_bsdcomp_opt = -1;
static gint ett_ccp_lzsdcp_opt = -1;
static gint ett_ccp_mvrca_opt = -1;
static gint ett_ccp_deflate_opt = -1;

static int proto_cbcp = -1;

static gint ett_cbcp = -1;
static gint ett_cbcp_options = -1;
static gint ett_cbcp_callback_opt = -1;
static gint ett_cbcp_callback_opt_addr = -1;

static int proto_bacp = -1;

static gint ett_bacp = -1;
static gint ett_bacp_options = -1;
static gint ett_bacp_favored_peer_opt = -1;

static int proto_bap = -1;

static gint ett_bap = -1;
static gint ett_bap_options = -1;
static gint ett_bap_link_type_opt = -1;
static gint ett_bap_phone_delta_opt = -1;
static gint ett_bap_phone_delta_subopt = -1;
static gint ett_bap_call_status_opt = -1;

static int proto_comp_data = -1;

static gint ett_comp_data = -1;

static int proto_pppmuxcp = -1;

static gint ett_pppmuxcp = -1;
static gint ett_pppmuxcp_options = -1;

static int proto_pppmux = -1;

static gint ett_pppmux = -1;
static gint ett_pppmux_subframe = -1;
static gint ett_pppmux_subframe_hdr = -1;
static gint ett_pppmux_subframe_flags = -1;
static gint ett_pppmux_subframe_info = -1;

static int proto_mp = -1;
static int hf_mp_frag_first = -1;
static int hf_mp_frag_last = -1;
static int hf_mp_sequence_num = -1;

static int ett_mp = -1;
static int ett_mp_flags = -1;

static int proto_mplscp = -1;
static gint ett_mplscp = -1;
static gint ett_mplscp_options = -1;

static int proto_cdpcp = -1;
static gint ett_cdpcp = -1;
static gint ett_cdpcp_options = -1;

static int proto_pap			= -1;		/* PAP vars */
static gint ett_pap			= -1;
static gint ett_pap_data		= -1;
static gint ett_pap_peer_id		= -1;
static gint ett_pap_password		= -1;
static gint ett_pap_message		= -1;

static int proto_chap			= -1;		/* CHAP vars */
static gint ett_chap			= -1;
static gint ett_chap_data		= -1;
static gint ett_chap_value		= -1;
static gint ett_chap_name		= -1;
static gint ett_chap_message		= -1;

static int proto_ipv6cp = -1;  /* IPv6CP vars */

static gint ett_ipv6cp = -1;
static gint ett_ipv6cp_options = -1;
static gint ett_ipv6cp_if_id_opt = -1;
static gint ett_ipv6cp_compress_opt = -1;  

static dissector_table_t ppp_subdissector_table;
static dissector_handle_t chdlc_handle;
static dissector_handle_t data_handle;

/* options */
static gint ppp_fcs_decode = 0; /* 0 = No FCS, 1 = 16 bit FCS, 2 = 32 bit FCS */
#define NO_FCS 0
#define FCS_16 1
#define FCS_32 2

const enum_val_t fcs_options[] = {
  {"none", "None", NO_FCS},
  {"16-bit", "16-Bit", FCS_16},
  {"32-bit", "32-Bit", FCS_32},
  {NULL, NULL, -1}
};

gboolean ppp_vj_decomp = TRUE; /* Default to VJ header decompression */

/*
 * For Default Protocol ID negotiated with PPPMuxCP. We need to
 * this ID so that if the first subframe doesn't have protocol
 * ID, we can use it
 */

static guint pppmux_def_prot_id = 0;

/* PPP definitions */

/*
 * Used by the GTP dissector as well.
 */
const value_string ppp_vals[] = {
	{PPP_PADDING,	"Padding Protocol" },
	{PPP_ROHC_SCID,	"ROHC small-CID" },
	{PPP_ROHC_LCID,	"ROHC large-CID" },
	{PPP_IP,        "IP"             },
	{PPP_OSI,       "OSI"            },
	{PPP_DEC4,	"DECnet Phase IV" },
	{PPP_AT,        "Appletalk"      },
	{PPP_IPX,       "Netware IPX/SPX"},
	{PPP_VJC_COMP,	"VJ compressed TCP"},
	{PPP_VJC_UNCOMP,"VJ uncompressed TCP"},
	{PPP_BPDU,      "Bridging PDU"},
	{PPP_ST,	"Stream Protocol (ST-II)" },
	{PPP_VINES,     "Vines"          },
	{PPP_AT_EDDP,	"AppleTalk EDDP" },
	{PPP_AT_SB,	"AppleTalk SmartBuffered" },
	{PPP_MP,	"Multilink"},
	{PPP_NB,	"NETBIOS Framing" },
	{PPP_CISCO,	"Cisco Systems" },
	{PPP_ASCOM,	"Ascom Timeplex" },
	{PPP_LBLB,	"Fujitsu Link Backup and Load Balancing" },
	{PPP_RL,	"DCA Remote Lan" },
	{PPP_SDTP,	"Serial Data Transport Protocol" },
	{PPP_LLC,	"SNA over LLC" },
	{PPP_SNA,	"SNA" },
	{PPP_IPV6HC,	"IPv6 Header Compression " },
	{PPP_KNX,	"KNX Bridging Data" },
	{PPP_ENCRYPT,	"Encryption" },
	{PPP_ILE,	"Individual Link Encryption" },
	{PPP_IPV6,      "IPv6"           },
        {PPP_MUX,       "PPP Multiplexing"},
	{PPP_RTP_FH,	"RTP IPHC Full Header" },
	{PPP_RTP_CTCP,	"RTP IPHC Compressed TCP" },
	{PPP_RTP_CNTCP,	"RTP IPHC Compressed Non TCP" },
	{PPP_RTP_CUDP8,	"RTP IPHC Compressed UDP 8" },
	{PPP_RTP_CRTP8,	"RTP IPHC Compressed RTP 8" },
	{PPP_STAMPEDE,	"Stampede Bridging" },
	{PPP_MPPLUS,	"MP+ Protocol" },
	{PPP_NTCITS_IPI,"NTCITS IPI" },
	{PPP_ML_SLCOMP,	"single link compression in multilink" },
	{PPP_COMP,	"compressed packet" },
	{PPP_STP_HELLO,	"802.1d Hello Packet" },
	{PPP_IBM_SR,	"IBM Source Routing BPDU" },
	{PPP_DEC_LB,	"DEC LANBridge100 Spanning Tree"},
	{PPP_CDP,       "Cisco Discovery Protocol" },
	{PPP_NETCS,	"Netcs Twin Routing" },
	{PPP_STP,       "Scheduled Transfer Protocol" },
	{PPP_EDP,       "Extreme Discovery Protocol" },
	{PPP_OSCP,	"Optical Supervisory Channel Protocol" },
	{PPP_OSCP2,	"Optical Supervisory Channel Protocol" },
	{PPP_LUXCOM,	"Luxcom" },
	{PPP_SIGMA,	"Sigma Network Systems" },
	{PPP_ACSP,	"Apple Client Server Protocol" },
	{PPP_MPLS_UNI,  "MPLS Unicast"},
	{PPP_MPLS_MULTI, "MPLS Multicast"},
	{PPP_P12844,	"IEEE p1284.4 standard - data packets" },
	{PPP_ETSI,	"ETSI TETRA Networks Procotol Type 1" },
	{PPP_MFTP,	"Multichannel Flow Treatment Protocol" },
	{PPP_RTP_CTCPND,"RTP IPHC Compressed TCP No Delta" },
	{PPP_RTP_CS,	"RTP IPHC Context State" },
	{PPP_RTP_CUDP16,"RTP IPHC Compressed UDP 16" },
	{PPP_RTP_CRDP16,"RTP IPHC Compressed RTP 16" },
	{PPP_CCCP,	"Cray Communications Control Protocol" },
	{PPP_CDPD_MNRP,	"CDPD Mobile Network Registration Protocol" },
	{PPP_EXPANDAP,	"Expand accelarator protocol" },
	{PPP_ODSICP,	"ODSICP NCP" },
	{PPP_DOCSIS,	"DOCSIS DLL" },
	{PPP_LZS,	"Stacker LZS" },
	{PPP_REFTEK,	"RefTek Protocol" },
	{PPP_FC,	"Fibre Channel" },
	{PPP_EMIT,	"EMIT Protocols" },
	{PPP_IPCP,	"IP Control Protocol" },
	{PPP_OSICP,     "OSI Control Protocol" },
	{PPP_XNSIDPCP,	"Xerox NS IDP Control Protocol" },
	{PPP_DECNETCP,	"DECnet Phase IV Control Protocol" },
	{PPP_ATCP,	"AppleTalk Control Protocol" },
	{PPP_IPXCP,	"IPX Control Protocol" },
	{PPP_BRIDGENCP,	"Bridging NCP" },
	{PPP_SPCP,	"Stream Protocol Control Protocol" },
	{PPP_BVCP,	"Banyan Vines Control Protocol" },
	{PPP_MLCP,	"Multi-Link Control Protocol" },
	{PPP_NBCP,	"NETBIOS Framing Control Protocol" },
	{PPP_CISCOCP,	"Cisco Systems Control Protocol" },
	{PPP_ASCOMCP,	"Ascom Timeplex" },
	{PPP_LBLBCP,	"Fujitsu LBLB Control Protocol" },
	{PPP_RLNCP,	"DCA Remote Lan Network Control Protocol" },
	{PPP_SDCP,	"Serial Data Control Protocol" },
	{PPP_LLCCP,	"SNA over LLC Control Protocol" },
	{PPP_SNACP,	"SNA Control Protocol" },
	{PPP_KNXCP,	"KNX Bridging Control Protocol" },
	{PPP_ECP,	"Encryption Control Protocol" },
	{PPP_ILECP,	"Individual Encryption Control Protocol" },
	{PPP_IPV6CP,	"IPv6 Control Protocol" },
	{PPP_MUXCP,     "PPPMux Control Protocol"},
	{PPP_STAMPEDECP,"Stampede Bridging Control Protocol" },
	{PPP_MPPCP,	"MP+ Contorol Protocol" },
	{PPP_IPICP,	"NTCITS IPI Control Protocol" },
	{PPP_SLCC,	"single link compression in multilink control" },
	{PPP_CCP,	"Compression Control Protocol" },
	{PPP_CDPCP,	"CDP Control Protocol" },
	{PPP_NETCSCP,	"Netcs Twin Routing" },
	{PPP_STPCP,	"STP - Control Protocol" },
	{PPP_EDPCP,	"EDP Control Protocol" },
	{PPP_ACSPC,	"Apple Client Server Protocol Control" },
	{PPP_MPLSCP,	"MPLS Control Protocol" },
	{PPP_P12844CP,	"IEEE p1284.4 standard - Protocol Control" },
	{PPP_ETSICP,	"ETSI TETRA TNP1 Control Protocol" },
	{PPP_MFTPCP,	"Multichannel Flow Treatment Protocol" },
	{PPP_LCP,	"Link Control Protocol" },
	{PPP_PAP,	"Password Authentication Protocol"  },
	{PPP_LQR,	"Link Quality Report protocol" },
	{PPP_SPAP,	"Shiva Password Authentication Protocol" },
	{PPP_CBCP,	"Callback Control Protocol" },
	{PPP_BACP,	"Bandwidth Allocation Control Protocol" },
	{PPP_BAP,	"Bandwidth Allocation Protocol" },
	{PPP_CONTCP,	"Container Control Protocol" },
	{PPP_CHAP,	"Challenge Handshake Authentication Protocol" },
	{PPP_RSAAP,	"RSA Authentication Protocol" },
	{PPP_EAP,	"Extensible Authentication Protocol" },
	{PPP_SIEP,	"Mitsubishi Security Information Exchange Protocol"},
	{PPP_SBAP,	"Stampede Bridging Authorization Protocol" },
	{PPP_PRPAP,	"Proprietary Authentication Protocol" },
	{PPP_PRPAP2,	"Proprietary Authentication Protocol" },
	{PPP_PRPNIAP,	"Proprietary Node ID Authentication Protocol" },
	{0,             NULL            }
};

/* CP (LCP, IPCP, etc.) codes.
 * from pppd fsm.h
 */
#define CONFREQ    1  /* Configuration Request */
#define CONFACK    2  /* Configuration Ack */
#define CONFNAK    3  /* Configuration Nak */
#define CONFREJ    4  /* Configuration Reject */
#define TERMREQ    5  /* Termination Request */
#define TERMACK    6  /* Termination Ack */
#define CODEREJ    7  /* Code Reject */

static const value_string cp_vals[] = {
	{CONFREQ,    "Configuration Request" },
	{CONFACK,    "Configuration Ack" },
	{CONFNAK,    "Configuration Nak" },
	{CONFREJ,    "Configuration Reject" },
	{TERMREQ,    "Termination Request" },
	{TERMACK,    "Termination Ack" },
	{CODEREJ,    "Code Reject" },
	{0,          NULL            } };

/*
 * LCP-specific packet types.
 */
#define PROTREJ    8  /* Protocol Reject */
#define ECHOREQ    9  /* Echo Request */
#define ECHOREP    10 /* Echo Reply */
#define DISCREQ    11 /* Discard Request */
#define IDENT      12 /* Identification */
#define TIMEREMAIN 13 /* Time remaining */

/*
 * CCP-specific packet types.
 */
#define RESETREQ   14  /* Reset Request */
#define RESETACK   15  /* Reset Ack */

/*
 * CBCP-specific packet types.
 */
#define CBREQ      1  /* Callback Request */
#define CBRES      2  /* Callback Response */
#define CBACK      3  /* Callback Ack */

#define CBCP_OPT  6 /* Use callback control protocol */

/*
 * BAP-specific packet types.
 */
#define BAP_CREQ   1  /* Call Request */
#define BAP_CRES   2  /* Call Response */
#define BAP_CBREQ  3  /* Callback Request */
#define BAP_CBRES  4  /* Callback Response */
#define BAP_LDQREQ 5  /* Link Drop Query Request */
#define BAP_LDQRES 6  /* Link Drop Query Response */
#define BAP_CSI    7  /* Call Status Indication */
#define BAP_CSRES  8  /* Call Status Response */

static const value_string lcp_vals[] = {
	{CONFREQ,    "Configuration Request" },
	{CONFACK,    "Configuration Ack" },
	{CONFNAK,    "Configuration Nak" },
	{CONFREJ,    "Configuration Reject" },
	{TERMREQ,    "Termination Request" },
	{TERMACK,    "Termination Ack" },
	{CODEREJ,    "Code Reject" },
	{PROTREJ,    "Protocol Reject" },
	{ECHOREQ,    "Echo Request" },
	{ECHOREP,    "Echo Reply" },
	{DISCREQ,    "Discard Request" },
	{IDENT,      "Identification" },
	{TIMEREMAIN, "Time Remaining" },
	{0,          NULL }
};

static const value_string ccp_vals[] = {
	{CONFREQ,    "Configuration Request" },
	{CONFACK,    "Configuration Ack" },
	{CONFNAK,    "Configuration Nak" },
	{CONFREJ,    "Configuration Reject" },
	{TERMREQ,    "Termination Request" },
	{TERMACK,    "Termination Ack" },
	{CODEREJ,    "Code Reject" },
	{RESETREQ,   "Reset Request" },
	{RESETACK,   "Reset Ack" },
	{0,          NULL }
};

static const value_string cbcp_vals[] = {
	{CBREQ,      "Callback Request" },
	{CBRES,      "Callback Response" },
	{CBACK,      "Callback Ack" },
	{0,          NULL }
};

static const value_string bap_vals[] = {
	{BAP_CREQ,	"Call Request" },
	{BAP_CRES,	"Call Response" },
	{BAP_CBREQ,	"Callback Request" },
	{BAP_CBRES,	"Callback Response" },
	{BAP_LDQREQ,	"Link Drop Query Request" },
	{BAP_LDQRES,	"Link Drop Query Response" },
	{BAP_CSI,	"Call Status Indication" },
	{BAP_CSRES,	"Call Status Response" },
	{0,		NULL }
};

#define BAP_RESP_CODE_REQACK	0x00
#define BAP_RESP_CODE_REQNAK	0x01
#define BAP_RESP_CODE_REQREJ	0x02
#define BAP_RESP_CODE_REQFULLNAK	0x03
static const value_string bap_resp_code_vals[] = {
	{BAP_RESP_CODE_REQACK,	"Request Ack" },
	{BAP_RESP_CODE_REQNAK,	"Request Nak" },
	{BAP_RESP_CODE_REQREJ,	"Request Rej" },
	{BAP_RESP_CODE_REQFULLNAK,	"Request Full Nak" },
	{0,			NULL }
};

#define BAP_LINK_TYPE_ISDN	0	/* ISDN */
#define BAP_LINK_TYPE_X25	1	/* X.25 */
#define BAP_LINK_TYPE_ANALOG	2	/* Analog */
#define BAP_LINK_TYPE_SD	3	/* Switched Digital (non-ISDN) */
#define BAP_LINK_TYPE_ISDNOV	4	/* ISDN data over voice */
#define BAP_LINK_TYPE_RESV5	5	/* Reserved */
#define BAP_LINK_TYPE_RESV6	6	/* Reserved */
#define BAP_LINK_TYPE_RESV7	7	/* Reserved */
static const value_string bap_link_type_vals[] = {
	{BAP_LINK_TYPE_ISDN,	"ISDN" },
	{BAP_LINK_TYPE_X25,	"X.25" },
	{BAP_LINK_TYPE_ANALOG,	"Analog" },
	{BAP_LINK_TYPE_SD,	"Switched Digital (non-ISDN)" },
	{BAP_LINK_TYPE_ISDNOV,	"ISDN data over voice" },
	{BAP_LINK_TYPE_RESV5,	"Reserved" },
	{BAP_LINK_TYPE_RESV6,	"Reserved" },
	{BAP_LINK_TYPE_RESV7,	"Reserved" },
	{0,			NULL }
};

#define BAP_PHONE_DELTA_SUBOPT_UNIQ_DIGIT	1	/* Unique Digit */
#define BAP_PHONE_DELTA_SUBOPT_SUBSC_NUM	2	/* Subscriber Number */
#define BAP_PHONE_DELTA_SUBOPT_PHONENUM_SUBADDR	3 /* Phone Number Sub Address */
static const value_string bap_phone_delta_subopt_vals[] = {
	{BAP_PHONE_DELTA_SUBOPT_UNIQ_DIGIT,	"Unique Digit" },
	{BAP_PHONE_DELTA_SUBOPT_SUBSC_NUM,	"Subscriber Number" },
	{BAP_PHONE_DELTA_SUBOPT_PHONENUM_SUBADDR, "Phone Number Sub Address" },
	{0,					NULL }
};

/*
 * Cause codes for Cause.
 *
 * The following code table is taken from packet-q931.c but is slightly
 * adapted to BAP protocol.
 */
static const value_string q931_cause_code_vals[] = {
	{ 0x00,	"Call successful" },
	{ 0x01,	"Unallocated (unassigned) number" },
	{ 0x02,	"No route to specified transit network" },
	{ 0x03,	"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" },
	{ 0x09,	"Prefix 1 dialed but not allowed" },
	{ 0x0A,	"Prefix 1 dialed but not required" },
	{ 0x0B,	"More digits received than allowed, call is proceeding" },
	{ 0x10,	"Normal call clearing" },
	{ 0x11,	"User busy" },
	{ 0x12,	"No user responding" },
	{ 0x13,	"No answer from user (user alerted)" },
	{ 0x14,	"Subscriber absent" },
	{ 0x15,	"Call rejected" },
	{ 0x16,	"Number changed" },
	{ 0x17,	"Reverse charging rejected" },
	{ 0x18,	"Call suspended" },
	{ 0x19,	"Call resumed" },
	{ 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" },
	{ 0x28,	"Throughput range cannot be achieved" },
	{ 0x29,	"Temporary failure" },
	{ 0x2A,	"Switching equipment congestion" },
	{ 0x2B,	"Access information discarded" },
	{ 0x2C,	"Requested circuit/channel not available" },
	{ 0x2D,	"Pre-empted" },
	{ 0x2E,	"Precedence call blocked" },
	{ 0x2F,	"Resources unavailable, unspecified" },
	{ 0x31,	"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" },
	{ 0x52,	"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" },
	{ 0x58,	"Incompatible destination" },
	{ 0x59,	"Non-existent abbreviated address entry" },
	{ 0x5A,	"Destination address missing, and direct call not subscribed" },
	{ 0x5B,	"Invalid transit network selection (national use)" },
	{ 0x5C,	"Invalid facility parameter" },
	{ 0x5D,	"Mandatory information element is missing" },
	{ 0x5F,	"Invalid message, unspecified" },
	{ 0x60,	"Mandatory information element is missing" },
	{ 0x61,	"Message type non-existent or not implemented" },
	{ 0x62,	"Message not compatible with call state or message type non-existent or not implemented" },
	{ 0x63,	"Information element nonexistant or not implemented" },
	{ 0x64,	"Invalid information element contents" },
	{ 0x65,	"Message not compatible with call state" },
	{ 0x66,	"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" },
	{ 0xFF, "Non-specific failure" },
	{ 0,	NULL }
};

static const value_string bap_call_status_opt_action_vals[] = {
	{0,	"No retry" },
	{1,	"Retry" },
	{0,	NULL }
};

#define STAC_CM_NONE		0
#define STAC_CM_LCB		1
#define	STAC_CM_CRC		2
#define	STAC_CM_SN		3
#define STAC_CM_EXTMODE		4
static const value_string stac_checkmode_vals[] = {
	{STAC_CM_NONE,		"None" },
	{STAC_CM_LCB,		"LCB" },
	{STAC_CM_CRC,		"CRC" },
	{STAC_CM_SN,		"Sequence Number" },
	{STAC_CM_EXTMODE,	"Extended Mode" },
	{0,			NULL }
};

#define LZSDCP_CM_NONE		0
#define LZSDCP_CM_LCB		1
#define	LZSDCP_CM_SN		2
#define	LZSDCP_CM_SN_LCB	3
static const value_string lzsdcp_checkmode_vals[] = {
	{LZSDCP_CM_NONE,	"None" },
	{LZSDCP_CM_LCB,		"LCB" },
	{LZSDCP_CM_SN,		"Sequence Number" },
	{LZSDCP_CM_SN_LCB,	"Sequence Number + LCB" },
	{0,			NULL }
};

#define LZSDCP_PM_NONE		0
#define LZSDCP_PM_PROC_UNCOMP	1
static const value_string lzsdcp_processmode_vals[] = {
	{LZSDCP_PM_NONE,	"None" },
	{LZSDCP_PM_PROC_UNCOMP,	"Process-Uncompressed" },
	{0,			NULL }
};

/*
 * Options.  (LCP)
 */
#define CI_MRU			1	/* Maximum Receive Unit */
#define CI_ASYNCMAP		2	/* Async Control Character Map */
#define CI_AUTHTYPE		3	/* Authentication Type */
#define CI_QUALITY		4	/* Quality Protocol */
#define CI_MAGICNUMBER		5	/* Magic Number */
#define CI_PCOMPRESSION		7	/* Protocol Field Compression */
#define CI_ACCOMPRESSION	8	/* Address/Control Field Compression */
#define CI_FCS_ALTERNATIVES	9	/* FCS Alternatives (RFC 1570) */
#define CI_SELF_DESCRIBING_PAD	10	/* Self-Describing Pad (RFC 1570) */
#define CI_NUMBERED_MODE	11	/* Numbered Mode (RFC 1663) */
#define CI_CALLBACK		13	/* Callback (RFC 1570) */
#define CI_COMPOUND_FRAMES	15	/* Compound frames (RFC 1570) */
#define CI_MULTILINK_MRRU	17	/* Multilink MRRU (RFC 1717) */
#define CI_MULTILINK_SSNH	18	/* Multilink Short Sequence Number
					   Header (RFC 1717) */
#define CI_MULTILINK_EP_DISC	19	/* Multilink Endpoint Discriminator
					   (RFC 1717) */
#define CI_DCE_IDENTIFIER	21	/* DCE Identifier */
#define CI_MULTILINK_PLUS_PROC	22	/* Multilink Plus Procedure */
#define CI_LINK_DISC_FOR_BACP	23	/* Link Discriminator for BACP
					   (RFC 2125) */
#define CI_LCP_AUTHENTICATION	24	/* LCP Authentication Option */
#define CI_COBS			25	/* Consistent Overhead Byte
					   Stuffing */
#define CI_PREFIX_ELISION	26	/* Prefix elision */
#define CI_MULTILINK_HDR_FMT	27	/* Multilink header format */
#define CI_INTERNATIONALIZATION	28	/* Internationalization (RFC 2484) */
#define	CI_SDL_ON_SONET_SDH	29	/* Simple Data Link on SONET/SDH */

static void dissect_lcp_mru_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_lcp_async_map_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_lcp_protocol_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_lcp_authprot_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_lcp_magicnumber_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_lcp_fcs_alternatives_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_lcp_numbered_mode_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_lcp_self_describing_pad_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_lcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_lcp_multilink_mrru_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_lcp_multilink_ep_disc_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_lcp_bap_link_discriminator_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_lcp_internationalization_opt(const ip_tcp_opt *optp,
			tvbuff_t *tvb, int offset, guint length,
			packet_info *pinfo, proto_tree *tree);
static void dissect_mp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);

static const ip_tcp_opt lcp_opts[] = {
	{
		CI_MRU,
		"Maximum Receive Unit",
		NULL,
		FIXED_LENGTH,
		4,
		dissect_lcp_mru_opt
	},
	{
		CI_ASYNCMAP,
		"Async Control Character Map",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_lcp_async_map_opt
	},
	{
		CI_AUTHTYPE,
		"Authentication protocol",
		&ett_lcp_authprot_opt,
		VARIABLE_LENGTH,
		4,
		dissect_lcp_authprot_opt
	},
	{
		CI_QUALITY,
		"Quality protocol",
		&ett_lcp_qualprot_opt,
		VARIABLE_LENGTH,
		4,
		dissect_lcp_protocol_opt
	},
	{
		CI_MAGICNUMBER,
		"Magic number",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_lcp_magicnumber_opt
	},
	{
		CI_PCOMPRESSION,
		"Protocol field compression",
		NULL,
		FIXED_LENGTH,
		2,
		NULL
	},
	{
		CI_ACCOMPRESSION,
		"Address/control field compression",
		NULL,
		FIXED_LENGTH,
		2,
		NULL
	},
	{
		CI_FCS_ALTERNATIVES,
		"FCS alternatives",
		&ett_lcp_fcs_alternatives_opt,
		FIXED_LENGTH,
		3,
		dissect_lcp_fcs_alternatives_opt
	},
	{
		CI_SELF_DESCRIBING_PAD,
		"Maximum octets of self-describing padding",
		NULL,
		FIXED_LENGTH,
		3,
		dissect_lcp_self_describing_pad_opt
	},
	{
		CI_NUMBERED_MODE,
		"Numbered mode",
		&ett_lcp_numbered_mode_opt,
		VARIABLE_LENGTH,
		4,
		dissect_lcp_numbered_mode_opt
	},
	{
		CI_CALLBACK,
		"Callback",
		&ett_lcp_callback_opt,
		VARIABLE_LENGTH,
		3,
		dissect_lcp_callback_opt,
	},
	{
		CI_COMPOUND_FRAMES,
		"Compound frames",
		NULL,
		FIXED_LENGTH,
		2,
		NULL
	},
	{
		CI_MULTILINK_MRRU,
		"Multilink MRRU",
		NULL,
		FIXED_LENGTH,
		4,
		dissect_lcp_multilink_mrru_opt
	},
	{
		CI_MULTILINK_SSNH,
		"Use short sequence number headers",
		NULL,
		FIXED_LENGTH,
		2,
		NULL
	},
	{
		CI_MULTILINK_EP_DISC,
		"Multilink endpoint discriminator",
		&ett_lcp_multilink_ep_disc_opt,
		VARIABLE_LENGTH,
		3,
		dissect_lcp_multilink_ep_disc_opt,
	},
	{
		CI_DCE_IDENTIFIER,
		"DCE identifier",
		NULL,
		VARIABLE_LENGTH,
		2,
		NULL
	},
	{
		CI_MULTILINK_PLUS_PROC,
		"Multilink Plus Procedure",
		NULL,
		VARIABLE_LENGTH,
		2,
		NULL
	},
	{
		CI_LINK_DISC_FOR_BACP,
		"Link discriminator for BAP",
		NULL,
		FIXED_LENGTH,
		4,
		dissect_lcp_bap_link_discriminator_opt
	},
	{
		CI_LCP_AUTHENTICATION,
		"LCP authentication",
		NULL,
		VARIABLE_LENGTH,
		2,
		NULL
	},
	{
		CI_COBS,
		"Consistent Overhead Byte Stuffing",
		NULL,
		VARIABLE_LENGTH,
		2,
		NULL
	},
	{
		CI_PREFIX_ELISION,
		"Prefix elision",
		NULL,
		VARIABLE_LENGTH,
		2,
		NULL
	},
	{
		CI_MULTILINK_HDR_FMT,
		"Multilink header format",
		NULL,
		VARIABLE_LENGTH,
		2,
		NULL
	},
	{
		CI_INTERNATIONALIZATION,
		"Internationalization",
		&ett_lcp_internationalization_opt,
		VARIABLE_LENGTH,
		7,
		dissect_lcp_internationalization_opt
	},
	{
		CI_SDL_ON_SONET_SDH,
		"Simple data link on SONET/SDH",
		NULL,
		VARIABLE_LENGTH,
		2,
		NULL
	}
};

#define N_LCP_OPTS	(sizeof lcp_opts / sizeof lcp_opts[0])

/*
 * CHAP Algorithms
 */
#define CHAP_ALG_MD5	0x05	/* CHAP with MD5 */
#define CHAP_ALG_MSV1	0x80	/* MS-CHAPv1 */
#define CHAP_ALG_MSV2	0x81	/* MS-CHAPv2 */

static const value_string chap_alg_vals[] = {
	{CHAP_ALG_MD5,	"CHAP with MD5" },
	{CHAP_ALG_MSV1,	"MS-CHAP" },
	{CHAP_ALG_MSV2,	"MS-CHAP-2" },
	{0,          	NULL }
};


/*
 * Options.  (IPCP)
 */
#define CI_ADDRS	1	/* IP Addresses (deprecated) (RFC 1172) */
#define CI_COMPRESSTYPE	2	/* Compression Type (RFC 1332) */
#define CI_ADDR		3	/* IP Address (RFC 1332) */
#define CI_MOBILE_IPv4	4	/* Mobile IPv4 (RFC 2290) */
#define CI_MS_DNS1	129	/* Primary DNS value (RFC 1877) */
#define CI_MS_WINS1	130	/* Primary WINS value (RFC 1877) */
#define CI_MS_DNS2	131	/* Secondary DNS value (RFC 1877) */
#define CI_MS_WINS2	132	/* Secondary WINS value (RFC 1877) */

static void dissect_ipcp_addrs_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_ipcp_addr_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_ipcp_compress_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);
static void dissect_ipcp_iphc_disableprot_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static const ip_tcp_opt ipcp_opts[] = {
	{
		CI_ADDRS,
		"IP addresses (deprecated)",
		&ett_ipcp_ipaddrs_opt,
		FIXED_LENGTH,
		10,
		dissect_ipcp_addrs_opt
	},
	{
		CI_COMPRESSTYPE,
		"IP compression",
		&ett_ipcp_compress_opt,
		VARIABLE_LENGTH,
		4,
		dissect_ipcp_compress_opt
	},
	{
		CI_ADDR,
		"IP address",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_ipcp_addr_opt
	},
	{
		CI_MOBILE_IPv4,
		"Mobile node's home IP address",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_ipcp_addr_opt
	},
	{
		CI_MS_DNS1,
		"Primary DNS server IP address",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_ipcp_addr_opt
	},
	{
		CI_MS_WINS1,
		"Primary WINS server IP address",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_ipcp_addr_opt
	},
	{
		CI_MS_DNS2,
		"Secondary DNS server IP address",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_ipcp_addr_opt
	},
	{
		CI_MS_WINS2,
		"Secondary WINS server IP address",
		NULL,
		FIXED_LENGTH,
		6,
		dissect_ipcp_addr_opt
	}
};

#define N_IPCP_OPTS	(sizeof ipcp_opts / sizeof ipcp_opts[0])


/*
 * IP Compression options
 */
#define IPCP_COMPRESS_VJ_1172	0x37	/* value defined in RFC1172 (typo) */
#define IPCP_COMPRESS_VJ	0x2d	/* value defined in RFC1332 (correct) */
#define IPCP_COMPRESS_IPHC	0x61

const value_string ipcp_compress_proto_vals[] = {
    { IPCP_COMPRESS_VJ_1172,	"VJ compression (RFC1172-typo)" },
    { IPCP_COMPRESS_VJ,		"VJ compression" },
    { IPCP_COMPRESS_IPHC,	"IPHC compression" },
    { 0,			NULL }
};

/* IPHC suboptions (RFC2508, 3544) */
#define IPCP_IPHC_CRTP		1
#define IPCP_IPHC_ECRTP		2
#define IPCP_IPHC_DISABLE_PROTO	3	/* Disable compression for protocol */

const value_string ipcp_iphc_disable_proto_vals[] = {
    { 1,	"TCP" },
    { 2,	"Non-TCP" },
    { 0,	NULL }
};

static const ip_tcp_opt ipcp_iphc_subopts[] = {
	{
		IPCP_IPHC_CRTP,
		"RTP compression (RFC2508)",
		NULL,
		FIXED_LENGTH,
		2,
		NULL
	},
	{
		IPCP_IPHC_CRTP,
		"Enhanced RTP compression (RFC3545)",
		NULL,
		FIXED_LENGTH,
		2,
		NULL
	},
	{
		IPCP_IPHC_DISABLE_PROTO,
		"Enhanced RTP compression (RFC3545)",
		&ett_ipcp_iphc_disableprot_opt,
		FIXED_LENGTH,
		3,
		dissect_ipcp_iphc_disableprot_opt
	},
};

#define N_IPCP_IPHC_SUBOPTS (sizeof ipcp_iphc_subopts / sizeof ipcp_iphc_subopts[0])


/*
 * Options.  (OSICP)
 */
#define CI_OSICP_ALIGN_NPDU      1       /* Alignment of the OSI NPDU (RFC 1377) */

static void dissect_osicp_align_npdu_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
                        proto_tree *tree);

static const ip_tcp_opt osicp_opts[] = {
        {
                CI_OSICP_ALIGN_NPDU,
                "Align-NPDU",
                &ett_osicp_align_npdu_opt,
                FIXED_LENGTH,
                3,
                dissect_osicp_align_npdu_opt
        }
};

#define N_OSICP_OPTS     (sizeof osicp_opts / sizeof osicp_opts[0])

/*
 * Options.  (CCP)
 */
#define CI_CCP_OUI	0	/* OUI (RFC1962) */
#define CI_CCP_PREDICT1	1	/* Predictor type 1 (RFC1962) */
#define CI_CCP_PREDICT2	2	/* Predictor type 2 (RFC1962) */
#define CI_CCP_PUDDLE	3	/* Puddle Jumper (RFC1962) */
#define CI_CCP_HPPPC	16	/* Hewlett-Packard PPC (RFC1962) */
#define CI_CCP_STAC	17	/* stac Electronics LZS (RFC1974) */
#define CI_CCP_MPPC	18	/* Microsoft PPC (RFC2218/3078) */
#define CI_CCP_GFZA	19	/* Gandalf FZA (RFC1962) */
#define CI_CCP_V42BIS	20	/* V.42bis compression */
#define CI_CCP_BSDLZW	21	/* BSD LZW Compress (RFC1977) */
#define CI_CCP_LZSDCP	23	/* LZS-DCP (RFC1967) */
#define CI_CCP_MVRCA	24	/* MVRCA (Magnalink) (RFC1975) */
#define CI_CCP_DEFLATE	26	/* Deflate (RFC1979) */
#define CI_CCP_RESERVED	255	/* Reserved (RFC1962) */

/*
 * Microsoft Point-To-Point Compression (MPPC) and Encryption (MPPE)
 * supported bits.
 */
#define MPPC_SUPPORTED_BITS_C	0x00000001	/* MPPC negotiation */
#define MPPE_SUPPORTED_BITS_D	0x00000010	/* Obsolete */
#define MPPE_SUPPORTED_BITS_L	0x00000020	/* 40-bit encryption */
#define MPPE_SUPPORTED_BITS_S	0x00000040	/* 128-bit encryption */
#define MPPE_SUPPORTED_BITS_M	0x00000080	/* 56-bit encryption */
#define MPPE_SUPPORTED_BITS_H	0x01000000	/* stateless mode */

static void dissect_ccp_stac_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_ccp_mppc_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_ccp_bsdcomp_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_ccp_lzsdcp_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_ccp_mvrca_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_ccp_deflate_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static const ip_tcp_opt ccp_opts[] = {
	{
		CI_CCP_STAC,
		"Stac Electronics LZS",
		&ett_ccp_stac_opt,
		VARIABLE_LENGTH,
		5,
		/* In RFC 1974, this is a fixed-length field of size 5,
		   but in Ascend Proprietary STAC compression this field
		   is 6 octets. Sigh... */
		dissect_ccp_stac_opt
	},
	{
		CI_CCP_MPPC,
		"Microsoft PPC",
		&ett_ccp_mppc_opt,
		FIXED_LENGTH,
		6,
		dissect_ccp_mppc_opt
	},
	{
		CI_CCP_BSDLZW,
		"BSD Compress",
		&ett_ccp_bsdcomp_opt,
		FIXED_LENGTH,
		3,
		dissect_ccp_bsdcomp_opt
	},
	{
		CI_CCP_LZSDCP,
		"LZS-DCP",
		&ett_ccp_lzsdcp_opt,
		FIXED_LENGTH,
		6,
		dissect_ccp_lzsdcp_opt
	},
	{
		CI_CCP_MVRCA,
		"MVRCA (Magnalink)",
		&ett_ccp_mvrca_opt,
		FIXED_LENGTH,
		4,
		dissect_ccp_mvrca_opt
	},
	{
		CI_CCP_DEFLATE,
		"Deflate",
		&ett_ccp_deflate_opt,
		FIXED_LENGTH,
		4,   /* RFC1979 says the length is 3 but it's actually 4. */
		dissect_ccp_deflate_opt
	},
};

#define N_CCP_OPTS	(sizeof ccp_opts / sizeof ccp_opts[0])

/*
 * Options.  (CBCP)
 */
#define CI_CBCP_NO_CALLBACK	1  /* No callback */
#define CI_CBCP_CB_USER		2  /* Callback to a user-specified number */
#define CI_CBCP_CB_PRE		3  /* Callback to a pre-specified or
                                            administrator specified number */
#define CI_CBCP_CB_ANY		4  /* Callback to any of a list of numbers */

static void dissect_cbcp_no_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_cbcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static const ip_tcp_opt cbcp_opts[] = {
	{
		CI_CBCP_NO_CALLBACK,
		"No callback",
		NULL,
		FIXED_LENGTH,
		2,
		dissect_cbcp_no_callback_opt
	},
	{
		CI_CBCP_CB_USER,
		"Callback to a user-specified number",
		&ett_cbcp_callback_opt,
		VARIABLE_LENGTH,
		4,
		dissect_cbcp_callback_opt
	},
	{
		CI_CBCP_CB_PRE,
		"Callback to a pre-specified or admin-specified number",
		&ett_cbcp_callback_opt,
		FIXED_LENGTH,
		3,
		dissect_cbcp_callback_opt
	},
	{
		CI_CBCP_CB_ANY,
		"Callback to any of a list of numbers",
		&ett_cbcp_callback_opt,
		VARIABLE_LENGTH,
		4,
		dissect_cbcp_callback_opt
	}

};

#define N_CBCP_OPTS	(sizeof cbcp_opts / sizeof cbcp_opts[0])

/*
 * Options.  (BACP)
 */
#define CI_BACP_FAVORED_PEER	1  /* Favored-Peer */

static void dissect_bacp_favored_peer_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static const ip_tcp_opt bacp_opts[] = {
	{
		CI_BACP_FAVORED_PEER,
		"Favored-Peer",
		&ett_bacp_favored_peer_opt,
		FIXED_LENGTH,
		6,
		dissect_bacp_favored_peer_opt
	}
};

#define N_BACP_OPTS	(sizeof bacp_opts / sizeof bacp_opts[0])

/*
 * Options.  (BAP)
 */
#define CI_BAP_LINK_TYPE	1  /* Link Type */
#define CI_BAP_PHONE_DELTA	2  /* Phone-Delta */
#define CI_BAP_NO_PHONE_NUM_NEEDED	3  /* No Phone Number Needed */
#define CI_BAP_REASON		4  /* Reason */
#define CI_BAP_LINK_DISC	5  /* Link Discriminator */
#define CI_BAP_CALL_STATUS	6  /* Call Status */

static void dissect_bap_link_type_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_bap_link_disc_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_bap_reason_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static void dissect_bap_call_status_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static const ip_tcp_opt bap_opts[] = {
	{
		CI_BAP_LINK_TYPE,
		"Link Type",
		&ett_bap_link_type_opt,
		FIXED_LENGTH,
		5,
		dissect_bap_link_type_opt
	},
	{
		CI_BAP_PHONE_DELTA,
		"Phone Delta",
		&ett_bap_phone_delta_opt,
		VARIABLE_LENGTH,
		4,
		dissect_bap_phone_delta_opt
	},
	{
		CI_BAP_NO_PHONE_NUM_NEEDED,
		"No Phone Number Needed",
		NULL,
		FIXED_LENGTH,
		2,
		NULL
	},
	{
		CI_BAP_REASON,
		"Reason",
		NULL,
		VARIABLE_LENGTH,
		2,
		dissect_bap_reason_opt
	},
	{
		CI_BAP_LINK_DISC,
		"Link Discriminator",
		NULL,
		FIXED_LENGTH,
		4,
		dissect_bap_link_disc_opt
	},
	{
		CI_BAP_CALL_STATUS,
		"Call Status",
		&ett_bap_call_status_opt,
		FIXED_LENGTH,
		4,
		dissect_bap_call_status_opt
	}
};

#define N_BAP_OPTS	(sizeof bap_opts / sizeof bap_opts[0])

static void dissect_ppp(tvbuff_t *tvb, packet_info *pinfo,
    proto_tree *tree);

static const value_string pap_vals[] = {
	{CONFREQ,    "Authenticate-Request" },
	{CONFACK,    "Authenticate-Ack" },
	{CONFNAK,    "Authenticate-Nak" },
	{0,          NULL            } };

static void dissect_pap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);

#define CHAP_CHAL  1  /* CHAP Challenge */
#define CHAP_RESP  2  /* CHAP Response */
#define CHAP_SUCC  3  /* CHAP Success */
#define CHAP_FAIL  4  /* CHAP Failure */

static const value_string chap_vals[] = {
	{CHAP_CHAL,  "Challenge" },
	{CHAP_RESP,  "Response" },
	{CHAP_SUCC,  "Success" },
        {CHAP_FAIL,  "Failure" },
	{0,          NULL            } };

static void dissect_chap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);

static const value_string pppmuxcp_vals[] = {
	{CONFREQ,    "Configuration Request" },
	{CONFACK,    "Configuration Ack" },
	{0,          NULL}
};

/*
 * PPPMuxCP options
 */

#define CI_DEFAULT_PID   1

static void dissect_pppmuxcp_def_pid_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo, proto_tree *tree);


static const ip_tcp_opt pppmuxcp_opts[] = {
	{
		CI_DEFAULT_PID,
		"Default Protocol ID",
		NULL,
		FIXED_LENGTH,
		4,
		dissect_pppmuxcp_def_pid_opt
	}
};

#define N_PPPMUXCP_OPTS (sizeof pppmuxcp_opts / sizeof pppmuxcp_opts[0])

/*
 * Options.  (IPv6CP)
 */
#define CI_IPV6CP_IF_ID		1	/* Interface Identifier (RFC 2472) */
#define CI_IPV6CP_COMPRESSTYPE	2	/* Compression Type (RFC 2472) */

static void dissect_ipv6cp_if_id_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo,
			proto_tree *tree);

static const ip_tcp_opt ipv6cp_opts[] = {
	{
		CI_IPV6CP_IF_ID,
		"Interface Identifier",
		&ett_ipv6cp_if_id_opt,
		FIXED_LENGTH,
		10,
		dissect_ipv6cp_if_id_opt
	},
	{
		CI_COMPRESSTYPE,
		"IPv6 compression",
		&ett_ipcp_compress_opt,
		VARIABLE_LENGTH,
		4,
		dissect_ipcp_compress_opt
	},
};

#define N_IPV6CP_OPTS	(sizeof ipv6cp_opts / sizeof ipv6cp_opts[0])

/*
*******************************************************************************
* DETAILS : Calculate a new FCS-16 given the current FCS-16 and the new data.
*******************************************************************************
*/
static guint16
fcs16(tvbuff_t * tvbuff)
{
    guint len = tvb_length(tvbuff)-2;

    /* Check for Invalid Length */
    if (len == 0)
        return (0x0000);
    return crc16_ccitt_tvb(tvbuff, len);
}

/*
*******************************************************************************
* DETAILS : Calculate a new FCS-32 given the current FCS-32 and the new data.
*******************************************************************************
*/
static guint32
fcs32(tvbuff_t * tvbuff)
{
    guint len = tvb_length(tvbuff)-4;

    /* Check for invalid Length */
    if (len == 0)
        return (0x00000000);
    return crc32_ccitt_tvb(tvbuff, len);
}

tvbuff_t *
decode_fcs(tvbuff_t *tvb, proto_tree *fh_tree, int fcs_decode, int proto_offset)
{
  tvbuff_t   *next_tvb;
  gint       len, reported_len;
  int        rx_fcs_offset;
  guint32    rx_fcs_exp;
  guint32    rx_fcs_got;

  /*
   * Remove the FCS, if any, from the packet data.
   */
  switch (fcs_decode) {

  case NO_FCS:
    next_tvb = tvb_new_subset(tvb, proto_offset, -1, -1);
    break;

  case FCS_16:
    /*
     * Do we have the entire packet, and does it include a 2-byte FCS?
     */
    len = tvb_length_remaining(tvb, proto_offset);
    reported_len = tvb_reported_length_remaining(tvb, proto_offset);
    if (reported_len < 2 || len < 0) {
      /*
       * The packet is claimed not to even have enough data for a 2-byte FCS,
       * or we're already past the end of the captured data.
       * Don't slice anything off.
       */
      next_tvb = tvb_new_subset(tvb, proto_offset, -1, -1);
    } else if (len < reported_len) {
      /*
       * The packet is claimed to have enough data for a 2-byte FCS, but
       * we didn't capture all of the packet.
       * Slice off the 2-byte FCS from the reported length, and trim the
       * captured length so it's no more than the reported length; that
       * will slice off what of the FCS, if any, is in the captured
       * length.
       */
      reported_len -= 2;
      if (len > reported_len)
        len = reported_len;
      next_tvb = tvb_new_subset(tvb, proto_offset, len, reported_len);
    } else {
      /*
       * We have the entire packet, and it includes a 2-byte FCS.
       * Slice it off.
       */
      len -= 2;
      reported_len -= 2;
      next_tvb = tvb_new_subset(tvb, proto_offset, len, reported_len);

      /*
       * Compute the FCS and put it into the tree.
       */
      rx_fcs_offset = proto_offset + len;
      rx_fcs_exp = fcs16(tvb);
      rx_fcs_got = tvb_get_letohs(tvb, rx_fcs_offset);
      if (rx_fcs_got != rx_fcs_exp) {
        proto_tree_add_text(fh_tree, tvb, rx_fcs_offset, 2,
                            "FCS 16: 0x%04x (incorrect, should be 0x%04x)",
                            rx_fcs_got, rx_fcs_exp);
      } else {
        proto_tree_add_text(fh_tree, tvb, rx_fcs_offset, 2,
                            "FCS 16: 0x%04x (correct)",
                            rx_fcs_got);
      }
    }
    break;

  case FCS_32:
    /*
     * Do we have the entire packet, and does it include a 4-byte FCS?
     */
    len = tvb_length_remaining(tvb, proto_offset);
    reported_len = tvb_reported_length_remaining(tvb, proto_offset);
    if (reported_len < 4) {
      /*
       * The packet is claimed not to even have enough data for a 4-byte FCS.
       * Just pass on the tvbuff as is.
       */
      next_tvb = tvb_new_subset(tvb, proto_offset, -1, -1);
    } else if (len < reported_len) {
      /*
       * The packet is claimed to have enough data for a 4-byte FCS, but
       * we didn't capture all of the packet.
       * Slice off the 4-byte FCS from the reported length, and trim the
       * captured length so it's no more than the reported length; that
       * will slice off what of the FCS, if any, is in the captured
       * length.
       */
      reported_len -= 4;
      if (len > reported_len)
        len = reported_len;
      next_tvb = tvb_new_subset(tvb, proto_offset, len, reported_len);
    } else {
      /*
       * We have the entire packet, and it includes a 4-byte FCS.
       * Slice it off.
       */
      len -= 4;
      reported_len -= 4;
      next_tvb = tvb_new_subset(tvb, proto_offset, len, reported_len);

      /*
       * Compute the FCS and put it into the tree.
       */
      rx_fcs_offset = proto_offset + len;
      rx_fcs_exp = fcs32(tvb);
      rx_fcs_got = tvb_get_letohl(tvb, rx_fcs_offset);
      if (rx_fcs_got != rx_fcs_exp) {
        proto_tree_add_text(fh_tree, tvb, rx_fcs_offset, 4,
                            "FCS 32: 0x%08x (incorrect, should be 0x%08x)",
                            rx_fcs_got, rx_fcs_exp);
      } else {
        proto_tree_add_text(fh_tree, tvb, rx_fcs_offset, 4,
                            "FCS 32: 0x%08x (correct)",
                            rx_fcs_got);
      }
    }
    break;

  default:
   g_assert_not_reached();
   next_tvb = NULL;
  }

  return next_tvb;
}

void
capture_ppp_hdlc( const guchar *pd, int offset, int len, packet_counts *ld ) {
  if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
    ld->other++;
    return;
  }
  if (pd[0] == CHDLC_ADDR_UNICAST || pd[0] == CHDLC_ADDR_MULTICAST) {
    capture_chdlc(pd, offset, len, ld);
    return;
  }
  if (!BYTES_ARE_IN_FRAME(offset, len, 4)) {
    ld->other++;
    return;
  }
  switch (pntohs(&pd[offset + 2])) {
    case PPP_IP:
      capture_ip(pd, offset + 4, len, ld);
      break;
    case PPP_IPX:
      capture_ipx(ld);
      break;
    case PPP_VINES:
      capture_vines(ld);
      break;
    default:
      ld->other++;
      break;
  }
}

static void
dissect_lcp_mru_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset,
			guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s: %u", optp->name,
			tvb_get_ntohs(tvb, offset + 2));
}

static void
dissect_lcp_async_map_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset,
			guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  guint32 map;
  char *mapstr;
  static const char *ctrlchars[32] = {
    "NUL", "SOH",       "STX", "ETX",        "EOT",      "ENQ", "ACK", "BEL",
    "BS",  "HT",        "NL",  "VT",         "NP (FF)",  "CR",  "SO",  "SI",
    "DLE", "DC1 (XON)", "DC2", "DC3 (XOFF)", "DC4",      "NAK", "SYN", "ETB",
    "CAN", "EM",        "SUB", "ESC",        "FS",       "GS",  "RS",  "US"
  };
  char mapbuf[32*(10+2)+1];
  char *mapp;
  int i;

  /*
   * XXX - walk through the map and show the characters to map?
   * Put them in a subtree of this item, and have the top-level item
   * either say "None", "All", or give a list of the characters?)
   */
  map = tvb_get_ntohl(tvb, offset + 2);
  if (map == 0x00000000)
    mapstr = "None";	/* don't map any control characters */
  else if (map == 0xffffffff)
    mapstr = "All";	/* map all control characters */
  else {
    /*
     * Show the names of the control characters being mapped.
     */
    mapp = &mapbuf[0];
    for (i = 0; i < 32; i++) {
      if (map & (1 << i)) {
      	if (mapp != &mapbuf[0]) {
      	  strcpy(mapp, ", ");
      	  mapp += 2;
        }
        strcpy(mapp, ctrlchars[i]);
        mapp += strlen(ctrlchars[i]);
      }
    }
    mapstr = mapbuf;
  }
  proto_tree_add_text(tree, tvb, offset, length, "%s: 0x%08x (%s)", optp->name,
		      map, mapstr);
}

static void
dissect_lcp_protocol_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset,
			guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  guint16 protocol;
  proto_item *tf;
  proto_tree *field_tree = NULL;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
	  optp->name, length, plurality(length, "", "s"));
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  length -= 2;
  protocol = tvb_get_ntohs(tvb, offset);
  proto_tree_add_text(field_tree, tvb, offset, 2, "%s: %s (0x%02x)", optp->name,
		val_to_str(protocol, ppp_vals, "Unknown"), protocol);
  offset += 2;
  length -= 2;
  if (length > 0)
    proto_tree_add_text(field_tree, tvb, offset, length, "Data (%d byte%s)", length,
    			plurality(length, "", "s"));
}

static void
dissect_lcp_authprot_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset,
			 guint length, packet_info *pinfo _U_,
			 proto_tree *tree)
{
  guint16 protocol;
  guint8 algorithm;
  proto_item *tf;
  proto_tree *field_tree = NULL;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
	  optp->name, length, plurality(length, "", "s"));
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  length -= 2;
  protocol = tvb_get_ntohs(tvb, offset);
  proto_tree_add_text(field_tree, tvb, offset, 2, "%s: %s (0x%02x)", optp->name,
		val_to_str(protocol, ppp_vals, "Unknown"), protocol);
  offset += 2;
  length -= 2;
  if (length > 0) {
    if (protocol == PPP_CHAP) {
      algorithm = tvb_get_guint8(tvb, offset);
      proto_tree_add_text(field_tree, tvb, offset, length,
			  "Algorithm: %s (0x%02x)",
			  val_to_str(algorithm, chap_alg_vals, "Unknown"),
			  algorithm);
      offset++;
    } else {
      proto_tree_add_text(field_tree, tvb, offset, length, "Data (%d byte%s)", length,
    			plurality(length, "", "s"));
    }
  }
}

static void
dissect_lcp_magicnumber_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s: 0x%08x", optp->name,
			tvb_get_ntohl(tvb, offset + 2));
}

static void
dissect_lcp_fcs_alternatives_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree = NULL;
  guint8 alternatives;

  alternatives = tvb_get_guint8(tvb, offset + 2);
  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: 0x%02x",
	  optp->name, alternatives);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  if (alternatives & 0x1)
    proto_tree_add_text(field_tree, tvb, offset + 2, 1, "%s",
       decode_boolean_bitfield(alternatives, 0x1, 8, "Null FCS", NULL));
  if (alternatives & 0x2)
    proto_tree_add_text(field_tree, tvb, offset + 2, 1, "%s",
       decode_boolean_bitfield(alternatives, 0x2, 8, "CCITT 16-bit FCS", NULL));
  if (alternatives & 0x4)
    proto_tree_add_text(field_tree, tvb, offset + 2, 1, "%s",
       decode_boolean_bitfield(alternatives, 0x4, 8, "CCITT 32-bit FCS", NULL));
}

static void
dissect_lcp_self_describing_pad_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s: %u", optp->name,
			tvb_get_guint8(tvb, offset + 2));
}

static void
dissect_lcp_numbered_mode_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree = NULL;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
	  optp->name, length, plurality(length, "", "s"));
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  length -= 2;
  proto_tree_add_text(field_tree, tvb, offset, 1, "Window: %u",
			tvb_get_guint8(tvb, offset));
  offset += 1;
  length -= 1;
  if (length > 0)
    proto_tree_add_text(field_tree, tvb, offset, length, "Address (%d byte%s)",
			length, plurality(length, "", "s"));
}

static const value_string callback_op_vals[] = {
	{0, "Location is determined by user authentication" },
	{1, "Message is dialing string" },
	{2, "Message is location identifier" },
	{3, "Message is E.164" },
	{4, "Message is distinguished name" },
	{5, "unassigned"},
	{6, "Location is determined during CBCP negotiation" },
	{0, NULL }
};

static void
dissect_lcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset,
			guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree = NULL;
  guint8 operation;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
	  optp->name, length, plurality(length, "", "s"));
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  length -= 2;
  operation = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(field_tree, tvb, offset, 1, "Operation: %s (0x%02x)",
		val_to_str(operation, callback_op_vals, "Unknown"),
		operation);
  offset += 1;
  length -= 1;
  if (length > 0)
    proto_tree_add_text(field_tree, tvb, offset, length, "Message (%d byte%s)",
			length, plurality(length, "", "s"));
}

static void
dissect_lcp_multilink_mrru_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s: %u", optp->name,
			tvb_get_ntohs(tvb, offset + 2));
}

#define CLASS_NULL			0
#define CLASS_LOCAL			1
#define CLASS_IP			2
#define CLASS_IEEE_802_1		3
#define CLASS_PPP_MAGIC_NUMBER		4
#define CLASS_PSDN_DIRECTORY_NUMBER	5

static const value_string multilink_ep_disc_class_vals[] = {
	{CLASS_NULL,                  "Null" },
	{CLASS_LOCAL,                 "Locally assigned address" },
	{CLASS_IP,                    "IP address" },
	{CLASS_IEEE_802_1,            "IEEE 802.1 globally assigned MAC address" },
	{CLASS_PPP_MAGIC_NUMBER,      "PPP magic-number block" },
	{CLASS_PSDN_DIRECTORY_NUMBER, "Public switched network directory number" },
	{0,                           NULL }
};

static void
dissect_lcp_multilink_ep_disc_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree = NULL;
  guint8 ep_disc_class;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
	  optp->name, length, plurality(length, "", "s"));
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  length -= 2;
  ep_disc_class = tvb_get_guint8(tvb, offset);
  proto_tree_add_text(field_tree, tvb, offset, 1, "Class: %s (%u)",
		val_to_str(ep_disc_class, multilink_ep_disc_class_vals, "Unknown"),
		ep_disc_class);
  offset += 1;
  length -= 1;
  if (length > 0) {
    switch (ep_disc_class) {

    case CLASS_NULL:
      proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s), should have been empty",
			length, plurality(length, "", "s"));
      break;

    case CLASS_LOCAL:
      if (length > 20) {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s), should have been <20",
			length, plurality(length, "", "s"));
      } else {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s)",
			length, plurality(length, "", "s"));
      }
      break;

    case CLASS_IP:
      if (length != 4) {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s), should have been 4",
			length, plurality(length, "", "s"));
      } else {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
      }
      break;

    case CLASS_IEEE_802_1:
      if (length != 6) {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s), should have been 6",
			length, plurality(length, "", "s"));
      } else {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address: %s", ether_to_str(tvb_get_ptr(tvb, offset, 6)));
      }
      break;

    case CLASS_PPP_MAGIC_NUMBER:
      /* XXX - dissect as 32-bit magic numbers */
      if (length > 20) {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s), should have been <20",
			length, plurality(length, "", "s"));
      } else {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s)",
			length, plurality(length, "", "s"));
      }
      break;

    case CLASS_PSDN_DIRECTORY_NUMBER:
      if (length > 15) {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s), should have been <20",
			length, plurality(length, "", "s"));
      } else {
        proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s)",
			length, plurality(length, "", "s"));
      }
      break;

    default:
      proto_tree_add_text(field_tree, tvb, offset, length,
			"Address (%d byte%s)",
			length, plurality(length, "", "s"));
      break;
    }
  }
}

static void
dissect_lcp_bap_link_discriminator_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length,
			"%s: 0x%04x", optp->name,
			tvb_get_ntohs(tvb, offset + 2));
}

/* Character set numbers from the IANA charset registry. */
static const value_string charset_num_vals[] = {
	{105, "UTF-8" },
	{0,   NULL }
};

static void
dissect_lcp_internationalization_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree = NULL;
  guint32 charset;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
	  optp->name, length, plurality(length, "", "s"));
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  length -= 2;
  charset = tvb_get_ntohl(tvb, offset);
  proto_tree_add_text(field_tree, tvb, offset, 4, "Character set: %s (0x%04x)",
		val_to_str(charset, charset_num_vals, "Unknown"),
		charset);
  offset += 4;
  length -= 4;
  if (length > 0) {
    /* XXX - should be displayed as an ASCII string */
    proto_tree_add_text(field_tree, tvb, offset, length, "Language tag (%d byte%s)",
			length, plurality(length, "", "s"));
  }
}

static void
dissect_ipcp_addrs_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree = NULL;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
	  optp->name, length, plurality(length, "", "s"));
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  offset += 2;
  length -= 2;
  proto_tree_add_text(field_tree, tvb, offset, 4,
			"Source IP address: %s",
			ip_to_str(tvb_get_ptr(tvb, offset, 4)));
  offset += 4;
  length -= 4;
  proto_tree_add_text(field_tree, tvb, offset, 4,
			"Destination IP address: %s",
			ip_to_str(tvb_get_ptr(tvb, offset, 4)));
}

static void dissect_ipcp_addr_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s: %s", optp->name,
			ip_to_str(tvb_get_ptr(tvb, offset + 2, 4)));
}

static void dissect_ipcp_compress_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
    guint8  ub;
    guint16 us;
    proto_item *tf;
    proto_tree *field_tree = NULL;

    tf = proto_tree_add_text(tree, tvb, offset, length, "%s: %u byte%s",
			     optp->name, length, plurality(length, "", "s"));

    field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
    offset += 2;	/* Skip option type + length */
    length -= 2;

    us = tvb_get_ntohs(tvb, offset);
    proto_tree_add_text( field_tree, tvb, offset, 2, "IP compression protocol: %s (0x%04x)",
			 val_to_str( us, ipcp_compress_proto_vals, "Unknown protocol" ),
			 us );
    offset += 2;	/* skip protocol */
    length -= 2;

    if (length > 0) {
	switch ( us ) {
	case IPCP_COMPRESS_VJ_1172:
	case IPCP_COMPRESS_VJ:
	    /* First byte is max slot id */
	    ub = tvb_get_guint8( tvb, offset );
	    proto_tree_add_text( field_tree, tvb, offset, 1,
				 "Max slot id: %u (0x%02x)",
				 ub, ub );
	    offset++;
	    length--;

	    if ( length > 0 ) {
		/* second byte is "compress slot id" */
		ub = tvb_get_guint8( tvb, offset );
		proto_tree_add_text( field_tree, tvb, offset, 1,
				     "Compress slot id: %s (0x%02x)",
				     ub ? "yes" : "no",  ub );
		offset++;
		length--;
	    }
	    break;

	    
	case IPCP_COMPRESS_IPHC:
	    if ( length < 2 ) {
		break;
	    }
	    us = tvb_get_ntohs(tvb, offset);
	    proto_tree_add_text( field_tree, tvb, offset, 2,
				 "TCP space: %u (0x%04x)",
				 us, us );
	    offset += 2;
	    length -= 2;


	    if ( length < 2 ) {
		break;
	    }
	    us = tvb_get_ntohs(tvb, offset);
	    proto_tree_add_text( field_tree, tvb, offset, 2,
				 "Non-TCP space: %u (0x%04x)",
				 us, us );
	    offset += 2;
	    length -= 2;


	    if ( length < 2 ) {
		break;
	    }
	    us = tvb_get_ntohs(tvb, offset);
	    proto_tree_add_text( field_tree, tvb, offset, 2,
				 "Max period: %u (0x%04x) compressed packets",
				 us, us );
	    offset += 2;
	    length -= 2;


	    if ( length < 2 ) {
		break;
	    }
	    us = tvb_get_ntohs(tvb, offset);
	    proto_tree_add_text( field_tree, tvb, offset, 2,
				 "Max time: %u (0x%04x) seconds",
				 us, us );
	    offset += 2;
	    length -= 2;


	    if ( length < 2 ) {
		break;
	    }
	    us = tvb_get_ntohs(tvb, offset);
	    proto_tree_add_text( field_tree, tvb, offset, 2,
				 "Max header: %u (0x%04x) bytes",
				 us, us );
	    offset += 2;
	    length -= 2;

	    if ( length > 0 ) {
		/* suboptions */
		tf = proto_tree_add_text(field_tree, tvb, offset, length,
					 "Suboptions: (%u byte%s)",
					 length, plurality(length, "", "s"));
		field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
		dissect_ip_tcp_options(tvb, offset, length,
				       ipcp_iphc_subopts, N_IPCP_IPHC_SUBOPTS, -1,
				       pinfo, field_tree);
	    }
	    return;
	}

	if (length > 0) {
	    proto_tree_add_text(field_tree, tvb, offset, length,
				"Data (%d byte%s)", length,
				plurality(length, "", "s"));
	}
    }
}

static void dissect_ipcp_iphc_disableprot_opt(const ip_tcp_opt *optp,
					      tvbuff_t *tvb,
					      int offset, guint length,
					      packet_info *pinfo _U_,
					      proto_tree *tree)
{
    proto_item *tf;
    proto_tree *field_tree;
    guint8 param;

    tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
    field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

    param = tvb_get_guint8(tvb, offset + 2);
    proto_tree_add_text(field_tree, tvb, offset + 2, 1,
			"Protocol: %s (0x%02x)",
			val_to_str( param, ipcp_iphc_disable_proto_vals, "Unknown" ),
			param );
}


static void dissect_osicp_align_npdu_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
                        int offset, guint length, packet_info *pinfo _U_,
                        proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  guint8 alignment;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  alignment = tvb_get_guint8(tvb, offset + 2);
  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
      "Alignment: %u", alignment);
}

static void dissect_pppmuxcp_def_pid_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  pppmux_def_prot_id = tvb_get_ntohs(tvb, offset + 2);
  proto_tree_add_text(tree, tvb, offset + 2, length - 2, "%s: %s (0x%02x)",optp->name,
		      val_to_str(pppmux_def_prot_id, ppp_vals, "Unknown"), pppmux_def_prot_id);
}


static void
dissect_ccp_stac_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  guint8 check_mode;

  if (length == 6) {
    proto_tree_add_text(tree, tvb, offset, length,
			"%s (Ascend Proprietary version)", optp->name);
    /* We don't know how to decode the following 4 octets, since
       there's no public document that describe their usage. */
  } else {
    tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
    field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

    proto_tree_add_text(field_tree, tvb, offset + 2, 2,
			"History Count: %u", tvb_get_ntohs(tvb, offset + 2));
    check_mode = tvb_get_guint8(tvb, offset + 4);
    proto_tree_add_text(field_tree, tvb, offset + 4, 1,
			"Check Mode: %s (0x%02X)",
			val_to_str(check_mode, stac_checkmode_vals, "Unknown"),
			check_mode);
  }
}

static void
dissect_ccp_mppc_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *flags_tree;
  guint32 supported_bits;

  supported_bits = tvb_get_ntohl(tvb, offset + 2);
  tf = proto_tree_add_text(tree, tvb, offset, length,
	      "%s: Supported Bits: 0x%08X", optp->name, supported_bits);
  flags_tree = proto_item_add_subtree(tf, *optp->subtree_index);
  proto_tree_add_text(flags_tree, tvb, offset + 2, 4, "%s",
      decode_boolean_bitfield(supported_bits, MPPC_SUPPORTED_BITS_C, 8*4,
      "Desire to negotiate MPPC", "NO Desire to negotiate MPPC"));
  proto_tree_add_text(flags_tree, tvb, offset + 2, 4, "%s",
      decode_boolean_bitfield(supported_bits, MPPE_SUPPORTED_BITS_D, 8*4,
      "Obsolete (should NOT be 1)", "Obsolete (should ALWAYS be 0)"));
  proto_tree_add_text(flags_tree, tvb, offset + 2, 4, "%s",
      decode_boolean_bitfield(supported_bits, MPPE_SUPPORTED_BITS_L, 8*4,
      "40-bit encryption ON", "40-bit encryption OFF"));
  proto_tree_add_text(flags_tree, tvb, offset + 2, 4, "%s",
      decode_boolean_bitfield(supported_bits, MPPE_SUPPORTED_BITS_S, 8*4,
      "128-bit encryption ON", "128-bit encryption OFF"));
  proto_tree_add_text(flags_tree, tvb, offset + 2, 4, "%s",
      decode_boolean_bitfield(supported_bits, MPPE_SUPPORTED_BITS_M, 8*4,
      "56-bit encryption ON", "56-bit encryption OFF"));
  proto_tree_add_text(flags_tree, tvb, offset + 2, 4, "%s",
      decode_boolean_bitfield(supported_bits, MPPE_SUPPORTED_BITS_H, 8*4,
      "Stateless mode ON", "Stateless mode OFF"));
}

static void
dissect_ccp_bsdcomp_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "Version: %u", tvb_get_guint8(tvb, offset + 2) >> 5);
  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "Dict: %u bits",
		      tvb_get_guint8(tvb, offset + 2) & 0x1f);
}

static void
dissect_ccp_lzsdcp_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  guint8 check_mode;
  guint8 process_mode;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  proto_tree_add_text(field_tree, tvb, offset + 2, 2,
		      "History Count: %u", tvb_get_ntohs(tvb, offset + 2));
  check_mode = tvb_get_guint8(tvb, offset + 4);
  proto_tree_add_text(field_tree, tvb, offset + 4, 1,
		      "Check Mode: %s (0x%02X)",
		      val_to_str(check_mode, lzsdcp_checkmode_vals, "Unknown"),
		      check_mode);
  process_mode = tvb_get_guint8(tvb, offset + 5);
  proto_tree_add_text(field_tree, tvb, offset + 5, 1,
		      "Process Mode: %s (0x%02X)",
		      val_to_str(process_mode, lzsdcp_processmode_vals, "Unkown"),
		      process_mode);
}

static void
dissect_ccp_mvrca_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "Features: %u", tvb_get_guint8(tvb, offset + 2) >> 5);
  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "Packet by Packet flag: %s",
		      tvb_get_guint8(tvb, offset + 2) & 0x20 ? "true" : "false");
  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "History: %u", tvb_get_guint8(tvb, offset + 2) & 0x20);
  proto_tree_add_text(field_tree, tvb, offset + 3, 1,
		      "Number of contexts: %u", tvb_get_guint8(tvb, offset + 3));
}

static void
dissect_ccp_deflate_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  guint8 method;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "Window: %u", hi_nibble(tvb_get_guint8(tvb, offset + 2)));
  method = lo_nibble(tvb_get_guint8(tvb, offset + 2));
  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "Method: %s (0x%02x)",
		      method == 0x08 ?  "zlib compression" : "other", method);
  proto_tree_add_text(field_tree, tvb, offset + 3, 1,
		      "Sequence number check method: %u",
		      tvb_get_guint8(tvb, offset + 2) & 0x03);
}

static void
dissect_cbcp_no_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
}

static void
dissect_cbcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  proto_item *ta;
  proto_tree *addr_tree;
  guint8 addr_type;
  guint addr_len;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
		      "Callback delay: %u", tvb_get_guint8(tvb, offset + 2));
  offset += 3;
  length -= 3;

  while (length > 0) {
    ta = proto_tree_add_text(field_tree, tvb, offset, length,
			     "Callback Address");
    addr_type = tvb_get_guint8(tvb, offset);
    addr_tree = proto_item_add_subtree(tf, ett_cbcp_callback_opt_addr);
    proto_tree_add_text(addr_tree, tvb, offset, 1,
			"Address Type: %s (%u)",
			((addr_type == 1) ? "PSTN/ISDN" : "Other"), addr_type);
    offset++;
    length--;
    addr_len = tvb_strsize(tvb, offset);
    if (addr_len > length) {
      proto_tree_add_text(addr_tree, tvb, offset, length,
			  "Address: (runs past end of option)");
      break;
    }
    proto_tree_add_text(addr_tree, tvb, offset, addr_len,
			"Address: %s",
			tvb_format_text(tvb, offset, addr_len - 1));
    offset += addr_len;
    length -= addr_len;
  }
}

static void
dissect_bacp_favored_peer_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  proto_tree_add_text(field_tree, tvb, offset + 2, 4,
		      "Magic number: 0x%08x", tvb_get_ntohl(tvb, offset + 2));
}

static void
dissect_bap_link_type_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  guint8 link_type;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  proto_tree_add_text(field_tree, tvb, offset + 2, 2,
	      "Link Speed: %u kbps", tvb_get_ntohs(tvb, offset + 2));
  link_type = tvb_get_guint8(tvb, offset + 4);
  proto_tree_add_text(field_tree, tvb, offset + 4, 1,
	      "Link Type: %s (%u)", val_to_str(link_type, bap_link_type_vals,
						"Unknown"), link_type);
}

static void
dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  proto_item *ti;
  proto_tree *suboption_tree;
  guint8 subopt_type;
  guint8 subopt_len;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  offset += 2;
  length -= 2;

  while (length > 0) {
    subopt_type = tvb_get_guint8(tvb, offset);
    subopt_len = tvb_get_guint8(tvb, offset + 1);
    ti = proto_tree_add_text(field_tree, tvb, offset, subopt_len,
		"Sub-Option (%u byte%s)",
		subopt_len, plurality(subopt_len, "", "s"));
    suboption_tree = proto_item_add_subtree(ti, ett_bap_phone_delta_subopt);

    proto_tree_add_text(suboption_tree, tvb, offset, 1,
	"Sub-Option Type: %s (%u)",
	val_to_str(subopt_type, bap_phone_delta_subopt_vals, "Unknown"),
	subopt_type);

    if (subopt_len < 2) {
      proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
	  "Sub-Option Length: %u (invalid, must be >= 2)", subopt_len);
      return;
    }
    if (subopt_len > length) {
      proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
	  "Sub-Option Length: %u (invalid, must be <= length remaining in option %u)", subopt_len, length);
      return;
    }

    proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
	"Sub-Option Length: %u", subopt_len);

    switch (subopt_type) {
    case BAP_PHONE_DELTA_SUBOPT_UNIQ_DIGIT:
      if (subopt_len == 3) {
        proto_tree_add_text(suboption_tree, tvb, offset + 2, 1, "Unique Digit: %u",
			    tvb_get_guint8(tvb, offset + 2));
      } else {
        proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
			  "Invalid suboption length: %u (must be == 3)",
			  subopt_len);
      }
      break;
    case BAP_PHONE_DELTA_SUBOPT_SUBSC_NUM:
      if (subopt_len > 2) {
        proto_tree_add_text(suboption_tree, tvb, offset + 2, subopt_len - 2,
			  "Subscriber Number: %s",
			  tvb_format_text(tvb, offset + 2, subopt_len - 2));
      } else {
        proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
			  "Invalid suboption length: %u (must be > 2)",
			  subopt_len);
      }
      break;
    case BAP_PHONE_DELTA_SUBOPT_PHONENUM_SUBADDR:
      if (subopt_len > 2) {
        proto_tree_add_text(suboption_tree, tvb, offset + 2, subopt_len - 2,
			  "Phone Number Sub Address: %s",
			  tvb_format_text(tvb, offset + 2, subopt_len - 2));
      } else {
        proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
			  "Invalid suboption length: %u (must be > 2)",
			  subopt_len);
      }
      break;
    default:
      if (subopt_len > 2) {
        proto_tree_add_text(suboption_tree, tvb, offset + 2, subopt_len - 2,
			  "Unknown");
      } else {
        proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
			  "Invalid suboption length: %u (must be > 2)",
			  subopt_len);
      }
      break;
    }
    offset += subopt_len;
    length -= subopt_len;
  }
}

static void
dissect_bap_reason_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  if (length > 2) {
    proto_tree_add_text(tree, tvb, offset, length, "%s: %s",
			   optp->name,
			   tvb_format_text(tvb, offset + 2, length - 2));
  }
}

static void
dissect_bap_link_disc_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s: 0x%04x",
		      optp->name, tvb_get_ntohs(tvb, offset + 2));
}

static void
dissect_bap_call_status_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_item *tf;
  proto_tree *field_tree;
  guint8 status, action;

  tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
  field_tree = proto_item_add_subtree(tf, *optp->subtree_index);

  status = tvb_get_guint8(tvb, offset + 2);
  proto_tree_add_text(field_tree, tvb, offset + 2, 1,
      "Status: %s (0x%02x)",
      val_to_str(status, q931_cause_code_vals, "Unknown"), status);

  action = tvb_get_guint8(tvb, offset + 3);
  proto_tree_add_text(field_tree, tvb, offset + 3, 1,
      "Action: %s (0x%02x)",
      val_to_str(action, bap_call_status_opt_action_vals, "Unknown"), action);
}

static void
dissect_cp( tvbuff_t *tvb, int proto_id, int proto_subtree_index,
	const value_string *proto_vals, int options_subtree_index,
	const ip_tcp_opt *opts, int nopts, packet_info *pinfo,
	proto_tree *tree )
{
  proto_item *ti;
  proto_tree *fh_tree = NULL;
  proto_item *tf;
  proto_tree *field_tree;

  guint8 code;
  guint8 id;
  int length, offset;
  guint16 protocol;

  code = tvb_get_guint8(tvb, 0);
  id = tvb_get_guint8(tvb, 1);
  length = tvb_get_ntohs(tvb, 2);

  if(check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL,
		proto_get_protocol_short_name(find_protocol_by_id(proto_id)));

  if(check_col(pinfo->cinfo, COL_INFO))
	col_add_str(pinfo->cinfo, COL_INFO,
		val_to_str(code, proto_vals, "Unknown"));

  if(tree) {
    ti = proto_tree_add_item(tree, proto_id, tvb, 0, length, FALSE);
    fh_tree = proto_item_add_subtree(ti, proto_subtree_index);
    proto_tree_add_text(fh_tree, tvb, 0, 1, "Code: %s (0x%02x)",
      val_to_str(code, proto_vals, "Unknown"), code);
    proto_tree_add_text(fh_tree, tvb, 1, 1, "Identifier: 0x%02x",
			id);
    proto_tree_add_text(fh_tree, tvb, 2, 2, "Length: %u",
			length);
  }
  offset = 4;
  length -= 4;

  switch (code) {
    case CONFREQ:
    case CONFACK:
    case CONFNAK:
    case CONFREJ:
      if(tree) {
        if (length > 0) {
          tf = proto_tree_add_text(fh_tree, tvb, offset, length,
            "Options: (%d byte%s)", length, plurality(length, "", "s"));
          field_tree = proto_item_add_subtree(tf, options_subtree_index);
          dissect_ip_tcp_options(tvb, offset, length, opts, nopts, -1,
				 pinfo, field_tree);
        }
      }
      break;

    case ECHOREQ:
    case ECHOREP:
    case DISCREQ:
    case IDENT:
      if(tree) {
	proto_tree_add_text(fh_tree, tvb, offset, 4, "Magic number: 0x%08x",
			tvb_get_ntohl(tvb, offset));
	offset += 4;
	length -= 4;
	if (length > 0)
          proto_tree_add_text(fh_tree, tvb, offset, length, "Message (%d byte%s)",
				length, plurality(length, "", "s"));
      }
      break;

    case TIMEREMAIN:
      if(tree) {
	proto_tree_add_text(fh_tree, tvb, offset, 4, "Magic number: 0x%08x",
			tvb_get_ntohl(tvb, offset));
	offset += 4;
	length -= 4;
	proto_tree_add_text(fh_tree, tvb, offset, 4, "Seconds remaining: %u",
			tvb_get_ntohl(tvb, offset));
	offset += 4;
	length -= 4;
	if (length > 0)
          proto_tree_add_text(fh_tree, tvb, offset, length, "Message (%d byte%s)",
				length, plurality(length, "", "s"));
      }
      break;

    case PROTREJ:
      if(tree) {
	gboolean save_in_error_pkt;
	tvbuff_t *next_tvb;

	protocol = tvb_get_ntohs(tvb, offset);
	proto_tree_add_text(fh_tree, tvb, offset, 2,
			    "Rejected protocol: %s (0x%04x)",
			    val_to_str(protocol, ppp_vals, "Unknown"),
			    protocol);
	offset += 2;
	length -= 2;
	if (length > 0) {
          proto_tree_add_text(fh_tree, tvb, offset, length,
			      "Rejected packet (%d byte%s)",
			      length, plurality(length, "", "s"));

	  /* Save the current value of the "we're inside an error packet"
	     flag, and set that flag; subdissectors may treat packets
	     that are the payload of error packets differently from
	     "real" packets. */
	  save_in_error_pkt = pinfo->in_error_pkt;
	  pinfo->in_error_pkt = TRUE;

	  /* Decode the rejected packet. */
	  next_tvb = tvb_new_subset(tvb, offset, length, length);
	  if (!dissector_try_port(ppp_subdissector_table, protocol,
				  next_tvb, pinfo, fh_tree)) {
	    call_dissector(data_handle, next_tvb, pinfo, fh_tree);
	  }

	  /* Restore the "we're inside an error packet" flag. */
	  pinfo->in_error_pkt = save_in_error_pkt;
        }
      }
      break;

    case CODEREJ:
		/* decode the rejected LCP packet here. */
      if (length > 0)
        proto_tree_add_text(fh_tree, tvb, offset, length, "Rejected packet (%d byte%s)",
				length, plurality(length, "", "s"));
      break;

    case TERMREQ:
    case TERMACK:
      if (length > 0)
        proto_tree_add_text(fh_tree, tvb, offset, length, "Data (%d byte%s)",
				length, plurality(length, "", "s"));
      break;

    default:
      if (length > 0)
        proto_tree_add_text(fh_tree, tvb, offset, length, "Stuff (%d byte%s)",
				length, plurality(length, "", "s"));
      break;
  }
}

/* Protocol field compression */
#define PFC_BIT 0x01

static void
dissect_ppp_common( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		proto_tree *fh_tree, proto_item *ti, int proto_offset )
{
  guint16 ppp_prot;
  int     proto_len;
  tvbuff_t	*next_tvb;

  ppp_prot = tvb_get_guint8(tvb, 0);
  if (ppp_prot & PFC_BIT) {
    /* Compressed protocol field - just the byte we fetched. */
    proto_len = 1;
  } else {
    /* Uncompressed protocol field - fetch all of it. */
    ppp_prot = tvb_get_ntohs(tvb, 0);
    proto_len = 2;
  }

  /* If "ti" is not null, it refers to the top-level "proto_ppp" item
     for PPP, and proto_offset is the length of any stuff in the header
     preceding the protocol type, e.g. an HDLC header; add the length
     of the protocol type field to it, and set the length of that item
     to the result. */
  if (ti != NULL)
    proto_item_set_len(ti, proto_offset + proto_len);

  if (tree)
    proto_tree_add_uint(fh_tree, hf_ppp_protocol, tvb, 0, proto_len, ppp_prot);

  next_tvb = tvb_new_subset(tvb, proto_len, -1, -1);

  /* do lookup with the subdissector table */
  if (!dissector_try_port(ppp_subdissector_table, ppp_prot, next_tvb, pinfo, tree)) {
    if (check_col(pinfo->cinfo, COL_PROTOCOL))
      col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "0x%04x", ppp_prot);
    if (check_col(pinfo->cinfo, COL_INFO))
      col_add_fstr(pinfo->cinfo, COL_INFO, "PPP %s (0x%04x)",
		   val_to_str(ppp_prot, ppp_vals, "Unknown"), ppp_prot);
    call_dissector(data_handle,next_tvb, pinfo, tree);
  }
}

static void
dissect_lcp_options(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_ip_tcp_options(tvb, 0, tvb_reported_length(tvb), lcp_opts, N_LCP_OPTS, 
            -1, pinfo, tree);
}

/*
 * RFC 1661.
 */
static void
dissect_lcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_lcp, ett_lcp, lcp_vals, ett_lcp_options,
	     lcp_opts, N_LCP_OPTS, pinfo, tree);
}

/*
 * RFC 1332.
 */
static void
dissect_ipcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_ipcp, ett_ipcp, cp_vals, ett_ipcp_options,
	     ipcp_opts, N_IPCP_OPTS, pinfo, tree);
}

/*
 * RFC 1377.
 */
static void
dissect_osicp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_osicp, ett_osicp, cp_vals, ett_osicp_options,
             osicp_opts, N_OSICP_OPTS, pinfo, tree);
}

/*
 * RFC 1962.
 */
static void
dissect_ccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_ccp, ett_ccp, ccp_vals, ett_ccp_options,
	     ccp_opts, N_CCP_OPTS, pinfo, tree);
}

/*
 * Callback Control Protocol - see
 *
 *	http://www.linet.gr.jp/~manabe/PPxP/doc/Standards/draft-gidwani-ppp-callback-cp-00.txt
 */
static void
dissect_cbcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_cbcp, ett_cbcp, cbcp_vals, ett_cbcp_options,
	     cbcp_opts, N_CBCP_OPTS, pinfo, tree);
}

/*
 * RFC 2125 (BACP and BAP).
 */
static void
dissect_bacp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_bacp, ett_bacp, cp_vals, ett_bacp_options,
	     bacp_opts, N_BACP_OPTS, pinfo, tree);
}

static void
dissect_bap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_item *ti;
  proto_tree *fh_tree = NULL;
  proto_item *tf;
  proto_tree *field_tree;

  guint8 type;
  guint8 id;
  int length, offset;
  guint8 resp_code;

  type = tvb_get_guint8(tvb, 0);
  id = tvb_get_guint8(tvb, 1);
  length = tvb_get_ntohs(tvb, 2);

  if(check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP BAP");

  if(check_col(pinfo->cinfo, COL_INFO))
	col_add_str(pinfo->cinfo, COL_INFO,
		val_to_str(type, bap_vals, "Unknown"));

  if(tree) {
    ti = proto_tree_add_item(tree, proto_bap, tvb, 0, length, FALSE);
    fh_tree = proto_item_add_subtree(ti, ett_bap_options);
    proto_tree_add_text(fh_tree, tvb, 0, 1, "Type: %s (0x%02x)",
      val_to_str(type, bap_vals, "Unknown"), type);
    proto_tree_add_text(fh_tree, tvb, 1, 1, "Identifier: 0x%02x",
			id);
    proto_tree_add_text(fh_tree, tvb, 2, 2, "Length: %u",
			length);
  }
  offset = 4;
  length -= 4;

  if (type == BAP_CRES || type == BAP_CBRES ||
      type == BAP_LDQRES || type == BAP_CSRES) {
    resp_code = tvb_get_guint8(tvb, offset);
    proto_tree_add_text(fh_tree, tvb, offset, 1, "Response Code: %s (0x%02x)",
	val_to_str(resp_code, bap_resp_code_vals, "Unknown"), resp_code);
    offset++;
    length--;
  }

  if(tree) {
    if (length > 0) {
      tf = proto_tree_add_text(fh_tree, tvb, offset, length,
	       "Data (%d byte%s)", length, plurality(length, "", "s"));
      field_tree = proto_item_add_subtree(tf, ett_bap_options);
      dissect_ip_tcp_options(tvb, offset, length, bap_opts, N_BAP_OPTS, -1,
			     pinfo, field_tree);
    }
  }
}

static void
dissect_comp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_item *ti;
  proto_tree *comp_data_tree;

  if (check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP Comp");

  if(check_col(pinfo->cinfo, COL_INFO))
    col_set_str(pinfo->cinfo, COL_INFO, "Compressed data");

  if (tree) {
    ti = proto_tree_add_item(tree, proto_comp_data, tvb, 0, -1, FALSE);
    comp_data_tree = proto_item_add_subtree(ti, ett_comp_data);
  }
}

/*
 * RFC 3153 (both PPPMuxCP and PPPMux).
 */
static void
dissect_pppmuxcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb,proto_pppmuxcp,ett_pppmuxcp,pppmuxcp_vals,
	     ett_pppmuxcp_options,pppmuxcp_opts,N_PPPMUXCP_OPTS,pinfo,tree);
}

#define PPPMUX_FLAGS_MASK          0xc0
#define PPPMUX_PFF_BIT_SET         0x80
#define PPPMUX_LXT_BIT_SET         0x40

static void
dissect_pppmux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_tree *mux_tree, *hdr_tree, *sub_tree, *flag_tree;
  proto_tree *info_tree;
  proto_item *ti = NULL,*sub_ti = NULL;
  guint8 flags, byte;
  guint16 length;
  static guint16 pid;
  tvbuff_t *next_tvb;
  int offset = 0, length_remaining;
  int length_field = 0, pid_field = 0,hdr_length = 0;

  if (check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo,COL_PROTOCOL, "PPP PPPMux");

  if (check_col(pinfo->cinfo, COL_INFO))
    col_set_str(pinfo->cinfo, COL_INFO, "PPP Multiplexing");

  length_remaining = tvb_reported_length(tvb);

  if (tree) {
    ti = proto_tree_add_item(tree, proto_pppmux, tvb, 0, -1, FALSE);
    mux_tree = proto_item_add_subtree(ti,ett_pppmux);

    while (length_remaining > 0) {

      flags = tvb_get_guint8(tvb,offset) & PPPMUX_FLAGS_MASK;

      if (flags && PPPMUX_LXT_BIT_SET ) {
	length = tvb_get_ntohs(tvb,offset) & 0x3fff;
	length_field = 2;
      } else {
	length = tvb_get_guint8(tvb,offset) & 0x3f;
	length_field = 1;
      }

      if (flags && PPPMUX_PFF_BIT_SET) {
	byte = tvb_get_guint8(tvb,offset + length_field);
	if (byte && PFC_BIT) {		  /* Compressed PID field*/
	  pid = byte;
	  pid_field = 1;
	} else {		  /*PID field is 2 bytes*/
	  pid = tvb_get_ntohs(tvb,offset + length_field);
	  pid_field = 2;
	}
      } else {
	if (!pid){	 /*No Last PID, hence use the default */
	  if (pppmux_def_prot_id)
	    pid = pppmux_def_prot_id;
	}
      }

      hdr_length = length_field + pid_field;

      ti = proto_tree_add_text(mux_tree, tvb, offset, length + length_field,
			       "PPPMux Sub-frame");
      sub_tree = proto_item_add_subtree(ti,ett_pppmux_subframe);
      sub_ti = proto_tree_add_text(sub_tree, tvb, offset,
				   hdr_length,"Header field");

      hdr_tree = proto_item_add_subtree(sub_ti,ett_pppmux_subframe_hdr);
      ti = proto_tree_add_text(hdr_tree, tvb, offset, length_field, "PFF/LXT: 0x%02X",
			       flags);

      flag_tree = proto_item_add_subtree(ti,ett_pppmux_subframe_flags);
      proto_tree_add_text(flag_tree,tvb,offset,length_field,"%s",
			  decode_boolean_bitfield(flags,0x80,8,"PID Present","PID not present"));
      proto_tree_add_text(flag_tree,tvb,offset,length_field,"%s",
			  decode_boolean_bitfield(flags,0x40,8,"2 bytes ength field ","1 byte length field"));

      ti = proto_tree_add_text(hdr_tree,tvb,offset,length_field,"Sub-frame Length = %u",length);

      if (flags && PPPMUX_PFF_BIT_SET)
	proto_tree_add_text(hdr_tree,tvb,offset + length_field,pid_field,"%s: %s(0x%02x)",
			    "Protocol ID",val_to_str(pid,ppp_vals,"Unknown"), pid);

      offset += hdr_length;
      length_remaining -= hdr_length;
      length -= pid_field;

      sub_ti = proto_tree_add_text(sub_tree,tvb,offset,length,"Information Field");
      info_tree = proto_item_add_subtree(sub_ti,ett_pppmux_subframe_info);

      next_tvb = tvb_new_subset(tvb,offset,length,-1);

      if (!dissector_try_port(ppp_subdissector_table, pid, next_tvb, pinfo, info_tree)) {
	call_dissector(data_handle, next_tvb, pinfo, info_tree);
      }
      offset += length;
      length_remaining -= length;
    }  /* While length_remaining */
    pid = 0;
  } /* if tree */
}

/*
 * RFC 3032.
 */
static void
dissect_mplscp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_mplscp, ett_mplscp, cp_vals, ett_mplscp_options,
	     NULL, 0, pinfo, tree);
}

/*
 * Cisco Discovery Protocol Control Protocol.
 * XXX - where is this documented?
 */
static void
dissect_cdpcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_cdpcp, ett_cdpcp, cp_vals, ett_cdpcp_options,
	     NULL, 0, pinfo, tree);
}

#define MP_FRAG_MASK     0xC0
#define MP_FRAG(bits)    ((bits) & MP_FRAG_MASK)
#define MP_FRAG_FIRST    0x80
#define MP_FRAG_LAST     0x40
#define MP_FRAG_RESERVED 0x3f

static const true_false_string frag_truth = {
  "Yes",
  "No"
};

/* According to RFC 1717, the length the MP header isn't indicated anywhere
   in the header itself.  It starts out at four bytes and can be
   negotiated down to two using LCP.  We currently assume that all
   headers are four bytes.  - gcc
 */
static void
dissect_mp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_tree *mp_tree, *hdr_tree;
  proto_item *ti = NULL;
  guint8      flags;
  gchar      *flag_str;
  tvbuff_t   *next_tvb;

  if (check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP MP");

  if (check_col(pinfo->cinfo, COL_INFO))
    col_set_str(pinfo->cinfo, COL_INFO, "PPP Multilink");

  flags = tvb_get_guint8(tvb, 0);

  if (tree) {
    switch (flags) {
      case MP_FRAG_FIRST:
        flag_str = "First";
        break;
      case MP_FRAG_LAST:
        flag_str = "Last";
        break;
      case MP_FRAG_FIRST|MP_FRAG_LAST:
        flag_str = "First, Last";
        break;
      default:
        flag_str = "Unknown";
        break;
    }
    ti = proto_tree_add_item(tree, proto_mp, tvb, 0, 4, FALSE);
    mp_tree = proto_item_add_subtree(ti, ett_mp);
    ti = proto_tree_add_text(mp_tree, tvb, 0, 1, "Fragment: 0x%2X (%s)",
      flags, flag_str);
    hdr_tree = proto_item_add_subtree(ti, ett_mp_flags);
    proto_tree_add_boolean(hdr_tree, hf_mp_frag_first, tvb, 0, 1, flags);
    proto_tree_add_boolean(hdr_tree, hf_mp_frag_last, tvb, 0, 1, flags),
    proto_tree_add_text(hdr_tree, tvb, 0, 1, "%s",
      decode_boolean_bitfield(flags, MP_FRAG_RESERVED, sizeof(flags) * 8,
        "reserved", "reserved"));
    proto_tree_add_item(mp_tree, hf_mp_sequence_num, tvb,  1, 3, FALSE);
  }

  if (tvb_reported_length_remaining(tvb, 4) > 0) {
    next_tvb = tvb_new_subset(tvb, 4, -1, -1);
    dissect_ppp(next_tvb, pinfo, tree);
  }
}

/*
 * Handles PPP without HDLC framing, just a protocol field (RFC 1661).
 */
static void
dissect_ppp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree ) {
  proto_item *ti = NULL;
  proto_tree *fh_tree = NULL;

  if(tree) {
    ti = proto_tree_add_item(tree, proto_ppp, tvb, 0, -1, FALSE);
    fh_tree = proto_item_add_subtree(ti, ett_ppp);
  }

  dissect_ppp_common(tvb, pinfo, tree, fh_tree, ti, 0);
}

static void
dissect_ppp_hdlc_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_item *ti = NULL;
  proto_tree *fh_tree = NULL;
  guint8     byte0;
  int        proto_offset;
  tvbuff_t  *next_tvb;

  byte0 = tvb_get_guint8(tvb, 0);

  /* PPP HDLC encapsulation */
  if (byte0 == 0xff)
    proto_offset = 2;
  else {
    /* address and control are compressed (NULL) */
    proto_offset = 0;
  }

  /* load the top pane info. This should be overwritten by
     the next protocol in the stack */
  if(tree) {
    ti = proto_tree_add_item(tree, proto_ppp, tvb, 0, -1, FALSE);
    fh_tree = proto_item_add_subtree(ti, ett_ppp);
    if (byte0 == 0xff) {
      proto_tree_add_item(fh_tree, hf_ppp_address, tvb, 0, 1, FALSE);
      proto_tree_add_item(fh_tree, hf_ppp_control, tvb, 1, 1, FALSE);
    }
  }

  next_tvb = decode_fcs(tvb, fh_tree, ppp_fcs_decode, proto_offset);

  dissect_ppp_common(next_tvb, pinfo, tree, fh_tree, ti, proto_offset);
}

/*
 * Handles link-layer encapsulations where the frame might be
 * a PPP in HDLC-like Framing frame (RFC 1662) or a Cisco HDLC frame.
 */
static void
dissect_ppp_hdlc( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
{
  guint8     byte0;

  byte0 = tvb_get_guint8(tvb, 0);
  if (byte0 == CHDLC_ADDR_UNICAST || byte0 == CHDLC_ADDR_MULTICAST) {
    /* Cisco HDLC encapsulation */
    call_dissector(chdlc_handle, tvb, pinfo, tree);
    return;
  }

  /*
   * XXX - should we have an exported dissector that always dissects PPP,
   * for use when we know the packets are PPP, not CHDLC?
   */
  if(check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP");
  switch (pinfo->p2p_dir) {

  case P2P_DIR_SENT:
    if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
      col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
    if(check_col(pinfo->cinfo, COL_RES_DL_DST))
      col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
    break;

  case P2P_DIR_RECV:
    if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
      col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
    if(check_col(pinfo->cinfo, COL_RES_DL_DST))
      col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
    break;

  default:
    if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
      col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A");
    if(check_col(pinfo->cinfo, COL_RES_DL_DST))
      col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
    break;
  }

  dissect_ppp_hdlc_common(tvb, pinfo, tree);
}

static tvbuff_t*
remove_escape_chars(tvbuff_t *tvb, int offset, int length)
{
  guint8	*buff;
  int		i;
  int		scanned_len = 0;
  guint8	octet;
  tvbuff_t  *next_tvb;
	
  buff = g_malloc(length);
  i = 0;
  while ( scanned_len < length ){
	  octet = tvb_get_guint8(tvb,offset);
	  if (octet == 0x7d){
		  offset++;
		  scanned_len++;
		  if (scanned_len >= length)
			  break;
		  octet = tvb_get_guint8(tvb,offset);
		  buff[i] = octet ^ 0x20;
	  }else{
		  buff[i]= octet;
	  }
	  offset++;
	  scanned_len++;
	  i++;
  }
  if (i == 0)
	  return NULL;
  next_tvb = tvb_new_real_data(buff,i,i);

  /* Arrange that the allocated packet data copy be freed when the
   * tvbuff is freed. 
   */
  tvb_set_free_cb( next_tvb, g_free );

  tvb_set_child_real_data_tvbuff(tvb,next_tvb);
  return next_tvb;

}

/*
 * Handles link-layer encapsulations where we have a raw RFC 1662
 * HDLC-like asynchronous framing byte stream, and have to
 * break the byte stream into frames and remove escapes.
 */
static void
dissect_ppp_raw_hdlc( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
{
  proto_item *ti;
  proto_tree *bs_tree = NULL;
  gint	      offset, end_offset, data_offset;
  int	      length, data_length;
  tvbuff_t   *ppp_tvb;
  gboolean    first = TRUE;

  if(check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP" );

  if (tree) {
    ti = proto_tree_add_item(tree, proto_ppp_hdlc, tvb, 0, -1, FALSE);
    bs_tree = proto_item_add_subtree(ti, ett_ppp_hdlc_data);
  }

  /*
   * XXX - this needs to handle a PPP frame split over multiple higher-level
   * packets.
   */

  /*
   * Look for a frame delimiter.
   */
  offset = tvb_find_guint8(tvb, 0, -1, 0x7e);
  if (offset == -1) {
	  /*
	   * None found - this is presumably continued from an earlier
	   * packet and continued in a later packet.
	   */
	  if (check_col(pinfo->cinfo, COL_INFO)){
		  col_add_str(pinfo->cinfo, COL_INFO,"PPP Fragment");
	  }
	  if (tree)
		  proto_tree_add_text(bs_tree, tvb, offset, -1, "PPP Fragment");
	  offset++;
	  length = tvb_length_remaining(tvb,offset);
	  ppp_tvb = remove_escape_chars(tvb, offset,length);
	  if (ppp_tvb != NULL) {
		  add_new_data_source(pinfo, ppp_tvb, "PPP Fragment");
		  call_dissector(data_handle, ppp_tvb, pinfo, tree);
	  }
	  return;
  }
  if (offset != 0) {
  	  /*
  	   * We have some data preceding the first PPP packet;
  	   * mark it as a PPP fragment.
  	   */
	  if(check_col(pinfo->cinfo, COL_INFO)){
		  col_add_str(pinfo->cinfo, COL_INFO,"PPP Fragment");
	  }
	  length = offset;
	  if (tree)
		  proto_tree_add_text(bs_tree, tvb, 0, length, "PPP Fragment");
	  if (length != 0) {
		  ppp_tvb = remove_escape_chars(tvb, 0, length - 1);
		  if (ppp_tvb != NULL) {
			  add_new_data_source(pinfo, ppp_tvb, "PPP Fragment");
			  call_dissector(data_handle, ppp_tvb, pinfo, tree);
		  }
	  }
  }
  while ( tvb_reported_length_remaining(tvb, offset) > 0 ){
	  /*
	   * Look for the next frame delimiter.
	   */
	  end_offset = tvb_find_guint8(tvb, offset+1, -1, 0x7e);
	  if ( end_offset == -1 ){
	  	  /*
	  	   * We didn't find one.  This is probably continued in
	  	   * a later packet.
	  	   */
		  if (first) {
			  if(check_col(pinfo->cinfo, COL_INFO)){
				  col_add_str(pinfo->cinfo, COL_INFO,"PPP Fragment");
			  }
		  }
		  if (tree)
			  proto_tree_add_text(bs_tree, tvb, offset, -1, "PPP Fragment");
		  offset++;
		  length = tvb_length_remaining(tvb, offset);
		  ppp_tvb = remove_escape_chars(tvb, offset,length);
		  if (ppp_tvb != NULL) {
			  add_new_data_source(pinfo, ppp_tvb, "PPP Fragment");
			  call_dissector(data_handle, ppp_tvb, pinfo, tree);
		  }
		  return;
	  }

	  data_offset = offset+1;	/* skip starting frame delimiter */
	  data_length = end_offset - data_offset;

	  /*
	   * Is that frame delimiter immediately followed by another one?
	   * Some PPP implementations put a frame delimiter at the
	   * beginning and the end of each frame, although RFC 1662
	   * appears only to require that there be one frame delimiter
	   * between adjacent frames:
	   *
	   *  Each frame begins and ends with a Flag Sequence, which is the
	   *  binary sequence 01111110 (hexadecimal 0x7e).  All implementations
	   *  continuously check for this flag, which is used for frame
	   *  synchronization.
	   *
	   *  Only one Flag Sequence is required between two frames.  Two
	   *  consecutive Flag Sequences constitute an empty frame, which is
	   *  silently discarded, and not counted as a FCS error.
	   *
	   * If the delimiter at the end of this frame is followed by
	   * another delimiter, we consider the first delimiter part
	   * of this frame.
	   */
	  if (tvb_offset_exists(tvb, end_offset+1) &&
	      tvb_get_guint8(tvb, end_offset+1) == 0x7e)
		  end_offset++;
	  length = end_offset - offset;
	  if (tree)
		  proto_tree_add_text(bs_tree, tvb, offset, length, "PPP Data");
	  if (length > 1) {
		  ppp_tvb = remove_escape_chars(tvb, data_offset, data_length);
		  if (ppp_tvb != NULL) {
			  add_new_data_source(pinfo, ppp_tvb, "PPP Message");
			  dissect_ppp_hdlc_common(ppp_tvb, pinfo, tree);
			  first = FALSE;
		  }
	  }
	  offset = end_offset;
  } /* end while */
}

void
proto_register_ppp_raw_hdlc(void)
{
  static gint *ett[] = {
    &ett_ppp_hdlc_data
  };

  proto_ppp_hdlc = proto_register_protocol("PPP In HDLC-Like Framing", "PPP-HDLC", "ppp_hdlc");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_ppp_raw_hdlc(void)
{
  dissector_handle_t ppp_raw_hdlc_handle;

  ppp_raw_hdlc_handle = create_dissector_handle(dissect_ppp_raw_hdlc, proto_ppp);
  dissector_add("gre.proto", ETHERTYPE_CDMA2000_A10_UBS, ppp_raw_hdlc_handle);
}

/*
 * Handles PAP just as a protocol field
 */
static void
dissect_pap( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree ) {
  proto_item *ti;
  proto_tree *fh_tree = NULL;
  proto_item *tf;
  proto_tree *field_tree;
  proto_item *tm;
  proto_tree *message_tree;
  proto_item *tp;
  proto_tree *peer_id_tree;
  proto_item *tpw;
  proto_tree *passwd_tree;

  guint8 code;
  guint8 id, peer_id_length, password_length, msg_length;
  int length, offset;

  code = tvb_get_guint8(tvb, 0);
  id = tvb_get_guint8(tvb, 1);
  length = tvb_get_ntohs(tvb, 2);

  if(check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP PAP");

  if(check_col(pinfo->cinfo, COL_INFO))
	col_add_str(pinfo->cinfo, COL_INFO,
		val_to_str(code, pap_vals, "Unknown"));

  if(tree) {
    ti = proto_tree_add_item(tree, proto_pap, tvb, 0, length, FALSE);
    fh_tree = proto_item_add_subtree(ti, ett_pap);
    proto_tree_add_text(fh_tree, tvb, 0, 1, "Code: %s (0x%02x)",
      val_to_str(code, pap_vals, "Unknown"), code);
    proto_tree_add_text(fh_tree, tvb, 1, 1, "Identifier: 0x%02x",
			id);
    proto_tree_add_text(fh_tree, tvb, 2, 2, "Length: %u",
			length);
  }
  offset = 4;
  length -= 4;

  switch (code) {
    case CONFREQ:
      if(tree) {
        if (length > 0) {
          tf = proto_tree_add_text(fh_tree, tvb, offset, length,
            "Data (%d byte%s)", length, plurality(length, "", "s"));
          field_tree = proto_item_add_subtree(tf, ett_pap_data);
		  peer_id_length = tvb_get_guint8(tvb, offset);
		  tp = proto_tree_add_text(field_tree, tvb, offset,      1,
              "Peer ID length: %d byte%s", peer_id_length, plurality(peer_id_length, "", "s"));
		  if (--length > 0) {
			  peer_id_tree = proto_item_add_subtree(tp, ett_pap_peer_id);
			  proto_tree_add_text(peer_id_tree, tvb, ++offset, ppp_min(peer_id_length, length),
              "Peer-ID (%d byte%s)", peer_id_length, plurality(peer_id_length, "", "s"));
			  offset+=peer_id_length;
			  length-=peer_id_length;
			  if (length > 0) {
				password_length = tvb_get_guint8(tvb, offset);
				if (--length > 0) {
					tpw = proto_tree_add_text(field_tree, tvb, offset,      1,
						"Password length: %d byte%s", password_length, plurality(password_length, "", "s"));
					passwd_tree = proto_item_add_subtree(tpw, ett_pap_password);
					proto_tree_add_text(passwd_tree, tvb, ++offset, ppp_min(password_length, length),
						"Password (%d byte%s)", password_length, plurality(password_length, "", "s"));
				}
			  }
		  }
        }
      }
      break;

    case CONFACK:
    case CONFNAK:
      if(tree) {
        if (length > 0) {
          tf = proto_tree_add_text(fh_tree, tvb, offset, length,
            "Data (%d byte%s)", length, plurality(length, "", "s"));
          field_tree = proto_item_add_subtree(tf, ett_pap_data);
		  msg_length = tvb_get_guint8(tvb, offset);
		  tm = proto_tree_add_text(field_tree, tvb, offset,      1,
              "Message length: %d byte%s", msg_length, plurality(msg_length, "", "s"));
		  if (--length > 0) {
			message_tree = proto_item_add_subtree(tm, ett_pap_message);
		    proto_tree_add_text(message_tree, tvb, ++offset, ppp_min(msg_length, length),
              "Message (%d byte%s)", msg_length, plurality(msg_length, "", "s"));
		  }
        }
      }
      break;
    default:
      if (length > 0)
        proto_tree_add_text(fh_tree, tvb, offset, length, "Stuff (%d byte%s)",
				length, plurality(length, "", "s"));
      break;
  }
}

/*
 * Handles CHAP just as a protocol field
 */
static void
dissect_chap( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree ) {
  proto_item *ti;
  proto_tree *fh_tree = NULL;
  proto_item *tf;
  proto_tree *field_tree;
  proto_item *tv;
  proto_tree *value_tree;

  guint8 code, id, value_size;
  gint32 length;
  int offset;

  code = tvb_get_guint8(tvb, 0);
  id = tvb_get_guint8(tvb, 1);
  length = tvb_get_ntohs(tvb, 2);

  if(check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PPP CHAP");

  if(check_col(pinfo->cinfo, COL_INFO))
	col_add_str(pinfo->cinfo, COL_INFO,
		val_to_str(code, chap_vals, "Unknown"));

  if(tree) {
    ti = proto_tree_add_item(tree, proto_chap, tvb, 0, length, FALSE);
    fh_tree = proto_item_add_subtree(ti, ett_chap);
    proto_tree_add_text(fh_tree, tvb, 0, 1, "Code: %s (0x%02x)",
      val_to_str(code, chap_vals, "Unknown"), code);
    proto_tree_add_text(fh_tree, tvb, 1, 1, "Identifier: 0x%02x",
			id);
  }
  if(length < 4) {
    if(tree) {
      proto_tree_add_text(fh_tree, tvb, 2, 2, "Length: %u (invalid, must be >= 4)",
			  length);
      return;
    }
  }
  if(tree) {
    proto_tree_add_text(fh_tree, tvb, 2, 2, "Length: %u",
			length);
  }
  offset = 4;
  length -= 4;

  switch (code) {
    case CHAP_CHAL:
    case CHAP_RESP:
      if(tree) {
        if (length > 0) {
          tf = proto_tree_add_text(fh_tree, tvb, offset, length,
				   "Data (%d byte%s)", length,
				   plurality(length, "", "s"));
          field_tree = proto_item_add_subtree(tf, ett_chap_data);
	  value_size = tvb_get_guint8(tvb, offset);
	  length--;
	  if (value_size > length) {
	    proto_tree_add_text(field_tree, tvb, offset, 1,
				"Value Size: %d byte%s (invalid, must be <= %u)",
				value_size, plurality(value_size, "", "s"),
				length);
	    return;
	  }
	  tv = proto_tree_add_text(field_tree, tvb, offset, 1,
				  "Value Size: %u byte%s",
				  value_size, plurality(value_size, "", "s"));
	  offset++;
	  if (length > 0) {
	    value_tree = proto_item_add_subtree(tv, ett_chap_value);
	    proto_tree_add_text(value_tree, tvb, offset, value_size,
				"Value (%u byte%s)",
				value_size, plurality(value_size, "", "s"));
	    offset+=value_size;
	    length-=value_size;
	    if (length > 0) {
		  tvb_ensure_bytes_exist(tvb, offset, length);
	      proto_tree_add_text(field_tree, tvb, offset, length,
				  "Name (%u byte%s)", length,
				  plurality(length, "", "s"));
	    }
	  }
        }
      }
      break;

    case CHAP_SUCC:
    case CHAP_FAIL:
      if(tree) {
        if (length > 0) {
          tf = proto_tree_add_text(fh_tree, tvb, offset, length,
				   "Data (%u byte%s)", length,
				   plurality(length, "", "s"));
          field_tree = proto_item_add_subtree(tf, ett_chap_data);
	  tv = proto_tree_add_text(field_tree, tvb, offset, length,
				   "Message: %u byte%s",
				   length, plurality(length, "", "s"));
	}
      }
      break;
    default:
      if (length > 0)
        proto_tree_add_text(fh_tree, tvb, offset, length, "Stuff (%u byte%s)",
				length, plurality(length, "", "s"));
      break;
  }
}

/*
 * RFC 2472.
 */
static void
dissect_ipv6cp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  dissect_cp(tvb, proto_ipv6cp, ett_ipv6cp, cp_vals, ett_ipv6cp_options,
	     ipv6cp_opts, N_IPV6CP_OPTS, pinfo, tree);
}

static void dissect_ipv6cp_if_id_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
			int offset, guint length, packet_info *pinfo _U_,
			proto_tree *tree)
{
  proto_tree_add_text(tree, tvb, offset, length, "%s: %02x%02x:%02x%02x:%02x%x:%02x%02x",
		      optp->name,
		      tvb_get_guint8(tvb, offset + 2),
		      tvb_get_guint8(tvb, offset + 3),
		      tvb_get_guint8(tvb, offset + 4),
		      tvb_get_guint8(tvb, offset + 5),
		      tvb_get_guint8(tvb, offset + 6),
		      tvb_get_guint8(tvb, offset + 7),
		      tvb_get_guint8(tvb, offset + 8),
		      tvb_get_guint8(tvb, offset + 9)
		      );
}

void
proto_register_ppp(void)
{
  static hf_register_info hf[] = {
    { &hf_ppp_address,
    { "Address", "ppp.address", FT_UINT8, BASE_HEX,
        NULL, 0x0, "", HFILL }},

    { &hf_ppp_control,
    { "Control", "ppp.control", FT_UINT8, BASE_HEX,
        NULL, 0x0, "", HFILL }},

    { &hf_ppp_protocol,
    { "Protocol", "ppp.protocol", FT_UINT16, BASE_HEX,
        VALS(ppp_vals), 0x0, "", HFILL }},
  };
  static gint *ett[] = {
    &ett_ppp
  };

  module_t *ppp_module;

  proto_ppp = proto_register_protocol("Point-to-Point Protocol", "PPP", "ppp");
  proto_register_field_array(proto_ppp, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));

/* subdissector code */
  ppp_subdissector_table = register_dissector_table("ppp.protocol",
	"PPP protocol", FT_UINT16, BASE_HEX);

  register_dissector("ppp_hdlc", dissect_ppp_hdlc, proto_ppp);
  register_dissector("ppp_lcp_options", dissect_lcp_options, proto_ppp);
  register_dissector("ppp", dissect_ppp, proto_ppp);

  /* Register the preferences for the ppp protocol */
  ppp_module = prefs_register_protocol(proto_ppp, NULL);

  prefs_register_enum_preference(ppp_module,
	"fcs_type",
	"PPP Frame Checksum Type",
	"The type of PPP frame checksum (none, 16-bit, 32-bit)",
	&ppp_fcs_decode,
	fcs_options, FALSE);
  prefs_register_bool_preference(ppp_module,
	"decompress_vj",
	"Decompress Van Jacobson-compressed frames",
	"Whether Van Jacobson-compressed PPP frames should be decompressed",
	&ppp_vj_decomp);
  prefs_register_uint_preference(ppp_module,
	"default_proto_id",
	"PPPMuxCP Default PID",
	"Default Protocol ID to be used for PPPMuxCP",
	16, &pppmux_def_prot_id);
}

void
proto_reg_handoff_ppp(void)
{
  dissector_handle_t ppp_hdlc_handle, ppp_handle;

  /*
   * Get a handle for the CHDLC dissector.
   */
  chdlc_handle = find_dissector("chdlc");
  data_handle = find_dissector("data");

  ppp_handle = find_dissector("ppp");
  dissector_add("fr.ietf", NLPID_PPP, ppp_handle);

  ppp_hdlc_handle = find_dissector("ppp_hdlc");
  dissector_add("wtap_encap", WTAP_ENCAP_PPP, ppp_hdlc_handle);
  dissector_add("wtap_encap", WTAP_ENCAP_PPP_WITH_PHDR, ppp_hdlc_handle);
  dissector_add("osinl.excl", NLPID_PPP, ppp_handle);
  dissector_add("gre.proto", ETHERTYPE_PPP, ppp_hdlc_handle);
}

void
proto_register_mp(void)
{
  static hf_register_info hf[] = {
    { &hf_mp_frag_first,
    { "First fragment",		"mp.first",	FT_BOOLEAN, 8,
        TFS(&frag_truth), MP_FRAG_FIRST, "", HFILL }},

    { &hf_mp_frag_last,
    { "Last fragment",		"mp.last",	FT_BOOLEAN, 8,
        TFS(&frag_truth), MP_FRAG_LAST, "", HFILL }},

    { &hf_mp_sequence_num,
    { "Sequence number",	"mp.seq",	FT_UINT24, BASE_DEC, NULL, 0x0,
    	"", HFILL }}
  };
  static gint *ett[] = {
    &ett_mp,
    &ett_mp_flags,
  };

  proto_mp = proto_register_protocol("PPP Multilink Protocol", "PPP MP", "mp");
  proto_register_field_array(proto_mp, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_mp(void)
{
  dissector_handle_t mp_handle;

  mp_handle = create_dissector_handle(dissect_mp, proto_mp);
  dissector_add("ppp.protocol", PPP_MP, mp_handle);
}

void
proto_register_lcp(void)
{
  static gint *ett[] = {
    &ett_lcp,
    &ett_lcp_options,
    &ett_lcp_authprot_opt,
    &ett_lcp_qualprot_opt,
    &ett_lcp_fcs_alternatives_opt,
    &ett_lcp_numbered_mode_opt,
    &ett_lcp_callback_opt,
    &ett_lcp_multilink_ep_disc_opt,
    &ett_lcp_internationalization_opt,
  };

  proto_lcp = proto_register_protocol("PPP Link Control Protocol", "PPP LCP",
				      "lcp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_lcp(void)
{
  dissector_handle_t lcp_handle;

  lcp_handle = create_dissector_handle(dissect_lcp, proto_lcp);
  dissector_add("ppp.protocol", PPP_LCP, lcp_handle);

  /*
   * NDISWAN on Windows translates Ethernet frames from higher-level
   * protocols into PPP frames to hand to the PPP driver, and translates
   * PPP frames from the PPP driver to hand to the higher-level protocols.
   *
   * Apparently the PPP driver, on at least some versions of Windows,
   * passes frames for internal-to-PPP protocols up through NDISWAN;
   * the protocol type field appears to be passed through unchanged
   * (unlike what's done with, for example, the protocol type field
   * for IP, which is mapped from its PPP value to its Ethernet value).
   *
   * This means that we may see, on Ethernet captures, frames for
   * protocols internal to PPP, so we register PPP_LCP with the
   * "ethertype" dissector table as well as the PPP protocol dissector
   * table.
   */
  dissector_add("ethertype", PPP_LCP, lcp_handle);

  /*
   * for GSM-A / MobileL3 / GPRS SM / PCO
   */
  dissector_add("sm_pco.protocol", PPP_LCP, lcp_handle);

}

void
proto_register_ipcp(void)
{
  static gint *ett[] = {
    &ett_ipcp,
    &ett_ipcp_options,
    &ett_ipcp_ipaddrs_opt,
    &ett_ipcp_compress_opt,
  };

  proto_ipcp = proto_register_protocol("PPP IP Control Protocol", "PPP IPCP",
				      "ipcp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_ipcp(void)
{
  dissector_handle_t ipcp_handle;

  ipcp_handle = create_dissector_handle(dissect_ipcp, proto_ipcp);
  dissector_add("ppp.protocol", PPP_IPCP, ipcp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_IPCP, ipcp_handle);

  /*
   * for GSM-A / MobileL3 / GPRS SM / PCO
   */
  dissector_add("sm_pco.protocol", PPP_IPCP, ipcp_handle);

}

void
proto_register_osicp(void)
{
  static gint *ett[] = {
    &ett_osicp,
    &ett_osicp_options,
    &ett_osicp_align_npdu_opt,
  };

  proto_osicp = proto_register_protocol("PPP OSI Control Protocol", "PPP OSICP",
                                      "osicp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_osicp(void)
{
  dissector_handle_t osicp_handle;

  osicp_handle = create_dissector_handle(dissect_osicp, proto_osicp);
  dissector_add("ppp.protocol", PPP_OSICP, osicp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_OSICP, osicp_handle);
}

void
proto_register_ccp(void)
{
  static gint *ett[] = {
    &ett_ccp,
    &ett_ccp_options,
    &ett_ccp_stac_opt,
    &ett_ccp_mppc_opt,
    &ett_ccp_bsdcomp_opt,
    &ett_ccp_lzsdcp_opt,
    &ett_ccp_mvrca_opt,
    &ett_ccp_deflate_opt,
  };

  proto_ccp = proto_register_protocol("PPP Compression Control Protocol",
				      "PPP CCP", "ccp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_ccp(void)
{
  dissector_handle_t ccp_handle;

  ccp_handle = create_dissector_handle(dissect_ccp, proto_ccp);
  dissector_add("ppp.protocol", PPP_CCP, ccp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_CCP, ccp_handle);
}

void
proto_register_cbcp(void)
{
  static gint *ett[] = {
    &ett_cbcp,
    &ett_cbcp_options,
    &ett_cbcp_callback_opt,
    &ett_cbcp_callback_opt_addr
  };

  proto_cbcp = proto_register_protocol("PPP Callback Control Protocol",
				      "PPP CBCP", "cbcp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_cbcp(void)
{
  dissector_handle_t cbcp_handle;

  cbcp_handle = create_dissector_handle(dissect_cbcp, proto_cbcp);
  dissector_add("ppp.protocol", PPP_CBCP, cbcp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_CBCP, cbcp_handle);
}

void
proto_register_bacp(void)
{
  static gint *ett[] = {
    &ett_bacp,
    &ett_bacp_options,
    &ett_bacp_favored_peer_opt
  };

  proto_bacp = proto_register_protocol("PPP Bandwidth Allocation Control Protocol",
				      "PPP BACP", "bacp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_bacp(void)
{
  dissector_handle_t bacp_handle;

  bacp_handle = create_dissector_handle(dissect_bacp, proto_bacp);
  dissector_add("ppp.protocol", PPP_BACP, bacp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_BACP, bacp_handle);
}

void
proto_register_bap(void)
{
  static gint *ett[] = {
    &ett_bap,
    &ett_bap_options,
    &ett_bap_link_type_opt,
    &ett_bap_phone_delta_opt,
    &ett_bap_phone_delta_subopt,
    &ett_bap_call_status_opt
  };

  proto_bap = proto_register_protocol("PPP Bandwidth Allocation Protocol",
				      "PPP BAP", "bap");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_bap(void)
{
  dissector_handle_t bap_handle;

  bap_handle = create_dissector_handle(dissect_bap, proto_bap);
  dissector_add("ppp.protocol", PPP_BAP, bap_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_BAP, bap_handle);
}

void
proto_register_comp_data(void)
{
  static gint *ett[] = {
    &ett_comp_data
  };

  proto_comp_data = proto_register_protocol("PPP Compressed Datagram",
				      "PPP Comp", "comp_data");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_comp_data(void)
{
  dissector_handle_t comp_data_handle;

  comp_data_handle = create_dissector_handle(dissect_comp_data,
					proto_comp_data);
  dissector_add("ppp.protocol", PPP_COMP, comp_data_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_COMP, comp_data_handle);
}

void
proto_register_pap(void)
{
  static gint *ett[] = {
    &ett_pap,
    &ett_pap_data,
    &ett_pap_peer_id,
    &ett_pap_password,
    &ett_pap_message,
  };

  proto_pap = proto_register_protocol("PPP Password Authentication Protocol", "PPP PAP",
				      "pap");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_pap(void)
{
  dissector_handle_t pap_handle;

  pap_handle = create_dissector_handle(dissect_pap, proto_pap);
  dissector_add("ppp.protocol", PPP_PAP, pap_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_PAP, pap_handle);

  /*
   * for GSM-A / MobileL3 / GPRS SM / PCO
   */
  dissector_add("sm_pco.protocol", PPP_PAP, pap_handle);
}

void
proto_register_chap(void)
{
  static gint *ett[] = {
    &ett_chap,
    &ett_chap_data,
    &ett_chap_value,
    &ett_chap_name,
    &ett_chap_message,
  };

  proto_chap = proto_register_protocol("PPP Challenge Handshake Authentication Protocol", "PPP CHAP",
				      "chap");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_chap(void)
{
  dissector_handle_t chap_handle;

  chap_handle = create_dissector_handle(dissect_chap, proto_chap);
  dissector_add("ppp.protocol", PPP_CHAP, chap_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_CHAP, chap_handle);
  
  /*
   * for GSM-A / MobileL3 / GPRS SM / PCO
   */
  dissector_add("sm_pco.protocol", PPP_CHAP, chap_handle);
}

void
proto_register_pppmuxcp(void)
{
  static gint *ett[] = {
    &ett_pppmuxcp,
    &ett_pppmuxcp_options,
  };

  proto_pppmuxcp = proto_register_protocol("PPPMux Control Protocol",
				       "PPP PPPMuxCP",
				      "pppmuxcp");
  proto_register_subtree_array(ett, array_length(ett));
}


void
proto_reg_handoff_pppmuxcp(void)
{
  dissector_handle_t muxcp_handle;

  muxcp_handle = create_dissector_handle(dissect_pppmuxcp, proto_pppmuxcp);
  dissector_add("ppp.protocol", PPP_MUXCP, muxcp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_MUXCP, muxcp_handle);
}


void
proto_register_pppmux(void)
{
  static gint *ett[] = {
    &ett_pppmux,
    &ett_pppmux_subframe,
    &ett_pppmux_subframe_hdr,
    &ett_pppmux_subframe_flags,
    &ett_pppmux_subframe_info,
  };

  proto_pppmux = proto_register_protocol("PPP Multiplexing",
				       "PPP PPPMux",
				      "pppmux");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_pppmux(void)
{
  dissector_handle_t pppmux_handle;

  pppmux_handle = create_dissector_handle(dissect_pppmux, proto_pppmux);
  dissector_add("ppp.protocol", PPP_MUX, pppmux_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_MUX, pppmux_handle);
}

void
proto_register_mplscp(void)
{
  static gint *ett[] = {
    &ett_mplscp,
    &ett_mplscp_options,
  };

  proto_mplscp = proto_register_protocol("PPP MPLS Control Protocol",
					 "PPP MPLSCP", "mplscp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_mplscp(void)
{
  dissector_handle_t mplscp_handle;

  mplscp_handle = create_dissector_handle(dissect_mplscp, proto_mplscp);
  dissector_add("ppp.protocol", PPP_MPLSCP, mplscp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_MPLSCP, mplscp_handle);
}

void
proto_register_cdpcp(void)
{
  static gint *ett[] = {
    &ett_cdpcp,
    &ett_cdpcp_options,
  };

  proto_cdpcp = proto_register_protocol("PPP CDP Control Protocol",
					 "PPP CDPCP", "cdpcp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_cdpcp(void)
{
  dissector_handle_t cdpcp_handle;

  cdpcp_handle = create_dissector_handle(dissect_cdpcp, proto_cdpcp);
  dissector_add("ppp.protocol", PPP_CDPCP, cdpcp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_CDPCP, cdpcp_handle);
}

void
proto_register_ipv6cp(void)
{
  static gint *ett[] = {
    &ett_ipv6cp,
    &ett_ipv6cp_options,
    &ett_ipv6cp_if_id_opt,
    &ett_ipv6cp_compress_opt,
  };

  proto_ipv6cp = proto_register_protocol("PPP IPv6 Control Protocol",
					 "PPP IPV6CP", "ipv6cp");
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_ipv6cp(void)
{
  dissector_handle_t ipv6cp_handle;

  ipv6cp_handle = create_dissector_handle(dissect_ipv6cp, proto_ipv6cp);
  dissector_add("ppp.protocol", PPP_IPV6CP, ipv6cp_handle);

  /*
   * See above comment about NDISWAN for an explanation of why we're
   * registering with the "ethertype" dissector table.
   */
  dissector_add("ethertype", PPP_IPV6CP, ipv6cp_handle);
}