1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
178
179
180
183
184
185
188
189
192
193
194
195
196
197
198
199
200
201
202
203
204
207
208
209
210
227
228
229
230
238
239
242
243
249
250
251
252
253
254
255
256
257
258
259
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
291
292
293
296
297
298
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
330
331
332
335
336
337
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
384
385
388
389
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
416
417
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
468
469
471
474
475
476
477
480
481
482
483
484
485
486
487
488
489
490
494
495
496
497
498
499
500
501
502
503
504
505
506
510
516
517
518
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
551
552
553
554
555
556
557
560
561
563
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
599
600
601
604
605
606
609
610
613
614
615
616
617
618
619
620
621
622
623
624
625
628
629
630
631
632
633
640
641
642
645
646
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
675
676
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
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
730
731
732
733
734
735
736
737
738
739
741
745
746
747
748
749
750
751
756
757
765
766
767
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
821
839
840
841
844
845
846
847
848
850
851
854
855
856
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
887
888
889
890
891
892
893
894
896
897
898
899
900
901
904
905
909
910
911
915
916
917
918
919
920
921
922
927
928
931
932
933
934
935
936
937
938
939
940
941
942
945
946
947
948
949
950
951
952
956
973
974
975
976
979
980
981
988
989
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
1039
1040
1041
1042
1045
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
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
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
1175
1176
1177
1178
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1229
1230
1231
1232
1233
1234
1235
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
1275
1276
1277
1278
1279
1285
1286
1287
1288
1289
1290
1291
1292
1293
1299
1300
1301
1302
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
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
1370
1371
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1421
1422
1431
1432
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1480
1481
1487
1488
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
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
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
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1621
1625
1627
1628
1629
1630
1631
1632
1633
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1664
1665
1666
1670
1671
1673
1674
1675
1676
1683
1684
1686
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
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
1752
1753
1754
1755
1759
1760
1761
1762
1763
1764
1765
1773
1774
1775
1776
1781
1782
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
1825
1826
1827
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1843
1844
1845
1846
1849
1850
1851
1852
1857
1858
1859
1860
1865
1866
1867
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1885
1886
1892
1893
1894
1898
1899
1902
1903
1904
1905
1909
1910
1914
1915
1916
1917
1918
1921
1922
1923
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1945
1946
1947
1955
1956
1957
1958
1959
1960
1961
1962
1966
1967
1968
1969
1970
1971
1972
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1992
1993
1994
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
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
2079
2080
2081
2082
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2139
2140
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
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
2192
2193
2202
2203
2204
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2225
2231
2232
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2302
2303
2304
2305
2310
2311
2312
2313
2314
2315
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
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
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
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
2773
2774
2779
2780
2781
2782
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
2846
2847
2848
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2877
2878
2879
2880
2881
2882
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
2943
2944
2945
2946
2952
2953
2954
2963
2964
2965
2974
/* ... */
/* ... */
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include "osi/alarm.h"
#include "stack/bt_types.h"
#include "device/controller.h"
#include "stack/hcimsgs.h"
#include "stack/btu.h"
#include "stack/btm_api.h"
#include "btm_int.h"
#include "stack/hcidefs.h"11 includes
#if (defined(SDP_INCLUDED) && SDP_INCLUDED == TRUE)
#include "stack/sdpdefs.h"
#endif
#define BTM_INQ_REPLY_TIMEOUT 3
#ifndef BTM_INQ_DEBUG
#define BTM_INQ_DEBUG FALSE
#endif
static const LAP general_inq_lap = {0x9e, 0x8b, 0x33};
static const LAP limited_inq_lap = {0x9e, 0x8b, 0x00};
#if (defined(SDP_INCLUDED) && SDP_INCLUDED == TRUE)
static const UINT16 BTM_EIR_UUID_LKUP_TBL[BTM_EIR_MAX_SERVICES] = {
UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER,
UUID_SERVCLASS_SERIAL_PORT,
UUID_SERVCLASS_LAN_ACCESS_USING_PPP,
UUID_SERVCLASS_DIALUP_NETWORKING,
UUID_SERVCLASS_IRMC_SYNC,
UUID_SERVCLASS_OBEX_OBJECT_PUSH,
UUID_SERVCLASS_OBEX_FILE_TRANSFER,
UUID_SERVCLASS_IRMC_SYNC_COMMAND,
UUID_SERVCLASS_HEADSET,
UUID_SERVCLASS_CORDLESS_TELEPHONY,
UUID_SERVCLASS_AUDIO_SOURCE,
UUID_SERVCLASS_AUDIO_SINK,
UUID_SERVCLASS_AV_REM_CTRL_TARGET,
UUID_SERVCLASS_AV_REMOTE_CONTROL,
UUID_SERVCLASS_INTERCOM,
UUID_SERVCLASS_FAX,
UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY,
UUID_SERVCLASS_PANU,
UUID_SERVCLASS_NAP,
UUID_SERVCLASS_GN,
UUID_SERVCLASS_DIRECT_PRINTING,
UUID_SERVCLASS_IMAGING,
UUID_SERVCLASS_IMAGING_RESPONDER,
UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE,
UUID_SERVCLASS_IMAGING_REF_OBJECTS,
UUID_SERVCLASS_HF_HANDSFREE,
UUID_SERVCLASS_AG_HANDSFREE,
UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE,
UUID_SERVCLASS_BASIC_PRINTING,
UUID_SERVCLASS_PRINTING_STATUS,
UUID_SERVCLASS_HUMAN_INTERFACE,
UUID_SERVCLASS_CABLE_REPLACEMENT,
UUID_SERVCLASS_HCRP_PRINT,
UUID_SERVCLASS_HCRP_SCAN,
UUID_SERVCLASS_SAP,
UUID_SERVCLASS_PBAP_PCE,
UUID_SERVCLASS_PBAP_PSE,
UUID_SERVCLASS_PHONE_ACCESS,
UUID_SERVCLASS_HEADSET_HS,
UUID_SERVCLASS_PNP_INFORMATION,
UUID_SERVCLASS_VIDEO_SOURCE,
UUID_SERVCLASS_VIDEO_SINK,
UUID_SERVCLASS_MESSAGE_ACCESS,
UUID_SERVCLASS_MESSAGE_NOTIFICATION,
UUID_SERVCLASS_HDP_SOURCE,
UUID_SERVCLASS_HDP_SINK
}{...};/* ... */
#else
static const UINT16 BTM_EIR_UUID_LKUP_TBL[BTM_EIR_MAX_SERVICES];
#endif
...
static void btm_initiate_inquiry (tBTM_INQUIRY_VAR_ST *p_inq);
static tBTM_STATUS btm_set_inq_event_filter (UINT8 filter_cond_type, tBTM_INQ_FILT_COND *p_filt_cond);
static void btm_clr_inq_result_flt (void);
static UINT8 btm_convert_uuid_to_eir_service( UINT16 uuid16 );
static void btm_set_eir_uuid( UINT8 *p_eir, tBTM_INQ_RESULTS *p_results );
static UINT8 *btm_eir_get_uuid_list( UINT8 *p_eir, UINT8 uuid_size,
UINT8 *p_num_uuid, UINT8 *p_uuid_list_type );
static UINT16 btm_convert_uuid_to_uuid16( UINT8 *p_uuid, UINT8 uuid_size );
/* ... */
tBTM_STATUS BTM_SetDiscoverability (UINT16 inq_mode, UINT16 window, UINT16 interval)
{
UINT8 scan_mode = 0;
UINT16 service_class;
UINT8 *p_cod;
UINT8 major, minor, reserved_2;
DEV_CLASS cod;
LAP temp_lap[2];
BOOLEAN is_limited;
BOOLEAN cod_limited;
BTM_TRACE_API ("BTM_SetDiscoverability\n");
if (inq_mode > BTM_MAX_DISCOVERABLE) {
return (BTM_ILLEGAL_VALUE);
}{...}
if (!controller_get_interface()->get_is_ready()) {
return (BTM_DEV_RESET);
}{...}
if (!window) {
window = BTM_DEFAULT_DISC_WINDOW;
}{...}
if (!interval) {
interval = BTM_DEFAULT_DISC_INTERVAL;
}{...}
BTM_TRACE_API ("BTM_SetDiscoverability: mode %d [NonDisc-0, Lim-1, Gen-2], window 0x%04x, interval 0x%04x\n",
inq_mode, window, interval);
if (inq_mode != BTM_NON_DISCOVERABLE) {
if (window < HCI_MIN_INQUIRYSCAN_WINDOW ||
window > HCI_MAX_INQUIRYSCAN_WINDOW ||
interval < HCI_MIN_INQUIRYSCAN_INTERVAL ||
interval > HCI_MAX_INQUIRYSCAN_INTERVAL ||
window > interval) {
return (BTM_ILLEGAL_VALUE);
}{...}
}{...}
if (inq_mode != BTM_NON_DISCOVERABLE) {
if (inq_mode & BTM_LIMITED_DISCOVERABLE) {
memcpy (temp_lap[0], limited_inq_lap, LAP_LEN);
memcpy (temp_lap[1], general_inq_lap, LAP_LEN);
if (!btsnd_hcic_write_cur_iac_lap (2, (LAP * const) temp_lap)) {
return (BTM_NO_RESOURCES);
}{...}
}{...} else {
if (!btsnd_hcic_write_cur_iac_lap (1, (LAP * const) &general_inq_lap)) {
return (BTM_NO_RESOURCES);
}{...}
}{...}
scan_mode |= HCI_INQUIRY_SCAN_ENABLED;
}{...}
if ((window != btm_cb.btm_inq_vars.inq_scan_window) ||
(interval != btm_cb.btm_inq_vars.inq_scan_period)) {
if (btsnd_hcic_write_inqscan_cfg (interval, window)) {
btm_cb.btm_inq_vars.inq_scan_window = window;
btm_cb.btm_inq_vars.inq_scan_period = interval;
}{...} else {
return (BTM_NO_RESOURCES);
}{...}
}{...}
if (btm_cb.btm_inq_vars.connectable_mode & BTM_CONNECTABLE_MASK) {
scan_mode |= HCI_PAGE_SCAN_ENABLED;
}{...}
if (btsnd_hcic_write_scan_enable (scan_mode)) {
btm_cb.btm_inq_vars.discoverable_mode &= (~BTM_DISCOVERABLE_MASK);
btm_cb.btm_inq_vars.discoverable_mode |= inq_mode;
}{...} else {
return (BTM_NO_RESOURCES);
}{...}
p_cod = BTM_ReadDeviceClass();
BTM_COD_SERVICE_CLASS(service_class, p_cod);
is_limited = (inq_mode & BTM_LIMITED_DISCOVERABLE) ? TRUE : FALSE;
cod_limited = (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? TRUE : FALSE;
if (is_limited ^ cod_limited) {
BTM_COD_MINOR_CLASS(minor, p_cod );
BTM_COD_MAJOR_CLASS(major, p_cod );
BTM_COD_RESERVED_2(reserved_2, p_cod);
if (is_limited) {
service_class |= BTM_COD_SERVICE_LMTD_DISCOVER;
}{...} else {
service_class &= ~BTM_COD_SERVICE_LMTD_DISCOVER;
}{...}
FIELDS_TO_COD(cod, reserved_2, minor, major, service_class);
(void) BTM_SetDeviceClass (cod);
}{...}
return (BTM_SUCCESS);
}{ ... }
/* ... */
tBTM_STATUS BTM_SetInquiryScanType (UINT16 scan_type)
{
BTM_TRACE_API ("BTM_SetInquiryScanType\n");
if (scan_type != BTM_SCAN_TYPE_STANDARD && scan_type != BTM_SCAN_TYPE_INTERLACED) {
return (BTM_ILLEGAL_VALUE);
}{...}
if (!controller_get_interface()->supports_interlaced_inquiry_scan()) {
return (BTM_MODE_UNSUPPORTED);
}{...}
if (scan_type != btm_cb.btm_inq_vars.inq_scan_type) {
if (BTM_IsDeviceUp()) {
if (btsnd_hcic_write_inqscan_type ((UINT8)scan_type)) {
btm_cb.btm_inq_vars.inq_scan_type = scan_type;
}{...} else {
return (BTM_NO_RESOURCES);
}{...}
}{...} else {
return (BTM_WRONG_MODE);
}{...}
}{...}
return (BTM_SUCCESS);
}{ ... }
/* ... */
tBTM_STATUS BTM_SetPageScanType (UINT16 scan_type)
{
BTM_TRACE_API ("BTM_SetPageScanType\n");
if (scan_type != BTM_SCAN_TYPE_STANDARD && scan_type != BTM_SCAN_TYPE_INTERLACED) {
return (BTM_ILLEGAL_VALUE);
}{...}
if (!controller_get_interface()->supports_interlaced_inquiry_scan()) {
return (BTM_MODE_UNSUPPORTED);
}{...}
if (scan_type != btm_cb.btm_inq_vars.page_scan_type) {
if (BTM_IsDeviceUp()) {
if (btsnd_hcic_write_pagescan_type ((UINT8)scan_type)) {
btm_cb.btm_inq_vars.page_scan_type = scan_type;
}{...} else {
return (BTM_NO_RESOURCES);
}{...}
}{...} else {
return (BTM_WRONG_MODE);
}{...}
}{...}
return (BTM_SUCCESS);
}{ ... }
/* ... */
tBTM_STATUS BTM_SetInquiryMode (UINT8 mode)
{
const controller_t *controller = controller_get_interface();
BTM_TRACE_API ("BTM_SetInquiryMode\n");
if (mode == BTM_INQ_RESULT_STANDARD) {
}{...} else if (mode == BTM_INQ_RESULT_WITH_RSSI) {
if (!controller->supports_rssi_with_inquiry_results()) {
return (BTM_MODE_UNSUPPORTED);
}{...}
}{...} else if (mode == BTM_INQ_RESULT_EXTENDED) {
if (!controller->supports_extended_inquiry_response()) {
return (BTM_MODE_UNSUPPORTED);
}{...}
}{...} else {
return (BTM_ILLEGAL_VALUE);
}{...}
if (!BTM_IsDeviceUp()) {
return (BTM_WRONG_MODE);
}{...}
if (!btsnd_hcic_write_inquiry_mode (mode)) {
return (BTM_NO_RESOURCES);
}{...}
return (BTM_SUCCESS);
}{ ... }
/* ... */
UINT16 BTM_ReadDiscoverability (UINT16 *p_window, UINT16 *p_interval)
{
BTM_TRACE_API ("BTM_ReadDiscoverability\n");
if (p_window) {
*p_window = btm_cb.btm_inq_vars.inq_scan_window;
}{...}
if (p_interval) {
*p_interval = btm_cb.btm_inq_vars.inq_scan_period;
}{...}
return (btm_cb.btm_inq_vars.discoverable_mode);
}{ ... }
/* ... */
tBTM_STATUS BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms, UINT16 max_delay,
UINT16 min_delay, tBTM_INQ_RESULTS_CB *p_results_cb)
{
tBTM_STATUS status;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
BTM_TRACE_API ("BTM_SetPeriodicInquiryMode: mode: %d, dur: %d, rsps: %d, flt: %d, min: %d, max: %d\n",
p_inqparms->mode, p_inqparms->duration, p_inqparms->max_resps,
p_inqparms->filter_cond_type, min_delay, max_delay);
if (!BTM_IsDeviceUp()) {
return (BTM_WRONG_MODE);
}{...}
/* ... */
if (p_inq->inq_active || p_inq->inqfilt_active) {
return (BTM_BUSY);
}{...}
if (p_inqparms->mode != BTM_GENERAL_INQUIRY &&
p_inqparms->mode != BTM_LIMITED_INQUIRY) {
return (BTM_ILLEGAL_VALUE);
}{...}
if (p_inqparms->duration < BTM_MIN_INQUIRY_LEN ||
p_inqparms->duration > BTM_MAX_INQUIRY_LENGTH ||
min_delay <= p_inqparms->duration ||
min_delay < BTM_PER_INQ_MIN_MIN_PERIOD ||
min_delay > BTM_PER_INQ_MAX_MIN_PERIOD ||
max_delay <= min_delay ||
max_delay < BTM_PER_INQ_MIN_MAX_PERIOD)
{
return (BTM_ILLEGAL_VALUE);
}{...}
p_inq->inqparms = *p_inqparms;
p_inq->per_min_delay = min_delay;
p_inq->per_max_delay = max_delay;
p_inq->inq_cmpl_info.num_resp = 0;
p_inq->p_inq_results_cb = p_results_cb;
p_inq->inq_active = (UINT8)((p_inqparms->mode == BTM_LIMITED_INQUIRY) ?
(BTM_LIMITED_INQUIRY_ACTIVE | BTM_PERIODIC_INQUIRY_ACTIVE) :
(BTM_GENERAL_INQUIRY_ACTIVE | BTM_PERIODIC_INQUIRY_ACTIVE));
/* ... */
if (p_inqparms->filter_cond_type != BTM_CLR_INQUIRY_FILTER) {
p_inq->state = BTM_INQ_CLR_FILT_STATE;
p_inqparms->filter_cond_type = BTM_CLR_INQUIRY_FILTER;
}{...} else {
p_inq->state = BTM_INQ_SET_FILT_STATE;
}{...}
if ((status = btm_set_inq_event_filter (p_inqparms->filter_cond_type, &p_inqparms->filter_cond)) != BTM_CMD_STARTED) {
p_inq->p_inq_results_cb = NULL;
p_inq->state = BTM_INQ_INACTIVE_STATE;
}{...}
return (status);
}{ ... }
/* ... */
tBTM_STATUS BTM_CancelPeriodicInquiry(void)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
tBTM_STATUS status = BTM_SUCCESS;
BTM_TRACE_API ("BTM_CancelPeriodicInquiry called\n");
if (!BTM_IsDeviceUp()) {
return (BTM_WRONG_MODE);
}{...}
if (btm_cb.btm_inq_vars.inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) {
btm_cb.btm_inq_vars.inq_active = BTM_INQUIRY_INACTIVE;
btm_cb.btm_inq_vars.p_inq_results_cb = (tBTM_INQ_RESULTS_CB *) NULL;
if (!btsnd_hcic_exit_per_inq ()) {
status = BTM_NO_RESOURCES;
}{...}
/* ... */
if (p_inq->inqfilt_active) {
p_inq->pending_filt_complete_event++;
}{...}
p_inq->inqfilt_active = FALSE;
p_inq->inq_counter++;
}{...}
return (status);
}{ ... }
/* ... */
tBTM_STATUS BTM_SetConnectability (UINT16 page_mode, UINT16 window, UINT16 interval)
{
UINT8 scan_mode = 0;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
BTM_TRACE_API ("BTM_SetConnectability\n");
if (page_mode != BTM_NON_CONNECTABLE && page_mode != BTM_CONNECTABLE) {
return (BTM_ILLEGAL_VALUE);
}{...}
if (!controller_get_interface()->get_is_ready()) {
return (BTM_DEV_RESET);
}{...}
if (!window) {
window = BTM_DEFAULT_CONN_WINDOW;
}{...}
if (!interval) {
interval = BTM_DEFAULT_CONN_INTERVAL;
}{...}
BTM_TRACE_API ("BTM_SetConnectability: mode %d [NonConn-0, Conn-1], window 0x%04x, interval 0x%04x\n",
page_mode, window, interval);
if (page_mode == BTM_CONNECTABLE) {
if (window < HCI_MIN_PAGESCAN_WINDOW ||
window > HCI_MAX_PAGESCAN_WINDOW ||
interval < HCI_MIN_PAGESCAN_INTERVAL ||
interval > HCI_MAX_PAGESCAN_INTERVAL ||
window > interval) {
return (BTM_ILLEGAL_VALUE);
}{...}
scan_mode |= HCI_PAGE_SCAN_ENABLED;
}{...}
if ((window != p_inq->page_scan_window) ||
(interval != p_inq->page_scan_period)) {
p_inq->page_scan_window = window;
p_inq->page_scan_period = interval;
if (!btsnd_hcic_write_pagescan_cfg (interval, window)) {
return (BTM_NO_RESOURCES);
}{...}
}{...}
if (p_inq->discoverable_mode & BTM_DISCOVERABLE_MASK) {
scan_mode |= HCI_INQUIRY_SCAN_ENABLED;
}{...}
if (btsnd_hcic_write_scan_enable (scan_mode)) {
p_inq->connectable_mode &= (~BTM_CONNECTABLE_MASK);
p_inq->connectable_mode |= page_mode;
return (BTM_SUCCESS);
}{...}
return (BTM_NO_RESOURCES);
}{ ... }
/* ... */
UINT16 BTM_ReadConnectability (UINT16 *p_window, UINT16 *p_interval)
{
BTM_TRACE_API ("BTM_ReadConnectability\n");
if (p_window) {
*p_window = btm_cb.btm_inq_vars.page_scan_window;
}{...}
if (p_interval) {
*p_interval = btm_cb.btm_inq_vars.page_scan_period;
}{...}
return (btm_cb.btm_inq_vars.connectable_mode);
}{ ... }
/* ... */
UINT16 BTM_IsInquiryActive (void)
{
BTM_TRACE_API ("BTM_IsInquiryActive\n");
return (btm_cb.btm_inq_vars.inq_active);
}{ ... }
/* ... */
tBTM_STATUS BTM_CancelInquiry(void)
{
tBTM_STATUS status = BTM_SUCCESS;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
UINT8 active_mode = p_inq->inq_active;
#endif
BTM_TRACE_API ("BTM_CancelInquiry called\n");
if (!BTM_IsDeviceUp()) {
return (BTM_WRONG_MODE);
}{...}
if ((p_inq->inq_active & BTM_INQUIRY_ACTIVE_MASK) != 0 &&
(!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE))) {
p_inq->inq_active = BTM_INQUIRY_INACTIVE;
p_inq->state = BTM_INQ_INACTIVE_STATE;
p_inq->p_inq_results_cb = (tBTM_INQ_RESULTS_CB *) NULL;
p_inq->p_inq_cmpl_cb = (tBTM_CMPL_CB *) NULL;
/* ... */
if (p_inq->inqfilt_active) {
p_inq->inqfilt_active = FALSE;
p_inq->pending_filt_complete_event++;
}{...}
else {
if (((p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK) != 0)
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
&& (active_mode & BTM_BR_INQUIRY_MASK)
#endif
) {
if (!btsnd_hcic_inq_cancel()) {
status = BTM_NO_RESOURCES;
}{...}
}{...}
#if BLE_INCLUDED == TRUE
if (((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0)
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
&& (active_mode & BTM_BLE_INQ_ACTIVE_MASK)
#endif
) {
btm_ble_stop_inquiry();
}{...}
#endif/* ... */
}{...}
/* ... */
p_inq->inq_counter++;
btm_clr_inq_result_flt();
}{...}
return (status);
}{ ... }
/* ... */
tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, tBTM_INQ_RESULTS_CB *p_results_cb,
tBTM_CMPL_CB *p_cmpl_cb)
{
tBTM_STATUS status = BTM_CMD_STARTED;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
BTM_TRACE_API ("BTM_StartInquiry: mode: %d, dur: %d, rsps: %d, flt: %d\n",
p_inqparms->mode, p_inqparms->duration, p_inqparms->max_resps,
p_inqparms->filter_cond_type);
/* ... */
if (p_inq->inq_active || p_inq->inqfilt_active) {
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
if (p_inq->scan_type == INQ_LE_OBSERVE && p_inq->p_inq_ble_results_cb != NULL) {
BTM_TRACE_API("BTM_StartInquiry: LE observe in progress");
p_inq->scan_type = INQ_GENERAL;
p_inq->inq_active = BTM_INQUIRY_INACTIVE;
btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE;
btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE);
}{...} else
#endif
{
return (BTM_BUSY);
BTM_TRACE_API("BTM_StartInquiry: return BUSY\n");
}{...}
}{...} else {
p_inq->scan_type = INQ_GENERAL;
}{...}
if (!BTM_IsDeviceUp()) {
return (BTM_WRONG_MODE);
}{...}
if ((p_inqparms->mode & BTM_BR_INQUIRY_MASK) != BTM_GENERAL_INQUIRY &&
(p_inqparms->mode & BTM_BR_INQUIRY_MASK) != BTM_LIMITED_INQUIRY
#if (BLE_INCLUDED == TRUE)
&& (p_inqparms->mode & BTM_BLE_INQUIRY_MASK) != BTM_BLE_GENERAL_INQUIRY
&& (p_inqparms->mode & BTM_BLE_INQUIRY_MASK) != BTM_BLE_LIMITED_INQUIRY/* ... */
#endif
) {
return (BTM_ILLEGAL_VALUE);
}{...}
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
if (p_inq->next_state == BTM_FINISH) {
return BTM_ILLEGAL_VALUE;
}{...}
#endif/* ... */
p_inq->inqparms = *p_inqparms;
p_inq->state = BTM_INQ_ACTIVE_STATE;
p_inq->p_inq_cmpl_cb = p_cmpl_cb;
p_inq->p_inq_results_cb = p_results_cb;
p_inq->inq_cmpl_info.num_resp = 0;
p_inq->inq_active = p_inqparms->mode;
BTM_TRACE_DEBUG("BTM_StartInquiry: p_inq->inq_active = 0x%02x\n", p_inq->inq_active);
#if (BLE_INCLUDED==TRUE && (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE))
if ((p_inqparms->mode & BTM_BLE_INQUIRY_MASK) && (p_inqparms->mode & BTM_BR_INQUIRY_MASK)) {
BTM_TRACE_API("BTM:Interleave Inquiry Mode Set\n");
p_inqparms->duration = p_inqparms->intl_duration[p_inq->next_state];
p_inq->inqparms.duration = p_inqparms->duration;
}{...} else {
BTM_TRACE_API("BTM:Single Mode: No interleaving, Mode:0x%02x\n", p_inqparms->mode);
p_inq->next_state = BTM_NO_INTERLEAVING;
}{...}
#endif/* ... */
#if BLE_INCLUDED == TRUE
if ((p_inqparms->mode & BTM_BLE_INQUIRY_MASK)
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
&& (p_inq->next_state == BTM_BLE_ONE || p_inq->next_state == BTM_BLE_TWO ||
p_inq->next_state == BTM_NO_INTERLEAVING)/* ... */
#endif
)
{
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
p_inq->inq_active = (p_inqparms->mode & BTM_BLE_INQUIRY_MASK);
BTM_TRACE_API("BTM:Starting LE Scan with duration %d and activeMode:0x%02x\n",
p_inqparms->duration, (p_inqparms->mode & BTM_BLE_INQUIRY_MASK));/* ... */
#endif
if (!controller_get_interface()->supports_ble()) {
p_inq->inqparms.mode &= ~ BTM_BLE_INQUIRY_MASK;
status = BTM_ILLEGAL_VALUE;
}{...}
else if ((status = btm_ble_start_inquiry((UINT8)(p_inqparms->mode & BTM_BLE_INQUIRY_MASK),
p_inqparms->duration)) != BTM_CMD_STARTED) {
BTM_TRACE_ERROR("Err Starting LE Inquiry.\n");
p_inq->inqparms.mode &= ~ BTM_BLE_INQUIRY_MASK;
}{...}
#if (!defined(BTA_HOST_INTERLEAVE_SEARCH) || BTA_HOST_INTERLEAVE_SEARCH == FALSE)
p_inqparms->mode &= ~BTM_BLE_INQUIRY_MASK;
#endif
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
if (p_inq->next_state == BTM_NO_INTERLEAVING) {
p_inq->next_state = BTM_FINISH;
}{...} else {
BTM_TRACE_API("BTM:Interleaving: started LE scan, Advancing to next state: %d\n",
p_inq->next_state + 1);
p_inq->next_state += 1;
}{...}
if (status != BTM_CMD_STARTED) {
p_inq->next_state = BTM_BR_ONE;
}{...}
return status;/* ... */
#endif
BTM_TRACE_DEBUG("BTM_StartInquiry: mode = %02x\n", p_inqparms->mode);
}{...}
#endif/* ... */
if ((p_inqparms->mode & BTM_BR_INQUIRY_MASK) == BTM_INQUIRY_NONE) {
return status;
}{...}
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
if ((p_inq->next_state == BTM_BR_ONE || p_inq->next_state == BTM_BR_TWO ||
p_inq->next_state == BTM_NO_INTERLEAVING )) {
p_inq->inq_active = (p_inqparms->mode & BTM_BR_INQUIRY_MASK);
#endif
/* ... */
switch (p_inqparms->filter_cond_type) {
case BTM_CLR_INQUIRY_FILTER:
p_inq->state = BTM_INQ_SET_FILT_STATE;
break;
...
case BTM_FILTER_COND_DEVICE_CLASS:
case BTM_FILTER_COND_BD_ADDR:
/* ... */
p_inq->state = BTM_INQ_CLR_FILT_STATE;
p_inqparms->filter_cond_type = BTM_CLR_INQUIRY_FILTER;
break;
...
default:
return (BTM_ILLEGAL_VALUE);...
}{...}
if ((status = btm_set_inq_event_filter (p_inqparms->filter_cond_type,
&p_inqparms->filter_cond)) != BTM_CMD_STARTED) {
p_inq->state = BTM_INQ_INACTIVE_STATE;
}{...}
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
if (p_inq->next_state == BTM_NO_INTERLEAVING) {
p_inq->next_state = BTM_FINISH;
}{...} else {
BTM_TRACE_API("BTM:Interleaving: Started BTM inq, Advancing to next state: %d\n",
p_inq->next_state + 1);
p_inq->next_state += 1;
}{...}
}{...}
if (status != BTM_CMD_STARTED) {
/* ... */
BTM_TRACE_API("BTM:Interleaving: Error in Starting inquiry, status: 0x%02x\n", status);
p_inq->next_state = BTM_BR_ONE;
}{...}
#endif
return (status);
}{ ... }
/* ... */
tBTM_STATUS BTM_ReadRemoteDeviceName (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb
, tBT_TRANSPORT transport)
{
tBTM_INQ_INFO *p_cur = NULL;
tINQ_DB_ENT *p_i;
BTM_TRACE_API ("BTM_ReadRemoteDeviceName: bd addr [%02x%02x%02x%02x%02x%02x]\n",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
if ((p_i = btm_inq_db_find (remote_bda)) != NULL) {
p_cur = &p_i->inq_info;
}{...}
BTM_TRACE_API ("no device found in inquiry db\n");
#if (BLE_INCLUDED == TRUE)
if (transport == BT_TRANSPORT_LE) {
return btm_ble_read_remote_name(remote_bda, p_cur, p_cb);
}{...} else
#endif
{
return (btm_initiate_rem_name (remote_bda, p_cur, BTM_RMT_NAME_EXT,
BTM_EXT_RMT_NAME_TIMEOUT, p_cb));
}{...}
}{ ... }
/* ... */
tBTM_STATUS BTM_CancelRemoteDeviceName (void)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
BTM_TRACE_API ("BTM_CancelRemoteDeviceName()\n");
if (p_inq->remname_active) {
#if BLE_INCLUDED == TRUE
if (BTM_UseLeLink(p_inq->remname_bda)) {
if (btm_ble_cancel_remote_name(p_inq->remname_bda)) {
return (BTM_CMD_STARTED);
}{...} else {
return (BTM_UNKNOWN_ADDR);
}{...}
}{...} else
#endif
{
if (btsnd_hcic_rmt_name_req_cancel (p_inq->remname_bda)) {
return (BTM_CMD_STARTED);
}{...} else {
return (BTM_NO_RESOURCES);
}{...}
}{...}
}{...} else {
return (BTM_WRONG_MODE);
}{...}
}{ ... }
/* ... */
tBTM_INQ_INFO *BTM_InqDbRead (BD_ADDR p_bda)
{
BTM_TRACE_API ("BTM_InqDbRead: bd addr [%02x%02x%02x%02x%02x%02x]\n",
p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]);
tINQ_DB_ENT *p_ent = btm_inq_db_find(p_bda);
if (!p_ent) {
return NULL;
}{...}
return &p_ent->inq_info;
}{ ... }
/* ... */
tBTM_INQ_INFO *BTM_InqDbFirst (void)
{
UINT16 xx;
tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db;
for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) {
if (p_ent->in_use) {
return (&p_ent->inq_info);
}{...}
}{...}
return ((tBTM_INQ_INFO *)NULL);
}{ ... }
/* ... */
tBTM_INQ_INFO *BTM_InqDbNext (tBTM_INQ_INFO *p_cur)
{
tINQ_DB_ENT *p_ent;
UINT16 inx;
if (p_cur) {
p_ent = (tINQ_DB_ENT *) ((UINT8 *)p_cur - offsetof (tINQ_DB_ENT, inq_info));
inx = (UINT16)((p_ent - btm_cb.btm_inq_vars.inq_db) + 1);
for (p_ent = &btm_cb.btm_inq_vars.inq_db[inx]; inx < BTM_INQ_DB_SIZE; inx++, p_ent++) {
if (p_ent->in_use) {
return (&p_ent->inq_info);
}{...}
}{...}
return ((tBTM_INQ_INFO *)NULL);
}{...} else {
return (BTM_InqDbFirst());
}{...}
}{ ... }
/* ... */
tBTM_STATUS BTM_ClearInqDb (BD_ADDR p_bda)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
if (p_inq->inq_active != BTM_INQUIRY_INACTIVE ||
p_inq->inqfilt_active) {
return (BTM_BUSY);
}{...}
btm_clr_inq_db(p_bda);
return (BTM_SUCCESS);
}{ ... }
/* ... */
tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb)
{
if (btm_cb.devcb.p_txpwer_cmpl_cb) {
return (BTM_BUSY);
}{...}
btu_start_timer (&btm_cb.devcb.txpwer_timer, BTU_TTYPE_BTM_ACL, BTM_INQ_REPLY_TIMEOUT );
btm_cb.devcb.p_txpwer_cmpl_cb = p_cb;
if (!btsnd_hcic_read_inq_tx_power ()) {
btm_cb.devcb.p_txpwer_cmpl_cb = NULL;
btu_stop_timer (&btm_cb.devcb.txpwer_timer);
return (BTM_NO_RESOURCES);
}{...} else {
return (BTM_CMD_STARTED);
}{...}
}{ ... }
/* ... */
/* ... */
void btm_inq_db_reset (void)
{
tBTM_REMOTE_DEV_NAME rem_name;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
UINT8 num_responses;
UINT8 temp_inq_active;
tBTM_STATUS status;
btu_stop_timer (&p_inq->inq_timer_ent);
if (p_inq->inq_active != BTM_INQUIRY_INACTIVE) {
temp_inq_active = p_inq->inq_active;
/* ... */
p_inq->inq_active = BTM_INQUIRY_INACTIVE;
if (temp_inq_active == BTM_LIMITED_INQUIRY_ACTIVE ||
temp_inq_active == BTM_GENERAL_INQUIRY_ACTIVE) {
if (p_inq->p_inq_cmpl_cb) {
num_responses = 0;
(*p_inq->p_inq_cmpl_cb)(&num_responses);
}{...}
}{...}
}{...}
if (p_inq->remname_active ) {
btu_stop_timer (&p_inq->rmt_name_timer_ent);
p_inq->remname_active = FALSE;
memset(p_inq->remname_bda, 0, BD_ADDR_LEN);
if (p_inq->p_remname_cmpl_cb) {
rem_name.status = BTM_DEV_RESET;
(*p_inq->p_remname_cmpl_cb)(&rem_name);
p_inq->p_remname_cmpl_cb = NULL;
}{...}
}{...}
if (p_inq->inqfilt_active) {
p_inq->inqfilt_active = FALSE;
if (p_inq->p_inqfilter_cmpl_cb) {
status = BTM_DEV_RESET;
(*p_inq->p_inqfilter_cmpl_cb)(&status);
}{...}
}{...}
p_inq->state = BTM_INQ_INACTIVE_STATE;
p_inq->pending_filt_complete_event = 0;
p_inq->p_inq_results_cb = NULL;
btm_clr_inq_db(NULL);
btm_clr_inq_result_flt();
p_inq->discoverable_mode = BTM_NON_DISCOVERABLE;
p_inq->connectable_mode = BTM_NON_CONNECTABLE;
p_inq->page_scan_type = BTM_SCAN_TYPE_STANDARD;
p_inq->inq_scan_type = BTM_SCAN_TYPE_STANDARD;
#if BLE_INCLUDED == TRUE
p_inq->discoverable_mode |= BTM_BLE_NON_DISCOVERABLE;
p_inq->connectable_mode |= BTM_BLE_NON_CONNECTABLE;/* ... */
#endif
return;
}{ ... }
/* ... */
void btm_inq_db_init (void)
{
#if 0
memset (&btm_cb.btm_inq_vars, 0, sizeof (tBTM_INQUIRY_VAR_ST));
#endif
btu_free_timer(&btm_cb.btm_inq_vars.rmt_name_timer_ent);
memset(&btm_cb.btm_inq_vars.rmt_name_timer_ent, 0, sizeof(TIMER_LIST_ENT));
btu_free_timer(&btm_cb.btm_inq_vars.inq_timer_ent);
memset(&btm_cb.btm_inq_vars.inq_timer_ent, 0, sizeof(TIMER_LIST_ENT));
btm_cb.btm_inq_vars.no_inc_ssp = BTM_NO_SSP_ON_INQUIRY;
}{ ... }
/* ... */
void btm_inq_stop_on_ssp(void)
{
UINT8 normal_active = (BTM_GENERAL_INQUIRY_ACTIVE | BTM_LIMITED_INQUIRY_ACTIVE);
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("btm_inq_stop_on_ssp: no_inc_ssp=%d inq_active:0x%x state:%d inqfilt_active:%d\n",
btm_cb.btm_inq_vars.no_inc_ssp, btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active);/* ... */
#endif
if (btm_cb.btm_inq_vars.no_inc_ssp) {
if (btm_cb.btm_inq_vars.state == BTM_INQ_ACTIVE_STATE) {
if (btm_cb.btm_inq_vars.inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) {
BTM_CancelPeriodicInquiry();
}{...} else if (btm_cb.btm_inq_vars.inq_active & normal_active) {
btsnd_hcic_inq_cancel();
}{...}
}{...}
btm_cb.btm_inq_vars.inq_active |= BTM_SSP_INQUIRY_ACTIVE;
}{...}
}{ ... }
/* ... */
void btm_inq_clear_ssp(void)
{
btm_cb.btm_inq_vars.inq_active &= ~BTM_SSP_INQUIRY_ACTIVE;
}{ ... }
/* ... */
void btm_clr_inq_db (BD_ADDR p_bda)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
tINQ_DB_ENT *p_ent = p_inq->inq_db;
UINT16 xx;
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("btm_clr_inq_db: inq_active:0x%x state:%d\n",
btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state);/* ... */
#endif
for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) {
if (p_ent->in_use) {
if (p_bda == NULL ||
(!memcmp (p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN))) {
p_ent->in_use = FALSE;
}{...}
}{...}
}{...}
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("inq_active:0x%x state:%d\n",
btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state);/* ... */
#endif
}{ ... }
/* ... */
static void btm_clr_inq_result_flt (void)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
if (p_inq->p_bd_db) {
osi_free(p_inq->p_bd_db);
p_inq->p_bd_db = NULL;
}{...}
p_inq->num_bd_entries = 0;
p_inq->max_bd_entries = 0;
}{ ... }
/* ... */
BOOLEAN btm_inq_find_bdaddr (BD_ADDR p_bda)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
tINQ_BDADDR *p_db = &p_inq->p_bd_db[0];
UINT16 xx;
if ((p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) || !p_db) {
return (FALSE);
}{...}
for (xx = 0; xx < p_inq->num_bd_entries; xx++, p_db++) {
if (!memcmp(p_db->bd_addr, p_bda, BD_ADDR_LEN)
&& p_db->inq_count == p_inq->inq_counter) {
return (TRUE);
}{...}
}{...}
if (xx < p_inq->max_bd_entries) {
p_db->inq_count = p_inq->inq_counter;
memcpy(p_db->bd_addr, p_bda, BD_ADDR_LEN);
p_inq->num_bd_entries++;
}{...}
return (FALSE);
}{ ... }
/* ... */
tINQ_DB_ENT *btm_inq_db_find (BD_ADDR p_bda)
{
UINT16 xx;
tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db;
for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) {
if ((p_ent->in_use) && (!memcmp (p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN))) {
return (p_ent);
}{...}
}{...}
return (NULL);
}{ ... }
/* ... */
tINQ_DB_ENT *btm_inq_db_new (BD_ADDR p_bda)
{
UINT16 xx;
tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db;
tINQ_DB_ENT *p_old = btm_cb.btm_inq_vars.inq_db;
UINT32 ot = 0xFFFFFFFF;
for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) {
if (!p_ent->in_use) {
memset (p_ent, 0, sizeof (tINQ_DB_ENT));
memcpy (p_ent->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN);
p_ent->in_use = TRUE;
return (p_ent);
}{...}
if (p_ent->time_of_resp < ot) {
p_old = p_ent;
ot = p_ent->time_of_resp;
}{...}
}{...}
memset (p_old, 0, sizeof (tINQ_DB_ENT));
memcpy (p_old->inq_info.results.remote_bd_addr, p_bda, BD_ADDR_LEN);
p_old->in_use = TRUE;
return (p_old);
}{ ... }
/* ... */
static tBTM_STATUS btm_set_inq_event_filter (UINT8 filter_cond_type,
tBTM_INQ_FILT_COND *p_filt_cond)
{
UINT8 condition_length = DEV_CLASS_LEN * 2;
UINT8 condition_buf[DEV_CLASS_LEN * 2];
UINT8 *p_cond = condition_buf;
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("btm_set_inq_event_filter: filter type %d [Clear-0, COD-1, BDADDR-2]\n",
filter_cond_type);
BTM_TRACE_DEBUG (" condition [%02x%02x%02x %02x%02x%02x]\n",
p_filt_cond->bdaddr_cond[0], p_filt_cond->bdaddr_cond[1], p_filt_cond->bdaddr_cond[2],
p_filt_cond->bdaddr_cond[3], p_filt_cond->bdaddr_cond[4], p_filt_cond->bdaddr_cond[5]);/* ... */
#endif
switch (filter_cond_type) {
case BTM_FILTER_COND_DEVICE_CLASS:
memcpy (condition_buf, p_filt_cond->cod_cond.dev_class, DEV_CLASS_LEN);
memcpy (&condition_buf[DEV_CLASS_LEN],
p_filt_cond->cod_cond.dev_class_mask, DEV_CLASS_LEN);
break;
...
case BTM_FILTER_COND_BD_ADDR:
p_cond = p_filt_cond->bdaddr_cond;
break;
...
case BTM_CLR_INQUIRY_FILTER:
condition_length = 0;
break;
...
default:
return (BTM_ILLEGAL_VALUE); ...
}{...}
btm_cb.btm_inq_vars.inqfilt_active = TRUE;
if (btsnd_hcic_set_event_filter(HCI_FILTER_INQUIRY_RESULT, filter_cond_type,
p_cond, condition_length))
{
return (BTM_CMD_STARTED);
}{...} else {
return (BTM_NO_RESOURCES);
}{...}
}{ ... }
/* ... */
void btm_event_filter_complete (UINT8 *p)
{
UINT8 hci_status;
tBTM_STATUS status;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
tBTM_CMPL_CB *p_cb = p_inq->p_inqfilter_cmpl_cb;
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("btm_event_filter_complete: inq_active:0x%x state:%d inqfilt_active:%d\n",
btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active);/* ... */
#endif
if (p_inq->pending_filt_complete_event) {
p_inq->pending_filt_complete_event--;
return;
}{...}
/* ... */
if (p_inq->inqfilt_active == TRUE ) {
STREAM_TO_UINT8 (hci_status, p);
if (hci_status != HCI_SUCCESS) {
BTM_TRACE_WARNING ("BTM Warning: Set Event Filter Failed (HCI returned 0x%x)\n", hci_status);
status = BTM_ERR_PROCESSING;
}{...} else {
status = BTM_SUCCESS;
}{...}
/* ... */
if (p_inq->state == BTM_INQ_INACTIVE_STATE) {
p_inq->inqfilt_active = FALSE;
if (p_cb) {
(*p_cb) (&status);
}{...}
}{...} else
/* ... */
{
if (status != BTM_SUCCESS) {
btm_process_inq_complete (BTM_ERR_PROCESSING, (UINT8)(p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK));
p_inq->inqfilt_active = FALSE;
p_inq->inq_active = BTM_INQUIRY_INACTIVE;
p_inq->state = BTM_INQ_INACTIVE_STATE;
return;
}{...}
if (p_inq->state == BTM_INQ_CLR_FILT_STATE) {
if ((status = btm_set_inq_event_filter (p_inq->inqparms.filter_cond_type, &p_inq->inqparms.filter_cond)) == BTM_CMD_STARTED) {
p_inq->state = BTM_INQ_SET_FILT_STATE;
}{...} else {
p_inq->inqfilt_active = FALSE;
btm_process_inq_complete (BTM_ERR_PROCESSING, (UINT8)(p_inq->inqparms.mode & BTM_BR_INQUIRY_MASK));
}{...}
}{...} else {
p_inq->state = BTM_INQ_ACTIVE_STATE;
p_inq->inqfilt_active = FALSE;
btm_initiate_inquiry (p_inq);
}{...}
}{...}
}{...}
}{ ... }
/* ... */
static void btm_initiate_inquiry (tBTM_INQUIRY_VAR_ST *p_inq)
{
const LAP *lap;
tBTM_INQ_PARMS *p_inqparms = &p_inq->inqparms;
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("btm_initiate_inquiry: inq_active:0x%x state:%d inqfilt_active:%d\n",
btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active);/* ... */
#endif
btm_acl_update_busy_level (BTM_BLI_INQ_EVT);
if (p_inq->inq_active & BTM_SSP_INQUIRY_ACTIVE) {
btm_process_inq_complete (BTM_NO_RESOURCES, (UINT8)(p_inqparms->mode & BTM_BR_INQUIRY_MASK));
return;
}{...}
p_inqparms->max_resps = (UINT8)((p_inqparms->max_resps <= BTM_INQ_DB_SIZE) ? p_inqparms->max_resps : BTM_INQ_DB_SIZE);
lap = (p_inq->inq_active & BTM_LIMITED_INQUIRY_ACTIVE) ? &limited_inq_lap : &general_inq_lap;
if (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) {
if (!btsnd_hcic_per_inq_mode (p_inq->per_max_delay,
p_inq->per_min_delay,
*lap, p_inqparms->duration,
p_inqparms->max_resps)) {
btm_process_inq_complete (BTM_NO_RESOURCES, (UINT8)(p_inqparms->mode & BTM_BR_INQUIRY_MASK));
}{...}
}{...} else {
btm_clr_inq_result_flt();
if ((p_inq->p_bd_db = (tINQ_BDADDR *)osi_calloc(BT_DEFAULT_BUFFER_SIZE)) != NULL) {
p_inq->max_bd_entries = (UINT16)(BT_DEFAULT_BUFFER_SIZE / sizeof(tINQ_BDADDR));
/* ... */
}{...}
if (!btsnd_hcic_inquiry(*lap, p_inqparms->duration, 0)) {
btm_process_inq_complete (BTM_NO_RESOURCES, (UINT8)(p_inqparms->mode & BTM_BR_INQUIRY_MASK));
}{...}
}{...}
}{ ... }
/* ... */
void btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode)
{
UINT8 num_resp, xx;
BD_ADDR bda;
tINQ_DB_ENT *p_i;
tBTM_INQ_RESULTS *p_cur = NULL;
BOOLEAN is_new = TRUE;
BOOLEAN update = FALSE;
INT8 i_rssi;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
tBTM_INQ_RESULTS_CB *p_inq_results_cb = p_inq->p_inq_results_cb;
UINT8 page_scan_rep_mode = 0;
UINT8 page_scan_per_mode = 0;
UINT8 page_scan_mode = 0;
UINT8 rssi = 0;
DEV_CLASS dc;
UINT16 clock_offset;
UINT8 *p_eir_data = NULL;
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("btm_process_inq_results inq_active:0x%x state:%d inqfilt_active:%d inq_res_mode=%d\n",
btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active, inq_res_mode);/* ... */
#endif
if (!(p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK)) {
return;
}{...}
STREAM_TO_UINT8 (num_resp, p);
for (xx = 0; xx < num_resp; xx++) {
update = FALSE;
STREAM_TO_BDADDR (bda, p);
STREAM_TO_UINT8 (page_scan_rep_mode, p);
STREAM_TO_UINT8 (page_scan_per_mode, p);
if (inq_res_mode == BTM_INQ_RESULT_STANDARD) {
STREAM_TO_UINT8(page_scan_mode, p);
}{...}
STREAM_TO_DEVCLASS (dc, p);
STREAM_TO_UINT16 (clock_offset, p);
if (inq_res_mode != BTM_INQ_RESULT_STANDARD) {
STREAM_TO_UINT8(rssi, p);
}{...}
p_i = btm_inq_db_find (bda);
/* ... */
if (p_inq->inqparms.max_resps &&
p_inq->inq_cmpl_info.num_resp >= p_inq->inqparms.max_resps
#if BLE_INCLUDED == TRUE
&& ( p_i == NULL ||
(p_i && (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0)
)/* ... */
#endif
) {
BTM_TRACE_WARNING("INQ RES: Extra Response Received...ignoring\n");
return;
}{...}
if (btm_inq_find_bdaddr(bda)) {
BTM_TRACE_DEBUG("BDA seen before [%02x%02x %02x%02x %02x%02x]\n",
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
i_rssi = (INT8)rssi;
if (p_inq->inqparms.report_dup && (rssi != 0) &&
p_i && (i_rssi > p_i->inq_info.results.rssi || p_i->inq_info.results.rssi == 0
#if BLE_INCLUDED == TRUE
|| (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0/* ... */
#endif
)) {
p_cur = &p_i->inq_info.results;
BTM_TRACE_DEBUG("update RSSI new:%d, old:%d\n", i_rssi, p_cur->rssi);
p_cur->rssi = i_rssi;
update = TRUE;
}{...}
else if ((inq_res_mode == BTM_INQ_RESULT_EXTENDED) && (p_i)) {
p_cur = &p_i->inq_info.results;
update = TRUE;
}{...}
else {
continue;
}{...}
}{...}
if (p_i == NULL) {
p_i = btm_inq_db_new (bda);
is_new = TRUE;
}{...}
/* ... */
else if (p_i->inq_count == p_inq->inq_counter
#if (BLE_INCLUDED == TRUE )
&& (p_i->inq_info.results.device_type == BT_DEVICE_TYPE_BREDR)
#endif
) {
is_new = FALSE;
}{...}
if ( inq_res_mode != BTM_INQ_RESULT_STANDARD ) {
p_i->inq_info.results.rssi = (INT8)rssi;
}{...} else {
p_i->inq_info.results.rssi = BTM_INQ_RES_IGNORE_RSSI;
}{...}
if (is_new == TRUE) {
p_cur = &p_i->inq_info.results;
p_cur->page_scan_rep_mode = page_scan_rep_mode;
p_cur->page_scan_per_mode = page_scan_per_mode;
p_cur->page_scan_mode = page_scan_mode;
p_cur->dev_class[0] = dc[0];
p_cur->dev_class[1] = dc[1];
p_cur->dev_class[2] = dc[2];
p_cur->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID;
p_i->time_of_resp = osi_time_get_os_boottime_ms();
if (p_i->inq_count != p_inq->inq_counter) {
p_inq->inq_cmpl_info.num_resp++;
}{...}
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
p_cur->inq_result_type = BTM_INQ_RESULT_BR;
if (p_i->inq_count != p_inq->inq_counter) {
p_cur->device_type = BT_DEVICE_TYPE_BREDR;
p_i->scan_rsp = FALSE;
}{...} else {
p_cur->device_type |= BT_DEVICE_TYPE_BREDR;
}{...}
#endif/* ... */
p_i->inq_count = p_inq->inq_counter;
if (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) &&
p_inq->inqparms.max_resps &&
p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps
#if BLE_INCLUDED == TRUE
&& ((((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) &&
p_cur->device_type == BT_DEVICE_TYPE_DUMO && p_i->scan_rsp) ||
(p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) == 0)/* ... */
#endif
) {
btsnd_hcic_inq_cancel();
#if BLE_INCLUDED == TRUE
if ((p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK) != 0) {
btm_ble_stop_inquiry();
}{...}
#endif/* ... */
btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT);
}{...}
p_i->inq_info.appl_knows_rem_name = FALSE;
}{...}
if (is_new || update) {
if ( inq_res_mode == BTM_INQ_RESULT_EXTENDED ) {
memset( p_cur->eir_uuid, 0,
BTM_EIR_SERVICE_ARRAY_SIZE * (BTM_EIR_ARRAY_BITS / 8));
btm_set_eir_uuid( p, p_cur );
p_eir_data = p;
}{...} else {
p_eir_data = NULL;
}{...}
if (p_inq_results_cb) {
(p_inq_results_cb)((tBTM_INQ_RESULTS *) p_cur, p_eir_data);
}{...}
}{...}
}{...}
}{ ... }
/* ... */
void btm_sort_inq_result(void)
{
UINT8 xx, yy, num_resp;
tINQ_DB_ENT *p_tmp = NULL;
tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db;
tINQ_DB_ENT *p_next = btm_cb.btm_inq_vars.inq_db + 1;
int size;
num_resp = (btm_cb.btm_inq_vars.inq_cmpl_info.num_resp < BTM_INQ_DB_SIZE) ?
btm_cb.btm_inq_vars.inq_cmpl_info.num_resp : BTM_INQ_DB_SIZE;
if ((p_tmp = (tINQ_DB_ENT *)osi_malloc(sizeof(tINQ_DB_ENT))) != NULL) {
size = sizeof(tINQ_DB_ENT);
for (xx = 0; xx < num_resp - 1; xx++, p_ent++) {
for (yy = xx + 1, p_next = p_ent + 1; yy < num_resp; yy++, p_next++) {
if (p_ent->inq_info.results.rssi < p_next->inq_info.results.rssi) {
memcpy (p_tmp, p_next, size);
memcpy (p_next, p_ent, size);
memcpy (p_ent, p_tmp, size);
}{...}
}{...}
}{...}
osi_free(p_tmp);
}{...}
}{ ... }
/* ... */
void btm_process_inq_complete (UINT8 status, UINT8 mode)
{
tBTM_CMPL_CB *p_inq_cb = btm_cb.btm_inq_vars.p_inq_cmpl_cb;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
/* ... */
if (status != HCI_SUCCESS || p_inq->next_state == BTM_FINISH || !p_inq->inq_active) {
p_inq->next_state = BTM_BR_ONE;
p_inq->inqparms.mode &= ~(p_inq->inqparms.mode);
}{...}
#endif/* ... */
#if (!defined(BTA_HOST_INTERLEAVE_SEARCH) || BTA_HOST_INTERLEAVE_SEARCH == FALSE)
p_inq->inqparms.mode &= ~(mode);
#endif
if (p_inq->scan_type == INQ_LE_OBSERVE && !p_inq->inq_active) {
p_inq->p_inq_ble_results_cb = (tBTM_INQ_RESULTS_CB *) NULL;
p_inq->p_inq_ble_cmpl_cb = (tBTM_CMPL_CB *) NULL;
p_inq->scan_type = INQ_NONE;
}{...}
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("btm_process_inq_complete inq_active:0x%x state:%d inqfilt_active:%d\n",
btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active);/* ... */
#endif
btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT);
if (p_inq->inq_active) {
p_inq->inq_cmpl_info.status = (tBTM_STATUS)((status == HCI_SUCCESS) ? BTM_SUCCESS : BTM_ERR_PROCESSING);
if (!(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) && p_inq->inqparms.mode == 0) {
#if BLE_INCLUDED == TRUE
btm_clear_all_pending_le_entry();
#endif
p_inq->state = BTM_INQ_INACTIVE_STATE;
p_inq->inq_counter++;
btm_clr_inq_result_flt();
if ((p_inq->inq_cmpl_info.status == BTM_SUCCESS) &&
controller_get_interface()->supports_rssi_with_inquiry_results()) {
btm_sort_inq_result();
}{...}
p_inq->p_inq_results_cb = (tBTM_INQ_RESULTS_CB *) NULL;
p_inq->inq_active = BTM_INQUIRY_INACTIVE;
p_inq->p_inq_cmpl_cb = (tBTM_CMPL_CB *) NULL;
BTM_TRACE_DEBUG ("BTM Inq Compl Callback: status 0x%02x, num results %d\n",
p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp);
if (p_inq_cb) {
(p_inq_cb)((tBTM_INQUIRY_CMPL *) &p_inq->inq_cmpl_info);
}{...}
}{...}
#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
if (p_inq->inqparms.mode != 0 && !(p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE)) {
p_inq->inq_active = BTM_INQUIRY_INACTIVE;
BTM_StartInquiry(&p_inq->inqparms, p_inq->p_inq_results_cb, p_inq->p_inq_cmpl_cb);
}{...}
#endif/* ... */
}{...}
if (p_inq->inqparms.mode == 0 && p_inq->scan_type == INQ_GENERAL) {
p_inq->scan_type = INQ_NONE;
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
if (p_inq->p_inq_ble_results_cb != NULL) {
BTM_TRACE_DEBUG("BTM Inq Compl: resuming a pending LE scan");
BTM_BleObserve(1, 0, p_inq->p_inq_ble_results_cb, p_inq->p_inq_ble_cmpl_cb);
}{...}
#endif/* ... */
}{...}
#if (BTM_INQ_DEBUG == TRUE)
BTM_TRACE_DEBUG ("inq_active:0x%x state:%d inqfilt_active:%d\n",
btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active);/* ... */
#endif
}{ ... }
/* ... */
void btm_process_cancel_complete(UINT8 status, UINT8 mode)
{
btm_acl_update_busy_level (BTM_BLI_INQ_CANCEL_EVT);
btm_process_inq_complete(status, mode);
}{ ... }
/* ... */
tBTM_STATUS btm_initiate_rem_name (BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur,
UINT8 origin, UINT32 timeout, tBTM_CMPL_CB *p_cb)
{
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
BOOLEAN cmd_ok;
if (!BTM_IsDeviceUp()) {
return (BTM_WRONG_MODE);
}{...}
if (origin == BTM_RMT_NAME_SEC) {
cmd_ok = btsnd_hcic_rmt_name_req (remote_bda, HCI_PAGE_SCAN_REP_MODE_R1,
HCI_MANDATARY_PAGE_SCAN_MODE, 0);
if (cmd_ok) {
return BTM_CMD_STARTED;
}{...} else {
return BTM_NO_RESOURCES;
}{...}
}{...}
else if (origin == BTM_RMT_NAME_EXT) {
if (p_inq->remname_active) {
return (BTM_BUSY);
}{...} else {
p_inq->p_remname_cmpl_cb = p_cb;
memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN);
btu_start_timer (&p_inq->rmt_name_timer_ent,
BTU_TTYPE_BTM_RMT_NAME,
timeout);
if (p_cur) {
cmd_ok = btsnd_hcic_rmt_name_req (remote_bda,
p_cur->results.page_scan_rep_mode,
p_cur->results.page_scan_mode,
(UINT16)(p_cur->results.clock_offset |
BTM_CLOCK_OFFSET_VALID));
}{...} else {
cmd_ok = btsnd_hcic_rmt_name_req (remote_bda, HCI_PAGE_SCAN_REP_MODE_R1,
HCI_MANDATARY_PAGE_SCAN_MODE, 0);
}{...}
if (cmd_ok) {
p_inq->remname_active = TRUE;
return BTM_CMD_STARTED;
}{...} else {
return BTM_NO_RESOURCES;
}{...}
}{...}
}{...} else {
return BTM_ILLEGAL_VALUE;
}{...}
}{ ... }
/* ... */
void btm_process_remote_name (BD_ADDR bda, BD_NAME bdn, UINT16 evt_len, UINT8 hci_status)
{
tBTM_REMOTE_DEV_NAME rem_name;
tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
tBTM_CMPL_CB *p_cb = p_inq->p_remname_cmpl_cb;
UINT8 *p_n1;
UINT16 temp_evt_len;
if (bda != NULL) {
BTM_TRACE_EVENT("BDA %02x:%02x:%02x:%02x:%02x:%02x\n", bda[0], bda[1],
bda[2], bda[3],
bda[4], bda[5]);
}{...}
BTM_TRACE_EVENT("Inquire BDA %02x:%02x:%02x:%02x:%02x:%02x\n", p_inq->remname_bda[0], p_inq->remname_bda[1],
p_inq->remname_bda[2], p_inq->remname_bda[3],
p_inq->remname_bda[4], p_inq->remname_bda[5]);
if ((p_inq->remname_active == TRUE) &&
(((bda != NULL) &&
(memcmp(bda, p_inq->remname_bda, BD_ADDR_LEN) == 0)) || bda == NULL))
{
#if BLE_INCLUDED == TRUE
if (BTM_UseLeLink(p_inq->remname_bda)) {
if (hci_status == HCI_ERR_UNSPECIFIED) {
btm_ble_cancel_remote_name(p_inq->remname_bda);
}{...}
}{...}
#endif/* ... */
btu_stop_timer (&p_inq->rmt_name_timer_ent);
p_inq->remname_active = FALSE;
if (hci_status == HCI_SUCCESS) {
p_n1 = (UINT8 *)rem_name.remote_bd_name;
rem_name.length = (evt_len < BD_NAME_LEN) ? evt_len : BD_NAME_LEN;
rem_name.remote_bd_name[rem_name.length] = 0;
rem_name.status = BTM_SUCCESS;
temp_evt_len = rem_name.length;
while (temp_evt_len > 0) {
*p_n1++ = *bdn++;
temp_evt_len--;
}{...}
rem_name.remote_bd_name[rem_name.length] = 0;
}{...}
else {
rem_name.status = BTM_BAD_VALUE_RET;
rem_name.length = 0;
rem_name.remote_bd_name[0] = '\0';
}{...}
memcpy(rem_name.bd_addr, p_inq->remname_bda, BD_ADDR_LEN);
memset(p_inq->remname_bda, 0, BD_ADDR_LEN);
p_inq->p_remname_cmpl_cb = NULL;
if (p_cb) {
(p_cb)((tBTM_REMOTE_DEV_NAME *)&rem_name);
}{...}
}{...}
}{ ... }
/* ... */
void btm_inq_rmt_name_failed (void)
{
BTM_TRACE_ERROR ("btm_inq_rmt_name_failed() remname_active=%d\n", btm_cb.btm_inq_vars.remname_active);
if (btm_cb.btm_inq_vars.remname_active) {
btm_process_remote_name (btm_cb.btm_inq_vars.remname_bda, NULL, 0, HCI_ERR_UNSPECIFIED);
}{...} else {
btm_process_remote_name (NULL, NULL, 0, HCI_ERR_UNSPECIFIED);
}{...}
#if (SMP_INCLUDED == TRUE)
btm_sec_rmt_name_request_complete (NULL, NULL, HCI_ERR_UNSPECIFIED);
#endif
}{ ... }
/* ... */
void btm_read_linq_tx_power_complete(UINT8 *p)
{
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_txpwer_cmpl_cb;
tBTM_INQ_TXPWR_RESULTS results;
btu_stop_timer (&btm_cb.devcb.txpwer_timer);
btm_cb.devcb.p_txpwer_cmpl_cb = NULL;
if (p_cb) {
STREAM_TO_UINT8 (results.hci_status, p);
if (results.hci_status == HCI_SUCCESS) {
results.status = BTM_SUCCESS;
STREAM_TO_UINT8 (results.tx_power, p);
BTM_TRACE_EVENT ("BTM INQ TX POWER Complete: tx_power %d, hci status 0x%02x\n",
results.tx_power, results.hci_status);
}{...} else {
results.status = BTM_ERR_PROCESSING;
}{...}
(*p_cb)(&results);
}{...}
}{ ... }
/* ... */
tBTM_STATUS BTM_WriteEIR( BT_HDR *p_buff, BOOLEAN fec_required)
{
if (controller_get_interface()->supports_extended_inquiry_response()) {
BTM_TRACE_API("Write Extended Inquiry Response to controller\n");
btsnd_hcic_write_ext_inquiry_response (p_buff, fec_required);
osi_free(p_buff);
return BTM_SUCCESS;
}{...} else {
osi_free(p_buff);
return BTM_MODE_UNSUPPORTED;
}{...}
}{ ... }
/* ... */
UINT8 *BTM_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length )
{
UINT8 *p = p_eir;
UINT8 length;
UINT8 eir_type;
BTM_TRACE_API("BTM_CheckEirData type=0x%02X\n", type);
STREAM_TO_UINT8(length, p);
while ( length && (p - p_eir <= HCI_EXT_INQ_RESPONSE_LEN)) {
STREAM_TO_UINT8(eir_type, p);
if ( eir_type == type ) {
*p_length = length - 1;
return p;
}{...}
p += length - 1;
STREAM_TO_UINT8(length, p);
}{...}
*p_length = 0;
return NULL;
}{ ... }
/* ... */
static UINT8 btm_convert_uuid_to_eir_service( UINT16 uuid16 )
{
UINT8 xx;
for ( xx = 0; xx < BTM_EIR_MAX_SERVICES; xx++ ) {
if ( uuid16 == BTM_EIR_UUID_LKUP_TBL[xx]) {
return xx;
}{...}
}{...}
return BTM_EIR_MAX_SERVICES;
}{ ... }
/* ... */
BOOLEAN BTM_HasEirService( UINT32 *p_eir_uuid, UINT16 uuid16 )
{
UINT8 service_id;
service_id = btm_convert_uuid_to_eir_service(uuid16);
if ( service_id < BTM_EIR_MAX_SERVICES ) {
return ( BTM_EIR_HAS_SERVICE( p_eir_uuid, service_id ));
}{...} else {
return ( FALSE );
}{...}
}{ ... }
/* ... */
tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( tBTM_INQ_RESULTS *p_results, UINT16 uuid16 )
{
if ( BTM_HasEirService( p_results->eir_uuid, uuid16 )) {
return BTM_EIR_FOUND;
}{...} else if ( p_results->eir_complete_list ) {
return BTM_EIR_NOT_FOUND;
}{...} else {
return BTM_EIR_UNKNOWN;
}{...}
}{ ... }
/* ... */
void BTM_AddEirService( UINT32 *p_eir_uuid, UINT16 uuid16 )
{
UINT8 service_id;
service_id = btm_convert_uuid_to_eir_service(uuid16);
if ( service_id < BTM_EIR_MAX_SERVICES ) {
BTM_EIR_SET_SERVICE( p_eir_uuid, service_id );
}{...}
}{ ... }
/* ... */
static bool btm_compare_uuid(tBT_UUID *uuid1, tBT_UUID *uuid2)
{
if (uuid1->len != uuid2->len) {
return FALSE;
}{...}
return (memcmp(&uuid1->uu, &uuid2->uu, uuid1->len) == 0);
}{ ... }
/* ... */
static UINT8 btm_find_empty_custom_uuid_slot(tBT_UUID *custom_uuid, tBT_UUID uuid)
{
for (UINT8 xx = 0; xx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; xx++) {
if (custom_uuid[xx].len == 0) {
return xx;
}{...}
}{...}
return BTA_EIR_SERVER_NUM_CUSTOM_UUID;
}{ ... }
/* ... */
static UINT8 btm_find_match_custom_uuid_slot(tBT_UUID *custom_uuid, tBT_UUID uuid)
{
for (UINT8 xx = 0; xx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; xx++) {
if (btm_compare_uuid(&custom_uuid[xx], &uuid)) {
return xx;
}{...}
}{...}
return BTA_EIR_SERVER_NUM_CUSTOM_UUID;
}{ ... }
/* ... */
BOOLEAN BTM_HasCustomEirService(tBT_UUID *custom_uuid, tBT_UUID uuid)
{
UINT8 match_slot = btm_find_match_custom_uuid_slot(custom_uuid, uuid);
if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) {
return FALSE;
}{...}
return TRUE;
}{ ... }
/* ... */
void BTM_AddCustomEirService(tBT_UUID *custom_uuid, tBT_UUID uuid)
{
UINT8 empty_slot = btm_find_empty_custom_uuid_slot(custom_uuid, uuid);
if (empty_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) {
BTM_TRACE_WARNING("No space to add UUID for EIR");
}{...} else {
memcpy(&(custom_uuid[empty_slot]), &(uuid), sizeof(tBT_UUID));
BTM_TRACE_EVENT("UUID saved in %d slot", empty_slot);
}{...}
}{ ... }
/* ... */
void BTM_RemoveEirService( UINT32 *p_eir_uuid, UINT16 uuid16 )
{
UINT8 service_id;
service_id = btm_convert_uuid_to_eir_service(uuid16);
if ( service_id < BTM_EIR_MAX_SERVICES ) {
BTM_EIR_CLR_SERVICE( p_eir_uuid, service_id );
}{...}
}{ ... }
/* ... */
void BTM_RemoveCustomEirService(tBT_UUID *custom_uuid, tBT_UUID uuid)
{
UINT8 match_slot = btm_find_match_custom_uuid_slot(custom_uuid, uuid);
if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) {
BTM_TRACE_WARNING("UUID is not found for EIR");
return;
}{...} else {
memset(&(custom_uuid[match_slot]), 0, sizeof(tBT_UUID));
}{...}
}{ ... }
/* ... */
UINT8 BTM_GetEirSupportedServices( UINT32 *p_eir_uuid, UINT8 **p,
UINT8 max_num_uuid16, UINT8 *p_num_uuid16)
{
UINT8 service_index;
*p_num_uuid16 = 0;
for (service_index = 0; service_index < BTM_EIR_MAX_SERVICES; service_index++) {
if ( BTM_EIR_HAS_SERVICE( p_eir_uuid, service_index )) {
if ( *p_num_uuid16 < max_num_uuid16 ) {
UINT16_TO_STREAM(*p, BTM_EIR_UUID_LKUP_TBL[service_index]);
(*p_num_uuid16)++;
}{...}
else {
return BTM_EIR_MORE_16BITS_UUID_TYPE;
}{...}
}{...}
}{...}
return BTM_EIR_COMPLETE_16BITS_UUID_TYPE;
}{ ... }
/* ... */
UINT8 BTM_GetEirUuidList( UINT8 *p_eir, UINT8 uuid_size, UINT8 *p_num_uuid,
UINT8 *p_uuid_list, UINT8 max_num_uuid)
{
UINT8 *p_uuid_data;
UINT8 type;
UINT8 yy, xx;
UINT16 *p_uuid16 = (UINT16 *)p_uuid_list;
UINT32 *p_uuid32 = (UINT32 *)p_uuid_list;
char buff[LEN_UUID_128 * 2 + 1];
p_uuid_data = btm_eir_get_uuid_list( p_eir, uuid_size, p_num_uuid, &type );
if ( p_uuid_data == NULL ) {
return 0x00;
}{...}
if ( *p_num_uuid > max_num_uuid ) {
BTM_TRACE_WARNING("BTM_GetEirUuidList number of uuid in EIR = %d, size of uuid list = %d\n",
*p_num_uuid, max_num_uuid );
*p_num_uuid = max_num_uuid;
}{...}
BTM_TRACE_DEBUG("BTM_GetEirUuidList type = %02X, number of uuid = %d\n", type, *p_num_uuid );
if ( uuid_size == LEN_UUID_16 ) {
for ( yy = 0; yy < *p_num_uuid; yy++ ) {
STREAM_TO_UINT16(*(p_uuid16 + yy), p_uuid_data);
BTM_TRACE_DEBUG(" 0x%04X\n", *(p_uuid16 + yy));
}{...}
}{...} else if ( uuid_size == LEN_UUID_32 ) {
for ( yy = 0; yy < *p_num_uuid; yy++ ) {
STREAM_TO_UINT32(*(p_uuid32 + yy), p_uuid_data);
BTM_TRACE_DEBUG(" 0x%08X\n", *(p_uuid32 + yy));
}{...}
}{...} else if ( uuid_size == LEN_UUID_128 ) {
for ( yy = 0; yy < *p_num_uuid; yy++ ) {
STREAM_TO_ARRAY16(p_uuid_list + yy * LEN_UUID_128, p_uuid_data);
for ( xx = 0; xx < LEN_UUID_128; xx++ ) {
sprintf(buff + xx * 2, "%02X", *(p_uuid_list + yy * LEN_UUID_128 + xx));
}{...}
BTM_TRACE_DEBUG(" 0x%s\n", buff);
}{...}
}{...}
return type;
}{ ... }
/* ... */
static UINT8 *btm_eir_get_uuid_list( UINT8 *p_eir, UINT8 uuid_size,
UINT8 *p_num_uuid, UINT8 *p_uuid_list_type )
{
UINT8 *p_uuid_data;
UINT8 complete_type, more_type;
UINT8 uuid_len;
switch ( uuid_size ) {
case LEN_UUID_16:
complete_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE;
more_type = BTM_EIR_MORE_16BITS_UUID_TYPE;
break;...
case LEN_UUID_32:
complete_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE;
more_type = BTM_EIR_MORE_32BITS_UUID_TYPE;
break;...
case LEN_UUID_128:
complete_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE;
more_type = BTM_EIR_MORE_128BITS_UUID_TYPE;
break;...
default:
*p_num_uuid = 0;
return NULL;
break;...
}{...}
p_uuid_data = BTM_CheckEirData( p_eir, complete_type, &uuid_len );
if (p_uuid_data == NULL) {
p_uuid_data = BTM_CheckEirData( p_eir, more_type, &uuid_len );
*p_uuid_list_type = more_type;
}{...} else {
*p_uuid_list_type = complete_type;
}{...}
*p_num_uuid = uuid_len / uuid_size;
return p_uuid_data;
}{ ... }
/* ... */
static UINT16 btm_convert_uuid_to_uuid16( UINT8 *p_uuid, UINT8 uuid_size )
{
static const UINT8 base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}{...};
UINT16 uuid16 = 0;
UINT32 uuid32;
BOOLEAN is_base_uuid;
UINT8 xx;
switch (uuid_size) {
case LEN_UUID_16:
STREAM_TO_UINT16 (uuid16, p_uuid);
break;...
case LEN_UUID_32:
STREAM_TO_UINT32 (uuid32, p_uuid);
if (uuid32 < 0x10000) {
uuid16 = (UINT16) uuid32;
}{...}
break;...
case LEN_UUID_128:
is_base_uuid = TRUE;
for (xx = 0; xx < LEN_UUID_128 - 4; xx++) {
if (p_uuid[xx] != base_uuid[xx]) {
is_base_uuid = FALSE;
break;
}{...}
}{...}
if (is_base_uuid) {
if ((p_uuid[LEN_UUID_128 - 1] == 0) && (p_uuid[LEN_UUID_128 - 2] == 0)) {
p_uuid += (LEN_UUID_128 - 4);
STREAM_TO_UINT16(uuid16, p_uuid);
}{...}
}{...}
break;...
default:
BTM_TRACE_WARNING("btm_convert_uuid_to_uuid16 invalid uuid size\n");
break;...
}{...}
return ( uuid16);
}{ ... }
/* ... */
void btm_set_eir_uuid( UINT8 *p_eir, tBTM_INQ_RESULTS *p_results )
{
UINT8 *p_uuid_data;
UINT8 num_uuid;
UINT16 uuid16;
UINT8 yy;
UINT8 type = BTM_EIR_MORE_16BITS_UUID_TYPE;
p_uuid_data = btm_eir_get_uuid_list( p_eir, LEN_UUID_16, &num_uuid, &type );
if (type == BTM_EIR_COMPLETE_16BITS_UUID_TYPE) {
p_results->eir_complete_list = TRUE;
}{...} else {
p_results->eir_complete_list = FALSE;
}{...}
BTM_TRACE_API("btm_set_eir_uuid eir_complete_list=0x%02X\n", p_results->eir_complete_list);
if ( p_uuid_data ) {
for ( yy = 0; yy < num_uuid; yy++ ) {
STREAM_TO_UINT16(uuid16, p_uuid_data);
BTM_AddEirService( p_results->eir_uuid, uuid16 );
}{...}
}{...}
p_uuid_data = btm_eir_get_uuid_list( p_eir, LEN_UUID_32, &num_uuid, &type );
if ( p_uuid_data ) {
for ( yy = 0; yy < num_uuid; yy++ ) {
uuid16 = btm_convert_uuid_to_uuid16( p_uuid_data, LEN_UUID_32 );
p_uuid_data += LEN_UUID_32;
if ( uuid16 ) {
BTM_AddEirService( p_results->eir_uuid, uuid16 );
}{...}
}{...}
}{...}
p_uuid_data = btm_eir_get_uuid_list( p_eir, LEN_UUID_128, &num_uuid, &type );
if ( p_uuid_data ) {
for ( yy = 0; yy < num_uuid; yy++ ) {
uuid16 = btm_convert_uuid_to_uuid16( p_uuid_data, LEN_UUID_128 );
p_uuid_data += LEN_UUID_128;
if ( uuid16 ) {
BTM_AddEirService( p_results->eir_uuid, uuid16 );
}{...}
}{...}
}{...}
}{ ... }