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
|
/* packet-btl2cap.c
* Routines for the Bluetooth L2CAP dissection
* Copyright 2002, Christoph Scholz <scholz@cs.uni-bonn.de>
* From: http://affix.sourceforge.net/archive/ethereal_affix-3.patch
*
* Refactored for wireshark checkin
* Ronnie Sahlberg 2006
*
* Added handling and reassembly of LE-Frames
* Anders Broman at ericsson dot com 2016
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <epan/packet.h>
#include <epan/exceptions.h>
#include <epan/expert.h>
#include <epan/decode_as.h>
#include <epan/proto_data.h>
#include <epan/reassemble.h>
#include <epan/unit_strings.h>
#include <wiretap/wtap.h>
#include "packet-bluetooth.h"
#include "packet-bthci_acl.h"
#include "packet-btsdp.h"
#include "packet-btl2cap.h"
/* Initialize the protocol and registered fields */
int proto_btl2cap;
static int hf_btl2cap_length;
static int hf_btl2cap_cid;
static int hf_btl2cap_payload;
static int hf_btl2cap_command;
static int hf_btl2cap_cmd_code;
static int hf_btl2cap_cmd_ident;
static int hf_btl2cap_cmd_length;
static int hf_btl2cap_cmd_data;
static int hf_btl2cap_psm;
static int hf_btl2cap_psm_dynamic;
static int hf_btl2cap_scid;
static int hf_btl2cap_dcid;
static int hf_btl2cap_icid;
static int hf_btl2cap_controller;
static int hf_btl2cap_dcontroller;
static int hf_btl2cap_result;
static int hf_btl2cap_move_result;
static int hf_btl2cap_move_confirmation_result;
static int hf_btl2cap_status;
static int hf_btl2cap_rej_reason;
static int hf_btl2cap_sig_mtu;
static int hf_btl2cap_info_mtu;
static int hf_btl2cap_info_flowcontrol;
static int hf_btl2cap_info_retransmission;
static int hf_btl2cap_info_bidirqos;
static int hf_btl2cap_info_enh_retransmission;
static int hf_btl2cap_info_streaming;
static int hf_btl2cap_info_fcs;
static int hf_btl2cap_info_flow_spec;
static int hf_btl2cap_info_fixedchan;
static int hf_btl2cap_info_fixedchans;
static int hf_btl2cap_info_fixedchans_null;
static int hf_btl2cap_info_fixedchans_signal;
static int hf_btl2cap_info_fixedchans_connless;
static int hf_btl2cap_info_fixedchans_amp_man;
static int hf_btl2cap_info_fixedchans_rfu;
static int hf_btl2cap_info_fixedchans_smp;
static int hf_btl2cap_info_fixedchans_amp_test;
static int hf_btl2cap_info_window;
static int hf_btl2cap_info_unicast;
static int hf_btl2cap_info_type;
static int hf_btl2cap_info_result;
static int hf_btl2cap_configuration_result;
static int hf_btl2cap_info_extfeatures;
static int hf_btl2cap_option;
static int hf_btl2cap_option_type;
static int hf_btl2cap_option_length;
static int hf_btl2cap_option_mtu;
static int hf_btl2cap_option_flushTO;
static int hf_btl2cap_option_flush_to_us;
static int hf_btl2cap_option_flags;
static int hf_btl2cap_option_service_type;
static int hf_btl2cap_option_tokenrate;
static int hf_btl2cap_option_tokenbucketsize;
static int hf_btl2cap_option_peakbandwidth;
static int hf_btl2cap_option_latency;
static int hf_btl2cap_option_delayvariation;
static int hf_btl2cap_option_retransmissionmode;
static int hf_btl2cap_option_txwindow;
static int hf_btl2cap_option_maxtransmit;
static int hf_btl2cap_option_retransmittimeout;
static int hf_btl2cap_option_monitortimeout;
static int hf_btl2cap_option_mps;
static int hf_btl2cap_option_fcs;
static int hf_btl2cap_option_window;
static int hf_btl2cap_option_identifier;
static int hf_btl2cap_option_sdu_size;
static int hf_btl2cap_option_sdu_arrival_time;
static int hf_btl2cap_option_access_latency;
static int hf_btl2cap_control;
static int hf_btl2cap_control_sar;
static int hf_btl2cap_control_reqseq;
static int hf_btl2cap_control_txseq;
static int hf_btl2cap_control_retransmissiondisable;
static int hf_btl2cap_control_supervisory;
static int hf_btl2cap_control_type;
static int hf_btl2cap_fcs;
static int hf_btl2cap_sdulength;
static int hf_btl2cap_continuation_to;
static int hf_btl2cap_reassembled_in;
static int hf_btl2cap_min_interval;
static int hf_btl2cap_max_interval;
static int hf_btl2cap_peripheral_latency;
static int hf_btl2cap_timeout_multiplier;
static int hf_btl2cap_conn_param_result;
static int hf_btl2cap_credits;
static int hf_btl2cap_initial_credits;
static int hf_btl2cap_le_result;
static int hf_btl2cap_le_psm;
static int hf_btl2cap_flags_reserved;
static int hf_btl2cap_flags_continuation;
static int hf_btl2cap_data;
static int hf_btl2cap_service;
static int hf_btl2cap_connect_in_frame;
static int hf_btl2cap_disconnect_in_frame;
static int hf_btl2cap_le_sdu_fragments;
static int hf_btl2cap_le_sdu_fragment;
static int hf_btl2cap_le_sdu_fragment_overlap;
static int hf_btl2cap_le_sdu_fragment_overlap_conflicts;
static int hf_btl2cap_le_sdu_fragment_multiple_tails;
static int hf_btl2cap_le_sdu_fragment_too_long_fragment;
static int hf_btl2cap_le_sdu_fragment_error;
static int hf_btl2cap_le_sdu_fragment_count;
static int hf_btl2cap_le_sdu_reassembled_in;
static int hf_btl2cap_le_sdu_reassembled_length;
static int hf_btl2cap_le_sdu_length;
/* Initialize the subtree pointers */
static int ett_btl2cap;
static int ett_btl2cap_cmd;
static int ett_btl2cap_option;
static int ett_btl2cap_extfeatures;
static int ett_btl2cap_fixedchans;
static int ett_btl2cap_control;
static int ett_btl2cap_le_sdu_fragment;
static int ett_btl2cap_le_sdu_fragments;
static expert_field ei_btl2cap_parameter_mismatch;
static expert_field ei_btl2cap_sdulength_bad;
static expert_field ei_btl2cap_length_bad;
static expert_field ei_btl2cap_unknown_command_code;
/* Initialize dissector table */
static dissector_table_t l2cap_psm_dissector_table;
static dissector_table_t l2cap_cid_dissector_table;
/* This table maps command identity values to psm values. */
static wmem_tree_t *cmd_ident_to_psm_table;
/* This table maps cid values to psm values.
* The same table is used both for SCID and DCID.
* For Remote CIDs (Receive Request SCID or Sent Response DCID)
* we 'or' the CID with 0x80000000 in this table
*/
static wmem_tree_t *cid_to_psm_table;
/* 5.4 RETRANSMISSION AND FLOW CONTROL OPTION
* Table 5.2
* Mode
* 0x00 L2CAP Basic Mode
* 0x01 Retransmission mode
* 0x02 Flow control mode
* 0x03 Enhanced Retransmission mode
* 0x04 Streaming mode
* Other values Reserved for future use
*/
#define L2CAP_BASIC_MODE 0
/* XXX Cheat and define a vaue for
* Connection-Oriented Channels in LE Credit Based Flow Control Mode
*/
#define L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE 0xff
typedef struct _config_data_t {
uint8_t mode;
uint8_t txwindow;
wmem_tree_t *start_fragments; /* indexed by pinfo->num */
/* Used for LE frame reassembly */
unsigned segmentation_started : 1; /* 0 = No, 1 = Yes */
unsigned segment_len_rem; /* The remaining segment length, used to find last segment */
} config_data_t;
typedef struct _sdu_reassembly_t
{
uint8_t *reassembled;
uint8_t seq;
uint32_t first_frame;
uint32_t last_frame;
uint16_t tot_len;
int cur_off; /* counter used by reassembly */
} sdu_reassembly_t;
typedef struct _psm_data_t {
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t local_cid;
uint32_t remote_cid;
uint16_t psm;
bool local_service;
uint32_t connect_in_frame;
uint32_t disconnect_in_frame;
config_data_t in;
config_data_t out;
} psm_data_t;
typedef struct _btl2cap_frame_data_t
{
/* LE frames info */
unsigned first_fragment : 1; /* 0 = No, 1 = First or only fragment*/
unsigned more_fragments : 1; /* 0 = Last fragment, 1 = more fragments*/
} btl2cap_frame_data_t;
static const value_string command_code_vals[] = {
{ 0x01, "Command Reject" },
{ 0x02, "Connection Request" },
{ 0x03, "Connection Response" },
{ 0x04, "Configure Request" },
{ 0x05, "Configure Response" },
{ 0x06, "Disconnection Request" },
{ 0x07, "Disconnection Response" },
{ 0x08, "Echo Request" },
{ 0x09, "Echo Response" },
{ 0x0A, "Information Request" },
{ 0x0B, "Information Response" },
{ 0x0C, "Create Channel Request" },
{ 0x0D, "Create Channel Response" },
{ 0x0E, "Move Channel Request" },
{ 0x0F, "Move Channel Response" },
{ 0x10, "Move Channel Confirmation" },
{ 0x11, "Move Channel Confirmation Response" },
{ 0x12, "Connection Parameter Update Request" },
{ 0x13, "Connection Parameter Update Response" },
{ 0x14, "LE Credit Based Connection Request" },
{ 0x15, "LE Credit Based Connection Response" },
{ 0x16, "LE Flow Control Credit" },
{ 0x17, "L2CAP Credit Based Connection Request" },
{ 0x18, "L2CAP Credit Based Connection Response" },
{ 0x19, "L2CAP Credit Based Reconfigure Request" },
{ 0x1A, "L2CAP Credit Based Reconfigure Response" },
{ 0, NULL }
};
static const value_string psm_vals[] = {
{ 0x0001, "SDP" },
{ 0x0003, "RFCOMM" },
{ 0x0005, "TCS-BIN" },
{ 0x0007, "TCS-BIN-CORDLESS" },
{ 0x000F, "BNEP" },
{ 0x0011, "HID-Control" },
{ 0x0013, "HID-Interrupt" },
{ 0x0015, "UPnP" },
{ 0x0017, "AVCTP-Control" },
{ 0x0019, "AVDTP" },
{ 0x001B, "AVCTP-Browsing" },
{ 0x001D, "UDI_C-Plane" },
{ 0x001F, "ATT" },
{ 0x0021, "3DSP" },
{ 0x0023, "IPSP" },
{ 0x0025, "OTS" },
{ 0x0027, "EATT" },
{ 0, NULL }
};
value_string_ext ext_psm_vals = VALUE_STRING_EXT_INIT(psm_vals);
static const value_string result_vals[] = {
{ 0x0000, "Successful" },
{ 0x0001, "Pending" },
{ 0x0002, "Refused - PSM not supported" },
{ 0x0003, "Refused - security block" },
{ 0x0004, "Refused - no resources available" },
{ 0x0005, "Refused - Controller ID not supported" },
{ 0, NULL }
};
static const value_string le_result_vals[] = {
{ 0x0000, "Connection Successful" },
{ 0x0002, "Connection Refused - LE_PSM Not Supported" },
{ 0x0004, "Connection Refused - No Resources Available" },
{ 0x0005, "Connection Refused - Insufficient Authentication" },
{ 0x0006, "Connection Refused - Insufficient Authorization" },
{ 0x0007, "Connection Refused - Insufficient Encryption Key Size" },
{ 0x0008, "Connection Refused - Insufficient Encryption" },
{ 0, NULL }
};
static const value_string move_result_vals[] = {
{ 0x0000, "Success" },
{ 0x0001, "Pending" },
{ 0x0002, "Refused - Controller ID not supported" },
{ 0x0003, "Refused - New Controller ID is same as old" },
{ 0x0004, "Refused - Configuration not supported" },
{ 0x0005, "Refused - Move Channel collision" },
{ 0x0006, "Refused - Channel not allowed to be moved" },
{ 0, NULL }
};
static const value_string move_result_confirmation_vals[] = {
{ 0x0000, "Success - both sides succeed" },
{ 0x0001, "Failure - one or both sides refuse" },
{ 0, NULL }
};
static const value_string configuration_result_vals[] = {
{ 0x0000, "Success"},
{ 0x0001, "Failure - unacceptable parameters" },
{ 0x0002, "Failure - reject (no reason provided)" },
{ 0x0003, "Failure - unknown options" },
{ 0x0004, "Pending" },
{ 0x0005, "Failure - flow spec rejected" },
{ 0, NULL }
};
static const value_string conn_param_result_vals[] = {
{ 0x0000, "Accepted" },
{ 0x0001, "Rejected" },
{ 0, NULL }
};
static const value_string status_vals[] = {
{ 0x0000, "No further information available" },
{ 0x0001, "Authentication pending" },
{ 0x0002, "Authorization pending" },
{ 0, NULL }
};
static const value_string reason_vals[] = {
{ 0x0000, "Command not understood" },
{ 0x0001, "Signaling MTU exceeded" },
{ 0x0002, "Invalid CID in request" },
{ 0, NULL }
};
static const value_string info_type_vals[] = {
{ 0x0001, "Connectionless MTU" },
{ 0x0002, "Extended Features Mask" },
{ 0x0003, "Fixed Channels Supported" },
{ 0, NULL }
};
static const value_string info_result_vals[] = {
{ 0x0000, "Success" },
{ 0x0001, "Not Supported" },
{ 0, NULL }
};
static const value_string option_servicetype_vals[] = {
{ 0x00, "No traffic" },
{ 0x01, "Best effort (Default)" },
{ 0x02, "Guaranteed" },
{ 0, NULL }
};
static const value_string option_type_vals[] = {
{ 0x01, "Maximum Transmission Unit" },
{ 0x02, "Flush Timeout" },
{ 0x03, "Quality of Service" },
{ 0x04, "Retransmission and Flow Control" },
{ 0x05, "FCS" },
{ 0x06, "Extended Flow Specification" },
{ 0x07, "Extended Window Size" },
{ 0, NULL }
};
static const value_string option_retransmissionmode_vals[] = {
{ 0x00, "Basic Mode" },
{ 0x01, "Retransmission Mode" },
{ 0x02, "Flow Control Mode" },
{ 0x03, "Enhanced Retransmission Mode" },
{ 0x04, "Streaming Mode" },
{ 0, NULL }
};
static const value_string control_sar_vals[] = {
{ 0x00, "Unsegmented" },
{ 0x01, "Start" },
{ 0x02, "End" },
{ 0x03, "Continuation" },
{ 0, NULL }
};
static const value_string control_supervisory_vals[] = {
{ 0x00, "RR" },
{ 0x01, "REJ" },
{ 0x02, "RNR" },
{ 0x03, "SREJ" },
{ 0, NULL }
};
static const value_string control_type_vals[] = {
{ 0x00, "I-Frame" },
{ 0x01, "S-Frame" },
{ 0, NULL }
};
static const value_string option_fcs_vals[] = {
{ 0x00, "No FCS" },
{ 0x01, "16-bit FCS" },
{ 0, NULL }
};
static const value_string ctrl_id_code_vals[] = {
{ 0x00, "Bluetooth BR/EDR" },
{ 0x01, "Wifi 802.11" },
{ 0, NULL }
};
static const range_string cid_rvals[] = {
{ 0x0000, 0x0000, "Null identifier" },
{ 0x0001, 0x0001, "L2CAP Signaling Channel" },
{ 0x0002, 0x0002, "Connectionless Channel" },
{ 0x0003, 0x0003, "AMP Manager Protocol" },
{ 0x0004, 0x0004, "Attribute Protocol" },
{ 0x0005, 0x0005, "Low Energy L2CAP Signaling Channel" },
{ 0x0006, 0x0006, "Security Manager Protocol" },
{ 0x0007, 0x003E, "Reserved" },
{ 0x003F, 0x003F, "AMP Test Manager" },
{ 0x0040, 0xFFFF, "Dynamically Allocated Channel" },
{ 0, 0, NULL }
};
static const range_string le_psm_rvals[] = {
{ 0x0001, 0x007F, "Fixed, SIG Assigned" },
{ 0x0080, 0x00FF, "Dynamically Allocated" },
{ 0x0100, 0xFFFF, "Reserved" },
{ 0, 0, NULL }
};
static const unit_name_string units_ll_connection_event = { " LL Connection Event", " LL Connection Events" };
#define PROTO_DATA_BTL2CAP_CID 0
#define PROTO_DATA_BTL2CAP_PSM 1
void proto_register_btl2cap(void);
void proto_reg_handoff_btl2cap(void);
/* Reassembly */
static reassembly_table btl2cap_le_sdu_reassembly_table;
static const fragment_items btl2cap_le_sdu_frag_items = {
/* Fragment subtrees */
&ett_btl2cap_le_sdu_fragment,
&ett_btl2cap_le_sdu_fragments,
/* Fragment fields */
&hf_btl2cap_le_sdu_fragments,
&hf_btl2cap_le_sdu_fragment,
&hf_btl2cap_le_sdu_fragment_overlap,
&hf_btl2cap_le_sdu_fragment_overlap_conflicts,
&hf_btl2cap_le_sdu_fragment_multiple_tails,
&hf_btl2cap_le_sdu_fragment_too_long_fragment,
&hf_btl2cap_le_sdu_fragment_error,
&hf_btl2cap_le_sdu_fragment_count,
/* Reassembled in field */
&hf_btl2cap_le_sdu_reassembled_in,
/* Reassembled length field */
&hf_btl2cap_le_sdu_reassembled_length,
/* Reassembled data field */
NULL,
/* Tag */
"BTL2CAP LE SDU fragments"
};
static void btl2cap_cid_prompt(packet_info *pinfo, char* result)
{
uint16_t *value_data;
value_data = (uint16_t *) p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_CID);
if (value_data)
snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "L2CAP CID 0x%04x as", (unsigned) *value_data);
else
snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Unknown L2CAP CID");
}
static void *btl2cap_cid_value(packet_info *pinfo)
{
uint16_t *value_data;
value_data = (uint16_t *) p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_CID);
if (value_data)
return GUINT_TO_POINTER((unsigned long)*value_data);
return NULL;
}
static void btl2cap_psm_prompt(packet_info *pinfo, char* result)
{
uint16_t *value_data;
value_data = (uint16_t *) p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM);
if (value_data)
snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "L2CAP PSM 0x%04x as", (unsigned) *value_data);
else
snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Unknown L2CAP PSM");
}
static void *btl2cap_psm_value(packet_info *pinfo)
{
uint16_t *value_data;
value_data = (uint16_t *) p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM);
if (value_data)
return GUINT_TO_POINTER((unsigned long)*value_data);
return NULL;
}
static uint16_t
get_service_uuid(packet_info *pinfo, btl2cap_data_t *l2cap_data, uint16_t psm, bool is_local_psm)
{
wmem_tree_key_t key[10];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_sdp_psm;
uint32_t k_direction;
uint32_t k_bd_addr_oui;
uint32_t k_bd_addr_id;
uint32_t k_service_type;
uint32_t k_service_channel;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t remote_bd_addr_oui;
uint32_t remote_bd_addr_id;
service_info_t *service_info;
interface_id = l2cap_data->interface_id;
adapter_id = l2cap_data->adapter_id;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_sdp_psm = SDP_PSM_DEFAULT;
k_direction = (is_local_psm) ? P2P_DIR_SENT : P2P_DIR_RECV;
if (k_direction == P2P_DIR_RECV) {
k_bd_addr_oui = l2cap_data->remote_bd_addr_oui;
k_bd_addr_id = l2cap_data->remote_bd_addr_id;
} else {
k_bd_addr_oui = 0;
k_bd_addr_id = 0;
}
remote_bd_addr_oui = k_bd_addr_oui;
remote_bd_addr_id = k_bd_addr_id;
k_service_type = BTSDP_L2CAP_PROTOCOL_UUID;
k_service_channel = psm;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_sdp_psm;
key[3].length = 1;
key[3].key = &k_direction;
key[4].length = 1;
key[4].key = &k_bd_addr_oui;
key[5].length = 1;
key[5].key = &k_bd_addr_id;
key[6].length = 1;
key[6].key = &k_service_type;
key[7].length = 1;
key[7].key = &k_service_channel;
key[8].length = 1;
key[8].key = &k_frame_number;
key[9].length = 0;
key[9].key = NULL;
service_info = btsdp_get_service_info(key);
if (service_info &&
service_info->interface_id == interface_id &&
service_info->adapter_id == adapter_id &&
service_info->sdp_psm == SDP_PSM_DEFAULT &&
((service_info->direction == P2P_DIR_RECV &&
service_info->bd_addr_oui == remote_bd_addr_oui &&
service_info->bd_addr_id == remote_bd_addr_id) ||
(service_info->direction != P2P_DIR_RECV &&
service_info->bd_addr_oui == 0 &&
service_info->bd_addr_id == 0)) &&
service_info->type == BTSDP_L2CAP_PROTOCOL_UUID &&
service_info->channel == psm)
{
return service_info->uuid.bt_uuid;
}
return 0;
}
static int
dissect_comrej(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
{
uint16_t reason;
reason = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_rej_reason, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
switch (reason) {
case 0x0000: /* Command not understood */
break;
case 0x0001: /* Signaling MTU exceeded */
proto_tree_add_item(tree, hf_btl2cap_sig_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
break;
case 0x0002: /* Invalid CID in requets */
proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_dcid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
break;
default:
break;
}
return offset;
}
static int
dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, proto_tree *command_tree, bool is_ch_request,
bthci_acl_data_t *acl_data, btl2cap_data_t *l2cap_data)
{
uint16_t scid;
uint16_t psm;
const char *psm_str = "<NONE>";
psm = tvb_get_letohs(tvb, offset);
if (p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM ) == NULL) {
uint16_t *value_data;
value_data = wmem_new(wmem_file_scope(), uint16_t);
*value_data = psm;
p_add_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM, value_data);
}
if (psm < BTL2CAP_DYNAMIC_PSM_START) {
proto_tree_add_item(command_tree, hf_btl2cap_psm, tvb, offset, 2, ENC_LITTLE_ENDIAN);
psm_str = val_to_str_const(psm, psm_vals, "Unknown PSM");
} else {
proto_item *item;
uint16_t uuid;
item = proto_tree_add_item(command_tree, hf_btl2cap_psm_dynamic, tvb, offset, 2, ENC_LITTLE_ENDIAN);
uuid = get_service_uuid(pinfo, l2cap_data, psm, (pinfo->p2p_dir == P2P_DIR_RECV) ? true : false);
if (uuid) {
psm_str = val_to_str_ext_const(uuid, &bluetooth_uuid_vals_ext, "Unknown PSM");
proto_item_append_text(item, " (%s)", psm_str);
}
}
offset += 2;
scid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(command_tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (%s, SCID: 0x%04x)", psm_str, scid);
if (is_ch_request) {
proto_tree_add_item(command_tree, hf_btl2cap_controller, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
}
if (!pinfo->fd->visited) {
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
psm_data_t *psm_data;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = scid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x80000000 : 0x00000000);
k_frame_number = pinfo->num;
psm_data = wmem_new0(wmem_file_scope(), psm_data_t);
if (pinfo->p2p_dir == P2P_DIR_RECV) {
psm_data->local_cid = BTL2CAP_UNKNOWN_CID;
psm_data->remote_cid = scid | 0x80000000;
} else {
psm_data->local_cid = scid;
psm_data->remote_cid = BTL2CAP_UNKNOWN_CID;
}
psm_data->psm = psm;
psm_data->local_service = (pinfo->p2p_dir == P2P_DIR_RECV) ? true : false;
psm_data->in.start_fragments = wmem_tree_new(wmem_file_scope());
psm_data->out.start_fragments = wmem_tree_new(wmem_file_scope());
psm_data->interface_id = k_interface_id;
psm_data->adapter_id = k_adapter_id;
psm_data->chandle = k_chandle;
psm_data->connect_in_frame = pinfo->num;
psm_data->disconnect_in_frame = bluetooth_max_disconnect_in_frame;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
wmem_tree_insert32_array(cid_to_psm_table, key, psm_data);
}
if (l2cap_data) {
proto_item *sub_item;
uint32_t bt_uuid = 0;
uint32_t disconnect_in_frame = 0;
psm_data_t *psm_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = scid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x80000000 : 0x00000000);
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->local_cid == k_cid)
{
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm_data->psm, psm_data->local_service);
disconnect_in_frame = psm_data->disconnect_in_frame;
}
if (bt_uuid) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_service, tvb, 0, 0, bt_uuid);
proto_item_set_generated(sub_item);
}
if (disconnect_in_frame < bluetooth_max_disconnect_in_frame) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_disconnect_in_frame, tvb, 0, 0, disconnect_in_frame);
proto_item_set_generated(sub_item);
}
}
return offset;
}
static int
dissect_le_credit_based_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, proto_tree *command_tree, uint16_t cid, uint8_t cmd_ident,
bthci_acl_data_t *acl_data, btl2cap_data_t *l2cap_data)
{
proto_item *psm_item;
uint32_t psm;
uint32_t scid;
proto_tree_add_item_ret_uint(command_tree, hf_btl2cap_le_psm, tvb, offset, 2, ENC_LITTLE_ENDIAN, &psm);
if (psm < 0x80) {
psm_item = proto_tree_add_item(command_tree, hf_btl2cap_psm, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_item_set_generated(psm_item);
}
offset += 2;
proto_tree_add_item_ret_uint(command_tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN, &scid);
offset += 2;
proto_tree_add_item(command_tree, hf_btl2cap_option_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(command_tree, hf_btl2cap_option_mps, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(command_tree, hf_btl2cap_initial_credits, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
if (!pinfo->fd->visited) {
wmem_tree_key_t key[8];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_cmd_ident;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
psm_data_t *psm_data;
uint32_t key_cid;
uint32_t cid_index;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_cmd_ident = cmd_ident;
k_frame_number = pinfo->num;
cid_index = 0;
psm_data = wmem_new0(wmem_file_scope(), psm_data_t);
if (pinfo->p2p_dir == P2P_DIR_RECV) {
key_cid = scid | 0x80000000;
psm_data->local_cid = BTL2CAP_UNKNOWN_CID;
psm_data->remote_cid = key_cid;
}
else {
key_cid = scid;
psm_data->local_cid = key_cid;
psm_data->remote_cid = BTL2CAP_UNKNOWN_CID;
}
psm_data->psm = psm;
psm_data->local_service = (pinfo->p2p_dir == P2P_DIR_RECV) ? true : false;
psm_data->in.mode = L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE;
psm_data->in.start_fragments = wmem_tree_new(wmem_file_scope());
psm_data->out.mode = L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE;
psm_data->out.start_fragments = wmem_tree_new(wmem_file_scope());
psm_data->interface_id = k_interface_id;
psm_data->adapter_id = k_adapter_id;
psm_data->chandle = k_chandle;
psm_data->connect_in_frame = pinfo->num;
psm_data->disconnect_in_frame = bluetooth_max_disconnect_in_frame;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_cmd_ident;
key[5].length = 1;
key[5].key = &k_frame_number;
key[6].length = 1;
key[6].key = &cid_index;
key[7].length = 0;
key[7].key = NULL;
wmem_tree_insert32_array(cmd_ident_to_psm_table, key, psm_data);
k_cid = key_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
wmem_tree_insert32_array(cid_to_psm_table, key, psm_data);
}
if (l2cap_data) {
proto_item *sub_item;
uint32_t bt_uuid = 0;
uint32_t disconnect_in_frame = 0;
psm_data_t *psm_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = scid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->local_cid == k_cid)
{
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm_data->psm, psm_data->local_service);
disconnect_in_frame = psm_data->disconnect_in_frame;
}
if (bt_uuid) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_service, tvb, 0, 0, bt_uuid);
proto_item_set_generated(sub_item);
}
if (disconnect_in_frame < bluetooth_max_disconnect_in_frame) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_disconnect_in_frame, tvb, 0, 0, disconnect_in_frame);
proto_item_set_generated(sub_item);
}
}
return offset;
}
static int
dissect_le_credit_based_connresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, uint16_t cid, uint8_t cmd_ident, bthci_acl_data_t *acl_data)
{
uint32_t dcid;
proto_tree_add_item_ret_uint(tree, hf_btl2cap_dcid, tvb, offset, 2, ENC_LITTLE_ENDIAN, &dcid);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_option_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_option_mps, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_initial_credits, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_le_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
if (pinfo->fd->visited == 0) {
psm_data_t *psm_data;
wmem_tree_key_t key[8];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_cmd_ident;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t key_cid;
uint32_t cid_index;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_cmd_ident = cmd_ident;
k_frame_number = pinfo->num;
cid_index = 0;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_cmd_ident;
key[5].length = 1;
key[5].key = &k_frame_number;
key[6].length = 1;
key[6].key = &cid_index;
key[7].length = 0;
key[7].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cmd_ident_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->disconnect_in_frame > pinfo->num)
{
key_cid = dcid | ((pinfo->p2p_dir != P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = key_cid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
if (pinfo->p2p_dir == P2P_DIR_RECV)
psm_data->remote_cid = key_cid;
else
psm_data->local_cid = key_cid;
wmem_tree_insert32_array(cid_to_psm_table, key, psm_data);
}
}
return offset;
}
static int
dissect_l2cap_credit_based_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, proto_tree *command_tree, uint16_t cid, uint8_t cmd_ident,
uint16_t length, bthci_acl_data_t *acl_data, btl2cap_data_t *l2cap_data)
{
proto_item *psm_item;
uint32_t psm;
uint32_t scid;
uint32_t cid_index;
proto_tree_add_item_ret_uint(command_tree, hf_btl2cap_le_psm, tvb, offset, 2, ENC_LITTLE_ENDIAN, &psm);
if (psm < 0x80) {
psm_item = proto_tree_add_item(command_tree, hf_btl2cap_psm, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_item_set_generated(psm_item);
}
offset += 2;
proto_tree_add_item(command_tree, hf_btl2cap_option_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(command_tree, hf_btl2cap_option_mps, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(command_tree, hf_btl2cap_initial_credits, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
cid_index = 0;
while (offset < length + 8) {
proto_tree_add_item_ret_uint(command_tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN, &scid);
offset += 2;
if (!pinfo->fd->visited) {
wmem_tree_key_t key[8];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_cmd_ident;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
psm_data_t *psm_data;
uint32_t key_cid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_cmd_ident = cmd_ident;
k_frame_number = pinfo->num;
psm_data = wmem_new0(wmem_file_scope(), psm_data_t);
if (pinfo->p2p_dir == P2P_DIR_RECV) {
key_cid = scid | 0x80000000;
psm_data->local_cid = BTL2CAP_UNKNOWN_CID;
psm_data->remote_cid = key_cid;
}
else {
key_cid = scid;
psm_data->local_cid = key_cid;
psm_data->remote_cid = BTL2CAP_UNKNOWN_CID;
}
psm_data->psm = psm;
psm_data->local_service = (pinfo->p2p_dir == P2P_DIR_RECV) ? true : false;
psm_data->in.mode = L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE;
psm_data->in.start_fragments = wmem_tree_new(wmem_file_scope());
psm_data->out.mode = L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE;
psm_data->out.start_fragments = wmem_tree_new(wmem_file_scope());
psm_data->interface_id = k_interface_id;
psm_data->adapter_id = k_adapter_id;
psm_data->chandle = k_chandle;
psm_data->connect_in_frame = pinfo->num;
psm_data->disconnect_in_frame = bluetooth_max_disconnect_in_frame;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_cmd_ident;
key[5].length = 1;
key[5].key = &k_frame_number;
key[6].length = 1;
key[6].key = &cid_index;
key[7].length = 0;
key[7].key = NULL;
wmem_tree_insert32_array(cmd_ident_to_psm_table, key, psm_data);
k_cid = key_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
wmem_tree_insert32_array(cid_to_psm_table, key, psm_data);
}
if (l2cap_data) {
proto_item *sub_item;
uint32_t bt_uuid = 0;
uint32_t disconnect_in_frame = 0;
psm_data_t *psm_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = scid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->local_cid == k_cid)
{
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm_data->psm, psm_data->local_service);
disconnect_in_frame = psm_data->disconnect_in_frame;
}
if (bt_uuid) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_service, tvb, 0, 0, bt_uuid);
proto_item_set_generated(sub_item);
}
if (disconnect_in_frame < bluetooth_max_disconnect_in_frame) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_disconnect_in_frame, tvb, 0, 0, disconnect_in_frame);
proto_item_set_generated(sub_item);
}
}
cid_index++;
}
return offset;
}
static int
dissect_l2cap_credit_based_connresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, uint16_t cid, uint8_t cmd_ident, uint16_t length,
bthci_acl_data_t *acl_data)
{
uint32_t dcid;
uint32_t cid_index;
proto_tree_add_item(tree, hf_btl2cap_option_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_option_mps, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_initial_credits, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_le_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
cid_index = 0;
while (offset < length + 8) {
proto_tree_add_item_ret_uint(tree, hf_btl2cap_dcid, tvb, offset, 2, ENC_LITTLE_ENDIAN, &dcid);
offset += 2;
if (pinfo->fd->visited == 0) {
psm_data_t *psm_data;
wmem_tree_key_t key[8];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_cmd_ident;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t key_cid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_cmd_ident = cmd_ident;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_cmd_ident;
key[5].length = 1;
key[5].key = &k_frame_number;
key[6].length = 1;
key[6].key = &cid_index;
key[7].length = 0;
key[7].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cmd_ident_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->disconnect_in_frame > pinfo->num)
{
key_cid = dcid | ((pinfo->p2p_dir != P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = key_cid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
if (pinfo->p2p_dir == P2P_DIR_RECV)
psm_data->remote_cid = key_cid;
else
psm_data->local_cid = key_cid;
wmem_tree_insert32_array(cid_to_psm_table, key, psm_data);
}
}
cid_index++;
}
return offset;
}
static int
dissect_movechanrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
uint16_t icid;
uint8_t ctrl_id;
icid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_icid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
ctrl_id = tvb_get_uint8(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_dcontroller, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
col_append_fstr(pinfo->cinfo, COL_INFO, " (ICID: 0x%04x, move to %s)", icid,
val_to_str_const(ctrl_id, ctrl_id_code_vals, "Unknown controller"));
return offset;
}
static int
dissect_options(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int length, config_data_t *config_data)
{
proto_item *ti_option;
proto_tree *ti_option_subtree;
uint8_t option_type, option_length;
if (config_data) {
config_data->mode = L2CAP_BASIC_MODE;
config_data->txwindow = 0;
}
while (length > 0) {
option_type = tvb_get_uint8(tvb, offset);
option_length = tvb_get_uint8(tvb, offset + 1);
ti_option = proto_tree_add_none_format(tree,
hf_btl2cap_option, tvb,
offset, option_length + 2,
"Option: ");
ti_option_subtree = proto_item_add_subtree(ti_option, ett_btl2cap_option);
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_length, tvb, offset + 1, 1, ENC_LITTLE_ENDIAN);
offset += 2;
if (option_length != 0) {
switch (option_type) {
case 0x01: /* MTU */
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_item_append_text(ti_option, "MTU");
break;
case 0x02: /* Flush timeout */
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_flushTO, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_item_append_text(ti_option, "Flush Timeout");
break;
case 0x03: /* QOS */
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_flags, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_service_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_tokenrate, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_tokenbucketsize, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_peakbandwidth, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_latency, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_delayvariation, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_item_append_text(ti_option, "QOS");
break;
case 0x04: /* Retransmission and Flow Control*/
if (config_data)
{
config_data->mode = tvb_get_uint8(tvb, offset);
config_data->txwindow = tvb_get_uint8(tvb, offset + 1);
}
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_retransmissionmode, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_txwindow, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_maxtransmit, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_retransmittimeout, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_monitortimeout, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_mps, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_item_append_text(ti_option, "Retransmission and Flow Control");
break;
case 0x05: /* FCS */
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_fcs, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_item_append_text(ti_option, "FCS");
break;
case 0x06: /* Extended Flow Specification */
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_identifier, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_service_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_sdu_size, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_sdu_arrival_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_access_latency, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_flush_to_us, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_item_append_text(ti_option, "Extended Flow Specification");
break;
case 0x07: /* Extended Window Size */
proto_tree_add_item(ti_option_subtree, hf_btl2cap_option_window, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_item_append_text(ti_option, "Extended Window Size");
break;
default:
proto_item_append_text(ti_option, "unknown");
offset += option_length;
break;
}
}
length -= (option_length + 2);
}
return offset;
}
static int
dissect_configrequest(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, uint16_t length, bthci_acl_data_t *acl_data)
{
uint16_t dcid;
dcid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_dcid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (DCID: 0x%04x)", dcid);
proto_tree_add_item(tree, hf_btl2cap_flags_reserved, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(tree, hf_btl2cap_flags_continuation, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
{
psm_data_t *psm_data;
config_data_t *config_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t cid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
cid = dcid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
((pinfo->p2p_dir == P2P_DIR_SENT && psm_data->remote_cid == cid) ||
(pinfo->p2p_dir == P2P_DIR_RECV && psm_data->local_cid == cid)) &&
psm_data->disconnect_in_frame > pinfo->num)
{
if (pinfo->p2p_dir == P2P_DIR_RECV)
config_data = &(psm_data->out);
else
config_data = &(psm_data->in);
} else {
config_data = NULL;
}
if (config_data != NULL) {
/* Reset config_data that might have been set by an earlier
* Configure Request that failed.
*/
config_data->mode = L2CAP_BASIC_MODE;
config_data->txwindow = 0;
}
if (tvb_reported_length_remaining(tvb, offset) > 0) {
offset = dissect_options(tvb, offset, pinfo, tree, length - 4, config_data);
}
}
return offset;
}
static int
dissect_inforequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
uint16_t info_type;
info_type = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_info_type, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", val_to_str_const(info_type, info_type_vals, "Unknown type"));
return offset;
}
static int
dissect_inforesponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
uint16_t info_type, result;
info_type = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_info_type, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
result = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_info_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (%s, %s)",
val_to_str_const(info_type, info_type_vals, "Unknown type"),
val_to_str_const(result, info_result_vals, "Unknown result"));
if (tvb_reported_length_remaining(tvb, offset) > 0) {
proto_item *ti_features;
proto_tree *ti_features_subtree;
uint32_t features;
switch (info_type) {
case 0x0001: /* Connectionless MTU */
proto_tree_add_item(tree, hf_btl2cap_info_mtu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
break;
case 0x0002: /* Extended Features */
ti_features = proto_tree_add_none_format(tree,
hf_btl2cap_info_extfeatures, tvb,
offset, 4,
"Features: ");
ti_features_subtree = proto_item_add_subtree(ti_features, ett_btl2cap_extfeatures);
features = tvb_get_letohl(tvb, offset);
if (features & 0x1)
proto_item_append_text(ti_features, "FlowControl ");
if (features & 0x2)
proto_item_append_text(ti_features, "Retransmission ");
if (features & 0x4)
proto_item_append_text(ti_features, "BiDirQOS ");
if (features & 0x8)
proto_item_append_text(ti_features, "EnhRetransmission ");
if (features & 0x10)
proto_item_append_text(ti_features, "Streaming ");
if (features & 0x20)
proto_item_append_text(ti_features, "FCS ");
if (features & 0x40)
proto_item_append_text(ti_features, "FlowSpec ");
if (features & 0x80)
proto_item_append_text(ti_features, "FixedChan ");
if (features & 0x100)
proto_item_append_text(ti_features, "WindowSize ");
if (features & 0x200)
proto_item_append_text(ti_features, "Unicast ");
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_flowcontrol, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_retransmission, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_bidirqos, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_enh_retransmission, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_streaming, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fcs, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_flow_spec, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchan, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_window, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_unicast, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
break;
case 0x0003: /* Fixed Channels Supported */
ti_features = proto_tree_add_none_format(tree,
hf_btl2cap_info_fixedchans, tvb,
offset, 8,
"Fixed Channels Supported:");
ti_features_subtree = proto_item_add_subtree(ti_features, ett_btl2cap_fixedchans);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchans_null, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchans_signal, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchans_connless, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchans_amp_man, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchans_rfu, tvb, offset, 4, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchans_smp, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
proto_tree_add_item(ti_features_subtree, hf_btl2cap_info_fixedchans_amp_test, tvb, offset, 4, ENC_LITTLE_ENDIAN);
offset += 4;
break;
default:
proto_tree_add_item(tree, hf_btl2cap_cmd_data, tvb, offset, -1, ENC_NA);
offset += tvb_reported_length_remaining(tvb, offset);
break;
}
}
return offset;
}
static int
dissect_configresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, uint16_t length, bthci_acl_data_t *acl_data)
{
uint16_t scid;
uint16_t result;
scid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_flags_reserved, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(tree, hf_btl2cap_flags_continuation, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
result = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_configuration_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " - %s (SCID: 0x%04x)",
val_to_str_const(result, configuration_result_vals, "Unknown"), scid);
if (tvb_reported_length_remaining(tvb, offset) > 0) {
psm_data_t *psm_data;
config_data_t *config_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t cid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
cid = scid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
((pinfo->p2p_dir == P2P_DIR_SENT && psm_data->local_cid == cid) ||
(pinfo->p2p_dir == P2P_DIR_RECV && psm_data->remote_cid == cid)) &&
psm_data->disconnect_in_frame > pinfo->num)
{
if (pinfo->p2p_dir == P2P_DIR_RECV)
config_data = &(psm_data->out);
else
config_data = &(psm_data->in);
} else {
config_data = NULL;
}
offset = dissect_options(tvb, offset, pinfo, tree, length - 6, config_data);
}
return offset;
}
static int
dissect_connresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, bthci_acl_data_t *acl_data)
{
uint16_t scid, dcid, result;
dcid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_dcid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
scid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
result = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(tree, hf_btl2cap_status, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
if (result == 0) {
col_append_fstr(pinfo->cinfo, COL_INFO, " - Success (SCID: 0x%04x, DCID: 0x%04x)", scid, dcid);
}
else {
col_append_fstr(pinfo->cinfo, COL_INFO, " - %s (SCID: 0x%04x)",
val_to_str_const(result, result_vals, "Unknown"), scid);
}
if (pinfo->fd->visited == 0) {
psm_data_t *psm_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t cid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
cid = scid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
((pinfo->p2p_dir == P2P_DIR_SENT && psm_data->remote_cid == cid) ||
(pinfo->p2p_dir == P2P_DIR_RECV && psm_data->local_cid == cid)) &&
psm_data->disconnect_in_frame > pinfo->num)
{
cid = dcid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x80000000 : 0x00000000);
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = cid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
if (pinfo->p2p_dir == P2P_DIR_RECV)
psm_data->remote_cid = cid;
else
psm_data->local_cid = cid;
wmem_tree_insert32_array(cid_to_psm_table, key, psm_data);
}
}
return offset;
}
static int
dissect_chanresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, bthci_acl_data_t *acl_data)
{
return dissect_connresponse(tvb, offset, pinfo, tree, acl_data);
}
static int
dissect_movechanresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
uint16_t icid, result;
icid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_icid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
result = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_move_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (ICID: 0x%04x, %s)", icid,
val_to_str_const(result, move_result_vals, "Unknown result"));
return offset;
}
static int
dissect_movechanconfirmation(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
uint16_t icid, result;
icid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_icid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
result = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_move_confirmation_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (ICID: 0x%04x, %s)", icid,
val_to_str_const(result, move_result_confirmation_vals, "Unknown result"));
return offset;
}
static int
dissect_movechanconfirmationresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
uint16_t icid;
icid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_icid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (ICID: 0x%04x)", icid);
return offset;
}
static int
dissect_connparamrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
proto_item *item;
uint16_t max_interval, peripheral_latency;
item = proto_tree_add_item(tree, hf_btl2cap_min_interval, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_item_append_text(item, " (%g msec)", tvb_get_letohs(tvb, offset) * 1.25);
offset += 2;
item = proto_tree_add_item(tree, hf_btl2cap_max_interval, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_item_append_text(item, " (%g msec)", tvb_get_letohs(tvb, offset) * 1.25);
max_interval = tvb_get_letohs(tvb, offset);
offset += 2;
item = proto_tree_add_item(tree, hf_btl2cap_peripheral_latency, tvb, offset, 2, ENC_LITTLE_ENDIAN);
peripheral_latency = tvb_get_letohs(tvb, offset);
if(peripheral_latency >= 500 || max_interval == 0 ||
peripheral_latency > 10.0 * tvb_get_letohs(tvb, offset + 2) / (max_interval *1.25))
expert_add_info(pinfo, item, &ei_btl2cap_parameter_mismatch);
offset += 2;
item = proto_tree_add_item(tree, hf_btl2cap_timeout_multiplier, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_item_append_text(item, " (%g sec)", tvb_get_letohs(tvb, offset) * 0.01);
offset += 2;
return offset;
}
static int
dissect_connparamresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
uint16_t result;
result = tvb_get_letohs(tvb, offset);
proto_tree_add_item(tree, hf_btl2cap_conn_param_result, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)",
val_to_str_const(result, conn_param_result_vals, "Unknown result"));
return offset;
}
static int
dissect_disconnrequestresponse(tvbuff_t *tvb, int offset, packet_info *pinfo,
proto_tree *tree, proto_tree *command_tree, bthci_acl_data_t *acl_data, btl2cap_data_t *l2cap_data,
bool is_request)
{
uint16_t scid;
uint16_t dcid;
unsigned psm = 0;
const char *service_name = "Unknown";
dcid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(command_tree, hf_btl2cap_dcid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
scid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(command_tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
if (!pinfo->fd->visited) {
psm_data_t *psm_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t key_scid;
uint32_t key_dcid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
if ((is_request && pinfo->p2p_dir == P2P_DIR_SENT) ||
(!is_request && pinfo->p2p_dir == P2P_DIR_RECV)) {
key_dcid = dcid | 0x80000000;
key_scid = scid;
} else {
key_dcid = scid | 0x80000000;
key_scid = dcid;
}
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = key_dcid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->remote_cid == key_dcid &&
psm_data->disconnect_in_frame == bluetooth_max_disconnect_in_frame)
{
psm_data->disconnect_in_frame = pinfo->num;
}
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = key_scid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->local_cid == key_scid &&
psm_data->disconnect_in_frame == bluetooth_max_disconnect_in_frame)
{
psm_data->disconnect_in_frame = pinfo->num;
}
}
if (l2cap_data) {
proto_item *sub_item;
uint32_t bt_uuid = 0;
uint32_t connect_in_frame = 0;
psm_data_t *psm_data;
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t key_dcid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
if ((is_request && pinfo->p2p_dir == P2P_DIR_SENT) ||
(!is_request && pinfo->p2p_dir == P2P_DIR_RECV)) {
key_dcid = dcid | 0x80000000;
} else {
key_dcid = scid | 0x80000000;
}
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = key_dcid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
psm_data->remote_cid == key_dcid)
{
psm = psm_data->psm;
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm_data->psm, psm_data->local_service);
connect_in_frame = psm_data->connect_in_frame;
}
if (bt_uuid) {
bluetooth_uuid_t uuid;
uuid.size = 2;
uuid.bt_uuid = bt_uuid;
uuid.data[0] = bt_uuid >> 8;
uuid.data[1] = bt_uuid & 0xFF;
service_name = val_to_str_ext_const(uuid.bt_uuid, &bluetooth_uuid_vals_ext, "Unknown");
}
if (strcmp(service_name, "Unknown") == 0) {
service_name = val_to_str_const(psm, psm_vals, "Unknown");
}
if (psm > 0) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_psm, tvb, offset, 0, psm);
proto_item_set_generated(sub_item);
}
if (bt_uuid) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_service, tvb, 0, 0, bt_uuid);
proto_item_set_generated(sub_item);
}
if (connect_in_frame > 0) {
sub_item = proto_tree_add_uint(tree, hf_btl2cap_connect_in_frame, tvb, 0, 0, connect_in_frame);
proto_item_set_generated(sub_item);
}
}
if (psm > 0)
col_append_fstr(pinfo->cinfo, COL_INFO, " (SCID: 0x%04x, DCID: 0x%04x, PSM: 0x%04x, Service: %s)", scid, dcid, psm, service_name);
else
col_append_fstr(pinfo->cinfo, COL_INFO, " (SCID: 0x%04x, DCID: 0x%04x, PSM: Unknown, Service: %s)", scid, dcid, service_name);
return offset;
}
static int
dissect_b_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_tree *btl2cap_tree, uint16_t cid, uint16_t psm,
bool is_local_psm, uint16_t length, int offset, btl2cap_data_t *l2cap_data)
{
tvbuff_t *next_tvb;
next_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset), length);
col_append_str(pinfo->cinfo, COL_INFO, "Connection oriented channel");
if (psm) {
proto_item *psm_item;
uint16_t bt_uuid;
bluetooth_uuid_t uuid;
if (p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM ) == NULL) {
uint16_t *value_data;
value_data = wmem_new(wmem_file_scope(), uint16_t);
*value_data = psm;
p_add_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM, value_data);
}
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm, is_local_psm);
uuid.size = 2;
uuid.bt_uuid = bt_uuid;
uuid.data[0] = bt_uuid >> 8;
uuid.data[1] = bt_uuid & 0xFF;
if (bt_uuid && p_get_proto_data(pinfo->pool, pinfo, proto_bluetooth, PROTO_DATA_BLUETOOTH_SERVICE_UUID) == NULL) {
char *value_data;
value_data = wmem_strdup(wmem_file_scope(), print_numeric_bluetooth_uuid(pinfo->pool, &uuid));
p_add_proto_data(pinfo->pool, pinfo, proto_bluetooth, PROTO_DATA_BLUETOOTH_SERVICE_UUID, value_data);
}
if (psm < BTL2CAP_DYNAMIC_PSM_START) {
psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm);
}
else {
psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm_dynamic, tvb, offset, 0, psm);
if (uuid.bt_uuid)
proto_item_append_text(psm_item, ": %s",
val_to_str_ext_const(uuid.bt_uuid, &bluetooth_uuid_vals_ext, "Unknown service"));
}
proto_item_set_generated(psm_item);
/* call next dissector */
if (!dissector_try_uint_new(l2cap_cid_dissector_table, (uint32_t) cid, next_tvb, pinfo, tree, true, l2cap_data)) {
if (!dissector_try_uint_new(l2cap_psm_dissector_table, (uint32_t) psm, next_tvb, pinfo, tree, true, l2cap_data)) {
/* not a known fixed PSM, try to find a registered service to a dynamic PSM */
if (!dissector_try_string(bluetooth_uuid_table, print_numeric_bluetooth_uuid(pinfo->pool, &uuid), next_tvb, pinfo, tree, l2cap_data)) {
/* unknown protocol. declare as data */
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
}
}
}
offset = tvb_captured_length(tvb);
} else {
if (!dissector_try_uint_new(l2cap_cid_dissector_table, (uint32_t) cid, next_tvb, pinfo, tree, true, l2cap_data))
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
offset = tvb_captured_length(tvb);
}
return offset;
}
/* An LE-frame is a PDU used in LE Credit Based Flow Control Mode. It
* contains an SDU segment and additional protocol information, encapsulated
* by a Basic L2CAP header.
*/
static int
dissect_le_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_tree *btl2cap_tree, uint16_t cid, uint16_t psm, bool is_local_psm,
uint16_t length, int offset, config_data_t *config_data, btl2cap_data_t *l2cap_data,
bool is_retransmit)
{
tvbuff_t *new_tvb = NULL;
bluetooth_uuid_t uuid;
btl2cap_frame_data_t *btl2cap_frame_data = NULL;
fragment_head *frag_btl2cap_le_sdu = NULL;
if ((!pinfo->fd->visited) && (config_data) && !is_retransmit) {
btl2cap_frame_data = wmem_new0(wmem_file_scope(), btl2cap_frame_data_t);
if (config_data->segmentation_started == 1) {
config_data->segment_len_rem = config_data->segment_len_rem - length;
if (config_data->segment_len_rem > 0) {
btl2cap_frame_data->more_fragments = 1;
} else {
btl2cap_frame_data->more_fragments = 0;
config_data->segmentation_started = 0;
config_data->segment_len_rem = 0;
}
} else {
/* First Frame in this SDU, SDU length is present */
uint16_t sdu_length;
sdu_length = tvb_get_letohs(tvb, offset);
btl2cap_frame_data->first_fragment = 1;
if (sdu_length == length - 2) {
/* Complete SDU no segmentation */
btl2cap_frame_data->more_fragments = 0;
config_data->segmentation_started = 0;
config_data->segment_len_rem = 0;
} else {
btl2cap_frame_data->more_fragments = 1;
config_data->segmentation_started = 1;
config_data->segment_len_rem = sdu_length - (length - 2);
}
}
p_add_proto_data(wmem_file_scope(), pinfo, proto_btl2cap, pinfo->curr_layer_num, btl2cap_frame_data);
} else {
/* Not the first pass */
btl2cap_frame_data = (btl2cap_frame_data_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_btl2cap, pinfo->curr_layer_num);
}
col_append_str(pinfo->cinfo, COL_INFO, "Connection oriented channel, LE Information frame");
if (!btl2cap_frame_data) {
/* Without frame data we do not have enough information to dissect the packet */
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
return tvb_captured_length(tvb);
}
if (psm) {
proto_item *psm_item;
uint16_t bt_uuid;
if (p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM) == NULL) {
uint16_t *value_data;
value_data = wmem_new(wmem_file_scope(), uint16_t);
*value_data = psm;
p_add_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM, value_data);
}
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm, is_local_psm);
uuid.size = 2;
uuid.bt_uuid = bt_uuid;
uuid.data[0] = bt_uuid >> 8;
uuid.data[1] = bt_uuid & 0xFF;
if (bt_uuid && p_get_proto_data(pinfo->pool, pinfo, proto_bluetooth, PROTO_DATA_BLUETOOTH_SERVICE_UUID) == NULL) {
char *value_data;
value_data = wmem_strdup(wmem_file_scope(), print_numeric_bluetooth_uuid(pinfo->pool, &uuid));
p_add_proto_data(pinfo->pool, pinfo, proto_bluetooth, PROTO_DATA_BLUETOOTH_SERVICE_UUID, value_data);
}
if (psm < BTL2CAP_DYNAMIC_PSM_START) {
psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm);
} else {
psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm_dynamic, tvb, offset, 0, psm);
if (uuid.bt_uuid)
proto_item_append_text(psm_item, ": %s",
val_to_str_ext_const(uuid.bt_uuid, &bluetooth_uuid_vals_ext, "Unknown service"));
}
proto_item_set_generated(psm_item);
}/*psm*/
if (btl2cap_frame_data->first_fragment) {
proto_tree_add_item(btl2cap_tree, hf_btl2cap_le_sdu_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
length = length - 2;
}
pinfo->fragmented = true;
frag_btl2cap_le_sdu = fragment_add_seq_next(&btl2cap_le_sdu_reassembly_table,
tvb, offset,
pinfo,
cid, /* uint32_t ID for fragments belonging together */
NULL, /* data* */
length, /* Fragment length */
btl2cap_frame_data->more_fragments); /* More fragments */
new_tvb = process_reassembled_data(tvb, offset, pinfo,
"Reassembled SDU",
frag_btl2cap_le_sdu,
&btl2cap_le_sdu_frag_items,
NULL,
btl2cap_tree);
if (new_tvb) {
if (psm) {
if (!dissector_try_uint_new(l2cap_cid_dissector_table, (uint32_t)cid, new_tvb, pinfo, tree, true, l2cap_data)) {
if (!dissector_try_uint_new(l2cap_psm_dissector_table, (uint32_t)psm, new_tvb, pinfo, tree, true, l2cap_data)) {
/* not a known fixed PSM, try to find a registered service to a dynamic PSM */
if (!dissector_try_string(bluetooth_uuid_table, print_numeric_bluetooth_uuid(pinfo->pool, &uuid), new_tvb, pinfo, tree, l2cap_data)) {
/* unknown protocol. declare as data */
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
}
}
}
} else {
/* call next dissector */
if (!dissector_try_uint_new(l2cap_cid_dissector_table, (uint32_t)cid, new_tvb, pinfo, tree, true, l2cap_data)) {
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
}
}
return tvb_captured_length(tvb);
}
col_set_str(pinfo->cinfo, COL_INFO, "L2CAP LE Fragment");
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
return tvb_captured_length(tvb);
}
static int
dissect_i_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_tree *btl2cap_tree, psm_data_t *psm_data, uint16_t length,
int offset, config_data_t *config_data, btl2cap_data_t *l2cap_data)
{
tvbuff_t *next_tvb = NULL;
uint16_t control, segment;
uint16_t sdulen;
proto_item* ti_control;
proto_tree* ti_control_subtree;
sdu_reassembly_t *mfp = NULL;
uint16_t psm = (psm_data ? psm_data->psm : 0);
control = tvb_get_letohs(tvb, offset);
segment = (control & 0xC000) >> 14;
switch (segment) {
case 0:
col_append_str(pinfo->cinfo, COL_INFO, "[I] Unsegmented SDU");
break;
case 1:
col_append_str(pinfo->cinfo, COL_INFO, "[I] Start SDU");
break;
case 2:
col_append_str(pinfo->cinfo, COL_INFO, "[I] End SDU");
break;
case 3:
col_append_str(pinfo->cinfo, COL_INFO, "[I] Continuation SDU");
break;
}
ti_control = proto_tree_add_none_format(btl2cap_tree, hf_btl2cap_control, tvb,
offset, 2, "Control: %s reqseq:%d r:%d txseq:%d",
val_to_str_const((control & 0xC000) >> 14, control_sar_vals, "unknown"),
(control & 0x3F00) >> 8,
(control & 0x0080) >> 7,
(control & 0x007E) >> 1);
ti_control_subtree = proto_item_add_subtree(ti_control, ett_btl2cap_control);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_sar, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_reqseq, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_retransmissiondisable, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_txseq, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_type, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
/*Segmented frames with SAR = start have an extra SDU length header field*/
if (segment == 0x01) {
proto_item *pi;
sdulen = tvb_get_letohs(tvb, offset);
pi = proto_tree_add_item(btl2cap_tree, hf_btl2cap_sdulength, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
/* Detect malformed data */
if (length <= 6) {
expert_add_info_format(pinfo, pi, &ei_btl2cap_sdulength_bad,
"SDU length too short: %u", length);
THROW(ReportedBoundsError);
}
length -= 6; /*Control, SDUlength, FCS*/
if (sdulen < length) {
sdulen = length;
expert_add_info_format(pinfo, pi, &ei_btl2cap_sdulength_bad,
"SDU length less than length of first packet (%u < %u)", sdulen, length);
}
if (!pinfo->fd->visited) {
mfp = wmem_new(wmem_file_scope(), sdu_reassembly_t);
mfp->first_frame = pinfo->num;
mfp->last_frame = 0;
mfp->tot_len = sdulen;
mfp->reassembled = (uint8_t *) wmem_alloc(wmem_file_scope(), sdulen);
tvb_memcpy(tvb, mfp->reassembled, offset, sdulen);
mfp->cur_off = sdulen;
wmem_tree_insert32(config_data->start_fragments, pinfo->num, mfp);
} else {
mfp = (sdu_reassembly_t *)wmem_tree_lookup32(config_data->start_fragments, pinfo->num);
}
if (mfp != NULL && mfp->last_frame) {
proto_item *item;
item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_reassembled_in, tvb, 0, 0, mfp->last_frame);
proto_item_set_generated(item);
col_append_frame_number(pinfo, COL_INFO, "[Reassembled in #%u] ", mfp->last_frame);
}
} else {
if (length <= 4) {
expert_add_info_format(pinfo, btl2cap_tree, &ei_btl2cap_length_bad,
"Control / FCS length too short: %u", length);
THROW(ReportedBoundsError);
}
length -= 4; /*Control, FCS*/
}
if (segment == 0x02 || segment == 0x03) {
mfp = (sdu_reassembly_t *)wmem_tree_lookup32_le(config_data->start_fragments, pinfo->num);
if (!pinfo->fd->visited) {
if (mfp != NULL && !mfp->last_frame && (mfp->tot_len>=mfp->cur_off + length)) {
tvb_memcpy(tvb, mfp->reassembled + mfp->cur_off, offset, length);
mfp->cur_off += length;
if (segment == 0x02) {
mfp->last_frame = pinfo->num;
}
}
}
if (mfp) {
proto_item *item;
item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_continuation_to, tvb, 0, 0, mfp->first_frame);
proto_item_set_generated(item);
col_append_fstr(pinfo->cinfo, COL_INFO, "[Continuation to #%u] ", mfp->first_frame);
}
}
if (segment == 0x02 && mfp != NULL && mfp->last_frame == pinfo->num) {
next_tvb = tvb_new_child_real_data(tvb, (uint8_t *)mfp->reassembled, mfp->tot_len, mfp->tot_len);
add_new_data_source(pinfo, next_tvb, "Reassembled L2CAP");
}
/*pass up to higher layer if we have a complete packet*/
if (segment == 0x00) {
next_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset) - 2, length);
}
if (next_tvb) {
if (psm) {
proto_item *psm_item;
uint16_t bt_uuid;
bluetooth_uuid_t uuid;
if (p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM ) == NULL) {
uint16_t *value_data;
value_data = wmem_new(wmem_file_scope(), uint16_t);
*value_data = psm;
p_add_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM, value_data);
}
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm, psm_data->local_service);
uuid.size = 2;
uuid.bt_uuid = bt_uuid;
uuid.data[0] = bt_uuid >> 8;
uuid.data[1] = bt_uuid & 0xFF;
if (bt_uuid && p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BLUETOOTH_SERVICE_UUID) == NULL) {
char *value_data;
value_data = wmem_strdup(wmem_file_scope(), print_numeric_bluetooth_uuid(pinfo->pool, &uuid));
p_add_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BLUETOOTH_SERVICE_UUID, value_data);
}
if (psm < BTL2CAP_DYNAMIC_PSM_START) {
psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm);
} else {
psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm_dynamic, tvb, offset, 0, psm);
if (uuid.bt_uuid)
proto_item_append_text(psm_item, " (%s)",
val_to_str_ext_const(uuid.bt_uuid, &bluetooth_uuid_vals_ext, "Unknown service"));
}
proto_item_set_generated(psm_item);
/* call next dissector */
if (!dissector_try_uint_new(l2cap_psm_dissector_table, (uint32_t) psm, next_tvb, pinfo, tree, true, l2cap_data)) {
/* not a known fixed PSM, try to find a registered service to a dynamic PSM */
if (!dissector_try_string(bluetooth_uuid_table, print_numeric_bluetooth_uuid(pinfo->pool, &uuid), next_tvb, pinfo, tree, l2cap_data)) {
/* unknown protocol. declare as data */
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, next_tvb, 0, tvb_reported_length(next_tvb), ENC_NA);
}
}
}
else {
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, next_tvb, 0, tvb_reported_length(next_tvb), ENC_NA);
}
}
offset += tvb_reported_length_remaining(tvb, offset) - 2;
proto_tree_add_item(btl2cap_tree, hf_btl2cap_fcs, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
return offset;
}
static int
dissect_s_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, proto_tree *btl2cap_tree,
uint16_t psm _U_, uint16_t length _U_, int offset, config_data_t *config_data _U_)
{
proto_item *ti_control;
proto_tree *ti_control_subtree;
uint16_t control;
control = tvb_get_letohs(tvb, offset);
switch ((control & 0x000C) >> 2) {
case 0:
col_append_str(pinfo->cinfo, COL_INFO, "[S] Receiver Ready");
break;
case 1:
col_append_str(pinfo->cinfo, COL_INFO, "[S] Reject");
break;
default:
col_append_str(pinfo->cinfo, COL_INFO, "[S] Unknown supervisory frame");
break;
}
ti_control = proto_tree_add_none_format(btl2cap_tree, hf_btl2cap_control, tvb,
offset, 2, "Control: %s reqseq:%d r:%d",
val_to_str_const((control & 0x000C) >> 2, control_supervisory_vals, "unknown"),
(control & 0x3F00) >> 8,
(control & 0x0080) >> 7);
ti_control_subtree = proto_item_add_subtree(ti_control, ett_btl2cap_control);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_reqseq, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_retransmissiondisable, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_supervisory, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_type, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(btl2cap_tree, hf_btl2cap_fcs, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
return offset;
}
static int
dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
int offset = 0;
proto_item *ti;
proto_tree *btl2cap_tree;
proto_item *length_item;
uint16_t length;
uint16_t cid;
uint16_t psm;
uint16_t control;
tvbuff_t *next_tvb = NULL;
psm_data_t *psm_data;
bthci_acl_data_t *acl_data;
btl2cap_data_t *l2cap_data;
bool dir_in_col = true;
acl_data = (bthci_acl_data_t *) data;
if ((acl_data) && (acl_data->is_btle)) {
dir_in_col = false;
}
ti = proto_tree_add_item(tree, proto_btl2cap, tvb, offset, -1, ENC_NA);
btl2cap_tree = proto_item_add_subtree(ti, ett_btl2cap);
col_set_str(pinfo->cinfo, COL_PROTOCOL, "L2CAP");
if (dir_in_col) {
switch (pinfo->p2p_dir) {
case P2P_DIR_SENT:
col_set_str(pinfo->cinfo, COL_INFO, "Sent ");
break;
case P2P_DIR_RECV:
col_set_str(pinfo->cinfo, COL_INFO, "Rcvd ");
break;
default:
col_set_str(pinfo->cinfo, COL_INFO, "UnknownDirection ");
break;
}
} else {
col_clear(pinfo->cinfo, COL_INFO);
}
length = tvb_get_letohs(tvb, offset);
length_item = proto_tree_add_item(btl2cap_tree, hf_btl2cap_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
if (tvb_captured_length_remaining(tvb, offset) < length) {
expert_add_info(pinfo, length_item, &ei_btl2cap_length_bad);
/* Try to dissect as more as possible */
length = tvb_captured_length_remaining(tvb, offset) - 4;
}
offset += 2;
cid = tvb_get_letohs(tvb, offset);
proto_tree_add_item(btl2cap_tree, hf_btl2cap_cid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
if (p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_CID ) == NULL) {
uint16_t *value_data;
value_data = wmem_new(wmem_file_scope(), uint16_t);
*value_data = cid;
p_add_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_CID, value_data);
}
offset += 2;
l2cap_data = wmem_new(pinfo->pool, btl2cap_data_t);
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
l2cap_data->interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
l2cap_data->interface_id = HCI_INTERFACE_DEFAULT;
if (acl_data) {
l2cap_data->adapter_id = acl_data->adapter_id;
l2cap_data->adapter_disconnect_in_frame = acl_data->adapter_disconnect_in_frame;
l2cap_data->chandle = acl_data->chandle;
l2cap_data->hci_disconnect_in_frame = acl_data->disconnect_in_frame;
l2cap_data->remote_bd_addr_oui = acl_data->remote_bd_addr_oui;
l2cap_data->remote_bd_addr_id = acl_data->remote_bd_addr_id;
} else {
l2cap_data->adapter_id = HCI_ADAPTER_DEFAULT;
l2cap_data->adapter_disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
l2cap_data->chandle = 0;
l2cap_data->hci_disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
l2cap_data->remote_bd_addr_oui = 0;
l2cap_data->remote_bd_addr_id = 0;
}
l2cap_data->disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
l2cap_data->cid = cid;
l2cap_data->local_cid = BTL2CAP_UNKNOWN_CID;
l2cap_data->remote_cid = BTL2CAP_UNKNOWN_CID;
l2cap_data->is_local_psm = false;
l2cap_data->psm = 0;
if (cid == BTL2CAP_FIXED_CID_SIGNAL || cid == BTL2CAP_FIXED_CID_LE_SIGNAL) {
/* This is a command packet*/
while (offset < length + 4) {
proto_item *ti_command;
proto_tree *btl2cap_cmd_tree;
uint8_t cmd_code;
uint8_t cmd_ident;
uint16_t cmd_length;
const char *cmd_str;
ti_command = proto_tree_add_none_format(btl2cap_tree,
hf_btl2cap_command, tvb,
offset, length,
"Command: ");
btl2cap_cmd_tree = proto_item_add_subtree(ti_command, ett_btl2cap_cmd);
cmd_code = tvb_get_uint8(tvb, offset);
proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cmd_code, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
cmd_ident = tvb_get_uint8(tvb, offset);
proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cmd_ident, tvb, offset, 1, ENC_LITTLE_ENDIAN);
offset += 1;
cmd_length = tvb_get_letohs(tvb, offset);
proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cmd_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_item_set_len(ti_command, cmd_length + 4);
offset += 2;
cmd_str = val_to_str_const(cmd_code, command_code_vals, "Unknown command");
proto_item_append_text(ti_command, "%s", cmd_str);
col_append_str(pinfo->cinfo, COL_INFO, cmd_str);
switch (cmd_code) {
case 0x01: /* Command Reject */
offset = dissect_comrej(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x02: /* Connection Request */
offset = dissect_connrequest(tvb, offset, pinfo, btl2cap_tree, btl2cap_cmd_tree, false, acl_data, l2cap_data);
break;
case 0x03: /* Connection Response */
offset = dissect_connresponse(tvb, offset, pinfo, btl2cap_cmd_tree, acl_data);
break;
case 0x04: /* Configure Request */
offset = dissect_configrequest(tvb, offset, pinfo, btl2cap_cmd_tree, cmd_length, acl_data);
break;
case 0x05: /* Configure Response */
offset = dissect_configresponse(tvb, offset, pinfo, btl2cap_cmd_tree, cmd_length, acl_data);
break;
case 0x06: /* Disconnect Request */
offset = dissect_disconnrequestresponse(tvb, offset, pinfo, btl2cap_tree, btl2cap_cmd_tree, acl_data, l2cap_data, true);
break;
case 0x07: /* Disconnect Response */
offset = dissect_disconnrequestresponse(tvb, offset, pinfo, btl2cap_tree, btl2cap_cmd_tree, acl_data, l2cap_data, false);
break;
case 0x08: /* Echo Request */
proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_data, tvb, offset, -1, ENC_NA);
offset = tvb_reported_length(tvb);
break;
case 0x09: /* Echo Response */
proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_data, tvb, offset, -1, ENC_NA);
offset = tvb_reported_length(tvb);
break;
case 0x0a: /* Information Request */
offset = dissect_inforequest(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x0b: /* Information Response */
offset = dissect_inforesponse(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x0c: /* Create Channel Request */
offset = dissect_connrequest(tvb, offset, pinfo, btl2cap_tree, btl2cap_cmd_tree, true, acl_data, l2cap_data);
break;
case 0x0d: /* Create Channel Response */
offset = dissect_chanresponse(tvb, offset, pinfo, btl2cap_cmd_tree, acl_data);
break;
case 0x0e: /* Move Channel Request */
offset = dissect_movechanrequest(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x0f: /* Move Channel Response */
offset = dissect_movechanresponse(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x10: /* Move Channel Confirmation */
offset = dissect_movechanconfirmation(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x11: /* Move Channel Confirmation Response */
offset = dissect_movechanconfirmationresponse(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x12: /* Connection Parameter Request */
offset = dissect_connparamrequest(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x13: /* Connection Parameter Response */
offset = dissect_connparamresponse(tvb, offset, pinfo, btl2cap_cmd_tree);
break;
case 0x14: /* LE Credit Based Connection Request */
offset = dissect_le_credit_based_connrequest(tvb, offset, pinfo, btl2cap_tree, btl2cap_cmd_tree, cid, cmd_ident, acl_data, l2cap_data);
col_append_fstr(pinfo->cinfo, COL_INFO, " (CID: %04x, Initial Credits: %u)",
tvb_get_letohs(tvb, offset - 8), tvb_get_letohs(tvb, offset - 2));
break;
case 0x15: /* LE Credit Based Connection Response */
offset = dissect_le_credit_based_connresponse(tvb, offset, pinfo, btl2cap_cmd_tree, cid, cmd_ident, acl_data);
col_append_fstr(pinfo->cinfo, COL_INFO, " (CID: %04x, Initial Credits: %u)",
tvb_get_letohs(tvb, offset - 10), tvb_get_letohs(tvb, offset - 4));
break;
case 0x16: /* LE Flow Control Credit */
proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_cid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(btl2cap_cmd_tree, hf_btl2cap_credits, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
col_append_fstr(pinfo->cinfo, COL_INFO, " (CID: %04x, Credits: %u)",
tvb_get_letohs(tvb, offset - 4), tvb_get_letohs(tvb, offset - 2));
break;
case 0x17: /* L2CAP Credit Based Connection Request */
offset = dissect_l2cap_credit_based_connrequest(tvb, offset, pinfo, btl2cap_tree, btl2cap_cmd_tree, cid, cmd_ident, cmd_length, acl_data, l2cap_data);
break;
case 0x18: /* L2CAP Credit Based Connection Response */
offset = dissect_l2cap_credit_based_connresponse(tvb, offset, pinfo, btl2cap_cmd_tree, cid, cmd_ident, cmd_length, acl_data);
break;
default:
proto_tree_add_expert(btl2cap_cmd_tree, pinfo, &ei_btl2cap_unknown_command_code, tvb, offset, -1);
offset += tvb_reported_length_remaining(tvb, offset);
break;
}
}
}
else if (cid == BTL2CAP_FIXED_CID_CONNLESS) { /* Connectionless reception channel */
col_append_str(pinfo->cinfo, COL_INFO, "Connectionless reception channel");
psm = tvb_get_letohs(tvb, offset);
if (pinfo->p2p_dir == P2P_DIR_RECV) {
l2cap_data->local_cid = cid;
l2cap_data->remote_cid = BTL2CAP_UNKNOWN_CID;
} else {
l2cap_data->local_cid = BTL2CAP_UNKNOWN_CID;
l2cap_data->remote_cid = cid;
}
l2cap_data->psm = psm;
l2cap_data->disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
if (p_get_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM ) == NULL) {
uint16_t *value_data;
value_data = wmem_new(wmem_file_scope(), uint16_t);
*value_data = psm;
p_add_proto_data(pinfo->pool, pinfo, proto_btl2cap, PROTO_DATA_BTL2CAP_PSM, value_data);
}
proto_tree_add_item(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
next_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset), length);
/* call next dissector */
if (!dissector_try_uint_new(l2cap_psm_dissector_table, (uint32_t) psm, next_tvb, pinfo, tree, true, l2cap_data)) {
/* not a known fixed PSM, try to find a registered service to a dynamic PSM */
uint16_t bt_uuid;
bluetooth_uuid_t uuid;
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm, (pinfo->p2p_dir == P2P_DIR_RECV) ? true : false );
uuid.size = 2;
uuid.bt_uuid = bt_uuid;
uuid.data[0] = bt_uuid >> 8;
uuid.data[1] = bt_uuid & 0xFF;
if (bt_uuid && p_get_proto_data(pinfo->pool, pinfo, proto_bluetooth, PROTO_DATA_BLUETOOTH_SERVICE_UUID ) == NULL) {
char* value_data;
value_data = wmem_strdup(wmem_file_scope(), print_numeric_bluetooth_uuid(pinfo->pool, &uuid));
p_add_proto_data(pinfo->pool, pinfo, proto_bluetooth, PROTO_DATA_BLUETOOTH_SERVICE_UUID, value_data);
}
if (!dissector_try_string(bluetooth_uuid_table, print_numeric_bluetooth_uuid(pinfo->pool, &uuid), next_tvb, pinfo, tree, l2cap_data)) {
/* unknown protocol. declare as data */
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
}
offset = tvb_captured_length(tvb);
}
}
else if (cid <= BTL2CAP_FIXED_CID_LAST) {
if (cid == BTL2CAP_FIXED_CID_AMP_MAN) {
control = tvb_get_letohs(tvb, offset);
if (control & 0x1) {
offset = dissect_s_frame(tvb, pinfo, tree, btl2cap_tree, 0 /* unused */, length, offset, NULL /* unused */);
} else {
proto_item* ti_control;
proto_tree* ti_control_subtree;
ti_control = proto_tree_add_none_format(btl2cap_tree, hf_btl2cap_control, tvb,
offset, 2, "Control: %s reqseq:%d r:%d txseq:%d",
val_to_str_const((control & 0xC000) >> 14, control_sar_vals, "unknown"),
(control & 0x3F00) >> 8,
(control & 0x0080) >> 7,
(control & 0x007E) >> 1);
ti_control_subtree = proto_item_add_subtree(ti_control, ett_btl2cap_control);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_sar, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_reqseq, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_retransmissiondisable, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_txseq, tvb, offset, 2, ENC_LITTLE_ENDIAN);
proto_tree_add_item(ti_control_subtree, hf_btl2cap_control_type, tvb, offset, 2, ENC_LITTLE_ENDIAN);
offset += 2;
proto_tree_add_item(btl2cap_tree, hf_btl2cap_fcs, tvb, tvb_reported_length(tvb) - 2, 2, ENC_LITTLE_ENDIAN);
next_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset)-2, length);
}
}
else {
next_tvb = tvb_new_subset_length_caplen(tvb, offset, tvb_captured_length_remaining(tvb, offset), length);
}
/* call next dissector */
if (next_tvb && !dissector_try_uint_new(l2cap_cid_dissector_table, (uint32_t) cid,
next_tvb, pinfo, tree, true, l2cap_data)) {
/* unknown protocol. declare as data */
proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA);
}
offset = tvb_captured_length(tvb);
}
else /* if (cid > BTL2CAP_FIXED_CID_LAST) */ { /* Connection oriented channel */
wmem_tree_key_t key[6];
uint32_t k_interface_id;
uint32_t k_adapter_id;
uint32_t k_chandle;
uint32_t k_cid;
uint32_t k_frame_number;
uint32_t interface_id;
uint32_t adapter_id;
uint32_t chandle;
uint32_t key_cid;
if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
interface_id = pinfo->rec->rec_header.packet_header.interface_id;
else
interface_id = HCI_INTERFACE_DEFAULT;
adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT;
chandle = (acl_data) ? acl_data->chandle : 0;
key_cid = cid | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x00000000 : 0x80000000);
k_interface_id = interface_id;
k_adapter_id = adapter_id;
k_chandle = chandle;
k_cid = key_cid;
k_frame_number = pinfo->num;
key[0].length = 1;
key[0].key = &k_interface_id;
key[1].length = 1;
key[1].key = &k_adapter_id;
key[2].length = 1;
key[2].key = &k_chandle;
key[3].length = 1;
key[3].key = &k_cid;
key[4].length = 1;
key[4].key = &k_frame_number;
key[5].length = 0;
key[5].key = NULL;
psm_data = (psm_data_t *)wmem_tree_lookup32_array_le(cid_to_psm_table, key);
if (psm_data &&
psm_data->interface_id == interface_id &&
psm_data->adapter_id == adapter_id &&
psm_data->chandle == chandle &&
(psm_data->local_cid == key_cid ||
psm_data->remote_cid == key_cid) &&
psm_data->disconnect_in_frame > pinfo->num)
{
config_data_t *config_data;
proto_item *sub_item;
uint32_t bt_uuid;
psm = psm_data->psm;
l2cap_data->local_cid = psm_data->local_cid;
l2cap_data->remote_cid = psm_data->remote_cid;
l2cap_data->psm = psm;
l2cap_data->is_local_psm = psm_data->local_service;
l2cap_data->disconnect_in_frame = &psm_data->disconnect_in_frame;
if (pinfo->p2p_dir == P2P_DIR_RECV)
config_data = &(psm_data->in);
else
config_data = &(psm_data->out);
if (psm_data->connect_in_frame > 0 && psm_data->connect_in_frame < UINT32_MAX) {
sub_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_connect_in_frame, tvb, 0, 0, psm_data->connect_in_frame);
proto_item_set_generated(sub_item);
}
if (psm_data->disconnect_in_frame > 0 && psm_data->disconnect_in_frame < UINT32_MAX) {
sub_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_disconnect_in_frame, tvb, 0, 0, psm_data->disconnect_in_frame);
proto_item_set_generated(sub_item);
}
bt_uuid = get_service_uuid(pinfo, l2cap_data, psm_data->psm, psm_data->local_service);
if (bt_uuid) {
sub_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_service, tvb, 0, 0, bt_uuid);
proto_item_set_generated(sub_item);
}
if (config_data->mode == L2CAP_BASIC_MODE) {
offset = dissect_b_frame(tvb, pinfo, tree, btl2cap_tree, cid, psm, psm_data->local_service, length, offset, l2cap_data);
} else if (config_data->mode == L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE) {
bool is_retransmit = false;
if (acl_data) {
is_retransmit = acl_data->is_btle_retransmit;
}
offset = dissect_le_frame(tvb, pinfo, tree, btl2cap_tree, cid, psm, psm_data->local_service, length, offset, config_data, l2cap_data, is_retransmit);
} else {
control = tvb_get_letohs(tvb, offset);
if (control & 0x1) {
offset = dissect_s_frame(tvb, pinfo, tree, btl2cap_tree, psm, length, offset, config_data);
} else {
offset = dissect_i_frame(tvb, pinfo, tree, btl2cap_tree, psm_data, length, offset, config_data, l2cap_data);
}
}
} else {
psm = 0;
offset = dissect_b_frame(tvb, pinfo, tree, btl2cap_tree, cid, psm, false, length, offset, l2cap_data);
}
}
return offset;
}
/* Register the protocol with Wireshark */
void
proto_register_btl2cap(void)
{
expert_module_t *expert_btl2cap;
/* Setup list of header fields See Section 1.6.1 for details*/
static hf_register_info hf[] = {
{ &hf_btl2cap_length,
{ "Length", "btl2cap.length",
FT_UINT16, BASE_DEC, NULL, 0x0,
"L2CAP Payload Length", HFILL }
},
{ &hf_btl2cap_cid,
{ "CID", "btl2cap.cid",
FT_UINT16, BASE_HEX | BASE_RANGE_STRING, RVALS(cid_rvals), 0x0,
"L2CAP Channel Identifier", HFILL }
},
{ &hf_btl2cap_payload,
{ "Payload", "btl2cap.payload",
FT_BYTES, BASE_NONE, NULL, 0x0,
"L2CAP Payload", HFILL }
},
{ &hf_btl2cap_command,
{ "Command", "btl2cap.command",
FT_NONE, BASE_NONE, NULL, 0x0,
"L2CAP Command", HFILL }
},
{ &hf_btl2cap_cmd_code,
{ "Command Code", "btl2cap.cmd_code",
FT_UINT8, BASE_HEX, VALS(command_code_vals), 0x0,
"L2CAP Command Code", HFILL }
},
{ &hf_btl2cap_cmd_ident,
{ "Command Identifier", "btl2cap.cmd_ident",
FT_UINT8, BASE_HEX, NULL, 0x0,
"L2CAP Command Identifier", HFILL }
},
{ &hf_btl2cap_cmd_length,
{ "Command Length", "btl2cap.cmd_length",
FT_UINT16, BASE_DEC, NULL, 0x0,
"L2CAP Command Length", HFILL }
},
{ &hf_btl2cap_cmd_data,
{ "Command Data", "btl2cap.cmd_data",
FT_NONE, BASE_NONE, NULL, 0x0,
"L2CAP Command Data", HFILL }
},
{ &hf_btl2cap_psm,
{ "PSM", "btl2cap.psm",
FT_UINT16, BASE_HEX, VALS(psm_vals), 0x0,
"Protocol/Service Multiplexer", HFILL }
},
{ &hf_btl2cap_psm_dynamic,
{ "Dynamic PSM", "btl2cap.psm",
FT_UINT16, BASE_HEX, NULL, 0x0,
"Dynamic Protocol/Service Multiplexer", HFILL }
},
{ &hf_btl2cap_scid,
{ "Source CID", "btl2cap.scid",
FT_UINT16, BASE_HEX | BASE_RANGE_STRING, RVALS(cid_rvals), 0x0,
"Source Channel Identifier", HFILL }
},
{ &hf_btl2cap_dcid,
{ "Destination CID", "btl2cap.dcid",
FT_UINT16, BASE_HEX | BASE_RANGE_STRING, RVALS(cid_rvals), 0x0,
"Destination Channel Identifier", HFILL }
},
{ &hf_btl2cap_icid,
{ "Initiator CID", "btl2cap.icid",
FT_UINT16, BASE_HEX | BASE_RANGE_STRING, RVALS(cid_rvals), 0x0,
"Initiator Channel Identifier", HFILL }
},
{ &hf_btl2cap_controller,
{ "Controller ID", "btl2cap.ctrl_id",
FT_UINT8, BASE_DEC, VALS(ctrl_id_code_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_dcontroller,
{ "Controller ID", "btl2cap.dctrl_id",
FT_UINT8, BASE_DEC, VALS(ctrl_id_code_vals), 0x0,
"Destination Controller ID", HFILL }
},
{ &hf_btl2cap_result,
{ "Result", "btl2cap.result",
FT_UINT16, BASE_HEX, VALS(result_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_move_result,
{ "Move Result", "btl2cap.move_result",
FT_UINT16, BASE_HEX, VALS(move_result_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_move_confirmation_result,
{ "Move Result", "btl2cap.move_result",
FT_UINT16, BASE_HEX, VALS(move_result_confirmation_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_status,
{ "Status", "btl2cap.status",
FT_UINT16, BASE_HEX, VALS(status_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_rej_reason,
{ "Reason", "btl2cap.rej_reason",
FT_UINT16, BASE_HEX, VALS(reason_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_sig_mtu,
{ "Maximum Signalling MTU", "btl2cap.sig_mtu",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_info_mtu,
{ "Remote Entity MTU", "btl2cap.info_mtu",
FT_UINT16, BASE_DEC, NULL, 0x0,
"Remote entity acceptable connectionless MTU", HFILL }
},
{ &hf_btl2cap_info_flowcontrol,
{ "Flow Control Mode", "btl2cap.info_flowcontrol",
FT_UINT32, BASE_DEC, NULL, 0x01,
"Flow Control mode support", HFILL }
},
{ &hf_btl2cap_info_retransmission,
{ "Retransmission Mode", "btl2cap.info_retransmission",
FT_UINT32, BASE_DEC, NULL, 0x02,
"Retransmission mode support", HFILL }
},
{ &hf_btl2cap_info_bidirqos,
{ "Bi-Directional QOS", "btl2cap.info_bidirqos",
FT_UINT32, BASE_DEC, NULL, 0x04,
"Bi-Directional QOS support", HFILL }
},
{ &hf_btl2cap_info_enh_retransmission,
{ "Enhanced Retransmission Mode", "btl2cap.info_enh_retransmission",
FT_UINT32, BASE_DEC, NULL, 0x08,
"Enhanced Retransmission mode support", HFILL }
},
{ &hf_btl2cap_info_streaming,
{ "Streaming Mode", "btl2cap.info_streaming",
FT_UINT32, BASE_DEC, NULL, 0x10,
"Streaming mode support", HFILL }
},
{ &hf_btl2cap_info_fcs,
{ "FCS", "btl2cap.info_fcs",
FT_UINT32, BASE_DEC, NULL, 0x20,
"FCS support", HFILL }
},
{ &hf_btl2cap_info_flow_spec,
{ "Extended Flow Specification for BR/EDR", "btl2cap.info_flow_spec",
FT_UINT32, BASE_DEC, NULL, 0x40,
"Extended Flow Specification for BR/EDR support", HFILL }
},
{ &hf_btl2cap_info_fixedchan,
{ "Fixed Channels", "btl2cap.info_fixedchan",
FT_UINT32, BASE_DEC, NULL, 0x80,
"Fixed Channels support", HFILL }
},
{ &hf_btl2cap_info_window,
{ "Extended Window Size", "btl2cap.info_window",
FT_UINT32, BASE_DEC, NULL, 0x0100,
"Extended Window Size support", HFILL }
},
{ &hf_btl2cap_info_unicast,
{ "Unicast Connectionless Data Reception", "btl2cap.info_unicast",
FT_UINT32, BASE_DEC, NULL, 0x0200,
"Unicast Connectionless Data Reception support", HFILL }
},
{ &hf_btl2cap_info_fixedchans,
{ "Fixed Channels", "btl2cap.info_fixedchans",
FT_NONE, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_info_fixedchans_null,
{ "Null identifier", "btl2cap.info_fixedchans_null",
FT_UINT32, BASE_DEC, NULL, 0x1,
NULL, HFILL }
},
{ &hf_btl2cap_info_fixedchans_signal,
{ "L2CAP signaling channel", "btl2cap.info_fixedchans_signal",
FT_UINT32, BASE_DEC, NULL, 0x2,
NULL, HFILL }
},
{ &hf_btl2cap_info_fixedchans_connless,
{ "Connectionless reception", "btl2cap.info_fixedchans_connless",
FT_UINT32, BASE_DEC, NULL, 0x4,
NULL, HFILL }
},
{ &hf_btl2cap_info_fixedchans_amp_man,
{ "AMP Manager protocol", "btl2cap.info_fixedchans_amp_man",
FT_UINT32, BASE_DEC, NULL, 0x8,
NULL, HFILL }
},
{ &hf_btl2cap_info_fixedchans_rfu,
{ "Reserved for future use", "btl2cap.info_fixedchans_rfu",
FT_UINT32, BASE_DEC, NULL, 0x00000070,
NULL, HFILL }
},
{ &hf_btl2cap_info_fixedchans_smp,
{ "BR/EDR Security Manager", "btl2cap.info_fixedchans_smp",
FT_UINT32, BASE_DEC, NULL, 0x00000080,
NULL, HFILL }
},
{ &hf_btl2cap_info_fixedchans_amp_test,
{ "AMP Test Manager", "btl2cap.info_fixedchans_amp_test",
FT_UINT32, BASE_DEC, NULL, 0x80000000,
NULL, HFILL }
},
{ &hf_btl2cap_info_type,
{ "Information Type", "btl2cap.info_type",
FT_UINT16, BASE_HEX, VALS(info_type_vals), 0x0,
"Type of implementation-specific information", HFILL }
},
{ &hf_btl2cap_info_result,
{ "Result", "btl2cap.info_result",
FT_UINT16, BASE_HEX, VALS(info_result_vals), 0x0,
"Information about the success of the request", HFILL }
},
{ &hf_btl2cap_info_extfeatures,
{ "Extended Features", "btl2cap.info_extfeatures",
FT_NONE, BASE_NONE, NULL, 0x0,
"Extended Features Mask", HFILL }
},
{ &hf_btl2cap_flags_reserved,
{ "Reserved", "btl2cap.flags.reserved",
FT_UINT16, BASE_HEX, NULL, 0xFFFE,
NULL, HFILL }
},
{ &hf_btl2cap_flags_continuation,
{ "Continuation Flag", "btl2cap.flags.continuation",
FT_BOOLEAN, 16, NULL, 0x0001,
NULL, HFILL }
},
{ &hf_btl2cap_configuration_result,
{ "Result", "btl2cap.conf_result",
FT_UINT16, BASE_HEX, VALS(configuration_result_vals), 0x0,
"Configuration Result", HFILL }
},
{ &hf_btl2cap_option_type,
{ "Type", "btl2cap.option_type",
FT_UINT8, BASE_HEX, VALS(option_type_vals), 0x0,
"Type of option", HFILL }
},
{ &hf_btl2cap_option_length,
{ "Length", "btl2cap.option_length",
FT_UINT8, BASE_DEC, NULL, 0x0,
"Number of octets in option payload", HFILL }
},
{ &hf_btl2cap_option_mtu,
{ "MTU", "btl2cap.option_mtu",
FT_UINT16, BASE_DEC, NULL, 0x0,
"Maximum Transmission Unit", HFILL }
},
{ &hf_btl2cap_option_flushTO,
{ "Flush Timeout (ms)", "btl2cap.option_flushto",
FT_UINT16, BASE_DEC, NULL, 0x0,
"Flush Timeout in milliseconds", HFILL }
},
{ &hf_btl2cap_option_flush_to_us,
{ "Flush Timeout (us)", "btl2cap.option_flushto",
FT_UINT32, BASE_DEC, NULL, 0x0,
"Flush Timeout (microseconds)", HFILL }
},
{ &hf_btl2cap_option_sdu_size,
{ "Maximum SDU Size", "btl2cap.option_sdu_size",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_option_sdu_arrival_time,
{ "SDU Inter-arrival Time (us)", "btl2cap.option_sdu_arrival_time",
FT_UINT32, BASE_DEC, NULL, 0x0,
"SDU Inter-arrival Time (microseconds)", HFILL }
},
{ &hf_btl2cap_option_identifier,
{ "Identifier", "btl2cap.option_ident",
FT_UINT8, BASE_HEX, NULL, 0x0,
"Flow Specification Identifier", HFILL }
},
{ &hf_btl2cap_option_access_latency,
{ "Access Latency (us)", "btl2cap.option_access_latency",
FT_UINT32, BASE_DEC, NULL, 0x0,
"Access Latency (microseconds)", HFILL }
},
{ &hf_btl2cap_option_flags,
{ "Flags", "btl2cap.option_flags",
FT_UINT8, BASE_HEX, NULL, 0x0,
"Flags - must be set to 0 (Reserved for future use)", HFILL }
},
{ &hf_btl2cap_option_service_type,
{ "Service Type", "btl2cap.option_servicetype",
FT_UINT8, BASE_HEX, VALS(option_servicetype_vals), 0x0,
"Level of service required", HFILL }
},
{ &hf_btl2cap_option_tokenrate,
{ "Token Rate (bytes/s)", "btl2cap.option_tokenrate",
FT_UINT32, BASE_DEC, NULL, 0x0,
"Rate at which traffic credits are granted (bytes/s)", HFILL }
},
{ &hf_btl2cap_option_tokenbucketsize,
{ "Token Bucket Size (bytes)", "btl2cap.option_tokenbsize",
FT_UINT32, BASE_DEC, NULL, 0x0,
"Size of the token bucket (bytes)", HFILL }
},
{ &hf_btl2cap_option_peakbandwidth,
{ "Peak Bandwidth (bytes/s)", "btl2cap.option_peakbandwidth",
FT_UINT32, BASE_DEC, NULL, 0x0,
"Limit how fast packets may be sent (bytes/s)", HFILL }
},
{ &hf_btl2cap_option_latency,
{ "Latency (microseconds)", "btl2cap.option_latency",
FT_UINT32, BASE_DEC, NULL, 0x0,
"Maximal acceptable delay (microseconds)", HFILL }
},
{ &hf_btl2cap_option_delayvariation,
{ "Delay Variation (microseconds)", "btl2cap.option_delayvar",
FT_UINT32, BASE_DEC, NULL, 0x0,
"Difference between maximum and minimum delay (microseconds)", HFILL }
},
{ &hf_btl2cap_option_retransmissionmode,
{ "Mode", "btl2cap.retransmissionmode",
FT_UINT8, BASE_HEX, VALS(option_retransmissionmode_vals), 0x0,
"Retransmission/Flow Control mode", HFILL }
},
{ &hf_btl2cap_option_txwindow,
{ "TxWindow", "btl2cap.txwindow",
FT_UINT8, BASE_DEC, NULL, 0x0,
"Retransmission window size", HFILL }
},
{ &hf_btl2cap_option_maxtransmit,
{ "MaxTransmit", "btl2cap.maxtransmit",
FT_UINT8, BASE_DEC, NULL, 0x0,
"Maximum I-frame retransmissions", HFILL }
},
{ &hf_btl2cap_option_retransmittimeout,
{ "Retransmit timeout (ms)", "btl2cap.retransmittimeout",
FT_UINT16, BASE_DEC, NULL, 0x0,
"Retransmission timeout (milliseconds)", HFILL }
},
{ &hf_btl2cap_option_monitortimeout,
{ "Monitor Timeout (ms)", "btl2cap.monitortimeout",
FT_UINT16, BASE_DEC, NULL, 0x0,
"S-frame transmission interval (milliseconds)", HFILL }
},
{ &hf_btl2cap_option_mps,
{ "MPS", "btl2cap.mps",
FT_UINT16, BASE_DEC, NULL, 0x0,
"Maximum PDU Payload Size", HFILL }
},
{ &hf_btl2cap_option_fcs,
{ "FCS", "btl2cap.option_fcs",
FT_UINT16, BASE_HEX, VALS(option_fcs_vals), 0x0,
"Frame Check Sequence", HFILL }
},
{ &hf_btl2cap_option_window,
{ "Extended Window Size", "btl2cap.option_window",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_option,
{ "Configuration Parameter Option", "btl2cap.conf_param_option",
FT_NONE, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_control_sar,
{ "Segmentation and reassembly", "btl2cap.control_sar",
FT_UINT16, BASE_HEX, VALS(control_sar_vals), 0xC000,
NULL, HFILL }
},
{ &hf_btl2cap_control_reqseq,
{ "ReqSeq", "btl2cap.control_reqseq",
FT_UINT16, BASE_DEC, NULL, 0x3F00,
"Request Sequence Number", HFILL }
},
{ &hf_btl2cap_control_txseq,
{ "TxSeq", "btl2cap.control_txseq",
FT_UINT16, BASE_DEC, NULL, 0x007E,
"Transmitted Sequence Number", HFILL }
},
{ &hf_btl2cap_control_retransmissiondisable,
{ "R", "btl2cap.control_retransmissiondisable",
FT_UINT16, BASE_HEX, NULL, 0x0080,
"Retransmission Disable", HFILL }
},
{ &hf_btl2cap_control_supervisory,
{ "S", "btl2cap.control_supervisory",
FT_UINT16, BASE_HEX, VALS(control_supervisory_vals), 0x000C,
"Supervisory Function", HFILL }
},
{ &hf_btl2cap_control_type,
{ "Frame Type", "btl2cap.control_type",
FT_UINT16, BASE_HEX, VALS(control_type_vals), 0x0001,
NULL, HFILL }
},
{ &hf_btl2cap_control,
{ "Control field", "btl2cap.control",
FT_NONE, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_fcs,
{ "FCS", "btl2cap.fcs",
FT_UINT16, BASE_HEX, NULL, 0,
"Frame Check Sequence", HFILL }
},
{ &hf_btl2cap_sdulength,
{ "SDU Length", "btl2cap.sdulength",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_btl2cap_reassembled_in,
{ "This SDU is reassembled in frame", "btl2cap.reassembled_in",
FT_FRAMENUM, BASE_NONE, NULL, 0,
"This SDU is reassembled in frame #", HFILL }
},
{ &hf_btl2cap_continuation_to,
{ "This is a continuation to the SDU in frame", "btl2cap.continuation_to",
FT_FRAMENUM, BASE_NONE, NULL, 0,
"This is a continuation to the SDU in frame #", HFILL }
},
{ &hf_btl2cap_min_interval,
{ "Min. Interval", "btl2cap.min_interval",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_btl2cap_max_interval,
{ "Max. Interval", "btl2cap.max_interval",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_btl2cap_peripheral_latency,
{ "Peripheral Latency", "btl2cap.peripheral_latency",
FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_ll_connection_event), 0,
NULL, HFILL }
},
{ &hf_btl2cap_timeout_multiplier,
{ "Timeout Multiplier", "btl2cap.timeout_multiplier",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL }
},
{ &hf_btl2cap_conn_param_result,
{ "Move Result", "btl2cap.move_result",
FT_UINT16, BASE_HEX, VALS(conn_param_result_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_le_result,
{ "LE Result", "btl2cap.le_result",
FT_UINT16, BASE_HEX, VALS(le_result_vals), 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_credits,
{ "Credits", "btl2cap.credits",
FT_UINT16, BASE_DEC, NULL, 0x0,
"L2CAP Channel Identifier", HFILL }
},
{ &hf_btl2cap_initial_credits,
{ "Initial Credits", "btl2cap.initial_credits",
FT_UINT16, BASE_DEC, NULL, 0x0,
"L2CAP Channel Identifier", HFILL }
},
{ &hf_btl2cap_le_psm,
{ "LE PSM", "btl2cap.le_psm",
FT_UINT16, BASE_HEX | BASE_RANGE_STRING, RVALS(le_psm_rvals), 0x0,
"Protocol/Service Multiplexer", HFILL }
},
{ &hf_btl2cap_data,
{ "Data", "btl2cap.data",
FT_BYTES, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_service,
{ "Service", "btl2cap.service",
FT_UINT16, BASE_HEX | BASE_EXT_STRING, &bluetooth_uuid_vals_ext, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_connect_in_frame,
{ "Connect in frame", "btl2cap.connect_in",
FT_FRAMENUM, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_disconnect_in_frame,
{ "Disconnect in frame", "btl2cap.disconnect_in",
FT_FRAMENUM, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragments,
{ "SDU fragments", "btl2cap.le_sdu.fragments",
FT_NONE, BASE_NONE, NULL, 0x00,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragment,
{ "SDU fragment", "btl2cap.le_sdu.fragment",
FT_FRAMENUM, BASE_NONE, NULL, 0x00,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragment_overlap,
{ "SDU fragment overlap", "btl2cap.le_sdu.fragment.overlap",
FT_BOOLEAN, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragment_overlap_conflicts,
{ "SDU fragment overlapping with conflicting data", "btl2cap.le_sdu.fragment.overlap.conflicts",
FT_BOOLEAN, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragment_multiple_tails,
{ "SDU has multiple tail fragments", "btl2cap.le_sdu.fragment.multiple_tails",
FT_BOOLEAN, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragment_too_long_fragment,
{ "SDU fragment too long", "btl2cap.le_sdu.fragment.too_long_fragment",
FT_BOOLEAN, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragment_error,
{ "SDU defragmentation error", "btl2cap.le_sdu.fragment.error",
FT_FRAMENUM, BASE_NONE, NULL, 0x00,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_fragment_count,
{ "SDU fragment count", "btl2cap.le_sdu.fragment.count",
FT_UINT32, BASE_DEC, NULL, 0x00,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_reassembled_in,
{ "Reassembled in", "btl2cap.le_sdu.reassembled.in",
FT_FRAMENUM, BASE_NONE, NULL, 0x00,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_reassembled_length,
{ "Reassembled SDU length", "btl2cap.le_sdu.reassembled.length",
FT_UINT32, BASE_DEC, NULL, 0x00,
NULL, HFILL }
},
{ &hf_btl2cap_le_sdu_length,
{ "SDU Length", "btl2cap.le_sdu_length",
FT_UINT16, BASE_DEC, NULL, 0x00,
NULL, HFILL }
},
};
/* Setup protocol subtree array */
static int *ett[] = {
&ett_btl2cap,
&ett_btl2cap_cmd,
&ett_btl2cap_option,
&ett_btl2cap_extfeatures,
&ett_btl2cap_fixedchans,
&ett_btl2cap_control,
&ett_btl2cap_le_sdu_fragment,
&ett_btl2cap_le_sdu_fragments
};
static ei_register_info ei[] = {
{ &ei_btl2cap_parameter_mismatch, { "btl2cap.parameter_mismatch", PI_PROTOCOL, PI_WARN, "Parameter mismatch", EXPFILL }},
{ &ei_btl2cap_sdulength_bad, { "btl2cap.sdulength.bad", PI_MALFORMED, PI_WARN, "SDU length bad", EXPFILL }},
{ &ei_btl2cap_length_bad, { "btl2cap.length.bad", PI_MALFORMED, PI_WARN, "Length too short", EXPFILL }},
{ &ei_btl2cap_unknown_command_code, { "btl2cap.unknown_command_code", PI_PROTOCOL, PI_WARN, "Unknown Command Code", EXPFILL }},
};
/* Decode As handling */
static build_valid_func btl2cap_cid_da_build_value[1] = {btl2cap_cid_value};
static decode_as_value_t btl2cap_cid_da_values = {btl2cap_cid_prompt, 1, btl2cap_cid_da_build_value};
static decode_as_t btl2cap_cid_da = {"btl2cap", "btl2cap.cid", 1, 0, &btl2cap_cid_da_values, NULL, NULL,
decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
static build_valid_func btl2cap_psm_da_build_value[1] = {btl2cap_psm_value};
static decode_as_value_t btl2cap_psm_da_values = {btl2cap_psm_prompt, 1, btl2cap_psm_da_build_value};
static decode_as_t btl2cap_psm_da = {"btl2cap", "btl2cap.psm", 1, 0, &btl2cap_psm_da_values, NULL, NULL,
decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
/* Register the protocol name and description */
proto_btl2cap = proto_register_protocol("Bluetooth L2CAP Protocol", "BT L2CAP", "btl2cap");
register_dissector("btl2cap", dissect_btl2cap, proto_btl2cap);
/* subdissector code */
l2cap_psm_dissector_table = register_dissector_table("btl2cap.psm", "BT L2CAP PSM", proto_btl2cap, FT_UINT16, BASE_HEX);
l2cap_cid_dissector_table = register_dissector_table("btl2cap.cid", "BT L2CAP CID", proto_btl2cap, FT_UINT16, BASE_HEX);
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_btl2cap, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
expert_btl2cap = expert_register_protocol(proto_btl2cap);
expert_register_field_array(expert_btl2cap, ei, array_length(ei));
cmd_ident_to_psm_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
cid_to_psm_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
register_decode_as(&btl2cap_cid_da);
register_decode_as(&btl2cap_psm_da);
reassembly_table_register(&btl2cap_le_sdu_reassembly_table,
&addresses_reassembly_table_functions);
}
void
proto_reg_handoff_btl2cap(void)
{
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
|